ParticleHistory.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file ParticleHistory.h
3 /// \brief A "chain" of particles associated with production of a Particle in a ParticleList.
4 ///
5 /// \version $Id: ParticleHistory.h,v 1.1 2010/04/29 15:38:01 seligman Exp $
6 /// \author seligman@nevis.columbia.edu
7 ////////////////////////////////////////////////////////////////////////
8 ///
9 
10 /// A container for a chain of particles in an event. It's a meant as
11 /// a convenience for looking at a sequence of particles within a
12 /// sim::ParticeList.
13 
14 /// Here's an example to illustrate the purpose and use of a
15 /// list. Assume a pi+ is a primary particle in an event whose decay
16 /// is modeled like this:
17 
18 /// TrackID Particle
19 /// 2 pi+
20 /// 101 nu_mu
21 /// 102 mu+
22 /// 341 nu_mu_bar
23 /// 342 nu_e
24 /// 343 e+
25 
26 /// I'm playing around with the ParticleList for the event, and I'm
27 /// interested in what produced track ID 343, which is an e+. I can
28 /// use the ParticleHistory class to quickly go through the production
29 /// chain:
30 
31 /// sim::ParticleList* particleList = // ... from somewhere
32 /// int trackID = 343;
33 /// const sim::ParticleHistory particleHistory( particleList, trackID );
34 /// for ( int i = 0; i != particleHistory.size(); ++i )
35 /// {
36 /// const simb::MCParticle* particle = particleHistory[i];
37 /// // ...
38 /// }
39 
40 /// In the above example:
41 /// particleHistory.size() == 3
42 /// particleHistory[0] points to the particle with track ID 2
43 /// particleHistory[1] points to the particle with track ID 102
44 /// particleHistory[2] points to the particle with track ID 343
45 
46 /// So as you go through a ParticleHistory "array," the first element
47 /// is a primary particle in the event, and the last element is the
48 /// particle you used to create the history.
49 
50 /// ParticleHistory looks like a vector< const simb::MCParticle* >, with the
51 /// following additions:
52 
53 /// - a ParticleList() method that returns a ParticleList* to the
54 /// object that's associated with the history.
55 
56 /// - an EndParticleID() method that returns the track ID of the last
57 /// particle in the chain; that is, it's the second argument in the
58 /// constructor.
59 
60 /// - operator<< method for ROOT display and ease of debugging.
61 
62 /// TECHNICAL NOTES:
63 
64 /// ParticleHistory behaves mostly like a vector, but it's actually a
65 /// deque. This means that you can't assume that &particleHistory[0]
66 /// is a continugous array of Particle*. If those two sentences mean
67 /// nothing to you, don't worry about it; this only matters to folks
68 /// familiar with STL.
69 
70 /// A given ParticleHistory object is associated with the ParticleList
71 /// used to create it. If you delete the ParticleList (by reading in a
72 /// new event, for example) then the contents of the corresponding
73 /// ParticleHistory object(s) are garbage.
74 
75 /// If you create a ParticleHistory object like this:
76 /// const sim::ParticleHistory ph(particleList,1123);
77 /// and there is no track 1123 in the particle list, then ph.size()==0.
78 
79 /// particleHistory[0] is not necessarily a primary particle in the
80 /// event. It's possible for a production chain to be broken due to
81 /// simulation cuts. The first element just represents as far back we
82 /// can go in the production chain given the ParticleList.
83 
84 
85 #ifndef SIM_PARTICLEHISTORY_H
86 #define SIM_PARTICLEHISTORY_H
87 
89 
90 #include <deque>
91 #include <iostream>
92 
93 namespace sim {
94 
95  // Forward declaration
96  class ParticleList;
97 
98  class ParticleHistory : public std::deque< const simb::MCParticle* >
99  {
100  public:
101 
102  // Constructor and destructor
103  ParticleHistory( const sim::ParticleList* list, const int trackID );
104  virtual ~ParticleHistory();
105 
106  // For which particle was this history generated?
107  int EndParticleID() const { return m_trackID; }
108 
109  // With which ParticleList is this history associated?
110  const sim::ParticleList* ParticleList() const { return m_particleList; }
111 
112  friend std::ostream& operator<< ( std::ostream& output, const ParticleHistory& );
113 
114  private:
115  const sim::ParticleList* m_particleList; ///> The ParticleList associated with this chain.
116  int m_trackID; ///> The particle for which a history was created.
117  };
118 
119 } // namespace sim
120 
121 #endif // SIM_PARTICLEHISTORY_H
const sim::ParticleList * m_particleList
int EndParticleID() const
Particle class.
int m_trackID
The ParticleList associated with this chain.
Monte Carlo Simulation.
ParticleHistory(const sim::ParticleList *list, const int trackID)
friend std::ostream & operator<<(std::ostream &output, const ParticleHistory &)
const sim::ParticleList * ParticleList() const