Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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 */
23int 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 ULong_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}
int main(int argc, char **argv)
Definition JK40Rates.cc:23
General purpose messaging.
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
I/O formatting auxiliaries.
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
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