4 #include "ScanMain.hpp" 5 #include "PixieEvent.hpp" 11 #include "TApplication.h" 18 #define ADC_CLOCK_uSEC 4E-3 // us 19 #define ADC_TIME_STEP 4 // ns 20 #define SLEEP_WAIT 1E4 // When not in shared memory mode, length of time to wait between calls to gSystem->ProcessEvents (in us). 22 void Filterer::Filter(
float *trace_,
const size_t &length_,
float *filtered1,
const unsigned int &risetime_,
const unsigned int &flattop_){
24 size_t a1, a2, a3, a4;
26 for(
size_t i = 0; i < 2*risetime_ + flattop_; i++){
30 for(
size_t i = 2*risetime_ + flattop_; i < length_; i++){
32 a1 = i - (2*risetime_ + flattop_);
33 a2 = i - (risetime_ + flattop_);
36 for(
size_t j = a1; j <= a2; j++){
39 for(
size_t j = a3; j <= a4; j++){
42 filtered1[i] = sum/risetime_;
66 rootapp =
new TApplication(
"filterer", 0, NULL);
67 gSystem->Load(
"libTree");
69 canvas =
new TCanvas(
"filterer_canvas",
"Filterer");
99 for(
size_t index = 0; index <
x_vals.size(); index++){
102 x_vals[index] = ADC_TIME_STEP * index;
104 while ((
unsigned int)
graph->GetN() > size)
graph->RemovePoint(
graph->GetN());
107 std::stringstream stream;
109 graph->SetTitle(stream.str().c_str());
117 static float axisMin, axisMax;
136 for (
size_t i = 0; i < event_->
size ; i++) {
142 if (
graph->GetYaxis()->GetXmax() > axisMax) axisMax =
graph->GetYaxis()->GetXmax();
143 if (
graph->GetYaxis()->GetXmin() < axisMin) axisMin =
graph->GetYaxis()->GetXmin();
145 if (
f_fast->GetYaxis()->GetXmax() > axisMax) axisMax =
f_fast->GetYaxis()->GetXmax();
146 if (
f_fast->GetYaxis()->GetXmin() < axisMin) axisMin =
f_fast->GetYaxis()->GetXmin();
148 if (
f_slow->GetYaxis()->GetXmax() > axisMax) axisMax =
f_slow->GetYaxis()->GetXmax();
149 if (
f_slow->GetYaxis()->GetXmin() < axisMin) axisMin =
f_slow->GetYaxis()->GetXmin();
151 graph->GetYaxis()->SetLimits(axisMin, axisMax);
152 graph->GetYaxis()->SetRangeUser(axisMin, axisMax);
166 PixieEvent *current_event = NULL;
170 if(kill_all){
break; }
176 if(shm_mode || kill_all){
return; }
178 gSystem->ProcessEvents();
186 if(!current_event || current_event->adcTrace.empty()){
191 if(current_event->modNum ==
mod_ && current_event->chanNum ==
chan_){
196 delete channel_event;
201 delete channel_event;
213 gSystem->ProcessEvents();
224 gSystem->ProcessEvents();
229 if(init){
return false; }
232 std::cout << prefix_ <<
"Displaying traces for mod = " <<
mod_ <<
", chan = " <<
chan_ <<
".\n";
234 return (init =
true);
241 std::cout << prefix_ <<
"--mod [module] | Module of signal of interest (default=0)\n";
242 std::cout << prefix_ <<
"--chan [channel] | Channel of signal of interest (default=0)\n";
250 std::cout << prefix_ <<
"set [mod] [chan] - Set the module and channel of signal of interest (default = 0, 0).\n";
251 std::cout << prefix_ <<
"single - Perform a single capture.\n";
252 std::cout << prefix_ <<
"thresh [low] <high> - Set the plotting window for trace maximum.\n";
253 std::cout << prefix_ <<
"delay [time] - Set the delay between drawing traces (in seconds, default = 1 s).\n";
254 std::cout << prefix_ <<
"log - Toggle log/linear mode on the y-axis.\n";
255 std::cout << prefix_ <<
"trise [risetime] - Set the length of the fast filter (in μs).\n";
256 std::cout << prefix_ <<
"tflat [flattop] - Set the gap of the fast filter (in μs).\n";
257 std::cout << prefix_ <<
"erise [risetime] - Set the length of the slow filter (in μs).\n";
258 std::cout << prefix_ <<
"eflat [flattop] - Set the gap of the slow filter (in μs).\n";
266 std::string current_arg;
267 while(!args_.empty()){
268 current_arg = args_.front();
271 if(current_arg ==
"--mod"){
273 std::cout <<
" Error: Missing required argument to option '--mod'!\n";
276 mod_ = atoi(args_.front().c_str());
279 else if(current_arg ==
"--chan"){
281 std::cout <<
" Error: Missing required argument to option '--chan'!\n";
284 chan_ = atoi(args_.front().c_str());
287 else{ filename_ = current_arg; }
295 if(args_.size() == 2){
297 mod_ = atoi(args_.at(0).c_str());
298 chan_ = atoi(args_.at(1).c_str());
310 std::cout << message_head <<
"Invalid number of parameters to 'set'\n";
311 std::cout << message_head <<
" -SYNTAX- set [module] [channel]\n";
314 else if(cmd_ ==
"single") {
317 else if (cmd_ ==
"thresh") {
318 if (args_.size() == 1) {
322 else if (args_.size() == 2) {
327 std::cout << message_head <<
"Invalid number of parameters to 'thresh'\n";
328 std::cout << message_head <<
" -SYNTAX- thresh <lowerThresh> [upperThresh]\n";
331 else if(cmd_ ==
"delay"){
332 if(args_.size() == 1){
delay_ = atoi(args_.at(0).c_str()); }
334 std::cout << message_head <<
"Invalid number of parameters to 'delay'\n";
335 std::cout << message_head <<
" -SYNTAX- delay [time]\n";
338 else if(cmd_ ==
"log"){
341 std::cout << message_head <<
"y-axis set to linear.\n";
345 std::cout << message_head <<
"y-axis set to log.\n";
348 else if(cmd_ ==
"trise"){
349 if(args_.size() == 1){
350 float temp = atof(args_.at(0).c_str());
352 std::cout << message_head <<
"Set TRIGGER_RISETIME to " << trig_rise <<
" ADC ticks (" << trig_rise*
ADC_CLOCK_uSEC <<
" μs).\n";
356 else if(cmd_ ==
"tflat"){
357 if(args_.size() == 1){
358 float temp = atof(args_.at(0).c_str());
360 std::cout << message_head <<
"Set TRIGGER_FLATTOP to " << trig_flat <<
" ADC ticks (" << trig_flat*
ADC_CLOCK_uSEC <<
" μs).\n";
364 else if(cmd_ ==
"erise"){
365 if(args_.size() == 1){
366 float temp = atof(args_.at(0).c_str());
368 std::cout << message_head <<
"Set ENERGY_RISETIME to " << energy_rise <<
" ADC ticks (" << energy_rise*
ADC_CLOCK_uSEC <<
" μs).\n";
372 else if(cmd_ ==
"eflat"){
373 if(args_.size() == 1){
374 float temp = atof(args_.at(0).c_str());
376 std::cout << message_head <<
"Set ENERGY_FLATTOP to " << energy_flat <<
" ADC ticks (" << energy_flat*
ADC_CLOCK_uSEC <<
" μs).\n";
380 else{
return false; }
396 gSystem->ProcessEvents();
399 int main(
int argc,
char *argv[]){
402 scan_main.Initialize(argc, argv);
404 scan_main.SetMessageHeader(
"Filterer: ");
406 return scan_main.Execute();
bool Initialize(std::string prefix_="")
TCanvas * canvas
The main plotting canvas.
void Plot(ChannelEvent *event_)
Plot the current event.
bool SetArgs(std::deque< std::string > &args_, std::string &filename_)
Scan input arguments and set class variables.
void ProcessRawEvent()
Process all events in the event list.
void Filter(float *trace_, const size_t &length_, float *filtered1, const unsigned int &risetime_, const unsigned int &flattop_)
float * yvals
x values used for fitting.
void StartAcquisition()
Scan has started data acquisition.
bool CommandControl(std::string cmd_, const std::vector< std::string > &args_)
void ResetGraph(unsigned int size_)
void ArgHelp(std::string prefix_="")
Print a command line help dialogue for recognized command line arguments.
std::deque< XiaData * > rawEvent
The list of all events in a spill.
unsigned int num_traces
The total number of traces.
TApplication * rootapp
Root application pointer.
unsigned int energy_flat
Set the slow filter risetime. Analogous to setting ENERGY_RISETIME.
virtual void IdleTask()
Perform tasks when waiting for a spill.
std::vector< int > x_vals
The number of seconds to wait between drawing traces.
int chan_
The channel of the signal of interest.
Filterer(int mod=0, int chan=0)
float maximum
Standard deviation of the baseline.
float FindQDC(const size_t &start_=0, const size_t &stop_=0)
Integrate the baseline corrected trace in the range [start_, stop_] and return the result...
TGraph * graph
The TGraph for plotting traces.
TGraph * f_fast
The TGraph for plotting the fast filter.
TGraph * f_slow
The TGraph for plotting the slow filter.
void CmdHelp(std::string prefix_="")
Print an in-terminal help dialogue for recognized commands.
size_t size
y values for the cfd analyzed waveform.
unsigned int num_displayed
The number of displayed traces.
void StopAcquisition()
Scan has stopped data acquisition.
time_t last_trace
The time of the last trace.
unsigned int trig_flat
Set the fast filter length. Analogous to setting TRIGGER_RISETIME.
int mod_
The module of the signal of interest.
int main(int argc, char *argv[])
unsigned int energy_rise
Set the fast filter gap. Analogous to setting TRIGGER_FLATTOP.
float * fast_filter_y
Set the slow filter gap. Analogous to setting ENERGY_FLATTOP.
float FindLeadingEdge(const float &thresh_=0.05)
Find the leading edge of the pulse at a given percentage of pulse maximum.
int delay_
Set to true if the graph range needs updated.