All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCTruthEveIdCalculator.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 ///
3 /// ********************************************************************
4 /// *** This class has been lifted from nutools and modified so that it
5 /// *** does NOT take ownwership of the MCParticles that are added to it
6 /// *** so we can avoid duplicating them
7 /// ********************************************************************
8 ///
9 /// \file MCTruthEveIdCalculator.cxx
10 /// \brief Interface for calculating the "ultimate mother" of a particle in a simulated event.
11 ///
12 /// \version $Id: MCTruthEveIdCalculator.cxx,v 1.1 2010/05/13 16:12:20 seligman Exp $
13 /// \author seligman@nevis.columbia.edu
14 ////////////////////////////////////////////////////////////////////////
15 
19 #include "nusimdata/SimulationBase/MCParticle.h"
20 
21 namespace truth {
22 
23  //----------------------------------------------------------------------------
24  // Constructor. Keep this empty, since users who override with their
25  // class may forget to call this constructor.
27  {
28  }
29 
30  //----------------------------------------------------------------------------
31  // Destructor.
33  {
34  }
35 
36  //----------------------------------------------------------------------------
37  // Initialization.
39  {
40  // Save the ParticleList associated with this simulated chain of
41  // particles.
43 
44  // Reset the results of previous calculations.
45  m_previousList.clear();
46  }
47 
48  //----------------------------------------------------------------------------
49  int MCTruthEveIdCalculator::CalculateEveId( const int trackID )
50  {
51  // Look to see if the eve ID has been previously calculated for
52  // this track.
53  m_previousList_ptr search = m_previousList.find( trackID );
54  if ( search == m_previousList.end() ){
55  // It hasn't been calculated before. Do the full eve ID
56  // calculation.
57  int eveID = DoCalculateEveId( trackID );
58 
59  // Save the result of the calculation.
60  m_previousList[ trackID ] = eveID;
61 
62  return eveID;
63  }
64 
65  // If we get here, we've calculated the eve ID for this track
66  // before. Return that result.
67  return (*search).second;
68  }
69 
70  //----------------------------------------------------------------------------
72  {
73  // This is the default eve ID calculation method. It gets called
74  // if the user doesn't override it with their own method.
75 
76  // Almost any eve ID calculation will use this: Get the entire
77  // history of the particle and its ancestors in the simulated
78  // event.
79  MCTruthParticleHistory particleHistory( m_particleList, trackID );
80 
81  if ( particleHistory.empty() ){
82  // Something went wrong; most likely the track ID isn't
83  // present in the event.
84  return 0;
85  }
86 
87  // Return the primary particle from the event generator associated
88  // with this track ID.
89  const simb::MCParticle* particle = particleHistory[0];
90  return particle->TrackId();
91  }
92 
93 }
Particle list in DetSim contains Monte Carlo particle information.
virtual int DoCalculateEveId(const int trackID)
MCTruthEveIdCalculator()
Constructor and destructor.
Interface for calculating the "ultimate mother" of a particle in a simulated event.
void Init(const MCTruthParticleList *list)
Initialize this calculator for a particular ParticleList.
A "chain" of particles associated with production of a Particle in a ParticleList.
m_previousList_t::const_iterator m_previousList_ptr
const MCTruthParticleList * m_particleList
list
Definition: file_to_url.sh:28