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