REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestGeant4BlobAnalysisProcess.cxx
1
16
17#include "TRestGeant4BlobAnalysisProcess.h"
18
20
21using namespace std;
22
23TRestGeant4BlobAnalysisProcess::TRestGeant4BlobAnalysisProcess() { Initialize(); }
24
25TRestGeant4BlobAnalysisProcess::TRestGeant4BlobAnalysisProcess(const char* configFilename) {
26 Initialize();
27
28 if (LoadConfigFromFile(configFilename)) LoadDefaultConfig();
29}
30
31TRestGeant4BlobAnalysisProcess::~TRestGeant4BlobAnalysisProcess() { delete fG4Event; }
32
33void TRestGeant4BlobAnalysisProcess::LoadDefaultConfig() { SetTitle("Default config"); }
34
36 SetSectionName(this->ClassName());
37 SetLibraryVersion(LIBRARY_VERSION);
38
39 fG4Event = new TRestGeant4Event();
41}
42
43void TRestGeant4BlobAnalysisProcess::LoadConfig(const string& configFilename, const string& name) {
44 if (LoadConfigFromFile(configFilename, name)) LoadDefaultConfig();
45}
46
48 std::vector<string> fObservables;
49 fObservables = TRestEventProcess::ReadObservables();
50
51 for (unsigned int i = 0; i < fObservables.size(); i++) {
52 if (fObservables[i].find("Q1_R") != string::npos) fQ1_Observables.push_back(fObservables[i]);
53 if (fObservables[i].find("Q2_R") != string::npos) fQ2_Observables.push_back(fObservables[i]);
54 }
55
56 for (unsigned int i = 0; i < fQ1_Observables.size(); i++) {
57 Double_t r1 = atof(fQ1_Observables[i].substr(4, fQ1_Observables[i].length() - 4).c_str());
58 fQ1_Radius.push_back(r1);
59 }
60
61 for (unsigned int i = 0; i < fQ2_Observables.size(); i++) {
62 Double_t r2 = atof(fQ2_Observables[i].substr(4, fQ2_Observables[i].length() - 4).c_str());
63 fQ2_Radius.push_back(r2);
64 }
65
66 fG4Metadata = GetMetadata<TRestGeant4Metadata>();
67}
68
70 *fG4Event = *((TRestGeant4Event*)inputEvent);
71
72 TString obsName;
73
74 Int_t nBlobs = 0;
75
76 Double_t xBlob1 = 0, yBlob1 = 0, zBlob1 = 0;
77 Double_t xBlob2 = 0, yBlob2 = 0, zBlob2 = 0;
78
79 for (unsigned int tck = 0; tck < fG4Event->GetNumberOfTracks(); tck++) {
80 const auto& track = fG4Event->GetTrack(tck);
81 if (track.GetParentID() == 0) {
82 if (track.GetParticleName() != "e-") {
83 cout << "TRestGeant4BlobAnalysis Warning. Primary particle is not an "
84 "electron!!"
85 << endl;
86 cout << "Skipping." << endl;
87 continue;
88 }
89
90 if (track.GetNumberOfHits() == 0) {
91 cout << "REST. FindG4Blobs WARNING. A primary electron with no hits "
92 "was found!!"
93 << endl;
94 cout << "Skipping." << endl;
95 continue;
96 }
97
98 if (nBlobs >= 2) {
99 cout << "TRestGeant4BlobAnalysis Warning. More than 2 e- primaries "
100 "found!"
101 << endl;
102 continue;
103 }
104
105 Int_t nHits = track.GetNumberOfHits();
106
107 if (nBlobs == 0) {
108 xBlob1 = track.GetHits().GetX(nHits - 1);
109 yBlob1 = track.GetHits().GetY(nHits - 1);
110 zBlob1 = track.GetHits().GetZ(nHits - 1);
111 } else {
112 xBlob2 = track.GetHits().GetX(nHits - 1);
113 yBlob2 = track.GetHits().GetY(nHits - 1);
114 zBlob2 = track.GetHits().GetZ(nHits - 1);
115 }
116
117 nBlobs++;
118 }
119 }
120
121 if (nBlobs != 2) {
122 cout << "REST. FindG4Blobs ERROR. Blobs != 2. Blobs found " << nBlobs << endl;
123 }
124
125 // The blob with z-coordinate closer to z=0 is stored in x1,y1,z1
126 Double_t x1, y1, z1;
127 Double_t x2, y2, z2;
128
129 if (fabs(zBlob1) < fabs(zBlob2)) {
130 x1 = xBlob1;
131 y1 = yBlob1;
132 z1 = zBlob1;
133
134 x2 = xBlob2;
135 y2 = yBlob2;
136 z2 = zBlob2;
137 } else {
138 x1 = xBlob2;
139 y1 = yBlob2;
140 z1 = zBlob2;
141
142 x2 = xBlob1;
143 y2 = yBlob1;
144 z2 = zBlob1;
145 }
146
147 SetObservableValue("x1", x1);
148
149 SetObservableValue("y1", y1);
150
151 SetObservableValue("z1", z1);
152
153 SetObservableValue("x2", x2);
154
155 SetObservableValue("y2", y2);
156
157 SetObservableValue("z2", z2);
158
159 Double_t deltaX = xBlob1 - xBlob2;
160 Double_t deltaY = yBlob1 - yBlob2;
161 Double_t deltaZ = zBlob1 - zBlob2;
162
163 Double_t blobDistance = deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
164 blobDistance = TMath::Sqrt(blobDistance);
165
166 SetObservableValue("distance", blobDistance);
167
169 TRestHits hits = fG4Event->GetHits();
170
171 for (unsigned int n = 0; n < fQ1_Observables.size(); n++) {
172 Double_t q = hits.GetEnergyInSphere(x1, y1, z1, fQ1_Radius[n]);
173
174 SetObservableValue(fQ1_Observables[n], q);
175 }
176
177 for (unsigned int n = 0; n < fQ2_Observables.size(); n++) {
178 Double_t q = hits.GetEnergyInSphere(x2, y2, z2, fQ2_Radius[n]);
179
180 SetObservableValue(fQ2_Observables[n], q);
181 }
182
183 return fG4Event;
184}
185
187 // Function to be executed once at the end of the process
188 // (after all events have been processed)
189
190 // Start by calling the EndProcess function of the abstract class.
191 // Comment this if you don't want it.
192 // TRestEventProcess::EndProcess();
193}
194
void SetObservableValue(const std::string &name, const T &value)
Set observable value for AnalysisTree.
A base class for any REST event.
Definition: TRestEvent.h:38
void Initialize() override
Making default settings.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void EndProcess() override
To be executed at the end of the run (outside event loop)
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
An event class to store geant4 generated event information.
TRestHits GetHits(Int_t volID=-1) const
Function that returns all the hit depositions in the Geant4 event. If a specific volume is given as a...
size_t GetNumberOfHits(Int_t volID=-1) const
Function that returns the number of hit depositions found inside the TRestGeant4Track....
It saves a 3-coordinate position and an energy for each punctual deposition.
Definition: TRestHits.h:39
Double_t GetEnergyInSphere(const TVector3 &pos0, Double_t radius) const
It determines the total energy contained in a sphere with position pos0 for a given spherical radius.
Definition: TRestHits.cxx:296
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