REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestEventRateAnalysisProcess.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
91#include "TRestEventRateAnalysisProcess.h"
92
93#include "TRestDataBase.h"
94using namespace std;
95
97
102
107
113 SetSectionName(this->ClassName());
114
115 fEvent = NULL;
116
117 fSingleThreadOnly = true;
118
119 fFirstEventTime = -1;
120 fPreviousEventTime.clear();
121}
122
127 if (fRunInfo != NULL && fRunInfo->GetStartTimestamp() != 0) {
128 fFirstEventTime = fRunInfo->GetStartTimestamp();
129 } else {
130 fFirstEventTime = -1;
131 }
132
133 // if is run under single thread mode, we add rate observables
134 fRateAnalysis = GetNumberOfParallelProcesses() <= 1;
135}
136
141 fEvent = inputEvent;
142
143 if (fFirstEventTime == -1) fFirstEventTime = fEvent->GetTime();
144
145 Double_t secondsFromStart = fEvent->GetTime() - fFirstEventTime;
146 SetObservableValue("SecondsFromStart", secondsFromStart);
147 SetObservableValue("HoursFromStart", secondsFromStart / 3600.);
148
149 if (fRateAnalysis) {
150 Double_t evTimeDelay = 0;
151 if (fPreviousEventTime.size() > 0) evTimeDelay = fEvent->GetTime() - fPreviousEventTime.back();
152 SetObservableValue("EventTimeDelay", evTimeDelay);
153
154 Double_t meanRate = 0;
155 if (fPreviousEventTime.size() == 10)
156 meanRate = 10. / (fEvent->GetTime() - fPreviousEventTime.front());
157 SetObservableValue("MeanRate_InHz", meanRate);
158
160 for (auto i : fObservablesDefined) {
161 fAnalysisTree->PrintObservable(i.second);
162 }
163 }
164
165 fPreviousEventTime.push_back(fEvent->GetTimeStamp());
166 if (fPreviousEventTime.size() > 10) fPreviousEventTime.erase(fPreviousEventTime.begin());
167 }
168 // If cut condition matches the event will be not registered.
169 if (ApplyCut()) return NULL;
170
171 return fEvent;
172}
TRestAnalysisTree * fAnalysisTree
TRestRun * fRunInfo
< Pointer to TRestRun object where to find metadata.
std::map< std::string, int > fObservablesDefined
Stores the list of all the appeared process observables in the code.
void SetObservableValue(const std::string &name, const T &value)
Set observable value for AnalysisTree.
A pure analysis process used to calculate event rates and other time observables.
TRestEvent * fEvent
A pointer to the input event.
void InitProcess() override
Process initialization.
void Initialize() override
Function to initialize input/output event members and define the section name.
std::vector< Double_t > fPreviousEventTime
It keeps a historic list of timestamps of the previous N events. Now fixed to N=10 events.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
Double_t fFirstEventTime
It registers the timestamp from the first event to calculate time from start observables.
bool fRateAnalysis
It indicates whether to add rate observables which is correct only under single thread run.
A base class for any REST event.
Definition: TRestEvent.h:38
TRestStringOutput::REST_Verbose_Level GetVerboseLevel()
returns the verboselevel in type of REST_Verbose_Level enumerator
void SetSectionName(std::string sName)
set the section name, clear the section content
@ REST_Debug
+show the defined debug messages