Jpp  17.3.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  for (const auto& i : header.physics) { // legacy
69  if (i.buffer.find(APPLICATION_GSEAGEN) != std::string::npos) {
70  return true;
71  }
72  }
73 
74  return false;
75  }
76 
77 
78  /**
79  * Check for generator.
80  *
81  * \param header header
82  * \return true if this header is produced by MUPAGE; else false
83  */
84  inline bool is_mupage(const JHead& header)
85  {
86  for (const auto& i : header.simul) {
87  if (i.program == APPLICATION_MUPAGE) {
88  return true;
89  }
90  }
91 
92  return false;
93  }
94 
95 
96  /**
97  * Check for generator.
98  *
99  * \param header header
100  * \return true if this header is produced by Corsika; else false
101  */
102  inline bool is_corsika(const JHead& header)
103  {
104  for (const auto& i : header.simul) {
105  if (i.program == APPLICATION_CORSIKA) {
106  return true;
107  }
108  }
109 
110  return false;
111  }
112 
113 
114  /**
115  * Check for generator.
116  *
117  * \param header header
118  * \return true if this header is produced by km3buu; else false
119  */
120  inline bool is_km3buu(const JHead& header)
121  {
122  for (const auto& i : header.simul) {
123  if (i.program == APPLICATION_KM3BUU) {
124  return true;
125  }
126  }
127 
128  return false;
129  }
130 
131 
132  /**
133  * Check for detector simulation.
134  *
135  * \param header header
136  * \return true if this header is processed with km3; else false
137  */
138  inline bool is_km3(const JHead& header)
139  {
140  for (const auto& i : header.simul) {
141  if (i.program == APPLICATION_KM3) {
142  return true;
143  }
144  }
145 
146  return false;
147  }
148 
149 
150  /**
151  * Check for detector simulation.
152  *
153  * \param header header
154  * \return true if this header is processed with KM3Sim; else false
155  */
156  inline bool is_km3sim(const JHead& header)
157  {
158  for (const auto& i : header.simul) {
159  if (i.program == APPLICATION_KM3SIM) {
160  return true;
161  }
162  }
163 
164  return false;
165  }
166 
167 
168  /**
169  * Check for detector simulation.
170  *
171  * \param header header
172  * \return true if this header is processed with JSirene; else false
173  */
174  inline bool is_sirene(const JHead& header)
175  {
176  for (const auto& i : header.simul) {
177  if (i.program == APPLICATION_JSIRENE) {
178  return true;
179  }
180  }
181 
182  return false;
183  }
184 
185 
186  /**
187  * Check for real data.
188  *
189  * \param header header
190  * \return true if this header corresponds to real data; else false
191  */
192  inline bool is_daq(const JHead& header)
193  {
194  return header.DAQ.livetime_s > 0.0;
195  }
196 
197 
198  /**
199  * Auxiliary map of application to check method.
200  */
201  struct JHeadHelper :
202  public std::map<std::string, is_head>
203  {
204  /**
205  * Constructor.
206  *
207  * \param input input
208  */
209  JHeadHelper(const std::initializer_list<value_type> input) :
210  std::map<std::string, is_head>(input)
211  {}
212 
213 
214  /**
215  * Get check method for given application.
216  *
217  * \param application application
218  * \return check method
219  */
220  is_head operator()(const std::string& application) const
221  {
222  return this->at(application);
223  }
224  };
225 
226 
227  /**
228  * Function object to get check method for given application.
229  */
231  std::make_pair(APPLICATION_GENHEN, is_genhen),
232  std::make_pair(APPLICATION_GSEAGEN, is_gseagen),
233  std::make_pair(APPLICATION_MUPAGE, is_mupage),
234  std::make_pair(APPLICATION_CORSIKA, is_corsika),
235  std::make_pair(APPLICATION_KM3BUU, is_km3buu),
236  std::make_pair(APPLICATION_KM3, is_km3),
237  std::make_pair(APPLICATION_KM3SIM, is_km3sim),
238  std::make_pair(APPLICATION_JSIRENE, is_sirene),
239  std::make_pair("DAQ", is_daq)
240  };
241 
242 
243  /**
244  * Get object from header.
245  *
246  * \param header header
247  * \return object
248  */
249  template<class T>
250  inline T get(const JHead& header);
251 
252 
253  /**
254  * Get position offset of detector due to generator.
255  *
256  * \param header header
257  * \return position
258  */
259  template<>
260  inline Vec get(const JHead& header)
261  {
262  if (is_sirene(header) || is_km3(header)) {
263 
264  return header.coord_origin;
265 
266  } else {
267 
268  if (header.is_valid(&JHead::can))
269  return Vec(0.0, 0.0, -header.can.zmin);
270  else if (header.is_valid(&JHead::coord_origin))
271  return header.coord_origin;
272  else
273  return Vec(0.0, 0.0, 0.0);
274  }
275  }
276 
277 
278  /**
279  * Get position offset of detector due to generator.
280  *
281  * \param header header
282  * \return position
283  */
284  template<>
285  inline JPosition3D get(const JHead& header)
286  {
287  const Vec pos = get<Vec>(header);
288 
289  return JPosition3D(pos.x, pos.y, pos.z);
290  }
291 
292 
293  /**
294  * Get cylinder corresponding to can.
295  *
296  * \param header header
297  * \return cylinder
298  */
299  template<>
300  inline JCylinder3D get(const JHead& header)
301  {
302  using namespace JGEOMETRY2D;
303 
304  return JCylinder3D(JCircle2D(JVector2D(), header.can.r),
305  header.can.zmin,
306  header.can.zmax);
307  }
308 }
309 
310 #endif
bool is_mupage(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:84
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:1516
std::vector< JAANET::simul > simul
Definition: JHead.hh:1517
double livetime_s
Live time [s].
Definition: JHead.hh:1040
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:1523
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.
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
Monte Carlo run header.
Definition: JHead.hh:1167
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 v3.0.0-3-gef79250 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:1532
Vec coord_origin() const
Get coordinate origin.
Definition: Head.hh:395
bool is_km3(const JHead &header)
Check for detector simulation.