Jpp
Trk.hh
Go to the documentation of this file.
1 #ifndef TRK_HH_INCLUDED
2 #define TRK_HH_INCLUDED
3 
4 #include "AAObject.hh"
5 #include "Vec.hh"
6 #include <vector>
7 #include "TDatabasePDG.h"
8 
9 /**
10  * The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
11  */
12 struct Trk: public AAObject
13 {
14  int id; ///< track identifier
15  Vec pos; ///< postion of the track at time t
16  Vec dir; ///< track direction
17  double t; ///< track time (when the particle is at pos )
18  double E; ///< Energy (either MC truth or reconstructed)
19 
20  double len; ///< length, if applicable
21  double lik; ///< likelihood or lambda value (for aafit, lambda)
22  int type; ///< MC: particle type in PDG encoding.
23  int rec_type; ///< identifyer for the overall fitting algorithm/chain/strategy
24  std::vector<int> rec_stages; ///< list of identifyers of succesfull fitting stages resulting in this track
25 
26  int status; ///< MC status code
27  int mother_id; ///< MC id of the parent particle
28 
29  std::vector<double> fitinf; ///< place to store additional fit info, for jgandalf, see JFitParameters.hh
30  std::vector<int> hit_ids; ///< list of associated hit-ids (corresponds to Hit::id).
31  std::vector<double> error_matrix; ///< (5x5) error covariance matrix (stored as linear vector)
32  std::string comment; ///< use as you like
33 
34  /**
35  * Default constructor.
36  */
37  Trk(): id(0),t(0),E(0),len(0),lik(0), type(0), rec_type(0), status(0), mother_id(-1) {}
38 
39  /**
40  * Read track (useful in python).
41  *
42  * \param t track
43  */
44  void read(const Trk& t) { *this = t;}
45 
46  /**
47  * Write track (useful in python).
48  *
49  * \param t track
50  */
51  void write(Trk& t) const { t = *this; }
52 
53 
54  /**
55  * Get distance of closes approach to another track.
56  *
57  * \param t track
58  * \return distance
59  */
60  double distance_to (const Trk& t) const
61  {
62  Vec v = dir.cross( t.dir );
63  v /= v.len();
64  const double d = (pos - t.pos ).dot( v );
65  return d>0?d:-d;
66  }
67 
68  /**
69  * Get distance to given position.
70  *
71  * \param p position
72  * \return distance
73  */
74  double distance_to( const Vec& p = Vec() ) const
75  {
76  Vec v = p - pos;
77  double dz = v.dot(dir);
78  return v.dot(v) - dz*dz;
79  }
80 
81  /**
82  * Get the name of the MC particle type.
83  *
84  * \return name
85  */
86  std::string name() const
87  {
88  TParticlePDG* p = TDatabasePDG::Instance()->GetParticle( type );
89  if (!p) return "unnamed state ("+ std::to_string(type)+")";
90  return p->GetName();
91  }
92 
93  /**
94  * Check if this is a primary particle (i.e. has not mother).
95  *
96  * \return true if primary; else false
97  */
98  bool is_primary() const
99  {
100  return mother_id == -1; // and/or status==0 ?
101  }
102 
103  /**
104  * Check if this is a netrino.
105  *
106  * Note that its is checked if the PDG type is a nu-e, nu-mu or nu-tau.
107  *
108  * \return true if neutrino; else false
109  */
110  bool is_neutrino() const
111  {
112  const unsigned t = abs(type);
113  return t == 12 || t == 14 || t == 16;
114  }
115 
116  /**
117  * Check if this is a charged lepton.
118  *
119  * Note that its is checked if the PDG type is a (anti-)electron, (anti-)muon or (anti-)tua.
120  *
121  * \return true if charged lepton; else false
122  */
123  bool is_lepton() const
124  {
125  const unsigned t = abs(type);
126  return t == 11 || t == 13 || t == 15;
127  }
128 
129  /**
130  * Check if this is a muon.
131  *
132  * Note that its is checked if the PDG type is a (anti-)muon.
133  *
134  * \return true if muon; else false
135  */
136  bool is_muon() const { return abs(type)==13; }
137 
138  /**
139  * Check if this is an orphan.
140  *
141  * If a particle's (intermediate) mother has been deleted from the track-list (the 3rd digit of status==1).
142  *
143  * \return true if orphan; else false
144  */
145  bool is_orphan() const
146  {
147  return (status / 100) % 10 == 1;
148  }
149 
150  /**
151  * Get list of of pointers to tracks, all of which have their mother identifier set to identifier of this track.
152  *
153  * \param mctrks list of input tracks
154  * \return list of pointers to tracks
155  */
157  {
159 
160  for( auto& t : mctrks )
161  {
162  if ( t.mother_id == id ) r.push_back( &t );
163  }
164  return r;
165  }
166 
167  /**
168  * Print track.
169  *
170  * \param out output stream
171  */
172  void print(std::ostream& out) const
173  {
174  out << "Trk: id=" << id << " pos="; pos.print(out);
175  out << " dir="; dir.print(out);
176  out << " t=" << t << " E=" << E << " pdg-type=" << type;
177  }
178 
179  ClassDef(Trk,11)
180 };
181 
182 #endif
Trk::Trk
Trk()
Default constructor.
Definition: Trk.hh:37
Trk::name
std::string name() const
Get the name of the MC particle type.
Definition: Trk.hh:86
Trk::distance_to
double distance_to(const Vec &p=Vec()) const
Get distance to given position.
Definition: Trk.hh:74
Trk::is_orphan
bool is_orphan() const
Check if this is an orphan.
Definition: Trk.hh:145
Trk::rec_type
int rec_type
identifyer for the overall fitting algorithm/chain/strategy
Definition: Trk.hh:23
Trk::is_primary
bool is_primary() const
Check if this is a primary particle (i.e.
Definition: Trk.hh:98
Trk::read
void read(const Trk &t)
Read track (useful in python).
Definition: Trk.hh:44
Trk::E
double E
Energy (either MC truth or reconstructed)
Definition: Trk.hh:18
std::vector< int >
Trk
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:12
ClassDef
#define ClassDef(name, version)
Definition: JRoot.hh:32
Trk::comment
std::string comment
use as you like
Definition: Trk.hh:32
Trk::t
double t
track time (when the particle is at pos )
Definition: Trk.hh:17
Trk::distance_to
double distance_to(const Trk &t) const
Get distance of closes approach to another track.
Definition: Trk.hh:60
Vec::cross
Vec cross(const Vec r) const
Get cross product.
Definition: Vec.hh:44
Vec.hh
Trk::dir
Vec dir
track direction
Definition: Trk.hh:16
Trk::len
double len
length, if applicable
Definition: Trk.hh:20
Trk::is_muon
bool is_muon() const
Check if this is a muon.
Definition: Trk.hh:136
Trk::hit_ids
std::vector< int > hit_ids
list of associated hit-ids (corresponds to Hit::id).
Definition: Trk.hh:30
Trk::status
int status
MC status code.
Definition: Trk.hh:26
Trk::mother_id
int mother_id
MC id of the parent particle.
Definition: Trk.hh:27
Trk::type
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:22
Trk::print
void print(std::ostream &out) const
Print track.
Definition: Trk.hh:172
JLANG::to_string
std::string to_string(const T &value)
Convert value to string.
Definition: JLangToolkit.hh:192
Trk::pos
Vec pos
postion of the track at time t
Definition: Trk.hh:15
Trk::write
void write(Trk &t) const
Write track (useful in python).
Definition: Trk.hh:51
JTOOLS::v
data_type v[N+1][M+1]
Definition: JPolint.hh:707
Trk::is_neutrino
bool is_neutrino() const
Check if this is a netrino.
Definition: Trk.hh:110
Trk::fitinf
std::vector< double > fitinf
place to store additional fit info, for jgandalf, see JFitParameters.hh
Definition: Trk.hh:29
Trk::id
int id
track identifier
Definition: Trk.hh:14
Trk::is_lepton
bool is_lepton() const
Check if this is a charged lepton.
Definition: Trk.hh:123
Trk::rec_stages
std::vector< int > rec_stages
list of identifyers of succesfull fitting stages resulting in this track
Definition: Trk.hh:24
Vec
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
Trk::lik
double lik
likelihood or lambda value (for aafit, lambda)
Definition: Trk.hh:21
JTOOLS::r
data_type r[M+1]
Definition: JPolint.hh:709
AAObject
AAObject is a base class for I/O-classes that adds the possibility to add 'user' information which wi...
Definition: AAObject.hh:18
Trk::error_matrix
std::vector< double > error_matrix
(5x5) error covariance matrix (stored as linear vector)
Definition: Trk.hh:31
Trk::get_daughters
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:156
Vec::print
void print(std::ostream &out=std::cout) const
Print vector.
Definition: Vec.hh:166
AAObject.hh