LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
EveIdCalculator.cxx
Go to the documentation of this file.
1 
13 
14 namespace sim {
15 
16  //----------------------------------------------------------------------------
17  // Constructor. Keep this empty, since users who override with their
18  // class may forget to call this constructor.
20  {
21  }
22 
23  //----------------------------------------------------------------------------
24  // Destructor.
26  {
27  }
28 
29  //----------------------------------------------------------------------------
30  // Initialization.
32  {
33  // Save the ParticleList associated with this simulated chain of
34  // particles.
35  m_particleList = list;
36 
37  // Reset the results of previous calculations.
38  m_previousList.clear();
39  }
40 
41  //----------------------------------------------------------------------------
42  int EveIdCalculator::CalculateEveId( const int trackID )
43  {
44  // Look to see if the eve ID has been previously calculated for
45  // this track.
46  m_previousList_ptr search = m_previousList.find( trackID );
47  if ( search == m_previousList.end() ){
48  // It hasn't been calculated before. Do the full eve ID
49  // calculation.
50  int eveID = DoCalculateEveId( trackID );
51 
52  // Save the result of the calculation.
53  m_previousList[ trackID ] = eveID;
54 
55  return eveID;
56  }
57 
58  // If we get here, we've calculated the eve ID for this track
59  // before. Return that result.
60  return (*search).second;
61  }
62 
63  //----------------------------------------------------------------------------
64  int EveIdCalculator::DoCalculateEveId( const int trackID )
65  {
66  // This is the default eve ID calculation method. It gets called
67  // if the user doesn't override it with their own method.
68 
69  // Almost any eve ID calculation will use this: Get the entire
70  // history of the particle and its ancestors in the simulated
71  // event.
72  ParticleHistory particleHistory( m_particleList, trackID );
73 
74  if ( particleHistory.empty() ){
75  // Something went wrong; most likely the track ID isn't
76  // present in the event.
77  return 0;
78  }
79 
80  // Return the primary particle from the event generator associated
81  // with this track ID.
82  const simb::MCParticle* particle = particleHistory[0];
83  return particle->TrackId();
84  }
85 
86 }
const sim::ParticleList * m_particleList
m_previousList_t::const_iterator m_previousList_ptr
virtual int DoCalculateEveId(const int trackID)
Particle class.
m_previousList_t m_previousList
int TrackId() const
Definition: MCParticle.h:211
int CalculateEveId(const int trackID)
Monte Carlo Simulation.
Interface for calculating the "ultimate mother" of a particle in a simulated event.
void Init(const sim::ParticleList *list)
Initialize this calculator for a particular ParticleList.
EveIdCalculator()
Constructor and destructor.
A "chain" of particles associated with production of a Particle in a ParticleList.
Particle list in DetSim contains Monte Carlo particle information.