eventAnalysis  7.0-49-g0ac7482
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TTruthTrajectoriesModule.hxx
Go to the documentation of this file.
1 ///
2 /// For questions or suggestions about this module please contact the
3 /// current responsible and CC in the eventAnalysis package manager.
4 ///
5 /// 26-Nov-2012: Current responsible for this module is,
6 /// Steve Dennis (stephen.dennis [*a*t*] warwick.ac.uk)
7 ///
8 
9 #ifndef TTruthTrajectoriesModule_hxx_seen
10 #define TTruthTrajectoriesModule_hxx_seen
11 
12 // c++
13 #include <set>
14 
15 // Root
16 #include <TClonesArray.h>
17 #include <TLorentzVector.h>
18 
19 // oaEvent
20 #include <TG4Trajectory.hxx>
21 #include <TND280Event.hxx>
22 
23 // analysisMasterTools
24 #include "eventAnalysisEnums.hxx"
25 
26 // eventAnalysis
27 #include <EeventAnalysis.hxx>
29 
30 namespace ND {
31 class TTruthTrajectoriesModule;
32 OA_EXCEPTION(EeventAnalysisInfiniteLoop, EeventAnalysis);
33 }
34 
35 ///\brief The eventAnalysis module responsible for saving information about the
36 /// True Particles in an event from MC.
37 ///\details It saves a tree called "Trajectories" in the "TruthDir" directory
38 /// of eventAnalysis files. The tree contains integers indicating how many
39 /// trajectories were in the event, and a TClonesArray "Trajectories" which
40 /// contains a TTruthTrajectory for every particle in the event which passed the
41 /// module's criteria to be saved.
43  public:
44  class TTruthTrajectory;
46 
47  TTruthTrajectoriesModule(const char *name = "Trajectories",
48  const char *title = "True Trajectory information");
49 
50  virtual ~TTruthTrajectoriesModule();
51 
52  /// This method returns true - the module is always enabled by defult.
53  virtual Bool_t IsEnabledByDefault() const { return true; }
54 
55  /// Called for the first event
56  /// This method checks whether this event is a real-data event an if so throws
57  /// an ND::EDataFile(). Otherwise it returns true.
58  virtual Bool_t ProcessFirstEvent(ND::TND280Event &);
59 
60  /// Method for setting behaviour of module.
61  /// Currently implemented
62  /// options are:
63  /// "saveall" - Save every trajectory longer than the minimum length
64  /// regardless of where it occurred
65  virtual Bool_t Configure(std::string &option);
66 
67  /// Getter for trajectory length save condition.
68  Double_t GetMinimumTrajectoryLengthToSave() const { return fMinLength; }
69 
70  /// Getter for maximum number of trajectories saveable per event.
72  return fMaxNTrajectories;
73  }
74 
75  /// Getter for trajectory length save condition. [mm]
76  void SetMinimumTrajectoryLengthToSave(Double_t mm) { fMinLength = mm; }
77 
78  /// Setter for maximum number of trajectories saveable per event.
80 
81  ///\brief Controls whether a trajectory that would ordinarily be saved
82  /// will also save all its parent trajectories.
83  void SetSaveParentChain(const Bool_t &yesorno = true) {
84  fSaveParentChain = yesorno;
85  }
86 
87  /// Controls whether just P0D/Tracker/ECal trajectories should be saved.
88  void SetSaveOnlyP0DTrackerECALTrajectories(const Bool_t &yesorno = true) {
90  }
91 
92  ///\brief Creates the necessary tree and branches for saving the Truth
93  /// Trajectories information
94  virtual void InitializeBranches();
95 
96  ///\brief Called for each event, this method is the master method for
97  /// retrieving and filling the Truth Trajectories information.
98  virtual bool FillTree(ND::TND280Event &);
99 
100  private:
101  ///\brief Fills a std::set (fSaveList) with the ID of every trajectory which
102  /// should be saved for the current event.
103  void FillSaveList(ND::THandle<ND::TG4TrajectoryContainer> trajectories);
104 
105  /// \brief Fills the vector of trajectory points.
106  /// \details The criteria used should be controlled in the parameters file.
108  ND::TG4Trajectory *const traj,
110 
111  ///\brief Fills vectors of entry/exit positions and momenta of the
112  /// trajectory for every subdetector traversed.
113  void FillTraces(ND::TG4Trajectory *const traj,
115 
116  ///\brief Determines if a TG4TrajectoryPoint is in the active region of the
117  /// specified subdetector.
118  ///\details Only implemented properly for TPC/FGD.
119  bool GetIsActive(const ND::TG4TrajectoryPoint &point,
121 
122  /// Determines the EParticleCategory to which a trajectory belongs.
124  const ND::TG4Trajectory *const traj);
125 
126  /// Returns true if a trajectory needs to be saved, and false oterwise.
127  bool SaveTraj(ND::TG4Trajectory *const traj) const;
128 
129  ///\brief The maximum number of trajectories that can be saved from a single
130  /// event.
131  ///\details Initialised by the constructor.
133 
134  ///\brief Minimum Length of Trajectories that will be saved in mm. All primary
135  /// particles will be saved regardless of this.
136  Double_t fMinLength;
137 
138  ///\brief Whether to save all trajectories, or only those which intersect the
139  /// P0D, Tracker or ECals.
141 
142  ///\brief Whether saving a trajectory should also trigger the saving of all
143  /// the trajectories in its parent chain.
145 
146  /// List of the trajectory IDs which are to be saved from the current event.
147  std::set<Int_t> fSaveList;
148 
149  public:
150  /// Total number of trajectories saved from the event
151  Int_t fNTraj;
152 
153  /// Number of Charged Lepton trajectories saved from the event
155 
156  /// Number of Charged Baryon Trajectories saved from the event
158 
159  /// Number of Charged Meson Trajectories saved from the event
160  Int_t fNTrajMeson;
161 
162  /// Number of Photon Trajectories saved from the event
164 
165  /// Number of Other Charged Trajectories saved from the event
166  Int_t fNTrajOtherCharged; ///< [branch]
167 
168  /// Number of Other Neutral Trajectories saved from the event
170 
171  /// Number of Any Other Trajectories saved from the event
172  Int_t fNTrajOther;
173 
174  ///\brief Clones array of ND::TTruthTrajectoriesModule::TTruthTrajectory
175  /// sorted in ascending ID order.
176  TClonesArray *fTrajectories;
177 };
178 
179 ///\brief Contains the truth information for points along the particle
180 /// trajectories generated during Monte Carlo simulations.
182  public:
183 
184  Int_t ProcessType; ///< The process type that caused the Monte Carlo to generate this point.
185  ///<\details The process types are detailed in the GEANT documentation, and
186  ///< this field contains a packed version of the GEANT type and
187  ///< sub-type. The saved value is [type + 1000*sub-type], and can be
188  ///< recovered by type = ProcessType%1000 and subType = ProcessType/1000.
189  ///< For quick reference, some of the interesting process type and sub-type
190  ///< definitions are below.
191  ///<
192  ///< * 0: The type for an undefined process.
193  ///< * 1: The type for a "transportation" process like crossing a boundary.
194  ///< * 2: The type for a electromagnetic process.
195  ///< * 1 [raw value of 1002]: The sub-type for Coulomb scattering.
196  ///< * 2 [raw value of 2002]: The sub-type for an ionization step.
197  ///< * 3 [raw value of 3002]: The sub-type for Bremsstrahlung.
198  ///< * 4 [raw value of 4002]: The sub-type for pair production by a
199  ///< charged particle.
200  ///< * 10 [raw value of 10002]: The sub-type for multiple scattering.
201  ///< * 12 [raw value of 12002]: The sub-type for the photo-electric
202  ///< effect.
203  ///< * 13 [raw value of 13002]: The sub-type for Compton scattering.
204  ///< * 14 [raw value of 14002]: The sub-type for pair production.
205  ///< * 4: The type for a hadronic process.
206  ///< * 111 [raw value of 111004]: The sub-type for hadron elastic.
207  ///< * 121 [raw value of 121004]: The sub-type for hadron inelastic.
208  ///< * 131 [raw value of 131004]: The sub-type for hadron capture.
209  ///< * 141 [raw value of 141004]: The sub-type for hadron charge
210  ///< exchange.
211  ///< * 6: The type for a decay.
212  ///< * 7: A general process (not a physics process).
213  ///< * 401 [raw value of 401007]: Step caused by a step limit.
214 
215  Float_t PositionX; ///< The X position of the trajectory point [mm].
216 
217  Float_t PositionY; ///< The Y position of the trajectory point [mm].
218 
219  Float_t PositionZ; ///< The Z position of the trajectory point [mm].
220 
221  Float_t PositionT; ///< The time of the trajectory point [ns].
222 
223 
224  Float_t MomentumX; ///< The X momentum of the particle leaving the trajectory point [MeV].
225 
226  Float_t MomentumY; ///< The Y momentum of the particle leaving the trajectory point [MeV].
227 
228  Float_t MomentumZ; ///< The Z position of the particle leaving the trajectory point [MeV].
229 
230 
231  private:
233 };
234 
235 ///\brief Contains the truth information associated with a particle from
236 /// Monte Carlo simulations.
238  public:
240  virtual ~TTruthTrajectory(){};
241 
242  ///\brief Comparison function of trajectory IDs so that a TClonesArray can
243  /// be sorted in ascending ID order.
244  Int_t Compare(const TObject *obj) const;
245 
246  /// Returns true - flagging the object as being sortable.
247  Bool_t IsSortable() const { return true; }
248 
249  ///\brief Trajectory's ID number. Uniquely identifies this trajectory
250  /// within the event. Used by other eventAnalysis modules to reference
251  /// trajectories.
252  Int_t ID;
253 
254  /// Particle PDG code
255  Int_t PDG;
256 
257  /// Particle name
258  std::string Name;
259 
260  /// Classifier of the particle type
261  Int_t Category;
262 
263  /// The Initial momentum of the particle at creation [MeV].
264  TLorentzVector InitMomentum;
265 
266  /// Initial Position at which the particle was created [mm].
267  TLorentzVector InitPosition;
268 
269  /// Final Position at which the particle stopped or left the simulation [mm].
270  TLorentzVector FinalPosition;
271 
272  /// Parent particle's Trajectory ID.
273  /// If this is a primary trajectory, the ParentID = 0.
274  Int_t ParentID;
275 
276  ///\brief ID of the primary particle at the top of this particle's parent
277  /// chain.
278  ///\details If this is a primary trajectory, then PrimaryID = ID.
279  Int_t PrimaryID;
280 
281  ///\brief Mass of the particle [MeV].
282  double Mass;
283 
284  /// Charge in units of |e|/3. (e.g. an electron has charge -3)
285  Int_t Charge;
286 
287  /// \brief The trajectory points where interactions occured along the
288  /// trajectory.
289  std::vector<ND::TTruthTrajectoriesModule::TTruthTrajectoryPoint> Points;///< The trajectory points where interactions occured along the trajectory.
290 
291  std::vector<Int_t> TraceSubdetectors;///<\brief Vector of integer subdetector codes indicating which subdetectors the particle travelled through.
292  ///<\details Uses the convention from eventAnalysisEnums::ESubdetector.
293  ///< This can be an active or inactive part of that subdetector.
294  ///< TraceSubdetectors.front() is the starting subdetector of the track
295  ///< (i.e. equivalent to the old InitSubdetector).
296  ///< TraceSubdetectors.back() is the final subdetector of the track
297  ///< (i.e. equivalent to the old FinalSubdetector).
298  ///< Note that all "Trace" prefixed variables store information in the
299  ///< order the particle encounters the subdetector, and can deal with
300  ///< encountering the same subdetector twice.
301 
302 
303  std::vector<bool> TraceInActive;///<\brief Vector of booleans indicating whether the particle went through an active part of the corresponding subdetector.
304  ///<\details TraceInActive.size() = TraceSubdetectors.size() (e.g.
305  ///< TraceInActive[4] tells you whether the particle went through an active
306  ///< part of the 5th subdetector in its path, TraceSubdetectors[4]).
307 
308 
309  std::vector<TLorentzVector> TraceEntrancePosition;///<\brief Vector of TLorentzVectors that stores the entrance position of the particle in each subdetector it encounters.
310  ///<\details TraceEntrancePosition.front() is the global starting position of
311  ///< the track (i.e. equivalent to the old InitPosition)
312  ///< TraceEntrancePosition.size() = TraceSubdetectors.size()
313  ///< (e.g. TraceEntrancePosition[4] tells you the entrance position of the
314  ///< 5th subdetector in its path, TraceSubdetectors[4]).
315 
316 
317  std::vector<TLorentzVector> TraceExitPosition;///<\brief Vector of TLorentzVectors that stores the exit position of the particle in each subdetector it encounters.
318  ///<\details TraceExitPosition.back() is the global stopping position of the
319  ///< track (i.e. equivalent to the old FinalPosition)
320  ///< TraceExitPosition.size() = TraceSubdetectors.size() (e.g.
321  ///< TraceExitPosition[4] tells you the exit position of the 5th subdetector
322  ///< in its path, TraceSubdetectors[4]).
323 
324 
325  std::vector<TVector3> TraceEntranceMomentum;///<\brief Vector of TVector3s that stores the entrance momentum of the particle in each subdetector it encounters.
326  ///<\details TraceEntranceMomentum.front() is the global starting momentum of
327  ///< the track (i.e. equivalent to the old InitMomentum).
328  ///< TraceEntranceMomentum.size() = TraceSubdetectors.size() (e.g.
329  ///< TraceEntranceMomentum[4] tells you the entrance momentum of the 5th
330  ///< subdetector in its path, TraceSubdetectors[4]).
331 
332 
333  std::vector<TVector3> TraceExitMomentum;///<\brief Vector of TVector3s that stores the exit momentum of the particle in each subdetector it encounters.
334  ///<\details TraceExitMomentum.back() is the global stopping momentum of the
335  ///< track (i.e. equivalent to the old FinalMomentum)
336  ///< TraceExitMomentum.size() = TraceSubdetectors.size() (e.g.
337  ///< TraceExitMomentum[4] tells you the exit momentum of the 5th subdetector
338  ///< in its path, TraceSubdetectors[4]).
339 
340 
341  private:
343 };
344 
345 #endif
void SetMaximumNumberTrajectoriesPerEvent(UInt_t n)
Setter for maximum number of trajectories saveable per event.
virtual Bool_t Configure(std::string &option)
Method for setting behaviour of module.
OA_EXCEPTION(EeventAnalysis, EoaCore)
Generate a base exception for the Analysis library.
std::vector< bool > TraceInActive
Vector of booleans indicating whether the particle went through an active part of the corresponding s...
Bool_t fSaveOnlyP0DTrackerECALTrajectories
Whether to save all trajectories, or only those which intersect the P0D, Tracker or ECals...
ClassDef(ND::TTruthTrajectoriesModule::TTruthTrajectoryPoint, 1)
Int_t fNTrajPhoton
Number of Photon Trajectories saved from the event.
Int_t ParentID
Parent particle&#39;s Trajectory ID.
std::vector< ND::TTruthTrajectoriesModule::TTruthTrajectoryPoint > Points
The trajectory points where interactions occured along the trajectory.
eventAnalysisEnums::EParticleCategory GetCategory(const ND::TG4Trajectory *const traj)
Determines the EParticleCategory to which a trajectory belongs.
std::vector< TVector3 > TraceExitMomentum
Vector of TVector3s that stores the exit momentum of the particle in each subdetector it encounters...
Bool_t IsSortable() const
Returns true - flagging the object as being sortable.
TLorentzVector InitMomentum
The Initial momentum of the particle at creation [MeV].
void SetSaveParentChain(const Bool_t &yesorno=true)
Controls whether a trajectory that would ordinarily be saved will also save all its parent trajectori...
Float_t MomentumX
The X momentum of the particle leaving the trajectory point [MeV].
Float_t PositionT
The time of the trajectory point [ns].
Contains the truth information for points along the particle trajectories generated during Monte Carl...
void FillSaveList(ND::THandle< ND::TG4TrajectoryContainer > trajectories)
Fills a std::set (fSaveList) with the ID of every trajectory which should be saved for the current ev...
Int_t fNTraj
Total number of trajectories saved from the event.
Float_t MomentumY
The Y momentum of the particle leaving the trajectory point [MeV].
std::vector< TLorentzVector > TraceEntrancePosition
Vector of TLorentzVectors that stores the entrance position of the particle in each subdetector it en...
Int_t Charge
Charge in units of |e|/3. (e.g. an electron has charge -3)
virtual bool FillTree(ND::TND280Event &)
Called for each event, this method is the master method for retrieving and filling the Truth Trajecto...
std::set< Int_t > fSaveList
List of the trajectory IDs which are to be saved from the current event.
Contains the truth information associated with a particle from Monte Carlo simulations.
virtual void InitializeBranches()
Creates the necessary tree and branches for saving the Truth Trajectories information.
virtual Bool_t ProcessFirstEvent(ND::TND280Event &)
Called for the first event This method checks whether this event is a real-data event an if so throws...
void FillTraces(ND::TG4Trajectory *const traj, ND::TTruthTrajectoriesModule::TTruthTrajectory *trajToFill)
Fills vectors of entry/exit positions and momenta of the trajectory for every subdetector traversed...
Int_t PrimaryID
ID of the primary particle at the top of this particle&#39;s parent chain.
Int_t fNTrajOther
Number of Any Other Trajectories saved from the event.
Float_t PositionY
The Y position of the trajectory point [mm].
std::vector< TVector3 > TraceEntranceMomentum
Vector of TVector3s that stores the entrance momentum of the particle in each subdetector it encounte...
Int_t fNTrajOtherCharged
Number of Other Charged Trajectories saved from the event.
std::vector< TLorentzVector > TraceExitPosition
Vector of TLorentzVectors that stores the exit position of the particle in each subdetector it encoun...
virtual Bool_t IsEnabledByDefault() const
This method returns true - the module is always enabled by defult.
void SetMinimumTrajectoryLengthToSave(Double_t mm)
Getter for trajectory length save condition. [mm].
Double_t GetMinimumTrajectoryLengthToSave() const
Getter for trajectory length save condition.
A base class for analysis output modules which contain event truth information.
void FillTrajectoryPoints(ND::TG4Trajectory *const traj, ND::TTruthTrajectoriesModule::TTruthTrajectory *trajToFill)
Fills the vector of trajectory points.
Int_t ProcessType
The process type that caused the Monte Carlo to generate this point.
void SetSaveOnlyP0DTrackerECALTrajectories(const Bool_t &yesorno=true)
Controls whether just P0D/Tracker/ECal trajectories should be saved.
bool GetIsActive(const ND::TG4TrajectoryPoint &point, eventAnalysisEnums::ESubdetector det) const
Determines if a TG4TrajectoryPoint is in the active region of the specified subdetector.
Int_t Category
Classifier of the particle type.
TLorentzVector FinalPosition
Final Position at which the particle stopped or left the simulation [mm].
The eventAnalysis module responsible for saving information about the True Particles in an event from...
Int_t fNTrajLepton
Number of Charged Lepton trajectories saved from the event.
std::vector< Int_t > TraceSubdetectors
Vector of integer subdetector codes indicating which subdetectors the particle travelled through...
UInt_t fMaxNTrajectories
The maximum number of trajectories that can be saved from a single event.
Int_t GetMaximumNumberTrajectoriesPerEvent() const
Getter for maximum number of trajectories saveable per event.
Float_t PositionX
The X position of the trajectory point [mm].
Int_t fNTrajMeson
Number of Charged Meson Trajectories saved from the event.
TLorentzVector InitPosition
Initial Position at which the particle was created [mm].
TTruthTrajectoriesModule(const char *name="Trajectories", const char *title="True Trajectory information")
Float_t PositionZ
The Z position of the trajectory point [mm].
ClassDef(ND::TTruthTrajectoriesModule::TTruthTrajectory, 2)
bool SaveTraj(ND::TG4Trajectory *const traj) const
Returns true if a trajectory needs to be saved, and false oterwise.
Int_t fNTrajBaryon
Number of Charged Baryon Trajectories saved from the event.
Int_t Compare(const TObject *obj) const
Comparison function of trajectory IDs so that a TClonesArray can be sorted in ascending ID order...
Int_t fNTrajOtherNeutral
Number of Other Neutral Trajectories saved from the event.
Float_t MomentumZ
The Z position of the particle leaving the trajectory point [MeV].
Double_t fMinLength
Minimum Length of Trajectories that will be saved in mm.
Bool_t fSaveParentChain
Whether saving a trajectory should also trigger the saving of all the trajectories in its parent chai...
TClonesArray * fTrajectories
Clones array of ND::TTruthTrajectoriesModule::TTruthTrajectory sorted in ascending ID order...

Package Summary
Package Name: eventAnalysis
Package Version: 7.0-49-g0ac7482
Package Manager:

Generated on Mon Mar 25 2024 14:43:59 for eventAnalysis by doxygen 1.8.5