Jpp test-rotations-old-57-g407471f53
the software that should make you happy
Loading...
Searching...
No Matches
JPrintAppliedWeights.cc
Go to the documentation of this file.
1#include <iostream>
2#include <string>
3
4#include "Jeep/JPrint.hh"
5#include "Jeep/JParser.hh"
6#include "Jeep/JMessage.hh"
7
8#include "JLang/JClonable.hh"
9#include "JLang/JException.hh"
10
11#include "JAAnet/JHead.hh"
15
17
18#include "JSupport/JSupport.hh"
22
23
24namespace {
25
26 /**
27 * Auxiliary class for event-categories without a defined weight.
28 */
29 class JEvtWeightFactorUndefined final :
30 public JLANG::JClonable<JAANET::JEvtWeightFactor, JEvtWeightFactorUndefined>
31 {
32 public:
33
34 /**
35 * Constructor.
36 */
37 JEvtWeightFactorUndefined()
38 {}
39
40
41 /**
42 * Get event-weight factor of given event.
43 *
44 * \param evt event
45 * \return event-weight factor
46 */
47 double getFactor(const Evt& evt) const override final
48 {
49 using namespace JPP;
50
51 THROW(JNoValue, "JEvtWeightFactorUndefined::getFactor(): No weight defined.");
52 };
53
54
55 /**
56 * Get properties of this class.
57 *
58 * \param eqpars equation parameters
59 */
60 JProperties getProperties(const JEquationParameters& eqpars = JEvtWeightFactor::getEquationParameters()) override final
61 {
62 return JEvtWeightFactorUndefinedHelper(*this, eqpars);
63 }
64
65
66 /**
67 * Get properties of this class.
68 *
69 * \param eqpars equation parameters
70 */
71 JProperties getProperties(const JEquationParameters& eqpars = JEvtWeightFactor::getEquationParameters()) const override final
72 {
73 return JEvtWeightFactorUndefinedHelper(*this, eqpars);
74 }
75
76
77 private:
78
79 /**
80 * Auxiliary class for I/O of JEvtWeightFactorUndefined.
81 */
82 struct JEvtWeightFactorUndefinedHelper :
84 {
85 /**
86 * Constructor.
87 *
88 * \param formula TFormula-based event-weight factor
89 * \param eqpars equation parameters
90 */
91 template<class JEvtWeightFactorUndefined_t>
92 JEvtWeightFactorUndefinedHelper(JEvtWeightFactorUndefined_t& factor,
93 const JEquationParameters& eqpars) :
94 JProperties(eqpars, 1)
95 {
96 (*this)[JEvtWeightFactor::getTypeKey()] = "undefined";
97 }
98 };
99 };
100}
101
102
103/**
104 * \file
105 * Program for printing the applied event-weights for each header type\n
106 * contained in a given set of input files.
107 *
108 * \author bjjung
109 */
110int main(int argc, char **argv)
111{
112 using namespace std;
113 using namespace JPP;
114
115
116 JMultipleFileScanner_t inputFiles;
117
118 JEvtWeightFactorMap factors;
119
120 int debug;
121
122 try {
123
124 JParser<> zap;
125
126 zap['f'] = make_field(inputFiles);
127 zap['@'] = make_field(factors) = JPARSER::initialised();
128 zap['d'] = make_field(debug) = 1;
129
130 zap(argc, argv);
131 }
132 catch(const exception& error) {
133 FATAL(error.what() << endl);
134 }
135
136
137 JEvtWeightFileScannerSet<> scanners(inputFiles);
138
139 if (scanners.setEvtWeightFactor(factors) == 0) {
140 WARNING("No flux functions set." << endl);
141 }
142
143 for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
144
145 const JHead& header = scanner->getHeader();
146 const JEvtWeight& weighter = scanner->getEvtWeighter();
147
148 const JEvtCategorySet categories = getCategories(header);
149
150 const JEvtWeightFactorHelper* p = dynamic_cast<const JEvtWeightFactorHelper*>(&weighter);
151
152 if (p == NULL) { continue; }
153
154 JEvtWeightFactorMap Fmap(factors.getOscProb());
155
156 if (*p) {
157
158 for (JEvtCategorySet::const_iterator i = categories.cbegin(); i != categories.cend(); ++i) {
159 Fmap.insert(*i, *p);
160 }
161
162 } else {
163
164 const JEvtWeightFactorHelper helper(make_shared<JEvtWeightFactorUndefined>());
165
166 for (JEvtCategorySet::const_iterator i = categories.cbegin(); i != categories.cend(); ++i) {
167 Fmap.insert(*i, helper);
168 }
169 }
170
171 NOTICE("scanner " << distance(scanners.begin(), scanner) << ":" << endl <<
172 "======================================================" << endl);
173 DEBUG (endl << header << endl << endl);
174 NOTICE(Fmap << endl);
175 }
176
177 return 0;
178}
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define WARNING(A)
Definition JMessage.hh:65
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, char **argv)
I/O formatting auxiliaries.
ROOT TTree parameter settings of various packages.
Auxiliary methods for evaluating visible energies.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Template specialisation for a map between event categories and event-weight factor products.
void insert(const JEvtCategoryHelper &category, const JEvtWeightFactorProduct &product)
Insert pair of an event category and a product of event-weight factors.
const JOscProbHelper & getOscProb() const
Get oscillation probability calculator.
Monte Carlo run header.
Definition JHead.hh:1236
const JHead & getHeader() const
Get header.
Definition JHead.hh:1270
Utility class to parse parameter values.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Exception for missing value.
Utility class to parse command line options.
Definition JParser.hh:1698
JEvtCategorySet getCategories(const JHead &header)
Auxiliary method to retrieve the unique event categories corresponding to a MC header.
JProperties & getProperties(T &object, const JEquationParameters &parameters=JEquationParameters(), const int debug=1)
Get properties of a given object.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
Container for a set of event categories.
Helper class for event-weight factor.
Abstract base class for event weighing.
Definition JEvtWeight.hh:31
Template class for object cloning.
Definition JClonable.hh:59
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
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.
std::vector< filescanner_type >::iterator iterator
Auxiliary base class for list of file names.