ParticleHistory.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \brief A "chain" of particles associated with production of
3 /// a Particle in a ParticleNavigator.
4 ///
5 /// \author seligman@nevis.columbia.edu
6 /// \date
7 ////////////////////////////////////////////////////////////////////////
9 
10 #include <cmath>
11 
13 
14 namespace sim
15 {
16  // Nothing special need be done for the constructor.
18  : m_particleNav(nav)
19  , m_trackID(trackID)
20  {
21  // Look for the track in the particle list.
23 
24  // While we're still finding particles in the chain...
25  while ( search != m_particleNav->end() )
26  {
27  const sim::Particle* particle = (*search).second;
28  push_front( particle );
29 
30  // If this is a primary particle, we're done.
31  int trackID = particle->TrackId();
32  if ( m_particleNav->IsPrimary( trackID ) ) break;
33 
34  // Now look for the parent of this particle.
35  int parentID = particle->Mother();
36  search = m_particleNav->find( parentID );
37 
38  } // while we're finding particles in the chain
39  }
40 
41  //......................................................................
43  {
44  }
45 
46  //......................................................................
47  void ParticleHistory::Print() const
48  {
49  std::cout << (*this);
50  }
51 
52  //......................................................................
53  std::ostream& operator<< ( std::ostream& output, const ParticleHistory& list )
54  {
55  // Determine a field width for the particle number.
56  ParticleHistory::size_type numberOfParticles = list.size();
57  int numberOfDigits = (int) std::log10( (double) numberOfParticles ) + 1;
58 
59  // A simple header.
60  output.width( numberOfDigits );
61  output << "#" << ": < ID, particle >" << std::endl;
62 
63  // Write each particle on a separate line.
64  ParticleHistory::size_type nParticle = 0;
65  for ( ParticleHistory::const_iterator particle = list.begin(); particle != list.end(); ++particle, ++nParticle ){
66  output.width( numberOfDigits );
67  output << nParticle << ": "
68  << *(*particle)
69  << std::endl;
70  }
71 
72  return output;
73  }
74 
75 } // end namespace sim
76 //////////////////////////////////////////////////////////////////////////////
ofstream output
int Mother() const
Definition: MCParticle.h:212
virtual void Print() const
list_type::const_iterator const_iterator
int TrackId() const
Definition: MCParticle.h:209
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Definition: typedefs.hpp:11
int m_trackID
The particle for which a history was created.
Example routine for calculating the "ultimate e-m mother" of a particle in a simulated event...
Definition: FillTruth.h:16
OStream cout
Definition: OStream.cxx:6
bool IsPrimary(int trackID) const
Int_t parentID
Definition: plot.C:85
T log10(T number)
Definition: d0nt_math.hpp:120
ParticleHistory(const sim::ParticleNavigator *nav, const int trackID)
const sim::ParticleNavigator * m_particleNav
The ParticleNavigator associated with this chain.
Int_t trackID
Definition: plot.C:84
friend std::ostream & operator<<(std::ostream &output, const ParticleHistory &)
iterator find(const key_type &key)