LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
ParticleHistory.cxx
Go to the documentation of this file.
1 
11 
12 #include <cmath>
13 
14 namespace sim {
15 
16  //----------------------------------------------------------------------------
17  // Nothing special need be done for the constructor.
18  ParticleHistory::ParticleHistory( const sim::ParticleList* list, const int trackID )
19  : m_particleList(list)
20  , m_trackID(trackID)
21  {
22  // Look for the track in the particle list.
24 
25  // While we're still finding particles in the chain...
26  while ( search != m_particleList->end() ){
27  const simb::MCParticle* 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_particleList->IsPrimary( trackID ) ) break;
33 
34  // Now look for the parent of this particle.
35  int parentID = particle->Mother();
36  search = m_particleList->find( parentID );
37 
38  } // while we're finding particles in the chain
39  }
40 
41  //----------------------------------------------------------------------------
42  // Nothing special for the destructor.
44  {}
45 
46  //----------------------------------------------------------------------------
47  std::ostream& operator<< ( std::ostream& output, const ParticleHistory& list )
48  {
49  // Determine a field width for the particle number.
50  ParticleHistory::size_type numberOfParticles = list.size();
51  int numberOfDigits = (int) std::log10( (double) numberOfParticles ) + 1;
52 
53  // A simple header.
54  output.width( numberOfDigits );
55  output << "#" << ": < ID, particle >" << "\n";
56 
57  // Write each particle on a separate line.
58  ParticleHistory::size_type nParticle = 0;
59  for ( ParticleHistory::const_iterator particle = list.begin();
60  particle != list.end(); ++particle, ++nParticle ){
61  output.width( numberOfDigits );
62  output << nParticle << ": "
63  << (*particle)
64  << "\n";
65  }
66 
67  return output;
68  }
69 
70 } // namespace sim
const sim::ParticleList * m_particleList
int Mother() const
Definition: MCParticle.h:217
list_type::const_iterator const_iterator
Definition: ParticleList.h:132
int TrackId() const
Definition: MCParticle.h:214
iterator find(const key_type &key)
Definition: ParticleList.h:318
int m_trackID
The ParticleList associated with this chain.
intermediate_table::const_iterator const_iterator
bool IsPrimary(int trackID) const
Monte Carlo Simulation.
ParticleHistory(const sim::ParticleList *list, const int trackID)
A "chain" of particles associated with production of a Particle in a ParticleList.
Particle list in DetSim contains Monte Carlo particle information.
friend std::ostream & operator<<(std::ostream &output, const ParticleHistory &)