Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JHeadToolkit.hh
Go to the documentation of this file.
1#ifndef __JAANET_JHEADTOOLKIT__
2#define __JAANET_JHEADTOOLKIT__
3
4#include <string>
5#include <map>
6
10
13
14#include "JAAnet/JHead.hh"
15
16#include "Jeep/JVersion.hh"
17
18
19/**
20 * \author mdejong
21 */
22namespace JAANET {
23
26
27 /**
28 * Type definition of test function of header.
29 */
30 typedef bool (*is_head)(const JHead&);
31
32
33 /**
34 * Check for generator.
35 *
36 * \param header header
37 * \return true if this header is produced by genhen; else false
38 */
39 inline bool is_genhen(const JHead& header)
40 {
41 for (const auto& i : header.simul) {
42 if (i.program == APPLICATION_GENHEN) {
43 return true;
44 }
45 }
46
47 for (const auto& i : header.physics) { // legacy
48 if (i.buffer.find(APPLICATION_GENHEN) != std::string::npos) {
49 return true;
50 }
51 }
52
53 return false;
54 }
55
56
57 /**
58 * Check for generator.
59 *
60 * \param header header
61 * \return true if this header is produced by gSeaGen; else false
62 */
63 inline bool is_gseagen(const JHead& header)
64 {
65 for (const auto& i : header.simul) {
66 if (i.program == APPLICATION_GSEAGEN) {
67 return true;
68 }
69 }
70
71 for (const auto& i : header.physics) { // legacy
72 if (i.buffer.find(APPLICATION_GSEAGEN) != std::string::npos) {
73 return true;
74 }
75 }
76
77 return false;
78 }
79
80
81 /**
82 * Check for generator.
83 *
84 * \param header header
85 * \return true if this header is produced by MUPAGE; else false
86 */
87 inline bool is_mupage(const JHead& header)
88 {
89 for (const auto& i : header.simul) {
90 if (i.program == APPLICATION_MUPAGE) {
91 return true;
92 }
93 }
94
95 return false;
96 }
97
98
99 /**
100 * Check for generator.
101 *
102 * \param header header
103 * \return true if this header is produced by Corsika; else false
104 */
105 inline bool is_corsika(const JHead& header)
106 {
107 for (const auto& i : header.simul) {
108 if (i.program == APPLICATION_CORSIKA) {
109 return true;
110 }
111 }
112
113 return false;
114 }
115
116
117 /**
118 * Check for generator.
119 *
120 * \param header header
121 * \return true if this header is produced by km3buu; else false
122 */
123 inline bool is_km3buu(const JHead& header)
124 {
125 for (const auto& i : header.simul) {
126 if (i.program == APPLICATION_KM3BUU) {
127 return true;
128 }
129 }
130
131 return false;
132 }
133
134
135 /**
136 * Check for detector simulation.
137 *
138 * \param header header
139 * \return true if this header is processed with km3; else false
140 */
141 inline bool is_km3(const JHead& header)
142 {
143 for (const auto& i : header.simul) {
144 if (i.program == APPLICATION_KM3) {
145 return true;
146 }
147 }
148
149 return false;
150 }
151
152
153 /**
154 * Check for detector simulation.
155 *
156 * \param header header
157 * \return true if this header is processed with KM3Sim; else false
158 */
159 inline bool is_km3sim(const JHead& header)
160 {
161 for (const auto& i : header.simul) {
162 if (i.program == APPLICATION_KM3SIM) {
163 return true;
164 }
165 }
166
167 return false;
168 }
169
170
171 /**
172 * Check for detector simulation.
173 *
174 * \param header header
175 * \return true if this header is processed with JSirene; else false
176 */
177 inline bool is_sirene(const JHead& header)
178 {
179 for (const auto& i : header.simul) {
180 if (i.program == APPLICATION_JSIRENE) {
181 return true;
182 }
183 }
184
185 return false;
186 }
187
188
189 /**
190 * Check for generator.
191 *
192 * \param header header
193 * \return true if this header is produced by pure noise; else false
194 */
195 inline bool is_pure_noise(const JHead& header)
196 {
197 return header.K40.livetime_s > 0.0;
198 }
199
200
201 /**
202 * Check for real data.
203 *
204 * \param header header
205 * \return true if this header corresponds to real data; else false
206 */
207 inline bool is_daq(const JHead& header)
208 {
209 return header.DAQ.livetime_s > 0.0;
210 }
211
212
213 /**
214 * Check for Monte-Carlo simulations.
215 *
216 * \param header header
217 * \return true if this header corresponds to a Monte-Carlo simulation; else false
218 */
219 inline bool is_MC(const JHead& header)
220 {
221 return (is_gseagen(header) ||
222 is_mupage (header) ||
223 is_corsika(header) ||
224 is_km3buu (header) ||
225 is_genhen (header));
226 }
227
228
229 /**
230 * Auxiliary map of application to check method.
231 */
232 struct JHeadHelper :
233 public std::map<std::string, is_head>
234 {
235 /**
236 * Default constructor.
237 */
239 {
240 (*this)[APPLICATION_GENHEN] = is_genhen;
242 (*this)[APPLICATION_MUPAGE] = is_mupage;
244 (*this)[APPLICATION_KM3BUU] = is_km3buu;
245 (*this)[APPLICATION_KM3] = is_km3;
246 (*this)[APPLICATION_KM3SIM] = is_km3sim;
248 (*this)["DAQ"] = is_daq;
249 }
250
251
252 /**
253 * Get check method for given application.
254 *
255 * \param application application
256 * \return check method
257 */
258 is_head operator()(const std::string& application) const
259 {
260 return this->at(application);
261 }
262 };
263
264
265 /**
266 * Function object to get check method for given application.
267 */
269
270
271 /**
272 * Get offset.
273 *
274 * For consistency with the position of the detector,
275 * a pending offset should be added to the positions of generated tracks (i.e. Evt::mc_trks).
276 *
277 * The main logic can be summarised as follows.
278 * -# if
279 * JHead::fixedcan is defined, the values correspond to an offset that has already been applied,
280 * <tt>(0,0,0)</tt> is returned;
281 * -# else if
282 * JHead::can is defined, the values correspond to a z-range that has already been applied,
283 * <tt>(0,0,-zmin)</tt> is returned;
284 * -# else if
285 * JHead::coord_origin is defined, the values correspond to an offset that has not yet been applied,
286 * <tt>(x,y,z)</tt> is returned;
287 * -# else
288 * <tt>(0,0,0)</tt> is returned;
289 *
290 * \param header header
291 * \return position
292 */
293 inline Vec getOffset(const JHead& header)
294 {
295 if (header.is_valid(&JHead::fixedcan))
296 return Vec(0.0, 0.0, 0.0);
297 else if (header.is_valid(&JHead::can))
298 return Vec(0.0, 0.0, -header.can.zmin);
299 else if (header.is_valid(&JHead::coord_origin))
300 return header.coord_origin;
301 else
302 return Vec(0.0, 0.0, 0.0);
303 }
304
305
306 /**
307 * Get origin.
308 *
309 * The origin corresponds to the offset that has already been applied to the positions of generated tracks (i.e. Evt::mc_trks).
310 *
311 * The main logic can be summarised as follows.
312 * -# if
313 * JHead::fixedcan is defined, the values correspond to the offset that has already been applied,
314 * <tt>(x,y,0)</tt> is returned;
315 * -# else if
316 * JHead::can is defined, the values correspond to a z-range that has already been applied,
317 * <tt>(0,0,zmin)</tt> is returned;
318 * -# else if
319 * JHead::coord_origin is defined, the values correspond to the offset that has not yet been applied,
320 * <tt>(0,0,0)</tt> is returned;
321 * -# else
322 * <tt>(0,0,0)</tt> is returned;
323 *
324 * \param header header
325 * \return position
326 */
327 inline Vec getOrigin(const JHead& header)
328 {
329 if (header.is_valid(&JHead::fixedcan))
330 return Vec(header.fixedcan.xcenter, header.fixedcan.ycenter, 0.0);
331 else if (header.is_valid(&JHead::can))
332 return Vec(0.0, 0.0, header.can.zmin);
333 else if (header.is_valid(&JHead::coord_origin))
334 return Vec(0.0, 0.0, 0.0);
335 else
336 return Vec(0.0, 0.0, 0.0);
337 }
338
339
340 /**
341 * Get cylinder corresponding to the positions of generated tracks (i.e. Evt::mc_trks).
342 *
343 * For consistency with the position of the detector,
344 * the pending offset (see method JAANET::getOffset) should be added to the position of cylinder.
345 *
346 * \param header header
347 * \return cylinder
348 */
349 inline JCylinder3D getCylinder(const JHead& header)
350 {
351 using namespace JPP;
352
353 if (header.is_valid(&JHead::fixedcan)) {
354
356 header.fixedcan.ycenter),
357 header.fixedcan.radius),
358 header.fixedcan.zmin,
359 header.fixedcan.zmax);
360
361 } else if (header.is_valid(&JHead::can)) {
362
363 return JCylinder3D(JCircle2D(JVector2D(), header.can.r),
364 header.can.zmin,
365 header.can.zmax);
366 } else {
367
368 return JCylinder3D();
369 }
370 }
371
372
373 /**
374 * MUPAGE minimal version using weights.
375 */
377
378
379 /**
380 * Check for generator.
381 *
382 * \param header header
383 * \return true if this header is produced by MUPAGE using weights; else false
384 */
385 inline bool has_mupage_weights(const JHead& header)
386 {
387 for (const auto& i : header.simul) {
388
389 if (i.program == APPLICATION_MUPAGE) {
390
391 std::string buffer = i.version;
392
393 if (!buffer.empty()) {
394
395 if (buffer[0] == 'v' ||
396 buffer[0] == 'V') {
397 buffer.erase(0,1);
398 }
399
400 const JEEP::JVersion version(buffer);
401
402 return version >= MUPAGE_MINIMAL_VERSION;
403 }
404 }
405 }
406
407 return false;
408 }
409}
410
411#endif
static const char *const APPLICATION_KM3SIM
detector simulation
static const char *const APPLICATION_KM3BUU
event generator
static const char *const APPLICATION_GENHEN
ile KM3NeT Data Definitions v3.6.5 https://git.km3net.de/common/km3net-dataformat
static const char *const APPLICATION_GSEAGEN
event generator
static const char *const APPLICATION_JSIRENE
detector simulation
static const char *const APPLICATION_MUPAGE
event generator
static const char *const APPLICATION_CORSIKA
event generator
static const char *const APPLICATION_KM3
detector simulation
Monte Carlo run header.
Definition JHead.hh:1236
std::vector< JAANET::simul > simul
Definition JHead.hh:1609
JAANET::coord_origin coord_origin
Definition JHead.hh:1619
JAANET::DAQ DAQ
Definition JHead.hh:1625
JAANET::can can
Definition JHead.hh:1616
JAANET::fixedcan fixedcan
Definition JHead.hh:1617
JAANET::K40 K40
Definition JHead.hh:1626
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition JHead.hh:1319
std::vector< JAANET::physics > physics
Definition JHead.hh:1608
Data structure for circle in two dimensions.
Definition JCircle2D.hh:35
Data structure for vector in two dimensions.
Definition JVector2D.hh:34
Data structure for position in three dimensions.
Extensions to Evt data format.
bool is_genhen(const JHead &header)
Check for generator.
Vec getOrigin(const JHead &header)
Get origin.
bool is_daq(const JHead &header)
Check for real data.
bool is_km3sim(const JHead &header)
Check for detector simulation.
bool is_corsika(const JHead &header)
Check for generator.
JCylinder3D getCylinder(const JHead &header)
Get cylinder corresponding to the positions of generated tracks (i.e.
bool is_MC(const JHead &header)
Check for Monte-Carlo simulations.
bool is_pure_noise(const JHead &header)
Check for generator.
static const JEEP::JVersion MUPAGE_MINIMAL_VERSION(6, 0, 2)
MUPAGE minimal version using weights.
bool is_sirene(const JHead &header)
Check for detector simulation.
bool is_gseagen(const JHead &header)
Check for generator.
bool has_mupage_weights(const JHead &header)
Check for generator.
static JHeadHelper get_is_head
Function object to get check method for given application.
bool(* is_head)(const JHead &)
Type definition of test function of header.
bool is_mupage(const JHead &header)
Check for generator.
Vec getOffset(const JHead &header)
Get offset.
bool is_km3buu(const JHead &header)
Check for generator.
bool is_km3(const JHead &header)
Check for detector simulation.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double livetime_s
Live time [s].
Definition JHead.hh:1053
Auxiliary map of application to check method.
is_head operator()(const std::string &application) const
Get check method for given application.
JHeadHelper()
Default constructor.
double livetime_s
Live time [s].
Definition JHead.hh:1107
double zmin
Bottom [m].
Definition JHead.hh:598
double zmax
Top [m].
Definition JHead.hh:599
double r
Radius [m].
Definition JHead.hh:600
double zmax
Top [m].
Definition JHead.hh:639
double radius
Radius [m].
Definition JHead.hh:640
double zmin
Bottom [m].
Definition JHead.hh:638
double ycenter
y-center [m]
Definition JHead.hh:637
double xcenter
x-center [m]
Definition JHead.hh:636
Auxiliary data structure for general purpose version number.
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition Vec.hh:13