// $Id$ // // File: jv_mainframe.cc // Created: Fri Oct 3 08:12:01 EDT 2014 // Creator: davidl (on Darwin harriet.jlab.org 13.4.0 i386) // #include #include "jv_mainframe.h" #include "JEventProcessor_fmwpcview.h" extern bool QUIT; //--------------------------------- // jv_mainframe (Constructor) //--------------------------------- jv_mainframe::jv_mainframe(const TGWindow *p, UInt_t w, UInt_t h, bool build_gui):TGMainFrame(p,w,h, kMainFrame | kVerticalFrame) { CreateGUI(); CanvasNeedsUpdate = false; continuous = false; SetWindowName("JANA Viewer"); SetIconName("JANA Viewer"); MapSubwindows(); MapWindow(); this->SetWidth(1000); Redraw(this); // timer = new TTimer(); // timer->Connect("Timeout()", "jv_mainframe", this, "DoTimer()"); // sleep_time = 250; // sleep_time = 10; // timer->Start(sleep_time, kFALSE); } //--------------------------------- // ~jv_mainframe (Destructor) //--------------------------------- jv_mainframe::~jv_mainframe() { } //------------------- // CloseWindow //------------------- void jv_mainframe::CloseWindow(void) { DeleteWindow(); QUIT = true; gApplication->Terminate(0); } //------------------- // HandleMenu //------------------- void jv_mainframe::HandleMenu(Int_t id) { // Handle menu items. //cout << "in HandleMenu(" << id << ")" << endl; switch (id) { case M_FILE_OPEN: break; case M_FILE_SAVE: break; case M_FILE_NEW_CONFIG: break; case M_FILE_OPEN_CONFIG: break; case M_FILE_SAVE_CONFIG: break; case M_FILE_SAVE_AS_CONFIG: break; case M_FILE_EXIT: DoQuit(); break; case M_TOOLS_MACROS: break; case M_TOOLS_TBROWSER: break; case M_VIEW_NEW_TAB: break; case M_VIEW_REMOVE_TAB: break; } } //------------------- // DoTimer //------------------- void jv_mainframe::DoTimer(void) { } //------------------- // DoQuit //------------------- void jv_mainframe::DoQuit(void) { cout<<"quitting ..."<Terminate(0); } //------------------- // DoGo //------------------- void jv_mainframe::DoGo(void) { bGo->SetEnabled(kFALSE); bStop->SetEnabled(kTRUE); continuous = true; } //------------------- // DoStop //------------------- void jv_mainframe::DoStop(void) { bGo->SetEnabled(kTRUE); bStop->SetEnabled(kFALSE); continuous = false; } //------------------- // DoNext //------------------- void jv_mainframe::DoNext(void) { JEP->NextEvent(); } //------------------- // DoWireNext //------------------- void jv_mainframe::DoWireNext(void) { int max = JEP->Ncols*JEP->Nrows; JEP->id_start += max; if( JEP->id_start >= (144-max) ) JEP->id_start = (144-max); JEP->DrawHistos(); } //------------------- // DoWirePrev //------------------- void jv_mainframe::DoWirePrev(void) { int max = JEP->Ncols*JEP->Nrows; JEP->id_start -= max; if( JEP->id_start <0 ) JEP->id_start = 0; JEP->DrawHistos(); } //------------------- // DoWireFirst //------------------- void jv_mainframe::DoWireFirst(void) { JEP->id_start = 0; JEP->DrawHistos(); } //------------------- // DoWireLast //------------------- void jv_mainframe::DoWireLast(void) { JEP->id_start = 144-12; JEP->DrawHistos(); } //------------------- // HandleConfigureNotify //------------------- Bool_t jv_mainframe::HandleConfigureNotify(Event_t *event) { /// This gets called when the window is resized (but also for other things) /// It is here so we can update the CallGraph tab when the window is resized. return this->TGMainFrame::HandleConfigureNotify(event); } //============================================================================== //------------------- // UpdateInfo //------------------- void jv_mainframe::UpdateInfo(string source, int run, int event) { lSource->SetText(source.c_str()); char str[256]; sprintf(str, "%d ", run); lRun->SetText(str); sprintf(str, "%d ", event); lEvent->SetText(str); Redraw(lSource); } //------------------- // Redraw //------------------- void jv_mainframe::Redraw(TGFrame *f) { // This unfortunate business seems to be needed to get the listbox to redraw itself TGDimension dim = f->GetSize(); dim.fWidth+=1; f->Resize(dim); dim.fWidth-=1; f->Resize(dim); } //============================================================================== //------------------- // AddLabel //------------------- TGLabel* jv_mainframe::AddLabel(TGCompositeFrame* frame, string text, Int_t mode, ULong_t hints) { TGLabel *lab = new TGLabel(frame, text.c_str()); lab->SetTextJustify(mode); lab->SetMargins(0,0,0,0); lab->SetWrapLength(-1); frame->AddFrame(lab, new TGLayoutHints(hints,2,2,2,2)); return lab; } //------------------- // AddNamedLabel //------------------- TGLabel* jv_mainframe::AddNamedLabel(TGCompositeFrame* frame, string title, Int_t mode, ULong_t hints) { TGHorizontalFrame *f = new TGHorizontalFrame(frame); AddLabel(f, title, kTextRight); TGLabel *lab = AddLabel(f, string(60, '-'), mode); frame->AddFrame(f, new TGLayoutHints(kLHintsExpandX,2,2,2,2)); return lab; } //------------------- // AddButton //------------------- TGTextButton* jv_mainframe::AddButton(TGCompositeFrame* frame, string text, ULong_t hints) { TGTextButton *b = new TGTextButton(frame, text.c_str()); b->SetTextJustify(36); b->SetMargins(0,0,0,0); b->SetWrapLength(-1); b->Resize(100,22); frame->AddFrame(b, new TGLayoutHints(hints,2,2,2,2)); return b; } //------------------- // AddCheckButton //------------------- TGCheckButton* jv_mainframe::AddCheckButton(TGCompositeFrame* frame, string text, ULong_t hints) { TGCheckButton *b = new TGCheckButton(frame, text.c_str()); b->SetTextJustify(36); b->SetMargins(0,0,0,0); b->SetWrapLength(-1); frame->AddFrame(b, new TGLayoutHints(hints,2,2,2,2)); return b; } //------------------- // AddPictureButton //------------------- TGPictureButton* jv_mainframe::AddPictureButton(TGCompositeFrame* frame, string picture, string tooltip, ULong_t hints) { TGPictureButton *b = new TGPictureButton(frame, gClient->GetPicture(picture.c_str())); if(tooltip.length()>0) b->SetToolTipText(tooltip.c_str()); frame->AddFrame(b, new TGLayoutHints(hints,2,2,2,2)); return b; } //------------------- // AddSpacer //------------------- TGFrame* jv_mainframe::AddSpacer(TGCompositeFrame* frame, UInt_t w, UInt_t h, ULong_t hints) { /// Add some empty space. Usually, you'll only want to set w or h to /// reserve width or height pixels and set the other to "1". TGFrame *f = new TGFrame(frame, w, h); frame->AddFrame(f, new TGLayoutHints(hints ,2,2,2,2)); return f; } //------------------- // AddListBox //------------------- TGListBox* jv_mainframe::AddListBox(TGCompositeFrame* frame, string lab, UInt_t w, ULong_t hints) { if(lab != "") AddLabel(frame, lab); TGListBox *lb = new TGListBox(frame); frame->AddFrame(lb, new TGLayoutHints(hints ,2,2,2,2)); lb->SetWidth(w); return lb; } //------------------- // CreateGUI //------------------- void jv_mainframe::CreateGUI(void) { // Use the "color wheel" rather than the classic palette. TColor::CreateColorWheel(); //============================================================================================== // make a menubar // Create menubar and popup menus. The hint objects are used to place // and group the different menu widgets with respect to eachother. TGMenuBar *fMenuBar; TGPopupMenu *fMenuFile, *fMenuTools, *fMenuView; TGLayoutHints *fMenuBarLayout, *fMenuBarItemLayout; fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX); fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0); fMenuFile = new TGPopupMenu(gClient->GetRoot()); fMenuFile->AddEntry("&Open List...", M_FILE_OPEN); fMenuFile->AddEntry("&Save List...", M_FILE_SAVE); fMenuFile->AddSeparator(); fMenuFile->AddEntry("New Configuration...", M_FILE_NEW_CONFIG); fMenuFile->AddEntry("Open Configuration...", M_FILE_OPEN_CONFIG); fMenuFile->AddEntry("Save Configuration", M_FILE_SAVE_CONFIG); fMenuFile->AddEntry("Save Configuration As ...", M_FILE_SAVE_AS_CONFIG); fMenuFile->AddEntry("E&xit", M_FILE_EXIT); fMenuTools = new TGPopupMenu(gClient->GetRoot()); fMenuTools->AddEntry("Config Macros...", M_TOOLS_MACROS); fMenuTools->AddEntry("Start TBrowser", M_TOOLS_TBROWSER); fMenuTools->AddEntry("View Tree Info", M_TOOLS_TREEINFO); fMenuTools->AddEntry("Save Hists...", M_TOOLS_SAVEHISTS); fMenuTools->AddSeparator(); fMenuTools->AddEntry("Reset Histograms/Macros...", M_TOOLS_RESET); fMenuView = new TGPopupMenu(gClient->GetRoot()); fMenuView->AddEntry("New Tab...", M_VIEW_NEW_TAB); fMenuView->AddEntry("Remove Tab...", M_VIEW_REMOVE_TAB); fMenuView->AddSeparator(); fMenuView->AddEntry("Log X axis", M_VIEW_LOGX); fMenuView->AddEntry("Log Y axis", M_VIEW_LOGY); fMenuView->AddEntry("Scale Options...", M_VIEW_SCALE_OPTS); fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame | kRaisedFrame ); this->AddFrame(fMenuBar, fMenuBarLayout); fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout); fMenuBar->AddPopup("&Tools", fMenuTools, fMenuBarItemLayout); fMenuBar->AddPopup("&View", fMenuView, fMenuBarItemLayout); // connect the menus to methods // Menu button messages are handled by the main frame (i.e. "this") // HandleMenu() method. fMenuFile->Connect("Activated(Int_t)", "jv_mainframe", this, "HandleMenu(Int_t)"); fMenuTools->Connect("Activated(Int_t)", "jv_mainframe", this, "HandleMenu(Int_t)"); fMenuView->Connect("Activated(Int_t)", "jv_mainframe", this, "HandleMenu(Int_t)"); //============================================================================================== // Fill in main content of window. Note that most of the area is taken up by the // contents of the TGTab object which is filled in by the RSTab class constructor. // Main vertical frame TGVerticalFrame *fMain = new TGVerticalFrame(this); this->AddFrame(fMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2)); // Top, middle(tabs), and bottom frames TGHorizontalFrame *fMainTop = new TGHorizontalFrame(fMain); TGHorizontalFrame *fMainMid = new TGHorizontalFrame(fMain); TGHorizontalFrame *fMainBot = new TGHorizontalFrame(fMain); fMain->AddFrame(fMainTop, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2)); fMain->AddFrame(fMainMid, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX | kLHintsExpandY,2,2,2,2)); fMain->AddFrame(fMainBot, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2)); //....... Top Frame ....... TGGroupFrame *fInfo = new TGGroupFrame(fMainTop, "Current Event Info ", kVerticalFrame); fMainTop->AddFrame(fInfo, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX | kLHintsExpandY,2,2,2,2)); lSource = AddNamedLabel(fInfo, "Source: "); lRun = AddNamedLabel(fInfo, " Run: "); lEvent = AddNamedLabel(fInfo, " Event: "); TGVerticalFrame *fNavframe = new TGVerticalFrame(fMainTop); fMainTop->AddFrame(fNavframe, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2)); TGHorizontalFrame *fNavigation = new TGHorizontalFrame(fNavframe); fNavframe->AddFrame(fNavigation, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2)); bGo = AddButton(fNavigation, "Go "); bStop = AddButton(fNavigation, "Stop "); TGButton *bNext = AddButton(fNavigation, "Next "); DoStop(); TGHorizontalFrame *fWireIDstart = new TGHorizontalFrame(fNavframe); fNavframe->AddFrame(fWireIDstart, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2)); TGButton *bWireFirst = AddButton(fWireIDstart, " |< "); TGButton *bWirePrev = AddButton(fWireIDstart, " < "); TGButton *bWireNext = AddButton(fWireIDstart, " > "); TGButton *bWireLast = AddButton(fWireIDstart, " >| "); //....... Middle Frame ....... fTab = new TGTab(fMainMid); fMainMid->AddFrame(fTab, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2)); fTab->SetWidth(1200); // ---- f125waveforms Tab ---- TGCompositeFrame *t125Waveforms = fTab->AddTab("f125 Waveforms "); canvasf125 = new TRootEmbeddedCanvas("rec1", t125Waveforms, 1600, 800); canvasf125->GetCanvas()->SetFillColor(TColor::GetColor( (Float_t)0.96, 0.96, 0.99)); t125Waveforms->AddFrame(canvasf125, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2)); // ---- f250waveforms Tab ---- TGCompositeFrame *t250Waveforms = fTab->AddTab("f250 Waveforms "); canvasf250 = new TRootEmbeddedCanvas("rec1", t250Waveforms, 1600, 800); canvasf250->GetCanvas()->SetFillColor(TColor::GetColor( (Float_t)0.96, 0.99, 0.96)); t250Waveforms->AddFrame(canvasf250, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2)); //....... Bottom Frame ....... TGTextButton *bQuit = AddButton(fMainBot, "Quit ", kLHintsRight | kLHintsBottom); //==================== Connect GUI elements to methods ==================== bQuit->Connect("Clicked()","jv_mainframe", this, "DoQuit()"); bGo->Connect("Clicked()","jv_mainframe", this, "DoGo()"); bStop->Connect("Clicked()","jv_mainframe", this, "DoStop()"); bNext->Connect("Clicked()","jv_mainframe", this, "DoNext()"); bWireFirst->Connect("Clicked()","jv_mainframe", this, "DoWireFirst()"); bWireNext->Connect("Clicked()","jv_mainframe", this, "DoWireNext()"); bWirePrev->Connect("Clicked()","jv_mainframe", this, "DoWirePrev()"); bWireLast->Connect("Clicked()","jv_mainframe", this, "DoWireLast()"); } //------------------- // Make125Histos //------------------- void jv_mainframe::Make125Histos(int Nbins) { cout << "Making f125 histograms with " << Nbins << " bins ...." << endl; for(int i=0; i<144; i++){ char hname[256]; char title[256]; sprintf(hname, "fmwpc_wire%03d", i); sprintf(title, "FMWPC wire %d;sample (8ns);amplitude (~0.122mV)", i); auto h = new TH1I(hname, title, Nbins, 0.0, (float)Nbins); h->GetYaxis()->SetRangeUser(1.0, 8000.0); h->SetLineColor(kBlue); hfmwpc.push_back( h ); h = (TH1I*)h->Clone(hname); sprintf(hname, "fmwpc_wire%03d_subtracted", i); h->SetLineColor(kMagenta); hfmwpc_subtracted.push_back( h ); } } //------------------- // Make250Histos //------------------- void jv_mainframe::Make250Histos(int Nbins) { cout << "Making f250 histograms with " << Nbins << " bins ...." << endl; for(int i=0; i<4; i++){ char hname[256]; string title; sprintf(hname, "paddles_chan%03d", i); switch(i){ case 0: title = "PMT downstream, bottom"; break; case 1: title = "PMT upstream, bottom"; break; case 2: title = "PMT downstream, top"; break; case 3: title = "PMT upstream, top"; break; } auto h = new TH1I(hname, title.c_str(), Nbins, 0.0, (float)Nbins); h->SetXTitle("sample (4ns)"); h->SetYTitle("amplitude"); h->GetYaxis()->SetRangeUser(0.0, 2500.0); hpaddles.push_back( h ); char fname[256]; sprintf(fname, "fpaddles_chan%03d", i); auto f = new TF1(fname, "[0]*TMath::Landau(x,[1],[2], kTRUE)+[3]"); f->SetParName(0, "amplitude"); f->SetParName(1, "time"); f->SetParName(2, "width"); f->SetParName(3, "pedestal"); fpaddles.push_back( f ); } }