Jpp
JK40Rates.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <vector>
6 #include <cmath>
7 
8 #include "TRandom3.h"
9 #include "TMath.h"
10 
11 #include "JDetector/JK40Rates.hh"
12 
13 #include "Jeep/JPrint.hh"
14 #include "Jeep/JParser.hh"
15 #include "Jeep/JMessage.hh"
16 
17 
18 /**
19  * \file
20  *
21  * Example program to check background calculation.
22  * \author mdejong
23  */
24 int main(int argc, char **argv)
25 {
26  using namespace std;
27  using namespace JPP;
28 
29  JK40Rates rates_Hz;
30  double QE;
31  double livetime_s;
32  double precision;
33  UInt_t seed;
34  int debug;
35 
36  try {
37 
38  JParser<> zap("Example program to check background calculation.");
39 
40  zap['B'] = make_field(rates_Hz);
41  zap['Q'] = make_field(QE) = 1.0;
42  zap['T'] = make_field(livetime_s) = 1.0e5;
43  zap['e'] = make_field(precision) = 0.02;
44  zap['S'] = make_field(seed) = 0;
45  zap['d'] = make_field(debug) = 1;
46 
47  zap(argc, argv);
48  }
49  catch(const exception &error) {
50  FATAL(error.what() << endl);
51  }
52 
53  gRandom->SetSeed(seed);
54 
55  NOTICE("K40 rates (original) " << rates_Hz << endl);
56 
57  JK40Rates corrected_rates_Hz = rates_Hz;
58 
59  corrected_rates_Hz.correct(QE);
60 
61  NOTICE("K40 rates (corrected) " << corrected_rates_Hz << endl);
62 
63  if (livetime_s > 0.0) {
64 
65  vector<double> buffer;
66 
67  buffer.resize(corrected_rates_Hz.getUpperL1Multiplicity() + 1);
68 
69  const double W = 1.0 / livetime_s;
70 
71  for (size_t M = corrected_rates_Hz.getLowerL1Multiplicity(); M <= corrected_rates_Hz.getUpperL1Multiplicity(); ++M) {
72 
73  const int numberOfEvents = (int) (livetime_s * corrected_rates_Hz.getMultiplesRate(M));
74 
75  for (int number_of_events = 0; number_of_events != numberOfEvents; ++number_of_events) {
76 
77  int n = 0;
78 
79  for (size_t i = 0; i != M; ++i) {
80  if (gRandom->Rndm() <= QE) {
81  ++n;
82  }
83  }
84 
85  buffer[n] += W;
86  }
87  }
88 
89  NOTICE("simulated" << endl);
90 
91  for (size_t M = corrected_rates_Hz.getLowerL1Multiplicity(); M <= corrected_rates_Hz.getUpperL1Multiplicity(); ++M) {
92  NOTICE(setw(2) << M << ' ' << FIXED(8,4) << buffer[M] << endl);
93  }
94 
95  // test
96 
97  for (size_t M = rates_Hz.getLowerL1Multiplicity(); M <= rates_Hz.getUpperL1Multiplicity(); ++M) {
98  if (fabs(buffer[M] - rates_Hz.getMultiplesRate(M)) > precision * rates_Hz.getMultiplesRate(M)) {
99  FATAL("R[" << setw(2) << M << "] [Hz] " << FIXED(8,4) << buffer[M] << " != " << rates_Hz.getMultiplesRate(M) << endl);
100  }
101  }
102  }
103 }
FIXED
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
JMessage.hh
JPrint.hh
JTOOLS::n
const int n
Definition: JPolint.hh:628
std::vector< double >
JK40Rates.hh
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
debug
int debug
debug level
Definition: JSirene.cc:59
JParser.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
std
Definition: jaanetDictionary.h:36
main
int main(int argc, char **argv)
Definition: JK40Rates.cc:24
FATAL
#define FATAL(A)
Definition: JMessage.hh:67