// $Id$ // // File: fcal11_mainframe.cc // Created: Wed Nov 30 07:42:06 EST 2011 // Creator: davidl (on Linux ifarm1101 2.6.18-128.7.1.el5 x86_64) // #include #include #include #include #include using namespace std; #include "fcal11view.h" #include "fcal11_mainframe.h" #include "fcal11_fADCviewer.h" #include "fcal11_SignalViewer.h" #include "MyProcessor.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include extern JApplication *japp; extern int GO; //--------------------------------- // fcal11_mainframe (Constructor) //--------------------------------- fcal11_mainframe::fcal11_mainframe(const TGWindow *p, UInt_t w, UInt_t h):TGMainFrame(p,w,h) { // Use the "color wheel" rather than the classic palette. TColor::CreateColorWheel(); events_to_process = 0; TGHorizontalFrame *sourceframe = new TGHorizontalFrame(this,w,20); TGHorizontalFrame *topframe = new TGHorizontalFrame(this, w, h); TGHorizontalFrame *midframe = new TGHorizontalFrame(this, w, h); TGHorizontalFrame *botframe = new TGHorizontalFrame(this, w, h); AddFrame(sourceframe, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 2,2,0,0)); AddFrame(topframe, new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 2,2,2,2)); AddFrame(midframe, new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY, 5,5,5,5)); AddFrame(botframe, new TGLayoutHints(kLHintsNormal, 2,2,2,2)); //========== Source =========== TGLabel *sourcelab = new TGLabel(sourceframe, "Source:"); sourceframe->AddFrame(sourcelab,new TGLayoutHints(kLHintsNormal, 2,2,0,0)); source = new TGLabel(sourceframe, "--"); sourceframe->AddFrame(source, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 2,2,0,0)); source->SetTextJustify(1); //========== TOP FRAME ============ TGGroupFrame *eventcontrols = new TGGroupFrame(topframe, "Event Controls", kVerticalFrame); TGGroupFrame *eventinfo = new TGGroupFrame(topframe, "Info", kHorizontalFrame); TGGroupFrame *displaycontrols = new TGGroupFrame(topframe, "Display Controls", kVerticalFrame); TGHorizontalFrame *programcontrols = new TGHorizontalFrame(topframe); topframe->AddFrame(eventcontrols, new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY, 5,5,5,5)); topframe->AddFrame(eventinfo, new TGLayoutHints(kLHintsNormal|kLHintsExpandY, 2,2,2,2)); topframe->AddFrame(displaycontrols, new TGLayoutHints(kLHintsNormal|kLHintsExpandY, 2,2,2,2)); topframe->AddFrame(programcontrols, new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY, 2,2,2,2)); //-------------- Next, continuous next = new TGTextButton(eventcontrols, "Next -->"); eventcontrols->AddFrame(next, new TGLayoutHints(kLHintsNormal, 2,2,2,2)); checkbuttons["continuous"] = new TGCheckButton(eventcontrols, "continuous"); eventcontrols->AddFrame(checkbuttons["continuous"], new TGLayoutHints(kLHintsNormal, 2,2,2,2)); TGHorizontalFrame *delayf = new TGHorizontalFrame(eventcontrols); eventcontrols->AddFrame(delayf, new TGLayoutHints(kLHintsNormal|kLHintsExpandY, 2,2,2,2)); TGLabel *delaylab = new TGLabel(delayf, "delay:"); delay = new TGComboBox(delayf, "0.25"); delay->Resize(50,20); float delays[]={0, 0.25, 0.5, 1, 2, 3, 5, 10}; for(int i=0; i<8; i++){ stringstream ss; ss<AddEntry(ss.str().c_str(),i); } delayf->AddFrame(delaylab, new TGLayoutHints(kLHintsNormal, 2,2,2,2)); delayf->AddFrame(delay, new TGLayoutHints(kLHintsNormal, 2,2,2,2)); //----------------- Event Info TGVerticalFrame *eventlabs = new TGVerticalFrame(eventinfo); TGVerticalFrame *eventvals = new TGVerticalFrame(eventinfo); eventinfo->AddFrame(eventlabs, new TGLayoutHints(kLHintsNormal, 2,2,2,2)); eventinfo->AddFrame(eventvals, new TGLayoutHints(kLHintsNormal, 2,2,2,2)); TGLabel *runlab = new TGLabel(eventlabs, "Run:"); TGLabel *eventlab = new TGLabel(eventlabs, "Event:"); run = new TGLabel(eventvals, "----------"); event = new TGLabel(eventvals, "----------"); eventlabs->AddFrame(runlab, new TGLayoutHints(kLHintsCenterY|kLHintsRight, 2,2,2,2)); eventlabs->AddFrame(eventlab,new TGLayoutHints(kLHintsCenterY|kLHintsRight, 2,2,2,2)); eventvals->AddFrame(run, new TGLayoutHints(kLHintsNormal, 2,2,2,2)); eventvals->AddFrame(event, new TGLayoutHints(kLHintsNormal, 2,2,2,2)); //-------------- Display Controls checkbuttons["require_remote"] = new TGCheckButton(displaycontrols, "Require remote scint. hit"); displaycontrols->AddFrame(checkbuttons["require_remote"], new TGLayoutHints(kLHintsNormal, 2,2,2,2)); checkbuttons["log_weighting"] = new TGCheckButton(displaycontrols, "Logarithmic weighting for dots"); displaycontrols->AddFrame(checkbuttons["log_weighting"], new TGLayoutHints(kLHintsNormal, 2,2,2,2)); TGGroupFrame *triggers = new TGGroupFrame(displaycontrols, "Require at least one of ...", kVerticalFrame); displaycontrols->AddFrame(triggers, new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY, 5,5,5,5)); TGHorizontalFrame *htrigs = new TGHorizontalFrame(triggers); triggers->AddFrame(htrigs, new TGLayoutHints(kLHintsNormal, 2,2,2,2)); trig_and_or = new TGComboBox(triggers, "OR"); trig_and_or->Resize(50,20); trig_and_or->AddEntry("OR",0); trig_and_or->AddEntry("AND",1); triggers->AddFrame(trig_and_or, new TGLayoutHints(kLHintsCenterX, 2,2,2,2)); trig_and_or->Select(0, kFALSE); TGHorizontalFrame *vtrigs = new TGHorizontalFrame(triggers); triggers->AddFrame(vtrigs, new TGLayoutHints(kLHintsNormal, 2,2,2,2)); for(int i=1; i<=5; i++){ char id[256], name[256]; sprintf(name, "htrig%d",i); sprintf(id, "h%d", i); checkbuttons[name] = new TGCheckButton(htrigs, id, NULL, i); htrigs->AddFrame(checkbuttons[name], new TGLayoutHints(kLHintsNormal, 2,2,2,2)); checkbuttons[name]->Connect("Clicked()","fcal11_mainframe", this, "DoSetTrig()"); sprintf(name, "vtrig%d",i); sprintf(id, "v%d", i); checkbuttons[name] = new TGCheckButton(vtrigs, id, NULL, i); vtrigs->AddFrame(checkbuttons[name], new TGLayoutHints(kLHintsNormal, 2,2,2,2)); checkbuttons[name]->Connect("Clicked()","fcal11_mainframe", this, "DoSetTrig()"); } //-------------- Program Controls TGVerticalFrame *viewers = new TGVerticalFrame(programcontrols); programcontrols->AddFrame(viewers, new TGLayoutHints(kLHintsTop|kLHintsExpandX, 2,2,2,2)); TGTextButton *openfADCviewer = new TGTextButton(viewers, "fADC viewer"); viewers->AddFrame(openfADCviewer, new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 2,2,2,2)); TGTextButton *openSignalViewer = new TGTextButton(viewers, "Signals viewer"); viewers->AddFrame(openSignalViewer, new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 2,2,2,2)); TGTextButton *quit = new TGTextButton(programcontrols, "&Quit"); programcontrols->AddFrame(quit, new TGLayoutHints(kLHintsTop|kLHintsRight|kLHintsExpandX, 2,2,2,2)); //========== MID FRAME ============ int width = 600; int height = 300; TGHorizontalFrame *canvasframe = new TGHorizontalFrame(midframe); midframe->AddFrame(canvasframe); canvas = new TRootEmbeddedCanvas("Main Canvas", canvasframe, width, height, kSunkenFrame, GetWhitePixel()); canvasframe->AddFrame(canvas); //--------- FCAL blocks double block_width = 4.0; double x_shift = -4.0*block_width; double y_shift = -4.0*block_width; double x_width = 16.0*block_width; double y_width = 8.0*block_width; canvas->GetCanvas()->cd(); canvas->GetCanvas()->Range(0.0+x_shift, 0.0+y_shift, x_width+x_shift, y_width+y_shift); for(int irow=0; irow<5; irow++){ for(int icol=0; icol<5; icol++){ double y = ((double)(4-irow)-2.5)*block_width; double x = ((double)icol-2.5)*block_width; blocks[icol][irow] = new TBox(x, y, x+block_width, y+block_width); blocks[icol][irow]->SetLineWidth(2); blocks[icol][irow]->SetLineColor(TColor::GetColor((float)0.4, (float)0.4, (float)0.4)); blocks[icol][irow]->SetFillColor(kGray); blocks[icol][irow]->Draw("l"); } } //--------- Dots (not drawn initially) dot_cntr = 0; for(int i=0; i<30; i++){ TMarker *m = new TMarker(-1000.0, -1000.0, 7); m->SetMarkerColor(kMagenta); m->SetMarkerSize(1.0); dots.push_back(m); } current_dot = new TMarker(-1000.0, -1000.0, 4); current_dot->SetMarkerColor(kRed); current_dot->SetMarkerSize(1.0); // --------- Paddles double inner_paddle_width = 3.3; double outer_paddle_width = 1.5*inner_paddle_width; double length = 3.0*inner_paddle_width + 2.0*outer_paddle_width; double drawing_offset = 30.0; double pmt_length = 2.0; double x = drawing_offset - length/2.0; for(int i=4; i>=0; i--){ double width = (i==0 || i==4) ? outer_paddle_width:inner_paddle_width; // Horizontal paddle vpaddles[i] = new TBox(drawing_offset-length/2.0, x-drawing_offset, drawing_offset+length/2.0, x-drawing_offset+width); vpaddles[i]->SetLineWidth(2); vpaddles[i]->SetLineColor(TColor::GetColor((float)0.2, (float)0.2, (float)0.2)); vpaddles[i]->SetFillColor(kGray); vpaddles[i]->SetFillStyle(3001); vpaddles[i]->Draw("l"); // Horizontal PMT vector pmt_x, pmt_y; pmt_x.push_back(vpaddles[i]->GetX2()); pmt_y.push_back(vpaddles[i]->GetY1()); pmt_x.push_back(vpaddles[i]->GetX2()); pmt_y.push_back(vpaddles[i]->GetY2()); pmt_x.push_back(vpaddles[i]->GetX2()+2.15); pmt_y.push_back(vpaddles[i]->GetY2()-width/2.0+1.4); pmt_x.push_back(vpaddles[i]->GetX2()+2.15+pmt_length); pmt_y.push_back(vpaddles[i]->GetY2()-width/2.0+1.4); pmt_x.push_back(vpaddles[i]->GetX2()+2.15+pmt_length); pmt_y.push_back(vpaddles[i]->GetY1()+width/2.0-1.4); pmt_x.push_back(vpaddles[i]->GetX2()+2.15); pmt_y.push_back(vpaddles[i]->GetY1()+width/2.0-1.4); pmt_x.push_back(vpaddles[i]->GetX2()); pmt_y.push_back(vpaddles[i]->GetY1()); TPolyLine *pmt = new TPolyLine(pmt_x.size(), &pmt_x[0], &pmt_y[0]); pmt->SetLineColor(kBlack); pmt->Draw(); x += width; } x = drawing_offset - length/2.0; for(int i=0; i<5; i++){ double width = (i==0 || i==4) ? outer_paddle_width:inner_paddle_width; // Vertical paddle hpaddles[i] = new TBox(x, -length/2.0, x+width, +length/2.0); hpaddles[i]->SetLineWidth(2); hpaddles[i]->SetLineColor(TColor::GetColor((float)0.2, (float)0.2, (float)0.2)); hpaddles[i]->SetFillColor(kGray); hpaddles[i]->SetFillStyle(3002); hpaddles[i]->Draw("l"); // Vertical PMT vector pmt_x, pmt_y; pmt_x.push_back(hpaddles[i]->GetX1()); pmt_y.push_back(hpaddles[i]->GetY1()); pmt_x.push_back(hpaddles[i]->GetX2()); pmt_y.push_back(hpaddles[i]->GetY1()); pmt_x.push_back(hpaddles[i]->GetX2()-width/2.0+1.4); pmt_y.push_back(hpaddles[i]->GetY1()-2.15); pmt_x.push_back(hpaddles[i]->GetX2()-width/2.0+1.4); pmt_y.push_back(hpaddles[i]->GetY1()-(2.15+pmt_length)); pmt_x.push_back(hpaddles[i]->GetX1()+width/2.0-1.4); pmt_y.push_back(hpaddles[i]->GetY1()-(2.15+pmt_length)); pmt_x.push_back(hpaddles[i]->GetX1()+width/2.0-1.4); pmt_y.push_back(hpaddles[i]->GetY1()-2.15); pmt_x.push_back(hpaddles[i]->GetX1()); pmt_y.push_back(hpaddles[i]->GetY1()); TPolyLine *pmt = new TPolyLine(pmt_x.size(), &pmt_x[0], &pmt_y[0]); pmt->SetLineColor(kBlack); pmt->Draw(); x += width; } //&&&&&&&&&&&&&&&& Connections quit->Connect("Clicked()","fcal11_mainframe", this, "DoQuit()"); next->Connect("Clicked()","fcal11_mainframe", this, "DoNext()"); openfADCviewer->Connect("Clicked()","fcal11_mainframe", this, "DoOpenfADCViewer()"); openSignalViewer->Connect("Clicked()","fcal11_mainframe", this, "DoOpenSignalViewer()"); delay->Connect("Selected(Int_t)","fcal11_mainframe", this, "DoSetDelay(Int_t)"); // Set up timer to call the DoTimer() method repeatedly // so events can be automatically advanced. timer = new TTimer(); timer->Connect("Timeout()", "fcal11_mainframe", this, "DoTimer()"); sleep_time = 250; timer->Start(sleep_time, kFALSE); // Create daughter windows new fcal11_fADCviewer(this, 1000, 600); new fcal11_SignalViewer(this, 1000, 600); // Finish up and map the window SetWindowName("FCAL 2011 Beam Test Event Viewer"); SetIconName("FCAL11View"); MapSubwindows(); Resize(GetDefaultSize()); MapWindow(); // Call Resize method of some group frames to get them to shrink down to smallest size eventinfo->Resize(); eventcontrols->Resize(); // canvas->GetCanvas()->cd(); } //------------------- // DoQuit //------------------- void fcal11_mainframe::DoQuit(void) { japp->Quit(); japp->Fini(); delete japp; japp = NULL; // This is supposed to return from the Run() method in "main()" // since we call SetReturnFromRun(true), but it doesn't seem to work. gApplication->Terminate(0); } //------------------- // DoNext //------------------- void fcal11_mainframe::DoNext(void) { if(events_to_process>0)events_to_process--; if(eventloop)eventloop->OneEvent(); //DoMyRedraw(); } //------------------- // DoTimer //------------------- void fcal11_mainframe::DoTimer(void) { /// This gets called periodically (value is set in constructor) /// It is used to automatically call DoNext() periodically /// so long as the global GO is set to 1. if(GetCheckButton("continuous") || events_to_process>0){ long my_sleep_time = sleep_time; if(events_to_process>0)my_sleep_time = 0; DoNext(); if(my_sleep_time != (long)timer->GetTime())timer->SetTime(my_sleep_time); }else{ if(sleep_time == 0)timer->SetTime(1); } } //------------------- // DoMyRedraw //------------------- void fcal11_mainframe::DoMyRedraw(void) { gMYPROC->UpdateBlocks(); gMYPROC->UpdateHisto(); } //------------------- // DoOpenfADCViewer //------------------- void fcal11_mainframe::DoOpenfADCViewer(void) { if(gfADCVIEWER){ gfADCVIEWER->Show(); } } //------------------- // DoOpenSignalViewer //------------------- void fcal11_mainframe::DoOpenSignalViewer(void) { if(gSIGNALVIEWER){ gSIGNALVIEWER->Show(); } } //------------------- // DoSetDelay //------------------- void fcal11_mainframe::DoSetDelay(Int_t id) { stringstream ss; ss<GetSelectedEntry()->GetTitle(); double seconds; ss>>seconds; sleep_time = (int)(1000.0*seconds); timer->SetTime(sleep_time); } //------------------- // DoSetTrig //------------------- void fcal11_mainframe::DoSetTrig(void) { bool any_trig = false; for(int i=1; i<=5; i++){ char name[256]; sprintf(name,"htrig%d", i); if(GetCheckButton(name)){ any_trig = true; break; } sprintf(name,"vtrig%d", i); if(GetCheckButton(name)){ any_trig = true; break; } } checkbuttons["require_remote"]->SetEnabled(!any_trig); } //------------------- // SetEvent //------------------- void fcal11_mainframe::SetEvent(int id) { if(!event)return; if(id>=0){ char str[256]; sprintf(str,"%5d", id); event->SetTitle(str); }else{ event->SetTitle("--"); } } //------------------- // SetSource //------------------- void fcal11_mainframe::SetSource(string source) { this->source->SetTitle(source.c_str()); } //------------------- // GetCheckButton //------------------- bool fcal11_mainframe::GetCheckButton(string who) { map::iterator iter = checkbuttons.find(who); if(iter==checkbuttons.end())return false; return iter->second->GetState()==kButtonDown; } //------------------- // AddCheckButtons //------------------- void fcal11_mainframe::AddCheckButtons(map &checkbuttons) { this->checkbuttons.insert(checkbuttons.begin(), checkbuttons.end()); } //------------------- // SetBlockColor //------------------- void fcal11_mainframe::SetBlockColor(int row, int col, float val) { if(row<0 || row>4 || col<0 || col>4)return; if(val<0.0)val = 0.0; if(val>1.0)val = 1.0; float h = 100.0; float s = 1.0-val; float v = val; float r,g,b; TColor::HSV2RGB(h, s, v, r, g, b); blocks[col][row]->SetFillColor(TColor::GetColor(r, g, b)); blocks[col][row]->Draw("l"); } //------------------- // SetPaddleColor //------------------- void fcal11_mainframe::SetPaddleColor(int orientation, int chid, bool is_hit) { if(chid<0 || chid>4)return; TBox *b = orientation ? hpaddles[chid]:vpaddles[chid]; int color = is_hit ? (orientation ? kRed:kBlue):kGray; b->SetFillColor(color); b->Draw("l"); } //------------------- // DrawDot //------------------- void fcal11_mainframe::DrawDot(double x, double y) { // When we get called, update the coordinates of the next dot // in the ring buffer and then redraw all of the dots. TMarker *m = dots[(dot_cntr++)%dots.size()]; m->SetX(x); m->SetY(y); for(unsigned int i=0; iDraw(); current_dot->SetX(x); current_dot->SetY(y); current_dot->Draw(); } //------------------- // GetTrigRequirement //------------------- void fcal11_mainframe::GetTrigRequirement(UInt_t &htrig_mask, UInt_t &vtrig_mask, bool &require_both) { htrig_mask = 0; vtrig_mask = 0; for(int i=1; i<=5; i++){ char name[256]; sprintf(name, "htrig%d", i); if(GetCheckButton(name))htrig_mask |= 0x1<<(i-1); sprintf(name, "vtrig%d", i); if(GetCheckButton(name))vtrig_mask |= 0x1<<(i-1); } if(trig_and_or->GetSelected()==1){ // AND require_both = true; }else{ // OR require_both = false; } } //--------------------------------- // ~fcal11_mainframe (Destructor) //--------------------------------- fcal11_mainframe::~fcal11_mainframe() { }