Jpp 20.0.0-rc.2
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 51 of file JEvtReweight.cc.

52{
53 using namespace std;
54 using namespace JPP;
55 using namespace KM3NETDAQ;
56
58
59
60 JMultipleFileScanner_t inputFiles;
62
63 JEvtWeightFactorMap factors;
64
65 int debug;
66
67 try {
68
69 JParser<> zap;
70
71 zap['f'] = make_field(inputFiles);
72 zap['o'] = make_field(outputFile);
73 zap['@'] = make_field(factors) = JPARSER::initialised();
74 zap['d'] = make_field(debug) = 1;
75
76 zap(argc, argv);
77 }
78 catch(const exception& error) {
79 FATAL(error.what() << endl);
80 }
81
82 // Reweight events
83
84 JEvtWeightFileScannerSet<> scanners(inputFiles);
85
86 if (scanners.setEvtWeightFactor(factors) == 0) {
87 FATAL("No weight factors could be set." << endl);
88 }
89
90 JMultiHead eventHeaders = getMultiHeader(inputFiles);
91
92 JHead commonHeader = scanners.begin()->getHeader();
93
94 outputFile.open();
95
96 outputFile.put(JMeta(argc, argv));
97
98 STATUS(RIGHT(15) << "event" << RIGHT(15) << "weight" << endl);
99
100 for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
101
102 JHead header = scanner->getHeader();
103
104 header.createUUID(); // Ensure UUID is set
105
106 commonHeader = commonHeader.getMatch(header);
107
108 eventHeaders.merge(header);
109
110 for (JMultipleFileScanner<Evt> in(scanner->getFilelist()); in.hasNext(); ) {
111
112 Evt* event = in.next();
113
114 if (event == NULL) {
115 WARNING("Event " << in.getCounter() << " is empty; skip.");
116 continue;
117 }
118
119 const double weight = scanner->getWeight(*event);
120
121 STATUS(RIGHT (15) << in.getCounter() <<
122 SCIENTIFIC(15, 3) << weight << '\r'); DEBUG(endl);
123
124 if (!isfinite(weight)) {
125
126 WARNING("Non-finite reweighting factor " << weight <<
127 " for event " << in.getCounter() << "!");
128 }
129
130 if (event->w.size() <= WEIGHTLIST_RESCALED_EVENT_RATE) {
131 event->w.resize(WEIGHTLIST_RESCALED_EVENT_RATE + 1, 0.0);
132 }
133
134 const JUUID headerUUID = (uuid_is_null(event->header_uuid) == 0 ? // is valid
135 eventHeaders.getHeaderUUID(*event) : header.UUID);
136
137 event->w[WEIGHTLIST_NORMALISATION] = eventHeaders.getNormalisation(headerUUID);
138 event->w.at(WEIGHTLIST_RESCALED_EVENT_RATE) = weight;
139
140 uuid_copy(event->header_uuid, headerUUID.uuid);
141
142 outputFile.put(*event);
143 }
144 }
145
146 Head newHead;
147 copy(commonHeader, newHead);
148
149 outputFile.put(newHead);
150
151 outputFile.put(static_cast<const MultiHead&>(eventHeaders));
152
154
155 io >> outputFile;
156
157 outputFile.close();
158
159 return 0;
160}
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:72
#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.
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.
virtual bool hasNext() override
Check availability of next element.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
@ 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.
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