Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "TpcMonDraw.h"
0002 
0003 #include <onlmon/OnlMonClient.h>
0004 
0005 #include <TAxis.h>  // for TAxis
0006 #include <TCanvas.h>
0007 #include <TDatime.h>
0008 #include <TGraphErrors.h>
0009 #include <TH1.h>
0010 #include <TH2.h>
0011 #include <TF1.h>
0012 #include <TPad.h>
0013 #include <TROOT.h>
0014 #include <TSystem.h>
0015 #include <TText.h>
0016 #include <TMath.h>
0017 #include <TPaveLabel.h>
0018 #include <TPaveText.h>
0019 #include <TStyle.h>
0020 #include <TString.h>
0021 #include <TLegend.h>
0022 #include <TLatex.h>
0023 #include <TLine.h>
0024 #include <TEllipse.h>
0025 
0026 #include <cstring>  // for memset
0027 #include <ctime>
0028 #include <fstream>
0029 #include <iostream>  // for operator<<, basic_ostream, basic_os...
0030 #include <sstream>
0031 #include <limits>
0032 #include <vector>  // for vector
0033 
0034 #include <cmath>
0035 #include <cstdio>  // for printf
0036 #include <string>  // for allocator, string, char_traits
0037 
0038 TpcMonDraw::TpcMonDraw(const std::string &name)
0039   : OnlMonDraw(name)
0040 {
0041   return;
0042 }
0043 
0044 int TpcMonDraw::Init()
0045 {
0046   return 0;
0047 }
0048 
0049 int TpcMonDraw::MakeCanvas(const std::string &name)
0050 {
0051   OnlMonClient *cl = OnlMonClient::instance();
0052   int xsize = cl->GetDisplaySizeX();
0053   int ysize = cl->GetDisplaySizeY();
0054   if (name == "TPCModules")
0055   {
0056     TC[0] = new TCanvas(name.c_str(), "ADC Count by GEM Example", -1, 0, 1350, 700);
0057     gSystem->ProcessEvents();
0058     TC[0]->Divide(2,1);
0059     //gStyle->SetPalette(57); //kBird CVD friendly
0060     // this one is used to plot the run number on the canvas
0061     transparent[0] = new TPad("transparent0", "this does not show", 0, 0, 1, 1);
0062     transparent[0]->SetFillStyle(4000);
0063     transparent[0]->Draw();
0064     TC[0]->SetEditable(false);
0065   }
0066   else if (name == "TPCSampleSize")
0067   {
0068     TC[1] = new TCanvas(name.c_str(), "TPC Sample Size Distribution in Events", -1, 0, xsize , ysize );
0069     gSystem->ProcessEvents();
0070     TC[1]->Divide(4,7);
0071     transparent[1] = new TPad("transparent1", "this does not show", 0, 0, 1, 1);
0072     transparent[1]->SetFillStyle(4000);
0073     transparent[1]->Draw();
0074     TC[1]->SetEditable(false);
0075   }
0076   else if (name == "TPCCheckSumError")
0077   {
0078     TC[2] = new TCanvas(name.c_str(), "TPC CheckSumError Probability in Events",-1, 0, xsize , ysize );
0079     gSystem->ProcessEvents();
0080     TC[2]->Divide(4,7);
0081     transparent[2] = new TPad("transparent2", "this does not show", 0, 0, 1, 1);
0082     transparent[2]->SetFillStyle(4000);
0083     transparent[2]->Draw();
0084     TC[2]->SetEditable(false);
0085   }
0086   else if (name == "TPCADCSample")
0087   {
0088     TC[3] = new TCanvas(name.c_str(), "TPC ADC vs Sample in Whole Sector",-1, 0, xsize , ysize);
0089     gSystem->ProcessEvents();
0090     //gStyle->SetPalette(57); //kBird CVD friendly
0091     TC[3]->Divide(4,7);
0092     transparent[3] = new TPad("transparent3", "this does not show", 0, 0, 1, 1);
0093     transparent[3]->SetFillStyle(4000);
0094     transparent[3]->Draw();
0095     TC[3]->SetEditable(false);
0096   }
0097   else if (name == "TPCMaxADCModule")
0098   {
0099     TC[4] = new TCanvas(name.c_str(), "(MAX ADC - pedestal) in SLIDING WINDOW for each Module in Sector", -1, 0, xsize , ysize);
0100     gSystem->ProcessEvents();
0101     //gStyle->SetPalette(57); //kBird CVD friendly
0102     TC[4]->Divide(4,7);
0103     transparent[4] = new TPad("transparent4", "this does not show", 0, 0, 1, 1);
0104     transparent[4]->SetFillStyle(4000);
0105     transparent[4]->Draw();
0106     TC[4]->SetEditable(false);
0107   }
0108   else if (name == "TPCRawADC1D")
0109   {
0110     TC[5] = new TCanvas(name.c_str(), "TPC RAW ADC 1D distribution", -1, 0, xsize , ysize);
0111     gSystem->ProcessEvents();
0112     //gStyle->SetPalette(57); //kBird CVD friendly
0113     TC[5]->Divide(4,7);
0114     transparent[5] = new TPad("transparent5", "this does not show", 0, 0, 1, 1);
0115     transparent[5]->SetFillStyle(4000);
0116     transparent[5]->Draw();
0117     TC[5]->SetEditable(false);
0118   }
0119   else if (name == "TPCMaxADC1D")
0120   {
0121     TC[6] = new TCanvas(name.c_str(), "(MAX ADC - pedestal) in SLIDING WINDOW 1D distribution",-1, 0, xsize , ysize);
0122     gSystem->ProcessEvents();
0123     //gStyle->SetPalette(57); //kBird CVD friendly
0124     TC[6]->Divide(4,7);
0125     transparent[6] = new TPad("transparent6", "this does not show", 0, 0, 1, 1);
0126     transparent[6]->SetFillStyle(4000);
0127     transparent[6]->Draw();
0128     TC[6]->SetEditable(false);
0129   }
0130   else if (name == "TPCClusterXY")
0131   {
0132     TC[7] = new TCanvas(name.c_str(), "(MAX ADC - pedestal)>  (20 ADC || 5sigma) for NS and SS, WEIGHTED", -1, 0, 1350, 700);
0133     gSystem->ProcessEvents();
0134     //gStyle->SetPalette(57); //kBird CVD friendly
0135     TC[7]->Divide(2,1);
0136     // this one is used to plot the run number on the canvas
0137     transparent[7] = new TPad("transparent7", "this does not show", 0, 0, 1, 1);
0138     transparent[7]->SetFillStyle(4000);
0139     transparent[7]->Draw();
0140     TC[7]->SetEditable(false);
0141   }
0142   else if (name == "TPCClusterXY_unw")
0143   {
0144     TC[8] = new TCanvas(name.c_str(), "(MAX ADC - pedestal)>  (20 ADC || 5sigma) for NS and SS, UNWEIGHTED", -1, 0, 1350, 700);
0145     gSystem->ProcessEvents();
0146     //gStyle->SetPalette(57); //kBird CVD friendly
0147     TC[8]->Divide(2,1);
0148     // this one is used to plot the run number on the canvas
0149     transparent[8] = new TPad("transparent8", "this does not show", 0, 0, 1, 1);
0150     transparent[8]->SetFillStyle(4000);
0151     transparent[8]->Draw();
0152     TC[8]->SetEditable(false);
0153   }
0154   else if (name == "TPCADCSamplelarge")
0155   {
0156     TC[9] = new TCanvas(name.c_str(), "TPC ADC vs Large Sample in Whole Sector",-1, 0, xsize , ysize);
0157     gSystem->ProcessEvents();
0158     //gStyle->SetPalette(57); //kBird CVD friendly
0159     TC[9]->Divide(4,7);
0160     transparent[9] = new TPad("transparent9", "this does not show", 0, 0, 1, 1);
0161     transparent[9]->SetFillStyle(4000);
0162     transparent[9]->Draw();
0163     TC[9]->SetEditable(false);
0164   }
0165 
0166   else if (name == "TPCClusterZY")
0167   {
0168     TC[10] = new TCanvas(name.c_str(), "(MAX ADC - pedestal)> (20 ADC || 5sigma) for NS and SS, WEIGHTED", -1, 0, 1350, 700);
0169     gSystem->ProcessEvents();
0170     //gStyle->SetPalette(57); //kBird CVD friendly
0171     TC[10]->Divide(1,1);
0172     // this one is used to plot the run number on the canvas
0173     transparent[10] = new TPad("transparent10", "this does not show", 0, 0, 1, 1);
0174     transparent[10]->SetFillStyle(4000);
0175     transparent[10]->Draw();
0176     TC[10]->SetEditable(false);
0177   }
0178 
0179   else if (name == "TPCClusterZY_unw")
0180   {
0181     TC[11] = new TCanvas(name.c_str(), "(MAX ADC - pedestal)> (20 ADC || 5sigma) for NS and SS, UNWEIGHTED", -1, 0, 1350, 700);
0182     gSystem->ProcessEvents();
0183     //gStyle->SetPalette(57); //kBird CVD friendly
0184     TC[11]->Divide(1,1);
0185     // this one is used to plot the run number on the canvas
0186     transparent[11] = new TPad("transparent11", "this does not show", 0, 0, 1, 1);
0187     transparent[11]->SetFillStyle(4000);
0188     transparent[11]->Draw();
0189     TC[11]->SetEditable(false);
0190   }
0191 
0192   else if (name == "TPCLayerPhi")
0193   {
0194     TC[12] = new TCanvas(name.c_str(), "Layer vs Channel Phi for NS and SS, WEIGHTED by Sum(ADC-pedestal)", -1, 0, 1350,700);
0195     gSystem->ProcessEvents();
0196     //gStyle->SetPalette(57); //kBird CVD friendly
0197     TC[12]->Divide(1,1);
0198     // this one is used to plot the run number on the canvas
0199     transparent[12] = new TPad("transparent12", "this does not show", 0, 0, 1, 1);
0200     transparent[12]->SetFillStyle(4000);
0201     transparent[12]->Draw();
0202     TC[12]->SetEditable(false);
0203   }
0204   else if (name == "TPCPedestSubADC1D")
0205   {
0206     TC[13] = new TCanvas(name.c_str(), "TPC PEDEST SUB ADC 1D distribution", -1, 0, xsize , ysize);
0207     gSystem->ProcessEvents();
0208     //gStyle->SetPalette(57); //kBird CVD friendly
0209     TC[13]->Divide(4,7);
0210     transparent[13] = new TPad("transparent13", "this does not show", 0, 0, 1, 1);
0211     transparent[13]->SetFillStyle(4000);
0212     transparent[13]->Draw();
0213     TC[13]->SetEditable(false);
0214   }
0215   else if (name == "TPCNEventsEBDC")
0216   {
0217     TC[14] = new TCanvas(name.c_str(), "TPC NUMBER EVENTS vs EBDC",1350,700);
0218     gSystem->ProcessEvents();
0219     //gStyle->SetPalette(57); //kBird CVD friendly
0220     TC[14]->Divide(1,1);
0221     // this one is used to plot the run number on the canvas
0222     transparent[14] = new TPad("transparent14", "this does not show", 0, 0, 1, 1);
0223     transparent[14]->SetFillStyle(4000);
0224     transparent[14]->Draw();
0225     TC[14]->SetEditable(false);
0226   }
0227   else if (name == "TPCPedestSubADCSample")
0228   {
0229     TC[15] = new TCanvas(name.c_str(), "TPC PEDEST SUB ADC vs Sample in Whole Sector",-1, 0, xsize , ysize);
0230     gSystem->ProcessEvents();
0231     //gStyle->SetPalette(57); //kBird CVD friendly
0232     TC[15]->Divide(4,7);
0233     transparent[15] = new TPad("transparent15", "this does not show", 0, 0, 1, 1);
0234     transparent[15]->SetFillStyle(4000);
0235     transparent[15]->Draw();
0236     TC[15]->SetEditable(false);
0237   } 
0238   else if (name == "TPCPedestSubADCSample_R1")
0239   {
0240     TC[16] = new TCanvas(name.c_str(), "TPC PEDEST SUB ADC vs Sample in R1 ONLY",-1, 0, xsize , ysize);
0241     gSystem->ProcessEvents();
0242     //gStyle->SetPalette(57); //kBird CVD friendly
0243     TC[16]->Divide(4,7);
0244     transparent[16] = new TPad("transparent16", "this does not show", 0, 0, 1, 1);
0245     transparent[16]->SetFillStyle(4000);
0246     transparent[16]->Draw();
0247     TC[16]->SetEditable(false);
0248   }
0249   else if (name == "TPCPedestSubADCSample_R2")
0250   {
0251     TC[17] = new TCanvas(name.c_str(), "TPC PEDEST SUB ADC vs Sample in R2 ONLY",-1, 0, xsize , ysize);
0252     gSystem->ProcessEvents();
0253     //gStyle->SetPalette(57); //kBird CVD friendly
0254     TC[17]->Divide(4,7);
0255     transparent[17] = new TPad("transparent17", "this does not show", 0, 0, 1, 1);
0256     transparent[17]->SetFillStyle(4000);
0257     transparent[17]->Draw();
0258     TC[17]->SetEditable(false);
0259   }   
0260   else if (name == "TPCPedestSubADCSample_R3")
0261   {
0262     TC[18] = new TCanvas(name.c_str(), "TPC PEDEST SUB ADC vs Sample in R3 ONLY",-1, 0, xsize , ysize);
0263     gSystem->ProcessEvents();
0264     //gStyle->SetPalette(57); //kBird CVD friendly
0265     TC[18]->Divide(4,7);
0266     transparent[18] = new TPad("transparent18", "this does not show", 0, 0, 1, 1);
0267     transparent[18]->SetFillStyle(4000);
0268     transparent[18]->Draw();
0269     TC[18]->SetEditable(false);
0270   }
0271   else if (name == "TPCClusterXY_laser")
0272   {
0273     TC[19] = new TCanvas(name.c_str(), "(MAX ADC - pedestal)> (20 ADC || 5sigma) for NS and SS, LASER FLASH ONLY, WEIGHTED", -1, 0, 1350, 700);
0274     gSystem->ProcessEvents();
0275     //gStyle->SetPalette(57); //kBird CVD friendly
0276     TC[19]->Divide(2,1);
0277     // this one is used to plot the run number on the canvas
0278     transparent[19] = new TPad("transparent19", "this does not show", 0, 0, 1, 1);
0279     transparent[19]->SetFillStyle(4000);
0280     transparent[19]->Draw();
0281     TC[19]->SetEditable(false);
0282   }      
0283   else if (name == "TpcMonServerStats")
0284   {
0285     TC[20] = new TCanvas(name.c_str(), "TpcMon Server Stats", -1, 0, xsize, ysize);
0286     gSystem->ProcessEvents();
0287     transparent[20] = new TPad("transparent20", "this does not show", 0, 0, 1, 1);
0288     transparent[20]->Draw();
0289     transparent[20]->SetFillColor(kGray);
0290     TC[20]->SetEditable(false);
0291     TC[20]->SetTopMargin(0.05);
0292     TC[20]->SetBottomMargin(0.05);
0293   }
0294   else if (name == "TPCStuckChannels")
0295   {
0296     TC[21] = new TCanvas(name.c_str(), "TPC Stuck Channels in Events", -1, 0, xsize , ysize );
0297     gSystem->ProcessEvents();
0298     TC[21]->Divide(4,7);
0299     transparent[21] = new TPad("transparent21", "this does not show", 0, 0, 1, 1);
0300     transparent[21]->SetFillStyle(4000);
0301     transparent[21]->Draw();
0302     TC[21]->SetEditable(false);
0303   }
0304   else if (name == "TPCClusterXY_u5")
0305   {
0306     TC[22] = new TCanvas(name.c_str(), "(MAX ADC - pedestal)>  (20 ADC || 5sigma) for NS and SS, <= 5 EVENTS WEIGHTED", -1, 0, 1350, 700);
0307     gSystem->ProcessEvents();
0308     //gStyle->SetPalette(57); //kBird CVD friendly
0309     TC[22]->Divide(2,1);
0310     // this one is used to plot the run number on the canvas
0311     transparent[22] = new TPad("transparent22", "this does not show", 0, 0, 1, 1);
0312     transparent[22]->SetFillStyle(4000);
0313     transparent[22]->Draw();
0314     TC[22]->SetEditable(false);
0315   }     
0316   else if (name == "TPCChan_in_Packets_NS")
0317   {
0318     TC[23] = new TCanvas(name.c_str(), "TPC Channel Fraction Present in Packet in RCDAQ Event, NS ONLY", -1, 0, xsize , ysize );
0319     gSystem->ProcessEvents();
0320     TC[23]->Divide(2,7);
0321     transparent[23] = new TPad("transparent23", "this does not show", 0, 0, 1, 1);
0322     transparent[23]->SetFillStyle(4000);
0323     transparent[23]->Draw();
0324     TC[23]->SetEditable(false);
0325   }
0326   else if (name == "TPCChan_in_Packets_SS")
0327   {
0328     TC[24] = new TCanvas(name.c_str(), "TPC Channel Fraction Present in Packet in RCDAQ Event, sS ONLY", -1, 0, xsize , ysize );
0329     gSystem->ProcessEvents();
0330     TC[24]->Divide(2,7);
0331     transparent[24] = new TPad("transparent24", "this does not show", 0, 0, 1, 1);
0332     transparent[24]->SetFillStyle(4000);
0333     transparent[24]->Draw();
0334     TC[24]->SetEditable(false);
0335   }
0336   else if (name == "TPCNonZSChannels")
0337   {
0338     TC[25] = new TCanvas(name.c_str(), "TPC non ZS Channels in SAMPAs acrosss whole Sector",-1, 0, xsize , ysize);
0339     gSystem->ProcessEvents();
0340     //gStyle->SetPalette(57); //kBird CVD friendly
0341     TC[25]->Divide(4,7);
0342     transparent[25] = new TPad("transparent25", "this does not show", 0, 0, 1, 1);
0343     transparent[25]->SetFillStyle(4000);
0344     transparent[25]->Draw();
0345     TC[25]->SetEditable(false);
0346   }
0347   else if (name == "TPCNonZSTriggerADCvsSample")
0348   {
0349     TC[26] = new TCanvas(name.c_str(), "",-1, 0, xsize , ysize);
0350     gSystem->ProcessEvents();
0351     //gStyle->SetPalette(57); //kBird CVD friendly
0352     TC[26]->Divide(4,7);
0353     transparent[26] = new TPad("transparent26", "this does not show", 0, 0, 1, 1);
0354     transparent[26]->SetFillStyle(4000);
0355     transparent[26]->Draw();
0356     TC[26]->SetEditable(false);
0357   }
0358   else if (name == "TPCFirstADCvsFirstSample")
0359   {
0360     TC[27] = new TCanvas(name.c_str(), "",-1, 0, xsize , ysize);
0361     gSystem->ProcessEvents();
0362     //gStyle->SetPalette(57); //kBird CVD friendly
0363     TC[27]->Divide(4,7);
0364     transparent[27] = new TPad("transparent27", "this does not show", 0, 0, 1, 1);
0365     transparent[27]->SetFillStyle(4000);
0366     transparent[27]->Draw();
0367     TC[27]->SetEditable(false);
0368   }
0369   else if (name == "TPCDriftWindow")
0370   {
0371     TC[28] = new TCanvas(name.c_str(), "",-1, 0, xsize , ysize);
0372     gSystem->ProcessEvents();
0373     //gStyle->SetPalette(57); //kBird CVD friendly
0374     TC[28]->Divide(4,7);
0375     transparent[28] = new TPad("transparent28", "this does not show", 0, 0, 1, 1);
0376     transparent[28]->SetFillStyle(4000);
0377     transparent[28]->Draw();
0378     TC[28]->SetEditable(false);
0379   }
0380   else if (name == "TPCNStreakersvsEventNo")
0381   {
0382     TC[29] = new TCanvas(name.c_str(), "TPC Number of Horizontal Tracks vs Event No.", -1, 0, xsize , ysize );
0383     gSystem->ProcessEvents();
0384     TC[29]->Divide(1,2);
0385     transparent[29] = new TPad("transparent29", "this does not show", 0, 0, 1, 1);
0386     transparent[29]->SetFillStyle(4000);
0387     transparent[29]->Draw();
0388     TC[29]->SetEditable(false);
0389   }
0390   else if (name == "TPCPacketType")
0391   {
0392     TC[30] = new TCanvas(name.c_str(), "",-1, 0, xsize , ysize);
0393     gSystem->ProcessEvents();
0394     //gStyle->SetPalette(57); //kBird CVD friendly
0395     TC[30]->Divide(4,7);
0396     transparent[30] = new TPad("transparent30", "this does not show", 0, 0, 1, 1);
0397     transparent[30]->SetFillStyle(4000);
0398     transparent[30]->Draw();
0399     TC[30]->SetEditable(false);
0400   }
0401   else if (name == "TPCChan_per_LVL1_NS")
0402   {
0403     TC[31] = new TCanvas(name.c_str(), "TPC Channels per LVL_1 in RCDAQ Event, NS ONLY", -1, 0, xsize , ysize );
0404     gSystem->ProcessEvents();
0405     TC[31]->Divide(2,7);
0406     transparent[31] = new TPad("transparent31", "this does not show", 0, 0, 1, 1);
0407     transparent[31]->SetFillStyle(4000);
0408     transparent[31]->Draw();
0409     TC[31]->SetEditable(false);
0410   }
0411   else if (name == "TPCChan_per_LVL1_SS")
0412   {
0413     TC[32] = new TCanvas(name.c_str(), "TPC Channels per LVL_1 in RCDAQ Event, SS ONLY", -1, 0, xsize , ysize );
0414     gSystem->ProcessEvents();
0415     TC[32]->Divide(2,7);
0416     transparent[32] = new TPad("transparent32", "this does not show", 0, 0, 1, 1);
0417     transparent[32]->SetFillStyle(4000);
0418     transparent[32]->Draw();
0419     TC[32]->SetEditable(false);
0420   }
0421   else if (name == "TPCParityError")
0422   {
0423     TC[33] = new TCanvas(name.c_str(), "TPC CheckSumError Probability in Events",-1, 0, xsize , ysize );
0424     gSystem->ProcessEvents();
0425     TC[33]->Divide(4,7);
0426     transparent[33] = new TPad("transparent33", "this does not show", 0, 0, 1, 1);
0427     transparent[33]->SetFillStyle(4000);
0428     transparent[33]->Draw();
0429     TC[33]->SetEditable(false);
0430   }     
0431   else if (name == "ShifterTPCDriftWindow")
0432   {
0433     TC[34] = new TCanvas(name.c_str(), "TPC Drift Window for Shifter Checks",-1, 0, xsize , ysize );
0434     gSystem->ProcessEvents();
0435     TC[34]->Divide(4,7);
0436     transparent[34] = new TPad("transparent34", "this does not show", 0, 0, 1, 1);
0437     transparent[34]->SetFillStyle(4000);
0438     transparent[34]->Draw();
0439     TC[34]->SetEditable(false);
0440   }
0441   else if (name == "TPCNoiseChannelsPlots")
0442   {
0443     TC[35] = new TCanvas(name.c_str(), "Noise Channel Check for nonZS events w/ no load in TPC",-1, 0, xsize , ysize );
0444     gSystem->ProcessEvents();
0445     TC[35]->Divide(4,7);
0446     transparent[35] = new TPad("transparent35", "this does not show", 0, 0, 1, 1);
0447     transparent[35]->SetFillStyle(4000);
0448     transparent[35]->Draw();
0449     TC[35]->SetEditable(false);
0450   }
0451   else if (name == "ShifterTPCTransmissionDist")
0452   {
0453     TC[36] = new TCanvas(name.c_str(), "Background Corrected Tranmission Distribution",-1, 0, xsize , ysize );
0454     gSystem->ProcessEvents();
0455     TC[36]->Divide(1,1);
0456     transparent[36] = new TPad("transparent36", "this does not show", 0, 0, 1, 1);
0457     transparent[36]->SetFillStyle(4000);
0458     transparent[36]->Draw();
0459     TC[36]->SetEditable(false);
0460   }
0461   else if (name == "DC_vs_SAMPA_CANVAS")
0462   {
0463     std::cout << "creating TC[37]" << std::endl;
0464     TC[37] = new TCanvas(name.c_str(), "Digital Current vs SAMPA",-1, 0, xsize , ysize );
0465     gSystem->ProcessEvents();
0466     TC[37]->Divide(4,7);
0467     transparent[37] = new TPad("transparent37", "this does not show", 0, 0, 1, 1);
0468     transparent[37]->SetFillStyle(4000);
0469     transparent[37]->Draw();
0470     TC[37]->SetEditable(false);
0471   }      
0472   else if (name == "DC_SAMPA_vs_TIME_CANVAS")
0473   {
0474     TC[38] = new TCanvas(name.c_str(), "SAMPA vs TIME wtd. by Digital Current",-1, 0, xsize , ysize );
0475     gSystem->ProcessEvents();
0476     TC[38]->Divide(4,7);
0477     transparent[38] = new TPad("transparent38", "this does not show", 0, 0, 1, 1);
0478     transparent[38]->SetFillStyle(4000);
0479     transparent[38]->Draw();
0480     TC[38]->SetEditable(false);
0481   }
0482   else if (name == "TPCPACKETTYPE_vs_SAMPLE_ADC")
0483   {
0484     TC[39] = new TCanvas(name.c_str(), "",-1, 0, xsize , ysize);
0485     gSystem->ProcessEvents();
0486     //gStyle->SetPalette(57); //kBird CVD friendly
0487     TC[39]->Divide(4,7);
0488     transparent[39] = new TPad("transparent39", "this does not show", 0, 0, 1, 1);
0489     transparent[39]->SetFillStyle(4000);
0490     transparent[39]->Draw();
0491     TC[39]->SetEditable(false);
0492   }
0493   return 0;
0494 }
0495 
0496 int TpcMonDraw::Draw(const std::string &what)
0497 {
0498   int iret = 0;
0499   int idraw = 0;
0500   if (what == "ALL" || what == "TPCMODULE")
0501   {
0502     iret += DrawTPCModules(what);
0503     idraw++;
0504   }
0505   if (what == "ALL" || what == "TPCSAMPLESIZE")
0506   {
0507     iret += DrawTPCSampleSize(what);
0508     idraw++;
0509   }
0510   if (what == "ALL" || what == "TPCSTUCKCHANNELS")
0511   {
0512     iret += DrawTPCStuckChannels(what);
0513     idraw++; 
0514   }
0515   if (what == "ALL" || what == "TPCCHECKSUMERROR")
0516   {
0517     iret += DrawTPCCheckSum(what);
0518     idraw++;
0519   }
0520   if (what == "ALL" || what == "TPCPARITYERROR")
0521   {
0522     iret += DrawTPCParity(what);
0523     idraw++;
0524   }
0525   if (what == "ALL" || what == "TPCADCVSSAMPLE")
0526   {
0527     iret += DrawTPCADCSample(what);
0528     idraw++;
0529   }
0530   if (what == "ALL" || what == "TPCMAXADCMODULE")
0531   {
0532     iret += DrawTPCMaxADCModule(what);
0533     idraw++;
0534   }
0535   if (what == "ALL" || what == "TPCRAWADC1D")
0536   {
0537     iret += DrawTPCRawADC1D(what);
0538     idraw++;
0539   }
0540   if (what == "ALL" || what == "TPCMAXADC1D")
0541   {
0542     iret += DrawTPCMaxADC1D(what);
0543     idraw++;
0544   }
0545   if (what == "ALL" || what == "TPCCLUSTERSXYWEIGTHED")
0546   {
0547     iret += DrawTPCXYclusters(what);
0548     idraw++;
0549   }
0550   if (what == "ALL" || what == "TPCCLUSTERSXYUNWEIGTHED")
0551   {
0552     iret += DrawTPCXYclusters_unweighted(what);
0553     idraw++;
0554   }
0555   if (what == "ALL" || what == "TPCADCVSSAMPLELARGE")
0556   {
0557     iret += DrawTPCADCSampleLarge(what);
0558     idraw++;
0559   }
0560   if (what == "ALL" || what == "TPCCLUSTERSZYWEIGTHED")
0561   {
0562     iret += DrawTPCZYclusters(what);
0563     idraw++;
0564   }
0565   if (what == "ALL" || what == "TPCCLUSTERSZYUNWEIGTHED")
0566   {
0567     iret += DrawTPCZYclusters_unweighted(what);
0568     idraw++;
0569   }
0570   if (what == "ALL" || what == "TPCCHANNELPHI_LAYER_WEIGHTED")
0571   {
0572     iret += DrawTPCchannelphi_layer_weighted(what);
0573     idraw++;
0574   }
0575   if (what == "ALL" || what == "TPCPEDESTSUBADC1D")
0576   {
0577     iret += DrawTPCPedestSubADC1D(what);
0578     idraw++;
0579   }
0580   if (what == "ALL" || what == "TPCNEVENTSEBDC")
0581   {
0582     iret += DrawTPCNEventsvsEBDC(what);
0583     idraw++;
0584   } 
0585   if (what == "ALL" || what == "TPCPEDESTSUBADCVSSAMPLE")
0586   {
0587     iret += DrawTPCPedestSubADCSample(what);
0588     idraw++;
0589   }
0590   if (what == "ALL" || what == "TPCPEDESTSUBADCVSSAMPLE_R1" )
0591   {
0592     iret += DrawTPCPedestSubADCSample_R1(what);
0593     idraw++;
0594   }
0595   if (what == "ALL" || what == "TPCPEDESTSUBADCVSSAMPLE_R2" )
0596   {
0597     iret += DrawTPCPedestSubADCSample_R2(what);
0598     idraw++;
0599   }
0600   if (what == "ALL" || what == "TPCPEDESTSUBADCVSSAMPLE_R3" )
0601   {
0602     iret += DrawTPCPedestSubADCSample_R3(what);
0603     idraw++;
0604   }
0605   if (what == "ALL" || what == "TPCLASERCLUSTERSXYWEIGTHED")
0606   {
0607     iret += DrawTPCXYlaserclusters(what);
0608     idraw++;
0609   }
0610   if (what == "ALL" || what == "TPCCLUSTERS5EXYUNWEIGTHED")
0611   {
0612     iret +=  DrawTPCXYclusters5event(what);
0613     idraw++;
0614   }
0615   if (what == "ALL" || what == "TPCCHANSINPACKETNS")
0616   {
0617     iret +=  DrawTPCChansinPacketNS(what);
0618     idraw++;
0619   }
0620   if (what == "ALL" || what == "TPCCHANSINPACKETSS")
0621   {
0622     iret +=  DrawTPCChansinPacketSS(what);
0623     idraw++;
0624   }
0625   if (what == "ALL" || what == "TPCCHANSPERLVL1NS")
0626   {
0627     iret +=  DrawTPCChansperLVL1_NS(what);
0628     idraw++;
0629   }
0630   if (what == "ALL" || what == "TPCCHANSPERLVL1SS")
0631   {
0632     iret +=  DrawTPCChansperLVL1_SS(what);
0633     idraw++;
0634   }
0635   if (what == "ALL" || what == "TPCNONZSCHANNELS")
0636   {
0637     iret += DrawTPCNonZSChannels(what);
0638     idraw++;
0639   }
0640   if (what == "ALL" || what == "TPCZSTRIGGERADCVSSAMPLE")
0641   {
0642     iret += DrawTPCZSTriggerADCSample(what);
0643     idraw++;
0644   }
0645   if (what == "ALL" || what == "TPCFIRSTNONZSADCVSFIRSTNONZSSAMPLE")
0646   {
0647     iret +=  DrawTPCFirstnonZSADCFirstnonZSSample(what);
0648     idraw++;
0649   }
0650   if (what == "ALL" || what == "TPCDRIFTWINDOW")
0651   {
0652     iret +=  DrawTPCDriftWindow(what);  
0653     idraw++;
0654   }
0655   if (what == "ALL" || what == "SERVERSTATS")
0656   {
0657     iret += DrawServerStats();
0658     idraw++;
0659   }
0660   if (what == "ALL" || what == "TPCNSTREAKERSVSEVENTNO")
0661   {
0662     iret += DrawTPCNStreaksvsEventNo(what);
0663     idraw++;
0664   }
0665   if (what == "ALL" || what == "TPCPACKETYPEFRACTION")
0666   {
0667     iret +=  DrawTPCPacketTypes(what);
0668     idraw++;
0669   }
0670   if (what == "ALL" || what == "TPCPACKETTYPEVSSAMPLEADC")
0671   {
0672     iret +=  DrawTPCPACKETTYPEvsSAMPLEADC(what);
0673     idraw++;
0674   }
0675   if (what == "ALL" || what == "SHIFTER_DRIFT_PLOT")
0676   {
0677     iret += DrawShifterTPCDriftWindow(what);
0678     idraw++;
0679   }
0680   if (what == "ALL" || what == "TPCNOISECHANNELPLOTS")
0681   {
0682     iret += DrawTPCNoiseChannelPlots(what);
0683     idraw++;
0684   }
0685   if (what == "ALL" || what == "SHIFTER_TRANSMISSION_PLOT")
0686   {
0687     iret += DrawShifterTransmissionDist(what); 
0688     idraw++;
0689   }
0690   if (what == "ALL" || what == "TPCDCVSSAMPA")
0691   {
0692     iret +=  DrawDCvsSAMPA(what);
0693     idraw++;
0694   }
0695   if (what == "ALL" || what == "TPCDCSAMPAVSTIME")
0696   {
0697     iret += DrawDCSAMPAvsTIME(what);
0698     idraw++;
0699   }
0700   if (!idraw)
0701   {
0702     std::cout << __PRETTY_FUNCTION__ << " Unimplemented Drawing option: " << what << std::endl;
0703     iret = -1;
0704   }
0705   return iret;
0706 }
0707 
0708 int TpcMonDraw::DrawTPCModules(const std::string & /* what */)
0709 {
0710   OnlMonClient *cl = OnlMonClient::instance();
0711   TH2 *tpcmon_NSIDEADC_u[48] = {nullptr};
0712   TH2 *tpcmon_SSIDEADC_u[48] = {nullptr};
0713 
0714   TH2 *tpcmon_NSIDEADC[24] = {nullptr};
0715   TH2 *tpcmon_SSIDEADC[24] = {nullptr};
0716   
0717   char TPCMON_STR[100];
0718   // TPC ADC pie chart
0719   for( int i=0; i<48; i++ ) 
0720   {
0721     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
0722     sprintf(TPCMON_STR,"TPCMON_%i",i);
0723     tpcmon_NSIDEADC_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC");
0724     tpcmon_SSIDEADC_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC");
0725   }
0726 
0727   add_TH2(tpcmon_NSIDEADC_u, tpcmon_NSIDEADC);
0728   add_TH2(tpcmon_SSIDEADC_u, tpcmon_SSIDEADC);
0729   
0730   //TH2 *tpcmon_NSIDEADC1 = (TH2*) cl->getHisto("TPCMON_0","NorthSideADC");
0731   //TH2 *tpcmon_SSIDEADC1 = (TH2*) cl->getHisto("TPCMON_0","SouthSideADC");
0732 
0733   if (!gROOT->FindObject("TPCModules"))
0734   {
0735     MakeCanvas("TPCModules");
0736   }
0737 
0738   TCanvas *MyTC = TC[0];
0739   TPad *TransparentTPad = transparent[0];
0740 
0741   dummy_his1 = new TH2F("dummy_his1", "ADC Counts North Side", 100, -1.5, 1.5, 100, -1.5, 1.5); //dummy histos for titles
0742   dummy_his2 = new TH2F("dummy_his2", "ADC Counts South Side", 100, -1.5, 1.5, 100, -1.5, 1.5);
0743 
0744   //labels
0745   NS18 = new TPaveLabel( 1.046586,-0.1938999,1.407997,0.2144871, "18" );
0746   NS17 = new TPaveLabel( 0.962076,0.4382608,1.323487,0.8466479 , "17" );
0747   NS16 = new TPaveLabel( 0.4801947,0.8802139,0.8416056,1.288601 , "16" );
0748   NS15 = new TPaveLabel( -0.1823921,1.011681,0.1790189,1.425662, "15" );
0749   NS14 = new TPaveLabel( -0.8449788,0.8690253,-0.4835679,1.288601 , "14" );
0750   NS13 = new TPaveLabel( -1.30879,0.441058,-0.9473786,0.8550394 , "13" );
0751   NS12 = new TPaveLabel( -1.411009,-0.2050886,-1.049598,0.2144871, "12" );
0752   NS23 = new TPaveLabel( -1.302585,-0.7757116,-0.9471979,-0.3561359 , "23" );
0753   NS22 = new TPaveLabel( -0.8449788,-1.309971,-0.4835679,-0.8848013 , "22" );
0754   NS21 = new TPaveLabel( -0.1823921,-1.426557,0.1790189,-1.006982 , "21" );
0755   NS20 = new TPaveLabel( 0.4801947,-1.309076,0.8416056,-0.8839062 , "20" );
0756   NS19 = new TPaveLabel( 0.9622567,-0.7785088,1.323668,-0.3533387 , "19" );
0757 
0758   SS00 = new TPaveLabel( 1.046586,-0.1938999,1.407997,0.2144871, "00" );
0759   SS01 = new TPaveLabel( 0.962076,0.4382608,1.323487,0.8466479 , "01" );
0760   SS02 = new TPaveLabel( 0.4801947,0.8802139,0.8416056,1.288601 , "02" );
0761   SS03 = new TPaveLabel( -0.1823921,1.011681,0.1790189,1.425662, "03" );
0762   SS04 = new TPaveLabel( -0.8449788,0.8690253,-0.4835679,1.288601 , "04" );
0763   SS05 = new TPaveLabel( -1.30879,0.441058,-0.9473786,0.8550394 , "05" );
0764   SS06 = new TPaveLabel( -1.411009,-0.2050886,-1.049598,0.2144871, "06" );
0765   SS07 = new TPaveLabel( -1.302585,-0.7757116,-0.9471979,-0.3561359 , "07" );
0766   SS08 = new TPaveLabel( -0.8449788,-1.309971,-0.4835679,-0.8848013 , "08" );
0767   SS09 = new TPaveLabel( -0.1823921,-1.426557,0.1790189,-1.006982 , "09" );
0768   SS10 = new TPaveLabel( 0.4801947,-1.309076,0.8416056,-0.8839062 , "10" );
0769   SS11 = new TPaveLabel( 0.9622567,-0.7785088,1.323668,-0.3533387 , "11" );
0770 
0771   NS18->SetFillColor(0);
0772   NS17->SetFillColor(0);
0773   NS16->SetFillColor(0);
0774   NS15->SetFillColor(0);
0775   NS14->SetFillColor(0);
0776   NS13->SetFillColor(0);
0777   NS12->SetFillColor(0);
0778   NS23->SetFillColor(0);
0779   NS22->SetFillColor(0);
0780   NS21->SetFillColor(0);
0781   NS20->SetFillColor(0);
0782   NS19->SetFillColor(0);
0783 
0784   SS00->SetFillColor(0);
0785   SS01->SetFillColor(0);
0786   SS02->SetFillColor(0);
0787   SS03->SetFillColor(0);
0788   SS04->SetFillColor(0);
0789   SS05->SetFillColor(0);
0790   SS06->SetFillColor(0);
0791   SS07->SetFillColor(0);
0792   SS08->SetFillColor(0);
0793   SS09->SetFillColor(0);
0794   SS10->SetFillColor(0);
0795   SS11->SetFillColor(0);
0796 
0797   MyTC->SetEditable(true);
0798   MyTC->Clear("D");
0799   MyTC->cd(1);
0800   gPad->SetTopMargin(0.15);
0801   gStyle->SetOptStat(0);
0802   dummy_his1->Draw("colpolzsame");
0803  
0804   float NS_max = 0;
0805   for( int i=0; i<12; i++ )
0806   {
0807     if( tpcmon_NSIDEADC[i] ){
0808     MyTC->cd(1);
0809     tpcmon_NSIDEADC[i] -> DrawCopy("colpolzsame");
0810     if( tpcmon_NSIDEADC[i]->GetBinContent(tpcmon_NSIDEADC[i]->GetMaximumBin()) > NS_max)
0811     {
0812       NS_max = tpcmon_NSIDEADC[i]->GetBinContent(tpcmon_NSIDEADC[i]->GetMaximumBin());
0813       dummy_his1->SetMaximum( NS_max );
0814     }
0815     gStyle->SetPalette(57); //kBird CVD friendly
0816     }
0817 
0818   }
0819   MyTC->Update();
0820   MyTC->cd(1);
0821   SS00->Draw("same");
0822   SS01->Draw("same");
0823   SS02->Draw("same");
0824   SS03->Draw("same");
0825   SS04->Draw("same");
0826   SS05->Draw("same");
0827   SS06->Draw("same");
0828   SS07->Draw("same");
0829   SS08->Draw("same");
0830   SS09->Draw("same");
0831   SS10->Draw("same");
0832   SS11->Draw("same");
0833 
0834   MyTC->cd(2);
0835   gPad->SetTopMargin(0.15);
0836   gStyle->SetOptStat(0);
0837   dummy_his2->Draw("colpolzsame");
0838 
0839   float SS_max = 0;
0840   for( int i=0; i<12; i++ )
0841   {
0842     if( tpcmon_SSIDEADC[i+12] ){
0843     //std::cout<<"tpcmon_SSIDEADC i: "<< i+12 <<std::endl;
0844     MyTC->cd(2);
0845     tpcmon_SSIDEADC[i+12] -> DrawCopy("colpolzsame");
0846 
0847     if ( tpcmon_SSIDEADC[i+12]->GetBinContent(tpcmon_SSIDEADC[i+12]->GetMaximumBin()) > SS_max)
0848     {
0849       SS_max = tpcmon_SSIDEADC[i+12]->GetBinContent(tpcmon_SSIDEADC[i+12]->GetMaximumBin());
0850       dummy_his2->SetMaximum( SS_max );
0851     }
0852 
0853     gStyle->SetPalette(57); //kBird CVD friendly
0854     }
0855   }
0856   MyTC->Update();
0857 
0858   MyTC->cd(2);
0859   NS18->Draw("same");
0860   NS17->Draw("same");
0861   NS16->Draw("same");
0862   NS15->Draw("same");
0863   NS14->Draw("same");
0864   NS13->Draw("same");
0865   NS12->Draw("same");
0866   NS23->Draw("same");
0867   NS22->Draw("same");
0868   NS21->Draw("same");
0869   NS20->Draw("same");
0870   NS19->Draw("same");
0871 
0872 
0873   TText PrintRun;
0874   PrintRun.SetTextFont(62);
0875   PrintRun.SetTextSize(0.04);
0876   PrintRun.SetNDC();          // set to normalized coordinates
0877   PrintRun.SetTextAlign(23);  // center/top alignment
0878   std::ostringstream runnostream;
0879   std::string runstring;
0880   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
0881   // fill run number and event time into string
0882   runnostream << ThisName << "_SUMADC Run " << cl->RunNumber()
0883               << ", Time: " << ctime(&evttime.first);
0884   runstring = runnostream.str();
0885   TransparentTPad->cd();
0886   PrintRun.SetTextColor(evttime.second);
0887   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
0888 
0889   //turn off stats box
0890   //dummy_his1->SetStats(0);
0891   //dummy_his2->SetStats(0);
0892   
0893   MyTC->Update();
0894 
0895 
0896 
0897   MyTC->Show();
0898   MyTC->SetEditable(false);
0899   
0900   return 0;
0901 }
0902 
0903 int TpcMonDraw::DrawTPCSampleSize(const std::string & /* what */)
0904 {
0905   OnlMonClient *cl = OnlMonClient::instance();
0906 
0907   TH1 *tpcmon_samplesizedist_u[48] = {nullptr};
0908   TH1 *tpcmon_samplesizedist[24] = {nullptr};
0909 
0910   char TPCMON_STR[100];
0911   for( int i=0; i<48; i++ ) 
0912   {
0913     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
0914     sprintf(TPCMON_STR,"TPCMON_%i",i);
0915     tpcmon_samplesizedist_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"sample_size_hist");
0916   }
0917 
0918   add_TH1(tpcmon_samplesizedist_u, tpcmon_samplesizedist);
0919   
0920   if (!gROOT->FindObject("TPCSampleSize"))
0921   {
0922     MakeCanvas("TPCSampleSize");
0923   }
0924   TCanvas *MyTC = TC[1];
0925   TPad *TransparentTPad = transparent[1];
0926   MyTC->SetEditable(true);
0927   MyTC->Clear("D");
0928   for( int i=0; i<24; i++ ) 
0929   {
0930     if( tpcmon_samplesizedist[i] )
0931     {
0932       MyTC->cd(i+5);
0933       tpcmon_samplesizedist[i]->DrawCopy("");
0934       gPad->SetLogx(kTRUE);
0935       gPad->SetLogy(kTRUE);
0936     }
0937   }
0938 
0939   TText PrintRun;
0940   PrintRun.SetTextFont(62);
0941   PrintRun.SetTextSize(0.04);
0942   PrintRun.SetNDC();          // set to normalized coordinates
0943   PrintRun.SetTextAlign(23);  // center/top alignment
0944   std::ostringstream runnostream;
0945   std::string runstring;
0946   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
0947   // fill run number and event time into string
0948   runnostream << ThisName << "_SampleSize Run " << cl->RunNumber()
0949               << ", Time: " << ctime(&evttime.first);
0950   runstring = runnostream.str();
0951   TransparentTPad->cd();
0952   PrintRun.SetTextColor(evttime.second);
0953   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
0954 
0955   MyTC->Update();
0956   MyTC->SetLogx();
0957   MyTC->Show();
0958   MyTC->SetEditable(false);
0959 
0960   return 0;
0961 }
0962 
0963 int TpcMonDraw::DrawTPCCheckSum(const std::string & /* what */)
0964 {
0965 
0966   OnlMonClient *cl = OnlMonClient::instance();
0967   
0968   TH1 *tpcmon_checksumerror[24] = {nullptr};
0969   TH1 *tpcmon_checksums[24] = {nullptr};
0970 
0971   TH1 *tpcmon_checksumerror_u[48] = {nullptr};
0972   TH1 *tpcmon_checksums_u[48] = {nullptr};
0973   
0974   char TPCMON_STR[100];
0975   for( int i=0; i<48; i++ ) 
0976   {
0977     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
0978     sprintf(TPCMON_STR,"TPCMON_%i",i);
0979     tpcmon_checksumerror_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Check_Sum_Error");
0980     tpcmon_checksums_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Check_Sums");
0981   }
0982 
0983   add_TH1(tpcmon_checksumerror_u, tpcmon_checksumerror);
0984   add_TH1(tpcmon_checksums_u, tpcmon_checksums);
0985   
0986   if (!gROOT->FindObject("TPCCheckSumError"))
0987   {
0988     MakeCanvas("TPCCheckSumError");
0989   }
0990   TCanvas *MyTC = TC[2];
0991   TPad *TransparentTPad = transparent[2];
0992 
0993   MyTC->SetEditable(true);
0994   MyTC->Clear("D");
0995   MyTC->cd(1);
0996 
0997   TLine *t1 = new TLine(); t1->SetLineWidth(2);
0998   TLine *t2 = new TLine(); t2->SetLineStyle(2);
0999   TText *tt1= new TText(); tt1->SetTextSize(0.05);
1000 
1001   int FEEid[26]={2,4,3,13,17,16, // R1
1002                  11,12,19,18,0,1,15,14, // R2
1003                  20,22,21,23,25,24,10,9,8,6,7,5 // R3
1004                 };
1005 
1006   char title[50];
1007 
1008   for( int i=0; i<24; i++ )
1009   {
1010     if( tpcmon_checksumerror[i] && tpcmon_checksums[i] )
1011     {
1012       MyTC->cd(i+5);
1013 
1014       tpcmon_checksumerror[i]->Divide(tpcmon_checksums[i]);
1015       tpcmon_checksumerror[i]->GetYaxis()->SetRangeUser(0.0001,1.5);
1016       tpcmon_checksumerror[i]->DrawCopy("HIST");
1017     
1018       MyTC->Update();
1019 
1020       for(int j=0;j<25;j++)
1021       {
1022         t2->DrawLine((j+1)*8,-0.01,(j+1)*8,1.5);
1023       }
1024       for(int k=0;k<26;k++)
1025       {
1026         sprintf(title,"%d",FEEid[k]);
1027         tt1->DrawText(k*8+4,1.2,title);
1028       }
1029       tt1->SetTextSize(0.06);
1030       tt1->DrawText(25,1.4,"R1");
1031       tt1->DrawText(77,1.4,"R2");
1032       tt1->DrawText(163,1.4,"R3");
1033       tt1->SetTextSize(0.05); 
1034 
1035       t1->DrawLine(48.5,-0.01,48.5,1.5);
1036       t1->DrawLine(112.5,-0.01,112.5,1.5);
1037 
1038     }
1039   }
1040 
1041   TText PrintRun;
1042   PrintRun.SetTextFont(62);
1043   PrintRun.SetTextSize(0.04);
1044   PrintRun.SetNDC();          // set to normalized coordinates
1045   PrintRun.SetTextAlign(23);  // center/top alignment
1046   std::ostringstream runnostream;
1047   std::string runstring;
1048   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1049   // fill run number and event time into string
1050   runnostream << ThisName << "_CheckSumError Run " << cl->RunNumber()
1051               << ", Time: " << ctime(&evttime.first);
1052   runstring = runnostream.str();
1053   TransparentTPad->cd();
1054   PrintRun.SetTextColor(evttime.second);
1055   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
1056 
1057   MyTC->Update();
1058   //MyTC->SetLogy();
1059   MyTC->Show();
1060   MyTC->SetEditable(false);
1061 
1062 
1063   return 0;
1064 }
1065 
1066 int TpcMonDraw::DrawTPCADCSample(const std::string & /* what */)
1067 {
1068   OnlMonClient *cl = OnlMonClient::instance();
1069 
1070   TH2 *tpcmon_ADCSAMPLE[24] = {nullptr};
1071   TH2 *tpcmon_ADCSAMPLE_u[48] = {nullptr};
1072   
1073   char TPCMON_STR[100];
1074   for( int i=0; i<48; i++ ) 
1075   {
1076     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
1077     sprintf(TPCMON_STR,"TPCMON_%i",i);
1078     tpcmon_ADCSAMPLE_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"ADC_vs_SAMPLE");
1079   }
1080 
1081   add_TH2(tpcmon_ADCSAMPLE_u, tpcmon_ADCSAMPLE);
1082 
1083   if (!gROOT->FindObject("TPCADCSample"))
1084   {
1085     MakeCanvas("TPCADCSample");
1086   }  
1087 
1088   TCanvas *MyTC = TC[3];
1089   TPad *TransparentTPad = transparent[3];
1090 
1091   MyTC->SetEditable(true);
1092   MyTC->Clear("D");
1093 
1094   for( int i=0; i<24; i++ )
1095   {
1096     if( tpcmon_ADCSAMPLE[i] )
1097     {
1098       MyTC->cd(i+5);
1099       gStyle->SetPalette(57); //kBird CVD friendly
1100       gPad->SetLogz(kTRUE);
1101       tpcmon_ADCSAMPLE[i] -> DrawCopy("colz");
1102     }
1103   }
1104 
1105   TText PrintRun;
1106   PrintRun.SetTextFont(62);
1107   PrintRun.SetTextSize(0.04);
1108   PrintRun.SetNDC();          // set to normalized coordinates
1109   PrintRun.SetTextAlign(23);  // center/top alignment
1110   std::ostringstream runnostream;
1111   std::string runstring;
1112   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1113   // fill run number and event time into string
1114   runnostream << ThisName << "_ADC_vs_SAMPLE Run " << cl->RunNumber()
1115               << ", Time: " << ctime(&evttime.first);
1116   runstring = runnostream.str();
1117   TransparentTPad->cd();
1118   PrintRun.SetTextColor(evttime.second);
1119   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
1120 
1121 
1122   MyTC->Update();
1123   MyTC->Show();
1124   MyTC->SetEditable(false);
1125 
1126   return 0;
1127 }
1128 
1129 int TpcMonDraw::DrawTPCMaxADCModule(const std::string & /* what */)
1130 {
1131   OnlMonClient *cl = OnlMonClient::instance();
1132 
1133   TH2 *tpcmon_MAXADC_MODULE[24] = {nullptr};
1134   TH2 *tpcmon_MAXADC_MODULE_u[48] = {nullptr};
1135   
1136   char TPCMON_STR[100];
1137   for( int i=0; i<48; i++ ) 
1138   {
1139     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
1140     sprintf(TPCMON_STR,"TPCMON_%i",i);
1141     tpcmon_MAXADC_MODULE_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"MAXADC");
1142   }
1143 
1144   add_TH2(tpcmon_MAXADC_MODULE_u, tpcmon_MAXADC_MODULE);
1145   
1146   if (!gROOT->FindObject("TPCMaxADCModule"))
1147   {
1148     MakeCanvas("TPCMaxADCModule");
1149   }  
1150 
1151   TCanvas *MyTC = TC[4];
1152   TPad *TransparentTPad = transparent[4];
1153 
1154   MyTC->SetEditable(true);
1155   MyTC->Clear("D");
1156 
1157   for( int i=0; i<24; i++ )
1158   {
1159     if( tpcmon_MAXADC_MODULE[i] )
1160     {
1161       MyTC->cd(i+5);
1162       gStyle->SetPalette(57); //kBird CVD friendly
1163       gPad->SetLogz(kTRUE);
1164       tpcmon_MAXADC_MODULE[i] -> DrawCopy("colz");
1165     }
1166   }
1167 
1168   TText PrintRun;
1169   PrintRun.SetTextFont(62);
1170   PrintRun.SetTextSize(0.04);
1171   PrintRun.SetNDC();          // set to normalized coordinates
1172   PrintRun.SetTextAlign(23);  // center/top alignment
1173   std::ostringstream runnostream;
1174   std::string runstring;
1175   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1176   // fill run number and event time into string
1177   runnostream << ThisName << "_MAXADC2D Run " << cl->RunNumber()
1178               << ", Time: " << ctime(&evttime.first);
1179   runstring = runnostream.str();
1180   TransparentTPad->cd();
1181   PrintRun.SetTextColor(evttime.second);
1182   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
1183 
1184 
1185 
1186   MyTC->Update();
1187   MyTC->Show();
1188   MyTC->SetEditable(false);
1189 
1190   return 0;
1191 }
1192 
1193 int TpcMonDraw::DrawTPCRawADC1D(const std::string & /* what */)
1194 {
1195   //std::cout<<"Made it inside DrawTPCRawADC1D"<<std::endl;
1196   OnlMonClient *cl = OnlMonClient::instance();
1197 
1198   TH1 *tpcmon_RAWADC1D[24][3] = {nullptr};
1199   TH1 *tpcmon_RAWADC1D_u[48][3] = {nullptr};
1200   
1201   char TPCMON_STR[100];
1202   for( int i=0; i<48; i++ ) 
1203   {
1204     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
1205     sprintf(TPCMON_STR,"TPCMON_%i",i);
1206     tpcmon_RAWADC1D_u[i][0] = (TH1*) cl->getHisto(TPCMON_STR,"RAWADC_1D_R1");
1207     tpcmon_RAWADC1D_u[i][1] = (TH1*) cl->getHisto(TPCMON_STR,"RAWADC_1D_R2");
1208     tpcmon_RAWADC1D_u[i][2] = (TH1*) cl->getHisto(TPCMON_STR,"RAWADC_1D_R3");
1209   }
1210 
1211   add_TH1_modules( tpcmon_RAWADC1D_u, tpcmon_RAWADC1D );
1212 
1213 
1214   if (!gROOT->FindObject("TPCRawADC1D"))
1215   {
1216     MakeCanvas("TPCRawADC1D");
1217   }  
1218 
1219   TCanvas *MyTC = TC[5];
1220   TPad *TransparentTPad = transparent[5];
1221 
1222   MyTC->SetEditable(true);
1223   MyTC->Clear("D");
1224 
1225   auto legend = new TLegend(0.7,0.65,0.98,0.95);
1226   bool draw_leg = 0;
1227 
1228   for( int i=0; i<24; i++ )
1229   {
1230     MyTC->cd(i+5);
1231     for( int j = 2; j>-1; j-- )
1232     {
1233       if( tpcmon_RAWADC1D[i][j] )
1234       {
1235         if(j == 2){tpcmon_RAWADC1D[i][j] -> DrawCopy("HIST");}
1236         else      {tpcmon_RAWADC1D[i][j] -> DrawCopy("HISTsame");} //assumes that R3 will always exist and is most entries
1237       }
1238     }
1239     gPad->Update();
1240     gPad->SetLogy(kTRUE);  
1241 
1242     if(draw_leg == 0 && tpcmon_RAWADC1D[i][0] && tpcmon_RAWADC1D[i][1] && tpcmon_RAWADC1D[i][2]) //if you have not drawn the legend yet, draw it BUT ONLY ONCE
1243     {
1244       legend->AddEntry(tpcmon_RAWADC1D[i][0], "R1");
1245       legend->AddEntry(tpcmon_RAWADC1D[i][1], "R2");
1246       legend->AddEntry(tpcmon_RAWADC1D[i][2], "R3");
1247       MyTC->cd(i+5);
1248       legend->Draw();
1249       draw_leg = 1; //don't draw it again
1250     }
1251   }
1252 
1253   TText PrintRun;
1254   PrintRun.SetTextFont(62);
1255   PrintRun.SetTextSize(0.04);
1256   PrintRun.SetNDC();          // set to normalized coordinates
1257   PrintRun.SetTextAlign(23);  // center/top alignment
1258   std::ostringstream runnostream;
1259   std::string runstring;
1260   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1261   // fill run number and event time into string
1262   runnostream << ThisName << "_RAWADC Run " << cl->RunNumber()
1263               << ", Time: " << ctime(&evttime.first);
1264   runstring = runnostream.str();
1265   TransparentTPad->cd();
1266   PrintRun.SetTextColor(evttime.second);
1267   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
1268 
1269   MyTC->Update();
1270   MyTC->Show();
1271   MyTC->SetEditable(false);
1272 
1273   return 0;
1274 }
1275 
1276 int TpcMonDraw::DrawTPCMaxADC1D(const std::string & /* what */)
1277 {
1278   //std::cout<<"Made it inside DrawTPCMaxADC1D"<<std::endl;
1279   OnlMonClient *cl = OnlMonClient::instance();
1280 
1281   TH1 *tpcmon_MAXADC1D[24][3] = {nullptr};
1282   TH1 *tpcmon_MAXADC1D_u[48][3] = {nullptr};
1283   
1284   char TPCMON_STR[100];
1285   for( int i=0; i<48; i++ ) 
1286   {
1287     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
1288     sprintf(TPCMON_STR,"TPCMON_%i",i);
1289     tpcmon_MAXADC1D_u[i][0] = (TH1*) cl->getHisto(TPCMON_STR,"MAXADC_1D_R1");
1290     tpcmon_MAXADC1D_u[i][1] = (TH1*) cl->getHisto(TPCMON_STR,"MAXADC_1D_R2");
1291     tpcmon_MAXADC1D_u[i][2] = (TH1*) cl->getHisto(TPCMON_STR,"MAXADC_1D_R3");
1292   }
1293 
1294   add_TH1_modules(tpcmon_MAXADC1D_u, tpcmon_MAXADC1D);
1295 
1296   if (!gROOT->FindObject("TPCMaxADC1D"))
1297   {
1298     MakeCanvas("TPCMaxADC1D");
1299   }  
1300 
1301   TCanvas *MyTC = TC[6];
1302   TPad *TransparentTPad = transparent[6];
1303 
1304   MyTC->SetEditable(true);
1305   MyTC->Clear("D");
1306 
1307   auto legend = new TLegend(0.7,0.65,0.98,0.95);
1308   bool draw_leg = 0;
1309 
1310   for( int i=0; i<24; i++ )
1311   {
1312     MyTC->cd(i+5);
1313     for( int j = 2; j>-1; j-- )
1314     {
1315       if( tpcmon_MAXADC1D[i][j] )
1316       {
1317         if(j == 2){tpcmon_MAXADC1D[i][j] -> DrawCopy("HIST");}
1318         else      {tpcmon_MAXADC1D[i][j] -> DrawCopy("HISTsame");} //assumes that R3 will always exist and is max
1319       }
1320     }
1321     gPad->Update();
1322     gPad->SetLogy(kTRUE);
1323      
1324     if(draw_leg == 0 && tpcmon_MAXADC1D[i][0] && tpcmon_MAXADC1D[i][1] && tpcmon_MAXADC1D[i][2]) //if you have not drawn the legend yet, draw it BUT ONLY ONCE
1325     {
1326       MyTC->cd(i+5);
1327       legend->AddEntry(tpcmon_MAXADC1D[i][0], "R1");
1328       legend->AddEntry(tpcmon_MAXADC1D[i][1], "R2");
1329       legend->AddEntry(tpcmon_MAXADC1D[i][2], "R3");
1330       legend->Draw();
1331       draw_leg = 1; //don't draw it again
1332     }
1333   }
1334 
1335   TText PrintRun;
1336   PrintRun.SetTextFont(62);
1337   PrintRun.SetTextSize(0.04);
1338   PrintRun.SetNDC();          // set to normalized coordinates
1339   PrintRun.SetTextAlign(23);  // center/top alignment
1340   std::ostringstream runnostream;
1341   std::string runstring;
1342   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1343   // fill run number and event time into string
1344   runnostream << ThisName << "_LOCALMAXADC-PEDESTAL Run " << cl->RunNumber()
1345               << ", Time: " << ctime(&evttime.first);
1346   runstring = runnostream.str();
1347   TransparentTPad->cd();
1348   PrintRun.SetTextColor(evttime.second);
1349   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
1350 
1351 
1352   MyTC->Update();
1353   MyTC->Show();
1354   MyTC->SetEditable(false);
1355   
1356   return 0;
1357 }
1358 int TpcMonDraw::DrawTPCXYclusters(const std::string & /* what */)
1359 {
1360   OnlMonClient *cl = OnlMonClient::instance();
1361 
1362   TH2 *tpcmon_NSTPC_clusXY[24][3] = {nullptr};
1363   TH2 *tpcmon_SSTPC_clusXY[24][3] = {nullptr};
1364 
1365   TH2 *tpcmon_NSTPC_clusXY_u[48][3] = {nullptr};
1366   TH2 *tpcmon_SSTPC_clusXY_u[48][3] = {nullptr};  
1367   
1368   dummy_his1_XY = new TH2F("dummy_his1_XY", "(ADC-Pedestal) > (5#sigma||20ADC) North Side, WEIGHTED", 400, -800, 800, 400, -800, 800); //dummy histos for titles
1369   dummy_his2_XY = new TH2F("dummy_his2_XY", "(ADC-Pedestal) > (5#sigma||20ADC) South Side, WEIGHTED", 400, -800, 800, 400, -800, 800);
1370 
1371   dummy_his1_XY->SetXTitle("X [mm]");
1372   dummy_his1_XY->SetYTitle("Y [mm]");
1373   dummy_his1_XY->GetYaxis()->SetTitleSize(0.02);
1374 
1375   dummy_his2_XY->SetXTitle("-X [mm]"); //SS x is flipped from global coordinates
1376   dummy_his2_XY->SetYTitle("Y [mm]");
1377   dummy_his2_XY->GetYaxis()->SetTitleSize(0.02);
1378 
1379   //the lines are for the sector boundaries
1380   Double_t sec_gap_inner = (2*M_PI - 0.5024*12.0)/12.0;
1381 
1382   Double_t sec_gap_outer = (2*M_PI - 0.5097*12.0)/12.0;
1383 
1384   Double_t sec_gap = (sec_gap_inner + sec_gap_outer)/2.0;
1385 
1386   Double_t sec_phi = (0.5024 + 0.5097)/2.0;
1387 
1388   TLine *lines[12];
1389 
1390   for(int ln=0;ln<12;ln++)
1391   {
1392     lines[ln] = new TLine(311.05*cos((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)),311.05*sin((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)),759.11*cos((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)),759.11*sin((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)));
1393   }
1394 
1395   TEllipse *e1 = new TEllipse(0.0,0.0,311.05,311.05);
1396   TEllipse *e2 = new TEllipse(0.0,0.0,(402.49+411.53)/2.0,(402.49+411.53)/2.0);
1397   TEllipse *e3 = new TEllipse(0.0,0.0,(583.67+574.75)/2.0,(583.67+574.75)/2.0);
1398   TEllipse *e4 = new TEllipse(0.0,0.0,759.11,759.11);
1399   //__________________
1400 
1401   char TPCMON_STR[100];
1402   for( int i=0; i<48; i++ ) 
1403   {
1404     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
1405     sprintf(TPCMON_STR,"TPCMON_%i",i);
1406     tpcmon_NSTPC_clusXY_u[i][0] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC_clusterXY_R1");
1407     tpcmon_NSTPC_clusXY_u[i][1] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC_clusterXY_R2");
1408     tpcmon_NSTPC_clusXY_u[i][2] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC_clusterXY_R3");
1409 
1410     tpcmon_SSTPC_clusXY_u[i][0] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC_clusterXY_R1");
1411     tpcmon_SSTPC_clusXY_u[i][1] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC_clusterXY_R2");
1412     tpcmon_SSTPC_clusXY_u[i][2] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC_clusterXY_R3");
1413   }
1414 
1415   add_TH2_modules(tpcmon_NSTPC_clusXY_u, tpcmon_NSTPC_clusXY);
1416   add_TH2_modules(tpcmon_SSTPC_clusXY_u, tpcmon_SSTPC_clusXY);
1417   
1418   if (!gROOT->FindObject("TPCClusterXY"))
1419   {
1420     MakeCanvas("TPCClusterXY");
1421   }
1422 
1423   TCanvas *MyTC = TC[7];
1424   TPad *TransparentTPad = transparent[7];
1425 
1426   MyTC->SetEditable(true);
1427   MyTC->Clear("D");
1428 
1429   TText PrintRun;
1430   PrintRun.SetTextFont(62);
1431   PrintRun.SetTextSize(0.04);
1432   PrintRun.SetNDC();          // set to normalized coordinates
1433   PrintRun.SetTextAlign(23);  // center/top alignment
1434   std::ostringstream runnostream;
1435   std::string runstring;
1436   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1437   // fill run number and event time into string
1438   runnostream << ThisName << "_ADC-Pedestal>(5sigma||20ADC) WEIGHTED, Run" << cl->RunNumber()
1439               << ", Time: " << ctime(&evttime.first);
1440   runstring = runnostream.str();
1441   TransparentTPad->cd();
1442   PrintRun.SetTextColor(evttime.second);
1443   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
1444 
1445   MyTC->cd(1);
1446   gStyle->SetOptStat(kFALSE);
1447   gPad->SetTopMargin(0.15);
1448   gPad->SetLogz(kTRUE);
1449   dummy_his1_XY->Draw("colzsame");
1450 
1451   float NS_max = 0;
1452   for( int i=0; i<12; i++ )
1453   {
1454     for( int j=0; j<3; j++ )
1455     {
1456       if( tpcmon_NSTPC_clusXY[i][j] )
1457       {
1458         MyTC->cd(1);
1459         tpcmon_NSTPC_clusXY[i][j] -> Draw("colzsame");
1460         //gStyle->SetLogz(kTRUE);
1461         if ( tpcmon_NSTPC_clusXY[i][j]->GetBinContent(tpcmon_NSTPC_clusXY[i][j]->GetMaximumBin()) > NS_max)
1462         {
1463           NS_max = tpcmon_NSTPC_clusXY[i][j]->GetBinContent(tpcmon_NSTPC_clusXY[i][j]->GetMaximumBin());
1464           dummy_his1_XY->SetMaximum( NS_max );
1465         }
1466         gStyle->SetPalette(57); //kBird CVD friendly
1467       }
1468 
1469     }
1470   }
1471   MyTC->cd(1);
1472   e1->SetFillStyle(0);
1473   e2->SetFillStyle(0);
1474   e3->SetFillStyle(0);
1475   e4->SetFillStyle(0);
1476 
1477   e1->Draw("same");
1478   e2->Draw("same");
1479   e3->Draw("same");
1480   e4->Draw("same");
1481   for(int ln2=0;ln2<12;ln2++)
1482   {
1483     lines[ln2]->Draw("same"); 
1484   }
1485   MyTC->Update();
1486 
1487   MyTC->cd(2);
1488   gStyle->SetOptStat(kFALSE);
1489   gPad->SetTopMargin(0.15);
1490   gPad->SetLogz(kTRUE);
1491   dummy_his2_XY->Draw("colzsame");
1492 
1493   float SS_max = 0;
1494   for( int i=0; i<12; i++ )
1495   {
1496     for( int j=0; j<3; j++ )
1497     {
1498       if( tpcmon_SSTPC_clusXY[i+12][j] )
1499       {
1500         //std::cout<<"South Side Custer XY i: "<< i+12 <<", j: "<<j<<std::endl;
1501         MyTC->cd(2);
1502         tpcmon_SSTPC_clusXY[i+12][j] -> Draw("colzsame");
1503         //gStyle->SetLogz(kTRUE);
1504         if ( tpcmon_SSTPC_clusXY[i+12][j]->GetBinContent(tpcmon_SSTPC_clusXY[i+12][j]->GetMaximumBin()) > SS_max)
1505         {
1506           SS_max = tpcmon_SSTPC_clusXY[i+12][j]->GetBinContent(tpcmon_SSTPC_clusXY[i+12][j]->GetMaximumBin());
1507           dummy_his2_XY->SetMaximum( SS_max );
1508         }
1509         gStyle->SetPalette(57); //kBird CVD friendly
1510       }
1511     }
1512 
1513   }
1514   MyTC->cd(2);
1515   e1->SetFillStyle(0);
1516   e2->SetFillStyle(0);
1517   e3->SetFillStyle(0);
1518   e4->SetFillStyle(0);
1519 
1520   e1->Draw("same");
1521   e2->Draw("same");
1522   e3->Draw("same");
1523   e4->Draw("same");
1524   for(int ln2=0;ln2<12;ln2++)
1525   {
1526     lines[ln2]->Draw("same"); 
1527   }
1528 
1529   MyTC->Update();
1530   MyTC->Show();
1531   MyTC->SetEditable(false);
1532 
1533   return 0;
1534 }
1535 
1536 int TpcMonDraw::DrawTPCXYclusters_unweighted(const std::string & /* what */)
1537 {
1538   OnlMonClient *cl = OnlMonClient::instance();
1539 
1540   TH2 *tpcmon_NSTPC_clusXY[24][3] = {nullptr};
1541   TH2 *tpcmon_SSTPC_clusXY[24][3] = {nullptr};
1542 
1543   TH2 *tpcmon_NSTPC_clusXY_u[48][3] = {nullptr};
1544   TH2 *tpcmon_SSTPC_clusXY_u[48][3] = {nullptr};
1545   
1546   dummy_his1_XY_unw = new TH2F("dummy_his1_XY_unw", "(ADC-Pedestal) > (5#sigma||20ADC) North Side, UNWEIGHTED", 400, -800, 800, 400, -800, 800); //dummy histos for titles
1547   dummy_his2_XY_unw = new TH2F("dummy_his2_XY_unw", "(ADC-Pedestal) > (5#sigma||20ADC) South Side, UNWEIGHTED", 400, -800, 800, 400, -800, 800);
1548 
1549   dummy_his1_XY_unw->SetXTitle("X [mm]");
1550   dummy_his1_XY_unw->SetYTitle("Y [mm]");
1551   dummy_his1_XY_unw->GetYaxis()->SetTitleSize(0.02);
1552 
1553   dummy_his2_XY_unw->SetXTitle("-X [mm]"); //SS x is flipped from global coordinates
1554   dummy_his2_XY_unw->SetYTitle("Y [mm]");
1555   dummy_his2_XY_unw->GetYaxis()->SetTitleSize(0.02);
1556 
1557   //the lines are for the sector boundaries
1558   Double_t sec_gap_inner = (2*M_PI - 0.5024*12.0)/12.0;
1559 
1560   Double_t sec_gap_outer = (2*M_PI - 0.5097*12.0)/12.0;
1561 
1562   Double_t sec_gap = (sec_gap_inner + sec_gap_outer)/2.0;
1563 
1564   Double_t sec_phi = (0.5024 + 0.5097)/2.0;
1565 
1566   TLine *lines[12];
1567 
1568   for(int ln=0;ln<12;ln++)
1569   {
1570     lines[ln] = new TLine(311.05*cos((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)),311.05*sin((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)),759.11*cos((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)),759.11*sin((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)));
1571   }
1572 
1573   TEllipse *e1 = new TEllipse(0.0,0.0,311.05,311.05);
1574   TEllipse *e2 = new TEllipse(0.0,0.0,(402.49+411.53)/2.0,(402.49+411.53)/2.0);
1575   TEllipse *e3 = new TEllipse(0.0,0.0,(583.67+574.75)/2.0,(583.67+574.75)/2.0);
1576   TEllipse *e4 = new TEllipse(0.0,0.0,759.11,759.11);
1577   //__________________
1578 
1579   char TPCMON_STR[100];
1580 
1581   for( int i=0; i<48; i++ ) 
1582   {
1583     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
1584     sprintf(TPCMON_STR,"TPCMON_%i",i);
1585     tpcmon_NSTPC_clusXY_u[i][0] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC_clusterXY_R1_unw");
1586     tpcmon_NSTPC_clusXY_u[i][1] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC_clusterXY_R2_unw");
1587     tpcmon_NSTPC_clusXY_u[i][2] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC_clusterXY_R3_unw");
1588 
1589     tpcmon_SSTPC_clusXY_u[i][0] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC_clusterXY_R1_unw");
1590     tpcmon_SSTPC_clusXY_u[i][1] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC_clusterXY_R2_unw");
1591     tpcmon_SSTPC_clusXY_u[i][2] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC_clusterXY_R3_unw");
1592   }
1593 
1594   add_TH2_modules(tpcmon_NSTPC_clusXY_u, tpcmon_NSTPC_clusXY);
1595   add_TH2_modules(tpcmon_SSTPC_clusXY_u, tpcmon_SSTPC_clusXY);
1596   
1597   if (!gROOT->FindObject("TPCClusterXY_unw"))
1598   {
1599     MakeCanvas("TPCClusterXY_unw");
1600   }  
1601 
1602   TCanvas *MyTC = TC[8];
1603   TPad *TransparentTPad = transparent[8];
1604 
1605   MyTC->SetEditable(true);
1606   MyTC->Clear("D");
1607 
1608   TText PrintRun;
1609   PrintRun.SetTextFont(62);
1610   PrintRun.SetTextSize(0.04);
1611   PrintRun.SetNDC();          // set to normalized coordinates
1612   PrintRun.SetTextAlign(23);  // center/top alignment
1613   std::ostringstream runnostream;
1614   std::string runstring;
1615   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1616   // fill run number and event time into string
1617   runnostream << ThisName << "_ADC-Pedestal>(5sigma||20ADC), UNWEIGHTED, Run " << cl->RunNumber()
1618               << ", Time: " << ctime(&evttime.first);
1619   runstring = runnostream.str();
1620   TransparentTPad->cd();
1621   PrintRun.SetTextColor(evttime.second);
1622   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
1623 
1624   MyTC->cd(1);
1625   gStyle->SetOptStat(kFALSE);
1626   gPad->SetTopMargin(0.15);
1627   //gPad->SetLogz(kTRUE);
1628   dummy_his1_XY_unw->Draw("colzsame");
1629 
1630   float NS_max = 0;
1631   for( int i=0; i<12; i++ )
1632   {
1633     for( int j=0; j<3; j++ )
1634     {
1635       if( tpcmon_NSTPC_clusXY[i][j] )
1636       {
1637         MyTC->cd(1);
1638         tpcmon_NSTPC_clusXY[i][j] -> Draw("colzsame");
1639         //gStyle->SetLogz(kTRUE);
1640         if ( tpcmon_NSTPC_clusXY[i][j]->GetBinContent(tpcmon_NSTPC_clusXY[i][j]->GetMaximumBin()) > NS_max)
1641         {
1642           NS_max = tpcmon_NSTPC_clusXY[i][j]->GetBinContent(tpcmon_NSTPC_clusXY[i][j]->GetMaximumBin());
1643           dummy_his1_XY_unw->SetMaximum( NS_max );
1644         }
1645         gStyle->SetPalette(57); //kBird CVD friendly
1646       }
1647     }
1648 
1649   }
1650   MyTC->cd(1);
1651   e1->SetFillStyle(0);
1652   e2->SetFillStyle(0);
1653   e3->SetFillStyle(0);
1654   e4->SetFillStyle(0);
1655 
1656   e1->Draw("same");
1657   e2->Draw("same");
1658   e3->Draw("same");
1659   e4->Draw("same");
1660   for(int ln2=0;ln2<12;ln2++)
1661   {
1662     lines[ln2]->Draw("same"); 
1663   }
1664   MyTC->Update();
1665 
1666   MyTC->cd(2);
1667   gStyle->SetOptStat(kFALSE);
1668   gPad->SetTopMargin(0.15);
1669   dummy_his2_XY_unw->Draw("colzsame");
1670   //gPad->SetLogz(kTRUE);
1671 
1672   float SS_max = 0;
1673   for( int i=0; i<12; i++ )
1674   {
1675     for( int j=0; j<3; j++ )
1676     {
1677       if( tpcmon_SSTPC_clusXY[i+12][j] )
1678       {
1679         //std::cout<<"South Side Custer XY i: "<< i+12 <<", j: "<<j<<std::endl;
1680         MyTC->cd(2);
1681         tpcmon_SSTPC_clusXY[i+12][j] -> Draw("colzsame");
1682         //gStyle->SetLogz(kTRUE);
1683         if ( tpcmon_SSTPC_clusXY[i+12][j]->GetBinContent(tpcmon_SSTPC_clusXY[i+12][j]->GetMaximumBin()) > SS_max)
1684         {
1685           SS_max = tpcmon_SSTPC_clusXY[i+12][j]->GetBinContent(tpcmon_SSTPC_clusXY[i+12][j]->GetMaximumBin());
1686           dummy_his2_XY_unw->SetMaximum( SS_max );
1687         }
1688         gStyle->SetPalette(57); //kBird CVD friendly
1689       }
1690     }
1691 
1692   }
1693   MyTC->cd(2);
1694   e1->SetFillStyle(0);
1695   e2->SetFillStyle(0);
1696   e3->SetFillStyle(0);
1697   e4->SetFillStyle(0);
1698 
1699   e1->Draw("same");
1700   e2->Draw("same");
1701   e3->Draw("same");
1702   e4->Draw("same");
1703   for(int ln2=0;ln2<12;ln2++)
1704   {
1705     lines[ln2]->Draw("same"); 
1706   }
1707   MyTC->Update();
1708 
1709   MyTC->Show();
1710   MyTC->SetEditable(false);
1711 
1712   return 0;
1713 }
1714 
1715 int TpcMonDraw::DrawTPCADCSampleLarge(const std::string & /* what */)
1716 {
1717   OnlMonClient *cl = OnlMonClient::instance();
1718 
1719   TH2 *tpcmon_ADCSAMPLE_large[24] = {nullptr};
1720   TH2 *tpcmon_ADCSAMPLE_large_u[48] = {nullptr};
1721   
1722   char TPCMON_STR[100];
1723   for( int i=0; i<48; i++ ) 
1724   {
1725     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
1726     sprintf(TPCMON_STR,"TPCMON_%i",i);
1727     tpcmon_ADCSAMPLE_large_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"ADC_vs_SAMPLE_large");
1728   }
1729 
1730   add_TH2(tpcmon_ADCSAMPLE_large_u, tpcmon_ADCSAMPLE_large);  
1731 
1732   if (!gROOT->FindObject("TPCADCSamplelarge"))
1733   {
1734     MakeCanvas("TPCADCSamplelarge");
1735   }  
1736 
1737   TCanvas *MyTC = TC[9];
1738   TPad *TransparentTPad = transparent[9];
1739 
1740   MyTC->SetEditable(true);
1741   MyTC->Clear("D");
1742 
1743   for( int i=0; i<24; i++ )
1744   {
1745     if( tpcmon_ADCSAMPLE_large[i] )
1746     {
1747       MyTC->cd(i+5);
1748       gStyle->SetPalette(57); //kBird CVD friendly
1749       gPad->SetLogz(kTRUE);
1750       tpcmon_ADCSAMPLE_large[i] -> DrawCopy("colz");
1751     }
1752   }
1753 
1754   TText PrintRun;
1755   PrintRun.SetTextFont(62);
1756   PrintRun.SetTextSize(0.04);
1757   PrintRun.SetNDC();          // set to normalized coordinates
1758   PrintRun.SetTextAlign(23);  // center/top alignment
1759   std::ostringstream runnostream;
1760   std::string runstring;
1761   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1762   // fill run number and event time into string
1763   runnostream << ThisName << "_ADC_vs_SAMPLE_large Run " << cl->RunNumber()
1764               << ", Time: " << ctime(&evttime.first);
1765   runstring = runnostream.str();
1766   TransparentTPad->cd();
1767   PrintRun.SetTextColor(evttime.second);
1768   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
1769 
1770 
1771   MyTC->Update();
1772   MyTC->Show();
1773   MyTC->SetEditable(false);
1774 
1775   return 0;
1776 }
1777 
1778 
1779 
1780 int TpcMonDraw::DrawTPCZYclusters(const std::string & /* what */)
1781 {
1782 
1783   OnlMonClient *cl = OnlMonClient::instance();
1784 
1785   TH2 *tpcmon_NSTPC_clusZY[24] = {nullptr};
1786   TH2 *tpcmon_SSTPC_clusZY[24] = {nullptr};
1787 
1788   TH2 *tpcmon_NSTPC_clusZY_u[48] = {nullptr};
1789   TH2 *tpcmon_SSTPC_clusZY_u[48] = {nullptr};
1790   
1791   dummy_his1_ZY = new TH2F("dummy_his1_ZY", "(ADC-Pedestal) > ((5#sigma||20ADC), WEIGHTED", 515, -1030, 1030, 400, -800, 800); //dummy histos for titles
1792   dummy_his1_ZY->SetXTitle("Z [mm]");
1793   dummy_his1_ZY->SetYTitle("Y [mm]");
1794 
1795   char TPCMON_STR[100];
1796   for( int i=0; i<48; i++ ) 
1797   {
1798     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
1799     sprintf(TPCMON_STR,"TPCMON_%i",i);
1800     tpcmon_NSTPC_clusZY_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC_clusterZY");
1801 
1802     tpcmon_SSTPC_clusZY_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC_clusterZY");
1803   }
1804 
1805   add_TH2(tpcmon_NSTPC_clusZY_u, tpcmon_NSTPC_clusZY);
1806   add_TH2(tpcmon_SSTPC_clusZY_u, tpcmon_SSTPC_clusZY);
1807   
1808   if (!gROOT->FindObject("TPCClusterZY"))
1809   {
1810     MakeCanvas("TPCClusterZY");
1811   }  
1812 
1813   TCanvas *MyTC = TC[10];
1814   TPad *TransparentTPad = transparent[10];
1815 
1816   MyTC->SetEditable(true);
1817   MyTC->Clear("D");
1818 
1819   TText PrintRun;
1820   PrintRun.SetTextFont(62);
1821   PrintRun.SetTextSize(0.04);
1822   PrintRun.SetNDC();          // set to normalized coordinates
1823   PrintRun.SetTextAlign(23);  // center/top alignment
1824   std::ostringstream runnostream;
1825   std::string runstring;
1826   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1827   // fill run number and event time into string
1828   runnostream << ThisName << "_ADC-Pedestal>(5sigma||20ADC), WEIGHTED, Run " << cl->RunNumber()
1829               << ", Time: " << ctime(&evttime.first);
1830   runstring = runnostream.str();
1831   TransparentTPad->cd();
1832   PrintRun.SetTextColor(evttime.second);
1833   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
1834 
1835   MyTC->cd(1);
1836   gStyle->SetOptStat(kFALSE);
1837   gPad->SetTopMargin(0.15);
1838   gPad->SetLogz(kTRUE);
1839   dummy_his1_ZY->Draw("colzsame");
1840 
1841 
1842   float max = 0;
1843   for( int i=0; i<12; i++ )
1844   {
1845     if( tpcmon_NSTPC_clusZY[i] )
1846     {
1847       MyTC->cd(1);
1848       tpcmon_NSTPC_clusZY[i] -> Draw("colzsame");
1849       if ( tpcmon_NSTPC_clusZY[i]->GetBinContent(tpcmon_NSTPC_clusZY[i]->GetMaximumBin()) > max ) 
1850       {
1851         max = tpcmon_NSTPC_clusZY[i]->GetBinContent(tpcmon_NSTPC_clusZY[i]->GetMaximumBin());
1852         dummy_his1_ZY->SetMaximum( max );
1853       }
1854       gStyle->SetPalette(57); //kBird CVD friendly
1855     }
1856 
1857   }
1858   MyTC->Update();
1859 
1860   for( int i=0; i<12; i++ )
1861   {
1862     if( tpcmon_SSTPC_clusZY[i+12] )
1863     {
1864       MyTC->cd(1);
1865       tpcmon_SSTPC_clusZY[i+12] -> Draw("colzsame");
1866       if ( tpcmon_SSTPC_clusZY[i+12]->GetBinContent(tpcmon_SSTPC_clusZY[i+12]->GetMaximumBin()) > max ) 
1867       {
1868         max = tpcmon_SSTPC_clusZY[i+12]->GetBinContent(tpcmon_SSTPC_clusZY[i+12]->GetMaximumBin());
1869         dummy_his1_ZY->SetMaximum( max );
1870       }
1871       //gStyle->SetLogz(kTRUE);
1872       gStyle->SetPalette(57); //kBird CVD friendly
1873     }
1874 
1875   }
1876 
1877   MyTC->Update();
1878   MyTC->Show();
1879   MyTC->SetEditable(false);
1880 
1881 
1882 
1883   return 0;
1884 }
1885 
1886 
1887 int TpcMonDraw::DrawTPCZYclusters_unweighted(const std::string & /* what */)
1888 {
1889 
1890 
1891   OnlMonClient *cl = OnlMonClient::instance();
1892 
1893   TH2 *tpcmon_NSTPC_clusZY_unw[24] = {nullptr};
1894   TH2 *tpcmon_SSTPC_clusZY_unw[24] = {nullptr};
1895 
1896   TH2 *tpcmon_NSTPC_clusZY_unw_u[48] = {nullptr};
1897   TH2 *tpcmon_SSTPC_clusZY_unw_u[48] = {nullptr};
1898   
1899   dummy_his1_ZY_unw = new TH2F("dummy_his1_ZY_unw", "(ADC-Pedestal) > (5#sigma||20ADC), UNWEIGHTED", 515, -1030, 1030, 400, -800, 800); //dummy histos for titles
1900   dummy_his1_ZY_unw->SetXTitle("Z [mm]");
1901   dummy_his1_ZY_unw->SetYTitle("Y [mm]");
1902 
1903   char TPCMON_STR[100];
1904   for( int i=0; i<48; i++ ) 
1905   {
1906     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
1907     sprintf(TPCMON_STR,"TPCMON_%i",i);
1908     tpcmon_NSTPC_clusZY_unw_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC_clusterZY_unw");
1909 
1910     tpcmon_SSTPC_clusZY_unw_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC_clusterZY_unw");
1911   }
1912 
1913   add_TH2(tpcmon_NSTPC_clusZY_unw_u, tpcmon_NSTPC_clusZY_unw);
1914   add_TH2(tpcmon_SSTPC_clusZY_unw_u, tpcmon_SSTPC_clusZY_unw);
1915   
1916   if (!gROOT->FindObject("TPCClusterZY_unw"))
1917   {
1918     MakeCanvas("TPCClusterZY_unw");
1919   }  
1920 
1921   TCanvas *MyTC = TC[11];
1922   TPad *TransparentTPad = transparent[11];
1923 
1924   MyTC->SetEditable(true);
1925   MyTC->Clear("D");
1926 
1927   TText PrintRun;
1928   PrintRun.SetTextFont(62);
1929   PrintRun.SetTextSize(0.04);
1930   PrintRun.SetNDC();          // set to normalized coordinates
1931   PrintRun.SetTextAlign(23);  // center/top alignment
1932   std::ostringstream runnostream;
1933   std::string runstring;
1934   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
1935   // fill run number and event time into string
1936   runnostream << ThisName << "_ADC-Pedestal>(5sigma||20ADC), UNWEIGHTED, Run " << cl->RunNumber()
1937               << ", Time: " << ctime(&evttime.first);
1938   runstring = runnostream.str();
1939   TransparentTPad->cd();
1940   PrintRun.SetTextColor(evttime.second);
1941   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
1942 
1943   MyTC->cd(1);
1944   gStyle->SetOptStat(kFALSE);
1945   gPad->SetTopMargin(0.15);
1946   gPad->SetLogz(kTRUE);
1947   dummy_his1_ZY_unw->Draw("colzsame");
1948 
1949   float max = 0;
1950   for( int i=0; i<12; i++ )
1951   {
1952     if( tpcmon_NSTPC_clusZY_unw[i] )
1953     {
1954       MyTC->cd(1);
1955       tpcmon_NSTPC_clusZY_unw[i] -> Draw("colzsame");
1956       if ( tpcmon_NSTPC_clusZY_unw[i]->GetBinContent(tpcmon_NSTPC_clusZY_unw[i]->GetMaximumBin()) > max ) 
1957       {
1958         max = tpcmon_NSTPC_clusZY_unw[i]->GetBinContent(tpcmon_NSTPC_clusZY_unw[i]->GetMaximumBin());
1959         dummy_his1_ZY->SetMaximum( max );
1960       }
1961       //gStyle->SetLogz(kTRUE);
1962       gStyle->SetPalette(57); //kBird CVD friendly
1963     }
1964 
1965   }
1966   MyTC->Update();
1967 
1968   for( int i=0; i<12; i++ )
1969   {
1970     if( tpcmon_SSTPC_clusZY_unw[i+12] )
1971     {
1972       MyTC->cd(1);
1973       tpcmon_SSTPC_clusZY_unw[i+12] -> Draw("colzsame");
1974       if ( tpcmon_SSTPC_clusZY_unw[i+12]->GetBinContent(tpcmon_SSTPC_clusZY_unw[i+12]->GetMaximumBin()) > max ) 
1975       {
1976         max = tpcmon_SSTPC_clusZY_unw[i+12]->GetBinContent(tpcmon_SSTPC_clusZY_unw[i+12]->GetMaximumBin());
1977         dummy_his1_ZY->SetMaximum( max );
1978       }
1979       //gStyle->SetLogz(kTRUE);
1980       gStyle->SetPalette(57); //kBird CVD friendly
1981     }
1982 
1983   }
1984   MyTC->Update();
1985 
1986   MyTC->Show();
1987   MyTC->SetEditable(false);
1988 
1989 
1990 
1991   return 0;
1992 }
1993 int TpcMonDraw::DrawTPCchannelphi_layer_weighted(const std::string & /* what */)
1994 {
1995   OnlMonClient *cl = OnlMonClient::instance();
1996 
1997   TH2 *tpcmonth2channelphi_layer[24] = {nullptr};
1998   TH2 *tpcmonth2channelphi_layer_u[48] = {nullptr};
1999   
2000   char TPCMON_STR[100];
2001 
2002   dummy_his1_channelphi_layer_w = new TH2F("dummy_his1_channelphi_layer_", "(ADC-Pedestal) > 20 ADC, UNWEIGHTED", 515, -1030, 1030, 400, -800, 800); //dummy histos for titles
2003   dummy_his1_channelphi_layer_w->SetXTitle("#phi chan. #");
2004   dummy_his1_channelphi_layer_w->SetYTitle("layer ");
2005   dummy_his1_channelphi_layer_w->SetZTitle("#Sigma(ADC-ped.)");
2006 
2007   for( int i=0; i<48; i++ ) 
2008   {
2009     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
2010     sprintf(TPCMON_STR,"TPCMON_%i",i);
2011     tpcmonth2channelphi_layer_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"Layer_ChannelPhi_ADC_weighted");
2012   }
2013 
2014   add_TH2(tpcmonth2channelphi_layer_u, tpcmonth2channelphi_layer);
2015 
2016   if (!gROOT->FindObject("TPCLayerPhi"))
2017   {
2018     MakeCanvas("TPCLayerPhi");
2019   }  
2020 
2021   TCanvas *MyTC = TC[12];
2022   TPad *TransparentTPad = transparent[12];
2023 
2024   MyTC->SetEditable(true);
2025   MyTC->Clear("D");
2026 
2027   TText PrintRun;
2028   PrintRun.SetTextFont(62);
2029   PrintRun.SetTextSize(0.04);
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 << "_ChannelPhi_vs_Layer_ADC_weighted " << cl->RunNumber()
2037               << ", Time: " << ctime(&evttime.first);
2038   runstring = runnostream.str();
2039   TransparentTPad->cd();
2040   PrintRun.SetTextColor(evttime.second);
2041   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
2042 
2043   MyTC->cd(1);
2044   gStyle->SetOptStat(kFALSE);
2045   gPad->SetTopMargin(0.15);
2046   gPad->SetLogz(kTRUE);
2047   dummy_his1_channelphi_layer_w->Draw("lego2zsame");
2048 
2049   float max = 0;
2050   for( int i=0; i<24; i++ )
2051   {
2052     if(  tpcmonth2channelphi_layer[i] )
2053     {
2054       MyTC->cd(1);
2055        tpcmonth2channelphi_layer[i] -> Draw("lego2zsame");
2056       if (   tpcmonth2channelphi_layer[i]->GetBinContent(  tpcmonth2channelphi_layer[i]->GetMaximumBin()) > max ) 
2057       {
2058         max =  tpcmonth2channelphi_layer[i]->GetBinContent( tpcmonth2channelphi_layer[i]->GetMaximumBin());
2059         dummy_his1_channelphi_layer_w->SetMaximum( max );
2060       }
2061       //gStyle->SetLogz(kTRUE);
2062       gStyle->SetPalette(57); //kBird CVD friendly
2063     }
2064 
2065   }
2066   MyTC->Update();
2067 
2068   MyTC->Show();
2069   MyTC->SetEditable(false);
2070 
2071   return 0;
2072 }
2073 
2074 int TpcMonDraw::DrawTPCPedestSubADC1D(const std::string & /* what */)
2075 {
2076   //std::cout<<"Made it inside DrawTPCRawADC1D"<<std::endl;
2077   OnlMonClient *cl = OnlMonClient::instance();
2078 
2079   TH1 *tpcmon_PEDESTSUBADC1D[24][3] = {nullptr};
2080   TH1 *tpcmon_PEDESTSUBADC1D_u[48][3] = {nullptr};
2081   
2082   char TPCMON_STR[100];
2083   for( int i=0; i<48; i++ ) 
2084   {
2085     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
2086     sprintf(TPCMON_STR,"TPCMON_%i",i);
2087     tpcmon_PEDESTSUBADC1D_u[i][0] = (TH1*) cl->getHisto(TPCMON_STR,"PEDEST_SUB_1D_R1");
2088     tpcmon_PEDESTSUBADC1D_u[i][1] = (TH1*) cl->getHisto(TPCMON_STR,"PEDEST_SUB_1D_R2");
2089     tpcmon_PEDESTSUBADC1D_u[i][2] = (TH1*) cl->getHisto(TPCMON_STR,"PEDEST_SUB_1D_R3");
2090   }
2091 
2092   add_TH1_modules(tpcmon_PEDESTSUBADC1D_u, tpcmon_PEDESTSUBADC1D);
2093   
2094   if (!gROOT->FindObject("TPCPedestSubADC1D"))
2095   {
2096     MakeCanvas("TPCPedestSubADC1D");
2097   }  
2098 
2099   TCanvas *MyTC = TC[13];
2100   TPad *TransparentTPad = transparent[13];
2101 
2102   MyTC->SetEditable(true);
2103   MyTC->Clear("D");
2104 
2105   auto legend = new TLegend(0.7,0.65,0.98,0.95);
2106   bool draw_leg = 0;
2107 
2108   for( int i=0; i<24; i++ )
2109   {
2110     MyTC->cd(i+5);
2111     for( int j = 2; j>-1; j-- )
2112     {
2113       if( tpcmon_PEDESTSUBADC1D[i][j] )
2114       {
2115         if(j == 2){tpcmon_PEDESTSUBADC1D[i][j] -> DrawCopy("HIST");}
2116         else      {tpcmon_PEDESTSUBADC1D[i][j] -> DrawCopy("HISTsame");} //assumes that R3 will always exist and is most entries
2117       }
2118     }
2119     gPad->Update();
2120     gPad->SetLogy(kTRUE);  
2121 
2122     if(draw_leg == 0 && tpcmon_PEDESTSUBADC1D[i][0] && tpcmon_PEDESTSUBADC1D[i][1] && tpcmon_PEDESTSUBADC1D[i][2]) //if you have not drawn the legend yet, draw it BUT ONLY ONCE
2123     {
2124       legend->AddEntry(tpcmon_PEDESTSUBADC1D[i][0], "R1");
2125       legend->AddEntry(tpcmon_PEDESTSUBADC1D[i][1], "R2");
2126       legend->AddEntry(tpcmon_PEDESTSUBADC1D[i][2], "R3");
2127       MyTC->cd(i+5);
2128       legend->Draw();
2129       draw_leg = 1; //don't draw it again
2130     }
2131   }
2132 
2133   TText PrintRun;
2134   PrintRun.SetTextFont(62);
2135   PrintRun.SetTextSize(0.04);
2136   PrintRun.SetNDC();          // set to normalized coordinates
2137   PrintRun.SetTextAlign(23);  // center/top alignment
2138   std::ostringstream runnostream;
2139   std::string runstring;
2140   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
2141   // fill run number and event time into string
2142   runnostream << ThisName << "_PEDESTSUBADC Run " << cl->RunNumber()
2143               << ", Time: " << ctime(&evttime.first);
2144   runstring = runnostream.str();
2145   TransparentTPad->cd();
2146   PrintRun.SetTextColor(evttime.second);
2147   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
2148 
2149   MyTC->Update();
2150   MyTC->Show();
2151   MyTC->SetEditable(false);
2152 
2153   return 0;
2154 }
2155 
2156 int TpcMonDraw::DrawTPCNEventsvsEBDC(const std::string & /* what */)
2157 {
2158   OnlMonClient *cl = OnlMonClient::instance();
2159 
2160   TH1 *tpcmoneventsebdc[24] = {nullptr};
2161   TH1 *tpcmoneventsebdc_u[48] = {nullptr};
2162   
2163   char TPCMON_STR[100];
2164 
2165   dummy_his1_NEvents_EBDC = new TH1F("dummy_his1_Nevents_EBDC", "N_{Events} vs EBDC", 24, -0.5, 23.5); //dummy histos for titles
2166   dummy_his1_NEvents_EBDC->SetXTitle("EBDC #");
2167   dummy_his1_NEvents_EBDC->SetYTitle("N_{Events}");
2168 
2169   for( int i=0; i<48; i++ ) 
2170   {
2171     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
2172     sprintf(TPCMON_STR,"TPCMON_%i",i);
2173     tpcmoneventsebdc_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"NEvents_vs_EBDC");
2174   }
2175 
2176   add_TH1( tpcmoneventsebdc_u,  tpcmoneventsebdc);
2177   
2178   if (!gROOT->FindObject("TPCNEventsEBDC"))
2179   {
2180     MakeCanvas("TPCNEventsEBDC");
2181   }  
2182 
2183   TCanvas *MyTC = TC[14];
2184   TPad *TransparentTPad = transparent[14];
2185 
2186   MyTC->SetEditable(true);
2187   MyTC->Clear("D");
2188 
2189   TText PrintRun;
2190   PrintRun.SetTextFont(62);
2191   PrintRun.SetTextSize(0.04);
2192   PrintRun.SetNDC();          // set to normalized coordinates
2193   PrintRun.SetTextAlign(23);  // center/top alignment
2194   std::ostringstream runnostream;
2195   std::string runstring;
2196   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
2197   // fill run number and event time into string
2198   runnostream << ThisName << "_N_Events_vs_EBDC " << cl->RunNumber()
2199               << ", Time: " << ctime(&evttime.first);
2200   runstring = runnostream.str();
2201   TransparentTPad->cd();
2202   PrintRun.SetTextColor(evttime.second);
2203   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
2204 
2205   MyTC->cd(1);
2206   gStyle->SetOptStat(kFALSE);
2207   gPad->SetTopMargin(0.15);
2208   dummy_his1_NEvents_EBDC->Draw("HISTsame");
2209 
2210   float max = 0;
2211   for( int i=0; i<24; i++ )
2212   {
2213     if( tpcmoneventsebdc[i] )
2214     {
2215       MyTC->cd(1);
2216       tpcmoneventsebdc[i] -> Draw("HISTsame");
2217       if( tpcmoneventsebdc[i]->GetBinContent(  tpcmoneventsebdc[i]->GetMaximumBin()) > max ) 
2218       {
2219         max =  tpcmoneventsebdc[i]->GetBinContent( tpcmoneventsebdc[i]->GetMaximumBin());
2220         dummy_his1_NEvents_EBDC->SetMaximum( max*(1.3) );
2221       }
2222 
2223     }
2224   }
2225   MyTC->Update();
2226 
2227   MyTC->Show();
2228   MyTC->SetEditable(false);
2229 
2230   return 0;
2231 }
2232 
2233 int TpcMonDraw::DrawTPCPedestSubADCSample(const std::string & /* what */)
2234 {
2235   OnlMonClient *cl = OnlMonClient::instance();
2236 
2237   TH2 *tpcmon_PEDESTSUBADCSAMPLE[24] = {nullptr};
2238   TH2 *tpcmon_PEDESTSUBADCSAMPLE_u[48] = {nullptr};
2239   
2240   char TPCMON_STR[100];
2241   for( int i=0; i<48; i++ ) 
2242   {
2243     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
2244     sprintf(TPCMON_STR,"TPCMON_%i",i);
2245     tpcmon_PEDESTSUBADCSAMPLE_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"PEDEST_SUB_ADC_vs_SAMPLE");
2246   }
2247 
2248   add_TH2(tpcmon_PEDESTSUBADCSAMPLE_u, tpcmon_PEDESTSUBADCSAMPLE);  
2249 
2250   if (!gROOT->FindObject("TPCPedestSubADCSample"))
2251   {
2252     MakeCanvas("TPCPedestSubADCSample");
2253   }  
2254 
2255   TCanvas *MyTC = TC[15];
2256   TPad *TransparentTPad = transparent[15];
2257 
2258   MyTC->SetEditable(true);
2259   MyTC->Clear("D");
2260 
2261   for( int i=0; i<24; i++ )
2262   {
2263     if( tpcmon_PEDESTSUBADCSAMPLE[i] )
2264     {
2265       MyTC->cd(i+5);
2266       gStyle->SetPalette(57); //kBird CVD friendly
2267       gPad->SetLogz(kTRUE);
2268       tpcmon_PEDESTSUBADCSAMPLE[i] -> DrawCopy("colz");
2269     }
2270   }
2271 
2272   TText PrintRun;
2273   PrintRun.SetTextFont(62);
2274   PrintRun.SetTextSize(0.04);
2275   PrintRun.SetNDC();          // set to normalized coordinates
2276   PrintRun.SetTextAlign(23);  // center/top alignment
2277   std::ostringstream runnostream;
2278   std::string runstring;
2279   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
2280   // fill run number and event time into string
2281   runnostream << ThisName << "_PEDEST_SUB_ADC_vs_SAMPLE Run " << cl->RunNumber()
2282               << ", Time: " << ctime(&evttime.first);
2283   runstring = runnostream.str();
2284   TransparentTPad->cd();
2285   PrintRun.SetTextColor(evttime.second);
2286   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
2287 
2288 
2289   MyTC->Update();
2290   MyTC->Show();
2291   MyTC->SetEditable(false);
2292 
2293   return 0;
2294 }
2295 
2296 int TpcMonDraw::DrawTPCPedestSubADCSample_R1(const std::string & /* what */)
2297 {
2298   OnlMonClient *cl = OnlMonClient::instance();
2299 
2300   TH2 *tpcmon_PEDESTSUBADCSAMPLE_R1[24] = {nullptr};
2301   TH2 *tpcmon_PEDESTSUBADCSAMPLE_R1_u[48] = {nullptr};
2302   
2303   char TPCMON_STR[100];
2304   for( int i=0; i<48; i++ ) 
2305   {
2306     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
2307     sprintf(TPCMON_STR,"TPCMON_%i",i);
2308     tpcmon_PEDESTSUBADCSAMPLE_R1_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"PEDEST_SUB_ADC_vs_SAMPLE_R1");
2309   }
2310 
2311   add_TH2(tpcmon_PEDESTSUBADCSAMPLE_R1_u, tpcmon_PEDESTSUBADCSAMPLE_R1);
2312 
2313   if (!gROOT->FindObject("TPCPedestSubADCSample_R1"))
2314   {
2315     MakeCanvas("TPCPedestSubADCSample_R1");
2316   }  
2317 
2318   TCanvas *MyTC = TC[16];
2319   TPad *TransparentTPad = transparent[16];
2320 
2321   MyTC->SetEditable(true);
2322   MyTC->Clear("D");
2323 
2324   for( int i=0; i<24; i++ )
2325   {
2326     if( tpcmon_PEDESTSUBADCSAMPLE_R1[i] )
2327     {
2328       MyTC->cd(i+5);
2329       gStyle->SetPalette(57); //kBird CVD friendly
2330       gPad->SetLogz(kTRUE);
2331       tpcmon_PEDESTSUBADCSAMPLE_R1[i] -> DrawCopy("colz");
2332     }
2333   }
2334 
2335   TText PrintRun;
2336   PrintRun.SetTextFont(62);
2337   PrintRun.SetTextSize(0.04);
2338   PrintRun.SetNDC();          // set to normalized coordinates
2339   PrintRun.SetTextAlign(23);  // center/top alignment
2340   std::ostringstream runnostream;
2341   std::string runstring;
2342   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
2343   // fill run number and event time into string
2344   runnostream << ThisName << "_PEDEST_SUB_ADC_vs_SAMPLE R1 ONLY Run " << cl->RunNumber()
2345               << ", Time: " << ctime(&evttime.first);
2346   runstring = runnostream.str();
2347   TransparentTPad->cd();
2348   PrintRun.SetTextColor(evttime.second);
2349   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
2350 
2351 
2352   MyTC->Update();
2353   MyTC->Show();
2354   MyTC->SetEditable(false);
2355 
2356   return 0;
2357 }
2358 
2359 int TpcMonDraw::DrawTPCPedestSubADCSample_R2(const std::string & /* what */)
2360 {
2361   OnlMonClient *cl = OnlMonClient::instance();
2362 
2363   TH2 *tpcmon_PEDESTSUBADCSAMPLE_R2[24] = {nullptr};
2364   TH2 *tpcmon_PEDESTSUBADCSAMPLE_R2_u[48] = {nullptr};
2365   
2366   char TPCMON_STR[100];
2367   for( int i=0; i<48; i++ ) 
2368   {
2369     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
2370     sprintf(TPCMON_STR,"TPCMON_%i",i);
2371     tpcmon_PEDESTSUBADCSAMPLE_R2_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"PEDEST_SUB_ADC_vs_SAMPLE_R2");
2372   }
2373 
2374   add_TH2(tpcmon_PEDESTSUBADCSAMPLE_R2_u, tpcmon_PEDESTSUBADCSAMPLE_R2);
2375   
2376   if (!gROOT->FindObject("TPCPedestSubADCSample_R2"))
2377   {
2378     MakeCanvas("TPCPedestSubADCSample_R2");
2379   }  
2380 
2381   TCanvas *MyTC = TC[17];
2382   TPad *TransparentTPad = transparent[17];
2383 
2384   MyTC->SetEditable(true);
2385   MyTC->Clear("D");
2386 
2387   for( int i=0; i<24; i++ )
2388   {
2389     if( tpcmon_PEDESTSUBADCSAMPLE_R2[i] )
2390     {
2391       MyTC->cd(i+5);
2392       gStyle->SetPalette(57); //kBird CVD friendly
2393       gPad->SetLogz(kTRUE);
2394       tpcmon_PEDESTSUBADCSAMPLE_R2[i] -> DrawCopy("colz");
2395     }
2396   }
2397 
2398   TText PrintRun;
2399   PrintRun.SetTextFont(62);
2400   PrintRun.SetTextSize(0.04);
2401   PrintRun.SetNDC();          // set to normalized coordinates
2402   PrintRun.SetTextAlign(23);  // center/top alignment
2403   std::ostringstream runnostream;
2404   std::string runstring;
2405   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
2406   // fill run number and event time into string
2407   runnostream << ThisName << "_PEDEST_SUB_ADC_vs_SAMPLE R2 ONLY Run " << cl->RunNumber()
2408               << ", Time: " << ctime(&evttime.first);
2409   runstring = runnostream.str();
2410   TransparentTPad->cd();
2411   PrintRun.SetTextColor(evttime.second);
2412   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
2413 
2414 
2415   MyTC->Update();
2416   MyTC->Show();
2417   MyTC->SetEditable(false);
2418 
2419   return 0;
2420 }
2421 
2422 int TpcMonDraw::DrawTPCPedestSubADCSample_R3(const std::string & /* what */)
2423 {
2424   OnlMonClient *cl = OnlMonClient::instance();
2425 
2426   TH2 *tpcmon_PEDESTSUBADCSAMPLE_R3[24] = {nullptr};
2427   TH2 *tpcmon_PEDESTSUBADCSAMPLE_R3_u[48] = {nullptr};
2428   
2429   char TPCMON_STR[100];
2430   for( int i=0; i<48; i++ ) 
2431   {
2432     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
2433     sprintf(TPCMON_STR,"TPCMON_%i",i);
2434     tpcmon_PEDESTSUBADCSAMPLE_R3_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"PEDEST_SUB_ADC_vs_SAMPLE_R3");
2435   }
2436 
2437   add_TH2(tpcmon_PEDESTSUBADCSAMPLE_R3_u, tpcmon_PEDESTSUBADCSAMPLE_R3);
2438   
2439   if (!gROOT->FindObject("TPCPedestSubADCSample_R3"))
2440   {
2441     MakeCanvas("TPCPedestSubADCSample_R3");
2442   }  
2443 
2444   TCanvas *MyTC = TC[18];
2445   TPad *TransparentTPad = transparent[18];
2446 
2447   MyTC->SetEditable(true);
2448   MyTC->Clear("D");
2449 
2450   for( int i=0; i<24; i++ )
2451   {
2452     if( tpcmon_PEDESTSUBADCSAMPLE_R3[i] )
2453     {
2454       MyTC->cd(i+5);
2455       gStyle->SetPalette(57); //kBird CVD friendly
2456       gPad->SetLogz(kTRUE);
2457       tpcmon_PEDESTSUBADCSAMPLE_R3[i] -> DrawCopy("colz");
2458     }
2459   }
2460 
2461   TText PrintRun;
2462   PrintRun.SetTextFont(62);
2463   PrintRun.SetTextSize(0.04);
2464   PrintRun.SetNDC();          // set to normalized coordinates
2465   PrintRun.SetTextAlign(23);  // center/top alignment
2466   std::ostringstream runnostream;
2467   std::string runstring;
2468   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
2469   // fill run number and event time into string
2470   runnostream << ThisName << "_PEDEST_SUB_ADC_vs_SAMPLE R3 ONLY Run " << cl->RunNumber()
2471               << ", Time: " << ctime(&evttime.first);
2472   runstring = runnostream.str();
2473   TransparentTPad->cd();
2474   PrintRun.SetTextColor(evttime.second);
2475   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
2476 
2477 
2478   MyTC->Update();
2479   MyTC->Show();
2480   MyTC->SetEditable(false);
2481 
2482   return 0;
2483 }
2484 
2485 int TpcMonDraw::DrawTPCXYlaserclusters(const std::string & /* what */)
2486 {
2487   OnlMonClient *cl = OnlMonClient::instance();
2488 
2489   TH2 *tpcmon_NSTPC_laser_clusXY[24][3] = {nullptr};
2490   TH2 *tpcmon_SSTPC_laser_clusXY[24][3] = {nullptr};
2491 
2492   TH2 *tpcmon_NSTPC_laser_clusXY_u[48][3] = {nullptr};
2493   TH2 *tpcmon_SSTPC_laser_clusXY_u[48][3] = {nullptr};
2494   
2495   dummy_his1_laser_XY = new TH2F("dummy_his1_laser_XY", "(ADC-Pedestal) > (5#sigma||20ADC) North Side, WEIGHTED", 400, -800, 800, 400, -800, 800); //dummy histos for titles
2496   dummy_his2_laser_XY = new TH2F("dummy_his2_laser_XY", "(ADC-Pedestal) > (5#sigma||20ADC) South Side, WEIGHTED", 400, -800, 800, 400, -800, 800);
2497 
2498   dummy_his1_laser_XY->SetXTitle("X [mm]");
2499   dummy_his1_laser_XY->SetYTitle("Y [mm]");
2500   dummy_his1_laser_XY->GetYaxis()->SetTitleSize(0.02);
2501 
2502   dummy_his2_laser_XY->SetXTitle("-X [mm]"); //SS x is flipped from global coordinates
2503   dummy_his2_laser_XY->SetYTitle("Y [mm]");
2504   dummy_his2_laser_XY->GetYaxis()->SetTitleSize(0.02);
2505 
2506   //the lines are for the sector boundaries
2507   Double_t sec_gap_inner = (2*M_PI - 0.5024*12.0)/12.0;
2508 
2509   Double_t sec_gap_outer = (2*M_PI - 0.5097*12.0)/12.0;
2510 
2511   Double_t sec_gap = (sec_gap_inner + sec_gap_outer)/2.0;
2512 
2513   Double_t sec_phi = (0.5024 + 0.5097)/2.0;
2514 
2515   TLine *lines[12];
2516 
2517   for(int ln=0;ln<12;ln++)
2518   {
2519     lines[ln] = new TLine(311.05*cos((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)),311.05*sin((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)),759.11*cos((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)),759.11*sin((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)));
2520   }
2521 
2522   TEllipse *e1 = new TEllipse(0.0,0.0,311.05,311.05);
2523   TEllipse *e2 = new TEllipse(0.0,0.0,(402.49+411.53)/2.0,(402.49+411.53)/2.0);
2524   TEllipse *e3 = new TEllipse(0.0,0.0,(583.67+574.75)/2.0,(583.67+574.75)/2.0);
2525   TEllipse *e4 = new TEllipse(0.0,0.0,759.11,759.11);
2526   //__________________
2527 
2528   char TPCMON_STR[100];
2529   for( int i=0; i<48; i++ ) 
2530   {
2531     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
2532     sprintf(TPCMON_STR,"TPCMON_%i",i);
2533     tpcmon_NSTPC_laser_clusXY_u[i][0] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC_clusterXY_R1_LASER");
2534     tpcmon_NSTPC_laser_clusXY_u[i][1] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC_clusterXY_R2_LASER");
2535     tpcmon_NSTPC_laser_clusXY_u[i][2] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC_clusterXY_R3_LASER");
2536 
2537     tpcmon_SSTPC_laser_clusXY_u[i][0] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC_clusterXY_R1_LASER");
2538     tpcmon_SSTPC_laser_clusXY_u[i][1] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC_clusterXY_R2_LASER");
2539     tpcmon_SSTPC_laser_clusXY_u[i][2] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC_clusterXY_R3_LASER");
2540   }
2541 
2542   add_TH2_modules( tpcmon_NSTPC_laser_clusXY_u,  tpcmon_NSTPC_laser_clusXY);
2543   add_TH2_modules( tpcmon_SSTPC_laser_clusXY_u,  tpcmon_SSTPC_laser_clusXY);
2544   
2545   if (!gROOT->FindObject("TPCClusterXY_laser"))
2546   {
2547     MakeCanvas("TPCClusterXY_laser");
2548   }  
2549 
2550   TCanvas *MyTC = TC[19];
2551   TPad *TransparentTPad = transparent[19];
2552 
2553   MyTC->SetEditable(true); //after Chris' change need to skip 22
2554   MyTC->Clear("D");
2555 
2556   TText PrintRun;
2557   PrintRun.SetTextFont(62);
2558   PrintRun.SetTextSize(0.04);
2559   PrintRun.SetNDC();          // set to normalized coordinates
2560   PrintRun.SetTextAlign(23);  // center/top alignment
2561   std::ostringstream runnostream;
2562   std::string runstring;
2563   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
2564   // fill run number and event time into string
2565   runnostream << ThisName << "_LASER_ADC-Pedestal>(5sigma||20ADC) WEIGHTED, Run" << cl->RunNumber()
2566               << ", Time: " << ctime(&evttime.first);
2567   runstring = runnostream.str();
2568   TransparentTPad->cd();
2569   PrintRun.SetTextColor(evttime.second);
2570   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
2571 
2572   MyTC->cd(1);
2573   gStyle->SetOptStat(kFALSE);
2574   gPad->SetTopMargin(0.15);
2575   gPad->SetLogz(kTRUE);
2576   dummy_his1_laser_XY->Draw("colzsame");
2577 
2578   float NS_max = 0;
2579   for( int i=0; i<12; i++ )
2580   {
2581     for( int j=0; j<3; j++ )
2582     {
2583       if( tpcmon_NSTPC_laser_clusXY[i][j] )
2584       {
2585         MyTC->cd(1);
2586         tpcmon_NSTPC_laser_clusXY[i][j] -> Draw("colzsame");
2587         //gStyle->SetLogz(kTRUE);
2588         if ( tpcmon_NSTPC_laser_clusXY[i][j]->GetBinContent(tpcmon_NSTPC_laser_clusXY[i][j]->GetMaximumBin()) > NS_max)
2589         {
2590           NS_max = tpcmon_NSTPC_laser_clusXY[i][j]->GetBinContent(tpcmon_NSTPC_laser_clusXY[i][j]->GetMaximumBin());
2591           dummy_his1_laser_XY->SetMaximum( NS_max );
2592         }
2593         gStyle->SetPalette(57); //kBird CVD friendly
2594       }
2595 
2596     }
2597   }
2598   MyTC->cd(1);
2599   e1->SetFillStyle(0);
2600   e2->SetFillStyle(0);
2601   e3->SetFillStyle(0);
2602   e4->SetFillStyle(0);
2603 
2604   e1->Draw("same");
2605   e2->Draw("same");
2606   e3->Draw("same");
2607   e4->Draw("same");
2608   for(int ln2=0;ln2<12;ln2++)
2609   {
2610     lines[ln2]->Draw("same"); 
2611   }
2612   MyTC->Update();
2613 
2614   MyTC->cd(2);
2615   gStyle->SetOptStat(kFALSE);
2616   gPad->SetTopMargin(0.15);
2617   gPad->SetLogz(kTRUE);
2618   dummy_his2_laser_XY->Draw("colzsame");
2619 
2620   float SS_max = 0;
2621   for( int i=0; i<12; i++ )
2622   {
2623     for( int j=0; j<3; j++ )
2624     {
2625       if( tpcmon_SSTPC_laser_clusXY[i+12][j] )
2626       {
2627         //std::cout<<"South Side Custer XY i: "<< i+12 <<", j: "<<j<<std::endl;
2628         MyTC->cd(2);
2629         tpcmon_SSTPC_laser_clusXY[i+12][j] -> Draw("colzsame");
2630         //gStyle->SetLogz(kTRUE);
2631         if ( tpcmon_SSTPC_laser_clusXY[i+12][j]->GetBinContent(tpcmon_SSTPC_laser_clusXY[i+12][j]->GetMaximumBin()) > SS_max)
2632         {
2633           SS_max = tpcmon_SSTPC_laser_clusXY[i+12][j]->GetBinContent(tpcmon_SSTPC_laser_clusXY[i+12][j]->GetMaximumBin());
2634           dummy_his2_laser_XY->SetMaximum( SS_max );
2635         }
2636         gStyle->SetPalette(57); //kBird CVD friendly
2637       }
2638     }
2639 
2640   }
2641   MyTC->cd(2);
2642   e1->SetFillStyle(0);
2643   e2->SetFillStyle(0);
2644   e3->SetFillStyle(0);
2645   e4->SetFillStyle(0);
2646 
2647   e1->Draw("same");
2648   e2->Draw("same");
2649   e3->Draw("same");
2650   e4->Draw("same");
2651   for(int ln2=0;ln2<12;ln2++)
2652   {
2653     lines[ln2]->Draw("same"); 
2654   }
2655 
2656   MyTC->Update();
2657   MyTC->Show();
2658   MyTC->SetEditable(false);
2659 
2660   return 0;
2661 }
2662 
2663 int TpcMonDraw::DrawTPCStuckChannels(const std::string & /* what */)
2664 {
2665   OnlMonClient *cl = OnlMonClient::instance();
2666   
2667   TH1 *tpcmon_stuckchannels[24] = {nullptr};
2668   TH1 *tpcmon_stuckchannels_u[48] = {nullptr};
2669   
2670   char TPCMON_STR[100];
2671   for( int i=0; i<48; i++ ) 
2672   {
2673     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
2674     sprintf(TPCMON_STR,"TPCMON_%i",i);
2675     tpcmon_stuckchannels_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Stuck_Channels");
2676     //if( !tpcmon_stuckchannels[i] ){std::cout<<"Not able to get stuck channel histo # "<<i<<std::endl;}
2677   }
2678 
2679   add_TH1(tpcmon_stuckchannels_u, tpcmon_stuckchannels);
2680   
2681   if (!gROOT->FindObject("TPCStuckChannels"))
2682   {
2683     MakeCanvas("TPCStuckChannels");
2684   }
2685 
2686   TCanvas *MyTC = TC[21];
2687   TPad *TransparentTPad = transparent[21];
2688 
2689   MyTC->SetEditable(true);
2690   MyTC->Clear("D");
2691   MyTC->cd(1);
2692 
2693   TLine *t1 = new TLine(); t1->SetLineWidth(2);
2694   TLine *t11 = new TLine(); t11->SetLineWidth(2);
2695   TLine *t2 = new TLine(); t2->SetLineStyle(2);
2696   TText *tt1= new TText(); tt1->SetTextSize(0.05);
2697 
2698   int FEEid[26]={2,4,3,13,17,16, // R1
2699                  11,12,19,18,0,1,15,14, // R2
2700                  20,22,21,23,25,24,10,9,8,6,7,5 // R3
2701                 };
2702 
2703   char title[50];
2704 
2705   for( int i=0; i<24; i++ )
2706   {
2707     if( tpcmon_stuckchannels[i] )
2708     {
2709       MyTC->cd(i+5);
2710 
2711       tpcmon_stuckchannels[i]->GetYaxis()->SetRangeUser(0.01,10000);
2712       tpcmon_stuckchannels[i]->DrawCopy("HIST");
2713 
2714       gPad->SetLogy(kTRUE);
2715 
2716       MyTC->Update();
2717 
2718       for(int j=0;j<25;j++)
2719       {
2720         t2->DrawLine((j+0.5),0.01,(j+0.5),1500);
2721       }
2722       for(int k=0;k<26;k++)
2723       {
2724         sprintf(title,"%d",FEEid[k]);
2725         tt1->DrawText(k,400,title);
2726       }
2727       tt1->SetTextSize(0.06);
2728       tt1->DrawText(3.1,2000,"R1");
2729       tt1->DrawText(9.6,2000,"R2");
2730       tt1->DrawText(20.4,2000,"R3");
2731       tt1->SetTextSize(0.05); 
2732 
2733       t1->DrawLine(5.5,0.01,5.5,5000);
2734       t1->DrawLine(13.5,0.01,13.5,5000);
2735 
2736       t11->DrawLine(-0.5,256,25.5,256);
2737     }
2738   }
2739 
2740   TText PrintRun;
2741   PrintRun.SetTextFont(62);
2742   PrintRun.SetTextSize(0.04);
2743   PrintRun.SetNDC();          // set to normalized coordinates
2744   PrintRun.SetTextAlign(23);  // center/top alignment
2745   std::ostringstream runnostream;
2746   std::string runstring;
2747   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
2748   // fill run number and event time into string
2749   runnostream << ThisName << "_StuckChannel Run " << cl->RunNumber()
2750               << ", Time: " << ctime(&evttime.first);
2751   runstring = runnostream.str();
2752   TransparentTPad->cd();
2753   PrintRun.SetTextColor(evttime.second);
2754   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
2755 
2756   MyTC->Update();
2757   //MyTC->SetLogy();
2758   MyTC->Show();
2759   MyTC->SetEditable(false);
2760 
2761 
2762   return 0;
2763 }
2764 int TpcMonDraw::DrawTPCXYclusters5event(const std::string & /* what */)
2765 {
2766   OnlMonClient *cl = OnlMonClient::instance();
2767 
2768   TH2 *tpcmon_NSTPC_5e_clusXY[24][3] = {nullptr};
2769   TH2 *tpcmon_SSTPC_5e_clusXY[24][3] = {nullptr};
2770 
2771   TH2 *tpcmon_NSTPC_5e_clusXY_u[48][3] = {nullptr};
2772   TH2 *tpcmon_SSTPC_5e_clusXY_u[48][3] = {nullptr}; 
2773   
2774   dummy_his1_u5_XY = new TH2F("dummy_his1_u5_XY", "(ADC-Pedestal) > (5#sigma||20ADC) North Side, <= 5 E , UNWEIGHTED", 400, -800, 800, 400, -800, 800); //dummy histos for titles
2775   dummy_his2_u5_XY = new TH2F("dummy_his2_u5_XY", "(ADC-Pedestal) > (5#sigma||20ADC) South Side, <= 5 E , UNWEIGHTED", 400, -800, 800, 400, -800, 800);
2776 
2777   dummy_his1_u5_XY->SetXTitle("X [mm]");
2778   dummy_his1_u5_XY->SetYTitle("Y [mm]");
2779   dummy_his1_u5_XY->GetYaxis()->SetTitleSize(0.02);
2780 
2781   dummy_his2_u5_XY->SetXTitle("-X [mm]"); //SS x is flipped from global coordinates
2782   dummy_his2_u5_XY->SetYTitle("Y [mm]");
2783   dummy_his2_u5_XY->GetYaxis()->SetTitleSize(0.02);
2784 
2785   //the lines are for the sector boundaries
2786   Double_t sec_gap_inner = (2*M_PI - 0.5024*12.0)/12.0;
2787 
2788   Double_t sec_gap_outer = (2*M_PI - 0.5097*12.0)/12.0;
2789 
2790   Double_t sec_gap = (sec_gap_inner + sec_gap_outer)/2.0;
2791 
2792   Double_t sec_phi = (0.5024 + 0.5097)/2.0;
2793 
2794   TLine *lines[12];
2795 
2796   for(int ln=0;ln<12;ln++)
2797   {
2798     lines[ln] = new TLine(311.05*cos((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)),311.05*sin((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)),759.11*cos((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)),759.11*sin((sec_phi+sec_gap)/2.0+ln*(sec_phi+sec_gap)));
2799   }
2800 
2801   TEllipse *e1 = new TEllipse(0.0,0.0,311.05,311.05);
2802   TEllipse *e2 = new TEllipse(0.0,0.0,(402.49+411.53)/2.0,(402.49+411.53)/2.0);
2803   TEllipse *e3 = new TEllipse(0.0,0.0,(583.67+574.75)/2.0,(583.67+574.75)/2.0);
2804   TEllipse *e4 = new TEllipse(0.0,0.0,759.11,759.11);
2805   //__________________
2806 
2807   char TPCMON_STR[100];
2808   for( int i=0; i<48; i++ ) 
2809   {
2810     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
2811     sprintf(TPCMON_STR,"TPCMON_%i",i);                             
2812     tpcmon_NSTPC_5e_clusXY_u[i][0] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC_clusterXY_R1_u5");
2813     tpcmon_NSTPC_5e_clusXY_u[i][1] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC_clusterXY_R2_u5");
2814     tpcmon_NSTPC_5e_clusXY_u[i][2] = (TH2*) cl->getHisto(TPCMON_STR,"NorthSideADC_clusterXY_R3_u5");
2815 
2816     tpcmon_SSTPC_5e_clusXY_u[i][0] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC_clusterXY_R1_u5");
2817     tpcmon_SSTPC_5e_clusXY_u[i][1] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC_clusterXY_R2_u5");
2818     tpcmon_SSTPC_5e_clusXY_u[i][2] = (TH2*) cl->getHisto(TPCMON_STR,"SouthSideADC_clusterXY_R3_u5");
2819   }
2820 
2821   add_TH2_modules( tpcmon_NSTPC_5e_clusXY_u,  tpcmon_NSTPC_5e_clusXY);  
2822   add_TH2_modules( tpcmon_SSTPC_5e_clusXY_u,  tpcmon_SSTPC_5e_clusXY);
2823   
2824   if (!gROOT->FindObject("TPCClusterXY_u5"))
2825   {
2826     MakeCanvas("TPCClusterXY_u5");
2827   }  
2828 
2829   TCanvas *MyTC = TC[22];
2830   TPad *TransparentTPad = transparent[22];
2831 
2832   MyTC->SetEditable(true); 
2833   MyTC->Clear("D");
2834 
2835   TText PrintRun;
2836   PrintRun.SetTextFont(62);
2837   PrintRun.SetTextSize(0.04);
2838   PrintRun.SetNDC();          // set to normalized coordinates
2839   PrintRun.SetTextAlign(23);  // center/top alignment
2840   std::ostringstream runnostream;
2841   std::string runstring;
2842   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
2843   // fill run number and event time into string
2844   runnostream << ThisName << "_ADC-Pedestal>(5sigma||20ADC) UNWEIGHTED, <= 5E, Run" << cl->RunNumber()
2845               << ", Time: " << ctime(&evttime.first);
2846   runstring = runnostream.str();
2847   TransparentTPad->cd();
2848   PrintRun.SetTextColor(evttime.second);
2849   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
2850 
2851   MyTC->cd(1);
2852   gStyle->SetOptStat(kFALSE);
2853   gPad->SetTopMargin(0.15);
2854   //gPad->SetLogz(kTRUE);
2855   dummy_his1_u5_XY->Draw("colzsame");
2856 
2857   float NS_max = 0;
2858   for( int i=0; i<12; i++ )
2859   {
2860     for( int j=0; j<3; j++ )
2861     {
2862       if( tpcmon_NSTPC_5e_clusXY[i][j] )
2863       {
2864         MyTC->cd(1);
2865         tpcmon_NSTPC_5e_clusXY[i][j] -> Draw("colzsame");
2866         //gStyle->SetLogz(kTRUE);
2867         if ( tpcmon_NSTPC_5e_clusXY[i][j]->GetBinContent(tpcmon_NSTPC_5e_clusXY[i][j]->GetMaximumBin()) > NS_max)
2868         {
2869           NS_max = tpcmon_NSTPC_5e_clusXY[i][j]->GetBinContent(tpcmon_NSTPC_5e_clusXY[i][j]->GetMaximumBin());
2870           dummy_his1_u5_XY->SetMaximum( NS_max );
2871         }
2872         gStyle->SetPalette(57); //kBird CVD friendly
2873       }
2874 
2875     }
2876   }
2877   MyTC->cd(1);
2878   e1->SetFillStyle(0);
2879   e2->SetFillStyle(0);
2880   e3->SetFillStyle(0);
2881   e4->SetFillStyle(0);
2882 
2883   e1->Draw("same");
2884   e2->Draw("same");
2885   e3->Draw("same");
2886   e4->Draw("same");
2887   for(int ln2=0;ln2<12;ln2++)
2888   {
2889     lines[ln2]->Draw("same"); 
2890   }
2891   MyTC->Update();
2892 
2893   MyTC->cd(2);
2894   gStyle->SetOptStat(kFALSE);
2895   gPad->SetTopMargin(0.15);
2896   //gPad->SetLogz(kTRUE);
2897   dummy_his2_u5_XY->Draw("colzsame");
2898 
2899   float SS_max = 0;
2900   for( int i=0; i<12; i++ )
2901   {
2902     for( int j=0; j<3; j++ )
2903     {
2904       if( tpcmon_SSTPC_5e_clusXY[i+12][j] )
2905       {
2906         //std::cout<<"South Side Custer XY i: "<< i+12 <<", j: "<<j<<std::endl;
2907         MyTC->cd(2);
2908         tpcmon_SSTPC_5e_clusXY[i+12][j] -> Draw("colzsame");
2909         //gStyle->SetLogz(kTRUE);
2910         if ( tpcmon_SSTPC_5e_clusXY[i+12][j]->GetBinContent(tpcmon_SSTPC_5e_clusXY[i+12][j]->GetMaximumBin()) > SS_max)
2911         {
2912           SS_max = tpcmon_SSTPC_5e_clusXY[i+12][j]->GetBinContent(tpcmon_SSTPC_5e_clusXY[i+12][j]->GetMaximumBin());
2913           dummy_his2_u5_XY->SetMaximum( SS_max );
2914         }
2915         gStyle->SetPalette(57); //kBird CVD friendly
2916       }
2917     }
2918 
2919   }
2920   MyTC->cd(2);
2921   e1->SetFillStyle(0);
2922   e2->SetFillStyle(0);
2923   e3->SetFillStyle(0);
2924   e4->SetFillStyle(0);
2925 
2926   e1->Draw("same");
2927   e2->Draw("same");
2928   e3->Draw("same");
2929   e4->Draw("same");
2930   for(int ln2=0;ln2<12;ln2++)
2931   {
2932     lines[ln2]->Draw("same"); 
2933   }
2934 
2935   MyTC->Update();
2936   MyTC->Show();
2937   MyTC->SetEditable(false);
2938 
2939   return 0;
2940 }
2941 
2942 int TpcMonDraw::DrawTPCChansinPacketNS(const std::string & /* what */)
2943 {
2944   OnlMonClient *cl = OnlMonClient::instance();
2945 
2946   TH1 *tpcmon_chanpacketNS[24] = {nullptr};
2947   TH1 *tpcmon_chanpacketalwaysNS[24] = {nullptr};
2948 
2949   TH1 *tpcmon_chanpacketNS_u[48] = {nullptr};
2950   TH1 *tpcmon_chanpacketalwaysNS_u[48] = {nullptr};
2951   
2952   char TPCMON_STR[100];
2953   for( int i=0; i<12; i++ ) 
2954   {
2955     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
2956     sprintf(TPCMON_STR,"TPCMON_%i",i);
2957     tpcmon_chanpacketNS_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Channels_in_Packet");
2958     tpcmon_chanpacketalwaysNS_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Channels_Always");
2959   }
2960 
2961   for( int i=24; i<36; i++ ) 
2962   {
2963     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
2964     sprintf(TPCMON_STR,"TPCMON_%i",i);
2965     tpcmon_chanpacketNS_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Channels_in_Packet");
2966     tpcmon_chanpacketalwaysNS_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Channels_Always");
2967   }
2968 
2969   add_TH1(tpcmon_chanpacketNS_u, tpcmon_chanpacketNS);
2970   add_TH1(tpcmon_chanpacketalwaysNS_u, tpcmon_chanpacketalwaysNS);
2971   
2972   if (!gROOT->FindObject("TPCChan_in_Packets_NS"))
2973   {
2974     MakeCanvas("TPCChan_in_Packets_NS");
2975   }
2976 
2977   TCanvas *MyTC = TC[23];
2978   TPad *TransparentTPad = transparent[23];
2979 
2980   TLine *t1 = new TLine(); t1->SetLineWidth(2);
2981   TLine *t2 = new TLine(); t2->SetLineStyle(2);
2982   TText *tt1= new TText(); tt1->SetTextSize(0.05);
2983 
2984   int FEEid[26]={2,4,3,13,17,16, // R1
2985                  11,12,19,18,0,1,15,14, // R2
2986                  20,22,21,23,25,24,10,9,8,6,7,5 // R3
2987                 };
2988 
2989   char title[50];
2990 
2991   MyTC->SetEditable(true);
2992   MyTC->Clear("D");
2993   for( int i=0; i<12; i++ ) 
2994   {
2995     if( tpcmon_chanpacketNS[i] && tpcmon_chanpacketalwaysNS[i] )
2996     {
2997       MyTC->cd(i+3);
2998       gStyle->SetPadLeftMargin(0.05);
2999       gStyle->SetPadRightMargin(0.02);
3000       tpcmon_chanpacketNS[i]->Divide(tpcmon_chanpacketalwaysNS[i]);
3001 
3002       double Yrange_upper = 1.32*tpcmon_chanpacketNS[i]->GetMaximum();
3003 
3004       tpcmon_chanpacketNS[i]->GetYaxis()->SetRangeUser(0, Yrange_upper);
3005 
3006       tpcmon_chanpacketNS[i]->SetMarkerColor(4);
3007       tpcmon_chanpacketNS[i]->SetLineColor(4);
3008       tpcmon_chanpacketNS[i]->DrawCopy("HIST");
3009       
3010       MyTC->Update();
3011 
3012       for(int j=0;j<25;j++)
3013       {
3014         t2->DrawLine((j+1)*256,-0.01,(j+1)*256,Yrange_upper);
3015       }
3016       for(int k=0;k<26;k++)
3017       {
3018         sprintf(title,"%d",FEEid[k]);
3019         tt1->DrawText(k*256+128,0.84*Yrange_upper,title);
3020       }
3021       tt1->SetTextSize(0.06);
3022       tt1->DrawText(800,0.92*Yrange_upper,"R1");
3023       tt1->DrawText(2450,0.92*Yrange_upper,"R2");
3024       tt1->DrawText(5200,0.92*Yrange_upper,"R3");
3025       tt1->SetTextSize(0.05); 
3026 
3027       t1->DrawLine(1536,0,1536,Yrange_upper);
3028       t1->DrawLine(3584,0,3584,Yrange_upper);
3029 
3030     }
3031   }
3032 
3033   TText PrintRun;
3034   PrintRun.SetTextFont(62);
3035   PrintRun.SetTextSize(0.04);
3036   PrintRun.SetNDC();          // set to normalized coordinates
3037   PrintRun.SetTextAlign(23);  // center/top alignment
3038   std::ostringstream runnostream;
3039   std::string runstring;
3040   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
3041   // fill run number and event time into string
3042   runnostream << ThisName << "_NS_Channels per Packet per RCDAQ Event Run " << cl->RunNumber()
3043               << ", Time: " << ctime(&evttime.first);
3044   runstring = runnostream.str();
3045   TransparentTPad->cd();
3046   PrintRun.SetTextColor(evttime.second);
3047   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
3048 
3049   MyTC->Update();
3050   MyTC->Show();
3051   MyTC->SetEditable(false);
3052 
3053   return 0;
3054 }
3055 
3056 int TpcMonDraw::DrawTPCChansinPacketSS(const std::string & /* what */)
3057 {
3058   OnlMonClient *cl = OnlMonClient::instance();
3059 
3060   TH1 *tpcmon_chanpacketSS[24] = {nullptr};
3061   TH1 *tpcmon_chanpacketalwaysSS[24] = {nullptr};
3062 
3063   TH1 *tpcmon_chanpacketSS_u[48] = {nullptr};
3064   TH1 *tpcmon_chanpacketalwaysSS_u[48] = {nullptr};  
3065   
3066   char TPCMON_STR[100];
3067   for( int i=12; i<24; i++ ) 
3068   {
3069     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
3070     sprintf(TPCMON_STR,"TPCMON_%i",i);
3071     tpcmon_chanpacketSS_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Channels_in_Packet");
3072     tpcmon_chanpacketalwaysSS_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Channels_Always");
3073   }
3074 
3075   for( int i=36; i<48; i++ ) 
3076   {
3077     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
3078     sprintf(TPCMON_STR,"TPCMON_%i",i);
3079     tpcmon_chanpacketSS_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Channels_in_Packet");
3080     tpcmon_chanpacketalwaysSS_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Channels_Always");
3081   }
3082 
3083   add_TH1(tpcmon_chanpacketSS_u, tpcmon_chanpacketSS);
3084   add_TH1(tpcmon_chanpacketalwaysSS_u, tpcmon_chanpacketalwaysSS);
3085 
3086   if (!gROOT->FindObject("TPCChan_in_Packets_SS"))
3087   {
3088     MakeCanvas("TPCChan_in_Packets_SS");
3089   }
3090 
3091   TCanvas *MyTC = TC[24];
3092   TPad *TransparentTPad = transparent[24];
3093 
3094   TLine *t1 = new TLine(); t1->SetLineWidth(2);
3095   TLine *t2 = new TLine(); t2->SetLineStyle(2);
3096   TText *tt1= new TText(); tt1->SetTextSize(0.05);
3097 
3098   int FEEid[26]={2,4,3,13,17,16, // R1
3099                  11,12,19,18,0,1,15,14, // R2
3100                  20,22,21,23,25,24,10,9,8,6,7,5 // R3
3101                 };
3102 
3103   char title[50];
3104 
3105   MyTC->SetEditable(true);
3106   MyTC->Clear("D");
3107   for( int i=12; i<24; i++ ) 
3108   {
3109     if( tpcmon_chanpacketSS[i] && tpcmon_chanpacketalwaysSS[i] )
3110     {
3111       MyTC->cd(i-12+3);
3112       gStyle->SetPadLeftMargin(0.05);
3113       gStyle->SetPadRightMargin(0.02);
3114       tpcmon_chanpacketSS[i]->Divide(tpcmon_chanpacketalwaysSS[i]);
3115       double Yrange_upper = 1.32*tpcmon_chanpacketSS[i]->GetMaximum();
3116       tpcmon_chanpacketSS[i]->GetYaxis()->SetRangeUser(0, Yrange_upper);
3117 
3118       tpcmon_chanpacketSS[i]->SetMarkerColor(4);
3119       tpcmon_chanpacketSS[i]->SetLineColor(4);
3120       tpcmon_chanpacketSS[i]->DrawCopy("HIST");
3121       
3122       MyTC->Update();
3123 
3124       for(int j=0;j<25;j++)
3125       {
3126         t2->DrawLine((j+1)*256,-0.01,(j+1)*256,Yrange_upper);
3127       }
3128       for(int k=0;k<26;k++)
3129       {
3130         sprintf(title,"%d",FEEid[k]);
3131         tt1->DrawText(k*256+128,0.84*Yrange_upper,title);
3132       }
3133       tt1->SetTextSize(0.06);
3134       tt1->DrawText(800,0.92*Yrange_upper,"R1");
3135       tt1->DrawText(2450,0.92*Yrange_upper,"R2");
3136       tt1->DrawText(5200,0.92*Yrange_upper,"R3");
3137       tt1->SetTextSize(0.05); 
3138 
3139       t1->DrawLine(1536,0,1536,Yrange_upper);
3140       t1->DrawLine(3584,0,3584,Yrange_upper);
3141 
3142     }
3143   }
3144 
3145   TText PrintRun;
3146   PrintRun.SetTextFont(62);
3147   PrintRun.SetTextSize(0.04);
3148   PrintRun.SetNDC();          // set to normalized coordinates
3149   PrintRun.SetTextAlign(23);  // center/top alignment
3150   std::ostringstream runnostream;
3151   std::string runstring;
3152   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
3153   // fill run number and event time into string
3154   runnostream << ThisName << "_SS_Channels per Packet per RCDAQ Event Run " << cl->RunNumber()
3155               << ", Time: " << ctime(&evttime.first);
3156   runstring = runnostream.str();
3157   TransparentTPad->cd();
3158   PrintRun.SetTextColor(evttime.second);
3159   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
3160 
3161   MyTC->Update();
3162   MyTC->Show();
3163   MyTC->SetEditable(false);
3164 
3165   return 0;
3166 }
3167 
3168 int TpcMonDraw::DrawTPCNonZSChannels(const std::string & /* what */)
3169 {
3170   OnlMonClient *cl = OnlMonClient::instance();
3171 
3172   TH2 *tpcmon_nonZSchannels_u[48] = {nullptr};
3173   TH2 *tpcmon_nonZSchannels[24] = {nullptr};
3174   
3175   char TPCMON_STR[100];
3176   for( int i=0; i<48; i++ ) 
3177   {
3178     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
3179     sprintf(TPCMON_STR,"TPCMON_%i",i);
3180     tpcmon_nonZSchannels_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"Num_non_ZS_channels_vs_SAMPA");
3181   }
3182 
3183   add_TH2(tpcmon_nonZSchannels_u, tpcmon_nonZSchannels);
3184 
3185   if (!gROOT->FindObject("TPCNonZSChannels"))
3186   {
3187     MakeCanvas("TPCNonZSChannels");
3188   }
3189   TCanvas *MyTC = TC[25];
3190   TPad *TransparentTPad = transparent[25];
3191   MyTC->SetEditable(true);
3192   MyTC->Clear("D");
3193 
3194   TLine *t1 = new TLine(); t1->SetLineWidth(2);
3195   TLine *t2 = new TLine(); t2->SetLineStyle(2);
3196   TText *tt1= new TText(); tt1->SetTextSize(0.05);
3197 
3198   int FEEid[26]={2,4,3,13,17,16, // R1
3199                  11,12,19,18,0,1,15,14, // R2
3200                  20,22,21,23,25,24,10,9,8,6,7,5 // R3
3201                 };
3202 
3203   char title[50];
3204 
3205   gStyle->SetOptStat(0);
3206   gStyle->SetPalette(57); //kBird CVD friendly
3207 
3208   for( int i=0; i<24; i++ ) 
3209   {
3210     if( tpcmon_nonZSchannels[i] )
3211     {
3212       MyTC->cd(i+5);
3213       tpcmon_nonZSchannels[i]->DrawCopy("colz");
3214       gPad->SetLogz(kTRUE);
3215 
3216       MyTC->Update();
3217 
3218       for(int j=0;j<25;j++)
3219       {
3220         t2->DrawLine((j+1)*8,-300.01,(j+1)*8,1024);
3221       }
3222       for(int k=0;k<26;k++)
3223       {
3224         sprintf(title,"%d",FEEid[k]);
3225         tt1->DrawText(k*8+4,-100,title);
3226       }
3227       tt1->SetTextSize(0.06);
3228       tt1->DrawText(25,-200,"R1");
3229       tt1->DrawText(77,-200,"R2");
3230       tt1->DrawText(163,-200,"R3");
3231       tt1->SetTextSize(0.05); 
3232 
3233       t1->DrawLine(48,-300.01,48,1024);
3234       t1->DrawLine(112,-300.01,112,1024);
3235     }
3236   }
3237 
3238   TText PrintRun;
3239   PrintRun.SetTextFont(62);
3240   PrintRun.SetTextSize(0.04);
3241   PrintRun.SetNDC();          // set to normalized coordinates
3242   PrintRun.SetTextAlign(23);  // center/top alignment
3243   std::ostringstream runnostream;
3244   std::string runstring;
3245   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
3246   // fill run number and event time into string
3247   runnostream << ThisName << "_Non-ZS Channels per SAMPA Run " << cl->RunNumber()
3248               << ", Time: " << ctime(&evttime.first);
3249   runstring = runnostream.str();
3250   TransparentTPad->cd();
3251   PrintRun.SetTextColor(evttime.second);
3252   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
3253 
3254   MyTC->Update();
3255   MyTC->Show();
3256   MyTC->SetEditable(false);
3257 
3258   return 0;
3259 }
3260 
3261 int TpcMonDraw::DrawTPCZSTriggerADCSample(const std::string & /* what */)
3262 {
3263   OnlMonClient *cl = OnlMonClient::instance();
3264 
3265   TH2 *tpcmon_ZSTriggerADCSampledist[24] = {nullptr};
3266   TH2 *tpcmon_ZSTriggerADCSampledist_u[48] = {nullptr};
3267 
3268   char TPCMON_STR[100];
3269   for( int i=0; i<48; i++ ) 
3270   {
3271     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
3272     sprintf(TPCMON_STR,"TPCMON_%i",i);
3273     tpcmon_ZSTriggerADCSampledist_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"ZS_Trigger_ADC_vs_Sample");
3274   }
3275 
3276   add_TH2( tpcmon_ZSTriggerADCSampledist_u,  tpcmon_ZSTriggerADCSampledist);
3277 
3278   if (!gROOT->FindObject("TPCNonZSTriggerADCvsSample"))
3279   {
3280     MakeCanvas("TPCNonZSTriggerADCvsSample");
3281   }
3282 
3283   TCanvas *MyTC = TC[26];
3284   TPad *TransparentTPad = transparent[26];
3285   MyTC->SetEditable(true);
3286   MyTC->Clear("D");
3287 
3288   gStyle->SetOptStat(0);
3289   gStyle->SetPalette(57); //kBird CVD friendly
3290 
3291   for( int i=0; i<24; i++ ) 
3292   {
3293     if( tpcmon_ZSTriggerADCSampledist[i] )
3294     {
3295       MyTC->cd(i+5);
3296       tpcmon_ZSTriggerADCSampledist[i]->GetXaxis()->SetRangeUser(0, 20);
3297       tpcmon_ZSTriggerADCSampledist[i]->DrawCopy("colz");
3298       gPad->SetLogz(kTRUE);
3299       gPad->SetLogy(kTRUE);
3300       gPad->SetGridy(kTRUE);
3301     }
3302   }
3303 
3304   TText PrintRun;
3305   PrintRun.SetTextFont(62);
3306   PrintRun.SetTextSize(0.04);
3307   PrintRun.SetNDC();          // set to normalized coordinates
3308   PrintRun.SetTextAlign(23);  // center/top alignment
3309   std::ostringstream runnostream;
3310   std::string runstring;
3311   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
3312   // fill run number and event time into string
3313   runnostream << ThisName << "_Trigger ADC vs Sample Run " << cl->RunNumber()
3314               << ", Time: " << ctime(&evttime.first);
3315   runstring = runnostream.str();
3316   TransparentTPad->cd();
3317   PrintRun.SetTextColor(evttime.second);
3318   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
3319 
3320   MyTC->Update();
3321   MyTC->Show();
3322   MyTC->SetEditable(false);
3323 
3324   return 0;
3325 }
3326 
3327 int TpcMonDraw::DrawTPCFirstnonZSADCFirstnonZSSample(const std::string & /* what */)
3328 {
3329   OnlMonClient *cl = OnlMonClient::instance();
3330 
3331   TH2 *tpcmon_FirstNZSADCvsFirstNZSSample[24] = {nullptr};
3332   TH2 *tpcmon_FirstNZSADCvsFirstNZSSample_u[48] = {nullptr};
3333   
3334   char TPCMON_STR[100];
3335   for( int i=0; i<48; i++ ) 
3336   {
3337     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
3338     sprintf(TPCMON_STR,"TPCMON_%i",i);
3339     tpcmon_FirstNZSADCvsFirstNZSSample_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"First_ADC_vs_First_Time_Bin");
3340   }
3341 
3342   add_TH2(tpcmon_FirstNZSADCvsFirstNZSSample_u, tpcmon_FirstNZSADCvsFirstNZSSample);
3343   
3344   if (!gROOT->FindObject("TPCFirstADCvsFirstSample"))
3345   {
3346     MakeCanvas("TPCFirstADCvsFirstSample");
3347   }
3348 
3349   TCanvas *MyTC = TC[27];
3350   TPad *TransparentTPad = transparent[27];
3351   MyTC->SetEditable(true);
3352   MyTC->Clear("D");
3353 
3354   gStyle->SetOptStat(0);
3355   gStyle->SetPalette(57); //kBird CVD friendly
3356 
3357   for( int i=0; i<24; i++ ) 
3358   {
3359     if( tpcmon_FirstNZSADCvsFirstNZSSample[i] )
3360     {
3361       MyTC->cd(i+5);
3362       tpcmon_FirstNZSADCvsFirstNZSSample[i]->RebinX(5);
3363       tpcmon_FirstNZSADCvsFirstNZSSample[i]->DrawCopy("colz");
3364       gPad->SetLogz(kTRUE);
3365       gPad->SetLogy(kTRUE);
3366     }
3367   }
3368 
3369   TText PrintRun;
3370   PrintRun.SetTextFont(62);
3371   PrintRun.SetTextSize(0.04);
3372   PrintRun.SetNDC();          // set to normalized coordinates
3373   PrintRun.SetTextAlign(23);  // center/top alignment
3374   std::ostringstream runnostream;
3375   std::string runstring;
3376   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
3377   // fill run number and event time into string
3378   runnostream << ThisName << "_1st non-ZS ADC vs 1st non-ZS Sample Run " << cl->RunNumber()
3379               << ", Time: " << ctime(&evttime.first);
3380   runstring = runnostream.str();
3381   TransparentTPad->cd();
3382   PrintRun.SetTextColor(evttime.second);
3383   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
3384 
3385   MyTC->Update();
3386   MyTC->Show();
3387   MyTC->SetEditable(false);
3388 
3389   return 0;
3390 }
3391 
3392 int TpcMonDraw::DrawTPCDriftWindow(const std::string & /* what */)
3393 {
3394   OnlMonClient *cl = OnlMonClient::instance();
3395 
3396   TH1 *tpcmon_DriftWindow[24][3] = {nullptr};
3397   TH1 *tpcmon_DriftWindow_u[48][3] = {nullptr};
3398   
3399   char TPCMON_STR[100];
3400   for( int i=0; i<48; i++ ) 
3401   {
3402     for( int j=0; j<3; j++ )
3403     {
3404       //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
3405       sprintf(TPCMON_STR,"TPCMON_%i",i);
3406       tpcmon_DriftWindow_u[i][0] = (TH1*) cl->getHisto(TPCMON_STR,"COUNTS_vs_SAMPLE_1D_R1");//tpcmon_DriftWindow[i][0]->GetXaxis()->SetRangeUser(0,500);
3407       tpcmon_DriftWindow_u[i][1] = (TH1*) cl->getHisto(TPCMON_STR,"COUNTS_vs_SAMPLE_1D_R2");//tpcmon_DriftWindow[i][1]->GetXaxis()->SetRangeUser(0,500);
3408       tpcmon_DriftWindow_u[i][2] = (TH1*) cl->getHisto(TPCMON_STR,"COUNTS_vs_SAMPLE_1D_R3");//tpcmon_DriftWindow[i][2]->GetXaxis()->SetRangeUser(0,500);
3409     }
3410   }
3411 
3412   add_TH1_modules( tpcmon_DriftWindow_u, tpcmon_DriftWindow);
3413 
3414   if (!gROOT->FindObject("TPCDriftWindow"))
3415   {
3416     MakeCanvas("TPCDriftWindow");
3417   }
3418 
3419   TCanvas *MyTC = TC[28];
3420   TPad *TransparentTPad = transparent[28];
3421   MyTC->SetEditable(true);
3422   MyTC->Clear("D");
3423 
3424   gStyle->SetOptStat(0);
3425   gStyle->SetPalette(57); //kBird CVD friendly
3426 
3427   auto legend = new TLegend(0.7,0.65,0.98,0.95);
3428   bool draw_leg = 0;
3429 
3430   for( int i=0; i<24; i++ )
3431   {
3432     MyTC->cd(i+5);
3433 
3434     int min = std::numeric_limits<int>::max(); // start wih the largest possible value
3435     int max = std::numeric_limits<int>::min(); // start with smalles possible value
3436     int no_laser_max =  std::numeric_limits<int>::min(); // start with smalles possible value
3437 
3438     bool no_laser_window = 0;
3439     
3440     for( int j = 2; j>-1; j-- )
3441     {
3442       if( tpcmon_DriftWindow[i][j] )
3443       {
3444         for( int k = 1; k < tpcmon_DriftWindow[i][j]->GetNbinsX(); k++ ) // old laser peak 416, new laser peak 403, new laser peak w/ 57.14 ns clock 368
3445     {
3446           if( (k>=0 && k<=350) || (k>380) ){ no_laser_window = 1;}
3447           if( k>350 && k<=380){ no_laser_window = 0;}
3448           if( (tpcmon_DriftWindow[i][j]->GetBinContent(k) > no_laser_max && tpcmon_DriftWindow[i][j]->GetBinContent(k) > 0) && (no_laser_window==1) ){no_laser_max = tpcmon_DriftWindow[i][j]->GetBinContent(k);}
3449           if( tpcmon_DriftWindow[i][j]->GetBinContent(k) > max && tpcmon_DriftWindow[i][j]->GetBinContent(k) > 0 ){max = tpcmon_DriftWindow[i][j]->GetBinContent(k);}
3450           if( tpcmon_DriftWindow[i][j]->GetBinContent(k) < min && tpcmon_DriftWindow[i][j]->GetBinContent(k) > 0 ){min = tpcmon_DriftWindow[i][j]->GetBinContent(k);}
3451     }
3452       }
3453     }
3454 
3455 
3456     for( int l = 2; l>-1; l-- )
3457     {
3458       if( tpcmon_DriftWindow[i][l] )
3459       {
3460         tpcmon_DriftWindow[i][l]->GetXaxis()->SetRangeUser(0,500);
3461         if(l == 2){tpcmon_DriftWindow[i][l]->GetYaxis()->SetRangeUser(0.9*min,1.1*max);tpcmon_DriftWindow[i][l] -> DrawCopy("HIST");} //used to be 
3462         else      {tpcmon_DriftWindow[i][l]->GetYaxis()->SetRangeUser(0.9*min,1.1*max);tpcmon_DriftWindow[i][l] -> DrawCopy("HISTsame");} //assumes that R3 will always exist and is most entries
3463       }
3464     }
3465     
3466     gPad->Update();  
3467 
3468     if(draw_leg == 0 && tpcmon_DriftWindow[i][0] && tpcmon_DriftWindow[i][1] && tpcmon_DriftWindow[i][2]) //if you have not drawn the legend yet, draw it BUT ONLY ONCE
3469     {
3470       legend->AddEntry(tpcmon_DriftWindow[i][0], "R1");
3471       legend->AddEntry(tpcmon_DriftWindow[i][1], "R2");
3472       legend->AddEntry(tpcmon_DriftWindow[i][2], "R3");
3473       MyTC->cd(i+5);
3474       legend->Draw();
3475       draw_leg = 1; //don't draw it again
3476     }
3477   }
3478 
3479   TText PrintRun;
3480   PrintRun.SetTextFont(62);
3481   PrintRun.SetTextSize(0.04);
3482   PrintRun.SetNDC();          // set to normalized coordinates
3483   PrintRun.SetTextAlign(23);  // center/top alignment
3484   std::ostringstream runnostream;
3485   std::string runstring;
3486   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
3487   // fill run number and event time into string
3488   runnostream << ThisName << "_Drift Window, ADC-Pedestal>(5sigma||20ADC) Run " << cl->RunNumber()
3489               << ", Time: " << ctime(&evttime.first);
3490   runstring = runnostream.str();
3491   TransparentTPad->cd();
3492   PrintRun.SetTextColor(evttime.second);
3493   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
3494 
3495   MyTC->Update();
3496   MyTC->Show();
3497   MyTC->SetEditable(false);
3498 
3499   return 0;
3500 }
3501 
3502 
3503 int TpcMonDraw::DrawTPCNStreaksvsEventNo(const std::string & /* what */)
3504 {
3505   OnlMonClient *cl = OnlMonClient::instance();
3506 
3507   TH1 *tpcmon_NStreak_vsEventNo[24] = {nullptr};
3508   TH1 *tpcmoneventsebdc[24] = {nullptr};
3509 
3510   TH1 *tpcmon_NStreak_vsEventNo_u[48] = {nullptr};
3511   TH1 *tpcmoneventsebdc_u[48] = {nullptr};
3512   
3513   char TPCMON_STR[100];
3514 
3515   for( int i=0; i<48; i++) //get the streakers vs event nos from each event histo 
3516   {
3517     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
3518     sprintf(TPCMON_STR,"TPCMON_%i",i);
3519     tpcmon_NStreak_vsEventNo_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"NStreaks_vs_EventNo");
3520   }
3521 
3522   for( int i=0; i<48; i++) //get the num of events from each event histo 
3523   {
3524     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
3525     sprintf(TPCMON_STR,"TPCMON_%i",i);
3526     tpcmoneventsebdc_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"NEvents_vs_EBDC");
3527   }
3528 
3529   add_TH1( tpcmon_NStreak_vsEventNo_u,  tpcmon_NStreak_vsEventNo);
3530   add_TH1( tpcmoneventsebdc_u,  tpcmoneventsebdc  );
3531   
3532   if (!gROOT->FindObject("TPCNStreakersvsEventNo"))
3533   {
3534     MakeCanvas("TPCNStreakersvsEventNo");
3535   }    
3536 
3537   int event_max = 0;
3538   int horiz_max = 0; 
3539 
3540   for ( int i=0; i< 24; i++ )
3541   {
3542     if( tpcmoneventsebdc[i] )
3543     {
3544       if(tpcmoneventsebdc[i]->GetBinContent(i+1) > event_max){event_max = tpcmoneventsebdc[i]->GetBinContent(i+1);}
3545       if(tpcmoneventsebdc[i]->GetBinContent(tpcmoneventsebdc[i]->GetMaximumBin()) > horiz_max){horiz_max = tpcmoneventsebdc[i]->GetBinContent(tpcmoneventsebdc[i]->GetMaximumBin());}
3546     }
3547   }
3548 
3549 
3550   int line_colors[24] = { 3, 8, 2, 6, 46, 14, 1, 39, 38, 4, 7, 30, 3, 8, 6, 2, 46, 4, 1, 39, 38, 4, 7, 30 }; // assumed filling down and across
3551   //int line_colors_leg[24] = {2, 3, 38, 14, 6, 8, 4, 1, 46, 30, 7, 39, 6, 3, 38, 4, 2, 8, 4, 1, 46, 30, 7, 39 }; // assumed filling across and down
3552 
3553   TCanvas *MyTC = TC[29];
3554   TPad *TransparentTPad = transparent[29];
3555 
3556   auto leg1 = new TLegend(0.6,0.65,0.98,0.95);
3557   leg1->SetNColumns(4);
3558 
3559   leg1->AddEntry((TObject*)0,"North Top","");
3560   leg1->AddEntry((TObject*)0,"North West","");
3561   leg1->AddEntry((TObject*)0,"North Bottom","");
3562   leg1->AddEntry((TObject*)0,"North East","");
3563 
3564   auto leg2 = new TLegend(0.6,0.65,0.98,0.95);
3565   leg2->SetNColumns(4);
3566   leg2->AddEntry((TObject*)0,"South Top","");
3567   leg2->AddEntry((TObject*)0,"South West","");
3568   leg2->AddEntry((TObject*)0,"South Bottom","");
3569   leg2->AddEntry((TObject*)0,"South East","");
3570 
3571   // int order[24] = {2, 3, 4, 0, 1, 11, 8, 9, 10, 5, 6, 7, 14, 15, 16, 12, 13, 23, 20, 21, 22, 17, 18, 19}; // assumed filling down and across
3572   int order_leg[24] = {2, 0, 8, 5, 3, 1, 9, 6, 4, 11, 10, 7, 14, 12, 20, 17, 15, 13, 21, 18, 16, 23, 22, 19}; // assumed filling across and down
3573 
3574   char legend_str[100];
3575 
3576   for( int i=0; i<24; i++) // legend loop
3577   {
3578 
3579     if( tpcmon_NStreak_vsEventNo[order_leg[i]] && i <=11 )
3580     {
3581       sprintf(legend_str,"Sector %i",order_leg[i]);
3582       leg1->AddEntry(tpcmon_NStreak_vsEventNo[order_leg[i]],legend_str);
3583     }
3584 
3585     if( !tpcmon_NStreak_vsEventNo[order_leg[i]] && i <=11 )
3586     {
3587       leg1->AddEntry((TObject*)0,"","");    
3588     }
3589 
3590     if( tpcmon_NStreak_vsEventNo[order_leg[i]] && i > 11 )
3591     {
3592       sprintf(legend_str,"Sector %i",order_leg[i]);
3593       leg2->AddEntry(tpcmon_NStreak_vsEventNo[order_leg[i]],legend_str);
3594     }
3595 
3596     if( !tpcmon_NStreak_vsEventNo[order_leg[i]] && i > 11 )
3597     {
3598       leg2->AddEntry((TObject*)0,"","");    
3599     }    
3600 
3601   }
3602 
3603   MyTC->SetEditable(true);
3604   MyTC->Clear("D");
3605   for( int i=0; i<24; i++ ) 
3606   {
3607     if( tpcmon_NStreak_vsEventNo[i] )
3608     {
3609 
3610       if( i <= 11){MyTC->cd(1);}
3611       else { MyTC->cd(2);}
3612       gStyle->SetPadLeftMargin(0.05);
3613       gStyle->SetPadRightMargin(0.02);
3614 
3615       tpcmon_NStreak_vsEventNo[i]->GetXaxis()->SetRangeUser(0, event_max);
3616       tpcmon_NStreak_vsEventNo[i]->GetYaxis()->SetRangeUser(0.01,1.1*horiz_max);
3617       tpcmon_NStreak_vsEventNo[i]->SetStats(kFALSE);
3618       tpcmon_NStreak_vsEventNo[i]->SetTitle("");    
3619 
3620       tpcmon_NStreak_vsEventNo[i]->SetMarkerColor(line_colors[i]);
3621       tpcmon_NStreak_vsEventNo[i]->SetLineColor(line_colors[i]);
3622       tpcmon_NStreak_vsEventNo[i]->SetLineWidth(3);   
3623       tpcmon_NStreak_vsEventNo[i]->Draw("LF2 same"); 
3624 
3625       gPad->SetLogy(kTRUE);
3626        
3627       MyTC->Update();
3628 
3629     }
3630   }
3631 
3632   MyTC->cd(1);
3633   leg1->Draw("same");
3634   MyTC->cd(2);
3635   leg2->Draw("same");
3636 
3637 
3638   TText PrintRun;
3639   PrintRun.SetTextFont(62);
3640   PrintRun.SetTextSize(0.04);
3641   PrintRun.SetNDC();          // set to normalized coordinates
3642   PrintRun.SetTextAlign(23);  // center/top alignment
3643   std::ostringstream runnostream;
3644   std::string runstring;
3645   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
3646   // fill run number and event time into string
3647   runnostream << ThisName << "_NStreakers_vs_Event # Packet per Sector" << cl->RunNumber()
3648               << ", Time: " << ctime(&evttime.first);
3649   runstring = runnostream.str();
3650   TransparentTPad->cd();
3651   PrintRun.SetTextColor(evttime.second);
3652   PrintRun.DrawText(0.5, 0.99, runstring.c_str());
3653 
3654   MyTC->Update();
3655   MyTC->Show();
3656   MyTC->SetEditable(false);
3657 
3658   return 0;
3659 }
3660 
3661 int TpcMonDraw::DrawTPCPacketTypes(const std::string & /* what */)
3662 {
3663   OnlMonClient *cl = OnlMonClient::instance();
3664 
3665   TH1 *tpcmon_PacketType[24][3] = {nullptr};
3666   TH1 *tpcmon_PacketType_u[48][3] = {nullptr};
3667   
3668   char TPCMON_STR[100];
3669   for( int i=0; i<48; i++ ) 
3670   {
3671     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
3672     sprintf(TPCMON_STR,"TPCMON_%i",i);
3673     tpcmon_PacketType_u[i][0] = (TH1*) cl->getHisto(TPCMON_STR,"Packet_Type_Fraction_HB");
3674     tpcmon_PacketType_u[i][1] = (TH1*) cl->getHisto(TPCMON_STR,"Packet_Type_Fraction_NORM");
3675     tpcmon_PacketType_u[i][2] = (TH1*) cl->getHisto(TPCMON_STR,"Packet_Type_Fraction_ELSE");
3676   }
3677 
3678   add_TH1_modules(tpcmon_PacketType_u, tpcmon_PacketType);
3679   
3680   if (!gROOT->FindObject("TPCPacketType"))
3681   {
3682     MakeCanvas("TPCPacketType");
3683   }
3684 
3685   TCanvas *MyTC = TC[30];
3686   TPad *TransparentTPad = transparent[30];
3687   MyTC->SetEditable(true);
3688   MyTC->Clear("D");
3689 
3690   gStyle->SetOptStat(0);
3691   gStyle->SetPalette(57); //kBird CVD friendly
3692 
3693   double normfactor = 0;
3694 
3695   int index_arr[3] = {1, 0, 2} ;
3696 
3697   double norm_highest = 0.;
3698   int index_highest = 1;
3699 
3700   for( int i=0; i<24; i++ ) 
3701   {
3702 
3703     for( int k=0; k<3; k++)
3704     { 
3705       if(tpcmon_PacketType[i][k])
3706       { 
3707         normfactor += (tpcmon_PacketType[i][k]->GetEntries()); 
3708         if(tpcmon_PacketType[i][k]->GetEntries()>norm_highest){ norm_highest = (tpcmon_PacketType[i][k]->GetEntries());index_highest=k; } 
3709       }  
3710     }
3711 
3712     if(index_highest == 0){ index_arr[0] = 0; index_arr[1] = 1; index_arr[2] = 2; }
3713     if(index_highest == 2){ index_arr[0] = 2; index_arr[1] = 1; index_arr[2] = 0; }
3714 
3715     for( int j=0; j< 3; j++)
3716     {
3717       if( tpcmon_PacketType[i][index_arr[j]] )
3718       {
3719         MyTC->cd(i+5);
3720         if(normfactor > 0){tpcmon_PacketType[i][index_arr[j]]->Scale(1/(normfactor),"width");}
3721         gPad->SetLogy(kTRUE);
3722         if(j == 0){ tpcmon_PacketType[i][index_arr[j]]->DrawCopy("HIST"); }
3723         else{  tpcmon_PacketType[i][index_arr[j]]->DrawCopy("HISTsame");}  
3724       } 
3725     }
3726 
3727     gPad->Update();
3728  
3729     normfactor = 0; //reset this after scaling each histogram at end of iteration of outer for loop (i loop)
3730 
3731   }
3732 
3733   TText PrintRun;
3734   PrintRun.SetTextFont(62);
3735   PrintRun.SetTextSize(0.04);
3736   PrintRun.SetNDC();          // set to normalized coordinates
3737   PrintRun.SetTextAlign(23);  // center/top alignment
3738   std::ostringstream runnostream;
3739   std::string runstring;
3740   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
3741   // fill run number and event time into string
3742   runnostream << ThisName << "_WF PACKET FRACTION Run " << cl->RunNumber()
3743               << ", Time: " << ctime(&evttime.first);
3744   runstring = runnostream.str();
3745   TransparentTPad->cd();
3746   PrintRun.SetTextColor(evttime.second);
3747   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
3748 
3749   MyTC->Update();
3750   MyTC->Show();
3751   MyTC->SetEditable(false);
3752 
3753   return 0;
3754 }
3755 
3756 int TpcMonDraw::DrawTPCChansperLVL1_NS(const std::string & /* what */)
3757 {
3758   OnlMonClient *cl = OnlMonClient::instance();
3759 
3760   TH1 *tpcmon_chanlvl1NS[24] = {nullptr};
3761   TH1 *lvl1_per_EBDC[24] = {nullptr};
3762 
3763   TH1 *tpcmon_chanlvl1NS_u[48] = {nullptr};
3764   TH1 *lvl1_per_EBDC_u[48] = {nullptr};
3765   
3766   char TPCMON_STR[100];
3767   for( int i=0; i<12; i++ ) 
3768   {
3769     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
3770     sprintf(TPCMON_STR,"TPCMON_%i",i);
3771     tpcmon_chanlvl1NS_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Channels_in_Packet");
3772     lvl1_per_EBDC_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"LVL_1_TAGGER_per_EBDC");
3773   }
3774 
3775   for( int i=24; i<36; i++ ) 
3776   {
3777     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
3778     sprintf(TPCMON_STR,"TPCMON_%i",i);
3779     tpcmon_chanlvl1NS_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Channels_in_Packet");
3780     lvl1_per_EBDC_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"LVL_1_TAGGER_per_EBDC");
3781   }  
3782 
3783   add_TH1(tpcmon_chanlvl1NS_u, tpcmon_chanlvl1NS);
3784   add_TH1(lvl1_per_EBDC_u, lvl1_per_EBDC);
3785   
3786   if (!gROOT->FindObject("TPCChan_per_LVL1_NS"))
3787   {
3788     MakeCanvas("TPCChan_per_LVL1_NS");
3789   }
3790 
3791   TCanvas *MyTC = TC[31];
3792   TPad *TransparentTPad = transparent[31];
3793 
3794   TLine *t1 = new TLine(); t1->SetLineWidth(2);
3795   TLine *t2 = new TLine(); t2->SetLineStyle(2);
3796   TText *tt1= new TText(); tt1->SetTextSize(0.05);
3797 
3798   int FEEid[26]={2,4,3,13,17,16, // R1
3799                  11,12,19,18,0,1,15,14, // R2
3800                  20,22,21,23,25,24,10,9,8,6,7,5 // R3
3801                 };
3802 
3803   char title[50];
3804 
3805   MyTC->SetEditable(true);
3806   MyTC->Clear("D");
3807   for( int i=0; i<12; i++ ) 
3808   {
3809     if( tpcmon_chanlvl1NS[i] && lvl1_per_EBDC[i] )
3810     {
3811       MyTC->cd(i+3);
3812       gStyle->SetPadLeftMargin(0.05);
3813       gStyle->SetPadRightMargin(0.02);
3814       tpcmon_chanlvl1NS[i]->Scale(1/(lvl1_per_EBDC[i]->GetBinContent(i+1)),"width");
3815       double Yrange_upper = 1.32*tpcmon_chanlvl1NS[i]->GetMaximum();
3816       tpcmon_chanlvl1NS[i]->GetYaxis()->SetRangeUser(0, Yrange_upper);
3817 
3818       tpcmon_chanlvl1NS[i]->SetMarkerColor(4);
3819       tpcmon_chanlvl1NS[i]->SetLineColor(4);
3820       tpcmon_chanlvl1NS[i]->SetFillColor(5);
3821       tpcmon_chanlvl1NS[i]->DrawCopy("HIST");
3822       
3823       MyTC->Update();
3824 
3825       for(int j=0;j<25;j++)
3826       {
3827         t2->DrawLine((j+1)*256,-0.01,(j+1)*256,Yrange_upper);
3828       }
3829       for(int k=0;k<26;k++)
3830       {
3831         sprintf(title,"%d",FEEid[k]);
3832         tt1->DrawText(k*256+128,0.84*Yrange_upper,title);
3833       }
3834       tt1->SetTextSize(0.06);
3835       tt1->DrawText(800,0.92*Yrange_upper,"R1");
3836       tt1->DrawText(2450,0.92*Yrange_upper,"R2");
3837       tt1->DrawText(5200,0.92*Yrange_upper,"R3");
3838       tt1->SetTextSize(0.05); 
3839 
3840       t1->DrawLine(1536,0,1536,Yrange_upper);
3841       t1->DrawLine(3584,0,3584,Yrange_upper);
3842 
3843     }
3844   }
3845 
3846   TText PrintRun;
3847   PrintRun.SetTextFont(62);
3848   PrintRun.SetTextSize(0.04);
3849   PrintRun.SetNDC();          // set to normalized coordinates
3850   PrintRun.SetTextAlign(23);  // center/top alignment
3851   std::ostringstream runnostream;
3852   std::string runstring;
3853   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
3854   // fill run number and event time into string
3855   runnostream << ThisName << "_NS_Channels per LEVEL_1 TAGGER Run " << cl->RunNumber()
3856               << ", Time: " << ctime(&evttime.first);
3857   runstring = runnostream.str();
3858   TransparentTPad->cd();
3859   PrintRun.SetTextColor(evttime.second);
3860   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
3861 
3862   MyTC->Update();
3863   MyTC->Show();
3864   MyTC->SetEditable(false);
3865 
3866   return 0;
3867 }
3868 
3869 int TpcMonDraw::DrawTPCChansperLVL1_SS(const std::string & /* what */)
3870 {
3871   OnlMonClient *cl = OnlMonClient::instance();
3872 
3873   TH1 *tpcmon_chanlvl1SS[24] = {nullptr};
3874   TH1 *lvl1_per_EBDC[24] = {nullptr};
3875 
3876   TH1 *tpcmon_chanlvl1SS_u[48] = {nullptr};
3877   TH1 *lvl1_per_EBDC_u[48] = {nullptr};
3878 
3879   char TPCMON_STR[100];
3880   for( int i=12; i<24; i++ ) 
3881   {
3882     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
3883     sprintf(TPCMON_STR,"TPCMON_%i",i);
3884     tpcmon_chanlvl1SS_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Channels_in_Packet");
3885     lvl1_per_EBDC_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"LVL_1_TAGGER_per_EBDC");
3886   }
3887 
3888   for( int i=36; i<48; i++ ) 
3889   {
3890     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
3891     sprintf(TPCMON_STR,"TPCMON_%i",i);
3892     tpcmon_chanlvl1SS_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Channels_in_Packet");
3893     lvl1_per_EBDC_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"LVL_1_TAGGER_per_EBDC");
3894   }  
3895 
3896   add_TH1(tpcmon_chanlvl1SS_u, tpcmon_chanlvl1SS);
3897   add_TH1(lvl1_per_EBDC_u, lvl1_per_EBDC);
3898 
3899   if (!gROOT->FindObject("TPCChan_per_LVL1_SS"))
3900   {
3901     MakeCanvas("TPCChan_per_LVL1_SS");
3902   }
3903 
3904   TCanvas *MyTC = TC[32];
3905   TPad *TransparentTPad = transparent[32];
3906 
3907   TLine *t1 = new TLine(); t1->SetLineWidth(2);
3908   TLine *t2 = new TLine(); t2->SetLineStyle(2);
3909   TText *tt1= new TText(); tt1->SetTextSize(0.05);
3910 
3911   int FEEid[26]={2,4,3,13,17,16, // R1
3912                  11,12,19,18,0,1,15,14, // R2
3913                  20,22,21,23,25,24,10,9,8,6,7,5 // R3
3914                 };
3915 
3916   char title[50];
3917 
3918   MyTC->SetEditable(true);
3919   MyTC->Clear("D");
3920   for( int i=12; i<24; i++ ) 
3921   {
3922     if( tpcmon_chanlvl1SS[i] && lvl1_per_EBDC[i] )
3923     {
3924       MyTC->cd(i-12+3);
3925       gStyle->SetPadLeftMargin(0.05);
3926       gStyle->SetPadRightMargin(0.02);
3927       tpcmon_chanlvl1SS[i]->Scale(1/(lvl1_per_EBDC[i]->GetBinContent(i-12+13)),"width");
3928       double Yrange_upper = 1.32*tpcmon_chanlvl1SS[i]->GetMaximum();
3929       tpcmon_chanlvl1SS[i]->GetYaxis()->SetRangeUser(0, Yrange_upper);
3930 
3931       tpcmon_chanlvl1SS[i]->SetMarkerColor(4);
3932       tpcmon_chanlvl1SS[i]->SetLineColor(4);
3933       tpcmon_chanlvl1SS[i]->SetFillColor(5);
3934       tpcmon_chanlvl1SS[i]->DrawCopy("HIST");
3935       
3936       MyTC->Update();
3937 
3938       for(int j=0;j<25;j++)
3939       {
3940         t2->DrawLine((j+1)*256,-0.01,(j+1)*256,Yrange_upper);
3941       }
3942       for(int k=0;k<26;k++)
3943       {
3944         sprintf(title,"%d",FEEid[k]);
3945         tt1->DrawText(k*256+128,0.84*Yrange_upper,title);
3946       }
3947       tt1->SetTextSize(0.06);
3948       tt1->DrawText(800,0.92*Yrange_upper,"R1");
3949       tt1->DrawText(2450,0.92*Yrange_upper,"R2");
3950       tt1->DrawText(5200,0.92*Yrange_upper,"R3");
3951       tt1->SetTextSize(0.05); 
3952 
3953       t1->DrawLine(1536,0,1536,Yrange_upper);
3954       t1->DrawLine(3584,0,3584,Yrange_upper);
3955 
3956     }
3957   }
3958 
3959   TText PrintRun;
3960   PrintRun.SetTextFont(62);
3961   PrintRun.SetTextSize(0.04);
3962   PrintRun.SetNDC();          // set to normalized coordinates
3963   PrintRun.SetTextAlign(23);  // center/top alignment
3964   std::ostringstream runnostream;
3965   std::string runstring;
3966   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
3967   // fill run number and event time into string
3968   runnostream << ThisName << "_SS_Channels per LEVEL_1 TAGGER Run " << cl->RunNumber()
3969               << ", Time: " << ctime(&evttime.first);
3970   runstring = runnostream.str();
3971   TransparentTPad->cd();
3972   PrintRun.SetTextColor(evttime.second);
3973   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
3974 
3975   MyTC->Update();
3976   MyTC->Show();
3977   MyTC->SetEditable(false);
3978 
3979   return 0;
3980 }
3981 
3982 int TpcMonDraw::DrawTPCParity(const std::string & /* what */)
3983 {
3984 
3985   OnlMonClient *cl = OnlMonClient::instance();
3986   
3987   TH1 *tpcmon_parityerror[24] = {nullptr};
3988   TH1 *tpcmon_parities[24] = {nullptr};
3989 
3990   TH1 *tpcmon_parityerror_u[48] = {nullptr};
3991   TH1 *tpcmon_parities_u[48] = {nullptr};
3992   
3993   char TPCMON_STR[100];
3994   for( int i=0; i<48; i++ ) 
3995   {
3996     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
3997     sprintf(TPCMON_STR,"TPCMON_%i",i);
3998     tpcmon_parityerror_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Parity_Error");
3999     tpcmon_parities_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Check_Sums");
4000   }
4001 
4002   add_TH1(tpcmon_parityerror_u, tpcmon_parityerror);
4003   add_TH1(tpcmon_parities_u, tpcmon_parities);
4004   
4005   if (!gROOT->FindObject("TPCParityError"))
4006   {
4007     MakeCanvas("TPCParityError");
4008   }
4009   TCanvas *MyTC = TC[33];
4010   TPad *TransparentTPad = transparent[33];
4011 
4012   MyTC->SetEditable(true);
4013   MyTC->Clear("D");
4014   MyTC->cd(1);
4015 
4016   TLine *t1 = new TLine(); t1->SetLineWidth(2);
4017   TLine *t2 = new TLine(); t2->SetLineStyle(2);
4018   TText *tt1= new TText(); tt1->SetTextSize(0.05);
4019 
4020   int FEEid[26]={2,4,3,13,17,16, // R1
4021                  11,12,19,18,0,1,15,14, // R2
4022                  20,22,21,23,25,24,10,9,8,6,7,5 // R3
4023                 };
4024 
4025   char title[50];
4026 
4027   for( int i=0; i<24; i++ )
4028   {
4029     if( tpcmon_parityerror[i] && tpcmon_parities[i] )
4030     {
4031       MyTC->cd(i+5);
4032 
4033       tpcmon_parityerror[i]->Divide(tpcmon_parities[i]);
4034       tpcmon_parityerror[i]->GetYaxis()->SetRangeUser(0.0001,1.5);
4035       tpcmon_parityerror[i]->DrawCopy("HIST");
4036     
4037       MyTC->Update();
4038 
4039       for(int j=0;j<25;j++)
4040       {
4041         t2->DrawLine((j+1)*8,-0.01,(j+1)*8,1.5);
4042       }
4043       for(int k=0;k<26;k++)
4044       {
4045         sprintf(title,"%d",FEEid[k]);
4046         tt1->DrawText(k*8+4,1.2,title);
4047       }
4048       tt1->SetTextSize(0.06);
4049       tt1->DrawText(25,1.4,"R1");
4050       tt1->DrawText(77,1.4,"R2");
4051       tt1->DrawText(163,1.4,"R3");
4052       tt1->SetTextSize(0.05); 
4053 
4054       t1->DrawLine(48.5,-0.01,48.5,1.5);
4055       t1->DrawLine(112.5,-0.01,112.5,1.5);
4056 
4057     }
4058   }
4059 
4060   TText PrintRun;
4061   PrintRun.SetTextFont(62);
4062   PrintRun.SetTextSize(0.04);
4063   PrintRun.SetNDC();          // set to normalized coordinates
4064   PrintRun.SetTextAlign(23);  // center/top alignment
4065   std::ostringstream runnostream;
4066   std::string runstring;
4067   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
4068   // fill run number and event time into string
4069   runnostream << ThisName << "_ParityError Run " << cl->RunNumber()
4070               << ", Time: " << ctime(&evttime.first);
4071   runstring = runnostream.str();
4072   TransparentTPad->cd();
4073   PrintRun.SetTextColor(evttime.second);
4074   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
4075 
4076   MyTC->Update();
4077   //MyTC->SetLogy();
4078   MyTC->Show();
4079   MyTC->SetEditable(false);
4080 
4081 
4082   return 0;
4083 }
4084                 
4085 int TpcMonDraw::DrawShifterTPCDriftWindow(const std::string & /* what */)
4086 {
4087   OnlMonClient *cl = OnlMonClient::instance();
4088 
4089   TH1 *tpcmon_DriftWindow_shifter[24][3] = {nullptr};
4090   TH1 *tpcmon_DriftWindow_shifter_u[48][3] = {nullptr};
4091   
4092   char TPCMON_STR[100];
4093   for( int i=0; i<48; i++ ) 
4094   {
4095     for( int j=0; j<3; j++ )
4096     {
4097       //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
4098       sprintf(TPCMON_STR,"TPCMON_%i",i);
4099       tpcmon_DriftWindow_shifter_u[i][0] = (TH1*) cl->getHisto(TPCMON_STR,"COUNTS_vs_SAMPLE_1D_R1");
4100       tpcmon_DriftWindow_shifter_u[i][1] = (TH1*) cl->getHisto(TPCMON_STR,"COUNTS_vs_SAMPLE_1D_R2");
4101       tpcmon_DriftWindow_shifter_u[i][2] = (TH1*) cl->getHisto(TPCMON_STR,"COUNTS_vs_SAMPLE_1D_R3");
4102     }
4103   }
4104 
4105   add_TH1_modules( tpcmon_DriftWindow_shifter_u, tpcmon_DriftWindow_shifter);
4106 
4107   // also get # of events that made it into each OnlMon Server
4108   TH1 *tpcmoneventsebdc[24] = {nullptr}; 
4109 
4110   char TPCMON_STR2[100];
4111   for( int i=0; i<24; i++ ) 
4112   {
4113     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
4114     sprintf(TPCMON_STR2,"TPCMON_%i",i);
4115     tpcmoneventsebdc[i] = (TH1*) cl->getHisto(TPCMON_STR2,"NEvents_vs_EBDC");
4116   }
4117   
4118   if (!gROOT->FindObject("ShifterTPCDriftWindow"))
4119   {
4120     MakeCanvas("ShifterTPCDriftWindow");
4121   }
4122 
4123   TCanvas *MyTC = TC[34];
4124   TPad *TransparentTPad = transparent[34];
4125   MyTC->SetEditable(true);
4126   MyTC->Clear("D");
4127 
4128   gStyle->SetOptStat(0);
4129   gStyle->SetPalette(57); //kBird CVD friendly
4130 
4131   auto legend = new TLegend(0.7,0.65,0.98,0.95);
4132   bool draw_leg = 0;
4133 
4134   char bad_message[128];
4135 
4136   TLine *t2 = new TLine(); t2->SetLineStyle(2);
4137   TPaveText *messages[24];  
4138 
4139   for( int i=0; i<24; i++ )
4140   {
4141     MyTC->cd(i+5);
4142 
4143     int min = std::numeric_limits<int>::max(); // start wih the largest possible value
4144     int max = std::numeric_limits<int>::min(); // start with smalles possible value
4145     
4146     int R1_max = std::numeric_limits<int>::min(); // start with smalles possible value
4147     int R2_max = std::numeric_limits<int>::min(); // start with smalles possible value
4148     int R3_max = std::numeric_limits<int>::min(); // start with smalles possible value
4149 
4150     bool R1_bad = 0;
4151     bool R2_bad = 0;
4152     bool R3_bad = 0;
4153 
4154     for( int j = 2; j>-1; j-- )
4155     {
4156       if( tpcmon_DriftWindow_shifter[i][j] )
4157       {
4158         for( int k = 1; k < tpcmon_DriftWindow_shifter[i][j]->GetNbinsX(); k++ )
4159     {
4160           //if(j == 2 &&  (tpcmon_DriftWindow_shifter[i][j]->GetBinContent(k) > R3_max && tpcmon_DriftWindow_shifter[i][j]->GetBinContent(k) > 0) ){ R3_max = k; }
4161           //if(j == 1 &&  (tpcmon_DriftWindow_shifter[i][j]->GetBinContent(k) > R2_max && tpcmon_DriftWindow_shifter[i][j]->GetBinContent(k) > 0) ){ R2_max = k; }
4162           //if(j == 0 &&  (tpcmon_DriftWindow_shifter[i][j]->GetBinContent(k) > R1_max && tpcmon_DriftWindow_shifter[i][j]->GetBinContent(k) > 0) ){ R1_max = k; }
4163           //std::cout<<"In Progress: "<<"R1_max = "<<R1_max<<" R2_max = "<<R2_max<<" R3_max = "<<R3_max<<std::endl;
4164           if( tpcmon_DriftWindow_shifter[i][j]->GetBinContent(k) > max && tpcmon_DriftWindow_shifter[i][j]->GetBinContent(k) > 0 ){max = tpcmon_DriftWindow_shifter[i][j]->GetBinContent(k);}
4165           if( tpcmon_DriftWindow_shifter[i][j]->GetBinContent(k) < min && tpcmon_DriftWindow_shifter[i][j]->GetBinContent(k) > 0 ){min = tpcmon_DriftWindow_shifter[i][j]->GetBinContent(k);}
4166     }
4167       }
4168     }
4169 
4170 
4171     if( tpcmon_DriftWindow_shifter[i][0] ){  R1_max = tpcmon_DriftWindow_shifter[i][0]->GetBinCenter(tpcmon_DriftWindow_shifter[i][0]->GetMaximumBin());}
4172     if( tpcmon_DriftWindow_shifter[i][1] ){  R2_max = tpcmon_DriftWindow_shifter[i][1]->GetBinCenter(tpcmon_DriftWindow_shifter[i][1]->GetMaximumBin());}
4173     if( tpcmon_DriftWindow_shifter[i][2] ){  R3_max = tpcmon_DriftWindow_shifter[i][2]->GetBinCenter(tpcmon_DriftWindow_shifter[i][2]->GetMaximumBin());}
4174 
4175     if( (R1_max>std::numeric_limits<int>::min() && (R1_max < 365)) || R1_max > 374 ){ R1_bad = 1;} // old peak - 416, new peak 403 50 ns clock, new peak 368 57.14 ns clock 
4176     if( (R2_max>std::numeric_limits<int>::min() && (R2_max < 365)) || R2_max > 374 ){ R2_bad = 1;} 
4177     if( (R3_max>std::numeric_limits<int>::min() && (R3_max < 365)) || R3_max > 374 ){ R3_bad = 1;}
4178 
4179     for( int l = 2; l>-1; l-- )
4180     {
4181       if( tpcmon_DriftWindow_shifter[i][l] )
4182       {
4183         tpcmon_DriftWindow_shifter[i][l]->GetXaxis()->SetRangeUser(346,396); // old peak - 416, new peak 403, new peak 368 57.14 ns clock
4184         if(l == 2)
4185         { 
4186           tpcmon_DriftWindow_shifter[i][l]->GetYaxis()->SetRangeUser(0.9*min,1.3*max);tpcmon_DriftWindow_shifter[i][l] -> DrawCopy("HIST");
4187         } //used to be 
4188         else      
4189         { 
4190           tpcmon_DriftWindow_shifter[i][l]->GetYaxis()->SetRangeUser(0.9*min,1.3*max); tpcmon_DriftWindow_shifter[i][l] -> DrawCopy("HISTsame");
4191         } //assumes that R3 will always exist and is most entries
4192       }
4193     }
4194 
4195     t2->DrawLine(365,0.9*min,365,1.3*max);
4196     t2->DrawLine(375,0.9*min,375,1.3*max);
4197     
4198     gPad->Update();  
4199 
4200     if(draw_leg == 0 && tpcmon_DriftWindow_shifter[i][0] && tpcmon_DriftWindow_shifter[i][1] && tpcmon_DriftWindow_shifter[i][2]) //if you have not drawn the legend yet, draw it BUT ONLY ONCE
4201     {
4202       legend->AddEntry(tpcmon_DriftWindow_shifter[i][0], "R1");
4203       legend->AddEntry(tpcmon_DriftWindow_shifter[i][1], "R2");
4204       legend->AddEntry(tpcmon_DriftWindow_shifter[i][2], "R3");
4205       MyTC->cd(i+5);
4206       legend->Draw();
4207       draw_leg = 1; //draw legend only once
4208     }
4209 
4210     //std::cout<<"R1_max = "<<R1_max<<" R2_max = "<<R2_max<<" R3_max = "<<R3_max<<std::endl;
4211     //messages->Clear();
4212     messages[i] = new TPaveText(0.1,0.5,0.4,0.9,"brNDC");  
4213     
4214     /*
4215     if( (i == 21 || i == 22) || (i == 23) )
4216     {
4217       messages[i]->AddText("SECTOR NOT MONITORED"); ((TText*)messages[i]->GetListOfLines()->Last())->SetTextColor(kBlack);
4218       MyTC->cd(i+5);
4219       messages[i]->Draw("same");      
4220     }
4221     */
4222     if( tpcmoneventsebdc[i] )
4223     {
4224       if(tpcmoneventsebdc[i]->GetEntries() <  8000)
4225       {
4226         messages[i]->AddText("NOT ENOUGH STATS"); ((TText*)messages[i]->GetListOfLines()->Last())->SetTextColor(kBlue);
4227         messages[i]->AddText("CHECK AGAIN"); ((TText*)messages[i]->GetListOfLines()->Last())->SetTextColor(kBlue);
4228         MyTC->cd(i+5);
4229         messages[i]->Draw("same");
4230       }
4231     }
4232     else if(  (R1_bad==1 || R2_bad==1) || R3_bad==1 )
4233     {
4234       //std::cout<<"made it into the if statement for bad timing"<<std::endl;
4235       sprintf(bad_message,"Sector %i BAD",i);
4236       messages[i]->SetFillColor(kRed);
4237       messages[i]->AddText(bad_message); ((TText*)messages[i]->GetListOfLines()->Last())->SetTextColor(kBlack);
4238       messages[i]->AddText("REFRESH. IF PERSISTS, CALL EXPERT"); ((TText*)messages[i]->GetListOfLines()->Last())->SetTextColor(kBlack);
4239       MyTC->cd(i+5);
4240       messages[i]->Draw("same");
4241     }
4242     else if( tpcmon_DriftWindow_shifter[i][0] && (tpcmon_DriftWindow_shifter[i][1] && tpcmon_DriftWindow_shifter[i][2]) )
4243     {
4244       messages[i]->SetFillColor(kGreen);
4245       messages[i]->AddText("ALL GOOD"); ((TText*)messages[i]->GetListOfLines()->Last())->SetTextColor(kBlack);
4246       MyTC->cd(i+5);
4247       messages[i]->Draw("same");
4248     }
4249     else
4250     {
4251       messages[i]->AddText("MISSING DATA"); ((TText*)messages[i]->GetListOfLines()->Last())->SetTextColor(kBlack);
4252       MyTC->cd(i+5);
4253       messages[i]->Draw("same");
4254     }
4255     
4256 
4257   }// finish looping over 24 sectors
4258 
4259   TText PrintRun;
4260   PrintRun.SetTextFont(62);
4261   PrintRun.SetTextSize(0.04);
4262   PrintRun.SetNDC();          // set to normalized coordinates
4263   PrintRun.SetTextAlign(23);  // center/top alignment
4264   std::ostringstream runnostream;
4265   std::string runstring;
4266   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
4267   // fill run number and event time into string
4268   runnostream << ThisName << "_Shifter_Drift Window, ADC-Pedestal>(5sigma||20ADC) Run " << cl->RunNumber()
4269               << ", Time: " << ctime(&evttime.first);
4270   runstring = runnostream.str();
4271   TransparentTPad->cd();
4272   PrintRun.SetTextColor(evttime.second);
4273   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
4274 
4275   MyTC->Update();
4276   MyTC->Show();
4277   MyTC->SetEditable(false);
4278 
4279   return 0;
4280 }
4281 
4282 int TpcMonDraw::DrawTPCNoiseChannelPlots(const std::string & /* what */)
4283 {
4284   OnlMonClient *cl = OnlMonClient::instance();
4285 
4286   TH1 *tpcmon_noise_channel_plots[24] = {nullptr};
4287   TH1 *tpcmon_lvl1_per_EBDC[24] = {nullptr};
4288 
4289   TH1 *tpcmon_noise_channel_plots_u[48] = {nullptr};
4290   TH1 *tpcmon_lvl1_per_EBDC_u[48] = {nullptr};
4291   
4292   char TPCMON_STR[100];
4293   for( int i=0; i<48; i++ ) 
4294   {
4295     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
4296     sprintf(TPCMON_STR,"TPCMON_%i",i);
4297     tpcmon_noise_channel_plots_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"Noise_Channel_Plots");
4298     tpcmon_lvl1_per_EBDC_u[i] = (TH1*) cl->getHisto(TPCMON_STR,"LVL_1_TAGGER_per_EBDC");
4299   }
4300 
4301   add_TH1(tpcmon_noise_channel_plots_u, tpcmon_noise_channel_plots);
4302   add_TH1(tpcmon_lvl1_per_EBDC_u, tpcmon_lvl1_per_EBDC);
4303   
4304   if (!gROOT->FindObject("TPCNoiseChannelsPlots"))
4305   {
4306     MakeCanvas("TPCNoiseChannelsPlots");
4307   }
4308 
4309   TCanvas *MyTC = TC[35];
4310   TPad *TransparentTPad = transparent[35];
4311 
4312   TLine *t1 = new TLine(); t1->SetLineWidth(2);
4313   TLine *t2 = new TLine(); t2->SetLineStyle(2);
4314   TText *tt1= new TText(); tt1->SetTextSize(0.05);
4315 
4316   int FEEid[26]={2,4,3,13,17,16, // R1
4317                  11,12,19,18,0,1,15,14, // R2
4318                  20,22,21,23,25,24,10,9,8,6,7,5 // R3
4319                 };
4320 
4321   char title[50];
4322 
4323   MyTC->SetEditable(true);
4324   MyTC->Clear("D");
4325   for( int i=0; i<24; i++ ) 
4326   {
4327     if( tpcmon_noise_channel_plots[i] && tpcmon_lvl1_per_EBDC[i]  )
4328     {
4329       MyTC->cd(i+5);
4330       gStyle->SetPadLeftMargin(0.05);
4331       gStyle->SetPadRightMargin(0.02);
4332       tpcmon_noise_channel_plots[i]->Scale(1./tpcmon_lvl1_per_EBDC[i]->GetEntries());
4333       
4334       double Yrange_upper = 2.0*tpcmon_noise_channel_plots[i]->GetMaximum();
4335       tpcmon_noise_channel_plots[i]->GetYaxis()->SetRangeUser(0,Yrange_upper);
4336       tpcmon_noise_channel_plots[i]->DrawCopy("HIST");      
4337 
4338       MyTC->Update();
4339 
4340       for(int j=0;j<25;j++)
4341       {
4342         t2->DrawLine((j+1)*256,-0.01,(j+1)*256,Yrange_upper);
4343       }
4344       for(int k=0;k<26;k++)
4345       {
4346         sprintf(title,"%d",FEEid[k]);
4347         tt1->DrawText(k*256+128,0.84*Yrange_upper,title);
4348       }
4349       tt1->SetTextSize(0.06);
4350       tt1->DrawText(800,0.92*Yrange_upper,"R1");
4351       tt1->DrawText(2450,0.92*Yrange_upper,"R2");
4352       tt1->DrawText(5200,0.92*Yrange_upper,"R3");
4353       tt1->SetTextSize(0.05); 
4354 
4355       t1->DrawLine(1536,0,1536,Yrange_upper);
4356       t1->DrawLine(3584,0,3584,Yrange_upper);
4357 
4358     }
4359   }
4360 
4361   TText PrintRun;
4362   PrintRun.SetTextFont(62);
4363   PrintRun.SetTextSize(0.04);
4364   PrintRun.SetNDC();          // set to normalized coordinates
4365   PrintRun.SetTextAlign(23);  // center/top alignment
4366   std::ostringstream runnostream;
4367   std::string runstring;
4368   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
4369   // fill run number and event time into string
4370   runnostream << ThisName << "_Counts of ADC-Ped. > 300, t < 360 Run " << cl->RunNumber()
4371               << ", Time: " << ctime(&evttime.first);
4372   runstring = runnostream.str();
4373   TransparentTPad->cd();
4374   PrintRun.SetTextColor(evttime.second);
4375   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
4376 
4377   MyTC->Update();
4378   MyTC->Show();
4379   MyTC->SetEditable(false);
4380 
4381   return 0;
4382 }
4383 
4384 int TpcMonDraw::DrawShifterTransmissionDist(const std::string & /* what */)
4385 {
4386   OnlMonClient *cl = OnlMonClient::instance();
4387 
4388   //TH1F *tpcmon_back[24][3] = {nullptr};
4389   // TH1F *tpcmon_drift[24][3] = {nullptr};
4390 
4391   TH1 *tpcmon_Drift[24][3] = {nullptr};
4392   TH1 *tpcmon_Drift_u[48][3] = {nullptr};
4393   //TH1 *tpcmoneventsebdc[24] = {nullptr};
4394 
4395   TH1F *PERCENT = new TH1F("PERCENT","TPC PERCENT TRANSMISSION; % Transmission; Counts",75,-1.5,151.5);
4396 
4397   TF1 *exxy = new TF1("exxy","[0]*exp(x*[1])",0,500);
4398 
4399   char TPCMON_STR[100];
4400  
4401   for( int i=0; i<48; i++ ) 
4402   {
4403     sprintf(TPCMON_STR,"TPCMON_%i",i);
4404     //tpcmoneventsebdc[i] = (TH1*) cl->getHisto(TPCMON_STR,"NEvents_vs_EBDC");
4405     for( int j=0; j<3; j++ )
4406     {
4407 
4408       tpcmon_Drift_u[i][0] = (TH1F*) cl->getHisto(TPCMON_STR,"COUNTS_vs_SAMPLE_1D_R1");
4409       tpcmon_Drift_u[i][1] = (TH1F*) cl->getHisto(TPCMON_STR,"COUNTS_vs_SAMPLE_1D_R2");
4410       tpcmon_Drift_u[i][2] = (TH1F*) cl->getHisto(TPCMON_STR,"COUNTS_vs_SAMPLE_1D_R3");
4411 
4412       /*
4413       sprintf(DRIFT_CLONE_STR,"drift_sec_%i_R%i",i,j+1);
4414 
4415       tpcmon_DriftBackground[i][j] = (TH1F*)tpcmon_back[i][j]->Clone(BACK_CLONE_STR);
4416       tpcmon_DriftNorm[i][j] = (TH1F*)tpcmon_back[i][j]->Clone(DRIFT_CLONE_STR);
4417       */
4418     }
4419   }
4420 
4421   add_TH1_modules(tpcmon_Drift_u, tpcmon_Drift);
4422 
4423   if (!gROOT->FindObject("ShifterTPCTransmissionDist"))
4424   {
4425     MakeCanvas("ShifterTPCTransmissionDist");
4426   }
4427 
4428   TCanvas *MyTC = TC[36];
4429   TPad *TransparentTPad = transparent[36];
4430   MyTC->SetEditable(true);
4431   MyTC->Clear("D");
4432 
4433   //left = 34, right = 350 for new firmware with laser around 380 samples
4434   int left=35; int right=350;
4435 
4436   //gStyle->SetOptStat(0);
4437   //gStyle->SetPalette(57); //kBird CVD friendly
4438 
4439   char norm_str[100];
4440   char back_str[100];
4441 
4442   for(int sector=0; sector<24; sector++)
4443   {
4444     for(int rad=0; rad<3; rad++)
4445     {
4446       if( (!tpcmon_Drift[sector][rad] || tpcmon_Drift[sector][rad]->GetEntries()<20000) ){continue;} //if doesn't exist move on
4447       //first zero the drift signal out of the background spectra
4448       sprintf(norm_str,"norm_sec_%i_r%i",sector,rad+1);
4449       sprintf(back_str,"back_sec_%i_r%i",sector,rad+1);
4450       
4451       TH1F *current_norm = (TH1F*) tpcmon_Drift[sector][rad]->Clone(norm_str);
4452       current_norm->GetXaxis()->SetRangeUser(0,500);
4453       TH1F *back_norm = (TH1F*) tpcmon_Drift[sector][rad]->Clone(back_str);
4454       back_norm->GetXaxis()->SetRangeUser(0,500);
4455 
4456       for(int bin=left; bin<=right; bin++)
4457       {
4458         back_norm->SetBinContent(bin,0.0);
4459       }
4460       //  second zero the laser signal out of the background spectra.
4461       for (int bin=367; bin<=376; bin++)
4462       {
4463         back_norm->SetBinContent(bin,0.0);
4464       }
4465 
4466       //Now Fit a function to each background and divide...
4467       exxy->SetParameter(0,back_norm->GetBinContent(2));
4468       exxy->SetParameter(1,0);
4469       back_norm->Fit(exxy,"QW");
4470       current_norm->Divide( back_norm->GetFunction("exxy")  );
4471       //  Subtract the "1" offset and set the minimum to -0.2...
4472       for (int bin=1; bin<=current_norm->GetNbinsX(); bin++)
4473       {
4474     current_norm->SetBinContent(bin, std::max(-0.2,  current_norm->GetBinContent(bin)-1.0 ));
4475       }
4476 
4477       if ( current_norm->GetBinContent(75) > 0)
4478       {
4479     exxy->SetParameter(0,current_norm->GetBinContent(75));
4480     exxy->SetParameter(1,0);
4481     current_norm->Fit(exxy,"QW","",75,275);
4482     double one  =  current_norm->GetFunction("exxy")->GetParameter(1);
4483     double percent = 100.0*exp(one*(275-75));
4484     PERCENT->Fill(percent);
4485       }
4486       
4487     }
4488   } 
4489 
4490   MyTC->Clear("D");
4491 
4492   TText PrintRun;
4493   PrintRun.SetTextFont(62);
4494   PrintRun.SetTextSize(0.04);
4495   PrintRun.SetNDC();          // set to normalized coordinates
4496   PrintRun.SetTextAlign(23);  // center/top alignment
4497   std::ostringstream runnostream;
4498   std::string runstring;
4499   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
4500   // fill run number and event time into string
4501   runnostream << ThisName << " Run " << cl->RunNumber()
4502               << ", Time: " << ctime(&evttime.first);
4503   runstring = runnostream.str();
4504   TransparentTPad->cd();
4505   PrintRun.SetTextColor(evttime.second);
4506   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
4507 
4508   TLine *t1 = new TLine(); t1->SetLineWidth(4); t1->SetLineColor(kBlack);
4509   TLine *t2 = new TLine(); t2->SetLineWidth(2); t2->SetLineStyle(10); t2->SetLineColor(kRed);
4510 
4511   MyTC->cd(1);
4512   gPad->SetTopMargin(0.15);
4513   PERCENT->DrawCopy("hist");
4514   if(PERCENT->GetEntries()>36){PERCENT->Fit("gaus");t2->DrawLine( PERCENT->GetFunction("gaus")->GetParameter(1),0, PERCENT->GetFunction("gaus")->GetParameter(1),1.05*PERCENT->GetMaximum());}
4515   t1->DrawLine(70,0,70,1.05*PERCENT->GetMaximum());
4516 
4517   MyTC->Update();
4518   MyTC->Show();
4519   MyTC->SetEditable(false);
4520   
4521   return 0;
4522 }
4523 
4524 int TpcMonDraw::DrawDCvsSAMPA(const std::string & /* what */)
4525 {
4526   OnlMonClient *cl = OnlMonClient::instance();
4527 
4528   TH2 *tpcmon_dc_vs_sampa_plots[24] = {nullptr};
4529   
4530   TH2 *tpcmon_dc_vs_sampa_plots_u[48] = {nullptr};
4531   
4532   char TPCMON_STR[100];
4533   for( int i=0; i<48; i++ ) 
4534   {
4535     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
4536     sprintf(TPCMON_STR,"TPCMON_%i",i);
4537     tpcmon_dc_vs_sampa_plots_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"DC_vs_SAMPA");
4538   }
4539 
4540   add_TH2(tpcmon_dc_vs_sampa_plots_u, tpcmon_dc_vs_sampa_plots);
4541   
4542   if (!gROOT->FindObject("DC_vs_SAMPA_CANVAS"))
4543   {
4544     MakeCanvas("DC_vs_SAMPA_CANVAS");
4545   }
4546 
4547   TCanvas *MyTC = TC[37];
4548   TPad *TransparentTPad = transparent[37];
4549 
4550   // Add lines and text annotations
4551   TLine *t1 = new TLine(); t1->SetLineWidth(2);
4552   TLine *t2 = new TLine(); t2->SetLineStyle(2);
4553   TText *tt1 = new TText(); tt1->SetTextSize(0.05);
4554 
4555   int FEEid[26] = {
4556       2,4,3,13,17,16,        // R1
4557       11,12,19,18,0,1,15,14, // R2
4558       20,22,21,23,25,24,10,9,8,6,7,5 // R3
4559   };
4560   char title[32];
4561 
4562   MyTC->SetEditable(true);
4563   MyTC->Clear("D");
4564   for( int i=0; i<24; i++ ) 
4565   {
4566     if(  tpcmon_dc_vs_sampa_plots[i] )
4567     {
4568       MyTC->cd(i+5);
4569       gPad->SetLogz();
4570       gStyle->SetPadLeftMargin(0.05);
4571       gStyle->SetPadRightMargin(0.02);
4572 
4573       tpcmon_dc_vs_sampa_plots[i]->SetStats(kFALSE); 
4574       tpcmon_dc_vs_sampa_plots[i]->DrawCopy("COLZ");      
4575 
4576       MyTC->Update();
4577 
4578       for(int j=0;j<25;j++)
4579       {
4580         t2->DrawLine((j + 1) * 8, -9000.01, (j + 1) * 8, 50240);
4581       }
4582       for (int k = 0; k < 26; k++) {
4583         sprintf(title, "%d", FEEid[k]);
4584         if (FEEid[k] > 9)
4585             tt1->DrawText(k * 8, -4000, title);
4586         else
4587             tt1->DrawText(k * 8 + 2, -4000, title);
4588       }
4589       tt1->SetTextSize(0.06);
4590       tt1->DrawText(25, -8000, "R1");
4591       tt1->DrawText(77, -8000, "R2");
4592       tt1->DrawText(163, -8000, "R3");
4593       tt1->SetTextSize(0.05);
4594 
4595       t1->DrawLine(48, -9000.01, 48, 50240);
4596       t1->DrawLine(112, -9000.01, 112, 50240);
4597 
4598     }
4599   }
4600 
4601   TText PrintRun;
4602   PrintRun.SetTextFont(62);
4603   PrintRun.SetTextSize(0.04);
4604   PrintRun.SetNDC();          // set to normalized coordinates
4605   PrintRun.SetTextAlign(23);  // center/top alignment
4606   std::ostringstream runnostream;
4607   std::string runstring;
4608   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
4609   // fill run number and event time into string
4610   runnostream << ThisName << "_DC_vs_SAMPA Run " << cl->RunNumber()
4611               << ", Time: " << ctime(&evttime.first);
4612   runstring = runnostream.str();
4613   TransparentTPad->cd();
4614   PrintRun.SetTextColor(evttime.second);
4615   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
4616 
4617   MyTC->Update();
4618   MyTC->Show();
4619   MyTC->SetEditable(false);
4620 
4621   return 0;
4622 }
4623 
4624 int TpcMonDraw::DrawDCSAMPAvsTIME(const std::string & /* what */)
4625 {
4626   OnlMonClient *cl = OnlMonClient::instance();
4627 
4628   TH2 *tpcmon_dc_sampa_vs_time_plots[24] = {nullptr};
4629  
4630   TH2 *tpcmon_dc_sampa_vs_time_plots_u[48] = {nullptr};
4631   
4632   char TPCMON_STR[100];
4633   for( int i=0; i<48; i++ ) 
4634   {
4635     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
4636     sprintf(TPCMON_STR,"TPCMON_%i",i);
4637     tpcmon_dc_sampa_vs_time_plots_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"DC_SAMPA_vs_TIME");
4638   }
4639 
4640   add_TH2(tpcmon_dc_sampa_vs_time_plots_u, tpcmon_dc_sampa_vs_time_plots);
4641   
4642   if (!gROOT->FindObject("DC_SAMPA_vs_TIME_CANVAS"))
4643   {
4644     MakeCanvas("DC_SAMPA_vs_TIME_CANVAS");
4645   }
4646 
4647   TCanvas *MyTC = TC[38];
4648   TPad *TransparentTPad = transparent[38];
4649 
4650   // Draw vertical lines and labels
4651   TLine *t1 = new TLine(); t1->SetLineWidth(2);
4652   TLine *t2 = new TLine(); t2->SetLineStyle(2);
4653   TText *tt1 = new TText(); tt1->SetTextSize(0.05);
4654   TText *tt2 = new TText(); tt2->SetTextSize(0.025); //fee labels
4655 
4656   int FEEid[26] = {
4657       2,4,3,13,17,16,        // R1
4658       11,12,19,18,0,1,15,14, // R2
4659       20,22,21,23,25,24,10,9,8,6,7,5 // R3
4660   };
4661   char title[32];
4662 
4663   MyTC->SetEditable(true);
4664   MyTC->Clear("D");
4665   for( int i=0; i<24; i++ ) 
4666   {
4667     if(  tpcmon_dc_sampa_vs_time_plots[i] )
4668     {
4669       MyTC->cd(i+5);
4670       gPad->SetLogz();
4671       gStyle->SetPadLeftMargin(0.05);
4672       gStyle->SetPadRightMargin(0.02);
4673 
4674       tpcmon_dc_sampa_vs_time_plots[i]->SetStats(kFALSE); 
4675       tpcmon_dc_sampa_vs_time_plots[i]->DrawCopy("COLZ");      
4676 
4677       MyTC->Update();
4678 
4679       for (int j = 0; j < 25; j++) {
4680         t2->DrawLine( -659999, (j+1)*8, 1200000.5, (j+1)*8); //rollover
4681         //t2->DrawLine( -49499999, (j+1)*8, 150000000.5, (j+1)*8); //no rollover
4682       }
4683       // FEE ID labels
4684       for (int k = 0; k < 26; k++) {
4685         sprintf(title, "%d", FEEid[k]);
4686         if(FEEid[k] >9){tt2->DrawText(-250000,k*8+2, title);} //rollover
4687     else {tt2->DrawText(-250000,k*8 + 2,title);} //rollover
4688         //if(FEEid[k] >9){tt2->DrawText(-17040000,k*8+2, title);} //no rollover
4689     //else {tt2->DrawText(-17040000,k*8 + 2,title);} //no rollover
4690       }
4691       // Region labels
4692       tt1->SetTextSize(0.06);
4693       tt1->DrawText(-550000,25, "R1"); //rollover
4694       tt1->DrawText(-550000,77, "R2"); //rollover
4695       tt1->DrawText(-550000,163, "R3"); //rollover
4696       //tt1->DrawText(-41250000,25, "R1"); //no rollover
4697       //tt1->DrawText(-41250000,77, "R2"); //no rollover
4698       //tt1->DrawText(-41250000,163, "R3"); // no rollover
4699       tt1->SetTextSize(0.05);
4700 
4701      // Solid region boundary lines
4702       t1->DrawLine(-659999,48,1200000.5,48); //rollover
4703       t1->DrawLine(-659999,112,1200000.5,112); //rollover
4704       //t1->DrawLine( -49499999,48,150000000.5,48); // no rollover
4705       //t1->DrawLine( -49499999,112,150000000.5,112); // no rollover
4706 
4707     }
4708   }
4709 
4710   TText PrintRun;
4711   PrintRun.SetTextFont(62);
4712   PrintRun.SetTextSize(0.04);
4713   PrintRun.SetNDC();          // set to normalized coordinates
4714   PrintRun.SetTextAlign(23);  // center/top alignment
4715   std::ostringstream runnostream;
4716   std::string runstring;
4717   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
4718   // fill run number and event time into string
4719   runnostream << ThisName << "_DC_SAMPA_vs_TIME Run " << cl->RunNumber()
4720               << ", Time: " << ctime(&evttime.first);
4721   runstring = runnostream.str();
4722   TransparentTPad->cd();
4723   PrintRun.SetTextColor(evttime.second);
4724   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
4725 
4726   MyTC->Update();
4727   MyTC->Show();
4728   MyTC->SetEditable(false);
4729 
4730   return 0;
4731 }
4732 
4733 int TpcMonDraw::DrawTPCPACKETTYPEvsSAMPLEADC(const std::string & /* what */)
4734 {
4735   OnlMonClient *cl = OnlMonClient::instance();
4736 
4737   TH2 *tpcmon_PacketType_vs_Sample_ADC[24] = {nullptr};
4738   TH2 *tpcmon_PacketType_vs_Sample_ADC_u[48] = {nullptr};
4739   
4740   char TPCMON_STR[100];
4741   for( int i=0; i<48; i++ ) 
4742   {
4743     //const TString TPCMON_STR( Form( "TPCMON_%i", i ) );
4744     sprintf(TPCMON_STR,"TPCMON_%i",i);
4745     tpcmon_PacketType_vs_Sample_ADC_u[i] = (TH2*) cl->getHisto(TPCMON_STR,"Packet_Type_vs_sample_ADC");
4746   }
4747 
4748   add_TH2(tpcmon_PacketType_vs_Sample_ADC_u, tpcmon_PacketType_vs_Sample_ADC);
4749   
4750   if (!gROOT->FindObject("TPCPACKETTYPE_vs_SAMPLE_ADC"))
4751   {
4752     MakeCanvas("TPCPACKETTYPE_vs_SAMPLE_ADC");
4753   }
4754 
4755   TCanvas *MyTC = TC[39];
4756   TPad *TransparentTPad = transparent[39];
4757   MyTC->SetEditable(true);
4758   MyTC->Clear("D");
4759 
4760   gStyle->SetOptStat(0);
4761   gStyle->SetPalette(57); //kBird CVD friendly
4762 
4763 
4764   for( int i=0; i<24; i++ ) 
4765   {
4766     if(tpcmon_PacketType_vs_Sample_ADC[i] )
4767     {
4768       MyTC->cd(i+5);
4769       tpcmon_PacketType_vs_Sample_ADC[i]->SetStats(0);
4770       tpcmon_PacketType_vs_Sample_ADC[i]->DrawCopy("COLZ");
4771     }
4772     gPad->Update();
4773   }
4774 
4775   TText PrintRun;
4776   PrintRun.SetTextFont(62);
4777   PrintRun.SetTextSize(0.04);
4778   PrintRun.SetNDC();          // set to normalized coordinates
4779   PrintRun.SetTextAlign(23);  // center/top alignment
4780   std::ostringstream runnostream;
4781   std::string runstring;
4782   std::pair<time_t,int> evttime = cl->EventTime("CURRENT");
4783   // fill run number and event time into string
4784   runnostream << ThisName << "_PACKET TYPE vs SAMPLE wtd. by ADC Run " << cl->RunNumber()
4785               << ", Time: " << ctime(&evttime.first);
4786   runstring = runnostream.str();
4787   TransparentTPad->cd();
4788   PrintRun.SetTextColor(evttime.second);
4789   PrintRun.DrawText(0.5, 0.91, runstring.c_str());
4790 
4791   MyTC->Update();
4792   MyTC->Show();
4793   MyTC->SetEditable(false);
4794 
4795   return 0;
4796 }
4797 
4798 int TpcMonDraw::SavePlot(const std::string &what, const std::string &type)
4799 {
4800 
4801   OnlMonClient *cl = OnlMonClient::instance();
4802   int iret = Draw(what);
4803   if (iret)  // on error no png files please
4804   {
4805       return iret;
4806   }
4807   int icnt = 0;
4808   for (TCanvas *canvas : TC)
4809   {
4810     if (canvas == nullptr)
4811     {
4812       continue;
4813     }
4814     icnt++;
4815     std::string filename = ThisName + "_" + std::to_string(icnt) + "_" +
4816       std::to_string(cl->RunNumber()) + "." + type;
4817     cl->CanvasToPng(canvas, filename);
4818   }
4819   return 0;
4820 }
4821 
4822 int TpcMonDraw::MakeHtml(const std::string &what)
4823 {
4824   int iret = Draw(what);
4825   if (iret)  // on error no html output please
4826   {
4827     return iret;
4828   }
4829 
4830   OnlMonClient *cl = OnlMonClient::instance();
4831 
4832   int icnt = 0;
4833   for (TCanvas *canvas : TC)
4834   {
4835     if (canvas == nullptr)
4836     {
4837       continue;
4838     }
4839     icnt++;
4840     // Register the canvas png file to the menu and produces the png file.
4841     std::string pngfile = cl->htmlRegisterPage(*this, canvas->GetTitle(), std::to_string(icnt), "png");
4842     cl->CanvasToPng(canvas, pngfile);
4843   }
4844   // Now register also EXPERTS html pages, under the EXPERTS subfolder.
4845 
4846   // std::string logfile = cl->htmlRegisterPage(*this, "EXPERTS/Log", "log", "html");
4847   // std::ofstream out(logfile.c_str());
4848   // out << "<HTML><HEAD><TITLE>Log file for run " << cl->RunNumber()
4849   //     << "</TITLE></HEAD>" << std::endl;
4850   // out << "<P>Some log file output would go here." << std::endl;
4851   // out.close();
4852 
4853   // std::string status = cl->htmlRegisterPage(*this, "EXPERTS/Status", "status", "html");
4854   // std::ofstream out2(status.c_str());
4855   // out2 << "<HTML><HEAD><TITLE>Status file for run " << cl->RunNumber()
4856   //      << "</TITLE></HEAD>" << std::endl;
4857   // out2 << "<P>Some status output would go here." << std::endl;
4858   // out2.close();
4859   // cl->SaveLogFile(*this);
4860   return 0;
4861 }
4862 
4863 time_t TpcMonDraw::getTime()
4864 {
4865   OnlMonClient *cl = OnlMonClient::instance();
4866   time_t currtime = 0;
4867   int i = 0;
4868   while (currtime == 0 && i <= 23)
4869   {
4870     std::string servername = "TPCMON_" + std::to_string(i);
4871     currtime = cl->EventTime(servername,"CURRENT");
4872     i++;
4873   }
4874   return currtime;
4875 }
4876 
4877 int TpcMonDraw::DrawServerStats()
4878 {
4879   OnlMonClient *cl = OnlMonClient::instance();
4880   if (!gROOT->FindObject("TpcMonServerStats"))
4881   {
4882     MakeCanvas("TpcMonServerStats");
4883   }
4884   TCanvas *MyTC = TC[20];
4885   TPad *TransparentTPad = transparent[20];
4886 
4887   MyTC->Clear("D");
4888   MyTC->SetEditable(true);
4889   TransparentTPad->cd();
4890   TText PrintRun;
4891   PrintRun.SetTextFont(62);
4892   PrintRun.SetNDC();          // set to normalized coordinates
4893   PrintRun.SetTextAlign(23);  // center/top alignment
4894   PrintRun.SetTextSize(0.04);
4895   PrintRun.SetTextColor(1);
4896   PrintRun.DrawText(0.5, 0.99, "Server Statistics");
4897 
4898   PrintRun.SetTextAlign(13);  // center/top alignment
4899   PrintRun.SetTextSize(0.02);
4900   double vdist = 0.03;
4901   double vstart = 0.9;
4902   double vpos = vstart;
4903   double hpos = 0.01;
4904   int i = 0;
4905   int numservers = m_ServerSet.size();
4906   std::vector<std::string> ServerVector;
4907   for (const auto &server : m_ServerSet)
4908     {
4909       if (server.size() <= 8)
4910     {
4911       ServerVector.push_back(server);
4912     }
4913     }
4914   for (const auto &server : m_ServerSet)
4915     {
4916       if (server.size() > 8)
4917     {
4918       ServerVector.push_back(server);
4919     }
4920     }
4921   for (const auto &server : ServerVector)
4922   {
4923     std::ostringstream txt;
4924     auto servermapiter = cl->GetServerMap(server);
4925     if (servermapiter == cl->GetServerMapEnd())
4926     {
4927       txt << "Server " << server
4928           << " is dead ";
4929       PrintRun.SetTextColor(kRed);
4930     }
4931     else
4932     {
4933       txt << "Server " << server
4934           << ", run number " << std::get<1>(servermapiter->second)
4935           << ", event count: " << std::get<2>(servermapiter->second)
4936           << ", current time " << ctime(&(std::get<3>(servermapiter->second)));
4937       if (std::get<0>(servermapiter->second))
4938       {
4939         PrintRun.SetTextColor(kGray+2);
4940       }
4941       else
4942       {
4943         PrintRun.SetTextColor(kRed);
4944       }
4945     }
4946     if (i >= numservers/2)
4947       {
4948     hpos = 0.5;
4949     vpos = vstart;
4950     i = 0;
4951       }
4952     PrintRun.DrawText(hpos, vpos, txt.str().c_str());
4953     vpos -= vdist;
4954     i++;
4955   }
4956   MyTC->Update();
4957   MyTC->Show();
4958   MyTC->SetEditable(false);
4959 
4960   return 0;
4961 }
4962 
4963 void TpcMonDraw::add_TH1(TH1* hist[48], TH1* histadd[24]) {
4964     for (int i = 0; i < 24; ++i) {
4965       // Clone hist[i] to preserve binning, axis labels, etc.
4966       //char name_str[256];
4967       //sprintf(name_str,"%s",hist[i]->GetName());
4968       if(!hist[i] && !hist[i+24]){continue;}
4969       if(hist[i] && !hist[i+24]){histadd[i] = (TH1*)hist[i]->Clone(Form("histadd_%d",i));}
4970       if(!hist[i] && hist[i+24]){histadd[i] = (TH1*)hist[i+24]->Clone(Form("histadd_%d",i));}
4971       if(hist[i] && hist[i+24]){
4972     histadd[i] = (TH1*)hist[i]->Clone(Form("histadd_%d",i));
4973         histadd[i]->Add(hist[i+24]);
4974       }
4975     }
4976 }
4977 
4978 void TpcMonDraw::add_TH2(TH2* hist[48], TH2* histadd[24]) {
4979     for (int i = 0; i < 24; ++i) {
4980       // Clone hist[i] to preserve binning, axis labels, etc.
4981       //char name_str[256];
4982       //sprintf(name_str,"%s",hist[i]->GetName());
4983       if(!hist[i] && !hist[i+24]){continue;}
4984       if(hist[i] && !hist[i+24]){histadd[i] = (TH2*)hist[i]->Clone(Form("histadd_%d",i));}
4985       if(!hist[i] && hist[i+24]){histadd[i] = (TH2*)hist[i+24]->Clone(Form("histadd_%d",i));}
4986       if(hist[i] && hist[i+24]){
4987     histadd[i] = (TH2*)hist[i]->Clone(Form("histadd_%d",i));
4988         histadd[i]->Add(hist[i+24]);
4989       }
4990     }
4991 }
4992 
4993 void TpcMonDraw::add_TH1_modules(TH1* hist[48][3], TH1* histadd[24][3]) {
4994     for (int i = 0; i < 24; ++i) {
4995       for (int j = 0; j < 3; ++j) {
4996         // Clone hist[i] to preserve binning, axis labels, etc.
4997         //char name_str[256];
4998         //sprintf(name_str,"%s",hist[i]->GetName());
4999         if(!hist[i][j] && !hist[i+24][j]){continue;}
5000         if(hist[i][j] && !hist[i+24][j]){histadd[i][j] = (TH1*)hist[i][j]->Clone(Form("histadd_%d_%d",i,j));}
5001         if(!hist[i][j] && hist[i+24][j]){histadd[i][j] = (TH1*)hist[i+24][j]->Clone(Form("histadd_%d_%d",i,j));}
5002         if(hist[i][j] && hist[i+24][j]){
5003       histadd[i][j] = (TH1*)hist[i][j]->Clone(Form("histadd_%d_%d",i,j));
5004           histadd[i][j]->Add(hist[i+24][j]);
5005         }
5006       } 
5007     }
5008 }
5009 
5010 void TpcMonDraw::add_TH2_modules(TH2* hist[48][3], TH2* histadd[24][3]) {
5011     for (int i = 0; i < 24; ++i) {
5012       for (int j = 0; j < 3; ++j) {
5013         // Clone hist[i] to preserve binning, axis labels, etc.
5014         //char name_str[256];
5015         //sprintf(name_str,"%s",hist[i]->GetName());
5016         if(!hist[i][j] && !hist[i+24][j]){continue;}
5017         if(hist[i][j] && !hist[i+24][j]){histadd[i][j] = (TH2*)hist[i][j]->Clone(Form("histadd_%d_%d",i,j));}
5018         if(!hist[i][j] && hist[i+24][j]){histadd[i][j] = (TH2*)hist[i+24][j]->Clone(Form("histadd_%d_%d",i,j));}
5019         if(hist[i][j] && hist[i+24][j]){
5020       histadd[i][j] = (TH2*)hist[i][j]->Clone(Form("histadd_%d_%d",i,j));
5021           histadd[i][j]->Add(hist[i+24][j]);
5022         }
5023       } 
5024     }
5025 }