Jpp master_rocky-44-g75b7c4f75
the software that should make you happy
Loading...
Searching...
No Matches
JEvtWeightFileScannerSet.hh
Go to the documentation of this file.
1#ifndef __JSUPPORT_JEVTWEIGHTFILESCANNERSET__
2#define __JSUPPORT_JEVTWEIGHTFILESCANNERSET__
3
4#include <vector>
5#include <string>
6
9
10#include "JLang/JException.hh"
11#include "JLang/JComparator.hh"
12
13#include "JAAnet/JHead.hh"
14
19
20#include "JAAnet/JEvtWeight.hh"
22
25#include "JAAnet/JFluxHelper.hh"
26
27#include "JSupport/JSupport.hh"
31
32
33/**
34 * \author bjung
35 */
36
37namespace JSUPPORT {}
38namespace JPP { using namespace JSUPPORT; }
39
40namespace JSUPPORT {
41
42 using JAANET::JHead;
43
47
50
51
52 /**
53 * Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
54 *
55 * Note: The template class `JFileScanner_t` must be derived from JMultipleFileScanner<Evt>.
56 */
57 template<class JFileScanner_t = JMultipleFileScanner<Evt>,
58 class JComparator_t = std::less<JHead> >
60 public std::vector< JEvtWeightFileScanner<JFileScanner_t> >
61 {
64
66
70
71 typedef typename std::vector<filescanner_type>::const_iterator const_iterator;
73 typedef typename std::vector<filescanner_type>::const_reverse_iterator const_reverse_iterator;
75
76
77
78 /**
79 * Default constructor.
80 */
83
84
85 /**
86 * Constructor.
87 *
88 * \param input input files
89 */
91 {
92 put(input);
93 }
94
95
96 /**
97 * Put files
98 *
99 * \param input input files
100 * \return number of added files
101 */
102 size_t put(const input_type& input)
103 {
104 size_t n = 0;
105
106 for (typename input_type::const_iterator i = input.begin(); i != input.end(); ++i) {
107 n += size_t(this->put(*i));
108 }
109
110 return n;
111 }
112
113
114 /**
115 * Put file
116 *
117 * \param input input file
118 * \return true if successfully added; else false.
119 */
120 bool put(const std::string& input)
121 {
122 using namespace std;
123 using namespace JPP;
124
125 const JHead& head = getHeader(input);
126
127 iterator i = lower_bound(this->begin(), this->end(), head,
129
130 if (i == this->end() || !i->getHeader().match(head)) {
131 i = this->insert(i, value_type(getEventWeighter(head)));
132 }
133
134 return i->put(input);
135 }
136
137
138 /**
139 * Get unique identifier for a file-scanner contained within this set of event-weighter-associated file-scanners.
140 *
141 * \param p iterator to contained file-scanner
142 * \return unique identifier of contained file-scanner
143 */
145 {
146 using namespace std;
147 using namespace JPP;
148
149 static const char SEPARATOR = '.';
150
151 string name = p->getProgramName();
152 int index = 0;
153
154 for (const_iterator i = this->cbegin(); i != this->cend() && i != p; ++i) {
155 if (i->getProgramName() == name) {
156 ++index;
157 }
158 }
159
160 return MAKE_STRING(name << SEPARATOR << index);
161 }
162
163
164 /**
165 * Find file scanner compatible with a given header.
166 *
167 * \param head header
168 * \return file scanner
169 */
170 const_reference find(const JHead& head) const
171 {
172 using namespace JPP;
173
174 for (const_iterator i = this->begin(); i != this->end(); ++i) {
175 if (i->match(head)) {
176 return *i;
177 }
178 }
179
180 THROW(JValueOutOfRange, "JEvtWeightFileScannerSet::get(): No corresponding scanner found for given header.");
181 }
182
183
184 /**
185 * Set event-weighting factor for all MC-files corresponding to a given PDG code.
186 *
187 * \param category event category
188 * \param factor event-weight factor
189 * \return number of modified event weighters
190 */
192 const JEvtWeightFactorHelper& factor)
193 {
194 using namespace std;
195 using namespace JPP;
196
197 size_t n = 0;
198
199 for (iterator i = this->begin(); i != this->end(); ++i) {
200 n += (size_t) i->setEvtWeightFactor(category, factor);
201 }
202
203 return n;
204 }
205
206
207 /**
208 * Set event-weight factor of all MC-files corresponding to a given set of event categories.
209 *
210 * If the boolean `requireAll` argument is set to `true`,\n
211 * the given event-weighting factor will only be assigned to those files\n
212 * whose 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 * \param requireAll toggle requirement that the file headers match all given event categories
217 * \return number of modified event weighters
218 */
219 size_t setEvtWeightFactor(const JEvtCategorySet& categories,
220 const JEvtWeightFactorHelper& factor,
221 const bool requireAll = false)
222 {
223 using namespace std;
224 using namespace JPP;
225
226 size_t n = 0;
227
228 if (requireAll) {
229
230 for (iterator i = this->begin(); i != this->end(); ++i) {
231 n += (size_t) i->setEvtWeightFactor(categories, factor);
232 }
233
234 } else {
235
236 for (iterator i = this->begin(); i != this->end(); ++i) {
237
238 bool isSet = false;
239
240 for (JEvtCategorySet::const_iterator j = categories.cbegin(); j != categories.cend() && !isSet; ++j) {
241 isSet = i->setEvtWeightFactor(*j, factor);
242 }
243
244 n += (size_t) isSet;
245 }
246 }
247
248 return n;
249 }
250
251
252 /**
253 * Set event-weight factor of all MC-files according to a given map between event categories and event-weight factors.
254 *
255 * The template argument refers either to the class `JAANET::JEvtWeightFactorHelper` or `JAANET::JFluxHelper`.
256 *
257 * If the boolean `requireAll` argument is set to `true`,\n
258 * the given event-weighting factor will only be assigned to those files\n
259 * whose header matches < b>all< /b> of the specified event categories.
260 *
261 * \param object map between event categories and event-weight factors
262 * \param requireAll toggle requirement that the file headers match all given event categories
263 * \return number of modified event weighters
264 */
265 template<class JEvtWeightFactorHelper_t>
267 const bool requireAll = false)
268 {
269 using namespace std;
270 using namespace JPP;
271
272 size_t n = 0;
273
274 if (requireAll) {
275
276 for (iterator i = this->begin(); i != this->end(); ++i) {
277 n += (size_t) i->template setEvtWeightFactor<JEvtWeightFactorHelper_t>(object);
278 }
279
280 } else {
281
282 for (iterator i = this->begin(); i != this->end(); ++i) {
283
284 bool isSet = false;
285
286 for (typename JEvtCategoryMap<JEvtWeightFactorHelper_t>::const_iterator j = object.cbegin(); j != object.cend() && !isSet; ++j) {
287 isSet = i->setEvtWeightFactor(j->first, j->second);
288 }
289
290 n += (size_t) isSet;
291 }
292 }
293
294 return n;
295 }
296
297
298 /**
299 * Set flux function for all MC-files corresponding to a given event category.
300 *
301 * \param category event category
302 * \param flux flux function
303 * \return number of modified event weighters
304 */
305 size_t setFlux(const JEvtCategoryHelper& category,
306 const JFluxHelper& flux)
307 {
308 return setEvtWeightFactor(category, flux);
309 }
310
311
312 /**
313 * Set flux function of all MC-files corresponding to a given set of event categories.
314 *
315 * If the boolean `requireAll` argument is set to `true`,
316 * the given flux function will only be assigned to those files\n
317 * whose header lists < b>all< /b> of the specified PDG codes as primaries.
318 *
319 * \param categories set of event categories
320 * \param flux flux function
321 * \param requireAll toggle requirement that each file header must contain every given PDG code.
322 * \return number of modified event weighters
323 */
324 size_t setFlux(const JEvtCategorySet& categories,
325 const JFluxHelper& flux,
326 const bool requireAll = false)
327 {
328 return setEvtWeightFactor(categories, flux, requireAll);
329 }
330
331
332 /**
333 * Set event-weight factor of all MC-files according to a given map between event categories and event-weight factors.
334 *
335 * If the boolean `requireAll` argument is set to `true`,
336 * the given flux function will only be assigned to those files\n
337 * whose header matches < b>all< /b> of the specified event categories.
338 *
339 * \param object map between event categories and flux functions
340 * \param requireAll toggle requirement that the file headers match all given event categories
341 * \return number of modified event weighters
342 */
344 const bool requireAll = false)
345 {
346 return setEvtWeightFactor(object, requireAll);
347 }
348
349
350 /**
351 * Function object for comparison of headers.
352 */
353 JComparator_t compare;
354 };
355
356
357}
358
359#endif
360
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:63
ROOT TTree parameter settings of various packages.
Auxiliary class for reading a map of event categories.
map_type::const_iterator const_iterator
Monte Carlo run header.
Definition JHead.hh:1236
const JHead & getHeader() const
Get header.
Definition JHead.hh:1270
Exception for accessing a value in a collection that is outside of its range.
JEvtWeighter getEventWeighter
Function object for mapping header to event weighter.
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
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.
const int n
Definition JPolint.hh:786
int j
Definition JPolint.hh:792
Helper class for event categories.
Container for a set of event categories.
Helper class for event-weight factor.
Helper class for flux function.
Neutrino flux.
Definition JHead.hh:906
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
size_t setEvtWeightFactor(const JEvtCategoryHelper &category, const JEvtWeightFactorHelper &factor)
Set event-weighting factor for all MC-files corresponding to a given PDG code.
const_reference find(const JHead &head) const
Find file scanner compatible with a given header.
size_t setFlux(const JEvtCategoryMap< JFluxHelper > &object, const bool requireAll=false)
Set event-weight factor of all MC-files according to a given map between event categories and event-w...
size_t setFlux(const JEvtCategoryHelper &category, const JFluxHelper &flux)
Set flux function for all MC-files corresponding to a given event category.
std::vector< filescanner_type >::value_type value_type
JEvtWeightFileScannerSet(const input_type &input)
Constructor.
size_t setEvtWeightFactor(const JEvtCategorySet &categories, const JEvtWeightFactorHelper &factor, const bool requireAll=false)
Set event-weight factor of all MC-files corresponding to a given set of event categories.
std::vector< filescanner_type >::const_reverse_iterator const_reverse_iterator
std::vector< filescanner_type >::const_reference const_reference
std::vector< filescanner_type >::const_iterator const_iterator
size_t setEvtWeightFactor(const JEvtCategoryMap< JEvtWeightFactorHelper_t > &object, const bool requireAll=false)
Set event-weight factor of all MC-files according to a given map between event categories and event-w...
JEvtWeightFileScanner< JFileScanner_t > filescanner_type
bool put(const std::string &input)
Put file.
size_t put(const input_type &input)
Put files.
JComparator_t compare
Function object for comparison of headers.
size_t setFlux(const JEvtCategorySet &categories, const JFluxHelper &flux, const bool requireAll=false)
Set flux function of all MC-files corresponding to a given set of event categories.
std::string getUniqueIdentifier(const_iterator p) const
Get unique identifier for a file-scanner contained within this set of event-weighter-associated file-...
JEvtWeightFileScannerSet< JFileScanner_t, JComparator_t > filescannerset_type
std::vector< filescanner_type >::reference reference
std::vector< filescanner_type >::iterator iterator
std::vector< filescanner_type >::reverse_iterator reverse_iterator
Template event-weighter-associated file scanner.
JFileScanner_t::input_type input_type