Ejemplo n.º 1
0
TH1D* createCorrelationPlot(TH2D* numerator2D, TH1D* denominator1D) {
    TH1::SetDefaultSumw2();
    normaliseHist(denominator1D);
    std::vector<double> massBins = generate4Bins();
    TH2D* denominator2D = create2Dfrom1D(massBins, denominator1D);
    normaliseHist(numerator2D);
    TH2D* corr2D = (TH2D*) numerator2D->Clone();
    corr2D->Divide(denominator2D);
    int nBinsX = massBins.size()-1;
    int nUniqueBins = (nBinsX+1)*nBinsX/2.;
    TH1D* corr1D = unique1DBinsFrom2D(corr2D, nUniqueBins);
    setCorrTitlesMaxMin(corr1D);
    return corr1D;
}
Ejemplo n.º 2
0
//___________________________________________________________________
Int_t studyBinZero(TString pathData, TString fileNameData, TString listName = "",
                   Double_t etaLow = -0.9, Double_t etaUp = 0.9,
                   Double_t lowerCentrality = -2, Double_t upperCentrality = -2)
{
  PrintSettingsAxisRangeForMultiplicityAxisForMB();
  
  TString pathNameData = Form("%s/%s", pathData.Data(), fileNameData.Data());
  
  if (listName == "") {
    listName = pathNameData;
    listName.Replace(0, listName.Last('/') + 1, "");
    listName.ReplaceAll(".root", "");
  }
  
  TObjArray* histList = 0x0;
  
  TFile* f = TFile::Open(pathNameData.Data());
  if (!f)  {
    std::cout << std::endl;
    std::cout << "Failed to open file \"" << pathNameData.Data() << "\"!" << std::endl;
    return -1;
  }
  
  histList = (TObjArray*)(f->Get(listName.Data()));
  if (!histList) {
    std::cout << std::endl;
    std::cout << "Failed to load list \"" << listName.Data() << "\"!" << std::endl;
    return -1;
  }
  
  // Extract the data histograms
  TH1* hNumEventsTriggerSel = dynamic_cast<TH1*>(histList->FindObject("fhEventsTriggerSel"));
  TH1* hNumEventsTriggerSelVtxCut = dynamic_cast<TH1*>(histList->FindObject("fhEventsTriggerSelVtxCut"));
  TH1* hNumEventsTriggerSelVtxCutZ= dynamic_cast<TH1*>(histList->FindObject("fhEventsProcessedNoPileUpRejection"));
  TH1* hNumEventsTriggerSelVtxCutZPileUpRej= dynamic_cast<TH1*>(histList->FindObject("fhEventsProcessed"));
  
  THnSparse* hDataTriggerSel = dynamic_cast<THnSparse*>(histList->FindObject("fChargedGenPrimariesTriggerSel"));
  THnSparse* hDataTriggerSelVtxCut = dynamic_cast<THnSparse*>(histList->FindObject("fChargedGenPrimariesTriggerSelVtxCut"));
  THnSparse* hDataTriggerSelVtxCutZ = dynamic_cast<THnSparse*>(histList->FindObject("fChargedGenPrimariesTriggerSelVtxCutZ"));
  THnSparse* hDataTriggerSelVtxCutZPileUpRej = dynamic_cast<THnSparse*>(histList->FindObject("fChargedGenPrimariesTriggerSelVtxCutZPileUpRej"));
  
  setSparseErrors(hDataTriggerSel);
  setSparseErrors(hDataTriggerSelVtxCut);
  setSparseErrors(hDataTriggerSelVtxCutZ);
  setSparseErrors(hDataTriggerSelVtxCutZPileUpRej);
  
  
  
  // Set multiplicity range, if desired. Note that mult and pT axes are the same for all histos
  Int_t lowerCentralityBinLimit = -1;
  Int_t upperCentralityBinLimit = -2;
  Bool_t restrictCentralityAxis = kFALSE;
  Double_t actualLowerCentrality = -1.;
  Double_t actualUpperCentrality = -1.;
  
  if (lowerCentrality >= -1 && upperCentrality >= -1) {
    // Add subtract a very small number to avoid problems with values right on the border between to bins
    lowerCentralityBinLimit = hNumEventsTriggerSel->GetXaxis()->FindFixBin(lowerCentrality + 0.001);
    upperCentralityBinLimit = hNumEventsTriggerSel->GetXaxis()->FindFixBin(upperCentrality - 0.001);
    
    // Check if the values look reasonable
    if (lowerCentralityBinLimit <= upperCentralityBinLimit && lowerCentralityBinLimit >= 1
        && upperCentralityBinLimit <= hNumEventsTriggerSel->GetXaxis()->GetNbins()) {
      actualLowerCentrality = hNumEventsTriggerSel->GetXaxis()->GetBinLowEdge(lowerCentralityBinLimit);
      actualUpperCentrality = hNumEventsTriggerSel->GetXaxis()->GetBinUpEdge(upperCentralityBinLimit);

      restrictCentralityAxis = kTRUE;
    }
    else {
      std::cout << std::endl;
      std::cout << "Requested centrality range out of limits or upper and lower limit are switched!" << std::endl;
      return -1;
    }
  }
  
  if (!restrictCentralityAxis)
    GetAxisRangeForMultiplicityAxisForMB(hNumEventsTriggerSel->GetXaxis(), lowerCentralityBinLimit, upperCentralityBinLimit);
  
  hNumEventsTriggerSel->GetXaxis()->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit);
  
  actualLowerCentrality = hNumEventsTriggerSel->GetXaxis()->GetBinLowEdge(hNumEventsTriggerSel->GetXaxis()->GetFirst());
  actualUpperCentrality = hNumEventsTriggerSel->GetXaxis()->GetBinUpEdge(hNumEventsTriggerSel->GetXaxis()->GetLast());
  
  std::cout << "centrality: ";
  if (restrictCentralityAxis) {
    std::cout << actualLowerCentrality << " - " << actualUpperCentrality << std::endl;
    std::cout << "WARNING: Does it really make sense to restrict the centrality? Usually, centrality estimators imply centrality >= 0!"
              << std::endl;
  }
  else
    std::cout << "MB (" << actualLowerCentrality << " - " << actualUpperCentrality << ")" << std::endl;
    
  if (restrictCentralityAxis) {
    hDataTriggerSel->GetAxis(iMult)->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit);
    hDataTriggerSelVtxCut->GetAxis(iMult)->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit);
    hDataTriggerSelVtxCutZ->GetAxis(iMult)->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit);
    hDataTriggerSelVtxCutZPileUpRej->GetAxis(iMult)->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit);
  }
  
  
  // Restrict eta range
  const Int_t lowerEtaBinLimit = hDataTriggerSel->GetAxis(iEta)->FindFixBin(etaLow + 0.0001);
  const Int_t upperEtaBinLimit = hDataTriggerSel->GetAxis(iEta)->FindFixBin(etaUp  - 0.0001);
  
  const Double_t actualLowerEta = hDataTriggerSel->GetAxis(iEta)->GetBinLowEdge(lowerEtaBinLimit);
  const Double_t actualUpperEta = hDataTriggerSel->GetAxis(iEta)->GetBinUpEdge(upperEtaBinLimit);
  
  std::cout << "Eta: ";
  std::cout << actualLowerEta << " - " << actualUpperEta << std::endl;
  
  
  
  Bool_t symmetricInEta = TMath::Abs(TMath::Abs(actualLowerEta) - TMath::Abs(actualUpperEta)) < 1e-6;
  TString etaRange = symmetricInEta ? Form("|#it{#eta}| < %.1f", TMath::Abs(actualLowerEta)) 
                                    : Form("%.1f < #it{#eta} < %.1f", actualLowerEta, actualUpperEta); 
  
  hDataTriggerSel->GetAxis(iEta)->SetRange(lowerEtaBinLimit, upperEtaBinLimit);
  hDataTriggerSelVtxCut->GetAxis(iEta)->SetRange(lowerEtaBinLimit, upperEtaBinLimit);
  hDataTriggerSelVtxCutZ->GetAxis(iEta)->SetRange(lowerEtaBinLimit, upperEtaBinLimit);
  hDataTriggerSelVtxCutZPileUpRej->GetAxis(iEta)->SetRange(lowerEtaBinLimit, upperEtaBinLimit);
  
  // Obtain number of events for each class
  // Note: Under- and overflow automatically taken into account for unrestricted axis by using -1 and -2 for limits
  const Double_t numEvtsTriggerSel = hNumEventsTriggerSel->Integral(lowerCentralityBinLimit, upperCentralityBinLimit);
  const Double_t numEvtsTriggerSelVtxCut = hNumEventsTriggerSelVtxCut->Integral(lowerCentralityBinLimit, upperCentralityBinLimit);
  const Double_t numEvtsTriggerSelVtxCutZ = hNumEventsTriggerSelVtxCutZ->Integral(lowerCentralityBinLimit, upperCentralityBinLimit);
  const Double_t numEvtsTriggerSelVtxCutZPileUpRej = hNumEventsTriggerSelVtxCutZPileUpRej->Integral(lowerCentralityBinLimit,
                                                                                                    upperCentralityBinLimit);
  
  // Project pT spectra
  TH1D* hSpectraTriggerSel = (TH1D*)hDataTriggerSel->Projection(iPt, "e");
  TH1D* hSpectraTriggerSelVtxCut = (TH1D*)hDataTriggerSelVtxCut->Projection(iPt, "e");
  TH1D* hSpectraTriggerSelVtxCutZ = (TH1D*)hDataTriggerSelVtxCutZ->Projection(iPt, "e");
  TH1D* hSpectraTriggerSelVtxCutZPileUpRej = (TH1D*)hDataTriggerSelVtxCutZPileUpRej->Projection(iPt, "e");
  
  // Normalise histos to 1/Nevt dN/dPt
  normaliseHist(hSpectraTriggerSel, numEvtsTriggerSel);
  normaliseHist(hSpectraTriggerSelVtxCut, numEvtsTriggerSelVtxCut);
  normaliseHist(hSpectraTriggerSelVtxCutZ, numEvtsTriggerSelVtxCutZ);
  normaliseHist(hSpectraTriggerSelVtxCutZPileUpRej, numEvtsTriggerSelVtxCutZPileUpRej);
  
  setupHist(hSpectraTriggerSel, kBlack, "Trigger selection");
  setupHist(hSpectraTriggerSelVtxCut, kRed, "& vertex cut");
  setupHist(hSpectraTriggerSelVtxCutZ, kBlue, "& vertex #it{z} cut");
  setupHist(hSpectraTriggerSelVtxCutZPileUpRej, kGreen, "& pile-up rejection");
  
  TCanvas* canvSpectra = new TCanvas("canvSpectra", "Spectra", 760, 420);
  canvSpectra->SetLogx();
  canvSpectra->SetLogy();
  canvSpectra->SetGrid(0, 0);
  SetCanvasMargins(canvSpectra);
  
  TLegend* leg = new TLegend(0.14, 0.26, 0.62, 0.55);
  leg->SetHeader(Form("MC pp #sqrt{s}=7 TeV, inclusive, %s", etaRange.Data()));
  leg->AddEntry(hSpectraTriggerSel, "", "l");
  leg->AddEntry(hSpectraTriggerSelVtxCut, "", "l");
  leg->AddEntry(hSpectraTriggerSelVtxCutZ, "", "l");
  if (drawPileUp)
    leg->AddEntry(hSpectraTriggerSelVtxCutZPileUpRej, "", "l");
  SetupLegend(leg);
  leg->SetMargin(0.15);
  
  hSpectraTriggerSel->Draw();
  hSpectraTriggerSelVtxCut->Draw("same");
  hSpectraTriggerSelVtxCutZ->Draw("same");
  if (drawPileUp)
    hSpectraTriggerSelVtxCutZPileUpRej->Draw("same");
  
  leg->Draw("same");
  
  // Ratios (take binomial errors, since real sub-samples)
  
  TH1D* hRatioVtxCut = new TH1D(*hSpectraTriggerSelVtxCut);
  hRatioVtxCut->SetName("hRatioVtxCut");
  setupHist(hRatioVtxCut, kBlack, "MB & vtx / MB");
  hRatioVtxCut->GetYaxis()->SetTitle("1/#it{N}_{evt} d#it{N}/d#it{p}_{T}^{gen} ratio");
  hRatioVtxCut->Divide(hRatioVtxCut, hSpectraTriggerSel, 1., 1., "B");
  hRatioVtxCut->GetYaxis()->SetRangeUser(1.08, 1.14);
  
  // Mean ratio of spectra and of Nevt
  TF1* funcRatioVtxCut = new TF1("funcRatioVtxCut", "pol0",
                                 0.15, hRatioVtxCut->GetXaxis()->GetBinUpEdge(hSpectraTriggerSelVtxCut->FindLastBinAbove(0)));
  funcRatioVtxCut->SetLineWidth(2);
  funcRatioVtxCut->SetLineColor(kRed);
  hRatioVtxCut->Fit(funcRatioVtxCut, "N");
  const Double_t meanRatioVtxCut = funcRatioVtxCut->GetParameter(0);
  const Double_t ratioNevtVtxCut = numEvtsTriggerSelVtxCut > 0 ? numEvtsTriggerSel / numEvtsTriggerSelVtxCut : -1.;
  const Double_t doubleRatioMinusOne = meanRatioVtxCut > 0 ? (ratioNevtVtxCut / meanRatioVtxCut - 1.) : -999.;
  
  
  
  TH1D* hRatioVtxCutZ = new TH1D(*hSpectraTriggerSelVtxCutZ);
  hRatioVtxCutZ->SetName("hRatioVtxCutZ");
  setupHist(hRatioVtxCutZ, kBlack, "MB & vtx & #it{z} vtx / MB & vtx");
  hRatioVtxCutZ->GetYaxis()->SetTitle("1/#it{N}_{evt} d#it{N}/d#it{p}_{T}^{gen} ratio");
  hRatioVtxCutZ->Divide(hRatioVtxCutZ, hSpectraTriggerSelVtxCut, 1., 1., "B");
  hRatioVtxCutZ->GetYaxis()->SetRangeUser(0.95, 1.05);
  
  // Mean ratio of spectra and of Nevt
  TF1* funcRatioVtxCutZ = new TF1("funcRatioVtxCutZ", "pol0",
                                  0.15, hRatioVtxCutZ->GetXaxis()->GetBinUpEdge(hSpectraTriggerSelVtxCutZ->FindLastBinAbove(0)));
  hRatioVtxCutZ->Fit(funcRatioVtxCutZ, "N");
  funcRatioVtxCutZ->SetLineWidth(2);
  funcRatioVtxCutZ->SetLineColor(kRed);
  const Double_t meanRatioVtxCutZ = funcRatioVtxCutZ->GetParameter(0);
  const Double_t ratioNevtVtxCutZ = numEvtsTriggerSelVtxCutZ > 0 ? numEvtsTriggerSelVtxCut / numEvtsTriggerSelVtxCutZ : -1.;
  
  TH1D* hRatioPileUp = new TH1D(*hSpectraTriggerSelVtxCutZPileUpRej);
  hRatioPileUp->SetName("hRatioPileUp");
  setupHist(hRatioPileUp, kBlack, "MB & vtx & #it{z} vtx & pile-up / MB & vtx & #it{z} vtx");
  hRatioPileUp->GetYaxis()->SetTitle("1/#it{N}_{evt} d#it{N}/d#it{p}_{T}^{gen} ratio");
  hRatioPileUp->Divide(hRatioPileUp, hSpectraTriggerSelVtxCutZ, 1., 1., "B");
  
  /*
  TF1* funcRatioPileUp = new TF1("funcRatioPileUp", "pol0",
                                 0.15, hRatioPileUp->GetXaxis()->GetBinUpEdge(hSpectraTriggerSelVtxCutZPileUpRej->FindLastBinAbove(0)));
  hRatioPileUp->Fit(funcRatioPileUp, "N");*/
  
  ClearTitleFromHistoInCanvas(canvSpectra);
  
  TCanvas* canvRatioVtx = new TCanvas("canvRatioVtx", "Ratio vertex", 760, 420);
  canvRatioVtx->SetLogx();
  canvRatioVtx->SetGrid(0, 1);
  SetCanvasMargins(canvRatioVtx);
  
  hRatioVtxCut->Draw();
  funcRatioVtxCut->Draw("same");
  
  TLegend* leg2 = new TLegend(0.22, 0.7, drawPileUp ? 0.87 : 0.72, 0.9);
  leg2->SetHeader(Form("MC pp #sqrt{s}=7 TeV, inclusive, %s", etaRange.Data()));
  leg2->AddEntry(hRatioVtxCut, "", "l");
  SetupLegend(leg2);
  leg2->SetMargin(0.1);
  
  leg2->Draw("same");
  
  ClearTitleFromHistoInCanvas(canvRatioVtx);
  
  TCanvas* canvRatioOther = new TCanvas("canvRatioOther", "Ratio others", 760, 420);
  canvRatioOther->SetLogx();
  canvRatioOther->SetGrid(0, 1);
  SetCanvasMargins(canvRatioOther);
  
  hRatioVtxCutZ->Draw();
  if (drawPileUp)
    hRatioPileUp->Draw("same");

  TLegend* leg3 = new TLegend(0.22, drawPileUp ? 0.63 : 0.7, drawPileUp ? 0.87 : 0.72, 0.9);
  leg3->SetHeader(Form("MC pp #sqrt{s}=7 TeV, inclusive, %s", etaRange.Data()));
  leg3->AddEntry(hRatioVtxCutZ, "", "l");
  if (drawPileUp)
    leg3->AddEntry(hRatioPileUp, "", "l");
  SetupLegend(leg3);
  leg3->SetMargin(0.1);
  
  leg3->Draw("same");
  
  ClearTitleFromHistoInCanvas(canvRatioOther);

  
  printf("meanRatioVtxCut %f <-> ratioNevtVtxCut %f => meanRatioVtxCutZ/ratioNevtVtxCutZ - 1 = %f\nmeanRatioVtxCutZ %f <-> ratioNevtVtxCutZ %f\n",
         meanRatioVtxCut, ratioNevtVtxCut, doubleRatioMinusOne, meanRatioVtxCutZ, ratioNevtVtxCutZ);
  
  
  TNamed* settings = new TNamed(
      Form("Settings: Data file \"%s\", lowerEta %.2f, uppEta %.2f, lowerCentrality %.3f, upperCentrality %.3f, doubleRatioMinusOne %.4f\n",
           pathNameData.Data(), etaLow, etaUp, lowerCentrality, upperCentrality, doubleRatioMinusOne), "");
  
  // Save results to file
  TString saveFileName = pathNameData;
  saveFileName = Form("%s_binZeroStudy.root", saveFileName.ReplaceAll(".root", "").Data());
  TFile *saveFile = TFile::Open(saveFileName.Data(), "RECREATE");
  saveFile->cd();
  hSpectraTriggerSel->Write();
  hSpectraTriggerSelVtxCut->Write();
  hSpectraTriggerSelVtxCutZ->Write();
  hSpectraTriggerSelVtxCutZPileUpRej->Write();
  
  hRatioVtxCut->Write();
  hRatioVtxCutZ->Write();
  hRatioPileUp->Write();
  
  funcRatioVtxCut->Write();
  funcRatioVtxCutZ->Write();
  
  canvSpectra->Write();
  canvRatioVtx->Write();
  canvRatioOther->Write();
  
  settings->Write();
  
  saveFile->Close();
  
  TString temp = saveFileName;
  canvRatioVtx->SaveAs(Form("%s", temp.ReplaceAll(".root", "_ratioVtx.pdf").Data()));
  temp = saveFileName;
  canvRatioOther->SaveAs(Form("%s", temp.ReplaceAll(".root", "_ratioOther.pdf").Data()));
  
  PrintSettingsAxisRangeForMultiplicityAxisForMB();
  
  return 0;
}
Ejemplo n.º 3
0
/////////////////
// MAIN SCRIPT //
/////////////////
void paperConvert() {
    gStyle->SetHistLineWidth(2);
    gStyle->SetOptStat("");
    TH1::SetDefaultSumw2();
    TCanvas *c1 = new TCanvas("c1", "c1",10,32,700,500);
    gStyle->SetOptStat(0);

    // For centralised hist with no title, legend inside plot
    c1->Range(-1.705566,0.8486743,10.78995,1.08077);
    c1->SetFillColor(0);
    c1->SetBorderMode(0);
    c1->SetBorderSize(2);
    c1->SetTickx(1);
    c1->SetTicky(1);
    c1->SetLeftMargin(0.1364942);
    c1->SetRightMargin(0.06321839);
    c1->SetTopMargin(0.07415254);
    c1->SetBottomMargin(0.1271186);
    c1->SetFrameBorderMode(0);
    c1->SetFrameBorderMode(0);

    TFile *f_sig_main1 = TFile::Open("Signal_1prong_HLT_bare/output_main_bare_sig_muRand_HLT_dR1.root", "READ");
    TFile *f_sig_main2 = TFile::Open("Signal_1prong_HLT_bare/output_main_bare_sig_muRand_HLT_dR2.root", "READ");
    TFile *f_sig_mass1 = TFile::Open("Signal_1prong_HLT_bare/output_bare_sig_muRand_HLT_dR1.root", "READ");
    TFile *f_sig_mass2 = TFile::Open("Signal_1prong_HLT_bare/output_bare_sig_muRand_HLT_dR2.root", "READ");
    TFile *f_bg_main1 = TFile::Open("QCDb_HLT_bare/output_main_bare_bg_muRand_HLT_dR1.root", "READ");
    // TFile *f_bg_main2 = TFile::Open("QCDb_HLT_bare/output_main_bare_bg_muRand_HLT_dR2.root", "READ");
    TFile *f_bg_main2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_noDz_dR2.root", "READ");

    // TFile *f_bg_mass1 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_dR1.root", "READ");
    // TFile *f_bg_mass1 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_1912_dR1.root", "READ");
    TFile *f_bg_mass1 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_1912IPopt2_dR1.root", "READ");
    // TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_dR2.root", "READ"); //normal
    // TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_looseIsoAndTau_dR2.root", "READ");
    // TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_IPiso0p5_dR2.root", "READ");
    // TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_1912_dR2.root", "READ");
    TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_1912IPopt2_dR2.root", "READ");
    // TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_noDz_dR2.root", "READ");
    // TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_IPopt2_dR2.root", "READ");
    // TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_IPopt3_dR2.root", "READ");

    TFile *f_scatter_main1 = TFile::Open("QCDbcScatter_HLT_bare/output_main_bare_bg_muRand_HLT_dR1.root", "READ");
    TFile *f_scatter_main2 = TFile::Open("QCDbcScatter_HLT_bare/output_main_bare_bg_muRand_HLT_dR2.root", "READ");
    TFile *f_scatter_mass1 = TFile::Open("QCDbcScatter_HLT_bare/output_bare_bg_muRand_HLT_dR1.root", "READ");
    TFile *f_scatter_mass2 = TFile::Open("QCDbcScatter_HLT_bare/output_bare_bg_muRand_HLT_dR2.root", "READ");

    // TString dir("normal");
    // TString dir("looseIsolooseTau");
    // TString dir("IPiso0p5");
    // TString dir("1912");
    TString dir("1912IPopt2");
    // TString dir("IPopt2");
    // TString dir("noDz");

    ///////////////////
    // 1D MASS PLOTS //
    ///////////////////

    ////////////////
    // Signal region plots
    ////////////////
    std::vector<TFile*> filesdR2;
    filesdR2.push_back(f_bg_mass2);
    filesdR2.push_back(f_scatter_mass2);

    TPaveText* t_signal = new TPaveText(0.6, 0.47, 0.85, 0.58, "NDC");
    t_signal->AddText("Signal region");
    t_signal->SetFillColor(kWhite);
    t_signal->SetBorderSize(0);
    
    TPaveText* t_side = new TPaveText(0.6, 0.47, 0.84, 0.57, "NDC");
    t_side->AddText("Control region B");
    t_side->SetFillColor(kWhite);
    t_side->SetBorderSize(0);

    // bbbar only
    TH1D* hM1_bare_bg_muRand_HLT_dR2 = (TH1D*) f_bg_mass2->Get("hM1");
    TH1D* hM2_bare_bg_muRand_HLT_dR2 = (TH1D*) f_bg_mass2->Get("hM2");
    TH1D* hM_bare_bg_muRand_HLT_dR2 = (TH1D*)hM1_bare_bg_muRand_HLT_dR2->Clone();
    hM_bare_bg_muRand_HLT_dR2->Add(hM2_bare_bg_muRand_HLT_dR2);
    normaliseHist(hM_bare_bg_muRand_HLT_dR2); // as we added m1 + m2
    setMassAUTitles(hM_bare_bg_muRand_HLT_dR2);
    doBGHist(hM_bare_bg_muRand_HLT_dR2);
    setAltTitleLabelSizes(hM_bare_bg_muRand_HLT_dR2);
    hM_bare_bg_muRand_HLT_dR2->Draw("HISTE");
    t_signal->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_bare_bg_muRand_HLT_dR2.pdf");

    std::vector<double> scalingFactors;
    scalingFactors.push_back(1.7649);
    scalingFactors.push_back(2.6577);

    // // bbbar + scatter
    TH1D* hM1_bg_dR2 = combineRebin10bins(filesdR2, "hM1_unnormalised", scalingFactors);
    TH1D* hM2_bg_dR2 = combineRebin10bins(filesdR2, "hM2_unnormalised", scalingFactors);
    TH1D* hM_bg_dR2 = (TH1D*) hM1_bg_dR2->Clone() ;
    hM_bg_dR2->Add(hM2_bg_dR2);
    normaliseHist(hM_bg_dR2);
    setMassAUTitles(hM_bg_dR2);
    doBGHist(hM_bg_dR2);
    setAltTitleLabelSizes(hM_bg_dR2);
    hM_bg_dR2->Draw("HISTE");
    t_signal->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_bare_bg_both_muRand_HLT_dR2.pdf");

    // signal
    TH1D* hM1_bare_sig_muRand_HLT_dR2 = (TH1D*) f_sig_mass2->Get("hM1");
    TH1D* hM2_bare_sig_muRand_HLT_dR2 = (TH1D*) f_sig_mass2->Get("hM2");
    TH1D* hM_bare_sig_muRand_HLT_dR2 = (TH1D*)hM1_bare_sig_muRand_HLT_dR2->Clone();
    hM_bare_sig_muRand_HLT_dR2->Add(hM2_bare_sig_muRand_HLT_dR2);
    normaliseHist(hM_bare_sig_muRand_HLT_dR2);
    setMassAUTitles(hM_bare_sig_muRand_HLT_dR2);
    doSignalHist(hM_bare_sig_muRand_HLT_dR2);
    setAltTitleLabelSizes(hM_bare_sig_muRand_HLT_dR2);
    hM_bare_sig_muRand_HLT_dR2->Draw("HISTE");
    t_signal->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_bare_sig_muRand_HLT_dR2.pdf");


    // bbbar + signal
    THStack* st = new THStack("st","");
    st->Add(hM_bare_bg_muRand_HLT_dR2);
    st->Add(hM_bare_sig_muRand_HLT_dR2);
    TLegend* l = new TLegend(0.67, 0.67, 0.88, 0.88);
    l->AddEntry(hM_bare_bg_muRand_HLT_dR2, "QCD b#bar{b} MC", "lp");
    l->AddEntry(hM_bare_sig_muRand_HLT_dR2, "#splitline{Signal MC}{m_{#phi} = 8 GeV}", "lp");
    doStandardLegend(l);
    st->Draw("NOSTACK HISTE");
    setMassAUTitles(st->GetHistogram());
    setAltTitleLabelSizes(st->GetHistogram());    
    l->Draw();
    t_signal->Draw();

    c1->SaveAs("Combined/"+dir+"/M_10bins_bare_both_muRand_HLT_dR2.pdf");

    // bbbar + scatter + signal
    THStack* st_all = new THStack("st_all","");
    st_all->Add(hM_bg_dR2);
    st_all->Add(hM_bare_sig_muRand_HLT_dR2);
    TLegend* l_all = new TLegend(0.52,0.62,0.86,0.89);
    l_all->AddEntry(hM_bg_dR2,"Gen. level QCD MC","lp");
    l_all->AddEntry((TObject*)0,"(b#bar{b} + q-g scatter,",""); //null pointers for blank entries
    l_all->AddEntry((TObject*)0,"q = b, #bar{b}, c, #bar{c})","");
    l_all->AddEntry(hM_bare_sig_muRand_HLT_dR2, "Signal MC", "lp");
    l_all->AddEntry((TObject*)0,"m_{#phi} = 8 GeV", "");
    doStandardLegend(l_all);
    st_all->Draw("NOSTACKHISTE");
    setMassAUTitles(st_all->GetHistogram());
    setAltTitleLabelSizes(st_all->GetHistogram());    
    l_all->Draw();
    t_signal->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_bare_allMC_muRand_HLT_dR2.pdf");

    
    ////////////
    // sideband plots
    ////////////
    
    std::vector<TFile*> filesdR1;
    filesdR1.push_back(f_bg_mass1);
    filesdR1.push_back(f_scatter_mass1);

    // bbbar
    TH1D* hM1_side_bg_muRand_HLT_dR1 = (TH1D*) f_bg_mass1->Get("hM1_side_1to2p5");
    hM1_side_bg_muRand_HLT_dR1->Rebin(5);
    TH1D* hM2_side_bg_muRand_HLT_dR1 = (TH1D*) f_bg_mass1->Get("hM2_side_1to2p5");
    hM2_side_bg_muRand_HLT_dR1->Rebin(5);
    TH1D* hM_side_bg_muRand_HLT_dR1 = (TH1D*)hM1_side_bg_muRand_HLT_dR1->Clone();
    hM_side_bg_muRand_HLT_dR1->Add(hM2_side_bg_muRand_HLT_dR1);
    normaliseHist(hM_side_bg_muRand_HLT_dR1);
    setMassAUTitles(hM_side_bg_muRand_HLT_dR1);
    doBGHist(hM_side_bg_muRand_HLT_dR1);
    setAltTitleLabelSizes(hM_side_bg_muRand_HLT_dR1);
    hM_side_bg_muRand_HLT_dR1->Draw("HISTE");
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_side_bg_muRand_HLT_dR1.pdf");

    // // bbbar + scatter
    TH1D* hM1_side_bg_dR1 = combineRebin10bins(filesdR1, "hM1_side_1to2p5_unnormalised", scalingFactors);
    TH1D* hM2_side_bg_dR1 = combineRebin10bins(filesdR1, "hM1_side_1to2p5_unnormalised", scalingFactors);
    TH1D* hM_side_bg_dR1 = (TH1D*) hM1_side_bg_dR1->Clone();
    hM_side_bg_dR1->Add(hM2_side_bg_dR1);
    normaliseHist(hM_side_bg_dR1);
    setMassAUTitles(hM_side_bg_dR1);
    doBGHist(hM_side_bg_dR1);
    setAltTitleLabelSizes(hM_side_bg_dR1);
    hM_side_bg_dR1->Draw("HISTE");
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_side_bg_both_muRand_HLT_dR1.pdf");

    // signal
    TH1D* hM1_side_sig_muRand_HLT_dR1 = (TH1D*) f_sig_mass1->Get("hM1_side_1to2p5");
    hM1_side_sig_muRand_HLT_dR1->Rebin(5);
    TH1D* hM2_side_sig_muRand_HLT_dR1 = (TH1D*) f_sig_mass1->Get("hM2_side_1to2p5");
    hM2_side_sig_muRand_HLT_dR1->Rebin(5);
    TH1D* hM_side_sig_muRand_HLT_dR1 = (TH1D*)hM1_side_sig_muRand_HLT_dR1->Clone();
    hM_side_sig_muRand_HLT_dR1->Add(hM2_side_sig_muRand_HLT_dR1);
    normaliseHist(hM_side_sig_muRand_HLT_dR1);
    setMassAUTitles(hM_side_sig_muRand_HLT_dR1);
    doSignalHist(hM_side_sig_muRand_HLT_dR1);
    setAltTitleLabelSizes(hM_side_sig_muRand_HLT_dR1);
    hM_side_sig_muRand_HLT_dR1->Draw("HISTE");
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_side_sig_muRand_HLT_dR1.pdf");

    // bbar + signal
    THStack* st_side = new THStack("st_side","");
    st_side->Add(hM_side_bg_muRand_HLT_dR1);
    st_side->Add(hM_side_sig_muRand_HLT_dR1);
    st_side->Draw("NOSTACK HISTE");
    setMassAUTitles(st_side->GetHistogram());
    setAltTitleLabelSizes(st_side->GetHistogram());    
    l->Draw();
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_side_both_muRand_HLT_dR1.pdf");
    
    // bbar + scatter + signal
    THStack* st_side_all = new THStack("st_side_all","");
    st_side_all->Add(hM_side_bg_dR1);
    st_side_all->Add(hM_side_sig_muRand_HLT_dR1);
    st_side_all->Draw("NOSTACK HISTE");
    setMassAUTitles(st_side_all->GetHistogram());
    setAltTitleLabelSizes(st_side_all->GetHistogram());    
    l_all->Draw();
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_side_allMC_muRand_HLT_dR1.pdf");


    ///////////////////////
    // CORRELATION PLOTS //
    ///////////////////////
    //signal mc
    TH1D* hCorr_bare_sig = (TH1D*) f_sig_mass2->Get("hCorr1D");
    TH1D* hCorr_side_sig = (TH1D*) f_sig_mass1->Get("hCorr1D_side_1to2p5");
    //bbbar
    TH1D* hCorr_bare_b = (TH1D*) f_bg_mass2->Get("hCorr1D");
    // TH1D* hCorr_bare_b = (TH1D*) f_bg_mass2->Get("hCorr1D_loosetau");
    TH1D* hCorr_side_b = (TH1D*) f_bg_mass1->Get("hCorr1D_side_1to2p5");
    
    TH1D* hM1D_bare_b_unnormalised = (TH1D*) f_bg_mass2->Get("hM_unnormalised"); // signal region
    TH2D* hM2D_bare_b_unnormalised = (TH2D*) f_bg_mass2->Get("hM1vsM2_unnormalised");
    
    TH1D* hM1D_side_b_unnormalised = (TH1D*) f_bg_mass1->Get("hM_side_1to2p5_unnormalised"); //sideband
    TH2D* hM2D_side_b_unnormalised = (TH2D*) f_bg_mass1->Get("hM1vsM2_side_1to2p5_unnormalised");
    
    // scatter
    TH1D* hCorr_bare_scatter = (TH1D*) f_scatter_mass2->Get("hCorr1D");
    TH1D* hCorr_side_scatter = (TH1D*) f_scatter_mass1->Get("hCorr1D_side_1to2p5");
    
    TH1D* hM1D_bare_scatter_unnormalised = (TH1D*) f_scatter_mass2->Get("hM_unnormalised"); //signal region
    TH2D* hM2D_bare_scatter_unnormalised = (TH2D*) f_scatter_mass2->Get("hM1vsM2_unnormalised");
    
    TH1D* hM1D_side_scatter_unnormalised = (TH1D*) f_scatter_mass1->Get("hM_side_1to2p5_unnormalised"); //sideband
    TH2D* hM2D_side_scatter_unnormalised = (TH2D*) f_scatter_mass1->Get("hM1vsM2_side_1to2p5_unnormalised");
    
    t_signal = new TPaveText(0.15, 0.7, 0.4, 0.8, "NDC");
    t_signal->AddText("Signal region");
    t_signal->SetFillColor(kWhite);
    t_signal->SetBorderSize(0);

    t_side = new TPaveText(0.15, 0.7, 0.4, 0.8, "NDC");
    t_side->AddText("Control region B");
    t_side->SetFillColor(kWhite);
    t_side->SetBorderSize(0);

    // set title sizes, titles, max, min, etc
    setTitleLabelSizes(hCorr_bare_sig);
    doSignalHist(hCorr_bare_sig);
    setCorrTitlesMaxMin(hCorr_bare_sig);
    
    setTitleLabelSizes(hCorr_side_sig);
    doSignalHist(hCorr_side_sig);
    setCorrTitlesMaxMin(hCorr_side_sig);

    setTitleLabelSizes(hCorr_bare_b);
    doBGHist(hCorr_bare_b);
    setCorrTitlesMaxMin(hCorr_bare_b);

    setTitleLabelSizes(hCorr_side_b);
    doBGHist(hCorr_side_b);
    setCorrTitlesMaxMin(hCorr_side_b);

    setTitleLabelSizes(hCorr_bare_scatter);
    doAltBGHist(hCorr_bare_scatter);
    setCorrTitlesMaxMin(hCorr_bare_scatter);
    
    setTitleLabelSizes(hCorr_side_scatter);
    doAltBGHist(hCorr_side_scatter);
    setCorrTitlesMaxMin(hCorr_side_scatter);
    
    TLine line(0,1,10,1);
    line.SetLineStyle(2);
    line.SetLineColor(12);
    line.SetLineWidth(2);

    c1->SetTicks(1,1);
    
    TLegend* l_bonly = new TLegend(0.6, 0.82, 0.88, 0.88);
    l_bonly->AddEntry(hCorr_bare_b, "QCD b#bar{b} MC", "lp");
    doStandardLegend(l_bonly);
    
    ///////////////////
    // signal region //
    ///////////////////

    // signal MC by itself
    hCorr_bare_sig->Draw();
    line.Draw();
    t_signal->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_bare_sig.pdf");
    
    // bbbar qcd by itself
    std::cout << "bbbar QCD MC in signal region:" << std::endl;
    printBinContents(hCorr_bare_b);
    hCorr_bare_b->Draw();
    line.Draw();
    t_signal->Draw();
    l_bonly->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_bare_b.pdf");
    c1->SaveAs("Combined/"+dir+"/Corr_bare_b.png");
    
    // bbbar + signal
    hCorr_bare_b->Draw();
    hCorr_bare_sig->Draw("SAME");
    line.Draw();
    l->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_bare_b_sig.pdf");


    // make combined corr plot for both qcd
    std::vector<TH1D*> bare_bg_hists1D;
    bare_bg_hists1D.push_back(hM1D_bare_b_unnormalised);
    bare_bg_hists1D.push_back(hM1D_bare_scatter_unnormalised);
    TH1D* hM1D_bare_bg = combineScale(bare_bg_hists1D, scalingFactors);
    
    std::vector<TH2D*> bare_bg_hists2D;
    bare_bg_hists2D.push_back(hM2D_bare_b_unnormalised);
    bare_bg_hists2D.push_back(hM2D_bare_scatter_unnormalised);
    TH2D* hM2D_bare_bg = combineScale(bare_bg_hists2D, scalingFactors);
    TH1D* hCorr_bare_bg = createCorrelationPlot(hM2D_bare_bg, hM1D_bare_bg);

    // both QCD summed together
    doBGHist(hCorr_bare_bg);
    setTitleLabelSizes(hCorr_bare_bg);
    setCorrTitlesMaxMin(hCorr_bare_bg);
    hCorr_bare_bg->Draw();
    line.Draw();
    t_signal->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_bare_bg.pdf");
    
    // all qcd + signal mc
    hCorr_bare_sig->Draw("SAME");
    l_all->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_bare_bg_sig.pdf");

    //////////////////////
    // control region B //
    //////////////////////

    // signal MC by itself
    hCorr_side_sig->Draw();
    line.Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_side_sig.pdf");
    
    // bbbar qcd by itself
    std::cout << "bbbar QCD MC in control region:" << std::endl;
    printBinContents(hCorr_side_b);
    hCorr_side_b->Draw();
    line.Draw();
    l_bonly->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_side_b.pdf");
    c1->SaveAs("Combined/"+dir+"/Corr_side_b.png");

    // signal + bbbar together
    hCorr_side_sig->Draw();
    hCorr_side_b->Draw("SAME");
    line.Draw();
    l->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_side_b_sig.pdf");

    // make combined corr plot for both qcd
    std::vector<TH1D*> side_bg_hists1D;
    side_bg_hists1D.push_back(hM1D_side_b_unnormalised);
    side_bg_hists1D.push_back(hM1D_side_scatter_unnormalised);
    TH1D* hM1D_side_bg = combineScale(side_bg_hists1D, scalingFactors);
    
    std::vector<TH2D*> side_bg_hists2D;
    side_bg_hists2D.push_back(hM2D_side_b_unnormalised);
    side_bg_hists2D.push_back(hM2D_side_scatter_unnormalised);
    TH2D* hM2D_side_bg = combineScale(side_bg_hists2D, scalingFactors);
    TH1D* hCorr_side_bg = createCorrelationPlot(hM2D_side_bg, hM1D_side_bg);

    // both QCD summed together
    doBGHist(hCorr_side_bg);
    setTitleLabelSizes(hCorr_side_bg);
    setCorrTitlesMaxMin(hCorr_side_bg);
    hCorr_side_bg->Draw();
    line.Draw();
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_side_bg.pdf");
    
    // signal + both QCD
    hCorr_side_sig->Draw("SAME");
    l_all->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_side_all_MC.pdf");

    // QCD + data
    hCorr_side_bg->Draw();
    TH1D* hCorr_side_data = dataCorr_side();
    doDataHist(hCorr_side_data);
    setCorrTitlesMaxMin(hCorr_side_data);
    hCorr_side_data->Draw("SAME");
    line.Draw();
    
    TLegend* l_all_data = new TLegend(0.52,0.65,0.86,0.89);
    l_all_data->AddEntry(hM_bg_dR2,"Gen. level QCD MC","lp");
    l_all_data->AddEntry((TObject*)0,"(b#bar{b} + q-g scatter,",""); //null pointers for blank entries
    l_all_data->AddEntry((TObject*)0,"q = b, #bar{b}, c, #bar{c})","");
    l_all_data->AddEntry(hCorr_side_data, "Data", "lp");
    doStandardLegend(l_all_data);
    l_all_data->Draw();
    
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_side_bg_data.pdf");
    // c1->SaveAs("Combined/"+dir+"/Corr_side_bg_data.png");

    // bbar + data
    hCorr_side_b->Draw();
    hCorr_side_data->Draw("SAME");
    TLegend* l_b_data = new TLegend(0.6,0.7,0.86,0.89);
    l_b_data->AddEntry(hM_bg_dR2,"QCD b#bar{b} MC","lp");
    l_b_data->AddEntry(hCorr_side_data, "Data", "lp");
    doStandardLegend(l_b_data);
    l_b_data->Draw();
    line.Draw();
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_side_b_data.pdf");
    c1->SaveAs("Combined/"+dir+"/Corr_side_b_data.png");


    /////////////////////////
    // TRACK DISTRIBUTIONS //
    /////////////////////////
    // combineHists(f_sig_main2, f_bg_main2, f_scatter_main2, "hNTracks1", "HISTE", "Combined/combined_NTrack1_muRand.pdf", scalingFactors, "Tracks with p_{T} > 2.5 GeV");
    // combineHists(f_sig_main2, f_bg_main2, f_scatter_main2, "hNTracksAbs1", "HISTE", "Combined/combined_NTrackAbs1_muRand.pdf", scalingFactors, "Tracks with p_{T} > 2.5 GeV", "Average number of tracks per #mu_{1} / bin");
    // combineHists(f_sig_main2, f_bg_main2, f_scatter_main2, "hNTracksAll1", "HISTE", "Combined/combined_NTrackAll1_muRand.pdf", scalingFactors, "Tracks with p_{T} > 1 GeV");
    // combineHists(f_sig_main2, f_bg_main2, f_scatter_main2, "hNTracksAllAbs1", "HISTE", "Combined/combined_NTrackAllAbs1_muRand.pdf", scalingFactors, "Tracks with p_{T} > 1 GeV", "Average number of tracks per #mu_{1} / bin");
    // combineHists(f_sig_main2, f_bg_main2, f_scatter_main2, "hNSoftTracks1", "HISTE", "Combined/combined_NSoftTrack1_muRand.pdf", scalingFactors, "Tracks with 1 < p_{T} < 2.5 GeV");
    // combineHists(f_sig_main2, f_bg_main2, f_scatter_main2, "hNSoftTracksAbs1", "HISTE", "Combined/combined_NSoftTrackAbs1_muRand.pdf", scalingFactors, "Tracks with 1 < p_{T} < 2.5 GeV", "Average number of tracks per #mu_{1} / bin");


    ////////////////////////////////////////////
    // mass shape as fn of # tracks about mu2 //
    ////////////////////////////////////////////
    THStack* st_Ntk2_234 = new THStack("","");
    TH1D* histM1_Ntk2_2 = (TH1D*) f_bg_mass2->Get("hM1_Ntk2_2");
    TH1D* histM1_Ntk2_3 = (TH1D*) f_bg_mass2->Get("hM1_Ntk2_3");
    TH1D* histM1_Ntk2_4 = (TH1D*) f_bg_mass2->Get("hM1_Ntk2_4");
    doStandardHist(hM1_bare_bg_muRand_HLT_dR2);
    // hM1_bare_bg_muRand_HLT_dR2->SetMarkerStyle();
    doCustomHist(histM1_Ntk2_2, kRed, 21);
    doCustomHist(histM1_Ntk2_3, kBlack, 22);
    doCustomHist(histM1_Ntk2_4, kGreen+3, 23);
    st_Ntk2_234->Add(hM1_bare_bg_muRand_HLT_dR2);
    st_Ntk2_234->Add(histM1_Ntk2_2);
    st_Ntk2_234->Add(histM1_Ntk2_3);
    st_Ntk2_234->Add(histM1_Ntk2_4);
    st_Ntk2_234->Draw("NOSTACK E");
    setMassAUTitles(st_Ntk2_234->GetHistogram());
    st_Ntk2_234->GetHistogram()->SetXTitle("m_{1}(#mu-tk) [GeV]");
    setAltTitleLabelSizes(st_Ntk2_234->GetHistogram());
    TLegend* l_Ntk2_234 = new TLegend(0.56, 0.6, 0.88, 0.88);
    l_Ntk2_234->AddEntry((TObject*)0, "Gen. level QCD b#bar{b} MC", "");
    l_Ntk2_234->AddEntry(hM1_bare_bg_muRand_HLT_dR2, "N_{tk,2} = 1", "lp");
    l_Ntk2_234->AddEntry(histM1_Ntk2_2, "N_{tk,2} = 2", "lp");
    l_Ntk2_234->AddEntry(histM1_Ntk2_3, "N_{tk,2} = 3", "lp");
    l_Ntk2_234->AddEntry(histM1_Ntk2_4, "N_{tk,2} = 4", "lp");
    doStandardLegend(l_Ntk2_234);
    l_Ntk2_234->Draw();
    c1->SaveAs("Combined/"+dir+"/M1_Ntk2.pdf");

    THStack* st_Ntk2_2or3 = new THStack("","");
    TH1D* histM1_Ntk2_2or3 = (TH1D*) f_bg_mass2->Get("hM1_Ntk2_2or3");
    doCustomHist(histM1_Ntk2_2or3, kRed, 22);
    // st_Ntk2_2or3->Add(hM1_bare_bg_muRand_HLT_dR2);
    st_Ntk2_2or3->Add(hM_bare_bg_muRand_HLT_dR2);
    st_Ntk2_2or3->Add(histM1_Ntk2_2or3);
    st_Ntk2_2or3->Draw("NOSTACK E");
    setMassAUTitles(st_Ntk2_2or3->GetHistogram());
    st_Ntk2_2or3->GetHistogram()->SetXTitle("m_{ i }(#mu-trk) [GeV]");
    setAltTitleLabelSizes(st_Ntk2_2or3->GetHistogram());
    TLegend* l_Ntk2_2or3 = new TLegend(0.55, 0.56, 0.88, 0.88);
    l_Ntk2_2or3->AddEntry((TObject*)0, "Gen. level QCD b#bar{b} MC", "");
    // l_Ntk2_2or3->AddEntry(hM1_bare_bg_muRand_HLT_dR2, "N_{trk,2} = 1", "lp");
    l_Ntk2_2or3->AddEntry(hM_bare_bg_muRand_HLT_dR2, "N_{trk, j} = 1", "lp");
    l_Ntk2_2or3->AddEntry(histM1_Ntk2_2or3, "N_{trk, j} = 2, 3", "lp");
    doStandardLegend(l_Ntk2_2or3);
    l_Ntk2_2or3->Draw();
    c1->SaveAs("Combined/"+dir+"/M_Ntk2_2or3.pdf");
    c1->SaveAs("Combined/"+dir+"/M_Ntk2_2or3.png");

    histM1_Ntk2_2or3->SetMinimum(0.001); // Stop SetLogy complainng
    // hM1_bare_bg_muRand_HLT_dR2->SetMinimum(0.001); // Stop SetLogy complainng
    hM_bare_bg_muRand_HLT_dR2->SetMinimum(0.001); // Stop SetLogy complainng
    setAltTitleLabelSizes(st_Ntk2_2or3->GetHistogram());
    c1->SetLogy();
    c1->SaveAs("Combined/"+dir+"/M_Ntk2_2or3_log.pdf");
    c1->SaveAs("Combined/"+dir+"/M_Ntk2_2or3_log.png");


    // cleanup
    f_sig_main1->Close();
    f_sig_main2->Close();
    f_sig_mass2->Close();
    f_sig_mass2->Close();
    f_bg_main1->Close();
    f_bg_main2->Close();
    f_bg_mass1->Close();
    f_bg_mass2->Close();
    f_scatter_main1->Close();
    f_scatter_main2->Close();
    f_scatter_mass1->Close();
    f_scatter_mass2->Close();

}
Ejemplo n.º 4
0
//___________________________________________________________________
Int_t extractPtResolution(TString pathNameData, TString listName,
                          Int_t chargeMode /*kNegCharge = -1, kAllCharged = 0, kPosCharge = 1*/,
                          Double_t lowerCentrality /*= -2*/, Double_t upperCentrality /*= -2*/,
                          Double_t lowerJetPt /*= -1*/ , Double_t upperJetPt/* = -1*/)
{
  if (listName == "") {
    listName = pathNameData;
    listName.Replace(0, listName.Last('/') + 1, "");
    listName.ReplaceAll(".root", "");
  }
  
  TString pathData = pathNameData;
  pathData.Replace(pathData.Last('/'), pathData.Length(), "");
  
  TH1D* hPtResolutionFit[AliPID::kSPECIES] = {0x0, };
  TH2D* hPtResolution[AliPID::kSPECIES] = {0x0, };
  THnSparse* hPtResolutionRaw[AliPID::kSPECIES] = {0x0, };

  TFile* fileData = TFile::Open(pathNameData.Data());
  if (!fileData) {
    printf("Failed to open data file \"%s\"\n", pathNameData.Data());
    return -1;
  }
  
  TObjArray* histList = (TObjArray*)(fileData->Get(listName.Data()));
  
  if (!histList) {
    printf("Failed to load list!\n");
    return -1;
  }
  
  Double_t actualLowerCentrality = -2;
  Double_t actualUpperCentrality = -2;
  
  Double_t actualLowerJetPt = -1.;
  Double_t actualUpperJetPt = -1.;
  
  Bool_t restrictJetPtAxis = (lowerJetPt >= 0 && upperJetPt >= 0);
  const Bool_t restrictCentrality = ((lowerCentrality >= -1) && (upperCentrality >= -1));
  
  for (Int_t species = 0; species < AliPID::kSPECIES; species++) {
    const TString sparseName = Form("fPtResolution_%s", AliPID::ParticleShortName(species));
    hPtResolutionRaw[species] = (THnSparse*)histList->FindObject(sparseName.Data());
    
    if (!hPtResolutionRaw[species]) {
      printf("Failed to load THnSparse for %s: %s!\n", AliPID::ParticleShortName(species), sparseName.Data());
      return -1;
    }
    
    // Set proper errors, if not yet calculated
    if (!hPtResolutionRaw[species]->GetCalculateErrors()) {
      std::cout << "Re-calculating errors of " << hPtResolutionRaw[species]->GetName() << "..." << std::endl;
      
      hPtResolutionRaw[species]->Sumw2();
      
      Long64_t nBinsPtResolutionRaw = hPtResolutionRaw[species]->GetNbins();
      Double_t binContent = 0;
      for (Long64_t bin = 0; bin < nBinsPtResolutionRaw; bin++) {
        binContent = hPtResolutionRaw[species]->GetBinContent(bin);
        hPtResolutionRaw[species]->SetBinError(bin, TMath::Sqrt(binContent));
      }
    }
    
    // Integral(lowerCentBinLimit, uppCentBinLimit) will not be restricted if these values are kept
    const Int_t lowerCentralityBinLimit = restrictCentrality ? hPtResolutionRaw[species]->GetAxis(kPtResCentrality)->FindBin(lowerCentrality + 0.001) 
                                                                    : -1;
    const Int_t upperCentralityBinLimit = restrictCentrality ? hPtResolutionRaw[species]->GetAxis(kPtResCentrality)->FindBin(upperCentrality - 0.001) 
                                                                    : -2;
    
    
    if (restrictCentrality) {
      actualLowerCentrality = hPtResolutionRaw[species]->GetAxis(kPtResCentrality)->GetBinLowEdge(lowerCentralityBinLimit);
      actualUpperCentrality = hPtResolutionRaw[species]->GetAxis(kPtResCentrality)->GetBinLowEdge(upperCentralityBinLimit);
      
      hPtResolutionRaw[species]->GetAxis(kPtResCentrality)->SetRange(lowerCentralityBinLimit, upperCentralityBinLimit);
    }
    
    const Bool_t restrictCharge = (chargeMode != kAllCharged);
    
    Int_t lowerChargeBinLimit = -1;
    Int_t upperChargeBinLimit = -2;
      
    if (restrictCharge) {
      // Add subtract a very small number to avoid problems with values right on the border between to bins
      if (chargeMode == kNegCharge) {
        lowerChargeBinLimit = hPtResolutionRaw[species]->GetAxis(kPtResCharge)->FindBin(-1. + 0.001);
        upperChargeBinLimit = hPtResolutionRaw[species]->GetAxis(kPtResCharge)->FindBin(0. - 0.001);
      }
      else if (chargeMode == kPosCharge) {
        lowerChargeBinLimit = hPtResolutionRaw[species]->GetAxis(kPtResCharge)->FindBin(0. + 0.001);
        upperChargeBinLimit = hPtResolutionRaw[species]->GetAxis(kPtResCharge)->FindBin(1. - 0.001);
      }
      
      // Check if the values look reasonable
      if (lowerChargeBinLimit <= upperChargeBinLimit && lowerChargeBinLimit >= 1
          && upperChargeBinLimit <= hPtResolutionRaw[species]->GetAxis(kPtResCharge)->GetNbins()) {
        // OK
      }
      else {
        std::cout << std::endl;
        std::cout << "Requested charge range out of limits or upper and lower limit are switched!" << std::endl;
        return -1;
      }
      
      hPtResolutionRaw[species]->GetAxis(kPtResCharge)->SetRange(lowerChargeBinLimit, upperChargeBinLimit);
    }
    
    // If desired, restrict jetPt axis
    Int_t lowerJetPtBinLimit = -1;
    Int_t upperJetPtBinLimit = -1;
    
    if (restrictJetPtAxis) {
      // Add subtract a very small number to avoid problems with values right on the border between to bins
      lowerJetPtBinLimit = hPtResolutionRaw[species]->GetAxis(kPtResJetPt)->FindBin(lowerJetPt + 0.001);
      upperJetPtBinLimit = hPtResolutionRaw[species]->GetAxis(kPtResJetPt)->FindBin(upperJetPt - 0.001);
      
      // Check if the values look reasonable
      if (lowerJetPtBinLimit <= upperJetPtBinLimit && lowerJetPtBinLimit >= 1 &&
          upperJetPtBinLimit <= hPtResolutionRaw[species]->GetAxis(kPtResJetPt)->GetNbins()) {
        actualLowerJetPt = hPtResolutionRaw[species]->GetAxis(kPtResJetPt)->GetBinLowEdge(lowerJetPtBinLimit);
        actualUpperJetPt = hPtResolutionRaw[species]->GetAxis(kPtResJetPt)->GetBinUpEdge(upperJetPtBinLimit);

        restrictJetPtAxis = kTRUE;
      }
      else {
        std::cout << std::endl;
        std::cout << "Requested jet pT range out of limits or upper and lower limit are switched!" << std::endl;
        return -1;
      }
    }
    
    std::cout << "jet pT: ";
    if (restrictJetPtAxis) {
      std::cout << actualLowerJetPt << " - " << actualUpperJetPt << std::endl;
      hPtResolutionRaw[species]->GetAxis(kPtResJetPt)->SetRange(lowerJetPtBinLimit, upperJetPtBinLimit);
    }
    else {
      std::cout << "All" << std::endl;
    }
    
    hPtResolution[species] = hPtResolutionRaw[species]->Projection(kPtResGenPt, kPtResRecPt, "e");
    hPtResolution[species]->SetName(Form("hPtResolution_%s", AliPID::ParticleShortName(species)));
    hPtResolution[species]->SetTitle(Form("%s", AliPID::ParticleLatexName(species)));
    hPtResolution[species]->SetStats(kFALSE);
    hPtResolution[species]->SetLineColor(getLineColorAliPID(species));
    hPtResolution[species]->SetMarkerColor(getLineColorAliPID(species));
    
    normaliseHist(hPtResolution[species]);
    
    TObjArray aSlices;
    hPtResolution[species]->FitSlicesY(0, 0, -1, 0, "QNR", &aSlices);
    TH1D* hMean = (TH1D*)(aSlices.At(1));
    TH1D* hSigma = (TH1D*)(aSlices.At(2));
    
    hPtResolutionFit[species] = new TH1D(*hSigma);
    hPtResolutionFit[species]->SetName(Form("hPtResolutionFit_%s", AliPID::ParticleShortName(species)));
    hPtResolutionFit[species]->SetTitle(Form("%s", AliPID::ParticleLatexName(species)));
    hPtResolutionFit[species]->SetLineColor(getLineColorAliPID(species));
    hPtResolutionFit[species]->SetMarkerColor(getLineColorAliPID(species));
    
    hPtResolutionFit[species]->Divide(hSigma, hMean);
  }
  
  
  
  // Save results to file
  TString chargeString = "";
  if (chargeMode == kPosCharge)
    chargeString = "_posCharge";
  else if (chargeMode == kNegCharge)
    chargeString = "_negCharge";
  
  TString saveFileName = pathNameData;
  saveFileName.Replace(0, pathNameData.Last('/') + 1, "");
  
  TString savePath = pathNameData;
  savePath.ReplaceAll(Form("/%s", saveFileName.Data()), "");
  
  saveFileName.Prepend("output_extractedPTResolution_");
  TString centralityString = restrictCentrality ? Form("_centrality_%.0f_%.0f.root", actualLowerCentrality,
                                                       actualUpperCentrality)
                                                    : "_centrality_all";
  TString jetPtString = restrictJetPtAxis ? Form("_jetPt_%.0f_%.0f.root", actualLowerJetPt, actualUpperJetPt)
                                          : "";  
  saveFileName.ReplaceAll(".root", Form("%s%s%s.root", centralityString.Data(), jetPtString.Data(), chargeString.Data()));
  
  TString saveFilePathName = Form("%s/%s", savePath.Data(), saveFileName.Data());
  TFile* saveFile = TFile::Open(saveFilePathName.Data(), "RECREATE");
  
  if (!saveFile) {
    printf("Failed to save results to file \"%s\"!\n", saveFilePathName.Data());
    return -1;
  }
  
  saveFile->cd();
  
  for (Int_t species = 0; species < AliPID::kSPECIES; species++) {
    if (hPtResolution[species])
      hPtResolution[species]->Write();
    
    if (hPtResolutionFit[species])
      hPtResolutionFit[species]->Write();
  }
  
  TNamed* settings = new TNamed(
      Form("Settings: Data file \"%s\", lowerCentrality %.3f, upperCentrality %.3f, lowerJetPt %.1f, upperJetPt %.1f\n",
           pathNameData.Data(), lowerCentrality, upperCentrality, lowerJetPt, upperJetPt), "");
  settings->Write();
  
  saveFile->Close();
  
  
  return 0;
}