Jpp  16.0.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 of the track at time t [m]
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; ///< identifyer for the overall fitting algorithm/chain/strategy
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 
31  std::vector<double> fitinf; ///< place to store additional fit info, for jgandalf, see JFitParameters.hh
32  std::vector<int> hit_ids; ///< list of associated hit-ids (corresponds to Hit::id).
33  std::vector<double> error_matrix; ///< (NxN) error covariance matrix for fit parameters (stored as linear vector)
34  std::string comment; ///< use as you like
35 
36  /**
37  * Default constructor.
38  */
40 
41 
42 
43 
44  /**
45  * Read track (useful in python).
46  *
47  * \param t track
48  */
49  void read(const Trk& t) { *this = t;}
50 
51  /**
52  * Write track (useful in python).
53  *
54  * \param t track
55  */
56  void write(Trk& t) const { t = *this; }
57 
58 
59  /**
60  * Get the name of the MC particle type.
61  *
62  * \return name
63  */
64  std::string name() const
65  {
66  TParticlePDG* p = TDatabasePDG::Instance()->GetParticle( type );
67  if (!p) return "unnamed state ("+ std::to_string(type)+")";
68  return p->GetName();
69  }
70 
71  /**
72  * Check if this is a primary particle.
73  *
74  * \return true if primary; else false
75  */
76  bool is_primary() const
77  {
79  }
80 
81  /**
82  * Test whether given particle is a final state inside the detector.
83  *
84  * \param track track
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,11)
190 };
191 
192 #endif
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
double t
track time [ns] (when the particle is at pos )
Definition: Trk.hh:19
static const int TRK_MOTHER_NONE
mother id of a particle if it has no parent
Definition: trkmembers.hh:13
bool is_neutrino() const
Check if this is a netrino.
Definition: Trk.hh:99
Vec dir
track direction
Definition: Trk.hh:18
std::string comment
use as you like
Definition: Trk.hh:34
bool is_primary() const
Check if this is a primary particle.
Definition: Trk.hh:76
data_type r[M+1]
Definition: JPolint.hh:758
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:20
std::string name() const
Get the name of the MC particle type.
Definition: Trk.hh:64
bool is_lepton() const
Check if this is a charged lepton.
Definition: Trk.hh:145
int mother_id
MC id of the parent particle.
Definition: Trk.hh:29
void read(const Trk &t)
Read track (useful in python).
Definition: Trk.hh:49
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
std::vector< int > hit_ids
list of associated hit-ids (corresponds to Hit::id).
Definition: Trk.hh:32
std::vector< double > fitinf
place to store additional fit info, for jgandalf, see JFitParameters.hh
Definition: Trk.hh:31
double len
length, if applicable [m]
Definition: Trk.hh:22
static const int TRK_ST_PRIMARYNEUTRINO
initial state neutrino (&#39;neutrino&#39; tag in evt files from gseagen and genhen).
Definition: trkmembers.hh:16
bool is_muon() const
Check if this is a muon.
Definition: Trk.hh:121
static const int TRK_ST_PRIMARYCOSMIC
initial state cosmic ray (&#39;track_primary&#39; tag in evt files from corant).
Definition: trkmembers.hh:17
void write(Trk &t) const
Write track (useful in python).
Definition: Trk.hh:56
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_UNDEFINED
KM3NeT Data Definitions v2.1.0-12-g9520e6e https://git.km3net.de/common/km3net-dataformat.
Definition: trkmembers.hh:12
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:24
int id
track identifier
Definition: Trk.hh:16
int status
MC status code, see km3net-dataformat/definitions/trkmembers.csv for values.
Definition: Trk.hh:28
#define ClassDef(name, version)
Definition: JRoot.hh:32
bool is_finalstate() const
Test whether given particle is a final state inside the detector.
Definition: Trk.hh:87
static const int TRK_ST_FINALSTATE
particle to be tracked by detector-level MC (&#39;track_in&#39; tag in evt files from gseagen ...
Definition: trkmembers.hh:15
Vec pos
postion of the track at time t [m]
Definition: Trk.hh:17
bool is_tau() const
Check if this is a tau.
Definition: Trk.hh:133
AAObject is a base class for I/O-classes that adds the possibility to add &#39;user&#39; information which wi...
Definition: AAObject.hh:18
std::vector< int > rec_stages
list of identifyers of succesfull fitting stages resulting in this track
Definition: Trk.hh:26
bool is_e() const
Check if this is an electron or positron.
Definition: Trk.hh:109
std::vector< double > error_matrix
(NxN) error covariance matrix for fit parameters (stored as linear vector)
Definition: Trk.hh:33
double lik
likelihood or lambda value (for aafit, lambda)
Definition: Trk.hh:23
std::string to_string(const T &value)
Convert value to string.
void print(std::ostream &out=std::cout) const
Print vector.
Definition: Vec.hh:166
Trk()
Default constructor.
Definition: Trk.hh:39
void print(std::ostream &out=std::cout) const
Print track.
Definition: Trk.hh:182
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:14
bool is_orphan() const
Check if this is an orphan (i.e.
Definition: Trk.hh:155
int rec_type
identifyer for the overall fitting algorithm/chain/strategy
Definition: Trk.hh:25