Jpp test-rotations-old
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
17/**
18 * \author mdejong
19 */
20namespace JAANET {
21
24
25 /**
26 * Type definition of test function of header.
27 */
28 typedef bool (*is_head)(const JHead&);
29
30
31 /**
32 * Check for generator.
33 *
34 * \param header header
35 * \return true if this header is produced by genhen; else false
36 */
37 inline bool is_genhen(const JHead& header)
38 {
39 for (const auto& i : header.simul) {
40 if (i.program == APPLICATION_GENHEN) {
41 return true;
42 }
43 }
44
45 for (const auto& i : header.physics) { // legacy
46 if (i.buffer.find(APPLICATION_GENHEN) != std::string::npos) {
47 return true;
48 }
49 }
50
51 return false;
52 }
53
54
55 /**
56 * Check for generator.
57 *
58 * \param header header
59 * \return true if this header is produced by gSeaGen; else false
60 */
61 inline bool is_gseagen(const JHead& header)
62 {
63 for (const auto& i : header.simul) {
64 if (i.program == APPLICATION_GSEAGEN) {
65 return true;
66 }
67 }
68
69 for (const auto& i : header.physics) { // legacy
70 if (i.buffer.find(APPLICATION_GSEAGEN) != std::string::npos) {
71 return true;
72 }
73 }
74
75 return false;
76 }
77
78
79 /**
80 * Check for generator.
81 *
82 * \param header header
83 * \return true if this header is produced by MUPAGE; else false
84 */
85 inline bool is_mupage(const JHead& header)
86 {
87 for (const auto& i : header.simul) {
88 if (i.program == APPLICATION_MUPAGE) {
89 return true;
90 }
91 }
92
93 return false;
94 }
95
96
97 /**
98 * Check for generator.
99 *
100 * \param header header
101 * \return true if this header is produced by Corsika; else false
102 */
103 inline bool is_corsika(const JHead& header)
104 {
105 for (const auto& i : header.simul) {
106 if (i.program == APPLICATION_CORSIKA) {
107 return true;
108 }
109 }
110
111 return false;
112 }
113
114
115 /**
116 * Check for generator.
117 *
118 * \param header header
119 * \return true if this header is produced by km3buu; else false
120 */
121 inline bool is_km3buu(const JHead& header)
122 {
123 for (const auto& i : header.simul) {
124 if (i.program == APPLICATION_KM3BUU) {
125 return true;
126 }
127 }
128
129 return false;
130 }
131
132
133 /**
134 * Check for detector simulation.
135 *
136 * \param header header
137 * \return true if this header is processed with km3; else false
138 */
139 inline bool is_km3(const JHead& header)
140 {
141 for (const auto& i : header.simul) {
142 if (i.program == APPLICATION_KM3) {
143 return true;
144 }
145 }
146
147 return false;
148 }
149
150
151 /**
152 * Check for detector simulation.
153 *
154 * \param header header
155 * \return true if this header is processed with KM3Sim; else false
156 */
157 inline bool is_km3sim(const JHead& header)
158 {
159 for (const auto& i : header.simul) {
160 if (i.program == APPLICATION_KM3SIM) {
161 return true;
162 }
163 }
164
165 return false;
166 }
167
168
169 /**
170 * Check for detector simulation.
171 *
172 * \param header header
173 * \return true if this header is processed with JSirene; else false
174 */
175 inline bool is_sirene(const JHead& header)
176 {
177 for (const auto& i : header.simul) {
178 if (i.program == APPLICATION_JSIRENE) {
179 return true;
180 }
181 }
182
183 return false;
184 }
185
186
187 /**
188 * Check for generator.
189 *
190 * \param header header
191 * \return true if this header is produced by pure noise; else false
192 */
193 inline bool is_pure_noise(const JHead& header)
194 {
195 return header.K40.livetime_s > 0.0;
196 }
197
198
199 /**
200 * Check for real data.
201 *
202 * \param header header
203 * \return true if this header corresponds to real data; else false
204 */
205 inline bool is_daq(const JHead& header)
206 {
207 return header.DAQ.livetime_s > 0.0;
208 }
209
210
211 /**
212 * Check for Monte-Carlo simulations.
213 *
214 * \param header header
215 * \return true if this header corresponds to a Monte-Carlo simulation; else false
216 */
217 inline bool is_MC(const JHead& header)
218 {
219 return (is_gseagen(header) ||
220 is_mupage (header) ||
221 is_corsika(header) ||
222 is_km3buu (header) ||
223 is_genhen (header));
224 }
225
226
227 /**
228 * Auxiliary map of application to check method.
229 */
230 struct JHeadHelper :
231 public std::map<std::string, is_head>
232 {
233 /**
234 * Default constructor.
235 */
237 {
238 (*this)[APPLICATION_GENHEN] = is_genhen;
240 (*this)[APPLICATION_MUPAGE] = is_mupage;
242 (*this)[APPLICATION_KM3BUU] = is_km3buu;
243 (*this)[APPLICATION_KM3] = is_km3;
244 (*this)[APPLICATION_KM3SIM] = is_km3sim;
246 (*this)["DAQ"] = is_daq;
247 }
248
249
250 /**
251 * Get check method for given application.
252 *
253 * \param application application
254 * \return check method
255 */
256 is_head operator()(const std::string& application) const
257 {
258 return this->at(application);
259 }
260 };
261
262
263 /**
264 * Function object to get check method for given application.
265 */
267
268
269 /**
270 * Get offset.
271 *
272 * For consistency with the position of the detector,
273 * a pending offset should be added to the positions of generated tracks (i.e. Evt::mc_trks).
274 *
275 * The main logic can be summarised as follows.
276 * -# if
277 * JHead::fixedcan is defined, the values correspond to an offset that has already been applied,
278 * <tt>(0,0,0)</tt> is returned;
279 * -# else if
280 * JHead::can is defined, the values correspond to a z-range that has already been applied,
281 * <tt>(0,0,-zmin)</tt> is returned;
282 * -# else if
283 * JHead::coord_origin is defined, the values correspond to an offset that has not yet been applied,
284 * <tt>(x,y,z)</tt> is returned;
285 * -# else
286 * <tt>(0,0,0)</tt> is returned;
287 *
288 * \param header header
289 * \return position
290 */
291 inline Vec getOffset(const JHead& header)
292 {
293 if (header.is_valid(&JHead::fixedcan))
294 return Vec(0.0, 0.0, 0.0);
295 else if (header.is_valid(&JHead::can))
296 return Vec(0.0, 0.0, -header.can.zmin);
297 else if (header.is_valid(&JHead::coord_origin))
298 return header.coord_origin;
299 else
300 return Vec(0.0, 0.0, 0.0);
301 }
302
303
304 /**
305 * Get origin.
306 *
307 * The origin corresponds to the offset that has already been applied to the positions of generated tracks (i.e. Evt::mc_trks).
308 *
309 * The main logic can be summarised as follows.
310 * -# if
311 * JHead::fixedcan is defined, the values correspond to the offset that has already been applied,
312 * <tt>(x,y,0)</tt> is returned;
313 * -# else if
314 * JHead::can is defined, the values correspond to a z-range that has already been applied,
315 * <tt>(0,0,zmin)</tt> is returned;
316 * -# else if
317 * JHead::coord_origin is defined, the values correspond to the offset that has not yet been applied,
318 * <tt>(0,0,0)</tt> is returned;
319 * -# else
320 * <tt>(0,0,0)</tt> is returned;
321 *
322 * \param header header
323 * \return position
324 */
325 inline Vec getOrigin(const JHead& header)
326 {
327 if (header.is_valid(&JHead::fixedcan))
328 return Vec(header.fixedcan.xcenter, header.fixedcan.ycenter, 0.0);
329 else if (header.is_valid(&JHead::can))
330 return Vec(0.0, 0.0, header.can.zmin);
331 else if (header.is_valid(&JHead::coord_origin))
332 return Vec(0.0, 0.0, 0.0);
333 else
334 return Vec(0.0, 0.0, 0.0);
335 }
336
337
338 /**
339 * Get cylinder corresponding to the positions of generated tracks (i.e. Evt::mc_trks).
340 *
341 * For consistency with the position of the detector,
342 * the pending offset (see method JAANET::getOffset) should be added to the position of cylinder.
343 *
344 * \param header header
345 * \return cylinder
346 */
347 inline JCylinder3D getCylinder(const JHead& header)
348 {
349 using namespace JPP;
350
351 if (header.is_valid(&JHead::fixedcan)) {
352
354 header.fixedcan.ycenter),
355 header.fixedcan.radius),
356 header.fixedcan.zmin,
357 header.fixedcan.zmax);
358
359 } else if (header.is_valid(&JHead::can)) {
360
361 return JCylinder3D(JCircle2D(JVector2D(), header.can.r),
362 header.can.zmin,
363 header.can.zmax);
364 } else {
365
366 return JCylinder3D();
367 }
368 }
369}
370
371#endif
static const char *const APPLICATION_KM3SIM
detector simulation
static const char *const APPLICATION_KM3BUU
event generator
static const char *const APPLICATION_GENHEN
KM3NeT Data Definitions v3.6.0 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:1591
JAANET::coord_origin coord_origin
Definition JHead.hh:1601
JAANET::DAQ DAQ
Definition JHead.hh:1607
JAANET::can can
Definition JHead.hh:1598
JAANET::fixedcan fixedcan
Definition JHead.hh:1599
JAANET::K40 K40
Definition JHead.hh:1608
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:1590
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.
bool is_sirene(const JHead &header)
Check for detector simulation.
bool is_gseagen(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
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition Vec.hh:13