16#include "TRestTrackBlobAnalysisProcess.h"
22TRestTrackBlobAnalysisProcess::TRestTrackBlobAnalysisProcess() {
Initialize(); }
24TRestTrackBlobAnalysisProcess::TRestTrackBlobAnalysisProcess(
const char* configFilename) {
30TRestTrackBlobAnalysisProcess::~TRestTrackBlobAnalysisProcess() {
delete fOutputTrackEvent; }
32void TRestTrackBlobAnalysisProcess::LoadDefaultConfig() { SetTitle(
"Default config"); }
38 fInputTrackEvent =
nullptr;
41 fHitsToCheckFraction = 0.2;
44void TRestTrackBlobAnalysisProcess::LoadConfig(
const string& configFilename,
const string& name) {
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.emplace_back(fObservables[i]);
54 if (fObservables[i].find(
"Q2_R") != string::npos) fQ2_Observables.emplace_back(fObservables[i]);
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]);
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]);
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]);
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]);
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]);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
148 for (
unsigned int i = 0; i < fQbalance_Observables.size(); i++) {
150 atof(fQbalance_Observables[i].substr(10, fQbalance_Observables[i].length() - 10).c_str());
151 fQbalance_Radius.emplace_back(r1);
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);
159 for (
unsigned int i = 0; i < fQbalance_X_Observables.size(); i++) {
161 atof(fQbalance_X_Observables[i].substr(12, fQbalance_X_Observables[i].length() - 12).c_str());
162 fQbalance_X_Radius.emplace_back(r1);
165 for (
unsigned int i = 0; i < fQratio_X_Observables.size(); i++) {
167 atof(fQratio_X_Observables[i].substr(10, fQratio_X_Observables[i].length() - 10).c_str());
168 fQratio_X_Radius.emplace_back(r2);
171 for (
unsigned int i = 0; i < fQbalance_Y_Observables.size(); i++) {
173 atof(fQbalance_Y_Observables[i].substr(12, fQbalance_Y_Observables[i].length() - 12).c_str());
174 fQbalance_Y_Radius.emplace_back(r1);
177 for (
unsigned int i = 0; i < fQratio_Y_Observables.size(); i++) {
179 atof(fQratio_Y_Observables[i].substr(10, fQratio_Y_Observables[i].length() - 10).c_str());
180 fQratio_Y_Radius.emplace_back(r2);
188 for (
int tck = 0; tck < fInputTrackEvent->GetNumberOfTracks(); tck++)
189 fOutputTrackEvent->AddTrack(fInputTrackEvent->GetTrack(tck));
191 vector<TRestTrack*> tracks;
193 TRestTrack* tXYZ = fInputTrackEvent->GetMaxEnergyTrack();
194 if (tXYZ) tracks.emplace_back(tXYZ);
196 TRestTrack* tX = fInputTrackEvent->GetMaxEnergyTrack(
"X");
197 if (tX) tracks.emplace_back(tX);
199 TRestTrack* tY = fInputTrackEvent->GetMaxEnergyTrack(
"Y");
200 if (tY) tracks.emplace_back(tY);
202 Double_t x1 = 0, y1 = 0, z1 = 0;
203 Double_t x2 = 0, y2 = 0, z2 = 0;
205 Double_t x1_X = 0, x2_X = 0;
206 Double_t z1_X = 0, z2_X = 0;
208 Double_t y1_Y = 0, y2_Y = 0;
209 Double_t z1_Y = 0, z2_Y = 0;
211 for (
unsigned int t = 0; t < tracks.size(); t++) {
214 Int_t nHits = hits->GetNumberOfHits();
216 Int_t nCheck = (Int_t)(nHits * fHitsToCheckFraction);
221 if (tracks[t]->isXYZ()) {
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);
228 x2 = hits->GetX(hit2);
229 y2 = hits->GetY(hit2);
230 z2 = hits->GetZ(hit2);
232 x2 = hits->GetX(hit1);
233 y2 = hits->GetY(hit1);
234 z2 = hits->GetZ(hit1);
236 x1 = hits->GetX(hit2);
237 y1 = hits->GetY(hit2);
238 z1 = hits->GetZ(hit2);
242 if (tracks[t]->isXZ()) {
244 if (fabs(hits->GetZ(hit1)) < fabs(hits->GetZ(hit2))) {
245 x1_X = hits->GetX(hit1);
246 z1_X = hits->GetZ(hit1);
248 x2_X = hits->GetX(hit2);
249 z2_X = hits->GetZ(hit2);
251 x2_X = hits->GetX(hit1);
252 z2_X = hits->GetZ(hit1);
254 x1_X = hits->GetX(hit2);
255 z1_X = hits->GetZ(hit2);
259 if (tracks[t]->isYZ()) {
261 if (fabs(hits->GetZ(hit1)) < fabs(hits->GetZ(hit2))) {
262 y1_Y = hits->GetY(hit1);
263 z1_Y = hits->GetZ(hit1);
265 y2_Y = hits->GetY(hit2);
266 z2_Y = hits->GetZ(hit2);
268 y2_Y = hits->GetY(hit1);
269 z2_Y = hits->GetZ(hit1);
271 y1_Y = hits->GetY(hit2);
272 z1_Y = hits->GetZ(hit2);
287 Double_t dist = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2);
288 dist = TMath::Sqrt(dist);
305 for (
unsigned int t = 0; t < tracks.size(); t++) {
308 Int_t longTrackId = tracks[t]->GetTrackID();
309 TRestTrack* originTrack = fInputTrackEvent->GetOriginTrackById(longTrackId);
312 if (tracks[t]->isXYZ()) {
313 for (
unsigned int n = 0; n < fQ1_Observables.size(); n++) {
318 for (
unsigned int n = 0; n < fQ2_Observables.size(); n++) {
323 for (
unsigned int n = 0; n < fQhigh_Observables.size(); n++) {
332 for (
unsigned int n = 0; n < fQlow_Observables.size(); n++) {
341 for (
unsigned int n = 0; n < fQbalance_Observables.size(); n++) {
347 qBalance = (q1 - q2) / (q1 + q2);
349 qBalance = (q2 - q1) / (q1 + q2);
353 for (
unsigned int n = 0; n < fQratio_Observables.size(); n++) {
366 if (tracks[t]->isXZ()) {
367 for (
unsigned int n = 0; n < fQ1_X_Observables.size(); n++) {
372 for (
unsigned int n = 0; n < fQ2_X_Observables.size(); n++) {
377 for (
unsigned int n = 0; n < fQhigh_X_Observables.size(); n++) {
386 for (
unsigned int n = 0; n < fQlow_X_Observables.size(); n++) {
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]);
401 qBalance = (q1 - q2) / (q1 + q2);
403 qBalance = (q2 - q1) / (q1 + q2);
407 for (
unsigned int n = 0; n < fQratio_X_Observables.size(); n++) {
420 if (tracks[t]->isYZ()) {
421 for (
unsigned int n = 0; n < fQ1_Y_Observables.size(); n++) {
426 for (
unsigned int n = 0; n < fQ2_Y_Observables.size(); n++) {
431 for (
unsigned int n = 0; n < fQhigh_Y_Observables.size(); n++) {
440 for (
unsigned int n = 0; n < fQlow_Y_Observables.size(); n++) {
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]);
455 qBalance = (q1 - q2) / (q1 + q2);
457 qBalance = (q2 - q1) / (q1 + q2);
461 for (
unsigned int n = 0; n < fQratio_Y_Observables.size(); n++) {
475 return fOutputTrackEvent;
void SetObservableValue(const std::string &name, const T &value)
Set observable value for AnalysisTree.
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.