Jpp master_rocky-44-g75b7c4f75
the software that should make you happy
Loading...
Searching...
No Matches
JEvtReweight.cc File Reference

Program for reweighting Monte-Carlo simulations. More...

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Program for reweighting Monte-Carlo simulations.

Author
bjjung

Definition in file JEvtReweight.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 53 of file JEvtReweight.cc.

54{
55 using namespace std;
56 using namespace JPP;
57 using namespace KM3NETDAQ;
58
60
61
62 JMultipleFileScanner_t inputFiles;
64
65 string oscProbTable;
66 JOscParameters<double> oscParameters;
67
69
70 int debug;
71
72 try {
73
74 JParser<> zap;
75
76 zap['f'] = make_field(inputFiles);
77 zap['o'] = make_field(outputFile);
78 zap['P'] = make_field(oscProbTable) = JPARSER::initialised();
79 zap['@'] = make_field(oscParameters) = JPARSER::initialised();
80 zap['%'] = make_field(factors) = JPARSER::initialised();
81 zap['d'] = make_field(debug) = 1;
82
83 zap(argc, argv);
84 }
85 catch(const exception& error) {
86 FATAL(error.what() << endl);
87 }
88
89
90 // Load oscillation probability table
91
92 if (!oscProbTable.empty()) {
93
94 JOscProbInterpolator<>& interpolator = static_cast<JOscProbInterpolator<>&>(factors.oscProb.getOscProbInterface());
95
96 interpolator.load(oscProbTable.c_str());
97 interpolator.set (oscParameters);
98 }
99
100
101 // Reweight events
102
103 JEvtWeightFileScannerSet<> scanners(inputFiles);
104
105 if (scanners.setEvtWeightFactor(factors) == 0) {
106 FATAL("No weight factors could be set." << endl);
107 }
108
109 JMultiHead eventHeaders = getMultiHeader(inputFiles);
110
111 JHead commonHeader = scanners.begin()->getHeader();
112
113 outputFile.open();
114
115 outputFile.put(JMeta(argc, argv));
116
117 STATUS(RIGHT(15) << "event" << RIGHT(15) << "weight" << endl);
118
119 for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
120
121 JHead header = scanner->getHeader();
122 header.createUUID(); // Ensure UUID is set
123
124 commonHeader = commonHeader.getMatch(header);
125
126 eventHeaders.merge(header);
127
128 while (scanner->hasNext()) {
129
130 Evt* event = scanner->next();
131
132 if (event == NULL) {
133 WARNING("Event " << scanner->getCounter() << " is empty; skip.");
134 continue;
135 }
136
137 const double weight = scanner->getWeight(*event);
138
139 STATUS(RIGHT (15) << scanner->getCounter() <<
140 SCIENTIFIC(15, 3) << weight << '\r'); DEBUG(endl);
141
142 if (!isfinite(weight)) {
143
144 WARNING("Non-finite reweighting factor " << weight <<
145 " for event " << scanner->getCounter() << "!");
146 }
147
148 if (event->w.size() <= WEIGHTLIST_RESCALED_EVENT_RATE) {
149 event->w.resize(WEIGHTLIST_RESCALED_EVENT_RATE + 1, 0.0);
150 }
151
152 const JUUID headerUUID = (uuid_is_null(event->header_uuid) == 0 ? // is valid
153 eventHeaders.getHeaderUUID(*event) : header.UUID);
154
155 event->w[WEIGHTLIST_NORMALISATION] = eventHeaders.getNormalisation(headerUUID);
156 event->w.at(WEIGHTLIST_RESCALED_EVENT_RATE) = weight;
157
158 uuid_copy(event->header_uuid, headerUUID.uuid);
159
160 outputFile.put(*event);
161 }
162 }
163
164 Head newHead;
165 copy(commonHeader, newHead);
166
167 outputFile.put(newHead);
168
169 outputFile.put(static_cast<const MultiHead&>(eventHeaders));
170
172
173 io >> outputFile;
174
175 outputFile.close();
176
177 return 0;
178}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:69
#define WARNING(A)
Definition JMessage.hh:65
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Template specialisation for a map between event categories and event-weight factor products.
Monte Carlo run header.
Definition JHead.hh:1236
void createUUID()
Create UUID if not already set.
Definition JHead.hh:1301
const JHead & getHeader() const
Get header.
Definition JHead.hh:1270
JHead getMatch(const JHead &header) const
Get matching fields.
Definition JHead.hh:1410
Data structure for set of track fit results.
Data structure for single set of oscillation parameters.
Template definition of a multi-dimensional oscillation probability interpolation table.
void load(const char *const fileName)
Load oscillation probability table from file.
Utility class to parse command line options.
Definition JParser.hh:1698
Object writing to file.
General purpose class for object reading from a list of file names.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:162
@ RIGHT
Definition JTwosome.hh:18
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JMultiHead getMultiHeader(const JMultipleFileScanner_t &file_list)
Get multi-header corresponding to a given file list.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition Head.hh:65
Auxiliary data structure to store multiple headers and bookkeep event-weight normalisations.
Definition JMultiHead.hh:39
void merge(const JHead &header)
Merge the given header into this object.
Definition JMultiHead.hh:56
double getNormalisation(const JUUID &UUID) const
Get normalisation for given header UUID.
JUUID getHeaderUUID(const Evt &event) const
Get the header UUID corresponding to the given event.
Auxiliary class for recursive type list generation.
Definition JTypeList.hh:351
Simple wrapper for UUID.
Definition JUUID.hh:24
uuid_t uuid
Definition JUUID.hh:172
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.
std::vector< filescanner_type >::iterator iterator
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72
Auxiliary base class for list of file names.
Auxiliary data structure for alignment of data.
Definition JManip.hh:298
Auxiliary data structure for floating point format specification.
Definition JManip.hh:488
static const int WEIGHTLIST_RESCALED_EVENT_RATE
Rescaled event rate [s-1].
Definition weightlist.hh:17
static const int WEIGHTLIST_NORMALISATION
Event rate normalisation.
Definition weightlist.hh:16