Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-12 23:01:26

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