Jpp  17.3.0-rc.2
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 [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  * \param track track
86  * \return true if particle is final state; else false
87  */
88  bool is_finalstate() const
89  {
90  return status==TRK_ST_FINALSTATE;
91  }
92 
93  /**
94  * Check if this is a netrino.
95  *
96  * Note that its is checked if the PDG type is a nu-e, nu-mu or nu-tau.
97  *
98  * \return true if neutrino; else false
99  */
100  bool is_neutrino() const
101  {
102  return type == kNuE || type == kNuEBar || type == kNuMu || type == kNuMuBar || type == kNuTau || type == kNuTauBar;
103  }
104 
105  /**
106  * Check if this is an electron or positron.
107  *
108  * \return true if this is an electron or positron
109  */
110  bool is_e() const
111  {
112  return type == kElectron || type == kPositron;
113  }
114 
115  /**
116  * Check if this is a muon.
117  *
118  * Note that its is checked if the PDG type is a (anti-)muon.
119  *
120  * \return true if muon; else false
121  */
122  bool is_muon() const
123  {
124  return type == kMuonMinus || type == kMuonPlus;
125  }
126 
127  /**
128  * Check if this is a tau.
129  *
130  * Note that its is checked if the PDG type is a (anti-)tau.
131  *
132  * \return true if tau; else false
133  */
134  bool is_tau() const
135  {
136  return type == kTauMinus || type == kTauPlus;
137  }
138 
139  /**
140  * Check if this is a charged lepton.
141  *
142  * Note that its is checked if the PDG type is a (anti-)electron, (anti-)muon or (anti-)tua.
143  *
144  * \return true if charged lepton; else false
145  */
146  bool is_lepton() const
147  {
148  return is_e() || is_muon() || is_tau();
149  }
150 
151  /**
152  * Check if this is an orphan (i.e. no mother).
153  *
154  * \return true if orphan; else false
155  */
156  bool is_orphan() const
157  {
158  return mother_id == TRK_MOTHER_NONE;
159  }
160 
161  /**
162  * Get list of of pointers to tracks, all of which have their mother identifier set to identifier of this track.
163  *
164  * \param mctrks list of input tracks
165  * \return list of pointers to tracks
166  */
168  {
170 
171  for( auto& t : mctrks )
172  {
173  if ( t.mother_id == id ) r.push_back( &t );
174  }
175  return r;
176  }
177 
178  /**
179  * Print track.
180  *
181  * \param out output stream
182  */
183  void print(std::ostream& out=std::cout) const
184  {
185  out << "Trk: id=" << id << " pos="; pos.print(out);
186  out << " dir="; dir.print(out);
187  out << " t=" << t << " E=" << E << " pdg-type=" << type;
188  }
189 
190  ClassDef(Trk,12)
191 };
192 
193 #endif
int counter
used by CORSIKA7 MC generation to store interaction counters, see CORSIKA Userguide ...
Definition: Trk.hh:30
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:167
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:100
Vec dir
track direction
Definition: Trk.hh:18
std::string comment
use as you like
Definition: Trk.hh:35
bool is_primary() const
Check if this is a primary particle.
Definition: Trk.hh:77
data_type r[M+1]
Definition: JPolint.hh:779
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:65
bool is_lepton() const
Check if this is a charged lepton.
Definition: Trk.hh:146
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:50
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:33
std::vector< double > fitinf
place to store additional fit info, see km3net-dataformat/definitions/fitparameters.csv
Definition: Trk.hh:32
then awk string
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:122
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:57
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 v3.0.0-3-gef79250 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:88
static const int TRK_ST_FINALSTATE
for MC: the particle must be processed by detector simulation (&#39;track_in&#39; tag in evt files)...
Definition: trkmembers.hh:15
Vec pos
postion [m] of the track at time t
Definition: Trk.hh:17
bool is_tau() const
Check if this is a tau.
Definition: Trk.hh:134
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:110
std::vector< double > error_matrix
(NxN) error covariance matrix for fit parameters (stored as linear vector)
Definition: Trk.hh:34
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:40
void print(std::ostream &out=std::cout) const
Print track.
Definition: Trk.hh:183
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:156
int rec_type
identifier of the fitting algorithm/chain/strategy, see km3net-dataformat/definitions/reconstruction...
Definition: Trk.hh:25