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
00011
00012 if ( genParticle->status() <= abs(depth_) && (genParticle->pdg_id() < 88 || genParticle->pdg_id() > 99) )
00013 {
00014 genParticleTrail_.push_back(genParticle);
00015
00016 traceGenHistory( genParticle->production_vertex() );
00017 }
00018 }
00019
00020
00021 void HistoryBase::traceGenHistory(HepMC::GenVertex const * genVertex)
00022 {
00023
00024 if (genVertex)
00025 {
00026
00027 if ( genVertexTrailHelper_.find(genVertex) != genVertexTrailHelper_.end() )
00028 return;
00029
00030 genVertexTrail_.push_back(genVertex);
00031 genVertexTrailHelper_.insert(genVertex);
00032
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
00042 if ( depth == depth_ && depth_ >= 0 ) return true;
00043
00044
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
00055 return traceSimHistory( trackingParticle->parentVertex(), depth );
00056 }
00057
00058
00059 bool HistoryBase::traceSimHistory(TrackingVertexRef const & trackingVertex, int depth)
00060 {
00061
00062 if ( trackingVertex.isNonnull() )
00063 {
00064
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
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
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
00101 simParticleTrail_.push_back(*its);
00102 return traceSimHistory (*its, --depth);
00103 }
00104 else if ( !trackingVertex->genVertices().empty() )
00105 {
00106
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