Jpp test-rotations-old
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 * Template event-weighter-associated file scanner.
58 *
59 * Note: The template class must be derived from JMultipleFileScanner<Evt>
60 */
61 template<class JFileScanner_t = JMultipleFileScanner<Evt> >
63 public JEvtWeightHelper,
64 public JFileScanner_t
65 {
66 typedef typename JFileScanner_t::input_type input_type;
67
68
69 /**
70 * Default constructor.
71 */
74 JFileScanner_t()
75 {}
76
77
78 /**
79 * Constructor.
80 *
81 * \param weighter event weighter
82 */
85 JFileScanner_t()
86 {
87 reset(weighter);
88 }
89
90
91 /**
92 * Constructor.
93 *
94 * \param input input
95 */
98 JFileScanner_t()
99 {
100 using namespace JPP;
101
102 const JHead& header = JSUPPORT::getHeader(input);
103 const JEvtWeight& weighter = getEventWeighter(header);
104
105 reset(weighter);
106 put (input);
107 }
108
109
110 /**
111 * Reset file scanner and event weighter.
112 *
113 * \param weighter event weighter
114 */
115 void reset(const JEvtWeight& weighter)
116 {
118 JFileScanner_t ::clear();
119 }
120
121
122 /**
123 * Put files.
124 *
125 * \param input input files
126 * \return number of added files
127 */
128 size_t put(const input_type& input)
129 {
130 size_t n = 0;
131
132 for (typename input_type::const_iterator i = input.begin(); i != input.end(); ++i) {
133 n += size_t(this->put(*i));
134 }
135
136 return n;
137 }
138
139
140 /**
141 * Put file.
142 *
143 * \param input input file
144 * \return true if successfully added; else false.
145 */
146 bool put(const std::string& input)
147 {
148 using namespace JPP;
149
150 const JHead& head = JSUPPORT::getHeader(input);
151
152 if (this->check(head)) {
153
155 JFileScanner_t ::push_back(input);
156
157 return true;
158
159 } else {
160
161 return false;
162 }
163 }
164
165
166 /**
167 * Set event-weight factor for the event-weighter associated with this file scanner.
168 *
169 * The template argument refers to the desired helper class for an event-weight factor\n
170 * (c.f. `JAANET::JEvtWeightFactorHelper`, `JAANET::JFluxHelper` or `JAANET::JDiffuseFluxHelper`).
171 *
172 * \param factor event-weight factor
173 * \return true if event-weight factor set successfully; else false
174 */
175 template<class JEvtWeightFactorHelper_t>
176 bool setEvtWeightFactor(const JEvtWeightFactorHelper_t& factor)
177 {
178 JEvtWeightFactorHelper_t* helper = dynamic_cast<JEvtWeightFactorHelper_t*>(this->get());
179
180 if (helper != NULL) {
181
182 helper->configure(factor);
183
184 return true;
185
186 } else {
187
188 return false;
189 }
190 }
191
192
193 /**
194 * Set event-weight factor corresponding to a given event category.
195 *
196 * \param category event category
197 * \param factor event-weight factor
198 * \return true if event-weight factor set successfully; else false
199 */
201 const JEvtWeightFactorHelper& factor)
202 {
203 const JHead& header = this->getHeader();
204
205 return (category.match(header) ? setEvtWeightFactor(factor) : false);
206 }
207
208
209 /**
210 * Set event-weight factor corresponding to a given set of event categories.
211 *
212 * Note that the given event-weight factor will only be assigned\n
213 * if the header matches < b>all< /b> of the specified event categories.
214 *
215 * \param categories set of event categories
216 * \param factor event-weight factor
217 * \return true if event-weight factor set successfully; else false
218 */
219 bool setEvtWeightFactor(const JEvtCategorySet& categories,
220 const JEvtWeightFactorHelper& factor)
221 {
222 using namespace std;
223 using namespace JPP;
224
225 bool matching = (!categories.empty());
226
227 const JHead& header = this->getHeader();
228
229 const JEvtCategorySet cats = getCategories(header);
230
231 for (JEvtCategorySet::const_iterator i = categories.cbegin(); i != categories.cend() && matching; ++i) {
232
233 JEvtCategorySet::const_iterator j = std::find(cats.cbegin(), cats.cend(), *i);
234
235 matching = (j != cats.cend());
236 }
237
238 return (matching ? setEvtWeightFactor(factor) : false);
239 }
240
241
242 /**
243 * Set event-weight factor according to a given map between event categories and event-weight factors.
244 *
245 * The template argument refers either to the class `JAANET::JEvtWeightFactorHelper` or `JAANET::JFluxHelper`.
246 *
247 * Note that the given event-weight factors will only be assigned\n
248 * if the header matches < b>all< /b> of the event categories associated with the given map.
249 *
250 * \param object map between event categories and event-weight factors
251 * \return true if event-weight factors are set successfully; else false
252 */
253 template<class JEvtWeightFactorHelper_t>
255 {
256 using namespace std;
257 using namespace JPP;
258
259 typedef JEvtCategoryMap<JEvtWeightFactorHelper_t> JEvtCategoryMap_t;
260
261
262 bool matching = (!object.empty());
263
264 const JHead& header = this->getHeader();
265
266 const JEvtCategorySet cats = getCategories(header);
267
268 for (typename JEvtCategoryMap_t::const_iterator i = object.cbegin(); i != object.cend() && matching; ++i) {
269
270 JEvtCategorySet::const_iterator j = std::find(cats.cbegin(), cats.cend(), i->first);
271
272 matching = (j != cats.cend());
273 }
274
275 return (matching ? setEvtWeightFactor(object) : false);
276 }
277
278
279 /**
280 * Set flux function for the event-weighter associated with this file scanner.
281 *
282 * \param flux flux function
283 * \return true if flux function set successfully; else false
284 */
286 {
287 return setEvtWeightFactor(flux);
288 }
289
290
291 /**
292 * Set flux function corresponding to a given event category.
293 *
294 * \param category event category
295 * \param flux flux function
296 * \return true if flux function set successfully; else false
297 */
298 bool setFlux(const JEvtCategoryHelper& category,
299 const JFluxHelper& flux)
300 {
301 return setEvtWeightFactor(category, flux);
302 }
303
304
305 /**
306 * Set flux function corresponding to a given set of event categories.
307 *
308 * Note that the given flux function will only be assigned\n
309 * if the header matches < b>all< /b> of the specified event categories.
310 *
311 * \param categories set of event categories
312 * \param flux flux function
313 * \return true if event-weight factor set successfully; else false
314 */
315 bool setFlux(const JEvtCategorySet& categories,
316 const JFluxHelper& flux)
317 {
318 return setEvtWeightFactor(categories, flux);
319 }
320
321
322 /**
323 * Set flux function according to a given map between event categories and flux functions.
324 *
325 * Note that the given flux functions will only be assigned\n
326 * if the header matches < b>all< /b> of the event categories associated with the given map.
327 *
328 * \param object map between event categories and flux functions
329 * \return true if event-weight factors are set successfully; else false
330 */
332 {
333 return setEvtWeightFactor<JFluxHelper>(object);
334 }
335
336 private:
337 using JEvtWeightHelper::reset;
338 };
339}
340
341#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
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.
void configure(const JEvtWeight &weighter)
Configuration.
void add(const JHead &header)
Add header.
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
Template event-weighter-associated file scanner.
bool setFlux(const JEvtCategoryHelper &category, const JFluxHelper &flux)
Set flux function corresponding to a given event category.
bool setEvtWeightFactor(const JEvtCategoryHelper &category, const JEvtWeightFactorHelper &factor)
Set event-weight factor corresponding to a given event category.
JEvtWeightFileScanner()
Default constructor.
bool put(const std::string &input)
Put file.
JFileScanner_t::input_type input_type
size_t put(const input_type &input)
Put files.
bool setEvtWeightFactor(const JEvtWeightFactorHelper_t &factor)
Set event-weight factor for the event-weighter associated with this file scanner.
JEvtWeightFileScanner(const JEvtWeight &weighter)
Constructor.
bool setEvtWeightFactor(const JEvtCategorySet &categories, const JEvtWeightFactorHelper &factor)
Set event-weight factor corresponding to a given set of event categories.
bool setEvtWeightFactor(const JEvtCategoryMap< JEvtWeightFactorHelper_t > &object)
Set event-weight factor according to a given map between event categories and event-weight factors.
void reset(const JEvtWeight &weighter)
Reset file scanner and event weighter.
bool setFlux(const JEvtCategoryMap< JFluxHelper > &object)
Set flux function according to a given map between event categories and flux functions.
bool setFlux(const JEvtCategorySet &categories, const JFluxHelper &flux)
Set flux function corresponding to a given set of event categories.
bool setFlux(const JFluxHelper &flux)
Set flux function for the event-weighter associated with this file scanner.
JEvtWeightFileScanner(const input_type &input)
Constructor.