Skip to content

Commit 2ffc29d

Browse files
AlvaroEzqlobis
andauthored
TRestEventSelectionProcess upgrade (#528)
* Adding event selection using condition on the fly (no fileWithIDs needed) * code review * Fixing small mistake --------- Co-authored-by: Luis Antonio Obis Aparicio <[email protected]>
1 parent a03d1a0 commit 2ffc29d

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

source/framework/analysis/inc/TRestEventSelectionProcess.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@
2424
#define RestProcess_TRestEventSelectionProcess
2525

2626
#include <TH1D.h>
27+
#include <TRestEventProcess.h>
2728

2829
#include <iostream>
2930

30-
#include "TRestEventProcess.h"
31-
3231
//! A template process to serve as an example to create new TRestRawSignalEventProcess
3332
class TRestEventSelectionProcess : public TRestEventProcess {
3433
private:
3534
TRestEvent* fEvent; //!
36-
std::string fFileWithIDs = "";
37-
std::string fConditions = "";
35+
std::string fFileWithIDs;
36+
std::string fConditions;
3837
std::vector<Int_t> fList;
3938

4039
/// A list with the event ids that have been selected.

source/framework/analysis/src/TRestEventSelectionProcess.cxx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
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,
@@ -32,6 +32,11 @@
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"/>
@@ -41,7 +46,7 @@
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
@@ -66,16 +71,21 @@
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

7887
using namespace std;
88+
7989
ClassImp(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() {
124135
TRestEvent* 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

Comments
 (0)