16 #include "TRestTrackBlobAnalysisProcess.h"
22 TRestTrackBlobAnalysisProcess::TRestTrackBlobAnalysisProcess() { Initialize(); }
24 TRestTrackBlobAnalysisProcess::TRestTrackBlobAnalysisProcess(
const char* configFilename) {
27 if (LoadConfigFromFile(configFilename)) LoadDefaultConfig();
30 TRestTrackBlobAnalysisProcess::~TRestTrackBlobAnalysisProcess() {
delete fOutputTrackEvent; }
32 void TRestTrackBlobAnalysisProcess::LoadDefaultConfig() { SetTitle(
"Default config"); }
35 SetSectionName(this->ClassName());
36 SetLibraryVersion(LIBRARY_VERSION);
38 fInputTrackEvent =
nullptr;
41 fHitsToCheckFraction = 0.2;
44 void TRestTrackBlobAnalysisProcess::LoadConfig(
const string& configFilename,
const string& name) {
45 if (LoadConfigFromFile(configFilename, name)) LoadDefaultConfig();
49 std::vector<string> fObservables;
50 fObservables = TRestEventProcess::ReadObservables();
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]);
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]);
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]);
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]);
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]);
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]);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
145 for (
unsigned int i = 0; i < fQbalance_Observables.size(); i++) {
147 atof(fQbalance_Observables[i].substr(10, fQbalance_Observables[i].length() - 10).c_str());
148 fQbalance_Radius.push_back(r1);
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);
156 for (
unsigned int i = 0; i < fQbalance_X_Observables.size(); i++) {
158 atof(fQbalance_X_Observables[i].substr(12, fQbalance_X_Observables[i].length() - 12).c_str());
159 fQbalance_X_Radius.push_back(r1);
162 for (
unsigned int i = 0; i < fQratio_X_Observables.size(); i++) {
164 atof(fQratio_X_Observables[i].substr(10, fQratio_X_Observables[i].length() - 10).c_str());
165 fQratio_X_Radius.push_back(r2);
168 for (
unsigned int i = 0; i < fQbalance_Y_Observables.size(); i++) {
170 atof(fQbalance_Y_Observables[i].substr(12, fQbalance_Y_Observables[i].length() - 12).c_str());
171 fQbalance_Y_Radius.push_back(r1);
174 for (
unsigned int i = 0; i < fQratio_Y_Observables.size(); i++) {
176 atof(fQratio_Y_Observables[i].substr(10, fQratio_Y_Observables[i].length() - 10).c_str());
177 fQratio_Y_Radius.push_back(r2);
185 for (
int tck = 0; tck < fInputTrackEvent->GetNumberOfTracks(); tck++)
186 fOutputTrackEvent->AddTrack(fInputTrackEvent->GetTrack(tck));
188 vector<TRestTrack*> tracks;
190 TRestTrack* tXYZ = fInputTrackEvent->GetMaxEnergyTrack();
191 if (tXYZ) tracks.push_back(tXYZ);
193 TRestTrack* tX = fInputTrackEvent->GetMaxEnergyTrack(
"X");
194 if (tX) tracks.push_back(tX);
196 TRestTrack* tY = fInputTrackEvent->GetMaxEnergyTrack(
"Y");
197 if (tY) tracks.push_back(tY);
199 Double_t x1 = 0, y1 = 0, z1 = 0;
200 Double_t x2 = 0, y2 = 0, z2 = 0;
202 Double_t x1_X = 0, x2_X = 0;
203 Double_t z1_X = 0, z2_X = 0;
205 Double_t y1_Y = 0, y2_Y = 0;
206 Double_t z1_Y = 0, z2_Y = 0;
208 for (
unsigned int t = 0; t < tracks.size(); t++) {
211 Int_t nHits = hits->GetNumberOfHits();
213 Int_t nCheck = (Int_t)(nHits * fHitsToCheckFraction);
218 if (tracks[t]->isXYZ()) {
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);
225 x2 = hits->GetX(hit2);
226 y2 = hits->GetY(hit2);
227 z2 = hits->GetZ(hit2);
229 x2 = hits->GetX(hit1);
230 y2 = hits->GetY(hit1);
231 z2 = hits->GetZ(hit1);
233 x1 = hits->GetX(hit2);
234 y1 = hits->GetY(hit2);
235 z1 = hits->GetZ(hit2);
239 if (tracks[t]->isXZ()) {
241 if (fabs(hits->GetZ(hit1)) < fabs(hits->GetZ(hit2))) {
242 x1_X = hits->GetX(hit1);
243 z1_X = hits->GetZ(hit1);
245 x2_X = hits->GetX(hit2);
246 z2_X = hits->GetZ(hit2);
248 x2_X = hits->GetX(hit1);
249 z2_X = hits->GetZ(hit1);
251 x1_X = hits->GetX(hit2);
252 z1_X = hits->GetZ(hit2);
256 if (tracks[t]->isYZ()) {
258 if (fabs(hits->GetZ(hit1)) < fabs(hits->GetZ(hit2))) {
259 y1_Y = hits->GetY(hit1);
260 z1_Y = hits->GetZ(hit1);
262 y2_Y = hits->GetY(hit2);
263 z2_Y = hits->GetZ(hit2);
265 y2_Y = hits->GetY(hit1);
266 z2_Y = hits->GetZ(hit1);
268 y1_Y = hits->GetY(hit2);
269 z1_Y = hits->GetZ(hit2);
276 SetObservableValue(
"x1", x1);
277 SetObservableValue(
"y1", y1);
278 SetObservableValue(
"z1", z1);
280 SetObservableValue(
"x2", x2);
281 SetObservableValue(
"y2", y2);
282 SetObservableValue(
"z2", z2);
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);
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);
299 SetObservableValue(
"y2_Y", y2_Y);
300 SetObservableValue(
"z2_Y", z2_Y);
302 for (
unsigned int t = 0; t < tracks.size(); t++) {
305 Int_t longTrackId = tracks[t]->GetTrackID();
306 TRestTrack* originTrack = fInputTrackEvent->GetOriginTrackById(longTrackId);
309 if (tracks[t]->isXYZ()) {
310 for (
unsigned int n = 0; n < fQ1_Observables.size(); n++) {
312 SetObservableValue(fQ1_Observables[n], q);
315 for (
unsigned int n = 0; n < fQ2_Observables.size(); n++) {
317 SetObservableValue(fQ2_Observables[n], q);
320 for (
unsigned int n = 0; n < fQhigh_Observables.size(); n++) {
326 SetObservableValue(fQhigh_Observables[n], q);
329 for (
unsigned int n = 0; n < fQlow_Observables.size(); n++) {
335 SetObservableValue(fQlow_Observables[n], q);
338 for (
unsigned int n = 0; n < fQbalance_Observables.size(); n++) {
344 qBalance = (q1 - q2) / (q1 + q2);
346 qBalance = (q2 - q1) / (q1 + q2);
347 SetObservableValue(fQbalance_Observables[n], qBalance);
350 for (
unsigned int n = 0; n < fQratio_Observables.size(); n++) {
359 SetObservableValue(fQratio_Observables[n], qRatio);
363 if (tracks[t]->isXZ()) {
364 for (
unsigned int n = 0; n < fQ1_X_Observables.size(); n++) {
366 SetObservableValue(fQ1_X_Observables[n], q);
369 for (
unsigned int n = 0; n < fQ2_X_Observables.size(); n++) {
371 SetObservableValue(fQ2_X_Observables[n], q);
374 for (
unsigned int n = 0; n < fQhigh_X_Observables.size(); n++) {
380 SetObservableValue(fQhigh_X_Observables[n], q);
383 for (
unsigned int n = 0; n < fQlow_X_Observables.size(); n++) {
389 SetObservableValue(fQlow_X_Observables[n], q);
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]);
398 qBalance = (q1 - q2) / (q1 + q2);
400 qBalance = (q2 - q1) / (q1 + q2);
401 SetObservableValue(fQbalance_X_Observables[n], qBalance);
404 for (
unsigned int n = 0; n < fQratio_X_Observables.size(); n++) {
413 SetObservableValue(fQratio_X_Observables[n], qRatio);
417 if (tracks[t]->isYZ()) {
418 for (
unsigned int n = 0; n < fQ1_Y_Observables.size(); n++) {
420 SetObservableValue(fQ1_Y_Observables[n], q);
423 for (
unsigned int n = 0; n < fQ2_Y_Observables.size(); n++) {
425 SetObservableValue(fQ2_Y_Observables[n], q);
428 for (
unsigned int n = 0; n < fQhigh_Y_Observables.size(); n++) {
434 SetObservableValue(fQhigh_Y_Observables[n], q);
437 for (
unsigned int n = 0; n < fQlow_Y_Observables.size(); n++) {
443 SetObservableValue(fQlow_Y_Observables[n], q);
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]);
452 qBalance = (q1 - q2) / (q1 + q2);
454 qBalance = (q2 - q1) / (q1 + q2);
455 SetObservableValue(fQbalance_Y_Observables[n], qBalance);
458 for (
unsigned int n = 0; n < fQratio_Y_Observables.size(); n++) {
467 SetObservableValue(fQratio_Y_Observables[n], qRatio);
472 return fOutputTrackEvent;
485 fHitsToCheckFraction =
StringToDouble(GetParameter(
"hitsToCheckFraction",
"0.2"));
A base class for any REST event.
It saves a 3-coordinate position and an energy for each punctual deposition.
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.
Int_t GetMostEnergeticHitInRange(Int_t n, Int_t m) const
It returns the most energetic hit found between hits n and m.
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.