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