Jpp master_rocky-44-g75b7c4f75
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 * Auxiliary map of application to check method.
213 */
214 struct JHeadHelper :
215 public std::map<std::string, is_head>
216 {
217 /**
218 * Default constructor.
219 */
221 {
222 (*this)[APPLICATION_GENHEN] = is_genhen;
224 (*this)[APPLICATION_MUPAGE] = is_mupage;
226 (*this)[APPLICATION_KM3BUU] = is_km3buu;
227 (*this)[APPLICATION_KM3] = is_km3;
228 (*this)[APPLICATION_KM3SIM] = is_km3sim;
230 (*this)["DAQ"] = is_daq;
231 }
232
233
234 /**
235 * Get check method for given application.
236 *
237 * \param application application
238 * \return check method
239 */
240 is_head operator()(const std::string& application) const
241 {
242 return this->at(application);
243 }
244 };
245
246
247 /**
248 * Function object to get check method for given application.
249 */
251
252
253 /**
254 * Get offset.
255 *
256 * For consistency with the position of the detector,
257 * a pending offset should be added to the positions of generated tracks (i.e. Evt::mc_trks).
258 *
259 * The main logic can be summarised as follows.
260 * -# if
261 * JHead::fixedcan is defined, the values correspond to an offset that has already been applied,
262 * <tt>(0,0,0)</tt> is returned;
263 * -# else if
264 * JHead::can is defined, the values correspond to a z-range that has already been applied,
265 * <tt>(0,0,-zmin)</tt> is returned;
266 * -# else if
267 * JHead::coord_origin is defined, the values correspond to an offset that has not yet been applied,
268 * <tt>(x,y,z)</tt> is returned;
269 * -# else
270 * <tt>(0,0,0)</tt> is returned;
271 *
272 * \param header header
273 * \return position
274 */
275 inline Vec getOffset(const JHead& header)
276 {
277 if (header.is_valid(&JHead::fixedcan))
278 return Vec(0.0, 0.0, 0.0);
279 else if (header.is_valid(&JHead::can))
280 return Vec(0.0, 0.0, -header.can.zmin);
281 else if (header.is_valid(&JHead::coord_origin))
282 return header.coord_origin;
283 else
284 return Vec(0.0, 0.0, 0.0);
285 }
286
287
288 /**
289 * Get origin.
290 *
291 * The origin corresponds to the offset that has already been applied to the positions of generated tracks (i.e. Evt::mc_trks).
292 *
293 * The main logic can be summarised as follows.
294 * -# if
295 * JHead::fixedcan is defined, the values correspond to the offset that has already been applied,
296 * <tt>(x,y,0)</tt> is returned;
297 * -# else if
298 * JHead::can is defined, the values correspond to a z-range that has already been applied,
299 * <tt>(0,0,zmin)</tt> is returned;
300 * -# else if
301 * JHead::coord_origin is defined, the values correspond to the offset that has not yet been applied,
302 * <tt>(0,0,0)</tt> is returned;
303 * -# else
304 * <tt>(0,0,0)</tt> is returned;
305 *
306 * \param header header
307 * \return position
308 */
309 inline Vec getOrigin(const JHead& header)
310 {
311 if (header.is_valid(&JHead::fixedcan))
312 return Vec(header.fixedcan.xcenter, header.fixedcan.ycenter, 0.0);
313 else if (header.is_valid(&JHead::can))
314 return Vec(0.0, 0.0, header.can.zmin);
315 else if (header.is_valid(&JHead::coord_origin))
316 return Vec(0.0, 0.0, 0.0);
317 else
318 return Vec(0.0, 0.0, 0.0);
319 }
320
321
322 /**
323 * Get cylinder corresponding to the positions of generated tracks (i.e. Evt::mc_trks).
324 *
325 * For consistency with the position of the detector,
326 * the pending offset (see method JAANET::getOffset) should be added to the position of cylinder.
327 *
328 * \param header header
329 * \return cylinder
330 */
331 inline JCylinder3D getCylinder(const JHead& header)
332 {
333 using namespace JPP;
334
335 if (header.is_valid(&JHead::fixedcan)) {
336
338 header.fixedcan.ycenter),
339 header.fixedcan.radius),
340 header.fixedcan.zmin,
341 header.fixedcan.zmax);
342
343 } else if (header.is_valid(&JHead::can)) {
344
345 return JCylinder3D(JCircle2D(JVector2D(), header.can.r),
346 header.can.zmin,
347 header.can.zmax);
348 } else {
349
350 return JCylinder3D();
351 }
352 }
353}
354
355#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.4.0-8-ge14cb17 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_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