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