Jpp  18.3.0-209-g56ce19a
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  */
20 namespace 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 real data.
189  *
190  * \param header header
191  * \return true if this header corresponds to real data; else false
192  */
193  inline bool is_daq(const JHead& header)
194  {
195  return header.DAQ.livetime_s > 0.0;
196  }
197 
198 
199  /**
200  * Auxiliary map of application to check method.
201  */
202  struct JHeadHelper :
203  public std::map<std::string, is_head>
204  {
205  /**
206  * Default constructor.
207  */
209  {
210  (*this)[APPLICATION_GENHEN] = is_genhen;
211  (*this)[APPLICATION_GSEAGEN] = is_gseagen;
212  (*this)[APPLICATION_MUPAGE] = is_mupage;
213  (*this)[APPLICATION_CORSIKA] = is_corsika;
214  (*this)[APPLICATION_KM3BUU] = is_km3buu;
215  (*this)[APPLICATION_KM3] = is_km3;
216  (*this)[APPLICATION_KM3SIM] = is_km3sim;
217  (*this)[APPLICATION_JSIRENE] = is_sirene;
218  (*this)["DAQ"] = is_daq;
219  }
220 
221 
222  /**
223  * Get check method for given application.
224  *
225  * \param application application
226  * \return check method
227  */
228  is_head operator()(const std::string& application) const
229  {
230  return this->at(application);
231  }
232  };
233 
234 
235  /**
236  * Function object to get check method for given application.
237  */
239 
240 
241  /**
242  * Get offset.
243  *
244  * For consistency with the position of the detector,
245  * a pending offset should be added to the positions of generated tracks (i.e. Evt::mc_trks).
246  *
247  * The main logic can be summarised as follows.
248  * -# if
249  * JHead::fixedcan is defined, the values correspond to an offset that has already been applied,
250  * <tt>(0,0,0)</tt> is returned;
251  * -# else if
252  * JHead::coord_origin is defined, the values correspond to an offset that has not yet been applied,
253  * <tt>(x,y,z)</tt> is returned;
254  * -# else if
255  * JHead::can is defined, the values correspond to a z-range that has already been applied,
256  * <tt>(0,0,-zmin)</tt> is returned;
257  * -# else
258  * <tt>(0,0,0)</tt> is returned;
259  *
260  * \param header header
261  * \return position
262  */
263  inline Vec getOffset(const JHead& header)
264  {
265  if (header.is_valid(&JHead::fixedcan))
266  return Vec(0.0, 0.0, 0.0);
267  else if (header.is_valid(&JHead::coord_origin))
268  return header.coord_origin;
269  else if (header.is_valid(&JHead::can))
270  return Vec(0.0, 0.0, -header.can.zmin);
271  else
272  return Vec(0.0, 0.0, 0.0);
273  }
274 
275 
276  /**
277  * Get origin.
278  *
279  * The origin corresponds to the offset that has already been applied to the positions of generated tracks (i.e. Evt::mc_trks).
280  *
281  * The main logic can be summarised as follows.
282  * -# if
283  * JHead::fixedcan is defined, the values correspond to the offset that has already been applied,
284  * <tt>(x,y,0)</tt> is returned;
285  * -# else if
286  * JHead::coord_origin is defined, the values correspond to the offset that has not yet been applied,
287  * <tt>(0,0,0)</tt> is returned;
288  * -# else if
289  * JHead::can is defined, the values correspond to a z-range that has already been applied,
290  * <tt>(0,0,zmin)</tt> is returned;
291  * -# else
292  * <tt>(0,0,0)</tt> is returned;
293  *
294  * \param header header
295  * \return position
296  */
297  inline Vec getOrigin(const JHead& header)
298  {
299  if (header.is_valid(&JHead::fixedcan))
300  return Vec(header.fixedcan.xcenter, header.fixedcan.ycenter, 0.0);
301  else if (header.is_valid(&JHead::coord_origin))
302  return Vec(0.0, 0.0, 0.0);
303  else if (header.is_valid(&JHead::can))
304  return Vec(0.0, 0.0, header.can.zmin);
305  else
306  return Vec(0.0, 0.0, 0.0);
307  }
308 
309 
310  /**
311  * Get cylinder corresponding to the positions of generated tracks (i.e. Evt::mc_trks).
312  *
313  * For consistency with the position of the detector,
314  * the pending offset (see method JAANET::getOffset) should be added to the position of cylinder.
315  *
316  * \param header header
317  * \return cylinder
318  */
319  inline JCylinder3D getCylinder(const JHead& header)
320  {
321  using namespace JPP;
322 
323  if (header.is_valid(&JHead::fixedcan)) {
324 
325  return JCylinder3D(JCircle2D(JVector2D(header.fixedcan.xcenter,
326  header.fixedcan.ycenter),
327  header.fixedcan.radius),
328  header.fixedcan.zmin,
329  header.fixedcan.zmax);
330 
331  } else if (header.is_valid(&JHead::can)) {
332 
333  return JCylinder3D(JCircle2D(JVector2D(), header.can.r),
334  header.can.zmin,
335  header.can.zmax);
336  } else {
337 
338  return JCylinder3D();
339  }
340  }
341 }
342 
343 #endif
bool is_mupage(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:85
double zmin
Bottom [m].
Definition: JHead.hh:598
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1319
bool is_km3buu(const JHead &header)
Check for generator.
static const char *const APPLICATION_KM3
detector simulation
Definition: applications.hh:17
Vec getOffset(const JHead &header)
Get offset.
JCylinder3D getCylinder(const JHead &header)
Get cylinder corresponding to the positions of generated tracks (i.e.
bool is_gseagen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:61
bool(* is_head)(const JHead &)
Type definition of test function of header.
Definition: JHeadToolkit.hh:28
static const char *const APPLICATION_GSEAGEN
event generator
Definition: applications.hh:13
double zmax
Top [m].
Definition: JHead.hh:639
double livetime_s
Live time [s].
Definition: JHead.hh:1053
static const char *const APPLICATION_JSIRENE
detector simulation
Definition: applications.hh:19
double ycenter
y-center [m]
Definition: JHead.hh:637
is_head operator()(const std::string &application) const
Get check method for given application.
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:12
Auxiliary map of application to check method.
Cylinder object.
Definition: JCylinder3D.hh:39
bool is_corsika(const JHead &header)
Check for generator.
JAANET::coord_origin coord_origin
Definition: JHead.hh:1598
Monte Carlo run header.
Definition: JHead.hh:1234
static const char *const APPLICATION_CORSIKA
event generator
Definition: applications.hh:15
bool is_daq(const JHead &header)
Check for real data.
then awk string
static const char *const APPLICATION_KM3BUU
event generator
Definition: applications.hh:16
double zmin
Bottom [m].
Definition: JHead.hh:638
static const char *const APPLICATION_KM3SIM
detector simulation
Definition: applications.hh:18
Vec getOrigin(const JHead &header)
Get origin.
static const char *const APPLICATION_MUPAGE
event generator
Definition: applications.hh:14
double r
Radius [m].
Definition: JHead.hh:600
bool is_genhen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:37
std::vector< JAANET::simul > simul
Definition: JHead.hh:1588
static const char *const APPLICATION_GENHEN
KM3NeT Data Definitions v3.3.0-2-g5cc95cf https://git.km3net.de/common/km3net-dataformat.
Definition: applications.hh:12
bool is_sirene(const JHead &header)
Check for detector simulation.
then fatal Wrong number of arguments fi set_variable ARCHIVE $argv[1] set_variable VERSION $argv[2] set_variable DIR $argv[3] source JAcousticsToolkit sh set_variable DETECTOR $DIR $ACOUSTICS_DETECTOR if[[!-f $DETECTOR]]
double radius
Radius [m].
Definition: JHead.hh:640
bool is_km3sim(const JHead &header)
Check for detector simulation.
static JHeadHelper get_is_head
Function object to get check method for given application.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
JHeadHelper()
Default constructor.
JAANET::can can
Definition: JHead.hh:1595
JAANET::DAQ DAQ
Definition: JHead.hh:1604
std::vector< JAANET::physics > physics
Definition: JHead.hh:1587
Vec coord_origin() const
Get coordinate origin.
Definition: Head.hh:398
bool is_km3(const JHead &header)
Check for detector simulation.
double zmax
Top [m].
Definition: JHead.hh:599
JAANET::fixedcan fixedcan
Definition: JHead.hh:1596