Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-08 02:26:06

0001 // How to run:
0002 //root -b -q -l RemoteMonitoringGLOBAL.C+
0003 //root -b -q -l 'RemoteMonitoringGLOBAL.C+("/afs/cern.ch/cms/CAF/CMSALCA/ALCA_HCALCALIB/HCALMONITORING/CMTweb/histos/Global_190707.root")'
0004 //
0005 //
0006 //
0007 #include "LogEleMapdb.h"
0008 
0009 #include <iostream>
0010 #include <fstream>
0011 
0012 #include "TH1.h"
0013 #include "TH2.h"
0014 #include "TCanvas.h"
0015 #include "TROOT.h"
0016 #include <TMath.h>
0017 #include "TStyle.h"
0018 #include "TSystem.h"
0019 #include "TLegend.h"
0020 #include "TText.h"
0021 #include "TAxis.h"
0022 #include "TFile.h"
0023 #include "TLine.h"
0024 #include "TGraph.h"
0025 #include <THStack.h>
0026 #include <TPaveText.h>
0027 
0028 // https://cms-conddb.cern.ch/eosweb/hcal/HcalRemoteMonitoring/CMT
0029 // https://cms-cpt-software.web.cern.ch/cms-cpt-software/General/Validation/SVSuite/HcalRemoteMonitoring/CMT
0030 
0031 using namespace std;
0032 //inline void HERE(const char *msg) { std::cout << msg << std::endl; }    kfitq
0033 int copyContents(TH1F **hDest, TString hname, TString htitle, const TH1F *hSrc, int lastBin);
0034 
0035 // -----------------------------------------------------
0036 
0037 int main(int argc, char *argv[]) {
0038   std::string dirnm = "Analyzer";
0039   gROOT->Reset();
0040   gROOT->SetStyle("Plain");
0041   gStyle->SetOptStat(0);
0042   gStyle->SetOptTitle(1);
0043 
0044   if (argc < 1)
0045     return 1;
0046   char fname[300];
0047   sprintf(fname, "%s", argv[1]);
0048   std::cout << fname << std::endl;
0049 
0050   //======================================================================
0051   // Connect the input files, parameters and get the 2-d histogram in memory
0052   //    TFile *hfile= new TFile("GlobalHist.root", "READ");
0053   string promt = (string)fname;
0054   string runnumber = "";
0055   for (unsigned int i = promt.size() - 11; i < promt.size() - 5; i++)
0056     runnumber += fname[i];
0057 
0058   TFile *hfile = new TFile(fname, "READ");
0059   hfile->ls();
0060   TDirectory *dir = (TDirectory *)hfile->FindObjectAny(dirnm.c_str());
0061   // Cut [test][sub][depth]
0062   //                              Empty                         HB                           HE                                                     HO                          HF
0063   double Cut0[7][5][8] = {
0064       {{0., 0., 0., 0., 0., 0., 0., 0.},
0065        {0., 1.0, 1.0, 0., 0., 0., 0., 0.},
0066        {0., 1., 1., 1., 0., 0., 0., 0.},
0067        {0., 0., 0., 0., 1., 0., 0., 0.},
0068        {0., 1., 1., 0., 0., 0., 0., 0.}},  //CapID  0,HB,HE,HO,HF
0069       //      {{0.,0.,0.,0.,0.,0.,0.,0.}, {0.,35.,35.,0.,0.,0.,0.,0.}, {0.,100.,140.,150.,0.,0.,0.,0.},                         {0.,0.,0.,0.,100.,0.,0.,0.}, {0.,170.,110.,170.,110.,0.,0.,0.} },  //Amplitude  0,HB,HE,HO,HF
0070       //
0071       //      {{0., 0., 0., 0., 0., 0., 0., 0.},
0072       //       {0., 10., 10., 10., 10., 0., 0., 0.},
0073       //       {0., 10., 10., 10., 10., 10., 10., 10.},
0074       //       {0., 0., 0., 0., 10., 0., 0., 0.},
0075       //       {0., 10., 10., 10., 10., 0., 0., 0.}},  //Amplitude  0,HB,HE,HO,HF
0076       {{0., 0., 0., 0., 0., 0., 0., 0.},
0077        {0., 3500., 3500., 3500., 3500., 0., 0., 0.},
0078        {0., 12000., 4500., 3500., 3500., 4000., 4500., 5500.},
0079        {0., 0., 0., 0., 200., 0., 0., 0.},
0080        {0., 4500., 4500., 4500., 4500., 0., 0., 0.}},  //Amplitude  0,HB,HE,HO,HF
0081       {{0., 0., 0., 0., 0., 0., 0., 0.},
0082        {0., 3., 3., 0., 0., 0., 0., 0.},
0083        {0., 3., 3., 3., 0., 0., 0., 0.},
0084        {0., 0., 0., 0., 3., 0., 0., 0.},
0085        {0., 2., 2., 0., 0., 0., 0., 0.}},  //Width  0,HB,HE,HO,HF
0086       {{0., 0., 0., 0., 0., 0., 0., 0.},
0087        {0., 0.4, 0.4, 0., 0., 0., 0., 0.},
0088        {0., 0.4, 0.4, 0.4, 0., 0., 0., 0.},
0089        {0., 0., 0., 0., 0.4, 0., 0., 0.},
0090        {0., 0.8, 0.8, 0., 0., 0., 0., 0.}},  //Ratio  0,HB,HE,HO,HF
0091       {{0., 0., 0., 0., 0., 0., 0., 0.},
0092        {0., 4.7, 4.7, 0., 0., 0., 0., 0.},
0093        {0., 4.8, 4.8, 5.0, 0., 0., 0., 0.},
0094        {0., 0., 0., 0., 4.8, 0., 0., 0.},
0095        {0., 4.0, 4.0, 0., 0., 0., 0., 0.}},  //TSn  0,HB,HE,HO,HF
0096       {{0., 0., 0., 0., 0., 0., 0., 0.},
0097        {0., 3.5, 3.5, 0., 0., 0., 0., 0.},
0098        {0., 4.0, 4.0, 4.0, 0., 0., 0., 0.},
0099        {0., 0., 0., 0., 3., 0., 0., 0.},
0100        {0., 3.5, 3.5, 0., 0., 0., 0., 0.}},  //TSx  0,HB,HE,HO,HF
0101       {{0., 0., 0., 0., 0., 0., 0., 0.},
0102        {0., 0., 0., 0., 0., 0., 0., 0.},
0103        {0., 0., 0., 0., 0., 0., 0., 0.},
0104        {0., 0., 0., 0., 0., 0., 0., 0.},
0105        {0., 0., 0., 0., 0., 0., 0., 0.}}};  //Empty
0106 
0107   double CutAb[5][8] = {{0., 0., 0., 0., 0., 0., 0., 0.},
0108                         {0., 20., 7., 0., 0., 0., 0., 0.},
0109                         {0., 16., 13., 4., 0., 0., 0., 0.},
0110                         {0., 0., 0., 0., 45., 0., 0., 0.},
0111                         {0., 10., 5., 0., 0., 0., 0., 0.}};  // cut 1 for CapIdErrors 0,HB,HE,HO,HF
0112 
0113   double CutPo[5][8] = {{0., 0., 0., 0., 0., 0., 0., 0.},
0114                         {0., 9., 3., 0., 0., 0., 0., 0.},
0115                         {0., 8., 6., 2., 0., 0., 0., 0.},
0116                         {0., 0., 0., 0., 20., 0., 0., 0.},
0117                         {0., 5., 3., 0., 0., 0., 0., 0.}};  //cut 3 for CapIdErrors (portions) 0,HB,HE,HO,HF
0118 
0119   //======================================================================
0120 
0121   // CUTs FOR IPHI RBX:
0122   int cutA_HB = 100;
0123   int cutA_HE = 6000;
0124   int cutA_HO = 150;
0125   int cutA_HF = 500;
0126   // CUTs FOR IETA RBX:
0127   int cutB_HB = 100;
0128   int cutB_HE = 10000;
0129   int cutB_HO = 150;
0130   int cutB_HF = 500;
0131 
0132   //======================================================================
0133   // Prepare histograms and plot them to .png files
0134   //  TCanvas *cHB = new TCanvas("cHB", "cHB", 200, 10, 700, 900);
0135   TCanvas *cHB = new TCanvas("cHB", "cHB", 1000, 500);
0136   TCanvas *cHE = new TCanvas("cHE", "cHE", 1500, 500);
0137   TCanvas *cONE = new TCanvas("cONE", "cONE", 500, 500);
0138   TCanvas *cFour = new TCanvas("cFour", "cFour", 1500, 1000);
0139   TCanvas *cFour1 = new TCanvas("cFour1", "cFour1", 1200, 800);
0140   TCanvas *cNine = new TCanvas("cNine", "cNine", 1500, 1500);
0141 
0142   // RBX:
0143   //  TCanvas *c4x6 = new TCanvas("c4x6","c4x6",1500,3000);
0144   TCanvas *c4x6 = new TCanvas("c4x6", "c4x6", 1200, 2400);
0145   //TCanvas *c5x6 = new TCanvas("c5x6","c5x6",2000,3000);
0146   TCanvas *c5x6 = new TCanvas("c5x6", "c5x6", 1500, 2400);
0147   //  TCanvas *cRBX1 = new TCanvas("cRBX1","cRBX1",200,10,1300,1110);
0148   TCanvas *cRBX1 = new TCanvas("cRBX1", "cRBX1", 1200, 1000);
0149   //
0150   //         TCanvas *cRBX31 = new TCanvas("cRBX31","cRBX31",1800,600);
0151   TCanvas *cRBX31 = new TCanvas("cRBX31", "cRBX31", 1860, 600);
0152   //         TCanvas *cRBX31 = new TCanvas("cRBX31","cRBX31",200,10,,1800,600);
0153 
0154   //  char *str = (char*)alloca(10000);
0155 
0156   int k_min[5] = {0, 1, 1, 4, 1};  // minimum depth for each subdet HB HE HO HF
0157 
0158   int k_max[5] = {0, 2, 3, 4, 2};  // maximum depth for each subdet HB HE HO HF
0159   //  int k_maxupgrade[5]={0,2,3,4,4}; // maximum depth for each subdet HB HE HO HF
0160   int k_maxupgrade[5] = {0, 4, 7, 4, 4};  // maximum depth for each subdet HB HE HO HF
0161 
0162   //+++++++++++++++++++++++++++++
0163   // Lumi iLumi and number of events
0164   //+++++++++++++++++++++++++++++
0165   // with TfileService implementation, change everywhere below:     hfile->Get     to     dir->FindObjectAny
0166   cHB->Divide(2, 1);
0167   cHB->cd(1);
0168   TH1F *LumLum = (TH1F *)dir->FindObjectAny("h_lsnumber_per_eachLS");
0169   int MaxLumDanila = LumLum->GetBinContent(LumLum->GetMaximumBin());  // old variant of Danila
0170   cout << " MaxLumDanila=     " << MaxLumDanila << endl;
0171   gStyle->SetOptStat(110000);
0172   gPad->SetGridy();
0173   gPad->SetGridx();
0174   LumLum->SetMarkerStyle(21);
0175   LumLum->SetMarkerSize(0.8);
0176   LumLum->GetYaxis()->SetLabelSize(0.04);
0177   LumLum->SetTitle("Cont. number per LS  \b");
0178   LumLum->SetXTitle("Cont.number \b");
0179   LumLum->SetYTitle("Ls \b");
0180   LumLum->SetMarkerColor(4);
0181   LumLum->SetLineColor(0);
0182   LumLum->SetMinimum(0.8);
0183   LumLum->GetXaxis()->SetRangeUser(0, MaxLumDanila + 5.);
0184   LumLum->Draw("Error");
0185 
0186   cHB->cd(2);
0187   TH1F *LumiEv = (TH1F *)dir->FindObjectAny("h_nevents_per_eachRealLS");
0188   int MaxLum0 = LumiEv->GetBinContent(LumiEv->GetMaximumBin());
0189   int MaxLum = 0;
0190   for (int i = 1; i <= LumiEv->GetXaxis()->GetNbins(); i++) {
0191     if (LumiEv->GetBinContent(i)) {
0192       MaxLum = i;
0193     }
0194   }
0195   cout << " Nev in bin of MaxLum =     " << MaxLum0 << " MaxLum=     " << MaxLum << endl;
0196 
0197   gStyle->SetOptStat(110000);
0198   gPad->SetGridy();
0199   gPad->SetGridx();
0200   gPad->SetLogy();
0201   //            gPad->SetLogx();
0202   LumiEv->GetYaxis()->SetLabelSize(0.04);
0203   LumiEv->SetTitle("Number of events per LS");
0204   LumiEv->SetXTitle("LS");
0205   LumiEv->SetYTitle("Number of events ");
0206   LumiEv->SetMarkerStyle(21);
0207   LumiEv->SetMarkerSize(0.8);
0208   LumiEv->SetMarkerColor(4);
0209   LumiEv->SetLineColor(0);
0210   //      LumiEv->SetMinimum(0.8);
0211   LumiEv->GetXaxis()->SetRangeUser(0, MaxLum + 5.);
0212   LumiEv->Draw("Error");
0213 
0214   cHB->Print("LumiEvent.png");
0215   cHB->Clear();
0216 
0217   //=======================================================================================================
0218   // Shape criteria: 1d histogram first definition
0219   //=======================================================================================================
0220   TH1F *H_NumBadChanDepth[7][5][5];  // 1d histogramm for test,subdet, depth
0221 
0222   //+++++++++++++++++++++++++++++
0223   // ADC Amplitude
0224   //+++++++++++++++++++++++++++++
0225 
0226   H_NumBadChanDepth[1][1][1] = (TH1F *)dir->FindObjectAny("h_sumADCAmplLS1");
0227   H_NumBadChanDepth[1][1][2] = (TH1F *)dir->FindObjectAny("h_sumADCAmplLS2");
0228 
0229   H_NumBadChanDepth[1][2][1] = (TH1F *)dir->FindObjectAny("h_sumADCAmplLS3");
0230   H_NumBadChanDepth[1][2][2] = (TH1F *)dir->FindObjectAny("h_sumADCAmplLS4");
0231   H_NumBadChanDepth[1][2][3] = (TH1F *)dir->FindObjectAny("h_sumADCAmplLS5");
0232 
0233   H_NumBadChanDepth[1][3][4] = (TH1F *)dir->FindObjectAny("h_sumADCAmplLS8");
0234 
0235   H_NumBadChanDepth[1][4][1] = (TH1F *)dir->FindObjectAny("h_sumADCAmplLS6");
0236   H_NumBadChanDepth[1][4][2] = (TH1F *)dir->FindObjectAny("h_sumADCAmplLS7");
0237 
0238   //+++++++++++++++++++++++++++++
0239   // Width
0240   //+++++++++++++++++++++++++++++
0241 
0242   H_NumBadChanDepth[2][1][1] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeLS1");
0243   H_NumBadChanDepth[2][1][2] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeLS2");
0244 
0245   H_NumBadChanDepth[2][2][1] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeLS3");
0246   H_NumBadChanDepth[2][2][2] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeLS4");
0247   H_NumBadChanDepth[2][2][3] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeLS5");
0248 
0249   H_NumBadChanDepth[2][3][4] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeLS8");
0250 
0251   H_NumBadChanDepth[2][4][1] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeLS6");
0252   H_NumBadChanDepth[2][4][2] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeLS7");
0253 
0254   //+++++++++++++++++++++++++++++
0255   // Ratio
0256   //+++++++++++++++++++++++++++++
0257 
0258   H_NumBadChanDepth[3][1][1] = (TH1F *)dir->FindObjectAny("h_sumAmplLS1");
0259   H_NumBadChanDepth[3][1][2] = (TH1F *)dir->FindObjectAny("h_sumAmplLS2");
0260 
0261   H_NumBadChanDepth[3][2][1] = (TH1F *)dir->FindObjectAny("h_sumAmplLS3");
0262   H_NumBadChanDepth[3][2][2] = (TH1F *)dir->FindObjectAny("h_sumAmplLS4");
0263   H_NumBadChanDepth[3][2][3] = (TH1F *)dir->FindObjectAny("h_sumAmplLS5");
0264 
0265   H_NumBadChanDepth[3][3][4] = (TH1F *)dir->FindObjectAny("h_sumAmplLS8");
0266 
0267   H_NumBadChanDepth[3][4][1] = (TH1F *)dir->FindObjectAny("h_sumAmplLS6");
0268   H_NumBadChanDepth[3][4][2] = (TH1F *)dir->FindObjectAny("h_sumAmplLS7");
0269 
0270   //+++++++++++++++++++++++++++++
0271   // Tmean
0272   //+++++++++++++++++++++++++++++
0273 
0274   H_NumBadChanDepth[4][1][1] = (TH1F *)dir->FindObjectAny("h_sumTSmeanALS1");
0275   H_NumBadChanDepth[4][1][2] = (TH1F *)dir->FindObjectAny("h_sumTSmeanALS2");
0276 
0277   H_NumBadChanDepth[4][2][1] = (TH1F *)dir->FindObjectAny("h_sumTSmeanALS3");
0278   H_NumBadChanDepth[4][2][2] = (TH1F *)dir->FindObjectAny("h_sumTSmeanALS4");
0279   H_NumBadChanDepth[4][2][3] = (TH1F *)dir->FindObjectAny("h_sumTSmeanALS5");
0280 
0281   H_NumBadChanDepth[4][3][4] = (TH1F *)dir->FindObjectAny("h_sumTSmeanALS8");
0282 
0283   H_NumBadChanDepth[4][4][1] = (TH1F *)dir->FindObjectAny("h_sumTSmeanALS6");
0284   H_NumBadChanDepth[4][4][2] = (TH1F *)dir->FindObjectAny("h_sumTSmeanALS7");
0285 
0286   //+++++++++++++++++++++++++++++
0287   // Tmax
0288   //+++++++++++++++++++++++++++++
0289 
0290   H_NumBadChanDepth[5][1][1] = (TH1F *)dir->FindObjectAny("h_sumTSmaxALS1");
0291   H_NumBadChanDepth[5][1][2] = (TH1F *)dir->FindObjectAny("h_sumTSmaxALS2");
0292 
0293   H_NumBadChanDepth[5][2][1] = (TH1F *)dir->FindObjectAny("h_sumTSmaxALS3");
0294   H_NumBadChanDepth[5][2][2] = (TH1F *)dir->FindObjectAny("h_sumTSmaxALS4");
0295   H_NumBadChanDepth[5][2][3] = (TH1F *)dir->FindObjectAny("h_sumTSmaxALS5");
0296 
0297   H_NumBadChanDepth[5][3][4] = (TH1F *)dir->FindObjectAny("h_sumTSmaxALS8");
0298 
0299   H_NumBadChanDepth[5][4][1] = (TH1F *)dir->FindObjectAny("h_sumTSmaxALS6");
0300   H_NumBadChanDepth[5][4][2] = (TH1F *)dir->FindObjectAny("h_sumTSmaxALS7");
0301 
0302   gStyle->SetOptStat(110000);
0303 
0304   for (int test = 1; test <= 5; test++) {  //Test: 0,
0305     for (int sub = 1; sub <= 4; sub++) {   //Subdetector: 1-HB, 2-HE, 3-HF, 4-HO
0306       if (sub == 1)
0307         cHB->Divide(2, 1);
0308       if (sub == 2)
0309         cHE->Divide(3, 1);
0310       if (sub == 3)
0311         cONE->Divide(1, 1);
0312       if (sub == 4)
0313         cHB->Divide(2, 1);
0314       for (int k = k_min[sub]; k <= k_max[sub]; k++) {  //Depth
0315         if (sub == 1)
0316           cHB->cd(k);
0317         if (sub == 2)
0318           cHE->cd(k);
0319         if (sub == 3)
0320           cONE->cd(k - 3);
0321         if (sub == 4)
0322           cHB->cd(k);
0323         gPad->SetGridy();
0324         gPad->SetGridx();
0325         gPad->SetLogy();
0326         H_NumBadChanDepth[test][sub][k]->SetMarkerStyle(20);
0327         H_NumBadChanDepth[test][sub][k]->SetMarkerSize(0.8);
0328         if (k == 1)
0329           H_NumBadChanDepth[test][sub][k]->SetTitle("Depth 1\b");
0330         if (k == 2)
0331           H_NumBadChanDepth[test][sub][k]->SetTitle("Depth 2\b");
0332         if (k == 3)
0333           H_NumBadChanDepth[test][sub][k]->SetTitle("Depth 3\b");
0334         if (k == 4)
0335           H_NumBadChanDepth[test][sub][k]->SetTitle("Depth 4\b");
0336         if (test == 1)
0337           H_NumBadChanDepth[test][sub][k]->SetXTitle(" <Amplitude> \b");
0338         if (test == 2)
0339           H_NumBadChanDepth[test][sub][k]->SetXTitle(" <Width> \b");
0340         if (test == 3)
0341           H_NumBadChanDepth[test][sub][k]->SetXTitle(" <Ratio> \b");
0342         if (test == 4)
0343           H_NumBadChanDepth[test][sub][k]->SetXTitle(" <TS mean> \b");
0344         if (test == 5)
0345           H_NumBadChanDepth[test][sub][k]->SetXTitle(" <TS max> \b");
0346         H_NumBadChanDepth[test][sub][k]->SetYTitle("Number of channel-LSs\b");
0347         H_NumBadChanDepth[test][sub][k]->SetMarkerColor(4);
0348         H_NumBadChanDepth[test][sub][k]->SetLineColor(0);
0349         //                H_NumBadChanDepth[test][sub][k]->GetXaxis()->SetRangeUser(0, MaxLum);
0350         H_NumBadChanDepth[test][sub][k]->SetMinimum(0.8);
0351         H_NumBadChanDepth[test][sub][k]->Draw("Error");
0352       }
0353       if (test == 0) {
0354         if (sub == 1) {
0355           cHB->Print("H_NBCMNHB.png");
0356           cHB->Clear();
0357         }
0358         if (sub == 2) {
0359           cHE->Print("H_NBCMNHE.png");
0360           cHE->Clear();
0361         }
0362         if (sub == 3) {
0363           cONE->Print("H_NBCMNHO.png");
0364           cONE->Clear();
0365         }
0366         if (sub == 4) {
0367           cHB->Print("H_NBCMNHF.png");
0368           cHB->Clear();
0369         }
0370       }
0371 
0372       if (test == 1) {
0373         if (sub == 1) {
0374           cHB->Print("H_ADCamplHB.png");
0375           cHB->Clear();
0376         }
0377         if (sub == 2) {
0378           cHE->Print("H_ADCamplHE.png");
0379           cHE->Clear();
0380         }
0381         if (sub == 3) {
0382           cONE->Print("H_ADCamplHO.png");
0383           cONE->Clear();
0384         }
0385         if (sub == 4) {
0386           cHB->Print("H_ADCamplHF.png");
0387           cHB->Clear();
0388         }
0389       }
0390       if (test == 2) {
0391         if (sub == 1) {
0392           cHB->Print("H_WidthHB.png");
0393           cHB->Clear();
0394         }
0395         if (sub == 2) {
0396           cHE->Print("H_WidthHE.png");
0397           cHE->Clear();
0398         }
0399         if (sub == 3) {
0400           cONE->Print("H_WidthHO.png");
0401           cONE->Clear();
0402         }
0403         if (sub == 4) {
0404           cHB->Print("H_WidthHF.png");
0405           cHB->Clear();
0406         }
0407       }
0408       if (test == 3) {
0409         if (sub == 1) {
0410           cHB->Print("H_RatioHB.png");
0411           cHB->Clear();
0412         }
0413         if (sub == 2) {
0414           cHE->Print("H_RatioHE.png");
0415           cHE->Clear();
0416         }
0417         if (sub == 3) {
0418           cONE->Print("H_RatioHO.png");
0419           cONE->Clear();
0420         }
0421         if (sub == 4) {
0422           cHB->Print("H_RatioHF.png");
0423           cHB->Clear();
0424         }
0425       }
0426       if (test == 4) {
0427         if (sub == 1) {
0428           cHB->Print("H_TmeanHB.png");
0429           cHB->Clear();
0430         }
0431         if (sub == 2) {
0432           cHE->Print("H_TmeanHE.png");
0433           cHE->Clear();
0434         }
0435         if (sub == 3) {
0436           cONE->Print("H_TmeanHO.png");
0437           cONE->Clear();
0438         }
0439         if (sub == 4) {
0440           cHB->Print("H_TmeanHF.png");
0441           cHB->Clear();
0442         }
0443       }
0444       if (test == 5) {
0445         if (sub == 1) {
0446           cHB->Print("H_TmaxHB.png");
0447           cHB->Clear();
0448         }
0449         if (sub == 2) {
0450           cHE->Print("H_TmaxHE.png");
0451           cHE->Clear();
0452         }
0453         if (sub == 3) {
0454           cONE->Print("H_TmaxHO.png");
0455           cONE->Clear();
0456         }
0457         if (sub == 4) {
0458           cHB->Print("H_TmaxHF.png");
0459           cHB->Clear();
0460         }
0461       }
0462     }  // end sub
0463   }    //end test
0464 
0465   gStyle->SetOptStat(0);
0466   //================================================================================================================================
0467 
0468   //=======================================================================================================
0469   // 2-d histograms second definition
0470   //=========================================================
0471   TH2F *MapNumBadChanDepth[7][5][5];  // 1d Mapogramm for test,subdet, depth
0472   TH2F *MapNumChanDepth[7][5][5];     // 1d Mapogramm for test,subdet, depth
0473   TH2F *MapNumBadChanFull[7];         // 1d Mapogramm for test
0474   TH2F *MapNumChanFull[7];            // 1d Mapogramm for test
0475 
0476   //+++++++++++++++++++++++++++++
0477   // CapID
0478   //+++++++++++++++++++++++++++++
0479 
0480   MapNumBadChanDepth[0][1][1] = (TH2F *)dir->FindObjectAny("h_mapDepth1Error_HB");
0481   MapNumBadChanDepth[0][1][2] = (TH2F *)dir->FindObjectAny("h_mapDepth2Error_HB");
0482 
0483   MapNumBadChanDepth[0][2][1] = (TH2F *)dir->FindObjectAny("h_mapDepth1Error_HE");
0484   MapNumBadChanDepth[0][2][2] = (TH2F *)dir->FindObjectAny("h_mapDepth2Error_HE");
0485   MapNumBadChanDepth[0][2][3] = (TH2F *)dir->FindObjectAny("h_mapDepth3Error_HE");
0486 
0487   MapNumBadChanDepth[0][3][4] = (TH2F *)dir->FindObjectAny("h_mapDepth4Error_HO");
0488 
0489   MapNumBadChanDepth[0][4][1] = (TH2F *)dir->FindObjectAny("h_mapDepth1Error_HF");
0490   MapNumBadChanDepth[0][4][2] = (TH2F *)dir->FindObjectAny("h_mapDepth2Error_HF");
0491 
0492   MapNumBadChanFull[0] = (TH2F *)MapNumBadChanDepth[0][1][1]->Clone();
0493 
0494   MapNumChanDepth[0][1][1] = (TH2F *)dir->FindObjectAny("h_mapDepth1_HB");
0495   MapNumChanDepth[0][1][2] = (TH2F *)dir->FindObjectAny("h_mapDepth2_HB");
0496 
0497   MapNumChanDepth[0][2][1] = (TH2F *)dir->FindObjectAny("h_mapDepth1_HE");
0498   MapNumChanDepth[0][2][2] = (TH2F *)dir->FindObjectAny("h_mapDepth2_HE");
0499   MapNumChanDepth[0][2][3] = (TH2F *)dir->FindObjectAny("h_mapDepth3_HE");
0500 
0501   MapNumChanDepth[0][3][4] = (TH2F *)dir->FindObjectAny("h_mapDepth4_HO");
0502 
0503   MapNumChanDepth[0][4][1] = (TH2F *)dir->FindObjectAny("h_mapDepth1_HF");
0504   MapNumChanDepth[0][4][2] = (TH2F *)dir->FindObjectAny("h_mapDepth2_HF");
0505 
0506   MapNumChanFull[0] = (TH2F *)MapNumChanDepth[0][1][1]->Clone();
0507 
0508   //+++++++++++++++++++++++++++++
0509   // ADC Amplitude
0510   //+++++++++++++++++++++++++++++
0511 
0512   MapNumBadChanDepth[1][1][1] = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplLS1");
0513   MapNumBadChanDepth[1][1][2] = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplLS2");
0514 
0515   MapNumBadChanDepth[1][2][1] = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplLS3");
0516   MapNumBadChanDepth[1][2][2] = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplLS4");
0517   MapNumBadChanDepth[1][2][3] = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplLS5");
0518 
0519   MapNumBadChanDepth[1][3][4] = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplLS8");
0520 
0521   MapNumBadChanDepth[1][4][1] = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplLS6");
0522   MapNumBadChanDepth[1][4][2] = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplLS7");
0523 
0524   MapNumBadChanFull[1] = (TH2F *)MapNumBadChanDepth[1][1][1]->Clone();
0525 
0526   MapNumChanDepth[1][1][1] = (TH2F *)dir->FindObjectAny("h_2D0sumADCAmplLS1");
0527   MapNumChanDepth[1][1][2] = (TH2F *)dir->FindObjectAny("h_2D0sumADCAmplLS2");
0528 
0529   MapNumChanDepth[1][2][1] = (TH2F *)dir->FindObjectAny("h_2D0sumADCAmplLS3");
0530   MapNumChanDepth[1][2][2] = (TH2F *)dir->FindObjectAny("h_2D0sumADCAmplLS4");
0531   MapNumChanDepth[1][2][3] = (TH2F *)dir->FindObjectAny("h_2D0sumADCAmplLS5");
0532 
0533   MapNumChanDepth[1][3][4] = (TH2F *)dir->FindObjectAny("h_2D0sumADCAmplLS8");
0534 
0535   MapNumChanDepth[1][4][1] = (TH2F *)dir->FindObjectAny("h_2D0sumADCAmplLS6");
0536   MapNumChanDepth[1][4][2] = (TH2F *)dir->FindObjectAny("h_2D0sumADCAmplLS7");
0537 
0538   MapNumChanFull[1] = (TH2F *)MapNumChanDepth[1][1][1]->Clone();
0539 
0540   //+++++++++++++++++++++++++++++
0541   // Width
0542   //+++++++++++++++++++++++++++++
0543 
0544   MapNumBadChanDepth[2][1][1] = (TH2F *)dir->FindObjectAny("h_2DsumAmplitudeLS1");
0545   MapNumBadChanDepth[2][1][2] = (TH2F *)dir->FindObjectAny("h_2DsumAmplitudeLS2");
0546 
0547   MapNumBadChanDepth[2][2][1] = (TH2F *)dir->FindObjectAny("h_2DsumAmplitudeLS3");
0548   MapNumBadChanDepth[2][2][2] = (TH2F *)dir->FindObjectAny("h_2DsumAmplitudeLS4");
0549   MapNumBadChanDepth[2][2][3] = (TH2F *)dir->FindObjectAny("h_2DsumAmplitudeLS5");
0550 
0551   MapNumBadChanDepth[2][3][4] = (TH2F *)dir->FindObjectAny("h_2DsumAmplitudeLS8");
0552 
0553   MapNumBadChanDepth[2][4][1] = (TH2F *)dir->FindObjectAny("h_2DsumAmplitudeLS6");
0554   MapNumBadChanDepth[2][4][2] = (TH2F *)dir->FindObjectAny("h_2DsumAmplitudeLS7");
0555 
0556   MapNumBadChanFull[2] = (TH2F *)MapNumBadChanDepth[2][1][1]->Clone();
0557 
0558   MapNumChanDepth[2][1][1] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplitudeLS1");
0559   MapNumChanDepth[2][1][2] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplitudeLS2");
0560 
0561   MapNumChanDepth[2][2][1] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplitudeLS3");
0562   MapNumChanDepth[2][2][2] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplitudeLS4");
0563   MapNumChanDepth[2][2][3] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplitudeLS5");
0564 
0565   MapNumChanDepth[2][3][4] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplitudeLS8");
0566 
0567   MapNumChanDepth[2][4][1] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplitudeLS6");
0568   MapNumChanDepth[2][4][2] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplitudeLS7");
0569 
0570   MapNumChanFull[2] = (TH2F *)MapNumChanDepth[2][1][1]->Clone();
0571 
0572   //+++++++++++++++++++++++++++++
0573   // Ratio
0574   //+++++++++++++++++++++++++++++
0575 
0576   MapNumBadChanDepth[3][1][1] = (TH2F *)dir->FindObjectAny("h_2DsumAmplLS1");
0577   MapNumBadChanDepth[3][1][2] = (TH2F *)dir->FindObjectAny("h_2DsumAmplLS2");
0578 
0579   MapNumBadChanDepth[3][2][1] = (TH2F *)dir->FindObjectAny("h_2DsumAmplLS3");
0580   MapNumBadChanDepth[3][2][2] = (TH2F *)dir->FindObjectAny("h_2DsumAmplLS4");
0581   MapNumBadChanDepth[3][2][3] = (TH2F *)dir->FindObjectAny("h_2DsumAmplLS5");
0582 
0583   MapNumBadChanDepth[3][3][4] = (TH2F *)dir->FindObjectAny("h_2DsumAmplLS8");
0584 
0585   MapNumBadChanDepth[3][4][1] = (TH2F *)dir->FindObjectAny("h_2DsumAmplLS6");
0586   MapNumBadChanDepth[3][4][2] = (TH2F *)dir->FindObjectAny("h_2DsumAmplLS7");
0587 
0588   MapNumBadChanFull[3] = (TH2F *)MapNumBadChanDepth[3][1][1]->Clone();
0589 
0590   MapNumChanDepth[3][1][1] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplLS1");
0591   MapNumChanDepth[3][1][2] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplLS2");
0592 
0593   MapNumChanDepth[3][2][1] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplLS3");
0594   MapNumChanDepth[3][2][2] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplLS4");
0595   MapNumChanDepth[3][2][3] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplLS5");
0596 
0597   MapNumChanDepth[3][3][4] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplLS8");
0598 
0599   MapNumChanDepth[3][4][1] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplLS6");
0600   MapNumChanDepth[3][4][2] = (TH2F *)dir->FindObjectAny("h_2D0sumAmplLS7");
0601 
0602   MapNumChanFull[3] = (TH2F *)MapNumChanDepth[3][1][1]->Clone();
0603 
0604   //+++++++++++++++++++++++++++++
0605   // Tmean
0606   //+++++++++++++++++++++++++++++
0607 
0608   MapNumBadChanDepth[4][1][1] = (TH2F *)dir->FindObjectAny("h_2DsumTSmeanALS1");
0609   MapNumBadChanDepth[4][1][2] = (TH2F *)dir->FindObjectAny("h_2DsumTSmeanALS2");
0610 
0611   MapNumBadChanDepth[4][2][1] = (TH2F *)dir->FindObjectAny("h_2DsumTSmeanALS3");
0612   MapNumBadChanDepth[4][2][2] = (TH2F *)dir->FindObjectAny("h_2DsumTSmeanALS4");
0613   MapNumBadChanDepth[4][2][3] = (TH2F *)dir->FindObjectAny("h_2DsumTSmeanALS5");
0614 
0615   MapNumBadChanDepth[4][3][4] = (TH2F *)dir->FindObjectAny("h_2DsumTSmeanALS8");
0616 
0617   MapNumBadChanDepth[4][4][1] = (TH2F *)dir->FindObjectAny("h_2DsumTSmeanALS6");
0618   MapNumBadChanDepth[4][4][2] = (TH2F *)dir->FindObjectAny("h_2DsumTSmeanALS7");
0619 
0620   MapNumBadChanFull[4] = (TH2F *)MapNumBadChanDepth[4][1][1]->Clone();
0621 
0622   MapNumChanDepth[4][1][1] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmeanALS1");
0623   MapNumChanDepth[4][1][2] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmeanALS2");
0624 
0625   MapNumChanDepth[4][2][1] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmeanALS3");
0626   MapNumChanDepth[4][2][2] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmeanALS4");
0627   MapNumChanDepth[4][2][3] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmeanALS5");
0628 
0629   MapNumChanDepth[4][3][4] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmeanALS8");
0630 
0631   MapNumChanDepth[4][4][1] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmeanALS6");
0632   MapNumChanDepth[4][4][2] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmeanALS7");
0633 
0634   MapNumChanFull[4] = (TH2F *)MapNumChanDepth[4][1][1]->Clone();
0635 
0636   //+++++++++++++++++++++++++++++
0637   // Tmax
0638   //+++++++++++++++++++++++++++++
0639 
0640   MapNumBadChanDepth[5][1][1] = (TH2F *)dir->FindObjectAny("h_2DsumTSmaxALS1");
0641   MapNumBadChanDepth[5][1][2] = (TH2F *)dir->FindObjectAny("h_2DsumTSmaxALS2");
0642 
0643   MapNumBadChanDepth[5][2][1] = (TH2F *)dir->FindObjectAny("h_2DsumTSmaxALS3");
0644   MapNumBadChanDepth[5][2][2] = (TH2F *)dir->FindObjectAny("h_2DsumTSmaxALS4");
0645   MapNumBadChanDepth[5][2][3] = (TH2F *)dir->FindObjectAny("h_2DsumTSmaxALS5");
0646 
0647   MapNumBadChanDepth[5][3][4] = (TH2F *)dir->FindObjectAny("h_2DsumTSmaxALS8");
0648 
0649   MapNumBadChanDepth[5][4][1] = (TH2F *)dir->FindObjectAny("h_2DsumTSmaxALS6");
0650   MapNumBadChanDepth[5][4][2] = (TH2F *)dir->FindObjectAny("h_2DsumTSmaxALS7");
0651 
0652   MapNumBadChanFull[5] = (TH2F *)MapNumBadChanDepth[5][1][1]->Clone();
0653 
0654   MapNumChanDepth[5][1][1] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmaxALS1");
0655   MapNumChanDepth[5][1][2] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmaxALS2");
0656 
0657   MapNumChanDepth[5][2][1] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmaxALS3");
0658   MapNumChanDepth[5][2][2] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmaxALS4");
0659   MapNumChanDepth[5][2][3] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmaxALS5");
0660 
0661   MapNumChanDepth[5][3][4] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmaxALS8");
0662 
0663   MapNumChanDepth[5][4][1] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmaxALS6");
0664   MapNumChanDepth[5][4][2] = (TH2F *)dir->FindObjectAny("h_2D0sumTSmaxALS7");
0665 
0666   MapNumChanFull[5] = (TH2F *)MapNumChanDepth[5][1][1]->Clone();
0667 
0668   for (int test = 0; test <= 5; test++) {  //Test: 0,
0669     for (int sub = 1; sub <= 4; sub++) {   //Subdetector: 1-HB, 2-HE, 3-HF, 4-HO
0670       if (sub == 1)
0671         cHB->Divide(2, 1);
0672       if (sub == 2)
0673         cHE->Divide(3, 1);
0674       if (sub == 3)
0675         cONE->Divide(1, 1);
0676       if (sub == 4)
0677         cHB->Divide(2, 1);
0678       for (int k = k_min[sub]; k <= k_max[sub]; k++) {  //Depth
0679         if (sub == 1)
0680           cHB->cd(k);
0681         if (sub == 2)
0682           cHE->cd(k);
0683         if (sub == 3)
0684           cONE->cd(k - 3);
0685         if (sub == 4)
0686           cHB->cd(k);
0687         MapNumBadChanDepth[test][sub][k]->Divide(
0688             MapNumBadChanDepth[test][sub][k], MapNumChanDepth[test][sub][k], 1, 1, "B");
0689 
0690         for (int x = 1; x <= MapNumBadChanFull[test]->GetXaxis()->GetNbins(); x++) {
0691           for (int y = 1; y <= MapNumBadChanFull[test]->GetYaxis()->GetNbins(); y++) {
0692             double ccc1 = MapNumBadChanDepth[test][sub][k]->GetBinContent(x, y);
0693             MapNumBadChanFull[test]->SetBinContent(x, y, MapNumBadChanFull[test]->GetBinContent(x, y) + ccc1);
0694           }  //end y
0695         }    //end x
0696 
0697         if (k == 1)
0698           MapNumBadChanDepth[test][sub][k]->SetTitle("Depth 1\b");
0699         if (k == 2)
0700           MapNumBadChanDepth[test][sub][k]->SetTitle("Depth 2\b");
0701         if (k == 3)
0702           MapNumBadChanDepth[test][sub][k]->SetTitle("Depth 3\b");
0703         if (k == 4)
0704           MapNumBadChanDepth[test][sub][k]->SetTitle("Depth 4\b");
0705         gPad->SetGridy();
0706         gPad->SetGridx();
0707         gPad->SetLogz();
0708         //
0709         //  gPad->DrawFrame(0.0, 0.0001, 1.0, 1000);
0710         //  gPad->DrawFrame(0.2, 0.0002, 0.8, 10000);
0711         MapNumBadChanDepth[test][sub][k]->SetXTitle("#eta \b");
0712         MapNumBadChanDepth[test][sub][k]->SetYTitle("#phi \b");
0713         MapNumBadChanDepth[test][sub][k]->SetZTitle("Average estimator \b");
0714         ////    //  MapNumBadChanDepth[test]->GetZaxis()->SetLabelSize(0.008); // can not be used which is of non-class type TH2F
0715         //  MapNumBadChanDepth[test][sub][k]->SetTitleOffset(0.75, "Z");
0716         MapNumBadChanDepth[test][sub][k]->Draw("COLZ");
0717         //        MapNumBadChanDepth[test][sub][k]->Draw("same");
0718         MapNumBadChanDepth[test][sub][k]->GetYaxis()->SetRangeUser(0, 72.);
0719         MapNumBadChanDepth[test][sub][k]->GetZaxis()->SetRangeUser(0.0001, 1.);
0720       }
0721       if (test == 0) {
0722         if (sub == 1) {
0723           cHB->Print("MapCapIdErrorHB.png");
0724           cHB->Clear();
0725         }
0726         if (sub == 2) {
0727           cHE->Print("MapCapIdErrorHE.png");
0728           cHE->Clear();
0729         }
0730         if (sub == 3) {
0731           cONE->Print("MapCapIdErrorHO.png");
0732           cONE->Clear();
0733         }
0734         if (sub == 4) {
0735           cHB->Print("MapCapIdErrorHF.png");
0736           cHB->Clear();
0737         }
0738       }
0739       if (test == 1) {
0740         if (sub == 1) {
0741           cHB->Print("MapADCamplHB.png");
0742           cHB->Clear();
0743         }
0744         if (sub == 2) {
0745           cHE->Print("MapADCamplHE.png");
0746           cHE->Clear();
0747         }
0748         if (sub == 3) {
0749           cONE->Print("MapADCamplHO.png");
0750           cONE->Clear();
0751         }
0752         if (sub == 4) {
0753           cHB->Print("MapADCamplHF.png");
0754           cHB->Clear();
0755         }
0756       }
0757       if (test == 2) {
0758         if (sub == 1) {
0759           cHB->Print("MapWidthHB.png");
0760           cHB->Clear();
0761         }
0762         if (sub == 2) {
0763           cHE->Print("MapWidthHE.png");
0764           cHE->Clear();
0765         }
0766         if (sub == 3) {
0767           cONE->Print("MapWidthHO.png");
0768           cONE->Clear();
0769         }
0770         if (sub == 4) {
0771           cHB->Print("MapWidthHF.png");
0772           cHB->Clear();
0773         }
0774       }
0775       if (test == 3) {
0776         if (sub == 1) {
0777           cHB->Print("MapRatioHB.png");
0778           cHB->Clear();
0779         }
0780         if (sub == 2) {
0781           cHE->Print("MapRatioHE.png");
0782           cHE->Clear();
0783         }
0784         if (sub == 3) {
0785           cONE->Print("MapRatioHO.png");
0786           cONE->Clear();
0787         }
0788         if (sub == 4) {
0789           cHB->Print("MapRatioHF.png");
0790           cHB->Clear();
0791         }
0792       }
0793       if (test == 4) {
0794         if (sub == 1) {
0795           cHB->Print("MapTmeanHB.png");
0796           cHB->Clear();
0797         }
0798         if (sub == 2) {
0799           cHE->Print("MapTmeanHE.png");
0800           cHE->Clear();
0801         }
0802         if (sub == 3) {
0803           cONE->Print("MapTmeanHO.png");
0804           cONE->Clear();
0805         }
0806         if (sub == 4) {
0807           cHB->Print("MapTmeanHF.png");
0808           cHB->Clear();
0809         }
0810       }
0811       if (test == 5) {
0812         if (sub == 1) {
0813           cHB->Print("MapTmaxHB.png");
0814           cHB->Clear();
0815         }
0816         if (sub == 2) {
0817           cHE->Print("MapTmaxHE.png");
0818           cHE->Clear();
0819         }
0820         if (sub == 3) {
0821           cONE->Print("MapTmaxHO.png");
0822           cONE->Clear();
0823         }
0824         if (sub == 4) {
0825           cHB->Print("MapTmaxHF.png");
0826           cHB->Clear();
0827         }
0828       }
0829     }  // end sub
0830     cONE->Divide(1, 1);
0831     cONE->cd(1);
0832     gPad->SetGridy();
0833     gPad->SetGridx();
0834     gPad->SetLogz();
0835     MapNumBadChanFull[test]->SetTitle("All subdetectors\b");
0836     MapNumBadChanFull[test]->SetXTitle("#eta \b");
0837     MapNumBadChanFull[test]->SetYTitle("#phi \b");
0838     if (test == 0)
0839       MapNumBadChanFull[test]->SetZTitle("Average Nbcs \b");
0840     if (test != 0)
0841       MapNumBadChanFull[test]->SetZTitle("Average estimator \b");
0842     //   MapNumBadChanFull[test]->GetZaxis()->SetLabelSize(0.008);
0843     MapNumBadChanFull[test]->SetTitleOffset(0.75, "Z");
0844     MapNumBadChanFull[test]->Draw("COLZ");
0845     MapNumBadChanFull[test]->GetYaxis()->SetRangeUser(0, 72.);
0846     //         MapNumBadChanFull[test]->GetZaxis()->SetRangeUser(0.0001, 1.);
0847     if (test == 0) {
0848       cONE->Print("MapCapIdError.png");
0849       cONE->Clear();
0850     }
0851     if (test == 1) {
0852       cONE->Print("MapADCAmpl.png");
0853       cONE->Clear();
0854     }
0855     if (test == 2) {
0856       cONE->Print("MapWidth.png");
0857       cONE->Clear();
0858     }
0859     if (test == 3) {
0860       cONE->Print("MapRatio.png");
0861       cONE->Clear();
0862     }
0863     if (test == 4) {
0864       cONE->Print("MapTmean.png");
0865       cONE->Clear();
0866     }
0867     if (test == 5) {
0868       cONE->Print("MapTmax.png");
0869       cONE->Clear();
0870     }
0871   }  //end test
0872 
0873   //================================================================================================================================
0874 
0875   //=======================================================================================================
0876   // 1-d histograms third definition
0877 
0878   TH1F *HistNumBadChanDepth[7][5][8];     // 1d histogramm for test,subdet, depth
0879   TH1F *HistCutNumBadChanDepth[7][5][8];  // 1d histogramm for test,subdet, depth
0880   TH1F *HistNumChanDepth[7][5][8];        // 1d histogramm for test,subdet, depth
0881 
0882   //      TH1F *HistNumBadChanDepth[7][5][5];    // 1d histogramm for test,subdet, depth
0883   //      TH1F *HistCutNumBadChanDepth[7][5][5];    // 1d histogramm for test,subdet, depth
0884   //      TH1F *HistNumChanDepth[7][5][5];    // 1d histogramm for test,subdet, depth
0885 
0886   TH1F *HistNumBadChanFull[7];  // 1d histogramm for test
0887   TH1F *HistNumChanFull[7];     // 1d histogramm for test
0888 
0889   //+++++++++++++++++++++++++++++
0890   // Rate of Cap ID errors
0891   //+++++++++++++++++++++++++++++
0892 
0893   HistNumBadChanDepth[0][1][1] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth1_HB");
0894   HistNumBadChanDepth[0][1][2] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth2_HB");
0895 
0896   HistNumBadChanDepth[0][2][1] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth1_HE");
0897   HistNumBadChanDepth[0][2][2] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth2_HE");
0898   HistNumBadChanDepth[0][2][3] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth3_HE");
0899 
0900   HistNumBadChanDepth[0][3][4] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth4_HO");
0901 
0902   HistNumBadChanDepth[0][4][1] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth1_HF");
0903   HistNumBadChanDepth[0][4][2] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth2_HF");
0904 
0905   HistNumBadChanFull[0] = (TH1F *)HistNumBadChanDepth[0][1][1]->Clone();
0906 
0907   HistCutNumBadChanDepth[0][1][1] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth1_HB");
0908   HistCutNumBadChanDepth[0][1][2] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth2_HB");
0909 
0910   HistCutNumBadChanDepth[0][2][1] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth1_HE");
0911   HistCutNumBadChanDepth[0][2][2] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth2_HE");
0912   HistCutNumBadChanDepth[0][2][3] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth3_HE");
0913 
0914   HistCutNumBadChanDepth[0][3][4] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth4_HO");
0915 
0916   HistCutNumBadChanDepth[0][4][1] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth1_HF");
0917   HistCutNumBadChanDepth[0][4][2] = (TH1F *)dir->FindObjectAny("h_runnbadchannels_depth2_HF");
0918 
0919   HistNumChanDepth[0][1][1] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth1_HB");
0920   HistNumChanDepth[0][1][2] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth2_HB");
0921 
0922   HistNumChanDepth[0][2][1] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth1_HE");
0923   HistNumChanDepth[0][2][2] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth2_HE");
0924   HistNumChanDepth[0][2][3] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth3_HE");
0925 
0926   HistNumChanDepth[0][3][4] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth4_HO");
0927 
0928   HistNumChanDepth[0][4][1] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth1_HF");
0929   HistNumChanDepth[0][4][2] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth2_HF");
0930 
0931   HistNumChanFull[0] = (TH1F *)HistNumChanDepth[0][1][1]->Clone();
0932 
0933   //+++++++++++++++++++++++++++++
0934   // ADC Amplitude
0935   //+++++++++++++++++++++++++++++
0936 
0937   //////////////////////
0938   // HB:
0939   HistNumBadChanDepth[1][1][1] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLS1");
0940   HistNumBadChanDepth[1][1][2] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLS2");
0941   // HB upgrade:
0942   HistNumBadChanDepth[1][1][3] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLSdepth3HBu");
0943   HistNumBadChanDepth[1][1][4] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLSdepth4HBu");
0944 
0945   // HE:
0946   HistNumBadChanDepth[1][2][1] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLS3");
0947   HistNumBadChanDepth[1][2][2] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLS4");
0948   HistNumBadChanDepth[1][2][3] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLS5");
0949   // HE upgrade:
0950   HistNumBadChanDepth[1][2][4] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLSdepth4HEu");
0951   HistNumBadChanDepth[1][2][5] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLSdepth5HEu");
0952   HistNumBadChanDepth[1][2][6] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLSdepth6HEu");
0953   HistNumBadChanDepth[1][2][7] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLSdepth7HEu");
0954 
0955   // HO:
0956   HistNumBadChanDepth[1][3][4] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLS8");
0957 
0958   // HF:
0959   HistNumBadChanDepth[1][4][1] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLS6");
0960   HistNumBadChanDepth[1][4][2] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLS7");
0961   // HF upgrade:
0962   HistNumBadChanDepth[1][4][3] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLS6u");
0963   HistNumBadChanDepth[1][4][4] = (TH1F *)dir->FindObjectAny("h_sumADCAmplperLS7u");
0964 
0965   // other cases:
0966   HistNumBadChanFull[1] = (TH1F *)HistNumBadChanDepth[1][1][1]->Clone();
0967 
0968   //////////////////////
0969   // HB:
0970   HistCutNumBadChanDepth[1][1][1] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLS1");
0971   HistCutNumBadChanDepth[1][1][2] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLS2");
0972   // HB upgrade:
0973   HistCutNumBadChanDepth[1][1][3] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLSdepth3HBu");
0974   HistCutNumBadChanDepth[1][1][4] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLSdepth4HBu");
0975 
0976   // HE:
0977   HistCutNumBadChanDepth[1][2][1] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLS3");
0978   HistCutNumBadChanDepth[1][2][2] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLS4");
0979   HistCutNumBadChanDepth[1][2][3] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLS5");
0980   // HE upgrade:
0981   HistCutNumBadChanDepth[1][2][4] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLSdepth4HEu");
0982   HistCutNumBadChanDepth[1][2][5] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLSdepth5HEu");
0983   HistCutNumBadChanDepth[1][2][6] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLSdepth6HEu");
0984   HistCutNumBadChanDepth[1][2][7] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLSdepth7HEu");
0985 
0986   // HO:
0987   HistCutNumBadChanDepth[1][3][4] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLS8");
0988 
0989   // HF:
0990   HistCutNumBadChanDepth[1][4][1] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLS6");
0991   HistCutNumBadChanDepth[1][4][2] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLS7");
0992   // HF upgrade:
0993   HistCutNumBadChanDepth[1][4][3] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLS6u");
0994   HistCutNumBadChanDepth[1][4][4] = (TH1F *)dir->FindObjectAny("h_sumCutADCAmplperLS7u");
0995 
0996   //////////////////////
0997   // HB:
0998   HistNumChanDepth[1][1][1] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLS1");
0999   HistNumChanDepth[1][1][2] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLS2");
1000   // HB upgrade:
1001   HistNumChanDepth[1][1][3] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLSdepth3HBu");
1002   HistNumChanDepth[1][1][4] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLSdepth4HBu");
1003 
1004   // HE:
1005   HistNumChanDepth[1][2][1] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLS3");
1006   HistNumChanDepth[1][2][2] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLS4");
1007   HistNumChanDepth[1][2][3] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLS5");
1008   // HE upgrade:
1009   HistNumChanDepth[1][2][4] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLSdepth4HEu");
1010   HistNumChanDepth[1][2][5] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLSdepth5HEu");
1011   HistNumChanDepth[1][2][6] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLSdepth6HEu");
1012   HistNumChanDepth[1][2][7] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLSdepth7HEu");
1013 
1014   // HO:
1015   HistNumChanDepth[1][3][4] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLS8");
1016 
1017   // HF:
1018   HistNumChanDepth[1][4][1] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLS6");
1019   HistNumChanDepth[1][4][2] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLS7");
1020   // HF upgrade:
1021   HistNumChanDepth[1][4][3] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLS6u");
1022   HistNumChanDepth[1][4][4] = (TH1F *)dir->FindObjectAny("h_sum0ADCAmplperLS7u");
1023 
1024   // other cases:
1025   HistNumChanFull[1] = (TH1F *)HistNumChanDepth[1][1][1]->Clone();
1026   // just initialization of [6] massive for alternative <A> calculation
1027   HistNumChanFull[6] = (TH1F *)HistNumChanDepth[1][1][1]->Clone();
1028 
1029   //+++++++++++++++++++++++++++++
1030   // Width
1031   //+++++++++++++++++++++++++++++
1032 
1033   HistNumBadChanDepth[2][1][1] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeperLS1");
1034   HistNumBadChanDepth[2][1][2] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeperLS2");
1035 
1036   HistNumBadChanDepth[2][2][1] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeperLS3");
1037   HistNumBadChanDepth[2][2][2] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeperLS4");
1038   HistNumBadChanDepth[2][2][3] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeperLS5");
1039 
1040   HistNumBadChanDepth[2][3][4] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeperLS8");
1041 
1042   HistNumBadChanDepth[2][4][1] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeperLS6");
1043   HistNumBadChanDepth[2][4][2] = (TH1F *)dir->FindObjectAny("h_sumAmplitudeperLS7");
1044 
1045   HistNumBadChanFull[2] = (TH1F *)HistNumBadChanDepth[2][1][1]->Clone();
1046 
1047   HistCutNumBadChanDepth[2][1][1] = (TH1F *)dir->FindObjectAny("h_sumCutAmplitudeperLS1");
1048   HistCutNumBadChanDepth[2][1][2] = (TH1F *)dir->FindObjectAny("h_sumCutAmplitudeperLS2");
1049 
1050   HistCutNumBadChanDepth[2][2][1] = (TH1F *)dir->FindObjectAny("h_sumCutAmplitudeperLS3");
1051   HistCutNumBadChanDepth[2][2][2] = (TH1F *)dir->FindObjectAny("h_sumCutAmplitudeperLS4");
1052   HistCutNumBadChanDepth[2][2][3] = (TH1F *)dir->FindObjectAny("h_sumCutAmplitudeperLS5");
1053 
1054   HistCutNumBadChanDepth[2][3][4] = (TH1F *)dir->FindObjectAny("h_sumCutAmplitudeperLS8");
1055 
1056   HistCutNumBadChanDepth[2][4][1] = (TH1F *)dir->FindObjectAny("h_sumCutAmplitudeperLS6");
1057   HistCutNumBadChanDepth[2][4][2] = (TH1F *)dir->FindObjectAny("h_sumCutAmplitudeperLS7");
1058 
1059   HistNumChanDepth[2][1][1] = (TH1F *)dir->FindObjectAny("h_sum0AmplitudeperLS1");
1060   HistNumChanDepth[2][1][2] = (TH1F *)dir->FindObjectAny("h_sum0AmplitudeperLS2");
1061 
1062   HistNumChanDepth[2][2][1] = (TH1F *)dir->FindObjectAny("h_sum0AmplitudeperLS3");
1063   HistNumChanDepth[2][2][2] = (TH1F *)dir->FindObjectAny("h_sum0AmplitudeperLS4");
1064   HistNumChanDepth[2][2][3] = (TH1F *)dir->FindObjectAny("h_sum0AmplitudeperLS5");
1065 
1066   HistNumChanDepth[2][3][4] = (TH1F *)dir->FindObjectAny("h_sum0AmplitudeperLS8");
1067 
1068   HistNumChanDepth[2][4][1] = (TH1F *)dir->FindObjectAny("h_sum0AmplitudeperLS6");
1069   HistNumChanDepth[2][4][2] = (TH1F *)dir->FindObjectAny("h_sum0AmplitudeperLS7");
1070 
1071   HistNumChanFull[2] = (TH1F *)HistNumChanDepth[2][1][1]->Clone();
1072   //+++++++++++++++++++++++++++++
1073   // Ratio
1074   //+++++++++++++++++++++++++++++
1075 
1076   HistNumBadChanDepth[3][1][1] = (TH1F *)dir->FindObjectAny("h_sumAmplperLS1");
1077   HistNumBadChanDepth[3][1][2] = (TH1F *)dir->FindObjectAny("h_sumAmplperLS2");
1078 
1079   HistNumBadChanDepth[3][2][1] = (TH1F *)dir->FindObjectAny("h_sumAmplperLS3");
1080   HistNumBadChanDepth[3][2][2] = (TH1F *)dir->FindObjectAny("h_sumAmplperLS4");
1081   HistNumBadChanDepth[3][2][3] = (TH1F *)dir->FindObjectAny("h_sumAmplperLS5");
1082 
1083   HistNumBadChanDepth[3][3][4] = (TH1F *)dir->FindObjectAny("h_sumAmplperLS8");
1084 
1085   HistNumBadChanDepth[3][4][1] = (TH1F *)dir->FindObjectAny("h_sumAmplperLS6");
1086   HistNumBadChanDepth[3][4][2] = (TH1F *)dir->FindObjectAny("h_sumAmplperLS7");
1087 
1088   HistNumBadChanFull[3] = (TH1F *)HistNumBadChanDepth[3][1][1]->Clone();
1089 
1090   HistCutNumBadChanDepth[3][1][1] = (TH1F *)dir->FindObjectAny("h_sumCutAmplperLS1");
1091   HistCutNumBadChanDepth[3][1][2] = (TH1F *)dir->FindObjectAny("h_sumCutAmplperLS2");
1092 
1093   HistCutNumBadChanDepth[3][2][1] = (TH1F *)dir->FindObjectAny("h_sumCutAmplperLS3");
1094   HistCutNumBadChanDepth[3][2][2] = (TH1F *)dir->FindObjectAny("h_sumCutAmplperLS4");
1095   HistCutNumBadChanDepth[3][2][3] = (TH1F *)dir->FindObjectAny("h_sumCutAmplperLS5");
1096 
1097   HistCutNumBadChanDepth[3][3][4] = (TH1F *)dir->FindObjectAny("h_sumCutAmplperLS8");
1098 
1099   HistCutNumBadChanDepth[3][4][1] = (TH1F *)dir->FindObjectAny("h_sumCutAmplperLS6");
1100   HistCutNumBadChanDepth[3][4][2] = (TH1F *)dir->FindObjectAny("h_sumCutAmplperLS7");
1101 
1102   HistNumChanDepth[3][1][1] = (TH1F *)dir->FindObjectAny("h_sum0AmplperLS1");
1103   HistNumChanDepth[3][1][2] = (TH1F *)dir->FindObjectAny("h_sum0AmplperLS2");
1104 
1105   HistNumChanDepth[3][2][1] = (TH1F *)dir->FindObjectAny("h_sum0AmplperLS3");
1106   HistNumChanDepth[3][2][2] = (TH1F *)dir->FindObjectAny("h_sum0AmplperLS4");
1107   HistNumChanDepth[3][2][3] = (TH1F *)dir->FindObjectAny("h_sum0AmplperLS5");
1108 
1109   HistNumChanDepth[3][3][4] = (TH1F *)dir->FindObjectAny("h_sum0AmplperLS8");
1110 
1111   HistNumChanDepth[3][4][1] = (TH1F *)dir->FindObjectAny("h_sum0AmplperLS6");
1112   HistNumChanDepth[3][4][2] = (TH1F *)dir->FindObjectAny("h_sum0AmplperLS7");
1113 
1114   HistNumChanFull[3] = (TH1F *)HistNumChanDepth[3][1][1]->Clone();
1115   //+++++++++++++++++++++++++++++
1116   // Tmean
1117   //+++++++++++++++++++++++++++++
1118 
1119   HistNumBadChanDepth[4][1][1] = (TH1F *)dir->FindObjectAny("h_sumTSmeanAperLS1");
1120   HistNumBadChanDepth[4][1][2] = (TH1F *)dir->FindObjectAny("h_sumTSmeanAperLS2");
1121 
1122   HistNumBadChanDepth[4][2][1] = (TH1F *)dir->FindObjectAny("h_sumTSmeanAperLS3");
1123   HistNumBadChanDepth[4][2][2] = (TH1F *)dir->FindObjectAny("h_sumTSmeanAperLS4");
1124   HistNumBadChanDepth[4][2][3] = (TH1F *)dir->FindObjectAny("h_sumTSmeanAperLS5");
1125 
1126   HistNumBadChanDepth[4][3][4] = (TH1F *)dir->FindObjectAny("h_sumTSmeanAperLS8");
1127 
1128   HistNumBadChanDepth[4][4][1] = (TH1F *)dir->FindObjectAny("h_sumTSmeanAperLS6");
1129   HistNumBadChanDepth[4][4][2] = (TH1F *)dir->FindObjectAny("h_sumTSmeanAperLS7");
1130 
1131   HistNumBadChanFull[4] = (TH1F *)HistNumBadChanDepth[4][1][1]->Clone();
1132 
1133   HistCutNumBadChanDepth[4][1][1] = (TH1F *)dir->FindObjectAny("h_sumCutTSmeanAperLS1");
1134   HistCutNumBadChanDepth[4][1][2] = (TH1F *)dir->FindObjectAny("h_sumCutTSmeanAperLS2");
1135 
1136   HistCutNumBadChanDepth[4][2][1] = (TH1F *)dir->FindObjectAny("h_sumCutTSmeanAperLS3");
1137   HistCutNumBadChanDepth[4][2][2] = (TH1F *)dir->FindObjectAny("h_sumCutTSmeanAperLS4");
1138   HistCutNumBadChanDepth[4][2][3] = (TH1F *)dir->FindObjectAny("h_sumCutTSmeanAperLS5");
1139 
1140   HistCutNumBadChanDepth[4][3][4] = (TH1F *)dir->FindObjectAny("h_sumCutTSmeanAperLS8");
1141 
1142   HistCutNumBadChanDepth[4][4][1] = (TH1F *)dir->FindObjectAny("h_sumCutTSmeanAperLS6");
1143   HistCutNumBadChanDepth[4][4][2] = (TH1F *)dir->FindObjectAny("h_sumCutTSmeanAperLS7");
1144 
1145   HistNumChanDepth[4][1][1] = (TH1F *)dir->FindObjectAny("h_sum0TSmeanAperLS1");
1146   HistNumChanDepth[4][1][2] = (TH1F *)dir->FindObjectAny("h_sum0TSmeanAperLS2");
1147 
1148   HistNumChanDepth[4][2][1] = (TH1F *)dir->FindObjectAny("h_sum0TSmeanAperLS3");
1149   HistNumChanDepth[4][2][2] = (TH1F *)dir->FindObjectAny("h_sum0TSmeanAperLS4");
1150   HistNumChanDepth[4][2][3] = (TH1F *)dir->FindObjectAny("h_sum0TSmeanAperLS5");
1151 
1152   HistNumChanDepth[4][3][4] = (TH1F *)dir->FindObjectAny("h_sum0TSmeanAperLS8");
1153 
1154   HistNumChanDepth[4][4][1] = (TH1F *)dir->FindObjectAny("h_sum0TSmeanAperLS6");
1155   HistNumChanDepth[4][4][2] = (TH1F *)dir->FindObjectAny("h_sum0TSmeanAperLS7");
1156 
1157   HistNumChanFull[4] = (TH1F *)HistNumChanDepth[4][1][1]->Clone();
1158   //+++++++++++++++++++++++++++++
1159   // Tmax
1160   //+++++++++++++++++++++++++++++
1161 
1162   HistNumBadChanDepth[5][1][1] = (TH1F *)dir->FindObjectAny("h_sumTSmaxAperLS1");
1163   HistNumBadChanDepth[5][1][2] = (TH1F *)dir->FindObjectAny("h_sumTSmaxAperLS2");
1164 
1165   HistNumBadChanDepth[5][2][1] = (TH1F *)dir->FindObjectAny("h_sumTSmaxAperLS3");
1166   HistNumBadChanDepth[5][2][2] = (TH1F *)dir->FindObjectAny("h_sumTSmaxAperLS4");
1167   HistNumBadChanDepth[5][2][3] = (TH1F *)dir->FindObjectAny("h_sumTSmaxAperLS5");
1168 
1169   HistNumBadChanDepth[5][3][4] = (TH1F *)dir->FindObjectAny("h_sumTSmaxAperLS8");
1170 
1171   HistNumBadChanDepth[5][4][1] = (TH1F *)dir->FindObjectAny("h_sumTSmaxAperLS6");
1172   HistNumBadChanDepth[5][4][2] = (TH1F *)dir->FindObjectAny("h_sumTSmaxAperLS7");
1173 
1174   HistNumBadChanFull[5] = (TH1F *)HistNumBadChanDepth[5][1][1]->Clone();
1175 
1176   HistCutNumBadChanDepth[5][1][1] = (TH1F *)dir->FindObjectAny("h_sumCutTSmaxAperLS1");
1177   HistCutNumBadChanDepth[5][1][2] = (TH1F *)dir->FindObjectAny("h_sumCutTSmaxAperLS2");
1178 
1179   HistCutNumBadChanDepth[5][2][1] = (TH1F *)dir->FindObjectAny("h_sumCutTSmaxAperLS3");
1180   HistCutNumBadChanDepth[5][2][2] = (TH1F *)dir->FindObjectAny("h_sumCutTSmaxAperLS4");
1181   HistCutNumBadChanDepth[5][2][3] = (TH1F *)dir->FindObjectAny("h_sumCutTSmaxAperLS5");
1182 
1183   HistCutNumBadChanDepth[5][3][4] = (TH1F *)dir->FindObjectAny("h_sumCutTSmaxAperLS8");
1184 
1185   HistCutNumBadChanDepth[5][4][1] = (TH1F *)dir->FindObjectAny("h_sumCutTSmaxAperLS6");
1186   HistCutNumBadChanDepth[5][4][2] = (TH1F *)dir->FindObjectAny("h_sumCutTSmaxAperLS7");
1187 
1188   HistNumChanDepth[5][1][1] = (TH1F *)dir->FindObjectAny("h_sum0TSmaxAperLS1");
1189   HistNumChanDepth[5][1][2] = (TH1F *)dir->FindObjectAny("h_sum0TSmaxAperLS2");
1190 
1191   HistNumChanDepth[5][2][1] = (TH1F *)dir->FindObjectAny("h_sum0TSmaxAperLS3");
1192   HistNumChanDepth[5][2][2] = (TH1F *)dir->FindObjectAny("h_sum0TSmaxAperLS4");
1193   HistNumChanDepth[5][2][3] = (TH1F *)dir->FindObjectAny("h_sum0TSmaxAperLS5");
1194 
1195   HistNumChanDepth[5][3][4] = (TH1F *)dir->FindObjectAny("h_sum0TSmaxAperLS8");
1196 
1197   HistNumChanDepth[5][4][1] = (TH1F *)dir->FindObjectAny("h_sum0TSmaxAperLS6");
1198   HistNumChanDepth[5][4][2] = (TH1F *)dir->FindObjectAny("h_sum0TSmaxAperLS7");
1199 
1200   HistNumChanFull[5] = (TH1F *)HistNumChanDepth[5][1][1]->Clone();
1201 
1202   for (int test = 0; test <= 5; test++) {  //Test: =0(CapIdErrors), =1(Amplitude), =2...
1203     for (int sub = 1; sub <= 4; sub++) {   //Subdetector: 1-HB, 2-HE, 3-HO, 4-HF
1204       if (sub == 1 && test != 1)
1205         cHE->Divide(2, 1);  //HB
1206       if (sub == 1 && test == 1) {
1207         cFour1->Clear();
1208         cFour1->Divide(2, 2);
1209       }  //HB upgrade with new depthes 3,4 for Amplitude test only
1210       if (sub == 2 && test != 1)
1211         cHE->Divide(3, 1);  //HE
1212       if (sub == 2 && test == 1) {
1213         cNine->Clear();
1214         cNine->Divide(3, 3);
1215       }  //HE upgrade with new depthes 4,5,6,7 for Amplitude test only
1216       if (sub == 3)
1217         cHB->Divide(1, 1);  //HO
1218       if (sub == 4 && test != 1)
1219         cHE->Divide(2, 1);  //HF
1220       if (sub == 4 && test == 1) {
1221         cFour1->Clear();
1222         cFour1->Divide(2, 2);
1223       }  // HF upgrade with new depthes 3 and 4 for Amplitude test only
1224 
1225       int kkkkkkmax = k_max[sub];
1226       //      if ( (sub==4 || sub==2) && test==1) kkkkkkmax = k_maxupgrade[sub];
1227       if ((sub == 4 || sub == 2 || sub == 1) && test == 1)
1228         kkkkkkmax = k_maxupgrade[sub];
1229       for (int k = k_min[sub]; k <= kkkkkkmax; k++) {  //Depth
1230         if (sub == 1 && test != 1)
1231           cHE->cd(k);  //HB
1232         if (sub == 1 && test == 1)
1233           cFour1->cd(k);  //HB
1234         if (sub == 2 && test != 1)
1235           cHE->cd(k);  //HE
1236         if (sub == 2 && test == 1)
1237           cNine->cd(k);  //HE upgrade with new depthes 4,5,6,7 for Amplitude test only
1238         if (sub == 3)
1239           cHB->cd(k - 3);  //HO
1240         if (sub == 4 && test != 1)
1241           cHE->cd(k);  //HF
1242         if (sub == 4 && test == 1)
1243           cFour1->cd(k);  // HF upgrade with new depthes 3 and 4 for Amplitude test only
1244         gPad->SetGridy();
1245         gPad->SetGridx();
1246         //                gPad->SetLogy();
1247 
1248         if (sub == 1 && k == 1) {
1249         } else {
1250           // use "else" because ...Full[test] are filled by estimastor for sub==1 && k== 1 at initialization of ...Full[test] variables
1251           for (int x = 1; x <= HistNumBadChanFull[test]->GetXaxis()->GetNbins(); x++) {
1252             double ccc1 = HistNumBadChanDepth[test][sub][k]->GetBinContent(x);
1253             HistNumBadChanFull[test]->SetBinContent(x, HistNumBadChanFull[test]->GetBinContent(x) + ccc1);
1254             double ccc2 = HistNumChanDepth[test][sub][k]->GetBinContent(x);
1255             HistNumChanFull[test]->SetBinContent(x, HistNumChanFull[test]->GetBinContent(x) + ccc2);
1256           }
1257         }  //end x
1258 
1259         // !!!!!!     change the sense of HistNumBadChanDepth: now it's averaged values(estimators)
1260         HistNumBadChanDepth[test][sub][k]->Divide(
1261             HistNumBadChanDepth[test][sub][k], HistNumChanDepth[test][sub][k], 1, 1, "B");
1262         // errors abnulling:
1263         for (int x = 1; x <= HistNumBadChanDepth[test][sub][k]->GetXaxis()->GetNbins(); x++) {
1264           HistNumBadChanDepth[test][sub][k]->SetBinError(float(x), 0.01);
1265         }
1266 
1267         //      int myMaxLum= HistNumBadChanDepth[test][sub][k]->GetBinContent(HistNumBadChanDepth[test][sub][k]->GetMaximumBin());
1268         //      cout<<"********************>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>     myMaxLum = "<<myMaxLum<<"        MaxLum = "<<MaxLum<<endl;
1269         HistNumBadChanDepth[test][sub][k]->GetXaxis()->SetRangeUser(0, MaxLum);
1270 
1271         //   //    //   //   //   //   //   //   //   //   //   //   //   //   //   //   //  //
1272         HistNumBadChanDepth[test][sub][k]->SetMarkerStyle(20);
1273         HistNumBadChanDepth[test][sub][k]->SetMarkerSize(0.4);
1274         HistNumBadChanDepth[test][sub][k]->GetYaxis()->SetLabelSize(0.04);
1275         if (k == 1)
1276           HistNumBadChanDepth[test][sub][k]->SetTitle("Depth 1\b");
1277         if (k == 2)
1278           HistNumBadChanDepth[test][sub][k]->SetTitle("Depth 2\b");
1279         if (k == 3)
1280           HistNumBadChanDepth[test][sub][k]->SetTitle("Depth 3\b");
1281         if (k == 4)
1282           HistNumBadChanDepth[test][sub][k]->SetTitle("Depth 4\b");
1283         if (k == 5)
1284           HistNumBadChanDepth[test][sub][k]->SetTitle("Depth 5\b");
1285         if (k == 6)
1286           HistNumBadChanDepth[test][sub][k]->SetTitle("Depth 6\b");
1287         if (k == 7)
1288           HistNumBadChanDepth[test][sub][k]->SetTitle("Depth 7\b");
1289         HistNumBadChanDepth[test][sub][k]->SetXTitle("LS \b");
1290         if (test == 0)
1291           HistNumBadChanDepth[test][sub][k]->SetYTitle("<Number of bad channels> \b");
1292         if (test != 0)
1293           HistNumBadChanDepth[test][sub][k]->SetYTitle("Averaged estimator \b");
1294         HistNumBadChanDepth[test][sub][k]->SetMarkerColor(2);
1295         HistNumBadChanDepth[test][sub][k]->SetLineColor(0);
1296         //      gPad->SetGridx();
1297         gPad->SetLogy();
1298         gPad->SetGridy();
1299         gPad->SetGridx();
1300         //      if (test == 1) HistNumBadChanDepth[test][sub][k]->SetMinimum(0.1);
1301         HistNumBadChanDepth[test][sub][k]->Draw("Error");
1302         /*
1303           if (k == 1) HistNumBadChanDepth[test][sub][k]->SetTitle("Depth 1\b");
1304           if (k == 2) HistNumBadChanDepth[test][sub][k]->SetTitle("Depth 2\b");
1305           if (k == 3) HistNumBadChanDepth[test][sub][k]->SetTitle("Depth 3\b");
1306           if (k == 4) HistNumBadChanDepth[test][sub][k]->SetTitle("Depth 4\b");
1307           HistNumBadChanDepth[test][sub][k]->SetXTitle("LS \b");
1308           if (test == 0) HistNumBadChanDepth[test][sub][k]->SetYTitle("<Number of bad channels> \b");
1309           if (test != 0) HistNumBadChanDepth[test][sub][k]->SetYTitle("Averaged estimator \b");
1310           
1311           if (MaxLum<=1000){
1312           HistNumBadChanDepth[test][sub][k]->SetMarkerStyle(20);
1313           HistNumBadChanDepth[test][sub][k]->SetMarkerSize(0.5);    
1314           HistNumBadChanDepth[test][sub][k]->SetMarkerColor(2);
1315           HistNumBadChanDepth[test][sub][k]->SetLineColor(0);
1316           HistNumBadChanDepth[test][sub][k]->GetXaxis()->SetRangeUser(0, MaxLum);
1317           HistNumBadChanDepth[test][sub][k]->Draw("P");
1318           }
1319           else{
1320           HistNumBadChanDepth[test][sub][k]->SetLineColor(2);
1321           HistNumBadChanDepth[test][sub][k]->GetXaxis()->SetRangeUser(0, MaxLum);
1322           HistNumBadChanDepth[test][sub][k]->Draw("L");
1323           } 
1324         */
1325         /*
1326         float min_x[] = {0,10000};
1327         float min_y[] = {(float)(Cut0[test][sub][k]),(float)(Cut0[test][sub][k])};
1328         TGraph* MIN = new TGraph(2, min_x, min_y);
1329         MIN->SetLineStyle(2);
1330         MIN->SetLineColor(5);
1331         MIN->SetLineWidth(2 + 100*100);
1332         MIN->SetFillStyle(3005);
1333         MIN->SetFillColor(5);
1334         gPad->SetGridy();
1335         gPad->SetGridx();
1336         MIN->Draw("L");
1337 */
1338 
1339         if (sub == 1 && test != 1) {
1340           cHE->Modified();
1341         }
1342         if (sub == 1 && test == 1) {
1343           cFour1->Modified();
1344         }  // HB upgrade
1345         if (sub == 2 && test != 1) {
1346           cHE->Modified();
1347         }
1348         if (sub == 2 && test == 1) {
1349           cNine->Modified();
1350         }  // HE upgrade
1351         if (sub == 3) {
1352           cHB->Modified();
1353         }
1354         if (sub == 4 && test != 1) {
1355           cHE->Modified();
1356         }
1357         if (sub == 4 && test == 1) {
1358           cFour1->Modified();
1359         }  // HF upgrade
1360 
1361       }  // k loop
1362 
1363       if (test == 0) {
1364         if (sub == 1) {
1365           cHE->Print("HistNBCMNHB.png");
1366           cHE->Clear();
1367         }
1368         if (sub == 2) {
1369           cHE->Print("HistNBCMNHE.png");
1370           cHE->Clear();
1371         }
1372         if (sub == 3) {
1373           cHB->Print("HistNBCMNHO.png");
1374           cHB->Clear();
1375         }
1376         if (sub == 4) {
1377           cHE->Print("HistNBCMNHF.png");
1378           cHE->Clear();
1379         }
1380       }
1381       // Amplitude:
1382       if (test == 1) {
1383         if (sub == 1) {
1384           cFour1->Print("HistADCamplHB.png");
1385           cFour1->Clear();
1386         }  // HB upgrade
1387         if (sub == 2) {
1388           cNine->Print("HistADCamplHE.png");
1389           cNine->Clear();
1390         }  // HE upgrade
1391         if (sub == 3) {
1392           cHB->Print("HistADCamplHO.png");
1393           cHB->Clear();
1394         }
1395         if (sub == 4) {
1396           cFour1->Print("HistADCamplHF.png");
1397           cFour1->Clear();
1398         }  // HF upgrade
1399       }
1400       if (test == 2) {
1401         if (sub == 1) {
1402           cHE->Print("HistWidthHB.png");
1403           cHE->Clear();
1404         }
1405         if (sub == 2) {
1406           cHE->Print("HistWidthHE.png");
1407           cHE->Clear();
1408         }
1409         if (sub == 3) {
1410           cHB->Print("HistWidthHO.png");
1411           cHB->Clear();
1412         }
1413         if (sub == 4) {
1414           cHE->Print("HistWidthHF.png");
1415           cHE->Clear();
1416         }
1417       }
1418       if (test == 3) {
1419         if (sub == 1) {
1420           cHE->Print("HistRatioHB.png");
1421           cHE->Clear();
1422         }
1423         if (sub == 2) {
1424           cHE->Print("HistRatioHE.png");
1425           cHE->Clear();
1426         }
1427         if (sub == 3) {
1428           cHB->Print("HistRatioHO.png");
1429           cHB->Clear();
1430         }
1431         if (sub == 4) {
1432           cHE->Print("HistRatioHF.png");
1433           cHE->Clear();
1434         }
1435       }
1436       if (test == 4) {
1437         if (sub == 1) {
1438           cHE->Print("HistTmeanHB.png");
1439           cHE->Clear();
1440         }
1441         if (sub == 2) {
1442           cHE->Print("HistTmeanHE.png");
1443           cHE->Clear();
1444         }
1445         if (sub == 3) {
1446           cHB->Print("HistTmeanHO.png");
1447           cHB->Clear();
1448         }
1449         if (sub == 4) {
1450           cHE->Print("HistTmeanHF.png");
1451           cHE->Clear();
1452         }
1453       }
1454       if (test == 5) {
1455         if (sub == 1) {
1456           cHE->Print("HistTmaxHB.png");
1457           cHE->Clear();
1458         }
1459         if (sub == 2) {
1460           cHE->Print("HistTmaxHE.png");
1461           cHE->Clear();
1462         }
1463         if (sub == 3) {
1464           cHB->Print("HistTmaxHO.png");
1465           cHB->Clear();
1466         }
1467         if (sub == 4) {
1468           cHE->Print("HistTmaxHF.png");
1469           cHE->Clear();
1470         }
1471       }
1472     }  // end sub
1473     ///////////////////////////////////////////// other cases:
1474     if (test == 1) {
1475       for (int x = 1; x <= HistNumChanFull[6]->GetXaxis()->GetNbins(); x++) {
1476         HistNumChanFull[6]->SetBinContent(x, 0.0);
1477         int depthsubcount = 0.;
1478         for (int sub = 1; sub <= 4; sub++) {  //Subdetector: 1-HB, 2-HE, 3-HO, 4-HF
1479           int kkkkkkmax = k_max[sub];
1480           if (sub == 4 || sub == 2 || sub == 1)
1481             kkkkkkmax = k_maxupgrade[sub];
1482           //          if ( sub==4 || sub==2) kkkkkkmax = k_maxupgrade[sub];
1483           for (int k = k_min[sub]; k <= kkkkkkmax; k++) {  //Depth
1484             // line below is temporary, just to avoid contribution of HEP(M)17 in depthes 4,5,6,7 but keep in depthes 1,2,3
1485             //      if(sub==2 && k>3 ) break;
1486             depthsubcount++;
1487             double ccc1 = HistNumBadChanDepth[test][sub][k]->GetBinContent(x);
1488             HistNumChanFull[6]->SetBinContent(x, HistNumChanFull[6]->GetBinContent(x) + ccc1);
1489           }  //depth
1490         }    //sub
1491         if (depthsubcount > 0.) {
1492           HistNumChanFull[6]->SetBinContent(x, (HistNumChanFull[6]->GetBinContent(x)) / depthsubcount);
1493         } else {
1494           HistNumChanFull[6]->SetBinContent(x, (HistNumChanFull[6]->GetBinContent(x)) / 8.);
1495         }
1496       }  //x
1497     }    //test=1
1498     ////////////  //////   //////  //////  ////// //////
1499     if (test != 1) {
1500       cHB->Divide(1, 1);
1501       cHB->cd(1);
1502     } else {
1503       cHE->Divide(2, 1);
1504       cHE->cd(1);
1505     }
1506     HistNumBadChanFull[test]->Divide(HistNumBadChanFull[test], HistNumChanFull[test], 1, 1, "B");
1507     TH1F *kfitq = new TH1F("kfitq", "", MaxLum, 1., MaxLum + 1.);
1508     int nx = kfitq->GetXaxis()->GetNbins();
1509     for (int i = 1; i <= nx; i++) {
1510       double ccc1 = HistNumBadChanFull[test]->GetBinContent(i);
1511       if (ccc1 > 0.) {
1512         kfitq->Fill(float(i), ccc1);
1513         kfitq->SetBinError(float(i), 0.01);
1514       }
1515     }
1516     kfitq->SetMarkerStyle(20);
1517     kfitq->SetMarkerSize(0.4);
1518     kfitq->GetYaxis()->SetLabelSize(0.04);
1519     if (test == 0)
1520       kfitq->SetTitle("Average Nbch for whole Hcal \b");
1521     if (test != 0)
1522       kfitq->SetTitle("Averaged estimator for whole Hcal \b");
1523     kfitq->SetXTitle("LS \b");
1524     if (test == 0)
1525       kfitq->SetYTitle("<Number of bad channels> \b");
1526     if (test != 0)
1527       kfitq->SetYTitle("Averaged estimator \b");
1528     kfitq->SetMarkerColor(2);
1529     kfitq->SetLineColor(0);
1530     gPad->SetGridx();
1531     kfitq->Draw("Error");
1532     /* 
1533        HistNumBadChanFull[test]->SetMarkerStyle(20);
1534        HistNumBadChanFull[test]->SetMarkerSize(0.8);
1535        HistNumBadChanFull[test]->SetTitle("Averaged estimator for whole Hcal \b");
1536        HistNumBadChanFull[test]->SetXTitle("LS \b");
1537        if (test == 0) HistNumBadChanFull[test]->SetYTitle("<Number of bad channels> \b");
1538        if (test != 0) HistNumBadChanFull[test]->SetYTitle("Averaged estimator \b");
1539        if (MaxLum<=1000){
1540        HistNumBadChanFull[test]->SetMarkerColor(1);
1541        HistNumBadChanFull[test]->SetLineColor(0);
1542        HistNumBadChanFull[test]->Draw("P"); 
1543        }
1544        else {
1545        HistNumBadChanFull[test]->SetLineColor(1);
1546        HistNumBadChanFull[test]->Draw("L"); 
1547        }
1548     */
1549     if (test == 1) {
1550       cHE->cd(2);
1551       TH1F *lpuio = new TH1F("lpuio", "", MaxLum, 1., MaxLum + 1.);
1552       int nx = lpuio->GetXaxis()->GetNbins();
1553       for (int i = 1; i <= nx; i++) {
1554         double ccc1 = HistNumChanFull[6]->GetBinContent(i);
1555         if (ccc1 > 0.) {
1556           lpuio->Fill(float(i), ccc1);
1557           lpuio->SetBinError(float(i), 0.01);
1558         }
1559       }
1560       lpuio->SetMarkerStyle(20);
1561       lpuio->SetMarkerSize(0.4);
1562       lpuio->GetYaxis()->SetLabelSize(0.04);
1563       lpuio->SetTitle("Mean of Averaged Amplitudes over all Hcal sub-detectors \b");
1564       lpuio->SetXTitle("LS \b");
1565       lpuio->SetYTitle("Mean of Averaged estimator \b");
1566       lpuio->SetMarkerColor(2);
1567       lpuio->SetLineColor(0);
1568       gPad->SetGridx();
1569       lpuio->Draw("Error");
1570     }
1571     if (test == 0) {
1572       cHB->Print("HistCapID.png");
1573       cHB->Clear();
1574     }
1575     if (test == 1) {
1576       cHE->Print("HistADCAmpl.png");
1577       cHE->Clear();
1578     }
1579     if (test == 2) {
1580       cHB->Print("HistWidth.png");
1581       cHB->Clear();
1582     }
1583     if (test == 3) {
1584       cHB->Print("HistRatio.png");
1585       cHB->Clear();
1586     }
1587     if (test == 4) {
1588       cHB->Print("HistTmean.png");
1589       cHB->Clear();
1590     }
1591     if (test == 5) {
1592       cHB->Print("HistTmax.png");
1593       cHB->Clear();
1594     }
1595 
1596     // clean-up
1597     if (kfitq)
1598       delete kfitq;
1599   }  //end test
1600 
1601   //================================================================================================================================
1602 
1603   //=======================================================================================================333
1604   //CapID 1-d histograms
1605 
1606   TH1F *HistAbnormNumBadChanDepth[5][5];  // 1d histogramm for subdet, depth
1607 
1608   //+++++++++++++++++++++++++++++
1609   // Abnormal Bad Channels Rate of Cap ID errors  first set of histograms
1610   //+++++++++++++++++++++++++++++
1611 
1612   HistAbnormNumBadChanDepth[1][1] = (TH1F *)dir->FindObjectAny("h_runnbadchannelsC_depth1_HB");
1613   HistAbnormNumBadChanDepth[1][2] = (TH1F *)dir->FindObjectAny("h_runnbadchannelsC_depth2_HB");
1614   HistAbnormNumBadChanDepth[2][1] = (TH1F *)dir->FindObjectAny("h_runnbadchannelsC_depth1_HE");
1615   HistAbnormNumBadChanDepth[2][2] = (TH1F *)dir->FindObjectAny("h_runnbadchannelsC_depth2_HE");
1616   HistAbnormNumBadChanDepth[2][3] = (TH1F *)dir->FindObjectAny("h_runnbadchannelsC_depth3_HE");
1617   HistAbnormNumBadChanDepth[3][4] = (TH1F *)dir->FindObjectAny("h_runnbadchannelsC_depth4_HO");
1618   HistAbnormNumBadChanDepth[4][1] = (TH1F *)dir->FindObjectAny("h_runnbadchannelsC_depth1_HF");
1619   HistAbnormNumBadChanDepth[4][2] = (TH1F *)dir->FindObjectAny("h_runnbadchannelsC_depth2_HF");
1620 
1621   for (int sub = 1; sub <= 4; sub++) {  //Subdetector: 1-HB, 2-HE, 3-HF, 4-HO
1622     if (sub == 1)
1623       cHB->Divide(2, 1);
1624     if (sub == 2)
1625       cHE->Divide(3, 1);
1626     if (sub == 3)
1627       cONE->Divide(1, 1);
1628     if (sub == 4)
1629       cHB->Divide(2, 1);
1630     for (int k = k_min[sub]; k <= k_max[sub]; k++) {  //Depth
1631       if (sub == 1)
1632         cHB->cd(k);
1633       if (sub == 2)
1634         cHE->cd(k);
1635       if (sub == 3)
1636         cONE->cd(k - 3);
1637       if (sub == 4)
1638         cHB->cd(k);
1639       gPad->SetGridy();
1640       gPad->SetGridx();
1641       //  gPad->SetLogy();
1642       HistAbnormNumBadChanDepth[sub][k]->Divide(
1643           HistAbnormNumBadChanDepth[sub][k], HistNumChanDepth[0][sub][k], 1, 1, "B");
1644       if (k == 1)
1645         HistAbnormNumBadChanDepth[sub][k]->SetTitle("Depth 1\b");
1646       if (k == 2)
1647         HistAbnormNumBadChanDepth[sub][k]->SetTitle("Depth 2\b");
1648       if (k == 3)
1649         HistAbnormNumBadChanDepth[sub][k]->SetTitle("Depth 3\b");
1650       if (k == 4)
1651         HistAbnormNumBadChanDepth[sub][k]->SetTitle("Depth 4\b");
1652       HistAbnormNumBadChanDepth[sub][k]->SetXTitle("LS \b");
1653       HistAbnormNumBadChanDepth[sub][k]->SetYTitle("< Number of bad channels > \b");
1654       if (MaxLum <= 1000) {
1655         HistAbnormNumBadChanDepth[sub][k]->SetMarkerStyle(20);
1656         HistAbnormNumBadChanDepth[sub][k]->SetMarkerSize(0.5);
1657         HistAbnormNumBadChanDepth[sub][k]->SetMarkerColor(1);
1658         HistAbnormNumBadChanDepth[sub][k]->SetLineColor(0);
1659         HistAbnormNumBadChanDepth[sub][k]->GetXaxis()->SetRangeUser(0, MaxLum);
1660         HistAbnormNumBadChanDepth[sub][k]->Draw("P");
1661       } else {
1662         HistAbnormNumBadChanDepth[sub][k]->SetLineColor(1);
1663         HistAbnormNumBadChanDepth[sub][k]->GetXaxis()->SetRangeUser(0, MaxLum);
1664         HistAbnormNumBadChanDepth[sub][k]->Draw("L");
1665       }
1666     }
1667     if (sub == 1) {
1668       cHB->Print("Hist_CAPID_Abnorm_HB.png");
1669       cHB->Clear();
1670     }
1671     if (sub == 2) {
1672       cHE->Print("Hist_CAPID_Abnorm_HE.png");
1673       cHE->Clear();
1674     }
1675     if (sub == 3) {
1676       cONE->Print("Hist_CAPID_Abnorm_HO.png");
1677       cONE->Clear();
1678     }
1679     if (sub == 4) {
1680       cHB->Print("Hist_CAPID_Abnorm_HF.png");
1681       cHB->Clear();
1682     }
1683   }  // end sub
1684 
1685   //+++++++++++++++++++++++++++++
1686   // Portions of bad channels events identified by Cap ID errors   third set of histograms
1687   //+++++++++++++++++++++++++++++
1688 
1689   TH1F *HistPortBadEventsDepth[5][5];  // 1d histogramm for subdet, depth
1690 
1691   HistPortBadEventsDepth[1][1] = (TH1F *)dir->FindObjectAny("h_runbadrateC_depth1_HB");
1692   HistPortBadEventsDepth[1][2] = (TH1F *)dir->FindObjectAny("h_runbadrateC_depth2_HB");
1693   HistPortBadEventsDepth[2][1] = (TH1F *)dir->FindObjectAny("h_runbadrateC_depth1_HE");
1694   HistPortBadEventsDepth[2][2] = (TH1F *)dir->FindObjectAny("h_runbadrateC_depth2_HE");
1695   HistPortBadEventsDepth[2][3] = (TH1F *)dir->FindObjectAny("h_runbadrateC_depth3_HE");
1696   HistPortBadEventsDepth[3][4] = (TH1F *)dir->FindObjectAny("h_runbadrateC_depth4_HO");
1697   HistPortBadEventsDepth[4][1] = (TH1F *)dir->FindObjectAny("h_runbadrateC_depth1_HF");
1698   HistPortBadEventsDepth[4][2] = (TH1F *)dir->FindObjectAny("h_runbadrateC_depth2_HF");
1699 
1700   TH1F *HistNumRateDepth[5][5];
1701   HistNumRateDepth[1][1] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth1_HB");
1702   HistNumRateDepth[1][2] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth2_HB");
1703   HistNumRateDepth[2][1] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth1_HE");
1704   HistNumRateDepth[2][2] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth2_HE");
1705   HistNumRateDepth[2][3] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth3_HE");
1706   HistNumRateDepth[3][4] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth4_HO");
1707   HistNumRateDepth[4][1] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth1_HF");
1708   HistNumRateDepth[4][2] = (TH1F *)dir->FindObjectAny("h_runbadrate0_depth2_HF");
1709 
1710   for (int sub = 1; sub <= 4; sub++) {  //Subdetector: 1-HB, 2-HE, 3-HF, 4-HO
1711     if (sub == 1)
1712       cHB->Divide(2, 1);
1713     if (sub == 2)
1714       cHE->Divide(3, 1);
1715     if (sub == 3)
1716       cONE->Divide(1, 1);
1717     if (sub == 4)
1718       cHB->Divide(2, 1);
1719     for (int k = k_min[sub]; k <= k_max[sub]; k++) {  //Depth
1720       if (sub == 1)
1721         cHB->cd(k);
1722       if (sub == 2)
1723         cHE->cd(k);
1724       if (sub == 3)
1725         cONE->cd(k - 3);
1726       if (sub == 4)
1727         cHB->cd(k);
1728       gPad->SetGridy();
1729       gPad->SetGridx();
1730       //  gPad->SetLogy();
1731       HistPortBadEventsDepth[sub][k]->Divide(HistPortBadEventsDepth[sub][k], HistNumRateDepth[sub][k], 1, 1, "B");
1732 
1733       if (k == 1)
1734         HistPortBadEventsDepth[sub][k]->SetTitle("Depth 1\b");
1735       if (k == 2)
1736         HistPortBadEventsDepth[sub][k]->SetTitle("Depth 2\b");
1737       if (k == 3)
1738         HistPortBadEventsDepth[sub][k]->SetTitle("Depth 3\b");
1739       if (k == 4)
1740         HistPortBadEventsDepth[sub][k]->SetTitle("Depth 4\b");
1741       HistPortBadEventsDepth[sub][k]->SetXTitle("LS \b");
1742       HistPortBadEventsDepth[sub][k]->SetYTitle("< Number of bad channels > \b");
1743       if (MaxLum <= 1000) {
1744         HistPortBadEventsDepth[sub][k]->SetMarkerStyle(20);
1745         HistPortBadEventsDepth[sub][k]->SetMarkerSize(0.5);
1746         HistPortBadEventsDepth[sub][k]->SetMarkerColor(1);
1747         HistPortBadEventsDepth[sub][k]->SetLineColor(0);
1748         HistPortBadEventsDepth[sub][k]->GetXaxis()->SetRangeUser(0, MaxLum);
1749         HistPortBadEventsDepth[sub][k]->Draw("P");
1750       } else {
1751         HistPortBadEventsDepth[sub][k]->SetLineColor(1);
1752         HistPortBadEventsDepth[sub][k]->GetXaxis()->SetRangeUser(0, MaxLum);
1753         HistPortBadEventsDepth[sub][k]->Draw("L");
1754       }
1755     }
1756     if (sub == 1) {
1757       cHB->Print("HistPortHB.png");
1758       cHB->Clear();
1759     }
1760     if (sub == 2) {
1761       cHE->Print("HistPortHE.png");
1762       cHE->Clear();
1763     }
1764     if (sub == 3) {
1765       cONE->Print("HistPortHO.png");
1766       cONE->Clear();
1767     }
1768     if (sub == 4) {
1769       cHB->Print("HistPortHF.png");
1770       cHB->Clear();
1771     }
1772   }  // end sub
1773 
1774   //================================================================================================================================
1775 
1776   //+++++++++++++++++++++++++++++
1777   // Number of bad channels events identified by Cap ID errors   third set of histograms
1778   //+++++++++++++++++++++++++++++
1779 
1780   TH1F *HistNBadChsDepth[5][5];  // 1d histogramm for subdet, depth
1781 
1782   HistNBadChsDepth[1][1] = (TH1F *)dir->FindObjectAny("h_nbadchannels_depth1_HB");
1783   HistNBadChsDepth[1][2] = (TH1F *)dir->FindObjectAny("h_nbadchannels_depth2_HB");
1784   HistNBadChsDepth[2][1] = (TH1F *)dir->FindObjectAny("h_nbadchannels_depth1_HE");
1785   HistNBadChsDepth[2][2] = (TH1F *)dir->FindObjectAny("h_nbadchannels_depth2_HE");
1786   HistNBadChsDepth[2][3] = (TH1F *)dir->FindObjectAny("h_nbadchannels_depth3_HE");
1787   HistNBadChsDepth[3][4] = (TH1F *)dir->FindObjectAny("h_nbadchannels_depth4_HO");
1788   HistNBadChsDepth[4][1] = (TH1F *)dir->FindObjectAny("h_nbadchannels_depth1_HF");
1789   HistNBadChsDepth[4][2] = (TH1F *)dir->FindObjectAny("h_nbadchannels_depth2_HF");
1790 
1791   for (int sub = 1; sub <= 4; sub++) {  //Subdetector: 1-HB, 2-HE, 3-HF, 4-HO
1792     if (sub == 1)
1793       cHB->Divide(2, 1);
1794     if (sub == 2)
1795       cHE->Divide(3, 1);
1796     if (sub == 3)
1797       cONE->Divide(1, 1);
1798     if (sub == 4)
1799       cHB->Divide(2, 1);
1800     for (int k = k_min[sub]; k <= k_max[sub]; k++) {  //Depth
1801       if (sub == 1)
1802         cHB->cd(k);
1803       if (sub == 2)
1804         cHE->cd(k);
1805       if (sub == 3)
1806         cONE->cd(k - 3);
1807       if (sub == 4)
1808         cHB->cd(k);
1809       gPad->SetGridy();
1810       gPad->SetGridx();
1811       gPad->SetLogy();
1812 
1813       if (k == 1)
1814         HistNBadChsDepth[sub][k]->SetTitle("Depth 1\b");
1815       if (k == 2)
1816         HistNBadChsDepth[sub][k]->SetTitle("Depth 2\b");
1817       if (k == 3)
1818         HistNBadChsDepth[sub][k]->SetTitle("Depth 3\b");
1819       if (k == 4)
1820         HistNBadChsDepth[sub][k]->SetTitle("Depth 4\b");
1821       HistNBadChsDepth[sub][k]->SetXTitle("Number of bad channels\b");
1822       HistNBadChsDepth[sub][k]->SetYTitle("Number of events\b");
1823       //         HistNBadChsDepth[sub][k]->SetMarkerStyle(20);
1824       //         HistNBadChsDepth[sub][k]->SetMarkerSize(0.5);
1825       //         HistNBadChsDepth[sub][k]->SetMarkerColor(1);
1826       //         HistNBadChsDepth[sub][k]->SetLineColor(0);
1827       HistNBadChsDepth[sub][k]->Draw("");
1828     }
1829     if (sub == 1) {
1830       cHB->Print("HistNBadChsHB.png");
1831       cHB->Clear();
1832     }
1833     if (sub == 2) {
1834       cHE->Print("HistNBadChsHE.png");
1835       cHE->Clear();
1836     }
1837     if (sub == 3) {
1838       cONE->Print("HistNBadChsHO.png");
1839       cONE->Clear();
1840     }
1841     if (sub == 4) {
1842       cHB->Print("HistNBadChsHF.png");
1843       cHB->Clear();
1844     }
1845   }  // end sub
1846 
1847   //====================================================================== HB                    :
1848   //====================================================================== HB                    :
1849   //====================================================================== HB                    :
1850   // Special test of errors type A and B in HB
1851   // AZ 08.02.2016
1852 
1853   int flagErrAB_HB[2];
1854   flagErrAB_HB[0] = -1;
1855   flagErrAB_HB[1] = -1;
1856   double avedelta_HB = 0.;
1857   int lastLumiBin_HB = -1;
1858   int LSofFirstErrB_HB = -1;
1859   {
1860     const int specCountA = 4;
1861     const int specColors[specCountA] = {1, 2, 3, 4};
1862     const TString hnames[specCountA][2] = {{"h_sumADCAmplperLS1_P1", "h_sum0ADCAmplperLS1_P1"},
1863                                            {"h_sumADCAmplperLS1_P2", "h_sum0ADCAmplperLS1_P2"},
1864                                            {"h_sumADCAmplperLS1_M1", "h_sum0ADCAmplperLS1_M1"},
1865                                            {"h_sumADCAmplperLS1_M2", "h_sum0ADCAmplperLS1_M2"}};
1866 
1867     std::vector<TH1F *> hV;
1868     THStack *hs = new THStack("hs", "ADCAmplerLS1");
1869     cHB->Clear();
1870     //    cHB->cd();
1871     cHB->Divide(2, 1);
1872     cHB->cd(1);
1873 
1874     ///////////////////////////////////////////////////////////////////////////
1875     for (int i = 0; i < specCountA; i++) {
1876       if (1)
1877         std::cout << "debugger: errA_HB : get histos for i=" << i << " " << hnames[i][0] << " and " << hnames[i][1]
1878                   << "\n";
1879       TH1F *h1 = (TH1F *)dir->FindObjectAny(hnames[i][0]);
1880       TH1F *h0 = (TH1F *)dir->FindObjectAny(hnames[i][1]);
1881       if (!h1 || !h0) {
1882         TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
1883         ptext->AddText("Missing histo");
1884         if (!h1) {
1885           std::cout << "\tfailed to get " << hnames[i][0] << "\n";
1886           ptext->AddText(hnames[i][0]);
1887         }
1888         if (!h0) {
1889           std::cout << "\tfailed to get " << hnames[i][1] << "\n";
1890           ptext->AddText(hnames[i][1]);
1891         }
1892         ptext->Draw();
1893         continue;
1894       }
1895       TH1F *hERT1orig = (TH1F *)h1->Clone(Form("ERT1orig_%d", i));
1896       hERT1orig->Divide(h1, h0, 1, 1, "B");
1897 
1898       if ((lastLumiBin_HB < 0) && (i == 0)) {
1899         for (int ibin = hERT1orig->GetNbinsX(); ibin >= 1; ibin--) {
1900           if (hERT1orig->GetBinContent(ibin) == 0)
1901             lastLumiBin_HB = ibin;
1902           else
1903             break;
1904         }
1905         lastLumiBin_HB += 3;  // show more bins
1906         if (lastLumiBin_HB >= hERT1orig->GetNbinsX())
1907           lastLumiBin_HB = -1;
1908       }
1909       TH1F *hERT1 = NULL;
1910       if (lastLumiBin_HB > 1) {
1911         if (!copyContents(&hERT1, Form("ERT1_%d", i), "", hERT1orig, lastLumiBin_HB)) {
1912           std::cout << "code failed" << std::endl;
1913           gSystem->Exit(1);
1914         }
1915       } else
1916         hERT1 = hERT1orig;
1917 
1918       hERT1->GetXaxis()->SetTitle("<ADCAmpl> per LS HB: black-P1, red-P2,green-M1,blue-M2");
1919       hV.push_back(hERT1);
1920       hERT1->SetMarkerStyle(20);
1921       hERT1->SetMarkerSize(0.4);
1922       hERT1->SetXTitle("<A>(ev.in LS & ch.) - HB P1     -    iLS \b");
1923       hERT1->SetMarkerColor(specColors[i]);
1924       hERT1->SetLineColor(0);
1925       hs->Add(hERT1);
1926       delete h1;
1927       delete h0;
1928       if (hERT1 != hERT1orig)
1929         delete hERT1orig;
1930     }  /////////////////////////////////////////////////////////////////////////
1931     hs->Draw("LPE1 nostack");
1932     cHB->Update();  // activate the axes
1933     hs->GetXaxis()->SetTitle("<A> per LS: black-P1, red-P2,green-M1,blue-M2");
1934     hs->Draw("LPE1 nostack");
1935     gPad->SetGridy();
1936     /////////////////////////////////////////////////////////////////////////////////////////
1937 
1938     // AZ corrections 08.02.2016
1939     cHB->cd(2);
1940     TH1F *diff = new TH1F("diff", "", 100, 0., 4.);
1941 
1942     if (int(hV.size()) == specCountA) {
1943       flagErrAB_HB[0] = 0;  // If we have the expected number of histograms, set the flag
1944       double sumdelta = 0.;
1945       int nnndelta = 0;
1946       for (int ibin = 1; ibin <= hV[0]->GetNbinsX(); ibin++) {
1947         double delta = 0.;
1948         double maxdelta = 0.;
1949         for (unsigned int i = 0; i < hV.size(); i++) {
1950           const TH1F *hi = hV[i];
1951           for (unsigned int j = 1; j < hV.size(); j++) {
1952             const TH1F *hj = hV[j];
1953             delta = fabs(hi->GetBinContent(ibin) - hj->GetBinContent(ibin));
1954             if (delta > maxdelta)
1955               maxdelta = delta;
1956           }  //for
1957         }    //for
1958         if (maxdelta > 0.) {
1959           diff->Fill(maxdelta);
1960           sumdelta += maxdelta;
1961           nnndelta++;
1962         }
1963       }  //for ibin
1964       //      avedelta_HB = sumdelta/hV[0]->GetNbinsX();
1965       avedelta_HB = sumdelta / nnndelta;
1966       std::cout << "******************>>>>>>      ErrA_HB:  avedelta_HB = " << avedelta_HB << std::endl;
1967       if (avedelta_HB > 0.24 || (avedelta_HB < 0.14 && avedelta_HB > 0.)) {
1968         flagErrAB_HB[0] = 1;
1969       }  //if
1970     }    //hV.size
1971     diff->SetMarkerStyle(20);
1972     diff->SetMarkerSize(0.8);
1973     diff->SetXTitle("max difference \b");
1974     diff->SetMarkerColor(2);
1975     diff->SetLineColor(0);
1976     gPad->SetGridx();
1977     gPad->SetLogy();
1978     diff->Draw("Error");
1979     /////////////////////////////////////////////////////////////////////////
1980     cHB->Update();
1981     cHB->Print("HistErrA_HB.png");
1982     cHB->Clear();
1983     /////////////////////////////////////////////////////////////////////////
1984 
1985     // clean-up
1986     if (diff)
1987       delete diff;
1988     for (unsigned int i = 0; i < hV.size(); i++)
1989       delete hV[i];
1990   }  // ErrorA in HB
1991 
1992   ///////////////////////////////////////////////////////////////////////// errors B:
1993 
1994   {  // errors type B
1995     const int specCountB = 4;
1996     const TString hnames[specCountB][2] = {{"h_2DsumErrorBLS1", "h_2D0sumErrorBLS1"},
1997                                            {"h_sumErrorBperLS1", "h_sum0ErrorBperLS1"},
1998                                            {"h_2DsumErrorBLS2", "h_2D0sumErrorBLS2"},
1999                                            {"h_sumErrorBperLS2", "h_sum0ErrorBperLS2"}};
2000 
2001     for (int depth = 1; depth <= 2; depth++) {
2002       cHB->Clear();
2003       cHB->Divide(2, 1);
2004       cHB->cd(1);
2005 
2006       TH1F *hRate2orig = NULL;
2007       TH2F *h2Cefz6 = NULL;
2008       TString hname1 = hnames[2 * depth - 2][0];
2009       TString hname0 = hnames[2 * depth - 2][1];
2010       TH2F *twod1 = (TH2F *)dir->FindObjectAny(hname1);
2011       TH2F *twod0 = (TH2F *)dir->FindObjectAny(hname0);
2012       if (1)
2013         std::cout << "debugger: errB_HB depth=" << depth << ". get 2D histos " << hname1 << " and " << hname0 << "\n";
2014       if (!twod1 || !twod0) {
2015         TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
2016         ptext->AddText("Missing histos");
2017         if (!twod1) {
2018           std::cout << "\tfailed to get " << hname1 << "\n";
2019           ptext->AddText(hname1);
2020         }
2021         if (!twod0) {
2022           std::cout << "\tfailed to get " << hname0 << "\n";
2023           ptext->AddText(hname0);
2024         }
2025         ptext->Draw();
2026       } else {
2027         h2Cefz6 = (TH2F *)twod1->Clone(Form("Cefz6_%d", depth));
2028         h2Cefz6->SetTitle(Form("HB Depth %d \b", depth));
2029         h2Cefz6->Divide(twod1, twod0, 1, 1, "B");
2030 
2031         gPad->SetGridy();
2032         gPad->SetGridx();
2033         gPad->SetLogz();
2034         h2Cefz6->SetTitle(Form("Depth %d \b", depth));
2035         h2Cefz6->SetMarkerStyle(20);
2036         h2Cefz6->SetMarkerSize(0.4);
2037         //  h2Cefz6->GetZaxis()->SetLabelSize(0.04);
2038         h2Cefz6->SetXTitle("#eta \b");
2039         h2Cefz6->SetYTitle("#phi \b");
2040         h2Cefz6->SetZTitle(Form("<ErrorB>  - HB Depth%d \b", depth));
2041         h2Cefz6->SetMarkerColor(2);
2042         h2Cefz6->SetLineColor(2);
2043         h2Cefz6->Draw("COLZ");
2044 
2045         delete twod1;
2046         delete twod0;
2047       }  // histos ok
2048 
2049       cHB->cd(2);
2050       hname1 = hnames[2 * depth - 1][0];
2051       hname0 = hnames[2 * depth - 1][1];
2052       TH1F *h1 = (TH1F *)dir->FindObjectAny(hname1);
2053       TH1F *h0 = (TH1F *)dir->FindObjectAny(hname0);
2054       if (1)
2055         std::cout << "errB_HB depth=" << depth << ". get 2D histos " << hname1 << " and " << hname0 << "\n";
2056       if (!h1 || !h0) {
2057         TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
2058         ptext->AddText("Missing histo");
2059         if (!h1) {
2060           std::cout << "\tfailed to get " << hname1 << "\n";
2061           ptext->AddText(hname1);
2062         }
2063         if (!h0) {
2064           std::cout << "\tfailed to get " << hname0 << "\n";
2065           ptext->AddText(hname0);
2066         }
2067         ptext->Draw();
2068       } else {
2069         gPad->SetGridx();
2070         gPad->SetGridy();
2071         //  gPad->SetLogy();
2072         hRate2orig = (TH1F *)h1->Clone(Form("Rate2orig_%d", depth));
2073         hRate2orig->Divide(h1, h0, 1, 1, "B");
2074 
2075         TH1F *hRate2 = NULL;
2076         if (lastLumiBin_HB > 1) {
2077           if (!copyContents(&hRate2, Form("Rate2_%d", depth), "", hRate2orig, lastLumiBin_HB)) {
2078             std::cout << "code failed" << std::endl;
2079             gSystem->Exit(1);
2080           }
2081         } else
2082           hRate2 = hRate2orig;
2083 
2084         hRate2->SetTitle(Form("Depth %d \b", depth));
2085         hRate2->SetMarkerStyle(20);
2086         hRate2->SetMarkerSize(0.8);
2087         //  hRate2->GetZaxis()->SetLabelSize(0.04);
2088         hRate2->SetXTitle(Form("<ErrorB>(ev.in LS & ch.) - HB depth%d -    iLS \b", depth));
2089         hRate2->SetMarkerColor(2);
2090         hRate2->SetLineColor(0);
2091         hRate2->Draw("Error");
2092 
2093         if (LSofFirstErrB_HB == -1) {
2094           int nx = hRate2->GetXaxis()->GetNbins();
2095           for (int i = 1; i <= nx; i++) {
2096             double ccc1 = hRate2->GetBinContent(i);
2097             if (ccc1 > 0.) {
2098               cout << "****************>>>>>>>>>>> ErrB_HB bad LS start at iLS = " << i << " with rate = " << ccc1
2099                    << endl;
2100               LSofFirstErrB_HB = i;
2101               break;
2102             }
2103           }
2104         }
2105 
2106         delete h1;
2107         delete h0;
2108         if (hRate2 != hRate2orig) {
2109           delete hRate2orig;
2110           hRate2orig = hRate2;
2111         }
2112       }
2113 
2114       cHB->Update();
2115       cHB->Print(Form("HistErrB_HB_%d.png", depth));
2116       cHB->Clear();
2117       if (h2Cefz6)
2118         delete h2Cefz6;
2119       if (hRate2orig)
2120         delete hRate2orig;
2121     }
2122   }  // ErrorsB in HB
2123 
2124   //====================================================================== HE                    :
2125   //====================================================================== HE                    :
2126   //====================================================================== HE                    :
2127   // Special test of errors type A and B in HE
2128   // AZ 08.02.2016
2129 
2130   int flagErrAB_HE[2];
2131   flagErrAB_HE[0] = -1;
2132   flagErrAB_HE[1] = -1;
2133   double avedelta_HE = 0.;
2134   int lastLumiBin_HE = -1;
2135   int LSofFirstErrB_HE = -1;
2136   {
2137     const int specCountA = 4;
2138     const int specColors[specCountA] = {1, 2, 3, 4};
2139     const TString hnames[specCountA][2] = {{"h_sumADCAmplperLS3_P1", "h_sum0ADCAmplperLS3_P1"},
2140                                            {"h_sumADCAmplperLS3_P2", "h_sum0ADCAmplperLS3_P2"},
2141                                            {"h_sumADCAmplperLS3_M1", "h_sum0ADCAmplperLS3_M1"},
2142                                            {"h_sumADCAmplperLS3_M2", "h_sum0ADCAmplperLS3_M2"}};
2143 
2144     std::vector<TH1F *> hV;
2145     THStack *hs = new THStack("hs", "ADCAmplerLS1");
2146     cHB->Clear();
2147     //    cHB->cd();
2148     cHB->Divide(2, 1);
2149     cHB->cd(1);
2150 
2151     ///////////////////////////////////////////////////////////////////////////
2152     for (int i = 0; i < specCountA; i++) {
2153       if (1)
2154         std::cout << "debugger: errA_HE : get histos for i=" << i << " " << hnames[i][0] << " and " << hnames[i][1]
2155                   << "\n";
2156       TH1F *h1 = (TH1F *)dir->FindObjectAny(hnames[i][0]);
2157       TH1F *h0 = (TH1F *)dir->FindObjectAny(hnames[i][1]);
2158       if (!h1 || !h0) {
2159         TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
2160         ptext->AddText("Missing histo");
2161         if (!h1) {
2162           std::cout << "\tfailed to get " << hnames[i][0] << "\n";
2163           ptext->AddText(hnames[i][0]);
2164         }
2165         if (!h0) {
2166           std::cout << "\tfailed to get " << hnames[i][1] << "\n";
2167           ptext->AddText(hnames[i][1]);
2168         }
2169         ptext->Draw();
2170         continue;
2171       }
2172       TH1F *hERT1orig = (TH1F *)h1->Clone(Form("ERT1orig_%d", i));
2173       hERT1orig->Divide(h1, h0, 1, 1, "B");
2174 
2175       if ((lastLumiBin_HE < 0) && (i == 0)) {
2176         for (int ibin = hERT1orig->GetNbinsX(); ibin >= 1; ibin--) {
2177           if (hERT1orig->GetBinContent(ibin) == 0)
2178             lastLumiBin_HE = ibin;
2179           else
2180             break;
2181         }
2182         lastLumiBin_HE += 3;  // show more bins
2183         if (lastLumiBin_HE >= hERT1orig->GetNbinsX())
2184           lastLumiBin_HE = -1;
2185       }
2186       TH1F *hERT1 = NULL;
2187       if (lastLumiBin_HE > 1) {
2188         if (!copyContents(&hERT1, Form("ERT1_%d", i), "", hERT1orig, lastLumiBin_HE)) {
2189           std::cout << "code failed" << std::endl;
2190           gSystem->Exit(1);
2191         }
2192       } else
2193         hERT1 = hERT1orig;
2194 
2195       hERT1->GetXaxis()->SetTitle("<ADCAmpl> per LS HE: black-P1, red-P2,green-M1,blue-M2");
2196       hV.push_back(hERT1);
2197       hERT1->SetMarkerStyle(20);
2198       hERT1->SetMarkerSize(0.4);
2199       hERT1->SetXTitle("<A>(ev.in LS & ch.) - HE P1     -    iLS \b");
2200       hERT1->SetMarkerColor(specColors[i]);
2201       hERT1->SetLineColor(0);
2202       hs->Add(hERT1);
2203       delete h1;
2204       delete h0;
2205       if (hERT1 != hERT1orig)
2206         delete hERT1orig;
2207     }  /////////////////////////////////////////////////////////////////////////
2208     hs->Draw("LPE1 nostack");
2209     cHB->Update();  // activate the axes
2210     hs->GetXaxis()->SetTitle("<A> per LS: black-P1, red-P2,green-M1,blue-M2");
2211     hs->Draw("LPE1 nostack");
2212     gPad->SetGridy();
2213     /////////////////////////////////////////////////////////////////////////////////////////
2214 
2215     // AZ corrections 08.02.2016
2216     cHB->cd(2);
2217     TH1F *diff = new TH1F("diff", "", 100, 0., 4.);
2218 
2219     if (int(hV.size()) == specCountA) {
2220       flagErrAB_HE[0] = 0;  // If we have the expected number of histograms, set the flag
2221       double sumdelta = 0.;
2222       int nnndelta = 0;
2223       for (int ibin = 1; ibin <= hV[0]->GetNbinsX(); ibin++) {
2224         double delta = 0.;
2225         double maxdelta = 0.;
2226         for (unsigned int i = 0; i < hV.size(); i++) {
2227           const TH1F *hi = hV[i];
2228           for (unsigned int j = 1; j < hV.size(); j++) {
2229             const TH1F *hj = hV[j];
2230             delta = fabs(hi->GetBinContent(ibin) - hj->GetBinContent(ibin));
2231             if (delta > maxdelta)
2232               maxdelta = delta;
2233           }  //for
2234         }    //for
2235         if (maxdelta > 0.) {
2236           diff->Fill(maxdelta);
2237           sumdelta += maxdelta;
2238           nnndelta++;
2239         }
2240       }  //for ibin
2241       //      avedelta_HE = sumdelta/hV[0]->GetNbinsX();
2242       avedelta_HE = sumdelta / nnndelta;
2243       std::cout << "******************>>>>>>      ErrA_HE:  avedelta_HE = " << avedelta_HE << std::endl;
2244       if (avedelta_HE > 1.1 || (avedelta_HE < 0.5 && avedelta_HE > 0.)) {
2245         flagErrAB_HE[0] = 1;
2246       }  //if
2247     }    //hV.size
2248     diff->SetMarkerStyle(20);
2249     diff->SetMarkerSize(0.8);
2250     diff->SetXTitle("max difference \b");
2251     diff->SetMarkerColor(2);
2252     diff->SetLineColor(0);
2253     gPad->SetGridx();
2254     gPad->SetLogy();
2255     diff->Draw("Error");
2256     /////////////////////////////////////////////////////////////////////////
2257     cHB->Update();
2258     cHB->Print("HistErrA_HE.png");
2259     cHB->Clear();
2260     /////////////////////////////////////////////////////////////////////////
2261 
2262     // clean-up
2263     if (diff)
2264       delete diff;
2265     for (unsigned int i = 0; i < hV.size(); i++)
2266       delete hV[i];
2267   }  // ErrorA in HE
2268 
2269   ///////////////////////////////////////////////////////////////////////// errors B:
2270 
2271   {  // errors type B
2272     const int specCountB = 6;
2273     const TString hnames[specCountB][2] = {{"h_2DsumErrorBLS3", "h_2D0sumErrorBLS3"},
2274                                            {"h_sumErrorBperLS3", "h_sum0ErrorBperLS3"},
2275                                            {"h_2DsumErrorBLS4", "h_2D0sumErrorBLS4"},
2276                                            {"h_sumErrorBperLS4", "h_sum0ErrorBperLS4"},
2277                                            {"h_2DsumErrorBLS5", "h_2D0sumErrorBLS5"},
2278                                            {"h_sumErrorBperLS5", "h_sum0ErrorBperLS5"}};
2279 
2280     for (int depth = 1; depth <= 3; depth++) {
2281       cHB->Clear();
2282       cHB->Divide(2, 1);
2283       cHB->cd(1);
2284 
2285       TH1F *hRate2orig = NULL;
2286       TH2F *h2Cefz6 = NULL;
2287       TString hname1 = hnames[2 * depth - 2][0];
2288       TString hname0 = hnames[2 * depth - 2][1];
2289       TH2F *twod1 = (TH2F *)dir->FindObjectAny(hname1);
2290       TH2F *twod0 = (TH2F *)dir->FindObjectAny(hname0);
2291       if (1)
2292         std::cout << "debugger: errB_HE depth=" << depth << ". get 2D histos " << hname1 << " and " << hname0 << "\n";
2293       if (!twod1 || !twod0) {
2294         TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
2295         ptext->AddText("Missing histos");
2296         if (!twod1) {
2297           std::cout << "\tfailed to get " << hname1 << "\n";
2298           ptext->AddText(hname1);
2299         }
2300         if (!twod0) {
2301           std::cout << "\tfailed to get " << hname0 << "\n";
2302           ptext->AddText(hname0);
2303         }
2304         ptext->Draw();
2305       } else {
2306         h2Cefz6 = (TH2F *)twod1->Clone(Form("Cefz6_%d", depth));
2307         h2Cefz6->SetTitle(Form("HE Depth %d \b", depth));
2308         h2Cefz6->Divide(twod1, twod0, 1, 1, "B");
2309 
2310         gPad->SetGridy();
2311         gPad->SetGridx();
2312         gPad->SetLogz();
2313         h2Cefz6->SetTitle(Form("Depth %d \b", depth));
2314         h2Cefz6->SetMarkerStyle(20);
2315         h2Cefz6->SetMarkerSize(0.4);
2316         //  h2Cefz6->GetZaxis()->SetLabelSize(0.04);
2317         h2Cefz6->SetXTitle("#eta \b");
2318         h2Cefz6->SetYTitle("#phi \b");
2319         h2Cefz6->SetZTitle(Form("<ErrorB>  - HE Depth%d \b", depth));
2320         h2Cefz6->SetMarkerColor(2);
2321         h2Cefz6->SetLineColor(2);
2322         h2Cefz6->Draw("COLZ");
2323 
2324         delete twod1;
2325         delete twod0;
2326       }  // histos ok
2327 
2328       cHB->cd(2);
2329       hname1 = hnames[2 * depth - 1][0];
2330       hname0 = hnames[2 * depth - 1][1];
2331       TH1F *h1 = (TH1F *)dir->FindObjectAny(hname1);
2332       TH1F *h0 = (TH1F *)dir->FindObjectAny(hname0);
2333       if (1)
2334         std::cout << "errB_HE depth=" << depth << ". get 2D histos " << hname1 << " and " << hname0 << "\n";
2335       if (!h1 || !h0) {
2336         TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
2337         ptext->AddText("Missing histo");
2338         if (!h1) {
2339           std::cout << "\tfailed to get " << hname1 << "\n";
2340           ptext->AddText(hname1);
2341         }
2342         if (!h0) {
2343           std::cout << "\tfailed to get " << hname0 << "\n";
2344           ptext->AddText(hname0);
2345         }
2346         ptext->Draw();
2347       } else {
2348         gPad->SetGridx();
2349         gPad->SetGridy();
2350         //  gPad->SetLogy();
2351         hRate2orig = (TH1F *)h1->Clone(Form("Rate2orig_%d", depth));
2352         hRate2orig->Divide(h1, h0, 1, 1, "B");
2353 
2354         TH1F *hRate2 = NULL;
2355         if (lastLumiBin_HE > 1) {
2356           if (!copyContents(&hRate2, Form("Rate2_%d", depth), "", hRate2orig, lastLumiBin_HE)) {
2357             std::cout << "code failed" << std::endl;
2358             gSystem->Exit(1);
2359           }
2360         } else
2361           hRate2 = hRate2orig;
2362 
2363         hRate2->SetTitle(Form("Depth %d \b", depth));
2364         hRate2->SetMarkerStyle(20);
2365         hRate2->SetMarkerSize(0.8);
2366         //  hRate2->GetZaxis()->SetLabelSize(0.04);
2367         hRate2->SetXTitle(Form("<ErrorB>(ev.in LS & ch.) - HE depth%d -    iLS \b", depth));
2368         hRate2->SetMarkerColor(2);
2369         hRate2->SetLineColor(0);
2370         hRate2->Draw("Error");
2371 
2372         if (LSofFirstErrB_HE == -1) {
2373           int nx = hRate2->GetXaxis()->GetNbins();
2374           for (int i = 1; i <= nx; i++) {
2375             double ccc1 = hRate2->GetBinContent(i);
2376             if (ccc1 > 0.) {
2377               cout << "****************>>>>>>>>>>> ErrB_HE bad LS start at iLS = " << i << " with rate = " << ccc1
2378                    << endl;
2379               LSofFirstErrB_HE = i;
2380               break;
2381             }
2382           }
2383         }
2384 
2385         delete h1;
2386         delete h0;
2387         if (hRate2 != hRate2orig) {
2388           delete hRate2orig;
2389           hRate2orig = hRate2;
2390         }
2391       }
2392 
2393       cHB->Update();
2394       cHB->Print(Form("HistErrB_HE_%d.png", depth));
2395       cHB->Clear();
2396       if (h2Cefz6)
2397         delete h2Cefz6;
2398       if (hRate2orig)
2399         delete hRate2orig;
2400     }
2401   }  // ErrorsB in HE
2402 
2403   //====================================================================== HO                    :
2404   //====================================================================== HO                    :
2405   //====================================================================== HO                    :
2406   // Special test of errors type A and B in HO
2407   // AZ 08.02.2016
2408 
2409   int flagErrAB_HO[2];
2410   flagErrAB_HO[0] = -1;
2411   flagErrAB_HO[1] = -1;
2412   double avedelta_HO = 0.;
2413   int lastLumiBin_HO = -1;
2414   int LSofFirstErrB_HO = -1;
2415   {
2416     const int specCountA = 4;
2417     const int specColors[specCountA] = {1, 2, 3, 4};
2418     const TString hnames[specCountA][2] = {{"h_sumADCAmplperLS8_P1", "h_sum0ADCAmplperLS8_P1"},
2419                                            {"h_sumADCAmplperLS8_P2", "h_sum0ADCAmplperLS8_P2"},
2420                                            {"h_sumADCAmplperLS8_M1", "h_sum0ADCAmplperLS8_M1"},
2421                                            {"h_sumADCAmplperLS8_M2", "h_sum0ADCAmplperLS8_M2"}};
2422 
2423     std::vector<TH1F *> hV;
2424     THStack *hs = new THStack("hs", "ADCAmplerLS1");
2425     cHB->Clear();
2426     //    cHB->cd();
2427     cHB->Divide(2, 1);
2428     cHB->cd(1);
2429 
2430     ///////////////////////////////////////////////////////////////////////////
2431     for (int i = 0; i < specCountA; i++) {
2432       if (1)
2433         std::cout << "debugger: errA_HO : get histos for i=" << i << " " << hnames[i][0] << " and " << hnames[i][1]
2434                   << "\n";
2435       TH1F *h1 = (TH1F *)dir->FindObjectAny(hnames[i][0]);
2436       TH1F *h0 = (TH1F *)dir->FindObjectAny(hnames[i][1]);
2437       if (!h1 || !h0) {
2438         TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
2439         ptext->AddText("Missing histo");
2440         if (!h1) {
2441           std::cout << "\tfailed to get " << hnames[i][0] << "\n";
2442           ptext->AddText(hnames[i][0]);
2443         }
2444         if (!h0) {
2445           std::cout << "\tfailed to get " << hnames[i][1] << "\n";
2446           ptext->AddText(hnames[i][1]);
2447         }
2448         ptext->Draw();
2449         continue;
2450       }
2451       TH1F *hoRT1orig = (TH1F *)h1->Clone(Form("ERT1orig_%d", i));
2452       hoRT1orig->Divide(h1, h0, 1, 1, "B");
2453 
2454       if ((lastLumiBin_HO < 0) && (i == 0)) {
2455         for (int ibin = hoRT1orig->GetNbinsX(); ibin >= 1; ibin--) {
2456           if (hoRT1orig->GetBinContent(ibin) == 0)
2457             lastLumiBin_HO = ibin;
2458           else
2459             break;
2460         }
2461         lastLumiBin_HO += 3;  // show more bins
2462         if (lastLumiBin_HO >= hoRT1orig->GetNbinsX())
2463           lastLumiBin_HO = -1;
2464       }
2465       TH1F *hoRT1 = NULL;
2466       if (lastLumiBin_HO > 1) {
2467         if (!copyContents(&hoRT1, Form("ERT1_%d", i), "", hoRT1orig, lastLumiBin_HO)) {
2468           std::cout << "code failed" << std::endl;
2469           gSystem->Exit(1);
2470         }
2471       } else
2472         hoRT1 = hoRT1orig;
2473 
2474       hoRT1->GetXaxis()->SetTitle("<ADCAmpl> per LS HO: black-P1, red-P2,green-M1,blue-M2");
2475       hV.push_back(hoRT1);
2476       hoRT1->SetMarkerStyle(20);
2477       hoRT1->SetMarkerSize(0.4);
2478       hoRT1->SetXTitle("<A>(ev.in LS & ch.) - HO P1     -    iLS \b");
2479       hoRT1->SetMarkerColor(specColors[i]);
2480       hoRT1->SetLineColor(0);
2481       hs->Add(hoRT1);
2482       delete h1;
2483       delete h0;
2484       if (hoRT1 != hoRT1orig)
2485         delete hoRT1orig;
2486     }  /////////////////////////////////////////////////////////////////////////
2487     hs->Draw("LPE1 nostack");
2488     cHB->Update();  // activate tho axes
2489     hs->GetXaxis()->SetTitle("<A> per LS: black-P1, red-P2,green-M1,blue-M2");
2490     hs->Draw("LPE1 nostack");
2491     gPad->SetGridy();
2492     /////////////////////////////////////////////////////////////////////////////////////////
2493 
2494     // AZ corrections 08.02.2016
2495     cHB->cd(2);
2496     TH1F *diff = new TH1F("diff", "", 100, 0., 4.);
2497 
2498     if (int(hV.size()) == specCountA) {
2499       flagErrAB_HO[0] = 0;  // If we have tho expected number of histograms, set tho flag
2500       double sumdelta = 0.;
2501       int nnndelta = 0;
2502       for (int ibin = 1; ibin <= hV[0]->GetNbinsX(); ibin++) {
2503         double delta = 0.;
2504         double maxdelta = 0.;
2505         for (unsigned int i = 0; i < hV.size(); i++) {
2506           const TH1F *hi = hV[i];
2507           for (unsigned int j = 1; j < hV.size(); j++) {
2508             const TH1F *hj = hV[j];
2509             delta = fabs(hi->GetBinContent(ibin) - hj->GetBinContent(ibin));
2510             if (delta > maxdelta)
2511               maxdelta = delta;
2512           }  //for
2513         }    //for
2514         if (maxdelta > 0.) {
2515           diff->Fill(maxdelta);
2516           sumdelta += maxdelta;
2517           nnndelta++;
2518         }
2519       }  //for ibin
2520       //      avedelta_HO = sumdelta/hV[0]->GetNbinsX();
2521       avedelta_HO = sumdelta / nnndelta;
2522       std::cout << "******************>>>>>>      ErrA_HO:  avedelta_HO = " << avedelta_HO << std::endl;
2523       if (avedelta_HO > 0.8 || (avedelta_HO < 0.2 && avedelta_HO > 0.)) {
2524         flagErrAB_HO[0] = 1;
2525       }  //if
2526     }    //hV.size
2527     diff->SetMarkerStyle(20);
2528     diff->SetMarkerSize(0.8);
2529     diff->SetXTitle("max difference \b");
2530     diff->SetMarkerColor(2);
2531     diff->SetLineColor(0);
2532     gPad->SetGridx();
2533     gPad->SetLogy();
2534     diff->Draw("Error");
2535     /////////////////////////////////////////////////////////////////////////
2536     cHB->Update();
2537     cHB->Print("HistErrA_HO.png");
2538     cHB->Clear();
2539     /////////////////////////////////////////////////////////////////////////
2540 
2541     // clean-up
2542     if (diff)
2543       delete diff;
2544     for (unsigned int i = 0; i < hV.size(); i++)
2545       delete hV[i];
2546   }  // ErrorA in HO
2547 
2548   ///////////////////////////////////////////////////////////////////////// errors B:
2549 
2550   {  // errors type B
2551     const int specCountB = 2;
2552     const TString hnames[specCountB][2] = {{"h_2DsumErrorBLS8", "h_2D0sumErrorBLS8"},
2553                                            {"h_sumErrorBperLS8", "h_sum0ErrorBperLS8"}};
2554 
2555     for (int depth = 4; depth <= 4; depth++) {
2556       cHB->Clear();
2557       cHB->Divide(2, 1);
2558       cHB->cd(1);
2559 
2560       TH1F *hRate2orig = NULL;
2561       TH2F *h2Cefz6 = NULL;
2562       TString hname1 = hnames[2 * depth - 8][0];
2563       TString hname0 = hnames[2 * depth - 8][1];
2564       TH2F *twod1 = (TH2F *)dir->FindObjectAny(hname1);
2565       TH2F *twod0 = (TH2F *)dir->FindObjectAny(hname0);
2566       if (1)
2567         std::cout << "debugger: errB_HO depth=" << depth << ". get 2D histos " << hname1 << " and " << hname0 << "\n";
2568       if (!twod1 || !twod0) {
2569         TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
2570         ptext->AddText("Missing histos");
2571         if (!twod1) {
2572           std::cout << "\tfailed to get " << hname1 << "\n";
2573           ptext->AddText(hname1);
2574         }
2575         if (!twod0) {
2576           std::cout << "\tfailed to get " << hname0 << "\n";
2577           ptext->AddText(hname0);
2578         }
2579         ptext->Draw();
2580       } else {
2581         h2Cefz6 = (TH2F *)twod1->Clone(Form("Cefz6_%d", depth));
2582         h2Cefz6->SetTitle(Form("HO Depth %d \b", depth));
2583         h2Cefz6->Divide(twod1, twod0, 1, 1, "B");
2584 
2585         gPad->SetGridy();
2586         gPad->SetGridx();
2587         gPad->SetLogz();
2588         h2Cefz6->SetTitle(Form("Depth %d \b", depth));
2589         h2Cefz6->SetMarkerStyle(20);
2590         h2Cefz6->SetMarkerSize(0.4);
2591         //  h2Cefz6->GetZaxis()->SetLabelSize(0.04);
2592         h2Cefz6->SetXTitle("#eta \b");
2593         h2Cefz6->SetYTitle("#phi \b");
2594         h2Cefz6->SetZTitle(Form("<ErrorB>  - HO Depth%d \b", depth));
2595         h2Cefz6->SetMarkerColor(2);
2596         h2Cefz6->SetLineColor(2);
2597         h2Cefz6->Draw("COLZ");
2598 
2599         delete twod1;
2600         delete twod0;
2601       }  // histos ok
2602 
2603       cHB->cd(2);
2604       hname1 = hnames[2 * depth - 7][0];
2605       hname0 = hnames[2 * depth - 7][1];
2606       TH1F *h1 = (TH1F *)dir->FindObjectAny(hname1);
2607       TH1F *h0 = (TH1F *)dir->FindObjectAny(hname0);
2608       if (1)
2609         std::cout << "errB_HO depth=" << depth << ". get 2D histos " << hname1 << " and " << hname0 << "\n";
2610       if (!h1 || !h0) {
2611         TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
2612         ptext->AddText("Missing histo");
2613         if (!h1) {
2614           std::cout << "\tfailed to get " << hname1 << "\n";
2615           ptext->AddText(hname1);
2616         }
2617         if (!h0) {
2618           std::cout << "\tfailed to get " << hname0 << "\n";
2619           ptext->AddText(hname0);
2620         }
2621         ptext->Draw();
2622       } else {
2623         gPad->SetGridx();
2624         gPad->SetGridy();
2625         //  gPad->SetLogy();
2626         hRate2orig = (TH1F *)h1->Clone(Form("Rate2orig_%d", depth));
2627         hRate2orig->Divide(h1, h0, 1, 1, "B");
2628 
2629         TH1F *hRate2 = NULL;
2630         if (lastLumiBin_HO > 1) {
2631           if (!copyContents(&hRate2, Form("Rate2_%d", depth), "", hRate2orig, lastLumiBin_HO)) {
2632             std::cout << "code failed" << std::endl;
2633             gSystem->Exit(1);
2634           }
2635         } else
2636           hRate2 = hRate2orig;
2637 
2638         hRate2->SetTitle(Form("Depth %d \b", depth));
2639         hRate2->SetMarkerStyle(20);
2640         hRate2->SetMarkerSize(0.8);
2641         //  hRate2->GetZaxis()->SetLabelSize(0.04);
2642         hRate2->SetXTitle(Form("<ErrorB>(ev.in LS & ch.) - HO depth%d -    iLS \b", depth));
2643         hRate2->SetMarkerColor(2);
2644         hRate2->SetLineColor(0);
2645         hRate2->Draw("Error");
2646 
2647         if (LSofFirstErrB_HO == -1) {
2648           int nx = hRate2->GetXaxis()->GetNbins();
2649           for (int i = 1; i <= nx; i++) {
2650             double ccc1 = hRate2->GetBinContent(i);
2651             if (ccc1 > 0.) {
2652               cout << "****************>>>>>>>>>>> ErrB_HO bad LS start at iLS = " << i << " with rate = " << ccc1
2653                    << endl;
2654               LSofFirstErrB_HO = i;
2655               break;
2656             }
2657           }
2658         }
2659 
2660         delete h1;
2661         delete h0;
2662         if (hRate2 != hRate2orig) {
2663           delete hRate2orig;
2664           hRate2orig = hRate2;
2665         }
2666       }
2667 
2668       cHB->Update();
2669       cHB->Print(Form("HistErrB_HO_%d.png", depth));
2670       cHB->Clear();
2671       if (h2Cefz6)
2672         delete h2Cefz6;
2673       if (hRate2orig)
2674         delete hRate2orig;
2675     }
2676   }  // ErrorsB in HO
2677 
2678   //====================================================================== done by Andrius for HF:
2679   //====================================================================== done by Andrius for HF:
2680   //====================================================================== done by Andrius for HF:
2681   // Special test of errors type A and B in HF
2682 
2683   int flagErrAB_HF[2];
2684   flagErrAB_HF[0] = -1;
2685   flagErrAB_HF[1] = -1;
2686   double avedelta_HF = 0.;
2687   int lastLumiBin_HF = -1;
2688   int LSofFirstErrB_HF = -1;
2689   {
2690     const int specCountA = 4;
2691     const int specColors[specCountA] = {1, 2, 3, 4};
2692     const TString hnames[specCountA][2] = {{"h_sumADCAmplperLS6_P1", "h_sum0ADCAmplperLS6_P1"},
2693                                            {"h_sumADCAmplperLS6_P2", "h_sum0ADCAmplperLS6_P2"},
2694                                            {"h_sumADCAmplperLS6_M1", "h_sum0ADCAmplperLS6_M1"},
2695                                            {"h_sumADCAmplperLS6_M2", "h_sum0ADCAmplperLS6_M2"}};
2696 
2697     std::vector<TH1F *> hV;
2698     THStack *hs = new THStack("hs", "ADCAmplerLS6");
2699     cHB->Clear();
2700     //    cHB->cd();
2701     cHB->Divide(2, 1);
2702     cHB->cd(1);
2703 
2704     ///////////////////////////////////////////////////////////////////////////
2705     for (int i = 0; i < specCountA; i++) {
2706       if (1)
2707         std::cout << "debugger: errA_HF : get histos for i=" << i << " " << hnames[i][0] << " and " << hnames[i][1]
2708                   << "\n";
2709       TH1F *h1 = (TH1F *)dir->FindObjectAny(hnames[i][0]);
2710       TH1F *h0 = (TH1F *)dir->FindObjectAny(hnames[i][1]);
2711       if (!h1 || !h0) {
2712         TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
2713         ptext->AddText("Missing histo");
2714         if (!h1) {
2715           std::cout << "\tfailed to get " << hnames[i][0] << "\n";
2716           ptext->AddText(hnames[i][0]);
2717         }
2718         if (!h0) {
2719           std::cout << "\tfailed to get " << hnames[i][1] << "\n";
2720           ptext->AddText(hnames[i][1]);
2721         }
2722         ptext->Draw();
2723         continue;
2724       }
2725       TH1F *hERT1orig = (TH1F *)h1->Clone(Form("ERT1orig_%d", i));
2726       hERT1orig->Divide(h1, h0, 1, 1, "B");
2727 
2728       if ((lastLumiBin_HF < 0) && (i == 0)) {
2729         for (int ibin = hERT1orig->GetNbinsX(); ibin >= 1; ibin--) {
2730           if (hERT1orig->GetBinContent(ibin) == 0)
2731             lastLumiBin_HF = ibin;
2732           else
2733             break;
2734         }
2735         lastLumiBin_HF += 3;  // show more bins
2736         if (lastLumiBin_HF >= hERT1orig->GetNbinsX())
2737           lastLumiBin_HF = -1;
2738       }
2739       TH1F *hERT1 = NULL;
2740       if (lastLumiBin_HF > 1) {
2741         if (!copyContents(&hERT1, Form("ERT1_%d", i), "", hERT1orig, lastLumiBin_HF)) {
2742           std::cout << "code failed" << std::endl;
2743           gSystem->Exit(1);
2744         }
2745       } else
2746         hERT1 = hERT1orig;
2747 
2748       hERT1->GetXaxis()->SetTitle("<ADCAmpl> per LS HF: black-P1, red-P2,green-M1,blue-M2");
2749       hV.push_back(hERT1);
2750       hERT1->SetMarkerStyle(20);
2751       hERT1->SetMarkerSize(0.4);
2752       hERT1->SetXTitle("<A>(ev.in LS & ch.) - HF P1     -    iLS \b");
2753       hERT1->SetMarkerColor(specColors[i]);
2754       hERT1->SetLineColor(0);
2755       hs->Add(hERT1);
2756       delete h1;
2757       delete h0;
2758       if (hERT1 != hERT1orig)
2759         delete hERT1orig;
2760     }  /////////////////////////////////////////////////////////////////////////
2761     hs->Draw("LPE1 nostack");
2762     cHB->Update();  // activate the axes
2763     hs->GetXaxis()->SetTitle("<A> per LS: black-P1, red-P2,green-M1,blue-M2");
2764     hs->Draw("LPE1 nostack");
2765     gPad->SetGridy();
2766     /////////////////////////////////////////////////////////////////////////////////////////
2767 
2768     // AZ corrections 04.02.2016
2769     cHB->cd(2);
2770     TH1F *diff = new TH1F("diff", "", 100, 0., 4.);
2771 
2772     if (int(hV.size()) == specCountA) {
2773       flagErrAB_HF[0] = 0;  // If we have the expected number of histograms, set the flag
2774       double sumdelta = 0.;
2775       int nnndelta = 0;
2776       std::cout << "********   GetNbinsX  = " << hV[0]->GetNbinsX() << std::endl;
2777       for (int ibin = 1; ibin <= hV[0]->GetNbinsX(); ibin++) {
2778         double delta = 0.;
2779         double maxdelta = 0.;
2780         for (unsigned int i = 0; i < hV.size(); i++) {
2781           const TH1F *hi = hV[i];
2782           for (unsigned int j = 1; j < hV.size(); j++) {
2783             const TH1F *hj = hV[j];
2784             delta = fabs(hi->GetBinContent(ibin) - hj->GetBinContent(ibin));
2785             if (delta > maxdelta)
2786               maxdelta = delta;
2787           }  //for
2788         }    //for
2789         //  std::cout << "*****      ibin = " << ibin << " nnndelta= " << nnndelta << " maxdelta= " << maxdelta <<std::endl;
2790         if (maxdelta > 0.) {
2791           diff->Fill(maxdelta);
2792           sumdelta += maxdelta;
2793           nnndelta++;
2794         }
2795       }  //for ibin
2796       //      avedelta_HF = sumdelta/hV[0]->GetNbinsX();
2797       avedelta_HF = sumdelta / nnndelta;
2798       //      std::cout << "******************>>>>>>      ErrA_HF:  avedelta_HF = " << avedelta_HF << " Npoints for comparison= " << nnndelta <<std::endl;
2799       if (avedelta_HF > 2.4 || (avedelta_HF < 0.8 && avedelta_HF > 0.)) {
2800         flagErrAB_HF[0] = 1;
2801       }  //if
2802     }    //hV.size
2803     diff->SetMarkerStyle(20);
2804     diff->SetMarkerSize(0.8);
2805     diff->SetXTitle("max difference \b");
2806     diff->SetMarkerColor(2);
2807     diff->SetLineColor(0);
2808     gPad->SetGridx();
2809     gPad->SetLogy();
2810     diff->Draw("Error");
2811     /////////////////////////////////////////////////////////////////////////
2812     cHB->Update();
2813     cHB->Print("HistErrA_HF.png");
2814     cHB->Clear();
2815     /////////////////////////////////////////////////////////////////////////
2816     // clean-up
2817     if (diff)
2818       delete diff;
2819     for (unsigned int i = 0; i < hV.size(); i++)
2820       delete hV[i];
2821   }  // ErrorA in HF
2822   ////////////////////////////////////////////////////////// errors B:
2823   /////////////////////////
2824   {  // errors type B
2825     const int specCountB = 4;
2826     const TString hnames[specCountB][2] = {{"h_2DsumErrorBLS6", "h_2D0sumErrorBLS6"},
2827                                            {"h_sumErrorBperLS6", "h_sum0ErrorBperLS6"},
2828                                            {"h_2DsumErrorBLS7", "h_2D0sumErrorBLS7"},
2829                                            {"h_sumErrorBperLS7", "h_sum0ErrorBperLS7"}};
2830 
2831     for (int depth = 1; depth <= 2; depth++) {
2832       cHB->Clear();
2833       cHB->Divide(2, 1);
2834       cHB->cd(1);
2835       TH1F *hRate2orig = NULL;
2836       TH2F *h2Cefz6 = NULL;
2837       TString hname1 = hnames[2 * depth - 2][0];
2838       TString hname0 = hnames[2 * depth - 2][1];
2839       TH2F *twod1 = (TH2F *)dir->FindObjectAny(hname1);
2840       TH2F *twod0 = (TH2F *)dir->FindObjectAny(hname0);
2841       if (1)
2842         std::cout << "debugger: errB_HF depth=" << depth << ". get 2D histos " << hname1 << " and " << hname0 << "\n";
2843       if (!twod1 || !twod0) {
2844         TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
2845         ptext->AddText("Missing histos");
2846         if (!twod1) {
2847           std::cout << "\tfailed to get " << hname1 << "\n";
2848           ptext->AddText(hname1);
2849         }
2850         if (!twod0) {
2851           std::cout << "\tfailed to get " << hname0 << "\n";
2852           ptext->AddText(hname0);
2853         }
2854         ptext->Draw();
2855       } else {
2856         h2Cefz6 = (TH2F *)twod1->Clone(Form("Cefz6_%d", depth));
2857         h2Cefz6->SetTitle(Form("HF Depth %d \b", depth));
2858         h2Cefz6->Divide(twod1, twod0, 1, 1, "B");
2859 
2860         gPad->SetGridy();
2861         gPad->SetGridx();
2862         gPad->SetLogz();
2863         h2Cefz6->SetTitle(Form("Depth %d \b", depth));
2864         h2Cefz6->SetMarkerStyle(20);
2865         h2Cefz6->SetMarkerSize(0.4);
2866         //  h2Cefz6->GetZaxis()->SetLabelSize(0.04);
2867         h2Cefz6->SetXTitle("#eta \b");
2868         h2Cefz6->SetYTitle("#phi \b");
2869         h2Cefz6->SetZTitle(Form("<ErrorB>  - HF Depth%d \b", depth));
2870         h2Cefz6->SetMarkerColor(2);
2871         h2Cefz6->SetLineColor(2);
2872         h2Cefz6->Draw("COLZ");
2873         delete twod1;
2874         delete twod0;
2875       }  // histos ok
2876       cHB->cd(2);
2877       hname1 = hnames[2 * depth - 1][0];
2878       hname0 = hnames[2 * depth - 1][1];
2879       TH1F *h1 = (TH1F *)dir->FindObjectAny(hname1);
2880       TH1F *h0 = (TH1F *)dir->FindObjectAny(hname0);
2881       if (1)
2882         std::cout << "errB_HF depth=" << depth << ". get 2D histos " << hname1 << " and " << hname0 << "\n";
2883       if (!h1 || !h0) {
2884         TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
2885         ptext->AddText("Missing histo");
2886         if (!h1) {
2887           std::cout << "\tfailed to get " << hname1 << "\n";
2888           ptext->AddText(hname1);
2889         }
2890         if (!h0) {
2891           std::cout << "\tfailed to get " << hname0 << "\n";
2892           ptext->AddText(hname0);
2893         }
2894         ptext->Draw();
2895       } else {
2896         gPad->SetGridx();
2897         gPad->SetGridy();
2898         //  gPad->SetLogy();
2899         hRate2orig = (TH1F *)h1->Clone(Form("Rate2orig_%d", depth));
2900         hRate2orig->Divide(h1, h0, 1, 1, "B");
2901 
2902         TH1F *hRate2 = NULL;
2903         if (lastLumiBin_HF > 1) {
2904           if (!copyContents(&hRate2, Form("Rate2_%d", depth), "", hRate2orig, lastLumiBin_HF)) {
2905             std::cout << "code failed" << std::endl;
2906             gSystem->Exit(1);
2907           }
2908         } else
2909           hRate2 = hRate2orig;
2910         hRate2->SetTitle(Form("Depth %d \b", depth));
2911         hRate2->SetMarkerStyle(20);
2912         hRate2->SetMarkerSize(0.8);
2913         //  hRate2->GetZaxis()->SetLabelSize(0.04);
2914         hRate2->SetXTitle(Form("<ErrorB>(ev.in LS & ch.) - HF depth%d -    iLS \b", depth));
2915         hRate2->SetMarkerColor(2);
2916         hRate2->SetLineColor(0);
2917         hRate2->Draw("Error");
2918         if (LSofFirstErrB_HF == -1) {
2919           int nx = hRate2->GetXaxis()->GetNbins();
2920           for (int i = 1; i <= nx; i++) {
2921             double ccc1 = hRate2->GetBinContent(i);
2922             if (ccc1 > 0.) {
2923               cout << "****************>>>>>>>>>>> ErrB_HF bad LS start at iLS = " << i << " with rate = " << ccc1
2924                    << endl;
2925               LSofFirstErrB_HF = i;
2926               break;
2927             }
2928           }
2929         }
2930         delete h1;
2931         delete h0;
2932         if (hRate2 != hRate2orig) {
2933           delete hRate2orig;
2934           hRate2orig = hRate2;
2935         }
2936       }
2937       cHB->Update();
2938       cHB->Print(Form("HistErrB_HF_%d.png", depth));
2939       cHB->Clear();
2940       if (h2Cefz6)
2941         delete h2Cefz6;
2942       if (hRate2orig)
2943         delete hRate2orig;
2944     }
2945   }  // ErrorsB in HF
2946 
2947   /////////////////  Cross-check A-errors & Occupancies:
2948 
2949   //===============================================================================  err A HB
2950   /// errA with average Amplitudes
2951   // For  2D and  1D plots with Amplitude. Produces ChkErrA_HBx.png
2952 
2953   for (int depth = 1; depth <= 2; depth++) {
2954     TH2F *h2Ceff = NULL;
2955     TH2F *h2Diffe = NULL;
2956     //    TH1F* h1diffADCAmpl= NULL;
2957     TH2F *h3Ceff = NULL;
2958 
2959     cHE->Clear();
2960     cHE->Divide(3, 1);
2961 
2962     cHE->cd(1);
2963     // h_mapDepth1ADCAmpl_HB div h_mapDepth1_HB
2964     TString hname1 = Form("h_mapDepth%dADCAmpl_HB", depth);
2965     TString hname0 = Form("h_mapDepth%d_HB", depth);
2966     TH2F *twod1 = (TH2F *)dir->FindObjectAny(hname1);
2967     TH2F *twod0 = (TH2F *)dir->FindObjectAny(hname0);
2968     if (!twod1 || !twod0) {
2969       TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
2970       ptext->AddText("Missing histo");
2971       std::cout << "specHB test: failed to load " << hname1 << " and/or " << hname0 << "\n";
2972       if (!twod1)
2973         ptext->AddText(hname1);
2974       if (!twod0)
2975         ptext->AddText(hname0);
2976       ptext->Draw();
2977       continue;
2978     } else {
2979       // To IDENTIFY: see color different bins in eta-phi space
2980       h2Ceff = (TH2F *)twod1->Clone(Form("Ceff_HB%d", depth));
2981       h2Ceff->SetTitle(Form("HB Depth %d. (No cut) \b", depth));
2982       h2Ceff->Divide(twod1, twod0, 1, 1, "B");
2983 
2984       gPad->SetGridy();
2985       gPad->SetGridx();
2986       gPad->SetLogz();
2987       h2Ceff->SetMarkerStyle(20);
2988       h2Ceff->SetMarkerSize(0.4);
2989       //h2Ceff->GetZaxis()->SetLabelSize(0.08);
2990       h2Ceff->SetXTitle("#eta \b");
2991       h2Ceff->SetYTitle("#phi \b");
2992       h2Ceff->SetZTitle("h_mapDepth1ADCAmpl_HB \b");
2993       h2Ceff->SetMarkerColor(2);
2994       h2Ceff->SetLineColor(2);
2995       h2Ceff->Draw("COLZ");
2996     }
2997 
2998     cHE->cd(2);
2999     ///////////////////////////////////////
3000     if (h2Ceff) {
3001       // TO IDENTIFY: see red bins in eta-phi space
3002       h2Diffe = (TH2F *)h2Ceff->Clone(Form("Diffe_Depth%d_HB", depth));
3003       h2Diffe->SetTitle(Form("HB Depth %d. Cut avg(ADCAmpl) > 25 \b", depth));
3004       int nx = h2Ceff->GetXaxis()->GetNbins();
3005       int ny = h2Ceff->GetYaxis()->GetNbins();
3006       for (int i = 1; i <= nx; i++) {
3007         for (int j = 1; j <= ny; j++) {
3008           double ccc1 = h2Ceff->GetBinContent(i, j);
3009           h2Diffe->SetBinContent(i, j, 0.);
3010           if (ccc1 > 25.)
3011             h2Diffe->SetBinContent(i, j, ccc1);
3012         }
3013       }
3014       gPad->SetGridy();
3015       gPad->SetGridx();
3016       gPad->SetLogz();
3017       h2Diffe->SetMarkerStyle(20);
3018       h2Diffe->SetMarkerSize(0.4);
3019       //h2Diffe->GetZaxis()->SetLabelSize(0.08);
3020       h2Diffe->SetXTitle("#eta \b");
3021       h2Diffe->SetYTitle("#phi \b");
3022       h2Diffe->SetZTitle("<ADCAmpl> bigger 25.- HB Depth1 \b");
3023       h2Diffe->SetMarkerColor(2);
3024       h2Diffe->SetLineColor(2);
3025       h2Diffe->Draw("COLZ");
3026     }
3027 
3028     cHE->cd(3);
3029     TString hname3 = Form("h_mapDepth%dADCAmpl225Copy_HB", depth);
3030     TH2F *twod3 = (TH2F *)dir->FindObjectAny(hname3);
3031     if (!twod3 || !twod0) {
3032       TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
3033       ptext->AddText("Missing histo");
3034       std::cout << "specHB test: failed to load " << hname3 << " and/or " << hname0 << "\n";
3035       if (!twod3)
3036         ptext->AddText(hname3);
3037       if (!twod0)
3038         ptext->AddText(hname0);
3039       ptext->Draw();
3040       continue;
3041     } else {
3042       // To IDENTIFY: see color different bins in eta-phi space
3043       h3Ceff = (TH2F *)twod3->Clone(Form("CeffA_HB%d", depth));
3044       h3Ceff->SetTitle(Form("HB Depth %d. \b", depth));
3045       h3Ceff->Divide(twod3, twod0, 1, 1, "B");
3046       gPad->SetGridy();
3047       gPad->SetGridx();
3048       gPad->SetLogz();
3049       h3Ceff->SetMarkerStyle(20);
3050       h3Ceff->SetMarkerSize(0.4);
3051       //      h3Ceff->GetZaxis()->SetLabelSize(0.08);
3052       h3Ceff->SetXTitle("#eta \b");
3053       h3Ceff->SetYTitle("#phi \b");
3054       h3Ceff->SetZTitle("rate for channels of HB \b");
3055       h3Ceff->SetMarkerColor(2);
3056       h3Ceff->SetLineColor(2);
3057       h3Ceff->Draw("COLZ");
3058     }
3059 
3060     cHE->Update();
3061     cHE->Print(Form("ChkErrA_HB%d.png", depth));
3062     cHE->Clear();
3063 
3064     if (h2Ceff)
3065       delete h2Ceff;
3066     if (h2Diffe)
3067       delete h2Diffe;
3068     //    if (h1diffADCAmpl) delete h1diffADCAmpl;
3069     //  if (twod0) delete twod0;// do not delete - sometimes causes trouble later
3070     if (twod1)
3071       delete twod1;
3072     if (twod3)
3073       delete twod3;
3074     if (h3Ceff)
3075       delete h3Ceff;
3076   }  // depth
3077 
3078   //===============================================================================  err A HE
3079   /// errA with average Amplitudes
3080   // For  2D and  1D plots with Amplitude. Produces ChkErrA_HEx.png
3081 
3082   for (int depth = 1; depth <= 3; depth++) {
3083     TH2F *h2Ceff = NULL;
3084     TH2F *h2Diffe = NULL;
3085     //    TH1F* h1diffADCAmpl= NULL;
3086     TH2F *h3Ceff = NULL;
3087 
3088     cHE->Clear();
3089     cHE->Divide(3, 1);
3090 
3091     cHE->cd(1);
3092     // h_mapDepth1ADCAmpl_HE div h_mapDepth1_HE
3093     TString hname1 = Form("h_mapDepth%dADCAmpl_HE", depth);
3094     TString hname0 = Form("h_mapDepth%d_HE", depth);
3095     TH2F *twod1 = (TH2F *)dir->FindObjectAny(hname1);
3096     TH2F *twod0 = (TH2F *)dir->FindObjectAny(hname0);
3097     if (!twod1 || !twod0) {
3098       TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
3099       ptext->AddText("Missing histo");
3100       std::cout << "specHE test: failed to load " << hname1 << " and/or " << hname0 << "\n";
3101       if (!twod1)
3102         ptext->AddText(hname1);
3103       if (!twod0)
3104         ptext->AddText(hname0);
3105       ptext->Draw();
3106       continue;
3107     } else {
3108       // To IDENTIFY: see color different bins in eta-phi space
3109       h2Ceff = (TH2F *)twod1->Clone(Form("Ceff_HE%d", depth));
3110       h2Ceff->SetTitle(Form("HE Depth %d. (No cut) \b", depth));
3111       h2Ceff->Divide(twod1, twod0, 1, 1, "B");
3112 
3113       gPad->SetGridy();
3114       gPad->SetGridx();
3115       gPad->SetLogz();
3116       h2Ceff->SetTitleOffset(0.75, "Z");
3117       h2Ceff->SetMarkerStyle(20);
3118       h2Ceff->SetMarkerSize(0.4);
3119       //h2Ceff->GetZaxis()->SetLabelSize(0.08);
3120       h2Ceff->SetXTitle("#eta \b");
3121       h2Ceff->SetYTitle("#phi \b");
3122       h2Ceff->SetZTitle("h_mapDepth1ADCAmpl_HE \b");
3123       h2Ceff->SetMarkerColor(2);
3124       h2Ceff->SetLineColor(2);
3125       h2Ceff->Draw("COLZ");
3126     }
3127 
3128     cHE->cd(2);
3129     ///////////////////////////////////////
3130     if (h2Ceff) {
3131       // TO IDENTIFY: see red bins in eta-phi space
3132       h2Diffe = (TH2F *)h2Ceff->Clone(Form("Diffe_Depth%d_HE", depth));
3133       h2Diffe->SetTitle(Form("HE Depth %d. Cut avg(ADCAmpl) > 1000 fC \b", depth));
3134       int nx = h2Ceff->GetXaxis()->GetNbins();
3135       int ny = h2Ceff->GetYaxis()->GetNbins();
3136       for (int i = 1; i <= nx; i++) {
3137         for (int j = 1; j <= ny; j++) {
3138           double ccc1 = h2Ceff->GetBinContent(i, j);
3139           h2Diffe->SetBinContent(i, j, 0.);
3140           if (ccc1 > 1000.)
3141             h2Diffe->SetBinContent(i, j, ccc1);
3142         }
3143       }
3144       gPad->SetGridy();
3145       gPad->SetGridx();
3146       gPad->SetLogz();
3147       h2Diffe->SetMarkerStyle(20);
3148       h2Diffe->SetMarkerSize(0.4);
3149       //h2Diffe->GetZaxis()->SetLabelSize(0.08);
3150       h2Diffe->SetXTitle("#eta \b");
3151       h2Diffe->SetYTitle("#phi \b");
3152       h2Diffe->SetZTitle("<ADCAmpl> bigger 1000.fC - HE Depth1 \b");
3153       h2Diffe->SetMarkerColor(2);
3154       h2Diffe->SetLineColor(2);
3155       h2Diffe->Draw("COLZ");
3156     }
3157 
3158     cHE->cd(3);
3159     TString hname3 = Form("h_mapDepth%dADCAmpl225Copy_HE", depth);
3160     TH2F *twod3 = (TH2F *)dir->FindObjectAny(hname3);
3161     if (!twod3 || !twod0) {
3162       TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
3163       ptext->AddText("Missing histo");
3164       std::cout << "specHE test: failed to load " << hname3 << " and/or " << hname0 << "\n";
3165       if (!twod3)
3166         ptext->AddText(hname3);
3167       if (!twod0)
3168         ptext->AddText(hname0);
3169       ptext->Draw();
3170       continue;
3171     } else {
3172       // To IDENTIFY: see color different bins in eta-phi space
3173       h3Ceff = (TH2F *)twod3->Clone(Form("CeffA_HE%d", depth));
3174       h3Ceff->SetTitle(Form("HE Depth %d. \b", depth));
3175       h3Ceff->Divide(twod3, twod0, 1, 1, "B");
3176       gPad->SetGridy();
3177       gPad->SetGridx();
3178       gPad->SetLogz();
3179       h3Ceff->SetMarkerStyle(20);
3180       h3Ceff->SetMarkerSize(0.4);
3181       //      h3Ceff->GetZaxis()->SetLabelSize(0.08);
3182       h3Ceff->SetXTitle("#eta \b");
3183       h3Ceff->SetYTitle("#phi \b");
3184       h3Ceff->SetZTitle("rate for channels of HE \b");
3185       h3Ceff->SetMarkerColor(2);
3186       h3Ceff->SetLineColor(2);
3187       h3Ceff->Draw("COLZ");
3188     }
3189 
3190     cHE->Update();
3191     cHE->Print(Form("ChkErrA_HE%d.png", depth));
3192     cHE->Clear();
3193 
3194     if (h2Ceff)
3195       delete h2Ceff;
3196     if (h2Diffe)
3197       delete h2Diffe;
3198     //    if (h1diffADCAmpl) delete h1diffADCAmpl;
3199     //  if (twod0) delete twod0;// do not delete - sometimes causes trouble later
3200     if (twod1)
3201       delete twod1;
3202     if (twod3)
3203       delete twod3;
3204     if (h3Ceff)
3205       delete h3Ceff;
3206   }  // depth
3207 
3208   //===============================================================================  err A HO
3209   /// errA with average Amplitudes
3210   // For  2D and  1D plots with Amplitude. Produces ChkErrA_HOx.png
3211 
3212   for (int depth = 4; depth <= 4; depth++) {
3213     TH2F *h2Ceff = NULL;
3214     TH2F *h2Diffe = NULL;
3215     //    TH1F* h1diffADCAmpl= NULL;
3216     TH2F *h3Ceff = NULL;
3217 
3218     cHE->Clear();
3219     cHE->Divide(3, 1);
3220 
3221     cHE->cd(1);
3222     // h_mapDepth1ADCAmpl_HO div h_mapDepth1_HO
3223     TString hname1 = Form("h_mapDepth%dADCAmpl_HO", depth);
3224     TString hname0 = Form("h_mapDepth%d_HO", depth);
3225     TH2F *twod1 = (TH2F *)dir->FindObjectAny(hname1);
3226     TH2F *twod0 = (TH2F *)dir->FindObjectAny(hname0);
3227     if (!twod1 || !twod0) {
3228       TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
3229       ptext->AddText("Missing histo");
3230       std::cout << "specHO test: failed to load " << hname1 << " and/or " << hname0 << "\n";
3231       if (!twod1)
3232         ptext->AddText(hname1);
3233       if (!twod0)
3234         ptext->AddText(hname0);
3235       ptext->Draw();
3236       continue;
3237     } else {
3238       // To IDENTIFY: see color different bins in eta-phi space
3239       h2Ceff = (TH2F *)twod1->Clone(Form("Ceff_HO%d", depth));
3240       h2Ceff->SetTitle(Form("HO Depth %d. (No cut) \b", depth));
3241       h2Ceff->Divide(twod1, twod0, 1, 1, "B");
3242 
3243       gPad->SetGridy();
3244       gPad->SetGridx();
3245       gPad->SetLogz();
3246       h2Ceff->SetMarkerStyle(20);
3247       h2Ceff->SetMarkerSize(0.4);
3248       //h2Ceff->GetZaxis()->SetLabelSize(0.08);
3249       h2Ceff->SetXTitle("#eta \b");
3250       h2Ceff->SetYTitle("#phi \b");
3251       h2Ceff->SetZTitle("h_mapDepth1ADCAmpl_HO \b");
3252       h2Ceff->SetMarkerColor(2);
3253       h2Ceff->SetLineColor(2);
3254       h2Ceff->Draw("COLZ");
3255     }
3256 
3257     cHE->cd(2);
3258     ///////////////////////////////////////
3259     if (h2Ceff) {
3260       // TO IDENTIFY: see red bins in eta-phi space (applied cut on Aij: <20 || >3000
3261       h2Diffe = (TH2F *)h2Ceff->Clone(Form("Diffe_Depth%d_HO", depth));
3262       h2Diffe->SetTitle(Form("HO Depth %d. Cut avg(ADCAmpl) > 80 \b", depth));
3263       int nx = h2Ceff->GetXaxis()->GetNbins();
3264       int ny = h2Ceff->GetYaxis()->GetNbins();
3265       for (int i = 1; i <= nx; i++) {
3266         for (int j = 1; j <= ny; j++) {
3267           double ccc1 = h2Ceff->GetBinContent(i, j);
3268           h2Diffe->SetBinContent(i, j, 0.);
3269           if (ccc1 > 20.)
3270             h2Diffe->SetBinContent(i, j, ccc1);
3271         }
3272       }
3273       gPad->SetGridy();
3274       gPad->SetGridx();
3275       gPad->SetLogz();
3276       h2Diffe->SetMarkerStyle(20);
3277       h2Diffe->SetMarkerSize(0.4);
3278       //h2Diffe->GetZaxis()->SetLabelSize(0.08);
3279       h2Diffe->SetXTitle("#eta \b");
3280       h2Diffe->SetYTitle("#phi \b");
3281       h2Diffe->SetZTitle("<ADCAmpl> bigger 80.- HO Depth1 \b");
3282       h2Diffe->SetMarkerColor(2);
3283       h2Diffe->SetLineColor(2);
3284       h2Diffe->Draw("COLZ");
3285     }
3286 
3287     cHE->cd(3);
3288     TString hname3 = Form("h_mapDepth%dADCAmpl225Copy_HO", depth);
3289     TH2F *twod3 = (TH2F *)dir->FindObjectAny(hname3);
3290     if (!twod3 || !twod0) {
3291       TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
3292       ptext->AddText("Missing histo");
3293       std::cout << "specHO test: failed to load " << hname3 << " and/or " << hname0 << "\n";
3294       if (!twod3)
3295         ptext->AddText(hname3);
3296       if (!twod0)
3297         ptext->AddText(hname0);
3298       ptext->Draw();
3299       continue;
3300     } else {
3301       // To IDENTIFY: see color different bins in eta-phi space
3302       h3Ceff = (TH2F *)twod3->Clone(Form("CeffA_HO%d", depth));
3303       h3Ceff->SetTitle(Form("HO Depth %d. \b", depth));
3304       h3Ceff->Divide(twod3, twod0, 1, 1, "B");
3305       gPad->SetGridy();
3306       gPad->SetGridx();
3307       gPad->SetLogz();
3308       h3Ceff->SetMarkerStyle(20);
3309       h3Ceff->SetMarkerSize(0.4);
3310       //      h3Ceff->GetZaxis()->SetLabelSize(0.08);
3311       h3Ceff->SetXTitle("#eta \b");
3312       h3Ceff->SetYTitle("#phi \b");
3313       h3Ceff->SetZTitle("rate for channels of HO \b");
3314       h3Ceff->SetMarkerColor(2);
3315       h3Ceff->SetLineColor(2);
3316       h3Ceff->Draw("COLZ");
3317     }
3318 
3319     cHE->Update();
3320     cHE->Print(Form("ChkErrA_HO%d.png", depth));
3321     cHE->Clear();
3322 
3323     if (h2Ceff)
3324       delete h2Ceff;
3325     if (h2Diffe)
3326       delete h2Diffe;
3327     //    if (h1diffADCAmpl) delete h1diffADCAmpl;
3328     //  if (twod0) delete twod0;// do not delete - sometimes causes trouble later
3329     if (twod1)
3330       delete twod1;
3331     if (twod3)
3332       delete twod3;
3333     if (h3Ceff)
3334       delete h3Ceff;
3335   }  // depth
3336 
3337   //===============================================================================  err A HF
3338   /// errA with average Amplitudes
3339   // For  2D and  1D plots with Amplitude. Produces ChkErrA_HFx.png
3340 
3341   for (int depth = 1; depth <= 2; depth++) {
3342     TH2F *h2Ceff = NULL;
3343     TH2F *h2Diffe = NULL;
3344     //    TH1F* h1diffADCAmpl= NULL;
3345     TH2F *h3Ceff = NULL;
3346 
3347     cHE->Clear();
3348     cHE->Divide(3, 1);
3349 
3350     cHE->cd(1);
3351     // h_mapDepth1ADCAmpl_HF div h_mapDepth1_HF
3352     TString hname1 = Form("h_mapDepth%dADCAmpl_HF", depth);
3353     TString hname0 = Form("h_mapDepth%d_HF", depth);
3354     TH2F *twod1 = (TH2F *)dir->FindObjectAny(hname1);
3355     TH2F *twod0 = (TH2F *)dir->FindObjectAny(hname0);
3356     if (!twod1 || !twod0) {
3357       TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
3358       ptext->AddText("Missing histo");
3359       std::cout << "specHF test: failed to load " << hname1 << " and/or " << hname0 << "\n";
3360       if (!twod1)
3361         ptext->AddText(hname1);
3362       if (!twod0)
3363         ptext->AddText(hname0);
3364       ptext->Draw();
3365       continue;
3366     } else {
3367       // To IDENTIFY: see color different bins in eta-phi space
3368       h2Ceff = (TH2F *)twod1->Clone(Form("Ceff_HF%d", depth));
3369       h2Ceff->SetTitle(Form("HF Depth %d. (No cut) \b", depth));
3370       h2Ceff->Divide(twod1, twod0, 1, 1, "B");
3371 
3372       gPad->SetGridy();
3373       gPad->SetGridx();
3374       gPad->SetLogz();
3375       h2Ceff->SetMarkerStyle(20);
3376       h2Ceff->SetMarkerSize(0.4);
3377       //h2Ceff->GetZaxis()->SetLabelSize(0.08);
3378       h2Ceff->SetXTitle("#eta \b");
3379       h2Ceff->SetYTitle("#phi \b");
3380       h2Ceff->SetZTitle("h_mapDepth1ADCAmpl_HF \b");
3381       h2Ceff->SetMarkerColor(2);
3382       h2Ceff->SetLineColor(2);
3383       h2Ceff->Draw("COLZ");
3384     }
3385 
3386     cHE->cd(2);
3387     ///////////////////////////////////////
3388     if (h2Ceff) {
3389       // TO IDENTIFY: see red bins in eta-phi space (applied cut on Aij: <20 || >3000
3390       h2Diffe = (TH2F *)h2Ceff->Clone(Form("Diffe_Depth%d_HF", depth));
3391       h2Diffe->SetTitle(Form("HF Depth %d. Cut avg(ADCAmpl) > 20 \b", depth));
3392       int nx = h2Ceff->GetXaxis()->GetNbins();
3393       int ny = h2Ceff->GetYaxis()->GetNbins();
3394       for (int i = 1; i <= nx; i++) {
3395         for (int j = 1; j <= ny; j++) {
3396           double ccc1 = h2Ceff->GetBinContent(i, j);
3397           h2Diffe->SetBinContent(i, j, 0.);
3398           if (ccc1 > 20.)
3399             h2Diffe->SetBinContent(i, j, ccc1);
3400         }
3401       }
3402       gPad->SetGridy();
3403       gPad->SetGridx();
3404       gPad->SetLogz();
3405       h2Diffe->SetMarkerStyle(20);
3406       h2Diffe->SetMarkerSize(0.4);
3407       //h2Diffe->GetZaxis()->SetLabelSize(0.08);
3408       h2Diffe->SetXTitle("#eta \b");
3409       h2Diffe->SetYTitle("#phi \b");
3410       h2Diffe->SetZTitle("<ADCAmpl> bigger 20.- HF Depth1 \b");
3411       h2Diffe->SetMarkerColor(2);
3412       h2Diffe->SetLineColor(2);
3413       h2Diffe->Draw("COLZ");
3414     }
3415 
3416     cHE->cd(3);
3417     /*
3418     if (h2Ceff) {
3419       h1diffADCAmpl = new TH1F(Form("diffADCAmpl_Depth%d_HF",depth),"",
3420                    100, -20.,200.);
3421       h1diffADCAmpl->SetTitle(Form("HF Depth %d \b",depth));
3422       int nx = h2Ceff->GetXaxis()->GetNbins();
3423       int ny = h2Ceff->GetYaxis()->GetNbins();
3424       for (int i=1;i<=nx;i++) {
3425     for (int j=1;j<=ny;j++) {
3426       if(h2Ceff->GetBinContent(i,j) !=0 ) {
3427         double ccc1 =  h2Ceff->GetBinContent(i,j) ;
3428         h1diffADCAmpl->Fill(ccc1);
3429       }
3430     }
3431       }
3432       gPad->SetLogy();
3433       h1diffADCAmpl->SetMarkerStyle(20);
3434       h1diffADCAmpl->SetMarkerSize(0.4);
3435       h1diffADCAmpl->GetYaxis()->SetLabelSize(0.04);
3436       h1diffADCAmpl->SetXTitle("<ADCAmpl> in each cell \b");
3437       h1diffADCAmpl->SetMarkerColor(2);
3438       h1diffADCAmpl->SetLineColor(2);
3439       h1diffADCAmpl->Draw("");
3440     }
3441     */
3442     TString hname3 = Form("h_mapDepth%dADCAmpl225Copy_HF", depth);
3443     TH2F *twod3 = (TH2F *)dir->FindObjectAny(hname3);
3444     if (!twod3 || !twod0) {
3445       TPaveText *ptext = new TPaveText(0.05, 0.85, 0.95, 0.95);
3446       ptext->AddText("Missing histo");
3447       std::cout << "specHF test: failed to load " << hname3 << " and/or " << hname0 << "\n";
3448       if (!twod3)
3449         ptext->AddText(hname3);
3450       if (!twod0)
3451         ptext->AddText(hname0);
3452       ptext->Draw();
3453       continue;
3454     } else {
3455       // To IDENTIFY: see color different bins in eta-phi space
3456       h3Ceff = (TH2F *)twod3->Clone(Form("CeffA_HF%d", depth));
3457       h3Ceff->SetTitle(Form("HF Depth %d. \b", depth));
3458       h3Ceff->Divide(twod3, twod0, 1, 1, "B");
3459       gPad->SetGridy();
3460       gPad->SetGridx();
3461       gPad->SetLogz();
3462       h3Ceff->SetMarkerStyle(20);
3463       h3Ceff->SetMarkerSize(0.4);
3464       //      h3Ceff->GetZaxis()->SetLabelSize(0.08);
3465       h3Ceff->SetXTitle("#eta \b");
3466       h3Ceff->SetYTitle("#phi \b");
3467       h3Ceff->SetZTitle("rate for channels of HF \b");
3468       h3Ceff->SetMarkerColor(2);
3469       h3Ceff->SetLineColor(2);
3470       h3Ceff->Draw("COLZ");
3471     }
3472 
3473     cHE->Update();
3474     cHE->Print(Form("ChkErrA_HF%d.png", depth));
3475     cHE->Clear();
3476 
3477     if (h2Ceff)
3478       delete h2Ceff;
3479     if (h2Diffe)
3480       delete h2Diffe;
3481     //    if (h1diffADCAmpl) delete h1diffADCAmpl;
3482     //  if (twod0) delete twod0;// do not delete - sometimes causes trouble later
3483     if (twod1)
3484       delete twod1;
3485     if (twod3)
3486       delete twod3;
3487     if (h3Ceff)
3488       delete h3Ceff;
3489   }  // depth
3490 
3491   std::cout << "************>>>   average Amplitudes done" << std::endl;
3492 
3493   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
3494   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
3495   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
3496   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
3497   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
3498 
3499   //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RBX study:  HistCapID
3500   //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RBX study:
3501   //////////////////////////////////////////////////////////////////////////////////////////////////////// RBX study:
3502   //////////////////////////////////////////////////////////////////////////////////// RBX study:
3503 
3504   cout << " RBX analysis START for  **************************" << endl;
3505   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
3506   //  int njeta = 22; int njphi = 18; int lsmax=2600;
3507   int njeta = 22;
3508   int njphi = 18;
3509   int lsmax = 1800;
3510   cout << ">>>>>>>>>>>>>>>>>>>>>>>>     int njeta = 22; int njphi = 18; int lsmax=1800;                        "
3511        << endl;
3512 
3513   double alexall[njeta][njphi][lsmax];
3514 
3515   // for phi tables(!):
3516   double alexhb[njphi][lsmax];
3517   double alexhe[njphi][lsmax];
3518   double alexho[njphi][lsmax];
3519   double alexhf[njphi][lsmax];
3520 
3521   // for eta tables(!):
3522   double blexhb[njeta][lsmax];
3523   double blexhe[njeta][lsmax];
3524   double blexho[njeta][lsmax];
3525   double blexhf[njeta][lsmax];
3526 
3527   cout << ">>>>>>>>>>>>>>>>>>>>>>>>  alexall   [njeta][njphi][lsmax];                         " << endl;
3528   int maxbinsRBX = MaxLum;
3529   int nx = maxbinsRBX;  // # LS
3530   cout << ">>>>>>>>>>>>>>>>>>>>>>>>   maxbinsRBX = MaxLum;                          " << endl;
3531   if (MaxLum > lsmax)
3532     cout << "***********************************   ERROR ERROR ERROR ERROR:   MaxLum > 1800 " << endl;
3533   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
3534 
3535   for (int i = 0; i < nx; i++) {
3536     for (int jphi = 0; jphi < njphi; jphi++) {
3537       alexhb[jphi][i] = 0.;
3538       alexhe[jphi][i] = 0.;
3539       alexho[jphi][i] = 0.;
3540       alexhf[jphi][i] = 0.;
3541 
3542       for (int jeta = 0; jeta < njeta; jeta++) {
3543         if (jphi == 0) {
3544           blexhb[jeta][i] = 0.;
3545           blexhe[jeta][i] = 0.;
3546           blexho[jeta][i] = 0.;
3547           blexhf[jeta][i] = 0.;
3548         }
3549 
3550         alexall[jeta][jphi][i] = 0.;
3551       }
3552     }
3553   }
3554 
3555   //////////
3556   /*
3557       // j = ietaphi = 1- 396
3558        int ietaphimax = 396;
3559       int ny = ietaphimax + 1 ;
3560       for (int j=1;j<ny;j++) {
3561       int jeta = (j-1)/znphi;
3562       int jphi = (j-1)-znphi*jeta+1;// jphi=1-18 
3563       jeta += 1;// jeta = 1-22      }
3564 // Outout is  jeta = 1-22   jphi=1-18 
3565 HB: j = 7,8,9,10            11,12,13,14
3566 HE: j = 3,4,5, 6, 7      14,15,16,17,18     
3567 HO: j = 7,8,9,10            11,12,13,14
3568 HF: j = 0,1,2, 3            18,19,20,21
3569 */
3570 
3571   ////////////////////////////////////////////////////////////////////////////////////     HB::  HBSTART HB: j = 7,8,9,10            11,12,13,14
3572   //======================================================================
3573   //======================================================================
3574   //======================================================================
3575   cout << " RBX general for HB **************************" << endl;
3576   TH2F *Ghb1KKK = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplEtaPhiLs0");
3577   TH2F *Ghb1LLL = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplEtaPhiLs00");
3578   TH2F *Ghb1 = (TH2F *)Ghb1LLL->Clone("Ghb1");
3579   Ghb1->Divide(Ghb1KKK, Ghb1LLL, 1, 1, "B");  // average A
3580   //    Ghb1->Sumw2();
3581   //      int nx = Ghb1->GetXaxis()->GetNbins(); // # LS
3582   int ny = Ghb1->GetYaxis()->GetNbins();  // # jetaphi indexes = 396 = 18*22
3583   //           cout<<"*****************************************      HB 54        ny=     "<< ny <<endl;
3584   for (int j = 1; j <= ny; j++) {
3585     int jeta = (j - 1) / njphi;  // jeta = 0-21
3586     if (jeta > 6 && jeta < 15) {
3587       int jphi = (j - 1) - njphi * jeta;  // jphi=0-17
3588       //       cout<<"HB 54        jeta=     "<< jeta <<"   jphi   =     "<<jphi  <<endl;
3589       // over LS:
3590       for (int i = 1; i <= nx; i++) {
3591         double ccc1 = Ghb1->GetBinContent(i, j);
3592         alexall[jeta][jphi][i - 1] = ccc1;
3593         //               if( i == 1 ) cout<<"HB 54  for LS=1      ccc1=     "<< ccc1 <<endl;
3594         //           if( ccc1 <= 0 ) cout<<"HB 54   ccc1=     "<< ccc1 <<"   iLS=     "<< i <<"   eta=     "<< jeta <<"   phi=     "<< jphi <<endl;
3595         //               cout<<"HB 54   ccc1=     "<< ccc1 <<"   j=     "<< j <<"   iLS=     "<< i <<"   eta=     "<< jeta <<"   phi=     "<< jphi <<endl;
3596       }  //i
3597     }    //if
3598   }      //j
3599   // clean-up
3600   if (Ghb1KKK)
3601     delete Ghb1KKK;
3602   if (Ghb1LLL)
3603     delete Ghb1LLL;
3604   //    if (Ghb1) delete Ghb1;
3605 
3606   //====================================================================== alexhb[k][i]
3607   for (int jphi = 0; jphi < njphi; jphi++) {
3608     for (int i = 0; i < nx; i++) {
3609       double sumccc1 = 0.;
3610       int isum = 0;
3611       for (int jeta = 0; jeta < njeta; jeta++) {
3612         double ccc1 = alexall[jeta][jphi][i];
3613         if (ccc1 > 0.) {
3614           sumccc1 += ccc1;
3615           isum++;
3616         }
3617       }  // for jeta
3618       if (isum > 0.)
3619         sumccc1 /= isum;
3620       alexhb[jphi][i] = sumccc1;
3621     }
3622   }  //for for
3623 
3624   //====================================================================== blexhb[k][i]
3625   for (int keta = 0; keta < njeta; keta++) {
3626     for (int i = 0; i < nx; i++) {
3627       double sumccc1 = 0.;
3628       int isum = 0;
3629       for (int kphi = 0; kphi < njphi; kphi++) {
3630         double ccc1 = alexall[keta][kphi][i];
3631         if (ccc1 > 0.) {
3632           sumccc1 += ccc1;
3633           isum++;
3634         }
3635       }  // for kphi
3636       if (isum > 0.)
3637         sumccc1 /= isum;
3638       blexhb[keta][i] = sumccc1;
3639     }
3640   }  //for for
3641 
3642   /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3643   //========================================================================================== 11   HB:: 2D  jeta = 0 - 21       jphi =0 - 17
3644   //======================================================================
3645   //======================================================================
3646   //======================================================================
3647   //======================================================================
3648   cout << "      RBX HB  2D plot *****" << endl;
3649   cRBX1->Clear();
3650   /////////////////
3651   cRBX1->Divide(1, 1);
3652   cRBX1->cd(1);
3653   // int ietaphi = 0; ietaphi = ((k2+1)-1)*nphi + (k3+1) ;  k2=0-neta-1; k3=0-nphi-1; neta=18; nphi=22;
3654   //       TH2F* Ghb42D      = new TH2F("Ghb42D","",   22, -11., 11., 18, 0., 18. );
3655   //       TH2F* Ghb42D0     = new TH2F("Ghb42D0","",  22, -11., 11., 18, 0., 18. );
3656   TH2F *Ghb42D = new TH2F("Ghb42D", "", 23, -11.5, 11.5, 18, 0., 18.);
3657   TH2F *Ghb42D0 = new TH2F("Ghb42D0", "", 23, -11.5, 11.5, 18, 0., 18.);
3658   TH2F *Ghb42DF = (TH2F *)Ghb42D0->Clone("Ghb42DF");
3659   for (int jphi = 0; jphi < njphi; jphi++) {
3660     for (int jeta = 0; jeta < njeta; jeta++) {
3661       for (int i = 0; i < nx; i++) {
3662         double ccc1 = alexall[jeta][jphi][i];
3663         int neweta = jeta - 11 - 0.5;
3664         if (jeta >= 11)
3665           neweta = jeta - 11 + 1.5;
3666         if (ccc1 > 0.) {
3667           Ghb42D->Fill(neweta, jphi, ccc1);
3668           Ghb42D0->Fill(neweta, jphi, 1.);
3669         }
3670         //       if(ccc1>0.) {Ghb42D ->Fill(jeta-11,jphi,ccc1); Ghb42D0 ->Fill(jeta-11,jphi,1.); }
3671       }
3672     }
3673   }
3674   Ghb42DF->Divide(Ghb42D, Ghb42D0, 1, 1, "B");  // average A
3675   //    Ghb1->Sumw2();
3676   gPad->SetGridy();
3677   gPad->SetGridx();  //      gPad->SetLogz();
3678   Ghb42DF->SetMarkerStyle(20);
3679   Ghb42DF->SetMarkerSize(0.4);
3680   Ghb42DF->GetZaxis()->SetLabelSize(0.04);
3681   Ghb42DF->SetXTitle("<A>_RBX         #eta  \b");
3682   Ghb42DF->SetYTitle("      #phi \b");
3683   Ghb42DF->SetZTitle("<A>_RBX  - All \b");
3684   Ghb42DF->SetMarkerColor(2);
3685   Ghb42DF->SetLineColor(2);  //      Ghb42DF->SetMaximum(1.000);  //      Ghb42DF->SetMinimum(1.0);
3686   Ghb42DF->Draw("COLZ");
3687 
3688   /////////////////
3689   cRBX1->Update();
3690   cRBX1->Print("RBX-HB-2Dplot.png");
3691   cRBX1->Clear();
3692   // clean-up
3693   if (Ghb42D)
3694     delete Ghb42D;
3695   if (Ghb42D0)
3696     delete Ghb42D0;
3697   if (Ghb42DF)
3698     delete Ghb42DF;
3699 
3700   //========================================================================================== 61   HB:: 1D  j = 7,8,9,10 ; 11,12,13,14       jphi =0 - 17
3701   //======================================================================
3702   //======================================================================
3703   //======================================================================
3704   //======================================================================
3705   cout << "      RBX HB  1D plot *****" << endl;
3706   cRBX1->Clear();
3707   /////////////////
3708   cRBX1->Divide(1, 1);
3709   cRBX1->cd(1);
3710   TH1F *GphiHB1D = new TH1F("GphiHB1D", "", 18, 0., 18.);
3711   TH1F *GphiHB1D0 = new TH1F("GphiHB1D0", "", 18, 0., 18.);
3712   TH1F *GphiHB1DF = (TH1F *)GphiHB1D0->Clone("GphiHB1DF");
3713   for (int jphi = 0; jphi < 18; jphi++) {
3714     for (int jeta = 0; jeta < 22; jeta++) {
3715       for (int i = 0; i < nx; i++) {
3716         double ccc1 = alexall[jeta][jphi][i];
3717         if (ccc1 > 0.) {
3718           GphiHB1D->Fill(jphi, ccc1);
3719           GphiHB1D0->Fill(jphi, 1.);
3720         }
3721       }
3722     }
3723   }
3724   //     GphiHB1D->Sumw2();GphiHB1D0->Sumw2();
3725   GphiHB1DF->Divide(GphiHB1D, GphiHB1D0, 1, 1, "B");  // average A
3726                                                       //     GphiHB1DF->Sumw2();
3727   for (int jphi = 1; jphi < 19; jphi++) {
3728     GphiHB1DF->SetBinError(jphi, 0.01);
3729   }
3730   gPad->SetGridy();
3731   gPad->SetGridx();  //      gPad->SetLogz();
3732   GphiHB1DF->SetMarkerStyle(20);
3733   GphiHB1DF->SetMarkerSize(1.4);
3734   GphiHB1DF->GetZaxis()->SetLabelSize(0.08);
3735   GphiHB1DF->SetXTitle("PHI of RBX\b");
3736   GphiHB1DF->SetYTitle(" <Amplitude> \b");
3737   GphiHB1DF->SetZTitle("<A>_PHI  - All \b");
3738   GphiHB1DF->SetMarkerColor(4);
3739   GphiHB1DF->SetLineColor(4);
3740   GphiHB1DF->SetMinimum(0.8);  //      GphiHB1DF->SetMaximum(1.000);
3741   GphiHB1DF->Draw("Error");
3742   /////////////////
3743   cRBX1->Update();
3744   cRBX1->Print("RBX-HB-1Dplot.png");
3745   cRBX1->Clear();
3746   // clean-up
3747   if (GphiHB1D)
3748     delete GphiHB1D;
3749   if (GphiHB1D0)
3750     delete GphiHB1D0;
3751   if (GphiHB1DF)
3752     delete GphiHB1DF;
3753 
3754   //========================================================================================== 62   HB:: 1D  j = 7,8,9,10 ; 11,12,13,14       jphi =0 - 17
3755   //======================================================================
3756   //======================================================================
3757   //======================================================================
3758   //======================================================================
3759   cout << "      RBX HB 11D plot *eta*" << endl;
3760   cRBX1->Clear();
3761   /////////////////
3762   cRBX1->Divide(1, 1);
3763   cRBX1->cd(1);
3764   TH1F *GetaHB11D = new TH1F("GetaHB11D", "", 23, -11.5, 11.5);
3765   TH1F *GetaHB11D0 = new TH1F("GetaHB11D0", "", 23, -11.5, 11.5);
3766   TH1F *GetaHB11DF = (TH1F *)GetaHB11D0->Clone("GetaHB11DF");
3767 
3768   for (int jeta = 0; jeta < 22; jeta++) {
3769     for (int jphi = 0; jphi < 18; jphi++) {
3770       for (int i = 0; i < nx; i++) {
3771         double ccc1 = alexall[jeta][jphi][i];
3772         int neweta = jeta - 11 - 0.5;
3773         if (jeta >= 11)
3774           neweta = jeta - 11 + 1.5;
3775         if (ccc1 > 0.) {
3776           GetaHB11D->Fill(neweta, ccc1);
3777           GetaHB11D0->Fill(neweta, 1.);
3778           //           if( i == 0 ) cout<<"62  HB:  ibin=  "<< i <<"      jphi= "<< jphi <<"      jeta= "<< jeta <<"      A= "<< ccc1 <<endl;
3779         }
3780       }
3781     }
3782   }
3783   //     GetaHB11D->Sumw2();GetaHB11D0->Sumw2();
3784   GetaHB11DF->Divide(GetaHB11D, GetaHB11D0, 1, 1, "B");  // average A
3785                                                          //     GetaHB11DF->Sumw2();
3786   for (int jeta = 1; jeta < 24; jeta++) {
3787     GetaHB11DF->SetBinError(jeta, 0.01);
3788   }
3789   gPad->SetGridy();
3790   gPad->SetGridx();  //      gPad->SetLogz();
3791   GetaHB11DF->SetMarkerStyle(20);
3792   GetaHB11DF->SetMarkerSize(1.4);
3793   GetaHB11DF->GetZaxis()->SetLabelSize(0.08);
3794   GetaHB11DF->SetXTitle("#eta  \b");
3795   GetaHB11DF->SetYTitle("  <A> \b");
3796   GetaHB11DF->SetZTitle("<A>_ETA  - All \b");
3797   GetaHB11DF->SetMarkerColor(4);
3798   GetaHB11DF->SetLineColor(4);
3799   GetaHB11DF->SetMinimum(0.8);  //      GetaHB11DF->SetMaximum(1.000);
3800   GetaHB11DF->Draw("Error");
3801 
3802   /////////////////
3803   cRBX1->Update();
3804   cRBX1->Print("RBX-HB-11Dplot.png");
3805   cRBX1->Clear();
3806   // clean-up
3807   if (GetaHB11D)
3808     delete GetaHB11D;
3809   if (GetaHB11D0)
3810     delete GetaHB11D0;
3811   if (GetaHB11DF)
3812     delete GetaHB11DF;
3813 
3814   //========================================================================================== 22   HB:: Ratio plots   jeta = 0 - 21       jphi =0 - 17
3815   //======================================================================
3816   //======================================================================22.11.2018
3817   //======================================================================
3818   //======================================================================
3819 
3820   gStyle->SetOptStat(1110000);
3821   cout << "      RBX HB  Ratio plots *****" << endl;
3822   cRBX31->Clear();
3823   /////////////////
3824   // gain stabilitY:
3825   // Rij = Aij / A1j , where i-over LSs, j-channels
3826   //
3827   //    nx = maxbinsRBX; // # LS
3828   //
3829   double ccc0HB = 0.;
3830   cRBX31->Divide(3, 1);
3831   //================
3832   cRBX31->cd(1);
3833   //    TH1F* Ghb5 = new TH1F("Ghb5","", nx, 1., nx+1.);
3834   TH1F *Ghb51 = new TH1F("Ghb51", "", nx, 1., nx + 1.);
3835   TH1F *Ghb50 = new TH1F("Ghb50", "", nx, 1., nx + 1.);
3836   TH1F *Ghb5 = (TH1F *)Ghb50->Clone("Ghb5");
3837   // j - etaphi index:
3838   for (int j = 1; j <= ny; j++) {
3839     ccc0HB = Ghb1->GetBinContent(1, j);
3840     //  if(ccc0HB <=0.) for (int i=1;i<=nx;i++) {double ccc2 =  Ghb1->GetBinContent(i,j);if(ccc2>0.){ccc0HB=ccc2;cout<<"!!! ccc0HB= "<<ccc0HB<<endl;break;} }
3841     if (ccc0HB <= 0.)
3842       for (int i = 1; i <= nx; i++) {
3843         double ccc2 = Ghb1->GetBinContent(i, j);
3844         if (ccc2 > 0.) {
3845           ccc0HB = ccc2;
3846           break;
3847         }
3848       }
3849     if (ccc0HB > 0.) {
3850       // i - # LSs:
3851       for (int i = 1; i <= nx; i++) {
3852         double ccc1 = Ghb1->GetBinContent(i, j);
3853         if (ccc1 > 0.) {
3854           double Rij = ccc1 / ccc0HB;
3855           //          Ghb5 ->Fill( float(i), Rij);
3856           Ghb51->Fill(float(i), Rij);
3857           Ghb50->Fill(float(i), 1.);
3858         }
3859       }
3860     }
3861   }
3862   Ghb5->Divide(Ghb51, Ghb50, 1, 1, "B");  // average A
3863   for (int i = 1; i <= nx; i++) {
3864     Ghb5->SetBinError(i, 0.0001);
3865   }
3866   Ghb5->SetMarkerStyle(20);
3867   Ghb5->SetMarkerSize(0.4);
3868   Ghb5->GetYaxis()->SetLabelSize(0.04);
3869   Ghb5->SetMarkerColor(2);
3870   Ghb5->SetLineColor(0);
3871   Ghb5->SetXTitle("        iLS  \b");
3872   Ghb5->SetYTitle("     <R> \b");
3873   Ghb5->SetTitle("<Ri> vs iLS \b");
3874   Ghb5->SetMinimum(0.);  //Ghb5->SetMaximum(2.5);
3875   //            gPad->SetLogy();
3876   gPad->SetGridy();
3877   gPad->SetGridx();
3878   Ghb5->SetStats(0);
3879   Ghb5->GetYaxis()->SetLabelSize(0.025);
3880   Ghb5->Draw("Error");
3881   //================
3882   cRBX31->cd(2);
3883   TH2F *Ghb60 = new TH2F("Ghb60", "", 22, -11., 11., 18, 0., 18.);
3884   TH2F *Ghb61 = new TH2F("Ghb61", "", 22, -11., 11., 18, 0., 18.);
3885   TH2F *Ghb6 = new TH2F("Ghb6", "", 22, -11., 11., 18, 0., 18.);
3886 
3887   TH2F *G20hb60 = new TH2F("G20hb60", "", 22, -11., 11., 18, 0., 18.);
3888   TH2F *G20hb61 = new TH2F("G20hb61", "", 22, -11., 11., 18, 0., 18.);
3889   TH2F *G20hb6 = new TH2F("G20hb6", "", 22, -11., 11., 18, 0., 18.);
3890   TH2F *G30hb60 = new TH2F("G30hb60", "", 22, -11., 11., 18, 0., 18.);
3891   TH2F *G30hb61 = new TH2F("G30hb61", "", 22, -11., 11., 18, 0., 18.);
3892   TH2F *G30hb6 = new TH2F("G30hb6", "", 22, -11., 11., 18, 0., 18.);
3893   TH2F *G40hb60 = new TH2F("G40hb60", "", 22, -11., 11., 18, 0., 18.);
3894   TH2F *G40hb61 = new TH2F("G40hb61", "", 22, -11., 11., 18, 0., 18.);
3895   TH2F *G40hb6 = new TH2F("G40hb6", "", 22, -11., 11., 18, 0., 18.);
3896   // j - etaphi index; i - # LSs;
3897   //
3898   // define mean and RMS:
3899   double sumjHB = 0.;
3900   int njHB = 0;
3901   double meanjHB = 0.;
3902   for (int j = 1; j <= ny; j++) {
3903     ccc0HB = Ghb1->GetBinContent(1, j);
3904     if (ccc0HB <= 0.)
3905       for (int i = 1; i <= nx; i++) {
3906         double ccc2 = Ghb1->GetBinContent(i, j);
3907         if (ccc2 > 0.) {
3908           ccc0HB = ccc2;
3909           break;
3910         }
3911       }
3912     if (ccc0HB > 0.) {
3913       for (int i = 1; i <= nx; i++) {
3914         double ccc1 = Ghb1->GetBinContent(i, j) / ccc0HB;
3915         if (ccc1 > 0.) {
3916           sumjHB += ccc1;
3917           njHB++;
3918         }
3919       }
3920       meanjHB = sumjHB / njHB;
3921     }
3922   }  // j
3923 
3924   double ssumjHB = 0.;
3925   njHB = 0;
3926   double sigmajHB = 0.;
3927   for (int j = 1; j <= ny; j++) {
3928     ccc0HB = Ghb1->GetBinContent(1, j);
3929     if (ccc0HB <= 0.)
3930       for (int i = 1; i <= nx; i++) {
3931         double ccc2 = Ghb1->GetBinContent(i, j);
3932         if (ccc2 > 0.) {
3933           ccc0HB = ccc2;
3934           break;
3935         }
3936       }
3937     if (ccc0HB > 0.) {
3938       for (int i = 1; i <= nx; i++) {
3939         double ccc1 = Ghb1->GetBinContent(i, j) / ccc0HB;
3940         if (ccc1 > 0.) {
3941           ssumjHB += (ccc1 - meanjHB) * (ccc1 - meanjHB);
3942           njHB++;
3943         }
3944       }
3945       sigmajHB = sqrt(ssumjHB / njHB);
3946     }
3947   }  // j
3948 
3949   double dif3rmsHBMIN = meanjHB - 3 * sigmajHB;
3950   if (dif3rmsHBMIN < 0.)
3951     dif3rmsHBMIN = 0.;
3952   double dif3rmsHBMAX = meanjHB + 3 * sigmajHB;
3953   cout << "22HB-2    meanjHB=  " << meanjHB << "  sigmajHB=  " << sigmajHB << "  dif3rmsHBMIN=  " << dif3rmsHBMIN
3954        << "  dif3rmsHBMAX=  " << dif3rmsHBMAX << endl;
3955 
3956   double MAXdif3rmsHBMIN = dif3rmsHBMIN;
3957   double MINdif3rmsHBMAX = dif3rmsHBMAX;
3958   if (MAXdif3rmsHBMIN < 0.95)
3959     MAXdif3rmsHBMIN = 0.95;
3960   if (MINdif3rmsHBMAX > 1.05)
3961     MINdif3rmsHBMAX = 1.05;
3962   cout << "22HB-2     MAXdif3rmsHBMIN=  " << MAXdif3rmsHBMIN << "     MINdif3rmsHBMAX=  " << MINdif3rmsHBMAX << endl;
3963   //
3964   for (int j = 1; j <= ny; j++) {
3965     ccc0HB = Ghb1->GetBinContent(1, j);
3966     if (ccc0HB <= 0.)
3967       for (int i = 1; i <= nx; i++) {
3968         double ccc2 = Ghb1->GetBinContent(i, j);
3969         if (ccc2 > 0.) {
3970           ccc0HB = ccc2;
3971           break;
3972         }
3973       }
3974     if (ccc0HB > 0.) {
3975       int jeta = (j - 1) / 18;         // jeta = 0-21
3976       int jphi = (j - 1) - 18 * jeta;  // jphi=0-17
3977       // i - # LSs:
3978       for (int i = 1; i <= nx; i++) {
3979         double ccc1 = Ghb1->GetBinContent(i, j);
3980         if (ccc1 > 0.) {
3981           double Rij = ccc1 / ccc0HB;
3982           if (Rij < MAXdif3rmsHBMIN || Rij > MINdif3rmsHBMAX) {
3983             Ghb61->Fill(jeta - 11, jphi, Rij);
3984             Ghb60->Fill(jeta - 11, jphi, 1.);
3985           }
3986           if (Rij < 0.8 || Rij > 1.2) {
3987             G20hb61->Fill(jeta - 11, jphi, Rij);
3988             G20hb60->Fill(jeta - 11, jphi, 1.);
3989           }
3990           if (Rij < 0.7 || Rij > 1.3) {
3991             G30hb61->Fill(jeta - 11, jphi, Rij);
3992             G30hb60->Fill(jeta - 11, jphi, 1.);
3993           }
3994           if (Rij < 0.6 || Rij > 1.4) {
3995             G40hb61->Fill(jeta - 11, jphi, Rij);
3996             G40hb60->Fill(jeta - 11, jphi, 1.);
3997           }
3998         }                                       //if(ccc1>0.
3999       }                                         // i
4000     }                                           //if(ccc0HB>0
4001   }                                             // j
4002   Ghb6->Divide(Ghb61, Ghb60, 1, 1, "B");        // average R
4003   G20hb6->Divide(G20hb61, G20hb60, 1, 1, "B");  // average R
4004   G30hb6->Divide(G30hb61, G30hb60, 1, 1, "B");  // average R
4005   G40hb6->Divide(G40hb61, G40hb60, 1, 1, "B");  // average R
4006 
4007   Ghb6->GetZaxis()->SetLabelSize(0.025);
4008   Ghb6->SetXTitle("             #eta  \b");
4009   Ghb6->SetYTitle("      #phi \b");
4010   Ghb6->SetTitle("<Rj> for |1-<R>| > 0.05 \b");
4011   Ghb6->SetStats(0);
4012   Ghb6->Draw("COLZ");
4013   //================
4014   cRBX31->cd(3);
4015   TH1F *Ghb7 = new TH1F("Ghb7", "", 120, 0.4, 1.6);
4016   // j - etaphi index:
4017   for (int j = 1; j <= ny; j++) {
4018     ccc0HB = Ghb1->GetBinContent(1, j);
4019     if (ccc0HB <= 0.)
4020       for (int i = 1; i <= nx; i++) {
4021         double ccc2 = Ghb1->GetBinContent(i, j);
4022         if (ccc2 > 0.) {
4023           ccc0HB = ccc2;
4024           break;
4025         }
4026       }
4027     if (ccc0HB > 0.) {
4028       // i - # LSs:
4029       for (int i = 1; i <= nx; i++) {
4030         double ccc1 = Ghb1->GetBinContent(i, j);
4031         if (ccc1 > 0.) {
4032           double Rij = ccc1 / ccc0HB;
4033           Ghb7->Fill(Rij);
4034         }
4035       }
4036     }
4037   }
4038   Ghb7->SetMarkerStyle(20);
4039   Ghb7->SetMarkerSize(0.4);
4040   Ghb7->GetYaxis()->SetLabelSize(0.04);
4041   Ghb7->SetMarkerColor(2);
4042   Ghb7->SetLineColor(0);
4043   Ghb7->SetYTitle("        N  \b");
4044   Ghb7->SetXTitle("     Rij \b");
4045   Ghb7->SetTitle(" Rij \b");
4046   //Ghb7->SetMinimum(0.8);Ghb7->SetMaximum(500.);
4047   gPad->SetGridy();
4048   gPad->SetGridx();  //            gPad->SetLogy();
4049   //      Ghb7->SetStats(1110000);
4050   Ghb7->GetYaxis()->SetLabelSize(0.025);
4051   Ghb7->Draw("Error");
4052   Float_t ymaxHB = Ghb7->GetMaximum();
4053   cout << "22HB-3   ymaxHB=  " << ymaxHB << "       MAXdif3rmsHBMIN=  " << MAXdif3rmsHBMIN
4054        << "         MINdif3rmsHBMAX=  " << MINdif3rmsHBMAX << endl;
4055   TLine *lineHB = new TLine(MAXdif3rmsHBMIN, 0., MAXdif3rmsHBMIN, ymaxHB);
4056   lineHB->SetLineColor(kBlue);
4057   lineHB->Draw();
4058   TLine *line1HB = new TLine(MINdif3rmsHBMAX, 0., MINdif3rmsHBMAX, ymaxHB);
4059   line1HB->SetLineColor(kBlue);
4060   line1HB->Draw();
4061   //================
4062   /////////////////
4063   cRBX31->Update();
4064   cRBX31->Print("RBX-HB-3plots.png");
4065   cRBX31->Clear();
4066   // clean-up
4067   if (Ghb5)
4068     delete Ghb5;
4069   if (Ghb60)
4070     delete Ghb60;
4071   if (Ghb61)
4072     delete Ghb61;
4073   if (Ghb6)
4074     delete Ghb6;
4075   if (Ghb7)
4076     delete Ghb7;
4077 
4078   if (G20hb60)
4079     delete G20hb60;
4080   if (G20hb61)
4081     delete G20hb61;
4082   if (G30hb60)
4083     delete G30hb60;
4084   if (G30hb61)
4085     delete G30hb61;
4086   if (G40hb60)
4087     delete G40hb60;
4088   if (G40hb61)
4089     delete G40hb61;
4090 
4091   if (Ghb1)
4092     delete Ghb1;
4093   //========================================================================================== 22-1   HB:: Ratio plots   jeta = 0 - 21       jphi =0 - 17
4094   //======================================================================
4095   //======================================================================28.11.2018
4096   //======================================================================
4097   //======================================================================
4098 
4099   gStyle->SetOptStat(1110000);
4100   cout << "      RBX HB  Ratio plotsmore *****" << endl;
4101   cRBX31->Clear();
4102   /////////////////
4103   cRBX31->Divide(3, 1);
4104   //================
4105   cRBX31->cd(1);
4106   G20hb6->GetZaxis()->SetLabelSize(0.025);
4107   G20hb6->SetXTitle("             #eta  \b");
4108   G20hb6->SetYTitle("      #phi \b");
4109   G20hb6->SetTitle("<Rj> for |1-<R>| > 0.20 \b");
4110   G20hb6->SetStats(0);
4111   G20hb6->Draw("COLZ");
4112   //================
4113   cRBX31->cd(2);
4114   G30hb6->GetZaxis()->SetLabelSize(0.025);
4115   G30hb6->SetXTitle("             #eta  \b");
4116   G30hb6->SetYTitle("      #phi \b");
4117   G30hb6->SetTitle("<Rj> for |1-<R>| > 0.30 \b");
4118   G30hb6->SetStats(0);
4119   G30hb6->Draw("COLZ");
4120   //================
4121   cRBX31->cd(3);
4122   G40hb6->GetZaxis()->SetLabelSize(0.025);
4123   G40hb6->SetXTitle("             #eta  \b");
4124   G40hb6->SetYTitle("      #phi \b");
4125   G40hb6->SetTitle("<Rj> for |1-<R>| > 0.40 \b");
4126   G40hb6->SetStats(0);
4127   G40hb6->Draw("COLZ");
4128   //================
4129 
4130   /////////////////
4131   cRBX31->Update();
4132   cRBX31->Print("RBX-HB-3plotsmore.png");
4133   cRBX31->Clear();
4134 
4135   // clean-up
4136   if (G20hb6)
4137     delete G20hb6;
4138   if (G30hb6)
4139     delete G30hb6;
4140   if (G40hb6)
4141     delete G40hb6;
4142   gStyle->SetOptStat(0);
4143 
4144   ////////////////////////////////////////////////////////////////////////////////////
4145 
4146   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
4147   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
4148   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
4149   for (int jphi = 0; jphi < njphi; jphi++) {
4150     for (int jeta = 0; jeta < njeta; jeta++) {
4151       for (int i = 0; i < nx; i++) {
4152         alexall[jeta][jphi][i] = 0.;
4153       }
4154     }
4155   }  // nulling
4156 
4157   ////////////////////////////////////////////////////////////////////////////////////   end HB RBX
4158 
4159   ////////////////////////////////////////////////////////////////////////////////////     HE::  HESTART HE: j = 3,4,5, 6, 7      14,15,16,17,18
4160   //======================================================================
4161   //======================================================================
4162   //======================================================================
4163   cout << " RBX general for HE **************************" << endl;
4164   TH2F *Ghe1KKK = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplEtaPhiLs1");
4165   TH2F *Ghe1LLL = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplEtaPhiLs10");
4166   TH2F *Ghe1 = (TH2F *)Ghe1LLL->Clone("Ghe1");
4167   Ghe1->Divide(Ghe1KKK, Ghe1LLL, 1, 1, "B");  // average A
4168   //    Ghe1->Sumw2();
4169   //      int nx = Ghe1->GetXaxis()->GetNbins(); // # LS
4170   //    nx = maxbinsRBX; // # LS
4171   ny = Ghe1->GetYaxis()->GetNbins();  // # jetaphi indexes
4172   for (int j = 1; j <= ny; j++) {
4173     int jeta = (j - 1) / njphi;  // jeta = 0-21
4174     if ((jeta < 8 && jeta > 2) || (jeta < 19 && jeta > 13)) {
4175       int jphi = (j - 1) - njphi * jeta;  // jphi=0-17
4176       //       cout<<"HE 54        jeta=     "<< jeta <<"   jphi   =     "<<jphi  <<endl;
4177       // over LS:
4178       for (int i = 1; i <= nx; i++) {
4179         double ccc1 = Ghe1->GetBinContent(i, j);
4180         alexall[jeta][jphi][i - 1] = ccc1;
4181         //       if( i == 1 ) cout<<"HE 54  for LS=1      ccc1=     "<< ccc1 <<endl;
4182       }  //i
4183     }    //if
4184   }      //j
4185   // clean-up
4186   if (Ghe1KKK)
4187     delete Ghe1KKK;
4188   if (Ghe1LLL)
4189     delete Ghe1LLL;
4190   //    if (Ghe1) delete Ghe1;
4191 
4192   //====================================================================== alexhe[k][i]
4193   for (int jphi = 0; jphi < njphi; jphi++) {
4194     for (int i = 0; i < nx; i++) {
4195       double sumccc1 = 0.;
4196       int isum = 0;
4197       for (int jeta = 0; jeta < njeta; jeta++) {
4198         double ccc1 = alexall[jeta][jphi][i];
4199         if (ccc1 > 0.) {
4200           sumccc1 += ccc1;
4201           isum++;
4202         }
4203       }  // for jeta
4204       if (isum > 0.)
4205         sumccc1 /= isum;
4206       alexhe[jphi][i] = sumccc1;
4207     }
4208   }  //for for
4209      //====================================================================== blexhe[k][i]
4210   for (int keta = 0; keta < njeta; keta++) {
4211     for (int i = 0; i < nx; i++) {
4212       double sumccc1 = 0.;
4213       int isum = 0;
4214       for (int kphi = 0; kphi < njphi; kphi++) {
4215         double ccc1 = alexall[keta][kphi][i];
4216         if (ccc1 > 0.) {
4217           sumccc1 += ccc1;
4218           isum++;
4219         }
4220       }  // for kphi
4221       if (isum > 0.)
4222         sumccc1 /= isum;
4223       blexhe[keta][i] = sumccc1;
4224     }
4225   }  //for for
4226   /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4227   //========================================================================================== 21   HE:: 2D  jeta = 0 - 21       jphi =0 - 17
4228   //======================================================================
4229   //======================================================================
4230   //======================================================================
4231   //======================================================================
4232   cout << "      RBX HE  2D plot *****" << endl;
4233   cRBX1->Clear();
4234   /////////////////
4235   cRBX1->Divide(1, 1);
4236   cRBX1->cd(1);
4237   // int ietaphi = 0; ietaphi = ((k2+1)-1)*nphi + (k3+1) ;  k2=0-neta-1; k3=0-nphi-1; neta=18; nphi=22;
4238   TH2F *Ghe42D = new TH2F("Ghe42D", "", 23, -11.5, 11.5, 18, 0., 18.);
4239   TH2F *Ghe42D0 = new TH2F("Ghe42D0", "", 23, -11.5, 11.5, 18, 0., 18.);
4240   //       TH2F* Ghe42D      = new TH2F("Ghe42D","",   22, -11., 11., 18, 0., 18. );
4241   //       TH2F* Ghe42D0     = new TH2F("Ghe42D0","",  22, -11., 11., 18, 0., 18. );
4242   TH2F *Ghe42DF = (TH2F *)Ghe42D0->Clone("Ghe42DF");
4243   for (int jphi = 0; jphi < njphi; jphi++) {
4244     for (int jeta = 0; jeta < njeta; jeta++) {
4245       for (int i = 0; i < nx; i++) {
4246         double ccc1 = alexall[jeta][jphi][i];
4247         int neweta = jeta - 11 - 0.5;
4248         if (jeta >= 11)
4249           neweta = jeta - 11 + 1.5;
4250         if (ccc1 > 0.) {
4251           Ghe42D->Fill(neweta, jphi, ccc1);
4252           Ghe42D0->Fill(neweta, jphi, 1.);
4253         }
4254         //       if(ccc1>0.) {Ghe42D ->Fill(jeta-11,jphi,ccc1); Ghe42D0 ->Fill(jeta-11,jphi,1.); }
4255       }
4256     }
4257   }
4258   Ghe42DF->Divide(Ghe42D, Ghe42D0, 1, 1, "B");  // average A
4259   //    Ghe1->Sumw2();
4260   gPad->SetGridy();
4261   gPad->SetGridx();  //      gPad->SetLogz();
4262   Ghe42DF->SetMarkerStyle(20);
4263   Ghe42DF->SetMarkerSize(0.4);
4264   Ghe42DF->GetZaxis()->SetLabelSize(0.04);
4265   Ghe42DF->SetXTitle("<A>_RBX         #eta  \b");
4266   Ghe42DF->SetYTitle("      #phi \b");
4267   Ghe42DF->SetZTitle("<A>_RBX  - All \b");
4268   Ghe42DF->SetMarkerColor(2);
4269   Ghe42DF->SetLineColor(2);  //      Ghe42DF->SetMaximum(1.000);  //      Ghe42DF->SetMinimum(1.0);
4270   Ghe42DF->Draw("COLZ");
4271 
4272   /////////////////
4273   cRBX1->Update();
4274   cRBX1->Print("RBX-HE-2Dplot.png");
4275   cRBX1->Clear();
4276   // clean-up
4277   if (Ghe42D)
4278     delete Ghe42D;
4279   if (Ghe42D0)
4280     delete Ghe42D0;
4281   if (Ghe42DF)
4282     delete Ghe42DF;
4283 
4284   //========================================================================================== 61   HE:: 1D  j = 3,4,5, 6, 7      14,15,16,17,18         jphi =0 - 17
4285   //======================================================================
4286   //======================================================================
4287   //======================================================================
4288   //======================================================================
4289   cout << "      RBX HE  1D plot *****" << endl;
4290   cRBX1->Clear();
4291   /////////////////
4292   cRBX1->Divide(1, 1);
4293   cRBX1->cd(1);
4294   TH1F *GphiHE1D = new TH1F("GphiHE1D", "", 18, 0., 18.);
4295   TH1F *GphiHE1D0 = new TH1F("GphiHE1D0", "", 18, 0., 18.);
4296   TH1F *GphiHE1DF = (TH1F *)GphiHE1D0->Clone("GphiHE1DF");
4297   for (int jphi = 0; jphi < 18; jphi++) {
4298     for (int jeta = 0; jeta < 22; jeta++) {
4299       for (int i = 0; i < nx; i++) {
4300         double ccc1 = alexall[jeta][jphi][i];
4301         if (ccc1 > 0.) {
4302           GphiHE1D->Fill(jphi, ccc1);
4303           GphiHE1D0->Fill(jphi, 1.);
4304         }
4305       }
4306     }
4307   }
4308   //     GphiHE1D->Sumw2();GphiHE1D0->Sumw2();
4309   GphiHE1DF->Divide(GphiHE1D, GphiHE1D0, 1, 1, "B");  // average A
4310                                                       //     GphiHE1DF->Sumw2();
4311   for (int jphi = 1; jphi < 19; jphi++) {
4312     GphiHE1DF->SetBinError(jphi, 0.01);
4313   }
4314   gPad->SetGridy();
4315   gPad->SetGridx();  //      gPad->SetLogz();
4316   GphiHE1DF->SetMarkerStyle(20);
4317   GphiHE1DF->SetMarkerSize(1.4);
4318   GphiHE1DF->GetZaxis()->SetLabelSize(0.08);
4319   GphiHE1DF->SetXTitle("PHI of RBX\b");
4320   GphiHE1DF->SetYTitle(" <Amplitude> \b");
4321   GphiHE1DF->SetZTitle("<A>_PHI  - All \b");
4322   GphiHE1DF->SetMarkerColor(4);
4323   GphiHE1DF->SetLineColor(4);
4324   GphiHE1DF->SetMinimum(0.8);  //      GphiHE1DF->SetMaximum(1.000);
4325   GphiHE1DF->Draw("Error");
4326   /////////////////
4327   cRBX1->Update();
4328   cRBX1->Print("RBX-HE-1Dplot.png");
4329   cRBX1->Clear();
4330   // clean-up
4331   if (GphiHE1D)
4332     delete GphiHE1D;
4333   if (GphiHE1D0)
4334     delete GphiHE1D0;
4335   if (GphiHE1DF)
4336     delete GphiHE1DF;
4337 
4338   //========================================================================================== 62   HE:: 1D  j = 3,4,5, 6, 7      14,15,16,17,18        jphi =0 - 17
4339   //======================================================================
4340   //======================================================================
4341   //======================================================================
4342   //======================================================================
4343   cout << "      RBX HE 11D plot *eta*" << endl;
4344   cRBX1->Clear();
4345   /////////////////
4346   cRBX1->Divide(1, 1);
4347   cRBX1->cd(1);
4348   TH1F *GetaHE11D = new TH1F("GetaHE11D", "", 23, -11.5, 11.5);
4349   TH1F *GetaHE11D0 = new TH1F("GetaHE11D0", "", 23, -11.5, 11.5);
4350   TH1F *GetaHE11DF = (TH1F *)GetaHE11D0->Clone("GetaHE11DF");
4351 
4352   for (int jeta = 0; jeta < 22; jeta++) {
4353     for (int jphi = 0; jphi < 18; jphi++) {
4354       for (int i = 0; i < nx; i++) {
4355         double ccc1 = alexall[jeta][jphi][i];
4356         int neweta = jeta - 11 - 0.5;
4357         if (jeta >= 11)
4358           neweta = jeta - 11 + 1.5;
4359         if (ccc1 > 0.) {
4360           GetaHE11D->Fill(neweta, ccc1);
4361           GetaHE11D0->Fill(neweta, 1.);
4362           //           if( i == 0 ) cout<<"62  HE:  ibin=  "<< i <<"      jphi= "<< jphi <<"      jeta= "<< jeta <<"      A= "<< ccc1 <<endl;
4363         }
4364       }
4365     }
4366   }
4367   //     GetaHE11D->Sumw2();GetaHE11D0->Sumw2();
4368   GetaHE11DF->Divide(GetaHE11D, GetaHE11D0, 1, 1, "B");  // average A
4369                                                          //     GetaHE11DF->Sumw2();
4370   for (int jeta = 1; jeta < 24; jeta++) {
4371     GetaHE11DF->SetBinError(jeta, 0.01);
4372   }
4373   gPad->SetGridy();
4374   gPad->SetGridx();  //      gPad->SetLogz();
4375   GetaHE11DF->SetMarkerStyle(20);
4376   GetaHE11DF->SetMarkerSize(1.4);
4377   GetaHE11DF->GetZaxis()->SetLabelSize(0.08);
4378   GetaHE11DF->SetXTitle("#eta  \b");
4379   GetaHE11DF->SetYTitle("  <A> \b");
4380   GetaHE11DF->SetZTitle("<A>_ETA  - All \b");
4381   GetaHE11DF->SetMarkerColor(4);
4382   GetaHE11DF->SetLineColor(4);
4383   GetaHE11DF->SetMinimum(0.8);  //      GetaHE11DF->SetMaximum(1.000);
4384   GetaHE11DF->Draw("Error");
4385 
4386   /////////////////
4387   cRBX1->Update();
4388   cRBX1->Print("RBX-HE-11Dplot.png");
4389   cRBX1->Clear();
4390   // clean-up
4391   if (GetaHE11D)
4392     delete GetaHE11D;
4393   if (GetaHE11D0)
4394     delete GetaHE11D0;
4395   if (GetaHE11DF)
4396     delete GetaHE11DF;
4397 
4398   //========================================================================================== 22   HE:: Ratio plots   jeta = 0 - 21       jphi =0 - 17
4399   //======================================================================
4400   //======================================================================22.11.2018
4401   //======================================================================
4402   //======================================================================
4403 
4404   gStyle->SetOptStat(1110000);
4405   cout << "      RBX HE  Ratio plots *****" << endl;
4406   cRBX31->Clear();
4407   /////////////////
4408   // gain stabilitY:
4409   // Rij = Aij / A1j , where i-over LSs, j-channels
4410   //
4411   //    nx = maxbinsRBX; // # LS
4412   //
4413   double ccc0HE = 0.;
4414   cRBX31->Divide(3, 1);
4415   //================
4416   cRBX31->cd(1);
4417   //      TH1F* Ghe5 = new TH1F("Ghe5","", nx, 1., nx+1.);
4418   TH1F *Ghe51 = new TH1F("Ghe51", "", nx, 1., nx + 1.);
4419   TH1F *Ghe50 = new TH1F("Ghe50", "", nx, 1., nx + 1.);
4420   TH1F *Ghe5 = (TH1F *)Ghe50->Clone("Ghe5");
4421   // j - etaphi index:
4422   for (int j = 1; j <= ny; j++) {
4423     ccc0HE = Ghe1->GetBinContent(1, j);
4424     //  if(ccc0HE <=0.) for (int i=1;i<=nx;i++) {double ccc2 =  Ghe1->GetBinContent(i,j);if(ccc2>0.){ccc0HE=ccc2;cout<<"!!! ccc0HE= "<<ccc0HE<<endl;break;} }
4425     if (ccc0HE <= 0.)
4426       for (int i = 1; i <= nx; i++) {
4427         double ccc2 = Ghe1->GetBinContent(i, j);
4428         if (ccc2 > 0.) {
4429           ccc0HE = ccc2;
4430           break;
4431         }
4432       }
4433     if (ccc0HE > 0.) {
4434       // i - # LSs:
4435       for (int i = 1; i <= nx; i++) {
4436         double ccc1 = Ghe1->GetBinContent(i, j);
4437         if (ccc1 > 0.) {
4438           double Rij = ccc1 / ccc0HE;
4439           //          Ghe5 ->Fill( float(i), Rij);
4440           Ghe51->Fill(float(i), Rij);
4441           Ghe50->Fill(float(i), 1.);
4442         }
4443       }
4444     }
4445   }
4446   Ghe5->Divide(Ghe51, Ghe50, 1, 1, "B");  // average A
4447   for (int i = 1; i <= nx; i++) {
4448     Ghe5->SetBinError(i, 0.0001);
4449   }
4450   Ghe5->SetMarkerStyle(20);
4451   Ghe5->SetMarkerSize(0.4);
4452   Ghe5->GetYaxis()->SetLabelSize(0.04);
4453   Ghe5->SetMarkerColor(2);
4454   Ghe5->SetLineColor(0);
4455   Ghe5->SetXTitle("        iLS  \b");
4456   Ghe5->SetYTitle("     <R> \b");
4457   Ghe5->SetTitle("<Ri> vs iLS \b");
4458   Ghe5->SetMinimum(0.);  //Ghe5->SetMaximum(2.5);
4459   //            gPad->SetLogy();
4460   gPad->SetGridy();
4461   gPad->SetGridx();
4462   Ghe5->SetStats(0);
4463   Ghe5->GetYaxis()->SetLabelSize(0.025);
4464   Ghe5->Draw("Error");
4465   //================
4466   cRBX31->cd(2);
4467   TH2F *Ghe60 = new TH2F("Ghe60", "", 22, -11., 11., 18, 0., 18.);
4468   TH2F *Ghe61 = new TH2F("Ghe61", "", 22, -11., 11., 18, 0., 18.);
4469   TH2F *Ghe6 = new TH2F("Ghe6", "", 22, -11., 11., 18, 0., 18.);
4470 
4471   TH2F *G20he60 = new TH2F("G20he60", "", 22, -11., 11., 18, 0., 18.);
4472   TH2F *G20he61 = new TH2F("G20he61", "", 22, -11., 11., 18, 0., 18.);
4473   TH2F *G20he6 = new TH2F("G20he6", "", 22, -11., 11., 18, 0., 18.);
4474   TH2F *G30he60 = new TH2F("G30he60", "", 22, -11., 11., 18, 0., 18.);
4475   TH2F *G30he61 = new TH2F("G30he61", "", 22, -11., 11., 18, 0., 18.);
4476   TH2F *G30he6 = new TH2F("G30he6", "", 22, -11., 11., 18, 0., 18.);
4477   TH2F *G40he60 = new TH2F("G40he60", "", 22, -11., 11., 18, 0., 18.);
4478   TH2F *G40he61 = new TH2F("G40he61", "", 22, -11., 11., 18, 0., 18.);
4479   TH2F *G40he6 = new TH2F("G40he6", "", 22, -11., 11., 18, 0., 18.);
4480   // j - etaphi index; i - # LSs;
4481   //
4482   // define mean and RMS:
4483   double sumjHE = 0.;
4484   int njHE = 0;
4485   double meanjHE = 0.;
4486   for (int j = 1; j <= ny; j++) {
4487     ccc0HE = Ghe1->GetBinContent(1, j);
4488     if (ccc0HE <= 0.)
4489       for (int i = 1; i <= nx; i++) {
4490         double ccc2 = Ghe1->GetBinContent(i, j);
4491         if (ccc2 > 0.) {
4492           ccc0HE = ccc2;
4493           break;
4494         }
4495       }
4496     if (ccc0HE > 0.) {
4497       for (int i = 1; i <= nx; i++) {
4498         double ccc1 = Ghe1->GetBinContent(i, j) / ccc0HE;
4499         if (ccc1 > 0.) {
4500           sumjHE += ccc1;
4501           njHE++;
4502         }
4503       }
4504       meanjHE = sumjHE / njHE;
4505     }
4506   }  // j
4507 
4508   double ssumjHE = 0.;
4509   njHE = 0;
4510   double sigmajHE = 0.;
4511   for (int j = 1; j <= ny; j++) {
4512     ccc0HE = Ghe1->GetBinContent(1, j);
4513     if (ccc0HE <= 0.)
4514       for (int i = 1; i <= nx; i++) {
4515         double ccc2 = Ghe1->GetBinContent(i, j);
4516         if (ccc2 > 0.) {
4517           ccc0HE = ccc2;
4518           break;
4519         }
4520       }
4521     if (ccc0HE > 0.) {
4522       for (int i = 1; i <= nx; i++) {
4523         double ccc1 = Ghe1->GetBinContent(i, j) / ccc0HE;
4524         if (ccc1 > 0.) {
4525           ssumjHE += (ccc1 - meanjHE) * (ccc1 - meanjHE);
4526           njHE++;
4527         }
4528       }
4529       sigmajHE = sqrt(ssumjHE / njHE);
4530     }
4531   }  // j
4532 
4533   double dif3rmsHEMIN = meanjHE - 3 * sigmajHE;
4534   if (dif3rmsHEMIN < 0.)
4535     dif3rmsHEMIN = 0.;
4536   double dif3rmsHEMAX = meanjHE + 3 * sigmajHE;
4537   cout << "22HE-2    meanjHE=  " << meanjHE << "  sigmajHE=  " << sigmajHE << "  dif3rmsHEMIN=  " << dif3rmsHEMIN
4538        << "  dif3rmsHEMAX=  " << dif3rmsHEMAX << endl;
4539 
4540   double MAXdif3rmsHEMIN = dif3rmsHEMIN;
4541   double MINdif3rmsHEMAX = dif3rmsHEMAX;
4542   if (MAXdif3rmsHEMIN < 0.95)
4543     MAXdif3rmsHEMIN = 0.95;
4544   if (MINdif3rmsHEMAX > 1.05)
4545     MINdif3rmsHEMAX = 1.05;
4546   cout << "22HE-2     MAXdif3rmsHEMIN=  " << MAXdif3rmsHEMIN << "     MINdif3rmsHEMAX=  " << MINdif3rmsHEMAX << endl;
4547   //
4548   for (int j = 1; j <= ny; j++) {
4549     ccc0HE = Ghe1->GetBinContent(1, j);
4550     if (ccc0HE <= 0.)
4551       for (int i = 1; i <= nx; i++) {
4552         double ccc2 = Ghe1->GetBinContent(i, j);
4553         if (ccc2 > 0.) {
4554           ccc0HE = ccc2;
4555           break;
4556         }
4557       }
4558     if (ccc0HE > 0.) {
4559       int jeta = (j - 1) / 18;         // jeta = 0-21
4560       int jphi = (j - 1) - 18 * jeta;  // jphi=0-17
4561       // i - # LSs:
4562       for (int i = 1; i <= nx; i++) {
4563         double ccc1 = Ghe1->GetBinContent(i, j);
4564         if (ccc1 > 0.) {
4565           double Rij = ccc1 / ccc0HE;
4566           if (Rij < MAXdif3rmsHEMIN || Rij > MINdif3rmsHEMAX) {
4567             Ghe61->Fill(jeta - 11, jphi, Rij);
4568             Ghe60->Fill(jeta - 11, jphi, 1.);
4569           }
4570           if (Rij < 0.8 || Rij > 1.2) {
4571             G20he61->Fill(jeta - 11, jphi, Rij);
4572             G20he60->Fill(jeta - 11, jphi, 1.);
4573           }
4574           if (Rij < 0.7 || Rij > 1.3) {
4575             G30he61->Fill(jeta - 11, jphi, Rij);
4576             G30he60->Fill(jeta - 11, jphi, 1.);
4577           }
4578           if (Rij < 0.6 || Rij > 1.4) {
4579             G40he61->Fill(jeta - 11, jphi, Rij);
4580             G40he60->Fill(jeta - 11, jphi, 1.);
4581           }
4582         }                                       //if(ccc1>0.
4583       }                                         // i
4584     }                                           //if(ccc0HE>0
4585   }                                             // j
4586   Ghe6->Divide(Ghe61, Ghe60, 1, 1, "B");        // average R
4587   G20he6->Divide(G20he61, G20he60, 1, 1, "B");  // average R
4588   G30he6->Divide(G30he61, G30he60, 1, 1, "B");  // average R
4589   G40he6->Divide(G40he61, G40he60, 1, 1, "B");  // average R
4590 
4591   //      Ghe6->SetLabelOffset (Float_t offset=0.005, Option_t *axis="X")//Set offset between axis and axis' labels
4592   //      Ghe6->GetZaxis()->SetLabelOffset(-0.05);
4593   Ghe6->GetZaxis()->SetLabelSize(0.025);
4594 
4595   Ghe6->SetXTitle("             #eta  \b");
4596   Ghe6->SetYTitle("      #phi \b");
4597   Ghe6->SetTitle(
4598       "<Rj> for |1-<R>| > 0.05 \b");  //      Ghe6->SetMaximum(1.000);  //      Ghe6->SetMinimum(1.0); //Ghe6->SetZTitle("Rij averaged over LSs \b"); //Ghe6->GetZaxis()->SetLabelSize(0.04); //Ghe6->SetMarkerStyle(20);// Ghe6->SetMarkerSize(0.4);//Ghe6->SetMarkerColor(2); //Ghe6->SetLineColor(2);
4599   //gStyle->SetOptStat(kFALSE);
4600   Ghe6->SetStats(0);
4601   Ghe6->Draw("COLZ");
4602   //================
4603   cRBX31->cd(3);
4604   TH1F *Ghe7 = new TH1F("Ghe7", "", 120, 0.4, 1.6);
4605   // j - etaphi index:
4606   for (int j = 1; j <= ny; j++) {
4607     ccc0HE = Ghe1->GetBinContent(1, j);
4608     if (ccc0HE <= 0.)
4609       for (int i = 1; i <= nx; i++) {
4610         double ccc2 = Ghe1->GetBinContent(i, j);
4611         if (ccc2 > 0.) {
4612           ccc0HE = ccc2;
4613           break;
4614         }
4615       }
4616     if (ccc0HE > 0.) {
4617       // i - # LSs:
4618       for (int i = 1; i <= nx; i++) {
4619         double ccc1 = Ghe1->GetBinContent(i, j);
4620         if (ccc1 > 0.) {
4621           double Rij = ccc1 / ccc0HE;
4622           Ghe7->Fill(Rij);
4623         }
4624       }
4625     }
4626   }
4627   Ghe7->SetMarkerStyle(20);
4628   Ghe7->SetMarkerSize(0.4);
4629   Ghe7->GetYaxis()->SetLabelSize(0.04);
4630   Ghe7->SetMarkerColor(2);
4631   Ghe7->SetLineColor(0);
4632   Ghe7->SetYTitle("        N  \b");
4633   Ghe7->SetXTitle("     Rij \b");
4634   Ghe7->SetTitle(" Rij \b");
4635   //Ghe7->SetMinimum(0.8);Ghe7->SetMaximum(500.);
4636   gPad->SetGridy();
4637   gPad->SetGridx();  //            gPad->SetLogy();
4638   //      Ghe7->SetStats(1110000);
4639   Ghe7->GetYaxis()->SetLabelSize(0.025);
4640   Ghe7->Draw("Error");
4641   Float_t ymaxHE = Ghe7->GetMaximum();
4642   cout << "22HE-3   ymaxHE=  " << ymaxHE << "       MAXdif3rmsHEMIN=  " << MAXdif3rmsHEMIN
4643        << "         MINdif3rmsHEMAX=  " << MINdif3rmsHEMAX << endl;
4644   TLine *lineHE = new TLine(MAXdif3rmsHEMIN, 0., MAXdif3rmsHEMIN, ymaxHE);
4645   lineHE->SetLineColor(kBlue);
4646   lineHE->Draw();
4647   TLine *line1HE = new TLine(MINdif3rmsHEMAX, 0., MINdif3rmsHEMAX, ymaxHE);
4648   line1HE->SetLineColor(kBlue);
4649   line1HE->Draw();
4650   //================
4651   /////////////////
4652   cRBX31->Update();
4653   cRBX31->Print("RBX-HE-3plots.png");
4654   cRBX31->Clear();
4655   // clean-up
4656   if (Ghe5)
4657     delete Ghe5;
4658   if (Ghe60)
4659     delete Ghe60;
4660   if (Ghe61)
4661     delete Ghe61;
4662   if (Ghe6)
4663     delete Ghe6;
4664   if (Ghe7)
4665     delete Ghe7;
4666 
4667   if (G20he60)
4668     delete G20he60;
4669   if (G20he61)
4670     delete G20he61;
4671   if (G30he60)
4672     delete G30he60;
4673   if (G30he61)
4674     delete G30he61;
4675   if (G40he60)
4676     delete G40he60;
4677   if (G40he61)
4678     delete G40he61;
4679 
4680   if (Ghe1)
4681     delete Ghe1;
4682   //========================================================================================== 22-1   HE:: Ratio plots   jeta = 0 - 21       jphi =0 - 17
4683   //======================================================================
4684   //======================================================================28.11.2018
4685   //======================================================================
4686   //======================================================================
4687 
4688   gStyle->SetOptStat(1110000);
4689   cout << "      RBX HE  Ratio plotsmore *****" << endl;
4690   cRBX31->Clear();
4691   /////////////////
4692   cRBX31->Divide(3, 1);
4693   //================
4694   cRBX31->cd(1);
4695   G20he6->GetZaxis()->SetLabelSize(0.025);
4696   G20he6->SetXTitle("             #eta  \b");
4697   G20he6->SetYTitle("      #phi \b");
4698   G20he6->SetTitle("<Rj> for |1-<R>| > 0.20 \b");
4699   G20he6->SetStats(0);
4700   G20he6->Draw("COLZ");
4701   //================
4702   cRBX31->cd(2);
4703   G30he6->GetZaxis()->SetLabelSize(0.025);
4704   G30he6->SetXTitle("             #eta  \b");
4705   G30he6->SetYTitle("      #phi \b");
4706   G30he6->SetTitle("<Rj> for |1-<R>| > 0.30 \b");
4707   G30he6->SetStats(0);
4708   G30he6->Draw("COLZ");
4709   //================
4710   cRBX31->cd(3);
4711   G40he6->GetZaxis()->SetLabelSize(0.025);
4712   G40he6->SetXTitle("             #eta  \b");
4713   G40he6->SetYTitle("      #phi \b");
4714   G40he6->SetTitle("<Rj> for |1-<R>| > 0.40 \b");
4715   G40he6->SetStats(0);
4716   G40he6->Draw("COLZ");
4717   //================
4718 
4719   /////////////////
4720   cRBX31->Update();
4721   cRBX31->Print("RBX-HE-3plotsmore.png");
4722   cRBX31->Clear();
4723 
4724   // clean-up
4725   if (G20he6)
4726     delete G20he6;
4727   if (G30he6)
4728     delete G30he6;
4729   if (G40he6)
4730     delete G40he6;
4731   gStyle->SetOptStat(0);
4732   ////////////////////////////////////////////////////////////////////////////////////
4733 
4734   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
4735   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
4736   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
4737   for (int jphi = 0; jphi < njphi; jphi++) {
4738     for (int jeta = 0; jeta < njeta; jeta++) {
4739       for (int i = 0; i < nx; i++) {
4740         alexall[jeta][jphi][i] = 0.;
4741       }
4742     }
4743   }  // nulling
4744 
4745   ////////////////////////////////////////////////////////////////////////////////////   end HE RBX
4746 
4747   ////////////////////////////////////////////////////////////////////////////////////     HO::  HOSTART HO: j = 7,8,9,10            11,12,13,14
4748   //======================================================================
4749   //======================================================================
4750   //======================================================================
4751   cout << " RBX general for HO **************************" << endl;
4752   TH2F *Gho1KKK = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplEtaPhiLs2");
4753   TH2F *Gho1LLL = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplEtaPhiLs20");
4754   TH2F *Gho1 = (TH2F *)Gho1LLL->Clone("Gho1");
4755   Gho1->Divide(Gho1KKK, Gho1LLL, 1, 1, "B");  // average A
4756   //    Gho1->Sumw2();
4757   //      int nx = Gho1->GetXaxis()->GetNbins(); // # LS
4758   //    nx = maxbinsRBX; // # LS
4759   ny = Gho1->GetYaxis()->GetNbins();  // # jetaphi indexes
4760   for (int j = 1; j <= ny; j++) {
4761     int jeta = (j - 1) / njphi;  // jeta = 0-21
4762     if (jeta < 15 && jeta > 6) {
4763       int jphi = (j - 1) - njphi * jeta;  // jphi=0-17
4764       //       cout<<"HO 54        jeta=     "<< jeta <<"   jphi   =     "<<jphi  <<endl;
4765       // over LS:
4766       for (int i = 1; i <= nx; i++) {
4767         double ccc1 = Gho1->GetBinContent(i, j);
4768         alexall[jeta][jphi][i - 1] = ccc1;
4769         //       if( i == 1 ) cout<<"HO 54  for LS=1      ccc1=     "<< ccc1 <<endl;
4770       }  //i
4771     }    //if
4772   }      //j
4773   // clean-up
4774   if (Gho1KKK)
4775     delete Gho1KKK;
4776   if (Gho1LLL)
4777     delete Gho1LLL;
4778   //    if (Gho1) delete Gho1;
4779 
4780   //====================================================================== alexho[k][i]
4781   for (int jphi = 0; jphi < njphi; jphi++) {
4782     for (int i = 0; i < nx; i++) {
4783       double sumccc1 = 0.;
4784       int isum = 0;
4785       for (int jeta = 0; jeta < njeta; jeta++) {
4786         double ccc1 = alexall[jeta][jphi][i];
4787         if (ccc1 > 0.) {
4788           sumccc1 += ccc1;
4789           isum++;
4790         }
4791       }  // for jeta
4792       if (isum > 0.)
4793         sumccc1 /= isum;
4794       alexho[jphi][i] = sumccc1;
4795     }
4796   }  //for for
4797      //====================================================================== blexho[k][i]
4798   for (int keta = 0; keta < njeta; keta++) {
4799     for (int i = 0; i < nx; i++) {
4800       double sumccc1 = 0.;
4801       int isum = 0;
4802       for (int kphi = 0; kphi < njphi; kphi++) {
4803         double ccc1 = alexall[keta][kphi][i];
4804         if (ccc1 > 0.) {
4805           sumccc1 += ccc1;
4806           isum++;
4807         }
4808       }  // for kphi
4809       if (isum > 0.)
4810         sumccc1 /= isum;
4811       blexho[keta][i] = sumccc1;
4812     }
4813   }  //for for
4814 
4815   /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4816   //========================================================================================== 33   HO:: 2D  jeta = 0 - 21       jphi =0 - 17
4817   //======================================================================
4818   //======================================================================
4819   //======================================================================
4820   //======================================================================
4821   cout << "      RBX HO  2D plot *****" << endl;
4822   cRBX1->Clear();
4823   /////////////////
4824   cRBX1->Divide(1, 1);
4825   cRBX1->cd(1);
4826   // int ietaphi = 0; ietaphi = ((k2+1)-1)*nphi + (k3+1) ;  k2=0-neta-1; k3=0-nphi-1; neta=18; nphi=22;
4827   TH2F *Gho42D = new TH2F("Gho42D", "", 23, -11.5, 11.5, 18, 0., 18.);
4828   TH2F *Gho42D0 = new TH2F("Gho42D0", "", 23, -11.5, 11.5, 18, 0., 18.);
4829   //     TH2F* Gho42D      = new TH2F("Gho42D","",   22, -11., 11., 18, 0., 18. );
4830   //     TH2F* Gho42D0     = new TH2F("Gho42D0","",  22, -11., 11., 18, 0., 18. );
4831   TH2F *Gho42DF = (TH2F *)Gho42D0->Clone("Gho42DF");
4832   for (int jphi = 0; jphi < njphi; jphi++) {
4833     for (int jeta = 0; jeta < njeta; jeta++) {
4834       for (int i = 0; i < nx; i++) {
4835         double ccc1 = alexall[jeta][jphi][i];
4836         int neweta = jeta - 11 - 0.5;
4837         if (jeta >= 11)
4838           neweta = jeta - 11 + 1.5;
4839         if (ccc1 > 0.) {
4840           Gho42D->Fill(neweta, jphi, ccc1);
4841           Gho42D0->Fill(neweta, jphi, 1.);
4842         }
4843         //       if(ccc1>0.) {Gho42D ->Fill(jeta-11,jphi,ccc1); Gho42D0 ->Fill(jeta-11,jphi,1.); }
4844       }
4845     }
4846   }
4847   Gho42DF->Divide(Gho42D, Gho42D0, 1, 1, "B");  // average A
4848   //    Gho1->Sumw2();
4849   gPad->SetGridy();
4850   gPad->SetGridx();  //      gPad->SetLogz();
4851   Gho42DF->SetMarkerStyle(20);
4852   Gho42DF->SetMarkerSize(0.4);
4853   Gho42DF->GetZaxis()->SetLabelSize(0.04);
4854   Gho42DF->SetXTitle("<A>_RBX         #eta  \b");
4855   Gho42DF->SetYTitle("      #phi \b");
4856   Gho42DF->SetZTitle("<A>_RBX  - All \b");
4857   Gho42DF->SetMarkerColor(2);
4858   Gho42DF->SetLineColor(2);  //      Gho42DF->SetMaximum(1.000);  //      Gho42DF->SetMinimum(1.0);
4859   Gho42DF->Draw("COLZ");
4860 
4861   /////////////////
4862   cRBX1->Update();
4863   cRBX1->Print("RBX-HO-2Dplot.png");
4864   cRBX1->Clear();
4865   // clean-up
4866   if (Gho42D)
4867     delete Gho42D;
4868   if (Gho42D0)
4869     delete Gho42D0;
4870   if (Gho42DF)
4871     delete Gho42DF;
4872 
4873   //========================================================================================== 61   HO:: 1D  j = 7,8,9,10 ; 11,12,13,14       jphi =0 - 17
4874   //======================================================================
4875   //======================================================================
4876   //======================================================================
4877   //======================================================================
4878   cout << "      RBX HO  1D plot *****" << endl;
4879   cRBX1->Clear();
4880   /////////////////
4881   cRBX1->Divide(1, 1);
4882   cRBX1->cd(1);
4883   TH1F *GphiHO1D = new TH1F("GphiHO1D", "", 18, 0., 18.);
4884   TH1F *GphiHO1D0 = new TH1F("GphiHO1D0", "", 18, 0., 18.);
4885   TH1F *GphiHO1DF = (TH1F *)GphiHO1D0->Clone("GphiHO1DF");
4886   for (int jphi = 0; jphi < 18; jphi++) {
4887     for (int jeta = 0; jeta < 22; jeta++) {
4888       for (int i = 0; i < nx; i++) {
4889         double ccc1 = alexall[jeta][jphi][i];
4890         if (ccc1 > 0.) {
4891           GphiHO1D->Fill(jphi, ccc1);
4892           GphiHO1D0->Fill(jphi, 1.);
4893         }
4894       }
4895     }
4896   }
4897   //     GphiHO1D->Sumw2();GphiHO1D0->Sumw2();
4898   GphiHO1DF->Divide(GphiHO1D, GphiHO1D0, 1, 1, "B");  // average A
4899                                                       //     GphiHO1DF->Sumw2();
4900   for (int jphi = 1; jphi < 19; jphi++) {
4901     GphiHO1DF->SetBinError(jphi, 0.01);
4902   }
4903   gPad->SetGridy();
4904   gPad->SetGridx();  //      gPad->SetLogz();
4905   GphiHO1DF->SetMarkerStyle(20);
4906   GphiHO1DF->SetMarkerSize(1.4);
4907   GphiHO1DF->GetZaxis()->SetLabelSize(0.08);
4908   GphiHO1DF->SetXTitle("PHI of RBX\b");
4909   GphiHO1DF->SetYTitle(" <Amplitude> \b");
4910   GphiHO1DF->SetZTitle("<A>_PHI  - All \b");
4911   GphiHO1DF->SetMarkerColor(4);
4912   GphiHO1DF->SetLineColor(4);
4913   GphiHO1DF->SetMinimum(0.8);  //      GphiHO1DF->SetMaximum(1.000);
4914   GphiHO1DF->Draw("Error");
4915   /////////////////
4916   cRBX1->Update();
4917   cRBX1->Print("RBX-HO-1Dplot.png");
4918   cRBX1->Clear();
4919   // clean-up
4920   if (GphiHO1D)
4921     delete GphiHO1D;
4922   if (GphiHO1D0)
4923     delete GphiHO1D0;
4924   if (GphiHO1DF)
4925     delete GphiHO1DF;
4926 
4927   //========================================================================================== 62   HO:: 1D  j = 7,8,9,10 ; 11,12,13,14       jphi =0 - 17
4928   //======================================================================
4929   //======================================================================
4930   //======================================================================
4931   //======================================================================
4932   cout << "      RBX HO 11D plot *eta*" << endl;
4933   cRBX1->Clear();
4934   /////////////////
4935   cRBX1->Divide(1, 1);
4936   cRBX1->cd(1);
4937   TH1F *GetaHO11D = new TH1F("GetaHO11D", "", 23, -11.5, 11.5);
4938   TH1F *GetaHO11D0 = new TH1F("GetaHO11D0", "", 23, -11.5, 11.5);
4939   TH1F *GetaHO11DF = (TH1F *)GetaHO11D0->Clone("GetaHO11DF");
4940 
4941   for (int jeta = 0; jeta < 22; jeta++) {
4942     for (int jphi = 0; jphi < 18; jphi++) {
4943       for (int i = 0; i < nx; i++) {
4944         double ccc1 = alexall[jeta][jphi][i];
4945         int neweta = jeta - 11 - 0.5;
4946         if (jeta >= 11)
4947           neweta = jeta - 11 + 1.5;
4948         if (ccc1 > 0.) {
4949           GetaHO11D->Fill(neweta, ccc1);
4950           GetaHO11D0->Fill(neweta, 1.);
4951           //           if( i == 0 ) cout<<"62  HO:  ibin=  "<< i <<"      jphi= "<< jphi <<"      jeta= "<< jeta <<"      A= "<< ccc1 <<endl;
4952         }
4953       }
4954     }
4955   }
4956   //     GetaHO11D->Sumw2();GetaHO11D0->Sumw2();
4957   GetaHO11DF->Divide(GetaHO11D, GetaHO11D0, 1, 1, "B");  // average A
4958                                                          //     GetaHO11DF->Sumw2();
4959   for (int jeta = 1; jeta < 24; jeta++) {
4960     GetaHO11DF->SetBinError(jeta, 0.01);
4961   }
4962   gPad->SetGridy();
4963   gPad->SetGridx();  //      gPad->SetLogz();
4964   GetaHO11DF->SetMarkerStyle(20);
4965   GetaHO11DF->SetMarkerSize(1.4);
4966   GetaHO11DF->GetZaxis()->SetLabelSize(0.08);
4967   GetaHO11DF->SetXTitle("#eta  \b");
4968   GetaHO11DF->SetYTitle("  <A> \b");
4969   GetaHO11DF->SetZTitle("<A>_ETA  - All \b");
4970   GetaHO11DF->SetMarkerColor(4);
4971   GetaHO11DF->SetLineColor(4);
4972   GetaHO11DF->SetMinimum(0.8);  //      GetaHO11DF->SetMaximum(1.000);
4973   GetaHO11DF->Draw("Error");
4974 
4975   /////////////////
4976   cRBX1->Update();
4977   cRBX1->Print("RBX-HO-11Dplot.png");
4978   cRBX1->Clear();
4979   // clean-up
4980   if (GetaHO11D)
4981     delete GetaHO11D;
4982   if (GetaHO11D0)
4983     delete GetaHO11D0;
4984   if (GetaHO11DF)
4985     delete GetaHO11DF;
4986 
4987   //========================================================================================== 22   HO:: Ratio plots   jeta = 0 - 21       jphi =0 - 17
4988   //======================================================================
4989   //======================================================================22.11.2018
4990   //======================================================================
4991   //======================================================================
4992 
4993   gStyle->SetOptStat(1110000);
4994   cout << "      RBX HO  Ratio plots *****" << endl;
4995   cRBX31->Clear();
4996   /////////////////
4997   // gain stabilitY:
4998   // Rij = Aij / A1j , where i-over LSs, j-channels
4999   //
5000   //    nx = maxbinsRBX; // # LS
5001   //
5002   double ccc0HO = 0.;
5003   cRBX31->Divide(3, 1);
5004   //================
5005   cRBX31->cd(1);
5006   //    TH1F* Gho5 = new TH1F("Gho5","", nx, 1., nx+1.);
5007   TH1F *Gho51 = new TH1F("Gho51", "", nx, 1., nx + 1.);
5008   TH1F *Gho50 = new TH1F("Gho50", "", nx, 1., nx + 1.);
5009   TH1F *Gho5 = (TH1F *)Gho50->Clone("Gho5");
5010   // j - etaphi index:
5011   for (int j = 1; j <= ny; j++) {
5012     ccc0HO = Gho1->GetBinContent(1, j);
5013     //  if(ccc0HO <=0.) for (int i=1;i<=nx;i++) {double ccc2 =  Gho1->GetBinContent(i,j);if(ccc2>0.){ccc0HO=ccc2;cout<<"!!! ccc0HO= "<<ccc0HO<<endl;break;} }
5014     if (ccc0HO <= 0.)
5015       for (int i = 1; i <= nx; i++) {
5016         double ccc2 = Gho1->GetBinContent(i, j);
5017         if (ccc2 > 0.) {
5018           ccc0HO = ccc2;
5019           break;
5020         }
5021       }
5022     if (ccc0HO > 0.) {
5023       // i - # LSs:
5024       for (int i = 1; i <= nx; i++) {
5025         double ccc1 = Gho1->GetBinContent(i, j);
5026         if (ccc1 > 0.) {
5027           double Rij = ccc1 / ccc0HO;
5028           //          Gho5 ->Fill( float(i), Rij);
5029           Gho51->Fill(float(i), Rij);
5030           Gho50->Fill(float(i), 1.);
5031         }
5032       }
5033     }
5034   }
5035   Gho5->Divide(Gho51, Gho50, 1, 1, "B");  // average A
5036   for (int i = 1; i <= nx; i++) {
5037     Gho5->SetBinError(i, 0.0001);
5038   }
5039   Gho5->SetMarkerStyle(20);
5040   Gho5->SetMarkerSize(0.4);
5041   Gho5->GetYaxis()->SetLabelSize(0.04);
5042   Gho5->SetMarkerColor(2);
5043   Gho5->SetLineColor(0);
5044   Gho5->SetXTitle("        iLS  \b");
5045   Gho5->SetYTitle("     <R> \b");
5046   Gho5->SetTitle("<Ri> vs iLS \b");
5047   Gho5->SetMinimum(0.);  //Gho5->SetMaximum(2.5);
5048   //            gPad->SetLogy();
5049   gPad->SetGridy();
5050   gPad->SetGridx();
5051   Gho5->SetStats(0);
5052   Gho5->GetYaxis()->SetLabelSize(0.025);
5053   Gho5->Draw("Error");
5054   //================
5055   cRBX31->cd(2);
5056   TH2F *Gho60 = new TH2F("Gho60", "", 22, -11., 11., 18, 0., 18.);
5057   TH2F *Gho61 = new TH2F("Gho61", "", 22, -11., 11., 18, 0., 18.);
5058   TH2F *Gho6 = new TH2F("Gho6", "", 22, -11., 11., 18, 0., 18.);
5059 
5060   TH2F *G20ho60 = new TH2F("G20ho60", "", 22, -11., 11., 18, 0., 18.);
5061   TH2F *G20ho61 = new TH2F("G20ho61", "", 22, -11., 11., 18, 0., 18.);
5062   TH2F *G20ho6 = new TH2F("G20ho6", "", 22, -11., 11., 18, 0., 18.);
5063   TH2F *G30ho60 = new TH2F("G30ho60", "", 22, -11., 11., 18, 0., 18.);
5064   TH2F *G30ho61 = new TH2F("G30ho61", "", 22, -11., 11., 18, 0., 18.);
5065   TH2F *G30ho6 = new TH2F("G30ho6", "", 22, -11., 11., 18, 0., 18.);
5066   TH2F *G40ho60 = new TH2F("G40ho60", "", 22, -11., 11., 18, 0., 18.);
5067   TH2F *G40ho61 = new TH2F("G40ho61", "", 22, -11., 11., 18, 0., 18.);
5068   TH2F *G40ho6 = new TH2F("G40ho6", "", 22, -11., 11., 18, 0., 18.);
5069 
5070   // j - etaphi index; i - # LSs;
5071   //
5072   // define mean and RMS:
5073   double sumjHO = 0.;
5074   int njHO = 0;
5075   double meanjHO = 0.;
5076   for (int j = 1; j <= ny; j++) {
5077     ccc0HO = Gho1->GetBinContent(1, j);
5078     if (ccc0HO <= 0.)
5079       for (int i = 1; i <= nx; i++) {
5080         double ccc2 = Gho1->GetBinContent(i, j);
5081         if (ccc2 > 0.) {
5082           ccc0HO = ccc2;
5083           break;
5084         }
5085       }
5086     if (ccc0HO > 0.) {
5087       for (int i = 1; i <= nx; i++) {
5088         double ccc1 = Gho1->GetBinContent(i, j) / ccc0HO;
5089         if (ccc1 > 0.) {
5090           sumjHO += ccc1;
5091           njHO++;
5092         }
5093       }
5094       meanjHO = sumjHO / njHO;
5095     }
5096   }  // j
5097 
5098   double ssumjHO = 0.;
5099   njHO = 0;
5100   double sigmajHO = 0.;
5101   for (int j = 1; j <= ny; j++) {
5102     ccc0HO = Gho1->GetBinContent(1, j);
5103     if (ccc0HO <= 0.)
5104       for (int i = 1; i <= nx; i++) {
5105         double ccc2 = Gho1->GetBinContent(i, j);
5106         if (ccc2 > 0.) {
5107           ccc0HO = ccc2;
5108           break;
5109         }
5110       }
5111     if (ccc0HO > 0.) {
5112       for (int i = 1; i <= nx; i++) {
5113         double ccc1 = Gho1->GetBinContent(i, j) / ccc0HO;
5114         if (ccc1 > 0.) {
5115           ssumjHO += (ccc1 - meanjHO) * (ccc1 - meanjHO);
5116           njHO++;
5117         }
5118       }
5119       sigmajHO = sqrt(ssumjHO / njHO);
5120     }
5121   }  // j
5122 
5123   double dif3rmsHOMIN = meanjHO - 3 * sigmajHO;
5124   if (dif3rmsHOMIN < 0.)
5125     dif3rmsHOMIN = 0.;
5126   double dif3rmsHOMAX = meanjHO + 3 * sigmajHO;
5127   cout << "22HO-2    meanjHO=  " << meanjHO << "  sigmajHO=  " << sigmajHO << "  dif3rmsHOMIN=  " << dif3rmsHOMIN
5128        << "  dif3rmsHOMAX=  " << dif3rmsHOMAX << endl;
5129 
5130   double MAXdif3rmsHOMIN = dif3rmsHOMIN;
5131   double MINdif3rmsHOMAX = dif3rmsHOMAX;
5132   if (MAXdif3rmsHOMIN < 0.95)
5133     MAXdif3rmsHOMIN = 0.95;
5134   if (MINdif3rmsHOMAX > 1.05)
5135     MINdif3rmsHOMAX = 1.05;
5136   cout << "22HO-2     MAXdif3rmsHOMIN=  " << MAXdif3rmsHOMIN << "     MINdif3rmsHOMAX=  " << MINdif3rmsHOMAX << endl;
5137   //
5138   for (int j = 1; j <= ny; j++) {
5139     ccc0HO = Gho1->GetBinContent(1, j);
5140     if (ccc0HO <= 0.)
5141       for (int i = 1; i <= nx; i++) {
5142         double ccc2 = Gho1->GetBinContent(i, j);
5143         if (ccc2 > 0.) {
5144           ccc0HO = ccc2;
5145           break;
5146         }
5147       }
5148     if (ccc0HO > 0.) {
5149       int jeta = (j - 1) / 18;         // jeta = 0-21
5150       int jphi = (j - 1) - 18 * jeta;  // jphi=0-17
5151       // i - # LSs:
5152       for (int i = 1; i <= nx; i++) {
5153         double ccc1 = Gho1->GetBinContent(i, j);
5154         if (ccc1 > 0.) {
5155           double Rij = ccc1 / ccc0HO;
5156           if (Rij < MAXdif3rmsHOMIN || Rij > MINdif3rmsHOMAX) {
5157             Gho61->Fill(jeta - 11, jphi, Rij);
5158             Gho60->Fill(jeta - 11, jphi, 1.);
5159           }
5160           if (Rij < 0.8 || Rij > 1.2) {
5161             G20ho61->Fill(jeta - 11, jphi, Rij);
5162             G20ho60->Fill(jeta - 11, jphi, 1.);
5163           }
5164           if (Rij < 0.7 || Rij > 1.3) {
5165             G30ho61->Fill(jeta - 11, jphi, Rij);
5166             G30ho60->Fill(jeta - 11, jphi, 1.);
5167           }
5168           if (Rij < 0.6 || Rij > 1.4) {
5169             G40ho61->Fill(jeta - 11, jphi, Rij);
5170             G40ho60->Fill(jeta - 11, jphi, 1.);
5171           }
5172         }                                       //if(ccc1>0.
5173       }                                         // i
5174     }                                           //if(ccc0HO>0
5175   }                                             // j
5176   Gho6->Divide(Gho61, Gho60, 1, 1, "B");        // average R
5177   G20ho6->Divide(G20ho61, G20ho60, 1, 1, "B");  // average R
5178   G30ho6->Divide(G30ho61, G30ho60, 1, 1, "B");  // average R
5179   G40ho6->Divide(G40ho61, G40ho60, 1, 1, "B");  // average R
5180   //      Gho6->SetLabelOffset (Float_t offset=0.005, Option_t *axis="X")//Set offset between axis and axis' labels
5181   //      Gho6->GetZaxis()->SetLabelOffset(-0.05);
5182   Gho6->GetZaxis()->SetLabelSize(0.025);
5183 
5184   Gho6->SetXTitle("             #eta  \b");
5185   Gho6->SetYTitle("      #phi \b");
5186   Gho6->SetTitle(
5187       "<Rj> for |1-<R>| > 0.05 \b");  //      Gho6->SetMaximum(1.000);  //      Gho6->SetMinimum(1.0); //Gho6->SetZTitle("Rij averaged over LSs \b"); //Gho6->GetZaxis()->SetLabelSize(0.04); //Gho6->SetMarkerStyle(20);// Gho6->SetMarkerSize(0.4);//Gho6->SetMarkerColor(2); //Gho6->SetLineColor(2);
5188   //gStyle->SetOptStat(kFALSE);
5189   Gho6->SetStats(0);
5190   Gho6->Draw("COLZ");
5191   //================
5192   cRBX31->cd(3);
5193   TH1F *Gho7 = new TH1F("Gho7", "", 120, 0.4, 1.6);
5194   // j - etaphi index:
5195   for (int j = 1; j <= ny; j++) {
5196     ccc0HO = Gho1->GetBinContent(1, j);
5197     if (ccc0HO <= 0.)
5198       for (int i = 1; i <= nx; i++) {
5199         double ccc2 = Gho1->GetBinContent(i, j);
5200         if (ccc2 > 0.) {
5201           ccc0HO = ccc2;
5202           break;
5203         }
5204       }
5205     if (ccc0HO > 0.) {
5206       // i - # LSs:
5207       for (int i = 1; i <= nx; i++) {
5208         double ccc1 = Gho1->GetBinContent(i, j);
5209         if (ccc1 > 0.) {
5210           double Rij = ccc1 / ccc0HO;
5211           Gho7->Fill(Rij);
5212         }
5213       }
5214     }
5215   }
5216   Gho7->SetMarkerStyle(20);
5217   Gho7->SetMarkerSize(0.4);
5218   Gho7->GetYaxis()->SetLabelSize(0.04);
5219   Gho7->SetMarkerColor(2);
5220   Gho7->SetLineColor(0);
5221   Gho7->SetYTitle("        N  \b");
5222   Gho7->SetXTitle("     Rij \b");
5223   Gho7->SetTitle(" Rij \b");
5224   //Gho7->SetMinimum(0.8);Gho7->SetMaximum(500.);
5225   gPad->SetGridy();
5226   gPad->SetGridx();  //            gPad->SetLogy();
5227   //      Gho7->SetStats(1110000);
5228   Gho7->GetYaxis()->SetLabelSize(0.025);
5229   Gho7->Draw("Error");
5230   Float_t ymaxHO = Gho7->GetMaximum();
5231   cout << "22HO-3   ymaxHO=  " << ymaxHO << "       MAXdif3rmsHOMIN=  " << MAXdif3rmsHOMIN
5232        << "         MINdif3rmsHOMAX=  " << MINdif3rmsHOMAX << endl;
5233   TLine *lineHO = new TLine(MAXdif3rmsHOMIN, 0., MAXdif3rmsHOMIN, ymaxHO);
5234   lineHO->SetLineColor(kBlue);
5235   lineHO->Draw();
5236   TLine *line1HO = new TLine(MINdif3rmsHOMAX, 0., MINdif3rmsHOMAX, ymaxHO);
5237   line1HO->SetLineColor(kBlue);
5238   line1HO->Draw();
5239   //================
5240   /////////////////
5241   cRBX31->Update();
5242   cRBX31->Print("RBX-HO-3plots.png");
5243   cRBX31->Clear();
5244   // clean-up
5245   if (Gho5)
5246     delete Gho5;
5247   if (Gho60)
5248     delete Gho60;
5249   if (Gho61)
5250     delete Gho61;
5251   if (Gho6)
5252     delete Gho6;
5253   if (Gho7)
5254     delete Gho7;
5255 
5256   if (G20ho60)
5257     delete G20ho60;
5258   if (G20ho61)
5259     delete G20ho61;
5260   if (G30ho60)
5261     delete G30ho60;
5262   if (G30ho61)
5263     delete G30ho61;
5264   if (G40ho60)
5265     delete G40ho60;
5266   if (G40ho61)
5267     delete G40ho61;
5268 
5269   if (Gho1)
5270     delete Gho1;
5271   //========================================================================================== 22-1   HO:: Ratio plots   jeta = 0 - 21       jphi =0 - 17
5272   //======================================================================
5273   //======================================================================28.11.2018
5274   //======================================================================
5275   //======================================================================
5276 
5277   gStyle->SetOptStat(1110000);
5278   cout << "      RBX HO  Ratio plotsmore *****" << endl;
5279   cRBX31->Clear();
5280   /////////////////
5281   cRBX31->Divide(3, 1);
5282   //================
5283   cRBX31->cd(1);
5284   G20ho6->GetZaxis()->SetLabelSize(0.025);
5285   G20ho6->SetXTitle("             #eta  \b");
5286   G20ho6->SetYTitle("      #phi \b");
5287   G20ho6->SetTitle("<Rj> for |1-<R>| > 0.20 \b");
5288   G20ho6->SetStats(0);
5289   G20ho6->Draw("COLZ");
5290   //================
5291   cRBX31->cd(2);
5292   G30ho6->GetZaxis()->SetLabelSize(0.025);
5293   G30ho6->SetXTitle("             #eta  \b");
5294   G30ho6->SetYTitle("      #phi \b");
5295   G30ho6->SetTitle("<Rj> for |1-<R>| > 0.30 \b");
5296   G30ho6->SetStats(0);
5297   G30ho6->Draw("COLZ");
5298   //================
5299   cRBX31->cd(3);
5300   G40ho6->GetZaxis()->SetLabelSize(0.025);
5301   G40ho6->SetXTitle("             #eta  \b");
5302   G40ho6->SetYTitle("      #phi \b");
5303   G40ho6->SetTitle("<Rj> for |1-<R>| > 0.40 \b");
5304   G40ho6->SetStats(0);
5305   G40ho6->Draw("COLZ");
5306   //================
5307 
5308   /////////////////
5309   cRBX31->Update();
5310   cRBX31->Print("RBX-HO-3plotsmore.png");
5311   cRBX31->Clear();
5312 
5313   // clean-up
5314   if (G20ho6)
5315     delete G20ho6;
5316   if (G30ho6)
5317     delete G30ho6;
5318   if (G40ho6)
5319     delete G40ho6;
5320   gStyle->SetOptStat(0);
5321   ////////////////////////////////////////////////////////////////////////////////////
5322 
5323   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
5324   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
5325   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
5326   for (int jphi = 0; jphi < njphi; jphi++) {
5327     for (int jeta = 0; jeta < njeta; jeta++) {
5328       for (int i = 0; i < nx; i++) {
5329         alexall[jeta][jphi][i] = 0.;
5330       }
5331     }
5332   }  // nulling
5333 
5334   ////////////////////////////////////////////////////////////////////////////////////   end HO RBX
5335 
5336   ////////////////////////////////////////////////////////////////////////////////////     HF::   HFSTART
5337   //======================================================================
5338   //======================================================================
5339   //======================================================================
5340   cout << " RBX general for HF **************************" << endl;
5341   TH2F *Ghf1KKK = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplEtaPhiLs3");
5342   TH2F *Ghf1LLL = (TH2F *)dir->FindObjectAny("h_2DsumADCAmplEtaPhiLs30");
5343   TH2F *Ghf1 = (TH2F *)Ghf1LLL->Clone("Ghf1");
5344   Ghf1->Divide(Ghf1KKK, Ghf1LLL, 1, 1, "B");  // average A
5345   //    Ghf1->Sumw2();
5346   //      int nx = Ghf1->GetXaxis()->GetNbins(); // # LS
5347   //    nx = maxbinsRBX; // # LS
5348   ny = Ghf1->GetYaxis()->GetNbins();  // # jetaphi indexes
5349   for (int j = 1; j <= ny; j++) {
5350     int jeta = (j - 1) / njphi;  // jeta = 0-21
5351     if (jeta < 4 || jeta > 17) {
5352       int jphi = (j - 1) - njphi * jeta;  // jphi=0-17
5353       //       cout<<"HF 54        jeta=     "<< jeta <<"   jphi   =     "<<jphi  <<endl;
5354       // over LS:
5355       for (int i = 1; i <= nx; i++) {
5356         double ccc1 = Ghf1->GetBinContent(i, j);
5357         alexall[jeta][jphi][i - 1] = ccc1;
5358         //       if( i == 1 ) cout<<"HF 54  for LS=1      ccc1=     "<< ccc1 <<endl;
5359       }  //i
5360     }    //if
5361   }      //j
5362   // clean-up
5363   if (Ghf1KKK)
5364     delete Ghf1KKK;
5365   if (Ghf1LLL)
5366     delete Ghf1LLL;
5367   //    if (Ghf1) delete Ghf1;
5368 
5369   //====================================================================== alexhf[k][i]
5370   for (int jphi = 0; jphi < njphi; jphi++) {
5371     for (int i = 0; i < nx; i++) {
5372       double sumccc1 = 0.;
5373       int isum = 0;
5374       for (int jeta = 0; jeta < njeta; jeta++) {
5375         double ccc1 = alexall[jeta][jphi][i];
5376         if (ccc1 > 0.) {
5377           sumccc1 += ccc1;
5378           isum++;
5379         }
5380       }  // for jeta
5381       if (isum > 0.)
5382         sumccc1 /= isum;
5383       alexhf[jphi][i] = sumccc1;
5384     }
5385   }  //for for
5386      //====================================================================== blexhf[k][i]
5387   for (int keta = 0; keta < njeta; keta++) {
5388     for (int i = 0; i < nx; i++) {
5389       double sumccc1 = 0.;
5390       int isum = 0;
5391       for (int kphi = 0; kphi < njphi; kphi++) {
5392         double ccc1 = alexall[keta][kphi][i];
5393         if (ccc1 > 0.) {
5394           sumccc1 += ccc1;
5395           isum++;
5396         }
5397       }  // for kphi
5398       if (isum > 0.)
5399         sumccc1 /= isum;
5400       blexhf[keta][i] = sumccc1;
5401     }
5402   }  //for for
5403   /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5404   //========================================================================================== 60   HF:: 2D  jeta = 0 - 21       jphi =0 - 17
5405   //======================================================================
5406   //======================================================================
5407   //======================================================================
5408   //======================================================================
5409   cout << "      RBX HF  2D plot *****" << endl;
5410   cRBX1->Clear();
5411   /////////////////
5412   cRBX1->Divide(1, 1);
5413   cRBX1->cd(1);
5414   // int ietaphi = 0; ietaphi = ((k2+1)-1)*nphi + (k3+1) ;  k2=0-neta-1; k3=0-nphi-1; neta=18; nphi=22;
5415   TH2F *Ghf42D = new TH2F("Ghf42D", "", 23, -11.5, 11.5, 18, 0., 18.);
5416   TH2F *Ghf42D0 = new TH2F("Ghf42D0", "", 23, -11.5, 11.5, 18, 0., 18.);
5417   //     TH2F* Ghf42D      = new TH2F("Ghf42D","",   22, -11., 11., 18, 0., 18. );
5418   //     TH2F* Ghf42D0     = new TH2F("Ghf42D0","",  22, -11., 11., 18, 0., 18. );
5419   TH2F *Ghf42DF = (TH2F *)Ghf42D0->Clone("Ghf42DF");
5420   for (int jphi = 0; jphi < njphi; jphi++) {
5421     for (int jeta = 0; jeta < njeta; jeta++) {
5422       for (int i = 0; i < nx; i++) {
5423         double ccc1 = alexall[jeta][jphi][i];
5424         int neweta = jeta - 11 - 0.5;
5425         if (jeta >= 11)
5426           neweta = jeta - 11 + 1.5;
5427         if (ccc1 > 0.) {
5428           Ghf42D->Fill(neweta, jphi, ccc1);
5429           Ghf42D0->Fill(neweta, jphi, 1.);
5430         }
5431         //       if(ccc1>0.) {Ghf42D ->Fill(jeta-11,jphi,ccc1); Ghf42D0 ->Fill(jeta-11,jphi,1.); }
5432       }
5433     }
5434   }
5435   Ghf42DF->Divide(Ghf42D, Ghf42D0, 1, 1, "B");  // average A
5436   //    Ghf1->Sumw2();
5437   gPad->SetGridy();
5438   gPad->SetGridx();  //      gPad->SetLogz();
5439   Ghf42DF->SetMarkerStyle(20);
5440   Ghf42DF->SetMarkerSize(0.4);
5441   Ghf42DF->GetZaxis()->SetLabelSize(0.04);
5442   Ghf42DF->SetXTitle("<A>_RBX         #eta  \b");
5443   Ghf42DF->SetYTitle("      #phi \b");
5444   Ghf42DF->SetZTitle("<A>_RBX  - All \b");
5445   Ghf42DF->SetMarkerColor(2);
5446   Ghf42DF->SetLineColor(2);  //      Ghf42DF->SetMaximum(1.000);  //      Ghf42DF->SetMinimum(1.0);
5447   Ghf42DF->Draw("COLZ");
5448 
5449   /////////////////
5450   cRBX1->Update();
5451   cRBX1->Print("RBX-HF-2Dplot.png");
5452   cRBX1->Clear();
5453   // clean-up
5454   if (Ghf42D)
5455     delete Ghf42D;
5456   if (Ghf42D0)
5457     delete Ghf42D0;
5458   if (Ghf42DF)
5459     delete Ghf42DF;
5460 
5461   //========================================================================================== 61   HF:: 1D  j = 7,8,9,10 ; 11,12,13,14       jphi =0 - 17
5462   //======================================================================
5463   //======================================================================
5464   //======================================================================
5465   //======================================================================
5466   cout << "      RBX HF  1D plot *****" << endl;
5467   cRBX1->Clear();
5468   /////////////////
5469   cRBX1->Divide(1, 1);
5470   cRBX1->cd(1);
5471   TH1F *GphiHF1D = new TH1F("GphiHF1D", "", 18, 0., 18.);
5472   TH1F *GphiHF1D0 = new TH1F("GphiHF1D0", "", 18, 0., 18.);
5473   TH1F *GphiHF1DF = (TH1F *)GphiHF1D0->Clone("GphiHF1DF");
5474   for (int jphi = 0; jphi < 18; jphi++) {
5475     for (int jeta = 0; jeta < 22; jeta++) {
5476       for (int i = 0; i < nx; i++) {
5477         double ccc1 = alexall[jeta][jphi][i];
5478         if (ccc1 > 0.) {
5479           GphiHF1D->Fill(jphi, ccc1);
5480           GphiHF1D0->Fill(jphi, 1.);
5481         }
5482       }
5483     }
5484   }
5485   //     GphiHF1D->Sumw2();GphiHF1D0->Sumw2();
5486   GphiHF1DF->Divide(GphiHF1D, GphiHF1D0, 1, 1, "B");  // average A
5487                                                       //     GphiHF1DF->Sumw2();
5488   for (int jphi = 1; jphi < 19; jphi++) {
5489     GphiHF1DF->SetBinError(jphi, 0.01);
5490   }
5491   gPad->SetGridy();
5492   gPad->SetGridx();  //      gPad->SetLogz();
5493   GphiHF1DF->SetMarkerStyle(20);
5494   GphiHF1DF->SetMarkerSize(1.4);
5495   GphiHF1DF->GetZaxis()->SetLabelSize(0.08);
5496   GphiHF1DF->SetXTitle("PHI of RBX\b");
5497   GphiHF1DF->SetYTitle(" <Amplitude> \b");
5498   GphiHF1DF->SetZTitle("<A>_PHI  - All \b");
5499   GphiHF1DF->SetMarkerColor(4);
5500   GphiHF1DF->SetLineColor(4);
5501   GphiHF1DF->SetMinimum(0.8);  //      GphiHF1DF->SetMaximum(1.000);
5502   GphiHF1DF->Draw("Error");
5503   /////////////////
5504   cRBX1->Update();
5505   cRBX1->Print("RBX-HF-1Dplot.png");
5506   cRBX1->Clear();
5507   // clean-up
5508   if (GphiHF1D)
5509     delete GphiHF1D;
5510   if (GphiHF1D0)
5511     delete GphiHF1D0;
5512   if (GphiHF1DF)
5513     delete GphiHF1DF;
5514 
5515   //========================================================================================== 62   HF:: 1D  j = 7,8,9,10 ; 11,12,13,14       jphi =0 - 17
5516   //======================================================================
5517   //======================================================================
5518   //======================================================================
5519   //======================================================================
5520   cout << "      RBX HF 11D plot *eta*" << endl;
5521   cRBX1->Clear();
5522   /////////////////
5523   cRBX1->Divide(1, 1);
5524   cRBX1->cd(1);
5525   TH1F *GetaHF11D = new TH1F("GetaHF11D", "", 23, -11.5, 11.5);
5526   TH1F *GetaHF11D0 = new TH1F("GetaHF11D0", "", 23, -11.5, 11.5);
5527   TH1F *GetaHF11DF = (TH1F *)GetaHF11D0->Clone("GetaHF11DF");
5528 
5529   for (int jeta = 0; jeta < 22; jeta++) {
5530     for (int jphi = 0; jphi < 18; jphi++) {
5531       for (int i = 0; i < nx; i++) {
5532         double ccc1 = alexall[jeta][jphi][i];
5533         int neweta = jeta - 11 - 0.5;
5534         if (jeta >= 11)
5535           neweta = jeta - 11 + 1.5;
5536         if (ccc1 > 0.) {
5537           GetaHF11D->Fill(neweta, ccc1);
5538           GetaHF11D0->Fill(neweta, 1.);
5539           //           if( i == 0 ) cout<<"62  HF:  ibin=  "<< i <<"      jphi= "<< jphi <<"      jeta= "<< jeta <<"      A= "<< ccc1 <<endl;
5540         }
5541       }
5542     }
5543   }
5544   //     GetaHF11D->Sumw2();GetaHF11D0->Sumw2();
5545   GetaHF11DF->Divide(GetaHF11D, GetaHF11D0, 1, 1, "B");  // average A
5546                                                          //     GetaHF11DF->Sumw2();
5547   for (int jeta = 1; jeta < 24; jeta++) {
5548     GetaHF11DF->SetBinError(jeta, 0.01);
5549   }
5550   gPad->SetGridy();
5551   gPad->SetGridx();  //      gPad->SetLogz();
5552   GetaHF11DF->SetMarkerStyle(20);
5553   GetaHF11DF->SetMarkerSize(1.4);
5554   GetaHF11DF->GetZaxis()->SetLabelSize(0.08);
5555   GetaHF11DF->SetXTitle("#eta  \b");
5556   GetaHF11DF->SetYTitle("  <A> \b");
5557   GetaHF11DF->SetZTitle("<A>_ETA  - All \b");
5558   GetaHF11DF->SetMarkerColor(4);
5559   GetaHF11DF->SetLineColor(4);
5560   GetaHF11DF->SetMinimum(0.8);  //      GetaHF11DF->SetMaximum(1.000);
5561   GetaHF11DF->Draw("Error");
5562 
5563   /////////////////
5564   cRBX1->Update();
5565   cRBX1->Print("RBX-HF-11Dplot.png");
5566   cRBX1->Clear();
5567   // clean-up
5568   if (GetaHF11D)
5569     delete GetaHF11D;
5570   if (GetaHF11D0)
5571     delete GetaHF11D0;
5572   if (GetaHF11DF)
5573     delete GetaHF11DF;
5574 
5575   //========================================================================================== 22   HF:: Ratio plots   jeta = 0 - 21       jphi =0 - 17
5576   //======================================================================
5577   //======================================================================22.11.2018
5578   //======================================================================
5579   //======================================================================
5580 
5581   gStyle->SetOptStat(1110000);
5582   cout << "      RBX HF  Ratio plots *****" << endl;
5583   cRBX31->Clear();
5584   /////////////////
5585   // gain stabilitY:
5586   // Rij = Aij / A1j , where i-over LSs, j-channels
5587   //
5588   //    nx = maxbinsRBX; // # LS
5589   //
5590   double ccc0HF = 0.;
5591   cRBX31->Divide(3, 1);
5592   //================
5593   cRBX31->cd(1);
5594   //      TH1F* Ghf5 = new TH1F("Ghf5","", nx, 1., nx+1.);
5595   TH1F *Ghf51 = new TH1F("Ghf51", "", nx, 1., nx + 1.);
5596   TH1F *Ghf50 = new TH1F("Ghf50", "", nx, 1., nx + 1.);
5597   TH1F *Ghf5 = (TH1F *)Ghf50->Clone("Ghf5");
5598   // j - etaphi index:
5599   for (int j = 1; j <= ny; j++) {
5600     ccc0HF = Ghf1->GetBinContent(1, j);
5601     //  if(ccc0HF <=0.) for (int i=1;i<=nx;i++) {double ccc2 =  Ghf1->GetBinContent(i,j);if(ccc2>0.){ccc0HF=ccc2;cout<<"!!! ccc0HF= "<<ccc0HF<<endl;break;} }
5602     if (ccc0HF <= 0.)
5603       for (int i = 1; i <= nx; i++) {
5604         double ccc2 = Ghf1->GetBinContent(i, j);
5605         if (ccc2 > 0.) {
5606           ccc0HF = ccc2;
5607           break;
5608         }
5609       }
5610     if (ccc0HF > 0.) {
5611       // i - # LSs:
5612       for (int i = 1; i <= nx; i++) {
5613         double ccc1 = Ghf1->GetBinContent(i, j);
5614         if (ccc1 > 0.) {
5615           double Rij = ccc1 / ccc0HF;
5616           //     Ghf5 ->Fill( float(i), Rij);
5617           Ghf51->Fill(float(i), Rij);
5618           Ghf50->Fill(float(i), 1.);
5619         }
5620       }
5621     }
5622   }
5623   Ghf5->Divide(Ghf51, Ghf50, 1, 1, "B");  // average A
5624   for (int i = 1; i <= nx; i++) {
5625     Ghf5->SetBinError(i, 0.0001);
5626   }
5627   Ghf5->SetMarkerStyle(20);
5628   Ghf5->SetMarkerSize(0.4);
5629   Ghf5->GetYaxis()->SetLabelSize(0.04);
5630   Ghf5->SetMarkerColor(2);
5631   Ghf5->SetLineColor(0);
5632   Ghf5->SetXTitle("        iLS  \b");
5633   Ghf5->SetYTitle("     <R> \b");
5634   Ghf5->SetTitle("<Ri> vs iLS \b");
5635   Ghf5->SetMinimum(0.);  //Ghf5->SetMaximum(2.5);
5636   //            gPad->SetLogy();
5637   gPad->SetGridy();
5638   gPad->SetGridx();
5639   Ghf5->SetStats(0);
5640   Ghf5->GetYaxis()->SetLabelSize(0.025);
5641   Ghf5->Draw("Error");
5642   //================
5643   cRBX31->cd(2);
5644   TH2F *Ghf60 = new TH2F("Ghf60", "", 22, -11., 11., 18, 0., 18.);
5645   TH2F *Ghf61 = new TH2F("Ghf61", "", 22, -11., 11., 18, 0., 18.);
5646   TH2F *Ghf6 = new TH2F("Ghf6", "", 22, -11., 11., 18, 0., 18.);
5647 
5648   TH2F *G20hf60 = new TH2F("G20hf60", "", 22, -11., 11., 18, 0., 18.);
5649   TH2F *G20hf61 = new TH2F("G20hf61", "", 22, -11., 11., 18, 0., 18.);
5650   TH2F *G20hf6 = new TH2F("G20hf6", "", 22, -11., 11., 18, 0., 18.);
5651   TH2F *G30hf60 = new TH2F("G30hf60", "", 22, -11., 11., 18, 0., 18.);
5652   TH2F *G30hf61 = new TH2F("G30hf61", "", 22, -11., 11., 18, 0., 18.);
5653   TH2F *G30hf6 = new TH2F("G30hf6", "", 22, -11., 11., 18, 0., 18.);
5654   TH2F *G40hf60 = new TH2F("G40hf60", "", 22, -11., 11., 18, 0., 18.);
5655   TH2F *G40hf61 = new TH2F("G40hf61", "", 22, -11., 11., 18, 0., 18.);
5656   TH2F *G40hf6 = new TH2F("G40hf6", "", 22, -11., 11., 18, 0., 18.);
5657   // j - etaphi index; i - # LSs;
5658   //
5659   // define mean and RMS:
5660   double sumjHF = 0.;
5661   int njHF = 0;
5662   double meanjHF = 0.;
5663   for (int j = 1; j <= ny; j++) {
5664     ccc0HF = Ghf1->GetBinContent(1, j);
5665     if (ccc0HF <= 0.)
5666       for (int i = 1; i <= nx; i++) {
5667         double ccc2 = Ghf1->GetBinContent(i, j);
5668         if (ccc2 > 0.) {
5669           ccc0HF = ccc2;
5670           break;
5671         }
5672       }
5673     if (ccc0HF > 0.) {
5674       for (int i = 1; i <= nx; i++) {
5675         double ccc1 = Ghf1->GetBinContent(i, j) / ccc0HF;
5676         if (ccc1 > 0.) {
5677           sumjHF += ccc1;
5678           njHF++;
5679         }
5680       }
5681       meanjHF = sumjHF / njHF;
5682     }
5683   }  // j
5684 
5685   double ssumjHF = 0.;
5686   njHF = 0;
5687   double sigmajHF = 0.;
5688   for (int j = 1; j <= ny; j++) {
5689     ccc0HF = Ghf1->GetBinContent(1, j);
5690     if (ccc0HF <= 0.)
5691       for (int i = 1; i <= nx; i++) {
5692         double ccc2 = Ghf1->GetBinContent(i, j);
5693         if (ccc2 > 0.) {
5694           ccc0HF = ccc2;
5695           break;
5696         }
5697       }
5698     if (ccc0HF > 0.) {
5699       for (int i = 1; i <= nx; i++) {
5700         double ccc1 = Ghf1->GetBinContent(i, j) / ccc0HF;
5701         if (ccc1 > 0.) {
5702           ssumjHF += (ccc1 - meanjHF) * (ccc1 - meanjHF);
5703           njHF++;
5704         }
5705       }
5706       sigmajHF = sqrt(ssumjHF / njHF);
5707     }
5708   }  // j
5709 
5710   double dif3rmsHFMIN = meanjHF - 3 * sigmajHF;
5711   if (dif3rmsHFMIN < 0.)
5712     dif3rmsHFMIN = 0.;
5713   double dif3rmsHFMAX = meanjHF + 3 * sigmajHF;
5714   cout << "22HF-2    meanjHF=  " << meanjHF << "  sigmajHF=  " << sigmajHF << "  dif3rmsHFMIN=  " << dif3rmsHFMIN
5715        << "  dif3rmsHFMAX=  " << dif3rmsHFMAX << endl;
5716 
5717   double MAXdif3rmsHFMIN = dif3rmsHFMIN;
5718   double MINdif3rmsHFMAX = dif3rmsHFMAX;
5719   if (MAXdif3rmsHFMIN < 0.95)
5720     MAXdif3rmsHFMIN = 0.95;
5721   if (MINdif3rmsHFMAX > 1.05)
5722     MINdif3rmsHFMAX = 1.05;
5723   cout << "22HF-2     MAXdif3rmsHFMIN=  " << MAXdif3rmsHFMIN << "     MINdif3rmsHFMAX=  " << MINdif3rmsHFMAX << endl;
5724   //
5725   for (int j = 1; j <= ny; j++) {
5726     ccc0HF = Ghf1->GetBinContent(1, j);
5727     if (ccc0HF <= 0.)
5728       for (int i = 1; i <= nx; i++) {
5729         double ccc2 = Ghf1->GetBinContent(i, j);
5730         if (ccc2 > 0.) {
5731           ccc0HF = ccc2;
5732           break;
5733         }
5734       }
5735     if (ccc0HF > 0.) {
5736       int jeta = (j - 1) / 18;         // jeta = 0-21
5737       int jphi = (j - 1) - 18 * jeta;  // jphi=0-17
5738       // i - # LSs:
5739       for (int i = 1; i <= nx; i++) {
5740         double ccc1 = Ghf1->GetBinContent(i, j);
5741         if (ccc1 > 0.) {
5742           double Rij = ccc1 / ccc0HF;
5743           if (Rij < MAXdif3rmsHFMIN || Rij > MINdif3rmsHFMAX) {
5744             Ghf61->Fill(jeta - 11, jphi, Rij);
5745             Ghf60->Fill(jeta - 11, jphi, 1.);
5746           }
5747           if (Rij < 0.8 || Rij > 1.2) {
5748             G20hf61->Fill(jeta - 11, jphi, Rij);
5749             G20hf60->Fill(jeta - 11, jphi, 1.);
5750           }
5751           if (Rij < 0.7 || Rij > 1.3) {
5752             G30hf61->Fill(jeta - 11, jphi, Rij);
5753             G30hf60->Fill(jeta - 11, jphi, 1.);
5754           }
5755           if (Rij < 0.6 || Rij > 1.4) {
5756             G40hf61->Fill(jeta - 11, jphi, Rij);
5757             G40hf60->Fill(jeta - 11, jphi, 1.);
5758           }
5759         }                                       //if(ccc1>0.
5760       }                                         // i
5761     }                                           //if(ccc0HF>0
5762   }                                             // j
5763   Ghf6->Divide(Ghf61, Ghf60, 1, 1, "B");        // average R
5764   G20hf6->Divide(G20hf61, G20hf60, 1, 1, "B");  // average R
5765   G30hf6->Divide(G30hf61, G30hf60, 1, 1, "B");  // average R
5766   G40hf6->Divide(G40hf61, G40hf60, 1, 1, "B");  // average R
5767   //      Ghf6->SetLabelOffset (Float_t offset=0.005, Option_t *axis="X")//Set offset between axis and axis' labels
5768   //      Ghf6->GetZaxis()->SetLabelOffset(-0.05);
5769   Ghf6->GetZaxis()->SetLabelSize(0.025);
5770 
5771   Ghf6->SetXTitle("             #eta  \b");
5772   Ghf6->SetYTitle("      #phi \b");
5773   Ghf6->SetTitle(
5774       "<Rj> for |1-<R>| > 0.05 \b");  //      Ghf6->SetMaximum(1.000);  //      Ghf6->SetMinimum(1.0); //Ghf6->SetZTitle("Rij averaged over LSs \b"); //Ghf6->GetZaxis()->SetLabelSize(0.04); //Ghf6->SetMarkerStyle(20);// Ghf6->SetMarkerSize(0.4);//Ghf6->SetMarkerColor(2); //Ghf6->SetLineColor(2);
5775   //gStyle->SetOptStat(kFALSE);
5776   Ghf6->SetStats(0);
5777   Ghf6->Draw("COLZ");
5778   //================
5779   cRBX31->cd(3);
5780   TH1F *Ghf7 = new TH1F("Ghf7", "", 120, 0.4, 1.6);
5781   // j - etaphi index:
5782   for (int j = 1; j <= ny; j++) {
5783     ccc0HF = Ghf1->GetBinContent(1, j);
5784     if (ccc0HF <= 0.)
5785       for (int i = 1; i <= nx; i++) {
5786         double ccc2 = Ghf1->GetBinContent(i, j);
5787         if (ccc2 > 0.) {
5788           ccc0HF = ccc2;
5789           break;
5790         }
5791       }
5792     if (ccc0HF > 0.) {
5793       // i - # LSs:
5794       for (int i = 1; i <= nx; i++) {
5795         double ccc1 = Ghf1->GetBinContent(i, j);
5796         if (ccc1 > 0.) {
5797           double Rij = ccc1 / ccc0HF;
5798           Ghf7->Fill(Rij);
5799         }
5800       }
5801     }
5802   }
5803   Ghf7->SetMarkerStyle(20);
5804   Ghf7->SetMarkerSize(0.4);
5805   Ghf7->GetYaxis()->SetLabelSize(0.04);
5806   Ghf7->SetMarkerColor(2);
5807   Ghf7->SetLineColor(0);
5808   Ghf7->SetYTitle("        N  \b");
5809   Ghf7->SetXTitle("     Rij \b");
5810   Ghf7->SetTitle(" Rij \b");
5811   //Ghf7->SetMinimum(0.8);Ghf7->SetMaximum(500.);
5812   gPad->SetGridy();
5813   gPad->SetGridx();  //            gPad->SetLogy();
5814   //      Ghf7->SetStats(1110000);
5815   Ghf7->GetYaxis()->SetLabelSize(0.025);
5816   Ghf7->Draw("Error");
5817   Float_t ymaxHF = Ghf7->GetMaximum();
5818   cout << "22HF-3   ymaxHF=  " << ymaxHF << "       MAXdif3rmsHFMIN=  " << MAXdif3rmsHFMIN
5819        << "         MINdif3rmsHFMAX=  " << MINdif3rmsHFMAX << endl;
5820   TLine *lineHF = new TLine(MAXdif3rmsHFMIN, 0., MAXdif3rmsHFMIN, ymaxHF);
5821   lineHF->SetLineColor(kBlue);
5822   lineHF->Draw();
5823   TLine *line1HF = new TLine(MINdif3rmsHFMAX, 0., MINdif3rmsHFMAX, ymaxHF);
5824   line1HF->SetLineColor(kBlue);
5825   line1HF->Draw();
5826   //================
5827   /////////////////
5828   cRBX31->Update();
5829   cRBX31->Print("RBX-HF-3plots.png");
5830   cRBX31->Clear();
5831   // clean-up
5832   if (Ghf5)
5833     delete Ghf5;
5834   if (Ghf60)
5835     delete Ghf60;
5836   if (Ghf61)
5837     delete Ghf61;
5838   if (Ghf6)
5839     delete Ghf6;
5840   if (Ghf7)
5841     delete Ghf7;
5842 
5843   if (G20hf60)
5844     delete G20hf60;
5845   if (G20hf61)
5846     delete G20hf61;
5847   if (G30hf60)
5848     delete G30hf60;
5849   if (G30hf61)
5850     delete G30hf61;
5851   if (G40hf60)
5852     delete G40hf60;
5853   if (G40hf61)
5854     delete G40hf61;
5855 
5856   if (Ghf1)
5857     delete Ghf1;
5858   //========================================================================================== 22-1   HF:: Ratio plots   jeta = 0 - 21       jphi =0 - 17
5859   //======================================================================
5860   //======================================================================28.11.2018
5861   //======================================================================
5862   //======================================================================
5863 
5864   gStyle->SetOptStat(1110000);
5865   cout << "      RBX HF  Ratio plotsmore *****" << endl;
5866   cRBX31->Clear();
5867   /////////////////
5868   cRBX31->Divide(3, 1);
5869   //================
5870   cRBX31->cd(1);
5871   G20hf6->GetZaxis()->SetLabelSize(0.025);
5872   G20hf6->SetXTitle("             #eta  \b");
5873   G20hf6->SetYTitle("      #phi \b");
5874   G20hf6->SetTitle("<Rj> for |1-<R>| > 0.20 \b");
5875   G20hf6->SetStats(0);
5876   G20hf6->Draw("COLZ");
5877   //================
5878   cRBX31->cd(2);
5879   G30hf6->GetZaxis()->SetLabelSize(0.025);
5880   G30hf6->SetXTitle("             #eta  \b");
5881   G30hf6->SetYTitle("      #phi \b");
5882   G30hf6->SetTitle("<Rj> for |1-<R>| > 0.30 \b");
5883   G30hf6->SetStats(0);
5884   G30hf6->Draw("COLZ");
5885   //================
5886   cRBX31->cd(3);
5887   G40hf6->GetZaxis()->SetLabelSize(0.025);
5888   G40hf6->SetXTitle("             #eta  \b");
5889   G40hf6->SetYTitle("      #phi \b");
5890   G40hf6->SetTitle("<Rj> for |1-<R>| > 0.40 \b");
5891   G40hf6->SetStats(0);
5892   G40hf6->Draw("COLZ");
5893   //================
5894 
5895   /////////////////
5896   cRBX31->Update();
5897   cRBX31->Print("RBX-HF-3plotsmore.png");
5898   cRBX31->Clear();
5899 
5900   // clean-up
5901   if (G20hf6)
5902     delete G20hf6;
5903   if (G30hf6)
5904     delete G30hf6;
5905   if (G40hf6)
5906     delete G40hf6;
5907   gStyle->SetOptStat(0);
5908   ////////////////////////////////////////////////////////////////////////////////////
5909   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
5910   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
5911   cout << ">>>>>>>>>>>>>>>>>>>>>>>>                             " << endl;
5912   //////////////////////////////////////////////////////////////////////////////////// RBX  HF  study END:
5913 
5914   //////////////////////////////////////////////////////////////////////////////////// RBX study END:
5915 
5916   //////////////////////////////////////////////////////////////////////////////////// Special tests:
5917   //===============================================================================   occupancyHB
5918   // For occup