Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JEvtCategoryHelper.hh
Go to the documentation of this file.
1#ifndef __JAANET__JEVTCATEGORYHELPER__
2#define __JAANET__JEVTCATEGORYHELPER__
3
4#include <memory>
5
8
10
11#include "JAAnet/JHead.hh"
15
16
17/**
18 * \author bjung
19 */
20
21namespace JAANET {}
22namespace JPP { using namespace JAANET; }
23
24namespace JAANET {
25
27
28
29 /**
30 * Helper class for event categories.
31 */
33 public std::shared_ptr<JEvtCategory>,
34 public JComparable<JEvtCategoryHelper>
35 {
36 typedef std::shared_ptr<JEvtCategory> pointer_type;
37
38 /**
39 * Default constructor.
40 */
44
45
46 /**
47 * Constructor.
48 *
49 * \param p shared pointer to event category
50 */
54
55
56 /**
57 * Constructor.
58 *
59 * \param category event category
60 */
62 {
63 this->configure(category);
64 }
65
66
67 /**
68 * Constructor.
69 *
70 * \param header MC header
71 */
73 {
74 this->configure(header);
75 }
76
77
78 /**
79 * Constructor.
80 *
81 * \param type PDG type
82 */
83 JEvtCategoryHelper(const int type)
84 {
85 this->configure(type);
86 }
87
88
89 /**
90 * Configuration.
91 *
92 * \param p shared pointer to event category
93 */
94 void configure(const pointer_type& p)
95 {
96 static_cast<pointer_type&>(*this) = p;
97 }
98
99
100 /**
101 * Configuration.
102 *
103 * \param category event category
104 */
105 void configure(const JEvtCategory& category)
106 {
107 reset(category.clone());
108 }
109
110
111 /**
112 * Configuration.
113 *
114 * \param header header
115 */
116 void configure(const JHead& header)
117 {
118 using namespace JPP;
119
120 if (is_neutrino_primary(header.primary.type)) {
121 reset(new JNeutrinoInteractionCategory(header));
122 } else if (is_mupage(header) || is_muon_bundle_primary(header.primary.type)) {
123 reset(new JMuonBundleCategory(header));
124 } else {
125 THROW(JValueOutOfRange, "JEvtCategoryHelper::configure(): Cannot construct event category for given header with primary ID " << header.primary.type);
126 }
127 }
128
129
130 /**
131 * Configuration.
132 *
133 * \param type PDG type
134 */
135 void configure(const int type)
136 {
137 using namespace JPP;
138
139 if (is_neutrino_primary(type)) {
140 reset(new JNeutrinoInteractionCategory(type));
141 } else if (is_muon_bundle_primary(type)) {
142 reset(new JMuonBundleCategory(type));
143 } else {
144 THROW(JValueOutOfRange, "JEvtCategoryHelper::configure(): Cannot construct event category for PDG type " << type);
145 }
146 }
147
148
149 /**
150 * Get reference to event category.
151 *
152 * \return reference to event category
153 */
155 {
156 using namespace JPP;
157
158 if (static_cast<const JEvtCategoryHelper&>(*this)) {
159 return *(this->get());
160 } else {
161 THROW(JNullPointerException, "JEvtCategoryHelper::getEvtCategory(): Event category is not set.");
162 }
163 }
164
165
166 /**
167 * Check if event category is valid.
168 *
169 * \return true if event category is valid; else false
170 */
171 bool is_valid() const
172 {
173 return static_cast<const JEvtCategoryHelper&>(*this) && this->get()->is_valid();
174 }
175
176
177 /**
178 * Check whether given MC header matches with this event category.
179 *
180 * \param header MC header
181 * \return true if matching; else false
182 */
183 bool match(const JHead& header) const
184 {
185 const JEvtCategory& category = getEvtCategory();
186
187 return category.match(header);
188 }
189
190
191 /**
192 * Check whether given event matches with this event category.
193 *
194 * \param event event
195 * \return true if matching; else false
196 */
197 bool match(const Evt& event) const
198 {
199 const JEvtCategory& category = getEvtCategory();
200
201 return category.match(event);
202 }
203
204
205 /**
206 * Less-than method.
207 *
208 * \param category event category
209 * \return true if this event category is less than given event category; else false
210 */
211 bool less(const JEvtCategory& category) const
212 {
213 const JEvtCategory& cat = getEvtCategory();
214
215 return cat.less(category);
216 }
217
218
219 /**
220 * Less-than method.
221 *
222 * \param helper shared pointer to event category
223 * \return true if this event category is less than given event category; else false
224 */
225 bool less(const JEvtCategoryHelper& helper) const
226 {
227 return this->less(helper.getEvtCategory());
228 }
229
230
231 /**
232 * Get properties of this class.
233 *
234 * \param equation equation parameters
235 */
240
241
242 /**
243 * Get properties of this class.
244 *
245 * \param equation equation parameters
246 */
251
252
253 /**
254 * Read event category from input.
255 *
256 * \param in input stream
257 * \param object event category
258 * \return input stream
259 */
260 friend inline std::istream& operator>>(std::istream& in, JEvtCategoryHelper& object)
261 {
262 using namespace std;
263
264 if (object) {
265
266 return object.get()->read(in);
267
268 } else {
269
270 streampos pos = in.tellg();
271
272 int type = 0;
273
274 if (in >> type) {
275 object.configure(type);
276 return in;
277 }
278
279 in.clear();
280 in.seekg(pos);
281
282 JNeutrinoInteractionCategory neutrinoInteraction;
283 neutrinoInteraction.getProperties().read(in);
284
285 if (neutrinoInteraction.is_valid()) {
286 object.configure(neutrinoInteraction);
287 return in;
288 }
289
290 in.clear();
291 in.seekg(pos);
292
293 JMuonBundleCategory muonBundle;
294 muonBundle.getProperties().read(in);
295
296 if (muonBundle.is_valid()) {
297 object.configure(muonBundle);
298 }
299
300 return in;
301 }
302 }
303
304
305 /**
306 * Write event category to output.
307 *
308 * \param out output stream
309 * \param object event category
310 * \return output stream
311 */
312 friend inline std::ostream& operator<<(std::ostream& out, const JEvtCategoryHelper& object)
313 {
314 if (object.is_valid()) {
315 return out << object.getEvtCategory();
316 } else {
317 return out << 0;
318 }
319 }
320 };
321}
322
323#endif
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Classes and methods for defining muon bundle categories.
Classes and methods for defining neutrino interaction categories.
Monte Carlo run header.
Definition JHead.hh:1236
JAANET::primary primary
Definition JHead.hh:1611
Utility class to parse parameter values.
bool read(const JEquation &equation)
Read equation.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Exception for null pointer operation.
Exception for accessing a value in a collection that is outside of its range.
Extensions to Evt data format.
bool is_neutrino_primary(const int type)
Auxiliary function to check if given PDG code corresponds to a neutrino.
bool is_mupage(const JHead &header)
Check for generator.
bool is_muon_bundle_primary(const int type)
Auxiliary function to check if given PDG code corresponds to a valid muon bundle primary type.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
Helper class for event categories.
bool is_valid() const
Check if event category is valid.
JEvtCategoryHelper(const pointer_type &p)
Constructor.
JEvtCategoryHelper(const int type)
Constructor.
JEvtCategoryHelper(const JHead &header)
Constructor.
JEvtCategoryHelper()
Default constructor.
void configure(const JHead &header)
Configuration.
bool less(const JEvtCategoryHelper &helper) const
Less-than method.
JEvtCategoryHelper(const JEvtCategory &category)
Constructor.
void configure(const int type)
Configuration.
friend std::istream & operator>>(std::istream &in, JEvtCategoryHelper &object)
Read event category from input.
void configure(const pointer_type &p)
Configuration.
JProperties getProperties(const JEquationParameters &equation=JEvtCategory::getEquationParameters()) const
Get properties of this class.
bool less(const JEvtCategory &category) const
Less-than method.
JEvtCategory & getEvtCategory() const
Get reference to event category.
bool match(const Evt &event) const
Check whether given event matches with this event category.
friend std::ostream & operator<<(std::ostream &out, const JEvtCategoryHelper &object)
Write event category to output.
JProperties getProperties(const JEquationParameters &equation=JEvtCategory::getEquationParameters())
Get properties of this class.
std::shared_ptr< JEvtCategory > pointer_type
void configure(const JEvtCategory &category)
Configuration.
bool match(const JHead &header) const
Check whether given MC header matches with this event category.
Low-level interface for event categories.
virtual JProperties getProperties(const JEquationParameters &eqpars=JEvtCategory::getEquationParameters())
Get properties of this class.
virtual bool less(const JEvtCategory &category) const
Less-than method.
virtual bool match(const JHead &header) const =0
Check whether given MC header matches with this event category.
static JEquationParameters & getEquationParameters()
Get equation parameters.
Class for muon bundle categories.
bool is_valid() const override final
Check if muon bundle category is valid.
JProperties getProperties(const JEquationParameters &equation=JEvtCategory::getEquationParameters()) override final
Get properties of this class.
Class for neutrino interaction categories.
bool is_valid() const override final
Check if neutrino interaction categories is valid.
JProperties getProperties(const JEquationParameters &eqpars=JEvtCategory::getEquationParameters()) override final
Get properties of this class.
int type
Particle type.
Definition JHead.hh:1204
virtual clone_type clone() const override
Get clone of this object.
Definition JClonable.hh:69
Template definition of auxiliary base class for comparison of data structures.