Jpp  15.0.4
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 one primary. 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/JFlux.hh"
#include "JAAnet/JAAnetToolkit.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 one primary.

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 217 of file JFluxMultiParticle.cc.

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