Jpp 20.0.0-rc.2
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 template<class JComparator_t = std::less<JHead> >
57 public std::vector<JEvtWeightFileScanner>
58 {
60
61
62 /**
63 * Default constructor.
64 */
67
68
69 /**
70 * Constructor.
71 *
72 * \param input input files
73 */
75 {
76 put(input);
77 }
78
79
80 /**
81 * Put files
82 *
83 * \param input input files
84 * \return number of added files
85 */
86 size_t put(const input_type& input)
87 {
88 size_t n = 0;
89
90 for (typename input_type::const_iterator i = input.begin(); i != input.end(); ++i) {
91 n += size_t(this->put(*i));
92 }
93
94 return n;
95 }
96
97
98 /**
99 * Put file
100 *
101 * \param input input file
102 * \return true if successfully added; else false.
103 */
104 bool put(const std::string& input)
105 {
106 using namespace std;
107 using namespace JPP;
108
109 const JHead& head = getHeader(input);
110
111 iterator i = lower_bound(this->begin(), this->end(), head,
113
114 if (i == this->end() || !i->getHeader().match(head)) {
115 i = this->insert(i, value_type(getEventWeighter(head)));
116 }
117
118 return i->put(input);
119 }
120
121
122 /**
123 * Find file scanner compatible with a given header.
124 *
125 * \param head header
126 * \return file scanner
127 */
128 const_reference find(const JHead& head) const
129 {
130 using namespace JPP;
131
132 for (const_iterator i = this->begin(); i != this->end(); ++i) {
133 if (i->match(head)) {
134 return *i;
135 }
136 }
137
138 THROW(JValueOutOfRange, "JEvtWeightFileScannerSet::get(): No corresponding scanner found for given header.");
139 }
140
141
142 /**
143 * Set event-weighting factor for all MC-files corresponding to a given PDG code.
144 *
145 * \param category event category
146 * \param factor event-weight factor
147 * \return number of modified event weighters
148 */
150 const JEvtWeightFactorHelper& factor)
151 {
152 using namespace std;
153 using namespace JPP;
154
155 size_t n = 0;
156
157 for (iterator i = this->begin(); i != this->end(); ++i) {
158 n += (size_t) i->setEvtWeightFactor(category, factor);
159 }
160
161 return n;
162 }
163
164
165 /**
166 * Set event-weight factor of all MC-files corresponding to a given set of event categories.
167 *
168 * If the boolean `requireAll` argument is set to `true`,\n
169 * the given event-weighting factor will only be assigned to those files\n
170 * whose header matches < b>all< /b> of the specified event categories.
171 *
172 * \param categories set of event categories
173 * \param factor event-weight factor
174 * \param requireAll toggle requirement that the file headers match all given event categories
175 * \return number of modified event weighters
176 */
177 size_t setEvtWeightFactor(const JEvtCategorySet& categories,
178 const JEvtWeightFactorHelper& factor,
179 const bool requireAll = false)
180 {
181 using namespace std;
182 using namespace JPP;
183
184 size_t n = 0;
185
186 if (requireAll) {
187
188 for (iterator i = this->begin(); i != this->end(); ++i) {
189 n += (size_t) i->setEvtWeightFactor(categories, factor);
190 }
191
192 } else {
193
194 for (iterator i = this->begin(); i != this->end(); ++i) {
195
196 bool isSet = false;
197
198 for (JEvtCategorySet::const_iterator j = categories.cbegin(); j != categories.cend() && !isSet; ++j) {
199 isSet = i->setEvtWeightFactor(*j, factor);
200 }
201
202 n += (size_t) isSet;
203 }
204 }
205
206 return n;
207 }
208
209
210 /**
211 * Set event-weight factor of all MC-files according to a given map between event categories and event-weight factors.
212 *
213 * The template argument refers either to the class `JAANET::JEvtWeightFactorHelper` or `JAANET::JFluxHelper`.
214 *
215 * If the boolean `requireAll` argument is set to `true`,\n
216 * the given event-weighting factor will only be assigned to those files\n
217 * whose header matches < b>all< /b> of the specified event categories.
218 *
219 * \param object map between event categories and event-weight factors
220 * \param requireAll toggle requirement that the file headers match all given event categories
221 * \return number of modified event weighters
222 */
223 template<class JEvtWeightFactorHelper_t>
225 const bool requireAll = false)
226 {
227 using namespace std;
228 using namespace JPP;
229
230 size_t n = 0;
231
232 if (requireAll) {
233
234 for (iterator i = this->begin(); i != this->end(); ++i) {
235 n += (size_t) i->template setEvtWeightFactor<JEvtWeightFactorHelper_t>(object);
236 }
237
238 } else {
239
240 for (iterator i = this->begin(); i != this->end(); ++i) {
241
242 bool isSet = false;
243
244 for (typename JEvtCategoryMap<JEvtWeightFactorHelper_t>::const_iterator j = object.cbegin(); j != object.cend() && !isSet; ++j) {
245 isSet = i->setEvtWeightFactor(j->first, j->second);
246 }
247
248 n += (size_t) isSet;
249 }
250 }
251
252 return n;
253 }
254
255
256 /**
257 * Set flux function for all MC-files corresponding to a given event category.
258 *
259 * \param category event category
260 * \param flux flux function
261 * \return number of modified event weighters
262 */
263 size_t setFlux(const JEvtCategoryHelper& category,
264 const JFluxHelper& flux)
265 {
266 return setEvtWeightFactor(category, flux);
267 }
268
269
270 /**
271 * Set flux function of all MC-files corresponding to a given set of event categories.
272 *
273 * If the boolean `requireAll` argument is set to `true`,
274 * the given flux function will only be assigned to those files\n
275 * whose header lists < b>all< /b> of the specified PDG codes as primaries.
276 *
277 * \param categories set of event categories
278 * \param flux flux function
279 * \param requireAll toggle requirement that each file header must contain every given PDG code.
280 * \return number of modified event weighters
281 */
282 size_t setFlux(const JEvtCategorySet& categories,
283 const JFluxHelper& flux,
284 const bool requireAll = false)
285 {
286 return setEvtWeightFactor(categories, flux, requireAll);
287 }
288
289
290 /**
291 * Set event-weight factor of all MC-files according to a given map between event categories and event-weight factors.
292 *
293 * If the boolean `requireAll` argument is set to `true`,
294 * the given flux function will only be assigned to those files\n
295 * whose header matches < b>all< /b> of the specified event categories.
296 *
297 * \param object map between event categories and flux functions
298 * \param requireAll toggle requirement that the file headers match all given event categories
299 * \return number of modified event weighters
300 */
302 const bool requireAll = false)
303 {
304 return setEvtWeightFactor(object, requireAll);
305 }
306
307
308 /**
309 * Function object for comparison of headers.
310 */
311 JComparator_t compare;
312 };
313
314
315}
316
317#endif
318
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...
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:791
int j
Definition JPolint.hh:801
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 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 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...
JComparator_t compare
Function object for comparison of headers.
JEvtWeightFileScannerSet(const input_type &input)
Constructor.
size_t setFlux(const JEvtCategoryHelper &category, const JFluxHelper &flux)
Set flux function for all MC-files corresponding to a given event category.
JEvtWeightFileScanner::input_type input_type
size_t put(const input_type &input)
Put files.
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.
bool put(const std::string &input)
Put file.
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 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.
Auxiliary base class for list of file names.