diff --git a/src/TRestTrack2DAnalysisProcess.cxx b/src/TRestTrack2DAnalysisProcess.cxx index 43b9e99..453c5ce 100644 --- a/src/TRestTrack2DAnalysisProcess.cxx +++ b/src/TRestTrack2DAnalysisProcess.cxx @@ -421,11 +421,13 @@ TRestEvent* TRestTrack2DAnalysisProcess::ProcessEvent(TRestEvent* inputEvent) { // --- Max track observables --- // - // Copy the MaxTrack keys immediately after checking the vector + // Check if the maximum (final) energy value in energiesX and Y is non-zero + bool hasNonZeroEnergyX = !energiesX.empty() && energiesX[0].second != 0; + bool hasNonZeroEnergyY = !energiesY.empty() && energiesY[0].second != 0; - SetObservableValue("MaxTrack_XZ_OK", !energiesX.empty()); + SetObservableValue("MaxTrack_XZ_OK", hasNonZeroEnergyX); - if (!energiesX.empty()) { + if (hasNonZeroEnergyX) { int energiesX0FirstKey = energiesX[0].first; // Declare Keys outside to avoid error when accessing "energiesX[0].first"... @@ -454,9 +456,9 @@ TRestEvent* TRestTrack2DAnalysisProcess::ProcessEvent(TRestEvent* inputEvent) { SetObservableValue("MaxTrack_XZ_SkewZ", 0.); } - SetObservableValue("MaxTrack_YZ_OK", !energiesY.empty()); + SetObservableValue("MaxTrack_YZ_OK", hasNonZeroEnergyY); - if (!energiesY.empty()) { + if (hasNonZeroEnergyY) { int energiesY0FirstKey = energiesY[0].first; SetObservableValue("MaxTrack_YZ_NHitsY", YZ_NHitsY[energiesY0FirstKey]); @@ -484,7 +486,7 @@ TRestEvent* TRestTrack2DAnalysisProcess::ProcessEvent(TRestEvent* inputEvent) { SetObservableValue("MaxTrack_YZ_SkewZ", 0.); } - SetObservableValue("MaxTrack_XZ_YZ_OK", !energiesY.empty() && !energiesX.empty()); + SetObservableValue("MaxTrack_XZ_YZ_OK", hasNonZeroEnergyX && hasNonZeroEnergyY); if (!energiesX.empty() && !energiesY.empty()) { Double_t energiesX0SecondKey = energiesX[0].second; @@ -508,10 +510,15 @@ 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); + + // Check if the second maximum energy value in energiesX and Y is non-zero + bool hasNonZeroSecondMaxEnergyX = energiesX.size() > 1 && energiesX[1].second != 0; + bool hasNonZeroSecondMaxEnergyY = energiesY.size() > 1 && energiesY[1].second != 0; + + SetObservableValue("SecondMaxTrack_XZ_OK", hasNonZeroSecondMaxEnergyX); // Copy the SecondTrack keys immediately after checking the vector - if (energiesX.size() > 1) { + if (hasNonZeroSecondMaxEnergyX) { int energiesX1FirstKey = energiesX[1].first; // Declare Keys outside to avoid error when accessing "energiesX[1].first"... @@ -540,9 +547,9 @@ TRestEvent* TRestTrack2DAnalysisProcess::ProcessEvent(TRestEvent* inputEvent) { SetObservableValue("SecondMaxTrack_XZ_SkewZ", 0.); } - SetObservableValue("SecondMaxTrack_YZ_OK", energiesY.size() > 1); + SetObservableValue("SecondMaxTrack_YZ_OK", hasNonZeroSecondMaxEnergyY); - if (!energiesY.empty()) { + if (hasNonZeroSecondMaxEnergyY) { int energiesY1FirstKey = energiesY[1].first; SetObservableValue("SecondMaxTrack_YZ_NHitsY", YZ_NHitsY[energiesY1FirstKey]); @@ -575,7 +582,7 @@ TRestEvent* TRestTrack2DAnalysisProcess::ProcessEvent(TRestEvent* inputEvent) { SetObservableValue("SecondMaxTrack_XZ_YZ_GaussSigmaXYBalance", XZ_YZ_GaussSigmaXYBalance[1]); SetObservableValue("SecondMaxTrack_XZ_YZ_GaussSigmaZBalance", XZ_YZ_GaussSigmaZBalance[1]); - SetObservableValue("SecondMaxTrack_XZ_YZ_OK", energiesY.size() > 1 && energiesX.size() > 1); + SetObservableValue("SecondMaxTrack_XZ_YZ_OK", hasNonZeroSecondMaxEnergyX && hasNonZeroSecondMaxEnergyY); if (energiesY.size() > 1 && energiesX.size() > 1) { Double_t energiesX1SecondKey = energiesX[1].second;