Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Evt.hh
Go to the documentation of this file.
1 #ifndef EVT_HH_INCLUDED
2 #define EVT_HH_INCLUDED
3 
4 #include "AAObject.hh"
5 #include "Hit.hh"
6 #include "Trk.hh"
7 #include "Hit.hh"
8 #include "Exception.hh"
9 
10 #include "TTimeStamp.h"
11 
12 #include <vector>
13 
14 /**
15  * The Evt class respresent a Monte Carlo (MC) event as well as an offline event.\n
16  * Some data from the online (DAQ) event are copied.
17  */
18 
19 struct Evt: public AAObject
20 {
21  int id; ///< offline event identifier
22  int det_id; ///< detector identifier from DAQ
23  int mc_id; ///< identifier of the MC event (as found in ascii or antcc file).
24 
25  int run_id; ///< DAQ run identifier
26  int mc_run_id; ///< MC run identifier
27 
28  int frame_index; ///< from the raw data
29  ULong64_t trigger_mask; ///< trigger mask from raw data (i.e. the trigger bits)
30  ULong64_t trigger_counter; ///< trigger counter
31  unsigned int overlays; ///< number of overlaying triggered events
32  TTimeStamp t; ///< UTC time of the start of the timeslice the event came from
33 
34  //hits and tracks
35  std::vector<Hit> hits; ///< list of hits
36  std::vector<Trk> trks; ///< list of reconstructed tracks (can be several because of prefits,showers, etc).
37 
38  //Monte carlo
39  std::vector<double> w; ///< MC: Weights w[0]=w1, w[1]=w2, w[2]]=w3 (see e.g. <a href="https://simulation.pages.km3net.de/taglist/taglist.pdf">Tag list</a>)
40  std::vector<double> w2list; ///< MC: factors that make up w[1]=w2 (see e.g. <a href="https://simulation.pages.km3net.de/taglist/taglist.pdf">Tag list</a>)
41  std::vector<double> w3list; ///< MC: atmospheric flux information
42 
43  double mc_t; ///< MC: time of the mc event
44  std::vector<Hit> mc_hits; ///< MC: list of MC truth hits
45  std::vector<Trk> mc_trks; ///< MC: list of MC truth tracks
46 
47  // --- place to store user info ---
48  TString comment; ///< user can use this as he/she likes
49  int index; ///< user can use this as he/she likes
50  int flags; ///< user can use this as he/she likes
51 
52 
53  // basic ctor and trival io
54  Evt() :
55  id(0), det_id(0), mc_id(0), run_id(0), mc_run_id(0), frame_index(0),
57  overlays(0), t(0), mc_t(0), index(0), flags(0) {}
58 
59 
60  /**
61  * Print event.
62  *
63  * \param out output stream
64  */
65  void print(std::ostream& out = std::cout) const
66  {
67  out << "Evt: id=" << id <<
68  " run_id=" << run_id <<
69  " #hits=" << hits.size() <<
70  " #mc_hits=" << mc_hits.size() <<
71  " #trks=" << trks.size() <<
72  " #mc_trks=" << mc_trks.size() << std::endl;
73  }
74 
75 
76  /**
77  * Get UTC time.
78  *
79  * \return time [ns]
80  */
81  double get_ns()
82  {
83  return this->t.GetSec()*1e9 + this->t.GetNanoSec();
84  }
85 
86  /**
87  * Reset event.
88  */
89  void clear()
90  {
91  *this = Evt();
92  }
93 
94  /**
95  * Clear the hit vectors and all the references to hits in the tracks
96  */
97  void clear_hits()
98  {
99  hits.clear();
100  mc_hits.clear();
101  for (auto& t: trks ) t.hit_ids.clear();
102  for (auto& t: mc_trks ) t.hit_ids.clear();
103  }
104 
105 
106  /**
107  * Get the original Monte-Carlo-time of the hit.
108  *
109  * Apply a correction to the hit time from the DAQ, so that the
110  * time returned by this fucntion matches the original time used
111  * in the Monte Carlo event.
112  *
113  * \param h hit
114  * \return time [ns]
115  */
116  double getMCtime(const Hit& h)
117  {
118  return h.t+this->get_ns() - this->mc_t;
119  }
120 
121  /**
122  * Get pointer to hit with given identifier.\n
123  * This method throws a run-time exception if no hit is available.
124  *
125  * \param req_id hit identifier
126  * \param use_mc_hits option to use MC hit
127  * \return pointer to hit.
128  */
129  Hit* get_hit_by_id( int req_id , bool use_mc_hits = false )
130  {
131  std::vector<Hit>& col = use_mc_hits? mc_hits : hits;
132 
133  if ( req_id < int(col.size()) ) // try to see if we are lucky
134  {
135  if ( col[req_id].id == req_id ) return &(col[id]);
136  }
137 
138  for( auto& h: col )
139  {
140  if ( h.id == req_id ) return &(col[id]);
141  }
142 
143  THROW(Exception, "Could not find hit with id=" << req_id);
144  }
145 
146 
147  /**
148  * Get all the tracks that are 'primary'.\n
149  * Here, primary means the tracks have no parents.
150  *
151  * Note that this method only works if MC parent-child relations are availabe.
152  *
153  * \return list of pointers to primary tracks
154  */
156  {
158  for(auto& t: mc_trks )
159  {
160  if ( t.is_primary() ) r.push_back(&t);
161  }
162  return r;
163  }
164 
165  /**
166  * Get a pointer to the (first) neutrino from the MC track list.
167  *
168  * \return pointers to neutrino (may be NULL)
169  */
171  {
172  for(auto& t: mc_trks )
173  {
174  if ( t.is_neutrino() ) return &t;
175  }
176  return nullptr;
177  }
178 
179  /**
180  * Get a pointer to primary neutrino from the MC track list.
181  *
182  * Note that this method only works if MC parent-child relations are availabe.
183  *
184  * \return pointer to primary neutrino (may be NULL)
185  */
187  {
188  for( auto& t : mc_trks )
189  {
190  if ( t.is_neutrino() and t.is_primary() ) return &t;
191  }
192  return nullptr;
193  }
194 
195  /**
196  * Get a pointer to leading lepton from the MC track list.
197  * Here, leading means the lepton that has a neutrino as mother.
198  *
199  * Note that this method only works if MC parent-child relations are availabe.
200  *
201  * \return pointer to leadig lepton (may be NULL)
202  */
204  {
205  int nu_id = primary_neutrino()->id;
206 
207  for(auto& t: mc_trks )
208  {
209  if ( t.is_lepton() &&
210  t.mother_id == nu_id &&
211  !t.is_orphan() ) return &t;
212  }
213  return nullptr;
214  }
215 
216  /**
217  * Get the (first) parent of the track 'child'.\n
218  * This method throws a run-time exception if no parent is available.
219  *
220  * \param child child particle
221  * \return pointer to parent
222  */
223  Trk* get_parent_of( Trk& child )
224  {
225  for(auto& t: mc_trks )
226  {
227  if (child.mother_id == t.id ) return &t;
228  }
229  THROW(Exception, "Failed to find parent of track" << child.id << " mother_id="<< child.mother_id);
230  }
231 
232  ClassDef(Evt,12)
233 };
234 
235 #endif
double getMCtime(const Hit &h)
Get the original Monte-Carlo-time of the hit.
Definition: Evt.hh:116
void clear_hits()
Clear the hit vectors and all the references to hits in the tracks.
Definition: Evt.hh:97
Trk * get_parent_of(Trk &child)
Get the (first) parent of the track &#39;child&#39;.
Definition: Evt.hh:223
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
ULong64_t trigger_counter
trigger counter
Definition: Evt.hh:30
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]]=w3 (see e.g. Tag list)
Definition: Evt.hh:39
data_type r[M+1]
Definition: JPolint.hh:709
double get_ns()
Get UTC time.
Definition: Evt.hh:81
int mother_id
MC id of the parent particle.
Definition: Trk.hh:27
Trk * primary_neutrino()
Get a pointer to primary neutrino from the MC track list.
Definition: Evt.hh:186
int frame_index
from the raw data
Definition: Evt.hh:28
unsigned int overlays
number of overlaying triggered events
Definition: Evt.hh:31
Trk * leading_lepton()
Get a pointer to leading lepton from the MC track list.
Definition: Evt.hh:203
int mc_run_id
MC run identifier.
Definition: Evt.hh:26
TString comment
user can use this as he/she likes
Definition: Evt.hh:48
Trk * neutrino()
Get a pointer to the (first) neutrino from the MC track list.
Definition: Evt.hh:170
int mc_id
identifier of the MC event (as found in ascii or antcc file).
Definition: Evt.hh:23
int run_id
DAQ run identifier.
Definition: Evt.hh:25
std::vector< Trk * > primary_trks()
Get all the tracks that are &#39;primary&#39;.
Definition: Evt.hh:155
double mc_t
MC: time of the mc event.
Definition: Evt.hh:43
int det_id
detector identifier from DAQ
Definition: Evt.hh:22
int id
track identifier
Definition: Trk.hh:14
#define ClassDef(name, version)
Definition: JRoot.hh:32
Definition: Hit.hh:8
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
TTimeStamp t
UTC time of the start of the timeslice the event came from.
Definition: Evt.hh:32
Evt()
Definition: Evt.hh:54
void print(std::ostream &out=std::cout) const
Print event.
Definition: Evt.hh:65
std::vector< Trk > trks
list of reconstructed tracks (can be several because of prefits,showers, etc).
Definition: Evt.hh:36
General exception.
Definition: Exception.hh:13
std::vector< Hit > mc_hits
MC: list of MC truth hits.
Definition: Evt.hh:44
double t
hit time (from calibration or MC truth)
Definition: Hit.hh:23
int flags
user can use this as he/she likes
Definition: Evt.hh:50
Hit * get_hit_by_id(int req_id, bool use_mc_hits=false)
Get pointer to hit with given identifier.
Definition: Evt.hh:129
int index
user can use this as he/she likes
Definition: Evt.hh:49
int id
offline event identifier
Definition: Evt.hh:21
void clear()
Reset event.
Definition: Evt.hh:89
std::vector< Hit > hits
list of hits
Definition: Evt.hh:35
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:12
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list)
Definition: Evt.hh:40
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition: Evt.hh:45
ULong64_t trigger_mask
trigger mask from raw data (i.e. the trigger bits)
Definition: Evt.hh:29
std::vector< double > w3list
MC: atmospheric flux information.
Definition: Evt.hh:41
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19