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

Program for reweighting gSeaGen 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 "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQTimesliceIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JTrigger/JTriggerParameters.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "Jeep/JProperties.hh"
#include "JLang/JToken.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JMultiHead.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JAAnet/JParticleTypes.hh"
#include "JAAnet/JEvtWeightFactorGSeaGen.hh"
#include "JAAnet/JEvtWeightFactorFunction.hh"
#include "JAAnet/JEvtWeightFactorMultiParticle.hh"
#include "JAAnet/JAtmosphericNeutrinoFlux.hh"
#include "JAAnet/JFlux.hh"
#include "JOscProb/JOscParameters.hh"
#include "JOscProb/JOscProbInterpolator.hh"
#include "JReconstruction/JEvt.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JEvtWeightFileScannerSet.hh"
#include "JSupport/JMonteCarloFileSupportkit.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 gSeaGen data according to a specifiable TFormula.

One TFormula can be specified for each neutrino type. The TFormula may take any number of parameters, but is limited to the physical variables
defined in JEvtWeightFactorGSeaGen. The indices of the physical variables are defined in
the enum JEvtWeightFactorGSeaGen::variables.
Parameter settings can be specified behind the TFormula separated by semicolons, e.g.:
-#anumu="[0]*(x[1]-[1]); p0=1; p1=2.5;"

Author
bjjung

Definition in file JEvtReweightGSeaGen.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 80 of file JEvtReweightGSeaGen.cc.

81 {
82  using namespace std;
83  using namespace JPP;
84  using namespace KM3NETDAQ;
85 
88 
89 
90  JMultipleFileScanner_t inputFiles;
92 
93  string oscProbTable;
94  JOscParameters oscParameters;
95 
97 
98  int debug;
99 
100  try {
101 
102  JProperties formulaMap(JEquationParameters("=","\n\r","./","#"));
103 
104  for (map<int, string>::const_iterator i = nuLabels.cbegin(); i != nuLabels.cend(); ++i) {
105  formulaMap[i->second] = formulae[i->first];
106  }
107 
108  JParser<> zap;
109 
110  zap['f'] = make_field(inputFiles);
111  zap['o'] = make_field(outputFile);
112  zap['P'] = make_field(oscProbTable);
113  zap['@'] = make_field(oscParameters) = JPARSER::initialised();
114  zap['#'] = make_field(formulaMap) = JPARSER::initialised();
115  zap['d'] = make_field(debug) = 1;
116 
117  zap(argc, argv);
118  }
119  catch(const exception& error) {
120  FATAL(error.what() << endl);
121  }
122 
123 
124  // Create flux function
125 
126  JFluxMultiParticle fluxFunction;
127 
128  const JFluxFunction_t atmFlux = make_atmosphericNeutrinoFluxFunction(oscProbTable.c_str(), oscParameters);
129 
130  for (map<int, JEvtWeightFactorGSeaGen>::iterator i = formulae.begin(); i != formulae.end(); ++i) {
131 
132  const TString expression = i->second.GetExpFormula();
133 
134  if (!expression.IsNull() && i->second.IsValid() && i->second.GetNdim() <= JEvtWeightFactorGSeaGen::NUMBER_OF_VARIABLES) {
135 
136  i->second.configure(atmFlux);
137 
138  fluxFunction.insert(i->first, make_fluxFunction(i->second));
139 
140  } else if (expression.IsNull()) {
141 
142  fluxFunction.insert(i->first, atmFlux);
143 
144  } else {
145 
146  FATAL("Invalid formula " << expression << " (number of dimensions must be < " <<
147  JEvtWeightFactorGSeaGen::NUMBER_OF_VARIABLES << "; see `JAANET::JEvtWeightFactorGSeaGen`).");
148  }
149  }
150 
151 
152  // Reweight events
153 
154  outputFile.open();
155 
156  outputFile.put(JMeta(argc, argv));
157 
158  JEvtWeightFileScannerSet<> scanners(inputFiles);
159  scanners.setFlux(fluxFunction);
160 
161  JMultiHead eventHeaders = getMultiHeader(inputFiles);
162 
163  JHead commonHeader = scanners.begin()->getHeader();
164 
165  STATUS(RIGHT(15) << "event" << RIGHT(15) << "weight" << endl);
166 
167  for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
168 
169  JHead header = scanner->getHeader();
170  header.createUUID(); // Ensure UUID is set
171 
172  commonHeader = commonHeader.getMatch(header);
173 
174  eventHeaders.merge(header);
175 
176  while (scanner->hasNext()) {
177 
178  Evt* event = scanner->next();
179 
180  if (event == NULL) {
181  WARNING("Event " << scanner->getCounter() << " is empty; skip.");
182  continue;
183  }
184 
185  const double weight = scanner->getWeight(*event);
186 
187  STATUS(RIGHT (15) << scanner->getCounter() <<
188  SCIENTIFIC(15, 3) << weight << '\r'); DEBUG(endl);
189 
190  if (!isfinite(weight)) {
191 
192  WARNING("Non-finite reweighting factor " << weight <<
193  " for event " << scanner->getCounter() << "!");
194  }
195 
196  if (event->w.size() <= WEIGHTLIST_RESCALED_EVENT_RATE) {
197  event->w.resize(WEIGHTLIST_RESCALED_EVENT_RATE + 1, 0.0);
198  }
199 
200  const JUUID headerUUID = (uuid_is_null(event->header_uuid) == 0 ? // is valid
201  eventHeaders.getHeaderUUID(*event) : header.UUID);
202 
203  event->w[WEIGHTLIST_NORMALISATION] = eventHeaders.getNormalisation(headerUUID);
204  event->w.at(WEIGHTLIST_RESCALED_EVENT_RATE) = weight;
205 
206  uuid_copy(event->header_uuid, headerUUID.uuid);
207 
208  outputFile.put(*event);
209  }
210  }
211 
212  Head newHead;
213  copy(commonHeader, newHead);
214 
215  outputFile.put(newHead);
216 
217  outputFile.put(static_cast<const MultiHead&>(eventHeaders));
218 
220 
221  io >> outputFile;
222 
223  outputFile.close();
224 
225  return 0;
226 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Object writing to file.
JEvtWeightFactorFunction< JAtmosphericNeutrinoFlux, JFlux > make_atmosphericNeutrinoFluxFunction(const std::string &oscProbTableFile, const JOscParameters &oscParameters)
Auxiliary method for creating an interface to an atmospheric neutrino flux function using an oscillat...
Utility class to parse command line options.
Definition: JParser.hh:1514
#define WARNING(A)
Definition: JMessage.hh:65
static const int WEIGHTLIST_RESCALED_EVENT_RATE
Rescaled event rate [s-1].
Definition: weightlist.hh:17
Auxiliary data structure to store multiple headers and bookkeep event-weight normalisations.
Definition: JMultiHead.hh:37
#define STATUS(A)
Definition: JMessage.hh:63
Utility class to parse parameter values.
Definition: JProperties.hh:497
Implementation of event-weight factor interface.
Data structure for single set of oscillation parameters.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
JEvtWeightFactorFunction< JFunction_t, JFlux > make_fluxFunction(const JFunction_t &flux)
Auxiliary method for creating an interface to a flux function.
string outputFile
Monte Carlo run header.
Definition: JHead.hh:1234
JUUID UUID
Definition: JHead.hh:1581
Auxiliary class for recursive type list generation.
Definition: JTypeList.hh:351
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 event-weight factor for multiple particle types.
JMultiHead getMultiHeader(const JMultipleFileScanner_t &file_list)
Get multi-header corresponding to a given file list.
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.
std::vector< filescanner_type >::iterator iterator
Data structure for set of track fit results.
General purpose class for object reading from a list of file names.
Simple wrapper for UUID.
Definition: JUUID.hh:22
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
static const int WEIGHTLIST_NORMALISATION
Event rate normalisation.
Definition: weightlist.hh:16
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1270
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
uuid_t uuid
Definition: JUUID.hh:172
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