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

Example program for scanning event-weights of Monte Carlo files
containing a given set of primaries. More...

#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "JLang/JException.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JAAnet/JEvtWeightFactorFunction.hh"
#include "JAAnet/JEvtWeightFactorMultiParticle.hh"
#include "JAAnet/JFlux.hh"
#include "JSupport/JLimit.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JEvtWeightFileScannerSet.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "Jeep/JProperties.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program for scanning event-weights of Monte Carlo files
containing a given set of primaries.

The list of possible options for the flux includes:

   -@ zero      <type>
   -@ flat      <type>  <value>
   -@ powerlaw  <type>  <normalisation>  <spectral index>
Author
bjung

Definition in file JFluxMultiParticle.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 219 of file JFluxMultiParticle.cc.

220 {
221  using namespace std;
222  using namespace JPP;
223 
224  JMultipleFileScanner_t inputFiles;
225 
226  vector<int> zeroFluxes;
227  map<int, JFlatFlux> flatFluxes;
228  map<int, JPowerLawFlux> powerlawFluxes;
229 
230  int debug;
231 
232  try {
233 
234  JProperties fluxMaps;
235 
236  fluxMaps["zero"] = zeroFluxes;
237  fluxMaps["flat"] = flatFluxes;
238  fluxMaps["powerlaw"] = powerlawFluxes;
239 
240  JParser<> zap;
241 
242  zap['f'] = make_field(inputFiles);
243  zap['@'] = make_field(fluxMaps) = JPARSER::initialised();
244  zap['d'] = make_field(debug) = 1;
245 
246  zap(argc, argv);
247  }
248  catch(const exception& error) {
249  FATAL(error.what() << endl);
250  }
251 
252  // Sanity checks
253 
254  for (map<int, JPowerLawFlux>::const_iterator i = powerlawFluxes.cbegin(); i != powerlawFluxes.cend(); ++i) {
255  if (abs(i->first) != TRACK_TYPE_NUE &&
256  abs(i->first) != TRACK_TYPE_NUMU &&
257  abs(i->first) != TRACK_TYPE_NUTAU) {
258  FATAL("Particle type " << i->first << " does not correspond to a neutrino." << endl);
259  }
260  }
261 
262  // Create multi-particle flux function
263 
264  JFluxMultiParticle multiFlux;
265 
266  for (vector<int>::const_iterator i = zeroFluxes.cbegin(); i != zeroFluxes.cend(); ++i) {
267  multiFlux.insert(*i, make_fluxFunction(zeroFlux));
268  }
269 
270  for (map<int, JFlatFlux>::const_iterator i = flatFluxes.cbegin(); i != flatFluxes.cend(); ++i) {
271  multiFlux.insert(i->first, make_fluxFunction(i->second));
272  }
273 
274  for (map<int, JPowerLawFlux>::const_iterator i = powerlawFluxes.cbegin(); i != powerlawFluxes.cend(); ++i) {
275  multiFlux.insert(i->first, make_fluxFunction(i->second));
276  }
277 
278 
279  // Set event weighter
280 
281  JEvtWeightFileScannerSet<> scanners(inputFiles);
282 
283  const size_t n = scanners.setFlux(multiFlux);
284 
285  if (n == 0) {
286  WARNING("No file found containing all given primaries; Flux function not set." << endl);
287  }
288 
289 
290  // Scan events
291 
292  for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
293 
294  if (scanner->simul.size() > 0) {
295  STATUS("Scanning " << scanner->simul[0].program << " files..." << endl);
296  }
297 
298  STATUS(LEFT(15) << "event" << RIGHT(15) << "weight" << endl);
299 
300  while (scanner->hasNext()) {
301 
302  const Evt* event = scanner->next();
303  const double weight = scanner->getWeight(*event);
304 
305  STATUS(LEFT (15) << scanner->getCounter() <<
306  SCIENTIFIC(15, 3) << weight << '\r'); DEBUG(endl);
307  }
308  }
309 
310  return 0;
311 }
Utility class to parse command line options.
Definition: JParser.hh:1517
void insert(const int type, const JEvtWeightFactor_t &factor)
Insert pair of particle code and event-weight factor.
#define STATUS(A)
Definition: JMessage.hh:63
Utility class to parse parameter values.
Definition: JProperties.hh:496
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.
const int n
Definition: JPolint.hh:697
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
Implementation of event-weight factor for multiple particle types.
#define FATAL(A)
Definition: JMessage.hh:67
Auxiliary base class for list of file names.
std::vector< filescanner_type >::iterator iterator
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
then echo WARNING
Definition: JTuneHV.sh:91
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