Skip to content
Snippets Groups Projects
Unverified Commit 2ffc29d4 authored by Álvaro's avatar Álvaro Committed by GitHub
Browse files

TRestEventSelectionProcess upgrade (#528)


* Adding event selection using condition on the fly (no fileWithIDs needed)

* code review

* Fixing small mistake

---------

Co-authored-by: default avatarLuis Antonio Obis Aparicio <luis.antonio.obis@gmail.com>
parent a03d1a0c
No related branches found
No related tags found
No related merge requests found
Pipeline #7773835 failed
...@@ -24,17 +24,16 @@ ...@@ -24,17 +24,16 @@
#define RestProcess_TRestEventSelectionProcess #define RestProcess_TRestEventSelectionProcess
#include <TH1D.h> #include <TH1D.h>
#include <TRestEventProcess.h>
#include <iostream> #include <iostream>
#include "TRestEventProcess.h"
//! A template process to serve as an example to create new TRestRawSignalEventProcess //! A template process to serve as an example to create new TRestRawSignalEventProcess
class TRestEventSelectionProcess : public TRestEventProcess { class TRestEventSelectionProcess : public TRestEventProcess {
private: private:
TRestEvent* fEvent; //! TRestEvent* fEvent; //!
std::string fFileWithIDs = ""; std::string fFileWithIDs;
std::string fConditions = ""; std::string fConditions;
std::vector<Int_t> fList; std::vector<Int_t> fList;
/// A list with the event ids that have been selected. /// A list with the event ids that have been selected.
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// The TRestEventSelectionProcess allows procesing of selected events only. /// 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). /// * 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, /// It reads the list, if an event is not in the list it returns NULL,
...@@ -32,6 +32,11 @@ ...@@ -32,6 +32,11 @@
/// * Providing a root file (fileWithIDs) and the conditions to select the events (conditions). /// * Providing a root file (fileWithIDs) and the conditions to select the events (conditions).
/// Only events that satisfy the conditions will be processed. /// 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: /// Examples for rml files:
/// <addProcess type="TRestEventSelectionProcess" name="evSelection" fileWithIDs="/path/to/file/IDs.txt" /// <addProcess type="TRestEventSelectionProcess" name="evSelection" fileWithIDs="/path/to/file/IDs.txt"
/// value="ON" verboseLevel="info"/> /// value="ON" verboseLevel="info"/>
...@@ -41,7 +46,7 @@ ...@@ -41,7 +46,7 @@
/// ///
/// <hr> /// <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 /// 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 /// 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 /// any problems/suggestions you may find while using it at [The REST Framework
...@@ -66,9 +71,13 @@ ...@@ -66,9 +71,13 @@
/// 2021-Mar: Read IDs from root with conditions /// 2021-Mar: Read IDs from root with conditions
/// David Diez /// David Diez
/// ///
/// 2024-Jun: Use of the processing file itself (no need for external fileWithIDs)
/// Alvaro Ezquerro
///
/// \class TRestEventSelectionProcess /// \class TRestEventSelectionProcess
/// \author Javier Galan /// \author Javier Galan
/// \author David Diez /// \author David Diez
/// \author Alvaro Ezquerro
/// ///
/// <hr> /// <hr>
/// ///
...@@ -76,6 +85,7 @@ ...@@ -76,6 +85,7 @@
#include "TRestEventSelectionProcess.h" #include "TRestEventSelectionProcess.h"
using namespace std; using namespace std;
ClassImp(TRestEventSelectionProcess); ClassImp(TRestEventSelectionProcess);
/////////////////////////////////////////////// ///////////////////////////////////////////////
...@@ -112,9 +122,10 @@ void TRestEventSelectionProcess::InitProcess() { ...@@ -112,9 +122,10 @@ void TRestEventSelectionProcess::InitProcess() {
File.close(); File.close();
} }
} else if (TRestTools::GetFileNameExtension(fFileWithIDs) == "root") { } else if (TRestTools::GetFileNameExtension(fFileWithIDs) == "root") {
TRestRun* run = new TRestRun(fFileWithIDs); TRestRun run(fFileWithIDs);
fList = run->GetEventIdsWithConditions(fConditions); fList = run.GetEventIdsWithConditions(fConditions);
delete run; } else {
RESTDebug << "TRestEventSelectionProcess: using the processing file itself." << RESTendl;
} }
} }
...@@ -124,8 +135,14 @@ void TRestEventSelectionProcess::InitProcess() { ...@@ -124,8 +135,14 @@ void TRestEventSelectionProcess::InitProcess() {
TRestEvent* TRestEventSelectionProcess::ProcessEvent(TRestEvent* inputEvent) { TRestEvent* TRestEventSelectionProcess::ProcessEvent(TRestEvent* inputEvent) {
fEvent = inputEvent; fEvent = inputEvent;
for (unsigned int i = 0; i < fList.size(); i++) { if (fFileWithIDs.empty()) {
if (fList[i] == fEvent->GetID()) { if (this->GetAnalysisTree()->EvaluateCuts(fConditions)) {
return fEvent;
}
}
for (auto id : fList) {
if (id == fEvent->GetID()) {
return fEvent; return fEvent;
} }
} }
...@@ -140,9 +157,7 @@ void TRestEventSelectionProcess::PrintMetadata() { ...@@ -140,9 +157,7 @@ void TRestEventSelectionProcess::PrintMetadata() {
BeginPrintProcess(); BeginPrintProcess();
RESTMetadata << "File with IDs: " << fFileWithIDs << RESTendl; RESTMetadata << "File with IDs: " << fFileWithIDs << RESTendl;
if (fFileWithIDs.substr(fFileWithIDs.length() - 4) == "root") { RESTMetadata << "Conditions: " << fConditions << RESTendl;
RESTMetadata << "Conditions: " << fConditions << RESTendl;
}
EndPrintProcess(); EndPrintProcess();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment