Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:52:10

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