2323// ////////////////////////////////////////////////////////////////////////
2424// / The TRestEventSelectionProcess allows procesing of selected events only.
2525// /
26- // / There are two ways of selecting events:
26+ // / There are three ways of selecting events:
2727// /
2828// / * Providing a txt file with the IDs of the events to be processed (fileWithIDs).
2929// / It reads the list, if an event is not in the list it returns NULL,
3232// / * Providing a root file (fileWithIDs) and the conditions to select the events (conditions).
3333// / Only events that satisfy the conditions will be processed.
3434// /
35+ // / * Not providing any fileWithIDs (empty string). In this case, the process will use the TRestAnalysisTree
36+ // / of the processing file itself to evaluate the conditions and select the events. Make sure that the
37+ // / analysis processes that generate the obervables needed for the conditions are executed before this
38+ // / process. See TRestAnalysisTree::EvaluateCuts for more information on conditions format.
39+ // /
3540// / Examples for rml files:
3641// / <addProcess type="TRestEventSelectionProcess" name="evSelection" fileWithIDs="/path/to/file/IDs.txt"
3742// / value="ON" verboseLevel="info"/>
4146// /
4247// / <hr>
4348// /
44- // / \warning **? REST is under continous development.** This documentation
49+ // / \warning ** REST is under continous development.** This documentation
4550// / is offered to you by the REST community. Your HELP is needed to keep this code
4651// / up to date. Your feedback will be worth to support this software, please report
4752// / any problems/suggestions you may find while using it at [The REST Framework
6671// / 2021-Mar: Read IDs from root with conditions
6772// / David Diez
6873// /
74+ // / 2024-Jun: Use of the processing file itself (no need for external fileWithIDs)
75+ // / Alvaro Ezquerro
76+ // /
6977// / \class TRestEventSelectionProcess
7078// / \author Javier Galan
7179// / \author David Diez
80+ // / \author Alvaro Ezquerro
7281// /
7382// / <hr>
7483// /
7584
7685#include " TRestEventSelectionProcess.h"
7786
7887using namespace std ;
88+
7989ClassImp (TRestEventSelectionProcess);
8090
8191// /////////////////////////////////////////////
@@ -112,9 +122,10 @@ void TRestEventSelectionProcess::InitProcess() {
112122 File.close ();
113123 }
114124 } else if (TRestTools::GetFileNameExtension (fFileWithIDs ) == " root" ) {
115- TRestRun* run = new TRestRun (fFileWithIDs );
116- fList = run->GetEventIdsWithConditions (fConditions );
117- delete run;
125+ TRestRun run (fFileWithIDs );
126+ fList = run.GetEventIdsWithConditions (fConditions );
127+ } else {
128+ RESTDebug << " TRestEventSelectionProcess: using the processing file itself." << RESTendl;
118129 }
119130}
120131
@@ -124,8 +135,14 @@ void TRestEventSelectionProcess::InitProcess() {
124135TRestEvent* TRestEventSelectionProcess::ProcessEvent (TRestEvent* inputEvent) {
125136 fEvent = inputEvent;
126137
127- for (unsigned int i = 0 ; i < fList .size (); i++) {
128- if (fList [i] == fEvent ->GetID ()) {
138+ if (fFileWithIDs .empty ()) {
139+ if (this ->GetAnalysisTree ()->EvaluateCuts (fConditions )) {
140+ return fEvent ;
141+ }
142+ }
143+
144+ for (auto id : fList ) {
145+ if (id == fEvent ->GetID ()) {
129146 return fEvent ;
130147 }
131148 }
@@ -140,9 +157,7 @@ void TRestEventSelectionProcess::PrintMetadata() {
140157 BeginPrintProcess ();
141158
142159 RESTMetadata << " File with IDs: " << fFileWithIDs << RESTendl;
143- if (fFileWithIDs .substr (fFileWithIDs .length () - 4 ) == " root" ) {
144- RESTMetadata << " Conditions: " << fConditions << RESTendl;
145- }
160+ RESTMetadata << " Conditions: " << fConditions << RESTendl;
146161
147162 EndPrintProcess ();
148163}
0 commit comments