Jpp  pmt_effective_area_update
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"
9 
10 /**
11  * The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
12  */
13 struct Trk: public AAObject
14 {
15  int id; ///< track identifier
16  Vec pos; ///< postion of the track at time t [m]
17  Vec dir; ///< track direction
18  double t; ///< track time [ns] (when the particle is at pos )
19  double E; ///< Energy [GeV] (either MC truth or reconstructed)
20 
21  double len; ///< length, if applicable [m]
22  double lik; ///< likelihood or lambda value (for aafit, lambda)
23  int type; ///< MC: particle type in PDG encoding.
24  int rec_type; ///< identifyer for the overall fitting algorithm/chain/strategy
25  std::vector<int> rec_stages; ///< list of identifyers of succesfull fitting stages resulting in this track
26 
27  int status; ///< MC status code, see km3net-dataformat/definitions/trkmembers.csv for values
28  int mother_id; ///< MC id of the parent particle
29 
30  std::vector<double> fitinf; ///< place to store additional fit info, for jgandalf, see JFitParameters.hh
31  std::vector<int> hit_ids; ///< list of associated hit-ids (corresponds to Hit::id).
32  std::vector<double> error_matrix; ///< (NxN) error covariance matrix for fit parameters (stored as linear vector)
33  std::string comment; ///< use as you like
34 
35  /**
36  * Default constructor.
37  */
39 
40 
41 
42 
43  /**
44  * Read track (useful in python).
45  *
46  * \param t track
47  */
48  void read(const Trk& t) { *this = t;}
49 
50  /**
51  * Write track (useful in python).
52  *
53  * \param t track
54  */
55  void write(Trk& t) const { t = *this; }
56 
57 
58  /**
59  * Get the name of the MC particle type.
60  *
61  * \return name
62  */
63  std::string name() const
64  {
65  TParticlePDG* p = TDatabasePDG::Instance()->GetParticle( type );
66  if (!p) return "unnamed state ("+ std::to_string(type)+")";
67  return p->GetName();
68  }
69 
70  /**
71  * Check if this is a primary particle.
72  *
73  * \return true if primary; else false
74  */
75  bool is_primary() const
76  {
78  }
79 
80  /**
81  * Test whether given particle is a final state inside the detector.
82  *
83  * \param track track
84  * \return true if particle is final state; else false
85  */
86  bool is_finalstate() const
87  {
88  return status==TRK_ST_FINALSTATE;
89  }
90 
91  /**
92  * Check if this is a netrino.
93  *
94  * Note that its is checked if the PDG type is a nu-e, nu-mu or nu-tau.
95  *
96  * \return true if neutrino; else false
97  */
98  bool is_neutrino() const
99  {
100  const unsigned t = abs(type);
101  return t == 12 || t == 14 || t == 16;
102  }
103 
104  /**
105  * Check if this is a charged lepton.
106  *
107  * Note that its is checked if the PDG type is a (anti-)electron, (anti-)muon or (anti-)tua.
108  *
109  * \return true if charged lepton; else false
110  */
111  bool is_lepton() const
112  {
113  const unsigned t = abs(type);
114  return t == 11 || t == 13 || t == 15;
115  }
116 
117  /**
118  * Check if this is a muon.
119  *
120  * Note that its is checked if the PDG type is a (anti-)muon.
121  *
122  * \return true if muon; else false
123  */
124  bool is_muon() const { return abs(type)==13; }
125 
126  /**
127  * Check if this is an orphan (i.e. no mother).
128  *
129  * \return true if orphan; else false
130  */
131  bool is_orphan() const
132  {
133  return mother_id == TRK_MOTHER_NONE;
134  }
135 
136  /**
137  * Get list of of pointers to tracks, all of which have their mother identifier set to identifier of this track.
138  *
139  * \param mctrks list of input tracks
140  * \return list of pointers to tracks
141  */
143  {
145 
146  for( auto& t : mctrks )
147  {
148  if ( t.mother_id == id ) r.push_back( &t );
149  }
150  return r;
151  }
152 
153  /**
154  * Print track.
155  *
156  * \param out output stream
157  */
158  void print(std::ostream& out=std::cout) const
159  {
160  out << "Trk: id=" << id << " pos="; pos.print(out);
161  out << " dir="; dir.print(out);
162  out << " t=" << t << " E=" << E << " pdg-type=" << type;
163  }
164 
165  ClassDef(Trk,11)
166 };
167 
168 #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:142
double t
track time [ns] (when the particle is at pos )
Definition: Trk.hh:18
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:98
Vec dir
track direction
Definition: Trk.hh:17
std::string comment
use as you like
Definition: Trk.hh:33
bool is_primary() const
Check if this is a primary particle.
Definition: Trk.hh:75
data_type r[M+1]
Definition: JPolint.hh:742
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:19
std::string name() const
Get the name of the MC particle type.
Definition: Trk.hh:63
bool is_lepton() const
Check if this is a charged lepton.
Definition: Trk.hh:111
int mother_id
MC id of the parent particle.
Definition: Trk.hh:28
void read(const Trk &t)
Read track (useful in python).
Definition: Trk.hh:48
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:31
std::vector< double > fitinf
place to store additional fit info, for jgandalf, see JFitParameters.hh
Definition: Trk.hh:30
double len
length, if applicable [m]
Definition: Trk.hh:21
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:124
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:55
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.0.0-15-g59d2e2b https://git.km3net.de/common/km3net-dataformat.
Definition: trkmembers.hh:12
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:23
int id
track identifier
Definition: Trk.hh:15
int status
MC status code, see km3net-dataformat/definitions/trkmembers.csv for values.
Definition: Trk.hh:27
#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:86
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:16
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:25
std::vector< double > error_matrix
(NxN) error covariance matrix for fit parameters (stored as linear vector)
Definition: Trk.hh:32
double lik
likelihood or lambda value (for aafit, lambda)
Definition: Trk.hh:22
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:38
void print(std::ostream &out=std::cout) const
Print track.
Definition: Trk.hh:158
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:13
bool is_orphan() const
Check if this is an orphan (i.e.
Definition: Trk.hh:131
int rec_type
identifyer for the overall fitting algorithm/chain/strategy
Definition: Trk.hh:24