Jpp  17.2.1-pre0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JAAnetTestkit.hh
Go to the documentation of this file.
1 #ifndef __JAANETTESTKIT__
2 #define __JAANETTESTKIT__
3 
4 #include "TRandom3.h"
5 
8 #include "JAAnet/JPDB.hh"
9 
10 #include "JMath/JRandom.hh"
11 
12 /**
13  * \author mdejong
14  */
15 
16 using JMATH::getRandom;
17 
18 
19 /**
20  * Global file format parameter.
21  */
22 static bool use_root;
23 
24 
25 /**
26  * Randomize 3D vector.
27  *
28  * \param p pointer to valid object
29  */
30 inline void randomize(Vec* p)
31 {
32  p->x = getRandom<double>();
33  p->y = getRandom<double>();
34  p->z = getRandom<double>();
35 };
36 
37 
38 /**
39  * Type definition for position.
40  */
41 struct pos_type : public Vec {};
42 
43 
44 /**
45  * Randomize position.
46  *
47  * \param p pointer to valid object
48  */
49 inline void randomize(pos_type* p)
50 {
51  p->x = getRandom<double>(-1.0e4, +1.0e4, 1.0);
52  p->y = getRandom<double>(-1.0e4, +1.0e4, 1.0);
53  p->z = getRandom<double>(-1.0e4, +1.0e4, 1.0);
54 };
55 
56 
57 /**
58  * Type definition for direction.
59  */
60 struct dir_type : public Vec {};
61 
62 
63 /**
64  * Randomize direction.
65  *
66  * \param p pointer to valid object
67  */
68 inline void randomize(dir_type* p)
69 {
70  p->x = getRandom<double>(-1.0, +1.0, 1.0e-3);
71  p->y = getRandom<double>(-1.0, +1.0, 1.0e-3);
72  p->z = getRandom<double>(-1.0, +1.0, 1.0e-3);
73 };
74 
75 
76 /**
77  * Randomize hit.
78  *
79  * \param p pointer to valid object
80  */
81 inline void randomize(Hit* p)
82 {
83  p->id = getRandom<int>(0, 1000);
84  if (use_root) {
85  p->dom_id = getRandom<int>(0, 1000);
86  p->channel_id = getRandom<unsigned int>(0, 31);
87  p->tdc = getRandom<unsigned int>();
88  p->tot = getRandom<unsigned int>(0, 256);
89  p->trig = getRandom<int>(0, 1000);
90  }
91  p->pmt_id = getRandom<int>(0, 1000);
92  p->t = getRandom<double>(0.0, 100.0e6, 0.1);
93  p->a = getRandom<double>(0.0, 100.0e0, 0.1);
94  if (use_root) {
95  p->pos = getRandom<pos_type>();
96  p->dir = getRandom<dir_type>();
97  }
98  p->type = getRandom<int>(0, 1000);
99  p->origin = getRandom<int>(0, 1000);
100 }
101 
102 
103 /**
104  * PDG particle type.
105  */
106 struct pdg_type {
107 
108  operator int() const { return type; }
109 
110  int type;
111 };
112 
113 
114 /**
115  * Randomize PDG particle type.
116  *
117  * \param p pointer to valid object
118  */
119 inline void randomize(pdg_type* p)
120 {
121  using namespace JAANET;
122 
123  const JPDB& pdb = JPDB::getInstance();
124 
125  for ( ; ; ) {
126 
127  const JParticle& particle = pdb[getRandom<int>(0, pdb.size())];
128 
129  if ( (use_root) || (particle.geant != GEANT4_TYPE_NEUTRINO && particle.geant != 0) ) {
130 
131  p->type = abs(particle.pdg);
132 
133  return;
134  }
135  }
136 }
137 
138 
139 /**
140  * Randomize track.
141  *
142  * \param p pointer to valid object
143  */
144 inline void randomize(Trk* p)
145 {
146  p->id = getRandom<int>(0, 1000);
147  p->pos = getRandom<pos_type>();
148  p->dir = getRandom<dir_type>();
149  p->t = getRandom<double>(0.0, 1.0e6, 1.0);
150  p->E = getRandom<double>(1.0, 1.0e6, 1.0);
151  if (use_root) {
152  p->len = getRandom<double>();
153  p->lik = getRandom<double>();
154  }
155  p->type = getRandom<pdg_type>();
156 
157  p->comment = "track_in:"; // aanet storage specifier
158 }
159 
160 
161 /**
162  * Randomize event.
163  *
164  * \param p pointer to valid object
165  */
166 inline void randomize(Evt* p)
167 {
168  new (p) Evt();
169 
170  if (use_root) {
171  p->id = getRandom<int>(0, 1000);
172  p->det_id = getRandom<int>(0, 1000);
173  }
174  p->mc_id = getRandom<int>(0, 1000);
175  if (use_root) {
176  p->run_id = getRandom<int>(0, 1000);
177  p->mc_run_id = getRandom<int>(0, 1000);
178  p->frame_index = getRandom<int>(0, 1000);
179  p->trigger_mask = getRandom<ULong64_t>(0, 1000);
180  p->trigger_counter = getRandom<ULong64_t>(0, 1000);
181  }
182 
183  for (int i = getRandom<int>(1, 1000); i != 0; --i) {
184  p->mc_hits.push_back(getRandom<Hit>());
185  }
186 
187  for (int i = getRandom<int>(1, 100); i != 0; --i) {
188  p->mc_trks.push_back(getRandom<Trk>());
189  }
190 
191  if (use_root) {
192 
193  for (int i = getRandom<int>(1, 1000); i != 0; --i) {
194  p->hits.push_back(getRandom<Hit>());
195  }
196 
197  for (int i = getRandom<int>(1, 100); i != 0; --i) {
198  p->trks.push_back(getRandom<Trk>());
199  }
200  }
201 }
202 
203 
204 /**
205  * Equal operator hit.
206  *
207  * \param first first hit
208  * \param second second hit
209  * \return true if hits are equal; else false
210  */
211 inline bool operator==(const Hit& first, const Hit& second)
212 {
213  return (first.id == second.id &&
214  first.channel_id == second.channel_id &&
215  first.tdc == second.tdc &&
216  first.tot == second.tot &&
217  first.trig == second.trig &&
218  first.pmt_id == second.pmt_id &&
219  first.t == second.t &&
220  first.a == second.a &&
221  first.pos == second.pos &&
222  first.dir == second.dir &&
223  first.type == second.type &&
224  first.origin == second.origin);
225 }
226 
227 
228 /**
229  * Equal operator track.
230  *
231  * \param first first track
232  * \param second second track
233  * \return true if tracks are equal; else false
234  */
235 inline bool operator==(const Trk& first, const Trk& second)
236 {
237  return (first.id == second.id &&
238  first.pos == second.pos &&
239  first.dir == second.dir &&
240  first.t == second.t &&
241  first.E == second.E &&
242  first.len == second.len &&
243  first.lik == second.lik &&
244  first.type == second.type &&
245  first.rec_type == second.rec_type &&
246  first.rec_stages == second.rec_stages &&
247  first.fitinf == second.fitinf &&
248  first.hit_ids == second.hit_ids &&
249  first.error_matrix == second.error_matrix);
250 }
251 
252 
253 /**
254  * Equal operator event.
255  *
256  * \param first first event
257  * \param second second event
258  * \return true if events are equal; else false
259  */
260 inline bool operator==(const Evt& first, const Evt& second)
261 {
262  return (first.id == second.id &&
263  first.det_id == second.det_id &&
264  first.mc_id == second.mc_id &&
265  first.run_id == second.run_id &&
266  first.mc_run_id == second.mc_run_id &&
267  first.frame_index == second.frame_index &&
268  first.trigger_mask == second.trigger_mask &&
269  first.trigger_counter == second.trigger_counter &&
270  first.hits == second.hits &&
271  first.trks == second.trks &&
272  first.mc_hits == second.mc_hits &&
273  first.mc_trks == second.mc_trks);
274 }
275 
276 #endif
Vec pos
hit position
Definition: Hit.hh:25
double t
track time [ns] (when the particle is at pos )
Definition: Trk.hh:19
double z
Definition: Vec.hh:14
Vec dir
track direction
Definition: Trk.hh:18
std::string comment
use as you like
Definition: Trk.hh:35
int pmt_id
global PMT identifier as found in evt files
Definition: Hit.hh:20
ULong64_t trigger_counter
trigger counter
Definition: Evt.hh:31
Definition of random value generator.
unsigned int tdc
hit tdc (=time in ns)
Definition: Hit.hh:16
static bool use_root
Global file format parameter.
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:20
Collection of particles.
Definition: JPDB.hh:109
double y
Definition: Vec.hh:14
int origin
track id of the track that created this hit (mc only)
Definition: Hit.hh:29
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
static const JPDB & getInstance()
Get particle data book.
Definition: JPDB.hh:125
double a
hit amplitude (in p.e.)
Definition: Hit.hh:24
double x
Definition: Vec.hh:14
int frame_index
from the raw data
Definition: Evt.hh:29
bool operator==(Packet const &p, ID const &id)
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
Type definition for direction.
int mc_run_id
MC run identifier.
Definition: Evt.hh:27
std::vector< int > hit_ids
list of associated hit-ids (corresponds to Hit::id).
Definition: Trk.hh:33
int mc_id
identifier of the MC event (as found in ascii or antcc file).
Definition: Evt.hh:24
std::vector< double > fitinf
place to store additional fit info, see km3net-dataformat/definitions/fitparameters.csv
Definition: Trk.hh:32
double len
length, if applicable [m]
Definition: Trk.hh:22
int run_id
DAQ run identifier.
Definition: Evt.hh:26
int id
Definition: Hit.hh:11
Vec dir
hit direction; i.e. direction of the PMT
Definition: Hit.hh:26
int det_id
detector identifier from DAQ
Definition: Evt.hh:23
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:24
int id
track identifier
Definition: Trk.hh:16
Auxiliary class to handle particle name, codes and mass.
Definition: JPDB.hh:37
Vec pos
postion [m] of the track at time t
Definition: Trk.hh:17
Definition: Hit.hh:8
std::vector< Trk > trks
list of reconstructed tracks (can be several because of prefits,showers, etc).
Definition: Evt.hh:39
int geant
GEANT code of particle.
Definition: JPDB.hh:91
std::vector< int > rec_stages
list of identifyers of succesfull fitting stages resulting in this track
Definition: Trk.hh:26
std::vector< double > error_matrix
(NxN) error covariance matrix for fit parameters (stored as linear vector)
Definition: Trk.hh:34
ULong64_t trig
non-zero if the hit is a trigger hit.
Definition: Hit.hh:18
double lik
likelihood or lambda value (for aafit, lambda)
Definition: Trk.hh:23
std::vector< Hit > mc_hits
MC: list of MC truth hits.
Definition: Evt.hh:48
double t
hit time (from tdc+calibration or MC truth)
Definition: Hit.hh:23
int dom_id
module identifier from the data (unique in the detector).
Definition: Hit.hh:14
unsigned int tot
tot value as stored in raw data (int for pyroot)
Definition: Hit.hh:17
T getRandom()
Get random value.
Definition: JRandom.hh:113
int id
offline event identifier
Definition: Evt.hh:22
unsigned int channel_id
PMT channel id {0,1, .., 30} local to moduke.
Definition: Hit.hh:15
std::vector< Hit > hits
list of hits
Definition: Evt.hh:38
int pdg
PDG code of particle.
Definition: JPDB.hh:90
PDG particle type.
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:14
int type
particle type or parametrisation used for hit (mc only)
Definition: Hit.hh:28
void randomize(Vec *p)
Randomize 3D vector.
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition: Evt.hh:49
Type definition for position.
ULong64_t trigger_mask
trigger mask from raw data (i.e. the trigger bits)
Definition: Evt.hh:30
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20
int rec_type
identifier of the fitting algorithm/chain/strategy, see km3net-dataformat/definitions/reconstruction...
Definition: Trk.hh:25