Commit in slicPandora on MAIN
include/DetectorGeometry.h+11-11.15 -> 1.16
src/DetectorGeometry.cpp+11-31.26 -> 1.27
   /SimCalorimeterHitProcessor.cpp+9-1881.27 -> 1.28
+31-192
3 modified files
add check of geometry's detector against LCIO's detector name in first processor to avoid running with the wrong detector

slicPandora/include
DetectorGeometry.h 1.15 -> 1.16
diff -u -r1.15 -r1.16
--- DetectorGeometry.h	19 Sep 2011 19:45:21 -0000	1.15
+++ DetectorGeometry.h	19 Sep 2011 20:34:53 -0000	1.16
@@ -1,4 +1,4 @@
-// $Id: DetectorGeometry.h,v 1.15 2011/09/19 19:45:21 jeremy Exp $
+// $Id: DetectorGeometry.h,v 1.16 2011/09/19 20:34:53 jeremy Exp $
 
 #ifndef DetectorGeometry_h
 #define DetectorGeometry_h 1
@@ -118,9 +118,19 @@
      */
     inline pandora::InputHitType getHitType(const std::string& calType) const;
 
+    /**
+     * Get the detector name.
+     * @return The detector name.
+     */
+    const std::string& getDetectorName() const
+    {
+        return detectorName;
+    }
+
 private:
     PandoraApi::Geometry::Parameters geom;
     ExtraSubDetectorParametersMap subdetExtras;
+    std::string detectorName;
 };
 
 

slicPandora/src
DetectorGeometry.cpp 1.26 -> 1.27
diff -u -r1.26 -r1.27
--- DetectorGeometry.cpp	16 Sep 2011 23:31:18 -0000	1.26
+++ DetectorGeometry.cpp	19 Sep 2011 20:34:53 -0000	1.27
@@ -14,9 +14,6 @@
 #include <cstring>
 #include <cmath>
 
-// tinyxml
-//#include "tinyxml.h"
-
 using namespace std;
 
 // Remove comment for debug output.
@@ -40,6 +37,17 @@
     // Get the root element.
     TiXmlElement* root = doc.RootElement();
 
+    // Get the name of the detector.
+    TiXmlElement* detector = root->FirstChildElement("detector");
+    if (detector->Attribute("name") != NULL)
+    {
+        detectorName = detector->Attribute("name");
+    }
+    else
+    {
+        throw runtime_error("Missing name of detector in XML geometry file.");
+    }
+
     // Process the calorimeter elements.
     TiXmlElement* calorimeters = root->FirstChildElement("calorimeters");
     TiXmlElement* calElem = (TiXmlElement*) calorimeters->FirstChild("calorimeter");

slicPandora/src
SimCalorimeterHitProcessor.cpp 1.27 -> 1.28
diff -u -r1.27 -r1.28
--- SimCalorimeterHitProcessor.cpp	16 Sep 2011 23:31:18 -0000	1.27
+++ SimCalorimeterHitProcessor.cpp	19 Sep 2011 20:34:53 -0000	1.28
@@ -19,6 +19,9 @@
 #include "IMPL/LCFlagImpl.h" 
 #include "EVENT/SimCalorimeterHit.h"
 
+// std
+#include <stdexcept>
+
 using EVENT::LCCollection;
 using IMPL::LCFlagImpl;
 using IMPL::CalorimeterHitImpl;
@@ -36,194 +39,6 @@
 {;}
 
 void SimCalorimeterHitProcessor::processEvent(EVENT::LCEvent* event)
-{   
-    processEventNew(event);
-}
-
-// Old code.
-/*
-void SimCalorimeterHitProcessor::processEvent(EVENT::LCEvent* event)
-{
-    //std::cout << "SimCalorimeterHitProcessor::processEvent" << std::endl;
-
-    JobManager* mgr = getJobManager();
-    const pandora::Pandora& pandora = mgr->getPandora();
-
-    // 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);
-
-    typedef std::map<MCParticle *, float> MCParticleToEnergyWeightMap;
-    MCParticleToEnergyWeightMap mcParticleToEnergyWeightMap;
-
-    // Loop over calorimeter types.
-    for (JobConfig::CalorimeterTypes::iterator iter = calTypes.begin();
-         iter != calTypes.end();
-         iter++)
-    {
-        // If a collection with name of CalorimeterType already exists,
-        // then assume conversion to CalorimeterHit took place externally and skip it.
-        const std::vector<std::string>* collNames = event->getCollectionNames();
-        if (find(collNames->begin(), collNames->end(), std::string(*iter)) != collNames->end())
-        {
-            continue;
-        }
-
-        PandoraApi::GeometryParameters::SubDetectorParameters* subdet = geom->getSubDetectorFromType((*iter));
-        std::string subdetName = (*iter);
-        const DetectorGeometry::ExtraSubDetectorParameters& xsubdet = subdetExtras->find(subdetName)->second;
-        const std::string& collectionName = xsubdet.m_collection;
-
-        LCCollection* simCalHits = 0;
-
-        // Try to fetch the collection by name from the input LCIO file and skip if doesn't exist.
-        try 
-        {
-            simCalHits = event->getCollection(collectionName);
-        }
-        // FIXME Could be some other problem than collection not found.
-        catch (...)
-        {
-            continue;
-        }
-
-        LCCollection* calHits = new LCCollectionVec(EVENT::LCIO::CALORIMETERHIT);        
-
-        float mipCut = xsubdet.m_mipCut.Get();
-        float timeCut = xsubdet.m_timeCut.Get();
-
-        PandoraApi::GeometryParameters::LayerParametersList* layerList = &(subdet->m_layerParametersList);
-
-        IDDecoder* decoder = xsubdet.m_decoder;
-
-        // Set correct flags for output collection.  
-        int flag = 1 << EVENT::LCIO::RCHBIT_LONG; // position
-        flag |= 1 << EVENT::LCIO::RCHBIT_ID1;     // cellId1
-        flag |= 1 << EVENT::LCIO::RCHBIT_TIME;    // time
-
-        LCFlagImpl chFlag(flag);
-        calHits->setFlag(chFlag.getFlag());
-        
-        // Convert input SimCalorimeterHits into CalorimeterHits.
-        int nSimHits = simCalHits->getNumberOfElements();
-        for (int i = 0; i < nSimHits; i++)
-        {
-            //            std::cout << "simhit " << i << "  nsimhits " << nSimHits << std::endl;
-            // Get the SimCalorimeterHit to be converted.
-            SimCalorimeterHit* simCalHit = dynamic_cast<SimCalorimeterHit*> (simCalHits->getElementAt(i));
-            if (!simCalHit)
-            {
-                std::cout << "simcalhit " << i << " is NULL" << std::endl;
-                exit(210);
-            }
-
-            float timeCont = simCalHit->getTimeCont(0);
-            float rawEnergy = simCalHit->getEnergy();
-
-            // Cut on late times.
-            if (timeCont > timeCut)
-            {
-                //std::cout << "cut on time: " << timeCont << std::endl;
-                continue;
-            }
-
-            // Cut on energies that are below the energy cut.
-            if (rawEnergy < mipCut)
-            {
-                //std::cout << "cut on energy: " << rawEnergy << std::endl;
-                continue;
-            }
-
-            // 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).
-            float samplingFrac = 0.f;
-            try
-            {
-                DetectorGeometry::ExtraLayerParameters xlayerParams = xsubdet.m_extraLayerParams.at(layer);
-                // Get the sampling fraction for this layer.
-                // TODO: Separate EM + HAD sampling fractions.
-                samplingFrac = xlayerParams.m_samplingFraction.Get();
-            }
-            catch(...)
-            {
-                std::cout << "no layer #" << layer << " existing in detector " << subdetName << std::endl;
-                throw;
-            }
-
-
-
-
-            // 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 relation between CalHit and SimHit.
-            scRel->addElement(new LCRelationImpl(calHit, simCalHit, 0.5));
-
-
-            // TODO, PROBLEM: the program gets never here if the Calorimeter collection has been created already before running SlicPandora
-            // -------- add link to MCParticle
-            mcParticleToEnergyWeightMap.clear();
-
-            for (int iCont = 0, iEnd = simCalHit->getNMCContributions(); iCont < iEnd; ++iCont)
-            {
-                mcParticleToEnergyWeightMap[simCalHit->getParticleCont(iCont)] += simCalHit->getEnergyCont(iCont);
-            }
-
-            for (MCParticleToEnergyWeightMap::const_iterator mcParticleIter = mcParticleToEnergyWeightMap.begin(),
-                     mcParticleIterEnd = mcParticleToEnergyWeightMap.end(); mcParticleIter != mcParticleIterEnd; ++mcParticleIter)
-            {
-                PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::SetCaloHitToMCParticleRelationship(pandora,     calHit     , mcParticleIter->first, mcParticleIter->second));
-            }
-            // -------- add link to MCParticle --- end
-
-
-
-            // Add the created CalorimeterHit to the collection.
-            calHits->addElement(calHit);            
-        }                
-
-        // Set the ReadoutName parameter for LCSim to find the correct IDDecoder.
-        calHits->parameters().setValue("ReadoutName", collectionName);
-
-        // Add the CalorimeterHits to the event with the collection name the same as the calorimeter type, e.g. EM_BARREL.
-        event->addCollection(calHits, (*iter));
-    }
-
-    // Add the CalorimeterHit to SimCalorimeterHit relations.
-    event->addCollection(scRel, "CalorimeterHitRelations");
-}
-*/
-
-void SimCalorimeterHitProcessor::processEventNew(EVENT::LCEvent* event)
 {
     // Get pointers to parameter and manager classes.
     JobManager* mgr = getJobManager();
@@ -232,6 +47,12 @@
     const LcioInputCollectionSettings& lcioConfig = mgr->getLcioCollectionSettings();
     const LcioInputCollectionSettings::CaloCollectionMap& caloCollMap = lcioConfig.getCaloCollectionMap();
 
+    // Check that the detector names match between file and geometry.
+    if (event->getDetectorName().compare(geom->getDetectorName()) != 0)
+    {
+        throw std::runtime_error("Detector name from LCIO file doesn't match geometry.");
+    }
+
     // Make the relation table from SimCalorimeterHit to corresponding CalorimeterHit.
     LCCollectionVec* scRel = new LCCollectionVec(EVENT::LCIO::LCRELATION);
     scRel->parameters().setValue("RelationFromType", EVENT::LCIO::CALORIMETERHIT);
CVSspam 0.2.8