diff --git a/source/framework/analysis/inc/TRestEventSelectionProcess.h b/source/framework/analysis/inc/TRestEventSelectionProcess.h index 1f762885ac961903002bc291111c8cf1927975b2..ddff7927fe9d46a3d8dc565106e285335ee1656d 100644 --- a/source/framework/analysis/inc/TRestEventSelectionProcess.h +++ b/source/framework/analysis/inc/TRestEventSelectionProcess.h @@ -24,17 +24,16 @@ #define RestProcess_TRestEventSelectionProcess #include <TH1D.h> +#include <TRestEventProcess.h> #include <iostream> -#include "TRestEventProcess.h" - //! A template process to serve as an example to create new TRestRawSignalEventProcess class TRestEventSelectionProcess : public TRestEventProcess { private: TRestEvent* fEvent; //! - std::string fFileWithIDs = ""; - std::string fConditions = ""; + std::string fFileWithIDs; + std::string fConditions; std::vector<Int_t> fList; /// A list with the event ids that have been selected. diff --git a/source/framework/analysis/src/TRestEventSelectionProcess.cxx b/source/framework/analysis/src/TRestEventSelectionProcess.cxx index 6b168819c7bee0fc2dd4d6ab9486c26a0062d852..01b3c7daab1b64a9332bbb3f29a6d2b98363819b 100644 --- a/source/framework/analysis/src/TRestEventSelectionProcess.cxx +++ b/source/framework/analysis/src/TRestEventSelectionProcess.cxx @@ -23,7 +23,7 @@ ////////////////////////////////////////////////////////////////////////// /// The TRestEventSelectionProcess allows procesing of selected events only. /// -/// There are two ways of selecting events: +/// There are three ways of selecting events: /// /// * Providing a txt file with the IDs of the events to be processed (fileWithIDs). /// It reads the list, if an event is not in the list it returns NULL, @@ -32,6 +32,11 @@ /// * Providing a root file (fileWithIDs) and the conditions to select the events (conditions). /// Only events that satisfy the conditions will be processed. /// +/// * Not providing any fileWithIDs (empty string). In this case, the process will use the TRestAnalysisTree +/// of the processing file itself to evaluate the conditions and select the events. Make sure that the +/// analysis processes that generate the obervables needed for the conditions are executed before this +/// process. See TRestAnalysisTree::EvaluateCuts for more information on conditions format. +/// /// Examples for rml files: /// <addProcess type="TRestEventSelectionProcess" name="evSelection" fileWithIDs="/path/to/file/IDs.txt" /// value="ON" verboseLevel="info"/> @@ -41,7 +46,7 @@ /// /// <hr> /// -/// \warning **? REST is under continous development.** This documentation +/// \warning ** REST is under continous development.** This documentation /// is offered to you by the REST community. Your HELP is needed to keep this code /// up to date. Your feedback will be worth to support this software, please report /// any problems/suggestions you may find while using it at [The REST Framework @@ -66,9 +71,13 @@ /// 2021-Mar: Read IDs from root with conditions /// David Diez /// +/// 2024-Jun: Use of the processing file itself (no need for external fileWithIDs) +/// Alvaro Ezquerro +/// /// \class TRestEventSelectionProcess /// \author Javier Galan /// \author David Diez +/// \author Alvaro Ezquerro /// /// <hr> /// @@ -76,6 +85,7 @@ #include "TRestEventSelectionProcess.h" using namespace std; + ClassImp(TRestEventSelectionProcess); /////////////////////////////////////////////// @@ -112,9 +122,10 @@ void TRestEventSelectionProcess::InitProcess() { File.close(); } } else if (TRestTools::GetFileNameExtension(fFileWithIDs) == "root") { - TRestRun* run = new TRestRun(fFileWithIDs); - fList = run->GetEventIdsWithConditions(fConditions); - delete run; + TRestRun run(fFileWithIDs); + fList = run.GetEventIdsWithConditions(fConditions); + } else { + RESTDebug << "TRestEventSelectionProcess: using the processing file itself." << RESTendl; } } @@ -124,8 +135,14 @@ void TRestEventSelectionProcess::InitProcess() { TRestEvent* TRestEventSelectionProcess::ProcessEvent(TRestEvent* inputEvent) { fEvent = inputEvent; - for (unsigned int i = 0; i < fList.size(); i++) { - if (fList[i] == fEvent->GetID()) { + if (fFileWithIDs.empty()) { + if (this->GetAnalysisTree()->EvaluateCuts(fConditions)) { + return fEvent; + } + } + + for (auto id : fList) { + if (id == fEvent->GetID()) { return fEvent; } } @@ -140,9 +157,7 @@ void TRestEventSelectionProcess::PrintMetadata() { BeginPrintProcess(); RESTMetadata << "File with IDs: " << fFileWithIDs << RESTendl; - if (fFileWithIDs.substr(fFileWithIDs.length() - 4) == "root") { - RESTMetadata << "Conditions: " << fConditions << RESTendl; - } + RESTMetadata << "Conditions: " << fConditions << RESTendl; EndPrintProcess(); }