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  // second stop condition: if a gen particle is associated to the TP
45  if ( !trackingParticle->genParticles().empty() )
46  {
47  LogDebug("TrackHistory") << "Particle " << trackingParticle->pdgId() << " has a GenParicle image."
48  << std::endl;
49  //#warning "This file has been modified just to get it to compile without any regard as to whether it still functions as intended"
50  // this code does not compile likely due to the wrong type of iterator
51  #ifdef REMOVED_JUST_TO_GET_IT_TO_COMPILE__THIS_CODE_NEEDS_TO_BE_CHECKED
52  traceGenHistory(&(**(trackingParticle->genParticle_begin())));
53  #endif
54 
55  }
56 
57  LogDebug("TrackHistory") << "No GenParticle image for " << trackingParticle->pdgId() << std::endl;
58 
59  // get a reference to the TP's parent vertex and trace it history
60  return traceSimHistory( trackingParticle->parentVertex(), depth );
61 }
62 
63 
64 bool HistoryBase::traceSimHistory(TrackingVertexRef const & trackingVertex, int depth)
65 {
66  // verify if the parent vertex exists
67  if ( trackingVertex.isNonnull() )
68  {
69  // save the vertex in the trail
70  simVertexTrail_.push_back(trackingVertex);
71 
72  if ( !trackingVertex->sourceTracks().empty() )
73  {
74  LogDebug("TrackHistory") << "Moving on to the parent particle." << std::endl;
75 
76  // select the original source in case of combined vertices
77  bool flag = false;
79 
80  for (its = trackingVertex->sourceTracks_begin(); its != trackingVertex->sourceTracks_end(); its++)
81  {
82  for (itd = trackingVertex->daughterTracks_begin(); itd != trackingVertex->daughterTracks_end(); itd++)
83  if (itd != its)
84  {
85  flag = true;
86  break;
87  }
88  if (flag)
89  break;
90  }
91 
92  // verify if the new particle is not in the trail (looping partiles)
93  if (
94  std::find(
95  simParticleTrail_.begin(),
96  simParticleTrail_.end(),
97  *its
98  ) != simParticleTrail_.end()
99  )
100  {
101  LogDebug("TrackHistory") << "WARNING: Looping track found." << std::endl;
102  return false;
103  }
104 
105  // save particle in the trail
106  simParticleTrail_.push_back(*its);
107  return traceSimHistory (*its, --depth);
108  }
109  else if ( !trackingVertex->genVertices().empty() )
110  {
111  // navigate over all the associated generated vertexes
112  LogDebug("TrackHistory") << "Vertex has " << trackingVertex->genVertices().size() << "GenVertex image." << std::endl;
113  for (
114  TrackingVertex::genv_iterator ivertex = trackingVertex->genVertices_begin();
115  ivertex != trackingVertex->genVertices_end();
116  ++ivertex
117  )
118  traceGenHistory(&(**(ivertex)));
119  return true;
120  }
121  else
122  {
123  LogDebug("TrackHistory") << "WARNING: Source track for tracking vertex cannot be found." << std::endl;
124  }
125  }
126  else
127  {
128  LogDebug("TrackHistory") << " WARNING: Vertex cannot be found.";
129  }
130 
131  return false;
132 }
133 
#define LogDebug(id)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
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
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
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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