Back to home page

Project CMSSW displayed by LXR

 
 

    


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