Jpp  debug
the software that should make you happy
Functions
JK40Rates.cc File Reference

Example program to check background calculation. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include "TRandom3.h"
#include "JPhysics/JK40Rates.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to check background calculation.

Author
mdejong

Definition in file JK40Rates.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file JK40Rates.cc.

24 {
25  using namespace std;
26  using namespace JPP;
27 
28  JK40Rates rates_Hz;
29  double QE;
30  double livetime_s;
31  double precision;
32  UInt_t seed;
33  int debug;
34 
35  try {
36 
37  JParser<> zap("Example program to check background calculation.");
38 
39  zap['B'] = make_field(rates_Hz);
40  zap['Q'] = make_field(QE) = 1.0;
41  zap['T'] = make_field(livetime_s) = 1.0e5;
42  zap['e'] = make_field(precision) = 0.02;
43  zap['S'] = make_field(seed) = 0;
44  zap['d'] = make_field(debug) = 1;
45 
46  zap(argc, argv);
47  }
48  catch(const exception &error) {
49  FATAL(error.what() << endl);
50  }
51 
52  gRandom->SetSeed(seed);
53 
54  NOTICE("K40 rates (original) " << rates_Hz << endl);
55 
56  JK40Rates corrected_rates_Hz = rates_Hz;
57 
58  corrected_rates_Hz.correct(QE);
59 
60  NOTICE("K40 rates (corrected) " << corrected_rates_Hz << endl);
61 
62  if (livetime_s > 0.0) {
63 
64  vector<double> buffer;
65 
66  buffer.resize(corrected_rates_Hz.getUpperL1Multiplicity() + 1);
67 
68  const double W = 1.0 / livetime_s;
69 
70  for (size_t M = corrected_rates_Hz.getLowerL1Multiplicity(); M <= corrected_rates_Hz.getUpperL1Multiplicity(); ++M) {
71 
72  const int numberOfEvents = (int) (livetime_s * corrected_rates_Hz.getMultiplesRate(M));
73 
74  for (int number_of_events = 0; number_of_events != numberOfEvents; ++number_of_events) {
75 
76  int n = 0;
77 
78  for (size_t i = 0; i != M; ++i) {
79  if (gRandom->Rndm() <= QE) {
80  ++n;
81  }
82  }
83 
84  buffer[n] += W;
85  }
86  }
87 
88  NOTICE("simulated" << endl);
89 
90  for (size_t M = corrected_rates_Hz.getLowerL1Multiplicity(); M <= corrected_rates_Hz.getUpperL1Multiplicity(); ++M) {
91  NOTICE(setw(2) << M << ' ' << FIXED(8,4) << buffer[M] << endl);
92  }
93 
94  // test
95 
96  for (size_t M = rates_Hz.getLowerL1Multiplicity(); M <= rates_Hz.getUpperL1Multiplicity(); ++M) {
97  if (fabs(buffer[M] - rates_Hz.getMultiplesRate(M)) > precision * rates_Hz.getMultiplesRate(M)) {
98  FATAL("R[" << setw(2) << M << "] [Hz] " << FIXED(8,4) << buffer[M] << " != " << rates_Hz.getMultiplesRate(M) << endl);
99  }
100  }
101  }
102 }
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
Utility class to parse command line options.
Definition: JParser.hh:1714
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
const int n
Definition: JPolint.hh:786
Definition: JSTDTypes.hh:14
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Auxiliary class for K40 rates.
Definition: JK40Rates.hh:41
double getMultiplesRate(const multiplicity_type M) const
Get multiples rate at given multiplicity.
Definition: JK40Rates.hh:94
multiplicity_type getLowerL1Multiplicity() const
Get lower multiplicty.
Definition: JK40Rates.hh:108
multiplicity_type getUpperL1Multiplicity() const
Get upper multiplicty.
Definition: JK40Rates.hh:119
void correct(const double QE)
Correct rates for global efficiency,.
Definition: JK40Rates.hh:130