Print

Print


Commit in GeomConverter/src/org/lcsim/geometry/compact/converter/pandora on MAIN
Main.java+120-301.13 -> 1.14
add 3 new subdetector params from Norman; work around not having CalorimeterCalibration file with defaults

GeomConverter/src/org/lcsim/geometry/compact/converter/pandora
Main.java 1.13 -> 1.14
diff -u -r1.13 -r1.14
--- Main.java	27 May 2010 17:18:58 -0000	1.13
+++ Main.java	7 Jun 2010 23:02:12 -0000	1.14
@@ -4,14 +4,18 @@
 import static org.lcsim.geometry.Calorimeter.CalorimeterType.EM_ENDCAP;
 import static org.lcsim.geometry.Calorimeter.CalorimeterType.HAD_BARREL;
 import static org.lcsim.geometry.Calorimeter.CalorimeterType.HAD_ENDCAP;
+import static org.lcsim.geometry.Calorimeter.CalorimeterType.MUON_BARREL;
+import static org.lcsim.geometry.Calorimeter.CalorimeterType.MUON_ENDCAP;
+import hep.physics.particle.properties.ParticlePropertyManager;
+import hep.physics.particle.properties.ParticleType;
 import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
 
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.text.DecimalFormat;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Set;
 import java.util.StringTokenizer;
 
 import javax.swing.filechooser.FileFilter;
@@ -23,6 +27,9 @@
 import org.lcsim.conditions.ConditionsManager;
 import org.lcsim.conditions.ConditionsSet;
 import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
+import org.lcsim.detector.material.BetheBlochCalculator;
+import org.lcsim.detector.material.IMaterial;
+import org.lcsim.detector.material.MaterialStore;
 import org.lcsim.detector.solids.Tube;
 import org.lcsim.geometry.Calorimeter;
 import org.lcsim.geometry.Detector;
@@ -46,7 +53,7 @@
  * geometry input format.
  * 
  * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: Main.java,v 1.13 2010/05/27 17:18:58 jeremy Exp $
+ * @version $Id: Main.java,v 1.14 2010/06/07 23:02:12 jeremy Exp $
  */
 public class Main implements Converter
 {
@@ -124,6 +131,9 @@
         SamplingLayers samplingLayers;
         String name;
         double mipEnergy;
+        double mipSigma;
+        double mipCut;
+        double timeCut;
 
         public String toString()
         {
@@ -253,17 +263,26 @@
             
             // MIP energy.
             String mipCondition = null;
+            String mipSigmaCondition = null;
+            String mipCutCondition = null;
             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)
             {
                 mipCondition = "HCalMip_MPV";
+                mipSigmaCondition = "HCalMip_sig";
+                mipCutCondition = "HCalMip_Cut";
             }                                                
-            mipEnergy = conditions.getDouble(mipCondition);           
+            mipEnergy = conditions.getDouble(mipCondition);
+            mipSigma = conditions.getDouble(mipSigmaCondition);
+            mipCut = conditions.getDouble(mipCutCondition);
+            timeCut = conditions.getDouble("timeCut");
         }
 
         public SamplingLayerRange getSamplingLayerRange(int layer)
@@ -280,6 +299,21 @@
         {
             return mipEnergy;
         }
+        
+        public double getMipSigma()
+        {
+            return mipSigma;
+        }
+        
+        public double getMipCut()
+        {
+            return mipCut;
+        }
+        
+        public double getTimeCut()
+        {
+            return timeCut;
+        }
     }
 
     public void convert(String inputFileName, InputStream in, OutputStream out) throws Exception
@@ -307,32 +341,39 @@
 
     public Document convertDetectorToPandora(Detector detector)
     {
+        // Setup XML output document.
         Document outputDoc = new Document();
         Element root = new Element("pandoraSetup");
         outputDoc.setRootElement(root);
-
         Element calorimeters = new Element("calorimeters");
         root.addContent(calorimeters);
-
-        ConditionsSet calorimeterCalibration = conditionsManager.getConditions("CalorimeterCalibration");
-
-        if (calorimeterCalibration == null)
-            throw new RuntimeException(
-                                       "Missing CalorimeterCalibration.properties for " + detector.getDetectorName() + ".");
-
+          
+        // Setup CalorimeterCalibration conditions.
+        ConditionsSet calorimeterCalibration = null;
+        try
+        {
+            calorimeterCalibration = conditionsManager.getConditions("CalorimeterCalibration");
+        }
+        catch (Exception x)
+        {}        
+        boolean haveCalCalib = (calorimeterCalibration == null ) ? false : true;
+              
+        // Process the subdetectors.
         for (Subdetector subdetector : detector.getSubdetectors().values())
         {
-            // Only handle polyhedra calorimeters for now.
+            // Only handle calorimeters that are planar.
             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))
+                        .equals(EM_BARREL) || calType.equals(MUON_BARREL) || calType.equals(MUON_ENDCAP))
                 {
+                    // Set basic parameters in pandora calorimeter.
                     calorimeter.setAttribute("type", Calorimeter.CalorimeterType.toString(calType));
-
                     calorimeter.setAttribute("innerR", Double.toString(polycal.getInnerR()));
                     calorimeter.setAttribute("innerZ", Double.toString(polycal.getInnerZ()));
                     calorimeter.setAttribute("innerPhi", Double.toString(polycal.getInnerPhi()));
@@ -341,9 +382,9 @@
                     calorimeter.setAttribute("outerZ", Double.toString(polycal.getOuterZ()));
                     calorimeter.setAttribute("outerPhi", Double.toString(polycal.getOuterPhi()));
                     calorimeter.setAttribute("outerSymmetryOrder", Double.toString(polycal.getOuterNumberOfSides()));
-
                     calorimeter.setAttribute("collection", subdetector.getReadout().getName());
 
+                    // Set cell sizes.
                     List<Double> cellSizes = getCellSizes(subdetector);
                     calorimeter.setAttribute("cellSizeU", Double.toString(cellSizes.get(0)));
                     calorimeter.setAttribute("cellSizeV", Double.toString(cellSizes.get(1)));
@@ -351,6 +392,7 @@
                     // Create identifier description and add to subdet.
                     calorimeter.addContent(makeIdentifierDescription(polycal));
 
+                    // Add the calorimeter.
                     calorimeters.addContent(calorimeter);
 
                     LayerStack layers = polycal.getLayering().getLayerStack();
@@ -371,10 +413,44 @@
                         layerD = polycal.getInnerZ();
                     }
 
-                    CalorimeterConditions subdetectorCalorimeterConditions 
-                        = new CalorimeterConditions((Calorimeter) subdetector, calorimeterCalibration);
+                    CalorimeterConditions subdetectorCalorimeterConditions = null;
                     
-                    calorimeter.setAttribute("mipEnergy", xfrac.format(subdetectorCalorimeterConditions.getMipEnergy()));
+                    if (haveCalCalib)
+                    {
+                        subdetectorCalorimeterConditions 
+                            = new CalorimeterConditions((Calorimeter) subdetector, calorimeterCalibration);
+                    }
+                    
+                    // Set MIP energy from calibration.
+                    if (haveCalCalib)
+                    {
+                        calorimeter.setAttribute("mipEnergy", xfrac.format(subdetectorCalorimeterConditions.getMipEnergy()));
+                        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.
+                    // 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");
+                        calorimeter.setAttribute("timeCut", xfrac.format(Double.MAX_VALUE));
+                    }
 
                     for (int i = 0; i < layers.getNumberOfLayers(); i++)
                     {
@@ -383,32 +459,44 @@
                         Element layerElem = new Element("layer");
                         layersElem.addContent(layerElem);
 
+                        // 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);
                             radLen += slice.getThickness() / slice.getMaterial().getRadiationLength();
                             intLen += slice.getThickness() / slice.getMaterial().getNuclearInteractionLength();
                         }
-
-                        double layerD2 = layerD + layer.getThicknessToSensitiveMid();
-
-                        layerElem.setAttribute("distanceToIp", xthick.format(layerD2));
                         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()));
 
+                        // Set basic sampling fraction.
                         double samplingFraction = SamplingFractionManager.defaultInstance().getSamplingFraction(
                                 subdetector,
                                 i);
                         layerElem.setAttribute("samplingFraction", xfrac.format(samplingFraction));
-
-                        // 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()));
+                        
+                        // Set EM and HAD sampling fractions from CalorimeterCalibration conditions.
+                        if (haveCalCalib)
+                        {
+                            SamplingLayerRange layerRange = subdetectorCalorimeterConditions.getSamplingLayerRange(i);
+                            layerElem.setAttribute("emSamplingFraction", xfrac.format(layerRange.getEMSampling()));
+                            layerElem.setAttribute("hadSamplingFraction", xfrac.format(layerRange.getHADSampling()));
+                        }
+                        // Set from base SamplingFraction conditions.
+                        else
+                        {
+                            layerElem.setAttribute("emSamplingFraction", xfrac.format(samplingFraction));
+                            layerElem.setAttribute("hadSamplingFraction", xfrac.format(samplingFraction));
+                        }
 
                         // Increment layer distance by thickness of layer.
                         layerD += layer.getThickness();
@@ -418,6 +506,8 @@
                 // Set digital attribute from conditions.
                 ConditionsSet conditions = conditionsManager
                         .getConditions("SamplingFractions/" + subdetector.getName());
+                
+                // Set digital flag.
                 try
                 {
                     boolean isDigital = conditions.getBoolean("digital");
CVSspam 0.2.8