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