Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential bug in track analysis #47

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 68 additions & 10 deletions src/TRestTrack2DAnalysisProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,10 @@ TRestEvent* TRestTrack2DAnalysisProcess::ProcessEvent(TRestEvent* inputEvent) {
auto hitsBoth = {hitsXZ, hitsYZ};

for (auto arg : hitsBoth) {
if (arg == nullptr) continue;
for (unsigned int n = 0; n < arg->GetNumberOfHits(); n++) {
if (arg == nullptr) {
continue;
}
for (int n = 0; n < int(arg->GetNumberOfHits()); n++) {
// your code in the existing loop, replacing `hits` by `arg`
Double_t eDep = arg->GetEnergy(n);
Double_t x = arg->GetX(n);
Expand Down Expand Up @@ -420,6 +422,9 @@ TRestEvent* TRestTrack2DAnalysisProcess::ProcessEvent(TRestEvent* inputEvent) {
// --- Max track observables --- //

// Copy the MaxTrack keys immediately after checking the vector

SetObservableValue("MaxTrack_XZ_OK", !energiesX.empty());

if (!energiesX.empty()) {
int energiesX0FirstKey =
energiesX[0].first; // Declare Keys outside to avoid error when accessing "energiesX[0].first"...
Expand All @@ -436,9 +441,21 @@ TRestEvent* TRestTrack2DAnalysisProcess::ProcessEvent(TRestEvent* inputEvent) {
SetObservableValue("MaxTrack_XZ_MeanZ", XZ_MeanZ[energiesX0FirstKey]);
SetObservableValue("MaxTrack_XZ_SkewZ", XZ_SkewZ[energiesX0FirstKey]);
} else {
std::cerr << "Error: energiesX is empty. The observables are set to 0." << std::endl;
SetObservableValue("MaxTrack_XZ_NHitsX", 0);
SetObservableValue("MaxTrack_XZ_EnergyX", 0);
SetObservableValue("MaxTrack_XZ_SigmaX", 0);
SetObservableValue("MaxTrack_XZ_SigmaZ", 0);
SetObservableValue("MaxTrack_XZ_GaussSigmaX", 0);
SetObservableValue("MaxTrack_XZ_GaussSigmaZ", 0);
SetObservableValue("MaxTrack_XZ_LengthX", 0);
SetObservableValue("MaxTrack_XZ_VolumeX", 0);
SetObservableValue("MaxTrack_XZ_MeanX", 0);
SetObservableValue("MaxTrack_XZ_MeanZ", 0);
SetObservableValue("MaxTrack_XZ_SkewZ", 0);
}

SetObservableValue("MaxTrack_YZ_OK", !energiesY.empty());

if (!energiesY.empty()) {
int energiesY0FirstKey = energiesY[0].first;

Expand All @@ -454,9 +471,21 @@ TRestEvent* TRestTrack2DAnalysisProcess::ProcessEvent(TRestEvent* inputEvent) {
SetObservableValue("MaxTrack_YZ_MeanZ", YZ_MeanZ[energiesY0FirstKey]);
SetObservableValue("MaxTrack_YZ_SkewZ", YZ_SkewZ[energiesY0FirstKey]);
} else {
std::cerr << "Error: energiesY is empty. The observables are set to 0." << std::endl;
SetObservableValue("MaxTrack_YZ_NHitsY", 0);
SetObservableValue("MaxTrack_YZ_EnergyY", 0);
SetObservableValue("MaxTrack_YZ_SigmaY", 0);
SetObservableValue("MaxTrack_YZ_SigmaZ", 0);
SetObservableValue("MaxTrack_YZ_GaussSigmaY", 0);
SetObservableValue("MaxTrack_YZ_GaussSigmaZ", 0);
SetObservableValue("MaxTrack_YZ_LengthY", 0);
SetObservableValue("MaxTrack_YZ_VolumeY", 0);
SetObservableValue("MaxTrack_YZ_MeanY", 0);
SetObservableValue("MaxTrack_YZ_MeanZ", 0);
SetObservableValue("MaxTrack_YZ_SkewZ", 0);
}

SetObservableValue("MaxTrack_XZ_YZ_OK", !energiesY.empty() && !energiesX.empty());

if (!energiesX.empty() && !energiesY.empty()) {
Double_t energiesX0SecondKey = energiesX[0].second;
Double_t energiesY0SecondKey = energiesY[0].second;
Expand All @@ -468,7 +497,9 @@ TRestEvent* TRestTrack2DAnalysisProcess::ProcessEvent(TRestEvent* inputEvent) {
(energiesX0SecondKey + energiesY0SecondKey));

} else {
std::cerr << "Error: energiesX or energiesY is empty. The observables are set to 0." << std::endl;
SetObservableValue("MaxTrack_XZ_YZ_Energy", 0);
SetObservableValue("MaxTrack_XZ_YZ_MaxTrackEnergyPercentage", 0);
SetObservableValue("MaxTrack_XZ_YZ_EnergyBalanceXY", 0);
}

SetObservableValue("MaxTrack_XZ_YZ_SigmaXYBalance", XZ_YZ_SigmaXYBalance[0]);
Expand All @@ -477,9 +508,10 @@ TRestEvent* TRestTrack2DAnalysisProcess::ProcessEvent(TRestEvent* inputEvent) {
SetObservableValue("MaxTrack_XZ_YZ_GaussSigmaZBalance", XZ_YZ_GaussSigmaZBalance[0]);

// --- Second max track observables --- //
SetObservableValue("SecondMaxTrack_XZ_OK", energiesX.size() > 1);

// Copy the SecondTrack keys immediately after checking the vector
if (!energiesX.empty()) {
if (energiesX.size() > 1) {
int energiesX1FirstKey =
energiesX[1].first; // Declare Keys outside to avoid error when accessing "energiesX[1].first"...

Expand All @@ -495,9 +527,21 @@ TRestEvent* TRestTrack2DAnalysisProcess::ProcessEvent(TRestEvent* inputEvent) {
SetObservableValue("SecondMaxTrack_XZ_MeanZ", XZ_MeanZ[energiesX1FirstKey]);
SetObservableValue("SecondMaxTrack_XZ_SkewZ", XZ_SkewZ[energiesX1FirstKey]);
} else {
std::cerr << "Error: energiesX is empty. The observables are set to 0." << std::endl;
SetObservableValue("SecondMaxTrack_XZ_NHitsX", 0);
SetObservableValue("SecondMaxTrack_XZ_EnergyX", 0);
SetObservableValue("SecondMaxTrack_XZ_SigmaX", 0);
SetObservableValue("SecondMaxTrack_XZ_SigmaZ", 0);
SetObservableValue("SecondMaxTrack_XZ_GaussSigmaX", 0);
SetObservableValue("SecondMaxTrack_XZ_GaussSigmaZ", 0);
SetObservableValue("SecondMaxTrack_XZ_LengthX", 0);
SetObservableValue("SecondMaxTrack_XZ_VolumeX", 0);
SetObservableValue("SecondMaxTrack_XZ_MeanX", 0);
SetObservableValue("SecondMaxTrack_XZ_MeanZ", 0);
SetObservableValue("SecondMaxTrack_XZ_SkewZ", 0);
}

SetObservableValue("SecondMaxTrack_YZ_OK", energiesY.size() > 1);

if (!energiesY.empty()) {
int energiesY1FirstKey = energiesY[1].first;

Expand All @@ -513,15 +557,27 @@ TRestEvent* TRestTrack2DAnalysisProcess::ProcessEvent(TRestEvent* inputEvent) {
SetObservableValue("SecondMaxTrack_YZ_MeanZ", YZ_MeanZ[energiesY1FirstKey]);
SetObservableValue("SecondMaxTrack_YZ_SkewZ", YZ_SkewZ[energiesY1FirstKey]);
} else {
std::cerr << "Error: energiesY is empty. The observables are set to 0." << std::endl;
SetObservableValue("SecondMaxTrack_YZ_NHitsY", 0);
SetObservableValue("SecondMaxTrack_YZ_EnergyY", 0);
SetObservableValue("SecondMaxTrack_YZ_SigmaY", 0);
SetObservableValue("SecondMaxTrack_YZ_SigmaZ", 0);
SetObservableValue("SecondMaxTrack_YZ_GaussSigmaY", 0);
SetObservableValue("SecondMaxTrack_YZ_GaussSigmaZ", 0);
SetObservableValue("SecondMaxTrack_YZ_LengthY", 0);
SetObservableValue("SecondMaxTrack_YZ_VolumeY", 0);
SetObservableValue("SecondMaxTrack_YZ_MeanY", 0);
SetObservableValue("SecondMaxTrack_YZ_MeanZ", 0);
SetObservableValue("SecondMaxTrack_YZ_SkewZ", 0);
}

SetObservableValue("SecondMaxTrack_XZ_YZ_SigmaXYBalance", XZ_YZ_SigmaXYBalance[1]);
SetObservableValue("SecondMaxTrack_XZ_YZ_SigmaZBalance", XZ_YZ_SigmaZBalance[1]);
SetObservableValue("SecondMaxTrack_XZ_YZ_GaussSigmaXYBalance", XZ_YZ_GaussSigmaXYBalance[1]);
SetObservableValue("SecondMaxTrack_XZ_YZ_GaussSigmaZBalance", XZ_YZ_GaussSigmaZBalance[1]);

if (!energiesX.empty() && !energiesY.empty()) {
SetObservableValue("SecondMaxTrack_XZ_YZ_OK", energiesY.size() > 1 && energiesX.size() > 1);

if (energiesY.size() > 1 && energiesX.size() > 1) {
Double_t energiesX1SecondKey = energiesX[1].second;
Double_t energiesY1SecondKey = energiesY[1].second;

Expand All @@ -538,7 +594,9 @@ TRestEvent* TRestTrack2DAnalysisProcess::ProcessEvent(TRestEvent* inputEvent) {
SetObservableValue("SecondMaxTrack_XZ_YZ_EnergyBalanceXY", 0.0);
}
} else {
std::cerr << "Error: energiesX or energiesY is empty. The observables are set to 0." << std::endl;
SetObservableValue("SecondMaxTrack_XZ_YZ_Energy", 0.0);
SetObservableValue("SecondMaxTrack_XZ_YZ_EnergyPercentage", 0.0);
SetObservableValue("SecondMaxTrack_XZ_YZ_EnergyBalanceXY", 0.0);
}

// --- Distance observables between first two tracks --- //
Expand Down
Loading