REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestRawSignalIdTaggingProcess.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 *************************************************************************/
68
99//
114
115#include "TRestRawSignalIdTaggingProcess.h"
116
117using namespace std;
118
120
125
130
136 SetSectionName(this->ClassName());
137 SetLibraryVersion(LIBRARY_VERSION);
138
139 fSignalEvent = nullptr;
140}
141
146
151 // This line is to exploit the retrieval of parameter as it is done at any process
153
154 RESTDebug << "fPointThreshold: " << fPointThreshold << RESTendl;
155 RESTDebug << "fSignalThreshold: " << fSignalThreshold << RESTendl;
156 RESTDebug << "fPointsOverThreshold: " << fPointsOverThreshold << RESTendl;
157 RESTDebug << "fBaseLineRange.X(): " << fBaseLineRange.X() << RESTendl;
158 RESTDebug << "fBaseLineRange.Y(): " << fBaseLineRange.Y() << RESTendl;
159
160 if (fPointThreshold != -1 && fSignalThreshold != -1 && fPointsOverThreshold != -1 &&
161 fBaseLineRange.X() != -1 && fBaseLineRange.Y() != -1) {
162 fGoodSignalsOnly = true;
163 }
164
165 // This is the additional code required by the process to read tags
166 TiXmlElement* tagDefinition = GetElement("tag");
167 while (tagDefinition) {
168 fTagNames.push_back(GetFieldValue("name", tagDefinition));
169 fIdRanges.push_back(Get2DVectorParameterWithUnits("ids", tagDefinition));
170
171 tagDefinition = GetNextElement(tagDefinition);
172 }
173}
174
180
181 std::vector<int> tagCode;
182
183 for (int j = 0; j < fSignalEvent->GetNumberOfSignals(); j++) {
184 TRestRawSignal* singleSignal = fSignalEvent->GetSignal(j);
185
186 if (fGoodSignalsOnly == true) {
187 singleSignal->CalculateBaseLine(fBaseLineRange.X(), fBaseLineRange.Y());
190 }
191
192 if (fGoodSignalsOnly == false ||
193 singleSignal->GetPointsOverThreshold().size() >= (unsigned int)fPointsOverThreshold) {
194 for (unsigned int n = 0; n < fIdRanges.size(); n++) {
195 if (singleSignal->GetID() >= fIdRanges[n].X() && singleSignal->GetID() <= fIdRanges[n].Y()) {
196 // If it is not already in the vector, adds it. n+1 to avoid 0.
197 if (std::find(tagCode.begin(), tagCode.end(), n + 1) == tagCode.end()) {
198 tagCode.push_back(n + 1);
199 }
200 }
201 }
202 }
203 }
204 std::sort(tagCode.begin(), tagCode.end());
205
206 int result = 0;
207 for (auto d : tagCode) {
208 result = result * 10 + d;
209 }
210 SetObservableValue("tagId", result);
211
212 // If cut condition matches the event will be not registered.
213 if (ApplyCut()) return nullptr;
214
215 return fSignalEvent;
216}
virtual void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
void SetObservableValue(const std::string &name, const T &value)
Set observable value for AnalysisTree.
A base class for any REST event.
Definition: TRestEvent.h:38
endl_t RESTendl
Termination flag object for TRestStringOutput.
TiXmlElement * GetElement(std::string eleDeclare, TiXmlElement *e=nullptr)
Get an xml element from a given parent element, according to its declaration.
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
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
TiXmlElement * GetNextElement(TiXmlElement *e)
Get the next sibling xml element of this element, with same eleDeclare.
An event container for time rawdata signals with fixed length.
An analysis process helping to assign tags to user defined ranges of signal ids.
std::vector< TVector2 > fIdRanges
A list containing the id range for each tag.
Double_t fSignalThreshold
A parameter to define a minimum signal fluctuation. Measured in sigmas.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
TRestRawSignalEvent * fSignalEvent
A pointer to the specific TRestRawSignalEvent input.
void InitFromConfigFile() override
Process initialization.
void InitProcess() override
Process initialization.
void Initialize() override
Function to initialize input/output event members and define the section name.
Double_t fPointThreshold
The number of sigmas over baseline fluctuations to identify a point overthreshold.
TVector2 fBaseLineRange
The range where the baseline range will be calculated.
Int_t fPointsOverThreshold
The minimum number of points over threshold to identify a signal as such.
std::vector< std::string > fTagNames
A list containing the tag names for each signal ids range.
It defines a Short_t array with a physical parameter that evolves in time using a fixed time bin.
Int_t GetID() const
Returns the value of signal ID.
void CalculateBaseLine(Int_t startBin, Int_t endBin, const std::string &option="")
This method calculates the average and fluctuation of the baseline in the specified range and writes ...
std::vector< Int_t > GetPointsOverThreshold() const
Returns a std::vector containing the indexes of data points over threshold.
void InitializePointsOverThreshold(const TVector2 &thrPar, Int_t nPointsOver, Int_t nPointsFlat=512)
It initializes the fPointsOverThreshold array with the indexes of data points that are found over thr...