REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorAvalancheProcess.cxx
1
21
22#include "TRestDetectorAvalancheProcess.h"
23
24using namespace std;
25
26#include <TRandom3.h>
27
29
30TRestDetectorAvalancheProcess::TRestDetectorAvalancheProcess() { Initialize(); }
31
32TRestDetectorAvalancheProcess::TRestDetectorAvalancheProcess(const char* configFilename) {
33 Initialize();
34
35 if (LoadConfigFromFile(configFilename)) {
36 LoadDefaultConfig();
37 }
38
40 fGas = new TRestDetectorGas(configFilename);
41}
42
43TRestDetectorAvalancheProcess::~TRestDetectorAvalancheProcess() {
44 delete fGas;
45 delete fHitsOutputEvent;
46}
47
48void 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
70void TRestDetectorAvalancheProcess::LoadConfig(string configFilename) {
71 if (LoadConfigFromFile(configFilename)) LoadDefaultConfig();
72
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.
Double_t fEnergyRef
reference energy for the FWHM
Double_t fResolutionAtEref
FWHM at Energy of reference.
void Initialize() override
Making default settings.
void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
void PrintMetadata() override
Prints the metadata information from the gas.
Double_t GetX(int n) const
Returns the X-coordinate of hit entry n in mm.
Double_t GetY(int n) const
Returns the Y-coordinate of hit entry n in mm.
Double_t GetZ(int n) const
Returns the Z-coordinate of hit entry n in mm.
void AddHit(Double_t x, Double_t y, Double_t z, Double_t en, Double_t t=0, REST_HitType type=XYZ)
Adds a new hit to this event.
A base class for any REST event.
Definition: TRestEvent.h:38
Int_t LoadConfigFromFile(const std::string &configFilename, const std::string &sectionName="")
Give the file name, find out the corresponding section. Then call the main starter.
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
void SetSectionName(std::string sName)
set the section name, clear the section content
std::string GetParameter(std::string parName, TiXmlElement *e, TString defaultValue=PARAMETER_NOT_FOUND_STR)
Returns the value for the parameter named parName in the given section.
Double_t StringToDouble(std::string in)
Gets a double from a string.