REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestTrack3DAnalysisProcess.cxx
1/*************************************************************************
2 * This file is part of the REST software framework. *
3 * *
4 * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5 * For more information see http://gifna.unizar.es/trex *
6 * *
7 * REST is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * REST is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have a copy of the GNU General Public License along with *
18 * REST in $REST_PATH/LICENSE. *
19 * If not, see http://www.gnu.org/licenses/. *
20 * For the list of contributors see $REST_PATH/CREDITS. *
21 *************************************************************************/
22
74
75#include "TRestTrack3DAnalysisProcess.h"
76using namespace std;
77
78// Comparator function for sorting in descending order
79bool sortByValueDescending3D(const std::pair<int, Double_t>& a, const std::pair<int, Double_t>& b) {
80 return a.second > b.second; // Change to < for ascending order
81}
82
84
85TRestTrack3DAnalysisProcess::TRestTrack3DAnalysisProcess() { Initialize(); }
86
87TRestTrack3DAnalysisProcess::TRestTrack3DAnalysisProcess(const char* configFilename) {
88 Initialize();
89 if (LoadConfigFromFile(configFilename)) LoadDefaultConfig();
90}
91
92TRestTrack3DAnalysisProcess::~TRestTrack3DAnalysisProcess() { delete fTrackEvent; }
93
94void TRestTrack3DAnalysisProcess::LoadDefaultConfig() { SetTitle("Default config"); }
95
97 SetSectionName(this->ClassName());
98 SetLibraryVersion(LIBRARY_VERSION);
99
100 fTrackEvent = new TRestTrackEvent();
101}
102
103void TRestTrack3DAnalysisProcess::LoadConfig(const string& configFilename, const string& name) {
104 if (LoadConfigFromFile(configFilename, name)) LoadDefaultConfig();
105}
106
108
110 fTrackEvent = (TRestTrackEvent*)inputEvent;
111
115
118 map<int, Double_t> XYZ_Energy;
119
121 map<int, int> XYZ_NHits;
122
124 map<int, Double_t> XYZ_SigmaX;
125 map<int, Double_t> XYZ_SigmaY;
126 map<int, Double_t> XYZ_SigmaZ;
127
129 map<int, Double_t> XYZ_SkewXY;
130 map<int, Double_t> XYZ_SkewZ;
131
133 map<int, Double_t> XYZ_GaussSigmaX;
134 map<int, Double_t> XYZ_GaussSigmaY;
135 map<int, Double_t> XYZ_GaussSigmaZ;
136
138 map<int, Double_t> XYZ_Length;
139
140 map<int, Double_t> XYZ_Volume;
141
142 map<int, Double_t> XYZ_MeanX;
143 map<int, Double_t> XYZ_MeanY;
144 map<int, Double_t> XYZ_MeanZ;
145
147 Double_t XYZ_FirstSecondTracksDistance;
148
152
154 for (int tck = 0; tck < fTrackEvent->GetNumberOfTracks(); tck++) {
155 if (!fTrackEvent->isTopLevel(tck)) continue;
156
157 TRestTrack* t = fTrackEvent->GetTrack(tck);
158
159 if (t->isXYZ()) {
160 XYZ_NHits[t->GetTrackID()] = t->GetNumberOfHits();
161 XYZ_Energy[t->GetTrackID()] = t->GetTrackEnergy();
162 XYZ_SigmaX[t->GetTrackID()] = t->GetHits()->GetSigmaX();
163 XYZ_SigmaY[t->GetTrackID()] = t->GetHits()->GetSigmaY();
164 XYZ_SigmaZ[t->GetTrackID()] = t->GetHits()->GetSigmaZ2();
165 XYZ_GaussSigmaX[t->GetTrackID()] = t->GetHits()->GetGaussSigmaX();
166 XYZ_GaussSigmaY[t->GetTrackID()] = t->GetHits()->GetGaussSigmaY();
167 XYZ_GaussSigmaZ[t->GetTrackID()] = t->GetHits()->GetGaussSigmaZ();
168 XYZ_Length[t->GetTrackID()] = t->GetLength();
169 XYZ_Volume[t->GetTrackID()] = t->GetVolume();
170 XYZ_MeanX[t->GetTrackID()] = t->GetMeanPosition().X();
171 XYZ_MeanY[t->GetTrackID()] = t->GetMeanPosition().Y();
172 XYZ_MeanZ[t->GetTrackID()] = t->GetMeanPosition().Z();
173 XYZ_SkewXY[t->GetTrackID()] = t->GetHits()->GetSkewXY();
174 XYZ_SkewZ[t->GetTrackID()] = t->GetHits()->GetSkewZ();
175 } else {
176 XYZ_NHits[t->GetTrackID()] = 0;
177 XYZ_Energy[t->GetTrackID()] = 0;
178 XYZ_SigmaX[t->GetTrackID()] = 0;
179 XYZ_SigmaY[t->GetTrackID()] = 0;
180 XYZ_SigmaZ[t->GetTrackID()] = 0;
181 XYZ_GaussSigmaX[t->GetTrackID()] = 0;
182 XYZ_GaussSigmaY[t->GetTrackID()] = 0;
183 XYZ_GaussSigmaZ[t->GetTrackID()] = 0;
184 XYZ_Length[t->GetTrackID()] = 0;
185 XYZ_Volume[t->GetTrackID()] = 0;
186 XYZ_MeanX[t->GetTrackID()] = 0;
187 XYZ_MeanY[t->GetTrackID()] = 0;
188 XYZ_MeanZ[t->GetTrackID()] = 0;
189 XYZ_SkewXY[t->GetTrackID()] = 0;
190 XYZ_SkewZ[t->GetTrackID()] = 0;
191 }
192 }
193
195 vector<pair<int, Double_t>> energies;
196
198 map<int, Double_t>::iterator it;
199 for (it = XYZ_Energy.begin(); it != XYZ_Energy.end(); it++) {
200 energies.emplace_back(make_pair(it->first, it->second));
201 }
202
204 sort(energies.begin(), energies.end(), sortByValueDescending3D);
205
207 if (fTrackEvent->GetNumberOfTracks() > 1) {
208 Double_t dX = 0, dY = 0, dZ = 0;
209
210 dX = abs(XYZ_MeanX[energies[0].first] - XYZ_MeanX[energies[1].first]);
211 dY = abs(XYZ_MeanY[energies[0].first] - XYZ_MeanY[energies[1].first]);
212 dZ = abs(XYZ_MeanZ[energies[0].first] - XYZ_MeanZ[energies[1].first]);
213
214 XYZ_FirstSecondTracksDistance = TMath::Sqrt(dX * dX + dY * dY + dZ * dZ);
215 } else {
216 XYZ_FirstSecondTracksDistance = 0;
217 }
218
222
223 // --- Number of tracks and energy --- //
224 SetObservableValue("NTracks", fTrackEvent->GetNumberOfTracks());
225 SetObservableValue("TotalEnergy", fTrackEvent->GetEnergy());
226
227 // --- Map observables --- //
228 SetObservableValue("Map_XYZ_NHits", XYZ_NHits);
229 SetObservableValue("Map_XYZ_Energy", XYZ_Energy);
230 SetObservableValue("Map_XYZ_SigmaX", XYZ_SigmaX);
231 SetObservableValue("Map_XYZ_SigmaY", XYZ_SigmaY);
232 SetObservableValue("Map_XYZ_SigmaZ", XYZ_SigmaZ);
233 SetObservableValue("Map_XYZ_GaussSigmaX", XYZ_GaussSigmaX);
234 SetObservableValue("Map_XYZ_GaussSigmaY", XYZ_GaussSigmaY);
235 SetObservableValue("Map_XYZ_GaussSigmaZ", XYZ_GaussSigmaZ);
236 SetObservableValue("Map_XYZ_Length", XYZ_Length);
237 SetObservableValue("Map_XYZ_Volume", XYZ_Volume);
238 SetObservableValue("Map_XYZ_MeanX", XYZ_MeanX);
239 SetObservableValue("Map_XYZ_MeanY", XYZ_MeanY);
240 SetObservableValue("Map_XYZ_MeanZ", XYZ_MeanZ);
241 SetObservableValue("Map_XYZ_SkewXY", XYZ_SkewXY);
242 SetObservableValue("Map_XYZ_SkewZ", XYZ_SkewZ);
243
244 // Copy the MaxTrack keys immediately after checking the vector
245 if (!energies.empty()) {
246 // --- Max track observables --- //
247 int energies0FirstKey =
248 energies[0].first; // Declare Keys outside to avoid error when accessing "energies[0].first"...
249 Double_t energies0SecondKey = energies[0].second;
250
251 SetObservableValue("MaxTrack_XYZ_NHits", XYZ_NHits[energies0FirstKey]);
252 SetObservableValue("MaxTrack_XYZ_Energy", XYZ_Energy[energies0FirstKey]);
253 SetObservableValue("MaxTrack_XYZ_SigmaX", XYZ_SigmaX[energies0FirstKey]);
254 SetObservableValue("MaxTrack_XYZ_SigmaY", XYZ_SigmaY[energies0FirstKey]);
255 SetObservableValue("MaxTrack_XYZ_SigmaZ", XYZ_SigmaZ[energies0FirstKey]);
256 SetObservableValue("MaxTrack_XYZ_GaussSigmaX", XYZ_GaussSigmaX[energies0FirstKey]);
257 SetObservableValue("MaxTrack_XYZ_GaussSigmaY", XYZ_GaussSigmaY[energies0FirstKey]);
258 SetObservableValue("MaxTrack_XYZ_GaussSigmaZ", XYZ_GaussSigmaZ[energies0FirstKey]);
259 SetObservableValue("MaxTrack_XYZ_Length", XYZ_Length[energies0FirstKey]);
260 SetObservableValue("MaxTrack_XYZ_Volume", XYZ_Volume[energies0FirstKey]);
261 SetObservableValue("MaxTrack_XYZ_MeanX", XYZ_MeanX[energies0FirstKey]);
262 SetObservableValue("MaxTrack_XYZ_MeanY", XYZ_MeanY[energies0FirstKey]);
263 SetObservableValue("MaxTrack_XYZ_MeanZ", XYZ_MeanZ[energies0FirstKey]);
264 SetObservableValue("MaxTrack_XYZ_SkewZ", XYZ_SkewXY[energies0FirstKey]);
265 SetObservableValue("MaxTrack_XYZ_SkewZ", XYZ_SkewZ[energies0FirstKey]);
266
267 SetObservableValue("MaxTrack_XYZ_MaxTrackEnergyPercentage",
268 (energies0SecondKey) / fTrackEvent->GetEnergy());
269
270 // --- Second max track observables --- //
271 int energies1FirstKey = energies[1].first;
272
273 SetObservableValue("SecondMaxTrack_XYZ_NHits", XYZ_NHits[energies1FirstKey]);
274 SetObservableValue("SecondMaxTrack_XYZ_Energy", XYZ_Energy[energies1FirstKey]);
275 SetObservableValue("SecondMaxTrack_XYZ_SigmaX", XYZ_SigmaX[energies1FirstKey]);
276 SetObservableValue("SecondMaxTrack_XYZ_SigmaY", XYZ_SigmaY[energies1FirstKey]);
277 SetObservableValue("SecondMaxTrack_XYZ_SigmaZ", XYZ_SigmaZ[energies1FirstKey]);
278 SetObservableValue("SecondMaxTrack_XYZ_GaussSigmaX", XYZ_GaussSigmaX[energies1FirstKey]);
279 SetObservableValue("SecondMaxTrack_XYZ_GaussSigmaY", XYZ_GaussSigmaY[energies1FirstKey]);
280 SetObservableValue("SecondMaxTrack_XYZ_GaussSigmaZ", XYZ_GaussSigmaZ[energies1FirstKey]);
281 SetObservableValue("SecondMaxTrack_XYZ_Length", XYZ_Length[energies1FirstKey]);
282 SetObservableValue("SecondMaxTrack_XYZ_Volume", XYZ_Volume[energies1FirstKey]);
283 SetObservableValue("SecondMaxTrack_XYZ_MeanX", XYZ_MeanX[energies1FirstKey]);
284 SetObservableValue("SecondMaxTrack_XYZ_MeanY", XYZ_MeanY[energies1FirstKey]);
285 SetObservableValue("SecondMaxTrack_XYZ_MeanZ", XYZ_MeanZ[energies1FirstKey]);
286 SetObservableValue("SecondMaxTrack_XYZ_SkewZ", XYZ_SkewXY[energies1FirstKey]);
287 SetObservableValue("SecondMaxTrack_XYZ_SkewZ", XYZ_SkewZ[energies1FirstKey]);
288
289 Double_t energies1SecondKey = energies[1].second;
290
291 if (fTrackEvent->GetNumberOfTracks() > 2) {
292 SetObservableValue("SecondMaxTrack_XYZ_MaxTrackEnergyPercentage",
293 (energies1SecondKey) / fTrackEvent->GetEnergy());
294 } else {
295 SetObservableValue("SecondMaxTrack_XYZ_MaxTrackEnergyPercentage", 0.0);
296 }
297 } else {
298 std::cerr << "Error: energies is empty. Some observables will not be set." << std::endl;
299 }
300
301 // --- Distance observables between first two tracks --- //
302 SetObservableValue("XYZ_FirstSecondTracksDistance", XYZ_FirstSecondTracksDistance);
303
304 return fTrackEvent;
305}
306
308
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
Double_t GetSkewXY() const
It returns the 2-dimensional skewness on the XY-plane which is a measure of the hits distribution asy...
Definition: TRestHits.cxx:979
Double_t GetGaussSigmaX(Double_t error=150.0, Int_t nHitsMin=100000)
It computes the gaussian sigma in the X-coordinate. It adds a hit to the right and a hit to the left,...
Definition: TRestHits.cxx:762
Double_t GetSigmaX() const
It calculates the hits standard deviation in the X-coordinate.
Definition: TRestHits.cxx:685
Double_t GetGaussSigmaZ(Double_t error=150.0, Int_t nHitsMin=100000)
It computes the gaussian sigma in the Z-coordinate. It adds a hit to the right and a hit to the left,...
Definition: TRestHits.cxx:907
Double_t GetGaussSigmaY(Double_t error=150.0, Int_t nHitsMin=100000)
It computes the gaussian sigma in the Y-coordinate. It adds a hit to the right and a hit to the left,...
Definition: TRestHits.cxx:836
Double_t GetSigmaZ2() const
It returns the hits distribution variance on the Z-axis.
Definition: TRestHits.cxx:997
Double_t GetSkewZ() const
It returns the hits distribution skewness, or asymmetry on the Z-axis.
Definition: TRestHits.cxx:1013
Double_t GetSigmaY() const
It calculates the hits standard deviation in the Y-coordinate.
Definition: TRestHits.cxx:703
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
An analysis REST process to extract valuable information from Track type of data.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
void Initialize() override
Making default settings.
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.