Jpp  debug
the software that should make you happy
Trk.hh
Go to the documentation of this file.
1 #ifndef TRK_HH_INCLUDED
2 #define TRK_HH_INCLUDED
3 
4 #include <vector>
5 #include "TDatabasePDG.h"
6 #include "TPDGCode.h"
10 
11 /**
12  * The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
13  */
14 struct Trk: public AAObject
15 {
16  int id; ///< track identifier
17  Vec pos; ///< postion [m] of the track at time t
18  Vec dir; ///< track direction
19  double t; ///< track time [ns] (when the particle is at pos )
20  double E; ///< Energy [GeV] (either MC truth or reconstructed)
21 
22  double len; ///< length, if applicable [m]
23  double lik; ///< likelihood or lambda value (for aafit, lambda)
24  int type; ///< MC: particle type in PDG encoding
25  int rec_type; ///< identifier of the fitting algorithm/chain/strategy, see km3net-dataformat/definitions/reconstruction.csv
26  std::vector<int> rec_stages; ///< list of identifyers of succesfull fitting stages resulting in this track
27 
28  int status; ///< MC status code, see km3net-dataformat/definitions/trkmembers.csv for values
29  int mother_id; ///< MC id of the parent particle
30  int counter; ///< used by CORSIKA7 MC generation to store interaction counters, see <a href="https://web.iap.kit.edu/corsika/usersguide/usersguide.pdf">CORSIKA Userguide</a>
31 
32  std::vector<double> fitinf; ///< place to store additional fit info, see km3net-dataformat/definitions/fitparameters.csv
33  std::vector<int> hit_ids; ///< list of associated hit-ids (corresponds to Hit::id).
34  std::vector<double> error_matrix; ///< (NxN) error covariance matrix for fit parameters (stored as linear vector)
35  std::string comment; ///< use as you like
36 
37  /**
38  * Default constructor.
39  */
41 
42 
43 
44 
45  /**
46  * Read track (useful in python).
47  *
48  * \param t track
49  */
50  void read(const Trk& t) { *this = t;}
51 
52  /**
53  * Write track (useful in python).
54  *
55  * \param t track
56  */
57  void write(Trk& t) const { t = *this; }
58 
59 
60  /**
61  * Get the name of the MC particle type.
62  *
63  * \return name
64  */
65  std::string name() const
66  {
67  TParticlePDG* p = TDatabasePDG::Instance()->GetParticle( type );
68  if (!p) return "unnamed state ("+ std::to_string(type)+")";
69  return p->GetName();
70  }
71 
72  /**
73  * Check if this is a primary particle.
74  *
75  * \return true if primary; else false
76  */
77  bool is_primary() const
78  {
80  }
81 
82  /**
83  * Test whether given particle is a final state inside the detector.
84  *
85  * \return true if particle is final state; else false
86  */
87  bool is_finalstate() const
88  {
89  return status==TRK_ST_FINALSTATE;
90  }
91 
92  /**
93  * Check if this is a netrino.
94  *
95  * Note that its is checked if the PDG type is a nu-e, nu-mu or nu-tau.
96  *
97  * \return true if neutrino; else false
98  */
99  bool is_neutrino() const
100  {
101  return type == kNuE || type == kNuEBar || type == kNuMu || type == kNuMuBar || type == kNuTau || type == kNuTauBar;
102  }
103 
104  /**
105  * Check if this is an electron or positron.
106  *
107  * \return true if this is an electron or positron
108  */
109  bool is_e() const
110  {
111  return type == kElectron || type == kPositron;
112  }
113 
114  /**
115  * Check if this is a muon.
116  *
117  * Note that its is checked if the PDG type is a (anti-)muon.
118  *
119  * \return true if muon; else false
120  */
121  bool is_muon() const
122  {
123  return type == kMuonMinus || type == kMuonPlus;
124  }
125 
126  /**
127  * Check if this is a tau.
128  *
129  * Note that its is checked if the PDG type is a (anti-)tau.
130  *
131  * \return true if tau; else false
132  */
133  bool is_tau() const
134  {
135  return type == kTauMinus || type == kTauPlus;
136  }
137 
138  /**
139  * Check if this is a charged lepton.
140  *
141  * Note that its is checked if the PDG type is a (anti-)electron, (anti-)muon or (anti-)tua.
142  *
143  * \return true if charged lepton; else false
144  */
145  bool is_lepton() const
146  {
147  return is_e() || is_muon() || is_tau();
148  }
149 
150  /**
151  * Check if this is an orphan (i.e. no mother).
152  *
153  * \return true if orphan; else false
154  */
155  bool is_orphan() const
156  {
157  return mother_id == TRK_MOTHER_NONE;
158  }
159 
160  /**
161  * Get list of of pointers to tracks, all of which have their mother identifier set to identifier of this track.
162  *
163  * \param mctrks list of input tracks
164  * \return list of pointers to tracks
165  */
167  {
169 
170  for( auto& t : mctrks )
171  {
172  if ( t.mother_id == id ) r.push_back( &t );
173  }
174  return r;
175  }
176 
177  /**
178  * Print track.
179  *
180  * \param out output stream
181  */
182  void print(std::ostream& out=std::cout) const
183  {
184  out << "Trk: id=" << id << " pos="; pos.print(out);
185  out << " dir="; dir.print(out);
186  out << " t=" << t << " E=" << E << " pdg-type=" << type;
187  }
188 
189  ClassDef(Trk,12)
190 };
191 
192 #endif
#define ClassDef(name, version)
Definition: JRoot.hh:32
std::string to_string(const T &value)
Convert value to string.
data_type r[M+1]
Definition: JPolint.hh:868
AAObject is a base class for I/O-classes that adds the possibility to add 'user' information which wi...
Definition: AAObject.hh:19
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:15
void print(std::ostream &out=std::cout) const
Print track.
Definition: Trk.hh:182
bool is_neutrino() const
Check if this is a netrino.
Definition: Trk.hh:99
bool is_tau() const
Check if this is a tau.
Definition: Trk.hh:133
bool is_primary() const
Check if this is a primary particle.
Definition: Trk.hh:77
int status
MC status code, see km3net-dataformat/definitions/trkmembers.csv for values.
Definition: Trk.hh:28
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:24
void read(const Trk &t)
Read track (useful in python).
Definition: Trk.hh:50
std::vector< int > hit_ids
list of associated hit-ids (corresponds to Hit::id).
Definition: Trk.hh:33
int id
track identifier
Definition: Trk.hh:16
std::vector< double > error_matrix
(NxN) error covariance matrix for fit parameters (stored as linear vector)
Definition: Trk.hh:34
std::vector< double > fitinf
place to store additional fit info, see km3net-dataformat/definitions/fitparameters....
Definition: Trk.hh:32
void write(Trk &t) const
Write track (useful in python).
Definition: Trk.hh:57
Vec dir
track direction
Definition: Trk.hh:18
std::string comment
use as you like
Definition: Trk.hh:35
std::vector< int > rec_stages
list of identifyers of succesfull fitting stages resulting in this track
Definition: Trk.hh:26
bool is_finalstate() const
Test whether given particle is a final state inside the detector.
Definition: Trk.hh:87
std::vector< Trk * > get_daughters(std::vector< Trk > &mctrks)
Get list of of pointers to tracks, all of which have their mother identifier set to identifier of thi...
Definition: Trk.hh:166
bool is_lepton() const
Check if this is a charged lepton.
Definition: Trk.hh:145
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:20
int counter
used by CORSIKA7 MC generation to store interaction counters, see CORSIKA Userguide
Definition: Trk.hh:30
bool is_e() const
Check if this is an electron or positron.
Definition: Trk.hh:109
double t
track time [ns] (when the particle is at pos )
Definition: Trk.hh:19
bool is_orphan() const
Check if this is an orphan (i.e.
Definition: Trk.hh:155
double len
length, if applicable [m]
Definition: Trk.hh:22
int rec_type
identifier of the fitting algorithm/chain/strategy, see km3net-dataformat/definitions/reconstruction....
Definition: Trk.hh:25
std::string name() const
Get the name of the MC particle type.
Definition: Trk.hh:65
int mother_id
MC id of the parent particle.
Definition: Trk.hh:29
double lik
likelihood or lambda value (for aafit, lambda)
Definition: Trk.hh:23
bool is_muon() const
Check if this is a muon.
Definition: Trk.hh:121
Vec pos
postion [m] of the track at time t
Definition: Trk.hh:17
Trk()
Default constructor.
Definition: Trk.hh:40
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:13
void print(std::ostream &out=std::cout) const
Print vector.
Definition: Vec.hh:166
static const int TRK_ST_FINALSTATE
for MC: the particle must be processed by detector simulation ('track_in' tag in evt files)....
Definition: trkmembers.hh:15
static const int TRK_MOTHER_UNDEFINED
KM3NeT Data Definitions v3.4.0-8-ge14cb17 https://git.km3net.de/common/km3net-dataformat.
Definition: trkmembers.hh:12
static const int TRK_ST_PRIMARYCOSMIC
initial state cosmic ray ('track_primary' tag in evt files from corant).
Definition: trkmembers.hh:17
static const int TRK_ST_PRIMARYNEUTRINO
initial state neutrino ('neutrino' tag in evt files from gseagen and genhen).
Definition: trkmembers.hh:16
static const int TRK_ST_UNDEFINED
status was not defined for this MC track (all reco tracks have this value)
Definition: trkmembers.hh:14
static const int TRK_MOTHER_NONE
mother id of a particle if it has no parent
Definition: trkmembers.hh:13