REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestTrackBlobAnalysisProcess.cxx
1
15
16#include "TRestTrackBlobAnalysisProcess.h"
17
18using namespace std;
19
21
22TRestTrackBlobAnalysisProcess::TRestTrackBlobAnalysisProcess() { Initialize(); }
23
24TRestTrackBlobAnalysisProcess::TRestTrackBlobAnalysisProcess(const char* configFilename) {
25 Initialize();
26
27 if (LoadConfigFromFile(configFilename)) LoadDefaultConfig();
28}
29
30TRestTrackBlobAnalysisProcess::~TRestTrackBlobAnalysisProcess() { delete fOutputTrackEvent; }
31
32void TRestTrackBlobAnalysisProcess::LoadDefaultConfig() { SetTitle("Default config"); }
33
35 SetSectionName(this->ClassName());
36 SetLibraryVersion(LIBRARY_VERSION);
37
38 fInputTrackEvent = nullptr;
39 fOutputTrackEvent = new TRestTrackEvent();
40
41 fHitsToCheckFraction = 0.2;
42}
43
44void TRestTrackBlobAnalysisProcess::LoadConfig(const string& configFilename, const string& name) {
45 if (LoadConfigFromFile(configFilename, name)) LoadDefaultConfig();
46}
47
49 std::vector<string> fObservables;
50 fObservables = TRestEventProcess::ReadObservables();
51
52 for (unsigned int i = 0; i < fObservables.size(); i++) {
53 if (fObservables[i].find("Q1_R") != string::npos) fQ1_Observables.emplace_back(fObservables[i]);
54 if (fObservables[i].find("Q2_R") != string::npos) fQ2_Observables.emplace_back(fObservables[i]);
55
56 if (fObservables[i].find("Q1_X_R") != string::npos) fQ1_X_Observables.emplace_back(fObservables[i]);
57 if (fObservables[i].find("Q2_X_R") != string::npos) fQ2_X_Observables.emplace_back(fObservables[i]);
58
59 if (fObservables[i].find("Q1_Y_R") != string::npos) fQ1_Y_Observables.emplace_back(fObservables[i]);
60 if (fObservables[i].find("Q2_Y_R") != string::npos) fQ2_Y_Observables.emplace_back(fObservables[i]);
61
62 if (fObservables[i].find("Qhigh_R") != string::npos) fQhigh_Observables.emplace_back(fObservables[i]);
63 if (fObservables[i].find("Qlow_R") != string::npos) fQlow_Observables.emplace_back(fObservables[i]);
64 if (fObservables[i].find("Qbalance_R") != string::npos)
65 fQbalance_Observables.emplace_back(fObservables[i]);
66 if (fObservables[i].find("Qratio_R") != string::npos)
67 fQratio_Observables.emplace_back(fObservables[i]);
68
69 if (fObservables[i].find("Qhigh_X_R") != string::npos)
70 fQhigh_X_Observables.emplace_back(fObservables[i]);
71 if (fObservables[i].find("Qlow_X_R") != string::npos)
72 fQlow_X_Observables.emplace_back(fObservables[i]);
73 if (fObservables[i].find("Qbalance_X_R") != string::npos)
74 fQbalance_X_Observables.emplace_back(fObservables[i]);
75 if (fObservables[i].find("Qratio_X_R") != string::npos)
76 fQratio_X_Observables.emplace_back(fObservables[i]);
77
78 if (fObservables[i].find("Qhigh_Y_R") != string::npos)
79 fQhigh_Y_Observables.emplace_back(fObservables[i]);
80 if (fObservables[i].find("Qlow_Y_R") != string::npos)
81 fQlow_Y_Observables.emplace_back(fObservables[i]);
82 if (fObservables[i].find("Qbalance_Y_R") != string::npos)
83 fQbalance_Y_Observables.emplace_back(fObservables[i]);
84 if (fObservables[i].find("Qratio_Y_R") != string::npos)
85 fQratio_Y_Observables.emplace_back(fObservables[i]);
86 }
87
88 for (unsigned int i = 0; i < fQ1_Observables.size(); i++) {
89 Double_t r1 = atof(fQ1_Observables[i].substr(4, fQ1_Observables[i].length() - 4).c_str());
90 fQ1_Radius.emplace_back(r1);
91 }
92
93 for (unsigned int i = 0; i < fQ2_Observables.size(); i++) {
94 Double_t r2 = atof(fQ2_Observables[i].substr(4, fQ2_Observables[i].length() - 4).c_str());
95 fQ2_Radius.emplace_back(r2);
96 }
97
98 for (unsigned int i = 0; i < fQ1_X_Observables.size(); i++) {
99 Double_t r1 = atof(fQ1_X_Observables[i].substr(6, fQ1_X_Observables[i].length() - 6).c_str());
100 fQ1_X_Radius.emplace_back(r1);
101 }
102
103 for (unsigned int i = 0; i < fQ2_X_Observables.size(); i++) {
104 Double_t r2 = atof(fQ2_X_Observables[i].substr(6, fQ2_X_Observables[i].length() - 6).c_str());
105 fQ2_X_Radius.emplace_back(r2);
106 }
107
108 for (unsigned int i = 0; i < fQ1_Y_Observables.size(); i++) {
109 Double_t r1 = atof(fQ1_Y_Observables[i].substr(6, fQ1_Y_Observables[i].length() - 6).c_str());
110 fQ1_Y_Radius.emplace_back(r1);
111 }
112
113 for (unsigned int i = 0; i < fQ2_Y_Observables.size(); i++) {
114 Double_t r2 = atof(fQ2_Y_Observables[i].substr(6, fQ2_Y_Observables[i].length() - 6).c_str());
115 fQ2_Y_Radius.emplace_back(r2);
116 }
117
118 for (unsigned int i = 0; i < fQhigh_Observables.size(); i++) {
119 Double_t r1 = atof(fQhigh_Observables[i].substr(7, fQhigh_Observables[i].length() - 7).c_str());
120 fQhigh_Radius.emplace_back(r1);
121 }
122
123 for (unsigned int i = 0; i < fQlow_Observables.size(); i++) {
124 Double_t r2 = atof(fQlow_Observables[i].substr(6, fQlow_Observables[i].length() - 6).c_str());
125 fQlow_Radius.emplace_back(r2);
126 }
127
128 for (unsigned int i = 0; i < fQhigh_X_Observables.size(); i++) {
129 Double_t r1 = atof(fQhigh_X_Observables[i].substr(9, fQhigh_X_Observables[i].length() - 9).c_str());
130 fQhigh_X_Radius.emplace_back(r1);
131 }
132
133 for (unsigned int i = 0; i < fQlow_X_Observables.size(); i++) {
134 Double_t r2 = atof(fQlow_X_Observables[i].substr(8, fQlow_X_Observables[i].length() - 8).c_str());
135 fQlow_X_Radius.emplace_back(r2);
136 }
137
138 for (unsigned int i = 0; i < fQhigh_Y_Observables.size(); i++) {
139 Double_t r1 = atof(fQhigh_Y_Observables[i].substr(9, fQhigh_Y_Observables[i].length() - 9).c_str());
140 fQhigh_Y_Radius.emplace_back(r1);
141 }
142
143 for (unsigned int i = 0; i < fQlow_Y_Observables.size(); i++) {
144 Double_t r2 = atof(fQlow_Y_Observables[i].substr(8, fQlow_Y_Observables[i].length() - 8).c_str());
145 fQlow_Y_Radius.emplace_back(r2);
146 }
147
148 for (unsigned int i = 0; i < fQbalance_Observables.size(); i++) {
149 Double_t r1 =
150 atof(fQbalance_Observables[i].substr(10, fQbalance_Observables[i].length() - 10).c_str());
151 fQbalance_Radius.emplace_back(r1);
152 }
153
154 for (unsigned int i = 0; i < fQratio_Observables.size(); i++) {
155 Double_t r2 = atof(fQratio_Observables[i].substr(8, fQratio_Observables[i].length() - 8).c_str());
156 fQratio_Radius.emplace_back(r2);
157 }
158
159 for (unsigned int i = 0; i < fQbalance_X_Observables.size(); i++) {
160 Double_t r1 =
161 atof(fQbalance_X_Observables[i].substr(12, fQbalance_X_Observables[i].length() - 12).c_str());
162 fQbalance_X_Radius.emplace_back(r1);
163 }
164
165 for (unsigned int i = 0; i < fQratio_X_Observables.size(); i++) {
166 Double_t r2 =
167 atof(fQratio_X_Observables[i].substr(10, fQratio_X_Observables[i].length() - 10).c_str());
168 fQratio_X_Radius.emplace_back(r2);
169 }
170
171 for (unsigned int i = 0; i < fQbalance_Y_Observables.size(); i++) {
172 Double_t r1 =
173 atof(fQbalance_Y_Observables[i].substr(12, fQbalance_Y_Observables[i].length() - 12).c_str());
174 fQbalance_Y_Radius.emplace_back(r1);
175 }
176
177 for (unsigned int i = 0; i < fQratio_Y_Observables.size(); i++) {
178 Double_t r2 =
179 atof(fQratio_Y_Observables[i].substr(10, fQratio_Y_Observables[i].length() - 10).c_str());
180 fQratio_Y_Radius.emplace_back(r2);
181 }
182}
183
185 fInputTrackEvent = (TRestTrackEvent*)inputEvent;
186
187 // Copying the input tracks to the output track
188 for (int tck = 0; tck < fInputTrackEvent->GetNumberOfTracks(); tck++)
189 fOutputTrackEvent->AddTrack(fInputTrackEvent->GetTrack(tck));
190
191 vector<TRestTrack*> tracks;
192
193 TRestTrack* tXYZ = fInputTrackEvent->GetMaxEnergyTrack();
194 if (tXYZ) tracks.emplace_back(tXYZ);
195
196 TRestTrack* tX = fInputTrackEvent->GetMaxEnergyTrack("X");
197 if (tX) tracks.emplace_back(tX);
198
199 TRestTrack* tY = fInputTrackEvent->GetMaxEnergyTrack("Y");
200 if (tY) tracks.emplace_back(tY);
201
202 Double_t x1 = 0, y1 = 0, z1 = 0;
203 Double_t x2 = 0, y2 = 0, z2 = 0;
204
205 Double_t x1_X = 0, x2_X = 0;
206 Double_t z1_X = 0, z2_X = 0;
207
208 Double_t y1_Y = 0, y2_Y = 0;
209 Double_t z1_Y = 0, z2_Y = 0;
210
211 for (unsigned int t = 0; t < tracks.size(); t++) {
212 TRestHits* hits = (TRestHits*)tracks[t]->GetVolumeHits();
213
214 Int_t nHits = hits->GetNumberOfHits();
215
216 Int_t nCheck = (Int_t)(nHits * fHitsToCheckFraction);
217
218 Int_t hit1 = hits->GetMostEnergeticHitInRange(0, nCheck);
219 Int_t hit2 = hits->GetMostEnergeticHitInRange(nHits - nCheck, nHits);
220
221 if (tracks[t]->isXYZ()) {
222 // The blob with z-coordinate closer to z=0 is stored in x1,y1,z1
223 if (fabs(hits->GetZ(hit1)) < fabs(hits->GetZ(hit2))) {
224 x1 = hits->GetX(hit1);
225 y1 = hits->GetY(hit1);
226 z1 = hits->GetZ(hit1);
227
228 x2 = hits->GetX(hit2);
229 y2 = hits->GetY(hit2);
230 z2 = hits->GetZ(hit2);
231 } else {
232 x2 = hits->GetX(hit1);
233 y2 = hits->GetY(hit1);
234 z2 = hits->GetZ(hit1);
235
236 x1 = hits->GetX(hit2);
237 y1 = hits->GetY(hit2);
238 z1 = hits->GetZ(hit2);
239 }
240 }
241
242 if (tracks[t]->isXZ()) {
243 // The blob with z-coordinate closer to z=0 is stored in x1,y1,z1
244 if (fabs(hits->GetZ(hit1)) < fabs(hits->GetZ(hit2))) {
245 x1_X = hits->GetX(hit1);
246 z1_X = hits->GetZ(hit1);
247
248 x2_X = hits->GetX(hit2);
249 z2_X = hits->GetZ(hit2);
250 } else {
251 x2_X = hits->GetX(hit1);
252 z2_X = hits->GetZ(hit1);
253
254 x1_X = hits->GetX(hit2);
255 z1_X = hits->GetZ(hit2);
256 }
257 }
258
259 if (tracks[t]->isYZ()) {
260 // The blob with z-coordinate closer to z=0 is stored in x1,y1,z1
261 if (fabs(hits->GetZ(hit1)) < fabs(hits->GetZ(hit2))) {
262 y1_Y = hits->GetY(hit1);
263 z1_Y = hits->GetZ(hit1);
264
265 y2_Y = hits->GetY(hit2);
266 z2_Y = hits->GetZ(hit2);
267 } else {
268 y2_Y = hits->GetY(hit1);
269 z2_Y = hits->GetZ(hit1);
270
271 y1_Y = hits->GetY(hit2);
272 z1_Y = hits->GetZ(hit2);
273 }
274 }
275 }
276
277 TString obsName;
278
279 SetObservableValue("x1", x1);
280 SetObservableValue("y1", y1);
281 SetObservableValue("z1", z1);
283 SetObservableValue("x2", x2);
284 SetObservableValue("y2", y2);
285 SetObservableValue("z2", z2);
286
287 Double_t dist = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2);
288 dist = TMath::Sqrt(dist);
289 SetObservableValue("distance", dist);
290
292 SetObservableValue("x1_X", x1_X);
293 SetObservableValue("z1_X", z1_X);
295 SetObservableValue("x2_X", x2_X);
296 SetObservableValue("z2_X", z2_X);
298 SetObservableValue("y1_Y", y1_Y);
299 SetObservableValue("z1_Y", z1_Y);
301
302 SetObservableValue("y2_Y", y2_Y);
303 SetObservableValue("z2_Y", z2_Y);
304
305 for (unsigned int t = 0; t < tracks.size(); t++) {
306 // We get the hit blob energy from the origin track (not from the reduced
307 // track)
308 Int_t longTrackId = tracks[t]->GetTrackID();
309 TRestTrack* originTrack = fInputTrackEvent->GetOriginTrackById(longTrackId);
310 TRestHits* originHits = (TRestHits*)(originTrack->GetVolumeHits());
311
312 if (tracks[t]->isXYZ()) {
313 for (unsigned int n = 0; n < fQ1_Observables.size(); n++) {
314 Double_t q = originHits->GetEnergyInSphere(x1, y1, z1, fQ1_Radius[n]);
315 SetObservableValue(fQ1_Observables[n], q);
316 }
317
318 for (unsigned int n = 0; n < fQ2_Observables.size(); n++) {
319 Double_t q = originHits->GetEnergyInSphere(x2, y2, z2, fQ2_Radius[n]);
320 SetObservableValue(fQ2_Observables[n], q);
321 }
322
323 for (unsigned int n = 0; n < fQhigh_Observables.size(); n++) {
324 Double_t q1 = originHits->GetEnergyInSphere(x1, y1, z1, fQhigh_Radius[n]);
325 Double_t q2 = originHits->GetEnergyInSphere(x2, y2, z2, fQhigh_Radius[n]);
326
327 Double_t q = q2;
328 if (q1 > q2) q = q1;
329 SetObservableValue(fQhigh_Observables[n], q);
330 }
331
332 for (unsigned int n = 0; n < fQlow_Observables.size(); n++) {
333 Double_t q1 = originHits->GetEnergyInSphere(x1, y1, z1, fQlow_Radius[n]);
334 Double_t q2 = originHits->GetEnergyInSphere(x2, y2, z2, fQlow_Radius[n]);
335
336 Double_t q = q2;
337 if (q1 < q2) q = q1;
338 SetObservableValue(fQlow_Observables[n], q);
339 }
340
341 for (unsigned int n = 0; n < fQbalance_Observables.size(); n++) {
342 Double_t q1 = originHits->GetEnergyInSphere(x1, y1, z1, fQbalance_Radius[n]);
343 Double_t q2 = originHits->GetEnergyInSphere(x2, y2, z2, fQbalance_Radius[n]);
344
345 Double_t qBalance;
346 if (q1 > q2)
347 qBalance = (q1 - q2) / (q1 + q2);
348 else
349 qBalance = (q2 - q1) / (q1 + q2);
350 SetObservableValue(fQbalance_Observables[n], qBalance);
351 }
352
353 for (unsigned int n = 0; n < fQratio_Observables.size(); n++) {
354 Double_t q1 = originHits->GetEnergyInSphere(x1, y1, z1, fQratio_Radius[n]);
355 Double_t q2 = originHits->GetEnergyInSphere(x2, y2, z2, fQratio_Radius[n]);
356
357 Double_t qRatio;
358 if (q1 > q2)
359 qRatio = q1 / q2;
360 else
361 qRatio = q2 / q1;
362 SetObservableValue(fQratio_Observables[n], qRatio);
363 }
364 }
365
366 if (tracks[t]->isXZ()) {
367 for (unsigned int n = 0; n < fQ1_X_Observables.size(); n++) {
368 Double_t q = originHits->GetEnergyInSphere(x1_X, 0, z1_X, fQ1_X_Radius[n]);
369 SetObservableValue(fQ1_X_Observables[n], q);
370 }
371
372 for (unsigned int n = 0; n < fQ2_X_Observables.size(); n++) {
373 Double_t q = originHits->GetEnergyInSphere(x2_X, 0, z2_X, fQ2_X_Radius[n]);
374 SetObservableValue(fQ2_X_Observables[n], q);
375 }
376
377 for (unsigned int n = 0; n < fQhigh_X_Observables.size(); n++) {
378 Double_t q1 = originHits->GetEnergyInSphere(x1_X, 0, z1_X, fQhigh_X_Radius[n]);
379 Double_t q2 = originHits->GetEnergyInSphere(x2_X, 0, z2_X, fQhigh_X_Radius[n]);
380
381 Double_t q = q2;
382 if (q1 > q2) q = q1;
383 SetObservableValue(fQhigh_X_Observables[n], q);
384 }
385
386 for (unsigned int n = 0; n < fQlow_X_Observables.size(); n++) {
387 Double_t q1 = originHits->GetEnergyInSphere(x1_X, 0, z1_X, fQlow_X_Radius[n]);
388 Double_t q2 = originHits->GetEnergyInSphere(x2_X, 0, z2_X, fQlow_X_Radius[n]);
389
390 Double_t q = q2;
391 if (q1 < q2) q = q1;
392 SetObservableValue(fQlow_X_Observables[n], q);
393 }
394
395 for (unsigned int n = 0; n < fQbalance_X_Observables.size(); n++) {
396 Double_t q1 = originHits->GetEnergyInSphere(x1_X, 0, z1_X, fQbalance_X_Radius[n]);
397 Double_t q2 = originHits->GetEnergyInSphere(x2_X, 0, z2_X, fQbalance_X_Radius[n]);
398
399 Double_t qBalance;
400 if (q1 > q2)
401 qBalance = (q1 - q2) / (q1 + q2);
402 else
403 qBalance = (q2 - q1) / (q1 + q2);
404 SetObservableValue(fQbalance_X_Observables[n], qBalance);
405 }
406
407 for (unsigned int n = 0; n < fQratio_X_Observables.size(); n++) {
408 Double_t q1 = originHits->GetEnergyInSphere(x1_X, 0, z1_X, fQratio_X_Radius[n]);
409 Double_t q2 = originHits->GetEnergyInSphere(x2_X, 0, z2_X, fQratio_X_Radius[n]);
410
411 Double_t qRatio;
412 if (q1 > q2)
413 qRatio = q1 / q2;
414 else
415 qRatio = q2 / q1;
416 SetObservableValue(fQratio_X_Observables[n], qRatio);
417 }
418 }
419
420 if (tracks[t]->isYZ()) {
421 for (unsigned int n = 0; n < fQ1_Y_Observables.size(); n++) {
422 Double_t q = originHits->GetEnergyInSphere(0, y1_Y, z1_Y, fQ1_Y_Radius[n]);
423 SetObservableValue(fQ1_Y_Observables[n], q);
424 }
425
426 for (unsigned int n = 0; n < fQ2_Y_Observables.size(); n++) {
427 Double_t q = originHits->GetEnergyInSphere(0, y2_Y, z2_Y, fQ2_Y_Radius[n]);
428 SetObservableValue(fQ2_Y_Observables[n], q);
429 }
430
431 for (unsigned int n = 0; n < fQhigh_Y_Observables.size(); n++) {
432 Double_t q1 = originHits->GetEnergyInSphere(0, y1_Y, z1_Y, fQhigh_Y_Radius[n]);
433 Double_t q2 = originHits->GetEnergyInSphere(0, y2_Y, z2_Y, fQhigh_Y_Radius[n]);
434
435 Double_t q = q2;
436 if (q1 > q2) q = q1;
437 SetObservableValue(fQhigh_Y_Observables[n], q);
438 }
439
440 for (unsigned int n = 0; n < fQlow_Y_Observables.size(); n++) {
441 Double_t q1 = originHits->GetEnergyInSphere(0, y1_Y, z1_Y, fQlow_Y_Radius[n]);
442 Double_t q2 = originHits->GetEnergyInSphere(0, y2_Y, z2_Y, fQlow_Y_Radius[n]);
443
444 Double_t q = q2;
445 if (q1 < q2) q = q1;
446 SetObservableValue(fQlow_Y_Observables[n], q);
447 }
448
449 for (unsigned int n = 0; n < fQbalance_Y_Observables.size(); n++) {
450 Double_t q1 = originHits->GetEnergyInSphere(0, y1_Y, z1_Y, fQbalance_Y_Radius[n]);
451 Double_t q2 = originHits->GetEnergyInSphere(0, y2_Y, z2_Y, fQbalance_Y_Radius[n]);
452
453 Double_t qBalance;
454 if (q1 > q2)
455 qBalance = (q1 - q2) / (q1 + q2);
456 else
457 qBalance = (q2 - q1) / (q1 + q2);
458 SetObservableValue(fQbalance_Y_Observables[n], qBalance);
459 }
460
461 for (unsigned int n = 0; n < fQratio_Y_Observables.size(); n++) {
462 Double_t q1 = originHits->GetEnergyInSphere(0, y1_Y, z1_Y, fQratio_Y_Radius[n]);
463 Double_t q2 = originHits->GetEnergyInSphere(0, y2_Y, z2_Y, fQratio_Y_Radius[n]);
464
465 Double_t qRatio;
466 if (q1 > q2)
467 qRatio = q1 / q2;
468 else
469 qRatio = q2 / q1;
470 SetObservableValue(fQratio_Y_Observables[n], qRatio);
471 }
472 }
473 }
474
475 return fOutputTrackEvent;
476}
477
479 // Function to be executed once at the end of the process
480 // (after all events have been processed)
481
482 // Start by calling the EndProcess function of the abstract class.
483 // Comment this if you don't want it.
484 // TRestEventProcess::EndProcess();
485}
486
488 fHitsToCheckFraction = StringToDouble(GetParameter("hitsToCheckFraction", "0.2"));
489}
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
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 GetMostEnergeticHitInRange(Int_t n, Int_t m) const
It returns the most energetic hit found between hits n and m.
Definition: TRestHits.cxx:1229
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.
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)
void Initialize() override
Making default settings.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
Double_t StringToDouble(std::string in)
Gets a double from a string.