Jpp 19.3.0-rc.1
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 header.createUUID(); // Ensure UUID is set
104
105 commonHeader = commonHeader.getMatch(header);
106
107 eventHeaders.merge(header);
108
109 while (scanner->hasNext()) {
110
111 Evt* event = scanner->next();
112
113 if (event == NULL) {
114 WARNING("Event " << scanner->getCounter() << " is empty; skip.");
115 continue;
116 }
117
118 const double weight = scanner->getWeight(*event);
119
120 STATUS(RIGHT (15) << scanner->getCounter() <<
121 SCIENTIFIC(15, 3) << weight << '\r'); DEBUG(endl);
122
123 if (!isfinite(weight)) {
124
125 WARNING("Non-finite reweighting factor " << weight <<
126 " for event " << scanner->getCounter() << "!");
127 }
128
129 if (event->w.size() <= WEIGHTLIST_RESCALED_EVENT_RATE) {
130 event->w.resize(WEIGHTLIST_RESCALED_EVENT_RATE + 1, 0.0);
131 }
132
133 const JUUID headerUUID = (uuid_is_null(event->header_uuid) == 0 ? // is valid
134 eventHeaders.getHeaderUUID(*event) : header.UUID);
135
136 event->w[WEIGHTLIST_NORMALISATION] = eventHeaders.getNormalisation(headerUUID);
137 event->w.at(WEIGHTLIST_RESCALED_EVENT_RATE) = weight;
138
139 uuid_copy(event->header_uuid, headerUUID.uuid);
140
141 outputFile.put(*event);
142 }
143 }
144
145 Head newHead;
146 copy(commonHeader, newHead);
147
148 outputFile.put(newHead);
149
150 outputFile.put(static_cast<const MultiHead&>(eventHeaders));
151
153
154 io >> outputFile;
155
156 outputFile.close();
157
158 return 0;
159}
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.
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.
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