Skip to content

Commit

Permalink
TRestEventSelectionProcess upgrade (#528)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
AlvaroEzq and lobis authored Jun 25, 2024
1 parent a03d1a0 commit 2ffc29d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
7 changes: 3 additions & 4 deletions source/framework/analysis/inc/TRestEventSelectionProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 25 additions & 10 deletions source/framework/analysis/src/TRestEventSelectionProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"/>
Expand All @@ -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
Expand All @@ -66,16 +71,21 @@
/// 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>
///

#include "TRestEventSelectionProcess.h"

using namespace std;

ClassImp(TRestEventSelectionProcess);

///////////////////////////////////////////////
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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;
}
}
Expand All @@ -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();
}

0 comments on commit 2ffc29d

Please sign in to comment.