From e745984b456164004f5324a162dfeb740d4da0f8 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Thu, 21 Sep 2023 23:50:25 +0200 Subject: [PATCH] add option to not skip event if zero energy in readout --- inc/TRestDetectorHitsReadoutAnalysisProcess.h | 1 + src/TRestDetectorHitsReadoutAnalysisProcess.cxx | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/inc/TRestDetectorHitsReadoutAnalysisProcess.h b/inc/TRestDetectorHitsReadoutAnalysisProcess.h index 0825d2ef..ece71bcd 100644 --- a/inc/TRestDetectorHitsReadoutAnalysisProcess.h +++ b/inc/TRestDetectorHitsReadoutAnalysisProcess.h @@ -27,6 +27,7 @@ class TRestDetectorHitsReadoutAnalysisProcess : public TRestEventProcess { std::string fChannelType; TVector3 fFiducialPosition; Double_t fFiducialDiameter = 0; + bool fRemoveZeroEnergyEvents = false; TRestDetectorReadout* fReadout = nullptr; //! diff --git a/src/TRestDetectorHitsReadoutAnalysisProcess.cxx b/src/TRestDetectorHitsReadoutAnalysisProcess.cxx index 11ea04af..9ba22c46 100644 --- a/src/TRestDetectorHitsReadoutAnalysisProcess.cxx +++ b/src/TRestDetectorHitsReadoutAnalysisProcess.cxx @@ -15,17 +15,17 @@ TRestEvent* TRestDetectorHitsReadoutAnalysisProcess::ProcessEvent(TRestEvent* in vector hitEnergy; double energyInFiducial = 0; - for (size_t hit_index = 0; hit_index < fInputHitsEvent->GetNumberOfHits(); hit_index++) { - const auto position = fInputHitsEvent->GetPosition(hit_index); - const auto energy = fInputHitsEvent->GetEnergy(hit_index); - const auto time = fInputHitsEvent->GetTime(hit_index); - const auto type = fInputHitsEvent->GetType(hit_index); + for (size_t hitIndex = 0; hitIndex < fInputHitsEvent->GetNumberOfHits(); hitIndex++) { + const auto position = fInputHitsEvent->GetPosition(hitIndex); + const auto energy = fInputHitsEvent->GetEnergy(hitIndex); + const auto time = fInputHitsEvent->GetTime(hitIndex); + const auto type = fInputHitsEvent->GetType(hitIndex); fOutputHitsEvent->AddHit(position, energy, time, type); if (energy <= 0) { // this should never happen cerr << "TRestDetectorHitsReadoutAnalysisProcess::ProcessEvent() : " - << "Negative or zero energy found in hit " << hit_index << endl; + << "Negative or zero energy found in hit " << hitIndex << endl; exit(1); } @@ -52,7 +52,7 @@ TRestEvent* TRestDetectorHitsReadoutAnalysisProcess::ProcessEvent(TRestEvent* in const double readoutEnergy = accumulate(hitEnergy.begin(), hitEnergy.end(), 0.0); - if (readoutEnergy <= 0) { + if (fRemoveZeroEnergyEvents && readoutEnergy <= 0) { return nullptr; } @@ -121,6 +121,7 @@ void TRestDetectorHitsReadoutAnalysisProcess::PrintMetadata() { } void TRestDetectorHitsReadoutAnalysisProcess::InitFromConfigFile() { + fRemoveZeroEnergyEvents = StringToBool(GetParameter("removeZeroEnergyEvents", "false")); fChannelType = GetParameter("channelType", fChannelType); fFiducialPosition = Get3DVectorParameterWithUnits("fiducialPosition", fFiducialPosition); fFiducialDiameter = GetDblParameterWithUnits("fiducialDiameter", fFiducialDiameter);