Skip to content

Commit 1402ff7

Browse files
committed
y-axis of scope program now remains fixed
The y-axis of the "scope" program is now set to a fixed value based on the largest encountered trace amplitude.
1 parent 7d748f9 commit 1402ff7

2 files changed

Lines changed: 76 additions & 20 deletions

File tree

Poll/include/scope.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ class ChannelEvent;
1010
class TApplication;
1111
class TCanvas;
1212
class TGraph;
13+
class TH2F;
1314

1415
class Oscilloscope : public Unpacker{
1516
private:
1617
int mod; /// The module of the signal of interest.
1718
int chan; /// The channel of the signal of interest.
1819

20+
float old_maximum; /// The maximum value of the largest trace.
21+
22+
bool need_graph_update; /// Set to true if the graph range needs updated.
23+
1924
int delay; /// The number of seconds to wait between drawing traces.
2025

2126
time_t last_trace; /// The time of the last trace.
@@ -32,6 +37,12 @@ class Oscilloscope : public Unpacker{
3237

3338
TGraph *graph; /// The TGraph for plotting traces.
3439

40+
TH2F *his; /// Dummy histogram for updating the plotting ranges.
41+
42+
void UpdateGraph(int size_);
43+
44+
void UpdateFrame(ChannelEvent *event_);
45+
3546
/// Plot the current event.
3647
void Plot(ChannelEvent *event_);
3748

Poll/source/scope.cpp

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,48 @@
1313
#include "TCanvas.h"
1414
#include "TGraph.h"
1515
#include "TAxis.h"
16+
#include "TH2F.h"
1617

1718
#define ADC_TIME_STEP 4 // ns
1819

20+
void Oscilloscope::UpdateGraph(int size_){
21+
if(size_ != graph->GetN()){
22+
std::cout << message_head << "Changing trace length from " << graph->GetN()*ADC_TIME_STEP << " to " << size_*ADC_TIME_STEP << " ns.\n";
23+
24+
x_vals.clear();
25+
x_vals.assign(size_, 0);
26+
for(size_t index = 0; index < x_vals.size(); index++){
27+
x_vals[index] = ADC_TIME_STEP * index;
28+
}
29+
30+
// Update the root TGraph
31+
delete graph;
32+
graph = new TGraph(size_);
33+
}
34+
35+
std::stringstream stream;
36+
stream << "mod = " << mod << ", chan = " << chan;
37+
his->SetTitle(stream.str().c_str());
38+
39+
need_graph_update = false;
40+
}
41+
42+
void Oscilloscope::UpdateFrame(ChannelEvent *event_){
43+
his->SetBins(1, 0, graph->GetN()*ADC_TIME_STEP, 1, 0.9*event_->baseline, 1.1*(event_->baseline+event_->maximum));
44+
his->Draw();
45+
old_maximum = event_->maximum;
46+
}
47+
1948
void Oscilloscope::Plot(ChannelEvent *event_){
2049
time_t cur_time;
2150
time(&cur_time);
2251

2352
// Draw the trace
2453
if((int)difftime(cur_time, last_trace) >= delay){
25-
if(event_->trace.size() != x_vals.size()){ // The length of the trace has changed.
26-
std::cout << message_head << "Changing trace length from " << x_vals.size() << " to " << event_->trace.size() << std::endl;
27-
x_vals.clear();
28-
x_vals.assign(event_->trace.size(), 0);
29-
for(size_t index = 0; index < x_vals.size(); index++){
30-
x_vals[index] = ADC_TIME_STEP * index;
31-
}
32-
33-
// Update the root TGraph
34-
delete graph;
35-
graph = new TGraph(event_->trace.size());
36-
37-
std::stringstream stream;
38-
stream << "mod = " << mod << ", chan = " << chan;
39-
graph->SetTitle(stream.str().c_str());
40-
graph->GetXaxis()->SetTitle("Time (ns)");
41-
graph->GetYaxis()->SetTitle("ADC Channel (a.u.)");
54+
event_->CorrectBaseline();
55+
56+
if(need_graph_update || event_->trace.size() != x_vals.size()){ // The length of the trace has changed.
57+
UpdateGraph(event_->trace.size());
4258
}
4359

4460
int index = 0;
@@ -47,7 +63,11 @@ void Oscilloscope::Plot(ChannelEvent *event_){
4763
graph->SetPoint(index++, *iterx, *itery);
4864
}
4965

50-
graph->Draw("APC");
66+
if(event_->maximum > old_maximum){
67+
UpdateFrame(event_);
68+
}
69+
70+
graph->Draw("PCSAME");
5171
canvas->Update();
5272

5373
time(&last_trace);
@@ -76,11 +96,13 @@ void Oscilloscope::ProcessRawEvent(){
7696
Oscilloscope::Oscilloscope(){
7797
mod = 0;
7898
chan = 0;
79-
delay = 1;
99+
delay = 2;
80100
num_traces = 0;
81101
num_displayed = 0;
82102
time(&last_trace);
83103

104+
old_maximum = -9999;
105+
84106
// Variables for root graphics
85107
rootapp = new TApplication("scope", 0, NULL);
86108
gSystem->Load("libTree");
@@ -89,15 +111,26 @@ Oscilloscope::Oscilloscope(){
89111
canvas->cd();
90112

91113
graph = new TGraph();
114+
115+
// Setup the default histogram frame.
116+
his = new TH2F("his", "", 1, 0, 1, 1, 0, 1);
117+
his->SetStats(false);
118+
his->GetYaxis()->SetTitleOffset(1.4);
119+
his->GetXaxis()->SetTitle("Time (ns)");
120+
his->GetYaxis()->SetTitle("ADC Channel (a.u.)");
121+
122+
need_graph_update = false;
92123
}
93124

94125
Oscilloscope::Oscilloscope(int mod_, int chan_){
95126
mod = mod_;
96127
chan = chan_;
97-
delay = 1;
128+
delay = 2;
98129
num_traces = 0;
99130
num_displayed = 0;
100131
time(&last_trace);
132+
133+
old_maximum = -9999;
101134

102135
// Variables for root graphics
103136
rootapp = new TApplication("scope", 0, NULL);
@@ -107,12 +140,22 @@ Oscilloscope::Oscilloscope(int mod_, int chan_){
107140
canvas->cd();
108141

109142
graph = new TGraph();
143+
144+
// Setup the default histogram frame.
145+
his = new TH2F("his", "", 1, 0, 1, 1, 0, 1);
146+
his->SetStats(false);
147+
his->GetYaxis()->SetTitleOffset(1.4);
148+
his->GetXaxis()->SetTitle("Time (ns)");
149+
his->GetYaxis()->SetTitle("ADC Channel (a.u.)");
150+
151+
need_graph_update = false;
110152
}
111153

112154
Oscilloscope::~Oscilloscope(){
113155
canvas->Close();
114156
delete canvas;
115157
delete graph;
158+
delete his;
116159
}
117160

118161
bool Oscilloscope::Initialize(std::string prefix_){
@@ -170,6 +213,8 @@ bool Oscilloscope::CommandControl(std::string cmd_, const std::vector<std::strin
170213
if(args_.size() >= 2){
171214
mod = atoi(args_.at(0).c_str());
172215
chan = atoi(args_.at(1).c_str());
216+
need_graph_update = true;
217+
old_maximum = -9999;
173218
}
174219
else{
175220
std::cout << message_head << "Invalid number of parameters to 'set'\n";

0 commit comments

Comments
 (0)