Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:57

0001 // example.C
0002 #include <TGClient.h>
0003 #include <TCanvas.h>
0004 #include <TF1.h>
0005 #include <TRandom.h>
0006 #include <TGButton.h>
0007 #include <TGButtonGroup.h>
0008 #include <TGTextEntry.h>
0009 #include <TGFrame.h>
0010 #include <TGLabel.h>
0011 #include <TGFileDialog.h>
0012 #include <TRootEmbeddedCanvas.h>
0013 #include <RQ_OBJECT.h>
0014 #include "PlotAllDisplay.h"
0015 #include "HistoManager.h"
0016 
0017 #include <string.h>
0018 #include <sys/types.h>
0019 #include <sys/stat.h>
0020 
0021 class PlotAllMenu {
0022   RQ_OBJECT("PlotAllMenu")
0023     private:
0024   TGMainFrame *fMain;
0025   TRootEmbeddedCanvas *fEcanvas;
0026   TGRadioButton* fET[HistoManager::NUMEVTTYPES];
0027   TGRadioButton* fFT[HistoManager::NUMHISTTYPES];
0028   TGRadioButton* fVT[2];
0029   TGRadioButton* fTBT[2];
0030   TGRadioButton* fDoE[1];
0031   TGCheckButton *checkbut,*elecbut,*topbut;
0032   TGTextEntry* iphiEntry, *ietaEntry, *runnoEntry, * fiberEntry, *fiberChanEntry, *crateEntry, *SlotEntry;
0033   PlotAllDisplay* theDisplay;
0034   const char *username_;
0035 public:
0036   PlotAllMenu(const TGWindow *p,UInt_t w,UInt_t h, const char *username);
0037   virtual ~PlotAllMenu();
0038   void DoSelector();
0039   void DoCrateSelector();
0040   void DoDraw();
0041   void DoBrowse();
0042   void DoProcessRunNumber();
0043 };
0044 
0045 PlotAllMenu::PlotAllMenu(const TGWindow *p,UInt_t w,UInt_t h,
0046              const char *username) {
0047   theDisplay=0;
0048   // Create a main frame
0049   fMain = new TGMainFrame(p,w,h);
0050 
0051   /***************************************************************
0052    * Create a vertical frame widget for File Selection objects   *
0053    ***************************************************************/
0054 
0055   TGGroupFrame* fileselgf=new TGGroupFrame(fMain,"File Selection",kVerticalFrame);
0056   fileselgf->SetLayoutManager(new TGMatrixLayout(fileselgf,0,2,5,5));
0057 
0058   // first row
0059   TGTextButton *processrn = new TGTextButton(fileselgf,"Process");
0060   processrn->Connect("Clicked()","PlotAllMenu",this,"DoProcessRunNumber()");
0061   fileselgf->AddFrame(processrn, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
0062 
0063   TGHorizontalFrame *hframe1 = new TGHorizontalFrame(fileselgf,200,40);
0064   hframe1->AddFrame(new TGLabel(hframe1," Run Number "));
0065   runnoEntry=new TGTextEntry(hframe1,"12345   ");
0066   hframe1->AddFrame(runnoEntry);
0067 
0068   fileselgf->AddFrame(hframe1, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
0069 
0070   // second row
0071   fileselgf->AddFrame(new TGLabel(fileselgf," or "));
0072   fileselgf->AddFrame(new TGLabel(fileselgf," "));
0073 
0074   // third row
0075   TGTextButton *browse = new TGTextButton(fileselgf,"Browse for file...");
0076   browse->Connect("Clicked()","PlotAllMenu",this,"DoBrowse()");
0077   fileselgf->AddFrame(browse, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
0078   checkbut = new TGCheckButton(fileselgf,"Force re-processing");
0079   fileselgf->AddFrame(checkbut, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
0080 
0081   fMain->AddFrame(fileselgf, new TGLayoutHints(kLHintsCenterX,2,2,2,2));
0082 
0083   /*************************************************************************
0084    * Create a vertical frame widget for Plot parameter Selection objects   *
0085    *************************************************************************/
0086 
0087   TGGroupFrame* plotselgf=new TGGroupFrame(fMain,"Plot Selection",kHorizontalFrame);
0088   //plotselgf->SetLayoutManager(new TGMatrixLayout(plotselgf,0,2,5,5));
0089 
0090   // first row:
0091   // Create Selection widget
0092   
0093   TGButtonGroup* ebg=new TGButtonGroup(plotselgf,"Event Type",kVerticalFrame);
0094   
0095   fET[0]=new TGRadioButton(ebg,"Other");
0096   fET[1]=new TGRadioButton(ebg,"Pedestal");
0097   fET[2]=new TGRadioButton(ebg,"LED");
0098   fET[3]=new TGRadioButton(ebg,"Laser");
0099   fET[4]=new TGRadioButton(ebg,"Beam");  
0100 
0101   plotselgf->AddFrame(ebg, new TGLayoutHints(kLHintsCenterX));  // ,5,5,3,4));
0102 
0103   TGButtonGroup* fbg=new TGButtonGroup(plotselgf,"Flavor Type",kVerticalFrame);
0104   fFT[0]=new TGRadioButton(fbg,"Energy");
0105   fFT[1]=new TGRadioButton(fbg,"Time");
0106   fFT[2]=new TGRadioButton(fbg,"Pulse Shape");
0107   fFT[3]=new TGRadioButton(fbg,"ADC");
0108 
0109   plotselgf->AddFrame(fbg, new TGLayoutHints(kLHintsCenterX)); // ,5,5,3,4));
0110 
0111   TGButtonGroup* vssbg=new TGButtonGroup(plotselgf,"VS Plot Stat",kHorizontalFrame);
0112   fVT[0]=new TGRadioButton(vssbg,"Mean");
0113   fVT[1]=new TGRadioButton(vssbg,"RMS");
0114 
0115   plotselgf->AddFrame(vssbg, new TGLayoutHints(kLHintsCenterX)); // ,5,5,3,4));
0116 
0117   fMain->AddFrame(plotselgf);
0118 
0119   TGGroupFrame* gf=new TGGroupFrame(fMain,"Channel Selection",kVerticalFrame);
0120   gf->SetLayoutManager(new TGMatrixLayout(gf,0,2,10,10));
0121   gf->AddFrame(new TGLabel(gf," IPhi "));
0122   iphiEntry=new TGTextEntry(gf,"0   ");
0123   gf->AddFrame(iphiEntry);
0124   gf->AddFrame(new TGLabel(gf," IEta "));
0125   ietaEntry=new TGTextEntry(gf,"0   ");
0126   gf->AddFrame(ietaEntry);
0127   TGTextButton *selector = new TGTextButton(gf,"Visual Selector");
0128   selector->Connect("Clicked()","PlotAllMenu",this,"DoSelector()");
0129   gf->AddFrame(selector,new TGLayoutHints(kLHintsCenterX,5,5,3,4));
0130   
0131  fMain->AddFrame(gf);
0132   
0133 
0134   TGGroupFrame* ef=new TGGroupFrame(fMain,"Electronics Selection",kVerticalFrame);
0135   ef->SetLayoutManager(new TGMatrixLayout(ef,0,4,10,10));
0136   
0137   
0138  elecbut = new TGCheckButton(ef,"Use ElecId");
0139   ef->AddFrame(elecbut, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
0140   ef->AddFrame(new TGLabel(ef,""));
0141 
0142    
0143   ef->AddFrame(new TGLabel(ef," Fiber "));
0144   fiberEntry=new TGTextEntry(ef,"-1  ");
0145   ef->AddFrame(fiberEntry);
0146   ef->AddFrame(new TGLabel(ef," Fiber Chan"));
0147   fiberChanEntry=new TGTextEntry(ef,"-1  ");
0148   ef->AddFrame(fiberChanEntry);
0149   ef->AddFrame(new TGLabel(ef," Crate "));
0150   crateEntry=new TGTextEntry(ef," 2 ");
0151   ef->AddFrame(crateEntry);
0152   ef->AddFrame(new TGLabel(ef," HTR FPGA "));
0153   SlotEntry=new TGTextEntry(ef,"16b  ");
0154   ef->AddFrame(SlotEntry);
0155 
0156 #if 0
0157   TGButtonGroup* topbot=new TGButtonGroup(ef,"Top or Bottom",kHorizontalFrame);
0158   fTBT[0]=new TGRadioButton(topbot,"Bottom");
0159   fTBT[1]=new TGRadioButton(topbot,"Top");
0160 
0161   ef->AddFrame(topbot, new TGLayoutHints(kLHintsCenterX));
0162 #endif
0163 
0164  TGTextButton *CrateSelector = new TGTextButton(ef,"Visual Selector");
0165  CrateSelector->Connect("Clicked()","PlotAllMenu",this,"DoCrateSelector()");
0166   ef->AddFrame(CrateSelector,new TGLayoutHints(kLHintsCenterX,5,5,3,4));
0167   
0168   
0169     fMain->AddFrame(ef);
0170  
0171  // Create a horizontal frame widget with buttons
0172   TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain,200,40);
0173 
0174   TGTextButton *draw = new TGTextButton(hframe,"&Draw");
0175   draw->Connect("Clicked()","PlotAllMenu",this,"DoDraw()");
0176   hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
0177 
0178 
0179   TGTextButton *exit = new TGTextButton(hframe,"&Exit",
0180                     "gApplication->Terminate(0)");
0181   hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
0182   fMain->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX,2,2,2,2));
0183   // Set a name to the main frame
0184   fMain->SetWindowName("Plot Menu for HCAL");
0185   // Map all subwindows of main frame
0186   fMain->MapSubwindows();
0187   // Initialize the layout algorithm
0188   fMain->Resize(fMain->GetDefaultSize());
0189   // Map main frame
0190   fMain->MapWindow();
0191 
0192   username_ = username;
0193 }
0194 
0195 void PlotAllMenu::DoSelector() {
0196 
0197   int iev=0;
0198   int ifl=0;
0199   int ipstat=0;
0200   for(int i=0; i<HistoManager::NUMEVTTYPES; i++) {
0201     if (fET[i]->IsOn()) iev=i;
0202     if (i<HistoManager::NUMHISTTYPES && fFT[i]->IsOn()) ifl=i;  
0203     if (i<2 && fVT[i]->IsOn()) ipstat=i;
0204   }
0205   theDisplay->displaySelector(iev,ifl,ipstat);
0206 }
0207 
0208 void PlotAllMenu::DoCrateSelector() {
0209 
0210   int iev=0;
0211   int ifl=0;
0212   int ipstat=0;
0213   for(int i=0; i<HistoManager::NUMEVTTYPES; i++) {
0214     if (fET[i]->IsOn()) iev=i;
0215     if (i<HistoManager::NUMHISTTYPES && fFT[i]->IsOn()) ifl=i;  
0216     if (i<2 && fVT[i]->IsOn()) ipstat=i;
0217   }
0218   
0219   int crate = atoi(crateEntry->GetText());
0220   if (crate ==-1){std::cout<<"Please enter a crate number to use Electronics Visual Selector"<<std::endl;
0221   }else{
0222     theDisplay->CrateDisplaySelector(crate,iev,ifl,ipstat);}
0223 }
0224 
0225 
0226 void PlotAllMenu::DoDraw() {
0227   int iev=0;
0228   int ifl=0;
0229   for (int i=0; i<HistoManager::NUMEVTTYPES; i++) {
0230     if (fET[i]->IsOn()) iev=i;
0231     if (i<HistoManager::NUMHISTTYPES && fFT[i]->IsOn()) ifl=i;
0232   }
0233 
0234   int ieta=atoi(ietaEntry->GetText());
0235   int iphi=atoi(iphiEntry->GetText());
0236   int fiber=atoi(fiberEntry->GetText());
0237   int fiberChan=atoi(fiberChanEntry->GetText());
0238   int crate=atoi(crateEntry->GetText());
0239 
0240   int slot=0,tb=0;
0241   char tbc='t';
0242   sscanf(SlotEntry->GetText(),"%d%c",&slot,&tbc);
0243 
0244   if (tbc=='t'){tb=1;}else{tb=0;}
0245 
0246 
0247   if(!elecbut->IsOn()){
0248     if (ieta==0 || iphi==0) {
0249       theDisplay->displaySummary(ieta,iphi,iev,ifl);
0250     } else {
0251       theDisplay->displayOne(ieta,iphi,1,iev,ifl);
0252     }
0253   }else {
0254     if (fiber==-1||fiberChan==-1){
0255      
0256       theDisplay->displayElecSummary(crate,slot,tb,iev,ifl);
0257     }else{
0258       theDisplay->displayElecOne(fiber,fiberChan,crate,slot,tb,iev,ifl);
0259     }
0260   }
0261 }
0262 static const char *filetypes[] = { "POOL files",    "*.root", 0,  0 };
0263 
0264 void PlotAllMenu::DoBrowse() {
0265   char line[1200];
0266   char outfn[1200];
0267 
0268   static TString dir(".");
0269   TGFileInfo fi;
0270   fi.fFileTypes = filetypes;
0271   fi.fIniDir    = StrDup(dir);
0272   new TGFileDialog(gClient->GetRoot(), fMain, kFDOpen, &fi);
0273 
0274   // Compose temporary root output filename
0275   strcpy(line,fi.fFilename);
0276   *(strstr(line,".root")) = 0;         // null out ".root" suffix
0277 
0278  // get rid of path prefix, put it in tmp
0279   char *fn=strrchr(line,'/');
0280   if (fn != NULL)
0281     sprintf (outfn,"/tmp/%s.%s.plotall.root", fn+1, username_);
0282   else
0283     sprintf (outfn,"/tmp/%s.%s.plotall.root", fi.fFilename, username_);
0284 
0285   struct stat buf;
0286   if (!checkbut->IsOn() &&
0287       !stat(outfn,&buf)) {
0288     std::cout << "File already processed, loading results." << std::endl;
0289   }
0290   else {
0291     std::cout << "Processing..." << std::endl;
0292     sprintf(line,".! ./runCMSSWReco.sh %s %s",fi.fFilename, outfn);
0293     gROOT->ProcessLine(line);
0294     std::cout << "Done." << std::endl;
0295   }
0296 
0297   if (theDisplay!=0) delete theDisplay;
0298   theDisplay=new PlotAllDisplay(outfn);
0299   
0300   dir = fi.fIniDir;
0301 }
0302 
0303 void PlotAllMenu::DoProcessRunNumber() {
0304   char line[1200];
0305   char outfn[1200];
0306   int runno=atoi(runnoEntry->GetText());
0307 
0308   // Compose temporary root output filename
0309   sprintf (outfn,"/tmp/%s.%d.plotall.root", username_,runno);
0310 
0311   struct stat buf;
0312   if (!checkbut->IsOn() &&
0313       !stat(outfn,&buf)) {
0314     std::cout << "File already processed, loading results." << std::endl;
0315   }
0316   else {
0317     std::cout << "Processing..." << std::endl;
0318     sprintf(line,".! ./runCMSSWReco.sh %d %s",runno, outfn);
0319     gROOT->ProcessLine(line);
0320     std::cout << "Done." << std::endl;
0321   }
0322 
0323   if (theDisplay!=0) delete theDisplay;
0324   theDisplay=new PlotAllDisplay(outfn);
0325 }
0326 
0327 PlotAllMenu::~PlotAllMenu() {
0328   // Clean up used widgets: frames, buttons, layouthints
0329   fMain->Cleanup();
0330   delete fMain;
0331 }