LMD/TFndLmdMonFrame.cxx

00001 // @(#)fROOT/LMD:$Name:  $:$Id: TFndLmdMonFrame.cxx,v 1.25 2007/09/24 07:32:41 Diego_Faso Exp $
00002 // Revision Author: Diego Faso <mailto:faso@to.infn.it>, 2005/06/24
00003 // Original Author: Piergiorgio Cerello <mailto:cerello@to.infn.it>
00004 
00006 //     GUI Monitor frame for the FINUDA Low Mass Drift Chambers' monitoring                //
00007 //                                                                                         //
00008 //                                                                                         //
00009 //  - Both online and offline mode are available (se constructors)                         //
00010 //  - Shared memories (TMapFile) are used for the online monitoring, while the "offline"   //
00011 //    histogram filling reads files directly (files are produced by the "geb2hdt" macro).  //
00012 //                                                                                         //
00013 //   (see GTS relative class for descriptions)                                             //
00014 //                                                                                         //
00016 
00017 #include <TSystem.h>
00018 #include <TStyle.h>
00019 
00020 #include "TFndLmdMonFrame.h" 
00021 #include "TFndRun.h" 
00022 
00023 ClassImp(TFndLmdMonFrame)
00024 
00025 //____________________________________________________
00026 TFndLmdMonFrame::TFndLmdMonFrame(TString filename):TFndMonFrame(filename),fIO(),fdch(),fwir(),maps(),iadc(),itdc(),oadc(),otdc(),fInnPad(),fOutPad(),fMultPad(),fWirePad(),fAllPad(),fChSelBut(),fAllButton(),fWireBut(),zoombutton(),fhists(),h2(),sly(),fWhichGroup(-1),fAllId(-1)
00027 {
00028   // the button highlight color can be different for the 2 layers
00029   // All colors are customizable
00030 
00031   Init();
00032 }
00033 
00034 //____________________________________________________
00035 void TFndLmdMonFrame::Init() {
00036 
00037   //   fCheckedHistos = new TObjArray(1000);
00038   SetStyle();
00039   fHighlightCol[0] = 5;
00040   fHighlightCol[1] = 5;
00041   //   fSHMEntries = 0;
00042   //   time_t now;
00043   //   now = time(&now);
00044   //   fTime = now;
00045   //   cout << "Time is: " << fTime << " in TFndLmdMonFrame::Init()" << endl;
00046   
00047   //  fndrun->SetLmdMonFrame(this);
00048   //  if(!fCanStartGUI){
00049   //    Warning("Init()","Can't start GUI interface");
00050   //    return;
00051   //  }
00052   //  StartInterface();
00053 }
00054 
00055 //____________________________________________________
00056 void TFndLmdMonFrame::Open() {
00057 
00058   if(!fClosed) return;
00059   if(!StartInterface()) return;
00060   fClosed = kFALSE;
00061 }
00062 
00063 //____________________________________________________
00064 Bool_t TFndLmdMonFrame::StartInterface() {
00065   // The GUI interface is built (including sub-pads and buttons) 
00066   // Shared memories are open if you are working online
00067   // Files have been already opened if you are working offline
00068 
00069   Int_t BackgroundCol = 12;
00070   Int_t DisplayPadCol = 15;
00071 
00072   Float_t sep = 0.001;
00073   Float_t smallsep = 0.0005;
00074 
00075   Float_t Start_X_displaypad = 0.08;
00076   Float_t Stop_X_displaypad  = 1.;
00077   Float_t Start_Y_displaypad = 0.05;
00078   Float_t Stop_Y_displaypad  = 0.94;
00079 
00080   Float_t MultInn_Y_Edge = 0.11;
00081   Float_t InnOutEdge = ((Stop_Y_displaypad-sep)+(MultInn_Y_Edge+smallsep))/2;
00082 
00083   // Stop here if no source file was found
00084   if(!fCanStartGUI) return kFALSE;
00085 
00086 
00087   fdch=1;
00088   fwir=1;
00089   // shared memories used only in "online-mode"
00090   ReloadMapFiles();
00091   //   fCanStartGUI = ReloadMapFiles();
00092   //   if(!fCanStartGUI) return;
00093   
00094   if (fRF)  Printf("TFndLmdMonFrame::StartInterface ---> source file found...starting GUI");
00095 
00096   // ---
00097   // main canvas
00098   //  Int_t xsize = 1050;
00099   //  Int_t ysize =  700;
00100   //  Int_t x0 = 150;
00101   //  Int_t y0 = 0;
00102   fMainCanvas[0] = new TCanvas("Lmd_MainCanvas","LMD Detector Display",
00103                                fMainCanvCoord[0],fMainCanvCoord[1],
00104                                fMainCanvCoord[2],fMainCanvCoord[3]);
00105   SetMonitorTitle(0,"LMD");
00106   fMainCanvas[0]->SetEditable(kFALSE);
00107   //  fMainCanvas[0]->ToggleEventStatus();
00108   fMainCanvas[0]->SetFillColor(BackgroundCol);
00109   fMainCanvas[0]->Draw();
00110   
00111   // Display pad
00112   fMainCanvas[0]->cd();
00113   fDisplayPad[0] = new TPad("LmdMonFrameDisplayPad","hist display",
00114                          Start_X_displaypad+sep,Start_Y_displaypad+sep,Stop_X_displaypad,Stop_Y_displaypad);
00115   fDisplayPad[0]->Draw();
00116   fDisplayPad[0]->SetFillColor(DisplayPadCol);
00117   fDisplayPad[0]->SetBorderSize(2);
00118 
00119   // Bottom pad
00120   fAllPad = new TPad("lmd_AllPadControl","lmd_AllPadControl",Start_X_displaypad+sep,0.,Stop_X_displaypad,Start_Y_displaypad-sep);
00121   fAllPad->Draw();
00122 
00123   // Left pad
00124   fMultPad = new TPad("mulLmdSelPad","mulLmdSelPad",0.,0.,Start_X_displaypad-sep,MultInn_Y_Edge-smallsep);
00125   fMultPad->SetFillColor(13);
00126   fMultPad->Draw();
00127   fInnPad = new TPad("iLmdSelPad","iLmdSelPad",0.,MultInn_Y_Edge+smallsep,Start_X_displaypad-sep,InnOutEdge-smallsep);
00128   fInnPad->SetFillColor(13);
00129   fInnPad->Draw();
00130   fOutPad = new TPad("oLmdSelPad","oLmdSelPad",0.,InnOutEdge+smallsep,Start_X_displaypad-sep,0.94);
00131   fOutPad->SetFillColor(13);
00132   fOutPad->Draw();
00133 
00134   //  Control Pads
00135   fMainCanvas[0]->cd();
00136   fWirePad = new TPad("selectwire","wr",0.,Stop_Y_displaypad+sep,1.,1.);
00137   fWirePad->SetFillColor(BackgroundCol);
00138   fWirePad->Draw();
00139 
00140   DrawButtons();
00141   BuildConnections();
00142 
00143   fAllPad->SetEditable(kFALSE);
00144   fMultPad->SetEditable(kFALSE);
00145   fInnPad->SetEditable(kFALSE);
00146   fOutPad->SetEditable(kFALSE);
00147 
00148   return kTRUE;
00149   //  fClosed = kFALSE;
00150 }
00151 
00152 //____________________________________________________
00153 void TFndLmdMonFrame::DrawButtons() {
00154 
00155   //  cout << "...drawing buttons..." << endl;
00156   Float_t MapWidth = 0.08;
00157 
00158   Float_t step = (1-MapWidth)/8.;
00159   Float_t xi = 0.;
00160   Float_t xf = MapWidth;
00161   //cout << "   -> ALL (bottom-pad)" << endl;
00162   fAllPad->cd();
00163   fAllButton[0] = new TButton("Maps","fndrun->LmdMonFrame()->DisplayMaps();",xi,0.,xf,1.);
00164   fAllButton[0]->SetTextSize(0.5);
00165   fAllButton[0]->Draw();
00166   xi = xf;
00167   xf += step;
00168   fAllButton[1] = new TButton("i_eff","fndrun->LmdMonFrame()->DisplayAllHist(0,0);",xi,0.,xf,1.);
00169   fAllButton[1]->SetTextSize(0.5);
00170   fAllButton[1]->Draw();
00171   xi = xf;
00172   xf += step;
00173   fAllButton[2] = new TButton("o_eff","fndrun->LmdMonFrame()->DisplayAllHist(1,0);",xi,0.,xf,1.);
00174   fAllButton[2]->SetTextSize(0.5);
00175   fAllButton[2]->Draw();
00176   xi = xf;
00177   xf += step;
00178   fAllButton[3] = new TButton("i_adcs","fndrun->LmdMonFrame()->DisplayAllHist(0,1);",xi,0.,xf,1.);
00179   fAllButton[3]->SetTextSize(0.5);
00180   fAllButton[3]->Draw();
00181   xi = xf;
00182   xf += step;
00183   fAllButton[4] = new TButton("o_adcs","fndrun->LmdMonFrame()->DisplayAllHist(1,1);",xi,0.,xf,1.);
00184   fAllButton[4]->SetTextSize(0.5);
00185   fAllButton[4]->Draw();
00186   xi = xf;
00187   xf += step;
00188   fAllButton[5] = new TButton("i_tdcs","fndrun->LmdMonFrame()->DisplayAllHist(0,2);",xi,0.,xf,1.);
00189   fAllButton[5]->SetTextSize(0.5);
00190   fAllButton[5]->Draw();
00191   xi = xf;
00192   xf += step;
00193   fAllButton[6] = new TButton("o_tdcs","fndrun->LmdMonFrame()->DisplayAllHist(1,2);",xi,0.,xf,1.);
00194   fAllButton[6]->SetTextSize(0.5);
00195   fAllButton[6]->Draw();
00196   xi = xf;
00197   xf += step;
00198   fAllButton[7] = new TButton("i_adc_tdc","fndrun->LmdMonFrame()->DisplayAllHist(0,3);",xi,0.,xf,1.);
00199   fAllButton[7]->SetTextSize(0.5);
00200   fAllButton[7]->Draw();
00201   xi = xf;
00202   xf += step;
00203   fAllButton[8] = new TButton("o_adc_tdc","fndrun->LmdMonFrame()->DisplayAllHist(1,3);",xi,0.,xf,1.);
00204   fAllButton[8]->SetTextSize(0.5);
00205   fAllButton[8]->Draw();
00206 
00207   //cout << "   -> PEDESTAL [fMultPad] (bottom-left-pad)" << endl;
00208   fMultPad->cd();
00209   fAllButton[9] = new TButton("i_mul","fndrun->LmdMonFrame()->DisplayAllHist(0,4);",0.,0.,1.0,0.5);
00210   fAllButton[9]->Draw();
00211   fAllButton[10] = new TButton("o_mul","fndrun->LmdMonFrame()->DisplayAllHist(1,4);",0.,0.5,1.0,1.);
00212   fAllButton[10]->Draw();
00213 
00214   fAllPad->Modified();
00215   // ---
00216   //cout << "   -> INNER LMDs Pad [fInnPad] (left-pad)" << endl;
00217   fInnPad->cd();
00218   for(Int_t i=0;i<8;i++) {
00219     TString str1 = TString("fndrun->LmdMonFrame()->SelectChamber(0,");
00220     TString modlab = TString("i_");
00221     modlab+=i+1;
00222     str1+=i+1;
00223     str1+="); ";
00224     str1+="fndrun->LmdMonFrame()->DrawWirePad();";
00225     //cout << "      -> fChSelBut[" << i << "] : " << modlab.Data() << " -> " << str1.Data() << endl;
00226     fChSelBut[i] = new TButton(modlab.Data(),str1.Data(),0.00,0.125*i,1.0,0.125*(i+1));
00227     fChSelBut[i]->Draw();
00228   }
00229   fInnPad->Modified();
00230   // ---
00231   //cout << "   -> OUTER LMDs Pad [fOutPad] (left-pad)" << endl;
00232   fOutPad->cd();
00233   for(Int_t i=0;i<8;i++) {
00234     TString str1 = TString("fndrun->LmdMonFrame()->SelectChamber(1,");
00235     TString modlab = TString("o_");
00236     modlab+=i+1;
00237     str1+=i+1;
00238     str1+=");";
00239     str1+="fndrun->LmdMonFrame()->DrawWirePad();";
00240     //cout << "      -> fChSelBut[" << i+8 << "] : " << modlab.Data() << " -> " << str1.Data() << endl;
00241     fChSelBut[i+8] = new TButton(modlab.Data(),str1.Data(),0.00,0.125*i,1.0,0.125*(i+1));
00242     fChSelBut[i+8]->Draw();
00243   }
00244   fOutPad->Modified();
00245   // ---
00246   //  cout << "Buttons drawing completed." << endl;
00247   RebuildWirePad();
00248   ResetFrameColors();
00249 }
00250 
00251 //____________________________________________________
00252 TFndLmdMonFrame::~TFndLmdMonFrame() {
00253    if(!fClosed) Close();
00254 }
00255 
00256 //____________________________________________________
00257 void TFndLmdMonFrame::Close() {
00258   // the consumer should not close shared memories
00259 
00260   if(!fClosed){
00261     Printf("TFndLmdMonFrame::Close ---> closing and re-initializing to zero all mapfiles...");    
00262     if(maps) { maps->Close(); maps = 0; }
00263     if(iadc) { iadc->Close(); iadc = 0; }
00264     if(itdc) { itdc->Close(); itdc = 0; }
00265     if(oadc) { oadc->Close(); oadc = 0; }
00266     if(otdc) { otdc->Close(); otdc = 0; }
00267     Printf("TFndLmdMonFrame::Close ---> Done.");    
00268     
00269     for(Int_t i=0;i<16;i++) { delete fChSelBut[i]; fChSelBut[i] = 0; }       // LDM num buttons
00270     for(Int_t i=0;i<11;i++) { delete fAllButton[i]; fAllButton[i] = 0; } // bottom pad buttons
00271     
00272     fWirePad->Close();  delete fWirePad; //fWirePad = 0;
00273     fOutPad->Close();   delete fOutPad;  //fOutPad = 0;
00274     fInnPad->Close();   delete fInnPad;  //fInnPad = 0;
00275     fMultPad->Close();  delete fMultPad; //fMultPad = 0;
00276     fAllPad->Close();   delete fAllPad;  //fAllPad = 0;
00277     fDisplayPad[0]->Close(); delete fDisplayPad[0]; fDisplayPad[0] = 0;
00278     fMainCanvas[0]->Close(); delete fMainCanvas[0]; fMainCanvas[0] = 0;
00279   }
00280   fClosed = kTRUE;
00281 }
00282 
00283 //____________________________________________________
00284 Bool_t TFndLmdMonFrame::ReloadMapFiles(){
00285 
00286   Bool_t result = kTRUE;
00287   if(!fIsOnline) return result;
00288 
00289   if( CheckProducerMessages() != 0 ) return kFALSE; // chech if shared memories are busy (producer message)
00290 
00291   TString shr_file_map_name[5] = 0;
00292 
00293 #if defined _FND_ONL_USE_MAP_FILES_
00294   if(fndrun->GetDebug()) Printf("TFndLmdMonFrame::ReloadMapFiles ---> closing and re-initializing to zero all mapfiles...");    
00295   if(maps) { maps->Close(); maps = 0; }
00296   if(iadc) { iadc->Close(); iadc = 0; }
00297   if(itdc) { itdc->Close(); itdc = 0; }
00298   if(oadc) { oadc->Close(); oadc = 0; }
00299   if(otdc) { otdc->Close(); otdc = 0; }
00300   if(fndrun->GetDebug()) Printf("TFndLmdMonFrame::ReloadMapFiles ---> Done");
00301   //
00302   shr_file_map_name[0] = "$FND_SHR/lmd.map";
00303   shr_file_map_name[1] = "$FND_SHR/lmd_i_adc.map";
00304   shr_file_map_name[2] = "$FND_SHR/lmd_i_tdc.map";
00305   shr_file_map_name[3] = "$FND_SHR/lmd_o_adc.map";
00306   shr_file_map_name[4] = "$FND_SHR/lmd_o_tdc.map";
00307 #elif defined _FND_ONL_USE_SHARED_FILES_
00308   if(maps) { if(maps->IsOpen()) maps->Close(); delete maps; maps = 0; }
00309   if(iadc) { if(iadc->IsOpen()) iadc->Close(); delete iadc; iadc = 0; }
00310   if(itdc) { if(itdc->IsOpen()) itdc->Close(); delete itdc; itdc = 0; }
00311   if(oadc) { if(oadc->IsOpen()) oadc->Close(); delete oadc; oadc = 0; }
00312   if(otdc) { if(otdc->IsOpen()) otdc->Close(); delete otdc; otdc = 0; }
00313   //
00314   shr_file_map_name[0] = "$FND_SHR/lmd.file.map";
00315   shr_file_map_name[1] = "$FND_SHR/lmd_i_adc.file.map";
00316   shr_file_map_name[2] = "$FND_SHR/lmd_i_tdc.file.map";
00317   shr_file_map_name[3] = "$FND_SHR/lmd_o_adc.file.map";
00318   shr_file_map_name[4] = "$FND_SHR/lmd_o_tdc.file.map";
00319 #endif
00320   
00321   
00322   if(fndrun->GetDebug()) Printf("TFndLmdMonFrame::ReloadMapFiles ---> Reloading shared memories...");
00323   if(!gSystem->AccessPathName(FROOT::ExpandPathName(shr_file_map_name[0].Data()))){
00324 #if defined _FND_ONL_USE_MAP_FILES_
00325     maps  = TMapFile::Create(FROOT::ExpandPathName(shr_file_map_name[0].Data()),"READ");
00326     if(fndrun->GetDebug()) maps->Print();
00327 #elif defined _FND_ONL_USE_SHARED_FILES_
00328     maps  = new TFile(FROOT::ExpandPathName(shr_file_map_name[0].Data()),"READ");
00329 #endif
00330   }
00331   else result = kFALSE;
00332   
00333   if(!gSystem->AccessPathName(FROOT::ExpandPathName(shr_file_map_name[1].Data()))){
00334 #if defined _FND_ONL_USE_MAP_FILES_
00335     iadc = TMapFile::Create(FROOT::ExpandPathName(shr_file_map_name[1].Data()),"READ");
00336     if(fndrun->GetDebug()) iadc->Print();
00337 #elif defined _FND_ONL_USE_SHARED_FILES_
00338     iadc = new TFile(FROOT::ExpandPathName(shr_file_map_name[1].Data()),"READ");
00339 #endif
00340   }
00341   else result = kFALSE;
00342   
00343   if(!gSystem->AccessPathName(FROOT::ExpandPathName(shr_file_map_name[2].Data()))){
00344 #if defined _FND_ONL_USE_MAP_FILES_
00345     itdc = TMapFile::Create(FROOT::ExpandPathName(shr_file_map_name[2].Data()),"READ");
00346     if(fndrun->GetDebug()) itdc->Print();
00347 #elif defined _FND_ONL_USE_SHARED_FILES_
00348     itdc = new TFile(FROOT::ExpandPathName(shr_file_map_name[2].Data()),"READ");
00349 #endif
00350   }
00351   else result = kFALSE;
00352   
00353   if(!gSystem->AccessPathName(FROOT::ExpandPathName(shr_file_map_name[3].Data()))){
00354 #if defined _FND_ONL_USE_MAP_FILES_
00355     //    oadc = TMapFile::Create(FROOT::ExpandPathName("$FND_SHR/lmd_o_adc.map"),"READ",(Int_t)(1048576*FROOT::K_LmdOadcMapSize));
00356     oadc = TMapFile::Create(FROOT::ExpandPathName(shr_file_map_name[3].Data()),"READ");
00357     if(fndrun->GetDebug()) oadc->Print();
00358 #elif defined _FND_ONL_USE_SHARED_FILES_
00359     oadc = new TFile(FROOT::ExpandPathName(shr_file_map_name[3].Data()),"READ");
00360 #endif
00361   }
00362   else result = kFALSE;
00363   
00364   if(!gSystem->AccessPathName(FROOT::ExpandPathName(shr_file_map_name[4].Data()))){
00365 #if defined _FND_ONL_USE_MAP_FILES_
00366     //    otdc = TMapFile::Create(FROOT::ExpandPathName("$FND_SHR/lmd_o_tdc.map"),"READ",(Int_t)(1048576*FROOT::K_LmdOtdcMapSize));
00367     otdc = TMapFile::Create(FROOT::ExpandPathName(shr_file_map_name[4].Data()),"READ");
00368     if(fndrun->GetDebug()) otdc->Print();
00369 #elif defined _FND_ONL_USE_SHARED_FILES_
00370     otdc = new TFile(FROOT::ExpandPathName(shr_file_map_name[4].Data()),"READ");
00371 #endif
00372   }
00373   else result = kFALSE; 
00374   
00375   if(fndrun->GetDebug()){
00376     if(result) Printf("TFndLmdMonFrame::ReloadMapFiles ---> Done");
00377     else Printf("TFndLmdMonFrame::ReloadMapFiles ---> shared memories not found!");
00378   }
00379   return result;
00380 }
00381 
00382 //____________________________________________________
00383 void TFndLmdMonFrame::ResetFrameColors() {
00384   // All pads and buttons are reset to their default colors
00385   
00386   //cout << "...Resetting default colors..." << endl;
00387   Int_t MultCol = 30;
00388   Int_t ChMapCol = 41;
00389   Int_t ChNumICol = 42;
00390   Int_t ChNumOCol = 44;
00391   Int_t EffCol = 17;
00392   Int_t AdcCol    = 38;
00393   Int_t TdcCol    = 50;
00394   Int_t AdcTdcCol = 29;
00395 
00396   Int_t WireButCol = 42;
00397 
00398   //  fAllPad->cd();
00399   fAllButton[0]->SetFillColor(ChMapCol);
00400   fAllButton[1]->SetFillColor(EffCol);
00401   fAllButton[2]->SetFillColor(EffCol);
00402   fAllButton[3]->SetFillColor(AdcCol);
00403   fAllButton[4]->SetFillColor(AdcCol);
00404   fAllButton[5]->SetFillColor(TdcCol);
00405   fAllButton[6]->SetFillColor(TdcCol);
00406   fAllButton[7]->SetFillColor(AdcTdcCol);
00407   fAllButton[8]->SetFillColor(AdcTdcCol);
00408   fAllButton[9] ->SetFillColor(MultCol);
00409   fAllButton[10]->SetFillColor(MultCol);
00410   for(Int_t i=0;i<11;i++) fAllButton[i]->Modified();
00411   // ---
00412   for(Int_t i=0;i<8;i++){
00413     fChSelBut[i]->SetFillColor(ChNumICol); fChSelBut[i]->Modified(); 
00414     fChSelBut[i+8]->SetFillColor(ChNumOCol); fChSelBut[i+8]->Modified();
00415   }
00416   fWireBut[0]->SetFillColor(50); fWireBut[0]->Modified();
00417   for(Int_t i=1;i<=fNWires;i++) { fWireBut[i]->SetFillColor(WireButCol); fWireBut[i]->Modified(); }
00418   //cout << "...done." << endl;
00419 }
00420 
00421 //____________________________________________________
00422 void TFndLmdMonFrame::SelectChamber(Int_t io, Int_t d){ 
00423   // Set the "fIO" and "fdch" data-members
00424   // and rebuild the wire-pad (without drawing it)
00425 
00426   fIO=io; fdch=d; 
00427   fNWires = 22;
00428   if(fIO == 0) fNWires = 12;
00429   fwir = 0;
00430   RebuildWirePad();
00431   //  gSystem->ProcessEvents();
00432   SelectWire(0);
00433   DisplayHist();
00434 
00435   fWhichGroup = 0;
00436   fAllId = 0;
00437 }
00438 
00439 //____________________________________________________
00440 void TFndLmdMonFrame::RebuildWirePad(){
00441   // all wire-buttons are deleted and rebuilt, but not drawn
00442 
00443   //cout << "Rebuilding wire pad: " << fWirePad << endl;
00444   Int_t WireButCol = 42;
00445   for(Int_t i=0;i<=23;i++) { delete fWireBut[i]; fWireBut[i] = 0;}
00446   fNWires = 22; 
00447   if(fIO == 0) fNWires = 12;
00448 
00449   Float_t xi = 0.;
00450   Float_t step = 1./(fNWires+1);
00451   Float_t xf = step;
00452 
00453   fWirePad->cd(); 
00454   fWireBut[0] = new TButton("All","fndrun->LmdMonFrame()->SelectWire(0);fndrun->LmdMonFrame()->DisplayHist();",xi,0.,xf,1.);
00455   fWireBut[0]->SetFillColor(50);
00456   xi = xf;
00457   xf += step;
00458 
00459   fWirePad->cd();
00460   for(Int_t i=1;i<=fNWires;i++) {
00461     TString str1 = TString("w");
00462     TString str3 = TString("fndrun->LmdMonFrame()->SelectWire(");
00463     str1+=i;
00464     str3+=i;
00465     str3+="); fndrun->LmdMonFrame()->DisplayHist();";
00466     fWireBut[i] = new TButton(str1.Data(),str3.Data(),xi,0.,xf,1.);
00467     fWireBut[i]->SetFillColor(WireButCol);
00468     fWireBut[i]->SetTextSize(0.4);
00469     xi = xf;
00470     xf += step;
00471     if(xf > 1.) xf = 1.;
00472   }
00473   fWirePad->Modified();
00474   //  fWirePad->Update();
00475 }
00476 
00477 //____________________________________________________
00478 void TFndLmdMonFrame::DrawWirePad(){
00479   // all wire-buttons are drawn (depending on the selected chamber)
00480 
00481 //   if(!ReloadMapFiles()){
00482 //     fDisplayPad[0]->Clear();
00483 //     fDisplayPad[0]->Modified();
00484 //     return;
00485 //   }
00486   //  cout << "Drawing wire pad: " << fWirePad << endl;
00487   fWirePad->cd(); 
00488   for(Int_t i=0;i<=fNWires;i++){
00489     fWireBut[i]->Draw();
00490   }
00491   gPad->Modified();
00492   //  cout << "WirePad drawn" << endl;
00493 }
00494 
00495 //____________________________________________________
00496 TButton *TFndLmdMonFrame::HighlightButtons(Int_t which_group,Int_t All_id){
00497   // Highlight active buttons (considering the selected Chamber/Layer/Wire)
00498   //  - which_group==0 : Chamber/Wire buttons highlighted
00499   //  - which_group==1 : fAllButtons buttons highlighted
00500   //  - All_id : index for the all_button
00501 
00502   fWhichGroup = which_group;
00503   fAllId = All_id;
00504 
00505   Int_t dch_id = fdch+fIO*8-1; // index for the LMD number button
00506   switch(which_group){
00507   case 0:
00508     fChSelBut[dch_id]->SetFillColor(fHighlightCol[fIO]);
00509     fChSelBut[dch_id]->Modified();
00510     
00511     fWireBut[fwir]->SetFillColor(fHighlightCol[fIO]);
00512     fWireBut[fwir]->Modified();
00513     return fWireBut[fwir];
00514     //return fChSelBut[dch_id];
00515     //    break;
00516   case 1:
00517     fAllButton[All_id]->SetFillColor(fHighlightCol[fIO]); 
00518     fAllButton[All_id]->Modified();
00519     return fAllButton[All_id];
00520     //    break;
00521   default: return 0;
00522   }
00523 }
00524 
00525 //___________________________________________
00526 void TFndLmdMonFrame::RefreshSingleMonView(){
00527 
00528   if(fWhichGroup == -1 || fAllId == -1) return;
00529   FlashDisplayPad();
00530   HighlightButtons(fWhichGroup,fAllId)->ExecuteEvent(11,0,0);
00531 }
00532 
00533 
00534 //_____________________
00535 //_____________________
00536 //_____________________
00537 //____________________________________________________
00538 void TFndLmdMonFrame::DrawHist(Int_t opt, Int_t flg, Char_t *DrawOpt){
00539   // Draw a selected histogram (see the source code for more details)
00540   // The field "flg" can be: "0":simple drawing ; "1":superposed drawing
00541   // The "DrawOpt" field acts only if "flg" is "0"
00542   
00543   //  Info("TFndLmdMonFrame::DrawHist"," ************************* called: %d ; %d; %s",opt,flg,DrawOpt);
00544 
00545   //  if(!fzoom) for(Int_t i=0;i<4;i++) fnbx[i] = 0;
00546 
00547   h2 = NULL;
00548   fhists = 0;
00549   sly = NULL;
00550 
00551   TString type = TString("");
00552   switch(opt){
00553   case 0:  type = "adc";  break;  // 2D
00554   case 1:  type = "adce";  break;
00555   case 2:  type = "adcp";  break;
00556   case 3:  type = "crg";  break;
00557   case 4:  type = "zet";  break;
00558     
00559     //  case 5:  type = "mapadce";  break;
00560     //   case 6:  type = "mapadcp";  break;
00561     //   case 7:  type = "maptdce";  break;
00562     //   case 8:  type = "maptdcp";  break;
00563   case 5:  type = "aepat";  break;
00564   case 6:  type = "appat";  break;
00565   case 7:  type = "tepat";  break;
00566   case 8:  type = "tppat";  break;
00567   case 9:  type = "mapadctdc";  break;  // 2D
00568   case 10: type = "adc_tdc";  break;  // 2D
00569     
00570   case 11: type = "tdc";  break;  // 2D
00571   case 12: type = "tdce";  break;
00572   case 13: type = "tdcp";  break;
00573   case 14: type = "tmean";  break;
00574   case 15: type = "tdf";  break;
00575     
00576   case 16: type = "mul";  break;
00577   default: break;
00578   }
00579 
00580   TString etichetta = TString("");
00581   //  if((fwir == 0 && (opt<6 || opt>9)) || opt==9) etichetta+="lmd_all_";
00582   //   if((fwir == 0 && (opt != 9)) || opt==9) etichetta+="lmd_all_";
00583   //   else etichetta+="lmd";
00584   //  etichetta+="lmd_all_";
00585   if(fwir == 0) etichetta+="lmd_all_";
00586   else etichetta+="lmd";
00587   etichetta+=type.Data();
00588 
00589   //  if(opt < 6 || opt > 8) {
00590   etichetta+="_"; 
00591   etichetta+=fIO+1; 
00592   etichetta+="_"; 
00593   etichetta+=fdch;
00594   //  }
00595   
00596   if(fwir != 0) {
00597     etichetta+="_"; 
00598     etichetta+=fwir;
00599   }
00600   // --- histogram name builld:
00601   //  now must get from the correct "shared-memory/file"
00602   
00603   // handle options from 0 to 8
00604   if(opt<9) {
00605     if(opt==0){
00606       if(!fRF){
00607         if(fIO==0) h2 =(TH2F*) iadc->Get(etichetta.Data());
00608         else h2 =(TH2F*) oadc->Get(etichetta.Data());
00609       } 
00610       else h2 =(TH2F*) fRF->Get(etichetta.Data());
00611     } 
00612     else if(opt==7 || opt ==8){
00613       if(!fRF){
00614         if(fIO==0) fhists  =(TH1F*) itdc->Get(etichetta.Data());
00615         else fhists  =(TH1F*) otdc->Get(etichetta.Data());
00616       } 
00617       else fhists  =(TH1F*) fRF->Get(etichetta.Data());
00618     }
00619     else {
00620       if(!fRF) {
00621         if(fIO==0) fhists =(TH1F*) iadc->Get(etichetta.Data());
00622         else fhists =(TH1F*) oadc->Get(etichetta.Data());
00623       } 
00624       else fhists =(TH1F*) fRF->Get(etichetta.Data());
00625     }
00626   }
00627   // now options 9,10
00628   else if (opt==9 || opt ==10) {
00629     if(!fRF) 
00630       h2 =(TH2F*) maps->Get(etichetta.Data());
00631     else
00632       h2 =(TH2F*) fRF->Get(etichetta.Data());
00633     //    if(opt>=6 && opt<=8) {
00634     Int_t drch = fdch;
00635     if(fIO == 1) drch += 10;
00636     if(h2) sly = h2->ProjectionY("_py",drch,drch);
00637     if(sly) sly->SetLineColor(2*(2-opt%2));
00638     //    }
00639   } 
00640   // now options 11,12,13,14,15,16
00641   else {
00642     if(opt==11) {
00643       if(!fRF) {
00644         if(fIO==0) h2 =(TH2F*) itdc->Get(etichetta.Data());
00645         else h2 =(TH2F*) otdc->Get(etichetta.Data());
00646       } 
00647       else h2 =(TH2F*) fRF->Get(etichetta.Data());
00648     } 
00649     else if(opt==16) {
00650       if(!fRF) {
00651         fhists =(TH1F*) maps->Get(etichetta.Data());
00652       } 
00653       else fhists =(TH1F*) fRF->Get(etichetta.Data());
00654     } 
00655     else {
00656       if(!fRF) {
00657         if(fIO==0) fhists =(TH1F*) itdc->Get(etichetta.Data());
00658         else fhists =(TH1F*) otdc->Get(etichetta.Data());
00659       } 
00660       else fhists =(TH1F*) fRF->Get(etichetta.Data());
00661     }
00662   }
00663 
00664   // --- here handle superimposing
00665   if(flg) {
00666     if(fhists) fhists->Draw("SAME");
00667     if(sly) { sly->Draw("SAME"); }
00668   }
00669   else {
00670     if(fhists) fhists->Draw(DrawOpt);
00671     if(sly) sly->Draw(DrawOpt);
00672   }
00673 
00674   //  Info("TFndLmdMonFrame::DrawHist"," ************************* finishing: %x",h2);
00675   if(h2) h2->Draw(DrawOpt);
00676 }
00677   
00678 //____________________________________________________
00679 void TFndLmdMonFrame::DisplayMaps(){
00680   // Control histograms are shown
00681 
00682   if(!ReloadMapFiles()){
00683     fDisplayPad[0]->Clear();
00684     fDisplayPad[0]->Modified();
00685     return;
00686   }
00687 
00688   Char_t *Draw2D_opt = "box";
00689   //  Char_t *Draw2D_opt = "colz";
00690   RebuildWirePad();
00691   fDisplayPad[0]->Clear();
00692   Int_t EachPadCol = 18;
00693   Float_t Margin = 0.002;
00694   Int_t npads = 8;
00695   //  cout << " -> displaying map histograms" << endl;
00696   fDisplayPad[0]->Divide(4,2,Margin,Margin,EachPadCol);
00697 
00698   fwir = 0;
00699   for(Int_t j=0;j<npads;j++) {
00700     TString hnamestr = TString("lmd");
00701     if(j==0)         hnamestr+="_i_o_mult";
00702     if(j!=0)         hnamestr+="map";
00703     if(j>0 && j<4)   hnamestr+="adc";
00704     if(j>4)          hnamestr+="tdc";
00705     if(j==2 || j==6) hnamestr+="e";
00706     if(j==3 || j==7) hnamestr+="p";
00707 
00708     fDisplayPad[0]->cd(j+1);
00709     //    Printf("Drawing \"%s\" in pad",hnamestr.Data(),j+1);
00710 
00711     if(!fRF) 
00712       h2 = (TH2F *) maps->Get(hnamestr.Data());
00713     else
00714       h2 = (TH2F *) fRF->Get(hnamestr.Data());
00715     if(h2){
00716       h2->Draw(Draw2D_opt);
00717       //TFndMonFrame::GetPadStats()->SetOptStat(11);
00718     }
00719   }    
00720   fDisplayPad[0]->Modified();
00721   ResetFrameColors();
00722   HighlightButtons(1,0);
00723 }
00724 
00725 //____________________________________________________
00726 void TFndLmdMonFrame::DisplayHist(){
00727   // Called when a wire-button is clicked
00728   // If the button is "ALL" overall histgrams of all wires
00729   // of the current chamber will be displayed
00730 
00731   if(!ReloadMapFiles()){
00732     fDisplayPad[0]->Clear();
00733     fDisplayPad[0]->Modified();
00734     return;
00735   }
00736 
00737   Char_t *Draw2D_opt = "colz";
00738   Int_t EachPadCol = 18;
00739   Float_t Margin = 0.002;
00740 
00741   fDisplayPad[0]->Clear();
00742   Int_t npads = 0;
00743   if(fwir == 0){
00744     //    cout << " -> displaying histograms for chamber " << fdch << " --- layer " << fIO << " (overall of all wires)" << endl;
00745     fDisplayPad[0]->Divide(4,3,Margin,Margin,EachPadCol);
00746     npads = 12;
00747   }
00748   else{
00749     //    cout << " -> displaying histograms for chamber " << fdch << " --- layer " << fIO << " --- wires " << fwir << endl;
00750     fDisplayPad[0]->Divide(4,2,Margin,Margin,EachPadCol);
00751     npads = 8;
00752   }
00753   
00754   Int_t opt = 0;
00755   if(fwir == 0){
00756     for(Int_t i=0;i<npads;i++){
00757       //      Info("TFndLmdMonFrame::DisplayHist"," ************************* Drawing DEBUG");
00758       fDisplayPad[0]->cd(i+1);
00759       if(i==0 || i==3) Draw2D_opt = "box";
00760       //      if(i==0) Draw2D_opt = "box";
00761       //else if(i>=4 && i<=8) Draw2D_opt = "box"; 
00762       else Draw2D_opt = "";
00763       //      Draw2D_opt = ""; // debug line!!!
00764       // cout <<"pad: " << i+1 << " --- draw-opt: \"" << Draw2D_opt << "\"" << endl;
00765       DrawHist(opt,0,Draw2D_opt);
00766       if(i==1 || i==9) DrawHist(++opt,1,Draw2D_opt);
00767       //if(i==1) DrawHist(++opt,1);
00768       opt++;
00769     }
00770   }
00771   else{
00772     opt = 1;
00773     for(Int_t i=0;i<npads;i++){
00774       if(i==4) opt = 12;
00775       fDisplayPad[0]->cd(i+1);
00776       DrawHist(opt,0);
00777       opt++;
00778     }
00779   }
00780   fDisplayPad[0]->Modified();
00781   ResetFrameColors();
00782   HighlightButtons(0,0);
00783 }
00784 
00785 //____________________________________________________
00786 void TFndLmdMonFrame::DisplayAllHist(Int_t io, Int_t option){
00787   // called by "all-buttons" (bottom-pad)
00788  
00789   if(!ReloadMapFiles()){
00790     fDisplayPad[0]->Clear();
00791     fDisplayPad[0]->Modified();
00792     return;
00793   }
00794 
00795   RebuildWirePad();
00796   fDisplayPad[0]->Clear();
00797   Int_t EachPadCol = 18;
00798   Float_t Margin = 0.002;
00799   Int_t npads = 8;
00800   fIO = io;
00801   //  cout << " -> displaying control histograms for layer " << fIO+1 << endl;
00802   fDisplayPad[0]->Divide(4,2,Margin,Margin,EachPadCol);
00803 
00804   fwir = 0;
00805   for(Int_t i=0;i<npads;i++){
00806     fDisplayPad[0]->cd(i+1);
00807     fdch = i+1;
00808 
00809     switch(option){
00810     case 0: DrawHist(9,0,"colz"); break;
00811     case 1: DrawHist(3,0); break;
00812     case 2: DrawHist(14,0); break;
00813     case 3: DrawHist(10,0); break;
00814     case 4: DrawHist(16,0); break;
00815       //    case 4: DrawHist(16,0); DrawHist(17,1); break;
00816     default: break;
00817     }
00818   }
00819   fDisplayPad[0]->Modified();
00820   ResetFrameColors();
00821 
00822   Int_t all_id = 1+fIO+2*option;
00823   HighlightButtons(1,all_id);
00824 }
00825 
00826 //____________________________________________________
00827 // void TFndLmdMonFrame::KillProd(){
00828 //    gSystem->Exec("rm mons_lmd.dat");
00829 //    gSystem->Exec("ps | grep geb2hdt | awk '{print $1}' > mons_lmd.dat");
00830 //    FILE *gs = fopen("mons_lmd.dat","r");
00831 //    Int_t gpid;
00832 //    if (gs) while ( fscanf(gs,"%d",&gpid) == 1) {
00833 //       char cmd[60];
00834 //       printf("Killing geb2hdt with Pid=%d\n",gpid);
00835 //       sprintf(cmd,"kill -9 %d\n",gpid);
00836 //       system(cmd);
00837 //    }
00838 // }
00839 
00840 //____________________________________________________
00841 // void TFndLmdMonFrame::Exec(Int_t option){
00842   
00843 //   switch(option){
00844 //   case 1:
00845 //     gSystem->Exec("geb2hdt $MSQLHOST $FND_DATA lmd>&lmd.dat&");
00846 //     break;
00847 //   case 2:
00848 //     KillProd();
00849 //     break;
00850 //   case 3:
00851 //     break;
00852 //   case 4:
00853 //     gSystem->Exec("tail lmd.dat");
00854 //     break;
00855 //   case 5:
00856 //     break;
00857 //   }
00858 
00859 // }
00860 
00861 //_____________________________________
00862 // Bool_t TFndLmdMonFrame::CheckEntries() 
00863 // { 
00864 //   Bool_t kReload = kFALSE;
00865 //   TH2F *i_o_mult = (TH2F *) maps->Get("lmd_i_o_mult");
00866 //   Int_t fEntries = (Int_t) i_o_mult->GetEntries();
00867 //   time_t now;
00868 //   now = time(&now);
00869 //   Int_t timeInterval = now - fTime;
00870 //   fTime = now;
00871 //   Int_t tUpdate = 60;
00872 //   if(timeInterval > tUpdate && fEntries == fSHMEntries) {
00873 //      cout << "Number of Entries did not change for the last " << tUpdate << " seconds: reload LMD Shared memories" << endl;
00874 //      kReload = kTRUE;
00875 //   }
00876 //   return kReload;
00877 // }
00878 
00879 //_____________________________________
00880 // void TFndLmdMonFrame::CheckHistos() 
00881 // { 
00882 //   Bool_t kReload = CheckEntries();
00883 //   if(kReload) ReloadMapFiles();
00884 //   CheckIOMult();
00885 //   CheckMaps();
00886 //   CheckAdcTdcMaps();
00887   
00888 //   CheckAdcs();
00889 //   CheckTdcs();
00890   
00891 // }
00892 
00893 
00894 //_____________________________________
00895 // void TFndLmdMonFrame::CheckIOMult() 
00896 // { 
00897 //   /*
00898 //   Bool_t isCosmic = fndrun->Hdt()->Trig()->Cosmic();
00899 //   if(isCosmic) cout << "Cosmic ray trigger on" << endl;
00900 //   */
00901 //   TString s2("lmd_i_o_mult");
00902 //   cout << "check lmd_i_o_mult" << endl;
00903 //   TH2F *i_o_mult = (TH2F *) maps->Get(s2.Data());
00904 //   Bool_t doCheck = kFALSE;
00905 
00906 //   /*
00907 //   Int_t nx = i_o_mult->GetNbinsX();
00908 //   Int_t ny = i_o_mult->GetNbinsY();
00909 //   for(Int_t i=0; i<nx; i++) {
00910 //     for(Int_t j=0; j<ny; j++) {
00911 //       Double_t nEntries = i_o_mult->GetBinContent(i+1,j+1);
00912 //       // FIXME
00913 //       if(nEntries > 0 && i >= 10) doCheck = kTRUE;
00914 //       if(nEntries > 0 && j >= 10) doCheck = kTRUE;
00915 //     }
00916 //   }
00917 //   */
00918 //   doCheck = kTRUE; // check by default
00919 
00920 //   TFndMonCheckFrame *a =0;
00921 //   Bool_t isThere = kFALSE;
00922 //   Int_t nH = fCheckedHistos->GetEntriesFast();
00923 //   //  cout << nH << " entries in objarray" << endl;
00924 //   for(Int_t i=0; i<nH; i++) {
00925 //     TString curName = ((TFndMonCheckFrame *) fCheckedHistos->At(i))->GetHName();    
00926 //     if(!curName.CompareTo(s2)) {
00927 //       isThere = kTRUE;
00928 //       a = ((TFndMonCheckFrame *) fCheckedHistos->At(i));
00929 //       if(!doCheck) {
00930 //      cout << "Remove: " << curName.Data() << endl;
00931 //      fCheckedHistos->Remove(a);
00932 //      fCheckedHistos->Compress();
00933 //       }
00934 //       break;
00935 //     }   
00936 //   }
00937 //   if(doCheck && isThere == kFALSE) {
00938 //     cout << "Add " << s2.Data() << " to objarray" << endl;
00939 //     a = new TFndMonCheckFrame(maps,s2,2,gClient->GetRoot());
00940 //     fCheckedHistos->Add(a);
00941 //   }
00942 //   delete i_o_mult;
00943 // }
00944 
00945 //_____________________________________
00946 // void TFndLmdMonFrame::CheckAdcTdcMaps() 
00947 // { 
00948 //   /*
00949 //   Bool_t isCosmic = fndrun->Hdt()->Trig()->Cosmic();
00950 //   if(isCosmic) cout << "Cosmic ray trigger on" << endl;
00951 //   */
00952 
00953 //   cout << "check Adc vs Tdc maps" << endl;
00954 //   Float_t ScalingFactor = 0.2;
00955 //   Bool_t lmdAdcTdcMap[16]; 
00956 //   Bool_t isMapThere[16];
00957 //   for(Int_t idet=0;idet<2;idet++) {
00958 //     char layer[3];
00959 //     sprintf(layer,"%d",idet+1);
00960 //     for(Int_t itsl=0; itsl<8; itsl++) {
00961 //       Int_t index = idet*8+itsl+1;
00962 //       TString hname("lmd_all_mapadctdc_");
00963 //       char dch[3];
00964 //       sprintf(dch,"%d",itsl+1);
00965 //       hname.Append(layer);
00966 //       hname.Append("_");
00967 //       hname.Append(dch);
00968 //       TH2F *mapAT = (TH2F *) maps->Get(hname.Data());
00969 //       lmdAdcTdcMap[index] = kFALSE;
00970 //       Int_t nx = mapAT->GetNbinsX();
00971 //       Int_t ny = mapAT->GetNbinsY();
00972       
00973 //       Int_t content[nx*ny];
00974 //       Float_t maxi = 0;
00975 //       Int_t maxi_x = -1;
00976 //       Int_t maxi_y = -1;
00977 //       for(Int_t nbx=0; nbx<nx; nbx++) {
00978 //              for(Int_t nby=0; nby<ny; nby++) {
00979 //                Int_t idx = nbx*ny+nby;
00980 //                content[idx] = (Int_t) mapAT->GetBinContent(nbx+1,nby+1);
00981 //                if(content[idx] > maxi) {
00982 //                      maxi_x = nbx;
00983 //                      maxi_y = nby;
00984 //                      maxi = content[idx];
00985 //                } 
00986 //              }
00987 //       }
00988 //       if(maxi_x*maxi_y != 9) {
00989 //              cout << "layer " << idet+1 << ", chamber: " << itsl+1 << ", maximum in wrong place: " << maxi_x << "," << maxi_y << endl;
00990 //              lmdAdcTdcMap[index] = kTRUE;
00991 //       }
00992 //       for(Int_t nbx=0; nbx<nx; nbx++) {
00993 //              for(Int_t nby=0; nby<ny; nby++) {
00994 //                Int_t idx = nbx*ny+nby;
00995 //                if(content[idx] > ScalingFactor*maxi && maxi_x != nbx && maxi_y != nby) {
00996 //                      lmdAdcTdcMap[itsl] = kTRUE;
00997 //                      cout << "layer " << idet+1 << ", chamber: " << itsl+1 << ", maximum in wrong place, idx: " << idx << "," << maxi_x << "," << maxi_y << endl;
00998 //                } 
00999 //              }      
01000 //       }
01001       
01002 //       TFndMonCheckFrame *a =0;
01003 //       isMapThere[index] = kFALSE;
01004 //       Int_t nH = fCheckedHistos->GetEntriesFast();
01005 //       for(Int_t i=0; i<nH; i++) {
01006 //              TString curName = ((TFndMonCheckFrame *) fCheckedHistos->At(i))->GetHName();
01007 //              if(!curName.CompareTo(hname)) {
01008 //                isMapThere[index] = kTRUE;
01009 //                a = ((TFndMonCheckFrame *) fCheckedHistos->At(i));
01010 //                if(!lmdAdcTdcMap[index]) {
01011 //                      cout << "Remove: " << curName.Data() << endl;
01012 //                      fCheckedHistos->Remove(a);
01013 //                      fCheckedHistos->Compress();
01014 //                }
01015 //                break;
01016 //              }
01017 //       }   
01018 //       if(lmdAdcTdcMap[index] && isMapThere[index] == kFALSE) {
01019 //              cout << "Add " << hname.Data() << " to objarray" << endl;
01020 //              a = new TFndMonCheckFrame(maps,hname,2,gClient->GetRoot());
01021 //              fCheckedHistos->Add(a);
01022 //       }
01023 //       delete mapAT;
01024 //     }
01025 //   }
01026 //   /*
01027 //   for(Int_t idet=0;idet<2;idet++) {
01028 //     for(Int_t itsl=0; itsl<8; itsl++) {
01029 //       Int_t index = idet*8+itsl+1;
01030 //       if(lmdAdcTdcMap[index]) {
01031 //      CheckAdcs(idet+1,itsl+1);
01032 //      CheckTdcs(idet+1,itsl+1);
01033 //       }
01034 //     }
01035 //   }
01036 //   */
01037 
01038 // }
01039 
01040 //_____________________________________
01041 // void TFndLmdMonFrame::CheckMaps() 
01042 // { 
01043 //   /*
01044 //   Bool_t isCosmic = fndrun->Hdt()->Trig()->Cosmic();
01045 //   if(isCosmic) cout << "Cosmic ray trigger on" << endl;
01046 //   */
01047 
01048 //   cout << "check hit maps" << endl;
01049 //   Float_t ScalingFactor = 0.1;
01050 //   Bool_t lmdAdcMap[4]; 
01051 //   Bool_t lmdTdcMap[4]; 
01052 //   Bool_t isAdcMapThere[4];
01053 //   Bool_t isTdcMapThere[4];
01054 //   TH2F *mapADC[4];
01055 //   TH2F *mapTDC[4];
01056 //   Int_t nx = 20;
01057 //   Int_t ny = 24;
01058 //   Int_t contentADC[4][nx][ny];
01059 //   Int_t contentTDC[4][nx][ny];
01060 //   for(Int_t idet=0;idet<4;idet++) {
01061 //     char suff[3];
01062 //     if(idet==1) sprintf(suff,"%s","0");
01063 //     if(idet==2) sprintf(suff,"%s","e");
01064 //     if(idet==3) sprintf(suff,"%s","p");
01065 //      TString hnamea("lmdmapadc");
01066 //      if(idet > 0) hnamea.Append(suff);
01067 //      TString hnamet("lmdmaptdc");
01068 //      if(idet > 0) hnamet.Append(suff);
01069 // //   cout << "analyse histograms " << hnamea.Data() << ", " << hnamet.Data() << endl; 
01070 //      mapADC[idet] = (TH2F *) maps->Get(hnamea.Data());
01071 //      mapTDC[idet] = (TH2F *) maps->Get(hnamet.Data());
01072 // //   cout << "got histograms " << hnamea.Data() << ", " << hnamet.Data() << endl; 
01073 //      lmdAdcMap[idet] = kFALSE;
01074 //      lmdTdcMap[idet] = kFALSE;
01075 //      Int_t nx = mapADC[idet]->GetNbinsX();
01076 //      Int_t ny = mapADC[idet]->GetNbinsY();
01077 // //   cout << "fill content for histograms " << hnamea.Data() << ", " << hnamet.Data() << endl; 
01078 //      for(Int_t nbx=0; nbx<nx; nbx++) {
01079 //              for(Int_t nby=0; nby<ny; nby++) {
01080 //                      contentADC[idet][nbx][nby] = (Int_t) mapADC[idet]->GetBinContent(nbx+1,nby+1);
01081 //                      contentTDC[idet][nbx][nby] = (Int_t) mapTDC[idet]->GetBinContent(nbx+1,nby+1);
01082 //              }
01083 //      }
01084 //   }
01085 
01086 // // check warning conditions
01087 
01088 // //   cout << "warning conditions" << endl; 
01089 //   for(Int_t nbx=0; nbx<18; nbx++) {
01090 //      if(nbx == 8 || nbx == 9) continue;
01091 //      for(Int_t nby=0; nby<22; nby++) {
01092 //        if(nbx < 10 && nby > 11) continue;
01093 //        for(Int_t idet=0;idet<4;idet++) {
01094 //              if((Float_t) TMath::Abs(contentADC[idet][nbx][nby] - contentTDC[idet][nbx][nby]) > ScalingFactor*TMath::Max(contentTDC[idet][nbx][nby],contentADC[idet][nbx][nby])) {
01095 //                lmdAdcMap[idet] = kTRUE;
01096 //                if(idet == 0) cout << "e||p != 0 Maps, ";
01097 //                if(idet == 1) cout << "e&&p != 0 Maps, ";
01098 //                if(idet == 2) cout << "e-side Maps, ";
01099 //                if(idet == 3) cout << "p-side Maps, ";
01100 //                cout << "Warning: ADC counts differ from TDC for more than " << (Int_t) 1./ScalingFactor << "%, Chamber: " << nbx+1 << ", Wire: " << nby+1 << endl;
01101 //          }
01102 //        }
01103 //        if((Float_t) TMath::Abs(contentADC[2][nbx][nby] - contentADC[3][nbx][nby]) > ScalingFactor*TMath::Max(contentADC[2][nbx][nby],contentADC[3][nbx][nby])) {
01104 //              lmdAdcMap[2] = kTRUE;
01105 //              lmdAdcMap[3] = kTRUE;
01106 //              cout << "Warning: ADC counts (e-side - p-side) for more than " << (Int_t) 1./ScalingFactor << "%, Chamber: " << nbx+1 << ", Wire: " << nby+1 << endl;
01107 //        }
01108 //        if((Float_t) TMath::Abs(contentTDC[2][nbx][nby] - contentTDC[3][nbx][nby]) > ScalingFactor*TMath::Max(contentTDC[2][nbx][nby],contentTDC[3][nbx][nby])) {
01109 //              lmdTdcMap[2] = kTRUE;
01110 //              lmdTdcMap[3] = kTRUE;
01111 //              cout << "Warning: TDC counts (e-side - p-side) for more than " << (Int_t) 1./ScalingFactor << "%, Chamber: " << nbx+1 << ", Wire: " << nby+1 << endl;
01112 //        }
01113 //      }      
01114 //   }
01115 
01116 // // update ObjArray
01117 
01118 //   for(Int_t idet=0;idet<4;idet++) {
01119 //     char suff[3];
01120 //     if(idet==1) sprintf(suff,"%s","0");
01121 //     if(idet==2) sprintf(suff,"%s","e");
01122 //     if(idet==3) sprintf(suff,"%s","p");
01123 //      TString hnamea("lmdmapadc");
01124 //      hnamea.Append(suff);
01125 //      TString hnamet("lmdmaptdc");
01126 //      hnamet.Append(suff);
01127 
01128 // //   cout << "update histograms " << hnamea.Data() << ", " << hnamet.Data() << endl; 
01129 //      TFndMonCheckFrame *a =0;
01130 //      isAdcMapThere[idet] = kFALSE;
01131 //      Int_t nH = fCheckedHistos->GetEntriesFast();
01132 //      for(Int_t i=0; i<nH; i++) {
01133 //        TString curName = ((TFndMonCheckFrame *) fCheckedHistos->At(i))->GetHName();
01134 //        if(!curName.CompareTo(hnamea)) {
01135 //                isAdcMapThere[idet] = kTRUE;
01136 //                a = ((TFndMonCheckFrame *) fCheckedHistos->At(i));
01137 //                if(!lmdAdcMap[idet]) {
01138 //                      cout << "Remove: " << curName.Data() << endl;
01139 //                      fCheckedHistos->Remove(a);
01140 //                      fCheckedHistos->Compress();
01141 //                }
01142 //                break;
01143 //        }
01144 //        if(!curName.CompareTo(hnamet)) {
01145 //                isTdcMapThere[idet] = kTRUE;
01146 //                a = ((TFndMonCheckFrame *) fCheckedHistos->At(i));
01147 //                if(!lmdTdcMap[idet]) {
01148 //                      cout << "Remove: " << curName.Data() << endl;
01149 //                      fCheckedHistos->Remove(a);
01150 //                      fCheckedHistos->Compress();
01151 //                }
01152 //                break;
01153 //        }
01154 //      }   
01155 //      if(lmdAdcMap[idet] && isAdcMapThere[idet] == kFALSE) {
01156 //              cout << "Add " << hnamea.Data() << " to objarray" << endl;
01157 //              a = new TFndMonCheckFrame(maps,hnamea,2,gClient->GetRoot());
01158 //              fCheckedHistos->Add(a);
01159 //      }
01160 //      delete mapADC[idet];
01161 //      if(lmdTdcMap[idet] && isTdcMapThere[idet] == kFALSE) {
01162 //              cout << "Add " << hnamet.Data() << " to objarray" << endl;
01163 //              a = new TFndMonCheckFrame(maps,hnamet,2,gClient->GetRoot());
01164 //              fCheckedHistos->Add(a);
01165 //      }
01166 //      delete mapTDC[idet];
01167 //   }
01168 // }
01169 
01170 //_____________________________________
01171 // void TFndLmdMonFrame::CheckAdcs() 
01172 // { 
01173 //   for(Int_t idet=0;idet<2;idet++)
01174 //     for(Int_t itsl=0; itsl<8; itsl++)
01175 //       CheckAdcs(idet+1,itsl+1); 
01176 // }
01177 
01178 //_____________________________________
01179 // void TFndLmdMonFrame::CheckAdcs(Int_t layer, Int_t chamber) 
01180 // { 
01181 //   /*
01182 //   Bool_t isCosmic = fndrun->Hdt()->Trig()->Cosmic();
01183 //   if(isCosmic) cout << "Cosmic ray trigger on" << endl;
01184 //   */
01185 
01186 //   cout << "check Adcs for layer: " << layer << ", chamber: " << chamber << endl;
01187 //   char clayer[3];
01188 //   sprintf(clayer,"%d",layer);
01189 //   char dch[3];
01190 //   sprintf(dch,"%d",chamber);
01191 //   Int_t nwires = 12;
01192 //   if(layer == 2) nwires = 22;
01193 //   Bool_t lmdAdcs[2*nwires]; 
01194 //   Bool_t isAdcThere[2*nwires];
01195 //   for(Int_t iw=0;iw<nwires;iw++) {
01196 //     char wire[3];
01197 //     sprintf(wire,"%d",iw+1);
01198     
01199 //     for(Int_t is=0;is<2;is++) {
01200 //       Int_t idx = nwires*is + iw;
01201 //       TString hname("lmdadc");
01202 //       if(is == 0) hname.Append("e_");
01203 //       else hname.Append("p_");
01204 //       hname.Append(clayer);
01205 //       hname.Append("_");
01206 //       hname.Append(dch);
01207 //       hname.Append("_");
01208 //       hname.Append(wire);
01209       
01210 //       TH1F *mapAT = 0;
01211 //       if(layer == 1)
01212 //              mapAT = (TH1F *) iadc->Get(hname.Data());
01213 //       else if(layer == 2)
01214 //              mapAT = (TH1F *) oadc->Get(hname.Data());
01215       
01216 //       lmdAdcs[idx] = kFALSE;
01217 //       Int_t nx = mapAT->GetNbinsX();
01218       
01219 //       Float_t lowEdge[nx];
01220 //       Int_t content[nx];
01221 //       Int_t nEntries = (Int_t) mapAT->GetEntries();
01222 //       Float_t maxi = 0;
01223 //       Int_t maxi_x = -1;
01224 //       for(Int_t nbx=0; nbx<nx; nbx++) {
01225 //              lowEdge[nbx] = (Float_t) mapAT->GetBinLowEdge(nbx+1);
01226 //         content[nbx] = (Int_t) mapAT->GetBinContent(nbx+1);
01227 //         if(content[nbx] > maxi) {
01228 //           maxi_x = (Int_t) lowEdge[nbx];
01229 //           maxi = content[nbx];
01230 //         } 
01231 //       }
01232 //       if(nEntries > 100 && maxi_x <= 100 && maxi_x > 0) {
01233 //              if(is == 0) cout << "layer " << layer << ", chamber: " << chamber << ", wire: " << iw+1 << ", side e: maximum in wrong place: " << maxi_x << endl;
01234 //              else cout << "layer " << layer << ", chamber: " << chamber << ", wire: " << iw+1 << ", side p: maximum in wrong place: " << maxi_x << endl;
01235 //              lmdAdcs[idx] = kTRUE;
01236 //       }
01237         
01238 //       TFndMonCheckFrame *a =0;
01239 //       isAdcThere[idx] = kFALSE;
01240 //       Int_t nH = fCheckedHistos->GetEntriesFast();
01241 //       for(Int_t i=0; i<nH; i++) {
01242 //              TString curName = ((TFndMonCheckFrame *) fCheckedHistos->At(i))->GetHName();
01243 //              if(!curName.CompareTo(hname)) {
01244 //                isAdcThere[idx] = kTRUE;
01245 //                a = ((TFndMonCheckFrame *) fCheckedHistos->At(i));
01246 //                if(!lmdAdcs[idx]) {
01247 //                      cout << "Remove: " << curName.Data() << endl;
01248 //                      fCheckedHistos->Remove(a);
01249 //                      fCheckedHistos->Compress();
01250 //                }
01251 //              break;
01252 //              }
01253 //       }   
01254 //       if(lmdAdcs[idx] && isAdcThere[idx] == kFALSE) {
01255 //              cout << "Add " << hname.Data() << " to objarray" << endl;
01256 //              if(layer == 1)
01257 //                a = new TFndMonCheckFrame(iadc,hname,1,gClient->GetRoot());
01258 //              else if(layer == 2)
01259 //                a = new TFndMonCheckFrame(oadc,hname,1,gClient->GetRoot());
01260 //              fCheckedHistos->Add(a);
01261 //       }   
01262 //       delete mapAT;
01263 //     }
01264 //   } 
01265 // }
01266 
01267 //_____________________________________
01268 // void TFndLmdMonFrame::CheckTdcs() 
01269 // { 
01270 //   for(Int_t idet=0;idet<2;idet++)
01271 //     for(Int_t itsl=0; itsl<8; itsl++)
01272 //       CheckTdcs(idet+1,itsl+1); 
01273 // }
01274 
01275 //_____________________________________
01276 // void TFndLmdMonFrame::CheckTdcs(Int_t layer, Int_t chamber) 
01277 // { 
01278 //   /*
01279 //     Bool_t isCosmic = fndrun->Hdt()->Trig()->Cosmic();
01280 //     if(isCosmic) cout << "Cosmic ray trigger on" << endl;
01281 //   */
01282   
01283 //   cout << "check Tdcs for layer: " << layer << ", chamber: " << chamber << endl;
01284 //   char clayer[3];
01285 //   sprintf(clayer,"%d",layer);
01286 //   char dch[3];
01287 //   sprintf(dch,"%d",chamber);
01288 //   Int_t nwires = 12;
01289 //   if(layer == 2) nwires = 22;
01290 //   Bool_t lmdTdcs[nwires]; 
01291 //   Bool_t isTdcThere[nwires];
01292 //   Float_t maxi[nwires];
01293 //   Int_t maxi_x[nwires];
01294 //   Int_t maxi_b[nwires];
01295 //   Int_t t_maxi[nwires];
01296 //   Float_t t_cell[nwires];
01297 //   Float_t t_start[nwires];
01298 //   Float_t t_stop[nwires];
01299 
01300 //   Float_t ScalingFactor = 0.1;
01301 //   for(Int_t iw=0;iw<nwires;iw++) {
01302   
01303 //     char wire[3];
01304 //     sprintf(wire,"%d",iw+1);
01305 //      TString hname("lmdtmean_");
01306 //      hname.Append(clayer);
01307 //      hname.Append("_");
01308 //      hname.Append(dch);
01309 //      hname.Append("_");
01310 //      hname.Append(wire);
01311         
01312 //      Int_t nx;
01313 //      Float_t lowEdge[nx];
01314 //      Int_t content[nx];
01315 // //   cout << "get histogram " << hname.Data() << endl;
01316 //      TH1F *mapAT = 0;
01317 //      if(layer == 1)
01318 //        mapAT = (TH1F *) itdc->Get(hname.Data());
01319 //      else if(layer == 2)
01320 //        mapAT = (TH1F *) otdc->Get(hname.Data());
01321       
01322 //      lmdTdcs[iw] = kFALSE;
01323 //      nx = mapAT->GetNbinsX();            
01324 //      Int_t nEntries = (Int_t) mapAT->GetEntries();
01325 // //   cout << "analyse histogram " << hname.Data() << ", " << nx << " bins, " << nEntries << " entries " << endl;       
01326 
01327 //      maxi_b[iw] = 0;
01328 //      for(Int_t nbx=0; nbx<nx; nbx++) {
01329 //        lowEdge[nbx] = (Float_t) mapAT->GetBinLowEdge(nbx+1);
01330 //        content[nbx] += (Int_t) mapAT->GetBinContent(nbx+1);
01331 //        if(content[nbx] > maxi[iw]) {
01332 //              maxi_b[iw] = nbx;
01333 //              maxi_x[iw] = (Int_t) lowEdge[nbx];
01334 //              maxi[iw] = content[nbx];
01335 //        } 
01336 //      }
01337 // //   cout << "analyse histogram " << hname.Data() << ", tstart " << maxi_b[iw] << endl;        
01338 //      for(Int_t nbx=0; nbx<nx; nbx++) {
01339 //        if(content[nbx] > (Int_t) ScalingFactor*content[maxi_b[iw]]) {
01340 //              t_start[iw] = lowEdge[nbx];
01341 //              break;
01342 //        }
01343 //      }
01344 // //   cout << "analyse histogram " << hname.Data() << ", tstop " << endl;       
01345 //      for(Int_t nbx=nx; nbx>0; nbx--) {
01346 //        if(content[nbx] > (Int_t) ScalingFactor*content[maxi_b[iw]]) {
01347 //              t_stop[iw] = lowEdge[nbx];
01348 //              break;
01349 //        }
01350 //      }
01351 
01352 // //   cout << "analyse histogram " << hname.Data() << ", tmaxi position" << endl;       
01353 //     t_cell[iw] = 1500;
01354 //      t_maxi[iw] = 3200;
01355 //      Int_t twidth = (Int_t)(t_stop[iw] - t_start[iw]);
01356 //      if(twidth > t_cell[iw]) {
01357 //        cout << "layer " << layer << ", chamber: " << chamber << ", wire: " << iw+1 << ", time distribution is wrong, interval is: " << twidth << endl;
01358 //        lmdTdcs[iw] = kTRUE;          
01359 //      }
01360 
01361 //      if(t_stop[iw] < maxi_x[iw]) {
01362 //        cout << "layer " << layer << ", chamber: " << chamber << ", wire: " << iw+1 << ", maximum and stopping time swapped" << endl;
01363 //        lmdTdcs[iw] = kTRUE;          
01364 //      }
01365 //      if(t_start[iw] > maxi_x[iw]) {
01366 //        cout << "layer " << layer << ", chamber: " << chamber << ", wire: " << iw+1 << ", maximum and starting time swapped" << endl;
01367 //        lmdTdcs[iw] = kTRUE;          
01368 //      }
01369 
01370 //      if(TMath::Abs(maxi_x[iw] - t_maxi[iw]) > 100 && maxi_x[iw] > 0) {
01371 //        cout << "layer " << layer << ", chamber: " << chamber << ", wire: " << iw+1 << ", TDC maximum in wrong place: " << maxi_x[iw] << endl;
01372 //        lmdTdcs[iw] = kTRUE;
01373 //      }
01374         
01375 //      TFndMonCheckFrame *a =0;
01376 //      isTdcThere[iw] = kFALSE;
01377 //      Int_t nH = fCheckedHistos->GetEntriesFast();
01378 //      if(nH > 1000) cout << "Fatal Error: too many entries in TObjArray" << endl;
01379 //      for(Int_t i=0; i<nH; i++) {
01380 //        TString curName = ((TFndMonCheckFrame *) fCheckedHistos->At(i))->GetHName();
01381 //        if(!curName.CompareTo(hname)) {
01382 //              isTdcThere[iw] = kTRUE;
01383 //              a = ((TFndMonCheckFrame *) fCheckedHistos->At(i));
01384 //              if(!lmdTdcs[iw]) {
01385 //                cout << "Remove: " << curName.Data() << endl;
01386 //                fCheckedHistos->Remove(a);
01387 //                fCheckedHistos->Compress();
01388 //              }
01389 //              break;
01390 //        }
01391 //      }   
01392 //      if(lmdTdcs[iw] && isTdcThere[iw] == kFALSE) {
01393 //        cout << "Add " << hname.Data() << " to objarray" << endl;
01394 //        if(layer == 1)
01395 //              a = new TFndMonCheckFrame(itdc,hname,1,gClient->GetRoot());
01396 //        else if(layer == 2)
01397 //              a = new TFndMonCheckFrame(otdc,hname,1,gClient->GetRoot());
01398 //        fCheckedHistos->Add(a);
01399 //      }
01400 //      delete mapAT;
01401 //   }
01402 // }
01403 
01404 //_____________________________________
01405 // void TFndLmdMonFrame::DrawCheckedHistos() 
01406 // { 
01407 //   static TFndMonCheckFrame *a[1000];
01408 //   if(fNHpres != 0 && fNHpres <= 1000) 
01409 //     for(Int_t i=0; i<fNHpres; i++) 
01410 //       if(a[i]) a[i]->DoClose();  
01411 //   Int_t nH = fCheckedHistos->GetEntriesFast();
01412 //   if(nH > 0) {
01413 //     fNHpres = nH;
01414 //     for(Int_t i=0; i<fNHpres; i++) {
01415 //       a[i] = ((TFndMonCheckFrame *) fCheckedHistos->At(i));
01416 //       a[i]->Create();
01417 //       a[i]->DoDraw();
01418 //     }
01419 //   }
01420 // }

Generated on Tue Oct 16 15:40:47 2007 by  doxygen 1.5.2