CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/SimTracker/TrackHistory/src/HistoryBase.cc

Go to the documentation of this file.
00001 #include <algorithm>
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "SimTracker/TrackHistory/interface/HistoryBase.h"
00006 
00007 
00008 void HistoryBase::traceGenHistory(HepMC::GenParticle const * genParticle)
00009 {
00010     // Third stop criteria: status abs(depth_) particles after the hadronization.
00011     // The after hadronization is done by detecting the pdg_id pythia code from 88 to 99
00012     if ( genParticle->status() <= abs(depth_) && (genParticle->pdg_id() < 88 || genParticle->pdg_id() > 99) )
00013     {
00014         genParticleTrail_.push_back(genParticle);
00015         // Get the producer vertex and trace it history
00016         traceGenHistory( genParticle->production_vertex() );
00017     }
00018 }
00019 
00020 
00021 void HistoryBase::traceGenHistory(HepMC::GenVertex const * genVertex)
00022 {
00023     // Verify if has a vertex associated
00024     if (genVertex)
00025     {
00026         // Skip if already exist in the collection
00027         if ( genVertexTrailHelper_.find(genVertex) != genVertexTrailHelper_.end() )
00028             return;
00029         // Add vertex to the history
00030         genVertexTrail_.push_back(genVertex);
00031         genVertexTrailHelper_.insert(genVertex);
00032         // Verify if the vertex has incoming particles
00033         if ( genVertex->particles_in_size() )
00034             traceGenHistory( *(genVertex->particles_in_const_begin()) );
00035     }
00036 }
00037 
00038 
00039 bool HistoryBase::traceSimHistory(TrackingParticleRef const & trackingParticle, int depth)
00040 {
00041     // first stop condition: if the required depth is reached
00042     if ( depth == depth_ && depth_ >= 0 ) return true;
00043 
00044     // sencond stop condition: if a gen particle is associated to the TP
00045     if ( !trackingParticle->genParticle().empty() )
00046     {
00047         LogDebug("TrackHistory") << "Particle " << trackingParticle->pdgId() << " has a GenParicle image." << std::endl;
00048         traceGenHistory(&(**(trackingParticle->genParticle_begin())));
00049         return true;
00050     }
00051 
00052     LogDebug("TrackHistory") << "No GenParticle image for " << trackingParticle->pdgId() << std::endl;
00053 
00054     // get a reference to the TP's parent vertex and trace it history
00055     return traceSimHistory( trackingParticle->parentVertex(), depth );
00056 }
00057 
00058 
00059 bool HistoryBase::traceSimHistory(TrackingVertexRef const & trackingVertex, int depth)
00060 {
00061     // verify if the parent vertex exists
00062     if ( trackingVertex.isNonnull() )
00063     {
00064         // save the vertex in the trail
00065         simVertexTrail_.push_back(trackingVertex);
00066 
00067         if ( !trackingVertex->sourceTracks().empty() )
00068         {
00069             LogDebug("TrackHistory") << "Moving on to the parent particle." << std::endl;
00070 
00071             // select the original source in case of combined vertices
00072             bool flag = false;
00073             TrackingVertex::tp_iterator itd, its;
00074 
00075             for (its = trackingVertex->sourceTracks_begin(); its != trackingVertex->sourceTracks_end(); its++)
00076             {
00077                 for (itd = trackingVertex->daughterTracks_begin(); itd != trackingVertex->daughterTracks_end(); itd++)
00078                     if (itd != its)
00079                     {
00080                         flag = true;
00081                         break;
00082                     }
00083                 if (flag)
00084                     break;
00085             }
00086 
00087             // verify if the new particle is not in the trail (looping partiles)
00088             if (
00089                 std::find(
00090                     simParticleTrail_.begin(),
00091                     simParticleTrail_.end(),
00092                     *its
00093                 ) != simParticleTrail_.end()
00094             )
00095             {
00096                 LogDebug("TrackHistory") <<  "WARNING: Looping track found." << std::endl;
00097                 return false;
00098             }
00099 
00100             // save particle in the trail
00101             simParticleTrail_.push_back(*its);
00102             return traceSimHistory (*its, --depth);
00103         }
00104         else if ( !trackingVertex->genVertices().empty() )
00105         {
00106             // navigate over all the associated generated vertexes
00107             LogDebug("TrackHistory") << "Vertex has " << trackingVertex->genVertices().size() << "GenVertex image." << std::endl;
00108             for (
00109                 TrackingVertex::genv_iterator ivertex = trackingVertex->genVertices_begin();
00110                 ivertex != trackingVertex->genVertices_end();
00111                 ++ivertex
00112             )
00113                 traceGenHistory(&(**(ivertex)));
00114             return true;
00115         }
00116         else
00117         {
00118             LogDebug("TrackHistory") <<  "WARNING: Source track for tracking vertex cannot be found." << std::endl;
00119         }
00120     }
00121     else
00122     {
00123         LogDebug("TrackHistory") << " WARNING: Vertex cannot be found.";
00124     }
00125 
00126     return false;
00127 }
00128