Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
JEvtCategoryToolkit.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTCATEGORYTOOLKIT__
2 #define __JAANET__JEVTCATEGORYTOOLKIT__
3 
4 #include <set>
5 #include <iostream>
6 
7 #include "JLang/JToken.hh"
8 
9 #include "Jeep/JProperties.hh"
10 
11 #include "JAAnet/JHead.hh"
12 #include "JAAnet/JHeadToolkit.hh"
13 
17 
18 
19 /**
20  * \author bjung
21  */
22 
23 namespace JAANET {}
24 namespace JPP { using namespace JAANET; }
25 
26 namespace JAANET {
27 
28 
29  /**
30  * Container for a set of event categories.
31  *
32  * Input syntax as follows:
33  * <pre>
34  * <PDG type> [& <PDG type>]...
35  * <key>=<value>[,<key>=<value>]...[ & <key>=<value>[,<key>=<value>]...]...
36  * </pre>
37  * where
38  * - <PDG type> refers to a PDG identifier;
39  * - <key> to one of the data members of a data structure derived from `JAANET::JEvtCategory`;
40  * - <value> and to the corresponding value.
41  * Multiple event categories can be specified, separated by the '&' character.
42  */
43  struct JEvtCategorySet :
44  public std::set<JEvtCategoryHelper>
45  {
46  /**
47  * Default constructor.
48  */
50  {}
51 
52 
53  /**
54  * Stream input.
55  *
56  * \param in input stream
57  * \param categories set of event categories
58  * \return input stream
59  */
60  friend inline std::istream& operator>>(std::istream& in, JEvtCategorySet& categories)
61  {
62  using namespace std;
63  using namespace JPP;
64 
65  for (JToken<'&'> token; in >> token; ) {
66 
67  JEvtCategoryHelper category;
68 
69  istringstream iss(token);
70  iss >> category;
71 
72  if (!fail(iss)) { categories.insert(category); }
73  }
74 
75  return in;
76  }
77 
78 
79  /**
80  * Stream output.
81  *
82  * \param out output stream
83  * \param categories set of event categories
84  * \return output stream
85  */
86  friend inline std::ostream& operator<<(std::ostream& out, const JEvtCategorySet& categories)
87  {
88  using namespace std;
89  using namespace JPP;
90 
91  if (categories.size() > 0) {
92  out << *categories.cbegin();
93  }
94 
95  for (iterator i = next(categories.cbegin()); i != categories.cend(); ++i) {
96  out << " & " << *i;
97  }
98 
99  return out;
100  }
101  };
102 
103 
104  /**
105  * Auxiliary method to retrieve the unique event categories corresponding to a MC header.
106  *
107  * \param header MC header
108  * \return vector of unique event categories
109  */
110  inline JEvtCategorySet getCategories(const JHead& header)
111  {
112  using namespace std;
113  using namespace JPP;
114 
115  JEvtCategorySet categories;
116 
117  if (is_gseagen(header)) {
118 
119  const JNeutrinoInteractionCategory cat(header);
120  const JEvtCategoryHelper helper(cat);
121 
122  categories.insert(helper);
123 
124  for (vector<JAANET::flux>::const_iterator i = header.flux.cbegin(); i != header.flux.cend(); ++i) {
125 
126  const JNeutrinoInteractionCategory cat2(header, i->type);
127  const JEvtCategoryHelper helper2(cat2);
128 
129  categories.insert(helper2);
130  }
131 
132  } else if (is_mupage(header) || is_corsika(header)) {
133 
134  const JMuonBundleCategory cat(header);
135  const JEvtCategoryHelper helper(cat);
136 
137  categories.insert(helper);
138  }
139 
140  return categories;
141  }
142 }
143 
144 #endif
Classes and methods for defining muon bundle categories.
Classes and methods for defining neutrino interaction categories.
Utility class to parse parameter values.
Monte Carlo run header.
Definition: JHead.hh:1236
std::vector< JAANET::flux > flux
Definition: JHead.hh:1612
Wrapper class around string.
Definition: JToken.hh:26
Extensions to Evt data format.
bool is_corsika(const JHead &header)
Check for generator.
JEvtCategorySet getCategories(const JHead &header)
Auxiliary method to retrieve the unique event categories corresponding to a MC header.
bool is_gseagen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:61
bool is_mupage(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:85
bool fail(std::istream &in)
Check for stream state.
Definition: JParser.hh:98
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
Helper class for event categories.
Container for a set of event categories.
friend std::ostream & operator<<(std::ostream &out, const JEvtCategorySet &categories)
Stream output.
friend std::istream & operator>>(std::istream &in, JEvtCategorySet &categories)
Stream input.
JEvtCategorySet()
Default constructor.
Class for muon bundle categories.
Class for neutrino interaction categories.