REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestSummaryProcess.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#include "TRestSummaryProcess.h"
85using namespace std;
86
87ClassImp(TRestSummaryProcess);
88
93
108TRestSummaryProcess::TRestSummaryProcess(const char* configFilename) {
109 Initialize();
110
111 LoadConfig(configFilename);
112}
113
118
123 SetName(this->ClassName());
124 SetTitle("Default config");
125}
126
139void TRestSummaryProcess::LoadConfig(const string& configFilename, const string& name) {
140 if (LoadConfigFromFile(configFilename, name)) LoadDefaultConfig();
141}
142
148 // For example, try to initialize a pointer to existing metadata
149 // accessible from TRestRun
150}
151
157
162 fEvent = inputEvent;
163
164 // This process does nothing at the event-by-event level
165
166 return fEvent;
167}
168
173 Int_t nEntries = GetFullAnalysisTree()->GetEntries();
174 Double_t startTime = fRunInfo->GetStartTimestamp();
175 Double_t endTime = fRunInfo->GetEndTimestamp();
176
177 fMeanRate = nEntries / (endTime - startTime);
178 fMeanRateSigma = TMath::Sqrt(nEntries) / (endTime - startTime);
179
180 for (auto const& x : fAverage) {
181 TVector2 range = fAverageRange[x.first];
182 fAverage[x.first] = this->GetFullAnalysisTree()->GetObservableAverage(x.first, range.X(), range.Y());
183 }
184
185 for (auto const& x : fRMS) {
186 TVector2 range = fRMSRange[x.first];
187 fRMS[x.first] = this->GetFullAnalysisTree()->GetObservableRMS(x.first, range.X(), range.Y());
188 }
189
190 for (auto const& x : fMaximum) {
191 TVector2 range = fMaximumRange[x.first];
192 fMaximum[x.first] = this->GetFullAnalysisTree()->GetObservableMaximum(x.first, range.X(), range.Y());
193 }
194
195 for (auto const& x : fMinimum) {
196 TVector2 range = fMinimumRange[x.first];
197 fMinimum[x.first] = this->GetFullAnalysisTree()->GetObservableMinimum(x.first, range.X(), range.Y());
198 }
199
201}
202
208 string definition;
209 size_t pos = 0;
210 while ((definition = GetKEYDefinition("average", pos)) != "") {
211 TString obsName = GetFieldValue("obsName", definition);
212
213 fAverage[obsName] = 0;
214 fAverageRange[obsName] = StringTo2DVector(GetFieldValue("range", definition));
215 }
216
217 pos = 0;
218 while ((definition = GetKEYDefinition("rms", pos)) != "") {
219 TString obsName = GetFieldValue("obsName", definition);
220
221 fRMS[obsName] = 0;
222 fRMSRange[obsName] = StringTo2DVector(GetFieldValue("range", definition));
223 }
224
225 pos = 0;
226 while ((definition = GetKEYDefinition("maximum", pos)) != "") {
227 TString obsName = GetFieldValue("obsName", definition);
228
229 fMaximum[obsName] = 0;
230 fMaximumRange[obsName] = StringTo2DVector(GetFieldValue("range", definition));
231 }
232
233 pos = 0;
234 while ((definition = GetKEYDefinition("minimum", pos)) != "") {
235 TString obsName = GetFieldValue("obsName", definition);
236
237 fMinimum[obsName] = 0;
238 fMinimumRange[obsName] = StringTo2DVector(GetFieldValue("range", definition));
239 }
240}
241
248
249 RESTMetadata << " - Mean rate : " << fMeanRate << " Hz" << RESTendl;
250 RESTMetadata << " - Mean rate sigma : " << fMeanRateSigma << " Hz" << RESTendl;
251 for (auto const& x : fAverage) {
252 RESTMetadata << " " << RESTendl;
253 RESTMetadata << x.first << " average:" << x.second << RESTendl;
254 TVector2 a = fAverageRange[x.first];
255 if (a.X() != -1 && a.Y() != -1)
256 RESTMetadata << " range : (" << a.X() << ", " << a.Y() << ")" << RESTendl;
257 }
258 for (auto const& x : fRMS) {
259 RESTMetadata << " " << RESTendl;
260 RESTMetadata << x.first << " RMS:" << x.second << RESTendl;
261 TVector2 a = fRMSRange[x.first];
262 if (a.X() != -1 && a.Y() != -1)
263 RESTMetadata << " range : (" << a.X() << ", " << a.Y() << ")" << RESTendl;
264 }
265 for (auto const& x : fMaximum) {
266 RESTMetadata << " " << RESTendl;
267 RESTMetadata << x.first << " Maximum:" << x.second << RESTendl;
268 TVector2 a = fMaximumRange[x.first];
269 if (a.X() != -1 && a.Y() != -1)
270 RESTMetadata << " range : (" << a.X() << ", " << a.Y() << ")" << RESTendl;
271 }
272 for (auto const& x : fMinimum) {
273 RESTMetadata << " " << RESTendl;
274 RESTMetadata << x.first << " Minimum:" << x.second << RESTendl;
275 TVector2 a = fMinimumRange[x.first];
276 if (a.X() != -1 && a.Y() != -1)
277 RESTMetadata << " range : (" << a.X() << ", " << a.Y() << ")" << RESTendl;
278 }
279 EndPrintProcess();
280}
Double_t GetObservableMaximum(const TString &obsName, Double_t xLow=-1, Double_t xHigh=-1)
It returns the maximum value of obsName considering the given range. If no range is given the full hi...
Double_t GetObservableAverage(const TString &obsName, Double_t xLow=-1, Double_t xHigh=-1)
It returns the average of the observable considering the given range. If no range is given the full h...
Double_t GetObservableRMS(const TString &obsName, Double_t xLow=-1, Double_t xHigh=-1)
It returns the RMS of the observable considering the given range. If no range is given the full histo...
Double_t GetObservableMinimum(const TString &obsName, Double_t xLow=-1, Double_t xHigh=-1)
It returns the minimum value of obsName considering the given range. If no range is given the full hi...
void BeginPrintProcess()
[name, cut range]
TRestRun * fRunInfo
< Pointer to TRestRun object where to find metadata.
A base class for any REST event.
Definition: TRestEvent.h:38
endl_t RESTendl
Termination flag object for TRestStringOutput.
Int_t LoadConfigFromFile(const std::string &configFilename, const std::string &sectionName="")
Give the file name, find out the corresponding section. Then call the main starter.
TRestStringOutput::REST_Verbose_Level GetVerboseLevel()
returns the verboselevel in type of REST_Verbose_Level enumerator
std::string GetFieldValue(std::string parName, TiXmlElement *e)
Returns the field value of an xml element which has the specified name.
void SetSectionName(std::string sName)
set the section name, clear the section content
std::string GetKEYDefinition(std::string keyName)
Gets the first key definition for keyName found inside buffer starting at fromPosition.
@ REST_Info
+show most of the information for each steps
A process to define basic data members to serve as a metadata summary in a data processing chain.
void EndProcess() override
Function to use when all events have been processed.
std::map< TString, TVector2 > fMinimumRange
If defined it will set the range where minimum is calculated.
std::map< TString, TVector2 > fMaximumRange
If defined it will set the range where maximum is calculated.
void LoadConfig(const std::string &configFilename, const std::string &name="")
Function to load the configuration from an external configuration file.
Double_t fMeanRate
The mean rate during the run, calculated as the final number of entries in the run.
void InitFromConfigFile() override
Function reading input parameters from the RML TRestSummaryProcess section.
void Initialize() override
Function to initialize input/output event members and define the section name and library version.
TRestEvent * fEvent
The event pointer is not used in this process.
Double_t fMeanRateSigma
The mean rate sigma calculated as the square root of the corresponding mean rate counts.
std::map< TString, TVector2 > fRMSRange
If defined it will set the range where RMS is calculated.
std::map< TString, TVector2 > fAverageRange
If defined it will set the range where average is calculated.
void PrintMetadata() override
It prints out the process parameters stored in the metadata structure.
void LoadDefaultConfig()
Function to load the default config in absence of RML input.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
TRestSummaryProcess()
Default constructor.
std::map< TString, Double_t > fMaximum
It will register the maximum value of an existing analyisTree observable.
void InitProcess() override
Function to use in initialization of process members before starting to process the event.
std::map< TString, Double_t > fAverage
It will register the average of an existing analyisTree observable.
~TRestSummaryProcess()
Default destructor.
std::map< TString, Double_t > fRMS
It will register the RMS of an existing analysisTree observable.
std::map< TString, Double_t > fMinimum
It will register the minimum value of an existing analyisTree observable.
TVector2 StringTo2DVector(std::string in)
Gets a 2D-vector from a string.