REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestRawSignalViewerProcess.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
57#include "TRestRawSignalViewerProcess.h"
58
59#include <TLegend.h>
60#include <TPaveText.h>
61
62using namespace std;
63
65
70
84 Initialize();
85
86 if (LoadConfigFromFile(configFilename)) LoadDefaultConfig();
87}
88
93
97void TRestRawSignalViewerProcess::LoadDefaultConfig() { SetTitle("Default config"); }
98
104 SetSectionName(this->ClassName());
105 SetLibraryVersion(LIBRARY_VERSION);
106
107 fSignalEvent = nullptr;
108
109 fDrawRefresh = 0;
110
111 fSingleThreadOnly = true;
112}
113
126void TRestRawSignalViewerProcess::LoadConfig(const string& configFilename, const string& name) {
127 if (LoadConfigFromFile(configFilename, name)) LoadDefaultConfig();
128}
129
135
140 TString obsName;
141
142 // no need for verbose copy now
143 fSignalEvent = (TRestRawSignalEvent*)inputEvent;
144
145 fCanvas->cd();
146 eveCounter++;
147 if (eveCounter >= fDrawRefresh) {
148 eveCounter = 0;
149 sgnCounter = 0;
151 GetAnalysisTree()->PrintObservables();
152 }
153 for (auto object : fDrawingObjects) {
154 delete object;
155 }
156
157 fDrawingObjects.clear();
158
159 TPad* pad2 = DrawSignal(sgnCounter);
160
161 fCanvas->cd();
162 pad2->Draw();
163 fCanvas->Update();
164
165 RESTcout.setborder("");
166 RESTcout.setorientation(TRestStringOutput::REST_Display_Orientation::kLeft);
167 RESTcout << "Press Enter to continue\nPress Esc to stop viewing\nPress n/p to "
168 "switch signals"
169 << RESTendl;
170
171 while (1) {
172 int a = GetChar("");
173 if (a == 10) // enter
174 {
175 break;
176 } else if (a == 27) // esc
177 {
178 fDrawRefresh = 1e99;
179 while (getchar() != '\n')
180 ;
181 break;
182 } else if (a == 110 || a == 78) // n
183 {
184 sgnCounter++;
185 if (sgnCounter >= 0 && sgnCounter < fSignalEvent->GetNumberOfSignals()) {
186 TPad* pad2 = DrawSignal(sgnCounter);
187 fCanvas->cd();
188 pad2->Draw();
189 fCanvas->Update();
190 } else {
191 RESTWarning << "cannot plot signal with id " << sgnCounter << RESTendl;
192 }
193 } else if (a == 112 || a == 80) // p
194 {
195 sgnCounter--;
196 if (sgnCounter >= 0 && sgnCounter < fSignalEvent->GetNumberOfSignals()) {
197 TPad* pad2 = DrawSignal(sgnCounter);
198 fCanvas->cd();
199 pad2->Draw();
200 fCanvas->Update();
201 } else {
202 RESTWarning << "cannot plot signal with id " << sgnCounter << RESTendl;
203 }
204 }
205 while (getchar() != '\n')
206 ;
207 }
208 }
209
210 return fSignalEvent;
211}
212
218 // Function to be executed once at the end of the process
219 // (after all events have been processed)
220
221 // Start by calling the EndProcess function of the abstract class.
222 // Comment this if you don't want it.
223 // TRestEventProcess::EndProcess();
224}
225
230 TPad* pad = new TPad(this->GetName(), this->GetTitle(), 0, 0, 1, 1);
231
232 pad->cd();
233
234 fDrawingObjects.push_back((TObject*)pad);
235
236 TGraph* gr = new TGraph();
237 fDrawingObjects.push_back((TObject*)gr);
238
239 TRestRawSignal* sgnl = fSignalEvent->GetSignal(signal);
240
241 RESTInfo << "Drawing signal. Event ID : " << fSignalEvent->GetID() << " Signal ID : " << sgnl->GetID()
242 << RESTendl;
243
244 for (int n = 0; n < sgnl->GetNumberOfPoints(); n++) gr->SetPoint(n, n, sgnl->GetData(n));
245
246 gr->Draw("AC*");
247
248 TGraph* gr2 = new TGraph();
249 fDrawingObjects.push_back((TObject*)gr2);
250
251 gr2->SetLineWidth(2);
252 gr2->SetLineColor(2);
253
254 for (int n = fBaseLineRange.X(); n < fBaseLineRange.Y(); n++)
255 gr2->SetPoint(n - fBaseLineRange.X(), n, sgnl->GetData(n));
256
257 gr2->Draw("CP");
258
259 vector<Int_t> pOver = sgnl->GetPointsOverThreshold();
260
261 TGraph* gr3[5];
262 Int_t nGraphs = 0;
263 gr3[nGraphs] = new TGraph();
264 fDrawingObjects.push_back((TObject*)gr3[nGraphs]);
265 gr3[nGraphs]->SetLineWidth(2);
266 gr3[nGraphs]->SetLineColor(3);
267 Int_t point = 0;
268 Int_t nPoints = pOver.size();
269 for (int n = 0; n < nPoints; n++) {
270 gr3[nGraphs]->SetPoint(point, pOver[n], sgnl->GetData(pOver[n]));
271 point++;
272 if (n + 1 < nPoints && pOver[n + 1] - pOver[n] > 1) {
273 gr3[nGraphs]->Draw("CP");
274 nGraphs++;
275 if (nGraphs > 4) cout << "Ngraphs : " << nGraphs << endl;
276 point = 0;
277 gr3[nGraphs] = new TGraph();
278 fDrawingObjects.push_back((TObject*)gr3[nGraphs]);
279 gr3[nGraphs]->SetLineWidth(2);
280 gr3[nGraphs]->SetLineColor(3);
281 }
282 }
283
284 if (nPoints > 0) gr3[nGraphs]->Draw("CP");
285
286 return pad;
287}
288
294 fDrawRefresh = StringToDouble(GetParameter("refreshEvery", "0"));
295
296 fBaseLineRange = StringTo2DVector(GetParameter("baseLineRange", "(5,55)"));
297
298 fCanvasSize = StringTo2DVector(GetParameter("canvasSize", "(800,600)"));
299}
TVector2 fCanvasSize
Canvas size.
TRestAnalysisTree * GetAnalysisTree() const
Return the local analysis tree (dummy)
TCanvas * fCanvas
< Canvas for some viewer event
void CreateCanvas()
Create the canvas.
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.
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
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
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.
An event container for time rawdata signals with fixed length.
void LoadConfig(const std::string &configFilename, const std::string &name="")
Function to load the configuration from an external configuration file.
TPad * DrawSignal(Int_t signal)
A helper method to draw signals in a pad.
TRestRawSignalViewerProcess()
Default constructor.
void LoadDefaultConfig()
Function to load the default config in absence of RML input.
void InitProcess() override
Process initialization. It creates the canvas available in TRestEventProcess.
void EndProcess() override
Function to include required actions after all events have been processed.
void Initialize() override
Function to initialize input/output event members and define the section name.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
~TRestRawSignalViewerProcess()
Default destructor.
void InitFromConfigFile() override
Function to read input parameters from the RML TRestRawSignalViewerProcess metadata section.
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.
std::vector< Int_t > GetPointsOverThreshold() const
Returns a std::vector containing the indexes of data points over threshold.
Double_t GetData(Int_t n) const
It returns the data value of point n including baseline correction.
Int_t GetNumberOfPoints() const
Returns the actual number of points, or size of the signal.
@ REST_Debug
+show the defined debug messages
Int_t GetChar(std::string hint="Press a KEY to continue ...")
Helps to pause the program, printing a message before pausing.
Double_t StringToDouble(std::string in)
Gets a double from a string.
TVector2 StringTo2DVector(std::string in)
Gets a 2D-vector from a string.