Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMultiParticleFlux.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/JAAnetToolkit.hh"
#include "JAAnet/JFluxFunction.hh"
#include "JAAnet/JMultiParticleFlux.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JLimit.hh"
#include "JSupport/JWeightFileScannerSet.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 JMultiParticleFlux.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 218 of file JMultiParticleFlux.cc.

219 {
220  using namespace std;
221  using namespace JPP;
222 
223  JMultipleFileScanner_t inputFiles;
224  JLimit numberOfEvents;
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['n'] = make_field(numberOfEvents) = JLimit::max();
245  zap['d'] = make_field(debug) = 1;
246 
247  zap(argc, argv);
248  }
249  catch(const exception& error) {
250  FATAL(error.what() << endl);
251  }
252 
253  // Sanity checks
254 
255  for (map<int, JPowerLawFlux>::const_iterator i = powerlawFluxes.cbegin(); i != powerlawFluxes.cend(); ++i) {
256  if (abs(i->first) != TRACK_TYPE_NUE &&
257  abs(i->first) != TRACK_TYPE_NUMU &&
258  abs(i->first) != TRACK_TYPE_NUTAU) {
259  FATAL("Particle type " << i->first << " does not correspond to a neutrino." << endl);
260  }
261  }
262 
263  // Create multi-particle flux function
264 
265  JMultiParticleFlux multiFlux;
266 
267  for (vector<int>::const_iterator i = zeroFluxes.cbegin(); i != zeroFluxes.cend(); ++i) {
268  multiFlux.insert(*i, make_fluxFunction(zeroFlux));
269  }
270 
271  for (map<int, JFlatFlux>::const_iterator i = flatFluxes.cbegin(); i != flatFluxes.cend(); ++i) {
272  multiFlux.insert(i->first, make_fluxFunction(i->second));
273  }
274 
275  for (map<int, JPowerLawFlux>::const_iterator i = powerlawFluxes.cbegin(); i != powerlawFluxes.cend(); ++i) {
276  multiFlux.insert(i->first, make_fluxFunction(i->second));
277  }
278 
279 
280  // Set event weighter
281 
282  JWeightFileScannerSet<> scanners(inputFiles, numberOfEvents);
283 
284  size_t n = scanners.setFlux(multiFlux);
285 
286  if (n == 0) {
287  WARNING("No file found containing all given primaries; Flux function not set." << endl);
288  }
289 
290 
291  // Scan events
292 
293  for (JWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
294 
295  if (scanner->simul.size() > 0) {
296  STATUS("Scanning " << scanner->simul[0].program << " files..." << endl);
297  }
298 
299  STATUS(LEFT(15) << "event" << RIGHT(15) << "weight" << endl);
300 
301  while (scanner->hasNext()) {
302 
303  const Evt* event = scanner->next();
304  const double weight = scanner->getWeight(*event);
305 
306  STATUS(LEFT (15) << scanner->getCounter() <<
307  SCIENTIFIC(15, 3) << weight << '\r'); DEBUG(endl);
308  }
309  }
310 
311  return 0;
312 }
Utility class to parse command line options.
Definition: JParser.hh:1500
Implementation of flux function for multiple particle types.
#define WARNING(A)
Definition: JMessage.hh:65
#define STATUS(A)
Definition: JMessage.hh:63
Utility class to parse parameter values.
Definition: JProperties.hh:496
void insert(const int type, const JFlux &flux)
Insert pair of particle code and flux function.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
Auxiliary class for organising Monte Carlo file scanners.
std::vector< value_type >::iterator iterator
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
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 flux function.
Auxiliary base class for list of file names.
alias put_queue eval echo n
Definition: qlib.csh:19
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
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