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