Print

Print


Commit in GeomConverter/src/org/lcsim/geometry/compact/converter/pandora on MAIN
Main.java+128-1101.9 -> 1.10
EM and HAD sampling fractions written to pandora XML geometry file

GeomConverter/src/org/lcsim/geometry/compact/converter/pandora
Main.java 1.9 -> 1.10
diff -u -r1.9 -r1.10
--- Main.java	19 May 2010 20:39:12 -0000	1.9
+++ Main.java	19 May 2010 21:00:03 -0000	1.10
@@ -45,7 +45,7 @@
  * geometry input format.
  * 
  * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: Main.java,v 1.9 2010/05/19 20:39:12 jeremy Exp $
+ * @version $Id: Main.java,v 1.10 2010/05/19 21:00:03 jeremy Exp $
  */
 public class Main implements Converter
 {
@@ -55,17 +55,75 @@
     // Numerical formatting.
     static final DecimalFormat xlen = new DecimalFormat("#.########");
     static final DecimalFormat xfrac = new DecimalFormat("#.########");
-    static final DecimalFormat xthick = new DecimalFormat("#.######");    
-    
+    static final DecimalFormat xthick = new DecimalFormat("#.######");
+
+    /**
+     * A range of layers with associated EM and HAD sampling fractions.
+     * 
+     * @author Jeremy McCormick <[log in to unmask]>
+     */
+    static class SamplingLayerRange
+    {
+        int lowerLayer;
+        int upperLayer;
+        double em;
+        double had;
+
+        SamplingLayerRange(int lowerLayer, int upperLayer, double em, double had)
+        {
+            this.lowerLayer = lowerLayer;
+            this.upperLayer = upperLayer;
+            this.em = em;
+            this.had = had;
+        }
+
+        public boolean inRange(int layerNumber)
+        {
+            return layerNumber >= lowerLayer && layerNumber <= upperLayer;
+        }
+
+        public int getLowerLayer()
+        {
+            return lowerLayer;
+        }
+
+        public int getUpperLayer()
+        {
+            return upperLayer;
+        }
+
+        public double getEMSampling()
+        {
+            return em;
+        }
+
+        public double getHADSampling()
+        {
+            return had;
+        }
+    }
+
+    /**
+     * A list of SamplingLayerRange objects to represent the sampling for a
+     * subdetector.
+     * 
+     * @author Jeremy McCormick <[log in to unmask]>
+     * 
+     */
+    static class SamplingLayers extends ArrayList<SamplingLayerRange>
+    {
+    }
+
     /**
      * Represents CalorimeterConditions for a single subdetector.
+     * 
      * @author Jeremy McCormick <[log in to unmask]>
      */
     private static class CalorimeterConditions
     {
         SamplingLayers samplingLayers;
         String name;
-        
+
         public String toString()
         {
             StringBuffer buff = new StringBuffer();
@@ -76,105 +134,60 @@
                 buff.append("    em = " + range.getEMSampling() + '\n');
                 buff.append("    had = " + range.getHADSampling() + '\n');
             }
-            
+
             return buff.toString();
         }
-        
+
         public SamplingLayers getSamplingLayers()
         {
             return samplingLayers;
         }
-        
-        private static class SamplingLayerRange
-        {
-            int lowerLayer;
-            int upperLayer;
-            double em;
-            double had;
-            
-            SamplingLayerRange(int lowerLayer, int upperLayer, double em, double had)
-            {
-                this.lowerLayer = lowerLayer;
-                this.upperLayer = upperLayer;
-                this.em = em;
-                this.had = had;
-            }
-            
-            public boolean inRange(int layerNumber)
-            {
-                return layerNumber >= lowerLayer && layerNumber <= upperLayer; 
-            }
-            
-            public int getLowerLayer()
-            {
-                return lowerLayer;
-            }
-            
-            public int getUpperLayer()
-            {
-                return upperLayer;
-            }
-            
-            public double getEMSampling()
-            {
-                return em;
-            }
-            
-            public double getHADSampling()
-            {
-                return had;
-            }
-        }            
-        
-        private static class SamplingLayers extends ArrayList<SamplingLayerRange>
-        {}
-                        
+
         /**
-         * Constructor that parses raw CalorimeterCalibration conditions for a single subdetector.
+         * Constructor that parses raw CalorimeterCalibration conditions for a
+         * single subdetector.
+         * 
          * @param calorimeter
          * @param conditions
          */
         protected CalorimeterConditions(Calorimeter calorimeter, ConditionsSet conditions)
-        {                        
+        {
             this.name = calorimeter.getName();
-            
+
             // Figure out which layering conditions to use based on the CalorimeterType.
             String layeringName = null;
-            if (calorimeter.getCalorimeterType() == CalorimeterType.EM_BARREL 
-                    || calorimeter.getCalorimeterType() == CalorimeterType.EM_ENDCAP)
+            if (calorimeter.getCalorimeterType() == CalorimeterType.EM_BARREL || calorimeter.getCalorimeterType() == CalorimeterType.EM_ENDCAP)
             {
                 layeringName = "ECalLayering";
             }
-            else if (calorimeter.getCalorimeterType() == CalorimeterType.HAD_BARREL 
-                    || calorimeter.getCalorimeterType() == CalorimeterType.HAD_ENDCAP)
+            else if (calorimeter.getCalorimeterType() == CalorimeterType.HAD_BARREL || calorimeter.getCalorimeterType() == CalorimeterType.HAD_ENDCAP)
             {
                 layeringName = "HCalLayering";
             }
             else
             {
-                throw new RuntimeException("Don't know how to handle CalorimeterConditions for " + calorimeter.getName() + ".");
+                throw new RuntimeException("Don't know how to handle CalorimeterConditions for " + calorimeter
+                        .getName() + ".");
             }
-                         
+
             String emName = null;
             String hadName = null;
-            if (calorimeter.getCalorimeterType() == CalorimeterType.EM_BARREL ||
-                    calorimeter.getCalorimeterType() == CalorimeterType.HAD_BARREL)
+            if (calorimeter.getCalorimeterType() == CalorimeterType.EM_BARREL || calorimeter.getCalorimeterType() == CalorimeterType.HAD_BARREL)
             {
                 emName = "EMBarrel_SF";
                 hadName = "HadBarrel_SF";
             }
-            else if (calorimeter.getCalorimeterType() == CalorimeterType.EM_ENDCAP ||
-                    calorimeter.getCalorimeterType() == CalorimeterType.HAD_ENDCAP)
+            else if (calorimeter.getCalorimeterType() == CalorimeterType.EM_ENDCAP || calorimeter.getCalorimeterType() == CalorimeterType.HAD_ENDCAP)
             {
                 emName = "EMEndcap_SF";
                 hadName = "HadEndcap_SF";
             }
-            
+
             if (emName == null || hadName == null)
             {
                 throw new RuntimeException("Sampling fractions not found for " + calorimeter.getName() + ".");
             }
-            
+
             String emSampling = conditions.getString(emName);
             String hadSampling = conditions.getString(hadName);
             List<Double> emSamplingFractions = new ArrayList<Double>();
@@ -184,15 +197,15 @@
             {
                 Double emSamplingFraction = Double.valueOf(tok.nextToken().trim());
                 emSamplingFractions.add(emSamplingFraction);
-            }            
+            }
             tok = new StringTokenizer(hadSampling, ",");
             while (tok.hasMoreTokens())
             {
                 Double hadSamplingFraction = Double.valueOf(tok.nextToken().trim());
                 hadSamplingFractions.add(hadSamplingFraction);
             }
-            
-            String layering = conditions.getString(layeringName);            
+
+            String layering = conditions.getString(layeringName);
             tok = new StringTokenizer(layering, ",");
             List<Integer> layers = new ArrayList<Integer>();
             int maxLayer = calorimeter.getLayering().getLayerCount() - 1;
@@ -202,41 +215,45 @@
                 int nextLayer = Integer.valueOf(nextToken);
                 layers.add(nextLayer);
             }
-            for (int i=0; i<layers.size(); i++)
+            for (int i = 0; i < layers.size(); i++)
             {
                 int l = layers.get(i);
-            }            
-            
+            }
+
             // FIXME Hack to get the correct starting index for the sampling fractions.  Ideally, the sampling fractions
             //       should be separated by subdetector name.
             int samplingIndex = 0;
             if (calorimeter.getCalorimeterType() == HAD_BARREL || calorimeter.getCalorimeterType() == HAD_ENDCAP)
             {
-                samplingIndex = (new StringTokenizer(conditions.getString("ECalLayering"), ",").countTokens() - 1);                       
+                samplingIndex = (new StringTokenizer(conditions.getString("ECalLayering"), ",").countTokens() - 1);
             }
-            
+
             // Create the SamplingLayerRange list.
             samplingLayers = new SamplingLayers();
-            for (int i=0; i<layers.size(); i++)
-            {                
+            for (int i = 0; i < layers.size(); i++)
+            {
                 // Figure out the layer range.
                 int lowerLayer = layers.get(i);
                 int upperLayer = 0;
                 if (i + 1 > layers.size() - 1)
                     upperLayer = maxLayer;
                 else
-                    upperLayer = layers.get(i+1) - 1;
-                
+                    upperLayer = layers.get(i + 1) - 1;
+
                 // Create the sampling layer range.                
                 double emSamplingFraction = emSamplingFractions.get(samplingIndex);
-                double hadSamplingFraction = hadSamplingFractions.get(samplingIndex);                                
-                SamplingLayerRange samplingLayerRange = new SamplingLayerRange(lowerLayer, upperLayer, emSamplingFraction, hadSamplingFraction);                
+                double hadSamplingFraction = hadSamplingFractions.get(samplingIndex);
+                SamplingLayerRange samplingLayerRange = new SamplingLayerRange(
+                                                                               lowerLayer,
+                                                                               upperLayer,
+                                                                               emSamplingFraction,
+                                                                               hadSamplingFraction);
                 samplingLayers.add(samplingLayerRange);
-                
+
                 ++samplingIndex;
-            }            
+            }
         }
-        
+
         public SamplingLayerRange getSamplingLayerRange(int layer)
         {
             for (SamplingLayerRange layers : this.samplingLayers)
@@ -245,9 +262,9 @@
                     return layers;
             }
             return null;
-        }                
+        }
     }
-        
+
     public void convert(String inputFileName, InputStream in, OutputStream out) throws Exception
     {
         GeometryReader reader = new GeometryReader();
@@ -280,12 +297,12 @@
         Element calorimeters = new Element("calorimeters");
         root.addContent(calorimeters);
 
-        ConditionsSet calorimeterCalibration = 
-            conditionsManager.getConditions("CalorimeterCalibration");
-        
+        ConditionsSet calorimeterCalibration = conditionsManager.getConditions("CalorimeterCalibration");
+
         if (calorimeterCalibration == null)
-            throw new RuntimeException("Missing CalorimeterCalibration.properties for " + detector.getDetectorName() + ".");                
-        
+            throw new RuntimeException(
+                                       "Missing CalorimeterCalibration.properties for " + detector.getDetectorName() + ".");
+
         for (Subdetector subdetector : detector.getSubdetectors().values())
         {
             // Only handle polyhedra calorimeters for now.
@@ -302,13 +319,11 @@
                     calorimeter.setAttribute("innerR", Double.toString(polycal.getInnerR()));
                     calorimeter.setAttribute("innerZ", Double.toString(polycal.getInnerZ()));
                     calorimeter.setAttribute("innerPhi", Double.toString(polycal.getInnerPhi()));
-                    calorimeter.setAttribute("innerSymmetryOrder", Double.toString(polycal
-                            .getInnerNumberOfSides()));
+                    calorimeter.setAttribute("innerSymmetryOrder", Double.toString(polycal.getInnerNumberOfSides()));
                     calorimeter.setAttribute("outerR", Double.toString(polycal.getOuterR()));
                     calorimeter.setAttribute("outerZ", Double.toString(polycal.getOuterZ()));
                     calorimeter.setAttribute("outerPhi", Double.toString(polycal.getOuterPhi()));
-                    calorimeter.setAttribute("outerSymmetryOrder", Double.toString(polycal
-                            .getOuterNumberOfSides()));
+                    calorimeter.setAttribute("outerSymmetryOrder", Double.toString(polycal.getOuterNumberOfSides()));
 
                     calorimeter.setAttribute("collection", subdetector.getReadout().getName());
 
@@ -337,13 +352,13 @@
                     else if (polycal.isEndcap())
                     {
                         layerD = polycal.getInnerZ();
-                    }        
-                    
-                    
-                    CalorimeterConditions subdetectorCalorimeterConditions = 
-                        new CalorimeterConditions((Calorimeter)subdetector, calorimeterCalibration);
-                    
-                    System.out.println(subdetectorCalorimeterConditions.toString());                    
+                    }
+
+                    CalorimeterConditions subdetectorCalorimeterConditions = new CalorimeterConditions(
+                                                                                                       (Calorimeter) subdetector,
+                                                                                                       calorimeterCalibration);
+
+                    //System.out.println(subdetectorCalorimeterConditions.toString());
 
                     for (int i = 0; i < layers.getNumberOfLayers(); i++)
                     {
@@ -359,8 +374,7 @@
                         {
                             LayerSlice slice = layer.getSlice(j);
                             radLen += slice.getThickness() / slice.getMaterial().getRadiationLength();
-                            intLen += slice.getThickness() / slice.getMaterial()
-                                    .getNuclearInteractionLength();
+                            intLen += slice.getThickness() / slice.getMaterial().getNuclearInteractionLength();
                         }
 
                         double layerD2 = layerD + layer.getThicknessToSensitiveMid();
@@ -370,19 +384,24 @@
                         layerElem.setAttribute("intLen", xlen.format(intLen));
                         layerElem.setAttribute("cellThickness", xthick.format(layer.getSensorThickness()));
 
-                        double samplingFraction = SamplingFractionManager.defaultInstance()
-                                .getSamplingFraction(subdetector, i);
+                        double samplingFraction = SamplingFractionManager.defaultInstance().getSamplingFraction(
+                                subdetector,
+                                i);
                         layerElem.setAttribute("samplingFraction", xfrac.format(samplingFraction));
 
-                        // TODO Add separate EM + HAD sampling fractions here.
+                        // Set EM and HAD sampling fractions.
+                        SamplingLayerRange layerRange = subdetectorCalorimeterConditions.getSamplingLayerRange(i);
+                        layerElem.setAttribute("emSamplingFraction", xfrac.format(layerRange.getEMSampling()));
+                        layerElem.setAttribute("hadSamplingFraction", xfrac.format(layerRange.getHADSampling()));
 
+                        // Increment layer distance by thickness of layer.
                         layerD += layer.getThickness();
                     }
                 }
 
                 // Set digital attribute from conditions.
-                ConditionsSet conditions = conditionsManager.getConditions("SamplingFractions/" + subdetector
-                        .getName());
+                ConditionsSet conditions = conditionsManager
+                        .getConditions("SamplingFractions/" + subdetector.getName());
                 try
                 {
                     boolean isDigital = conditions.getBoolean("digital");
@@ -485,6 +504,5 @@
             return "Pandora Geometry file (*.xml)";
         }
     }
-    
-    
+
 }
CVSspam 0.2.8