REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorAvalancheProcess.cxx
1 
22 #include "TRestDetectorAvalancheProcess.h"
23 
24 using namespace std;
25 
26 #include <TRandom3.h>
27 
29 
30 TRestDetectorAvalancheProcess::TRestDetectorAvalancheProcess() { Initialize(); }
31 
32 TRestDetectorAvalancheProcess::TRestDetectorAvalancheProcess(const char* configFilename) {
33  Initialize();
34 
35  if (LoadConfigFromFile(configFilename)) {
36  LoadDefaultConfig();
37  }
38 
39  PrintMetadata();
40  fGas = new TRestDetectorGas(configFilename);
41 }
42 
43 TRestDetectorAvalancheProcess::~TRestDetectorAvalancheProcess() {
44  delete fGas;
45  delete fHitsOutputEvent;
46 }
47 
48 void TRestDetectorAvalancheProcess::LoadDefaultConfig() {
49  SetTitle("Default config");
50 
51  fEnergyRef = 5.9;
52  fResolutionAtEref = 15.0;
53  fDetectorGain = 8000.0;
54 }
55 
57  SetSectionName(this->ClassName());
58  SetLibraryVersion(LIBRARY_VERSION);
59 
60  fGas = nullptr;
61 
62  fEnergyRef = 5.9;
63  fResolutionAtEref = 15.0;
64  fDetectorGain = 8000.0;
65 
66  fHitsInputEvent = nullptr;
67  fHitsOutputEvent = new TRestDetectorHitsEvent();
68 }
69 
70 void TRestDetectorAvalancheProcess::LoadConfig(string configFilename) {
71  if (LoadConfigFromFile(configFilename)) LoadDefaultConfig();
72 
73  PrintMetadata();
74  fGas = new TRestDetectorGas(configFilename.c_str());
75  fGas->PrintMetadata();
76 }
77 
79  // Function to be executed once at the beginning of process
80  // (before starting the process of the events)
81 
82  // Start by calling the InitProcess function of the abstract class.
83  // Comment this if you don't want it.
84  // TRestEventProcess::InitProcess();
85 
86  if (fGas == nullptr) cout << "REST ERROR: Gas has not been initialized" << endl;
87 }
88 
90  fHitsInputEvent = (TRestDetectorHitsEvent*)inputEvent;
91 
92  Double_t fW = fGas->GetWvalue();
93  Double_t gain, totelectrons = 0;
94 
95  Double_t eDep = fHitsInputEvent->GetTotalEnergy() * fW / 1000.0;
96  Double_t eRes = fResolutionAtEref * TMath::Sqrt(fEnergyRef / eDep) / 2.35 / 100.0;
97 
98  cout << "Initial electrons " << fHitsInputEvent->GetTotalEnergy() << " ; eDep " << eDep
99  << " keV; resolution " << eRes * 2.35 * 100 << " fwhm" << endl;
100 
101  TRandom3* rnd = new TRandom3(0);
102 
103  for (unsigned int hit = 0; hit < fHitsInputEvent->GetNumberOfHits(); hit++) {
104  gain = fDetectorGain * rnd->Gaus(1.0, eRes);
105 
106  // The electronics gain is applied.
107  // gain = gain * 4096.0 / fElectronicsGain;
108 
109  totelectrons += gain;
110 
111  fHitsOutputEvent->AddHit(fHitsInputEvent->GetX(hit), fHitsInputEvent->GetY(hit),
112  fHitsInputEvent->GetZ(hit), fHitsInputEvent->GetEnergy(hit) * gain);
113  }
114 
115  delete rnd;
116 
117  if (fHitsOutputEvent->GetNumberOfHits() == 0) return nullptr;
118 
119  cout << "Initial: " << fHitsInputEvent->GetNumberOfHits() << "e-s, and amplified: " << totelectrons
120  << " e-s : " << endl;
121  return fHitsOutputEvent;
122 }
123 
125  // Function to be executed once at the end of the process
126  // (after all events have been processed)
127 
128  // Start by calling the EndProcess function of the abstract class.
129  // Comment this if you don't want it.
130  // TRestEventProcess::EndProcess();
131 }
132 
134  fEnergyRef = GetDblParameterWithUnits("energyReference");
135  fResolutionAtEref = StringToDouble(GetParameter("resolutionReference"));
136  fDetectorGain = StringToDouble(GetParameter("detectorGain"));
137 }
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
void EndProcess() override
To be executed at the end of the run (outside event loop)
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void Initialize() override
Making default settings.
A base class for any REST event.
Definition: TRestEvent.h:38
Double_t StringToDouble(std::string in)
Gets a double from a string.