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"
85 using namespace std;
86 
87 ClassImp(TRestSummaryProcess);
88 
93 
108 TRestSummaryProcess::TRestSummaryProcess(const char* configFilename) {
109  Initialize();
110 
111  LoadConfig(configFilename);
112 }
113 
118 
123  SetName(this->ClassName());
124  SetTitle("Default config");
125 }
126 
139 void 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 
156 void TRestSummaryProcess::Initialize() { SetSectionName(this->ClassName()); }
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 
200  if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Info) PrintMetadata();
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 
247  BeginPrintProcess();
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 }
A base class for any REST event.
Definition: TRestEvent.h:38
@ 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.
void LoadConfig(const std::string &configFilename, const std::string &name="")
Function to load the configuration from an external configuration file.
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.
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.
void InitProcess() override
Function to use in initialization of process members before starting to process the event.
~TRestSummaryProcess()
Default destructor.
TVector2 StringTo2DVector(std::string in)
Gets a 2D-vector from a string.