REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorSignalViewerProcess.cxx
1
16
17#include "TRestDetectorSignalViewerProcess.h"
18
19#include <TLegend.h>
20#include <TPaveText.h>
21
22using namespace std;
23
24int rawCounter3 = 0;
25
27
28TRestDetectorSignalViewerProcess::TRestDetectorSignalViewerProcess() { Initialize(); }
29
30TRestDetectorSignalViewerProcess::TRestDetectorSignalViewerProcess(const char* configFilename) {
31 Initialize();
32 if (LoadConfigFromFile(configFilename)) {
33 LoadDefaultConfig();
34 }
35}
36
37TRestDetectorSignalViewerProcess::~TRestDetectorSignalViewerProcess() {}
38
39void TRestDetectorSignalViewerProcess::LoadDefaultConfig() { SetTitle("Default config"); }
40
42 SetSectionName(this->ClassName());
43 SetLibraryVersion(LIBRARY_VERSION);
44
45 fSignalEvent = nullptr;
46
47 fDrawRefresh = 0;
48
49 fSingleThreadOnly = true;
50}
51
52void TRestDetectorSignalViewerProcess::LoadConfig(const string& configFilename, const string& name) {
53 if (LoadConfigFromFile(configFilename, name)) LoadDefaultConfig();
54}
55
57
59 TString obsName;
60
61 TRestDetectorSignalEvent* fInputSignalEvent = (TRestDetectorSignalEvent*)inputEvent;
62
64 fSignalEvent = fInputSignalEvent;
65 // fSignalEvent->SetID( fInputSignalEvent->GetID() );
66 // fSignalEvent->SetSubID( fInputSignalEvent->GetSubID() );
67 // fSignalEvent->SetTimeStamp( fInputSignalEvent->GetTimeStamp() );
68 // fSignalEvent->SetSubEventTag( fInputSignalEvent->GetSubEventTag() );
69
70 // //for( int sgnl = 0; sgnl < fInputSignalEvent->GetNumberOfSignals();
71 // sgnl++ ) Int_t N = fInputSignalEvent->GetNumberOfSignals();
72 // // if( GetVerboseLevel() >= REST_Debug ) N = 1;
73 // for( int sgnl = 0; sgnl < N; sgnl++ )
74 // fSignalEvent->AddSignal( *fInputSignalEvent->GetSignal( sgnl ) );
76
77 GetCanvas()->cd();
78 GetCanvas()->SetGrid();
79 fCanvas->cd();
80 eveCounter++;
81 if (eveCounter >= fDrawRefresh) {
82 eveCounter = 0;
83 sgnCounter = 0;
85 GetAnalysisTree()->PrintObservables();
86 }
87 for (auto object : fDrawingObjects) {
88 delete object;
89 }
90 fDrawingObjects.clear();
91
92 TPad* pad2 = DrawSignal(sgnCounter);
93
94 fCanvas->cd();
95 pad2->Draw();
96 fCanvas->Update();
97
98 RESTcout.setborder("");
99 RESTcout.setorientation(TRestStringOutput::REST_Display_Orientation::kLeft);
100 RESTcout << "Press Enter to continue\nPress Esc to stop viewing\nPress n/p to "
101 "switch signals"
102 << RESTendl;
103
104 while (true) {
105 int a = GetChar("");
106 if (a == 10) // enter
107 {
108 break;
109 } else if (a == 27) // esc
110 {
111 fDrawRefresh = 1e99;
112 while (getchar() != '\n')
113 ;
114 break;
115 } else if (a == 110 || a == 78) // n
116 {
117 sgnCounter++;
118 if (sgnCounter >= 0 && sgnCounter < fInputSignalEvent->GetNumberOfSignals()) {
119 TPad* pad2 = DrawSignal(sgnCounter);
120 fCanvas->cd();
121 pad2->Draw();
122 fCanvas->Update();
123 } else {
124 RESTWarning << "cannot plot signal with id " << sgnCounter << RESTendl;
125 }
126 } else if (a == 112 || a == 80) // p
127 {
128 sgnCounter--;
129 if (sgnCounter >= 0 && sgnCounter < fInputSignalEvent->GetNumberOfSignals()) {
130 TPad* pad2 = DrawSignal(sgnCounter);
131 fCanvas->cd();
132 pad2->Draw();
133 fCanvas->Update();
134 } else {
135 RESTWarning << "cannot plot signal with id " << sgnCounter << RESTendl;
136 }
137 }
138 while (getchar() != '\n')
139 ;
140 }
141 }
142
143 return fSignalEvent;
144}
145
147 // Function to be executed once at the end of the process
148 // (after all events have been processed)
149
150 // Start by calling the EndProcess function of the abstract class.
151 // Comment this if you don't want it.
152 // TRestEventProcess::EndProcess();
153}
154
156 fDrawRefresh = StringToDouble(GetParameter("refreshEvery", "0"));
157
158 fBaseLineRange = StringTo2DVector(GetParameter("baseLineRange", "(5,55)"));
159
160 fCanvasSize = StringTo2DVector(GetParameter("canvasSize", "(800,600)"));
161}
162
163TPad* TRestDetectorSignalViewerProcess::DrawSignal(Int_t signal) {
164 TPad* pad = new TPad(this->GetName(), this->GetTitle(), 0, 0, 1, 1);
165 pad->cd();
166 pad->DrawFrame(fSignalEvent->GetMinTime() - 1, -10, fSignalEvent->GetMaxTime() + 1,
167 fSignalEvent->GetMaxValue() + 10, this->GetTitle());
168
169 TMultiGraph* mg = new TMultiGraph();
170 mg->SetTitle(this->GetTitle());
171 mg->GetXaxis()->SetTitle("time bins");
172 mg->GetYaxis()->SetTitleOffset(1.4);
173 mg->GetYaxis()->SetTitle("Energy");
174
175 for (int n = 0; n < fSignalEvent->GetNumberOfSignals(); n++) {
176 TGraph* gr = fSignalEvent->GetSignal(n)->GetGraph((n + 1) % 6);
177 mg->Add(gr);
178 }
179
180 mg->Draw("");
181
182 return pad;
183}
void Initialize() override
Making default settings.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
void EndProcess() override
To be executed at the end of the run (outside event loop)
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
TVector2 fCanvasSize
Canvas size.
TCanvas * GetCanvas() const
Get canvas.
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.
@ 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.