Print

Print


Commit in slicPandora on MAIN
src/DetectorGeometry.cpp+38-91.3 -> 1.4
   /SimCalorimeterHitProcessor.cpp+88-31.2 -> 1.3
include/DetectorGeometry.h+101.3 -> 1.4
       /IDDecoder.h+51.1 -> 1.2
       /SimCalorimeterHitProcessor.h+111.1 -> 1.2
+152-12
5 modified files
full implementation of SimCalorimeterHitProcessor (based on CalorimeterHitMaker) including required additions and changes to DetectorGeometry and IDDecoder classes

slicPandora/src
DetectorGeometry.cpp 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- DetectorGeometry.cpp	2 Mar 2010 21:00:57 -0000	1.3
+++ DetectorGeometry.cpp	3 Mar 2010 22:47:51 -0000	1.4
@@ -13,6 +13,8 @@
 
 using namespace std;
 
+#define DETECTOR_GEOMETRY_DEBUG 1
+
 DetectorGeometry::DetectorGeometry(std::string filename)
 {
     loadFromFile(filename);
@@ -45,6 +47,8 @@
         PandoraApi::GeometryParameters::SubDetectorParameters* subdet = 
             getSubDetectorFromType(subdetType);
 
+        ExtraSubDetectorParameters extras;
+
         if (subdet == 0)
         {
             std::cerr << "FATAL ERROR: Could not find subdetector with type " << subdetType << ".  Exiting!"  << std::endl;
@@ -92,28 +96,31 @@
              layerElem = layerElem->NextSiblingElement() )
         {
             PandoraApi::GeometryParameters::LayerParameters layerParams;
+            DetectorGeometry::ExtraLayerParameters layerExtra;
 
             float dToIp = 0;
             float radLen = 0.;
             float intLen = 0.;
+            float samplingFrac = 0.;
 
             layerElem->QueryFloatAttribute("intLen", &intLen);
             layerElem->QueryFloatAttribute("radLen", &radLen);
             layerElem->QueryFloatAttribute("distanceToIp", &dToIp);
+            layerElem->QueryFloatAttribute("samplingFraction", &samplingFrac);
             
             layerParams.m_closestDistanceToIp = dToIp;
             layerParams.m_nRadiationLengths = radLen;
             layerParams.m_nInteractionLengths = intLen;
 
+            // Layer extras (sampling fraction).
+            layerExtra.m_samplingFraction = samplingFrac;
+            extras.m_extraLayerParams.push_back(layerExtra);
+
             // Add the layer to the subdetector's layer list.
             subdet->m_layerParametersList.push_back(layerParams);
         }
 
-        // Dump subdetector parameters to screen.
-        printOut(subdetType, subdet);
-
         // Add cell size information to extras map.
-        ExtraSubDetectorParameters extras;
         int cellSizeU = 0;
         int cellSizeV = 0;
         calElem->QueryIntAttribute("cellSizeU", &cellSizeU);
@@ -128,31 +135,39 @@
         TiXmlElement* fieldElem = (TiXmlElement*) idElem->FirstChild("field");
         for (fieldElem;
              fieldElem;
-             fieldElem = idElem->NextSiblingElement())
+             fieldElem = fieldElem->NextSiblingElement())
         {
             std::string name;
             int length = 0;
             int start = 0;
             bool isSigned = false;
-            std::string isSignedStr = false;
+            std::string isSignedStr;
 
-            name = std::string(fieldElem->Attribute("name"));
+            name = fieldElem->Attribute("name");
             fieldElem->QueryIntAttribute("length", &length);
             fieldElem->QueryIntAttribute("start", &start);
-            isSignedStr = fieldElem->Attribute("isSigned");
+            isSignedStr = fieldElem->Attribute("signed");
             if (isSignedStr == "true")
             {
                 isSigned = true;
             }
             IDDecoder::IDField* field = new IDDecoder::IDField(name, start, length, isSigned);
+            
             fields.push_back(field);            
-        }        
+        }   
+
+        // Make an IDDecoder for this calorimeter.
         IDDecoder* decoder = new IDDecoder(fields);
         extras.m_decoder = decoder;
 
         // Insert the extra subdetector information.            
         std::string subdetTypeStr(subdetType);
         subdetExtras[subdetTypeStr] = extras;
+
+        // Dump subdetector parameters to screen.
+#ifdef DETECTOR_GEOMETRY_DEBUG
+        printOut(subdetType, subdet);
+#endif
     }   
 
     // Tracking parameters.
@@ -166,12 +181,14 @@
     geom.m_mainTrackerOuterRadius = touterR;
     geom.m_mainTrackerZExtent = tz;
 
+#ifdef DETECTOR_GEOMETRY_DEBUG
     // Print tracking.
     printf("Tracking: \n");
     printf("    mainTrackerInnerRadius: %f\n", geom.m_mainTrackerInnerRadius.Get());
     printf("    mainTrackerOuterRadius: %f\n", geom.m_mainTrackerOuterRadius.Get());
     printf("    mainTrackerZExtent: %f\n", geom.m_mainTrackerZExtent.Get());
     printf("\n" );    
+#endif
 
     // Coil and B-field.
     TiXmlElement* coil = root->FirstChildElement("coil");
@@ -186,6 +203,7 @@
     geom.m_coilZExtent = cz;
     geom.m_bField = bfield;  
 
+#ifdef DETECTOR_GEOMETRY_DEBUG
     // Print coil and field.
     printf("Coil: \n");
     printf("    coilInnerRadius: %f\n", geom.m_coilInnerRadius.Get());
@@ -193,6 +211,7 @@
     printf("    coilZExtent: %f\n", geom.m_coilZExtent.Get());
     printf("    bField: %f\n", geom.m_bField.Get());
     printf("\n" );
+#endif
 }
 
 PandoraApi::GeometryParameters::SubDetectorParameters* DetectorGeometry::getSubDetectorFromType(const std::string& subdetType)
@@ -250,6 +269,16 @@
         printf("        layer %i - dToIp=%f, radLen=%f, intLen=%f\n", cntr, lp.m_closestDistanceToIp.Get(), lp.m_nRadiationLengths.Get(), lp.m_nInteractionLengths.Get());
         ++cntr;             
     }
+
+    // Extras.
+    const DetectorGeometry::ExtraSubDetectorParameters& extras = subdetExtras[subdetType];
+    IDDecoder* decoder = extras.m_decoder;
+    std::cout << "    ID Fields (name, start, length, signed) - " << decoder->getFieldCount() << std::endl;           
+    for (int i=0, j=decoder->getFieldCount(); i<j; i++)
+    {
+        IDDecoder::IDField* field = decoder->getField(i);
+        std::cout << "        " << field->getName() << ", " << field->getStart() << ", " << field->getLength() << ", " << field->isSigned() << std::endl;
+    }
     
     printf("\n");    
 }

slicPandora/src
SimCalorimeterHitProcessor.cpp 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- SimCalorimeterHitProcessor.cpp	24 Feb 2010 01:13:49 -0000	1.2
+++ SimCalorimeterHitProcessor.cpp	3 Mar 2010 22:47:51 -0000	1.3
@@ -7,6 +7,23 @@
 #include "JobManager.h"
 #include "JobConfig.h"
 #include "DetectorGeometry.h"
+#include "IDDecoder.h"
+
+// lcio
+#include "EVENT/LCIO.h"
+#include "EVENT/LCCollection.h"
+#include "IMPL/LCCollectionVec.h"
+#include "IMPL/CalorimeterHitImpl.h"
+#include "IMPL/LCRelationImpl.h"
+#include "IMPL/LCFlagImpl.h" 
+#include "EVENT/SimCalorimeterHit.h"
+
+using EVENT::LCCollection;
+using IMPL::LCFlagImpl;
+using IMPL::CalorimeterHitImpl;
+using IMPL::LCCollectionVec;
+using IMPL::LCRelationImpl;
+using EVENT::SimCalorimeterHit;
 
 SimCalorimeterHitProcessor::SimCalorimeterHitProcessor()
     : EventProcessor("SimCalorimeterHitProcessor")
@@ -18,17 +35,85 @@
 void SimCalorimeterHitProcessor::processEvent(EVENT::LCEvent* event)
 {   
     JobManager* mgr = getJobManager();
+
+    // Get the job's DetectorGeometry from the JobManager.
     DetectorGeometry* geom = mgr->getDetectorGeometry();
+
+    // Get extra subdetector parameters map defined by slicPandora and not in PandoraApi.
     DetectorGeometry::ExtraSubDetectorParametersMap* subdetExtras = geom->getExtraParameters();
+
+    // Get the list of calorimeter types being used for this job.
     JobConfig::CalorimeterTypes calTypes = getJobManager()->getJobConfig()->getCalorimeterTypes();
+
+    // Make the relation table from SimCalorimeterHit to corresponding CalorimeterHit.
+    LCCollectionVec* scRel = new LCCollectionVec(EVENT::LCIO::LCRELATION);
+    scRel->parameters().setValue("RelationFromType", EVENT::LCIO::CALORIMETERHIT);
+    scRel->parameters().setValue("RelationToType", EVENT::LCIO::SIMCALORIMETERHIT);
+
+    // Loop over calorimeter types.
     for (JobConfig::CalorimeterTypes::iterator iter = calTypes.begin();
          iter != calTypes.end();
          iter++)
     {
         PandoraApi::GeometryParameters::SubDetectorParameters* subdet = geom->getSubDetectorFromType((*iter));
-        const DetectorGeometry::ExtraSubDetectorParameters& subdetX = subdetExtras->at((*iter));
+        const DetectorGeometry::ExtraSubDetectorParameters& xsubdet = subdetExtras->at((*iter));
 
-    }
-}
+        PandoraApi::GeometryParameters::LayerParametersList* layerList = &(subdet->m_layerParametersList);
+
+        const std::string& collectionName = xsubdet.m_collection;
+        IDDecoder* decoder = xsubdet.m_decoder;
 
+        LCCollection* simCalHits = event->getCollection(collectionName);
+        LCCollection* calHits = new LCCollectionVec(EVENT::LCIO::CALORIMETERHIT);
+        LCFlagImpl chFlag(0);
+        chFlag.setBit(EVENT::LCIO::CHBIT_LONG);
+
+        int nSimHits = simCalHits->getNumberOfElements();
+        for (int i = 0; i < nSimHits; i++)
+        {
+            // Get the SimCalorimeterHit to be converted.
+            SimCalorimeterHit* simCalHit = dynamic_cast<SimCalorimeterHit*> (simCalHits->getElementAt(i));
+
+            // Create a new, empty CalorimeterHit.
+            CalorimeterHitImpl* calHit = new CalorimeterHitImpl;
+
+            // Get the 32-bit chunks of the id.
+            int cellId0 = simCalHit->getCellID0();
+            int cellId1 = simCalHit->getCellID1();
+
+            // Make a 64-bit id for the IDDecoder.  This MUST be type "long long" and not "long".  (Tony)
+            long long cellId = ((long long)cellId1)<<32 | cellId0;
+
+            // Decode the layer number from the id.
+            int layer = decoder->getFieldValue("layer", cellId);
+
+            // Get the layer parameters for this layer.
+            PandoraApi::GeometryParameters::LayerParameters layerParams = (*layerList)[layer];
+
+            // Get the extra layer parameters for this layer (sampling).
+            DetectorGeometry::ExtraLayerParameters xlayerParams = xsubdet.m_extraLayerParams[layer];
+
+            // Get the sampling fraction for this layer.
+            // TODO: Separate EM + HAD sampling fractions.
+            float samplingFrac = xlayerParams.m_samplingFraction.Get();
+
+            // Copy SimCalorimeterHit information into CalorimeterHit.
+            calHit->setEnergy(simCalHit->getEnergy() / samplingFrac);
+            calHit->setCellID0(simCalHit->getCellID0());
+            calHit->setCellID1(simCalHit->getCellID1());
+            calHit->setTime(simCalHit->getTimeCont(0));
+            calHit->setPosition(simCalHit->getPosition());
+            
+            // Setup the relations.
+            scRel->addElement(new LCRelationImpl(calHit, simCalHit, 0.5));
+            scRel->addElement(new LCRelationImpl(calHit, simCalHit, 0.5));
+            scRel->addElement(new LCRelationImpl(calHit, simCalHit, 0.5));
+
+            // Add the created CalorimeterHit to the collection.
+            calHits->addElement(calHit);            
+        }                
 
+        // Add the CalorimeterHits to the event with the collection name the same as the calorimeter type, e.g. EM_BARREL.
+        event->addCollection(calHits, (*iter));
+    }
+}

slicPandora/include
DetectorGeometry.h 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- DetectorGeometry.h	24 Feb 2010 01:13:49 -0000	1.3
+++ DetectorGeometry.h	3 Mar 2010 22:47:51 -0000	1.4
@@ -10,6 +10,15 @@
     
 public:
 
+    // Extra layer parameters.
+    class ExtraLayerParameters
+    {
+    public:
+        pandora::InputFloat m_samplingFraction;
+    };
+
+    typedef std::vector<ExtraLayerParameters> ExtraLayerParametersList;
+
     // Extra subdetector parameters, including cell sizes.
     class ExtraSubDetectorParameters
     {
@@ -18,6 +27,7 @@
         pandora::InputFloat m_cellSizeV;
         std::string m_collection;
         IDDecoder* m_decoder;
+        ExtraLayerParametersList m_extraLayerParams;
     };
 
     typedef std::map<std::string, ExtraSubDetectorParameters> ExtraSubDetectorParametersMap;

slicPandora/include
IDDecoder.h 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- IDDecoder.h	24 Feb 2010 01:13:49 -0000	1.1
+++ IDDecoder.h	3 Mar 2010 22:47:52 -0000	1.2
@@ -96,6 +96,11 @@
     {
         return m_name2IndexMap[name];
     }
+    
+    int getFieldCount()
+    {
+        return m_fields.size();
+    }
 
 private:
     IDFields m_fields;

slicPandora/include
SimCalorimeterHitProcessor.h 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- SimCalorimeterHitProcessor.h	23 Feb 2010 02:27:27 -0000	1.1
+++ SimCalorimeterHitProcessor.h	3 Mar 2010 22:47:52 -0000	1.2
@@ -3,12 +3,23 @@
 
 #include "EventProcessor.h"
 
+/**
+ * This EventProcessor converts SimCalorimeterHits from slic output into CalorimeterHits suitable for Pandora input.
+ * A sampling fraction is applied to the raw energy during this conversion process, and a relation table is
+ * setup to connect the original SimCalorimeterHits to their converted CalorimeterHits.  The output CalorimeterHit
+ * collection is given the same name as the CalorimeterType being processed (e.g. "EM_BARREL", "HAD_ENDCAP", etc.).
+ * This class is based on the example code in slicPandora/src/CalorimeterHitMaker by Norman Graf.  In the future, 
+ * this procedure may be removed from slicPandora and performed in a Java reconstruction processor in LCSim, instead.
+ *
+ * @author Jeremy McCormick
+ */
 class SimCalorimeterHitProcessor : public EventProcessor
 {
 public:
     SimCalorimeterHitProcessor();
     virtual ~SimCalorimeterHitProcessor();
 
+public:
     void processEvent(EVENT::LCEvent*);    
 };
 
CVSspam 0.2.8