Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "LocalPolMonDraw.h"
0002 
0003 #include <onlmon/OnlMonClient.h>
0004 #include <onlmon/OnlMonDB.h>
0005 
0006 #include <TAxis.h>  // for TAxis
0007 #include <TCanvas.h>
0008 #include <TDatime.h>
0009 #include <TGraphErrors.h>
0010 #include <TGraphPolar.h>
0011 #include <TGraphPolargram.h>
0012 #include <TH1.h>
0013 #include <TH2.h>
0014 #include <TH2I.h>
0015 #include <TLegend.h>
0016 #include <TLine.h>
0017 #include <TMath.h>
0018 #include <TPad.h>
0019 #include <TProfile.h>
0020 #include <TROOT.h>
0021 #include <TString.h>
0022 #include <TStyle.h>
0023 #include <TSystem.h>
0024 #include <TText.h>
0025 
0026 #include <cstring>  // for memset
0027 #include <ctime>
0028 #include <fstream>
0029 #include <iostream>  // for operator<<, basic_ostream, basic_os...
0030 #include <map>
0031 #include <sstream>
0032 #include <vector>  // for vector
0033 
0034 LocalPolMonDraw::LocalPolMonDraw(const std::string &name)
0035   : OnlMonDraw(name)
0036 {
0037   return;
0038 }
0039 
0040 int LocalPolMonDraw::Init()
0041 {
0042   g_Asym = new TGraphErrors ***[2];
0043   g_AsymScramble = new TGraphErrors ***[2];
0044   h_Asym = new TH1D ***[2];
0045   h_ScrambleAsym = new TH1D ***[2];
0046   TString BeamName[2] = {"Blue", "Yell"};
0047   TString MethodName[2] = {"Arithmetic", "Geometric"};
0048   TString Orientation[2] = {"LR", "UD"};
0049   for (int beam = 0; beam < 2; beam++)
0050   {
0051     g_Asym[beam] = new TGraphErrors **[2];
0052     g_AsymScramble[beam] = new TGraphErrors **[2];
0053     h_Asym[beam] = new TH1D **[2];
0054     h_ScrambleAsym[beam] = new TH1D **[2];
0055     for (int method = 0; method < 2; method++)
0056     {
0057       g_Asym[beam][method] = new TGraphErrors *[2];
0058       g_AsymScramble[beam][method] = new TGraphErrors *[2];
0059       h_Asym[beam][method] = new TH1D *[2];
0060       h_ScrambleAsym[beam][method] = new TH1D *[2];
0061       for (int orient = 0; orient < 2; orient++)
0062       {
0063         // Since root badely handle the associated histograms for drawing the frame, ending up in instabilities and crashes
0064         // Poor alternative for the moment, to create Fresh TGraph each time we need
0065         g_Asym[beam][method][orient] = nullptr;
0066         g_AsymScramble[beam][method][orient] = nullptr;
0067       }
0068     }
0069   }
0070 
0071   // Equivalent of TH1F frame when drawing a TGraph for polar coordinate system
0072   gpolargram = new TGraphPolargram("locpolpolargram", 0, 0.05, -TMath::Pi(), TMath::Pi());
0073   gpolargram->SetToRadian();
0074   gpolargram->SetNdivPolar(216);
0075   gpolargram->SetNdivRadial(105);
0076 
0077   g_Polar = new TGraphPolar **[2];
0078   for (int beam = 0; beam < 2; beam++)
0079   {
0080     g_Polar[beam] = new TGraphPolar *[2];
0081     for (int method = 0; method < 2; method++)
0082     {
0083       // For the same reason as above, to prevent random crash inside root, create a fresh object each time we need
0084       g_Polar[beam][method] = nullptr;
0085     }
0086   }
0087   Pad = new TPad **[9];  // Who is taking care of the deletion?
0088   Pad[0] = new TPad *[16];
0089   Pad[1] = new TPad *[4];
0090   Pad[2] = new TPad *[1];
0091   Pad[3] = new TPad *[16];
0092   Pad[4] = new TPad *[12];
0093   Pad[5] = new TPad *[6];
0094   Pad[6] = new TPad *[1];
0095   Pad[7] = new TPad *[2];
0096   Pad[8] = new TPad *[1];
0097 
0098   return 0;
0099 }
0100 
0101 int LocalPolMonDraw::MakeCanvas(const std::string &name)
0102 {
0103   OnlMonClient *cl = OnlMonClient::instance();
0104   int xsize = cl->GetDisplaySizeX();
0105   int ysize = cl->GetDisplaySizeY();
0106   if (name == "LocalPolMon1")
0107   {
0108     // xpos (-1) negative: do not draw menu bar
0109     TC[0] = new TCanvas(name.c_str(), "LocalPolMon Asymmetries", -1 , 0, xsize , ysize * 0.9);
0110     // root is pathetic, whenever a new TCanvas is created root piles up
0111     // 6kb worth of X11 events which need to be cleared with
0112     // gSystem->ProcessEvents(), otherwise your process will grow and
0113     // grow and grow but will not show a definitely lost memory leak
0114     gSystem->ProcessEvents();
0115     for (int ipad = 0; ipad < 16; ipad++)
0116     {
0117       Pad[0][ipad] = new TPad(Form("locpolpad0%d", ipad), "who needs this?", 0.0 + 0.25 * (ipad % 4), 0.95 - 0.2375 * (ipad / 4 + 1), 0.0 + 0.25 * (ipad % 4 + 1), 0.95 - 0.2375 * (ipad / 4), 0);
0118       Pad[0][ipad]->SetLeftMargin(0.15);
0119       Pad[0][ipad]->SetBottomMargin(0.15);
0120       Pad[0][ipad]->Draw();
0121     }
0122 
0123     // this one is used to plot the run number on the canvas
0124     transparent[0] = new TPad("locpoltransparent0", "this does not show", 0, 0, 1, 1);
0125     transparent[0]->SetFillStyle(4000);
0126     transparent[0]->Draw();
0127     TC[0]->SetEditable(false);
0128   }
0129   else if (name == "LocalPolMon2")
0130   {
0131     // xpos negative: do not draw menu bar
0132     TC[1] = new TCanvas(name.c_str(), "LocalPolMon Polarisation direction", -1, 0, xsize, ysize);
0133     gSystem->ProcessEvents();
0134     for (int ipad = 0; ipad < 4; ipad++)
0135     {
0136       Pad[1][ipad] = new TPad(Form("locpolpad1%d", ipad), "who needs this?", 0.0 + 0.5 * (ipad % 2), 0.95 - 0.475 * (ipad / 2 + 1), 0.0 + 0.5 * (ipad % 2 + 1), 0.95 - 0.475 * (ipad / 2), 0);
0137       Pad[1][ipad]->SetTopMargin(0.15);
0138       Pad[1][ipad]->Draw();
0139     }
0140 
0141     // this one is used to plot the run number on the canvas
0142     transparent[1] = new TPad("locpoltransparent1", "this does not show", 0, 0, 1, 1);
0143     transparent[1]->SetFillStyle(4000);
0144     transparent[1]->Draw();
0145     TC[1]->SetEditable(false);
0146   }
0147   else if(name=="LocalPolMon3"){
0148     // xpos negative: do not draw menu bar
0149     TC[2] = new TCanvas(name.c_str(), "LocalPolMon Spin Pattern", -1, 0, xsize, ysize);
0150     gSystem->ProcessEvents();
0151     Pad[2][0] = new TPad(Form("locpolpad2%d", 0), "who needs this?", 0.05 , 0.05, 0.95, 0.95, 0);
0152     Pad[2][0]->SetTopMargin(0.15);
0153     Pad[2][0]->Draw();
0154 
0155     // this one is used to plot the run number on the canvas
0156     transparent[2] = new TPad("locpoltransparent2", "this does not show", 0, 0, 1, 1);
0157     transparent[2]->SetFillStyle(4000);
0158     transparent[2]->Draw();
0159     TC[2]->SetEditable(false);
0160     
0161   }
0162   else if(name=="LocalPolMon4"){
0163     // xpos negative: do not draw menu bar
0164     TC[3] = new TCanvas(name.c_str(), "Trigger distribution", -1, 0, xsize, ysize);
0165     gSystem->ProcessEvents();
0166     for (int ipad = 0; ipad < 16; ipad++)
0167     {
0168       Pad[3][ipad] = new TPad(Form("locpolpad3%d", ipad), "who needs this?", 0.0 + 0.25 * (ipad % 4), 0.95 - 0.2375 * (ipad / 4 + 1), 0.0 + 0.25 * (ipad % 4 + 1), 0.95 - 0.2375 * (ipad / 4), 0);
0169       Pad[3][ipad]->SetLeftMargin(0.15);
0170       Pad[3][ipad]->SetBottomMargin(0.15);
0171       Pad[3][ipad]->Draw();
0172     }
0173     // this one is used to plot the run number on the canvas
0174     transparent[3] = new TPad("locpoltransparent3", "this does not show", 0, 0, 1, 1);
0175     transparent[3]->SetFillStyle(4000);
0176     transparent[3]->Draw();
0177     TC[3]->SetEditable(false);
0178     
0179   }
0180   else if(name=="LocalPolMon5"){
0181     // xpos negative: do not draw menu bar
0182     TC[4] = new TCanvas(name.c_str(), "SMD distributions", -1, 0, xsize, ysize);
0183     gSystem->ProcessEvents();
0184     for (int ipad = 0; ipad < 12; ipad++)
0185     {
0186       Pad[4][ipad] = new TPad(Form("locpolpad4%d", ipad), "who needs this?", 0.0 + 0.25 * (ipad % 4), 0.95 - 0.316 * (ipad / 4 + 1), 0.0 + 0.25 * (ipad % 4 + 1), 0.95 - 0.316 * (ipad / 4), 0);
0187       Pad[4][ipad]->SetLeftMargin(0.15);
0188       Pad[4][ipad]->SetBottomMargin(0.15);
0189       Pad[4][ipad]->Draw();
0190     }
0191     // this one is used to plot the run number on the canvas
0192     transparent[4] = new TPad("locpoltransparent4", "this does not show", 0, 0, 1, 1);
0193     transparent[4]->SetFillStyle(4000);
0194     transparent[4]->Draw();
0195     TC[4]->SetEditable(false);
0196   }
0197   else if(name=="LocalPolMon6"){
0198     // xpos negative: do not draw menu bar
0199     TC[5] = new TCanvas(name.c_str(), "Waveforms", -1, 0, xsize, ysize);
0200     gSystem->ProcessEvents();
0201     for (int ipad = 0; ipad < 6; ipad++)
0202     {
0203       Pad[5][ipad] = new TPad(Form("locpolpad5%d", ipad), "who needs this?", 0.0 + 0.33 * (ipad % 3), 0.95 - 0.475 * (ipad / 3 + 1), 0.0 + 0.33 * (ipad % 3 + 1), 0.95 - 0.475 * (ipad / 3), 0);
0204       Pad[5][ipad]->SetLeftMargin(0.15);
0205       Pad[5][ipad]->SetBottomMargin(0.15);
0206       Pad[5][ipad]->Draw();
0207     }
0208     // this one is used to plot the run number on the canvas
0209     transparent[5] = new TPad("locpoltransparent5", "this does not show", 0, 0, 1, 1);
0210     transparent[5]->SetFillStyle(4000);
0211     transparent[5]->Draw();
0212     TC[5]->SetEditable(false);
0213   }
0214   else if(name=="LocalPolMon7"){
0215     // xpos negative: do not draw menu bar
0216     TC[6] = new TCanvas(name.c_str(), "Dropped events", -1, 0, xsize, ysize);
0217     gSystem->ProcessEvents();
0218     Pad[6][0] = new TPad(Form("locpolpad6%d", 0), "who needs this?", 0.0 , 0.05, 1.0, 0.95, 0);
0219     Pad[6][0]->SetLeftMargin(0.15);
0220     Pad[6][0]->SetBottomMargin(0.15);
0221     Pad[6][0]->Draw();
0222     // this one is used to plot the run number on the canvas
0223     transparent[6] = new TPad("locpoltransparent6", "this does not show", 0, 0, 1, 1);
0224     transparent[6]->SetFillStyle(4000);
0225     transparent[6]->Draw();
0226     TC[6]->SetEditable(false);
0227   }
0228   else if(name=="LocalPolMon8"){
0229     // xpos negative: do not draw menu bar
0230     TC[7] = new TCanvas(name.c_str(), "2D SMD profile", -1, 0, xsize / 2., ysize);
0231     gSystem->ProcessEvents();
0232     Pad[7][0] = new TPad(Form("locpolpad7%d", 0), "who needs this?", 0.0 , 0.05, 0.50, 0.95, 0);
0233     Pad[7][0]->SetLeftMargin(0.15);
0234     Pad[7][0]->SetBottomMargin(0.15);
0235     Pad[7][0]->Draw();
0236     Pad[7][1] = new TPad(Form("locpolpad7%d", 1), "who needs this?", 0.5 , 0.05, 1.0, 0.95, 0);
0237     Pad[7][1]->SetLeftMargin(0.15);
0238     Pad[7][1]->SetBottomMargin(0.15);
0239     Pad[7][1]->Draw();
0240     // this one is used to plot the run number on the canvas
0241     transparent[7] = new TPad("locpoltransparent7", "this does not show", 0, 0, 1, 1);
0242     transparent[7]->SetFillStyle(4000);
0243     transparent[7]->Draw();
0244     TC[7]->SetEditable(false);
0245   }
0246   else if(name=="LocalPolMon9"){
0247     // xpos negative: do not draw menu bar
0248     TC[8] = new TCanvas(name.c_str(), "Dropped events", -1, 0, xsize, ysize);
0249     gSystem->ProcessEvents();
0250     Pad[8][0] = new TPad(Form("locpolpad6%d", 0), "who needs this?", 0.0 , 0.05, 1.0, 0.95, 0);
0251     Pad[8][0]->SetLeftMargin(0.15);
0252     Pad[8][0]->SetBottomMargin(0.15);
0253     Pad[8][0]->Draw();
0254     // this one is used to plot the run number on the canvas
0255     transparent[8] = new TPad("locpoltransparent8", "this does not show", 0, 0, 1, 1);
0256     transparent[8]->SetFillStyle(4000);
0257     transparent[8]->Draw();
0258     TC[8]->SetEditable(false);
0259   }
0260 
0261 
0262   return 0;
0263 }
0264 
0265 int LocalPolMonDraw::Draw(const std::string &what)
0266 {
0267   int iret = 0;
0268   int idraw = 0;
0269   if (what == "ALL" || what == "FIRST")
0270   {
0271     iret += DrawFirst(what);
0272     idraw++;
0273   }
0274   if (what == "ALL" || what == "SECOND")
0275   {
0276     iret += DrawSecond(what);
0277     idraw++;
0278   }
0279   if (what == "ALL" || what == "THIRD")
0280   {
0281     iret += DrawThird(what);
0282     idraw++;
0283   }
0284   if (what == "ALL" || what == "FOURTH")
0285   {
0286     iret += DrawFourth(what);
0287     idraw++;
0288   }
0289   if (what == "ALL" || what == "FIFTH")
0290   {
0291     iret += DrawFifth(what);
0292     idraw++;
0293   }
0294   if (what == "ALL" || what == "SIXTH")
0295   {
0296     iret += DrawSixth(what);
0297     idraw++;
0298   }
0299   if (what == "ALL" || what == "SEVENTH")
0300   {
0301     iret += DrawSeventh(what);
0302     idraw++;
0303   }
0304   if (what == "ALL" || what == "EIGHTH")
0305   {
0306     iret += DrawEighth(what);
0307     idraw++;
0308   }
0309   if (what == "ALL" || what == "NINTH")
0310   {
0311     iret += DrawNinth(what);
0312     idraw++;
0313   }
0314   if (!idraw)
0315   {
0316     std::cout << __PRETTY_FUNCTION__ << " Unimplemented Drawing option: " << what << std::endl;
0317     iret = -1;
0318   }
0319   return iret;
0320 }
0321 
0322 int LocalPolMonDraw::DrawFirst(const std::string & /* what */)
0323 {
0324   OnlMonClient *cl = OnlMonClient::instance();
0325 
0326   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
0327 
0328   if (!gROOT->FindObject("LocalPolMon1"))
0329   {
0330     MakeCanvas("LocalPolMon1");
0331   }
0332   TC[0]->SetEditable(true);
0333   TC[0]->Clear("D");
0334   gStyle->SetOptStat(0);
0335   bool IsGood = true;
0336   bool AtLeastOnePoint=true;
0337   TString BeamName[2] = {"Blue", "Yell"};
0338   TString MethodName[2] = {"Arithmetic", "Geometric"};
0339   TString Orientation[2] = {"LR", "UD"};
0340   for (int ibeam = 0; ibeam < 2; ibeam++)
0341   {
0342     for (int method = 0; method < 2; method++)
0343     {
0344       for (int orient = 0; orient < 2; orient++)
0345       {
0346         h_Asym[ibeam][method][orient] = (TH1D *) cl->getHisto("LOCALPOLMON_0", Form("h_Asym%s%s%s", BeamName[ibeam].Data(), MethodName[method].Data(), Orientation[orient].Data()));
0347         if (!h_Asym[ibeam][method][orient])
0348         {
0349           IsGood = false;
0350         }
0351     else if(h_Asym[ibeam][method][orient]->GetBinError(1)==0){
0352       AtLeastOnePoint=false;
0353     }
0354         h_ScrambleAsym[ibeam][method][orient] = (TH1D *) cl->getHisto("LOCALPOLMON_0", Form("h_AsymScramble%s%s%s", BeamName[ibeam].Data(), MethodName[method].Data(), Orientation[orient].Data()));
0355         if (!h_ScrambleAsym[ibeam][method][orient])
0356         {
0357           IsGood = false;
0358         }
0359     else if(h_ScrambleAsym[ibeam][method][orient]->GetBinError(1)==0){
0360       AtLeastOnePoint=false;
0361     }
0362       }
0363     }
0364   }
0365   TProfile *h_times = (TProfile *) cl->getHisto("LOCALPOLMON_0", "h_times");
0366   if (!h_times)
0367   {
0368     IsGood = false;
0369   }
0370   if (!IsGood)
0371   {
0372     DrawDeadServer(transparent[0]);
0373     TC[0]->SetEditable(false);
0374     return -1;
0375   }
0376   if( !AtLeastOnePoint)//could also be simply check h_events->GetBinContent(12+1)>0;
0377     {
0378       TText NotEnough;
0379       NotEnough.SetTextFont(62);
0380       NotEnough.SetTextSize(0.04);
0381       NotEnough.SetNDC();
0382       NotEnough.SetTextAlign(23);
0383       std::ostringstream textstream;
0384       std::string runstring;
0385       textstream<< ThisName<< "_1 Run "<<cl->RunNumber()
0386         << ", Time: "<< ctime(&evttime.first);
0387       runstring = textstream.str();
0388       transparent[0]->cd();
0389       NotEnough.SetTextColor(evttime.second);
0390       NotEnough.DrawText(0.5,0.99,runstring.c_str());
0391       textstream.str("");
0392       textstream.clear();
0393       //std::ostringstream textstream2;
0394       textstream<< " Not enought selected neutron events for asymmetry measurement ";
0395       runstring = textstream.str();
0396       NotEnough.DrawText(0.5,0.5,runstring.c_str());
0397       textstream.str("");
0398       textstream.clear();
0399       textstream<< " Keep accumulating statistics and check later ";
0400       runstring = textstream.str();
0401       NotEnough.DrawText(0.5,0.3,runstring.c_str());
0402       TC[0]->Update();
0403       TC[0]->Show();
0404       TC[0]->SetEditable(false);
0405       return 0;
0406     }
0407 
0408 
0409   for (int ibeam = 0; ibeam < 2; ibeam++)
0410   {
0411     for (int orient = 0; orient < 2; orient++)
0412     {
0413       for (int method = 0; method < 2; method++)
0414       {
0415         if (g_Asym[ibeam][method][orient])
0416         {
0417           delete g_Asym[ibeam][method][orient];
0418           g_Asym[ibeam][method][orient] = nullptr;
0419         }
0420         g_Asym[ibeam][method][orient] = new TGraphErrors();
0421         g_Asym[ibeam][method][orient]->SetName(Form("g_Asym%s%s%s", BeamName[ibeam].Data(), MethodName[method].Data(), Orientation[orient].Data()));
0422         g_Asym[ibeam][method][orient]->SetMarkerStyle(kFullCircle);
0423         g_Asym[ibeam][method][orient]->SetMarkerColor(kBlue);
0424         g_Asym[ibeam][method][orient]->SetLineColor(kBlue);
0425         g_Asym[ibeam][method][orient]->SetTitle(Form("%s %s %s Asym.", BeamName[ibeam].Data(), Orientation[orient].Data(), MethodName[method].Data()));
0426 
0427         if (g_AsymScramble[ibeam][method][orient])
0428         {
0429           delete g_AsymScramble[ibeam][method][orient];
0430           g_AsymScramble[ibeam][method][orient] = nullptr;
0431         }
0432         g_AsymScramble[ibeam][method][orient] = new TGraphErrors();
0433         g_AsymScramble[ibeam][method][orient]->SetName(Form("g_AsymScramble%s%s%s", BeamName[ibeam].Data(), MethodName[method].Data(), Orientation[orient].Data()));
0434         g_AsymScramble[ibeam][method][orient]->SetMarkerStyle(kFullCircle);
0435         g_AsymScramble[ibeam][method][orient]->SetMarkerColor(kGray);
0436         g_AsymScramble[ibeam][method][orient]->SetLineColor(kGray);
0437         g_AsymScramble[ibeam][method][orient]->SetTitle(Form("Unpol %s %s %s Asym.", BeamName[ibeam].Data(), Orientation[orient].Data(), MethodName[method].Data()));
0438 
0439         int N = h_times->GetNbinsX();
0440         for (int i = 0; i < N; i++)
0441         {
0442           if (h_Asym[ibeam][method][orient]->GetBinError(i + 1) == 0)
0443           {
0444             break;
0445           }
0446           g_Asym[ibeam][method][orient]->SetPoint(i, h_times->GetBinContent(i + 1), h_Asym[ibeam][method][orient]->GetBinContent(i + 1));
0447           g_Asym[ibeam][method][orient]->SetPointError(i, h_times->GetBinError(i + 1), h_Asym[ibeam][method][orient]->GetBinError(i + 1));
0448 
0449           g_AsymScramble[ibeam][method][orient]->SetPoint(i, h_times->GetBinContent(i + 1), h_ScrambleAsym[ibeam][method][orient]->GetBinContent(i + 1));
0450           g_AsymScramble[ibeam][method][orient]->SetPointError(i, h_times->GetBinError(i + 1), h_ScrambleAsym[ibeam][method][orient]->GetBinError(i + 1));
0451           m_time[i] = (long int) h_times->GetBinContent(i + 1);
0452         }
0453       }
0454     }
0455   }
0456   long int start = min_element(m_time.begin(), m_time.end(), [](const std::pair<int, long int> &lhs, const std::pair<int, long int> &rhs)
0457                                { return lhs.second < rhs.second; })
0458                        ->second;
0459   long int stop = max_element(m_time.begin(), m_time.end(), [](const std::pair<int, long int> &lhs, const std::pair<int, long int> &rhs)
0460                               { return lhs.second < rhs.second; })
0461                       ->second;
0462 
0463   if (stop - start < 15 * 60)
0464   {  // less than 15 min, we set it to 15min
0465     stop = start + 15 * 60;
0466   }
0467   else
0468   {
0469     stop = stop + 60;  // we add 1 min
0470   }
0471   start = start - 60;
0472 
0473   if (hframe)
0474   {
0475     delete hframe;
0476     hframe = nullptr;
0477   }
0478   hframe = new TH1F("locpolframe", "", 100, start, stop);
0479   hframe->SetStats(kFALSE);
0480 
0481   if (hscrambleframe)
0482   {
0483     delete hscrambleframe;
0484     hscrambleframe = nullptr;
0485   }
0486   hscrambleframe = new TH1F("locpolscrambleframe", "", 100, start, stop);
0487   hscrambleframe->SetStats(kFALSE);
0488 
0489   gStyle->SetTitleFontSize(0.1);
0490   gStyle->SetTitleBorderSize(0);
0491   gStyle->SetTitleFillColor(kWhite);
0492   gROOT->ForceStyle();
0493   TLine l;
0494   TLine lref;
0495   lref.SetLineColor(kRed);
0496   TText PrintTitle;
0497   PrintTitle.SetTextFont(62);
0498   PrintTitle.SetTextSize(0.06);
0499   PrintTitle.SetNDC();          // set to normalized coordinates
0500   PrintTitle.SetTextAlign(23);  // center/top alignment
0501   double reflow[2]={-0.03,-0.01};
0502   double refhig[2]={-0.01, 0.01};
0503   for (int ibeam = 0; ibeam < 2; ibeam++)
0504   {
0505     for (int orient = 0; orient < 2; orient++)
0506     {
0507       for (int method = 0; method < 2; method++)
0508       {
0509         Pad[0][8 * ibeam + 2 * method + orient]->cd();
0510         hframe->Draw();
0511         hframe->GetXaxis()->SetTimeDisplay(1);
0512         hframe->GetXaxis()->SetTimeFormat("%H:%M%F1970-01-01 00:00:00s0");
0513         hframe->GetXaxis()->SetNdivisions(507);
0514         hframe->GetXaxis()->SetTitle("Time (hh:mm)");
0515         hframe->GetXaxis()->SetTitleSize(0.06);
0516         hframe->GetXaxis()->SetTitleOffset(1.1);
0517         hframe->GetXaxis()->SetLabelSize(0.06);
0518         hframe->GetXaxis()->SetLabelOffset(0.025);
0519 
0520         hframe->GetYaxis()->SetTitle("Fwd Asymmetry");
0521         hframe->GetYaxis()->SetTitleSize(0.06);
0522         hframe->GetYaxis()->SetTitleOffset(1.1);
0523         hframe->GetYaxis()->CenterTitle(true);
0524         hframe->GetYaxis()->SetRangeUser(-0.1, 0.1);
0525         hframe->GetYaxis()->SetLabelSize(0.06);
0526         l.DrawLine(start, 0.00, stop, 0.00);
0527         //lref.DrawLine(start, 0.01, stop, 0.01);
0528         //lref.DrawLine(start, 0.02, stop, 0.02);
0529         lref.DrawLine(start, reflow[orient], stop, reflow[orient]);
0530         lref.DrawLine(start, refhig[orient], stop, refhig[orient]);
0531         g_Asym[ibeam][method][orient]->Draw("epsame");
0532         PrintTitle.DrawText(0.5, 0.95, Form("%s %s %s Asym.", BeamName[ibeam].Data(), Orientation[orient].Data(), MethodName[method].Data()));
0533 
0534         Pad[0][8 * ibeam + 2 * method + orient + 4]->cd();
0535         hscrambleframe->Draw();
0536         hscrambleframe->GetXaxis()->SetTimeDisplay(1);
0537         hscrambleframe->GetXaxis()->SetTimeFormat("%H:%M%F1970-01-01 00:00:00s0");
0538         hscrambleframe->GetXaxis()->SetNdivisions(507);
0539         hscrambleframe->GetXaxis()->SetTitle("Time (hh:mm)");
0540         hscrambleframe->GetXaxis()->SetTitleSize(0.06);
0541         hscrambleframe->GetXaxis()->SetTitleOffset(1.1);
0542         hscrambleframe->GetXaxis()->SetLabelSize(0.06);
0543         hscrambleframe->GetXaxis()->SetLabelOffset(0.025);
0544 
0545         hscrambleframe->GetYaxis()->SetTitle("Bwd Asymmetry");
0546         hscrambleframe->GetYaxis()->SetTitleSize(0.06);
0547         hscrambleframe->GetYaxis()->SetTitleOffset(1.1);
0548         hscrambleframe->GetYaxis()->CenterTitle(true);
0549         hscrambleframe->GetYaxis()->SetRangeUser(-0.1, 0.1);
0550         hscrambleframe->GetYaxis()->SetLabelSize(0.06);
0551         l.DrawLine(start, 0, stop, 0);
0552         lref.DrawLine(start, -0.01, stop, -0.01);
0553         lref.DrawLine(start, 0.01, stop, 0.01);
0554         g_AsymScramble[ibeam][method][orient]->Draw("epsame");
0555         PrintTitle.DrawText(0.5, 0.95, Form("Unpol. %s %s %s Asym.", BeamName[ibeam].Data(), Orientation[orient].Data(), MethodName[method].Data()));
0556       }
0557     }
0558   }
0559 
0560   TText PrintRun;
0561   PrintRun.SetTextFont(62);
0562   PrintRun.SetTextSize(0.04);
0563   PrintRun.SetNDC();          // set to normalized coordinates
0564   PrintRun.SetTextAlign(23);  // center/top alignment
0565   std::ostringstream runnostream;
0566   std::string runstring;
0567   // fill run number and event time into string
0568   runnostream << ThisName << "_1 Run " << cl->RunNumber()
0569               << ", Time: " << ctime(&evttime.first);
0570   runstring = runnostream.str();
0571   transparent[0]->cd();
0572   PrintRun.SetTextColor(evttime.second);
0573   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
0574   TC[0]->Update();
0575   TC[0]->Show();
0576   TC[0]->SetEditable(false);
0577   return 0;
0578 }
0579 
0580 int LocalPolMonDraw::DrawSecond(const std::string & /* what */)
0581 {
0582   OnlMonClient *cl = OnlMonClient::instance();
0583 
0584   if (!gROOT->FindObject("LocalPolMon2"))
0585   {
0586     MakeCanvas("LocalPolMon2");
0587   }
0588   TC[1]->SetEditable(true);
0589   TC[1]->Clear("D");
0590   TC[1]->Update();
0591 
0592   TString BeamName[2] = {"Blue", "Yell"};
0593   TString MethodName[2] = {"Arithmetic", "Geometric"};
0594   TString Orientation[2] = {"LR", "UD"};
0595   for (int beam = 0; beam < 2; beam++)
0596   {
0597     for (int method = 0; method < 2; method++)
0598     {
0599       if (g_Polar[beam][method])
0600       {
0601         delete g_Polar[beam][method];
0602         g_Polar[beam][method] = nullptr;
0603       }
0604       g_Polar[beam][method] = new TGraphPolar();
0605       g_Polar[beam][method]->SetName(Form("g_Polar%s%s", BeamName[beam].Data(), MethodName[method].Data()));
0606       g_Polar[beam][method]->SetMarkerStyle(kFullCircle);
0607       g_Polar[beam][method]->SetMarkerColor(kRed);
0608       g_Polar[beam][method]->SetLineColor(kRed);
0609       g_Polar[beam][method]->SetPoint(0, 0, 0);
0610       g_Polar[beam][method]->SetPolargram(gpolargram);
0611     }
0612   }
0613 
0614   bool IsGood = true;
0615   for (int ibeam = 0; ibeam < 2; ibeam++)
0616   {
0617     for (int method = 0; method < 2; method++)
0618     {
0619       for (int orient = 0; orient < 2; orient++)
0620       {
0621         h_Asym[ibeam][method][orient] = (TH1D *) cl->getHisto("LOCALPOLMON_0", Form("h_Asym%s%s%s", BeamName[ibeam].Data(), MethodName[method].Data(), Orientation[orient].Data()));
0622         if (!h_Asym[ibeam][method][orient])
0623         {
0624           IsGood = false;
0625         }
0626         h_ScrambleAsym[ibeam][method][orient] = (TH1D *) cl->getHisto("LOCALPOLMON_0", Form("h_AsymScramble%s%s%s", BeamName[ibeam].Data(), MethodName[method].Data(), Orientation[orient].Data()));
0627         if (!h_ScrambleAsym[ibeam][method][orient])
0628         {
0629           IsGood = false;
0630         }
0631       }
0632     }
0633   }
0634   TProfile *h_times = (TProfile *) cl->getHisto("LOCALPOLMON_0", "h_times");
0635   if (!h_times)
0636   {
0637     IsGood = false;
0638   }
0639   if (!IsGood)
0640   {
0641     DrawDeadServer(transparent[1]);
0642     TC[1]->SetEditable(false);
0643     return -1;
0644   }
0645   gStyle->SetTitleBorderSize(0);
0646   gStyle->SetTitleFillColor(kWhite);
0647   gROOT->ForceStyle();
0648   TText PrintTitle;
0649   PrintTitle.SetTextFont(62);
0650   PrintTitle.SetTextSize(0.06);
0651   PrintTitle.SetNDC();          // set to normalized coordinates
0652   PrintTitle.SetTextAlign(23);  // center/top alignment
0653   for (int ibeam = 0; ibeam < 2; ibeam++)
0654   {
0655     for (int method = 0; method < 2; method++)
0656     {
0657       int N = h_Asym[ibeam][method][0]->GetNbinsX();
0658       for (int i = 0; i < N; i++)
0659       {
0660         double x = h_Asym[ibeam][method][1]->GetBinContent(i + 1);  // left right
0661         double y = h_Asym[ibeam][method][0]->GetBinContent(i + 1);  // top-bottom
0662         double ex = h_Asym[ibeam][method][1]->GetBinError(i + 1);
0663         double ey = h_Asym[ibeam][method][0]->GetBinError(i + 1);
0664         double theta = atan2(y,-1* x);
0665         double radius = sqrt(x * x + y * y);
0666         if (radius < 1e-7)
0667         {
0668           radius = 1e-7;
0669         }
0670         double etheta = sqrt(y * y * ex * ex + x * x * ey * ey) / pow(radius, 2);
0671         double eradius = sqrt(x * x * ex * ex + y * y * ey * ey) / radius;
0672         g_Polar[ibeam][method]->SetPoint(i + 1, theta, radius);
0673         g_Polar[ibeam][method]->SetPointError(i + 1, etheta, eradius);
0674       }
0675       Pad[1][2 * method + ibeam]->cd();
0676       // if(gPad->FindObject("polargram"))   std::cout<<"polargram found\n";
0677       // if(gPad->FindObject("locpolpolargram")) std::cout<<"mypolagram found\n";
0678       g_Polar[ibeam][method]->GetPolargram()->Draw();
0679       g_Polar[ibeam][method]->Draw("epsame");
0680       PrintTitle.DrawText(0.15, 0.98, Form("%s %s", BeamName[ibeam].Data(), MethodName[method].Data()));
0681       Pad[1][2 * method + ibeam]->Update();
0682     }
0683   }
0684 
0685   TC[1]->Update();
0686   TText PrintRun;
0687   PrintRun.SetTextFont(62);
0688   PrintRun.SetTextSize(0.04);
0689   PrintRun.SetNDC();          // set to normalized coordinates
0690   PrintRun.SetTextAlign(23);  // center/top alignment
0691   std::ostringstream runnostream;
0692   std::string runstring;
0693   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
0694   // fill run number and event time into string
0695   runnostream << ThisName << "_2 Run " << cl->RunNumber()
0696               << ", Time: " << ctime(&evttime.first);
0697   runstring = runnostream.str();
0698   transparent[1]->cd();
0699   PrintRun.SetTextColor(evttime.second);
0700   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
0701   TC[1]->Update();
0702   TC[1]->Show();
0703   TC[1]->SetEditable(false);
0704   return 0;
0705 }
0706 
0707 
0708 int LocalPolMonDraw::DrawThird(const std::string & /* what */)
0709 {
0710   OnlMonClient *cl = OnlMonClient::instance();
0711   
0712   if (!gROOT->FindObject("LocalPolMon3"))
0713   {
0714     MakeCanvas("LocalPolMon3");
0715   }
0716   TC[2]->SetEditable(true);
0717   TC[2]->Clear("D");
0718   gStyle->SetOptStat(0);
0719   TH2I* hspin=(TH2I*)cl->getHisto("LOCALPOLMON_0","hspinpattern");
0720   if(!hspin){
0721     DrawDeadServer(transparent[2]);
0722     TC[2]->SetEditable(false);
0723     return -1;
0724   }
0725   
0726   Pad[2][0]->cd();
0727   hspin->GetXaxis()->SetTitle("Bunch number");
0728   hspin->GetYaxis()->SetBinLabel(1,"Blue Beam");
0729   hspin->GetYaxis()->SetBinLabel(2,"Yellow Beam");
0730   hspin->SetStats(kFALSE);
0731   hspin->DrawCopy("colz");
0732   
0733   TC[2]->Update();
0734   TText PrintRun;
0735   PrintRun.SetTextFont(62);
0736   PrintRun.SetTextSize(0.04);
0737   PrintRun.SetNDC();          // set to normalized coordinates
0738   PrintRun.SetTextAlign(23);  // center/top alignment
0739   std::ostringstream runnostream;
0740   std::string runstring;
0741   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
0742   // fill run number and event time into string
0743   runnostream << ThisName << "_1 Run " << cl->RunNumber()
0744               << ", Time: " << ctime(&evttime.first);
0745   runstring = runnostream.str();
0746   transparent[2]->cd();
0747   PrintRun.SetTextColor(evttime.second);
0748   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
0749   TC[2]->Update();
0750   TC[2]->Show();
0751   TC[2]->SetEditable(false);
0752   return 0;
0753 }
0754 
0755 int LocalPolMonDraw::DrawFourth(const std::string & /* what */)
0756 {
0757   OnlMonClient *cl = OnlMonClient::instance();
0758   
0759   if (!gROOT->FindObject("LocalPolMon4"))
0760   {
0761     MakeCanvas("LocalPolMon4");
0762   }
0763   TC[3]->SetEditable(true);
0764   TC[3]->Clear("D");
0765   gStyle->SetOptStat(0);
0766   TH1D* htrig[16];
0767   for(int i=0; i<16; i++){
0768     htrig[i]=(TH1D*)cl->getHisto("LOCALPOLMON_0",Form("h_trigger%d",i));
0769     if(!htrig[i]){
0770       DrawDeadServer(transparent[3]);
0771       TC[3]->SetEditable(false);
0772       return -1;
0773     }
0774     else{
0775       Pad[3][i]->cd();
0776       htrig[i]->SetFillColor(kBlue);
0777       htrig[i]->GetXaxis()->SetTitle("Bunch number");
0778       htrig[i]->GetYaxis()->SetTitle("Counts");
0779       htrig[i]->SetStats(kFALSE);
0780       htrig[i]->DrawCopy();
0781     }   
0782   }
0783   
0784   TC[3]->Update();
0785   TText PrintRun;
0786   PrintRun.SetTextFont(62);
0787   PrintRun.SetTextSize(0.04);
0788   PrintRun.SetNDC();          // set to normalized coordinates
0789   PrintRun.SetTextAlign(23);  // center/top alignment
0790   std::ostringstream runnostream;
0791   std::string runstring;
0792   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
0793   // fill run number and event time into string
0794   runnostream << ThisName << "_1 Run " << cl->RunNumber()
0795               << ", Time: " << ctime(&evttime.first);
0796   runstring = runnostream.str();
0797   transparent[3]->cd();
0798   PrintRun.SetTextColor(evttime.second);
0799   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
0800   TC[3]->Update();
0801   TC[3]->Show();
0802   TC[3]->SetEditable(false);
0803   return 0;
0804 }
0805 
0806 int LocalPolMonDraw::DrawFifth(const std::string & /* what */)
0807 {
0808   OnlMonClient *cl = OnlMonClient::instance();
0809   
0810   if (!gROOT->FindObject("LocalPolMon5"))
0811   {
0812     MakeCanvas("LocalPolMon5");
0813   }
0814   TC[4]->SetEditable(true);
0815   TC[4]->Clear("D");
0816   gStyle->SetOptStat(0);
0817 
0818   TH1D* htmp;
0819   Pad[4][0]->cd();
0820   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hmultiplicitySMD_NH");
0821   if(!htmp){
0822     DrawDeadServer(transparent[4]);
0823     TC[4]->SetEditable(false);
0824     return -1;
0825   }
0826   else{
0827     htmp->GetXaxis()->SetTitle("North-SMD hor. multiplicity");
0828     htmp->GetYaxis()->SetTitle("Counts");
0829     htmp->SetStats(kFALSE);
0830     htmp->DrawCopy();
0831   }
0832   Pad[4][1]->cd();
0833   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hmultiplicitySMD_NV");
0834   if(!htmp){
0835     DrawDeadServer(transparent[4]);
0836     TC[4]->SetEditable(false);
0837     return -1;
0838   }
0839   else{
0840     htmp->GetXaxis()->SetTitle("North-SMD ver. multiplicity");
0841     htmp->GetYaxis()->SetTitle("Counts");
0842     htmp->SetStats(kFALSE);
0843     htmp->DrawCopy();
0844   }
0845   Pad[4][2]->cd();
0846   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hmultiplicitySMD_SH");
0847   if(!htmp){
0848     DrawDeadServer(transparent[4]);
0849     TC[4]->SetEditable(false);
0850     return -1;
0851   }
0852   else{
0853     htmp->GetXaxis()->SetTitle("South-SMD hor. multiplicity");
0854     htmp->GetYaxis()->SetTitle("Counts");
0855     htmp->SetStats(kFALSE);
0856     htmp->DrawCopy();
0857   }
0858   Pad[4][3]->cd();
0859   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hmultiplicitySMD_SV");
0860   if(!htmp){
0861     DrawDeadServer(transparent[4]);
0862     TC[4]->SetEditable(false);
0863     return -1;
0864   }
0865   else{
0866     htmp->GetXaxis()->SetTitle("South-SMD ver. multiplicity");
0867     htmp->GetYaxis()->SetTitle("Counts");
0868     htmp->SetStats(kFALSE);
0869     htmp->DrawCopy();
0870   }
0871 
0872   Pad[4][4]->cd();
0873   Pad[4][4]->cd()->SetLogy();
0874   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hadcsumSMD_NH");
0875   if(!htmp){
0876     DrawDeadServer(transparent[4]);
0877     TC[4]->SetEditable(false);
0878     return -1;
0879   }
0880   else{
0881     htmp->GetXaxis()->SetTitle("North-SMD hor. sum ADC");
0882     htmp->GetYaxis()->SetTitle("Counts");
0883     htmp->SetStats(kFALSE);
0884     htmp->DrawCopy();
0885   }
0886   Pad[4][5]->cd();
0887   Pad[4][5]->cd()->SetLogy();
0888   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hadcsumSMD_NV");
0889   if(!htmp){
0890     DrawDeadServer(transparent[4]);
0891     TC[4]->SetEditable(false);
0892     return -1;
0893   }
0894   else{
0895     htmp->GetXaxis()->SetTitle("North-SMD ver. sum ADC");
0896     htmp->GetYaxis()->SetTitle("Counts");
0897     htmp->SetStats(kFALSE);
0898     htmp->DrawCopy();
0899   }
0900   Pad[4][6]->cd();
0901   Pad[4][6]->cd()->SetLogy();
0902   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hadcsumSMD_SH");
0903   if(!htmp){
0904     DrawDeadServer(transparent[4]);
0905     TC[4]->SetEditable(false);
0906     return -1;
0907   }
0908   else{
0909     htmp->GetXaxis()->SetTitle("South-SMD hor. sum ADC");
0910     htmp->GetYaxis()->SetTitle("Counts");
0911     htmp->SetStats(kFALSE);
0912     htmp->DrawCopy();
0913   }
0914   Pad[4][7]->cd();
0915   Pad[4][7]->cd()->SetLogy();
0916   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hadcsumSMD_SV");
0917   if(!htmp){
0918     DrawDeadServer(transparent[4]);
0919     TC[4]->SetEditable(false);
0920     return -1;
0921   }
0922   else{
0923     htmp->GetXaxis()->SetTitle("South-SMD ver. sum ADC");
0924     htmp->GetYaxis()->SetTitle("Counts");
0925     htmp->SetStats(kFALSE);
0926     htmp->DrawCopy();
0927   }
0928 
0929   Pad[4][8]->cd();
0930   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hpositionSMD_NH_up");
0931   if(!htmp){
0932     DrawDeadServer(transparent[4]);
0933     TC[4]->SetEditable(false);
0934     return -1;
0935   }
0936   else{
0937     htmp->SetLineColor(kRed);
0938     htmp->GetXaxis()->SetTitle("y-North-SMD [cm]");
0939     htmp->GetYaxis()->SetTitle("Counts");
0940     htmp->SetStats(kFALSE);
0941     htmp->DrawCopy();
0942   }
0943   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hpositionSMD_NH_dn");
0944   if(!htmp){
0945     DrawDeadServer(transparent[4]);
0946     TC[4]->SetEditable(false);
0947     return -1;
0948   }
0949   else{
0950     htmp->SetLineColor(kBlue);
0951     htmp->SetStats(kFALSE);
0952     htmp->DrawCopy("same");
0953   }
0954   Pad[4][9]->cd();
0955   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hpositionSMD_NV_up");
0956   if(!htmp){
0957     DrawDeadServer(transparent[4]);
0958     TC[4]->SetEditable(false);
0959     return -1;
0960   }
0961   else{
0962     htmp->SetLineColor(kRed);
0963     htmp->GetXaxis()->SetTitle("x-North-SMD [cm]");
0964     htmp->GetYaxis()->SetTitle("Counts");
0965     htmp->SetStats(kFALSE);
0966     htmp->DrawCopy();
0967   }
0968   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hpositionSMD_NV_dn");
0969   if(!htmp){
0970     DrawDeadServer(transparent[4]);
0971     TC[4]->SetEditable(false);
0972     return -1;
0973   }
0974   else{
0975     htmp->SetLineColor(kBlue);
0976     htmp->SetStats(kFALSE);
0977     htmp->DrawCopy("same");
0978   }
0979   Pad[4][10]->cd();
0980   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hpositionSMD_SH_up");
0981   if(!htmp){
0982     DrawDeadServer(transparent[4]);
0983     TC[4]->SetEditable(false);
0984     return -1;
0985   }
0986   else{
0987     htmp->SetLineColor(kRed);
0988     htmp->GetXaxis()->SetTitle("y-South-SMD [cm]");
0989     htmp->GetYaxis()->SetTitle("Counts");
0990     htmp->SetStats(kFALSE);
0991     htmp->DrawCopy();
0992   }
0993   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hpositionSMD_SH_dn");
0994   if(!htmp){
0995     DrawDeadServer(transparent[4]);
0996     TC[4]->SetEditable(false);
0997     return -1;
0998   }
0999   else{
1000     htmp->SetLineColor(kBlue);
1001     htmp->SetStats(kFALSE);
1002     htmp->DrawCopy("same");
1003   }
1004   Pad[4][11]->cd();
1005   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hpositionSMD_SV_up");
1006   if(!htmp){
1007     DrawDeadServer(transparent[4]);
1008     TC[4]->SetEditable(false);
1009     return -1;
1010   }
1011   else{
1012     htmp->SetLineColor(kRed);
1013     htmp->GetXaxis()->SetTitle("x-South-SMD [cm]");
1014     htmp->GetYaxis()->SetTitle("Counts");
1015     htmp->SetStats(kFALSE);
1016     htmp->DrawCopy();
1017   }
1018   htmp=(TH1D*)cl->getHisto("LOCALPOLMON_0","hpositionSMD_SV_dn");
1019   if(!htmp){
1020     DrawDeadServer(transparent[4]);
1021     TC[4]->SetEditable(false);
1022     return -1;
1023   }
1024   else{
1025     htmp->SetLineColor(kBlue);
1026     htmp->SetStats(kFALSE);
1027     htmp->DrawCopy("same");
1028   }
1029 
1030 
1031   TC[4]->Update();
1032   TText PrintRun;
1033   PrintRun.SetTextFont(62);
1034   PrintRun.SetTextSize(0.04);
1035   PrintRun.SetNDC();          // set to normalized coordinates
1036   PrintRun.SetTextAlign(23);  // center/top alignment
1037   std::ostringstream runnostream;
1038   std::string runstring;
1039   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1040   // fill run number and event time into string
1041   runnostream << ThisName << "_2 Run " << cl->RunNumber()
1042               << ", Time: " << ctime(&evttime.first);
1043   runstring = runnostream.str();
1044   transparent[4]->cd();
1045   PrintRun.SetTextColor(evttime.second);
1046   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
1047   TC[4]->Update();
1048   TC[4]->Show();
1049   TC[4]->SetEditable(false);
1050   return 0;
1051 }
1052 
1053 int LocalPolMonDraw::DrawSixth(const std::string & /* what */)
1054 {
1055   OnlMonClient *cl = OnlMonClient::instance();
1056   
1057   if (!gROOT->FindObject("LocalPolMon6"))
1058   {
1059     MakeCanvas("LocalPolMon6");
1060   }
1061   TC[5]->SetEditable(true);
1062   TC[5]->Clear("D");
1063   gStyle->SetOptStat(0);
1064   for(int i=0; i<6; i++){
1065     Pad[5][i]->cd();
1066     Pad[5][i]->cd()->SetLogz();
1067     TH2D* h2=(TH2D*)cl->getHisto("LOCALPOLMON_0",Form("hwaveform%d",i));
1068     if(!h2){
1069       DrawDeadServer(transparent[5]);
1070       TC[5]->SetEditable(false);
1071       return -1;
1072     }
1073     else{
1074       h2->GetXaxis()->SetTitle("Sample #");
1075       h2->GetYaxis()->SetTitle("ADC counts");
1076       h2->SetStats(kFALSE);
1077       h2->DrawCopy("colz");
1078     }
1079   }
1080   TC[5]->Update();
1081   TText PrintRun;
1082   PrintRun.SetTextFont(62);
1083   PrintRun.SetTextSize(0.04);
1084   PrintRun.SetNDC();          // set to normalized coordinates
1085   PrintRun.SetTextAlign(23);  // center/top alignment
1086   std::ostringstream runnostream;
1087   std::string runstring;
1088   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1089   // fill run number and event time into string
1090   runnostream << ThisName << "_5 Run " << cl->RunNumber()
1091               << ", Time: " << ctime(&evttime.first);
1092   runstring = runnostream.str();
1093   transparent[5]->cd();
1094   PrintRun.SetTextColor(evttime.second);
1095   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
1096   TC[5]->Update();
1097   TC[5]->Show();
1098   TC[5]->SetEditable(false);
1099   return 0;
1100 }
1101 
1102 int LocalPolMonDraw::DrawSeventh(const std::string & /* what */)
1103 {
1104   OnlMonClient *cl = OnlMonClient::instance();
1105   
1106   if (!gROOT->FindObject("LocalPolMon7"))
1107   {
1108     MakeCanvas("LocalPolMon7");
1109   }
1110   TC[6]->SetEditable(true);
1111   TC[6]->Clear("D");
1112   gStyle->SetOptStat(0);
1113   TH1D* hsyncfrac=(TH1D*)cl->getHisto("LOCALPOLMON_0","hsyncfrac");
1114   TH1D* hevent=(TH1D*)cl->getHisto("LOCALPOLMON_0","h_events");
1115   if(!hsyncfrac){
1116     DrawDeadServer(transparent[6]);
1117     TC[6]->SetEditable(false);
1118     return -1;
1119   }
1120   else{
1121     Pad[6][0]->cd();
1122     Pad[6][0]->SetLogy();
1123     if(hevent){
1124       if(hevent->GetBinContent(2)){
1125     hsyncfrac->Scale(1./hevent->GetBinContent(2));
1126       }
1127     }
1128     hsyncfrac->GetXaxis()->SetBinLabel(1,"dropped events");
1129     hsyncfrac->GetXaxis()->SetBinLabel(2,"sync events");
1130     hsyncfrac->GetYaxis()->SetTitle("fraction %");
1131     hsyncfrac->SetStats(kFALSE);
1132     hsyncfrac->DrawCopy();
1133   }
1134   TC[6]->Update();
1135   TText PrintRun;
1136   PrintRun.SetTextFont(62);
1137   PrintRun.SetTextSize(0.04);
1138   PrintRun.SetNDC();          // set to normalized coordinates
1139   PrintRun.SetTextAlign(23);  // center/top alignment
1140   std::ostringstream runnostream;
1141   std::string runstring;
1142   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1143   // fill run number and event time into string
1144   runnostream << ThisName << "_7 Run " << cl->RunNumber()
1145               << ", Time: " << ctime(&evttime.first);
1146   runstring = runnostream.str();
1147   transparent[6]->cd();
1148   PrintRun.SetTextColor(evttime.second);
1149   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
1150   TC[6]->Update();
1151   TC[6]->Show();
1152   TC[6]->SetEditable(false);
1153   return 0;
1154 }
1155 
1156 int LocalPolMonDraw::DrawEighth(const std::string & /* what */)
1157 {
1158   OnlMonClient *cl = OnlMonClient::instance();
1159   
1160   if (!gROOT->FindObject("LocalPolMon8"))
1161   {
1162     MakeCanvas("LocalPolMon8");
1163   }
1164   TC[7]->SetEditable(true);
1165   TC[7]->Clear("D");
1166   gStyle->SetOptStat(0);
1167   TH2D* h2d=nullptr;
1168   h2d=(TH2D*)cl->getHisto("LOCALPOLMON_0","Bluespace");
1169   if(!h2d){
1170     DrawDeadServer(transparent[7]);
1171     TC[7]->SetEditable(false);
1172     return -1;
1173   }
1174   else{
1175     Pad[7][0]->cd();
1176     h2d->GetXaxis()->SetTitle("SMD-North-x [cm]");
1177     h2d->GetYaxis()->SetTitle("SMD-North-y [cm]");
1178     h2d->SetStats(kFALSE);
1179     h2d->DrawCopy("colz");
1180   }
1181   h2d=(TH2D*)cl->getHisto("LOCALPOLMON_0","Yellowspace");
1182   if(!h2d){
1183     DrawDeadServer(transparent[7]);
1184     TC[7]->SetEditable(false);
1185     return -1;
1186   }
1187   else{
1188     Pad[7][1]->cd();
1189     h2d->GetXaxis()->SetTitle("SMD-South-x [cm]");
1190     h2d->GetYaxis()->SetTitle("SMD-South-y [cm]");
1191     h2d->SetStats(kFALSE);
1192     h2d->DrawCopy("colz");
1193   }
1194   TC[7]->Update();
1195   TText PrintRun;
1196   PrintRun.SetTextFont(62);
1197   PrintRun.SetTextSize(0.04);
1198   PrintRun.SetNDC();          // set to normalized coordinates
1199   PrintRun.SetTextAlign(23);  // center/top alignment
1200   std::ostringstream runnostream;
1201   std::string runstring;
1202   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1203   // fill run number and event time into string
1204   runnostream << ThisName << "_8 Run " << cl->RunNumber()
1205               << ", Time: " << ctime(&evttime.first);
1206   runstring = runnostream.str();
1207   transparent[7]->cd();
1208   PrintRun.SetTextColor(evttime.second);
1209   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
1210   TC[7]->Update();
1211   TC[7]->Show();
1212   TC[7]->SetEditable(false);
1213   return 0;
1214 }
1215 
1216 int LocalPolMonDraw::DrawNinth(const std::string & /* what */)
1217 {
1218   OnlMonClient *cl = OnlMonClient::instance();
1219   
1220   if (!gROOT->FindObject("LocalPolMon9"))
1221   {
1222     MakeCanvas("LocalPolMon9");
1223   }
1224   TC[8]->SetEditable(true);
1225   TC[8]->Clear("D");
1226   gStyle->SetOptStat(0);
1227   TH2D* hclocks=(TH2D*)cl->getHisto("LOCALPOLMON_0","hclocks");
1228   if(!hclocks){
1229     DrawDeadServer(transparent[8]);
1230     TC[8]->SetEditable(false);
1231     return -1;
1232   }
1233   else{
1234     Pad[8][0]->cd();
1235     hclocks->GetXaxis()->SetTitle("GL1 clock diff%8192");
1236     hclocks->GetYaxis()->SetTitle("ZDC clock diff%8192");
1237     hclocks->SetMarkerStyle(kFullCircle);
1238     hclocks->SetStats(kFALSE);
1239     //hclocks->Fit("pol1");
1240     hclocks->DrawCopy();
1241   }
1242   TC[8]->Update();
1243   TText PrintRun;
1244   PrintRun.SetTextFont(62);
1245   PrintRun.SetTextSize(0.04);
1246   PrintRun.SetNDC();          // set to normalized coordinates
1247   PrintRun.SetTextAlign(23);  // center/top alignment
1248   std::ostringstream runnostream;
1249   std::string runstring;
1250   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1251   // fill run number and event time into string
1252   runnostream << ThisName << "_9 Run " << cl->RunNumber()
1253               << ", Time: " << ctime(&evttime.first);
1254   runstring = runnostream.str();
1255   transparent[8]->cd();
1256   PrintRun.SetTextColor(evttime.second);
1257   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
1258   TC[8]->Update();
1259   TC[8]->Show();
1260   TC[8]->SetEditable(false);
1261   return 0;
1262 }
1263 
1264 
1265 int LocalPolMonDraw::SavePlot(const std::string &what, const std::string &type)
1266 {
1267   OnlMonClient *cl = OnlMonClient::instance();
1268   int iret = Draw(what);
1269   if (iret)  // on error no png files please
1270   {
1271     return iret;
1272   }
1273   int icnt = 0;
1274   for (TCanvas *canvas : TC)
1275   {
1276     if (canvas == nullptr)
1277     {
1278       continue;
1279     }
1280     icnt++;
1281     std::string filename = ThisName + "_" + std::to_string(icnt) + "_" +
1282                            std::to_string(cl->RunNumber()) + "." + type;
1283     cl->CanvasToPng(canvas, filename);
1284   }
1285   return 0;
1286 }
1287 
1288 int LocalPolMonDraw::MakeHtml(const std::string &what)
1289 {
1290   int iret = Draw(what);
1291   if (iret)  // on error no html output please
1292   {
1293     return iret;
1294   }
1295 
1296   OnlMonClient *cl = OnlMonClient::instance();
1297 
1298   int icnt = 0;
1299   for (TCanvas *canvas : TC)
1300   {
1301     if (canvas == nullptr)
1302     {
1303       continue;
1304     }
1305     icnt++;
1306     // Register the canvas png file to the menu and produces the png file.
1307     std::string pngfile = cl->htmlRegisterPage(*this, canvas->GetTitle(), std::to_string(icnt), "png");
1308     cl->CanvasToPng(canvas, pngfile);
1309   }
1310   //// Register the 1st canvas png file to the menu and produces the png file.
1311   //std::string pngfile = cl->htmlRegisterPage(*this, "First Canvas", "1", "png");
1312   //cl->CanvasToPng(TC[0], pngfile);
1313   //
1314   //// idem for 2nd canvas.
1315   //pngfile = cl->htmlRegisterPage(*this, "Second Canvas", "2", "png");
1316   //cl->CanvasToPng(TC[1], pngfile);
1317 
1318   return 0;
1319 }