Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JEvtWeightFileScanner.hh
Go to the documentation of this file.
1#ifndef __JSUPPORT__JEVTWEIGHTFILESCANNER__
2#define __JSUPPORT__JEVTWEIGHTFILESCANNER__
3
4#include <set>
5#include <vector>
6#include <string>
7#include <algorithm>
8
11
12#include "JLang/JException.hh"
13
14#include "JAAnet/JHead.hh"
15
20
21#include "JAAnet/JEvtWeight.hh"
24
27#include "JAAnet/JFluxHelper.hh"
28
29#include "JSupport/JSupport.hh"
32
33
34/**
35 * \author bjung
36 */
37
38namespace JSUPPORT {}
39namespace JPP { using namespace JSUPPORT; }
40
41namespace JSUPPORT {
42
43 using JAANET::JHead;
44
48
51
54
55
56 /**
57 * Event-weighter-associated file organiser.
58 */
60 public JEvtWeightHelper,
62 {
64
65
66 /**
67 * Default constructor.
68 */
73
74
75 /**
76 * Constructor.
77 *
78 * \param weighter event weighter
79 */
83 {
84 reset(weighter);
85 }
86
87
88 /**
89 * Constructor.
90 *
91 * \param input input
92 */
96 {
97 using namespace JPP;
98
99 const JHead& header = JSUPPORT::getHeader(input);
100 const JEvtWeight& weighter = getEventWeighter(header);
101
102 reset(weighter);
103 put (input);
104 }
105
106
107 /**
108 * Reset file scanner and event weighter.
109 *
110 * \param weighter event weighter
111 */
112 void reset(const JEvtWeight& weighter)
113 {
114 JEvtWeightHelper ::configure(weighter);
115 JMultipleFileScanner_t::clear();
116 }
117
118
119 /**
120 * Put files.
121 *
122 * \param input input files
123 * \return number of added files
124 */
125 size_t put(const input_type& input)
126 {
127 size_t n = 0;
128
129 for (typename input_type::const_iterator i = input.begin(); i != input.end(); ++i) {
130 n += size_t(this->put(*i));
131 }
132
133 return n;
134 }
135
136
137 /**
138 * Put file.
139 *
140 * \param input input file
141 * \return true if successfully added; else false.
142 */
143 bool put(const std::string& input)
144 {
145 using namespace JPP;
146
147 JHead head = JSUPPORT::getHeader(input);
148
149 head.createUUID(); // Ensure valid UUID
150
151 if (this->check(head)) {
152
153 JEvtWeightHelper ::add(head);
154 JMultipleFileScanner_t::push_back(input);
155
156 return true;
157
158 } else {
159
160 return false;
161 }
162 }
163
164
165 /**
166 * Set event-weight factor for the event-weighter associated with this file scanner.
167 *
168 * The template argument refers to the desired helper class for an event-weight factor\n
169 * (c.f. `JAANET::JEvtWeightFactorHelper`, `JAANET::JFluxHelper` or `JAANET::JDiffuseFluxHelper`).
170 *
171 * \param factor event-weight factor
172 * \return true if event-weight factor set successfully; else false
173 */
174 template<class JEvtWeightFactorHelper_t>
175 bool setEvtWeightFactor(const JEvtWeightFactorHelper_t& factor)
176 {
177 JEvtWeightFactorHelper_t* helper = dynamic_cast<JEvtWeightFactorHelper_t*>(this->get());
178
179 if (helper != NULL) {
180
181 helper->configure(factor);
182
183 return true;
184
185 } else {
186
187 return false;
188 }
189 }
190
191
192 /**
193 * Set event-weight factor corresponding to a given event category.
194 *
195 * \param category event category
196 * \param factor event-weight factor
197 * \return true if event-weight factor set successfully; else false
198 */
200 const JEvtWeightFactorHelper& factor)
201 {
202 const JHead& header = this->getHeader();
203
204 return (category.match(header) ? setEvtWeightFactor(factor) : false);
205 }
206
207
208 /**
209 * Set event-weight factor corresponding to a given set of event categories.
210 *
211 * Note that the given event-weight factor will only be assigned\n
212 * if the header matches < b>all< /b> of the specified event categories.
213 *
214 * \param categories set of event categories
215 * \param factor event-weight factor
216 * \return true if event-weight factor set successfully; else false
217 */
218 bool setEvtWeightFactor(const JEvtCategorySet& categories,
219 const JEvtWeightFactorHelper& factor)
220 {
221 using namespace std;
222 using namespace JPP;
223
224 bool matching = (!categories.empty());
225
226 const JHead& header = this->getHeader();
227
228 const JEvtCategorySet cats = getCategories(header);
229
230 for (JEvtCategorySet::const_iterator i = categories.cbegin(); i != categories.cend() && matching; ++i) {
231
232 JEvtCategorySet::const_iterator j = std::find(cats.cbegin(), cats.cend(), *i);
233
234 matching = (j != cats.cend());
235 }
236
237 return (matching ? setEvtWeightFactor(factor) : false);
238 }
239
240
241 /**
242 * Set event-weight factor according to a given map between event categories and event-weight factors.
243 *
244 * The template argument refers either to the class `JAANET::JEvtWeightFactorHelper` or `JAANET::JFluxHelper`.
245 *
246 * Note that the given event-weight factors will only be assigned\n
247 * if the header matches < b>all< /b> of the event categories associated with the given map.
248 *
249 * \param object map between event categories and event-weight factors
250 * \return true if event-weight factors are set successfully; else false
251 */
252 template<class JEvtWeightFactorHelper_t>
254 {
255 using namespace std;
256 using namespace JPP;
257
258 typedef JEvtCategoryMap<JEvtWeightFactorHelper_t> JEvtCategoryMap_t;
259
260
261 bool matching = (!object.empty());
262
263 const JHead& header = this->getHeader();
264
265 const JEvtCategorySet cats = getCategories(header);
266
267 for (typename JEvtCategoryMap_t::const_iterator i = object.cbegin(); i != object.cend() && matching; ++i) {
268
269 JEvtCategorySet::const_iterator j = std::find(cats.cbegin(), cats.cend(), i->first);
270
271 matching = (j != cats.cend());
272 }
273
274 return (matching ? setEvtWeightFactor(object) : false);
275 }
276
277
278 /**
279 * Set flux function for the event-weighter associated with this file scanner.
280 *
281 * \param flux flux function
282 * \return true if flux function set successfully; else false
283 */
285 {
286 return setEvtWeightFactor(flux);
287 }
288
289
290 /**
291 * Set flux function corresponding to a given event category.
292 *
293 * \param category event category
294 * \param flux flux function
295 * \return true if flux function set successfully; else false
296 */
297 bool setFlux(const JEvtCategoryHelper& category,
298 const JFluxHelper& flux)
299 {
300 return setEvtWeightFactor(category, flux);
301 }
302
303
304 /**
305 * Set flux function corresponding to a given set of event categories.
306 *
307 * Note that the given flux function will only be assigned\n
308 * if the header matches < b>all< /b> of the specified event categories.
309 *
310 * \param categories set of event categories
311 * \param flux flux function
312 * \return true if event-weight factor set successfully; else false
313 */
314 bool setFlux(const JEvtCategorySet& categories,
315 const JFluxHelper& flux)
316 {
317 return setEvtWeightFactor(categories, flux);
318 }
319
320
321 /**
322 * Set flux function according to a given map between event categories and flux functions.
323 *
324 * Note that the given flux functions will only be assigned\n
325 * if the header matches < b>all< /b> of the event categories associated with the given map.
326 *
327 * \param object map between event categories and flux functions
328 * \return true if event-weight factors are set successfully; else false
329 */
331 {
332 return setEvtWeightFactor<JFluxHelper>(object);
333 }
334
335 private:
336 using JEvtWeightHelper::reset;
337 };
338}
339
340#endif
Exceptions.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
ROOT TTree parameter settings of various packages.
Auxiliary class for reading a map of event categories.
Monte Carlo run header.
Definition JHead.hh:1236
void createUUID()
Create UUID if not already set.
Definition JHead.hh:1301
const JHead & getHeader() const
Get header.
Definition JHead.hh:1270
JEvtWeighter getEventWeighter
Function object for mapping header to event weighter.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Support classes and methods for experiment specific I/O.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
JAANET::JEvtCategorySet getCategories(const JMultipleFileScanner_t &file_list)
Get the unique event categories corresponding to a given list of MC files.
const int n
Definition JPolint.hh:791
int j
Definition JPolint.hh:801
Helper class for event categories.
bool match(const JHead &header) const
Check whether given MC header matches with this event category.
Container for a set of event categories.
Helper class for event-weight factor.
Helper class for event weighing.
bool check(const JHead &header) const
Check if a given header is consistent with this event weighter.
Abstract base class for event weighing.
Definition JEvtWeight.hh:31
Helper class for flux function.
Neutrino flux.
Definition JHead.hh:906
Event-weighter-associated file organiser.
void reset(const JEvtWeight &weighter)
Reset file scanner and event weighter.
JEvtWeightFileScanner()
Default constructor.
bool setEvtWeightFactor(const JEvtCategoryMap< JEvtWeightFactorHelper_t > &object)
Set event-weight factor according to a given map between event categories and event-weight factors.
bool put(const std::string &input)
Put file.
bool setEvtWeightFactor(const JEvtCategorySet &categories, const JEvtWeightFactorHelper &factor)
Set event-weight factor corresponding to a given set of event categories.
bool setEvtWeightFactor(const JEvtCategoryHelper &category, const JEvtWeightFactorHelper &factor)
Set event-weight factor corresponding to a given event category.
JEvtWeightFileScanner(const JEvtWeight &weighter)
Constructor.
size_t put(const input_type &input)
Put files.
bool setFlux(const JEvtCategorySet &categories, const JFluxHelper &flux)
Set flux function corresponding to a given set of event categories.
bool setFlux(const JEvtCategoryHelper &category, const JFluxHelper &flux)
Set flux function corresponding to a given event category.
bool setEvtWeightFactor(const JEvtWeightFactorHelper_t &factor)
Set event-weight factor for the event-weighter associated with this file scanner.
bool setFlux(const JFluxHelper &flux)
Set flux function for the event-weighter associated with this file scanner.
bool setFlux(const JEvtCategoryMap< JFluxHelper > &object)
Set flux function according to a given map between event categories and flux functions.
JEvtWeightFileScanner(const input_type &input)
Constructor.
Auxiliary base class for list of file names.