Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
10 #include "JPhysics/JK40Rates.hh"
11 
12 #include "Jeep/JPrint.hh"
13 #include "Jeep/JParser.hh"
14 #include "Jeep/JMessage.hh"
15 
16 
17 /**
18  * \file
19  *
20  * Example program to check background calculation.
21  * \author mdejong
22  */
23 int main(int argc, char **argv)
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 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
do $JPP JMEstimator M
Definition: JMEstimator.sh:37
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
then JDataQuality D $DETECTOR R $RUNS[*] o $QUALITY_TXT d $DEBUG!fi JDataQuality f $QUALITY_TXT Q livetime_s
Definition: JDataQuality.sh:48
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define NOTICE(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
alias put_queue eval echo n
Definition: qlib.csh:19