CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HistoryBase.cc
Go to the documentation of this file.
1 #include <algorithm>
2 
4 
6 
7 
9 {
10  // Third stop criteria: status abs(depth_) particles after the hadronization.
11  // The after hadronization is done by detecting the pdg_id pythia code from 88 to 99
12  if ( genParticle->status() <= abs(depth_) && (genParticle->pdg_id() < 88 || genParticle->pdg_id() > 99) )
13  {
14  genParticleTrail_.push_back(genParticle);
15  // Get the producer vertex and trace it history
16  traceGenHistory( genParticle->production_vertex() );
17  }
18 }
19 
20 
21 void HistoryBase::traceGenHistory(HepMC::GenVertex const * genVertex)
22 {
23  // Verify if has a vertex associated
24  if (genVertex)
25  {
26  // Skip if already exist in the collection
27  if ( genVertexTrailHelper_.find(genVertex) != genVertexTrailHelper_.end() )
28  return;
29  // Add vertex to the history
30  genVertexTrail_.push_back(genVertex);
31  genVertexTrailHelper_.insert(genVertex);
32  // Verify if the vertex has incoming particles
33  if ( genVertex->particles_in_size() )
34  traceGenHistory( *(genVertex->particles_in_const_begin()) );
35  }
36 }
37 
38 
39 bool HistoryBase::traceSimHistory(TrackingParticleRef const & trackingParticle, int depth)
40 {
41  // first stop condition: if the required depth is reached
42  if ( depth == depth_ && depth_ >= 0 ) return true;
43 
44  // sencond stop condition: if a gen particle is associated to the TP
45  if ( !trackingParticle->genParticle().empty() )
46  {
47  LogDebug("TrackHistory") << "Particle " << trackingParticle->pdgId() << " has a GenParicle image." << std::endl;
48  traceGenHistory(&(**(trackingParticle->genParticle_begin())));
49  return true;
50  }
51 
52  LogDebug("TrackHistory") << "No GenParticle image for " << trackingParticle->pdgId() << std::endl;
53 
54  // get a reference to the TP's parent vertex and trace it history
55  return traceSimHistory( trackingParticle->parentVertex(), depth );
56 }
57 
58 
59 bool HistoryBase::traceSimHistory(TrackingVertexRef const & trackingVertex, int depth)
60 {
61  // verify if the parent vertex exists
62  if ( trackingVertex.isNonnull() )
63  {
64  // save the vertex in the trail
65  simVertexTrail_.push_back(trackingVertex);
66 
67  if ( !trackingVertex->sourceTracks().empty() )
68  {
69  LogDebug("TrackHistory") << "Moving on to the parent particle." << std::endl;
70 
71  // select the original source in case of combined vertices
72  bool flag = false;
74 
75  for (its = trackingVertex->sourceTracks_begin(); its != trackingVertex->sourceTracks_end(); its++)
76  {
77  for (itd = trackingVertex->daughterTracks_begin(); itd != trackingVertex->daughterTracks_end(); itd++)
78  if (itd != its)
79  {
80  flag = true;
81  break;
82  }
83  if (flag)
84  break;
85  }
86 
87  // verify if the new particle is not in the trail (looping partiles)
88  if (
89  std::find(
90  simParticleTrail_.begin(),
91  simParticleTrail_.end(),
92  *its
93  ) != simParticleTrail_.end()
94  )
95  {
96  LogDebug("TrackHistory") << "WARNING: Looping track found." << std::endl;
97  return false;
98  }
99 
100  // save particle in the trail
101  simParticleTrail_.push_back(*its);
102  return traceSimHistory (*its, --depth);
103  }
104  else if ( !trackingVertex->genVertices().empty() )
105  {
106  // navigate over all the associated generated vertexes
107  LogDebug("TrackHistory") << "Vertex has " << trackingVertex->genVertices().size() << "GenVertex image." << std::endl;
108  for (
109  TrackingVertex::genv_iterator ivertex = trackingVertex->genVertices_begin();
110  ivertex != trackingVertex->genVertices_end();
111  ++ivertex
112  )
113  traceGenHistory(&(**(ivertex)));
114  return true;
115  }
116  else
117  {
118  LogDebug("TrackHistory") << "WARNING: Source track for tracking vertex cannot be found." << std::endl;
119  }
120  }
121  else
122  {
123  LogDebug("TrackHistory") << " WARNING: Vertex cannot be found.";
124  }
125 
126  return false;
127 }
128 
#define LogDebug(id)
long int flag
Definition: mlp_lapack.h:47
#define abs(x)
Definition: mlp_lapack.h:159
SimVertexTrail simVertexTrail_
Definition: HistoryBase.h:100
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:248
GenVertexTrail genVertexTrail_
Definition: HistoryBase.h:98
void traceGenHistory(HepMC::GenParticle const *)
Trace all the simulated information for a given pointer to a GenParticle.
Definition: HistoryBase.cc:8
GenVertexTrailHelper genVertexTrailHelper_
Definition: HistoryBase.h:104
SimParticleTrail simParticleTrail_
Definition: HistoryBase.h:101
void depth(int d)
Set the depth of the history.
Definition: HistoryBase.h:47
bool traceSimHistory(TrackingParticleRef const &, int)
Trace all the simulated information for a given reference to a TrackingParticle.
Definition: HistoryBase.cc:39
GenParticleTrail genParticleTrail_
Definition: HistoryBase.h:99