Jpp  15.0.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 #include "JAAnet/JHead.hh"
14 
15 
16 /**
17  * \author mdejong
18  */
19 namespace JAANET {
20 
23 
24  /**
25  * Type definition of test function of header.
26  */
27  typedef bool (*is_head)(const JHead&);
28 
29 
30  /**
31  * Check for generator.
32  *
33  * \param header header
34  * \return true if this header is produced by genhen; else false
35  */
36  inline bool is_genhen(const JHead& header)
37  {
38  for (const auto& i : header.simul) {
39  if (i.program == APPLICATION_GENHEN) {
40  return true;
41  }
42  }
43 
44  for (const auto& i : header.physics) { // legacy
45  if (i.buffer.find(APPLICATION_GENHEN) != std::string::npos) {
46  return true;
47  }
48  }
49 
50  return false;
51  }
52 
53 
54  /**
55  * Check for generator.
56  *
57  * \param header header
58  * \return true if this header is produced by gSeaGen; else false
59  */
60  inline bool is_gseagen(const JHead& header)
61  {
62  for (const auto& i : header.simul) {
63  if (i.program == APPLICATION_GSEAGEN) {
64  return true;
65  }
66  }
67 
68  return false;
69  }
70 
71 
72  /**
73  * Check for generator.
74  *
75  * \param header header
76  * \return true if this header is produced by MUPAGE; else false
77  */
78  inline bool is_mupage(const JHead& header)
79  {
80  for (const auto& i : header.simul) {
81  if (i.program == APPLICATION_MUPAGE) {
82  return true;
83  }
84  }
85 
86  return false;
87  }
88 
89 
90  /**
91  * Check for generator.
92  *
93  * \param header header
94  * \return true if this header is produced by Corsika; else false
95  */
96  inline bool is_corsika(const JHead& header)
97  {
98  for (const auto& i : header.simul) {
99  if (i.program == APPLICATION_CORSIKA) {
100  return true;
101  }
102  }
103 
104  return false;
105  }
106 
107 
108  /**
109  * Check for generator.
110  *
111  * \param header header
112  * \return true if this header is produced by km3buu; else false
113  */
114  inline bool is_km3buu(const JHead& header)
115  {
116  for (const auto& i : header.simul) {
117  if (i.program == APPLICATION_KM3BUU) {
118  return true;
119  }
120  }
121 
122  return false;
123  }
124 
125 
126  /**
127  * Check for detector simulation.
128  *
129  * \param header header
130  * \return true if this header is processed with km3; else false
131  */
132  inline bool is_km3(const JHead& header)
133  {
134  for (const auto& i : header.simul) {
135  if (i.program == APPLICATION_KM3) {
136  return true;
137  }
138  }
139 
140  return false;
141  }
142 
143 
144  /**
145  * Check for detector simulation.
146  *
147  * \param header header
148  * \return true if this header is processed with KM3Sim; else false
149  */
150  inline bool is_km3sim(const JHead& header)
151  {
152  for (const auto& i : header.simul) {
153  if (i.program == APPLICATION_KM3SIM) {
154  return true;
155  }
156  }
157 
158  return false;
159  }
160 
161 
162  /**
163  * Check for detector simulation.
164  *
165  * \param header header
166  * \return true if this header is processed with JSirene; else false
167  */
168  inline bool is_sirene(const JHead& header)
169  {
170  for (const auto& i : header.simul) {
171  if (i.program == APPLICATION_JSIRENE) {
172  return true;
173  }
174  }
175 
176  return false;
177  }
178 
179 
180  /**
181  * Check for real data.
182  *
183  * \param header header
184  * \return true if this header corresponds to real data; else false
185  */
186  inline bool is_daq(const JHead& header)
187  {
188  return header.DAQ.livetime_s > 0.0;
189  }
190 
191 
192  /**
193  * Auxiliary map of application to check method.
194  */
195  struct JHeadHelper :
196  public std::map<std::string, is_head>
197  {
198  /**
199  * Constructor.
200  *
201  * \param input input
202  */
203  JHeadHelper(const std::initializer_list<value_type> input) :
204  std::map<std::string, is_head>(input)
205  {}
206 
207 
208  /**
209  * Get check method for given application.
210  *
211  * \param application application
212  * \return check method
213  */
214  is_head operator()(const std::string& application) const
215  {
216  return this->at(application);
217  }
218  };
219 
220 
221  /**
222  * Function object to get check method for given application.
223  */
225  std::make_pair(APPLICATION_GENHEN, is_genhen),
226  std::make_pair(APPLICATION_GSEAGEN, is_gseagen),
227  std::make_pair(APPLICATION_MUPAGE, is_mupage),
228  std::make_pair(APPLICATION_CORSIKA, is_corsika),
229  std::make_pair(APPLICATION_KM3BUU, is_km3buu),
230  std::make_pair(APPLICATION_KM3, is_km3),
231  std::make_pair(APPLICATION_KM3SIM, is_km3sim),
232  std::make_pair(APPLICATION_JSIRENE, is_sirene),
233  std::make_pair("DAQ", is_daq)
234  };
235 
236 
237  /**
238  * Get object from header.
239  *
240  * \param header header
241  * \return object
242  */
243  template<class T>
244  inline T get(const JHead& header);
245 
246 
247  /**
248  * Get position offset of detector due to generator.
249  *
250  * \param header header
251  * \return position
252  */
253  template<>
254  inline Vec get(const JHead& header)
255  {
256  if (is_sirene(header) || is_km3(header)) {
257 
258  return header.coord_origin;
259 
260  } else {
261 
262  if (header.is_valid(&JHead::can))
263  return Vec(0.0, 0.0, -header.can.zmin);
264  else if (header.is_valid(&JHead::coord_origin))
265  return header.coord_origin;
266  else
267  return Vec(0.0, 0.0, 0.0);
268  }
269  }
270 
271 
272  /**
273  * Get position offset of detector due to generator.
274  *
275  * \param header header
276  * \return position
277  */
278  template<>
279  inline JPosition3D get(const JHead& header)
280  {
281  const Vec pos = get<Vec>(header);
282 
283  return JPosition3D(pos.x, pos.y, pos.z);
284  }
285 
286 
287  /**
288  * Get cylinder corresponding to can.
289  *
290  * \param header header
291  * \return cylinder
292  */
293  template<>
294  inline JCylinder3D get(const JHead& header)
295  {
296  using namespace JGEOMETRY2D;
297 
298  return JCylinder3D(JCircle2D(JVector2D(), header.can.r),
299  header.can.zmin,
300  header.can.zmax);
301  }
302 }
303 
304 #endif
bool is_mupage(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:78
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:60
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:27
static const char *const APPLICATION_GSEAGEN
event generator
Definition: applications.hh:13
std::vector< JAANET::physics > physics
Definition: JHead.hh:1399
std::vector< JAANET::simul > simul
Definition: JHead.hh:1400
double livetime_s
Live time [s].
Definition: JHead.hh:986
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
JAANET::can can
Definition: JHead.hh:1406
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.
Definition: JHeadToolkit.hh:96
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.
static const char *const APPLICATION_KM3BUU
event generator
Definition: applications.hh:16
static const char *const APPLICATION_KM3SIM
detector simulation
Definition: applications.hh:18
Monte Carlo run header.
Definition: JHead.hh:1113
static const char *const APPLICATION_MUPAGE
event generator
Definition: applications.hh:14
bool is_genhen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:36
static const char *const APPLICATION_GENHEN
KM3NeT Data Definitions v2.1.0-7-g97845ea 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
const char * map
Definition: elog.cc:87
JAANET::DAQ DAQ
Definition: JHead.hh:1415
Vec coord_origin() const
Get coordinate origin.
Definition: Head.hh:393
bool is_km3(const JHead &header)
Check for detector simulation.