Jpp  18.2.1
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 <map>
5 #include <initializer_list>
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  * Constructor.
207  *
208  * \param input input
209  */
211  std::map<std::string, is_head>(input)
212  {}
213 
214 
215  /**
216  * Get check method for given application.
217  *
218  * \param application application
219  * \return check method
220  */
221  is_head operator()(const std::string& application) const
222  {
223  return this->at(application);
224  }
225  };
226 
227 
228  /**
229  * Function object to get check method for given application.
230  */
232  std::make_pair(APPLICATION_GENHEN, is_genhen),
233  std::make_pair(APPLICATION_GSEAGEN, is_gseagen),
234  std::make_pair(APPLICATION_MUPAGE, is_mupage),
235  std::make_pair(APPLICATION_CORSIKA, is_corsika),
236  std::make_pair(APPLICATION_KM3BUU, is_km3buu),
237  std::make_pair(APPLICATION_KM3, is_km3),
238  std::make_pair(APPLICATION_KM3SIM, is_km3sim),
239  std::make_pair(APPLICATION_JSIRENE, is_sirene),
240  std::make_pair("DAQ", is_daq)
241  };
242 
243 
244  /**
245  * Get object from header.
246  *
247  * \param header header
248  * \return object
249  */
250  template<class T>
251  inline T get(const JHead& header);
252 
253 
254  /**
255  * Get position offset of detector due to generator.
256  *
257  * \param header header
258  * \return position
259  */
260  template<>
261  inline Vec get(const JHead& header)
262  {
263  if (is_sirene(header) || is_km3(header)) {
264 
265  return header.coord_origin;
266 
267  } else {
268 
269  if (header.is_valid(&JHead::fixedcan))
270  return Vec(-header.fixedcan.xcenter,
271  -header.fixedcan.ycenter,
272  -header.fixedcan.zmin);
273  else if (header.is_valid(&JHead::can))
274  return Vec(0.0, 0.0, -header.can.zmin);
275  else if (header.is_valid(&JHead::coord_origin))
276  return header.coord_origin;
277  else
278  return Vec(0.0, 0.0, 0.0);
279  }
280  }
281 
282 
283  /**
284  * Get position offset of detector due to generator.
285  *
286  * \param header header
287  * \return position
288  */
289  template<>
290  inline JPosition3D get(const JHead& header)
291  {
292  const Vec pos = get<Vec>(header);
293 
294  return JPosition3D(pos.x, pos.y, pos.z);
295  }
296 
297 
298  /**
299  * Get cylinder corresponding to can.
300  *
301  * \param header header
302  * \return cylinder
303  */
304  template<>
305  inline JCylinder3D get(const JHead& header)
306  {
307  using namespace JGEOMETRY2D;
308 
309  if (header.is_valid(&JHead::fixedcan)) {
310 
311  return JCylinder3D(JCircle2D(JVector2D(header.fixedcan.xcenter,
312  header.fixedcan.ycenter),
313  header.fixedcan.radius),
314  header.fixedcan.zmin,
315  header.fixedcan.zmax);
316 
317  } else if (header.is_valid(&JHead::can)) {
318 
319  return JCylinder3D(JCircle2D(JVector2D(), header.can.r),
320  header.can.zmin,
321  header.can.zmax);
322  } else {
323 
324  return JCylinder3D();
325  }
326  }
327 }
328 
329 #endif
bool is_mupage(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:85
Data structure for vector in two dimensions.
Definition: JVector2D.hh:32
bool is_km3buu(const JHead &header)
Check for generator.
static const char *const APPLICATION_KM3
detector simulation
Definition: applications.hh:17
double z
Definition: Vec.hh:14
bool is_gseagen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:61
Data structure for circle in two dimensions.
Definition: JCircle2D.hh:33
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 livetime_s
Live time [s].
Definition: JHead.hh:1053
double y
Definition: Vec.hh:14
static const char *const APPLICATION_JSIRENE
detector simulation
Definition: applications.hh:19
is_head operator()(const std::string &application) const
Get check method for given application.
double x
Definition: Vec.hh:14
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.
Monte Carlo run header.
Definition: JHead.hh:1234
static const char *const APPLICATION_CORSIKA
event generator
Definition: applications.hh:15
JHeadHelper(const std::initializer_list< value_type > input)
Constructor.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
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
static const char *const APPLICATION_KM3SIM
detector simulation
Definition: applications.hh:18
static const char *const APPLICATION_MUPAGE
event generator
Definition: applications.hh:14
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.2.0-2-gaaf0dd0 https://git.km3net.de/common/km3net-dataformat.
Definition: applications.hh:12
bool is_sirene(const JHead &header)
Check for detector simulation.
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
JAANET::can can
Definition: JHead.hh:1595
const char * map
Definition: elog.cc:87
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.
JAANET::fixedcan fixedcan
Definition: JHead.hh:1596