Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:20:25

0001 #include "HcalMonDraw.h"
0002 
0003 #include <onlmon/OnlMonClient.h>
0004 #include <onlmon/triggerEnum.h>
0005 
0006 #include <TAxis.h>  // for TAxis
0007 #include <TButton.h>
0008 #include <TCanvas.h>
0009 #include <TFile.h>
0010 #include <TFrame.h>
0011 #include <TGraphErrors.h>
0012 #include <TH1.h>
0013 #include <TH2.h>
0014 #include <TProfile2D.h>
0015 #include <TLegend.h>
0016 #include <TLine.h>
0017 #include <TPad.h>
0018 #include <TProfile.h>
0019 #include <TQObject.h>
0020 #include <TROOT.h>
0021 #include <TStyle.h>
0022 #include <TSystem.h>
0023 #include <TText.h>
0024 
0025 #include <cstring>  // for memset
0026 #include <ctime>
0027 #include <fstream>
0028 #include <iostream>  // for operator<<, basic_ostream, basic_os...
0029 #include <sstream>
0030 #include <vector>  // for vector
0031 
0032 HcalMonDraw::HcalMonDraw(const std::string& name)
0033   : OnlMonDraw(name)
0034 {
0035   // if name start with O prefix = "OHCALMON"
0036   // if name start with I prefix = "IHCALMON"
0037   if (ThisName[0] == 'O')
0038   {
0039     prefix = "OHCALMON";
0040   }
0041   else if (ThisName[0] == 'I')
0042   {
0043     prefix = "IHCALMON";
0044   }
0045   else
0046   {
0047     std::cout << "HcalMonDraw::HcalMonDraw() ERROR: name does not start with O or I " << ThisName << std::endl;
0048     exit(1);
0049   }
0050   for (int i = 0; i < 2; i++)
0051   {
0052     hcalmon[i] = prefix + "_" + std::to_string(i);
0053   }
0054   return;
0055 }
0056 
0057 int HcalMonDraw::Init()
0058 {
0059   delete hcalStyle;  // make cppcheck happy - deleting a nullptr here
0060   hcalStyle = new TStyle("hcalStyle", "hcalStyle");
0061 
0062   Int_t font = 42;  // Helvetica
0063   hcalStyle->SetLabelFont(font, "x");
0064   hcalStyle->SetTitleFont(font, "x");
0065   hcalStyle->SetLabelFont(font, "y");
0066   hcalStyle->SetTitleFont(font, "y");
0067   hcalStyle->SetLabelFont(font, "z");
0068   hcalStyle->SetTitleFont(font, "z");
0069   hcalStyle->SetOptStat(0);
0070   hcalStyle->SetPadTickX(1);
0071   hcalStyle->SetPadTickY(1);
0072   gROOT->SetStyle("hcalStyle");
0073   gROOT->ForceStyle();
0074   char TEMPFILENAME[100];
0075   const char* hcalcalib = getenv("HCALCALIB");
0076 
0077   sprintf(TEMPFILENAME, "%s/%s_71597.root", hcalcalib, prefix.c_str());
0078 
0079   TFile* tempfile = new TFile(TEMPFILENAME, "READ");
0080   if (!tempfile->IsOpen())
0081   {
0082     std::cout << "HcalMonDraw::Init() ERROR: Could not open file " << TEMPFILENAME << std::endl;
0083     exit(1);
0084   }
0085   h2_mean_template = (TH2*) tempfile->Get("h2_hcal_hits_template");
0086 
0087   if (!h2_mean_template)
0088   {
0089     std::cout << "HcalMonDraw::Init() ERROR: Could not find histogram h2_mean_template in file " << TEMPFILENAME << std::endl;
0090     exit(1);
0091   }
0092   sprintf(TEMPFILENAME, "%s/%s_cosmic_63461_1000ADC.root", hcalcalib, prefix.c_str());
0093   TFile* tempfile2 = new TFile(TEMPFILENAME, "READ");
0094   if (!tempfile2->IsOpen())
0095   {
0096     std::cout << "HcalMonDraw::Init() ERROR: Could not open file " << TEMPFILENAME << std::endl;
0097     exit(1);
0098   }
0099   h2_mean_template_cosmic = (TH2*) tempfile2->Get("h2_hcal_hits_template_cosmic");
0100 
0101   if (!h2_mean_template_cosmic)
0102   {
0103     std::cout << "HcalMonDraw::Init() ERROR: Could not find histogram h2_mean_template_cosmic in file " << TEMPFILENAME << std::endl;
0104     exit(1);
0105   }
0106 
0107   h1_zs = new TH1F("h1_zs", "unsuppressed rate ", 100, 0, 1.1);
0108   h1_zs_low = new TH1F("h1_zs_low", "unsuppressed rate ", 100, 0, 1.1);
0109   h1_zs_high = new TH1F("h1_zs_high", "unsuppressed rate ", 100, 0, 1.1);
0110 
0111   //  MakeZSPalette();
0112   return 0;
0113 }
0114 
0115 int HcalMonDraw::MakeCanvas(const std::string& name)
0116 {
0117   OnlMonClient* cl = OnlMonClient::instance();
0118   int xsize = cl->GetDisplaySizeX();
0119   int ysize = cl->GetDisplaySizeY();
0120   if (name == "HcalMon1")
0121   {
0122     // xpos (-1) negative: do not draw menu bar
0123     TC[0] = new TCanvas(name.c_str(), "Hcal Towers", -1, ysize, xsize / 3, ysize);
0124     // root is pathetic, whenever a new TCanvas is created root piles up
0125     // 6kb worth of X11 events which need to be cleared with
0126     // gSystem->ProcessEvents(), otherwise your process will grow and
0127     // grow and grow but will not show a definitely lost memory leak
0128     gSystem->ProcessEvents();
0129     Pad[0] = new TPad("hist", "On the top", 0., 0.2, 1., 0.97);
0130     Pad[0]->Draw();
0131     // Pad[1]->Draw();
0132     //  this one is used to plot the run number on the canvas
0133     transparent[0] = new TPad("transparent0", "this does not show", 0, 0, 1, 1);
0134     transparent[0]->SetFillStyle(4000);
0135     transparent[0]->Draw();
0136 
0137     // warning
0138     warning[0] = new TPad("warning0", "this does not show", 0, 0, 0.9, 0.2);
0139     warning[0]->SetFillStyle(4000);
0140     warning[0]->Draw();
0141 
0142     TC[0]->SetEditable(false);
0143   }
0144 
0145   else if (name == "HcalMon2")
0146   {
0147     // xpos negative: do not draw menu bar
0148     TC[1] = new TCanvas(name.c_str(), "Hcal Sector Running Mean", -1, ysize, xsize / 3, ysize);
0149     gSystem->ProcessEvents();
0150     Pad[2] = new TPad("hcalpad3", "who needs this?", 0.0, 0.0, 1, 0.92, 0);
0151     // Pad[3] = new TPad("hcalpad4", "who needs this?", 0.1, 0.05, 0.9, 0.45, 0);
0152     Pad[2]->Draw();
0153     // Pad[3]->Draw();
0154     //  this one is used to plot the run number on the canvas
0155     transparent[1] = new TPad("transparent1", "this does not show", 0, 0, 1, 1);
0156     transparent[1]->SetFillStyle(4000);
0157     transparent[1]->Draw();
0158     TC[1]->SetEditable(false);
0159   }
0160   else if (name == "HcalMon3")
0161   {
0162     TC[3] = new TCanvas(name.c_str(), "HcalMon3 Waveform Info", -1, ysize, xsize / 3, ysize);
0163     gSystem->ProcessEvents();
0164     Pad[6] = new TPad("hcalpad6", "who needs this?", 0.0, 0.6, 1.0, 0.95, 0);
0165     Pad[7] = new TPad("hcalpad7", "who needs this?", 0.0, 0.3, 1.0, 0.6, 0);
0166     Pad[8] = new TPad("hcalpad8", "who needs this?", 0.0, 0.0, 1.0, 0.3, 0);
0167     Pad[6]->Draw();
0168     Pad[7]->Draw();
0169     Pad[8]->Draw();
0170     // this one is used to plot the run number on the canvas
0171     transparent[3] = new TPad("transparent3", "this does not show", 0, 0, 1, 1);
0172     transparent[3]->SetFillStyle(4000);
0173     transparent[3]->Draw();
0174     TC[3]->SetEditable(false);
0175   }
0176   else if (name == "HcalMon4")
0177   {
0178     // xpos negative: do not draw menu bar
0179     TC[5] = new TCanvas(name.c_str(), "HCAL Packet Information", -1, ysize, 2 * xsize / 3, ysize);
0180     gSystem->ProcessEvents();
0181     Pad[10] = new TPad("pad10", "packet event check", 0.0, 0.6, 1.0 / 2, 0.95, 0);
0182     Pad[11] = new TPad("pad11", "packet size", 0.0, 0.3, 1.0 / 2, 0.6, 0);
0183     Pad[12] = new TPad("pad12", "packet channels", 0.0, 0.0, 1.0 / 2, 0.3, 0);
0184     Pad[13] = new TPad("pad13", "event number offset", 0.5, 0.6, 1.0, 0.95, 0);
0185     // pad 14 and 15 side by side from left to right for correlation
0186     Pad[14] = new TPad("pad14", "correlation0", 0.5, 0.3, 0.75, 0.6, 0);
0187     Pad[15] = new TPad("pad15", "correlation1", 0.75, 0.3, 1.0, 0.6, 0);
0188 
0189     Pad[10]->Draw();
0190     Pad[11]->Draw();
0191     Pad[12]->Draw();
0192     Pad[13]->Draw();
0193     Pad[14]->Draw();
0194     Pad[15]->Draw();
0195     //  this one is used to plot the run number on the canvas
0196     transparent[5] = new TPad("transparent1", "this does not show", 0, 0, 1., 1);
0197     transparent[5]->SetFillStyle(4000);
0198     transparent[5]->Draw();
0199 
0200     // packet warnings
0201     warning[1] = new TPad("warning1", "packet warnings", 0.5, 0, 1, 0.2);
0202     warning[1]->SetFillStyle(4000);
0203     warning[1]->Draw();
0204     TC[5]->SetEditable(false);
0205   }
0206   else if (name == "HcalMon5")
0207   {
0208     TC[6] = new TCanvas(name.c_str(), "Expert: Trigger Info", -1, ysize, xsize / 2, ysize);
0209     gSystem->ProcessEvents();
0210     Pad[16] = new TPad("hcalpad16", "", 0.0, 0.6, 0.5, 0.95, 0);
0211     Pad[17] = new TPad("hcalpad17", "", 0.5, 0.6, 1.0, 0.95, 0);
0212     Pad[19] = new TPad("hcalpad19", "", 0.0, 0.3, 0.5, 0.6, 0);
0213     Pad[20] = new TPad("hcalpad20", "", 0.5, 0.3, 1.0, 0.6, 0);
0214     Pad[18] = new TPad("hcalpad18", "", 0.0, 0.0, 1.0, 0.2, 0);
0215     Pad[16]->Draw();
0216     Pad[17]->Draw();
0217     Pad[18]->Draw();
0218     Pad[19]->Draw();
0219     Pad[20]->Draw();
0220     // this one is used to plot the run number on the canvas
0221     transparent[6] = new TPad("transparent6", "this does not show", 0, 0, 1, 1);
0222     transparent[6]->SetFillStyle(4000);
0223     transparent[6]->Draw();
0224     TC[6]->SetEditable(false);
0225   }
0226   else if (name == "HcalMon6")
0227   {
0228     TC[7] = new TCanvas(name.c_str(), "Expert: Tower Information", -1, ysize, xsize * 0.9, ysize);
0229     gSystem->ProcessEvents();
0230     Pad[21] = new TPad("hcalpad21", "", 0.0, 0.5, 0.5, 0.95, 0);
0231     Pad[22] = new TPad("hcalpad22", "", 0.5, 0.5, 1.0, 0.95, 0);
0232     Pad[23] = new TPad("hcalpad23", "", 0.0, 0.0, 0.5, 0.5, 0);
0233 
0234     Pad[21]->Draw();
0235     Pad[22]->Draw();
0236     Pad[23]->Draw();
0237 
0238     // this one is used to plot the run number on the canvas
0239     transparent[7] = new TPad("transparent7", "this does not show", 0, 0, 1, 1);
0240     transparent[7]->SetFillStyle(4000);
0241     transparent[7]->Draw();
0242     TC[7]->SetEditable(false);
0243   }
0244   else if (name == "HcalMon7")
0245   {
0246     TC[9] = new TCanvas(name.c_str(), "Channel unsuppressed event fraction ", -1, ysize, xsize / 2, ysize);
0247     gSystem->ProcessEvents();
0248     Pad[24] = new TPad("hcalpad24", "who needs this?", 0.00, 0.3, 1.00, 0.95);
0249     Pad[24]->SetRightMargin(0.15);
0250     Pad[24]->Draw();
0251     Pad[25] = new TPad("hcalpad24", "1d zs rate", 0.0, 0.0, 1.00, 0.3);
0252     Pad[25]->SetRightMargin(0.15);
0253     Pad[25]->Draw();
0254     transparent[9] = new TPad("transparent7", "this does not show", 0, 0, 1, 1);
0255     transparent[9]->SetFillStyle(4000);
0256     transparent[9]->Draw();
0257     TC[9]->SetEditable(0);
0258   }
0259   else if (name == "HcalPopUp")
0260   {
0261     TC[4] = new TCanvas(name.c_str(), "!!!DO NOT CLOSE!!! OR THE CODE WILL CRASH!!!!(Maybe not...)", -1, ysize, xsize / 2, 2 * ysize / 3);
0262     gSystem->ProcessEvents();
0263     Pad[9] = new TPad("hcalpad9", "for single tower running mean", 0.0, 0.0, 1, 0.92, 0);
0264     Pad[9]->Draw();
0265     transparent[4] = new TPad("transparent4", "this does not show", 0, 0, 1, 1);
0266     transparent[4]->SetFillStyle(4000);
0267     transparent[4]->Draw();
0268     TC[4]->SetEditable(false);
0269   }
0270   else if (name == "HcalServerStats")
0271   {
0272     TC[8] = new TCanvas(name.c_str(), "HcalMon Server Stats", -1, 0, xsize, ysize);
0273     gSystem->ProcessEvents();
0274     // this one is used to plot the run number on the canvas
0275     transparent[8] = new TPad("transparent5", "this does not show", 0, 0, 1, 1);
0276     transparent[8]->Draw();
0277     transparent[8]->SetFillColor(kGray);
0278     TC[8]->SetEditable(false);
0279   }
0280   else if (name == "HcalAllTrigHits")
0281   {
0282     // xpos (-1) negative: do not draw menu bar
0283     TC[10] = new TCanvas(name.c_str(), "Hcal Towers", -1, ysize, xsize / 3, ysize);
0284 
0285     gSystem->ProcessEvents();
0286     Pad[26] = new TPad("hist", "On the top", 0., 0.2, 1., 0.97);
0287     Pad[26]->Draw();
0288     //  this one is used to plot the run number on the canvas
0289     transparent[10] = new TPad("transparent10", "this does not show", 0, 0, 1, 1);
0290     transparent[10]->SetFillStyle(4000);
0291     transparent[10]->Draw();
0292 
0293     // warning
0294     warning[2] = new TPad("warning2", "this does not show", 0, 0, 0.9, 0.2);
0295     warning[2]->SetFillStyle(4000);
0296     warning[2]->Draw();
0297 
0298     TC[10]->SetEditable(false);
0299   }
0300   else if (name == "HcalNoiseRMS")
0301   {
0302     // xpos (-1) negative: do not draw menu bar
0303     TC[11] = new TCanvas(name.c_str(), "HcalMon Noise RMS per tower", -1, ysize, xsize / 3, ysize);
0304     // root is pathetic, whenever a new TCanvas is created root piles up
0305     // 6kb worth of X11 events which need to be cleared with
0306     // gSystem->ProcessEvents(), otherwise your process will grow and
0307     // grow and grow but will not show a definitely lost memory leak
0308     gSystem->ProcessEvents();
0309     Pad[27] = new TPad("hcalpad22", "rms map", 0., 0.15, 1., 0.95);
0310     Pad[27]->Draw();
0311     // this one is used to plot the run number on the canvas
0312     transparent[11] = new TPad("transparent6", "this does not show", 0, 0, 1, 1);
0313     transparent[11]->SetFillStyle(4000);
0314     transparent[11]->Draw();
0315 
0316     // warning
0317     warning[3] = new TPad("warning6", "hot tower warnings", 0, 0, 1, 0.15);
0318     warning[3]->SetFillStyle(4000);
0319     warning[3]->Draw();
0320     TC[11]->SetEditable(false);
0321   }
0322   return 0;
0323 }
0324 
0325 int HcalMonDraw::Draw(const std::string& what)
0326 {
0327   int iret = 0;
0328   int idraw = 0;
0329   int isuccess = 0;
0330   if (what == "ALL" || what == "FIRST")
0331   {
0332     int retcode = DrawFirst(what);
0333     iret += retcode;
0334     if (!retcode)
0335     {
0336       isuccess++;
0337     }
0338     idraw++;
0339   }
0340   /*
0341   if (what == "ALL" || what == "SECOND")
0342   {
0343     int retcode = DrawSecond(what);
0344     if (!retcode)
0345     {
0346       isuccess++;
0347     }
0348     idraw++;
0349   }
0350   */
0351   if (what == "ALL" || what == "THIRD")
0352   {
0353     int retcode = DrawThird(what);
0354     if (!retcode)
0355     {
0356       isuccess++;
0357     }
0358     idraw++;
0359   }
0360   /*
0361   if (what == "ALL" || what == "FOURTH")
0362   {
0363     int retcode = DrawFourth(what);
0364     if (!retcode)
0365     {
0366       isuccess++;
0367     }
0368     idraw++;
0369   }
0370   */
0371   if (what == "ALL" || what == "FIFTH")
0372   {
0373     int retcode = DrawFifth(what);
0374     if (!retcode)
0375     {
0376       isuccess++;
0377     }
0378     idraw++;
0379   }
0380   if (what == "ALL" || what == "SIXTH")
0381   {
0382     int retcode = DrawSixth(what);
0383     if (!retcode)
0384     {
0385       isuccess++;
0386     }
0387     idraw++;
0388   }
0389   if (what == "ALL")
0390   {
0391     int retcode = DrawSeventh("SEVENTH");
0392     if (!retcode)
0393     {
0394       isuccess++;
0395     }
0396     idraw++;
0397     retcode = DrawSeventh("ALLTRIGZS");
0398     if (!retcode)
0399     {
0400       isuccess++;
0401     }
0402   }
0403   if (what == "SEVENTH" || what == "ALLTRIGZS")
0404   {
0405     int retcode = DrawSeventh(what);
0406     if (!retcode)
0407     {
0408       isuccess++;
0409     }
0410     idraw++;
0411   }
0412   if (what == "ALL" || what == "SERVERSTATS")
0413   {
0414     int retcode = DrawServerStats();
0415     if (!retcode)
0416     {
0417       isuccess++;
0418     }
0419     idraw++;
0420   }
0421   if (what == "ALL" || what == "ALLTRIGHITS")
0422   {
0423     int retcode = DrawAllTrigHits(what);
0424     if (!retcode)
0425     {
0426       isuccess++;
0427     }
0428     idraw++;
0429   }
0430   if (what == "ALL" || what == "NOISERMS")
0431   {
0432     iret += DrawNoiseRMS(what);
0433     idraw++;
0434   }
0435 
0436   if (!idraw)
0437   {
0438     std::cout << __PRETTY_FUNCTION__ << " Unimplemented Drawing option: " << what << std::endl;
0439     iret = -1;
0440   }
0441   if (!isuccess)
0442   {
0443     return iret;
0444   }
0445   else
0446   {
0447     return 0;
0448   }
0449 }
0450 
0451 int HcalMonDraw::DrawFirst(const std::string& /* what */)
0452 {
0453   OnlMonClient* cl = OnlMonClient::instance();
0454 
0455   TH2* hist1 = (TH2*) cl->getHisto(hcalmon[0], "h2_hcal_rm");
0456   TH1* h_event = cl->getHisto(hcalmon[0], "h_event");
0457 
0458   TH2* hist1_1 = (TH2*) cl->getHisto(hcalmon[1], "h2_hcal_rm");
0459   TH1* h_event_1 = cl->getHisto(hcalmon[1], "h_event");
0460 
0461   TH1* h_hcal_trig = cl->getHisto(hcalmon[0], "h_hcal_trig");
0462 
0463   if (!gROOT->FindObject("HcalMon1"))
0464   {
0465     MakeCanvas("HcalMon1");
0466   }
0467   if (!hist1 || !hist1_1 || !h_event || !h_event_1 || !h_hcal_trig)
0468   {
0469     DrawDeadServer(transparent[0]);
0470     TC[0]->SetEditable(false);
0471     if (isHtml())
0472     {
0473       delete TC[0];
0474       TC[0] = nullptr;
0475     }
0476     return -1;
0477   }
0478 
0479   hist1->Add(hist1_1);
0480   bool iscosmic = false;
0481 
0482   std::set<int> hcal_cosmic_bits = {TriggerEnum::BitCodes::RANDOM,
0483                                     TriggerEnum::BitCodes::HCAL_SINGLES,
0484                                     TriggerEnum::BitCodes::HCAL_NARROW_VERT,
0485                                     TriggerEnum::BitCodes::HCAL_WIDE_VERT,
0486                                     TriggerEnum::BitCodes::HCAL_NARROW_HORZ,
0487                                     TriggerEnum::BitCodes::HCAL_WIDE_HORZ};
0488 
0489   for (auto bit : hcal_cosmic_bits)
0490   {
0491     if (h_hcal_trig->GetBinContent(bit + 1) > 0)
0492     {
0493       iscosmic = true;
0494       break;
0495     }
0496   }
0497 
0498   if (iscosmic)
0499   {
0500     hist1->Divide(h2_mean_template_cosmic);
0501   }
0502   else
0503   {
0504     hist1->Divide(h2_mean_template);
0505   }
0506   int avgevents = h_event->GetEntries() + h_event_1->GetEntries();
0507   avgevents /= 2;
0508   // h_event->Add(h_event_1);
0509 
0510   // h2_hcal_mean->Scale(1. / h_event->GetEntries());
0511   // hist1->Divide(h2_hcal_mean);
0512 
0513   TC[0]->SetEditable(true);
0514   TC[0]->Clear("D");
0515   Pad[0]->cd();
0516 
0517   hist1->GetXaxis()->SetTitle("eta index");
0518   hist1->GetYaxis()->SetTitle("phi index");
0519   hist1->GetXaxis()->CenterTitle();
0520   hist1->GetYaxis()->CenterTitle();
0521   hist1->GetXaxis()->SetNdivisions(24);
0522   hist1->GetYaxis()->SetNdivisions(232);
0523 
0524   float tsize = 0.025;
0525   hist1->GetXaxis()->SetLabelSize(tsize);
0526   hist1->GetYaxis()->SetLabelSize(tsize);
0527   hist1->GetZaxis()->SetLabelSize(tsize);
0528   hist1->GetXaxis()->SetTitleSize(tsize);
0529   hist1->GetYaxis()->SetTitleSize(tsize);
0530   hist1->GetXaxis()->SetTickLength(0.02);
0531 
0532   hist1->GetZaxis()->SetRangeUser(0, 4);
0533 
0534   gPad->SetTopMargin(0.08);
0535   gPad->SetBottomMargin(0.07);
0536   gPad->SetLeftMargin(0.08);
0537   gPad->SetRightMargin(0.11);
0538 
0539   hist1->Draw("colz");
0540 
0541   TLine line_sector[32];
0542   for (int i_line = 0; i_line < 32; i_line++)
0543   {
0544     line_sector[i_line] = TLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
0545     line_sector[i_line].SetLineColor(1);
0546     line_sector[i_line].SetLineWidth(4);
0547     line_sector[i_line].SetLineStyle(1);
0548   }
0549   TLine line_board1(8, 0, 8, 64);
0550   line_board1.SetLineColor(1);
0551   line_board1.SetLineWidth(4);
0552   line_board1.SetLineStyle(1);
0553   TLine line_board2(16, 0, 16, 64);
0554   line_board2.SetLineColor(1);
0555   line_board2.SetLineWidth(4);
0556   line_board2.SetLineStyle(1);
0557 
0558   TLine line_iphi[64];
0559   for (int i_line = 0; i_line < 64; i_line++)
0560   {
0561     line_iphi[i_line] = TLine(0, (i_line + 1), 24, (i_line + 1));
0562     line_iphi[i_line].SetLineColor(1);
0563     line_iphi[i_line].SetLineWidth(1);
0564     line_iphi[i_line].SetLineStyle(1);
0565   }
0566   TLine line_ieta[24];
0567   for (int i_line = 0; i_line < 24; i_line++)
0568   {
0569     line_ieta[i_line] = TLine((i_line + 1), 0, (i_line + 1), 64);
0570     line_ieta[i_line].SetLineColor(1);
0571     line_ieta[i_line].SetLineWidth(1);
0572     line_ieta[i_line].SetLineStyle(1);
0573   }
0574 
0575   for (int i_line = 0; i_line < 32; i_line++)
0576   {
0577     line_sector[i_line].DrawLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
0578   }
0579 
0580   line_board1.DrawLine(8, 0, 8, 64);
0581   line_board2.DrawLine(16, 0, 16, 64);
0582 
0583   for (int i_line = 0; i_line < 64; i_line++)
0584   {
0585     line_iphi[i_line].DrawLine(0, (i_line + 1), 24, (i_line + 1));
0586   }
0587   for (int i_line = 0; i_line < 24; i_line++)
0588   {
0589     line_ieta[i_line].DrawLine((i_line + 1), 0, (i_line + 1), 64);
0590   }
0591 
0592   Int_t palette[4] = {kBlack, kBlue, 8, 2};
0593   hcalStyle->SetPalette(4, palette);
0594   gROOT->SetStyle("hcalStyle");
0595   gROOT->ForceStyle();
0596   gStyle->SetPalette(4, palette);
0597   double cold_tower_thresh = 0.75;
0598   double hot_tower_thresh = 1.5;
0599   double dead_tower_thresh = 0.01;
0600   if(iscosmic) cold_tower_thresh = 0.5;
0601   double_t levels[5] = {0, dead_tower_thresh, cold_tower_thresh, hot_tower_thresh, 4};
0602   hist1->SetContour(5, levels);
0603 
0604   FindHotTower(warning[0], hist1, true, cold_tower_thresh, hot_tower_thresh, dead_tower_thresh);
0605   TText PrintRun;
0606   PrintRun.SetTextFont(62);
0607   PrintRun.SetTextSize(0.03);
0608   PrintRun.SetNDC();          // set to normalized coordinates
0609   PrintRun.SetTextAlign(23);  // center/top alignment
0610   std::ostringstream runnostream;
0611   std::ostringstream runnostream2;
0612   std::ostringstream runnostream3;
0613   std::string runstring;
0614   std::pair<time_t, int> evttime = cl->EventTime("CURRENT");
0615   float threshold = 30;
0616   if (iscosmic)
0617   {
0618     threshold = 1000;
0619   }
0620   // fill run number and event time into string
0621   runnostream << ThisName << ": tower occupancy running mean/template";
0622   runnostream2 << " threshold: " << threshold << "ADC, Run " << cl->RunNumber() << ", Event: " << avgevents;
0623   runnostream3 << "Time: " << ctime(&evttime.first);
0624 
0625   transparent[0]->cd();
0626   runstring = runnostream.str();
0627   PrintRun.SetTextColor(evttime.second);
0628   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
0629   runstring = runnostream2.str();
0630   PrintRun.DrawText(0.5, 0.96, runstring.c_str());
0631   runstring = runnostream3.str();
0632   PrintRun.DrawText(0.5, 0.93, runstring.c_str());
0633   /*
0634   // make a TButton at bottom left to pop up a window with average ADC for all tower
0635   TButton* but1 = new TButton("Draw Template", "", 0.01, 0.01, 0.5, 0.05);
0636   but1->SetName("avgenergy");
0637   TC[0]->cd();
0638   but1->Draw();
0639   TButton* but2 = new TButton("Draw Multiplicity", "", 0.51, 0.01, 0.99, 0.05);
0640   but2->SetName("hitmap");
0641   but2->Draw();
0642   TButton* but3 = new TButton("Draw Avg. Time", "", 0.01, 0.06, 0.5, 0.1);
0643   but3->SetName("avgtime");
0644   but3->Draw();
0645   */
0646   // this connects the clicks on TCavas to the HandleEvent method that makes a pop up window
0647   // and display the running mean history of the tower correponding to the bin you click on
0648   TC[0]->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "HcalMonDraw", this,
0649                  "HandleEvent(int,int,int,TObject*)");
0650 
0651   TC[0]->Update();
0652 
0653   TC[0]->Show();
0654 
0655   TC[0]->SetEditable(false);
0656 
0657   // TC[0]->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "TCanvas", TC[0],
0658   //           "Paint()");
0659   return 0;
0660 }
0661 
0662 int HcalMonDraw::DrawAllTrigHits(const std::string& /* what */)
0663 {
0664   OnlMonClient* cl = OnlMonClient::instance();
0665 
0666   TH2* hist1 = (TH2*) cl->getHisto(hcalmon[0], "h2_hcal_rm_alltrig");
0667   TH1* h_event = cl->getHisto(hcalmon[0], "h_event");
0668 
0669   TH2* hist1_1 = (TH2*) cl->getHisto(hcalmon[1], "h2_hcal_rm_alltrig");
0670   TH1* h_event_1 = cl->getHisto(hcalmon[1], "h_event");
0671 
0672   if (!gROOT->FindObject("HcalAllTrigHits"))
0673   {
0674     MakeCanvas("HcalAllTrigHits");
0675   }
0676   if (!hist1 || !hist1_1 || !h_event || !h_event_1)
0677   {
0678     DrawDeadServer(transparent[10]);
0679     TC[10]->SetEditable(false);
0680     if (isHtml())
0681     {
0682       delete TC[10];
0683       TC[10] = nullptr;
0684     }
0685     return -1;
0686   }
0687 
0688   hist1->Add(hist1_1);
0689 
0690   int avgevents = h_event->GetEntries() + h_event_1->GetEntries();
0691   avgevents /= 2;
0692   // h_event->Add(h_event_1);
0693 
0694   // h2_hcal_mean->Scale(1. / h_event->GetEntries());
0695   // hist1->Divide(h2_hcal_mean);
0696 
0697   TC[10]->SetEditable(true);
0698   TC[10]->Clear("D");
0699   Pad[26]->cd();
0700   gStyle->SetPalette(57);
0701   gStyle->SetOptStat(0);
0702   hist1->GetXaxis()->SetTitle("eta index");
0703   hist1->GetYaxis()->SetTitle("phi index");
0704   hist1->GetXaxis()->CenterTitle();
0705   hist1->GetYaxis()->CenterTitle();
0706   hist1->GetXaxis()->SetNdivisions(24);
0707   hist1->GetYaxis()->SetNdivisions(232);
0708 
0709   float tsize = 0.025;
0710   hist1->GetXaxis()->SetLabelSize(tsize);
0711   hist1->GetYaxis()->SetLabelSize(tsize);
0712   hist1->GetZaxis()->SetLabelSize(tsize);
0713   hist1->GetXaxis()->SetTitleSize(tsize);
0714   hist1->GetYaxis()->SetTitleSize(tsize);
0715   hist1->GetXaxis()->SetTickLength(0.02);
0716 
0717   hist1->GetZaxis()->SetRangeUser(0, 0.5);
0718 
0719   gPad->SetTopMargin(0.08);
0720   gPad->SetBottomMargin(0.07);
0721   gPad->SetLeftMargin(0.08);
0722   gPad->SetRightMargin(0.11);
0723 
0724   hist1->Draw("colz");
0725 
0726   TLine line_sector[32];
0727   for (int i_line = 0; i_line < 32; i_line++)
0728   {
0729     line_sector[i_line] = TLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
0730     line_sector[i_line].SetLineColor(1);
0731     line_sector[i_line].SetLineWidth(4);
0732     line_sector[i_line].SetLineStyle(1);
0733   }
0734   TLine line_board1(8, 0, 8, 64);
0735   line_board1.SetLineColor(1);
0736   line_board1.SetLineWidth(4);
0737   line_board1.SetLineStyle(1);
0738   TLine line_board2(16, 0, 16, 64);
0739   line_board2.SetLineColor(1);
0740   line_board2.SetLineWidth(4);
0741   line_board2.SetLineStyle(1);
0742 
0743   TLine line_iphi[64];
0744   for (int i_line = 0; i_line < 64; i_line++)
0745   {
0746     line_iphi[i_line] = TLine(0, (i_line + 1), 24, (i_line + 1));
0747     line_iphi[i_line].SetLineColor(1);
0748     line_iphi[i_line].SetLineWidth(1);
0749     line_iphi[i_line].SetLineStyle(1);
0750   }
0751   TLine line_ieta[24];
0752   for (int i_line = 0; i_line < 24; i_line++)
0753   {
0754     line_ieta[i_line] = TLine((i_line + 1), 0, (i_line + 1), 64);
0755     line_ieta[i_line].SetLineColor(1);
0756     line_ieta[i_line].SetLineWidth(1);
0757     line_ieta[i_line].SetLineStyle(1);
0758   }
0759 
0760   for (int i_line = 0; i_line < 32; i_line++)
0761   {
0762     line_sector[i_line].DrawLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
0763   }
0764 
0765   line_board1.DrawLine(8, 0, 8, 64);
0766   line_board2.DrawLine(16, 0, 16, 64);
0767 
0768   for (int i_line = 0; i_line < 64; i_line++)
0769   {
0770     line_iphi[i_line].DrawLine(0, (i_line + 1), 24, (i_line + 1));
0771   }
0772   for (int i_line = 0; i_line < 24; i_line++)
0773   {
0774     line_ieta[i_line].DrawLine((i_line + 1), 0, (i_line + 1), 64);
0775   }
0776 
0777   FindHotTower(warning[2], hist1, false);
0778   TText PrintRun;
0779   PrintRun.SetTextFont(62);
0780   PrintRun.SetTextSize(0.03);
0781   PrintRun.SetNDC();          // set to normalized coordinates
0782   PrintRun.SetTextAlign(23);  // center/top alignment
0783   std::ostringstream runnostream;
0784   std::ostringstream runnostream2;
0785   std::ostringstream runnostream3;
0786   std::string runstring;
0787   std::pair<time_t, int> evttime = cl->EventTime("CURRENT");
0788   float threshold = 30;
0789   // fill run number and event time into string
0790   runnostream << ThisName << ": tower occupancy running mean with all trigger";
0791   runnostream2 << " threshold: " << threshold << "ADC, Run " << cl->RunNumber();
0792   runnostream3 << "Time: " << ctime(&evttime.first);
0793 
0794   transparent[10]->cd();
0795   runstring = runnostream.str();
0796   PrintRun.SetTextColor(evttime.second);
0797   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
0798   runstring = runnostream2.str();
0799   PrintRun.DrawText(0.5, 0.96, runstring.c_str());
0800   runstring = runnostream3.str();
0801   PrintRun.DrawText(0.5, 0.93, runstring.c_str());
0802 
0803   TC[10]->Update();
0804 
0805   TC[10]->Show();
0806 
0807   TC[10]->SetEditable(false);
0808 
0809   return 0;
0810 }
0811 int HcalMonDraw::DrawNoiseRMS(const std::string& /* what */)
0812 {
0813   // 11 27 3
0814   OnlMonClient* cl = OnlMonClient::instance();
0815   // watch the absolute insanity as we merge all these
0816   // histograms from across seven different machines
0817 
0818   if (!h2_noiserms)
0819   {
0820     h2_noiserms = new TH2D("h2_noiserms", "", 24, 0, 24, 64, 0, 64);
0821   }
0822   else
0823   {
0824     h2_noiserms->Reset();
0825   }
0826   if (!p2_noiserms)
0827   {
0828     p2_noiserms = new TProfile2D("p2_noiserms", "", 24, 0, 24, 64, 0, 64, "S");
0829   }
0830   else
0831   {
0832     p2_noiserms->Reset();
0833   }
0834 
0835   TProfile2D* hist1 = (TProfile2D*) cl->getHisto(hcalmon[0], "p2_pre_post");
0836   TProfile2D* hist1_1 = (TProfile2D*) cl->getHisto(hcalmon[1], "p2_pre_post");
0837 
0838   if (!gROOT->FindObject("HcalNoiseRMS"))
0839   {
0840     MakeCanvas("HcalNoiseRMS");
0841   }
0842 
0843   if (!hist1 || !hist1_1)
0844   {
0845     // if we do not have the histograms, we cannot draw anything
0846     // so we just draw a dead server message
0847     DrawDeadServer(transparent[11]);
0848     TC[11]->SetEditable(false);
0849     return -1;
0850   }
0851   p2_noiserms->Add(hist1);
0852   p2_noiserms->Add(hist1_1);
0853 
0854   // loop over p2_noiserms and set the error to h2_cemc_noiserms
0855   for (int i = 1; i <= p2_noiserms->GetNbinsX(); i++)
0856   {
0857     for (int j = 1; j <= p2_noiserms->GetNbinsY(); j++)
0858     {
0859       double error = p2_noiserms->GetBinError(i, j);
0860       h2_noiserms->SetBinContent(i, j, error);
0861     }
0862   }
0863 
0864   TC[11]->SetEditable(true);
0865   TC[11]->Clear("D");
0866   Pad[27]->cd();
0867 
0868   h2_noiserms->GetXaxis()->SetTitle("eta index");
0869   h2_noiserms->GetYaxis()->SetTitle("phi index");
0870   h2_noiserms->GetZaxis()->SetTitle("Tower Noise RMS with all trig");
0871   h2_noiserms->GetXaxis()->CenterTitle();
0872   h2_noiserms->GetYaxis()->CenterTitle();
0873   h2_noiserms->GetZaxis()->CenterTitle();
0874   h2_noiserms->GetXaxis()->SetNdivisions(12, kFALSE);
0875   h2_noiserms->GetYaxis()->SetNdivisions(32, kFALSE);
0876 
0877   float tsize = 0.03;
0878   h2_noiserms->GetXaxis()->SetLabelSize(tsize);
0879   h2_noiserms->GetYaxis()->SetLabelSize(tsize);
0880   h2_noiserms->GetYaxis()->SetTitleOffset(1.4);
0881   h2_noiserms->GetZaxis()->SetLabelSize(tsize);
0882   h2_noiserms->GetXaxis()->SetTitleSize(tsize);
0883   h2_noiserms->GetYaxis()->SetTitleSize(tsize);
0884   h2_noiserms->GetXaxis()->SetTickLength(0.02);
0885   h2_noiserms->GetZaxis()->SetTitleOffset(1.6);
0886 
0887   gPad->SetTopMargin(0.08);
0888   gPad->SetBottomMargin(0.07);
0889   gPad->SetLeftMargin(0.08);
0890   gPad->SetRightMargin(0.2);
0891 
0892   gStyle->SetPalette(57);
0893   h2_noiserms->GetZaxis()->SetRangeUser(0, 100);
0894 
0895   gStyle->SetOptStat(0);
0896   h2_noiserms->DrawCopy("colz");
0897   TLine line_sector[32];
0898   for (int i_line = 0; i_line < 32; i_line++)
0899   {
0900     line_sector[i_line] = TLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
0901     line_sector[i_line].SetLineColor(1);
0902     line_sector[i_line].SetLineWidth(4);
0903     line_sector[i_line].SetLineStyle(1);
0904   }
0905   TLine line_board1(8, 0, 8, 64);
0906   line_board1.SetLineColor(1);
0907   line_board1.SetLineWidth(4);
0908   line_board1.SetLineStyle(1);
0909   TLine line_board2(16, 0, 16, 64);
0910   line_board2.SetLineColor(1);
0911   line_board2.SetLineWidth(4);
0912   line_board2.SetLineStyle(1);
0913 
0914   TLine line_iphi[64];
0915   for (int i_line = 0; i_line < 64; i_line++)
0916   {
0917     line_iphi[i_line] = TLine(0, (i_line + 1), 24, (i_line + 1));
0918     line_iphi[i_line].SetLineColor(1);
0919     line_iphi[i_line].SetLineWidth(1);
0920     line_iphi[i_line].SetLineStyle(1);
0921   }
0922   TLine line_ieta[24];
0923   for (int i_line = 0; i_line < 24; i_line++)
0924   {
0925     line_ieta[i_line] = TLine((i_line + 1), 0, (i_line + 1), 64);
0926     line_ieta[i_line].SetLineColor(1);
0927     line_ieta[i_line].SetLineWidth(1);
0928     line_ieta[i_line].SetLineStyle(1);
0929   }
0930 
0931   for (int i_line = 0; i_line < 32; i_line++)
0932   {
0933     line_sector[i_line].DrawLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
0934   }
0935 
0936   line_board1.DrawLine(8, 0, 8, 64);
0937   line_board2.DrawLine(16, 0, 16, 64);
0938 
0939   for (int i_line = 0; i_line < 64; i_line++)
0940   {
0941     line_iphi[i_line].DrawLine(0, (i_line + 1), 24, (i_line + 1));
0942   }
0943   for (int i_line = 0; i_line < 24; i_line++)
0944   {
0945     line_ieta[i_line].DrawLine((i_line + 1), 0, (i_line + 1), 64);
0946   }
0947   FindGainMode(warning[3], h2_noiserms);
0948 
0949   TText PrintRun;
0950   PrintRun.SetTextFont(62);
0951   PrintRun.SetTextSize(0.03);
0952   PrintRun.SetNDC();          // set to normalized coordinates
0953   PrintRun.SetTextAlign(23);  // center/top alignment
0954   std::ostringstream runnostream;
0955   std::ostringstream runnostream2;
0956   std::ostringstream runnostream3;
0957   std::string runstring;
0958   std::pair<time_t, int> evttime = cl->EventTime("CURRENT");
0959   // fill run number and event time into string
0960   runnostream << ThisName << ": tower negative post - pre RMS all trig";
0961   runnostream2 << "Run " << cl->RunNumber();
0962   runnostream3 << "Time: " << ctime(&evttime.first);
0963 
0964   transparent[11]->cd();
0965   runstring = runnostream.str();
0966   PrintRun.SetTextColor(evttime.second);
0967   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
0968   runstring = runnostream2.str();
0969   PrintRun.DrawText(0.5, 0.96, runstring.c_str());
0970   runstring = runnostream3.str();
0971   PrintRun.DrawText(0.5, 0.93, runstring.c_str());
0972 
0973   TC[11]->Update();
0974   TC[11]->Show();
0975   TC[11]->SetEditable(false);
0976 
0977   return 0;
0978 }
0979 
0980 int HcalMonDraw::DrawSecond(const std::string& /* what */)
0981 {
0982   const int Nsector = 32;
0983   OnlMonClient* cl = OnlMonClient::instance();
0984 
0985   TH1* h_sectorAvg_total = cl->getHisto(hcalmon[0], "h_sectorAvg_total");
0986   TH1* h_event = cl->getHisto(hcalmon[0], "h_event");
0987   TH1* h_sectorAvg_total_1 = cl->getHisto(hcalmon[1], "h_sectorAvg_total");
0988   TH1* h_event_1 = cl->getHisto(hcalmon[1], "h_event");
0989   TH1* h_rm_sectorAvg[Nsector];
0990   TH1* h_rm_sectorAvg_1[Nsector];
0991   for (int ih = 0; ih < Nsector; ih++)
0992   {
0993     h_rm_sectorAvg[ih] = cl->getHisto(hcalmon[0], Form("h_rm_sectorAvg_s%d", ih));
0994     h_rm_sectorAvg_1[ih] = cl->getHisto(hcalmon[1], Form("h_rm_sectorAvg_s%d", ih));
0995     h_rm_sectorAvg[ih]->Add(h_rm_sectorAvg_1[ih]);
0996   }
0997 
0998   if (!gROOT->FindObject("HcalMon2"))
0999   {
1000     MakeCanvas("HcalMon2");
1001   }
1002 
1003   TC[1]->SetEditable(true);
1004   TC[1]->Clear("D");
1005   Pad[2]->cd();
1006   if (!h_rm_sectorAvg[0] || !h_event || !h_sectorAvg_total)
1007   {
1008     DrawDeadServer(transparent[1]);
1009     TC[1]->SetEditable(false);
1010     if (isHtml())
1011     {
1012       delete TC[1];
1013       TC[1] = nullptr;
1014     }
1015     return -1;
1016   }
1017 
1018   h_sectorAvg_total->Scale(1. / h_event->GetEntries());
1019   h_sectorAvg_total_1->Scale(1. / h_event_1->GetEntries());
1020   h_sectorAvg_total->Add(h_sectorAvg_total_1);
1021 
1022   for (int ih = 0; ih < Nsector; ih++)
1023   {
1024     h_rm_sectorAvg[ih]->Scale(1. / h_sectorAvg_total->GetBinContent(ih + 1));
1025     for (int ib = 1; ib < h_rm_sectorAvg[ih]->GetNbinsX(); ib++)
1026     {
1027       h_rm_sectorAvg[ih]->SetBinContent(ib, ih + h_rm_sectorAvg[ih]->GetBinContent(ib));
1028     }
1029   }
1030 
1031   gStyle->SetTitleFontSize(0.03);
1032 
1033   gStyle->SetOptStat(0);
1034 
1035   TH1* frame = new TH1F("frame", "", 100, 0, 100);
1036   frame->Draw("AXIS");
1037   frame->GetXaxis()->SetTitle("time");
1038   frame->GetYaxis()->SetTitle("sector running mean / template + sector #");
1039   frame->GetXaxis()->CenterTitle();
1040   frame->GetYaxis()->CenterTitle();
1041   // frame->GetXaxis()->SetNdivisions(20);
1042   // frame->GetYaxis()->SetNdivisions(232);
1043   float tsize = 0.03;
1044   frame->GetXaxis()->SetLabelSize(tsize);
1045   frame->GetYaxis()->SetLabelSize(tsize);
1046   frame->GetXaxis()->SetTitleSize(tsize);
1047   frame->GetYaxis()->SetTitleSize(tsize);
1048 
1049   frame->GetXaxis()->SetRangeUser(0, 100);
1050   frame->GetYaxis()->SetRangeUser(0, 32.75);
1051 
1052   gPad->SetTickx();
1053   gPad->SetTicky();
1054   gPad->SetTopMargin(0.01);
1055 
1056   for (auto& ih : h_rm_sectorAvg)
1057   {
1058     ih->Draw("same hist ][");
1059   }
1060 
1061   TText PrintRun;
1062   PrintRun.SetTextFont(62);
1063   PrintRun.SetTextSize(0.03);
1064   PrintRun.SetNDC();          // set to normalized coordinates
1065   PrintRun.SetTextAlign(23);  // center/top alignment
1066   std::ostringstream runnostream;
1067   std::string runstring;
1068   std::pair<time_t, int> evttime = cl->EventTime("CURRENT");
1069   // fill run number and event time into string
1070   runnostream << ThisName << "_running mean, Run" << cl->RunNumber()
1071               << ", Time: " << ctime(&evttime.first);
1072   runstring = runnostream.str();
1073   transparent[1]->cd();
1074   PrintRun.SetTextColor(evttime.second);
1075   PrintRun.DrawText(0.5, 1., runstring.c_str());
1076   TC[1]->Update();
1077   TC[1]->Show();
1078   TC[1]->SetEditable(false);
1079   return 0;
1080 }
1081 
1082 int HcalMonDraw::DrawThird(const std::string& /* what */)
1083 {
1084   OnlMonClient* cl = OnlMonClient::instance();
1085 
1086   // TH1* h_waveform_twrAvg =  cl->getHisto(hcalmon0, "h_waveform_twrAvg");
1087   TH1* h_waveform_time = cl->getHisto(hcalmon[0], "h_waveform_time");
1088   TH1* h_waveform_pedestal = cl->getHisto(hcalmon[0], "h_waveform_pedestal");
1089   TH2* h2_hcal_waveform = (TH2*) cl->getHisto(hcalmon[0], "h2_hcal_waveform");
1090   // TH1* hwaveform_twrAvg_1 =  cl->getHisto(hcalmon[1], "h_waveform_twrAvg");
1091   TH1* hwaveform_time_1 = cl->getHisto(hcalmon[1], "h_waveform_time");
1092   TH1* hwaveform_pedestal_1 = cl->getHisto(hcalmon[1], "h_waveform_pedestal");
1093   TH2* h2_hcal_waveform_1 = (TH2*) cl->getHisto(hcalmon[1], "h2_hcal_waveform");
1094 
1095   if (!gROOT->FindObject("HcalMon3"))
1096   {
1097     MakeCanvas("HcalMon3");
1098   }
1099 
1100   TC[3]->SetEditable(true);
1101   TC[3]->Clear("D");
1102   Pad[6]->cd();
1103   if (!h2_hcal_waveform || !h_waveform_time || !h_waveform_pedestal)
1104   {
1105     DrawDeadServer(transparent[3]);
1106     TC[3]->SetEditable(false);
1107     if (isHtml())
1108     {
1109       delete TC[3];
1110       TC[3] = nullptr;
1111     }
1112     return -1;
1113   }
1114 
1115   // h_waveform_twrAvg->Add(hwaveform_twrAvg_1);
1116   h_waveform_time->Add(hwaveform_time_1);
1117   h_waveform_pedestal->Add(hwaveform_pedestal_1);
1118   h2_hcal_waveform->Add(h2_hcal_waveform_1);
1119 
1120   // Tprofie of h2_hcal_waveform
1121   float ymaxp = h2_hcal_waveform->ProfileX()->GetMaximum();
1122   /*
1123   TProfile* profile_y = h2_hcal_waveform->ProfileY();
1124   profile_y->Rebin(5);
1125 
1126     // Define the range
1127     double x_min = 100;
1128     double x_max = 7 * ymaxp;
1129     int n_points_in_range = 0;
1130     // Loop through the bins of the Profile Y histogram and count the bins within the range
1131     int n_bins = profile_y->GetNbinsX();
1132     for (int i = 1; i <= n_bins; ++i) {
1133         double bin_center = profile_y->GetBinCenter(i);
1134         if (profile_y->GetBinContent(i) == 0) {
1135             continue;
1136         }
1137         if (bin_center >= x_min && bin_center <= x_max) {
1138             n_points_in_range++;
1139         }
1140     }
1141 
1142     double* x_vals = new double[n_points_in_range];
1143     double* y_vals = new double[n_points_in_range];
1144 
1145     // Extract the Profile Y values and their corresponding Y positions within the range
1146     int point_index = 0;
1147     for (int i = 1; i <= n_bins; ++i) {
1148         double bin_center = profile_y->GetBinCenter(i);
1149         if (profile_y->GetBinContent(i) == 0) {
1150             continue;
1151         }
1152         if (bin_center >= x_min && bin_center <= x_max) {
1153             y_vals[point_index] = bin_center;
1154             x_vals[point_index] = profile_y->GetBinContent(i);
1155             point_index++;
1156         }
1157     }
1158 */
1159 
1160   Pad[6]->cd();
1161   gStyle->SetTitleFontSize(0.03);
1162 
1163   h2_hcal_waveform->GetYaxis()->SetRangeUser(0, ymaxp * 20);
1164 
1165   h2_hcal_waveform->Draw("colz");
1166 
1167   float tsize = 0.06;
1168   h2_hcal_waveform->GetXaxis()->SetNdivisions(510, kTRUE);
1169   h2_hcal_waveform->GetXaxis()->SetRangeUser(0, 16);
1170   h2_hcal_waveform->GetXaxis()->SetTitle("Sample #");
1171   h2_hcal_waveform->GetYaxis()->SetTitle("Waveform [ADC]");
1172   h2_hcal_waveform->GetXaxis()->SetLabelSize(tsize);
1173   h2_hcal_waveform->GetYaxis()->SetLabelSize(tsize);
1174   h2_hcal_waveform->GetXaxis()->SetTitleSize(tsize);
1175   h2_hcal_waveform->GetYaxis()->SetTitleSize(tsize);
1176   h2_hcal_waveform->GetXaxis()->SetTitleOffset(1.2);
1177   h2_hcal_waveform->GetYaxis()->SetTitleOffset(0.85);
1178   // over lay the profile draw only the marker
1179   /*
1180   TGraph* graph = new TGraph(n_points_in_range, x_vals, y_vals);
1181   graph->SetMarkerStyle(20);
1182   graph->SetMarkerSize(1);
1183   graph->SetMarkerColor(1);
1184   graph->Draw("P same");
1185   */
1186   // draw two black lines for the okay timing range
1187   TLine line1(4.5, 0, 4.5, ymaxp * 20);
1188   line1.SetLineColor(1);
1189   line1.SetLineWidth(3);
1190   line1.SetLineStyle(1);
1191   line1.DrawLine(4.5, 0, 4.5, ymaxp * 20);
1192 
1193   TLine line2(7.5, 0, 7.5, ymaxp * 20);
1194   line2.SetLineColor(1);
1195   line2.SetLineWidth(3);
1196   line2.SetLineStyle(1);
1197   line2.DrawLine(7.5, 0, 7.5, ymaxp * 20);
1198 
1199   gPad->SetLogz();
1200   gPad->SetTopMargin(0.06);
1201   gPad->SetBottomMargin(0.18);
1202   gPad->SetRightMargin(0.05);
1203   gPad->SetLeftMargin(0.15);
1204   gStyle->SetOptStat(0);
1205   gStyle->SetPalette(57);
1206   gPad->SetTicky();
1207   gPad->SetTickx();
1208 
1209   TText PrintRun;
1210   PrintRun.SetTextFont(62);
1211   PrintRun.SetTextSize(0.03);
1212   PrintRun.SetNDC();          // set to normalized coordinates
1213   PrintRun.SetTextAlign(23);  // center/top alignment
1214   std::ostringstream runnostream;
1215   std::ostringstream runnostream2;
1216   std::string runstring;
1217   std::string runstring2;
1218   std::pair<time_t, int> evttime = cl->EventTime("CURRENT");
1219   // fill run number and event time into string
1220   runnostream << ThisName << ": Pulse fitting, Run" << cl->RunNumber();
1221   runnostream2 << ", Time: " << ctime(&evttime.first);
1222   runstring = runnostream.str();
1223   runstring2 = runnostream2.str();
1224   transparent[3]->cd();
1225   PrintRun.SetTextColor(evttime.second);
1226   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
1227   PrintRun.DrawText(0.5, 0.96, runstring2.c_str());
1228 
1229   Pad[7]->cd();
1230 
1231   gStyle->SetTitleFontSize(0.06);
1232 
1233   float tsize2 = 0.08;
1234   h_waveform_time->Draw("hist");
1235   h_waveform_time->GetXaxis()->SetNdivisions(510, kTRUE);
1236   h_waveform_time->GetXaxis()->SetRangeUser(0, 16);
1237   h_waveform_time->GetXaxis()->SetTitle("Sample #");
1238   h_waveform_time->GetYaxis()->SetTitle("Fraction of Towers");
1239   h_waveform_time->GetXaxis()->SetLabelSize(tsize2);
1240   h_waveform_time->GetYaxis()->SetLabelSize(tsize2);
1241   h_waveform_time->GetXaxis()->SetTitleSize(tsize2);
1242   h_waveform_time->GetYaxis()->SetTitleSize(tsize2);
1243   h_waveform_time->GetXaxis()->SetTitleOffset(1.0);
1244   h_waveform_time->GetYaxis()->SetTitleOffset(0.85);
1245   h_waveform_time->SetFillColorAlpha(kBlue, 0.1);
1246   if (h_waveform_time->GetEntries())
1247   {
1248     h_waveform_time->Scale(1. / h_waveform_time->GetEntries());
1249   }
1250   gPad->Update();
1251   // draw two black lines for the okay timing range
1252   TLine line3(4.5, 0, 4.5, gPad->GetFrame()->GetY2());
1253   line3.SetLineColor(1);
1254   line3.SetLineWidth(3);
1255   line3.SetLineStyle(1);
1256   line3.DrawLine(4.5, 0, 4.5, gPad->GetFrame()->GetY2());
1257 
1258   TLine line4(7.5, 0, 7.5, gPad->GetFrame()->GetY2());
1259   line4.SetLineColor(1);
1260   line4.SetLineWidth(3);
1261   line4.SetLineStyle(1);
1262   line4.DrawLine(7.5, 0, 7.5, gPad->GetFrame()->GetY2());
1263 
1264   // Draw a red line at mean x
1265   TLine line5(h_waveform_time->GetMean(), 0, h_waveform_time->GetMean(), gPad->GetFrame()->GetY2());
1266   line5.SetLineColor(2);
1267   line5.SetLineWidth(3);
1268   line5.SetLineStyle(1);
1269   line5.DrawLine(h_waveform_time->GetMean(), 0, h_waveform_time->GetMean(), gPad->GetFrame()->GetY2());
1270 
1271   gPad->SetTopMargin(0.06);
1272   gPad->SetBottomMargin(0.18);
1273   gPad->SetRightMargin(0.05);
1274   gPad->SetLeftMargin(0.15);
1275   gStyle->SetOptStat(0);
1276   gPad->SetTicky();
1277   gPad->SetTickx();
1278 
1279   Pad[8]->cd();
1280 
1281   gStyle->SetTitleFontSize(0.06);
1282 
1283   h_waveform_pedestal->Draw("hist");
1284   h_waveform_pedestal->GetXaxis()->SetNdivisions(505, kTRUE);
1285   h_waveform_pedestal->GetXaxis()->SetTitle("ADC Pedestal");
1286   h_waveform_pedestal->GetYaxis()->SetTitle("Fraction of Towers");
1287   h_waveform_pedestal->GetXaxis()->SetLabelSize(tsize2);
1288   h_waveform_pedestal->GetYaxis()->SetLabelSize(tsize2);
1289   h_waveform_pedestal->GetXaxis()->SetTitleSize(tsize2);
1290   h_waveform_pedestal->GetYaxis()->SetTitleSize(tsize2);
1291   h_waveform_pedestal->GetXaxis()->SetTitleOffset(0.9);
1292   h_waveform_pedestal->GetYaxis()->SetTitleOffset(0.85);
1293   h_waveform_pedestal->SetFillColorAlpha(kBlue, 0.1);
1294   if (h_waveform_pedestal->GetEntries())
1295   {
1296     h_waveform_pedestal->Scale(1. / h_waveform_pedestal->GetEntries());
1297   }
1298   gPad->Update();
1299   TLine line6(1000, 0, 1000, gPad->GetFrame()->GetY2());
1300   line6.SetLineColor(1);
1301   line6.SetLineWidth(3);
1302   line6.SetLineStyle(1);
1303   line6.DrawLine(1000, 0, 1000, gPad->GetFrame()->GetY2());
1304 
1305   TLine line7(2000, 0, 2000, gPad->GetFrame()->GetY2());
1306   line7.SetLineColor(1);
1307   line7.SetLineWidth(3);
1308   line7.SetLineStyle(1);
1309   line7.DrawLine(2000, 0, 2000, gPad->GetFrame()->GetY2());
1310 
1311   gPad->SetTopMargin(0.06);
1312   gPad->SetBottomMargin(0.18);
1313   gPad->SetRightMargin(0.05);
1314   gPad->SetLeftMargin(0.15);
1315   gPad->SetLogy();
1316   gStyle->SetOptStat(0);
1317   gPad->SetTicky();
1318   gPad->SetTickx();
1319 
1320   TC[3]->Update();
1321   TC[3]->Show();
1322   TC[3]->SetEditable(false);
1323 
1324   return 0;
1325 }
1326 
1327 int HcalMonDraw::DrawFourth(const std::string& /* what */)
1328 {
1329   OnlMonClient* cl = OnlMonClient::instance();
1330 
1331   TH1* h1_packet_number = cl->getHisto(hcalmon[0], "h1_packet_number");
1332   TH1* h1_packet_length = cl->getHisto(hcalmon[0], "h1_packet_length");
1333   TH1* h1_packet_chans = cl->getHisto(hcalmon[0], "h1_packet_chans");
1334   TH1* h1_packet_event = cl->getHisto(hcalmon[0], "h1_packet_event");
1335   TH1* h_event = cl->getHisto(hcalmon[0], "h_event");
1336   TH2* h2_hcal_correlation = (TH2*) cl->getHisto(hcalmon[0], "h2_hcal_correlation");
1337 
1338   TH1* h1_packet_number_1 = cl->getHisto(hcalmon[1], "h1_packet_number");
1339   TH1* h1_packet_length_1 = cl->getHisto(hcalmon[1], "h1_packet_length");
1340   TH1* h1_packet_chans_1 = cl->getHisto(hcalmon[1], "h1_packet_chans");
1341   TH1* h1_packet_event_1 = cl->getHisto(hcalmon[1], "h1_packet_event");
1342   TH2* h2_hcal_correlation_1 = (TH2*) cl->getHisto(hcalmon[1], "h2_hcal_correlation");
1343   TH1* h_event_1 = cl->getHisto(hcalmon[1], "h_event");
1344 
1345   if (!gROOT->FindObject("HcalMon4"))
1346   {
1347     MakeCanvas("HcalMon4");
1348   }
1349 
1350   TC[5]->SetEditable(true);
1351   TC[5]->Clear("D");
1352 
1353   if (!h1_packet_number || !h1_packet_length || !h1_packet_chans || !h_event || !h1_packet_event || !h2_hcal_correlation)
1354   {
1355     // print out which is not found
1356     if (!h1_packet_number)
1357     {
1358       std::cout << "h1_packet_number not found" << std::endl;
1359     }
1360     if (!h1_packet_length)
1361     {
1362       std::cout << "h1_packet_length not found" << std::endl;
1363     }
1364     if (!h1_packet_chans)
1365     {
1366       std::cout << "h1_packet_chans not found" << std::endl;
1367     }
1368     if (!h_event)
1369     {
1370       std::cout << "h_event not found" << std::endl;
1371     }
1372     if (!h1_packet_event)
1373     {
1374       std::cout << "h1_packet_event not found" << std::endl;
1375     }
1376     if (!h2_hcal_correlation)
1377     {
1378       std::cout << "h2_hcal_correlation not found" << std::endl;
1379     }
1380 
1381     DrawDeadServer(transparent[5]);
1382     TC[5]->SetEditable(false);
1383     if (isHtml())
1384     {
1385       delete TC[5];
1386       TC[5] = nullptr;
1387     }
1388     return -1;
1389   }
1390   // h1_packet_number->Scale(1. / h_event->GetEntries());
1391   // h1_packet_length->Scale(1. / h_event->GetEntries());
1392   // h1_packet_chans->Scale(1. / h_event->GetEntries());
1393 
1394   // h1_packet_number_1->Scale(1. / h_event_1->GetEntries());
1395   // h1_packet_length_1->Scale(1. / h_event_1->GetEntries());
1396   // h1_packet_chans_1->Scale(1. / h_event_1->GetEntries());
1397 
1398   h1_packet_number->Add(h1_packet_number_1);
1399   h1_packet_length->Add(h1_packet_length_1);
1400   h1_packet_chans->Add(h1_packet_chans_1);
1401 
1402   // int maxbin = h1_packet_event->GetMaximumBin();
1403   int maxy = h1_packet_event->GetMaximum();
1404   // substract all none zero bin by maxy
1405   for (int i = 1; i <= h1_packet_event->GetNbinsX(); i++)
1406   {
1407     if (h1_packet_event->GetBinContent(i) != 0)
1408     {
1409       h1_packet_event->SetBinContent(i, h1_packet_event->GetBinContent(i) - maxy);
1410     }
1411   }
1412   int maxy1 = h1_packet_event_1->GetMaximum();
1413   for (int i = 1; i <= h1_packet_event_1->GetNbinsX(); i++)
1414   {
1415     if (h1_packet_event_1->GetBinContent(i) != 0)
1416     {
1417       h1_packet_event_1->SetBinContent(i, h1_packet_event_1->GetBinContent(i) - maxy1);
1418     }
1419   }
1420 
1421   /*
1422     if (maxbin < 3|| maxbin > 6){
1423     //substract bin 1,2 ,7 8 by maxy
1424     h1_packet_event->SetBinContent(1, h1_packet_event->GetBinContent(1) - maxy);
1425     h1_packet_event->SetBinContent(2, h1_packet_event->GetBinContent(2) - maxy);
1426     h1_packet_event->SetBinContent(7, h1_packet_event->GetBinContent(7) - maxy);
1427     h1_packet_event->SetBinContent(8, h1_packet_event->GetBinContent(8) - maxy);
1428 
1429     h1_packet_event_1->SetBinContent(3, h1_packet_event_1->GetBinContent(3) - maxy1);
1430     h1_packet_event_1->SetBinContent(4, h1_packet_event_1->GetBinContent(4) - maxy1);
1431     h1_packet_event_1->SetBinContent(5, h1_packet_event_1->GetBinContent(5) - maxy1);
1432     h1_packet_event_1->SetBinContent(6, h1_packet_event_1->GetBinContent(6) - maxy1);
1433     }
1434     else{
1435     //substract bin 3,4,5,6 by maxy
1436     h1_packet_event->SetBinContent(3, h1_packet_event->GetBinContent(3) - maxy);
1437     h1_packet_event->SetBinContent(4, h1_packet_event->GetBinContent(4) - maxy);
1438     h1_packet_event->SetBinContent(5, h1_packet_event->GetBinContent(5) - maxy);
1439     h1_packet_event->SetBinContent(6, h1_packet_event->GetBinContent(6) - maxy);
1440 
1441     h1_packet_event_1->SetBinContent(1, h1_packet_event_1->GetBinContent(1) - maxy1);
1442     h1_packet_event_1->SetBinContent(2, h1_packet_event_1->GetBinContent(2) - maxy1);
1443     h1_packet_event_1->SetBinContent(7, h1_packet_event_1->GetBinContent(7) - maxy1);
1444     h1_packet_event_1->SetBinContent(8, h1_packet_event_1->GetBinContent(8) - maxy1);
1445     }
1446   */
1447   h1_packet_event->Add(h1_packet_event_1);
1448 
1449   // find the x range for h1_packet_number
1450   double xmin = h1_packet_number->GetXaxis()->GetXmin();
1451   double xmax = h1_packet_number->GetXaxis()->GetXmax();
1452 
1453   TLine one(xmin, 1, xmax, 1);
1454   one.SetLineStyle(7);
1455   one.DrawLine(xmin, 1, xmax, 1);
1456 
1457   TLine goodSize(xmin, 5981, xmax, 5981);
1458   goodSize.SetLineStyle(7);
1459   goodSize.DrawLine(xmin, 5981, xmax, 5981);
1460 
1461   TLine goodChans(xmin, 192, xmax, 192);
1462   goodChans.SetLineStyle(7);
1463   goodChans.DrawLine(xmin, 192, xmax, 192);
1464 
1465   // float param = 0.75;
1466   float param = 0.95;
1467 
1468   TLegend* leg = new TLegend(0.3, 0.16, 0.95, 0.4);
1469   leg->SetFillStyle(0);
1470   leg->SetBorderSize(0);
1471 
1472   TLine warnLineOne(xmin, param * 1, xmax, param * 1);
1473   warnLineOne.SetLineStyle(7);
1474   warnLineOne.SetLineColor(2);
1475   warnLineOne.DrawLine(xmin, param * 1, xmax, param * 1);
1476 
1477   leg->AddEntry(&warnLineOne, "95% Threshold", "l");
1478 
1479   TLine warnLineSize(xmin, param * 5981., xmax, param * 5981.);
1480   warnLineSize.SetLineStyle(7);
1481   warnLineSize.SetLineColor(2);
1482   warnLineSize.DrawLine(xmin, param * 5981., xmax, param * 5981.);
1483 
1484   TLine warnLineChans(xmin, param * 192., xmax, param * 192.);
1485   warnLineChans.SetLineStyle(7);
1486   warnLineChans.SetLineColor(2);
1487   warnLineChans.DrawLine(xmin, param * 192., xmax, param * 192.);
1488 
1489   Pad[10]->cd();
1490   float tsize = 0.08;
1491   h1_packet_number->GetYaxis()->SetRangeUser(0.0, 1.3);
1492   h1_packet_number->Draw("hist");
1493   // std::vector<std::vector<int>> badPackets;
1494   // badPackets.push_back(getBadPackets(h1_packet_number, 0, param));
1495   // one->Draw("same");
1496   // warnLineOne->Draw("same");
1497   h1_packet_number->GetXaxis()->SetNdivisions(510, kTRUE);
1498   h1_packet_number->GetXaxis()->SetTitle("Packet #");
1499   h1_packet_number->GetYaxis()->SetTitle("% Of Events Present");
1500   h1_packet_number->GetXaxis()->SetLabelSize(tsize - 0.01);
1501   h1_packet_number->GetYaxis()->SetLabelSize(tsize - 0.01);
1502   h1_packet_number->GetXaxis()->SetTitleSize(tsize - 0.01);
1503   h1_packet_number->GetYaxis()->SetTitleSize(tsize - 0.01);
1504   h1_packet_number->GetXaxis()->SetTitleOffset(1);
1505   gPad->SetBottomMargin(0.16);
1506   gPad->SetLeftMargin(0.16);
1507   gPad->SetRightMargin(0.05);
1508   gPad->SetLeftMargin(0.15);
1509   gStyle->SetOptStat(0);
1510   gPad->SetTicky();
1511   gPad->SetTickx();
1512 
1513   Pad[11]->cd();
1514   h1_packet_length->Draw("hist");
1515   h1_packet_length->GetYaxis()->SetRangeUser(0, 6500);
1516   // badPackets.push_back(getBadPackets(h1_packet_length, 1, param));
1517   // goodSize->Draw("same");
1518   // warnLineSize->Draw("same");
1519   leg->Draw("same");
1520   h1_packet_length->GetXaxis()->SetNdivisions(510, kTRUE);
1521   h1_packet_length->GetXaxis()->SetTitle("Packet #");
1522   h1_packet_length->GetYaxis()->SetTitle("Average Packet Size");
1523   h1_packet_length->GetXaxis()->SetLabelSize(tsize - .01);
1524   h1_packet_length->GetYaxis()->SetLabelSize(tsize);
1525   h1_packet_length->GetXaxis()->SetTitleSize(tsize - .01);
1526   h1_packet_length->GetYaxis()->SetTitleSize(tsize);
1527   h1_packet_length->GetXaxis()->SetTitleOffset(1);
1528   h1_packet_length->GetYaxis()->SetTitleOffset(0.8);
1529   gPad->SetBottomMargin(0.16);
1530   gPad->SetLeftMargin(0.16);
1531   gPad->SetRightMargin(0.05);
1532   gPad->SetLeftMargin(0.15);
1533   gStyle->SetOptStat(0);
1534   gPad->SetTicky();
1535   gPad->SetTickx();
1536 
1537   Pad[12]->cd();
1538   h1_packet_chans->Draw("hist");
1539   h1_packet_chans->GetYaxis()->SetRangeUser(0, 212);
1540   // badPackets.push_back(getBadPackets(h1_packet_chans, 2, param));
1541   // goodChans->Draw("same");
1542   // warnLineChans->Draw("same");
1543   h1_packet_chans->GetXaxis()->SetNdivisions(510, kTRUE);
1544   h1_packet_chans->GetXaxis()->SetTitle("Packet #");
1545   h1_packet_chans->GetYaxis()->SetTitle("Average # of Channels");
1546   h1_packet_chans->GetXaxis()->SetLabelSize(tsize - .01);
1547   h1_packet_chans->GetYaxis()->SetLabelSize(tsize);
1548   h1_packet_chans->GetXaxis()->SetTitleSize(tsize - .01);
1549   h1_packet_chans->GetYaxis()->SetTitleSize(tsize);
1550   h1_packet_chans->GetXaxis()->SetTitleOffset(0.8);
1551   h1_packet_chans->GetYaxis()->SetTitleOffset(0.8);
1552   gPad->SetBottomMargin(0.16);
1553   gPad->SetLeftMargin(0.16);
1554   gPad->SetRightMargin(0.05);
1555   gPad->SetLeftMargin(0.15);
1556   gStyle->SetOptStat(0);
1557   gPad->SetTicky();
1558   gPad->SetTickx();
1559 
1560   Pad[13]->cd();
1561   h1_packet_event->Draw("hist");
1562   double ymax = h1_packet_event->GetMaximum();
1563   double ymin = h1_packet_event->GetMinimum();
1564 
1565   h1_packet_event->GetYaxis()->SetRangeUser(ymin - 0.3 * (ymax - ymin + 30), ymax + 0.3 * (ymax - ymin + 30));
1566   h1_packet_event->GetXaxis()->SetTitle("Packet #");
1567   h1_packet_event->GetYaxis()->SetTitle("clock offset");
1568   h1_packet_event->GetXaxis()->SetLabelSize(tsize - .01);
1569   h1_packet_event->GetYaxis()->SetLabelSize(tsize);
1570   h1_packet_event->GetXaxis()->SetTitleSize(tsize - .01);
1571   h1_packet_event->GetYaxis()->SetTitleSize(tsize);
1572   h1_packet_event->GetXaxis()->SetTitleOffset(0.8);
1573   h1_packet_event->GetYaxis()->SetTitleOffset(1.2);
1574   gPad->SetBottomMargin(0.16);
1575   gPad->SetLeftMargin(0.2);
1576   gPad->SetRightMargin(0.05);
1577   gPad->SetLeftMargin(0.2);
1578   gStyle->SetOptStat(0);
1579   gPad->SetTicky();
1580   gPad->SetTickx();
1581 
1582   Pad[14]->cd();
1583   h2_hcal_correlation->Draw("colz");
1584   ymax = h2_hcal_correlation->ProfileX()->GetMaximum();
1585   xmax = h2_hcal_correlation->ProfileY()->GetMaximum();
1586   h2_hcal_correlation->GetYaxis()->SetRangeUser(0, ymax * 1.2);
1587   h2_hcal_correlation->GetXaxis()->SetRangeUser(0, xmax * 1.2);
1588   h2_hcal_correlation->GetXaxis()->SetNdivisions(510, kTRUE);
1589   h2_hcal_correlation->GetYaxis()->SetNdivisions(510, kTRUE);
1590   h2_hcal_correlation->GetXaxis()->SetTitle("Total West OHCal Energy[a.u.]");
1591   h2_hcal_correlation->GetYaxis()->SetTitle("Total West IHCal Energy[a.u.]");
1592   h2_hcal_correlation->GetXaxis()->SetLabelSize(0);
1593   h2_hcal_correlation->GetYaxis()->SetLabelSize(0);
1594   h2_hcal_correlation->GetXaxis()->SetTitleSize(tsize - .02);
1595   h2_hcal_correlation->GetYaxis()->SetTitleSize(tsize - .02);
1596   h2_hcal_correlation->GetXaxis()->SetTitleOffset(0.8);
1597   h2_hcal_correlation->GetYaxis()->SetTitleOffset(0.8);
1598   gPad->SetBottomMargin(0.16);
1599   gPad->SetLeftMargin(0.2);
1600   gPad->SetRightMargin(0.03);
1601   gPad->SetLeftMargin(0.2);
1602   gStyle->SetOptStat(0);
1603   gPad->SetTicky();
1604   gPad->SetTickx();
1605 
1606   Pad[15]->cd();
1607   h2_hcal_correlation_1->Draw("colz");
1608   ymax = h2_hcal_correlation_1->ProfileX()->GetMaximum();
1609   xmax = h2_hcal_correlation_1->ProfileY()->GetMaximum();
1610   h2_hcal_correlation_1->GetYaxis()->SetRangeUser(0, ymax * 1.2);
1611   h2_hcal_correlation_1->GetXaxis()->SetRangeUser(0, xmax * 1.2);
1612   h2_hcal_correlation_1->GetXaxis()->SetNdivisions(510, kTRUE);
1613   h2_hcal_correlation_1->GetYaxis()->SetNdivisions(510, kTRUE);
1614   h2_hcal_correlation_1->GetXaxis()->SetTitle("Total East OHCal Energy[a.u.]");
1615   h2_hcal_correlation_1->GetYaxis()->SetTitle("Total East IHCal Energy[a.u.]");
1616   h2_hcal_correlation_1->GetXaxis()->SetLabelSize(0);
1617   h2_hcal_correlation_1->GetYaxis()->SetLabelSize(0);
1618   h2_hcal_correlation_1->GetXaxis()->SetTitleSize(tsize - .02);
1619   h2_hcal_correlation_1->GetYaxis()->SetTitleSize(tsize - .02);
1620   h2_hcal_correlation_1->GetXaxis()->SetTitleOffset(0.8);
1621   h2_hcal_correlation_1->GetYaxis()->SetTitleOffset(0.8);
1622   gPad->SetBottomMargin(0.16);
1623   gPad->SetLeftMargin(0.2);
1624   gPad->SetRightMargin(0.05);
1625   gPad->SetLeftMargin(0.2);
1626   gStyle->SetOptStat(0);
1627   gPad->SetTicky();
1628   gPad->SetTickx();
1629 
1630   // draw the warning here:
1631   warning[1]->cd();
1632   std::vector<int> badPackets;
1633   std::vector<std::string> whatswrong;
1634   for (int i = 1; i <= 8; i++)
1635   {
1636     bool missing = false;
1637     bool badnumber = false;
1638     bool badlength = false;
1639     bool badchans = false;
1640     if (h1_packet_number->GetBinContent(i) == 0)
1641     {
1642       missing = true;
1643     }
1644     if (h1_packet_number->GetBinContent(i) < param)
1645     {
1646       badnumber = true;
1647     }
1648     if (h1_packet_length->GetBinContent(i) < param * 5981.)
1649     {
1650       badlength = true;
1651     }
1652     if (h1_packet_chans->GetBinContent(i) < param * 192.)
1653     {
1654       badchans = true;
1655     }
1656     if (badnumber || badlength || badchans || missing)
1657     {
1658       badPackets.push_back((int) h1_packet_number->GetBinCenter(i));
1659       std::string reason = "";
1660       if (missing)
1661       {
1662         reason += "packet lost! ";
1663       }
1664       else
1665       {
1666         if (badnumber)
1667         {
1668           reason += "some events are missing, ";
1669         }
1670         if (badlength)
1671         {
1672           reason += "too short, ";
1673         }
1674         if (badchans)
1675         {
1676           reason += "too few channels, ";
1677         }
1678         // remove the last two characters
1679         reason.resize(reason.size() - 2);
1680         reason += ".";
1681       }
1682       whatswrong.push_back(reason);
1683     }
1684   }
1685   bool westmismatch = false;
1686   bool eastmismatch = false;
1687   for (int i = 1; i <= h1_packet_event->GetNbinsX(); i++)
1688   {
1689     if (h1_packet_event->GetBinContent(i) != 0)
1690     {
1691       if (i < 3 || i > 6)
1692       {
1693         westmismatch = true;
1694       }
1695       else
1696       {
1697         eastmismatch = true;
1698       }
1699     }
1700   }
1701   // draw the mismatch warning on the pad
1702   TText mismatchWarn;
1703   mismatchWarn.SetTextFont(62);
1704   mismatchWarn.SetTextSize(0.06);
1705   mismatchWarn.SetTextColor(2);
1706   mismatchWarn.SetNDC();
1707   mismatchWarn.SetTextAlign(23);
1708   if (westmismatch)
1709   {
1710     mismatchWarn.DrawText(0.5, 0.95, "West misaligned!");
1711   }
1712   if (eastmismatch)
1713   {
1714     mismatchWarn.DrawText(0.5, 0.9, "East misaligned!");
1715   }
1716   mismatchWarn.SetTextColor(1);
1717   mismatchWarn.SetTextSize(0.05);
1718   if (westmismatch || eastmismatch)
1719   {
1720     // mismatchWarn.DrawText(0.5, 0.7, "Restart the run and see if this persists.");
1721     //  draw a line for seperation
1722     TLine* line = new TLine(0., 0.8, 1., 0.8);
1723     line->SetLineColor(1);
1724     line->SetLineStyle(1);
1725     line->SetLineWidth(10);
1726     line->Draw("same");
1727   }
1728 
1729   // draw the bad packet warning here
1730   TText PacketWarn;
1731   PacketWarn.SetTextFont(62);
1732   PacketWarn.SetTextSize(0.04);
1733   PacketWarn.SetTextColor(1);
1734   PacketWarn.SetNDC();
1735   PacketWarn.SetTextAlign(23);
1736   PacketWarn.DrawText(0.5, 0.75, "Bad Packets:");
1737   for (int i = 0; i < (int) badPackets.size(); i++)
1738   {
1739     PacketWarn.DrawText(0.5, 0.7 - 0.05 * i, Form("%i: %s", badPackets[i], whatswrong[i].c_str()));
1740   }
1741   if ((int) badPackets.size() > 0 && (h_event->GetEntries() > 1000 || h_event_1->GetEntries() > 1000))
1742   {
1743     PacketWarn.SetTextSize(0.04);
1744     PacketWarn.DrawText(0.5, 0.7 - 0.05 * (int) badPackets.size(), "Check with HCal experts.");
1745   }
1746   TText PrintRun;
1747   PrintRun.SetTextFont(62);
1748   PrintRun.SetTextSize(0.02);
1749   PrintRun.SetNDC();          // set to normalized coordinates
1750   PrintRun.SetTextAlign(23);  // center/top alignment
1751   std::ostringstream runnostream;
1752   std::string runstring;
1753   std::ostringstream runnostream2;
1754   std::pair<time_t, int> evttime = cl->EventTime("CURRENT");
1755   // fill run number and event time into string
1756 
1757   runnostream << "Packet Information";
1758   runnostream2 << " Run " << cl->RunNumber() << ", Time: " << ctime(&evttime.first);
1759   transparent[5]->cd();
1760 
1761   runstring = runnostream.str();
1762   PrintRun.SetTextColor(evttime.second);
1763   PrintRun.DrawText(0.5, .99, runstring.c_str());
1764 
1765   runstring = runnostream2.str();
1766   PrintRun.DrawText(0.5, .966, runstring.c_str());
1767   TC[5]->Update();
1768   TC[5]->Show();
1769   TC[5]->SetEditable(false);
1770   // if (save) TC[5]->SaveAs("plots/packets.pdf");
1771   return 0;
1772 }
1773 int HcalMonDraw::FindGainMode(TPad* warningpad, TH2* hhit)
1774 {
1775   float avgrms = 0;
1776   float totaltowers = 0;
1777   int nTowersEta = hhit->GetNbinsX();
1778   int nTowersPhi = hhit->GetNbinsY();
1779   for (int ieta = 0; ieta < nTowersEta; ieta++)
1780   {
1781     for (int iphi = 0; iphi < nTowersPhi; iphi++)
1782     {
1783       if (hhit->GetBinContent(ieta + 1, iphi + 1) == 0)
1784       {
1785         continue;
1786       }
1787       double rms = hhit->GetBinContent(ieta + 1, iphi + 1);
1788       avgrms += rms;
1789       totaltowers += 1;
1790     }
1791   }
1792   avgrms /= totaltowers;
1793 
1794   bool hg = false;
1795   if (avgrms > 20)
1796   {
1797     hg = true;
1798   }
1799 
1800   warningpad->cd();
1801   std::string gainmode = "Gain mode: LOW";
1802   if (hg)
1803   {
1804     gainmode = "Gain mode: HIGH";
1805   }
1806 
1807   TText warn;
1808   warn.SetTextFont(62);
1809   warn.SetTextSize(0.3);
1810   warn.SetTextColor(kRed);
1811   warn.SetNDC();
1812   warn.SetTextAlign(23);
1813   warn.DrawText(0.5, 0.5, gainmode.c_str());
1814 
1815   warn.SetTextFont(62);
1816   warn.SetTextSize(0.06);
1817   warn.SetTextColor(1);
1818   warn.SetNDC();
1819   warn.SetTextAlign(23);
1820   warn.DrawText(0.5, 0.9, "Average RMS of pedestal:");
1821   warn.DrawText(0.5, 0.8, Form("%.2f", avgrms));
1822 
1823   warningpad->Update();
1824   return 0;
1825 }
1826 int HcalMonDraw::FindHotTower(TPad* warningpad, TH2* hhit, bool usetemplate, float cold_threshold, float hot_threshold, float dead_threshold)
1827 {
1828   float nhott = 0;
1829   float ndeadt = 0;
1830   float ncoldt = 0;
1831   int displaylimit = 10;
1832   std::ostringstream hottowerlist;
1833   std::ostringstream deadtowerlist;
1834   std::ostringstream coldtowerlist;
1835   //float hot_threshold = hot_threshold;
1836   //float dead_threshold = dead_threshold;
1837   //float cold_threshold = cold_threshold;
1838   if (!usetemplate)
1839   {
1840     // loop over histogram to find mean and rms
1841     double mean = 0;
1842     double rms = 0;
1843     double n = 0;
1844     for (int ieta = 0; ieta < 24; ieta++)
1845     {
1846       for (int iphi = 0; iphi < 64; iphi++)
1847       {
1848         double nhit = hhit->GetBinContent(ieta + 1, iphi + 1);
1849         if (hhit->GetBinContent(ieta + 1, iphi + 1) != 0)
1850         {
1851           mean += nhit;
1852           rms += nhit * nhit;
1853           n++;
1854         }
1855       }
1856     }
1857     mean /= n;
1858     rms = sqrt(rms / n - mean * mean);
1859     hot_threshold = mean + 10 * rms;
1860     cold_threshold = mean - 3 * rms;
1861     dead_threshold = 0.01 * mean;
1862   }
1863   for (int ieta = 0; ieta < 24; ieta++)
1864   {
1865     for (int iphi = 0; iphi < 64; iphi++)
1866     {
1867       double nhit = hhit->GetBinContent(ieta + 1, iphi + 1);
1868 
1869       if (nhit > hot_threshold)
1870       {
1871         if (nhott <= displaylimit)
1872         {
1873           hottowerlist << " (" << ieta << "," << iphi << ")";
1874         }
1875         nhott++;
1876       }
1877 
1878       if (nhit < dead_threshold)
1879       {
1880         if (ndeadt <= displaylimit)
1881         {
1882           deadtowerlist << " (" << ieta << "," << iphi << ")";
1883         }
1884         ndeadt++;
1885       }
1886       else if (nhit < cold_threshold)
1887       {
1888         if (ncoldt <= displaylimit)
1889         {
1890           coldtowerlist << " (" << ieta << "," << iphi << ")";
1891         }
1892         ncoldt++;
1893       }
1894     }
1895   }
1896 
1897   if (nhott > displaylimit)
1898   {
1899     hottowerlist << "... " << nhott << " total";
1900   }
1901   if (ndeadt > displaylimit)
1902   {
1903     deadtowerlist << "... " << ndeadt << " total";
1904   }
1905   if (ncoldt > displaylimit)
1906   {
1907     coldtowerlist << "... " << ncoldt << " total";
1908   }
1909   if (nhott == 0)
1910   {
1911     hottowerlist << " None";
1912   }
1913   if (ndeadt == 0)
1914   {
1915     deadtowerlist << " None";
1916   }
1917   if (ncoldt == 0)
1918   {
1919     coldtowerlist << " None";
1920   }
1921 
1922   // draw warning here
1923   warningpad->cd();
1924   TText Warn;
1925   Warn.SetTextFont(62);
1926   Warn.SetTextSize(0.06);
1927   Warn.SetTextColor(2);
1928   Warn.SetNDC();
1929   Warn.SetTextAlign(23);
1930   Warn.DrawText(0.5, 0.9, "Hot towers (ieta,iphi):");
1931   Warn.DrawText(0.5, 0.8, hottowerlist.str().c_str());
1932 
1933   Warn.SetTextColor(1);
1934   Warn.SetTextAlign(23);
1935   Warn.DrawText(0.5, 0.5, "Dead towers (ieta,iphi):");
1936   Warn.DrawText(0.5, 0.4, deadtowerlist.str().c_str());
1937 
1938   Warn.SetTextColor(4);
1939   Warn.SetTextAlign(23);
1940   Warn.DrawText(0.5, 0.7, "Cold towers (ieta,iphi):");
1941   Warn.DrawText(0.5, 0.6, coldtowerlist.str().c_str());
1942 
1943   warningpad->Update();
1944   return 0;
1945 }
1946 
1947 // int HcalMonDraw::DrawSecond(const std::string & /* what */)
1948 /*
1949   {
1950   OnlMonClient *cl = OnlMonClient::instance();
1951   TH2* hist1 = (TH2*)cl->getHisto("h2_hcal_rm");
1952 
1953   if (!gROOT->FindObject("HcalMon2"))
1954   {
1955   MakeCanvas("HcalMon2");
1956   }
1957 
1958 
1959   TC[1]->SetEditable(1);
1960   TC[1]->Clear("D");
1961   Pad[2]->cd();
1962   if (!hist1)
1963   {
1964   DrawDeadServer(transparent[1]);
1965   TC[1]->SetEditable(0);
1966   if (isHtml())
1967   {
1968   delete TC[1];
1969   TC[1] = nullptr;
1970   }
1971   return -1;
1972   }
1973 
1974 
1975 
1976   gStyle->SetTitleFontSize(0.03);
1977 
1978   gStyle->SetOptStat(0);
1979   gStyle->SetPalette(57);
1980 
1981 
1982   hist1->GetXaxis()->SetTitle("ieta");
1983   hist1->GetYaxis()->SetTitle("iphi");
1984   hist1->GetXaxis()->SetTitleSize(0.025);
1985   hist1->GetYaxis()->SetTitleSize(0.025);
1986   hist1->GetXaxis()->CenterTitle();
1987   hist1->GetYaxis()->CenterTitle();
1988   hist1->GetXaxis()->SetNdivisions(24);
1989   hist1->GetYaxis()->SetNdivisions(232);
1990   hist1->GetXaxis()->SetLabelSize(0.02);
1991   hist1->GetYaxis()->SetLabelSize(0.02);
1992   hist1->GetZaxis()->SetLabelSize(0.018);
1993 
1994 
1995   TLine *line_sector[32];
1996   for(int i_line=0;i_line<32;i_line++)
1997   {
1998   line_sector[i_line] = new TLine(0,(i_line+1)*2,24,(i_line+1)*2);
1999   line_sector[i_line]->SetLineColor(1);
2000   line_sector[i_line]->SetLineWidth(1.2);
2001   line_sector[i_line]->SetLineStyle(1);
2002   }
2003   TLine *line_board1 = new TLine(8,0,8,64);
2004   line_board1->SetLineColor(1);
2005   line_board1->SetLineWidth(1.2);
2006   line_board1->SetLineStyle(1);
2007   TLine *line_board2 = new TLine(16,0,16,64);
2008   line_board2->SetLineColor(1);
2009   line_board2->SetLineWidth(1.2);
2010   line_board2->SetLineStyle(1);
2011 
2012   gPad->SetTopMargin(0.04);
2013   gPad->SetBottomMargin(0.06);
2014   gPad->SetLeftMargin(0.06);
2015   gPad->SetRightMargin(0.11);
2016   gPad->SetTickx();
2017   gPad->SetTicky();
2018 
2019   hist1->Draw("colz");
2020   for(int i_line=0;i_line<32;i_line++)
2021   {
2022   line_sector[i_line]->Draw();
2023   }
2024   line_board1->Draw();
2025   line_board2->Draw();
2026 
2027   TText PrintRun;
2028   PrintRun.SetTextFont(62);
2029   PrintRun.SetTextSize(0.03);
2030   PrintRun.SetNDC();          // set to normalized coordinates
2031   PrintRun.SetTextAlign(23);  // center/top alignment
2032   std::ostringstream runnostream;
2033   std::string runstring;
2034   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
2035   // fill run number and event time into string
2036   runnostream << ThisName << "_running mean, Run" << cl->RunNumber()
2037   << ", Time: " << ctime(&evttime.first);
2038   runstring = runnostream.str();
2039   transparent[1]->cd();
2040   PrintRun.SetTextColor(evttime.second);
2041   PrintRun.DrawText(0.5, 1., runstring.c_str());
2042   TC[1]->Update();
2043   TC[1]->Show();
2044   TC[1]->SetEditable(0);
2045   return 0;
2046   }
2047 */
2048 
2049 int HcalMonDraw::SavePlot(const std::string& what, const std::string& type)
2050 {
2051   OnlMonClient* cl = OnlMonClient::instance();
2052   int iret = Draw(what);
2053   if (iret)  // on error no png files please
2054   {
2055     return iret;
2056   }
2057   int icnt = 0;
2058   for (TCanvas* canvas : TC)
2059   {
2060     if (canvas == nullptr)
2061     {
2062       continue;
2063     }
2064     icnt++;
2065     std::string filename = ThisName + "_" + std::to_string(icnt) + "_" +
2066                            std::to_string(cl->RunNumber()) + "." + type;
2067     cl->CanvasToPng(canvas, filename);
2068   }
2069   return 0;
2070 }
2071 
2072 int HcalMonDraw::MakeHtml(const std::string& what)
2073 {
2074   int iret = Draw(what);
2075   if (iret)  // on error no html output please
2076   {
2077     return iret;
2078   }
2079 
2080   OnlMonClient* cl = OnlMonClient::instance();
2081   int icnt = 0;
2082   for (TCanvas* canvas : TC)
2083   {
2084     if (canvas == nullptr)
2085     {
2086       continue;
2087     }
2088     icnt++;
2089     // Register the canvas png file to the menu and produces the png file.
2090     std::string pngfile = cl->htmlRegisterPage(*this, canvas->GetTitle(), std::to_string(icnt), "png");
2091     cl->CanvasToPng(canvas, pngfile);
2092   }
2093 
2094   // Now register also EXPERTS html pages, under the EXPERTS subfolder.
2095 
2096   // std::string logfile = cl->htmlRegisterPage(*this, "EXPERTS/Log", "log", "html");
2097   // std::ofstream out(logfile.c_str());
2098   // out << "<HTML><HEAD><TITLE>Log file for run " << cl->RunNumber()
2099   //     << "</TITLE></HEAD>" << std::endl;
2100   // out << "<P>Some log file output would go here." << std::endl;
2101   // out.close();
2102 
2103   // std::string status = cl->htmlRegisterPage(*this, "EXPERTS/Status", "status", "html");
2104   // std::ofstream out2(status.c_str());
2105   // out2 << "<HTML><HEAD><TITLE>Status file for run " << cl->RunNumber()
2106   //      << "</TITLE></HEAD>" << std::endl;
2107   // out2 << "<P>Some status output would go here." << std::endl;
2108   // out2.close();
2109   // cl->SaveLogFile(*this);
2110   return 0;
2111 }
2112 
2113 // this is a method that draw the tower average energy
2114 void HcalMonDraw::DrawTowerAvg()
2115 {
2116   OnlMonClient* cl = OnlMonClient::instance();
2117 
2118   TH2* h2_hcal_mean = (TH2*) cl->getHisto(hcalmon[0], "h2_hcal_mean");
2119   // TH1* h_event =  cl->getHisto(hcalmon[0], "h_event");
2120   // TH2* h2_hcal_mean_1 = (TH2*) cl->getHisto(hcalmon[1], "h2_hcal_mean");
2121   // TH1* h_event_1 =  cl->getHisto(hcalmon[1], "h_event");
2122 
2123   if (!gROOT->FindObject("HcalPopUp"))
2124   {
2125     MakeCanvas("HcalPopUp");
2126   }
2127   if (!h2_hcal_mean)
2128   {
2129     DrawDeadServer(transparent[4]);
2130     TC[4]->SetEditable(false);
2131     if (isHtml())
2132     {
2133       delete TC[4];
2134       TC[4] = nullptr;
2135     }
2136     return;
2137   }
2138 
2139   // h2_hcal_mean->Scale(1. / h_event->GetEntries());
2140   // h2_hcal_mean_1->Scale(1. / h_event_1->GetEntries());
2141   // h2_hcal_mean->Add(h2_hcal_mean_1);
2142 
2143   TC[4]->SetEditable(true);
2144   TC[4]->Clear("D");
2145   Pad[9]->cd();
2146 
2147   // gPad->SetLogz();
2148   gStyle->SetOptStat(0);
2149   gStyle->SetPalette(57);
2150   h2_hcal_mean->GetXaxis()->SetTitle("eta index");
2151   h2_hcal_mean->GetYaxis()->SetTitle("phi index");
2152   h2_hcal_mean->SetTitle("Tower Average Energy[ADC]");
2153   h2_hcal_mean->Draw("COLZ");
2154   // lines
2155   TLine* line_sector[32];
2156   for (int i_line = 0; i_line < 32; i_line++)
2157   {
2158     line_sector[i_line] = new TLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
2159     line_sector[i_line]->SetLineColor(1);
2160     line_sector[i_line]->SetLineWidth(4);
2161     line_sector[i_line]->SetLineStyle(1);
2162   }
2163   TLine* line_board1 = new TLine(8, 0, 8, 64);
2164   line_board1->SetLineColor(1);
2165   line_board1->SetLineWidth(4);
2166   line_board1->SetLineStyle(1);
2167   TLine* line_board2 = new TLine(16, 0, 16, 64);
2168   line_board2->SetLineColor(1);
2169   line_board2->SetLineWidth(4);
2170   line_board2->SetLineStyle(1);
2171 
2172   for (auto& i_line : line_sector)
2173   {
2174     i_line->Draw();
2175   }
2176   line_board1->Draw();
2177   line_board2->Draw();
2178 
2179   TC[4]->Update();
2180   TC[4]->Show();
2181   TC[4]->SetEditable(false);
2182 }
2183 
2184 // this is a method that draw the tower hit map
2185 void HcalMonDraw::DrawHitMap()
2186 {
2187   OnlMonClient* cl = OnlMonClient::instance();
2188 
2189   TH2* h2_hcal_hits = (TH2*) cl->getHisto(hcalmon[0], "h2_hcal_hits");
2190 
2191   if (!gROOT->FindObject("HcalPopUp"))
2192   {
2193     MakeCanvas("HcalPopUp");
2194   }
2195   if (!h2_hcal_hits)
2196   {
2197     DrawDeadServer(transparent[4]);
2198     TC[4]->SetEditable(false);
2199     if (isHtml())
2200     {
2201       delete TC[4];
2202       TC[4] = nullptr;
2203     }
2204     return;
2205   }
2206 
2207   TC[4]->SetEditable(true);
2208   TC[4]->Clear("D");
2209   Pad[9]->cd();
2210   gPad->SetLogz(0);
2211   gStyle->SetOptStat(0);
2212   gStyle->SetPalette(57);
2213   h2_hcal_hits->GetXaxis()->SetTitle("eta index");
2214   h2_hcal_hits->GetYaxis()->SetTitle("phi index");
2215   h2_hcal_hits->SetTitle("Average Multiplicity");
2216   h2_hcal_hits->Draw("COLZ");
2217   // lines
2218   TLine* line_sector[32];
2219   for (int i_line = 0; i_line < 32; i_line++)
2220   {
2221     line_sector[i_line] = new TLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
2222     line_sector[i_line]->SetLineColor(1);
2223     line_sector[i_line]->SetLineWidth(4);
2224     line_sector[i_line]->SetLineStyle(1);
2225   }
2226   TLine* line_board1 = new TLine(8, 0, 8, 64);
2227   line_board1->SetLineColor(1);
2228   line_board1->SetLineWidth(4);
2229   line_board1->SetLineStyle(1);
2230   TLine* line_board2 = new TLine(16, 0, 16, 64);
2231   line_board2->SetLineColor(1);
2232   line_board2->SetLineWidth(4);
2233   line_board2->SetLineStyle(1);
2234 
2235   for (auto& i_line : line_sector)
2236   {
2237     i_line->Draw();
2238   }
2239   line_board1->Draw();
2240   line_board2->Draw();
2241   TC[4]->Update();
2242   TC[4]->Show();
2243   TC[4]->SetEditable(false);
2244 }
2245 
2246 void HcalMonDraw::DrawAvgTime()
2247 {
2248   OnlMonClient* cl = OnlMonClient::instance();
2249 
2250   TH2* h2_hcal_time = (TH2*) cl->getHisto(hcalmon[0], "h2_hcal_time");
2251 
2252   if (!gROOT->FindObject("HcalPopUp"))
2253   {
2254     MakeCanvas("HcalPopUp");
2255   }
2256   if (!h2_hcal_time)
2257   {
2258     DrawDeadServer(transparent[4]);
2259     TC[4]->SetEditable(false);
2260     return;
2261   }
2262 
2263   TC[4]->SetEditable(true);
2264   TC[4]->Clear("D");
2265   Pad[9]->cd();
2266   gPad->SetLogz(0);
2267   gStyle->SetOptStat(0);
2268   gStyle->SetPalette(57);
2269   h2_hcal_time->GetXaxis()->SetTitle("eta index");
2270   h2_hcal_time->GetYaxis()->SetTitle("phi index");
2271   h2_hcal_time->SetTitle("Average Time[samples]");
2272   h2_hcal_time->Draw("COLZ");
2273   // lines
2274   TLine* line_sector[32];
2275   for (int i_line = 0; i_line < 32; i_line++)
2276   {
2277     line_sector[i_line] = new TLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
2278     line_sector[i_line]->SetLineColor(1);
2279     line_sector[i_line]->SetLineWidth(4);
2280     line_sector[i_line]->SetLineStyle(1);
2281   }
2282   TLine* line_board1 = new TLine(8, 0, 8, 64);
2283   line_board1->SetLineColor(1);
2284   line_board1->SetLineWidth(4);
2285   line_board1->SetLineStyle(1);
2286   TLine* line_board2 = new TLine(16, 0, 16, 64);
2287   line_board2->SetLineColor(1);
2288   line_board2->SetLineWidth(4);
2289   line_board2->SetLineStyle(1);
2290 
2291   for (auto& i_line : line_sector)
2292   {
2293     i_line->Draw();
2294   }
2295   line_board1->Draw();
2296   line_board2->Draw();
2297   TC[4]->Update();
2298   TC[4]->Show();
2299   TC[4]->SetEditable(false);
2300 }
2301 
2302 // this is the method to idetify which bin you are clicking on and make the pop up window of TH1
2303 void HcalMonDraw::HandleEvent(int event, int x, int y, TObject* selected)
2304 {
2305   if (event == 1)
2306   {
2307     // printf("Canvas %s: event=%d, x=%d, y=%d, selected=%s\n", "a",
2308     //        event, x, y, selected->IsA()->GetName());
2309     // std::cout << "selected->GetName()=" << selected->GetName() << std::endl;
2310 
2311     if (strcmp(selected->GetName(), "avgenergy") == 0)
2312     {
2313       DrawTowerAvg();
2314       return;
2315     }
2316     if (strcmp(selected->GetName(), "hitmap") == 0)
2317     {
2318       DrawHitMap();
2319       return;
2320     }
2321     // avg time
2322     if (strcmp(selected->GetName(), "avgtime") == 0)
2323     {
2324       DrawAvgTime();
2325       return;
2326     }
2327 
2328     double xx = Pad[0]->AbsPixeltoX(x);
2329     double xhis = Pad[0]->PadtoX(xx);
2330     int binx = (int) xhis;
2331     double yy = Pad[0]->AbsPixeltoY(y);
2332     double yhis = Pad[0]->PadtoY(yy);
2333     int biny = (int) yhis;
2334     // printf("ieta=%d, iphi=%d \n", binx, biny);
2335     if (binx < 0 || binx > 23)
2336     {
2337       return;
2338     }
2339     if (biny < 0 || biny > 63)
2340     {
2341       return;
2342     }
2343 
2344     OnlMonClient* cl = OnlMonClient::instance();
2345 
2346     TH1* h_rm_tower = cl->getHisto(hcalmon[0], Form("h_rm_tower_%d_%d", binx, biny));
2347     TH1* h_rm_tower_1 = cl->getHisto(hcalmon[1], Form("h_rm_tower_%d_%d", binx, biny));
2348     if (!gROOT->FindObject("HcalPopUp"))
2349     {
2350       MakeCanvas("HcalPopUp");
2351     }
2352 
2353     if (!h_rm_tower || !h_rm_tower_1)
2354     {
2355       DrawDeadServer(transparent[4]);
2356       TC[4]->SetEditable(false);
2357       return;
2358     }
2359     h_rm_tower->Add(h_rm_tower_1);
2360     h_rm_tower->SetXTitle("Time");
2361     h_rm_tower->SetYTitle("Running Mean");
2362 
2363     TC[4]->SetEditable(true);
2364     TC[4]->Clear("D");
2365     Pad[9]->cd();
2366     gStyle->SetOptStat(0);
2367     h_rm_tower->Draw();
2368     TC[4]->Update();
2369     TC[4]->Show();
2370     TC[4]->SetEditable(false);
2371   }
2372 }
2373 
2374 int HcalMonDraw::DrawFifth(const std::string& /* what */)
2375 {
2376   OnlMonClient* cl = OnlMonClient::instance();
2377 
2378   TH2* h2_hcal_hist_trig[64];
2379   TH2* h2_hcal_hist_trig_1[64];
2380 
2381   if (!gROOT->FindObject("HcalMon5"))
2382   {
2383     MakeCanvas("HcalMon5");
2384   }
2385   for (int itrig = 0; itrig < 64; itrig++)
2386   {
2387     h2_hcal_hist_trig[itrig] = (TH2*) cl->getHisto(hcalmon[0], Form("h2_hcal_hits_trig_%d", itrig));
2388     h2_hcal_hist_trig_1[itrig] = (TH2*) cl->getHisto(hcalmon[1], Form("h2_hcal_hits_trig_%d", itrig));
2389     if (!h2_hcal_hist_trig[itrig] || !h2_hcal_hist_trig_1[itrig])
2390     {
2391       DrawDeadServer(transparent[6]);
2392       TC[6]->SetEditable(false);
2393       if (isHtml())
2394       {
2395         delete TC[6];
2396         TC[6] = nullptr;
2397       }
2398       return -1;
2399     }
2400     h2_hcal_hist_trig[itrig]->Add(h2_hcal_hist_trig_1[itrig]);
2401   }
2402 
2403   TH2* h2_hcal_hits = (TH2*) cl->getHisto(hcalmon[0], "h2_hcal_hits");
2404   TH2* h_evtRec = (TH2*) cl->getHisto(hcalmon[0], "h_evtRec");
2405   TH1* h_hcal_trig = cl->getHisto(hcalmon[0], "h_hcal_trig");
2406 
2407   TC[6]->SetEditable(true);
2408   TC[6]->Clear("D");
2409   Pad[16]->cd();
2410   if (!h2_hcal_hits || !h_hcal_trig || !h_evtRec)
2411   {
2412     DrawDeadServer(transparent[6]);
2413     TC[6]->SetEditable(false);
2414     if (isHtml())
2415     {
2416       delete TC[6];
2417       TC[6] = nullptr;
2418     }
2419     return -1;
2420   }
2421 
2422   // vector of pairs (Number of entries, Trigger bit)
2423   std::vector<std::pair<float, int>> n_entries;
2424 
2425   for (int i = 0; i < 64; i++)
2426   {
2427     n_entries.push_back(std::make_pair(h2_hcal_hist_trig[i]->GetEntries(), i));
2428   }
2429 
2430   // Sort it in ascending order of entries
2431   std::sort(n_entries.begin(), n_entries.end());
2432   // Reverse it to get the vector in descending order
2433   std::reverse(n_entries.begin(), n_entries.end());
2434 
2435   // Get the 4 priority trigger bits to be displayed
2436   std::vector<int> priority_triggers;
2437 
2438   // these are jet triggers which aren't available in 2025 -- tanner
2439   // for (int itrig = 0; itrig < 64; itrig++)
2440   // {
2441   //   // Priority to the bits between 16 and 23, don't need to plot photon trigger
2442   //   if (n_entries[itrig].second >= 16 && n_entries[itrig].second <= 23)
2443   //   {
2444   //     if (n_entries[itrig].first > 0. && priority_triggers.size() < 4)
2445   //     {
2446   //       priority_triggers.push_back(n_entries[itrig].second);
2447   //     }
2448   //   }
2449   // }
2450 
2451   // If trigger bits from 16 to 23 do not have 4 with entries, plot the others
2452   if (priority_triggers.size() < 4)
2453   {
2454     for (int itrig = 0; itrig < 64; itrig++)
2455     {
2456       if (priority_triggers.size() < 4 && n_entries[itrig].second < TriggerEnum::BitCodes::MBD_NS1_ZVRTX10)  // < 15 ( last non-photon trigger)
2457       {
2458         priority_triggers.push_back(n_entries[itrig].second);
2459       }
2460     }
2461   }
2462 
2463   Pad[16]->cd();
2464   gStyle->SetTitleFontSize(0.03);
2465 
2466   float tsize = 0.06;
2467   h2_hcal_hist_trig[priority_triggers[0]]->Draw("colz");
2468   h2_hcal_hist_trig[priority_triggers[0]]->GetXaxis()->SetNdivisions(510, kTRUE);
2469   h2_hcal_hist_trig[priority_triggers[0]]->GetXaxis()->SetTitle(Form("(trigger bit %d)  ieta", priority_triggers[0]));
2470   h2_hcal_hist_trig[priority_triggers[0]]->GetYaxis()->SetTitle("iphi");
2471   h2_hcal_hist_trig[priority_triggers[0]]->GetXaxis()->SetLabelSize(tsize);
2472   h2_hcal_hist_trig[priority_triggers[0]]->GetYaxis()->SetLabelSize(tsize);
2473   h2_hcal_hist_trig[priority_triggers[0]]->GetXaxis()->SetTitleSize(tsize);
2474   h2_hcal_hist_trig[priority_triggers[0]]->GetYaxis()->SetTitleSize(tsize);
2475   h2_hcal_hist_trig[priority_triggers[0]]->GetXaxis()->SetTitleOffset(1.2);
2476   h2_hcal_hist_trig[priority_triggers[0]]->GetYaxis()->SetTitleOffset(0.75);
2477   gPad->SetLogz();
2478   gPad->SetBottomMargin(0.16);
2479   gPad->SetLeftMargin(0.2);
2480   gPad->SetRightMargin(0.05);
2481   gPad->SetLeftMargin(0.15);
2482   gStyle->SetOptStat(0);
2483   gStyle->SetPalette(57);
2484   gPad->SetTicky();
2485   gPad->SetTickx();
2486 
2487   TText PrintRun;
2488   PrintRun.SetTextFont(62);
2489   PrintRun.SetTextSize(0.03);
2490   PrintRun.SetNDC();          // set to normalized coordinates
2491   PrintRun.SetTextAlign(23);  // center/top alignment
2492   std::ostringstream runnostream;
2493   std::string runstring;
2494   std::pair<time_t, int> evttime = cl->EventTime("CURRENT");
2495   // fill run number and event time into string
2496   runnostream << ThisName << ": Pulse fitting, Run" << cl->RunNumber()
2497               << ", Time: " << ctime(&evttime.first);
2498   runstring = runnostream.str();
2499   transparent[6]->cd();
2500   PrintRun.SetTextColor(evttime.second);
2501   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
2502 
2503   Pad[17]->cd();
2504   gStyle->SetTitleFontSize(0.06);
2505 
2506   float tsize2 = 0.06;
2507   h2_hcal_hist_trig[priority_triggers[1]]->Draw("colz");
2508   h2_hcal_hist_trig[priority_triggers[1]]->GetXaxis()->SetNdivisions(510, kTRUE);
2509   h2_hcal_hist_trig[priority_triggers[1]]->GetXaxis()->SetTitle(Form("(trigger bit %d)  ieta", priority_triggers[1]));
2510   h2_hcal_hist_trig[priority_triggers[1]]->GetYaxis()->SetTitle("iphi");
2511   h2_hcal_hist_trig[priority_triggers[1]]->GetXaxis()->SetLabelSize(tsize2);
2512   h2_hcal_hist_trig[priority_triggers[1]]->GetYaxis()->SetLabelSize(tsize2);
2513   h2_hcal_hist_trig[priority_triggers[1]]->GetXaxis()->SetTitleSize(tsize2);
2514   h2_hcal_hist_trig[priority_triggers[1]]->GetYaxis()->SetTitleSize(tsize2);
2515   h2_hcal_hist_trig[priority_triggers[1]]->GetXaxis()->SetTitleOffset(1.0);
2516   h2_hcal_hist_trig[priority_triggers[1]]->GetYaxis()->SetTitleOffset(0.85);
2517   gPad->SetTopMargin(0.06);
2518   gPad->SetBottomMargin(0.18);
2519   gPad->SetRightMargin(0.05);
2520   gPad->SetLeftMargin(0.2);
2521   gStyle->SetOptStat(0);
2522   gPad->SetTicky();
2523   gPad->SetTickx();
2524 
2525   Pad[19]->cd();
2526   gStyle->SetTitleFontSize(0.06);
2527 
2528   h2_hcal_hist_trig[priority_triggers[2]]->Draw("colz");
2529   h2_hcal_hist_trig[priority_triggers[2]]->GetXaxis()->SetNdivisions(510, kTRUE);
2530   h2_hcal_hist_trig[priority_triggers[2]]->GetXaxis()->SetTitle(Form("(trigger bit %d)  ieta", priority_triggers[2]));
2531   h2_hcal_hist_trig[priority_triggers[2]]->GetYaxis()->SetTitle("iphi");
2532   h2_hcal_hist_trig[priority_triggers[2]]->GetXaxis()->SetLabelSize(tsize2);
2533   h2_hcal_hist_trig[priority_triggers[2]]->GetYaxis()->SetLabelSize(tsize2);
2534   h2_hcal_hist_trig[priority_triggers[2]]->GetXaxis()->SetTitleSize(tsize2);
2535   h2_hcal_hist_trig[priority_triggers[2]]->GetYaxis()->SetTitleSize(tsize2);
2536   h2_hcal_hist_trig[priority_triggers[2]]->GetXaxis()->SetTitleOffset(1.0);
2537   h2_hcal_hist_trig[priority_triggers[2]]->GetYaxis()->SetTitleOffset(0.85);
2538 
2539   gPad->SetTopMargin(0.06);
2540   gPad->SetBottomMargin(0.18);
2541   gPad->SetRightMargin(0.05);
2542   gPad->SetLeftMargin(0.2);
2543   gStyle->SetOptStat(0);
2544   gPad->SetTicky();
2545   gPad->SetTickx();
2546 
2547   Pad[20]->cd();
2548   gStyle->SetTitleFontSize(0.06);
2549 
2550   h2_hcal_hist_trig[priority_triggers[3]]->Draw("colz");
2551   h2_hcal_hist_trig[priority_triggers[3]]->GetXaxis()->SetNdivisions(510, kTRUE);
2552   h2_hcal_hist_trig[priority_triggers[3]]->GetXaxis()->SetTitle(Form("(trigger bit %d)  ieta", priority_triggers[3]));
2553   h2_hcal_hist_trig[priority_triggers[3]]->GetYaxis()->SetTitle("iphi");
2554   h2_hcal_hist_trig[priority_triggers[3]]->GetXaxis()->SetLabelSize(tsize2);
2555   h2_hcal_hist_trig[priority_triggers[3]]->GetYaxis()->SetLabelSize(tsize2);
2556   h2_hcal_hist_trig[priority_triggers[3]]->GetXaxis()->SetTitleSize(tsize2);
2557   h2_hcal_hist_trig[priority_triggers[3]]->GetYaxis()->SetTitleSize(tsize2);
2558   h2_hcal_hist_trig[priority_triggers[3]]->GetXaxis()->SetTitleOffset(1.0);
2559   h2_hcal_hist_trig[priority_triggers[3]]->GetYaxis()->SetTitleOffset(0.85);
2560 
2561   gPad->SetTopMargin(0.06);
2562   gPad->SetBottomMargin(0.18);
2563   gPad->SetRightMargin(0.2);
2564   gPad->SetLeftMargin(0.2);
2565   gStyle->SetOptStat(0);
2566   gPad->SetTicky();
2567   gPad->SetTickx();
2568 
2569   Pad[18]->cd();
2570   gStyle->SetTitleFontSize(0.06);
2571 
2572   h_hcal_trig->SetTitle(Form("Receiving %0.3f of events from event receiver", h_evtRec->GetBinContent(1)));
2573   tsize2 = 0.1;
2574   h_hcal_trig->Draw("hist");
2575   h_hcal_trig->GetXaxis()->SetNdivisions(510, kTRUE);
2576   h_hcal_trig->GetXaxis()->SetTitle("trigger index");
2577   h_hcal_trig->GetYaxis()->SetTitle("events");
2578   h_hcal_trig->GetXaxis()->SetLabelSize(tsize2);
2579   h_hcal_trig->GetYaxis()->SetLabelSize(tsize2);
2580   h_hcal_trig->GetXaxis()->SetTitleSize(tsize2);
2581   h_hcal_trig->GetYaxis()->SetTitleSize(tsize2);
2582   h_hcal_trig->GetXaxis()->SetTitleOffset(0.9);
2583   h_hcal_trig->GetYaxis()->SetTitleOffset(0.85);
2584   gPad->SetTopMargin(0.06);
2585   gPad->SetBottomMargin(0.18);
2586   gPad->SetRightMargin(0.05);
2587   gPad->SetLeftMargin(0.2);
2588   gStyle->SetOptStat(0);
2589   gPad->SetTicky();
2590   gPad->SetTickx();
2591 
2592   TC[6]->Update();
2593   TC[6]->Show();
2594   TC[6]->SetEditable(false);
2595 
2596   return 0;
2597 }
2598 
2599 int HcalMonDraw::DrawSixth(const std::string& /* what */)
2600 {
2601   OnlMonClient* cl = OnlMonClient::instance();
2602 
2603   TH2* h2_hcal_mean = (TH2*) cl->getHisto(hcalmon[0], "h2_hcal_mean");
2604   TH1* h_event = cl->getHisto(hcalmon[0], "h_event");
2605   TH2* h2_hcal_hits = (TH2*) cl->getHisto(hcalmon[0], "h2_hcal_hits");
2606   TH2* h2_hcal_time = (TH2*) cl->getHisto(hcalmon[0], "h2_hcal_time");
2607   TH2* h2_hcal_mean_1 = (TH2*) cl->getHisto(hcalmon[1], "h2_hcal_mean");
2608   TH1* h_event_1 = cl->getHisto(hcalmon[1], "h_event");
2609   TH2* h2_hcal_hits_1 = (TH2*) cl->getHisto(hcalmon[1], "h2_hcal_hits");
2610   TH2* h2_hcal_time_1 = (TH2*) cl->getHisto(hcalmon[1], "h2_hcal_time");
2611 
2612   if (!gROOT->FindObject("HcalMon6"))
2613   {
2614     MakeCanvas("HcalMon6");
2615   }
2616   if (!h2_hcal_mean || !h_event || !h2_hcal_hits || !h2_hcal_time || !h2_hcal_mean_1 || !h_event_1 || !h2_hcal_hits_1 || !h2_hcal_time_1)
2617   {
2618     DrawDeadServer(transparent[6]);
2619     TC[7]->SetEditable(false);
2620     if (isHtml())
2621     {
2622       delete TC[7];
2623       TC[7] = nullptr;
2624     }
2625     return -1;
2626   }
2627   if (h_event->GetEntries())
2628   {
2629     h2_hcal_mean->Scale(1. / h_event->GetEntries());
2630     h2_hcal_hits->Scale(1. / h_event->GetEntries());
2631   }
2632   if (h_event_1->GetEntries())
2633   {
2634     h2_hcal_mean_1->Scale(1. / h_event_1->GetEntries());
2635     h2_hcal_hits_1->Scale(1. / h_event_1->GetEntries());
2636   }
2637 
2638   h2_hcal_mean->Add(h2_hcal_mean_1);
2639   h2_hcal_hits->Add(h2_hcal_hits_1);
2640   h2_hcal_time->Add(h2_hcal_time_1);
2641 
2642   float tsize = 0.06;
2643 
2644   TC[7]->SetEditable(true);
2645   TC[7]->Clear("D");
2646   Pad[21]->cd();
2647   gStyle->SetTitleFontSize(0.06);
2648 
2649   h2_hcal_mean->Draw("colz");
2650   h2_hcal_mean->GetXaxis()->SetNdivisions(510, kTRUE);
2651   h2_hcal_mean->GetXaxis()->SetTitle("eta index");
2652   h2_hcal_mean->GetYaxis()->SetTitle("phi index");
2653   h2_hcal_mean->SetTitle("Tower Average Energy[ADC]");
2654   h2_hcal_mean->GetXaxis()->SetLabelSize(tsize);
2655   h2_hcal_mean->GetYaxis()->SetLabelSize(tsize);
2656   h2_hcal_mean->GetXaxis()->SetTitleSize(tsize);
2657   h2_hcal_mean->GetYaxis()->SetTitleSize(tsize);
2658   h2_hcal_mean->GetXaxis()->SetTitleOffset(1.2);
2659   h2_hcal_mean->GetYaxis()->SetTitleOffset(0.75);
2660 
2661   gPad->SetBottomMargin(0.16);
2662   gPad->SetLeftMargin(0.15);
2663   gPad->SetRightMargin(0.2);
2664   gPad->SetTopMargin(0.1);
2665   gPad->SetTicky();
2666   gPad->SetTickx();
2667   gStyle->SetOptStat(0);
2668   gStyle->SetPalette(57);
2669 
2670   {
2671     // lines
2672     TLine line_sector[32];
2673     for (int i_line = 0; i_line < 32; i_line++)
2674     {
2675       line_sector[i_line] = TLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
2676       line_sector[i_line].SetLineColor(1);
2677       line_sector[i_line].SetLineWidth(4);
2678       line_sector[i_line].SetLineStyle(1);
2679       line_sector[i_line].DrawLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
2680     }
2681 
2682     TLine line_board1(8, 0, 8, 64);
2683     line_board1.SetLineColor(1);
2684     line_board1.SetLineWidth(4);
2685     line_board1.SetLineStyle(1);
2686     line_board1.DrawLine(8, 0, 8, 64);
2687 
2688     TLine line_board2(16, 0, 16, 64);
2689     line_board2.SetLineColor(1);
2690     line_board2.SetLineWidth(4);
2691     line_board2.SetLineStyle(1);
2692     line_board2.DrawLine(16, 0, 16, 64);
2693   }
2694 
2695   Pad[22]->cd();
2696   gStyle->SetTitleFontSize(0.06);
2697 
2698   h2_hcal_hits->Draw("colz");
2699   h2_hcal_hits->GetXaxis()->SetNdivisions(510, kTRUE);
2700   h2_hcal_hits->GetXaxis()->SetTitle("eta index");
2701   h2_hcal_hits->GetYaxis()->SetTitle("phi index");
2702   h2_hcal_hits->SetTitle("Average Occupancy");
2703   h2_hcal_hits->GetXaxis()->SetLabelSize(tsize);
2704   h2_hcal_hits->GetYaxis()->SetLabelSize(tsize);
2705   h2_hcal_hits->GetXaxis()->SetTitleSize(tsize);
2706   h2_hcal_hits->GetYaxis()->SetTitleSize(tsize);
2707   h2_hcal_hits->GetXaxis()->SetTitleOffset(1.2);
2708   h2_hcal_hits->GetYaxis()->SetTitleOffset(0.75);
2709   gPad->SetBottomMargin(0.16);
2710   gPad->SetLeftMargin(0.15);
2711   gPad->SetRightMargin(0.2);
2712   gPad->SetTopMargin(0.1);
2713   gPad->SetTicky();
2714   gPad->SetTickx();
2715 
2716   gStyle->SetOptStat(0);
2717   gStyle->SetPalette(57);
2718 
2719   {
2720     // lines
2721     TLine line_sector[32];
2722     for (int i_line = 0; i_line < 32; i_line++)
2723     {
2724       line_sector[i_line] = TLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
2725       line_sector[i_line].SetLineColor(1);
2726       line_sector[i_line].SetLineWidth(4);
2727       line_sector[i_line].SetLineStyle(1);
2728       line_sector[i_line].DrawLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
2729     }
2730 
2731     TLine line_board1(8, 0, 8, 64);
2732     line_board1.SetLineColor(1);
2733     line_board1.SetLineWidth(4);
2734     line_board1.SetLineStyle(1);
2735     line_board1.DrawLine(8, 0, 8, 64);
2736 
2737     TLine line_board2(16, 0, 16, 64);
2738     line_board2.SetLineColor(1);
2739     line_board2.SetLineWidth(4);
2740     line_board2.SetLineStyle(1);
2741     line_board2.DrawLine(16, 0, 16, 64);
2742   }
2743 
2744   Pad[23]->cd();
2745   gStyle->SetTitleFontSize(0.06);
2746 
2747   h2_hcal_time->Draw("colz");
2748   h2_hcal_time->GetXaxis()->SetNdivisions(510, kTRUE);
2749   h2_hcal_time->GetXaxis()->SetTitle("eta index");
2750   h2_hcal_time->GetYaxis()->SetTitle("phi index");
2751   h2_hcal_time->SetTitle("Average Time[samples]");
2752   h2_hcal_time->GetXaxis()->SetLabelSize(tsize);
2753   h2_hcal_time->GetYaxis()->SetLabelSize(tsize);
2754   h2_hcal_time->GetXaxis()->SetTitleSize(tsize);
2755   h2_hcal_time->GetYaxis()->SetTitleSize(tsize);
2756   h2_hcal_time->GetXaxis()->SetTitleOffset(1.2);
2757   h2_hcal_time->GetYaxis()->SetTitleOffset(0.75);
2758   h2_hcal_time->GetZaxis()->SetRangeUser(4, 8);
2759 
2760   gPad->SetBottomMargin(0.16);
2761   gPad->SetLeftMargin(0.15);
2762   gPad->SetRightMargin(0.2);
2763   gPad->SetTopMargin(0.1);
2764   gPad->SetTicky();
2765   gPad->SetTickx();
2766 
2767   gStyle->SetOptStat(0);
2768 
2769   {
2770     // lines
2771     TLine line_sector[32];
2772     for (int i_line = 0; i_line < 32; i_line++)
2773     {
2774       line_sector[i_line] = TLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
2775       line_sector[i_line].SetLineColor(1);
2776       line_sector[i_line].SetLineWidth(4);
2777       line_sector[i_line].SetLineStyle(1);
2778       line_sector[i_line].DrawLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
2779     }
2780 
2781     TLine line_board1(8, 0, 8, 64);
2782     line_board1.SetLineColor(1);
2783     line_board1.SetLineWidth(4);
2784     line_board1.SetLineStyle(1);
2785     line_board1.DrawLine(8, 0, 8, 64);
2786 
2787     TLine line_board2(16, 0, 16, 64);
2788     line_board2.SetLineColor(1);
2789     line_board2.SetLineWidth(4);
2790     line_board2.SetLineStyle(1);
2791     line_board2.DrawLine(16, 0, 16, 64);
2792   }
2793 
2794   TText PrintRun;
2795   PrintRun.SetTextFont(62);
2796   PrintRun.SetTextSize(0.03);
2797   PrintRun.SetNDC();          // set to normalized coordinates
2798   PrintRun.SetTextAlign(23);  // center/top alignment
2799   std::ostringstream runnostream;
2800   std::string runstring;
2801   std::pair<time_t, int> evttime = cl->EventTime("CURRENT");
2802   // fill run number and event time into string
2803   runnostream << ThisName << ": Tower status, Run" << cl->RunNumber()
2804               << ", Time: " << ctime(&evttime.first);
2805   runstring = runnostream.str();
2806   transparent[7]->cd();
2807   PrintRun.SetTextColor(evttime.second);
2808   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
2809 
2810   TC[7]->Update();
2811   TC[7]->Show();
2812   TC[7]->SetEditable(false);
2813 
2814   return 0;
2815 }
2816 
2817 int HcalMonDraw::DrawSeventh(const std::string& what)
2818 {
2819   OnlMonClient* cl = OnlMonClient::instance();
2820   TH2* pr_zsFrac_etaphi = nullptr;
2821   TH2* pr_zsFrac_etaphi_1 = nullptr;
2822   if (what == "SEVENTH")
2823   {
2824     pr_zsFrac_etaphi = (TH2*) cl->getHisto(hcalmon[0], "pr_zsFrac_etaphi");
2825     pr_zsFrac_etaphi_1 = (TH2*) cl->getHisto(hcalmon[1], "pr_zsFrac_etaphi");
2826   }
2827   else
2828   {
2829     pr_zsFrac_etaphi = (TH2*) cl->getHisto(hcalmon[0], "pr_zsFrac_etaphi_all");
2830     pr_zsFrac_etaphi_1 = (TH2*) cl->getHisto(hcalmon[1], "pr_zsFrac_etaphi_all");
2831   }
2832 
2833   if (!gROOT->FindObject("HcalMon7"))
2834   {
2835     MakeCanvas("HcalMon7");
2836   }
2837   if (!pr_zsFrac_etaphi || !pr_zsFrac_etaphi_1)
2838   {
2839     DrawDeadServer(transparent[7]);
2840     TC[9]->SetEditable(false);
2841     if (isHtml())
2842     {
2843       delete TC[9];
2844       TC[9] = nullptr;
2845     }
2846     return -1;
2847   }
2848 
2849   pr_zsFrac_etaphi->Add(pr_zsFrac_etaphi_1);
2850 
2851   float tsize = 0.04;
2852 
2853   TC[9]->SetEditable(true);
2854   TC[9]->Clear("D");
2855 
2856   if (what == "SEVENTH")
2857   {
2858     TC[9]->SetTitle("Unsuppressed Rate");
2859   }
2860   else
2861   {
2862     TC[9]->SetTitle("Unsuppressed Rate All triggers");
2863   }
2864 
2865   Pad[24]->cd();
2866 
2867   gStyle->SetTitleFontSize(0.06);
2868 
2869   pr_zsFrac_etaphi->Draw("colz");
2870   // find the average z for all bins
2871   double sum = 0;
2872   int count = 0;
2873   h1_zs->Reset();
2874   h1_zs_low->Reset();
2875   h1_zs_high->Reset();
2876   for (int i = 0; i < pr_zsFrac_etaphi->GetNbinsX(); i++)
2877   {
2878     for (int j = 0; j < pr_zsFrac_etaphi->GetNbinsY(); j++)
2879     {
2880       float rate = pr_zsFrac_etaphi->GetBinContent(i + 1, j + 1);
2881       if (rate <= 0.1)
2882       {
2883         h1_zs_low->Fill(rate);
2884       }
2885       else if (rate > 0.8)
2886       {
2887         h1_zs_high->Fill(rate);
2888       }
2889 
2890       h1_zs->Fill(rate);
2891       
2892       sum += pr_zsFrac_etaphi->GetBinContent(i + 1, j + 1);
2893       count++;
2894     }
2895   }
2896   double maxx = (sum / count) * 5 > 1.1 ? 1.1 : (sum / count) * 5;
2897   h1_zs->GetXaxis()->SetRangeUser(0, maxx);
2898   double averagezs = sum / count * 100;
2899   //double maxy = std::max({h1_zs->GetMaximum(), h1_zs_low->GetMaximum(), h1_zs_high->GetMaximum()});
2900   //h1_zs->SetMaximum(maxy * 1.2);
2901 
2902   pr_zsFrac_etaphi->GetXaxis()->SetNdivisions(510, kTRUE);
2903   pr_zsFrac_etaphi->GetXaxis()->SetTitle("eta index");
2904   pr_zsFrac_etaphi->GetYaxis()->SetTitle("phi index");
2905   pr_zsFrac_etaphi->SetTitle(Form("Average unsuppressed rate = %0.3f%%", averagezs));
2906   pr_zsFrac_etaphi->GetXaxis()->SetLabelSize(tsize);
2907   pr_zsFrac_etaphi->GetYaxis()->SetLabelSize(tsize);
2908   pr_zsFrac_etaphi->GetXaxis()->SetTitleSize(tsize);
2909   pr_zsFrac_etaphi->GetYaxis()->SetTitleSize(tsize);
2910   pr_zsFrac_etaphi->GetXaxis()->SetTitleOffset(1.2);
2911   pr_zsFrac_etaphi->GetYaxis()->SetTitleOffset(0.9);
2912   pr_zsFrac_etaphi->GetZaxis()->SetRangeUser(0, 1);
2913 
2914   gPad->SetBottomMargin(0.16);
2915   gPad->SetLeftMargin(0.15);
2916   gPad->SetRightMargin(0.2);
2917   gPad->SetTopMargin(0.1);
2918   gPad->SetTicky();
2919   gPad->SetTickx();
2920   gStyle->SetPalette(57);
2921   gStyle->SetOptStat(0);
2922 
2923   {
2924     // lines
2925     TLine line_sector[32];
2926     for (int i_line = 0; i_line < 32; i_line++)
2927     {
2928       line_sector[i_line] = TLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
2929       line_sector[i_line].SetLineColor(1);
2930       line_sector[i_line].SetLineWidth(4);
2931       line_sector[i_line].SetLineStyle(1);
2932       line_sector[i_line].DrawLine(0, (i_line + 1) * 2, 24, (i_line + 1) * 2);
2933     }
2934 
2935     TLine line_board1(8, 0, 8, 64);
2936     line_board1.SetLineColor(1);
2937     line_board1.SetLineWidth(4);
2938     line_board1.SetLineStyle(1);
2939     line_board1.DrawLine(8, 0, 8, 64);
2940 
2941     TLine line_board2(16, 0, 16, 64);
2942     line_board2.SetLineColor(1);
2943     line_board2.SetLineWidth(4);
2944     line_board2.SetLineStyle(1);
2945     line_board2.DrawLine(16, 0, 16, 64);
2946   }
2947 
2948   Pad[25]->cd();
2949   gStyle->SetTitleFontSize(0.06);
2950   tsize = 0.08;
2951   h1_zs->Draw();
2952   h1_zs->GetXaxis()->SetTitle("unsuppressed fraction");
2953   h1_zs->GetYaxis()->SetTitle("towers");
2954   h1_zs->GetXaxis()->SetLabelSize(tsize);
2955   h1_zs->GetYaxis()->SetLabelSize(tsize);
2956   h1_zs->GetXaxis()->SetTitleSize(tsize);
2957   h1_zs->GetYaxis()->SetTitleSize(tsize);
2958   h1_zs->GetXaxis()->SetTitleOffset(0.9);
2959   h1_zs->GetYaxis()->SetTitleOffset(0.85);
2960   h1_zs->GetXaxis()->SetNdivisions(510, kTRUE);
2961   h1_zs->SetFillColorAlpha(kBlue, 0.1);
2962   h1_zs_low->SetFillColorAlpha(kRed, 0.1);
2963   h1_zs_high->SetFillColorAlpha(kYellow, 0.1);
2964   h1_zs_low->Draw("same");
2965   h1_zs_high->Draw("same");
2966   gPad->SetBottomMargin(0.16);
2967   gPad->SetLeftMargin(0.15);
2968   gPad->SetRightMargin(0.15);
2969   gPad->SetTopMargin(0.1);
2970   gStyle->SetOptStat(0);
2971   gPad->SetTicky();
2972   gPad->SetTickx();
2973 
2974   TText PrintRun;
2975   PrintRun.SetTextFont(62);
2976   PrintRun.SetTextSize(0.03);
2977   PrintRun.SetNDC();          // set to normalized coordinates
2978   PrintRun.SetTextAlign(23);  // center/top alignment
2979   std::ostringstream runnostream;
2980   std::ostringstream runnostream2;
2981   std::string runstring;
2982   std::string runstring2;
2983   std::pair<time_t, int> evttime = cl->EventTime("CURRENT");
2984   // fill run number and event time into string
2985   runnostream << ThisName << ": Unsuppressed event fraction, Run" << cl->RunNumber();
2986   runnostream2 << ", Time: " << ctime(&evttime.first);
2987   runstring = runnostream.str();
2988   runstring2 = runnostream2.str();
2989   transparent[9]->cd();
2990   PrintRun.SetTextColor(evttime.second);
2991   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
2992   PrintRun.DrawText(0.5, 0.95, runstring2.c_str());
2993 
2994   TC[9]->Update();
2995   TC[9]->Show();
2996   TC[9]->SetEditable(false);
2997 
2998   return 0;
2999 }
3000 
3001 int HcalMonDraw::DrawServerStats()
3002 {
3003   OnlMonClient* cl = OnlMonClient::instance();
3004   if (!gROOT->FindObject("HcalServerStats"))
3005   {
3006     MakeCanvas("HcalServerStats");
3007   }
3008   TC[8]->Clear("D");
3009   TC[8]->SetEditable(true);
3010   transparent[8]->cd();
3011   TText PrintRun;
3012   PrintRun.SetTextFont(62);
3013   PrintRun.SetNDC();          // set to normalized coordinates
3014   PrintRun.SetTextAlign(23);  // center/top alignment
3015   PrintRun.SetTextSize(0.04);
3016   PrintRun.SetTextColor(1);
3017   PrintRun.DrawText(0.5, 0.99, "Server Statistics");
3018 
3019   PrintRun.SetTextSize(0.02);
3020   double vdist = 0.05;
3021   double vpos = 0.9;
3022   for (const auto& server : m_ServerSet)
3023   {
3024     std::ostringstream txt;
3025     auto servermapiter = cl->GetServerMap(server);
3026     if (servermapiter == cl->GetServerMapEnd())
3027     {
3028       txt << "Server " << server
3029           << " is dead ";
3030       PrintRun.SetTextColor(kRed);
3031     }
3032     else
3033     {
3034       int gl1counts = std::get<4>(servermapiter->second) / 2;
3035       txt << "Server " << server
3036           << ", run number " << std::get<1>(servermapiter->second)
3037           << ", event count: " << std::get<2>(servermapiter->second);
3038       if (gl1counts >= 0)
3039       {
3040         txt << ", gl1 count: " << gl1counts;
3041       }
3042       txt << ", current time " << ctime(&(std::get<3>(servermapiter->second)));
3043       if (std::get<0>(servermapiter->second))
3044       {
3045         PrintRun.SetTextColor(kGray + 2);
3046       }
3047       else
3048       {
3049         PrintRun.SetTextColor(kRed);
3050       }
3051     }
3052     PrintRun.DrawText(0.5, vpos, txt.str().c_str());
3053     vpos -= vdist;
3054   }
3055   TC[8]->Update();
3056   TC[8]->Show();
3057   TC[8]->SetEditable(false);
3058 
3059   return 0;
3060 }