29 #include "TPaveStats.h" 33 #define PROG_NAME "Scope" 36 #define ADC_TIME_STEP 4 // ns 37 #define SLEEP_WAIT 1E4 // When not in shared memory mode, length of time to wait after gSystem->ProcessEvents is called (in us). 60 if (diff < 0 )
return p[0];
62 return p[0] + p[1] * exp(-diff * p[3]) * (1 - exp(-pow(diff * p[4],4)));
96 if(!current_event || current_event->
GetTrace().empty()){
103 current_event->
GetTrace().size()).second;
107 delete current_event;
111 delete current_event;
148 graph =
new TGraph();
151 cfdPol3 =
new TF1(
"cfdPol3",
"pol3");
152 cfdPol3->SetLineColor(kGreen+1);
153 cfdPol2 =
new TF1(
"cfdPol2",
"pol2");
154 cfdPol2->SetLineColor(kMagenta+1);
156 hist =
new TH2F(
"hist",
"",256,0,1,256,0,1);
160 gStyle->SetPalette(51);
163 gStyle->SetOptStat(1000000);
166 gStyle->SetOptFit(111);
181 paulauskasFunc->SetParNames(
"voffset",
"amplitude",
"phase",
"beta",
"gamma");
189 graph =
new TGraph(size);
190 graph->SetMarkerStyle(kFullDotSmall);
192 if(size !=
x_vals.size()){
195 for(
size_t index = 0; index <
x_vals.size(); index++)
196 x_vals[index] = ADC_TIME_STEP * index;
200 std::stringstream stream;
202 graph->SetTitle(stream.str().c_str());
203 hist->SetTitle(stream.str().c_str());
209 static float histAxis[2][2];
220 for (
int i=0;i<2;i++) {
221 histAxis[i][0] = 1E9;
222 histAxis[i][1] = -1E9;
229 for (
size_t i = 0; i <
chanEvents_.front()->size; ++i) {
286 evtMin -= fabs(0.1 * evtMax);
287 evtMax += fabs(0.1 * evtMax);
288 if (evtMin < histAxis[1][0]) histAxis[1][0] = evtMin;
289 if (evtMax > histAxis[1][1]) histAxis[1][1] = evtMax;
301 for (
size_t i=0; i < evt->
size; ++i) {
307 prof->SetLineColor(kRed);
308 prof->SetMarkerColor(kRed);
320 hist->SetStats(
false);
327 TPaveStats*
stats = (TPaveStats*)
prof->GetListOfFunctions()->FindObject(
"stats");
329 stats->SetX1NDC(0.55);
330 stats->SetX2NDC(0.9);
346 graph->Clone(
"trace")->Write();
360 if(
init){
return false; }
365 return (
init =
true);
373 if(code_ ==
"START_SCAN"){
377 else if(code_ ==
"STOP_SCAN"){
acqRun_ =
false; }
378 else if(code_ ==
"SCAN_COMPLETE"){ std::cout <<
msgHeader <<
"Scan complete.\n"; }
379 else if(code_ ==
"LOAD_FILE"){ std::cout <<
msgHeader <<
"File loaded.\n"; }
380 else if(code_ ==
"REWIND_FILE"){ }
381 else{ std::cout <<
msgHeader <<
"Unknown notification code '" << code_ <<
"'!\n"; }
399 if(!event_){
return false; }
465 std::cout <<
" set <module> <channel> - Set the module and channel of signal of interest (default = 0, 0).\n";
466 std::cout <<
" stop - Stop the acquistion.\n";
467 std::cout <<
" run - Run the acquistion.\n";
468 std::cout <<
" single - Perform a single capture.\n";
469 std::cout <<
" thresh <low> [high] - Set the plotting window for trace maximum.\n";
470 std::cout <<
" fit <low> <high> - Turn on fitting of waveform. Set <low> to \"off\" to disable.\n";
471 std::cout <<
" cfd [F=0.5] [D=1] [L=1] - Turn on cfd analysis of waveform. Set [F] to \"off\" to disable.\n";
472 std::cout <<
" avg <numWaveforms> - Set the number of waveforms to average.\n";
473 std::cout <<
" save <fileName> - Save the next trace to the specified file name..\n";
474 std::cout <<
" delay [time] - Set the delay between drawing traces (in seconds, default = 1 s).\n";
475 std::cout <<
" log - Toggle log/linear mode on the y-axis.\n";
476 std::cout <<
" clear - Clear all stored traces and start over.\n";
486 AddOption(
optionExt(
"mod", required_argument, NULL,
'M',
"<module>",
"Module of signal of interest (default=0)"));
487 AddOption(
optionExt(
"chan", required_argument, NULL,
'C',
"<channel>",
"Channel of signal of interest (default=0)"));
495 std::cout <<
" usage: " << std::string(name_) <<
" [options]\n";
520 if(args_.size() == 2){
531 std::cout <<
msgHeader <<
"Invalid number of parameters to 'set'\n";
532 std::cout << msgHeader <<
" -SYNTAX- set <module> <channel>\n";
535 else if(cmd_ ==
"single") {
538 else if (cmd_ ==
"thresh") {
539 if (args_.size() == 1) {
543 else if (args_.size() == 2) {
548 std::cout <<
msgHeader <<
"Invalid number of parameters to 'thresh'\n";
549 std::cout << msgHeader <<
" -SYNTAX- thresh <lowerThresh> [upperThresh]\n";
552 else if (cmd_ ==
"fit") {
553 if (args_.size() >= 1 && args_.at(0) ==
"off") {
555 std::cout <<
msgHeader <<
"Disabling root fitting.\n";
560 else{ std::cout <<
msgHeader <<
"Fitting is not enabled.\n"; }
562 else if (args_.size() == 2) {
563 fitLow_ = atoi(args_.at(0).c_str());
564 fitHigh_ = atoi(args_.at(1).c_str());
565 std::cout <<
msgHeader <<
"Setting root fitting range to [" <<
fitLow_ <<
", " << fitHigh_ <<
"].\n";
569 std::cout <<
msgHeader <<
"Invalid number of parameters to 'fit'\n";
570 std::cout << msgHeader <<
" -SYNTAX- fit <low> <high>\n";
571 std::cout << msgHeader <<
" -SYNTAX- fit off\n";
574 else if (cmd_ ==
"cfd") {
579 else if (args_.size() == 1) {
580 if(args_.at(0) ==
"off"){
582 std::cout <<
msgHeader <<
"Disabling cfd analysis.\n";
585 else{ std::cout <<
msgHeader <<
"Cfd is not enabled.\n"; }
588 cfdF_ = atof(args_.at(0).c_str());
592 else if (args_.size() == 2) {
593 cfdF_ = atof(args_.at(0).c_str());
594 cfdD_ = atoi(args_.at(1).c_str());
597 else if (args_.size() == 3) {
598 cfdF_ = atof(args_.at(0).c_str());
599 cfdD_ = atoi(args_.at(1).c_str());
600 cfdL_ = atoi(args_.at(2).c_str());
604 std::cout <<
msgHeader <<
"Enabling cfd analysis with F=" <<
cfdF_ <<
", D=" <<
cfdD_ <<
", L=" <<
cfdL_ << std::endl;
606 else if (cmd_ ==
"avg") {
607 if (args_.size() == 1) {
611 std::cout <<
msgHeader <<
"Invalid number of parameters to 'avg'\n";
612 std::cout << msgHeader <<
" -SYNTAX- avg <numWavefroms>\n";
615 else if(cmd_ ==
"save") {
616 if (args_.size() == 1) {
620 std::cout <<
msgHeader <<
"Invalid number of parameters to 'save'\n";
621 std::cout << msgHeader <<
" -SYNTAX- save <fileName>\n";
624 else if(cmd_ ==
"delay"){
625 if(args_.size() == 1){
delay_ = atoi(args_.at(0).c_str()); }
627 std::cout <<
msgHeader <<
"Invalid number of parameters to 'delay'\n";
628 std::cout << msgHeader <<
" -SYNTAX- delay <time>\n";
631 else if(cmd_ ==
"log"){
634 std::cout <<
msgHeader <<
"y-axis set to linear.\n";
638 std::cout <<
msgHeader <<
"y-axis set to log.\n";
641 else if(cmd_ ==
"clear"){
643 std::cout <<
msgHeader <<
"Event deque cleared.\n";
645 else{
return false; }
652 int main(
int argc,
char *argv[]){
660 if(!scanner.
Setup(argc, argv))
664 int retval = scanner.
Execute();
688 extern "C" void drrsub_(uint32_t &iexist) {
690 hd1d_(8000, 2, 256, 256, 0, 255,
"Run DAMM you!", strlen(
"Run DAMM you!"));
698 std::cout <<
"\nCleaning up..\n";
int main(int argc, char *argv[])
bool running
True if debug mode is set.
virtual bool AddEvent(XiaData *event_)
time_t last_trace
The time of the last trace.
scopeScanner(int mod=0, int chan=0)
Default constructor.
int GetNumberArguments(void)
void startup_()
Do some startup stuff.
virtual void ExtraArguments()
void UpdateZoom(TVirtualPad *pad=gPad)
virtual void CmdHelp(const std::string &prefix_="")
virtual void Notify(const std::string &code_="")
StatsData stats
Instance of the class (not sure why -SVP)
std::deque< XiaData * > rawEvent
The list of all events in a spill.
TF1 * paulauskasFunc
A TF1 of the Paulauskas Function (NIM A 737 (2014) 22)
A file containing stand-alone functions (only depend on standard C++ headers) that are used in the so...
virtual bool AddEvent(XiaData *event_)
unsigned int GetChannelNumber() const
bool Close()
Shutdown cleanly.
void AddOption(optionExt opt_)
Pointer to class derived from Unpacker class.
TGraph * graph
The TGraph for plotting traces.
bool need_graph_update
The number of seconds to wait between drawing traces.
virtual bool ProcessEvents()
bool Setup(int argc, char *argv[])
Setup user options and initialize all required objects.
double PaulauskasFitFunc(double *x, double *p)
UtkScanInterface * scanner
std::deque< ChannelEvent * > chanEvents_
The buffer of waveforms to be plotted.
virtual Unpacker * GetCore()
unsigned int numAvgWaveforms_
TH2F * hist
The histogram containing the waveform frequencies.
void SetProgramName(const std::string &head_)
Set the header string used to prefix output messages.
void drrmake_()
DAMM initialization call.
XiaData * event
Ignore this event.
unsigned int mod_
The module of the signal of interest.
size_t size
y values for the cfd analyzed waveform.
bool ShmMode()
Return true if shared memory mode is enabled.
~scopeScanner()
Destructor.
char ** GetArguments(void)
Returns an argv style array that can be used to pass to getopt and other similar functions.
scopeUnpacker(const unsigned int &mod=0, const unsigned int &chan=0)
Default constructor.
virtual bool ExtraCommands(const std::string &cmd_, std::vector< std::string > &args_)
void ResetGraph(unsigned int size_)
TProfile * prof
The profile of the average histogram.
std::vector< int > x_vals
virtual void SyntaxStr(char *name_)
void drrsub_(uint32_t &iexist)
Defines the main interface with the SCANOR library, the program essentially starts here...
void Plot()
Plot the current event.
static ScanorInterface * get()
void endrr_()
DAMM declaration wrap-up call.
pair< unsigned int, double > FindMaximum(const vector< T > &data, const unsigned int &traceDelayInBins)
This function finds the maximum bin and the value of the maximum bin for the provided vector...
virtual bool Initialize(std::string prefix_="")
bool resetGraph_
Set to true if the graph range needs updated.
float cfdF_
The number of waveforms to store.
virtual void ProcessRawEvent(ScanInterface *addr_=NULL)
void ResetZoom(TVirtualPad *pad=gPad)
unsigned int num_displayed
The number of displayed traces.
virtual bool ProcessEvents()
std::string saveFile_
The name of the file to save a trace.
std::vector< unsigned int > GetTrace() const
void SetUnpacker(Unpacker *a)
void cleanup_()
Catch the exit call from scanor and clean up c++ objects CRT.
int Execute()
Run the program.
void hd1d_(const int &, const int &, const int &, const int &, const int &, const int &, const char *, int)
create a DAMM 1D histogram args are damm id, half-words per channel, param length, hist length, low x-range, high x-range, and title
std::vector< optionExt > userOpts
Base level command line options for the scan.
unsigned int chan_
The channel of the signal of interest.
unsigned int GetModuleNumber() const