Jpp  18.2.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JEvtReweightMupage.cc File Reference

Program for reweighting mupage data according to a specifiable TFormula. More...

#include <uuid/uuid.h>
#include <iostream>
#include <string>
#include <vector>
#include "km3net-dataformat/definitions/weightlist.hh"
#include "km3net-dataformat/offline/MultiHead.hh"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JLang/JToken.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JAAnet/JEvtWeightFactorMupage.hh"
#include "JAAnet/JEvtWeightFactorFunction.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JEvtWeightFileScanner.hh"
#include "JGizmo/JGizmoToolkit.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Program for reweighting mupage data according to a specifiable TFormula.

The TFormula may take any number of parameters, but is limited to the physical variables
defined in JEvtWeightFactorMupage. The indices of the physical variables are defined in
the enum JEvtWeightFactorMupage::variables.

Author
bjung

Definition in file JEvtReweightMupage.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 43 of file JEvtReweightMupage.cc.

44 {
45  using namespace std;
46  using namespace JPP;
47 
48  typedef typename JTYPELIST<JAAnetTypes_t, JMetaTypes_t>::typelist typelist;
49  typedef JToken<';'> JToken_t;
50 
51 
52  JMultipleFileScanner_t inputFiles;
54 
55  string formula;
57 
58  int debug;
59 
60  try {
61 
62  JParser<> zap;
63 
64  zap['f'] = make_field(inputFiles);
65  zap['o'] = make_field(outputFile);
66  zap['F'] = make_field(formula, "Reweighting formula, e.g.: \"[0] + [1]*x[0]\"") = "";
67  zap['@'] = make_field(parameters, "Parameter values, e.g.: \"p0 = 0.5; p1 = 0.2;\"") = JPARSER::initialised();
68  zap['d'] = make_field(debug) = 1;
69 
70  zap(argc, argv);
71  }
72  catch(const exception& error) {
73  FATAL(error.what() << endl);
74  }
75 
76 
77  // Create file scanner
78 
79  JEvtWeightFileScanner<> scanner(inputFiles);
80 
81  JHead& header = scanner.getHeader();
82  header.createUUID();
83 
84  if (!is_mupage(header)) {
85  FATAL("MC-header is incompatible with MUPAGE.");
86  }
87 
88 
89  // Define reweighting function
90 
91  JEvtWeightFactorMupage reweighter("reweighter", formula.c_str());
92 
93  if (reweighter.GetNdim() > JEvtWeightFactorMupage::NUMBER_OF_VARIABLES) {
94 
95  FATAL("Invalid formula " << formula << " (number of dimensions must be < " <<
96  JEvtWeightFactorMupage::NUMBER_OF_VARIABLES << "; see `JAANET::JEvtWeightFactorMupage`).");
97  }
98 
99  if (size_t(reweighter.GetNpar()) != parameters.size()) {
100 
101  FATAL("Not all parameters have been specified.");
102  }
103 
104 
105  // Read parameter settings
106 
107  try {
108 
109  for (vector<JToken_t>::const_iterator i = parameters.begin(); i != parameters.cend(); ++i) {
110 
111  const int index = getParameter(*i);
112 
113  reweighter.SetParameter(index, getValue(*i, 0));
114  }
115  }
116  catch (JLANG::JParseError& error) {
117  FATAL(error << endl);
118  }
119 
120 
121  // Set reweighting factors for mupage-files
122 
123  if (!scanner.setEvtWeightFactor(TRACK_TYPE_MUON, make_weightFactor(reweighter)) ||
124  !scanner.setEvtWeightFactor(TRACK_TYPE_ANTIMUON, make_weightFactor(reweighter))) {
125  FATAL("Setting of reweighting factor was unsuccessful.");
126  }
127 
128 
129  // Store events with new weights
130 
131  outputFile.open();
132 
133  Head head;
134  copy(header, head);
135  outputFile.put(head);
136 
137  outputFile.put(JMeta(argc, argv));
138 
139  STATUS(RIGHT(15) << "event" << RIGHT(15) << "weight" << endl);
140 
141  while (scanner.hasNext()) {
142 
143  const Evt* event = scanner.next();
144 
145  if (event != NULL) {
146 
147  const double weight = scanner.getWeight(*event);
148 
149  STATUS(RIGHT (15) << scanner.getCounter() <<
150  SCIENTIFIC(15, 3) << weight << '\r'); DEBUG(endl);
151 
152  if (!isfinite(weight)) {
153 
154  WARNING("Non-finite reweighting factor " << weight <<
155  " for event " << scanner.getCounter() << "!");
156  }
157 
158  Evt out = *event;
159 
160  uuid_copy(out.header_uuid, header.UUID.uuid);
161 
162  if (out.w.size() <= WEIGHTLIST_RESCALED_EVENT_RATE) {
163  out.w.resize(WEIGHTLIST_RESCALED_EVENT_RATE + 1, 0.0);
164  }
165 
166  out.w.at(WEIGHTLIST_NORMALISATION) = scanner.getNormalisation(*event);
167  out.w.at(WEIGHTLIST_RESCALED_EVENT_RATE) = weight;
168 
169  outputFile.put(out);
170 
171  } else {
172 
173  WARNING("Event " << scanner.getCounter() << " is empty; skip.");
174  }
175  }
176 
178 
179  io >> outputFile;
180 
181  outputFile.close();
182 
183  return 0;
184 }
bool is_mupage(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:85
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1514
#define WARNING(A)
Definition: JMessage.hh:65
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
Definition: JScale.hh:47
int getParameter(const std::string &text)
Get parameter number from text string.
static const int WEIGHTLIST_RESCALED_EVENT_RATE
Rescaled event rate [s-1].
Definition: weightlist.hh:17
#define STATUS(A)
Definition: JMessage.hh:63
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]=w3 (see e.g. Tag list or km3net-dataformat/definitions) ...
Definition: Evt.hh:42
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
string outputFile
Type list.
Definition: JTypeList.hh:22
JEvtWeightFactorFunction< JFunction_t, JEvtWeightFactor_t > make_weightFactor(const JFunction_t &function)
Auxiliary method for creating an interface to an event-weight factor.
Monte Carlo run header.
Definition: JHead.hh:1234
uuid_t header_uuid
UUID of header containing the event-weight information.
Definition: Evt.hh:35
void createUUID()
Create UUID if not already set.
Definition: JHead.hh:1301
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
Implementation of reweighting factor for mupage events according to a specifiable ROOT TFormula...
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
#define FATAL(A)
Definition: JMessage.hh:67
Auxiliary base class for list of file names.
General purpose class for object reading from a list of file names.
Wrapper class around string.
Definition: JToken.hh:23
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
Exception for parsing value.
Definition: JException.hh:196
static const int WEIGHTLIST_NORMALISATION
Event rate normalisation.
Definition: weightlist.hh:16
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1270
Template event-weighter-associated file scanner.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484
int debug
debug level
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62