//------------------------------------------------------------------------------ // NP**Additional functions by NP for the "Nico" menu -- // (C) Nicola Pozzobon 2008, DipFIS UniPD -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "task_Nico.cpp" // [Author] "Nicola Pozzobon" // [Version] "0.0" // [Modified by] "Nicola Pozzobon" // [Last revision] "29 Sept 2008" // [Language] "C++" // [Compiler] "Visual C++ 8.x 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Header for the gui_Button class" // [Key documentation] // "Visual C++ Reference Help" // "Root reference guide" // {Trace} //______________________________________________________________________________ // Std #include #include #include #include #include #include // Root #include "TH1.h" #include "TH2.h" #include "TFile.h" #include "TSystem.h" //NP** additional libraries needed by me #include "TTree.h" #include "TMath.h" #include "TNtuple.h" #include "TRandom.h" #include "TBrowser.h" #include "TChain.h" #include "THStack.h" #include "TCanvas.h" #include "TObjArray.h" #include "TGraph.h" // Application #include "global.h" #include "geom_Frame.h" #include "comm_Master.h" #include "gui_Button.h" #include "gui_Display.h" #include "gui_Canvas.h" #include "comm_USB.h" #include "comm_Master.h" #include "comm_Reg.h" #include "gui_Main.h" #include "gui_Menu.h" #include "data_Frame.h" #include "task_Nico.h" task_Nico::task_Nico() { // Standard constructor dbg_Print("task_Nico::task_Nico: constructor called", DBG_LVL_ZERO); } //______________________________________________________________________________ task_Nico::~task_Nico() { // Standard destructor dbg_Print("task_Nico::~task_Nico: destructor called", DBG_LVL_ZERO); // Kill itself //delete this; } //______________________________________________________________________________ //NP**Imaging-live DAQ void task_Nico::test_SaveAs_GUI_IMAGE() { static HANDLE read_thread_Hnd; // Read thread handle static unsigned int read_thread_ID; // Read thread ID app_Test_GUI_IMAGE(0); } //______________________________________________________________________________ unsigned int __stdcall task_Nico::app_Test_GUI_IMAGE(void* Args) { //NP**Sets Buttons gui_Button* btn_AUTO = new gui_Button("Turn Autorefresh On", 64, 60, 120, 32, gui_Button::km_Latch); btn_AUTO->backColor(0x00AA00); btn_AUTO->btn_Status(false); gui_Button* btn_Run = new gui_Button("Go", 64, 120, 120, 32, gui_Button::km_Latch); btn_Run->backColor(0x00FF00); btn_Run->btn_Status(false); gui_Button* btn_HIST = new gui_Button("Pause + Show\n (double click)", 64, 180, 120, 52, gui_Button::km_Latch); btn_HIST->backColor(0x00FFFF); btn_HIST->btn_Status(false); gui_Button* btn_TBRO = new gui_Button("Save + Browse", 64, 270, 120, 32, gui_Button::km_Button); btn_TBRO->backColor(0x0000FF); btn_TBRO->btn_Status(false); gui_Button* btn_Quit = new gui_Button("Quit", 64, 330, 120, 32, gui_Button::km_Button); btn_Quit->btn_Status(false); //NP**Sets Canvas gui_Canvas* cnv_Test = new gui_Canvas(220, 26, 1000, 750); cnv_Test->backColor(0x0D114A); cnv_Test->foreColor(0x121212); cnv_Test->root()->GetCanvas()->Pad()->SetBorderMode(0); cnv_Test->root()->GetCanvas()->Divide(2,2); cnv_Test->root()->GetCanvas()->GetPad(1)->SetFillColor(33); cnv_Test->root()->GetCanvas()->GetPad(2)->SetFillColor(11); cnv_Test->root()->GetCanvas()->GetPad(3)->SetFillColor(22); cnv_Test->root()->GetCanvas()->GetPad(4)->SetFillColor(44); cnv_Test->update(); gui_Canvas* cnv_Test2 = new gui_Canvas(640, 26, 240, 90); cnv_Test2->backColor(cnv_Test->backColor()); cnv_Test2->update(); //NP**Sets some other useful objects TRandom* data_gen; data_gen = new TRandom(0); data_gen->SetSeed(0); Double_t px, py; //NP**Sets some variables Int_t contapad = 4; Int_t contaentry = 0; //NP**Sets histograms, files and ntuples TH2F* hpxpy = new TH2F("hpxpy","py vs px",300,-15,15,300,-15,15); TFile* hfile = (TFile *)0; //TTree* htree = (TTree *)0; //TNtuple* ntuple = new TNtuple("ntuple","Demo ntuple","px:py:i"); //TTree* htree = new TTree("htree","htree"); //htree->Branch("jetPx",&px,"jetPx/F"); //htree->Branch("jetPy",&py,"jetPy/F"); //htree->Branch("index",&contaentry,"index/F"); //NP**Quit means Quit..... while (btn_Quit->btn_Status() == false) { //NP**Enable or disable autorefresh mode if (btn_AUTO->btn_Status() == true) { btn_AUTO->backColor(0xAA0000); btn_AUTO->text("Autorefresshing!!!"); } else if (btn_AUTO->btn_Status() == false && contaentry > 0) { btn_AUTO->backColor(0x00AA00); btn_AUTO->text("Autorefresh paused"); } //NP**if you click on RUN you start the DAQ if (btn_Run->btn_Status() == true) { btn_Run->backColor(0xFF0000); btn_Run->text("Stop"); //NP**What happens while you are running the DAQ? while (btn_Run->btn_Status() == true) { //NP**Fill histograms until you click on STOP //(while condition above) or PAUSE (see later) //AND FILL NTUPLE TOO?????????????????????????????????????????????????????? //??????????????????????????????????????????????????? px = data_gen->Gaus(2, 6); py = data_gen->Gaus(-5, 3); hpxpy->Fill(px,py); contaentry++; //ntuple->Fill(px,py,++i); //htree->Fill(); //NP**If autorefresh mode is on, automatically changes histogram images //If autorefresh mode is off, manually changes histogram images //Anyway, manual refresh can be invoked anytime if you click on the button PAUSE //Any time manual refresh is invoked, manual restart must occur!!! if (btn_AUTO->btn_Status() == true) { btn_HIST->btn_Status(false); if (contaentry%20000 == 0) btn_HIST->btn_Status(true); } if (btn_HIST->btn_Status() == true) { btn_Run->btn_Status(false); if (btn_AUTO->btn_Status() == true && contaentry%20000 == 0) btn_Run->btn_Status(true); contapad++; if (contapad>4) contapad = 1; cnv_Test->root()->GetCanvas()->GetPad(contapad)->cd(); hpxpy->Draw(); cnv_Test->root()->GetCanvas()->GetPad(contapad)->Update(); btn_HIST->btn_Status(false); } } // Wait mode btn_Run->backColor(0xFFFF00); btn_Run->text("Resume"); } //NP**Save data, histogram and open a TBrowser if (btn_TBRO->btn_Status() == true) { //gui_Form* frm_TBRO = new gui_Form("Question"); //frm_TBRO->form_Show(); std::string name_TT; std::cout<<"please enter the name:"<>name_TT; name_TT += ".root"; hfile = new TFile(name_TT.c_str(),"RECREATE"); if (! hfile->IsOpen()) { std::cerr << "Did not successfully open " << std::endl; return 0; } //htree->GetCurrentFile()->cd(); //htree->Write(); //hpxpy->GetCurrentFile()->cd(); hpxpy->Write(); hfile->ls(); hfile->Close(); std::cout<<"the file has been saved as "<btn_Status(false); delete btn_AUTO; delete btn_Run; delete btn_Quit; delete btn_TBRO; delete btn_HIST; delete cnv_Test; delete cnv_Test2; delete hfile; //delete htree; // Exit the thread return 0; } //______________________________________________________________________________ //NP**Oscilloscope mode DAQ void task_Nico::test_SaveAs_GUI_OSCILL() { static HANDLE read_thread_Hnd; // Read thread handle static unsigned int read_thread_ID; // Read thread ID app_Test_GUI_OSCILL(0); } //______________________________________________________________________________ unsigned int __stdcall task_Nico::app_Test_GUI_OSCILL(void* Args) { //NP**Sets Buttons gui_Button* btn_THR = new gui_Button("Set Threshold", 64, 60, 120, 32, gui_Button::km_Button); btn_THR->backColor(0x00AA00); btn_THR->btn_Status(false); gui_Button* btn_Run = new gui_Button("Go", 64, 120, 120, 32, gui_Button::km_Latch); btn_Run->backColor(0x00FF00); btn_Run->btn_Status(false); //gui_Button* btn_HIST = new gui_Button("Pause + Show\n (double click)", 64, 180, 120, 52, gui_Button::km_Latch); // btn_HIST->backColor(0x00FFFF); // btn_HIST->btn_Status(false); gui_Button* btn_TBRO = new gui_Button("Save + Browse", 64, 270, 120, 32, gui_Button::km_Button); btn_TBRO->backColor(0x0000FF); btn_TBRO->btn_Status(false); gui_Button* btn_Quit = new gui_Button("Quit", 64, 330, 120, 32, gui_Button::km_Button); btn_Quit->btn_Status(false); //NP**Sets Canvas gui_Canvas* cnv_Test = new gui_Canvas(220, 26, 1000, 750); cnv_Test->backColor(0x0D114A); cnv_Test->foreColor(0x121212); cnv_Test->root()->GetCanvas()->Pad()->SetBorderMode(0); cnv_Test->root()->GetCanvas()->Divide(1,1); cnv_Test->root()->GetCanvas()->GetPad(1)->SetFillColor(33); cnv_Test->update(); gui_Canvas* cnv_Test2 = new gui_Canvas(640, 26, 240, 90); cnv_Test2->backColor(cnv_Test->backColor()); cnv_Test2->update(); //NP**Sets some other useful objects TRandom* data_gen; data_gen = new TRandom(0); data_gen->SetSeed(0); Double_t signal, noise; //NP**Sets some variables Int_t contaentry = 0; Double_t threshold = -10000000; //NP**Sets graphs, files and ntuples TGraph* hprobe = new TGraph(400); hprobe->SetLineColor(2); hprobe->SetLineWidth(1); hprobe->SetMarkerColor(4); hprobe->SetMarkerStyle(21); hprobe->SetTitle("OSCILLOSCOPE EMULATOR"); hprobe->GetXaxis()->SetTitle("fake time"); hprobe->GetYaxis()->SetTitle("fake waveform"); TFile* hfile = (TFile *)0; //TTree* htree = (TTree *)0; //TNtuple* ntuple = new TNtuple("ntuple","Demo ntuple","px:py:i"); //TTree* htree = new TTree("htree","htree"); //htree->Branch("jetPx",&px,"jetPx/F"); //htree->Branch("jetPy",&py,"jetPy/F"); //htree->Branch("index",&contaentry,"index/F"); //NP**Initialize the graph for (int j=0; j<400; j++) hprobe->SetPoint(j, j, threshold); cnv_Test->root()->GetCanvas()->GetPad(1)->cd(); hprobe->Draw(); //NP**Quit means Quit..... while (btn_Quit->btn_Status() == false) { //NP**Pause to set the threshold //otherwise, threshold does not exist if (btn_THR->btn_Status() == true) { btn_Run->btn_Status(false); std::cout<<"enter the threshold value"<>threshold; //btn_Run->btn_Status(true); } //NP**if you click on RUN you start the DAQ if (btn_Run->btn_Status() == true) { btn_Run->backColor(0xFF0000); btn_Run->text("Stop"); //NP**What happens while you are running the DAQ? while (btn_Run->btn_Status() == true) { //NP**Fill histograms until you click on STOP //(while condition above) or PAUSE (see later) //AND FILL NTUPLE TOO?????????????????????????????????????????????????????? //??????????????????????????????????????????????????? signal = 10*TMath::Sin((Double_t)contaentry / 30+0.3); //noise = (data_gen->Uniform(1)-0.5); noise = data_gen->Gaus(0,5)/3; contaentry++; if (signal + noise > threshold) hprobe->SetPoint(contaentry%400, contaentry%400, signal+noise); else hprobe->SetPoint(contaentry%400, contaentry%400, threshold); //ntuple->Fill(px,py,++i); //htree->Fill(); cnv_Test->root()->GetCanvas()->GetPad(1)->cd(); hprobe->Draw("AP"); if (contaentry%10==0) cnv_Test->root()->GetCanvas()->GetPad(1)->Update(); } // Wait mode btn_Run->backColor(0xFFFF00); btn_Run->text("Resume"); } //NP**Save data, histogram and open a TBrowser if (btn_TBRO->btn_Status() == true) { //gui_Form* frm_TBRO = new gui_Form("Question"); //frm_TBRO->form_Show(); std::string name_TT; std::cout<<"please enter the name:"<>name_TT; name_TT += ".root"; hfile = new TFile(name_TT.c_str(),"RECREATE"); if (! hfile->IsOpen()) { std::cerr << "Did not successfully open " << std::endl; return 0; } //htree->GetCurrentFile()->cd(); //htree->Write(); //hpxpy->GetCurrentFile()->cd(); hprobe->Write(); hfile->ls(); hfile->Close(); std::cout<<"the file has been saved as "<btn_Status(false); delete btn_THR; delete btn_Run; delete btn_Quit; delete btn_TBRO; delete cnv_Test; delete cnv_Test2; //delete htree; // Exit the thread return 0; } void task_Nico::do_mnu_Nico(Int_t entry_Id) { // Call switch(entry_Id) { case 1: task_Nico::test_SaveAs_GUI_IMAGE(); break; case 2: task_Nico::test_SaveAs_GUI_OSCILL(); break; case 3: std::cout<<" E PIM POM PEA..... "<