test
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  if(!flag)
93  return false;
94 
95  // verify if the new particle is not in the trail (looping partiles)
96  if (
97  std::find(
98  simParticleTrail_.begin(),
99  simParticleTrail_.end(),
100  *its
101  ) != simParticleTrail_.end()
102  )
103  {
104  LogDebug("TrackHistory") << "WARNING: Looping track found." << std::endl;
105  return false;
106  }
107 
108  // save particle in the trail
109  simParticleTrail_.push_back(*its);
110  return traceSimHistory (*its, --depth);
111  }
112  else if ( !trackingVertex->genVertices().empty() )
113  {
114  // navigate over all the associated generated vertexes
115  LogDebug("TrackHistory") << "Vertex has " << trackingVertex->genVertices().size() << "GenVertex image." << std::endl;
116  for (
117  TrackingVertex::genv_iterator ivertex = trackingVertex->genVertices_begin();
118  ivertex != trackingVertex->genVertices_end();
119  ++ivertex
120  )
121  traceGenHistory(&(**(ivertex)));
122  return true;
123  }
124  else
125  {
126  LogDebug("TrackHistory") << "WARNING: Source track for tracking vertex cannot be found." << std::endl;
127  }
128  }
129  else
130  {
131  LogDebug("TrackHistory") << " WARNING: Vertex cannot be found.";
132  }
133 
134  return false;
135 }
136 
#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