REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestRawBaseLineCorrectionProcess.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 *************************************************************************/
69
70#include "TRestRawBaseLineCorrectionProcess.h"
71
72using namespace std;
73
75
76TRestRawBaseLineCorrectionProcess::TRestRawBaseLineCorrectionProcess() { Initialize(); }
77
78TRestRawBaseLineCorrectionProcess::~TRestRawBaseLineCorrectionProcess() {
79 delete fInputEvent;
80 delete fOutputEvent;
81}
82
84 SetSectionName(this->ClassName());
85 SetLibraryVersion(LIBRARY_VERSION);
86
87 fInputEvent = nullptr;
88 fOutputEvent = new TRestRawSignalEvent();
89}
90
92 fInputEvent = dynamic_cast<TRestRawSignalEvent*>(inputEvent);
93
94 const auto run = GetRunInfo();
95 if (run != nullptr) {
96 fInputEvent->InitializeReferences(run);
97 }
98
99 if (fReadoutMetadata == nullptr) {
100 fReadoutMetadata = fInputEvent->GetReadoutMetadata();
101 }
102
103 if (fReadoutMetadata == nullptr && !fChannelTypes.empty()) {
104 cerr << "TRestRawBaseLineCorrectionProcess::ProcessEvent: readout metadata is null, cannot filter "
105 "the process by signal type"
106 << endl;
107 exit(1);
108 }
109
110 for (int s = 0; s < fInputEvent->GetNumberOfSignals(); s++) {
111 TRestRawSignal* signal = fInputEvent->GetSignal(s);
112 const UShort_t signalId = signal->GetSignalID();
113
114 const string channelType = fReadoutMetadata->GetTypeForChannelDaqId(signalId);
115 const string channelName = fReadoutMetadata->GetNameForChannelDaqId(signalId);
116
117 // Check if channel type is in the list of selected channel types
118 if (!fChannelTypes.empty() && fChannelTypes.find(channelType) == fChannelTypes.end()) {
119 // If channel type is not in the selected types, add the signal without baseline correction
120 fOutputEvent->AddSignal(*signal);
121 continue;
122 }
123
124 if (fRangeEnabled && (signal->GetID() < fSignalsRange.X() || signal->GetID() > fSignalsRange.Y())) {
125 // If signal is outside the specified range, add the signal without baseline correction
126 fOutputEvent->AddSignal(*signal);
127 continue;
128 }
129
130 TRestRawSignal signalCorrected;
131 signal->GetBaseLineCorrected(&signalCorrected, fSmoothingWindow);
132 signalCorrected.SetID(signal->GetID());
133 fOutputEvent->AddSignal(signalCorrected);
134 }
135
136 return fOutputEvent;
137}
138
140
142 if (fSignalsRange.X() != -1 && fSignalsRange.Y() != -1) {
143 fRangeEnabled = true;
144 }
145
146 const auto filterType = GetParameter("channelType", "");
147 if (!filterType.empty()) {
148 fChannelTypes.insert(filterType);
149 }
150
151 fSignalsRange = Get2DVectorParameterWithUnits("signalsRange", fSignalsRange);
152 fSmoothingWindow = (Int_t)StringToDouble(GetParameter("smoothingWindow", double(fSmoothingWindow)));
153}
154
157
158 if (fChannelTypes.empty()) {
159 RESTMetadata << "No type specified. All signal types will be processed." << RESTendl;
160 } else {
161 RESTMetadata << "Channel type for baseline correction: ";
162 for (const auto& channelType : fChannelTypes) {
163 RESTMetadata << channelType << " ";
164 }
165 RESTMetadata << RESTendl;
166 }
167
168 RESTMetadata << "Smoothing window size: " << fSmoothingWindow << RESTendl;
169 RESTMetadata << "Baseline correction applied to signals with IDs in range (" << fSignalsRange.X() << ","
170 << fSignalsRange.Y() << ")" << RESTendl;
171
172 EndPrintProcess();
173}
174
TRestRun * GetRunInfo() const
Return the pointer of the hosting TRestRun object.
void BeginPrintProcess()
[name, cut range]
A base class for any REST event.
Definition: TRestEvent.h:38
virtual void InitializeReferences(TRestRun *run)
Initialize dynamical references when loading the event from a root file.
Definition: TRestEvent.cxx:175
endl_t RESTendl
Termination flag object for TRestStringOutput.
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
void SetSectionName(std::string sName)
set the section name, clear the section content
std::string GetParameter(std::string parName, TiXmlElement *e, TString defaultValue=PARAMETER_NOT_FOUND_STR)
Returns the value for the parameter named parName in the given section.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
TRestEvent * ProcessEvent(TRestEvent *eventInput) override
Process one event.
void EndProcess() override
To be executed at the end of the run (outside event loop)
void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
TVector2 fSignalsRange
It defines the signals id range where analysis is applied.
void Initialize() override
Making default settings.
Int_t fSmoothingWindow
Time window width in bins for the moving average filter for baseline correction.
Bool_t fRangeEnabled
Just a flag to quickly determine if we have to apply the range filter.
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
An event container for time rawdata signals with fixed length.
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 SetID(Int_t sID)
It sets the id number of the signal.
Int_t GetSignalID() const
Returns the value of signal ID.
void GetBaseLineCorrected(TRestRawSignal *smoothedSignal, Int_t averagingPoints)
It applies the moving average filter (GetSignalSmoothed) to the signal, which is then subtracted from...
Double_t StringToDouble(std::string in)
Gets a double from a string.