MCTrajectory.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file MCTrajectory.h
3 /// \version $Id: MCTrajectory.h,v 1.6 2012-11-01 19:18:11 brebel Exp $
4 /// \brief Trajectory class
5 ///
6 /// \author seligman@nevis.columbia.edu
7 ////////////////////////////////////////////////////////////////////////
8 
9 /// This class describes the trajectory of a particle created in the
10 /// Monte Carlo simulation. It generally behaves like a
11 /// vector< pair<TLorentzVector,TLorentzVector> >, where the first
12 /// TLorentzVector is the position and the seoond is the momentum,
13 /// with the following additions:
14 
15 /// - Methods Position(int) and Momentum(int) for those who are unfamiliar with the
16 /// concept of "first" and "second" as used with STL pairs:
17 /// sim::Trajectory* trajectory = simb::MCParticle.Trajectory();
18 /// int numberOfPonts = trajectory->size();
19 /// for (int i=0; i<numberOfPoints; ++i)
20 /// {
21 /// TLorentzVector position = trajectory->Position(i);
22 /// TLorentzVector momentum = trajectory->Momentum(i);
23 /// }
24 /// The STL equivalent to the above statements (more efficient):
25 /// sim::Trajectory* trajectory = simb::MCParticle.Trajectory();
26 /// for ( sim::Trajectory::const_iterator i = trajectory->begin();
27 /// i != trajectory->end(); ++i )
28 /// {
29 /// const TLorentzVector& position = (*i).first;
30 /// const TLorentzVector& momentum = (*i).second;
31 /// }
32 
33 /// - As above, but for each position or momentum component; e.g.,
34 /// trajectory->X(i).
35 
36 /// - In addition to push_back(pair< TLorentzVector, TLorentzVector>),
37 /// there's also push_back(TLorentzVector,TLorentzVector) and
38 /// Add(TLorentzVector,TLorentzVector). They all do the same thing:
39 /// add another point to the trajectory.
40 
41 /// - Print() and operator<< methods for ROOT display and ease of
42 /// debugging.
43 
44 /// There are no units defined in this class. If it's used with
45 /// Geant4, the units will be (mm,ns,GeV), but this class does not
46 /// enforce this.
47 
48 #ifndef SIMB_MCTRAJECTORY_H
49 #define SIMB_MCTRAJECTORY_H
50 
51 #include <vector>
52 #include <iostream>
53 
54 #include <TLorentzVector.h>
55 
56 namespace simb {
57 
58  class MCTrajectory {
59  public:
60  /// Some type definitions to make life easier, and to help "hide"
61  /// the implementation details. (If you're not familiar with STL,
62  /// you can ignore these definitions.)
63  typedef std::vector< std::pair<TLorentzVector, TLorentzVector> > list_type;
64  typedef list_type::value_type value_type;
67  typedef list_type::reverse_iterator reverse_iterator;
68  typedef list_type::const_reverse_iterator const_reverse_iterator;
69  typedef list_type::size_type size_type;
70  typedef list_type::difference_type difference_type;
71  typedef std::vector< std::pair<size_t, unsigned char> > ProcessMap;
72  /// Standard constructor: Start with initial position and momentum
73  /// of the particle.
74  MCTrajectory();
75 
76  private:
77  list_type ftrajectory; ///< The list of trajectory points
78  ProcessMap fTrajectoryProcess; ///< map of the scattering process to index
79  ///< in ftrajectory for a given point
80 
81  public:
82 
83  MCTrajectory( const TLorentzVector& vertex,
84  const TLorentzVector& momentum );
85 
86  /// The accessor methods described above.
87  const TLorentzVector& Position( const size_type ) const;
88  const TLorentzVector& Momentum( const size_type ) const;
89  double X( const size_type i ) const;
90  double Y( const size_type i ) const;
91  double Z( const size_type i ) const;
92  double T( const size_type i ) const;
93  double Px( const size_type i ) const;
94  double Py( const size_type i ) const;
95  double Pz( const size_type i ) const;
96  double E( const size_type i ) const;
97 
98  double TotalLength() const;
99 
100  friend std::ostream& operator<< ( std::ostream& output, const MCTrajectory& );
101 
102  /// Standard STL methods, to make this class look like an STL map.
103  /// Again, if you don't know STL, you can just ignore these
104  /// methods.
105  iterator begin();
106  const_iterator begin() const;
107  iterator end();
108  const_iterator end() const;
109  reverse_iterator rbegin();
110  const_reverse_iterator rbegin() const;
111  reverse_iterator rend();
112  const_reverse_iterator rend() const;
113 
114  size_type size() const;
115  bool empty() const;
117  void clear();
118 
119  // Note that there's no non-const version of operator[] or at() here; once
120  // you've added a point to a trajectory, you can't modify it.
121  const value_type& operator[](const size_type i) const;
122  const value_type& at(const size_type i) const;
123 
124  /// The only "set" methods for this class; once you've added a
125  /// trajectory point, you can't take it back.
126  void push_back(value_type const& v );
127  void push_back(TLorentzVector const& p,
128  TLorentzVector const& m );
129  void Add(TLorentzVector const& p,
130  TLorentzVector const& m );
131  void Add(TLorentzVector const& p,
132  TLorentzVector const& m,
133  std::string const& process,
134  bool keepTransportation = false);
135 
136  unsigned char ProcessToKey(std::string const& process) const;
137  std::string KeyToProcess(unsigned char const& key) const;
138  ProcessMap const& TrajectoryProcesses() const;
139 
140  /// Remove points from trajectory. Straight line interpolation between the
141  /// remaining points will pass no further than \a margin from removed
142  /// points.
143  void Sparsify(double margin = .1, bool keep_second_to_last = false);
144 
145  };
146 
147 } // namespace simb
148 
149 inline double simb::MCTrajectory::X ( const size_type i ) const { return Position(i).X(); }
150 inline double simb::MCTrajectory::Y ( const size_type i ) const { return Position(i).Y(); }
151 inline double simb::MCTrajectory::Z ( const size_type i ) const { return Position(i).Z(); }
152 inline double simb::MCTrajectory::T ( const size_type i ) const { return Position(i).T(); }
153 inline double simb::MCTrajectory::Px( const size_type i ) const { return Momentum(i).Px(); }
154 inline double simb::MCTrajectory::Py( const size_type i ) const { return Momentum(i).Py(); }
155 inline double simb::MCTrajectory::Pz( const size_type i ) const { return Momentum(i).Pz(); }
156 inline double simb::MCTrajectory::E ( const size_type i ) const { return Momentum(i).E(); }
157 
167 inline bool simb::MCTrajectory::empty() const { return ftrajectory.empty(); }
168 inline void simb::MCTrajectory::clear() { ftrajectory.clear(); }
170  { ftrajectory.swap( other.ftrajectory ); }
171 
173  { return ftrajectory[i]; }
174 
176  { return ftrajectory.at(i); }
177 
179  { ftrajectory.push_back(v); }
180 
181 inline void simb::MCTrajectory::push_back(const TLorentzVector& p,
182  const TLorentzVector& m )
183  { ftrajectory.push_back( simb::MCTrajectory::value_type(p,m) ); }
184 
185 inline void simb::MCTrajectory::Add(const TLorentzVector& p,
186  const TLorentzVector& m ) { push_back(p,m); }
187 
189 
190 #endif // SIMB_MCTRAJECTORY_H
intermediate_table::iterator iterator
void Add(TLorentzVector const &p, TLorentzVector const &m)
double Z(const size_type i) const
Definition: MCTrajectory.h:151
double X(const size_type i) const
Definition: MCTrajectory.h:149
void push_back(value_type const &v)
double E(const size_type i) const
Definition: MCTrajectory.h:156
reverse_iterator rbegin()
Definition: MCTrajectory.h:162
std::string string
Definition: nybbler.cc:12
double Pz(const size_type i) const
Definition: MCTrajectory.h:155
const value_type & at(const size_type i) const
Definition: MCTrajectory.h:175
std::string KeyToProcess(unsigned char const &key) const
intermediate_table::const_iterator const_iterator
std::vector< std::pair< TLorentzVector, TLorentzVector > > list_type
Definition: MCTrajectory.h:63
unsigned char ProcessToKey(std::string const &process) const
list_type::value_type value_type
Definition: MCTrajectory.h:64
bool empty() const
Definition: MCTrajectory.h:167
list_type::size_type size_type
Definition: MCTrajectory.h:69
def process(f, kind)
Definition: search.py:254
list_type::difference_type difference_type
Definition: MCTrajectory.h:70
double Y(const size_type i) const
Definition: MCTrajectory.h:150
def key(type, name=None)
Definition: graph.py:13
list_type::const_iterator const_iterator
Definition: MCTrajectory.h:66
ProcessMap fTrajectoryProcess
Definition: MCTrajectory.h:78
p
Definition: test.py:223
list_type::iterator iterator
Definition: MCTrajectory.h:65
const TLorentzVector & Position(const size_type) const
The accessor methods described above.
ProcessMap const & TrajectoryProcesses() const
Definition: MCTrajectory.h:188
Base utilities and modules for event generation and detector simulation.
reverse_iterator rend()
Definition: MCTrajectory.h:164
list_type::reverse_iterator reverse_iterator
Definition: MCTrajectory.h:67
std::vector< std::pair< size_t, unsigned char > > ProcessMap
Definition: MCTrajectory.h:71
void swap(simb::MCTrajectory &other)
Definition: MCTrajectory.h:169
list_type::const_reverse_iterator const_reverse_iterator
Definition: MCTrajectory.h:68
size_type size() const
Definition: MCTrajectory.h:166
void Sparsify(double margin=.1, bool keep_second_to_last=false)
double TotalLength() const
double T(const size_type i) const
Definition: MCTrajectory.h:152
double Px(const size_type i) const
Definition: MCTrajectory.h:153
def momentum(x1, x2, x3, scale=1.)
const value_type & operator[](const size_type i) const
Definition: MCTrajectory.h:172
double Py(const size_type i) const
Definition: MCTrajectory.h:154
const TLorentzVector & Momentum(const size_type) const
friend std::ostream & operator<<(std::ostream &output, const MCTrajectory &)
list_type ftrajectory
The list of trajectory points.
Definition: MCTrajectory.h:77
vertex reconstruction