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;
65  typedef list_type::iterator iterator;
66  typedef list_type::const_iterator const_iterator;
67  typedef list_type::reverse_iterator reverse_iterator;
68  typedef list_type::const_reverse_iterator const_reverse_iterator;
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 
135  unsigned char ProcessToKey(std::string const& process) const;
136  std::string KeyToProcess(unsigned char const& key) const;
137  ProcessMap const& TrajectoryProcesses() const;
138 
139  /// Remove points from trajectory. Straight line interpolation between the
140  /// remaining points will pass no further than \a margin from removed
141  /// points.
142  void Sparsify(double margin = .1);
143 
144  };
145 
146 } // namespace simb
147 
148 inline double simb::MCTrajectory::X ( const size_type i ) const { return Position(i).X(); }
149 inline double simb::MCTrajectory::Y ( const size_type i ) const { return Position(i).Y(); }
150 inline double simb::MCTrajectory::Z ( const size_type i ) const { return Position(i).Z(); }
151 inline double simb::MCTrajectory::T ( const size_type i ) const { return Position(i).T(); }
152 inline double simb::MCTrajectory::Px( const size_type i ) const { return Momentum(i).Px(); }
153 inline double simb::MCTrajectory::Py( const size_type i ) const { return Momentum(i).Py(); }
154 inline double simb::MCTrajectory::Pz( const size_type i ) const { return Momentum(i).Pz(); }
155 inline double simb::MCTrajectory::E ( const size_type i ) const { return Momentum(i).E(); }
156 
166 inline bool simb::MCTrajectory::empty() const { return ftrajectory.empty(); }
167 inline void simb::MCTrajectory::clear() { ftrajectory.clear(); }
169  { ftrajectory.swap( other.ftrajectory ); }
170 
172  { return ftrajectory[i]; }
173 
175  { return ftrajectory.at(i); }
176 
178  { ftrajectory.push_back(v); }
179 
180 inline void simb::MCTrajectory::push_back(const TLorentzVector& p,
181  const TLorentzVector& m )
182  { ftrajectory.push_back( simb::MCTrajectory::value_type(p,m) ); }
183 
184 inline void simb::MCTrajectory::Add(const TLorentzVector& p,
185  const TLorentzVector& m ) { push_back(p,m); }
186 
188 
189 #endif // SIMB_MCTRAJECTORY_H
void Add(TLorentzVector const &p, TLorentzVector const &m)
ofstream output
double Z(const size_type i) const
Definition: MCTrajectory.h:150
double X(const size_type i) const
Definition: MCTrajectory.h:148
Definition: event.h:34
void push_back(value_type const &v)
double E(const size_type i) const
Definition: MCTrajectory.h:155
reverse_iterator rbegin()
Definition: MCTrajectory.h:161
double Pz(const size_type i) const
Definition: MCTrajectory.h:154
const char * p
Definition: xmltok.h:285
const value_type & at(const size_type i) const
Definition: MCTrajectory.h:174
std::string KeyToProcess(unsigned char const &key) const
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:166
void Sparsify(double margin=.1)
list_type::size_type size_type
Definition: MCTrajectory.h:69
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Definition: typedefs.hpp:11
list_type::difference_type difference_type
Definition: MCTrajectory.h:70
double Y(const size_type i) const
Definition: MCTrajectory.h:149
list_type::const_iterator const_iterator
Definition: MCTrajectory.h:66
ProcessMap fTrajectoryProcess
Definition: MCTrajectory.h:78
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:187
This class describes a particle created in the detector Monte Carlo simulation.
reverse_iterator rend()
Definition: MCTrajectory.h:163
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:168
list_type::const_reverse_iterator const_reverse_iterator
Definition: MCTrajectory.h:68
size_type size() const
Definition: MCTrajectory.h:165
double TotalLength() const
double T(const size_type i) const
Definition: MCTrajectory.h:151
double Px(const size_type i) const
Definition: MCTrajectory.h:152
const value_type & operator[](const size_type i) const
Definition: MCTrajectory.h:171
double Py(const size_type i) const
Definition: MCTrajectory.h:153
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
enum BeamMode string