Commit in GeomConverter/src/org/lcsim/geometry/compact/converter/pandora on MAIN
Main.java+92-931.16 -> 1.17
get default sampling fractions from CalorimeterCalibration properties file.
added muon calorimeters back in.
expect to fail.

GeomConverter/src/org/lcsim/geometry/compact/converter/pandora
Main.java 1.16 -> 1.17
diff -u -r1.16 -r1.17
--- Main.java	15 Jun 2010 20:21:29 -0000	1.16
+++ Main.java	15 Jun 2010 21:36:53 -0000	1.17
@@ -55,13 +55,13 @@
  * geometry input format.
  * 
  * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: Main.java,v 1.16 2010/06/15 20:21:29 ngraf Exp $
+ * @version $Id: Main.java,v 1.17 2010/06/15 21:36:53 ngraf Exp $
  */
 public class Main implements Converter
 {
     // ConditionsManager instance.
-    private ConditionsManager conditionsManager = ConditionsManager.defaultInstance();
 
+    private ConditionsManager conditionsManager = ConditionsManager.defaultInstance();
     // Numerical formatting.
     static final DecimalFormat xlen = new DecimalFormat("#.########");
     static final DecimalFormat xfrac = new DecimalFormat("#.########");
@@ -74,6 +74,7 @@
      */
     static class SamplingLayerRange
     {
+
         int lowerLayer;
         int upperLayer;
         double em;
@@ -122,8 +123,10 @@
      */
     static class SamplingLayers extends ArrayList<SamplingLayerRange>
     {
+
         public SamplingLayers()
-        {}
+        {
+        }
 
         public SamplingLayers(SamplingLayerRange range)
         {
@@ -143,24 +146,24 @@
                     return range;
             }
             return null;
-        }        
+        }
     }
-    
+
     private static class QCalCalibration
     {
+
         private static final String resourceName = "Qcal-v2r3p10";
-       
-        Map<String,SamplingLayers> calLayers = new HashMap<String,SamplingLayers>();
-        
-        protected QCalCalibration (Detector detector)
+        Map<String, SamplingLayers> calLayers = new HashMap<String, SamplingLayers>();
+
+        protected QCalCalibration(Detector detector)
         {
             ConditionsManager mgr = ConditionsManager.defaultInstance();
-            
+
             ConditionsSet hadronCalibration = mgr.getConditions("hadronCalibration/nh" + resourceName);
             ConditionsSet photonCalibration = mgr.getConditions("photonCalibration/photon" + resourceName);
-            
+
             int nFrontLayersEcal = hadronCalibration.getInt("nFrontLayersEcal");
-            
+
             // Get sampling fraction conditions.
             double photonSf[] = photonCalibration.getDoubleArray("SFs");
             double hadronSf[] = hadronCalibration.getDoubleArray("SFs");
@@ -169,48 +172,48 @@
             Calorimeter emBarr = detector.getCalorimeterByType(Calorimeter.CalorimeterType.EM_BARREL);
             if (emBarr != null)
             {
-                int emBarrMaxLayer = emBarr.getLayering().getLayerCount() - 1;                         
+                int emBarrMaxLayer = emBarr.getLayering().getLayerCount() - 1;
                 SamplingLayerRange ecalBarrFrontRange = new SamplingLayerRange(0, nFrontLayersEcal - 1, photonSf[0], hadronSf[0]);
                 SamplingLayerRange ecalBarrBackRange = new SamplingLayerRange(nFrontLayersEcal, emBarrMaxLayer, photonSf[1], hadronSf[1]);
                 calLayers.put("EM_BARREL", new SamplingLayers());
                 calLayers.get("EM_BARREL").add(ecalBarrFrontRange);
                 calLayers.get("EM_BARREL").add(ecalBarrBackRange);
             }
-            
+
             // EM Endcap.
             Calorimeter emEc = detector.getCalorimeterByType(Calorimeter.CalorimeterType.EM_ENDCAP);
             if (emEc != null)
             {
-                int emEcMaxLayer = emEc.getLayering().getLayerCount() - 1;            
+                int emEcMaxLayer = emEc.getLayering().getLayerCount() - 1;
                 SamplingLayerRange ecalEcFrontRange = new SamplingLayerRange(0, nFrontLayersEcal - 1, photonSf[2], hadronSf[2]);
                 SamplingLayerRange ecalEcBackRange = new SamplingLayerRange(nFrontLayersEcal, emEcMaxLayer, photonSf[3], hadronSf[3]);
                 calLayers.put("EM_ENDCAP", new SamplingLayers());
                 calLayers.get("EM_ENDCAP").add(ecalEcFrontRange);
                 calLayers.get("EM_ENDCAP").add(ecalEcBackRange);
             }
-            
+
             // HAD Barrel.           
             Calorimeter hadBarr = detector.getCalorimeterByType(Calorimeter.CalorimeterType.HAD_BARREL);
             if (hadBarr != null)
             {
                 int hadBarrMaxLayer = hadBarr.getLayering().getLayerCount() - 1;
                 ConditionsSet hcalBarrSampling = mgr.getConditions("SamplingFractions/" + hadBarr.getName());
-                double hcalBarrSF = hcalBarrSampling.getDouble("samplingFraction");            
-                SamplingLayerRange hcalBarrRange = new SamplingLayerRange(0, hadBarrMaxLayer, hcalBarrSF, hadronSf[4]);            
+                double hcalBarrSF = hcalBarrSampling.getDouble("samplingFraction");
+                SamplingLayerRange hcalBarrRange = new SamplingLayerRange(0, hadBarrMaxLayer, hcalBarrSF, hadronSf[4]);
                 calLayers.put("HAD_BARREL", new SamplingLayers(hcalBarrRange));
             }
-            
+
             // HAD Endcap.
             Calorimeter hadEc = detector.getCalorimeterByType(Calorimeter.CalorimeterType.HAD_ENDCAP);
             if (hadEc != null)
             {
                 int hadEcMaxLayer = hadEc.getLayering().getLayerCount() - 1;
                 ConditionsSet hcalEcSampling = mgr.getConditions("SamplingFractions/" + hadEc.getName());
-                double hcalEcSF = hcalEcSampling.getDouble("samplingFraction");            
-                SamplingLayerRange hcalEcRange = new SamplingLayerRange(0, hadEcMaxLayer, hcalEcSF, hadronSf[5]);            
+                double hcalEcSF = hcalEcSampling.getDouble("samplingFraction");
+                SamplingLayerRange hcalEcRange = new SamplingLayerRange(0, hadEcMaxLayer, hcalEcSF, hadronSf[5]);
                 calLayers.put("HAD_ENDCAP", new SamplingLayers(hcalEcRange));
             }
-            
+
             // MUON Barrel.
             Calorimeter muonBarr = detector.getCalorimeterByType(Calorimeter.CalorimeterType.MUON_BARREL);
             if (muonBarr != null)
@@ -221,7 +224,7 @@
                 SamplingLayerRange muonBarrRange = new SamplingLayerRange(0, muonBarrMaxLayer, muonBarrSF, muonBarrSF);
                 calLayers.put("MUON_BARREL", new SamplingLayers(muonBarrRange));
             }
-            
+
             // MUON Endcap.
             Calorimeter muonEc = detector.getCalorimeterByType(Calorimeter.CalorimeterType.MUON_ENDCAP);
             if (muonEc != null)
@@ -233,16 +236,16 @@
                 calLayers.put("MUON_ENDCAP", new SamplingLayers(muonEcRange));
             }
         }
-        
+
         public double getHadronSamplingFraction(Calorimeter calorimeter, int layern)
         {
-            return calLayers.get(calorimeter.getCalorimeterType().toString()).getSamplingLayerRange(layern).getHADSampling();            
+            return calLayers.get(calorimeter.getCalorimeterType().toString()).getSamplingLayerRange(layern).getHADSampling();
         }
-        
+
         double getPhotonSamplingFraction(Calorimeter calorimeter, int layern)
         {
             return calLayers.get(calorimeter.getCalorimeterType().toString()).getSamplingLayerRange(layern).getEMSampling();
-        }        
+        }
     }
 
     /**
@@ -252,6 +255,7 @@
      */
     private static class CalorimeterConditions
     {
+
         SamplingLayers samplingLayers;
         String name;
         double mipEnergy;
@@ -288,25 +292,21 @@
         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)
             {
                 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 if (calorimeter.getCalorimeterType() == CalorimeterType.MUON_BARREL || calorimeter.getCalorimeterType() == CalorimeterType.MUON_ENDCAP)
+            } else if (calorimeter.getCalorimeterType() == CalorimeterType.MUON_BARREL || calorimeter.getCalorimeterType() == CalorimeterType.MUON_ENDCAP)
             {
                 layeringName = "MuonLayering";
-            }
-            else
+            } 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;
@@ -315,8 +315,7 @@
             {
                 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";
@@ -326,7 +325,7 @@
             {
                 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>();
@@ -362,7 +361,7 @@
             {
                 samplingIndex = (new StringTokenizer(conditions.getString("ECalLayering"), ",").countTokens());
             }
-            
+
             // Create the SamplingLayerRange list.
             samplingLayers = new SamplingLayers();
             for (int i = 0; i < layers.size(); i++)
@@ -379,34 +378,33 @@
                 double emSamplingFraction = emSamplingFractions.get(samplingIndex);
                 double hadSamplingFraction = hadSamplingFractions.get(samplingIndex);
                 SamplingLayerRange samplingLayerRange = new SamplingLayerRange(
-                                                                               lowerLayer,
-                                                                               upperLayer,
-                                                                               emSamplingFraction,
-                                                                               hadSamplingFraction);
-                                
+                        lowerLayer,
+                        upperLayer,
+                        emSamplingFraction,
+                        hadSamplingFraction);
+
                 samplingLayers.add(samplingLayerRange);
 
                 ++samplingIndex;
             }
-            
+
             // MIP energy.
             String mipCondition = null;
             String mipSigmaCondition = null;
             String mipCutCondition = null;
-            if (calorimeter.getCalorimeterType() == CalorimeterType.EM_BARREL || 
-                    calorimeter.getCalorimeterType() == CalorimeterType.EM_ENDCAP)
+            if (calorimeter.getCalorimeterType() == CalorimeterType.EM_BARREL
+                    || calorimeter.getCalorimeterType() == CalorimeterType.EM_ENDCAP)
             {
                 mipCondition = "ECalMip_MPV";
                 mipSigmaCondition = "ECalMip_sig";
                 mipCutCondition = "ECalMip_Cut";
-            }
-            else if (calorimeter.getCalorimeterType() == CalorimeterType.HAD_BARREL ||
-                    calorimeter.getCalorimeterType() == CalorimeterType.HAD_ENDCAP)
+            } else if (calorimeter.getCalorimeterType() == CalorimeterType.HAD_BARREL
+                    || calorimeter.getCalorimeterType() == CalorimeterType.HAD_ENDCAP)
             {
                 mipCondition = "HCalMip_MPV";
                 mipSigmaCondition = "HCalMip_sig";
                 mipCutCondition = "HCalMip_Cut";
-            }                                                
+            }
             mipEnergy = conditions.getDouble(mipCondition);
             mipSigma = conditions.getDouble(mipSigmaCondition);
             mipCut = conditions.getDouble(mipCutCondition);
@@ -422,22 +420,22 @@
             }
             return null;
         }
-        
+
         public double getMipEnergy()
         {
             return mipEnergy;
         }
-        
+
         public double getMipSigma()
         {
             return mipSigma;
         }
-        
+
         public double getMipCut()
         {
             return mipCut;
         }
-        
+
         public double getTimeCut()
         {
             return timeCut;
@@ -452,8 +450,7 @@
         try
         {
             conditionsManager.setDetector(detectorName, 0);
-        }
-        catch (ConditionsNotFoundException x)
+        } catch (ConditionsNotFoundException x)
         {
             throw new RuntimeException("Failed to setup conditions system for detector: " + detectorName, x);
         }
@@ -475,20 +472,20 @@
         outputDoc.setRootElement(root);
         Element calorimeters = new Element("calorimeters");
         root.addContent(calorimeters);
-          
+
         // Setup CalorimeterCalibration conditions.
         ConditionsSet calorimeterCalibration = null;
         try
         {
             calorimeterCalibration = conditionsManager.getConditions("CalorimeterCalibration");
+        } catch (Exception x)
+        {
         }
-        catch (Exception x)
-        {}        
-        boolean haveCalCalib = (calorimeterCalibration == null ) ? false : true;
-        
+        boolean haveCalCalib = (calorimeterCalibration == null) ? false : true;
+
         // Setup QCalCalibration.
         QCalCalibration qcalib = new QCalCalibration(detector);
-                             
+
         // Process the subdetectors.
         for (Subdetector subdetector : detector.getSubdetectors().values())
         {
@@ -496,12 +493,11 @@
             if (subdetector instanceof AbstractPolyhedraCalorimeter)
             {
                 Element calorimeter = new Element("calorimeter");
-                AbstractPolyhedraCalorimeter polycal = (AbstractPolyhedraCalorimeter) subdetector;                
-                
+                AbstractPolyhedraCalorimeter polycal = (AbstractPolyhedraCalorimeter) subdetector;
+
                 // Look for specific calorimeter types in the compact description.
                 Calorimeter.CalorimeterType calType = polycal.getCalorimeterType();
-                if (calType.equals(HAD_BARREL) || calType.equals(HAD_ENDCAP) || calType.equals(EM_ENDCAP) || calType
-                        .equals(EM_BARREL) ) // || calType.equals(MUON_BARREL) || calType.equals(MUON_ENDCAP))
+                if (calType.equals(HAD_BARREL) || calType.equals(HAD_ENDCAP) || calType.equals(EM_ENDCAP) || calType.equals(EM_BARREL) || calType.equals(MUON_BARREL) || calType.equals(MUON_ENDCAP))
                 {
                     // Set basic parameters in pandora calorimeter.
                     calorimeter.setAttribute("type", Calorimeter.CalorimeterType.toString(calType));
@@ -538,20 +534,18 @@
                     if (polycal.isBarrel())
                     {
                         layerD = polycal.getInnerR();
-                    }
-                    else if (polycal.isEndcap())
+                    } else if (polycal.isEndcap())
                     {
                         layerD = polycal.getInnerZ();
                     }
 
                     CalorimeterConditions subdetectorCalorimeterConditions = null;
-                    
+
                     if (haveCalCalib)
                     {
-                        subdetectorCalorimeterConditions 
-                            = new CalorimeterConditions((Calorimeter) subdetector, calorimeterCalibration);
+                        subdetectorCalorimeterConditions = new CalorimeterConditions((Calorimeter) subdetector, calorimeterCalibration);
                     }
-                    
+
                     // Set MIP energy from calibration.
                     if (haveCalCalib)
                     {
@@ -559,24 +553,23 @@
                         calorimeter.setAttribute("mipSigma", xfrac.format(subdetectorCalorimeterConditions.getMipSigma()));
                         calorimeter.setAttribute("mipCut", xfrac.format(subdetectorCalorimeterConditions.getMipCut()));
                         calorimeter.setAttribute("timeCut", xfrac.format(subdetectorCalorimeterConditions.getTimeCut()));
-                    }
-                    // Set MIP energy from Bethe-Bloche calculation.
+                    } // Set MIP energy from Bethe-Bloche calculation.
                     // TODO Check accuracy of this algorithm.
                     else
                     {
                         List<LayerSlice> sensors = subdetector.getLayering().getLayerStack().getLayer(0).getSensors();
                         LayerSlice sensor = sensors.get(0);
                         IMaterial sensorMaterial = MaterialStore.getInstance().get(sensor.getMaterial().getName());
-                                                                        
+
                         ParticleType particleType = ParticlePropertyManager.getParticlePropertyProvider().get(13);
-                        
+
                         Hep3Vector p = new BasicHep3Vector(-6.8641, -7.2721, 1.2168e-7);
-                        
+
                         double emip = BetheBlochCalculator.computeBetheBloch(sensorMaterial, p, particleType.getMass(), particleType.getCharge(), sensor.getThickness());
-                        
+
                         // Set MIP Energy from Bethe Bloche.
                         calorimeter.setAttribute("mipEnergy", xfrac.format(emip));
-                        
+
                         // Set defaults for CalCalib parameters.
                         calorimeter.setAttribute("mipSigma", "0");
                         calorimeter.setAttribute("mipCut", "0");
@@ -592,7 +585,7 @@
 
                         // Set radiation and interaction lengths.
                         double intLen = 0;
-                        double radLen = 0;                      
+                        double radLen = 0;
                         for (int j = 0; j < layer.getNumberOfSlices(); j++)
                         {
                             LayerSlice slice = layer.getSlice(j);
@@ -601,11 +594,11 @@
                         }
                         layerElem.setAttribute("radLen", xlen.format(radLen));
                         layerElem.setAttribute("intLen", xlen.format(intLen));
-                        
+
                         // Set distance to IP.                        
                         double layerD2 = layerD + layer.getThicknessToSensitiveMid();
                         layerElem.setAttribute("distanceToIp", xthick.format(layerD2));
-                        
+
                         // Set cell thickness. 
                         layerElem.setAttribute("cellThickness", xthick.format(layer.getSensorThickness()));
 
@@ -614,15 +607,22 @@
                                 subdetector,
                                 i);
                         layerElem.setAttribute("samplingFraction", xfrac.format(samplingFraction));
-                        
+
                         // Set EM and HAD sampling fractions from CalorimeterCalibration conditions.
                         if (haveCalCalib)
                         {
                             SamplingLayerRange layerRange = subdetectorCalorimeterConditions.getSamplingLayerRange(i);
+                            if (calType == EM_BARREL || calType == EM_ENDCAP)
+                            {
+                                layerElem.setAttribute("samplingFraction", xfrac.format(layerRange.getEMSampling()));
+                            }
+                            if (calType == HAD_BARREL || calType == HAD_ENDCAP)
+                            {
+                                layerElem.setAttribute("samplingFraction", xfrac.format(layerRange.getHADSampling()));
+                            }
                             layerElem.setAttribute("emSamplingFraction", xfrac.format(layerRange.getEMSampling()));
                             layerElem.setAttribute("hadSamplingFraction", xfrac.format(layerRange.getHADSampling()));
-                        }
-                        // Set from base SamplingFraction conditions.
+                        } // Set from base SamplingFraction conditions.
                         else
                         {
                             layerElem.setAttribute("emSamplingFraction", xfrac.format(samplingFraction));
@@ -635,16 +635,14 @@
                 }
 
                 // Set digital attribute from conditions.
-                ConditionsSet conditions = conditionsManager
-                        .getConditions("SamplingFractions/" + subdetector.getName());
-                
+                ConditionsSet conditions = conditionsManager.getConditions("SamplingFractions/" + subdetector.getName());
+
                 // Set digital flag.
                 try
                 {
                     boolean isDigital = conditions.getBoolean("digital");
                     calorimeter.setAttribute("digital", String.valueOf(isDigital));
-                }
-                catch (IllegalArgumentException x)
+                } catch (IllegalArgumentException x)
                 {
                     calorimeter.setAttribute("digital", "false");
                 }
@@ -730,6 +728,7 @@
 
     private static class PandoraFileFilter extends FileFilter
     {
+
         public boolean accept(java.io.File file)
         {
             return file.isDirectory() || file.getName().endsWith(".xml");
@@ -740,4 +739,4 @@
             return "Pandora Geometry file (*.xml)";
         }
     }
-}
\ No newline at end of file
+}
CVSspam 0.2.8