All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCTruthEmEveIdCalculator.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 MCTruthEmEveIdCalculator.cxx
10 /// \brief Example routine for calculating the "ultimate e-m mother" of a particle in a simulated event.
11 ///
12 /// \version $Id: MCTruthEmEveIdCalculator.cxx,v 1.1 2010/05/13 16:12:20 seligman Exp $
13 /// \author seligman@nevis.columbia.edu
14 ////////////////////////////////////////////////////////////////////////
15 
19 
20 #include <TString.h>
21 
22 namespace truth {
23 
24  //----------------------------------------------------------------------------
25  // This particular class attempts to find the "ultimate mother" for
26  // electromagnetic showers. It goes up the chain of particles in an
27  // event, until it encounters a particle that is either primary or
28  // was not produced by a "trivial" e-m process.
30  {
31  // Almost any eve ID calculation will use this: Get the entire
32  // history of the particle and its ancestors in the simulated
33  // event. (m_particleList is defined in EveIdCalculator.h)
34  const MCTruthParticleHistory particleHistory( m_particleList, trackID );
35 
36  // You can treat particleHistory like an array, and do something
37  // like:
38 
39  // for ( int i = particleHistory.size(); i >= 0; --i )
40  // { const simb::MCParticle* particle = particleHistory[i]; ... }
41 
42  // But we know how to use the Standard Template Library (Yes, you
43  // do! Don't doubt yourself!) so let's treat particleHistory in
44  // the most efficient manner, as an STL container. We want to scan
45  // the container from its last element to its first, from the base
46  // of the particle production chain towards the primary particle.
47 
48  for(auto i = particleHistory.rbegin(); i != particleHistory.rend(); ++i){
49  // Get the text string that describes the process that created
50  // the particle.
51  std::string process = (*i)->Process();
52 
53  // Skip it if it was created by pair production, compton
54  // scattering, photoelectric effect, bremstrahlung,
55  // annihilation, or any ionization. (The ultimate source of
56  // the process names are the physics lists used in Geant4.)
57 
58  if ( process.find("conv") != std::string::npos ||
59  process.find("LowEnConversion") != std::string::npos ||
60  process.find("Pair") != std::string::npos ||
61  process.find("compt") != std::string::npos ||
62  process.find("Compt") != std::string::npos ||
63  process.find("Brem") != std::string::npos ||
64  process.find("phot") != std::string::npos ||
65  process.find("Photo") != std::string::npos ||
66  process.find("Ion") != std::string::npos ||
67  process.find("annihil") != std::string::npos) continue;
68 
69  // If we get here, the particle wasn't created by any of the
70  // above processes. Return its ID.
71  return (*i)->TrackId();
72  }
73 
74  // If we get here, we've skipped every particle in the
75  // chain. Perhaps it was empty.
76  return 0;
77  }
78 
79 } // namespace sim
Particle list in DetSim contains Monte Carlo particle information.
A &quot;chain&quot; of particles associated with production of a Particle in a ParticleList.
Example routine for calculating the &quot;ultimate e-m mother&quot; of a particle in a simulated event...
virtual int DoCalculateEveId(const int trackID)
const MCTruthParticleList * m_particleList