Commit in slicPandora on MAIN
include/SimpleTrackProcessor.h+8-61.3 -> 1.4
src/SimpleTrackProcessor.cpp+95-1171.15 -> 1.16
+103-123
2 modified files
make MCParticle relation setup optional so that slicPandora continues if not present (tested and works); move some variables outside loops to optimize

slicPandora/include
SimpleTrackProcessor.h 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- SimpleTrackProcessor.h	8 Jun 2010 22:12:42 -0000	1.3
+++ SimpleTrackProcessor.h	6 Oct 2010 22:51:22 -0000	1.4
@@ -1,4 +1,4 @@
-// $Id: SimpleTrackProcessor.h,v 1.3 2010/06/08 22:12:42 jeremy Exp $
+// $Id: SimpleTrackProcessor.h,v 1.4 2010/10/06 22:51:22 jeremy Exp $
 #ifndef SIMPLETRACKPROCESSOR_H
 #define SIMPLETRACKPROCESSOR_H 1
 
@@ -17,7 +17,9 @@
  * This class converts from LCIO Tracks to PandoraApi::Track::Parameters
  * by reading in the "Tracks" collection from LCSim output events, as well
  * as three LCGenericObject collections containing TrackStates (x,y,z,px,py,pz)
- * at the track start, at the ECal face, and at the track end point.
+ * at the track start, at the ECal face, and at the track end point.  It will
+ * also setup links between Tracks and their associated MCParticles if the 
+ * LCRelations collection is present.
  */
 class SimpleTrackProcessor : public EventProcessor
 {
@@ -37,15 +39,15 @@
 
 private:
 
-    void setupTrackStatesFromRelations(PandoraApi::Track::Parameters&, EVENT::LCEvent*);
+    //void setupTrackStatesFromRelations(PandoraApi::Track::Parameters&, EVENT::LCEvent*);
     void setupTrackStatesFromGenericObjects(PandoraApi::Track::Parameters&, EVENT::LCEvent*, int);
 
 private:
 
     static std::string trackCollectionName;
-    static std::string startCollectionName;
-    static std::string ecalCollectionName;
-    static std::string endCollectionName;
+    //static std::string startCollectionName;
+    //static std::string ecalCollectionName;
+    //static std::string endCollectionName;
 };
 
 #endif

slicPandora/src
SimpleTrackProcessor.cpp 1.15 -> 1.16
diff -u -r1.15 -r1.16
--- SimpleTrackProcessor.cpp	6 Oct 2010 12:48:26 -0000	1.15
+++ SimpleTrackProcessor.cpp	6 Oct 2010 22:51:22 -0000	1.16
@@ -1,3 +1,4 @@
+// $Id: SimpleTrackProcessor.cpp,v 1.16 2010/10/06 22:51:22 jeremy Exp $
 #include "SimpleTrackProcessor.h"
 
 // slicPandora
@@ -23,7 +24,6 @@
 #include <cmath>
 #include <limits>
 
-
 using EVENT::LCCollection;
 using EVENT::Track;
 using EVENT::LCObjectVec;
@@ -31,11 +31,11 @@
 using UTIL::LCRelationNavigator;
 using pandora::CartesianVector;
 
-// FIXME Name of collection containing LCIO Track objects is hard-coded to "Tracks".
+// FIXME: Name of collection containing LCIO Track objects is hard-coded to "Tracks".
 std::string SimpleTrackProcessor::trackCollectionName = "Tracks";
-std::string SimpleTrackProcessor::startCollectionName = trackCollectionName + "_StateAtStart";
-std::string SimpleTrackProcessor::ecalCollectionName = trackCollectionName + "_StateAtECal";
-std::string SimpleTrackProcessor::endCollectionName = trackCollectionName + "_StateAtEnd";
+//std::string SimpleTrackProcessor::startCollectionName = trackCollectionName + "_StateAtStart";
+//std::string SimpleTrackProcessor::ecalCollectionName = trackCollectionName + "_StateAtECal";
+//std::string SimpleTrackProcessor::endCollectionName = trackCollectionName + "_StateAtEnd";
 
 void SimpleTrackProcessor::processEvent(EVENT::LCEvent* event)
 {   
@@ -50,6 +50,34 @@
         return;
     }
 
+
+    // Check if MC information is present.
+    bool haveMCRelations = false;
+    const EVENT::LCCollection *pMCRelationCollection = 0;
+    UTIL::LCRelationNavigator* navigate;
+    
+    // Look for LCRelations collection of HelicalTrackHits to MCParticles.
+    try 
+    {
+        pMCRelationCollection = event->getCollection("HelicalTrackMCRelations");
+    }
+    catch (EVENT::DataNotAvailableException &exception)
+    {}    
+
+    // Found relations collection.
+    if (pMCRelationCollection != 0)
+    {
+        haveMCRelations = true;
+        navigate = new UTIL::LCRelationNavigator(pMCRelationCollection);
+    }
+
+    // Get the GeometryHelper.
+    pandora::GeometryHelper *pGeometryHelper = pandora::GeometryHelper::GetInstance();
+
+    // Get the B field.
+    const float magneticField(pGeometryHelper->GetBField());
+
+    // Loop over input tracks.
     int ntracks = trackCollection->getNumberOfElements();
     for (int i=0; i<ntracks; i++)
     {
@@ -57,32 +85,34 @@
         std::cout << "proc track #" << i << std::endl;
 #endif
 
+        // Get the current Track.
         Track* track = dynamic_cast<Track*>(trackCollection->getElementAt(i));
 
+        // Setup a new Track parameters object.
         PandoraApi::Track::Parameters trackParameters;
 
-        // Pointer to LCIO Track.
+        // Get the pointer to the LCIO Track.
         trackParameters.m_pParentAddress = track;
 
-        // Impact parameters.
+        // Set impact parameters.
         trackParameters.m_d0 = track->getD0();
         trackParameters.m_z0 = track->getZ0();
 
-        // Sign.
+        // Set the sign.
         const float signedCurvature(track->getOmega());
         if (0. != signedCurvature)
             trackParameters.m_charge = static_cast<int>(signedCurvature / std::fabs(signedCurvature));
 
-        // FIXME Mass hard-coded to charged pion.
+        // FIXME: Mass hard-coded to charged pion.
         trackParameters.m_mass = 0.13957018;
 
-        // FIXME Particle Id hard-coded to charged pion.
+        // FIXME: Particle Id hard-coded to charged pion.
         if (signedCurvature > 0.)
             trackParameters.m_particleId = 211;
         else
             trackParameters.m_particleId = -211;
 
-        // FIXME Next three boolean parameters are hard-coded.
+        // FIXME: Next three boolean parameters are hard-coded.
         trackParameters.m_reachesECal = true;
         trackParameters.m_canFormPfo = true;
         trackParameters.m_canFormClusterlessPfo = false;
@@ -93,6 +123,7 @@
         // Set the momentum at DCA to track's start state.  
         trackParameters.m_momentumAtDca = trackParameters.m_trackStateAtStart.Get().GetMomentum();
 
+        // Print debug info if enabled.
 #ifdef SIMPLETRACKPROCESSOR_DEBUG
         std::cout << "Track Parameters: " << std::endl;
         std::cout << "    d0 = " << trackParameters.m_d0.Get() << std::endl;
@@ -108,78 +139,76 @@
         std::cout << "    parentAddress = " << trackParameters.m_pParentAddress.Get() << std::endl;
 #endif       
 
-        // Register object with Pandora.
+        // Register Track parameters with Pandora.
         const pandora::Pandora& pandora = getJobManager()->getPandora();
         PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::Track::Create(pandora, trackParameters));
 
-
-        pandora::GeometryHelper *pGeometryHelper = pandora::GeometryHelper::GetInstance();
-        const float magneticField(pGeometryHelper->GetBField());
-
-
-        // --- add MC information 
-        const EVENT::LCCollection *pMCRelationCollection = event->getCollection("HelicalTrackMCRelations");
-        UTIL::LCRelationNavigator navigate(pMCRelationCollection);
-
-
+        // Setup the Track to MCParticle relations (optional).
         EVENT::TrackerHitVec trackHits = track->getTrackerHits();
-
-        try
+        if (haveMCRelations)
         {
-            EVENT::MCParticle *pBestMCParticle = NULL;
-            for (EVENT::TrackerHitVec::const_iterator itTh = trackHits.begin(), itThEnd = trackHits.end(); itTh != itThEnd; ++itTh )
+            try
             {
-                EVENT::TrackerHit* trackerHit = (*itTh);
-                const EVENT::LCObjectVec &objectVec = navigate.getRelatedToObjects(trackerHit);
-
-                // Get reconstructed momentum at dca
-                const pandora::Helix helixFit(track->getPhi(), track->getD0(), track->getZ0(), track->getOmega(), track->getTanLambda(), magneticField);
-                const float recoMomentum(helixFit.GetMomentum().GetMagnitude());
-
-                // Use momentum magnitude to identify best mc particle
-                float bestDeltaMomentum(std::numeric_limits<float>::max());
-
-                for (EVENT::LCObjectVec::const_iterator itRel = objectVec.begin(), itRelEnd = objectVec.end(); itRel != itRelEnd; ++itRel)
+                EVENT::MCParticle *pBestMCParticle = NULL;
+                for (EVENT::TrackerHitVec::const_iterator itTh = trackHits.begin(), itThEnd = trackHits.end(); itTh != itThEnd; ++itTh )
                 {
-                    EVENT::MCParticle *pMCParticle = NULL;
-                    pMCParticle = dynamic_cast<EVENT::MCParticle *>(*itRel);
-
-                    if (NULL == pMCParticle)
-                        continue;
-
-                    const float trueMomentum(pandora::CartesianVector(pMCParticle->getMomentum()[0], pMCParticle->getMomentum()[1],
-                                                                      pMCParticle->getMomentum()[2]).GetMagnitude());
-
-                    const float deltaMomentum(std::fabs(recoMomentum - trueMomentum));
-
-                    if (deltaMomentum < bestDeltaMomentum)
+                    EVENT::TrackerHit* trackerHit = (*itTh);
+                    const EVENT::LCObjectVec &objectVec = navigate->getRelatedToObjects(trackerHit);
+                    
+                    // Get reconstructed momentum at dca
+                    const pandora::Helix helixFit(track->getPhi(), track->getD0(), track->getZ0(), track->getOmega(), track->getTanLambda(), magneticField);
+                    const float recoMomentum(helixFit.GetMomentum().GetMagnitude());
+                    
+                    // Use momentum magnitude to identify best mc particle
+                    float bestDeltaMomentum(std::numeric_limits<float>::max());
+                    
+                    for (EVENT::LCObjectVec::const_iterator itRel = objectVec.begin(), itRelEnd = objectVec.end(); itRel != itRelEnd; ++itRel)
                     {
-                        pBestMCParticle = pMCParticle;
-                        bestDeltaMomentum = deltaMomentum;
+                        EVENT::MCParticle *pMCParticle = NULL;
+                        pMCParticle = dynamic_cast<EVENT::MCParticle *>(*itRel);
+                        
+                        if (NULL == pMCParticle)
+                            continue;
+                        
+                        const float trueMomentum(pandora::CartesianVector(pMCParticle->getMomentum()[0], pMCParticle->getMomentum()[1],
+                                                                          pMCParticle->getMomentum()[2]).GetMagnitude());
+                        
+                        const float deltaMomentum(std::fabs(recoMomentum - trueMomentum));
+                        
+                        if (deltaMomentum < bestDeltaMomentum)
+                        {
+                            pBestMCParticle = pMCParticle;
+                            bestDeltaMomentum = deltaMomentum;
+                        }
                     }
                 }
+                
+                if (NULL == pBestMCParticle)
+                    continue;
+                
+                PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::SetTrackToMCParticleRelationship(pandora, track,
+                                                                                                              pBestMCParticle));
+            }                    
+            catch (StatusCodeException &statusCodeException)
+            {
+                std::cout << "Failed to extract track to mc particle relationship: " << statusCodeException.ToString() << std::endl;
+            }
+            catch (EVENT::Exception &exception)
+            {
+                std::cout << "Failed to extract track to mc particle relationship: " << exception.what() << std::endl;
             }
-
-            if (NULL == pBestMCParticle)
-                continue;
-
-            PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraApi::SetTrackToMCParticleRelationship(pandora, track,
-                                                                                                          pBestMCParticle));
-        
-        }
-        catch (StatusCodeException &statusCodeException)
-        {
-            std::cout << "Failed to extract track to mc particle relationship: " << statusCodeException.ToString() << std::endl;
-        }
-        catch (EVENT::Exception &exception)
-        {
-            std::cout << "Failed to extract track to mc particle relationship: " << exception.what() << std::endl;
         }
     }
+
+    // Delete LCRelationsNavigator if exists.
+    if (navigate != 0)
+        delete navigate;
 }
 
 void SimpleTrackProcessor::setupTrackStatesFromGenericObjects(PandoraApi::Track::Parameters& trackParameters, EVENT::LCEvent* event, int i)
 {       
+    // Get the Track state collections.
+    // FIXME: Hard-coded collection names.
     LCCollection* startCollection = event->getCollection("StateAtStart");
     LCCollection* ecalCollection = event->getCollection("StateAtECal");
     LCCollection* endCollection = event->getCollection("StateAtEnd");
@@ -228,54 +257,3 @@
                                                             endObj->getFloatVal(4), 
                                                             endObj->getFloatVal(5));
 }
-
-/**
- * LCRelations read from LCSim do NOT work.  Don't call this!  Left here for reference.
- * FIXME Can't read relations from LCSim into slicPandora.
- */
-void SimpleTrackProcessor::setupTrackStatesFromRelations(PandoraApi::Track::Parameters& trackParameters, EVENT::LCEvent* event)
-{    
-    // Make LCRelationNavigators for each of the three state collections.
-    LCRelationNavigator navStart((const_cast<const LCEvent*>(event))->getCollection(startCollectionName));
-    LCRelationNavigator navEcal((const_cast<const LCEvent*>(event))->getCollection(ecalCollectionName));
-    LCRelationNavigator navEnd((const_cast<const LCEvent*>(event))->getCollection(endCollectionName));
-
-    LCCollection* trackCollection = event->getCollection(trackCollectionName);
-    int ntracks = trackCollection->getNumberOfElements();
-    for (int i=0; i<ntracks; i++)
-    {
-        Track* track = dynamic_cast<Track*>(trackCollection->getElementAt(i));
-
-        // Add start state.
-        const LCObjectVec& startCollection = navStart.getRelatedToObjects(track);
-        LCGenericObject* startObj = dynamic_cast<LCGenericObject*>(startCollection.at(0));
-        trackParameters.m_trackStateAtStart = 
-            pandora::TrackState(startObj->getFloatVal(0), 
-                                startObj->getFloatVal(1), 
-                                startObj->getFloatVal(2), 
-                                startObj->getFloatVal(3), 
-                                startObj->getFloatVal(4), 
-                                startObj->getFloatVal(5));
-
-        // Add ECal state.
-        const LCObjectVec& ecalCollection = navEcal.getRelatedToObjects(track);
-        LCGenericObject* ecalObj = dynamic_cast<LCGenericObject*>(ecalCollection.at(0));
-        trackParameters.m_trackStateAtECal = 
-            pandora::TrackState(ecalObj->getFloatVal(0), 
-                                ecalObj->getFloatVal(1), 
-                                ecalObj->getFloatVal(2), 
-                                ecalObj->getFloatVal(3), 
-                                ecalObj->getFloatVal(4), 
-                                ecalObj->getFloatVal(5));
-        
-        // Add end state.
-        const LCObjectVec& endCollection = navEnd.getRelatedToObjects(track);
-        LCGenericObject* endObj = dynamic_cast<LCGenericObject*>(endCollection.at(0));
-        trackParameters.m_trackStateAtEnd = pandora::TrackState(endObj->getFloatVal(0), 
-                                                                 endObj->getFloatVal(1), 
-                                                                 endObj->getFloatVal(2), 
-                                                                 endObj->getFloatVal(3), 
-                                                                 endObj->getFloatVal(4), 
-                                                                 endObj->getFloatVal(5));
-    }       
-}
CVSspam 0.2.8