Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:58

0001 #include "BbcMonDraw.h"
0002 
0003 #include <onlmon/OnlMonClient.h>
0004 #include <onlmon/triggerEnum.h>
0005 
0006 #include <TArc.h>
0007 #include <TArrow.h>
0008 #include <TAxis.h>
0009 #include <TCanvas.h>
0010 #include <TDatime.h>
0011 #include <TF1.h>
0012 #include <TFrame.h>
0013 #include <TGraph.h>
0014 #include <TGraphErrors.h>
0015 #include <TH1.h>
0016 #include <TH2.h>
0017 #include <TLatex.h>
0018 #include <TLine.h>
0019 #include <TPad.h>
0020 #include <TPaveText.h>
0021 #include <TROOT.h>
0022 #include <TSpectrum.h>
0023 #include <TStyle.h>
0024 #include <TSystem.h>
0025 #include <TText.h>
0026 
0027 #include <algorithm>
0028 #include <chrono>
0029 #include <cstring>
0030 #include <ctime>
0031 #include <fstream>
0032 #include <iomanip>
0033 #include <iostream>
0034 #include <sstream>
0035 #include <vector>
0036 
0037 #define DEBUG
0038 #ifdef DEBUG
0039 #define PRINT_DEBUG(x) std::cout << (x) << std::endl
0040 #else
0041 #define PRINT_DEBUG(x) {};
0042 #endif
0043 
0044 #ifdef DEBUGNEW
0045 #define ifdelete(x)                            \
0046   if (x != nullptr)                            \
0047   {                                            \
0048     std::cout << "Delete " << #x << std::endl; \
0049     delete x;                                  \
0050     x = nullptr;                               \
0051   }
0052 #define ifnew(t, x)                              \
0053   {                                              \
0054     if (x != nullptr)                            \
0055     {                                            \
0056       std::cout << "Delete " << #x << std::endl; \
0057       delete x;                                  \
0058     }                                            \
0059     std::cout << "New " << #x << std::endl;      \
0060     x = new t;                                   \
0061   }
0062 #else
0063 #define ifdelete(x) \
0064   if (x != nullptr) \
0065   {                 \
0066     delete x;       \
0067     x = nullptr;    \
0068   }
0069 #define ifnew(t, x)   \
0070   {                   \
0071     if (x != nullptr) \
0072     {                 \
0073       delete x;       \
0074     }                 \
0075     x = new t;        \
0076   }
0077 #endif
0078 
0079 // x position of trigger, scale factor and vtx mean
0080 // static float xpos[3] = {0.30, 0.50, 0.75};
0081 static float xpos[4] = {0.20, 0.35, 0.55, 0.75};
0082 
0083 BbcMonDraw::BbcMonDraw(const std::string &name)
0084   : OnlMonDraw(name)
0085 {
0086   PRINT_DEBUG("In BbcMonDraw::BbcMonDraw()");
0087   std::cout << "Done with BbcMonDraw::BbcMonDraw" << std::endl;
0088   return;
0089 }
0090 
0091 BbcMonDraw::~BbcMonDraw()
0092 {
0093   PRINT_DEBUG("In BbcMonDraw::~BbcMonDraw()");
0094 
0095   ifdelete(bbcStyle);
0096 
0097   // ------------------------------------------------------
0098   // Canvas and Histogram
0099 
0100   ifdelete(PaveTop);
0101   ifdelete(TextTop);
0102 
0103   for (int i = 0; i < BbcMonDefs::MAX_WARNING; i++)
0104   {
0105     ifdelete(PaveWarning[i]);
0106     ifdelete(ArcWarning[i]);
0107   }
0108 
0109   // ------------------------------------------------------
0110   // Graph for visualization
0111 
0112   // for the 1st Page
0113 
0114   for (int side = 0; side < nSIDE; side++)
0115   {
0116     ifdelete(TdcOver[side]);
0117     ifdelete(LineTdcOver[side][0]);
0118     ifdelete(LineTdcOver[side][1]);
0119     ifdelete(BoxTdcOver[side]);
0120 
0121     for (int trig = 0; trig < nTRIGGER; trig++)
0122     {
0123       ifdelete(nHit[trig][side]);
0124       ifdelete(LinenHit[trig][side][0]);
0125       ifdelete(LinenHit[trig][side][1]);
0126       ifdelete(BoxnHit[trig][side]);
0127     }
0128   }
0129   ifdelete(TextnHitStatus);
0130 
0131   // for 2nd Page
0132 
0133   for (int side = 0; side < nSIDE; side++)
0134   {
0135     ifdelete(HitTime[side]);
0136     ifdelete(LineHitTime[side][0]);
0137     ifdelete(LineHitTime[side][1]);
0138     ifdelete(ArrowHitTime[side]);
0139     ifdelete(TextHitTime[side]);
0140     ifdelete(FitHitTime[side]);
0141   }
0142 
0143   ifdelete(AvrHitTime);
0144   ifdelete(LineAvrHitTime[0]);
0145   ifdelete(LineAvrHitTime[1]);
0146   ifdelete(ArrowAvrHitTime);
0147   ifdelete(TextAvrHitTime);
0148   ifdelete(FitAvrHitTime);
0149 
0150   ifdelete(NorthHitTime);
0151   ifdelete(LineNorthHitTime[0]);
0152   ifdelete(LineNorthHitTime[1]);
0153   ifdelete(ArrowNorthHitTime);
0154   ifdelete(TextNorthHitTime);
0155   ifdelete(FitNorthHitTime);
0156   ifdelete(SouthHitTime);
0157   ifdelete(LineSouthHitTime[0]);
0158   ifdelete(LineSouthHitTime[1]);
0159   ifdelete(ArrowSouthHitTime);
0160   ifdelete(TextSouthHitTime);
0161   ifdelete(FitSouthHitTime);
0162 
0163   ifdelete(NorthChargeSum);
0164   ifdelete(SouthChargeSum);
0165   ifdelete(TextSouthChargeSum);
0166   ifdelete(TextNorthChargeSum);
0167 
0168   ifdelete(TextBbcSummaryHitTime[0]);
0169   ifdelete(TextBbcSummaryHitTime[1]);
0170   ifdelete(TextBbcSummaryGlobalOffset[0]);
0171   ifdelete(TextBbcSummaryGlobalOffset[1]);
0172   ifdelete(TextBbcSummaryZvertex);
0173   ifdelete(TextBbcSummaryTrigRate);
0174 
0175   ifdelete(Zvtx);
0176   ifdelete(FitZvtx);
0177   ifdelete(LineZvtx[0]);
0178   ifdelete(LineZvtx[1]);
0179   ifdelete(ArrowZvtx);
0180   ifdelete(TextZvtx);
0181   ifdelete(TextZvtxNorth);
0182   ifdelete(TextZvtxSouth);
0183   ifdelete(TextZvtxStatus[0]);
0184   ifdelete(TextZvtxStatus[1]);
0185   ifdelete(TextZvtxStatus[2]);
0186 
0187   ifdelete(RunVtx);
0188   ifdelete(RunVtxErr);
0189   ifdelete(RunVtxTime);
0190 
0191   ifdelete(ArmHit);
0192   ifdelete(TextArmHit);
0193   ifdelete(ArcArmHit);
0194 
0195   // for 3rd Page
0196   ifdelete(South_Nhit);
0197   ifdelete(North_Nhit);
0198   for (int iarm=0; iarm<2; iarm++)
0199   {
0200     ifdelete(Nhit_emcal[iarm]);
0201     ifdelete(Nhit_hcal[iarm]);
0202     ifdelete(Nhit_emcalmbd[iarm]);
0203     ifdelete(Nhit_hcalmbd[iarm]);
0204   }
0205 
0206   ifdelete(Zvtx);
0207   ifdelete(Zvtx_alltrigger);
0208   ifdelete(Zvtx_ns);
0209   ifdelete(Zvtx_10);
0210   ifdelete(Zvtx_30);
0211   ifdelete(Zvtx_60);
0212   ifdelete(Zvtx_ns_chk);
0213   ifdelete(Zvtx_10_chk);
0214   ifdelete(Zvtx_30_chk);
0215   ifdelete(Zvtx_60_chk);
0216   ifdelete(Zvtx_zdcns);
0217   ifdelete(Zvtx_emcal);
0218   ifdelete(Zvtx_hcal);
0219   ifdelete(Zvtx_emcalmbd);
0220   ifdelete(Zvtx_hcalmbd);
0221 
0222   // for 4th Page
0223   ifdelete(TzeroZvtx);
0224   ifdelete(TextZVertexNotice);
0225 
0226   ifdelete(Adc);
0227   ifdelete(MultiView1F);
0228   ifdelete(MultiView2F);
0229   ifdelete(PaveWarnings);
0230 
0231   ifdelete(LineTzeroZvtx[0]);
0232   ifdelete(LineTzeroZvtx[1]);
0233   ifdelete(LineTzeroZvtx[2]);
0234   ifdelete(LineTzeroZvtx[3]);
0235   ifdelete(TextTzeroZvtx);
0236 
0237   // for (int i = 0; i < 4; i++)//need a look
0238   for (int i = 0; i < 5; i++)
0239   {
0240     ifdelete(TextZVertex[i]);
0241     ifdelete(TextZVertex_scale[i]);
0242     ifdelete(TextZVertex_mean[i]);
0243   }
0244   ifdelete(FitZvtx);
0245   ifdelete(TextZvtxStatus[0]);
0246   ifdelete(TextZvtxStatus[1]);
0247   ifdelete(TextZvtxStatus[2]);
0248 
0249   for (auto &icv : TC)
0250   {
0251     ifdelete(icv);
0252   }
0253 
0254   ifdelete(Prescale_hist);
0255   ifdelete(tspec);
0256   ifdelete(gRunVtx);
0257   ifdelete(gRunAvgVtx);
0258 
0259   return;
0260 }
0261 
0262 int BbcMonDraw::UpdateSendFlag(const int flag)
0263 {
0264   sendflag = flag;
0265   std::ofstream sendflagfile( sendflagfname );
0266   if ( sendflagfile.is_open() )
0267   {
0268     sendflagfile << sendflag << std::endl;
0269   }
0270   else
0271   {
0272     std::cout << "UpdateSendFlag, unable to open file " << sendflagfname << std::endl;
0273     return 0;
0274   }
0275   sendflagfile.close();
0276   return 1;
0277 }
0278 
0279 int BbcMonDraw::GetSendFlag()
0280 {
0281   std::ifstream sendflagfile( sendflagfname );
0282   if ( sendflagfile.is_open() )
0283   {
0284     sendflagfile >> sendflag;
0285   }
0286   else
0287   {
0288     std::cout << "GetSendFlag, unable to open file " << sendflagfname << std::endl;
0289     sendflag = 0;
0290   }
0291   sendflagfile.close();
0292 
0293   return sendflag;
0294 }
0295 
0296 int BbcMonDraw::UpdateZResetFlag(const int flag)
0297 {
0298   zresetflag = flag;
0299   std::ofstream zresetflagfile( zresetflagfname );
0300   if ( zresetflagfile.is_open() )
0301   {
0302     zresetflagfile << zresetflag << std::endl;
0303   }
0304   else
0305   {
0306     std::cout << "UpdatezresetFlag, unable to open file " << zresetflagfname << std::endl;
0307     return 0;
0308   }
0309   zresetflagfile.close();
0310   return 1;
0311 }
0312 
0313 int BbcMonDraw::GetZResetFlag()
0314 {
0315   std::ifstream zresetflagfile( zresetflagfname );
0316   if ( zresetflagfile.is_open() )
0317   {
0318     zresetflagfile >> zresetflag;
0319   }
0320   else
0321   {
0322     std::cout << "GetZResetFlag, unable to open file " << zresetflagfname << std::endl;
0323     zresetflag = 0;
0324   }
0325   zresetflagfile.close();
0326 
0327   return zresetflag;
0328 }
0329 
0330 int BbcMonDraw::UpdateGL1BadFlag(const int flag)
0331 {
0332   gl1badflag = flag;
0333   std::ofstream gl1badflagfile( gl1badflagfname );
0334   if ( gl1badflagfile.is_open() )
0335   {
0336     gl1badflagfile << gl1badflag << std::endl;
0337   }
0338   else
0339   {
0340     std::cout << "unable to open file " << gl1badflagfname << std::endl;
0341     return 0;
0342   }
0343   gl1badflagfile.close();
0344   return 1;
0345 }
0346 
0347 int BbcMonDraw::GetGL1BadFlag()
0348 {
0349   std::ifstream gl1badflagfile( gl1badflagfname );
0350   if ( gl1badflagfile.is_open() )
0351   {
0352     gl1badflagfile >> gl1badflag;
0353   }
0354   else
0355   {
0356     std::cout << "unable to open file " << gl1badflagfname << std::endl;
0357     gl1badflag = 0;
0358   }
0359   gl1badflagfile.close();
0360 
0361   return gl1badflag;
0362 }
0363 
0364 
0365 int BbcMonDraw::Init()
0366 {
0367   PRINT_DEBUG("In BbcMonDraw::Init()");
0368   TStyle *oldStyle = gStyle;
0369   bbcStyle = new TStyle("bbcStyle", "MBD Online Monitor Style");
0370   bbcStyle->SetOptStat(0);
0371   bbcStyle->SetTitleH(0.075);
0372   bbcStyle->SetTitleW(0.98);
0373   bbcStyle->SetPalette(1);
0374   bbcStyle->SetFrameBorderMode(0);
0375   bbcStyle->SetPadBorderMode(0);
0376   bbcStyle->SetCanvasBorderMode(0);
0377   oldStyle->cd();
0378 
0379   /*
0380   for ( auto server : m_ServerSet )
0381   {
0382       std::cout << "servers " << server << std::endl;
0383   }
0384   */
0385   
0386   // prep the vtx to MCR info
0387   sendflagfname = "/home/phnxrc/operations/mbd/mbd2mcr.seb18";
0388   std::cout << "sendflagfname " << sendflagfname << std::endl;
0389   GetSendFlag();
0390 
0391   // prep z-reset
0392   zresetflagfname = "/home/phnxrc/operations/mbd/mbdzreset.seb18";
0393 
0394   // ------------------------------------------------------
0395   // Canvas and Histogram
0396 
0397   memset(TC, 0, sizeof(TC));
0398   memset(transparent, 0, sizeof(transparent));
0399   memset(PadTop, 0, sizeof(PadTop));
0400   memset(PaveWarning, 0, sizeof(PaveWarning));
0401   memset(ArcWarning, 0, sizeof(ArcWarning));
0402   memset(PadWarning, 0, sizeof(PadWarning));
0403   memset(nPadWarning, 0, sizeof(nPadWarning));
0404   memset(PadAutoUpdate, 0, sizeof(PadAutoUpdate));
0405   // ------------------------------------------------------
0406   // Graph for visualization
0407 
0408   // for the 1st Page
0409   memset(TdcOver, 0, sizeof(TdcOver));
0410   memset(PadTdcOver, 0, sizeof(PadTdcOver));
0411   memset(LineTdcOver, 0, sizeof(LineTdcOver));
0412   memset(BoxTdcOver, 0, sizeof(BoxTdcOver));
0413   memset(FrameTdcOver, 0, sizeof(FrameTdcOver));
0414   memset(PadnHit, 0, sizeof(PadnHit));
0415   memset(nHit, 0, sizeof(nHit));
0416   memset(LinenHit, 0, sizeof(LinenHit));
0417   memset(BoxnHit, 0, sizeof(BoxnHit));
0418   memset(FramenHit, 0, sizeof(FramenHit));
0419 
0420   // for 2nd Page
0421 
0422   memset(HitTime, 0, sizeof(HitTime));
0423   memset(PadHitTime, 0, sizeof(PadHitTime));
0424   memset(LineHitTime, 0, sizeof(LineHitTime));
0425   memset(ArrowHitTime, 0, sizeof(ArrowHitTime));
0426   memset(TextHitTime, 0, sizeof(TextHitTime));
0427   memset(FitHitTime, 0, sizeof(FitHitTime));
0428   memset(LineAvrHitTime, 0, sizeof(LineAvrHitTime));
0429 
0430   memset(LineNorthHitTime, 0, sizeof(LineNorthHitTime));
0431   memset(LineSouthHitTime, 0, sizeof(LineSouthHitTime));
0432 
0433   memset(TextBbcSummaryHitTime, 0, sizeof(TextBbcSummaryHitTime));
0434   memset(TextBbcSummaryGlobalOffset, 0, sizeof(TextBbcSummaryGlobalOffset));
0435 
0436   memset(LineZvtx, 0, sizeof(LineZvtx));
0437 
0438   memset(LineTzeroZvtx, 0, sizeof(LineTzeroZvtx));
0439 
0440   memset(TextZVertex, 0, sizeof(TextZVertex));
0441   memset(TextZVertex_scale, 0, sizeof(TextZVertex_scale));
0442   memset(TextZVertex_mean, 0, sizeof(TextZVertex_mean));
0443 
0444   // memset(Pad, 0, sizeof(Pad));
0445 
0446   FitZvtx = new TF1("FitZvtx", "gaus", -60, 60);
0447   TextZvtxStatus[0] = new TLatex;
0448   TextZvtxStatus[1] = new TLatex;
0449   TextZvtxStatus[2] = new TLatex;
0450 
0451   tspec = new TSpectrum(5);  // 5 peaks is enough - we have 4
0452 
0453   gRunVtx = new TGraphErrors();
0454   gRunVtx->SetName("gRunVtx");
0455   gRunVtx->SetTitle("Zvertex vs. Time");
0456   gRunVtx->GetHistogram()->SetXTitle("time [s]");
0457   gRunVtx->GetHistogram()->SetYTitle("Z_{MBD} [cm]");
0458   gRunVtx->GetHistogram()->GetXaxis()->SetTitleSize(0.08);
0459   gRunVtx->GetHistogram()->GetXaxis()->SetTitleOffset(0.5);
0460   gRunVtx->GetHistogram()->GetXaxis()->SetLabelSize(0.1);
0461   gRunVtx->GetHistogram()->GetXaxis()->SetTickSize(0.1);
0462   gRunVtx->GetHistogram()->GetYaxis()->SetTitleSize(0.08);
0463   gRunVtx->GetHistogram()->GetYaxis()->SetTitleOffset(0.35);
0464   gRunVtx->GetHistogram()->GetYaxis()->SetLabelSize(0.1);
0465   //gRunVtx->GetHistogram()->GetYaxis()->SetTickSize(0.05);
0466 
0467   gRunAvgVtx = new TGraph();
0468   gRunAvgVtx->SetName("gRunAvgVtx");
0469   gRunAvgVtx->SetLineWidth(2);
0470 
0471   // Create Empty Histogram for Running Vtx Plot when plot is blank
0472   EmptyHist = new TH1F("EmptyHist","",1,0,1);
0473   EmptyHist->SetTitle("Zvertex vs. Time");
0474   EmptyHist->SetXTitle("time [s]");
0475   EmptyHist->SetYTitle("Z_{MBD} [cm]");
0476   EmptyHist->GetXaxis()->SetTitleSize(0.08);
0477   EmptyHist->GetXaxis()->SetTitleOffset(0.5);
0478   EmptyHist->GetXaxis()->SetLabelSize(0.1);
0479   EmptyHist->GetXaxis()->SetTickSize(0.1);
0480   EmptyHist->GetYaxis()->SetTitleSize(0.08);
0481   EmptyHist->GetYaxis()->SetTitleOffset(0.35);
0482   EmptyHist->GetYaxis()->SetLabelSize(0.1);
0483 
0484   return 0;
0485 }
0486 
0487 int BbcMonDraw::ClearWarning()
0488 {
0489   for (int i = 0; i < nWarning; i++)
0490   {
0491     ifdelete(PaveWarning[i]);
0492     ifdelete(ArcWarning[i]);
0493   }
0494   nWarning = 0;
0495 
0496   if (PaveWarnings)
0497   {
0498     PaveWarnings->Clear();
0499   }
0500   // if( PadWarnings )
0501   // PaveWarnings->Draw();
0502   return 0;
0503 }
0504 
0505 int BbcMonDraw::Warning(TPad *pad, const float x, const float y, const int r, const std::string &msg)
0506 {
0507   static int brink = 1;
0508   float x1, x2, y1, y2;
0509 
0510   x1 = pad->GetX1() * 0.97 + pad->GetX2() * 0.03;
0511   x2 = pad->GetX1() * 0.03 + pad->GetX2() * 0.97;
0512   // pave rises on top if error point is lower
0513   if (y > pad->GetY1() * 0.5 + pad->GetY2() * 0.5)
0514   {
0515     y1 = pad->GetY1() + (pad->GetY2() - pad->GetY1()) * 0.10;
0516     y2 = pad->GetY1() + (pad->GetY2() - pad->GetY1()) * 0.30;
0517   }
0518   else
0519   {
0520     y1 = pad->GetY1() + (pad->GetY2() - pad->GetY1()) * 0.70;
0521     y2 = pad->GetY1() + (pad->GetY2() - pad->GetY1()) * 0.90;
0522   }
0523 
0524   int newWarning = nWarning;
0525   for (int i = 0; i < nWarning; i++)
0526   {
0527     if (PadWarning[i] == pad)
0528     {
0529       newWarning = i;
0530     }
0531   }
0532 
0533   ifnew(TArc(x, y, r), ArcWarning[newWarning]);
0534   ArcWarning[newWarning]->SetLineWidth(r);
0535   ArcWarning[newWarning]->SetLineColor(2);
0536 
0537   ifnew(TPaveText(x1, y1, x2, y2), PaveWarning[newWarning]);
0538   PaveWarning[newWarning]->AddText(msg.c_str());
0539   ArcWarning[newWarning]->SetLineColor(2 + 3 * brink);
0540   PaveWarning[newWarning]->SetFillColor(5 + 5 * brink);
0541   PaveWarning[newWarning]->SetTextColor(2);
0542   PaveWarning[newWarning]->SetLineColor(2);
0543   PaveWarning[newWarning]->SetLineWidth(2);
0544 
0545   if (newWarning == nWarning)
0546   {
0547     PadWarning[newWarning] = pad;
0548     nPadWarning[newWarning] = 1;
0549     nWarning++;
0550   }
0551   else
0552   {
0553     std::ostringstream wmsg;
0554     wmsg << "... and other " << nPadWarning[newWarning] << " warnings";
0555     nPadWarning[newWarning]++;
0556     PaveWarning[newWarning]->AddText(wmsg.str().c_str());
0557     wmsg.str("");
0558   }
0559   // PaveWarning[newWarning]->AddText( "Call MBD Expert. If this run is a PHYSICS run " );
0560   PaveWarning[newWarning]->AddText("Do Quick-feed MBD");
0561   PaveWarning[newWarning]->AddText("If it is NOT fixed by feed at PHYSICS run, call MBD experts");
0562   // PaveWarning[newWarning]->AddText( "If it is NOT fixed by quick feed at PHYSICS run, conform to the MBD standing orders" );
0563 
0564   if (PaveWarnings)
0565   {
0566     PaveWarnings->AddText(msg.c_str());
0567   }
0568 
0569   if (PadWarnings && PaveWarnings)
0570   {
0571     PaveWarnings->Draw();
0572   }
0573   // ArcWarning[newWarning]->Draw();
0574   PaveWarning[newWarning]->Draw();
0575 
0576   // brink = 1 - brink;
0577 
0578   if (nWarning == BbcMonDefs::MAX_WARNING - 2)
0579   {
0580     std::string bmsg = "Too Many Warnings";
0581     Warning(pad, x, y, 0, bmsg);
0582     bmsg.erase();
0583   }
0584 
0585   return 0;
0586 }
0587 
0588 int BbcMonDraw::MakeCanvas(const std::string &name)
0589 {
0590   PRINT_DEBUG("In BbcMonDraw::MakeCanvas()");
0591   OnlMonClient *cl = OnlMonClient::instance();
0592   int xsize = cl->GetDisplaySizeX();
0593   int ysize = cl->GetDisplaySizeY();
0594 
0595   if (name == "BbcMon1")
0596   {
0597     std::cout << "Creating Canvas BbcMon1..." << std::endl;
0598 
0599     TC[0] = new TCanvas("BbcMon1", "MBD Z-Vertex View for Shift crew", -1, 0, xsize / 2, ysize);
0600 
0601     // root is pathetic, whenever a new TCanvas is created root piles up
0602     // 6kb worth of X11 events which need to be cleared with
0603     // gSystem->ProcessEvents(), otherwise your process will grow and
0604     // grow and grow but will not show a defninitely lost memory leak
0605     gSystem->ProcessEvents();
0606 
0607     TC[0]->cd();
0608     PadTop[0] = new TPad("PadTop0", "PadTop0", 0.00, 0.90, 1.00, 1.00, 0, 0, 0);
0609     PadZVertex = new TPad("PadZVertex", "PadZVertex", 0.00, 0.70, 1.00, 0.90, 0, 0, 0);
0610     PadZVertexSummary = new TPad("PadZVertexSummary", "PadZVertexSummary", 0.00, 0.55, 1.00, 0.70, 0, 0, 0);
0611     PadRunZVertex = new TPad("PadRunZVertex", "PadRunZVertex", 0.00, 0.40, 1.00, 0.55, 0, 0, 0);
0612     PadSouthHitMap = new TPad("PadSouthHitMap", "PadSouthHitMap", 0.00, 0.00, 0.495, 0.40, 0, 0, 0);
0613     PadNorthHitMap = new TPad("PadNorthHitMap", "PadNorthHitMap", 0.505, 0.00, 1.0, 0.40, 0, 0, 0);
0614     // PadTzeroZVertex = new TPad("PadTzeroZVertex", "PadTzeroZVertex", 0.00, 0.00, 1.00, 0.40, 0, 0, 0);
0615 
0616     PadTop[0]->Draw();
0617     // PadZVertex->SetLogy();
0618     PadZVertex->Draw();
0619     PadRunZVertex->Draw();
0620     // PadTzeroZVertex->Draw();
0621     PadSouthHitMap->Draw();
0622     PadNorthHitMap->Draw();
0623     PadZVertexSummary->Draw();
0624 
0625     PadZVertexSummary->cd();
0626 
0627     // ifnew( TText, TextZVertexNotice );
0628     // TextZVertexNotice->SetTextSize(0.08);
0629     // TextZVertexNotice->SetText(0.05, 0.75, "< Z vertex deviation may NOT be due to MBD, don't page expert easily! >");
0630 
0631     // for (int i = 0; i < 4; i++)
0632     for (int i = 0; i < 1; i++)  //  pp
0633     {
0634       ifnew(TText, TextZVertex[i]);
0635       TextZVertex[i]->SetTextColor(BbcMonDefs::BBC_COLOR_ZVTX[i]);
0636       // TextZVertex[i]->SetTextSize(0.15);
0637       TextZVertex[i]->SetTextSize(0.08);
0638 
0639       ifnew(TText, TextZVertex_scale[i]);
0640       ifnew(TText, TextZVertex_mean[i]);
0641       TextZVertex_scale[i]->SetTextColor(BbcMonDefs::BBC_COLOR_ZVTX[i]);
0642       TextZVertex_mean[i]->SetTextColor(BbcMonDefs::BBC_COLOR_ZVTX[i]);
0643       TextZVertex_scale[i]->SetTextSize(0.08);
0644       TextZVertex_mean[i]->SetTextSize(0.08);
0645     }
0646     /*chiu
0647     TextZVertex[0]->SetText(xpos[0], 0.65, "Zbbc [BBLL1]");       // RUN11 pp
0648     */
0649     TC[0]->cd();
0650     transparent[0] = new TPad("transparent0", "this does not show", 0, 0, 1, 1, 0, 0);
0651     transparent[0]->SetFillStyle(4000);
0652     transparent[0]->Draw();
0653 
0654     /*
0655     ifnew(TLine(BbcMonDefs::BBC_MIN_REGULAR_ZVERTEX_MEAN, -6,
0656                 BbcMonDefs::BBC_MIN_REGULAR_ZVERTEX_MEAN, 16),
0657           LineTzeroZvtx[0]);
0658     ifnew(TLine(BbcMonDefs::BBC_MAX_REGULAR_ZVERTEX_MEAN, -6,
0659                 BbcMonDefs::BBC_MAX_REGULAR_ZVERTEX_MEAN, 16),
0660           LineTzeroZvtx[1]);
0661     ifnew(TLine(-200, BbcMonDefs::BBC_MIN_REGULAR_TDC1_MEAN - 5,
0662                 200, BbcMonDefs::BBC_MIN_REGULAR_TDC1_MEAN - 5),
0663           LineTzeroZvtx[2]);
0664     ifnew(TLine(-200, BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN - 5,
0665                 200, BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN - 5),
0666           LineTzeroZvtx[3]);
0667     ifnew(TText, TextTzeroZvtx);
0668     */
0669   }
0670 
0671   else if (name == "BbcMon2")
0672   {
0673     std::cout << "Creating Canvas BbcMon2..." << std::endl;
0674 
0675     TC[1] = new TCanvas("BbcMon2", "Beam status view for Shift crew", -xsize / 2, 0, xsize / 2, ysize);
0676     gSystem->ProcessEvents();
0677     TC[1]->cd();
0678     PadTop[1] = new TPad("PadTop1", "PadTop1", 0.00, 0.90, 1.00, 1.00, 0, 0, 0);
0679     PadTimeWave = new TPad("PadTimeWave", "PadTimeWave", 0.00, 0.30, 1.00, 0.90, 0, 0, 0);
0680     PadSouthHitTime = new TPad("PadHitTimeSouth1", "PadHitTimeSouth1", 0.00, 0.00, 0.50, 0.30, 0, 0, 0);
0681     PadNorthHitTime = new TPad("PadHitTimeNorth1", "PadHitTimeNorth1", 0.50, 0.00, 1.00, 0.30, 0, 0, 0);
0682 
0683     // PadArmHit = new TPad("PadArmHit", "PadArmHit", 0.50, 0.00, 1.00, 0.40, 0, 0, 0);
0684     // PadBbcSummary = new TPad("PadBbcSummary", "PadBbcSummary", 0.00, 0.40, 1.00, 0.55, 0, 0, 0);
0685     // PadAvrHitTime = new TPad("PadAvrHitTime", "PadAvrHitTime", 0.00, 0.00, 0.50, 0.40, 0, 0, 0);
0686 
0687     // PadArmHit->SetLogz();
0688 
0689     PadTop[1]->Draw();
0690     if (PadTimeWave)
0691     {
0692       PadTimeWave->Draw();
0693     }
0694     if (PadNorthHitTime)
0695     {
0696       PadNorthHitTime->Draw();
0697     }
0698     if (PadSouthHitTime)
0699     {
0700       PadSouthHitTime->Draw();
0701     }
0702     if (PadArmHit)
0703     {
0704       PadArmHit->Draw();
0705     }
0706     if (PadBbcSummary)
0707     {
0708       PadBbcSummary->Draw();
0709     }
0710     if (PadAvrHitTime)
0711     {
0712       PadAvrHitTime->Draw();
0713     }
0714 
0715     ifnew(TText, TextBbcSummaryHitTime[0]);
0716     ifnew(TText, TextBbcSummaryHitTime[1]);
0717     ifnew(TText, TextBbcSummaryZvertex);
0718     ifnew(TText, TextBbcSummaryGlobalOffset[0]);
0719     ifnew(TText, TextBbcSummaryGlobalOffset[1]);
0720     // TextBbcSummaryHitTime->SetTextSize(0.2);
0721     TextBbcSummaryHitTime[0]->SetTextSize(0.2);
0722     TextBbcSummaryHitTime[1]->SetTextSize(0.2);
0723     TextBbcSummaryZvertex->SetTextSize(0.2);
0724     TextBbcSummaryGlobalOffset[0]->SetTextSize(0.2);
0725     TextBbcSummaryGlobalOffset[1]->SetTextSize(0.2);
0726 
0727     ifnew(TArc(10.5, 10.5, 4, 0, 360), ArcArmHit);
0728     ArcArmHit->SetFillStyle(4000);
0729     // ifnew( TArc(10.5, 10.5, 4), ArcArmHit );
0730     ifnew(TText, TextArmHit);
0731     TextArmHit->SetTextSize(0.08);
0732     TextArmHit->SetText(10, 4, "Good region");
0733 
0734     // PadSouthHitTime = new TPad("PadSouthHitTime", "PadSouthHitTime", 0.00, 0.55, 0.50, 0.90, 0);
0735     // PadNorthHitTime = new TPad("PadNorthHitTime", "PadNorthHitTime", 0.50, 0.55, 1.00, 0.90, 0);
0736 
0737     if (PadAvrHitTime)
0738     {
0739       ifnew(TLine(BbcMonDefs::BBC_MIN_REGULAR_TDC1_MEAN, 0,
0740                   BbcMonDefs::BBC_MIN_REGULAR_TDC1_MEAN, 10000),
0741             LineAvrHitTime[0]);
0742       ifnew(TLine(BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 0,
0743                   BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 10000),
0744             LineAvrHitTime[1]);
0745 
0746       ifnew(TArrow(BbcMonDefs::BBC_MIN_REGULAR_TDC1_MEAN, 10000,
0747                    BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 10000),
0748             ArrowAvrHitTime);
0749       ArrowAvrHitTime->SetOption("<>");
0750 
0751       ifnew(TText, TextAvrHitTime);
0752       TextAvrHitTime->SetTextSize(0.08);
0753       TextAvrHitTime->SetText(BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 10000, " good mean");
0754 
0755       LineAvrHitTime[0]->SetLineColor(9);
0756       LineAvrHitTime[1]->SetLineColor(9);
0757       ArrowAvrHitTime->SetLineColor(9);
0758       TextAvrHitTime->SetTextColor(9);
0759     }
0760 
0761     if (PadSouthHitTime)
0762     {
0763       ifnew(TLine(BbcMonDefs::BBC_MIN_REGULAR_TDC1_MEAN, 0,
0764                   BbcMonDefs::BBC_MIN_REGULAR_TDC1_MEAN, 10000),
0765             LineSouthHitTime[0]);
0766       ifnew(TLine(BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 0,
0767                   BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 10000),
0768             LineSouthHitTime[1]);
0769 
0770       ifnew(TArrow(BbcMonDefs::BBC_MIN_REGULAR_TDC1_MEAN, 10000,
0771                    BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 10000),
0772             ArrowSouthHitTime);
0773       ArrowSouthHitTime->SetOption("<>");
0774 
0775       ifnew(TText, TextSouthHitTime);
0776       TextSouthHitTime->SetTextSize(0.08);
0777       TextSouthHitTime->SetText(BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 10000, " good mean");
0778 
0779       LineSouthHitTime[0]->SetLineColor(9);
0780       LineSouthHitTime[1]->SetLineColor(9);
0781       ArrowSouthHitTime->SetLineColor(9);
0782       TextSouthHitTime->SetTextColor(9);
0783     }
0784 
0785     if (PadNorthHitTime)
0786     {
0787       ifnew(TLine(BbcMonDefs::BBC_MIN_REGULAR_TDC1_MEAN, 0,
0788                   BbcMonDefs::BBC_MIN_REGULAR_TDC1_MEAN, 10000),
0789             LineNorthHitTime[0]);
0790       ifnew(TLine(BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 0,
0791                   BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 10000),
0792             LineNorthHitTime[1]);
0793 
0794       ifnew(TArrow(BbcMonDefs::BBC_MIN_REGULAR_TDC1_MEAN, 10000,
0795                    BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 10000),
0796             ArrowNorthHitTime);
0797       ArrowNorthHitTime->SetOption("<>");
0798 
0799       ifnew(TText, TextNorthHitTime);
0800       TextNorthHitTime->SetTextSize(0.08);
0801       TextNorthHitTime->SetText(BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 10000, " good mean");
0802 
0803       LineNorthHitTime[0]->SetLineColor(9);
0804       LineNorthHitTime[1]->SetLineColor(9);
0805       ArrowNorthHitTime->SetLineColor(9);
0806       TextNorthHitTime->SetTextColor(9);
0807     }
0808 
0809     transparent[1] = new TPad("transparent1", "this does not show", 0, 0, 1, 1, 0, 0);
0810     transparent[1]->SetFillStyle(4000);
0811     transparent[1]->Draw();
0812   }
0813 
0814   //
0815   // 3rd Page
0816   else if (name == "BbcMon3")
0817   {
0818     std::cout << "Creating Canvas BbcMon3..." << std::endl;
0819 
0820     // ifnew( TText, TextBbcSummaryTrigRate );
0821     ifnew(TLatex, TextBbcSummaryTrigRate);
0822     // TextBbcSummaryTrigRate->SetTextSize(0.109);
0823     TextBbcSummaryTrigRate->SetTextSize(0.08);
0824     // TextBbcSummaryTrigRate->SetTextSize(0.075);
0825 
0826     TC[2] = new TCanvas("BbcMon3", "Trigger view for Shift crew", -1, 0, xsize / 2, ysize);
0827     gSystem->ProcessEvents();
0828     TC[2]->cd();
0829 
0830     PadTop[2] = new TPad("PadTop2", "PadTop3", 0.00, 0.90, 1.00, 1.00, 0, 0, 0);
0831     PadTop[2]->Draw();
0832 
0833     PadZvtx  = new TPad("PadZvtx", "PadZvtx", 0.00, 0.60, 0.50, 0.90, 0, 0, 0);
0834     PadNhits = new TPad("PadNhits", "PadNhits", 0.50, 0.60, 1.00, 0.90, 0, 0, 0);
0835     PadZvtx->SetLeftMargin(0.17);
0836     PadNhits->SetLeftMargin(0.17);
0837     PadZvtx->Draw();
0838     PadNhits->Draw();
0839 
0840     /*
0841     PadHitTime[0] = new TPad("PadHitTimeSouth1", "PadHitTimeSouth1", 0.00, 0.60, 0.50, 0.90, 0, 0, 0);
0842     PadHitTime[1] = new TPad("PadHitTimeNorth1", "PadHitTimeNorth1", 0.50, 0.60, 1.00, 0.90, 0, 0, 0);
0843     PadHitTime[0]->SetLeftMargin(0.17);
0844     PadHitTime[1]->SetLeftMargin(0.17);
0845     PadHitTime[0]->Draw();
0846     PadHitTime[1]->Draw();
0847 
0848     for (int side = 0; side < nSIDE; side++)
0849     {
0850       ifnew(TLine(BbcMonDefs::BBC_MIN_REGULAR_TDC1_MEAN, 0, BbcMonDefs::BBC_MIN_REGULAR_TDC1_MEAN, 10000), LineHitTime[side][0]);
0851       ifnew(TLine(BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 0, BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 10000), LineHitTime[side][1]);
0852 
0853       ifnew(TArrow(BbcMonDefs::BBC_MIN_REGULAR_TDC1_MEAN, 10000,
0854                    BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 10000),
0855             ArrowHitTime[side]);
0856       ArrowHitTime[side]->SetOption("<>");
0857 
0858       ifnew(TText, TextHitTime[side]);
0859       TextHitTime[side]->SetTextSize(0.08);
0860       TextHitTime[side]->SetText(BbcMonDefs::BBC_MAX_REGULAR_TDC1_MEAN, 10000, " good mean");
0861 
0862       LineHitTime[side][0]->SetLineColor(9);
0863       LineHitTime[side][1]->SetLineColor(9);
0864       ArrowHitTime[side]->SetLineColor(9);
0865       TextHitTime[side]->SetTextColor(9);
0866     }
0867     */
0868 
0869     PadZvtxEMCAL  = new TPad("PadZvtxEMCAL", "PadZvtxEMCAL", 0.00, 0.30, 0.50, 0.60, 0, 0, 0);
0870     PadNhitsEMCAL = new TPad("PadNhitsEMCAL", "PadNhitsEMCAL", 0.50, 0.30, 1.00, 0.60, 0, 0, 0);
0871     PadZvtxEMCAL->SetLeftMargin(0.17);
0872     PadNhitsEMCAL->SetLeftMargin(0.17);
0873     PadZvtxEMCAL->Draw();
0874     PadNhitsEMCAL->Draw();
0875 
0876     PadZvtxHCAL  = new TPad("PadZvtxHCAL", "PadZvtxHCAL", 0.00, 0.00, 0.50, 0.30, 0, 0, 0);
0877     PadNhitsHCAL = new TPad("PadNhitsHCAL", "PadNhitsHCAL", 0.50, 0.00, 1.00, 0.30, 0, 0, 0);
0878     PadZvtxHCAL->SetLeftMargin(0.17);
0879     PadNhitsHCAL->SetLeftMargin(0.17);
0880     PadZvtxHCAL->Draw();
0881     PadNhitsHCAL->Draw();
0882 
0883     /*
0884     // for Zvtx
0885     PadZvtx = new TPad("PadZvtx", "PadZvtx", 0.00, 0.30, 0.50, 0.60, 0, 0, 0);
0886     if (PadZvtx)
0887     {
0888       PadZvtx->SetLeftMargin(0.17);
0889       PadZvtx->Draw();
0890       ifnew(TLine(BbcMonDefs::BBC_MIN_REGULAR_ZVERTEX_MEAN, 0,
0891                   BbcMonDefs::BBC_MIN_REGULAR_ZVERTEX_MEAN, 10000),
0892             LineZvtx[0]);
0893       ifnew(TLine(BbcMonDefs::BBC_MAX_REGULAR_ZVERTEX_MEAN, 0,
0894                   BbcMonDefs::BBC_MAX_REGULAR_ZVERTEX_MEAN, 10000),
0895             LineZvtx[1]);
0896 
0897       ifnew(TArrow(BbcMonDefs::BBC_MIN_REGULAR_ZVERTEX_MEAN, 10000,
0898                    BbcMonDefs::BBC_MAX_REGULAR_ZVERTEX_MEAN, 10000),
0899             ArrowZvtx);
0900       ArrowZvtx->SetOption("<>");
0901 
0902       ifnew(TText, TextZvtx);
0903       TextZvtx->SetTextSize(0.08);
0904       TextZvtx->SetText(BbcMonDefs::BBC_MAX_REGULAR_ZVERTEX_MEAN, 10000, " good mean");
0905       ifnew(TText, TextZvtxNorth);
0906       TextZvtxNorth->SetTextSize(0.05);
0907       TextZvtxNorth->SetText(130, 0, "North");
0908       ifnew(TText, TextZvtxSouth);
0909       TextZvtxSouth->SetTextSize(0.05);
0910       TextZvtxSouth->SetText(-160, 0, "South");
0911 
0912       LineZvtx[0]->SetLineColor(9);
0913       LineZvtx[1]->SetLineColor(9);
0914       ArrowZvtx->SetLineColor(9);
0915       TextZvtx->SetTextColor(9);
0916     }
0917     */
0918 
0919     /*
0920     PadChargeSum = new TPad("PadChargeSum", "PadCHargeSum", 0.50, 0.30, 1.00, 0.60, 0, 0, 0);
0921     PadChargeSum->SetLogy();
0922     PadChargeSum->Draw();
0923 
0924     ifnew(TText, TextNorthChargeSum);
0925     // SetNDC(): this will use normalized coordinates (0-1/0-1) for drawing no matter what the histogram uses
0926     TextNorthChargeSum->SetNDC();
0927     TextNorthChargeSum->SetTextSize(0.08);
0928     TextNorthChargeSum->SetText(0.3, 0.8, "--North");  // for p+p
0929     TextNorthChargeSum->SetTextColor(4);
0930 
0931     ifnew(TText, TextSouthChargeSum);
0932     // SetNDC(): this will use normalized coordinates (0-1/0-1) for drawing no matter what the histogram uses
0933     TextSouthChargeSum->SetNDC();
0934     TextSouthChargeSum->SetTextSize(0.08);
0935     TextSouthChargeSum->SetText(0.6, 0.8, "--South");  // for p+p
0936     TextSouthChargeSum->SetTextColor(2);
0937     */
0938 
0939     /*
0940     PadAdc = new TPad("PadAdc", "PadAdc", 0.00, 0.00, 1.00, 0.30, 0, 0, 0);
0941     PadAdc->SetLogz();
0942     PadAdc->Draw();
0943     */
0944 
0945     transparent[2] = new TPad("transparent2", "this does not show", 0, 0, 1, 1);
0946     transparent[2]->SetFillStyle(4000);
0947     transparent[2]->Draw();
0948 
0949     // PadHitTime[1][0]->SetLogy();
0950     // PadHitTime[1][1]->SetLogy();
0951 
0952     /*
0953        ifnew( TPad("PadButton" , "PadButton" , 0.00, 0.70, 1.00, 0.90, 0), PadButton);
0954        ifnew( TPad("PadMultiView" , "PadMultiView" , 0.10, 0.20, 1.00, 0.70, 0), PadMultiView);
0955        ifnew( TPad("PadWarnings" , "PadWarnings" , 0.00, 0.00, 1.00, 0.20, 0), PadWarnings);
0956        PadMultiView->Draw();
0957        PadWarnings->Draw();
0958        PadButton->Draw();
0959        ifnew( TPaveText(0.05, 0.05, 0.95, 0.95) , PaveWarnings );
0960        */
0961 
0962     // TC[3]->SetEditable(0);
0963   }
0964 
0965   else if (name == "BbcMon4")
0966   {
0967     std::cout << "Creating Canvas BbcMon4..." << std::endl;
0968 
0969     TC[3] = new TCanvas("BbcMon4", "MBD status view for Expert", -xsize / 2, 0, xsize / 2, ysize);
0970     gSystem->ProcessEvents();
0971     TC[3]->cd();
0972 
0973     PadTop[3] = new TPad("PadTop0", "PadTop0", 0.00, 0.90, 1.00, 1.00, 0, 0, 0);
0974     PadTdcOver[0] = new TPad("PadTdcOverSouth0", "PadTdcOverSouth0", 0.00, 0.30, 0.50, 0.60, 0, 0, 0);
0975     PadTdcOver[1] = new TPad("PadTdcOverNorth1", "PadTdcOverNorth1", 0.50, 0.60, 1.00, 0.90, 0, 0, 0);
0976     PadnHit[1] = new TPad("PadnHitNorth", "PadnHitNorth", 0.50, 0.03, 1.00, 0.30, 0, 0, 0);
0977     PadnHit[0] = new TPad("PadnHitSouth", "PadnHitSouth", 0.00, 0.03, 0.50, 0.30, 0);
0978     PadnHitStatus = new TPad("PadnHitStatus", "PadnHitStatus", 0.00, 0.00, 1.00, 0.03, 0, 0, 0);
0979 
0980     PadTop[3]->Draw();
0981     for (int side = 0; side < nSIDE; side++)
0982     {
0983       PadTdcOver[side]->Draw();
0984       PadnHit[side]->Draw();
0985       PadnHitStatus->Draw();
0986 
0987       ifnew(TBox(0.5, BbcMonDefs::BBC_nHIT_MB_MIN[side], nPMT_1SIDE_BBC + .5, BbcMonDefs::BBC_nHIT_MB_MAX[side]), BoxnHit[0][side]);
0988       BoxnHit[0][side]->SetFillColor(5);
0989       BoxnHit[0][side]->SetLineColor(3);
0990 
0991       ifnew(TBox(0.5, BbcMonDefs::BBC_nHIT_LASER_MIN[side], nPMT_1SIDE_BBC + .5, BbcMonDefs::BBC_nHIT_LASER_MAX[side]), BoxnHit[1][side]);
0992       BoxnHit[1][side]->SetFillColor(7);
0993       BoxnHit[1][side]->SetLineColor(4);
0994     }
0995 
0996     for (auto &side : BoxTdcOver)
0997     {
0998       ifnew(TBox(0.5, BbcMonDefs::BBC_TDC_OVERFLOW_REGULAR_MIN, nPMT_1SIDE_BBC + .5, BbcMonDefs::BBC_TDC_OVERFLOW_REGULAR_MAX), side);
0999       side->SetFillColor(5);
1000       side->SetLineColor(3);
1001     }
1002     ifnew(TText, TextnHitStatus);
1003     TextnHitStatus->SetTextSize(0.7);
1004     TextnHitStatus->SetText(0.05, 0.5, "Red Square : Collision Event  / Blue Triangle : Laser Event");
1005     transparent[3] = new TPad("transparent3", "this does not show", 0, 0, 1, 1, 0, 0);
1006     transparent[3]->SetFillStyle(4000);
1007     transparent[3]->Draw();
1008   }
1009   else if (name == "BbcVertexSend")
1010   {
1011     TC[4] = new TCanvas(name.c_str(), "Bbc Vertex Sender", -1, 0, 2 * xsize / 3, ysize * 0.9);
1012     gSystem->ProcessEvents();
1013     TC[4]->cd();
1014     // this one is used to plot the run number on the canvas
1015     transparent[4] = new TPad("transparent4", "this does not show", 0, 0, 1, 1);
1016     transparent[4]->SetFillColor(kGray);
1017    transparent[4]->Draw();
1018      TC[4]->SetEditable(false);
1019   }
1020   else if (name == "BbcMonServerStats")
1021     {
1022       TC[5] = new TCanvas(name.c_str(), "BbcMon Server Stats", -1, 0, 2 * xsize / 3, ysize * 0.9);
1023       gSystem->ProcessEvents();
1024       TC[5]->cd();
1025       // this one is used to plot the run number on the canvas
1026       transparent[5] = new TPad("transparent4", "this does not show", 0, 0, 1, 1);
1027       transparent[5]->SetFillColor(kGray);
1028       transparent[5]->Draw();
1029       TC[5]->SetEditable(false);
1030     }
1031 
1032   else if (name == "BbcMon5")
1033   {
1034     std::cout << "Creating Canvas BbcMon5..." << std::endl;
1035 
1036     TC[6] = new TCanvas("BbcMon5", "MBD Z-Vertex View for Shift crew", -1, 0, xsize / 2, ysize);
1037 
1038     // root is pathetic, whenever a new TCanvas is created root piles up
1039     // 6kb worth of X11 events which need to be cleared with
1040     // gSystem->ProcessEvents(), otherwise your process will grow and
1041     // grow and grow but will not show a definitely lost memory leak
1042     gSystem->ProcessEvents();
1043 
1044     TC[6]->cd();
1045     PadTop[4] = new TPad("PadTop0", "PadTop0", 0.00, 0.90, 1.00, 1.00, 0, 0, 0);
1046     PadZVertex = new TPad("PadZVertex", "PadZVertex", 0.00, 0.70, 1.00, 0.90, 0, 0, 0);
1047     PadZVertexSummary = new TPad("PadZVertexSummary", "PadZVertexSummary", 0.00, 0.55, 1.00, 0.70, 0, 0, 0);
1048     PadRunZVertex = new TPad("PadRunZVertex", "PadRunZVertex", 0.00, 0.40, 1.00, 0.55, 0, 0, 0);
1049     PadSouthHitMap = new TPad("PadSouthHitMap", "PadSouthHitMap", 0.00, 0.00, 0.495, 0.40, 0, 0, 0);
1050     PadNorthHitMap = new TPad("PadNorthHitMap", "PadNorthHitMap", 0.505, 0.00, 1.0, 0.40, 0, 0, 0);
1051     // PadTzeroZVertex = new TPad("PadTzeroZVertex", "PadTzeroZVertex", 0.00, 0.00, 1.00, 0.40, 0, 0, 0);
1052 
1053     PadTop[4]->Draw();
1054     // PadZVertex->SetLogy();
1055     PadZVertex->Draw();
1056     PadRunZVertex->Draw();
1057     // PadTzeroZVertex->Draw();
1058     PadSouthHitMap->Draw();
1059     PadNorthHitMap->Draw();
1060     PadZVertexSummary->Draw();
1061 
1062     PadZVertexSummary->cd();
1063     // for (int i = 0; i < 4; i++)
1064     for (int i = 0; i < 1; i++)  //  pp
1065     {
1066       ifnew(TText, TextZVertex[i]);
1067       TextZVertex[i]->SetTextColor(BbcMonDefs::BBC_COLOR_ZVTX[i]);
1068       // TextZVertex[i]->SetTextSize(0.15);
1069       TextZVertex[i]->SetTextSize(0.08);
1070 
1071       ifnew(TText, TextZVertex_scale[i]);
1072       ifnew(TText, TextZVertex_mean[i]);
1073       TextZVertex_scale[i]->SetTextColor(BbcMonDefs::BBC_COLOR_ZVTX[i]);
1074       TextZVertex_mean[i]->SetTextColor(BbcMonDefs::BBC_COLOR_ZVTX[i]);
1075       TextZVertex_scale[i]->SetTextSize(0.08);
1076       TextZVertex_mean[i]->SetTextSize(0.08);
1077     }
1078     /*chiu
1079     TextZVertex[0]->SetText(xpos[0], 0.65, "Zbbc [BBLL1]");       // RUN11 pp
1080     */
1081     TC[6]->cd();
1082     transparent[6] = new TPad("transparent6", "this does not show", 0, 0, 1, 1, 0, 0);
1083     transparent[6]->SetFillStyle(4000);
1084     transparent[6]->Draw();
1085   }
1086   else if (name == "BbcAutoUpdate")
1087   {
1088     
1089     TC[8] = new TCanvas(name.c_str(), "Bbc Autoupdating", -1, 0, 2 * xsize / 3, ysize * 0.9);
1090     gSystem->ProcessEvents();
1091     TC[8]->cd();
1092     // this one is used to plot the run number on the canvas
1093     transparent[8] = new TPad("transparent8", "this does not show", 0, 0, 1, 1);
1094     transparent[8]->SetFillColor(kGray);
1095     transparent[8]->Draw();
1096     TC[8]->SetEditable(false);
1097 
1098     // create 4x2 grid of pads
1099     for (int i = 0; i < nCANVAS; i++)
1100     {
1101       std::string padname = "PadAutoUpdate" + std::to_string(i);
1102       PadAutoUpdate[i] = new TPad(padname.c_str(), padname.c_str(), (i % 4) * 0.25, (i / 4) * 0.5, (i % 4 + 1) * 0.25, (i / 4 + 1) * 0.5, 0, 0, 0);
1103       PadAutoUpdate[i]->SetFillColor(kWhite);
1104       PadAutoUpdate[i]->Draw();
1105     }
1106   }
1107   else
1108   {
1109     std::cout << "Unknown canvas name: " << name << std::endl;
1110     return -1;
1111   }
1112   //
1113 
1114   /*
1115      if ( ( strlen(name) < 1 || strcmp(name, "BBCMon1") == 0 ) ||
1116      ( strlen(name) < 1 || strcmp(name, "BBCMon2") == 0 ) ||
1117      ( strlen(name) < 1 || strcmp(name, "BBCMon3") == 0 ) ||
1118      ( strlen(name) < 1 || strcmp(name, "BBCMon4") == 0 ) )
1119      */
1120   {
1121     ifnew(TPaveText(0.05, 0.65, 0.70, 0.95), PaveTop);
1122     PaveTop->AddText("MBD ONLINE MONITOR");
1123     ifnew(TText, TextTop);
1124     TextTop->SetTextSize(0.25);
1125   }
1126 
1127   std::cout << "Initialize completed" << std::endl;
1128 
1129   return 0;
1130 }
1131 
1132 int BbcMonDraw::Draw(const std::string &what)
1133 {
1134   PRINT_DEBUG("In BbcMonDraw::Draw()");
1135   std::cout << what << std::endl;
1136 
1137   TStyle *oldStyle = gStyle;
1138   bbcStyle->cd();
1139   int canvasindex = -1;
1140   if (!gROOT->FindObject("BbcMon1"))
1141   {
1142     PRINT_DEBUG("In BbcMonDraw::Draw(), BbcMon1");
1143     TC[0] = nullptr;
1144     if (what == "ALL" || what == "FIRST" || what == "BbcMon1" || what == "BbcMonitor")
1145     {
1146       canvasindex = 0;
1147       MakeCanvas("BbcMon1");
1148     }
1149   }
1150   if (!gROOT->FindObject("BbcMon2"))
1151   {
1152     PRINT_DEBUG("In BbcMonDraw::Draw(), BbcMon2");
1153     TC[1] = nullptr;
1154     if (what == "ALL" || what == "SECOND" || what == "BbcMon2" || what == "VertexMonitor")
1155     {
1156       canvasindex = 1;
1157       MakeCanvas("BbcMon2");
1158     }
1159   }
1160   if (!gROOT->FindObject("BbcMon3"))
1161   {
1162     TC[2] = nullptr;
1163     if (what == "ALL" || what == "THIRD" ||  what == "BbcMon3" || what == "TriggerMonitor")
1164     {
1165       canvasindex = 2;
1166       MakeCanvas("BbcMon3");
1167     }
1168   }
1169   // 4th canvas
1170   if (!gROOT->FindObject("BbcMon4"))
1171   {
1172     TC[3] = nullptr;
1173     if (what == "BbcMon4" || what == "VertexMonitor")
1174     {
1175       canvasindex = 3;
1176       MakeCanvas("BbcMon4");
1177     }
1178   }
1179   if (!gROOT->FindObject("BbcMon5"))
1180   {
1181     TC[6] = nullptr;
1182     if (what == "BbcMon5" || what == "VertexMonitor")
1183     {
1184       canvasindex = 6;
1185       MakeCanvas("BbcMon5");
1186     }
1187   }
1188   
1189 
1190   //
1191   if ( what == "MBD2MCR" )
1192   {
1193     if (!gROOT->FindObject("BbcVertexSend"))
1194     {
1195       MakeCanvas("BbcVertexSend");
1196     }
1197     TC[4]->Clear("D");
1198     TC[4]->SetEditable(true);
1199     transparent[4]->cd();
1200 
1201     TText PrintRun;
1202     PrintRun.SetTextFont(62);
1203     PrintRun.SetNDC();          // set to normalized coordinates
1204     PrintRun.SetTextAlign(23);  // center/top alignment
1205     PrintRun.SetTextSize(0.04);
1206     PrintRun.SetTextColor(1);
1207 
1208     GetSendFlag();
1209     if ( sendflag==0 )
1210     {
1211       UpdateSendFlag( 1 );
1212       PrintRun.DrawText(0.5, 0.5, "MBD: NOW Sending vertex to MCR");
1213       std::cout << "MBD: NOW Sending vertex to MCR" << std::endl;
1214     }
1215     else if ( sendflag==1 )
1216     {
1217       UpdateSendFlag( 0 );
1218       PrintRun.DrawText(0.5, 0.5, "MBD: STOP sending vertex to MCR");
1219       std::cout << "MBD: STOP sending vertex to MCR" << std::endl;
1220     }
1221     else
1222     {
1223       UpdateSendFlag( 0 );
1224       PrintRun.DrawText(0.5, 0.5, "MBD: something wrong with sendflag, setting to 0");
1225       std::cout << "MBD: something wrong with sendflag, setting to 0" << std::endl;
1226     }
1227     TC[4]->Update();
1228     TC[4]->Show();
1229     TC[4]->SetEditable(false);
1230     return 0;
1231   }
1232 
1233   //
1234   if ( what == "MBDZRESET" )
1235   {
1236     UpdateZResetFlag( 1 );
1237     return 0;
1238   }
1239 
1240   if ( what == "BADGL1" )
1241   {
1242     GetGL1BadFlag();
1243     if ( gl1badflag==0 )
1244     {
1245       UpdateGL1BadFlag( 1 );
1246     }
1247     else if ( gl1badflag==1 )
1248     {
1249       UpdateGL1BadFlag( 0 );
1250     }
1251     else
1252     {
1253       UpdateGL1BadFlag( 0 );
1254     }
1255     return 0;
1256   }
1257 
1258   if ( what == "BbcMonServerStats" )
1259   {
1260     OnlMonClient *cl = OnlMonClient::instance();
1261       if (!gROOT->FindObject("BbcMonServerStats"))
1262     {
1263       MakeCanvas("BbcMonServerStats");
1264     }
1265       TC[5]->Clear("D");
1266       TC[5]->SetEditable(true);
1267       transparent[5]->cd();
1268 
1269       TText PrintRun;
1270     PrintRun.SetTextFont(62);
1271     PrintRun.SetNDC();          // set to normalized coordinates
1272     PrintRun.SetTextAlign(23);  // center/top alignment
1273     PrintRun.SetTextSize(0.04);
1274     PrintRun.SetTextColor(1);
1275     PrintRun.DrawText(0.5, 0.99, "Server Statistics");
1276     PrintRun.SetTextSize(0.02);
1277     double vdist = 0.05;
1278     double vpos = 0.9;
1279     for (const auto &server : m_ServerSet)
1280     {
1281       std::ostringstream txt;
1282       auto servermapiter = cl->GetServerMap(server);
1283       if (servermapiter == cl->GetServerMapEnd())
1284       {
1285         txt << "Server " << server
1286             << " is dead ";
1287         PrintRun.SetTextColor(kRed);
1288       }
1289       else
1290       {
1291         int gl1counts = std::get<4>(servermapiter->second);
1292         txt << "Server " << server
1293             << ", run number " << std::get<1>(servermapiter->second)
1294             << ", event count: " << std::get<2>(servermapiter->second);
1295         if (gl1counts >= 0)
1296     {
1297             txt << ", gl1 count: " << std::get<4>(servermapiter->second);
1298     }
1299         txt << ", current time " << ctime(&(std::get<3>(servermapiter->second)));
1300         if (std::get<0>(servermapiter->second))
1301         {
1302           PrintRun.SetTextColor(kGray + 2);
1303         }
1304         else
1305         {
1306           PrintRun.SetTextColor(kRed);
1307         }
1308       }
1309       PrintRun.DrawText(0.5, vpos, txt.str().c_str());
1310       vpos -= vdist;
1311     }
1312     TC[5]->Update();
1313     TC[5]->Show();
1314     TC[5]->SetEditable(false);
1315     return 0;
1316   }
1317   
1318   if (what == "BbcAutoUpdate" )
1319   {
1320     if (!gROOT->FindObject("BbcAutoUpdate"))
1321     {
1322       canvasindex = 8;
1323       MakeCanvas("BbcAutoUpdate");
1324     }
1325   }
1326 
1327   ClearWarning();
1328 
1329   std::ostringstream otext;
1330   std::string text;
1331   std::string textok;
1332   // std::ostringstream textok;
1333 
1334   // ---------------------------------------------------------------------------------
1335   // Get Histograms from BbcMon server
1336 
1337   OnlMonClient *cl = OnlMonClient::instance();
1338 
1339   PRINT_DEBUG("Start Getting Histogram");
1340 
1341   TH1 *bbc_trigs = cl->getHisto("BBCMON_0", "bbc_trigs");
1342   ifdelete(Trigs);
1343   if ( bbc_trigs!=0 )
1344   {
1345     Trigs = static_cast<TH1 *>(bbc_trigs->Clone());
1346   }
1347 
1348   std::ostringstream name;
1349 
1350   TH1 *bbc_south_nhit = cl->getHisto("BBCMON_0", "bbc_south_nhit");
1351   if (! bbc_south_nhit)
1352   {
1353     if (canvasindex >= 0)
1354     {
1355       DrawDeadServer(transparent[canvasindex]);
1356     }
1357     return -1;
1358   }
1359   ifdelete(South_Nhit);
1360   South_Nhit = static_cast<TH1 *>(bbc_south_nhit->Clone());
1361 
1362   TH1 *bbc_north_nhit = cl->getHisto("BBCMON_0", "bbc_north_nhit");
1363   ifdelete(North_Nhit);
1364   North_Nhit = static_cast<TH1 *>(bbc_north_nhit->Clone());
1365 
1366   for (int iarm=0; iarm<2; iarm++)
1367   {
1368     TString name2 = "bbc_nhit_emcal"; name2 += iarm;
1369     TH1 *bbc_nhit_emcal = cl->getHisto("BBCMON_0", name2.Data());
1370     ifdelete(Nhit_emcal[iarm]);
1371     Nhit_emcal[iarm] = static_cast<TH1 *>(bbc_nhit_emcal->Clone());
1372 
1373     name2 = "bbc_nhit_hcal"; name2 += iarm;
1374     TH1 *bbc_nhit_hcal = cl->getHisto("BBCMON_0", name2.Data());
1375     ifdelete(Nhit_hcal[iarm]);
1376     Nhit_hcal[iarm] = static_cast<TH1 *>(bbc_nhit_hcal->Clone());
1377 
1378     name2 = "bbc_nhit_emcalmbd"; name2 += iarm;
1379     TH1 *bbc_nhit_emcalmbd = cl->getHisto("BBCMON_0", name2.Data());
1380     ifdelete(Nhit_emcalmbd[iarm]);
1381     Nhit_emcalmbd[iarm] = static_cast<TH1 *>(bbc_nhit_emcalmbd->Clone());
1382 
1383     name2 = "bbc_nhit_hcalmbd"; name2 += iarm;
1384     TH1 *bbc_nhit_hcalmbd = cl->getHisto("BBCMON_0", name2.Data());
1385     ifdelete(Nhit_hcalmbd[iarm]);
1386     Nhit_hcalmbd[iarm] = static_cast<TH1 *>(bbc_nhit_hcalmbd->Clone());
1387   }
1388 
1389   TH1 *bbc_nevent_counter = cl->getHisto("BBCMON_0", "bbc_nevent_counter");
1390 
1391   TH2 *bbc_tdc = static_cast<TH2 *>(cl->getHisto("BBCMON_0", "bbc_tdc"));
1392   //std::cout << "BBCTDC2 " << (uint64_t)bbc_tdc << std::endl;
1393 
1394   /*
1395   name << "bbc_tdc_overflow" ;
1396   bbc_tdc_overflow =  static_cast<TH2 *> (cl->getHisto("BBCMON_0",name.str().c_str()));
1397   name.str("");
1398 
1399   for ( int i = 0 ; i < nPMT_BBC ; i++ )
1400   {
1401     name << "bbc_tdc_overflow_" << setw(3) << setfill('0') << i ;
1402     bbc_tdc_overflow_each[i] = cl->getHisto("BBCMON_0",name.str().c_str());
1403     name.str("");
1404   }
1405   */
1406 
1407   TH2 *bbc_adc = static_cast<TH2 *>(cl->getHisto("BBCMON_0", "bbc_adc"));
1408   ifdelete(Adc);
1409   for (int i = 0; i < nCANVAS; i++)
1410   {
1411     if (TC[i] && i != 4 && i != 5)
1412     {
1413       transparent[i]->Clear();  // clear dead server msg if it was printed before
1414     }
1415   }
1416 
1417   if (bbc_adc)
1418   {
1419     Adc = static_cast<TH2 *>(bbc_adc->Clone());
1420   }
1421   else
1422   {
1423     // here I assume server is dead and there must be a message saying so
1424     std::cout << "SERVER IS DEAD, no bbc_adc" << std::endl;
1425     for (auto &i : TC)
1426     {
1427       if (i)
1428       {
1429         i->cd();
1430         i->Clear("D");
1431         //        DrawDeadServer(transparent[i]);
1432         i->Update();
1433       }
1434     }
1435     return -1;
1436   }
1437 
1438   TH2 *bbc_tdc_armhittime = static_cast<TH2 *>(cl->getHisto("BBCMON_0", "bbc_tdc_armhittime"));
1439   ifdelete(ArmHit);
1440   ArmHit = static_cast<TH2 *>(bbc_tdc_armhittime->Clone());
1441 
1442   TH1 *bbc_zvertex = cl->getHisto("BBCMON_0", "bbc_zvertex");
1443   ifdelete(Zvtx);
1444   Zvtx = static_cast<TH1 *>(bbc_zvertex->Clone());
1445 
1446   TH1 *bbc_zvertex_alltrigger = cl->getHisto("BBCMON_0", "bbc_zvertex_alltrigger");
1447   ifdelete(Zvtx_alltrigger);
1448   Zvtx_alltrigger = static_cast<TH1 *>(bbc_zvertex_alltrigger->Clone());
1449 
1450   TH1 *bbc_zvertex_ns = cl->getHisto("BBCMON_0", "bbc_zvertex_ns");
1451   ifdelete(Zvtx_ns);
1452   Zvtx_ns = static_cast<TH1 *>(bbc_zvertex_ns->Clone());
1453   Zvtx_ns->Rebin(2);
1454 
1455   TH1 *bbc_zvertex_10 = cl->getHisto("BBCMON_0", "bbc_zvertex_10");
1456   ifdelete(Zvtx_10);
1457   Zvtx_10 = static_cast<TH1 *>(bbc_zvertex_10->Clone());
1458 
1459   TH1 *bbc_zvertex_30 = cl->getHisto("BBCMON_0", "bbc_zvertex_30");
1460   ifdelete(Zvtx_30);
1461   Zvtx_30 = static_cast<TH1 *>(bbc_zvertex_30->Clone());
1462 
1463   TH1 *bbc_zvertex_60 = cl->getHisto("BBCMON_0", "bbc_zvertex_60");
1464   ifdelete(Zvtx_60);
1465   Zvtx_60 = static_cast<TH1 *>(bbc_zvertex_60->Clone());
1466 
1467   TH1 *bbc_zvertex_ns_chk = cl->getHisto("BBCMON_0", "bbc_zvertex_ns_chk");
1468   ifdelete(Zvtx_ns_chk);
1469   Zvtx_ns_chk = static_cast<TH1 *>(bbc_zvertex_ns_chk->Clone());
1470 
1471   TH1 *bbc_zvertex_10_chk = cl->getHisto("BBCMON_0", "bbc_zvertex_10_chk");
1472   ifdelete(Zvtx_10_chk);
1473   Zvtx_10_chk = static_cast<TH1 *>(bbc_zvertex_10_chk->Clone());
1474 
1475   TH1 *bbc_zvertex_30_chk = cl->getHisto("BBCMON_0", "bbc_zvertex_30_chk");
1476   ifdelete(Zvtx_30_chk);
1477   Zvtx_30_chk = static_cast<TH1 *>(bbc_zvertex_30_chk->Clone());
1478 
1479   TH1 *bbc_zvertex_60_chk = cl->getHisto("BBCMON_0", "bbc_zvertex_60_chk");
1480   ifdelete(Zvtx_60_chk);
1481   Zvtx_60_chk = static_cast<TH1 *>(bbc_zvertex_60_chk->Clone());
1482 
1483   TH1 *bbc_zvertex_zdcns = cl->getHisto("BBCMON_0", "bbc_zvertex_zdcns");
1484   ifdelete(Zvtx_zdcns);
1485   Zvtx_zdcns = static_cast<TH1 *>(bbc_zvertex_zdcns->Clone());
1486 
1487   TH1 *bbc_zvertex_emcal = cl->getHisto("BBCMON_0", "bbc_zvertex_emcal");
1488   ifdelete(Zvtx_emcal);
1489   Zvtx_emcal = static_cast<TH1 *>(bbc_zvertex_emcal->Clone());
1490 
1491   TH1 *bbc_zvertex_hcal = cl->getHisto("BBCMON_0", "bbc_zvertex_hcal");
1492   ifdelete(Zvtx_hcal);
1493   Zvtx_hcal = static_cast<TH1 *>(bbc_zvertex_hcal->Clone());
1494 
1495   TH1 *bbc_zvertex_emcalmbd = cl->getHisto("BBCMON_0", "bbc_zvertex_emcalmbd");
1496   ifdelete(Zvtx_emcalmbd);
1497   Zvtx_emcalmbd = static_cast<TH1 *>(bbc_zvertex_emcalmbd->Clone());
1498 
1499   TH1 *bbc_zvertex_hcalmbd = cl->getHisto("BBCMON_0", "bbc_zvertex_hcalmbd");
1500   ifdelete(Zvtx_hcalmbd);
1501   Zvtx_hcalmbd = static_cast<TH1 *>(bbc_zvertex_hcalmbd->Clone());
1502 
1503   TH2 *bbc_tzero_zvtx = static_cast<TH2 *>(cl->getHisto("BBCMON_0", "bbc_tzero_zvtx"));
1504   ifdelete(TzeroZvtx);
1505   TzeroZvtx = static_cast<TH2 *>(bbc_tzero_zvtx->Clone());
1506 
1507   TH1 *bbc_avr_hittime = cl->getHisto("BBCMON_0", "bbc_avr_hittime");
1508   ifdelete(AvrHitTime);
1509   AvrHitTime = static_cast<TH1 *>(bbc_avr_hittime->Clone());
1510 
1511   TH1 *bbc_north_hittime = cl->getHisto("BBCMON_0", "bbc_north_hittime");
1512   ifdelete(NorthHitTime);
1513   NorthHitTime = static_cast<TH1 *>(bbc_north_hittime->Clone());
1514 
1515   TH1 *bbc_south_hittime = cl->getHisto("BBCMON_0", "bbc_south_hittime");
1516   ifdelete(SouthHitTime);
1517   SouthHitTime = static_cast<TH1 *>(bbc_south_hittime->Clone());
1518 
1519   TH1 *bbc_south_chargesum = cl->getHisto("BBCMON_0", "bbc_south_chargesum");
1520   ifdelete(SouthChargeSum);
1521   SouthChargeSum = static_cast<TH1 *>(bbc_south_chargesum->Clone());
1522 
1523   TH1 *bbc_north_chargesum = cl->getHisto("BBCMON_0", "bbc_north_chargesum");
1524   ifdelete(NorthChargeSum);
1525   NorthChargeSum = static_cast<TH1 *>(bbc_north_chargesum->Clone());
1526 
1527   TH1 *bbc_prescale_hist = cl->getHisto("BBCMON_0", "bbc_prescale_hist");
1528   ifdelete(Prescale_hist);
1529   Prescale_hist = static_cast<TH1 *>(bbc_prescale_hist->Clone());
1530 
1531   TH1 *bbc_runvtx = cl->getHisto("BBCMON_0", "bbc_runvtx");
1532   ifdelete(RunVtx);
1533   RunVtx = static_cast<TH1 *>(bbc_runvtx->Clone());
1534 
1535   TH1 *bbc_runvtxerr = cl->getHisto("BBCMON_0", "bbc_runvtxerr");
1536   ifdelete(RunVtxErr);
1537   RunVtxErr = static_cast<TH1 *>(bbc_runvtxerr->Clone());
1538 
1539   TH1 *bbc_runvtxtime = cl->getHisto("BBCMON_0", "bbc_runvtxtime");
1540   ifdelete(RunVtxTime);
1541   RunVtxTime = static_cast<TH1 *>(bbc_runvtxtime->Clone());
1542 
1543   TH2 *bbc_time_wave = static_cast<TH2 *>(cl->getHisto("BBCMON_0", "bbc_time_wave"));
1544   ifdelete(TimeWave);
1545   TimeWave = static_cast<TH2 *>(bbc_time_wave->Clone());
1546 
1547   TH2 *bbc_charge_wave = static_cast<TH2 *>(cl->getHisto("BBCMON_0", "bbc_charge_wave"));
1548   ifdelete(ChargeWave);
1549   ChargeWave = static_cast<TH2 *>(bbc_charge_wave->Clone());
1550 
1551   TH2 *bbc_south_hitmap = static_cast<TH2 *>(cl->getHisto("BBCMON_0", "bbc_south_hitmap"));
1552   ifdelete(SouthHitMap);
1553   SouthHitMap = static_cast<TH2 *>(bbc_south_hitmap->Clone());
1554 
1555   TH2 *bbc_north_hitmap = static_cast<TH2 *>(cl->getHisto("BBCMON_0", "bbc_north_hitmap"));
1556   ifdelete(NorthHitMap);
1557   NorthHitMap = static_cast<TH2 *>(bbc_north_hitmap->Clone());
1558 
1559 
1560   TH1 *bbc_zvertex_auto[TriggerEnum::NUM_MBD_TRIGGERS] = {nullptr};
1561   for (int i = 0; i < static_cast<int>(TriggerEnum::NUM_MBD_TRIGGERS); i++)
1562   {
1563     // std::string name = Form("bbc_zvertex_autoupdate_%i", i);
1564     bbc_zvertex_auto[i] = static_cast<TH1 *>(cl->getHisto("BBCMON_0", Form("bbc_zvertex_autoupdate_%i", i)));
1565     ifdelete(ZvrtxAuto[i]);
1566     ZvrtxAuto[i] = static_cast<TH1F *>(bbc_zvertex_auto[i]->Clone());
1567   }
1568   PRINT_DEBUG("Start Creating graphs");
1569 
1570   // Create HitTime projection ------------------------------------------
1571 
1572   for (int side = 0; side < nSIDE; side++)
1573   {
1574     ifdelete(HitTime[side]);
1575 
1576     name << "FitHitTime" << BbcMonDefs::SIDE_Str[side];
1577     if ( bbc_tdc!=nullptr )
1578     {
1579       HitTime[side] = bbc_tdc->ProjectionY(name.str().c_str(), side * 64, side * 64 + 63);
1580       name.str("");
1581     }
1582 
1583     name << BbcMonDefs::SIDE_Str[side] << " MBD TDC Distribution";
1584     // name << BbcMonDefs::SIDE_Str[side] << " MBD TDC" << tdc << " Distribution(Trigger:BBLL1)" ; // Run14 AuAu 15GeV 2014.02.23
1585     HitTime[side]->SetTitle(name.str().c_str());
1586     ifnew(TF1(name.str().c_str(), "gaus"), FitHitTime[side]);
1587     name.str("");
1588     FitHitTime[side]->SetLineWidth(1);  // 0.05 was used fro run3
1589     FitHitTime[side]->SetLineColor(4);
1590   }
1591 
1592   // Create ZVertex Fit
1593 
1594   ifnew(TF1("FitZvtx", "gaus"), FitZvtx);
1595   ifnew(TF1("FitAvrHitTime", "gaus"), FitAvrHitTime);
1596   ifnew(TF1("FitNorthHitTime", "gaus"), FitNorthHitTime);
1597   ifnew(TF1("FitSouthHitTime", "gaus"), FitSouthHitTime);
1598   FitZvtx->SetLineWidth(3);
1599   FitZvtx->SetLineColor(1);
1600 
1601   // ------------------------------------------------------------------------------
1602   // making nHit TGraph
1603 
1604   double pmt[nPMT_1SIDE_BBC] = {0.};
1605   double zero[nPMT_1SIDE_BBC] = {0.};
1606   double nhitPmt[nTRIGGER][nSIDE][nPMT_1SIDE_BBC];
1607   double nhit_total = bbc_nevent_counter->GetBinContent(2);
1608   double nhit[nTRIGGER];
1609   nhit[0] = bbc_nevent_counter->GetBinContent(2);
1610   nhit[1] = bbc_nevent_counter->GetBinContent(3);
1611 
1612   for (int i = 0; i < nPMT_1SIDE_BBC; i++)
1613   {
1614     pmt[i] = i + 1;
1615     // zero[i] = 0;
1616   }
1617 
1618   PRINT_DEBUG("Creating nHit Graph");
1619 
1620   for (int side = 0; side < nSIDE; side++)
1621   {
1622     for (int trig = 0; trig < nTRIGGER; trig++)
1623     {
1624       for (int i = 0; i < nPMT_1SIDE_BBC; i++)
1625       {
1626         if (nhit[trig] != 0)
1627         {
1628           // RUN12: to ignore laser rate for ch8, fiber is broken.
1629           if (side == 0 && trig == 1 && i == 7)
1630           {
1631             nhitPmt[trig][side][i] = 999;
1632           }
1633           else
1634           {
1635             // nhitPmt[trig][side][i] = bbc_nhit[trig]->GetBinContent(i + side * nPMT_1SIDE_BBC + 1) / nhit[trig];
1636             nhitPmt[trig][side][i] = 999;
1637           }
1638         }
1639         else
1640         {
1641           nhitPmt[trig][side][i] = 0;
1642         }
1643       }
1644       ifnew(TGraph(nPMT_1SIDE_BBC, pmt, nhitPmt[trig][side]), nHit[trig][side]);
1645       // nHit[trig][side]->GetXaxis()->SetTitleSize(  0.05);
1646       // nHit[trig][side]->GetYaxis()->SetTitleSize(  0.05);
1647       // nHit[trig][side]->GetXaxis()->SetTitleOffset(0.70);
1648       // nHit[trig][side]->GetYaxis()->SetTitleOffset(1.75);
1649     }
1650   }
1651   PRINT_DEBUG("Creating OverFlow Grapth");
1652 
1653   // Create TDC Overflow Graph
1654 
1655   double tdcOverMean[nSIDE][nPMT_1SIDE_BBC];
1656   double tdcOverErrY[nSIDE][nPMT_1SIDE_BBC];
1657   for (int iside = 0; iside < nSIDE; iside++)
1658   {
1659     for (int i = 0; i < nPMT_1SIDE_BBC; i++)
1660     {
1661       tdcOverMean[iside][i] = 0.0;
1662       tdcOverErrY[iside][i] = 0.0;
1663     }
1664   }
1665 
1666   for (int side = 0; side < nSIDE; side++)
1667   {
1668     for (int i = 0; i < nPMT_1SIDE_BBC; i++)
1669     {
1670       /*
1671       tdcOverMean[0][side][i] = bbc_tdc_overflow_each[0][i + side * nPMT_1SIDE_BBC]->GetMean() /
1672         bbccalib->getOverflow0()->getCalibPar(i)->getDeviation();
1673       tdcOverErrY[0][side][i] = bbc_tdc_overflow_each[0][i + side * nPMT_1SIDE_BBC]->GetRMS() /
1674         bbccalib->getOverflow0()->getCalibPar(i)->getDeviation();
1675 
1676       tdcOverMean[1][side][i] = bbc_tdc_overflow_each[1][i + side * nPMT_1SIDE_BBC]->GetMean() /
1677         bbccalib->getOverflow1()->getCalibPar(i)->getDeviation();
1678       tdcOverErrY[1][side][i] = bbc_tdc_overflow_each[1][i + side * nPMT_1SIDE_BBC]->GetRMS() /
1679         bbccalib->getOverflow1()->getCalibPar(i)->getDeviation();
1680         */
1681 
1682       ifnew(TGraphErrors(nPMT_1SIDE_BBC, pmt, tdcOverMean[side], zero,
1683                          tdcOverErrY[side]),
1684             TdcOver[side]);
1685     }
1686   }
1687 
1688   // Redraw each Pad
1689 
1690   // ------------------------------------------------------------------------
1691   // Draw 1st Page
1692   // ------------------------------------------------------------------------
1693   std::ostringstream msg;
1694   PRINT_DEBUG("Drawing Graphs on Canvas");
1695 
1696   // Make TopPave
1697   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1698 
1699   otext.str("");
1700   otext << "Run #" << cl->RunNumber();
1701   otext << " Events: " << nhit_total;
1702   otext << " Date:" << ctime(&evttime.first);
1703   text = otext.str();
1704   //ifnew(TText, TextTop);
1705   TextTop->SetTextColor(evttime.second);
1706   TextTop->SetText(0.01, 0.25, text.c_str());
1707 
1708   if (TC[0])
1709   {
1710     TC[0]->cd();
1711 
1712     PadTop[0]->cd();
1713     PaveTop->Draw();
1714     TextTop->Draw();
1715 
1716     PadZVertexSummary->cd();
1717 
1718     Zvtx->SetLineColor(4);
1719     Zvtx->SetFillColor(7);
1720 
1721     Zvtx_ns->SetTitle("MBD Wide Zvertex");
1722     Zvtx_ns->SetLineColor(4);
1723     Zvtx_ns->SetFillColor(7);
1724     Zvtx_ns->SetMinimum(0); // start plots at zero
1725 
1726     double nevt = Trigs->GetBinContent(11); // trig 10 is MBDNS>=1, +1 for bin
1727     double prescale = Prescale_hist->GetBinContent(11);
1728     std::cout << "TRIG 10 " << nevt << "\t" << prescale << std::endl;
1729     /*
1730     if ( prescale!= -1.0 )
1731     {
1732       Zvtx_ns->Scale( prescale+1 );
1733     }
1734     */
1735 
1736     Zvtx_10->SetLineColor(2);
1737     Zvtx_10->SetFillColor(2);
1738     nevt = Trigs->GetBinContent(13); // trig 10 is MBDNS, |vtx|<10
1739     prescale = Prescale_hist->GetBinContent(13);
1740     std::cout << "TRIG 12 " << nevt << "\t" << prescale << std::endl;
1741     if ( prescale!= -1.0 )
1742     {
1743       Zvtx_10->Scale( prescale+1 );
1744     }
1745 
1746     // Get Maximum at the inside of BBC which is 130cm from center;
1747     float maxEntries = 10;
1748 
1749     for (int i = 0; i < Zvtx->GetNbinsX(); i++)
1750     {
1751       if (fabs(Zvtx->GetBinCenter(i)) < 130)
1752       {
1753         if (maxEntries < Zvtx->GetBinContent(i + 1))
1754         {
1755           maxEntries = Zvtx->GetBinContent(i + 1);
1756         }
1757       }
1758     }
1759 
1760     // Fit No-Vertex Distribution
1761     FitZvtx->SetRange(-75, 75);
1762     FitZvtx->SetLineColor(1);
1763 
1764     // Zvtx->Fit("FitZvtx", "LRQ");
1765     Zvtx_ns->Fit("FitZvtx", "LRNQ");
1766 
1767     // here we get the relative scaling right to put all on the same plot
1768     // the binning might be different, so we first find the bins corresponding to
1769     // +- 20cm and then get the Integral corrected for the binwidth
1770     // this is then used to get the histograms on the same scale
1771     /*
1772        int lowbin = Zvtx_zdc->GetXaxis()->FindBin(-20.);
1773        int hibin = Zvtx_zdc->GetXaxis()->FindBin(20.);
1774        double zdc_count = Zvtx_zdc->Integral(lowbin, hibin, "width");
1775        */
1776 
1777     /*
1778        int lowbin = Zvtx->GetXaxis()->FindBin(-20.);
1779        int hibin = Zvtx->GetXaxis()->FindBin(20.);
1780        double bbc_count = Zvtx->Integral(lowbin, hibin, "width");
1781        */
1782 
1783     // std::cout << "the ratio of integral (-30cm < ZVertex < 30cm) between BBLL1 without vtx cut and ZDC : " << bbc_count_novtx / zdc_count << std::endl ;
1784     // std::cout << "the ratio of integral (-30cm < ZVertex < 30cm) between BBLL1 without vtx cut  and BBLL1 with BBCZ < |30cm|  : " << bbc_count_novtx/bbc_count << std::endl ;
1785 
1786     // Get the Trigger Name that is used
1787     GetMinBiasTrigName();
1788 
1789     // Draw ZVertex triggerd variable trigger
1790     Zvtx->SetMaximum(maxEntries * 1.05);
1791     TString title = "MBD ZVertex (TRIG = "; title += TrigName; title += ")";
1792     Zvtx->SetTitle( title );
1793     // PadZVertex->DrawFrame(-160,0,160,maxEntries*1.05,"Bbc ZVertex (south<-->north)");
1794     // std::cout << "maxEntries " << maxEntries << std::endl;
1795     // Zvtx->Draw("hist");
1796     // Zvtx->Scale(bbc_count_novtx/bbc_count);
1797 
1798     // just in case the bbcll1 with vtx cut histo is empty
1799     // draw the novertex cut (happens during setup)
1800     if (Zvtx_ns->GetEntries() > 0)
1801     {
1802       Zvtx_ns->Draw("hist");
1803       //Zvtx->Draw("histsame");
1804       FitZvtx->Draw("same");
1805     }
1806 
1807     // trigger rate between BBCLL1 and Zvertex within +- BBC_ZVERTEX_CUT_FOR_TRIG_RATE
1808     // bbll1, zdc, bbll1_novtx
1809 
1810     float trig_rate[3], trig_rate_err[3];
1811     double nevent[3];
1812     memset(trig_rate, 0, sizeof(trig_rate));
1813     memset(trig_rate_err, 0, sizeof(trig_rate_err));
1814     memset(nevent, 0, sizeof(nevent));
1815 
1816     /*
1817        CalculateTriggerRates(trig_rate[0], trig_rate_err[0], nevent[0],
1818        trig_rate[1], trig_rate_err[1], nevent[1],
1819        trig_rate[2], trig_rate_err[2], nevent[2]);
1820        */
1821 
1822     /* chiu
1823         float sigma_zdc = 0.0;
1824         // float sigma_zdc_err = 0.0;
1825         float effic_bbc = 0.0;
1826         // float effic_bbc_err = 0.0;
1827         float beamInZdc = 0.0;
1828         // float beamInZdc_err = 0.0;
1829         float beamInBbc = 0.0;
1830         // float beamInBbc_err = 0.0;
1831     */
1832 
1833     /*
1834        BeamMonitoring( sigma_zdc, sigma_zdc_err, effic_bbc, effic_bbc_err,
1835        beamInZdc, beamInZdc_err, beamInBbc, beamInBbc_err);
1836        */
1837 
1838     /*chiu
1839     std::ostringstream trig_rate_text;
1840     trig_rate_text << " #sigma_{ZDC} = " << std::fixed << std::setprecision(3) << sigma_zdc
1841                    << " #epsilon_{BBC} = " << effic_bbc
1842                    << " {}^{beam in acceptance}_{       ZDC      } = " << beamInZdc
1843                    << " {}^{beam in acceptance}_{       BBC      } = " << beamInBbc;
1844     TextBbcSummaryTrigRate->SetText(0.02, 0.05, trig_rate_text.str().c_str());
1845     trig_rate_text.str("");
1846     */
1847 
1848     // float xpos[3] = {0.1, 0.34, 0.58};
1849     //     float xpos[3] = {0.30, 0.50, 0.75};
1850     // TextZVertexNotice->Draw();
1851 
1852     TH1 *Zvtx_array[4];  // with narrow
1853     // TH1 *Zvtx_array[3];
1854     Zvtx_array[0] = Zvtx;
1855     // Zvtx_array[1] = Zvtx;
1856     // Zvtx_array[2] = Zvtx;
1857     //  Zvtx_array[1] = Zvtx_zdc;
1858 
1859     // Show status of ZVertex
1860     int i = 0;
1861 
1862     // TextZVertex[i]->Draw();
1863 
1864     // scale factor ---------------------------------------------------------------------
1865     //  std::cout << "  " << i << " " << Prescale_hist->GetBinContent(i + 1) << std::endl;
1866     otext.str("");
1867     // otext << "( "<< Prescale_hist->GetBinContent(i+1)<<" )";
1868     // otext << "( "<< Prescale_hist->GetBinContent(i+1)<<" )"<<" ";
1869     // otext << nevent[i] ;
1870     // otext.precision(8);
1871     otext << " ( " << Prescale_hist->GetBinContent(i + 1) << " ) "
1872           << " ";
1873     // otext << nevent[i]/Prescale_hist->GetBinContent(i+1) ;
1874     otext << Zvtx_array[i]->GetEntries();
1875 
1876     text = otext.str();
1877     TextZVertex_scale[i]->SetText(xpos[i], 0.50, text.c_str());
1878     // TextZVertex_scale[i]->Draw();
1879 
1880     // mean and RMS ---------------------------------------------------------------------
1881     otext.str("");
1882     otext << ((float) int(Zvtx_array[i]->GetMean() * 10)) / 10.0 << "cm ( "
1883           << ((float) int(Zvtx_array[i]->GetRMS() * 10)) / 10.0 << " cm) ";
1884     text = otext.str();
1885 
1886     TextZVertex_mean[i]->SetText(xpos[i], 0.25, text.c_str());
1887     // TextZVertex_mean[i]->Draw();
1888     //  otext.precision(6);
1889 
1890     // TextZVertex[i]->Draw();
1891 
1892     /*
1893     TextZVertex_scale[i]->SetText(0.00, 0.50, "(Scale Fac.) #Evt.");
1894     TextZVertex_scale[i]->Draw();
1895     // TextZVertex_mean[i]->SetText(0.05, 0.25, "Vertex Mean (RMS)");
1896     TextZVertex_mean[i]->SetText(0.00, 0.25, "Vertex Mean (RMS)");
1897     TextZVertex_mean[i]->Draw();
1898     */
1899 
1900     // Draw Status
1901     otext.str("");
1902     otext << "Z_{MBDNS}^{Fit}= " << ((float) int(FitZvtx->GetParameter(1) * 10)) / 10.0 
1903           << " #pm " << ((float)int(FitZvtx->GetParError(1)*10))/10.0
1904           << " cm";
1905 
1906     text = otext.str();
1907     // TextZvtxStatus[0]->SetText(0.0, 0.85, text.c_str());
1908     Double_t ymax = Zvtx_ns->GetMaximum();
1909     TextZvtxStatus[0]->SetText(-230., ymax * 0.8, text.c_str());
1910     TextZvtxStatus[0]->SetTextSize(0.10);
1911     TextZvtxStatus[0]->Draw();
1912 
1913     otext.str("");
1914     otext << "#sigma = " << int(FitZvtx->GetParameter(2))
1915           << " #pm " << ((float)int(FitZvtx->GetParError(2)*10))/10.0
1916           << " cm";
1917     text = otext.str();
1918     TextZvtxStatus[1]->SetText(100., ymax * 0.8, text.c_str());
1919     TextZvtxStatus[1]->SetTextSize(0.10);
1920     TextZvtxStatus[1]->Draw();
1921 
1922     // chiu TextBbcSummaryTrigRate->Draw();
1923 
1924     PadZVertex->cd();
1925 
1926     if (Zvtx->GetEntries() > 0)
1927     {
1928       Zvtx->SetLineColor(2);
1929       Zvtx->SetFillColor(2);
1930       Zvtx->Draw("hist");
1931       Zvtx->GetXaxis()->SetRangeUser(-60, 60);
1932       Zvtx->Draw("hist");
1933       //Zvtx_10->Draw("histsame");
1934     }
1935 
1936     // Status of sending vertex
1937     GetSendFlag();
1938     if ( sendflag==1 )
1939     {
1940       text = "Sending Vertex to MCR";
1941     }
1942     else
1943     {
1944       text = "NOT Sending Vertex to MCR";
1945     }
1946 
1947     //TextZvtxStatus[2]->SetText(-55., Zvtx_ns->GetMaximum()*0.95, text.c_str());
1948     TextZvtxStatus[2]->SetTextSize(0.05);
1949     TextZvtxStatus[2]->DrawLatexNDC(0.15,0.8,text.c_str());
1950 
1951     /*
1952     // replaced with hitmap
1953     PadTzeroZVertex->cd();
1954     TzeroZvtx->Draw("colz");
1955 
1956     // insert line
1957     LineTzeroZvtx[0]->Draw();
1958     LineTzeroZvtx[1]->Draw();
1959     LineTzeroZvtx[2]->Draw();
1960     LineTzeroZvtx[3]->Draw();
1961 
1962     // insert text
1963     TextTzeroZvtx->SetText(10, 4, "Good region");
1964     TextTzeroZvtx->Draw();
1965     */
1966 
1967     PadRunZVertex->cd();
1968 
1969     TLine aline;
1970     gRunVtx->Set(0);
1971     gRunAvgVtx->Set(0);
1972 
1973     int n = RunVtx->GetEntries();
1974     //std::cout << "XXXX " << n << std::endl;
1975     if ( n>0 )
1976     {
1977         for (int ibin=1; ibin<=n; ibin++)
1978         {
1979             Double_t zvtxmean = RunVtx->GetBinContent(ibin);
1980             Double_t zvtxmeanerr = RunVtxErr->GetBinContent(ibin);
1981             Double_t zvtxtime = RunVtxTime->GetBinContent(ibin);
1982             // drop outliers
1983             if ( zvtxmeanerr>5 || zvtxmeanerr<1e-2 )
1984             {
1985                 continue;
1986             }
1987             int npts = gRunVtx->GetN();
1988             gRunVtx->SetPoint(npts,zvtxtime,zvtxmean);
1989             gRunVtx->SetPointError(npts,0,zvtxmeanerr);
1990         }
1991 
1992         int nvtx = gRunVtx->GetN();
1993         Double_t *xtime = gRunVtx->GetX();
1994         Double_t *yzvtx = gRunVtx->GetY();
1995 
1996         // calculate moving average (navg data points)
1997         for (int ix=0; ix<nvtx; ix++)
1998         {
1999             int imin = ix-4;
2000             if (imin<0)
2001             {
2002                 imin=0;
2003             }
2004             int imax = ix+4;
2005             if (imax>nvtx-1)
2006             {
2007                 imax=nvtx-1;
2008             }
2009             double nsum = 0.;
2010             double sum = 0.;
2011             for (int isum=imin; isum<=imax; isum++)
2012             {
2013                 sum += yzvtx[isum];
2014                 nsum += 1.0;
2015             }
2016 
2017             double runavg = sum/nsum;
2018 
2019             gRunAvgVtx->SetPoint(ix,xtime[ix],runavg);
2020         }
2021 
2022         gRunVtx->SetMarkerStyle(20);
2023         gRunVtx->SetMarkerColor(4);
2024         gRunVtx->SetLineColor(4);
2025 
2026         //std::cout << "DRAWING GRUNVTX" << std::endl;
2027         if ( nvtx>0 )
2028         {
2029             gRunVtx->Draw("ap");
2030             gRunAvgVtx->Draw("c");
2031 
2032             PadRunZVertex->Update();
2033             aline.SetLineStyle(7);
2034             aline.SetLineColor(kRed);
2035             aline.SetLineWidth(2);
2036             aline.DrawLine(gPad->GetFrame()->GetX1(),0,gPad->GetFrame()->GetX2(),0);
2037         }
2038         else
2039         {
2040             // Draw an empty histogram
2041             EmptyHist->Draw();
2042         }
2043     }
2044     else
2045     {
2046         // Draw an empty histogram
2047         EmptyHist->Draw();
2048     }
2049 
2050     //NorthHitMap->Draw("colz");
2051 
2052     double nevents = bbc_nevent_counter->GetBinContent(2);
2053     PadSouthHitMap->cd();
2054     SouthHitMap->Scale(1.0 / nevents);
2055     SouthHitMap->Draw("colz");
2056 
2057     PadNorthHitMap->cd();
2058     NorthHitMap->Scale(1.0 / nevents);
2059     NorthHitMap->Draw("colz");
2060   }
2061   //copy for all triggers plot
2062   if (TC[6])
2063   {
2064     TC[6]->cd();
2065 
2066     PadTop[4]->cd();
2067     PaveTop->Draw();
2068     TextTop->Draw();
2069 
2070     PadZVertexSummary->cd();
2071 
2072     Zvtx_alltrigger->SetLineColor(4);
2073     Zvtx_alltrigger->SetFillColor(7);
2074 
2075     Zvtx_alltrigger->SetTitle("MBD zvertex");
2076     Zvtx_alltrigger->SetLineColor(4);
2077     Zvtx_alltrigger->SetFillColor(7);
2078     Zvtx_alltrigger->SetMinimum(0); // start plots at zero
2079 
2080 
2081     // Get Maximum at the inside of BBC which is 130cm from center;
2082     float maxEntries = 10;
2083 
2084     for (int i = 0; i < Zvtx_alltrigger->GetNbinsX(); i++)
2085     {
2086       if (fabs(Zvtx_alltrigger->GetBinCenter(i)) < 130)
2087       {
2088         if (maxEntries < Zvtx_alltrigger->GetBinContent(i + 1))
2089         {
2090           maxEntries = Zvtx_alltrigger->GetBinContent(i + 1);
2091         }
2092       }
2093     }
2094     
2095     // Fit No-Vertex Distribution
2096     FitZvtx->SetRange(-75, 75);
2097     FitZvtx->SetLineColor(1);
2098     // Zvtx->Fit("FitZvtx", "LRQ");
2099     Zvtx_alltrigger->Fit("FitZvtx", "LRQ");
2100 
2101     // here we get the relative scaling right to put all on the same plot
2102     // the binning might be different, so we first find the bins corresponding to
2103     // +- 20cm and then get the Integral corrected for the binwidth
2104     // this is then used to get the histograms on the same scale
2105 
2106     Zvtx_alltrigger->SetMaximum(maxEntries * 1.05);
2107     Zvtx_alltrigger->SetTitle("MBD ZVertex (south<-->north)");
2108 
2109     if (Zvtx_alltrigger->GetEntries() > 0)
2110     {
2111       Zvtx_alltrigger->Draw("hist");
2112       FitZvtx->Draw("same");
2113     }
2114     // trigger rate between BBCLL1 and Zvertex within +- BBC_ZVERTEX_CUT_FOR_TRIG_RATE
2115     // bbll1, zdc, bbll1_novtx
2116 
2117     float trig_rate[3], trig_rate_err[3];
2118     double nevent[3];
2119     memset(trig_rate, 0, sizeof(trig_rate));
2120     memset(trig_rate_err, 0, sizeof(trig_rate_err));
2121     memset(nevent, 0, sizeof(nevent));
2122 
2123     TH1 *Zvtx_array[4];  // with narrow
2124     // TH1 *Zvtx_array[3];
2125     Zvtx_array[0] = Zvtx_alltrigger;
2126 
2127     int i = 0;
2128 
2129   
2130     otext.str("");
2131    
2132     otext << " ( " << Prescale_hist->GetBinContent(i + 1) << " ) "
2133           << " ";
2134     // otext << nevent[i]/Prescale_hist->GetBinContent(i+1) ;
2135     otext << Zvtx_array[i]->GetEntries();
2136 
2137     text = otext.str();
2138     TextZVertex_scale[i]->SetText(xpos[i], 0.50, text.c_str());
2139     // TextZVertex_scale[i]->Draw();
2140 
2141     // mean and RMS ---------------------------------------------------------------------
2142     otext.str("");
2143     otext << ((float) int(Zvtx_array[i]->GetMean() * 10)) / 10.0 << "cm ( "
2144           << ((float) int(Zvtx_array[i]->GetRMS() * 10)) / 10.0 << " cm) ";
2145     text = otext.str();
2146 
2147     TextZVertex_mean[i]->SetText(xpos[i], 0.25, text.c_str());
2148    
2149     // Draw Status
2150     otext.str("");
2151     otext << "Z_{MBDNS}^{Fit}= " << ((float) int(FitZvtx->GetParameter(1) * 10)) / 10.0 
2152           << " #pm " << ((float)int(FitZvtx->GetParError(1)*10))/10.0
2153           << " cm";
2154 
2155     text = otext.str();
2156     // TextZvtxStatus[0]->SetText(0.0, 0.85, text.c_str());
2157     //TextZvtxStatus[0]->SetText(-230., maxEntries * 0.8, text.c_str());
2158     TextZvtxStatus[0]->SetTextSize(0.10);
2159     TextZvtxStatus[0]->DrawLatexNDC(0.3,0.75,text.c_str());
2160 
2161     otext.str("");
2162     otext << "#sigma = " << int(FitZvtx->GetParameter(2))
2163           << " #pm " << ((float)int(FitZvtx->GetParError(2)*10))/10.0
2164           << " cm";
2165     text = otext.str();
2166     //TextZvtxStatus[1]->SetText(100., maxEntries * 0.8, text.c_str());
2167     TextZvtxStatus[1]->SetTextSize(0.10);
2168     TextZvtxStatus[1]->DrawLatexNDC(0.7,0.75,text.c_str());
2169 
2170     // chiu TextBbcSummaryTrigRate->Draw();
2171 
2172     PadZVertex->cd();
2173 
2174     if (Zvtx_alltrigger->GetEntries() > 0)
2175     {
2176       Zvtx_alltrigger->GetXaxis()->SetRangeUser(-60, 60);
2177       Zvtx_alltrigger->Draw("hist");
2178       //      Zvtx_10->Draw("histsame");
2179     }
2180 
2181     // Status of sending vertex
2182     GetSendFlag();
2183     if ( sendflag==1 )
2184     {
2185       text = "Sending Vertex to MCR";
2186     }
2187     else
2188     {
2189       text = "NOT Sending Vertex to MCR";
2190     }
2191 
2192     //TextZvtxStatus[2]->SetText(-55., Zvtx_alltrigger->GetMaximum()*0.95, text.c_str());
2193     TextZvtxStatus[2]->SetTextSize(0.05);
2194     TextZvtxStatus[2]->DrawLatexNDC(0.15,0.8,text.c_str());
2195 
2196     // double nevents = bbc_nevent_counter->GetBinContent(2);
2197     // PadSouthHitMap->cd();
2198     // SouthHitMap->Scale(1.0 / nevents);
2199     // SouthHitMap->Draw("colz");
2200 
2201     // PadNorthHitMap->cd();
2202     // NorthHitMap->Scale(1.0 / nevents);
2203     // NorthHitMap->Draw("colz");
2204   }
2205 
2206   //  bbc_t0_pave->Draw("same");
2207 
2208   // ------------------------------------------------------------------------
2209   // Draw 2nd Page
2210   // ------------------------------------------------------------------------
2211   if (TC[1])
2212   {
2213     TC[1]->cd();
2214 
2215     PadTop[1]->cd();
2216     PaveTop->Draw();
2217     TextTop->Draw();
2218 
2219     if (PadAvrHitTime)
2220     {
2221       PadAvrHitTime->cd();
2222       AvrHitTime->Draw();
2223 
2224       float rangemin;
2225       float rangemax;
2226       int npeak = tspec->Search(AvrHitTime, 5, "goff",0.2);  // finds the highest peak, draws marker
2227       if (npeak < 3)                                     // no center peak
2228       {
2229         AvrHitTime->Fit("FitAvrHitTime", "QN0L");
2230         rangemin = FitAvrHitTime->GetParameter(1) - FitAvrHitTime->GetParameter(2);
2231         rangemax = FitAvrHitTime->GetParameter(1) + FitAvrHitTime->GetParameter(2);
2232       }
2233       else
2234       {
2235         double *peakpos = tspec->GetPositionX();
2236         float centerpeak = peakpos[0];
2237         float sidepeak[2];
2238         if (peakpos[2] > peakpos[1])
2239         {
2240           sidepeak[0] = peakpos[1];
2241           sidepeak[1] = peakpos[2];
2242         }
2243         else
2244         {
2245           sidepeak[1] = peakpos[1];
2246           sidepeak[0] = peakpos[2];
2247         }
2248         rangemin = centerpeak - (centerpeak - sidepeak[0]) / 2.;
2249         rangemax = centerpeak + (sidepeak[1] - centerpeak) / 2.;
2250       }
2251 
2252       FitAvrHitTime->SetRange(rangemin, rangemax);
2253       AvrHitTime->Fit("FitAvrHitTime", "QRL");
2254       FitAvrHitTime->Draw("same");
2255 
2256       float height = AvrHitTime->GetMaximum();
2257       FitAvrHitTime->Draw("same");
2258 
2259       LineAvrHitTime[1]->SetY2(height);
2260       LineAvrHitTime[0]->SetY2(height);
2261       ArrowAvrHitTime->SetY1(height * 0.90);
2262       ArrowAvrHitTime->SetY2(height * 0.90);
2263       TextAvrHitTime->SetY(height * 0.88);
2264       LineAvrHitTime[0]->Draw();
2265       LineAvrHitTime[1]->Draw();
2266       ArrowAvrHitTime->Draw();
2267       TextAvrHitTime->Draw();
2268     }
2269 
2270     if (PadTimeWave)
2271     {
2272       PadTimeWave->cd();
2273       TimeWave->GetXaxis()->SetRangeUser(-0.5,15.5);
2274       TimeWave->Draw("colz");
2275       PadTimeWave->Update();
2276       TLine aline;
2277       aline.SetLineColor(kRed);
2278       aline.SetLineWidth(4);
2279       aline.DrawLine( 6.5,gPad->GetFrame()->GetY1(), 6.5,gPad->GetFrame()->GetY2());
2280       aline.DrawLine(10.5,gPad->GetFrame()->GetY1(),10.5,gPad->GetFrame()->GetY2());
2281     }
2282 
2283     if (PadSouthHitTime)
2284     {
2285       PadSouthHitTime->cd();
2286       SouthHitTime->Draw();
2287       float rangemin;
2288       float rangemax;
2289       int npeak = tspec->Search(SouthHitTime, 5, "goff",0.2);  // finds the highest peak, draws marker
2290 
2291       //std::cout << "NPEAKS " << npeak << std::endl;
2292       if (npeak < 3)                                       
2293       {
2294         SouthHitTime->Fit("FitSouthHitTime", "QN0L");
2295         rangemin = FitSouthHitTime->GetParameter(1) - 1.0*FitSouthHitTime->GetParameter(2);
2296         rangemax = FitSouthHitTime->GetParameter(1) + 1.0*FitSouthHitTime->GetParameter(2);
2297       }
2298       else
2299       {
2300         double *peakpos = tspec->GetPositionX();
2301         float centerpeak = peakpos[0];
2302         float sidepeak[2];
2303         if (peakpos[2] > peakpos[1])
2304         {
2305           sidepeak[0] = peakpos[1];
2306           sidepeak[1] = peakpos[2];
2307         }
2308         else
2309         {
2310           sidepeak[1] = peakpos[1];
2311           sidepeak[0] = peakpos[2];
2312         }
2313         rangemin = centerpeak - (centerpeak - sidepeak[0]) / 2.;
2314         rangemax = centerpeak + (sidepeak[1] - centerpeak) / 2.;
2315       }
2316 
2317       rangemin = -3;
2318       rangemax = 3;
2319       FitSouthHitTime->SetRange(rangemin, rangemax);
2320       SouthHitTime->Fit("FitSouthHitTime", "QRL");
2321       FitSouthHitTime->Draw("same");
2322 
2323       PadSouthHitTime->Update();
2324       TLine aline;
2325       aline.SetLineStyle(7);
2326       aline.SetLineColor(kRed);
2327       aline.SetLineWidth(4);
2328       aline.DrawLine(-3.0, gPad->GetFrame()->GetY1(), -3.0, gPad->GetFrame()->GetY2());
2329       aline.DrawLine(+3.0, gPad->GetFrame()->GetY1(), +3.0, gPad->GetFrame()->GetY2());
2330 
2331       /*
2332       // Lines to indicate good mean
2333       float height = SouthHitTime->GetMaximum();
2334       LineSouthHitTime[1]->SetY2(height);
2335       LineSouthHitTime[0]->SetY2(height);
2336       ArrowSouthHitTime->SetY1(height * 0.90);
2337       ArrowSouthHitTime->SetY2(height * 0.90);
2338       TextSouthHitTime->SetY(height * 0.88);
2339       LineSouthHitTime[0]->Draw();
2340       LineSouthHitTime[1]->Draw();
2341       ArrowSouthHitTime->Draw();
2342       TextSouthHitTime->Draw();
2343       */
2344     }
2345 
2346     if (PadNorthHitTime)
2347     {
2348       PadNorthHitTime->cd();
2349       NorthHitTime->Draw();
2350 
2351       float rangemin;
2352       float rangemax;
2353       int npeak = tspec->Search(NorthHitTime, 5, "goff",0.2);  // finds the highest peak, draws marker
2354       if (npeak < 3)                                       // no center peak
2355       {
2356         NorthHitTime->Fit("FitNorthHitTime", "QN0L");
2357         rangemin = FitNorthHitTime->GetParameter(1) - 1.0*FitNorthHitTime->GetParameter(2);
2358         rangemax = FitNorthHitTime->GetParameter(1) + 1.0*FitNorthHitTime->GetParameter(2);
2359       }
2360       else
2361       {
2362         double *peakpos = tspec->GetPositionX();
2363         float centerpeak = peakpos[0];
2364         float sidepeak[2];
2365         if (peakpos[2] > peakpos[1])
2366         {
2367           sidepeak[0] = peakpos[1];
2368           sidepeak[1] = peakpos[2];
2369         }
2370         else
2371         {
2372           sidepeak[1] = peakpos[1];
2373           sidepeak[0] = peakpos[2];
2374         }
2375         rangemin = centerpeak - (centerpeak - sidepeak[0]) / 2.;
2376         rangemax = centerpeak + (sidepeak[1] - centerpeak) / 2.;
2377       }
2378 
2379       rangemin = -3;
2380       rangemax = 3;
2381       FitNorthHitTime->SetRange(rangemin, rangemax);
2382       NorthHitTime->Fit("FitNorthHitTime", "QRL");
2383       FitNorthHitTime->Draw("same");
2384 
2385       PadNorthHitTime->Update();
2386       TLine aline;
2387       aline.SetLineStyle(7);
2388       aline.SetLineColor(kRed);
2389       aline.SetLineWidth(4);
2390       aline.DrawLine(-3.0 ,gPad->GetFrame()->GetY1(),-3.0,gPad->GetFrame()->GetY2());
2391       aline.DrawLine(+3.0,gPad->GetFrame()->GetY1(),+3.0,gPad->GetFrame()->GetY2());
2392 
2393       /*
2394       // Lines to indicate good mean
2395       float height = NorthHitTime->GetMaximum();
2396       LineNorthHitTime[1]->SetY2(height);
2397       LineNorthHitTime[0]->SetY2(height);
2398       ArrowNorthHitTime->SetY1(height * 0.90);
2399       ArrowNorthHitTime->SetY2(height * 0.90);
2400       TextNorthHitTime->SetY(height * 0.88);
2401       LineNorthHitTime[0]->Draw();
2402       LineNorthHitTime[1]->Draw();
2403       ArrowNorthHitTime->Draw();
2404       TextNorthHitTime->Draw();
2405       */
2406     }
2407 
2408     /*
2409     PadArmHit->cd();
2410     if (ArmHit)
2411     {
2412       ArmHit->Draw("colz");
2413       ArcArmHit->Draw();
2414       TextArmHit->Draw();
2415     }
2416     */
2417 
2418     if (PadBbcSummary)
2419     {
2420       PadBbcSummary->cd();
2421       otext.str("");
2422       otext << "South:" << ((float) int(FitSouthHitTime->GetParameter(1) * 10)) / 10 << "[ns]  ";
2423       otext << "North:" << ((float) int(FitNorthHitTime->GetParameter(1) * 10)) / 10 << "[ns]  ";
2424       otext << "...  ";
2425       if (BbcMonDefs::BBC_MIN_REGULAR_TDC0_MEAN < FitNorthHitTime->GetParameter(1) &&
2426           BbcMonDefs::BBC_MAX_REGULAR_TDC0_MEAN > FitNorthHitTime->GetParameter(1) &&
2427           BbcMonDefs::BBC_MIN_REGULAR_TDC0_MEAN < FitSouthHitTime->GetParameter(1) &&
2428           BbcMonDefs::BBC_MAX_REGULAR_TDC0_MEAN > FitSouthHitTime->GetParameter(1))
2429       {
2430         // otext << "OK";
2431         textok = "                                                         OK";
2432       }
2433       else
2434       {
2435         textok = " ";
2436         if (BbcMonDefs::BBC_MIN_WORNING_STATISTICS_FOR_ZVERTEX_MEAN > Zvtx->GetEntries())
2437         {
2438           otext << "Too low statistics";
2439         }
2440         else
2441         {
2442           otext << "Change Global-Offset on V124";
2443         }
2444       }
2445       text = otext.str();
2446       TextBbcSummaryHitTime[0]->SetText(0.01, 0.75, text.c_str());
2447       TextBbcSummaryHitTime[0]->Draw();
2448       text = textok;
2449       // TextBbcSummaryHitTime[1]->SetText(0.65, 0.75, text.c_str() );
2450       TextBbcSummaryHitTime[1]->SetText(0.01, 0.75, text.c_str());
2451       TextBbcSummaryHitTime[1]->SetTextColor(3);
2452       TextBbcSummaryHitTime[1]->Draw();
2453     }
2454 
2455     // Global offset
2456     float delay = (BbcMonDefs::BBC_DEFAULT_OFFSET -
2457                    ((FitNorthHitTime->GetParameter(1) + FitSouthHitTime->GetParameter(1)) * 0.5));  //[ns]
2458     otext.str("");
2459     otext << "   Global offset : ";
2460     if (int(-2 * delay) == 0)
2461     {
2462       // otext << "need not to move ... OK";
2463       // otext << " ... OK";
2464       // textok = "                                    ... OK";
2465     }
2466     else
2467     {
2468       // textok = " ";
2469       if (!(BbcMonDefs::BBC_MIN_REGULAR_TDC0_MEAN < FitNorthHitTime->GetParameter(1) &&
2470             BbcMonDefs::BBC_MAX_REGULAR_TDC0_MEAN > FitNorthHitTime->GetParameter(1) &&
2471             BbcMonDefs::BBC_MIN_REGULAR_TDC0_MEAN < FitSouthHitTime->GetParameter(1) &&
2472             BbcMonDefs::BBC_MAX_REGULAR_TDC0_MEAN > FitSouthHitTime->GetParameter(1)))
2473       {
2474         // otext << "Need to move " << int( -2*delay) << "count";
2475         otext << "Need to call BBC expert: " << int(-2 * delay) << "count shifted";
2476       }
2477       else
2478       {
2479         // otext << " ... OK";
2480         // textok = "                            OK";
2481       }
2482     }
2483 
2484     /*chiu
2485         // otext << "...     )" ;
2486         text = otext.str();
2487         TextBbcSummaryGlobalOffset[0]->SetText(0.01, 0.50, text.c_str());
2488         TextBbcSummaryGlobalOffset[0]->Draw();
2489         text = textok;
2490         // TextBbcSummaryGlobalOffset[1]->SetText(0.35, 0.50, text.c_str() );
2491         TextBbcSummaryGlobalOffset[1]->SetText(0.01, 0.50, text.c_str());
2492         TextBbcSummaryGlobalOffset[1]->SetTextColor(3);
2493         TextBbcSummaryGlobalOffset[1]->Draw();
2494         // textok = " ";
2495     */
2496 
2497     // ZVertex
2498     /*
2499        otext.str("");
2500        otext << "Mean ZVertex:" << ((float)int(FitZvtx->GetParameter(1)*10)) / 10 << "[cm] ";
2501        if(Zvtx->GetEntries() > BbcMonDefs::BBC_MIN_WORNING_STATISTICS_FOR_ZVERTEX_MEAN ) {
2502        otext << "( sigma " << ((float)int(FitZvtx->GetParameter(2)*10)) / 10 << "cm)";
2503        }else{
2504     // otext << "( RMS " << ((float)int(Zvtx->GetRMS()*10)) / 10 << "cm)";
2505     }
2506     otext << " ... ";
2507     if ( BbcMonDefs::BBC_MIN_REGULAR_ZVERTEX_MEAN < FitZvtx->GetParameter(1) &&
2508     BbcMonDefs::BBC_MAX_REGULAR_ZVERTEX_MEAN > FitZvtx->GetParameter(1) )
2509     otext << "OK";
2510     else {
2511     if( BbcMonDefs::BBC_MIN_WORNING_STATISTICS_FOR_ZVERTEX_MEAN > Zvtx->GetEntries() )
2512     otext << "Too low statistics";
2513     else
2514     otext << "Ask SL to contact MCR";
2515     }
2516     text = otext.str();
2517     TextBbcSummaryZvertex->SetText(0.01, 0.25, text.c_str() );
2518     */
2519 
2520     /*chiu
2521         TextBbcSummaryZvertex->SetText(0.01, 0.25, "Shown data are triggered by BBLL1 |z|<130cm");
2522         TextBbcSummaryZvertex->Draw();
2523     */
2524   }
2525 
2526   // ------------------------------------------------------------------------
2527   // Draw 3rd Page
2528   // ------------------------------------------------------------------------
2529   bbcStyle->cd();
2530   if (TC[2])
2531   {
2532     PadTop[2]->cd();
2533     PaveTop->Draw();
2534     TextTop->Draw();
2535 
2536     /*
2537     for (int side = 0; side < nSIDE; side++)
2538     {
2539       PadHitTime[side]->cd();
2540 
2541       HitTime[side]->Draw();
2542       float rangemin;
2543       float rangemax;
2544       int npeak = tspec->Search(HitTime[side], 2, "goff");  // finds the highest peak, draws marker
2545       if (npeak < 3)                                        // no center peak
2546       {
2547         FitHitTime[side]->SetRange(BbcMonDefs::TDC_FIT_MIN, BbcMonDefs::TDC_FIT_MAX);
2548         HitTime[side]->Fit(FitHitTime[side]->GetName(), "QRNL");
2549         rangemax = std::min(BbcMonDefs::TDC_FIT_MAX,
2550                             FitHitTime[side]->GetParameter(1) + FitHitTime[side]->GetParameter(2));
2551         rangemin = std::max(BbcMonDefs::TDC_FIT_MIN,
2552                             FitHitTime[side]->GetParameter(1) - FitHitTime[side]->GetParameter(2));
2553       }
2554       else
2555       {
2556         double *peakpos = tspec->GetPositionX();
2557         float centerpeak = peakpos[0];
2558         float sidepeak[2];
2559         if (peakpos[2] > peakpos[1])
2560         {
2561           sidepeak[0] = peakpos[1];
2562           sidepeak[1] = peakpos[2];
2563         }
2564         else
2565         {
2566           sidepeak[1] = peakpos[1];
2567           sidepeak[0] = peakpos[2];
2568         }
2569         rangemin = centerpeak - (centerpeak - sidepeak[0]) / 2.;
2570         rangemax = centerpeak + (sidepeak[1] - centerpeak) / 2.;
2571       }
2572 
2573       FitHitTime[side]->SetRange(rangemin, rangemax);
2574 
2575       HitTime[side]->Fit(FitHitTime[side]->GetName(), "QRL");
2576       float height = HitTime[side]->GetMaximum();
2577       FitHitTime[side]->Draw("same");
2578 
2579       LineHitTime[side][1]->SetY2(height);
2580       LineHitTime[side][0]->SetY2(height);
2581       ArrowHitTime[side]->SetY1(height * 0.90);
2582       ArrowHitTime[side]->SetY2(height * 0.90);
2583       TextHitTime[side]->SetY(height * 0.88);
2584       LineHitTime[side][0]->Draw();
2585       LineHitTime[side][1]->Draw();
2586       ArrowHitTime[side]->Draw();
2587       TextHitTime[side]->Draw();
2588     }
2589     // PadWarnings->cd();
2590     // PaveWarnings->Draw();
2591     */
2592 
2593     if (PadZvtx)
2594     {
2595       PadZvtx->cd();
2596 
2597 
2598       if (Zvtx_ns_chk->GetEntries() > 0)
2599       {
2600         Zvtx_ns_chk->SetMinimum(0); // start plots at zero
2601 
2602         /*
2603         double prescale = Prescale_hist->GetBinContent(11);
2604         Zvtx_10_chk->Scale( prescale+1.0 );
2605         Zvtx_30_chk->Scale( prescale+1.0 );
2606         Zvtx_60_chk->Scale( prescale+1.0 );
2607         */
2608 
2609         std::vector<double> max;
2610         max.push_back( Zvtx_ns_chk->GetBinContent( Zvtx_ns_chk->GetMaximumBin() ) );
2611         max.push_back( Zvtx_60_chk->GetBinContent( Zvtx_60_chk->GetMaximumBin() ) );
2612         max.push_back( Zvtx_30_chk->GetBinContent( Zvtx_30_chk->GetMaximumBin() ) );
2613         max.push_back( Zvtx_10_chk->GetBinContent( Zvtx_10_chk->GetMaximumBin() ) );
2614         max.push_back( Zvtx_zdcns->GetBinContent( Zvtx_zdcns->GetMaximumBin() ) );
2615         double maximum = *std::max_element(max.begin(), max.end());
2616 
2617         //Zvtx_ns_chk->GetXaxis()->SetRangeUser(-60, 60);
2618         Zvtx_ns_chk->SetMaximum(maximum*1.1);
2619         Zvtx_ns_chk->Draw("hist");
2620 
2621         Zvtx_60_chk->SetLineColor(40);
2622         Zvtx_60_chk->SetFillColor(6);
2623 
2624         Zvtx_30_chk->SetLineColor(30);
2625         Zvtx_30_chk->SetFillColor(3);
2626 
2627         Zvtx_10_chk->SetLineColor(46);
2628         Zvtx_10_chk->SetFillColor(2);
2629 
2630         Zvtx_zdcns->Draw("histsame");
2631         Zvtx_60_chk->Draw("histsame");
2632         Zvtx_30_chk->Draw("histsame");
2633         Zvtx_10_chk->Draw("histsame");
2634         //std::cout << "aaa " << Zvtx_ns->GetEntries() << " " << Zvtx_10->GetEntries() << " " << Zvtx_30->GetEntries() << " " << Zvtx_60->GetEntries() << " " << Zvtx_zdcns->GetEntries() << " " << std::endl;
2635       }
2636 
2637       /*
2638       Zvtx->Draw();
2639       Zvtx->Fit("FitZvtx", "QN0L");
2640       FitZvtx->SetRange(FitZvtx->GetParameter(1) - FitZvtx->GetParameter(2) * 2,
2641                         FitZvtx->GetParameter(1) + FitZvtx->GetParameter(2) * 2);
2642       Zvtx->Fit("FitZvtx", "QRL");
2643       FitZvtx->Draw("same");
2644 
2645       float height = Zvtx->GetMaximum();
2646       FitZvtx->Draw("same");
2647 
2648       LineZvtx[1]->SetY2(height);
2649       LineZvtx[0]->SetY2(height);
2650       ArrowZvtx->SetY1(height * 0.90);
2651       ArrowZvtx->SetY2(height * 0.90);
2652       TextZvtx->SetY(height * 0.88);
2653       LineZvtx[0]->Draw();
2654       LineZvtx[1]->Draw();
2655       ArrowZvtx->Draw();
2656       TextZvtx->Draw();
2657       TextZvtxNorth->Draw();
2658       TextZvtxSouth->Draw();
2659       */
2660     }
2661 
2662     if (PadNhits)
2663     {
2664       PadNhits->cd();
2665 
2666       std::vector<double> max;
2667       max.push_back( South_Nhit->GetBinContent( South_Nhit->GetMaximumBin() ) );
2668       max.push_back( North_Nhit->GetBinContent( North_Nhit->GetMaximumBin() ) );
2669       double maximum = *std::max_element(max.begin(), max.end());
2670 
2671       South_Nhit->SetLineColor(2);
2672       North_Nhit->SetLineColor(4);
2673       South_Nhit->GetXaxis()->SetRangeUser(0,64);
2674       North_Nhit->GetXaxis()->SetRangeUser(0,64);
2675       South_Nhit->SetTitle("MBD Nhits, MBD trig");
2676       North_Nhit->SetTitle("MBD Nhits, MBD trig");
2677       South_Nhit->SetMaximum( maximum*1.1 );
2678       South_Nhit->Draw();
2679       North_Nhit->Draw("same");
2680     }
2681 
2682     if (PadZvtxEMCAL)
2683     {
2684       PadZvtxEMCAL->cd();
2685 
2686       Zvtx_emcal->GetXaxis()->SetRangeUser(-60, 60);
2687       Zvtx_emcalmbd->GetXaxis()->SetRangeUser(-60, 60);
2688       if ( Zvtx_emcal->GetEntries() > Zvtx_emcalmbd->GetEntries() )
2689       {
2690         Zvtx_emcal->Draw();
2691         Zvtx_emcalmbd->Draw("same");
2692       }
2693       else
2694       {
2695         Zvtx_emcalmbd->Draw();
2696         Zvtx_emcal->Draw("same");
2697       }
2698     }
2699     if (PadNhitsEMCAL)
2700     {
2701       PadNhitsEMCAL->cd();
2702 
2703       Nhit_emcal[0]->SetLineColor(2);
2704       Nhit_emcal[1]->SetLineColor(4);
2705       Nhit_emcalmbd[0]->SetLineColor(2);
2706       Nhit_emcalmbd[1]->SetLineColor(4);
2707       Nhit_emcalmbd[0]->SetLineStyle(7);
2708       Nhit_emcalmbd[1]->SetLineStyle(7);
2709       for (int iarm=0; iarm<2; iarm++)
2710       {
2711         Nhit_emcal[iarm]->GetXaxis()->SetRangeUser(0,64);
2712         Nhit_emcalmbd[iarm]->GetXaxis()->SetRangeUser(0,64);
2713 
2714         if ( iarm==0 ) Nhit_emcal[iarm]->Draw();
2715         else           Nhit_emcal[iarm]->Draw("same");
2716         Nhit_emcalmbd[iarm]->Draw("same");
2717       }
2718     }
2719 
2720     if (PadZvtxHCAL)
2721     {
2722       PadZvtxHCAL->cd();
2723       Zvtx_hcal->GetXaxis()->SetRangeUser(-60, 60);
2724       Zvtx_hcalmbd->GetXaxis()->SetRangeUser(-60, 60);
2725 
2726       if ( Zvtx_hcal->GetEntries() > Zvtx_hcalmbd->GetEntries() )
2727       {
2728         Zvtx_hcal->Draw();
2729         Zvtx_hcalmbd->Draw("same");
2730       }
2731       else
2732       {
2733         Zvtx_hcalmbd->Draw();
2734         Zvtx_hcal->Draw("same");
2735       }
2736     }
2737     if (PadNhitsHCAL)
2738     {
2739       PadNhitsHCAL->cd();
2740 
2741       Nhit_hcal[0]->SetLineColor(2);
2742       Nhit_hcal[1]->SetLineColor(4);
2743       Nhit_hcalmbd[0]->SetLineColor(2);
2744       Nhit_hcalmbd[1]->SetLineColor(4);
2745       Nhit_hcalmbd[0]->SetLineStyle(7);
2746       Nhit_hcalmbd[1]->SetLineStyle(7);
2747       for (int iarm=0; iarm<2; iarm++)
2748       {
2749         Nhit_hcal[iarm]->GetXaxis()->SetRangeUser(0,64);
2750         Nhit_hcalmbd[iarm]->GetXaxis()->SetRangeUser(0,64);
2751 
2752         if ( iarm==0 ) Nhit_hcal[iarm]->Draw();
2753         else           Nhit_hcal[iarm]->Draw("same");
2754         Nhit_hcalmbd[iarm]->Draw("same");
2755       }
2756     }
2757 
2758 
2759     if (PadChargeSum)
2760     {
2761       PadChargeSum->cd();
2762 
2763       NorthChargeSum->SetLineColor(4);
2764       SouthChargeSum->SetLineColor(2);
2765       NorthChargeSum->GetXaxis()->SetRangeUser(0,60);
2766       SouthChargeSum->GetXaxis()->SetRangeUser(0,60);
2767       NorthChargeSum->Draw();
2768       SouthChargeSum->Draw("same");
2769 
2770       //       float height = NorthChargeSum->GetMaximum();
2771       //       TextNorthChargeSum->SetY( height*0.88);
2772       //       TextSouthChargeSum->SetY( height*0.88);
2773       TextNorthChargeSum->SetTextColor(4);
2774       TextSouthChargeSum->SetTextColor(2);
2775       TextNorthChargeSum->Draw();
2776       TextSouthChargeSum->Draw();
2777     }
2778 
2779     if (PadAdc)
2780     {
2781       PadAdc->cd();
2782       Adc->Draw("colz");
2783     }
2784   }  // TC[2]
2785 
2786   // ------------------------------------------------------------------------
2787   // Draw 4th Page
2788   // ------------------------------------------------------------------------
2789   if (TC[3])
2790   {
2791     TC[3]->cd();
2792 
2793     // -------------------------------------------------------------------------
2794     PadTop[3]->cd();
2795     PaveTop->Draw();
2796     TextTop->Draw();
2797 
2798     // TDC
2799 
2800     for (int side = 0; side < nSIDE; side++)
2801     {
2802       PadTdcOver[side]->cd();
2803       // ifdelete( FrameTdcOver[side] );
2804       FrameTdcOver[side] = TC[0]->DrawFrame(0.5, -5, 64.5, 5);
2805       // FrameTdcOver[side] = gPad->DrawFrame( 0.5, -5, 64.5, 5);
2806 
2807       std::cout << "FrameTdcOver[" << side << "] = " << (unsigned long) FrameTdcOver[side] << std::endl;
2808       BoxTdcOver[side]->Draw();
2809 
2810       name << BbcMonDefs::SIDE_Str[side] << " MBD TDC Distribution";
2811       FrameTdcOver[side]->SetTitle(name.str().c_str());
2812       name.str("");
2813 
2814       FrameTdcOver[side]->GetXaxis()->SetTitle("PMT Number");
2815       FrameTdcOver[side]->GetXaxis()->SetTitleSize(0.05);
2816       FrameTdcOver[side]->GetXaxis()->SetLabelSize(0.05);
2817       FrameTdcOver[side]->GetYaxis()->SetTitle("Deviation [#sigma]");
2818       FrameTdcOver[side]->GetYaxis()->SetTitleSize(0.07);
2819       FrameTdcOver[side]->GetYaxis()->SetTitleOffset(0.50);
2820       FrameTdcOver[side]->GetYaxis()->SetLabelSize(0.05);
2821       TdcOver[side]->SetMarkerStyle(21);
2822       TdcOver[side]->SetMarkerSize(0.5);
2823       TdcOver[side]->SetMarkerColor(2);
2824       TdcOver[side]->Draw("P");
2825 
2826       // Check Warning
2827       if (nhit[0] > 100)
2828       {
2829         for (int i = 0; i < nPMT_1SIDE_BBC; i++)
2830         {
2831           if (tdcOverMean[side][i] == 0 && tdcOverErrY[side][i] == 0)
2832           {
2833             msg.str("");
2834             msg << "Stop the run (ch " << i + 1 << " is out of the range)";
2835             std::string wmsg = msg.str();
2836             Warning(PadTdcOver[side], i, tdcOverMean[side][i], 1, wmsg);
2837             wmsg.erase();
2838             msg.str("");
2839           }
2840           if (tdcOverMean[side][i] < BbcMonDefs::BBC_TDC_OVERFLOW_REGULAR_MIN)
2841           {
2842             msg.str("");
2843             msg << "ch " << i + 1 << " is too low ( " << std::fixed << std::setprecision(1) << tdcOverMean[side][i] << " #sigma)";
2844             std::string wmsg = msg.str();
2845             Warning(PadTdcOver[side], i, tdcOverMean[side][i], 1, wmsg);
2846             wmsg.erase();
2847             msg.str("");
2848           }
2849           if (tdcOverMean[side][i] > BbcMonDefs::BBC_TDC_OVERFLOW_REGULAR_MAX)
2850           {
2851             msg.str("");
2852             msg << "ch " << i + 1 << " is too high ( " << std::fixed << std::setprecision(1) << tdcOverMean[side][i] << " #sigma)";
2853             std::string wmsg = msg.str();
2854             Warning(PadTdcOver[side], i, tdcOverMean[side][i], 1, wmsg);
2855             wmsg.erase();
2856             msg.str("");
2857           }
2858           if (tdcOverMean[side][i] > BbcMonDefs::BBC_TDC_OVERFLOW_REGULAR_RMS_MAX)
2859           {
2860             msg.str("");
2861             msg << "ch " << i + 1 << " is too wide ( " << std::fixed << std::setprecision(1) << tdcOverErrY[side][i] << " #sigma)";
2862             std::string wmsg = msg.str();
2863             Warning(PadTdcOver[side], i, tdcOverMean[side][i], 1, wmsg);
2864             wmsg.erase();
2865             msg.str("");
2866           }
2867         }
2868       }
2869 
2870       PadnHit[side]->cd();
2871       // ifdelete( FramenHit[side] );
2872       // FramenHit[side] = TC[0]->DrawFrame( 0.5, 0, 64.5, 1);
2873       FramenHit[side] = gPad->DrawFrame(0.5, 0, 64.5, 1);
2874       BoxnHit[0][side]->Draw();
2875       BoxnHit[1][side]->Draw();
2876 
2877       name << BbcMonDefs::SIDE_Str[side] << " MBD number of Hit per Event";
2878       FramenHit[side]->SetTitle(name.str().c_str());
2879       name.str("");
2880 
2881       FramenHit[side]->GetXaxis()->SetTitle("PMT Number");
2882       FramenHit[side]->GetXaxis()->SetTitleSize(0.05);
2883       FramenHit[side]->GetXaxis()->SetLabelSize(0.05);
2884       FramenHit[side]->GetYaxis()->SetTitleSize(0.05);
2885       FramenHit[side]->GetYaxis()->SetLabelSize(0.05);
2886       nHit[0][side]->SetMarkerStyle(21);
2887       nHit[0][side]->SetMarkerSize(0.5);
2888       nHit[0][side]->SetMarkerColor(2);
2889       nHit[0][side]->Draw("P");
2890       nHit[1][side]->SetMarkerStyle(22);
2891       nHit[1][side]->SetMarkerSize(0.5);
2892       nHit[1][side]->SetMarkerColor(4);
2893       nHit[1][side]->Draw("P");
2894 
2895       for (int i = 0; i < nPMT_1SIDE_BBC; i++)
2896       {
2897         if (nhit[0] > 100)
2898         {
2899           if (nhitPmt[0][side][i] < BbcMonDefs::BBC_nHIT_MB_MIN[side])
2900           {
2901             // RUN11: to ignore hit rate since ch29 before FEM input is dead.
2902             // RUN11: to ignore hit rate since the gain for ch40 is unstable.
2903             // if( (side==0)&&(i==29 || i==40))
2904             //{
2905             // if(i == 29){
2906             //    std::cout << "ch29 : Ignore hit rate into ch29" << std::endl;
2907             // }
2908             // else {
2909             //    std::cout << "ch40 : Ignore hit rate into ch40" << std::endl;
2910             // }
2911             //  continue;
2912             // }
2913 
2914             msg.str("");
2915             msg << "Too low hit-rate into ch " << i + 1 << " ("
2916                 << std::fixed << std::setprecision(2) << nhitPmt[0][side][i]
2917                 << "/" << std::setprecision(0) << nhit[0] << "evt)";
2918             std::string wmsg = msg.str();
2919             Warning(PadnHit[side], i, nhitPmt[0][side][i], 1, wmsg);
2920             wmsg.erase();
2921             msg.str("");
2922           }
2923           if (nhitPmt[0][side][i] > BbcMonDefs::BBC_nHIT_MB_MAX[side])
2924           {
2925             msg.str("");
2926             msg << "Too high hit-rate into ch " << i + 1 << " ("
2927                 << std::fixed << std::setprecision(2) << nhitPmt[0][side][i]
2928                 << "/" << std::setprecision(0) << nhit[0] << "evt)";
2929             std::string wmsg = msg.str();
2930             Warning(PadnHit[side], i, nhitPmt[0][side][i], 1, wmsg);
2931             wmsg.erase();
2932             msg.str("");
2933           }
2934         }
2935 
2936         if (nhit[1] > 0)
2937         {
2938           if (nhitPmt[1][side][i] < BbcMonDefs::BBC_nHIT_LASER_MIN[side])
2939           {
2940             if (side == 0)
2941             {
2942               // RUN12: to ignore lack of laser rate, since fiber of ch7 is broken.
2943               if (i == 7)
2944               {
2945                 std::cout << "ch7(S8) : Ignore hit rate of laser" << std::endl;
2946                 continue;
2947               }
2948               msg.str("");
2949               msg << "Lack of laser's hit into ch " << i + 1 << " ("
2950                   << std::fixed << std::setprecision(2) << nhitPmt[1][side][i]
2951                   << "/" << std::setprecision(0) << nhit[1] << "evt)";
2952               std::string wmsg = msg.str();
2953               Warning(PadnHit[side], i, nhitPmt[1][side][i], 1, wmsg);
2954               wmsg.erase();
2955               msg.str("");
2956             }
2957             else  // North
2958             {
2959               msg.str("");
2960               msg << "Lack of laser's hit into ch " << i + 1 << " ("
2961                   << std::fixed << std::setprecision(2) << nhitPmt[1][side][i]
2962                   << "/" << std::setprecision(0) << nhit[1] << "evt)";
2963               std::string wmsg = msg.str();
2964               Warning(PadnHit[side], i, nhitPmt[1][side][i], 1, wmsg);
2965               wmsg.erase();
2966               msg.str("");
2967             }
2968           }
2969         }
2970       }
2971       // if ( nhit[0] == 0 )
2972       // Warning( PadnHit[side], 1, 0, 1, "No Event" );
2973       // if ( nhit[1] == 0 )
2974       // Warning( PadnHit[side], 1, 0, 1, "No Laser Event" );
2975     }
2976 
2977     PadnHitStatus->cd();
2978     TextnHitStatus->Draw();
2979   }
2980 
2981 
2982   if(TC[8])
2983   {
2984     TC[8]->cd();
2985     for (int i = 0; i < static_cast<int>(TriggerEnum::NUM_MBD_TRIGGERS); i++)
2986     {
2987       PadAutoUpdate[i]->cd();
2988       if (ZvrtxAuto[i])
2989       {
2990         ZvrtxAuto[i]->Draw();
2991         ZvrtxAuto[i]->SetTitle(TriggerEnum::MBTriggerNames[i]);
2992         ZvrtxAuto[i]->GetXaxis()->SetTitle(Form("MBD ZVertex Trigger %s", TriggerEnum::MBTriggerNames[i]));
2993         ZvrtxAuto[i]->GetYaxis()->SetTitle("Number of Event");
2994         ZvrtxAuto[i]->GetXaxis()->SetTitleOffset(0.70);
2995         ZvrtxAuto[i]->GetYaxis()->SetTitleOffset(1.75);
2996         ZvrtxAuto[i]->GetXaxis()->SetLabelSize(0.07);
2997         ZvrtxAuto[i]->GetXaxis()->SetTickSize(0.1);
2998         ZvrtxAuto[i]->GetYaxis()->SetTitleOffset(1.75);
2999         ZvrtxAuto[i]->GetYaxis()->SetTitleSize(0.05);
3000       } else
3001       {
3002         TH1 *dummy = new TH1F(Form("DummyZvrtxAuto_%d", i), "No Data", 100, -60, 60);
3003         dummy->GetXaxis()->SetTitle(Form("MBD ZVertex Trigger %s",
3004                                         TriggerEnum::MBTriggerNames[i]));
3005         dummy->GetYaxis()->SetTitle("Number of Event");   
3006         dummy->GetXaxis()->SetTitleOffset(0.70);
3007         dummy->GetYaxis()->SetTitleOffset(1.75);
3008         dummy->GetXaxis()->SetLabelSize(0.07);
3009         dummy->GetXaxis()->SetTickSize(0.1);
3010         dummy->GetYaxis()->SetTitleOffset(1.75);
3011         dummy->GetYaxis()->SetTitleSize(0.05);
3012         dummy->Draw();
3013       }
3014       PadAutoUpdate[i]->Update();
3015       
3016     }
3017 
3018   }
3019 
3020   //  std::cout << "Got Histgram Got-Pad 0" << std::endl;
3021 
3022   if (TC[0])
3023   {
3024     TC[0]->Update();
3025   }
3026   if (TC[1])
3027   {
3028     TC[1]->Update();
3029   }
3030   if (TC[2])
3031   {
3032     TC[2]->Update();
3033   }
3034   if (TC[3])
3035   {
3036     TC[3]->Update();
3037   }
3038   if (TC[8])
3039   {
3040     TC[8]->Update();
3041   }
3042 
3043 
3044   // std::cout << "Got Histgram Got-Pad 1" << std::endl;
3045 
3046   oldStyle->cd();
3047 
3048   //******************************************
3049   int iret = 0;
3050   //  int idraw = 0;
3051   /*
3052      if (what == "ALL" || what == "FIRST")
3053      {
3054      iret += DrawFirst(what);
3055      idraw++;
3056      }
3057      if (what == "ALL" || what == "SECOND")
3058      {
3059      iret += DrawSecond(what);
3060      idraw++;
3061      }
3062   if (what == "ALL" || what == "HISTORY")
3063   {
3064     iret += DrawHistory(what);
3065     //    idraw++;
3066   }
3067      */
3068 
3069   /*
3070      if (!idraw)
3071      {
3072      std::cout << __PRETTY_FUNCTION__ << " Unimplemented Drawing option: " << what << std::endl;
3073      iret = -1;
3074      }
3075      */
3076 
3077   //******************************************
3078   return iret;
3079 }
3080 
3081 int BbcMonDraw::DrawFirst(const std::string & /*unused*/)
3082 {
3083   PRINT_DEBUG("In BbcMonDraw::DrawFirst()");
3084   OnlMonClient *cl = OnlMonClient::instance();
3085   TH1 *bbcmon_hist1 = cl->getHisto("BBCMON_0", "bbc_zvertex");
3086   TH2 *bbcmon_hist2 = (TH2 *) cl->getHisto("BBCMON_0", "bbc_tzero_zvtx");
3087 
3088   if (!gROOT->FindObject("BbcMon1"))
3089   {
3090     MakeCanvas("BbcMon1");
3091   }
3092   TC[0]->SetEditable(true);
3093   TC[0]->Clear("D");
3094   Pad[0]->cd();
3095   if (bbcmon_hist1)
3096   {
3097     bbcmon_hist1->DrawCopy();
3098   }
3099   else
3100   {
3101     DrawDeadServer(transparent[0]);
3102     TC[0]->SetEditable(false);
3103     return -1;
3104   }
3105 
3106   Pad[1]->cd();
3107   if (bbcmon_hist2)
3108   {
3109     bbcmon_hist2->DrawCopy();
3110   }
3111   TText PrintRun;
3112   PrintRun.SetTextFont(62);
3113   PrintRun.SetTextSize(0.04);
3114   PrintRun.SetNDC();          // set to normalized coordinates
3115   PrintRun.SetTextAlign(23);  // center/top alignment
3116   std::ostringstream runnostream;
3117   std::string runstring;
3118   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
3119   // fill run number and event time into string
3120   runnostream << ThisName << "_1 Run " << cl->RunNumber()
3121               << ", Time: " << ctime(&evttime.first);
3122   runstring = runnostream.str();
3123   transparent[0]->cd();
3124   PrintRun.DrawText(0.5, 1., runstring.c_str());
3125   TC[0]->Update();
3126   TC[0]->Show();
3127   TC[0]->SetEditable(false);
3128   return 0;
3129 }
3130 
3131 int BbcMonDraw::DrawSecond(const std::string & /*unused*/)
3132 {
3133   PRINT_DEBUG("In BbcMonDraw::DrawSecond()");
3134 
3135   OnlMonClient *cl = OnlMonClient::instance();
3136   TH1 *bbcmon_hist1 = cl->getHisto("BBCMON_0", "bbc_zvertex");
3137   TH2 *bbcmon_hist2 = (TH2 *) cl->getHisto("BBCMON_0", "bbc_tzero_zvtx");
3138   if (!gROOT->FindObject("BbcMon2"))
3139   {
3140     MakeCanvas("BbcMon2");
3141   }
3142   TC[1]->SetEditable(true);
3143   TC[1]->Clear("D");
3144   Pad[2]->cd();
3145   if (bbcmon_hist1)
3146   {
3147     bbcmon_hist1->DrawCopy();
3148   }
3149   else
3150   {
3151     DrawDeadServer(transparent[1]);
3152     TC[1]->SetEditable(false);
3153     return -1;
3154   }
3155   Pad[3]->cd();
3156   if (bbcmon_hist2)
3157   {
3158     bbcmon_hist2->DrawCopy();
3159   }
3160   TText PrintRun;
3161   PrintRun.SetTextFont(62);
3162   PrintRun.SetTextSize(0.04);
3163   PrintRun.SetNDC();          // set to normalized coordinates
3164   PrintRun.SetTextAlign(23);  // center/top alignment
3165   std::ostringstream runnostream;
3166   std::string runstring;
3167   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
3168 
3169   // fill run number and event time into string
3170   runnostream << ThisName << "_2 Run " << cl->RunNumber()
3171               << ", Time: " << ctime(&evttime.first);
3172   runstring = runnostream.str();
3173   transparent[1]->cd();
3174   PrintRun.SetTextColor(evttime.second);
3175   PrintRun.DrawText(0.5, 1., runstring.c_str());
3176   TC[1]->Update();
3177   TC[1]->Show();
3178   TC[1]->SetEditable(false);
3179   return 0;
3180 }
3181 
3182 int BbcMonDraw::SavePlot(const std::string &what, const std::string &type)
3183 {
3184   OnlMonClient *cl = OnlMonClient::instance();
3185   int iret = Draw(what);
3186   if (iret)  // on error no png files please
3187   {
3188     return iret;
3189   }
3190   int icnt = 0;
3191   for (TCanvas *canvas : TC)
3192   {
3193     if (canvas == nullptr)
3194     {
3195       continue;
3196     }
3197     icnt++;
3198     std::string filename = ThisName + "_" + std::to_string(icnt) + "_" +
3199                            std::to_string(cl->RunNumber()) + "." + type;
3200     cl->CanvasToPng(canvas, filename);
3201   }
3202   return 0;
3203 }
3204 
3205 int BbcMonDraw::MakeHtml(const std::string &what)
3206 {
3207   int iret = Draw(what);
3208   if (iret)  // on error no html output please
3209   {
3210     return iret;
3211   }
3212 
3213   OnlMonClient *cl = OnlMonClient::instance();
3214 
3215   int icnt = 0;
3216   for (TCanvas *canvas : TC)
3217   {
3218     if (canvas == nullptr)
3219     {
3220       continue;
3221     }
3222     icnt++;
3223     // Register the canvas png file to the menu and produces the png file.
3224     std::string pngfile = cl->htmlRegisterPage(*this, canvas->GetTitle(), std::to_string(icnt), "png");
3225     cl->CanvasToPng(canvas, pngfile);
3226   }
3227 
3228   // Now register also EXPERTS html pages, under the EXPERTS subfolder.
3229   // std::string logfile = cl->htmlRegisterPage(*this, "EXPERTS/Log", "log", "html");
3230   // std::ofstream out(logfile.c_str());
3231   // out << "<HTML><HEAD><TITLE>Log file for run " << cl->RunNumber()
3232   //     << "</TITLE></HEAD>" << std::endl;
3233   // out << "<P>Some log file output would go here." << std::endl;
3234   // out.close();
3235 
3236   // std::string status = cl->htmlRegisterPage(*this, "EXPERTS/Status", "status", "html");
3237   // std::ofstream out2(status.c_str());
3238   // out2 << "<HTML><HEAD><TITLE>Status file for run " << cl->RunNumber()
3239   //     << "</TITLE></HEAD>" << std::endl;
3240   // out2 << "<P>Some status output would go here." << std::endl;
3241   // out2.close();
3242 
3243   // cl->SaveLogFile(*this);
3244 
3245   return 0;
3246 }
3247 
3248 int BbcMonDraw::DrawHistory(const std::string & /* what */)
3249 {
3250   // you need to provide the following vectors
3251   // which are filled from the db
3252   std::vector<float> var;
3253   std::vector<float> varerr;
3254   std::vector<time_t> timestamp;
3255   /*chiu
3256     std::vector<int> runnumber;
3257   //std::string varname = "bbcmondummy";
3258   // this sets the time range from whihc values should be returned
3259   time_t begin = 0;            // begin of time (1.1.1970)
3260   time_t end = time(nullptr);  // current time (right NOW)
3261   int iret = dbvars->GetVar(begin, end, varname, timestamp, runnumber, var, varerr);
3262   if (iret)
3263   {
3264   std::cout << __PRETTY_FUNCTION__ << " Error in db access" << std::endl;
3265   return iret;
3266   }
3267   */
3268   if (!gROOT->FindObject("BbcMon4"))
3269   {
3270     MakeCanvas("BbcMon4");
3271   }
3272   // timestamps come sorted in ascending order
3273   float *x = new float[var.size()];
3274   float *y = new float[var.size()];
3275   float *ex = new float[var.size()];
3276   float *ey = new float[var.size()];
3277   // int n = var.size();
3278   for (unsigned int i = 0; i < var.size(); i++)
3279   {
3280     //       std::cout << "timestamp: " << ctime(&timestamp[i])
3281     //     << ", run: " << runnumber[i]
3282     //     << ", var: " << var[i]
3283     //     << ", varerr: " << varerr[i]
3284     //     << std::endl;
3285     x[i] = timestamp[i] - TimeOffsetTicks;
3286     y[i] = var[i];
3287     ex[i] = 0;
3288     ey[i] = varerr[i];
3289   }
3290 
3291   /* need to implement history for BBC
3292      Pad[4]->cd(); // neeed to fix
3293      if (gr[0])
3294      {
3295      delete gr[0];
3296      }
3297      gr[0] = new TGraphErrors(n, x, y, ex, ey);
3298      gr[0]->SetMarkerColor(4);
3299      gr[0]->SetMarkerStyle(21);
3300      gr[0]->Draw("ALP");
3301      gr[0]->GetXaxis()->SetTimeDisplay(1);
3302      gr[0]->GetXaxis()->SetLabelSize(0.03);
3303   // the x axis labeling looks like crap
3304   // please help me with this, the SetNdivisions
3305   // don't do the trick
3306   gr[0]->GetXaxis()->SetNdivisions(-1006);
3307   gr[0]->GetXaxis()->SetTimeOffset(TimeOffsetTicks);
3308   gr[0]->GetXaxis()->SetTimeFormat("%Y/%m/%d %H:%M");
3309   */
3310   delete[] x;
3311   delete[] y;
3312   delete[] ex;
3313   delete[] ey;
3314 
3315   /*chiu
3316     varname = "bbcmoncount";
3317     iret = dbvars->GetVar(begin, end, varname, timestamp, runnumber, var, varerr);
3318     if (iret)
3319     {
3320     std::cout << __PRETTY_FUNCTION__ << " Error in db access" << std::endl;
3321     return iret;
3322     }
3323     */
3324   x = new float[var.size()];
3325   y = new float[var.size()];
3326   ex = new float[var.size()];
3327   ey = new float[var.size()];
3328   // n = var.size();
3329   for (unsigned int i = 0; i < var.size(); i++)
3330   {
3331     //       std::cout << "timestamp: " << ctime(&timestamp[i])
3332     //     << ", run: " << runnumber[i]
3333     //     << ", var: " << var[i]
3334     //     << ", varerr: " << varerr[i]
3335     //     << std::endl;
3336     x[i] = timestamp[i] - TimeOffsetTicks;
3337     y[i] = var[i];
3338     ex[i] = 0;
3339     ey[i] = varerr[i];
3340   }
3341 
3342   /* Need to implement
3343      Pad[5]->cd();
3344      if (gr[1])
3345      {
3346      delete gr[1];
3347      }
3348      gr[1] = new TGraphErrors(n, x, y, ex, ey);
3349      gr[1]->SetMarkerColor(4);
3350      gr[1]->SetMarkerStyle(21);
3351      gr[1]->Draw("ALP");
3352      gr[1]->GetXaxis()->SetTimeDisplay(1);
3353   // TC[2]->Update();
3354   //    h1->GetXaxis()->SetTimeDisplay(1);
3355   //    h1->GetXaxis()->SetLabelSize(0.03);
3356   gr[1]->GetXaxis()->SetLabelSize(0.03);
3357   gr[1]->GetXaxis()->SetTimeOffset(TimeOffsetTicks);
3358   gr[1]->GetXaxis()->SetTimeFormat("%Y/%m/%d %H:%M");
3359   //    h1->Draw();
3360   */
3361 
3362   delete[] x;
3363   delete[] y;
3364   delete[] ex;
3365   delete[] ey;
3366 
3367   TC[3]->Update();
3368   return 0;
3369 }
3370 
3371 int BbcMonDraw::DrawDeadServer(TPad *transparent_pad)
3372 {
3373   transparent_pad->cd();
3374   TText FatalMsg;
3375   FatalMsg.SetTextFont(62);
3376   FatalMsg.SetTextSize(0.1);
3377   FatalMsg.SetTextColor(4);
3378   FatalMsg.SetNDC();          // set to normalized coordinates
3379   FatalMsg.SetTextAlign(23);  // center/top alignment
3380   FatalMsg.DrawText(0.5, 0.9, "BBCMONITOR");
3381   FatalMsg.SetTextAlign(22);  // center/center alignment
3382   FatalMsg.DrawText(0.5, 0.5, "SERVER");
3383   FatalMsg.SetTextAlign(21);  // center/bottom alignment
3384   FatalMsg.DrawText(0.5, 0.1, "DEAD");
3385   transparent_pad->Update();
3386   return 0;
3387 }
3388 
3389 void BbcMonDraw::GetMinBiasTrigName()
3390 {
3391   // look for MB triggers
3392   for ( int itrig = 0; itrig < TriggerEnum::nMBTriggers; itrig++ )
3393   {
3394     int ibit = static_cast<int>(TriggerEnum::MBTriggers[itrig]);
3395     double prescale = Prescale_hist->GetBinContent(ibit+1);
3396     if ( prescale >= 0 )
3397     {
3398         TrigName = TriggerEnum::MBTriggerNames[itrig];
3399         return;
3400     }
3401   }
3402   // maybe here we could fall back to a coincidence with an MBD trigger?
3403 
3404   // no mb bit found, take all triggers
3405   TrigName = "ALL TRIGGERS";
3406   return;
3407 }
3408