ROOT logo
#ifndef __CINT__
#include "TTree.h"
#include "TFile.h"
#include "TMath.h"
#endif
#include "triggerInfo.C"

// TODO read number of bits from AliVEvent?
#define NBITS 29
#define NMAXCLASSES 100
TString bitNames[NBITS] = {
"kMB",
"kINT7",
"kMUON",
"kHighMult",
"kEMC1",
"kCINT5",
"kCMUS5",
"kMUSH7",
"kMUL7",
"kMUU7",
"kEMC7",
"kMUS7",
"kPHI1",
"kPHI78",
"kEMCEJE",
"kEMCEGA",
"kCentral",
"kSemiCentral",
"kDG5",
"kZED",
"kSPI78",
"kINT8",
"kMuonSingleLowPt8",
"kMuonSingleHighPt8",
"kMuonLikeLowPt8",
"kMuonUnlikeLowPt8",
"kMuonUnlikeLowPt0",
"kUserDefined",
"kTRD"
};


//Int_t runLevelEventStatQA(TString qafilename="/data/alice/2013/LHC13f/000197348/pass2/QA_merge_archive.zip#event_stat.root", Int_t run=197348, TString ocdbStorage = "local:///data/alice/OCDB"){
//Int_t runLevelEventStatQA(TString qafilename="/data/alice/2011/LHC11a/000146805/pass4_with_SDD/QA_merge_archive.zip#event_stat.root", Int_t run=146805, TString ocdbStorage = "local:///data/alice/OCDB"){
//Int_t runLevelEventStatQA(TString qafilename="/data/alice/2013/LHC13g/000197584/pass1/QA_merge_archive.zip#event_stat.root", Int_t run=114783, TString ocdbStorage = "raw://"){
//Int_t runLevelEventStatQA(TString qafilename="/data/alice/2012/LHC12b/000177789/pass1/QA_merge_archive.zip#event_stat.root", Int_t run=177789, TString ocdbStorage = "local:///data/alice/OCDB"){
//Int_t runLevelEventStatQA(TString qafilename="/data/alice/2010/LHC10b/000114751/pass4/QA_merge_archive.zip#event_stat.root", Int_t run=114751, TString ocdbStorage = "local:///data/alice/OCDB"){
//Int_t runLevelEventStatQA(TString qafilename="/data/alice/2012/LHC12d/000184719/pass1/QA_merge_archive.zip#event_stat.root", Int_t run=184719, TString ocdbStorage = "local:///data/alice/OCDB"){
//Int_t runLevelEventStatQA(TString qafilename="/data/alice/2012/LHC12h/000189694/pass1/QA_merge_archive.zip#event_stat.root", Int_t run=189694, TString ocdbStorage = "local:///data/alice/OCDB"){
//Int_t runLevelEventStatQA(TString qafilename="/data/alice/sim/2014/LHC14j5/138192/QA_merge_archive.zip#event_stat.root", Int_t run=138192, TString ocdbStorage = "local:///data/alice/OCDB"){
//  Int_t runLevelEventStatQA(TString qafilename="/alice/data/2010/LHC10d/000124360/pass4/QA_merge_archive.zip#event_stat.root", Int_t run=124360, TString ocdbStorage = "local:///alice/data/OCDB"){
  Int_t runLevelEventStatQA(TString qafilename="/alice/data/2010/LHC10f/000133007/pass4/QA_merge_archive.zip#event_stat.root", Int_t run=133007, TString ocdbStorage = "local:///alice/data/OCDB"){
  printf("runLevelEventStatQA %s %i\n",qafilename.Data(),run);
  gStyle->SetOptStat(0);
  gStyle->SetLineScalePS(1.5);
  gStyle->SetPadBottomMargin(0.08);
  gStyle->SetPadRightMargin(0.02);
  gStyle->SetPadTopMargin(0.07);
  gStyle->SetPadLeftMargin(0.07);

  TFile* fin = new TFile(qafilename);
  TH2D* h = (TH2D*) fin->Get("fHistStatistics");
  if (!h) { printf("fHistStatistics not found\n"); return 1; }

  // tree variables
  TObjArray classes = TObjArray();
  TObjString activeDetectors = TObjString();
  Int_t fill               = 0;
  Double_t run_duration    = 0;
  Int_t nBCsPerOrbit       = 0;
  Double_t refl0b          = 0;
  Double_t mu              = 0;
  Double_t lumi_seen       = 0;
  Double_t interactionRate = 0;
  ULong64_t class_l0b[NMAXCLASSES]         = {0};
  ULong64_t class_l0a[NMAXCLASSES]         = {0};
  ULong64_t class_l1b[NMAXCLASSES]         = {0};
  ULong64_t class_l1a[NMAXCLASSES]         = {0};
  ULong64_t class_l2b[NMAXCLASSES]         = {0};
  ULong64_t class_l2a[NMAXCLASSES]         = {0};
  Double_t  class_lifetime[NMAXCLASSES]    = {0};
  Double_t  class_lumi[NMAXCLASSES]        = {0};
  ULong64_t alias_recorded[NBITS]          = {0};
  ULong64_t alias_reconstructed[NBITS]     = {0};
  ULong64_t alias_accepted[NBITS]          = {0};
  Double_t alias_l0b_rate[NBITS]           = {0};
  Double_t alias_lifetime[NBITS]           = {0};
  Double_t alias_lumi_recorded[NBITS]      = {0};
  Double_t alias_lumi_reconstructed[NBITS] = {0};
  Double_t alias_lumi_accepted[NBITS]      = {0};

  TString refClass="";
  Double_t refSigma=-1;
  Double_t refEff = 1.;
  if      (               run<=118501) { refSigma=  62.; refEff = 1.00; refClass = "CINT1B-ABCE-NOPF-ALL";   } // pp_7.00: 62mb=54.3mb*1.15=sigma(VBAND)*R(INT1/VBAND) (Martino,2012-03-12,RunCond)
  else if (run>=118502 && run<=118561) { refSigma=  47.; refEff = 1.00; refClass = "CINT1B-ABCE-NOPF-ALL";   } // pp_0.90: 47mb=52 mb *0.91=sigma(INEL)*R(INT1/INEL) (arxiv: 1208.4968, fig.10 + table 3)
  else if (run>=118903 && run<=120829) { refSigma=  62.; refEff = 1.00; refClass = "CINT1B-ABCE-NOPF-ALL";   } // pp_7.00: 62mb=54.3mb*1.15=sigma(VBAND)*R(INT1/VBAND) (Martino,2012-03-12,RunCond)
  else if (run>=121039 && run<=121040) { refSigma=  47.; refEff = 1.00; refClass = "CINT1B-ABCE-NOPF-ALL";   } // pp_0.90: 47mb=52 mb *0.91=sigma(INEL)*R(INT1/INEL) (arxiv: 1208.4968, fig.10 + table 3)
  else if (run>=121041 && run<=126437) { refSigma=  62.; refEff = 1.00; refClass = "CINT1B-ABCE-NOPF-ALL";   } // pp_7.00: 62mb=54.3mb*1.15=sigma(VBAND)*R(INT1/VBAND) (Martino,2012-03-12,RunCond)
  else if (run>=126438 && run<=127718) { refSigma=  62.; refEff = 1.00; refClass = "CINT1-B-NOPF-ALLNOTRD";  } // pp_7.00: 62mb=54.3mb*1.15=sigma(VBAND)*R(INT1/VBAND) (Martino,2012-03-12,RunCond)
  else if (run>=127719 && run<=127730) { refSigma=  62.; refEff = 1.00; refClass = "CINT1B-ABCE-NOPF-ALL";   } // pp_7.00: 62mb=54.3mb*1.15=sigma(VBAND)*R(INT1/VBAND) (Martino,2012-03-12,RunCond)
  else if (run>=127731 && run<=136848) { refSigma=  62.; refEff = 1.00; refClass = "CINT1-B-NOPF-ALLNOTRD";  } // pp_7.00: 62mb=54.3mb*1.15=sigma(VBAND)*R(INT1/VBAND) (Martino,2012-03-12,RunCond)
  else if (run>=136849 && run<=139316) { refSigma=5970.; refEff = 0.78; refClass = "C0SMH-B-NOPF-ALL";       } // PbPb_2.76: (Oyama,2011-05-20,RunCond), sigma_hardronic = 7.64 b
  else if (run>=139328 && run<=139517) { refSigma=5970.; refEff = 0.78; refClass = "C0SMH-B-NOPF-ALLNOTRD";  } // PbPb_2.76: (Oyama,2011-05-20,RunCond), sigma_hardronic = 7.64 b
  else if (run>=145289 && run<=146860) { refSigma=  57.; refEff = 1.00; refClass = "CINT1-B-NOPF-ALLNOTRD";  } // pp_2.76: 57mb=47.7mb*1.20=sigma(VBAND)*R(INT1/VBAND) (Martino,2012-03-12,RunCond)
  else if (run>=146808 && run<=146814) { refSigma=  57.; refEff = 1.00; refClass = "CINT1-B-NOPF-ALL";       } // pp_2.76: 57mb=47.7mb*1.20=sigma(VBAND)*R(INT1/VBAND) (Martino,2012-03-12,RunCond)
  else if (run>=145815 && run<=146856) { refSigma=  57.; refEff = 1.00; refClass = "CINT1-B-NOPF-ALLNOTRD";  } // pp_2.76: 57mb=47.7mb*1.20=sigma(VBAND)*R(INT1/VBAND) (Martino,2012-03-12,RunCond)
  else if (run>=146857 && run<=146857) { refSigma=  57.; refEff = 1.00; refClass = "CINT1-B-NOPF-ALL";       } // pp_2.76: 57mb=47.7mb*1.20=sigma(VBAND)*R(INT1/VBAND) (Martino,2012-03-12,RunCond)
  else if (run>=146858 && run<=146860) { refSigma=  57.; refEff = 1.00; refClass = "CINT1-B-NOPF-ALLNOTRD";  } // pp_2.76: 57mb=47.7mb*1.20=sigma(VBAND)*R(INT1/VBAND) (Martino,2012-03-12,RunCond)
  else if (run>=148370 && run<=157078) { refSigma=  54.; refEff = 1.00; refClass = "CVBAND-B-NOPF-ALLNOTRD"; } // pp_7.00: 54.3mb (Martino,2012-03-12,RunCond)
  else if (run>=157079 && run<=165746) { refSigma=  24.; refEff = 0.44; refClass = "C0TVX-B-NOPF-ALLNOTRD";  } // pp_7.00: 24mb=54.3mb*0.44=sigma(VBAND)*R(0TVX/VBAND) (Martino,2012-03-12,RunCond)
  else if (run>=166477 && run<=170593) { refSigma=4100.; refEff = 0.54; refClass = "CVLN-B-NOPF-ALLNOTRD";   } // PbPb_2.76: (Martino,2013-03-15,RunCond)
  else if (run>=176658 && run<=177143) { refSigma=  25.; refEff = 0.45; refClass = "C0TVX-B-NOPF-ALLNOTRD";  } // pp_8.00: (Artem, 2013-10-04,RunCond)
  else if (run>=177146 && run<=177147) { refSigma=  25.; refEff = 0.45; refClass = "C0TVX-B-NOPF-CENTNOTRD"; } // pp_8.00: (Artem, 2013-10-04,RunCond)
  else if (run>=177148 && run<=177149) { refSigma=  25.; refEff = 0.45; refClass = "C0TVX-B-NOPF-ALLNOTRD";  } // pp_8.00: (Artem, 2013-10-04,RunCond)
  else if (run>=177150 && run<=177506) { refSigma=  25.; refEff = 0.45; refClass = "C0TVX-B-NOPF-CENTNOTRD"; } // pp_8.00: (Artem, 2013-10-04,RunCond)
  else if (run>=177580 && run<=178220) { refSigma=  25.; refEff = 0.45; refClass = "C0TVX-B-NOPF-ALLNOTRD";  } // pp_8.00: (Artem, 2013-10-04,RunCond)
  else if (run>=179444 && run<=188229) { refSigma=  25.; refEff = 0.45; refClass = "C0TVX-S-NOPF-ALLNOTRD";  } // pp_8.00: (Artem, 2013-10-04,RunCond)
  else if (run>=188230 && run<=188366) { refSigma=1590.; refEff = 0.76; refClass = "C0TVX-B-NOPF-ALLNOTRD";  } // pPb_5.02: pilot. arxiv:1405.1849
  else if (run>=188367 && run<=193692) { refSigma=  25.; refEff = 0.45; refClass = "C0TVX-S-NOPF-ALLNOTRD";  } // pp_8.00: (Artem, 2013-10-04,RunCond)
  else if (run>=193693 && run<=193766) { refSigma=  25.; refEff = 0.45; refClass = "C0TVX-B-NOPF-ALLNOTRD";  } // pp_8.00: (Artem, 2013-10-04,RunCond)
  else if (run>=195344 && run<=197388) { refSigma=1590.; refEff = 0.76; refClass = "C0TVX-B-NOPF-ALLNOTRD";  } // pPb_5.02: arxiv:1405.1849
  else if (run>=197470 && run<=197692) { refSigma=  18.; refEff = 0.39; refClass = "C0TVX-B-NOPF-ALLNOTRD";  } // pp_2.76: 18mb=47.7mb*0.39=sigma(VBAND)*R(0TVX/VBAND) (Martino,2012-03-12,RunCond)

  Double_t par[5] = {0};
  TString det;
  triggerInfo(run,refClass,ocdbStorage,det,par);
  fill          = TMath::Nint(par[0]);
  run_duration   = par[1];
  refl0b         = par[2];
  nBCsPerOrbit   = TMath::Nint(par[3]);
  mu             = par[4];
  activeDetectors.SetString(det.Data());

  interactionRate = (run_duration>1e-10) ? refl0b/run_duration/refEff : 0;
  if (refSigma>1.e-10) lumi_seen = refl0b/refSigma/1000; //[ub-1]
  if (mu>1.e-10) lumi_seen*=mu/(1-TMath::Exp(-mu)); // pile-up correction

  classes = GetClasses(run,ocdbStorage,class_l0b,class_l0a,class_l1b,class_l1a,class_l2b,class_l2a);
  for (Int_t i=0;i<classes.GetEntriesFast();i++){
    // printf("%30s %12lli %10lli %10lli %10lli %10lli %10lli\n",classes.At(i)->GetName(),class_l0b[i],class_l0a[i],class_l1b[i],class_l1a[i],class_l2b[i],class_l2a[i]);
    class_lifetime[i] = class_l0b[i]>0 ? Double_t(class_l0a[i])/class_l0b[i]: 0;
    class_lifetime[i]*= class_l1b[i]>0 ? Double_t(class_l1a[i])/class_l1b[i]: 0;
    class_lifetime[i]*= class_l2b[i]>0 ? Double_t(class_l2a[i])/class_l2b[i]: 0;
    class_lumi[i] = lumi_seen*class_lifetime[i];
  }
  

  TFile* fout = new TFile("trending.root","recreate");
  TTree* t = new TTree("trending","tree of trending variables");
  t->Branch("run",&run);
  t->Branch("fill",&fill);
  t->Branch("bcs",&nBCsPerOrbit);
  t->Branch("run_duration",&run_duration);
  t->Branch("mu",&mu);
  t->Branch("interactionRate",&interactionRate);
  t->Branch("refl0b",&refl0b);
  t->Branch("lumi_seen",&lumi_seen);
  t->Branch("classes",&classes);
  t->Branch("class_l0b",&class_l0b,Form("class_l0b[%i]/l",NMAXCLASSES));
  t->Branch("class_l0a",&class_l0a,Form("class_l0a[%i]/l",NMAXCLASSES));
  t->Branch("class_l1b",&class_l1b,Form("class_l1b[%i]/l",NMAXCLASSES));
  t->Branch("class_l1a",&class_l1a,Form("class_l1a[%i]/l",NMAXCLASSES));
  t->Branch("class_l2b",&class_l2b,Form("class_l2b[%i]/l",NMAXCLASSES));
  t->Branch("class_l2a",&class_l2a,Form("class_l2a[%i]/l",NMAXCLASSES));
  t->Branch("class_lifetime",&class_lifetime,Form("class_lifetime[%i]/D",NMAXCLASSES));
  t->Branch("class_lumi",&class_lumi,Form("class_lumi[%i]/D",NMAXCLASSES));
  t->Branch("alias_recorded",&alias_recorded,Form("alias_recorded[%i]/l",NBITS));
  t->Branch("alias_reconstructed",&alias_reconstructed,Form("alias_reconstructed[%i]/l",NBITS));
  t->Branch("alias_accepted",&alias_accepted,Form("alias_accepted[%i]/l",NBITS));
  t->Branch("alias_l0b_rate",&alias_lifetime,Form("alias_l0b_rate[%i]/D",NBITS));
  t->Branch("alias_lifetime",&alias_lifetime,Form("alias_lifetime[%i]/D",NBITS));
  t->Branch("alias_lumi_recorded",&alias_lumi_recorded,Form("alias_lumi_recorded[%i]/D",NBITS));
  t->Branch("alias_lumi_reconstructed",&alias_lumi_reconstructed,Form("alias_lumi_reconstructed[%i]/D",NBITS));
  t->Branch("alias_lumi_accepted",&alias_lumi_accepted,Form("alias_lumi_accepted[%i]/D",NBITS));
  t->Branch("activeDetectors",&activeDetectors);
  
  for (Int_t j=1;j<=h->GetNbinsY();j++){
    TString label = h->GetYaxis()->GetBinLabel(j);
    // skip background triggers
    // TODO introduce identifier to filter-out background triggers
    if      (label.Contains("-A-"))      continue;
    else if (label.Contains("-C-"))      continue;
    else if (label.Contains("-E-"))      continue;
    else if (label.Contains("-AC-"))     continue;
    else if (label.Contains("-ACE-"))    continue;
    else if (label.Contains("-GA-"))     continue;
    else if (label.Contains("-GC-"))     continue;
    else if (label.Contains("1A-ABCE-")) continue;
    else if (label.Contains("1C-ABCE-")) continue;
    else if (label.Contains("C0LSR-ABCE-")) continue;

    // Read mask
    // TODO think how to propagate mask with TBit aliases
    UInt_t mask = 0;
    TString classList = ""; // list of classes for given PS bit
    TObjArray* array = label.Tokenize(" ");
    for (Int_t itoken=0;itoken<array->GetEntries();itoken++){
      TString token = array->At(itoken)->GetName();
      if (itoken==0) classList = token; 
      if (token[0]!='&') continue;
      token.Remove(0,1);
      mask = token.Atoi();
      break;
    }
    array->Delete();
    delete array;
    printf("%s\n",label.Data());
    printf("%i\n",mask);
    if (!mask) continue;
    // Fill all and accepted counters for the most significant bit
    Int_t ibit = TMath::Nint(TMath::Log2(mask));
    if (ibit>=NBITS) continue;
    if (alias_recorded[ibit]) break; 

    alias_reconstructed[ibit] = Int_t(h->GetBinContent(1             ,j));
    alias_accepted[ibit]      = Int_t(h->GetBinContent(h->GetNbinsX(),j));
    
//    printf("%4i %8i %8i\n",ibit,alias_reconstructed[ibit],alias_accepted[ibit]);
    
    classList.Remove(0,1); // remove +
    array = classList.Tokenize(",");
    // if trigger bit corresponds to several active classes, just take the last one
    // example: kTRD
    // TODO think about more elegant solution
    for (Int_t i=0;i<array->GetEntriesFast();i++){
      TString token = array->At(i)->GetName();
      AliTriggerClass* cl = (AliTriggerClass*) classes.FindObject(token.Data());
      if (!cl) continue;
      Int_t iclass = classes.IndexOf(cl);
      printf(" %30s",token.Data());
      printf(" %12lli",class_l0b[iclass]);
      printf(" %12lli",class_l0a[iclass]);
      printf(" %12lli",class_l1b[iclass]);
      printf(" %12lli",class_l1a[iclass]);
      printf(" %12lli",class_l2b[iclass]);
      printf(" %12lli",class_l2a[iclass]);
      printf("\n");
      alias_recorded[ibit]      = class_l2a[iclass];
      alias_lifetime[ibit]      = class_lifetime[iclass];
      alias_lumi_recorded[ibit] = class_lumi[iclass];
      if (!alias_recorded[ibit]) continue;
      alias_lumi_reconstructed[ibit] = alias_lumi_recorded[ibit]/alias_recorded[ibit]*alias_reconstructed[ibit];
      alias_lumi_accepted[ibit]      = alias_lumi_recorded[ibit]/alias_recorded[ibit]*alias_accepted[ibit];
    }
    array->Delete();
    delete array;

    // Fill run QA histograms
    const char* bitName = bitNames[ibit].Data();
    TH1F* hV0A          = (TH1F*) fin->Get(Form("trigger_histograms_%s/fHistV0A"         ,label.Data()));
    TH1F* hV0C          = (TH1F*) fin->Get(Form("trigger_histograms_%s/fHistV0C"         ,label.Data()));
    TH1F* hFiredBitsSPD = (TH1F*) fin->Get(Form("trigger_histograms_%s/fHistFiredBitsSPD",label.Data()));
    TH2F* hBitsSPD      = (TH2F*) fin->Get(Form("trigger_histograms_%s/fHistBitsSPD"     ,label.Data()));
    TH1F* hTDCZDC       = (TH1F*) fin->Get(Form("trigger_histograms_%s/fHistTDCZDC"      ,label.Data()));
    TH2F* hTimeZDC      = (TH2F*) fin->Get(Form("trigger_histograms_%s/fHistTimeZDC"     ,label.Data()));
    TH2F* hTimeCorrZDC  = (TH2F*) fin->Get(Form("trigger_histograms_%s/fHistTimeCorrZDC" ,label.Data()));
    if (!hV0A)          { printf("QA histogram not found\n"); return 1; }
    if (!hV0C)          { printf("QA histogram not found\n"); return 1; }
    if (!hFiredBitsSPD) { printf("QA histogram not found\n"); return 1; }
    if (!hBitsSPD)      { printf("QA histogram not found\n"); return 1; }
    if (!hTDCZDC)       { printf("QA histogram not found\n"); return 1; }
    if (!hTimeZDC)      { printf("QA histogram not found\n"); return 1; }
    if (!hTimeCorrZDC)  { printf("QA histogram not found\n"); return 1; }

    TCanvas* cV0A = new TCanvas(Form("cV0A_%s",bitName),Form("cV0A_%s",bitName),1000,800);
    gPad->SetLogy();
    hV0A->SetTitle(Form("%s: V0A",bitName));
    hV0A->SetLineWidth(2);
    hV0A->SetLineColor(kBlue);
    hV0A->Draw();
    gPad->Print(Form("%s_V0A.pdf",bitName));
    hV0A->Write(Form("%s_V0A",bitName));

    TCanvas* cV0C = new TCanvas(Form("cV0C_%s",bitName),Form("cV0C_%s",bitName),1000,800);
    gPad->SetLogy();
    hV0C->SetTitle(Form("%s: V0C",bitName));
    hV0C->SetLineWidth(2);
    hV0C->SetLineColor(kBlue);
    hV0C->Draw();
    gPad->Print(Form("%s_V0C.pdf",bitName));
    hV0C->Write(Form("%s_V0C",bitName));

    TCanvas* cFiredBitsSPD = new TCanvas(Form("cFiredBitsSPD_%s",bitName),Form("cFiredBitsSPD_%s",bitName),1800,500);
    gPad->SetLogy();
    gPad->SetMargin(0.05,0.01,0.12,0.06);
    hFiredBitsSPD->SetTitle(Form("%s: hardware FO",bitName));
    hFiredBitsSPD->SetTitleFont(43);
    hFiredBitsSPD->SetTitleSize(25);
    hFiredBitsSPD->GetYaxis()->SetTitleFont(43);
    hFiredBitsSPD->GetXaxis()->SetLabelFont(43);
    hFiredBitsSPD->GetYaxis()->SetLabelFont(43);
    hFiredBitsSPD->GetYaxis()->SetTitleSize(25);
    hFiredBitsSPD->GetXaxis()->SetLabelSize(25);
    hFiredBitsSPD->GetYaxis()->SetLabelSize(25);
    hFiredBitsSPD->GetYaxis()->SetTickLength(0.01);
    hFiredBitsSPD->GetYaxis()->SetTitleOffset(0.5);
    hFiredBitsSPD->GetYaxis()->SetDecimals(1);
    hFiredBitsSPD->SetLineWidth(2);
    hFiredBitsSPD->SetLineColor(kBlue);
    hFiredBitsSPD->Draw();
    gPad->Print(Form("%s_FiredBitsSPD.pdf",bitName));
    hFiredBitsSPD->Write(Form("%s_FiredBitsSPD",bitName));

    TCanvas* cBitsSPD = new TCanvas(Form("cBitsSPD_%s",bitName),Form("cBitsSPD_%s",bitName),800,800);
    gPad->SetLogz();
    gPad->SetMargin(0.12,0.12,0.10,0.06);
    hBitsSPD->SetTitle(Form("%s: hardware FO vs offline FO",bitName));
    hBitsSPD->GetXaxis()->SetTitleOffset(1.3);
    hBitsSPD->GetYaxis()->SetTitleOffset(1.6);
    hBitsSPD->Draw("colz");
    gPad->Print(Form("%s_BitsSPD.pdf",bitName));
    hBitsSPD->Write(Form("%s_BitsSPD",bitName));

    TCanvas* cTimeZDC = new TCanvas(Form("cTimeZDC_%s",bitName),Form("cTimeZDC_%s",bitName),800,800);
    gPad->SetLogz();
    gPad->SetMargin(0.12,0.12,0.10,0.06);
    hTimeZDC->SetTitle(Form("%s: ZDC timing;TDC timing C-A;TDC timing C+A",bitName));
    hTimeZDC->GetXaxis()->SetTitleOffset(1.3);
    hTimeZDC->GetYaxis()->SetTitleOffset(1.6);
    hTimeZDC->Draw("colz");
    gPad->Print(Form("%s_TimeZDC.pdf",bitName));
    hTimeZDC->Write(Form("%s_TimeZDC",bitName));

    TCanvas* cTimeCorrZDC = new TCanvas(Form("cTimeCorrZDC_%s",bitName),Form("cTimeCorrZDC_%s",bitName),800,800);
    gPad->SetLogz();
    gPad->SetMargin(0.12,0.12,0.10,0.06);
    hTimeCorrZDC->SetTitle(Form("%s: corrected ZDC timing;TDC timing C-A;TDC timing C+A",bitName));
    hTimeCorrZDC->GetXaxis()->SetTitleOffset(1.3);
    hTimeCorrZDC->GetYaxis()->SetTitleOffset(1.6);
    hTimeCorrZDC->Draw("colz");
    gPad->Print(Form("%s_TimeCorrZDC.pdf",bitName));
    hTimeCorrZDC->Write(Form("%s_TimeCorrZDC",bitName));
  }
  
  t->Fill();
  t->Write();
  fout->Close();
  return 0;
}


 runLevelEventStatQA.C:1
 runLevelEventStatQA.C:2
 runLevelEventStatQA.C:3
 runLevelEventStatQA.C:4
 runLevelEventStatQA.C:5
 runLevelEventStatQA.C:6
 runLevelEventStatQA.C:7
 runLevelEventStatQA.C:8
 runLevelEventStatQA.C:9
 runLevelEventStatQA.C:10
 runLevelEventStatQA.C:11
 runLevelEventStatQA.C:12
 runLevelEventStatQA.C:13
 runLevelEventStatQA.C:14
 runLevelEventStatQA.C:15
 runLevelEventStatQA.C:16
 runLevelEventStatQA.C:17
 runLevelEventStatQA.C:18
 runLevelEventStatQA.C:19
 runLevelEventStatQA.C:20
 runLevelEventStatQA.C:21
 runLevelEventStatQA.C:22
 runLevelEventStatQA.C:23
 runLevelEventStatQA.C:24
 runLevelEventStatQA.C:25
 runLevelEventStatQA.C:26
 runLevelEventStatQA.C:27
 runLevelEventStatQA.C:28
 runLevelEventStatQA.C:29
 runLevelEventStatQA.C:30
 runLevelEventStatQA.C:31
 runLevelEventStatQA.C:32
 runLevelEventStatQA.C:33
 runLevelEventStatQA.C:34
 runLevelEventStatQA.C:35
 runLevelEventStatQA.C:36
 runLevelEventStatQA.C:37
 runLevelEventStatQA.C:38
 runLevelEventStatQA.C:39
 runLevelEventStatQA.C:40
 runLevelEventStatQA.C:41
 runLevelEventStatQA.C:42
 runLevelEventStatQA.C:43
 runLevelEventStatQA.C:44
 runLevelEventStatQA.C:45
 runLevelEventStatQA.C:46
 runLevelEventStatQA.C:47
 runLevelEventStatQA.C:48
 runLevelEventStatQA.C:49
 runLevelEventStatQA.C:50
 runLevelEventStatQA.C:51
 runLevelEventStatQA.C:52
 runLevelEventStatQA.C:53
 runLevelEventStatQA.C:54
 runLevelEventStatQA.C:55
 runLevelEventStatQA.C:56
 runLevelEventStatQA.C:57
 runLevelEventStatQA.C:58
 runLevelEventStatQA.C:59
 runLevelEventStatQA.C:60
 runLevelEventStatQA.C:61
 runLevelEventStatQA.C:62
 runLevelEventStatQA.C:63
 runLevelEventStatQA.C:64
 runLevelEventStatQA.C:65
 runLevelEventStatQA.C:66
 runLevelEventStatQA.C:67
 runLevelEventStatQA.C:68
 runLevelEventStatQA.C:69
 runLevelEventStatQA.C:70
 runLevelEventStatQA.C:71
 runLevelEventStatQA.C:72
 runLevelEventStatQA.C:73
 runLevelEventStatQA.C:74
 runLevelEventStatQA.C:75
 runLevelEventStatQA.C:76
 runLevelEventStatQA.C:77
 runLevelEventStatQA.C:78
 runLevelEventStatQA.C:79
 runLevelEventStatQA.C:80
 runLevelEventStatQA.C:81
 runLevelEventStatQA.C:82
 runLevelEventStatQA.C:83
 runLevelEventStatQA.C:84
 runLevelEventStatQA.C:85
 runLevelEventStatQA.C:86
 runLevelEventStatQA.C:87
 runLevelEventStatQA.C:88
 runLevelEventStatQA.C:89
 runLevelEventStatQA.C:90
 runLevelEventStatQA.C:91
 runLevelEventStatQA.C:92
 runLevelEventStatQA.C:93
 runLevelEventStatQA.C:94
 runLevelEventStatQA.C:95
 runLevelEventStatQA.C:96
 runLevelEventStatQA.C:97
 runLevelEventStatQA.C:98
 runLevelEventStatQA.C:99
 runLevelEventStatQA.C:100
 runLevelEventStatQA.C:101
 runLevelEventStatQA.C:102
 runLevelEventStatQA.C:103
 runLevelEventStatQA.C:104
 runLevelEventStatQA.C:105
 runLevelEventStatQA.C:106
 runLevelEventStatQA.C:107
 runLevelEventStatQA.C:108
 runLevelEventStatQA.C:109
 runLevelEventStatQA.C:110
 runLevelEventStatQA.C:111
 runLevelEventStatQA.C:112
 runLevelEventStatQA.C:113
 runLevelEventStatQA.C:114
 runLevelEventStatQA.C:115
 runLevelEventStatQA.C:116
 runLevelEventStatQA.C:117
 runLevelEventStatQA.C:118
 runLevelEventStatQA.C:119
 runLevelEventStatQA.C:120
 runLevelEventStatQA.C:121
 runLevelEventStatQA.C:122
 runLevelEventStatQA.C:123
 runLevelEventStatQA.C:124
 runLevelEventStatQA.C:125
 runLevelEventStatQA.C:126
 runLevelEventStatQA.C:127
 runLevelEventStatQA.C:128
 runLevelEventStatQA.C:129
 runLevelEventStatQA.C:130
 runLevelEventStatQA.C:131
 runLevelEventStatQA.C:132
 runLevelEventStatQA.C:133
 runLevelEventStatQA.C:134
 runLevelEventStatQA.C:135
 runLevelEventStatQA.C:136
 runLevelEventStatQA.C:137
 runLevelEventStatQA.C:138
 runLevelEventStatQA.C:139
 runLevelEventStatQA.C:140
 runLevelEventStatQA.C:141
 runLevelEventStatQA.C:142
 runLevelEventStatQA.C:143
 runLevelEventStatQA.C:144
 runLevelEventStatQA.C:145
 runLevelEventStatQA.C:146
 runLevelEventStatQA.C:147
 runLevelEventStatQA.C:148
 runLevelEventStatQA.C:149
 runLevelEventStatQA.C:150
 runLevelEventStatQA.C:151
 runLevelEventStatQA.C:152
 runLevelEventStatQA.C:153
 runLevelEventStatQA.C:154
 runLevelEventStatQA.C:155
 runLevelEventStatQA.C:156
 runLevelEventStatQA.C:157
 runLevelEventStatQA.C:158
 runLevelEventStatQA.C:159
 runLevelEventStatQA.C:160
 runLevelEventStatQA.C:161
 runLevelEventStatQA.C:162
 runLevelEventStatQA.C:163
 runLevelEventStatQA.C:164
 runLevelEventStatQA.C:165
 runLevelEventStatQA.C:166
 runLevelEventStatQA.C:167
 runLevelEventStatQA.C:168
 runLevelEventStatQA.C:169
 runLevelEventStatQA.C:170
 runLevelEventStatQA.C:171
 runLevelEventStatQA.C:172
 runLevelEventStatQA.C:173
 runLevelEventStatQA.C:174
 runLevelEventStatQA.C:175
 runLevelEventStatQA.C:176
 runLevelEventStatQA.C:177
 runLevelEventStatQA.C:178
 runLevelEventStatQA.C:179
 runLevelEventStatQA.C:180
 runLevelEventStatQA.C:181
 runLevelEventStatQA.C:182
 runLevelEventStatQA.C:183
 runLevelEventStatQA.C:184
 runLevelEventStatQA.C:185
 runLevelEventStatQA.C:186
 runLevelEventStatQA.C:187
 runLevelEventStatQA.C:188
 runLevelEventStatQA.C:189
 runLevelEventStatQA.C:190
 runLevelEventStatQA.C:191
 runLevelEventStatQA.C:192
 runLevelEventStatQA.C:193
 runLevelEventStatQA.C:194
 runLevelEventStatQA.C:195
 runLevelEventStatQA.C:196
 runLevelEventStatQA.C:197
 runLevelEventStatQA.C:198
 runLevelEventStatQA.C:199
 runLevelEventStatQA.C:200
 runLevelEventStatQA.C:201
 runLevelEventStatQA.C:202
 runLevelEventStatQA.C:203
 runLevelEventStatQA.C:204
 runLevelEventStatQA.C:205
 runLevelEventStatQA.C:206
 runLevelEventStatQA.C:207
 runLevelEventStatQA.C:208
 runLevelEventStatQA.C:209
 runLevelEventStatQA.C:210
 runLevelEventStatQA.C:211
 runLevelEventStatQA.C:212
 runLevelEventStatQA.C:213
 runLevelEventStatQA.C:214
 runLevelEventStatQA.C:215
 runLevelEventStatQA.C:216
 runLevelEventStatQA.C:217
 runLevelEventStatQA.C:218
 runLevelEventStatQA.C:219
 runLevelEventStatQA.C:220
 runLevelEventStatQA.C:221
 runLevelEventStatQA.C:222
 runLevelEventStatQA.C:223
 runLevelEventStatQA.C:224
 runLevelEventStatQA.C:225
 runLevelEventStatQA.C:226
 runLevelEventStatQA.C:227
 runLevelEventStatQA.C:228
 runLevelEventStatQA.C:229
 runLevelEventStatQA.C:230
 runLevelEventStatQA.C:231
 runLevelEventStatQA.C:232
 runLevelEventStatQA.C:233
 runLevelEventStatQA.C:234
 runLevelEventStatQA.C:235
 runLevelEventStatQA.C:236
 runLevelEventStatQA.C:237
 runLevelEventStatQA.C:238
 runLevelEventStatQA.C:239
 runLevelEventStatQA.C:240
 runLevelEventStatQA.C:241
 runLevelEventStatQA.C:242
 runLevelEventStatQA.C:243
 runLevelEventStatQA.C:244
 runLevelEventStatQA.C:245
 runLevelEventStatQA.C:246
 runLevelEventStatQA.C:247
 runLevelEventStatQA.C:248
 runLevelEventStatQA.C:249
 runLevelEventStatQA.C:250
 runLevelEventStatQA.C:251
 runLevelEventStatQA.C:252
 runLevelEventStatQA.C:253
 runLevelEventStatQA.C:254
 runLevelEventStatQA.C:255
 runLevelEventStatQA.C:256
 runLevelEventStatQA.C:257
 runLevelEventStatQA.C:258
 runLevelEventStatQA.C:259
 runLevelEventStatQA.C:260
 runLevelEventStatQA.C:261
 runLevelEventStatQA.C:262
 runLevelEventStatQA.C:263
 runLevelEventStatQA.C:264
 runLevelEventStatQA.C:265
 runLevelEventStatQA.C:266
 runLevelEventStatQA.C:267
 runLevelEventStatQA.C:268
 runLevelEventStatQA.C:269
 runLevelEventStatQA.C:270
 runLevelEventStatQA.C:271
 runLevelEventStatQA.C:272
 runLevelEventStatQA.C:273
 runLevelEventStatQA.C:274
 runLevelEventStatQA.C:275
 runLevelEventStatQA.C:276
 runLevelEventStatQA.C:277
 runLevelEventStatQA.C:278
 runLevelEventStatQA.C:279
 runLevelEventStatQA.C:280
 runLevelEventStatQA.C:281
 runLevelEventStatQA.C:282
 runLevelEventStatQA.C:283
 runLevelEventStatQA.C:284
 runLevelEventStatQA.C:285
 runLevelEventStatQA.C:286
 runLevelEventStatQA.C:287
 runLevelEventStatQA.C:288
 runLevelEventStatQA.C:289
 runLevelEventStatQA.C:290
 runLevelEventStatQA.C:291
 runLevelEventStatQA.C:292
 runLevelEventStatQA.C:293
 runLevelEventStatQA.C:294
 runLevelEventStatQA.C:295
 runLevelEventStatQA.C:296
 runLevelEventStatQA.C:297
 runLevelEventStatQA.C:298
 runLevelEventStatQA.C:299
 runLevelEventStatQA.C:300
 runLevelEventStatQA.C:301
 runLevelEventStatQA.C:302
 runLevelEventStatQA.C:303
 runLevelEventStatQA.C:304
 runLevelEventStatQA.C:305
 runLevelEventStatQA.C:306
 runLevelEventStatQA.C:307
 runLevelEventStatQA.C:308
 runLevelEventStatQA.C:309
 runLevelEventStatQA.C:310
 runLevelEventStatQA.C:311
 runLevelEventStatQA.C:312
 runLevelEventStatQA.C:313
 runLevelEventStatQA.C:314
 runLevelEventStatQA.C:315
 runLevelEventStatQA.C:316
 runLevelEventStatQA.C:317
 runLevelEventStatQA.C:318
 runLevelEventStatQA.C:319
 runLevelEventStatQA.C:320
 runLevelEventStatQA.C:321
 runLevelEventStatQA.C:322
 runLevelEventStatQA.C:323
 runLevelEventStatQA.C:324
 runLevelEventStatQA.C:325
 runLevelEventStatQA.C:326
 runLevelEventStatQA.C:327
 runLevelEventStatQA.C:328
 runLevelEventStatQA.C:329
 runLevelEventStatQA.C:330
 runLevelEventStatQA.C:331
 runLevelEventStatQA.C:332
 runLevelEventStatQA.C:333
 runLevelEventStatQA.C:334
 runLevelEventStatQA.C:335
 runLevelEventStatQA.C:336
 runLevelEventStatQA.C:337
 runLevelEventStatQA.C:338
 runLevelEventStatQA.C:339
 runLevelEventStatQA.C:340
 runLevelEventStatQA.C:341
 runLevelEventStatQA.C:342
 runLevelEventStatQA.C:343
 runLevelEventStatQA.C:344