RPCChargeGenerator.cc
Go to the documentation of this file.
1 #include "RPCChargeGenerator.h"
2 #include <cmath>
3 #include <cfloat>
4 #include <utl/AugerUnits.h>
5 #include <utl/Math.h>
6 #include <utl/ErrorLogger.h>
7 #include <fwk/RandomEngineRegistry.h>
8 #include <CLHEP/Random/Randomize.h>
9 #include <boost/math/special_functions/gamma.hpp>
10 
11 using namespace std;
12 using namespace fwk;
13 using namespace utl;
14 using namespace RPCSimulatorLX;
15 using CLHEP::RandGeneral;
16 
17 RPCChargeGenerator::RPCChargeGenerator(double k0, double theta0, double referenceAngle) :
18  fK0(k0),
19  fTheta0(theta0),
20  fReferenceAngle(referenceAngle),
21  fMinSecTheta(1.0),
22  fMaxSecTheta(11.0),
23  fNumberOfChargeBins(100),
24  fNumberOfChargePDF(100),
25  fListChargePDF(0),
26  fListMinCharge(0),
27  fListMaxCharge(0),
28  fIsInitialized(false),
29  fRandomEngine(0)
30 {
31  Initialize();
32 }
33 
34 
36 {;}
37 
38 
39 double
41 {
42 
43  double charge = 0.0;
44 
45  if (fIsInitialized) {
46 
47  double secTheta = 1.0/abs(cos(angle));
48 
49  if (secTheta > fMaxSecTheta)
50  secTheta = fMaxSecTheta;
51  else if (secTheta < fMinSecTheta)
52  secTheta = fMinSecTheta;
53 
54  unsigned int iChargePDF =
55  int(rint((secTheta-fMinSecTheta)*double(fNumberOfChargePDF-1)/(fMaxSecTheta-fMinSecTheta)));
56 
57  double minCharge = fListMinCharge[iChargePDF];
58  double maxCharge = fListMaxCharge[iChargePDF];
59 
60  charge =
61  minCharge + (maxCharge - minCharge)*(fListChargePDF[iChargePDF])->fire();
62 
63  charge *= utl::pico*coulomb;
64  }
65  else
66  ERROR("Error in RPCChargeGenerator::GetCharge: Parameters not initialized !!!");
67 
68  return charge;
69 }
70 
71 
73 {
74  if (fIsInitialized) {
75  ERROR("RPCChargeGenerator already initialized !");
76  }
77  else {
78  double secTheta0 = 1.0/abs(cos(fReferenceAngle));
79 
80  for (unsigned int i = 0 ; i < fNumberOfChargePDF; i++) {
81 
82  double secTheta = fMinSecTheta +
83  double(i)*(fMaxSecTheta-fMinSecTheta)/double(fNumberOfChargePDF-1);
84 
85  // cout << "sec theta: " << secTheta << " theta: " << acos(1.0/secTheta)/deg << endl;
86  double k = fK0 * secTheta/secTheta0;
87  double theta = fTheta0;
88 
89  fRandomEngine =
90  &RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector);
91 
92  // The maximum charge for the pdf is defined to contain 99.9% of the integral
93  double maxCharge = InverseCumulativeGammaDistribution(0.999,k,theta);;
94  double minCharge = 0.0;
95 
96  // cout << "max charge/integral " << maxCharge << "/"
97  // << CumulativeGammaDistribution(maxCharge,k,theta)
98  // << endl;
99 
100  vector<double> chargeProbability;
101 
102  for (unsigned int jCharge = 0 ; jCharge < fNumberOfChargeBins; jCharge++) {
103  double charge =
104  minCharge + jCharge*(maxCharge-minCharge)/double(fNumberOfChargeBins);
105 
106  chargeProbability.push_back(GammaDistribution(charge,k,theta));
107 
108  // cout << charge << " " << chargeProbability[jCharge] << endl;
109  }
110 
111 
112  const unsigned int chargeProbN = chargeProbability.size();
113 
114  RandGeneral * chargeDist =
115  new RandGeneral(&fRandomEngine->GetEngine(), &chargeProbability[0], chargeProbN);
116 
117  fListMinCharge.push_back(minCharge);
118  fListMaxCharge.push_back(maxCharge);
119  fListChargePDF.push_back(chargeDist);
120  }
121 
122  fIsInitialized = true;
123  }
124 
125 
126 }
double GammaDistribution(double x, double k, double theta)
RandomEngineType & GetEngine()
Definition: RandomEngine.h:32
constexpr double pico
Definition: AugerUnits.h:63
double abs(const SVector< n, T > &v)
double InverseCumulativeGammaDistribution(double y, double k, double theta)
std::vector< CLHEP::RandGeneral * > fListChargePDF
constexpr double coulomb
Definition: AugerUnits.h:169
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.