EveIdCalculator.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \brief Interface for calculating the "ultimate mother" of a particle in a simulated event.
3 ///
4 /// \author seligman@nevis.columbia.edu
5 /// \date
6 ////////////////////////////////////////////////////////////////////////
8 
11 
12 #include "cetlib_except/exception.h"
13 
14 namespace sim {
15 
16  // Constructor. Keep this empty, since users who override with their
17  // class may forget to call this constructor.
19  {}
20 
21  // Destructor.
23  {}
24 
25 
26  // Initialization.
28  {
29  // Save the ParticleNavigator associated with this simulated chain of
30  // particles.
31  m_particleNav = nav;
32 
33  // Reset the results of previous calculations.
34  m_previousNav.clear();
35  }
36 
37 
39  {
40  // Look to see if the eve ID has been previously calculated for
41  // this track.
42  m_previousNav_ptr search = m_previousNav.find( trackID );
43  if ( search == m_previousNav.end() ){
44  // It hasn't been calculated before. Do the full eve ID
45  // calculation.
46  int eveID = DoCalculateEveId( trackID );
47 
48  // Save the result of the calculation.
49  m_previousNav[ trackID ] = eveID;
50 
51  return eveID;
52  }
53 
54  // If we get here, we've calculated the eve ID for this track
55  // before. Return that result.
56  return (*search).second;
57  }
58 
59 
61  {
62  // This is the default eve ID calculation method. It gets called
63  // if the user doesn't override it with their own method.
64 
65  // Almost any eve ID calculation will use this: Get the entire
66  // history of the particle and its ancestors in the simulated
67  // event.
68  sim::ParticleHistory particleHistory( m_particleNav, trackID );
69 
70  if ( particleHistory.empty() ){
71  // Something went wrong; most likely the track ID isn't
72  // present in the event.
73  throw cet::exception("EveIdCalculator")
74  << "particle history for track id: " << trackID
75  << " is empty, that can't be good\n"
76  << __FILE__ << ":" << __LINE__ << "\n";
77  }
78 
79  // Return the primary particle from the event generator associated
80  // with this track ID.
81  const Particle* particle = particleHistory[0];
82  return particle->TrackId();
83  }
84 
85 }
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
virtual int DoCalculateEveId(const int trackID)
const sim::ParticleNavigator * m_particleNav
The ParticleNavigator associated with the eve ID calculation.
int TrackId() const
Definition: MCParticle.h:209
m_previousNav_t::const_iterator m_previousNav_ptr
int CalculateEveId(const int trackID)
void Init(const sim::ParticleNavigator *list)
Initialize this calculator for a particular ParticleNavigator.
m_previousNav_t m_previousNav
The results of previous eve ID calculations for the current ParticleNavigator.
Example routine for calculating the "ultimate e-m mother" of a particle in a simulated event...
Definition: FillTruth.h:16
EveIdCalculator()
Constructor and destructor.
Int_t trackID
Definition: plot.C:84