Jpp 19.3.0-rc.3
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 * Find file scanner compatible with a given header.
140 *
141 * \param head header
142 * \return file scanner
143 */
144 const_reference find(const JHead& head) const
145 {
146 using namespace JPP;
147
148 for (const_iterator i = this->begin(); i != this->end(); ++i) {
149 if (i->match(head)) {
150 return *i;
151 }
152 }
153
154 THROW(JValueOutOfRange, "JEvtWeightFileScannerSet::get(): No corresponding scanner found for given header.");
155 }
156
157
158 /**
159 * Set event-weighting factor for all MC-files corresponding to a given PDG code.
160 *
161 * \param category event category
162 * \param factor event-weight factor
163 * \return number of modified event weighters
164 */
166 const JEvtWeightFactorHelper& factor)
167 {
168 using namespace std;
169 using namespace JPP;
170
171 size_t n = 0;
172
173 for (iterator i = this->begin(); i != this->end(); ++i) {
174 n += (size_t) i->setEvtWeightFactor(category, factor);
175 }
176
177 return n;
178 }
179
180
181 /**
182 * Set event-weight factor of all MC-files corresponding to a given set of event categories.
183 *
184 * If the boolean `requireAll` argument is set to `true`,\n
185 * the given event-weighting factor will only be assigned to those files\n
186 * whose header matches < b>all< /b> of the specified event categories.
187 *
188 * \param categories set of event categories
189 * \param factor event-weight factor
190 * \param requireAll toggle requirement that the file headers match all given event categories
191 * \return number of modified event weighters
192 */
193 size_t setEvtWeightFactor(const JEvtCategorySet& categories,
194 const JEvtWeightFactorHelper& factor,
195 const bool requireAll = false)
196 {
197 using namespace std;
198 using namespace JPP;
199
200 size_t n = 0;
201
202 if (requireAll) {
203
204 for (iterator i = this->begin(); i != this->end(); ++i) {
205 n += (size_t) i->setEvtWeightFactor(categories, factor);
206 }
207
208 } else {
209
210 for (iterator i = this->begin(); i != this->end(); ++i) {
211
212 bool isSet = false;
213
214 for (JEvtCategorySet::const_iterator j = categories.cbegin(); j != categories.cend() && !isSet; ++j) {
215 isSet = i->setEvtWeightFactor(*j, factor);
216 }
217
218 n += (size_t) isSet;
219 }
220 }
221
222 return n;
223 }
224
225
226 /**
227 * Set event-weight factor of all MC-files according to a given map between event categories and event-weight factors.
228 *
229 * The template argument refers either to the class `JAANET::JEvtWeightFactorHelper` or `JAANET::JFluxHelper`.
230 *
231 * If the boolean `requireAll` argument is set to `true`,\n
232 * the given event-weighting factor will only be assigned to those files\n
233 * whose header matches < b>all< /b> of the specified event categories.
234 *
235 * \param object map between event categories and event-weight factors
236 * \param requireAll toggle requirement that the file headers match all given event categories
237 * \return number of modified event weighters
238 */
239 template<class JEvtWeightFactorHelper_t>
241 const bool requireAll = false)
242 {
243 using namespace std;
244 using namespace JPP;
245
246 size_t n = 0;
247
248 if (requireAll) {
249
250 for (iterator i = this->begin(); i != this->end(); ++i) {
251 n += (size_t) i->template setEvtWeightFactor<JEvtWeightFactorHelper_t>(object);
252 }
253
254 } else {
255
256 for (iterator i = this->begin(); i != this->end(); ++i) {
257
258 bool isSet = false;
259
260 for (typename JEvtCategoryMap<JEvtWeightFactorHelper_t>::const_iterator j = object.cbegin(); j != object.cend() && !isSet; ++j) {
261 isSet = i->setEvtWeightFactor(j->first, j->second);
262 }
263
264 n += (size_t) isSet;
265 }
266 }
267
268 return n;
269 }
270
271
272 /**
273 * Set flux function for all MC-files corresponding to a given event category.
274 *
275 * \param category event category
276 * \param flux flux function
277 * \return number of modified event weighters
278 */
279 size_t setFlux(const JEvtCategoryHelper& category,
280 const JFluxHelper& flux)
281 {
282 return setEvtWeightFactor(category, flux);
283 }
284
285
286 /**
287 * Set flux function of all MC-files corresponding to a given set of event categories.
288 *
289 * If the boolean `requireAll` argument is set to `true`,
290 * the given flux function will only be assigned to those files\n
291 * whose header lists < b>all< /b> of the specified PDG codes as primaries.
292 *
293 * \param categories set of event categories
294 * \param flux flux function
295 * \param requireAll toggle requirement that each file header must contain every given PDG code.
296 * \return number of modified event weighters
297 */
298 size_t setFlux(const JEvtCategorySet& categories,
299 const JFluxHelper& flux,
300 const bool requireAll = false)
301 {
302 return setEvtWeightFactor(categories, flux, requireAll);
303 }
304
305
306 /**
307 * Set event-weight factor of all MC-files according to a given map between event categories and event-weight factors.
308 *
309 * If the boolean `requireAll` argument is set to `true`,
310 * the given flux function will only be assigned to those files\n
311 * whose header matches < b>all< /b> of the specified event categories.
312 *
313 * \param object map between event categories and flux functions
314 * \param requireAll toggle requirement that the file headers match all given event categories
315 * \return number of modified event weighters
316 */
318 const bool requireAll = false)
319 {
320 return setEvtWeightFactor(object, requireAll);
321 }
322
323
324 /**
325 * Function object for comparison of headers.
326 */
327 JComparator_t compare;
328 };
329
330
331}
332
333#endif
334
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 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.
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