REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestEventSelectionProcess.cxx
1 /*************************************************************************
2  * This file is part of the REST software framework. *
3  * *
4  * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5  * For more information see http://gifna.unizar.es/trex *
6  * *
7  * REST is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * REST is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have a copy of the GNU General Public License along with *
18  * REST in $REST_PATH/LICENSE. *
19  * If not, see http://www.gnu.org/licenses/. *
20  * For the list of contributors see $REST_PATH/CREDITS. *
21  *************************************************************************/
22 
84 
85 #include "TRestEventSelectionProcess.h"
86 
87 using namespace std;
88 
90 
95 
104  SetSectionName(this->ClassName());
105 
106  fEvent = nullptr;
107 }
108 
114  if (TRestTools::GetFileNameExtension(fFileWithIDs) == "txt") {
115  string line;
116  ifstream File(fFileWithIDs);
117 
118  if (File.is_open()) {
119  while (getline(File, line)) {
120  fList.push_back(stoi(line));
121  }
122  File.close();
123  }
124  } else if (TRestTools::GetFileNameExtension(fFileWithIDs) == "root") {
125  TRestRun run(fFileWithIDs);
126  fList = run.GetEventIdsWithConditions(fConditions);
127  } else {
128  RESTDebug << "TRestEventSelectionProcess: using the processing file itself." << RESTendl;
129  }
130 }
131 
136  fEvent = inputEvent;
137 
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()) {
146  return fEvent;
147  }
148  }
149 
150  return nullptr;
151 }
152 
157  BeginPrintProcess();
158 
159  RESTMetadata << "File with IDs: " << fFileWithIDs << RESTendl;
160  RESTMetadata << "Conditions: " << fConditions << RESTendl;
161 
162  EndPrintProcess();
163 }
A template process to serve as an example to create new TRestRawSignalEventProcess.
void PrintMetadata() override
Prints on screen the process data members.
TRestEventSelectionProcess()
Default constructor.
void Initialize() override
A list with the event ids that have been selected.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
void InitProcess() override
Process initialization.
A base class for any REST event.
Definition: TRestEvent.h:38
Data provider and manager in REST.
Definition: TRestRun.h:18
static std::string GetFileNameExtension(const std::string &fullname)
Gets the file extension as the substring found after the latest ".".
Definition: TRestTools.cxx:823