ROOT Analysis for the Inclusive Detachted Dilepton Trigger Lines
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

214 lines
8.6 KiB

#include "TH1D.h"
#include "TH2D.h"
#include "THStack.h"
#include "TGraph.h"
#include "TTree.h"
#include "TChain.h"
#include "TFile.h"
#include "TCanvas.h"
#include "TROOT.h"
#include "TStyle.h"
#include "TColor.h"
#include "TLorentzVector.h"
#include "TRandom3.h"
#include "TLorentzVector.h"
#include "RooDataHist.h"
#include "RooRealVar.h"
#include "RooPlot.h"
#include "RooGaussian.h"
#include "RooExponential.h"
#include "RooRealConstant.h"
#include "RooAddPdf.h"
#include "RooFitResult.h"
#include "RooProduct.h"
#include "RooCrystalBall.h"
#include "RooBreitWigner.h"
#include "RooArgSet.h"
#include "RooFFTConvPdf.h"
#include "RooNovosibirsk.h"
#include <string>
#include <iostream>
#include <cmath>
const int nBins = 70;
const Double_t MASS_HIST_MIN = 5150.;
const Double_t MASS_HIST_MAX = 6000.;
const char *B0_DECAY = "Hlt2RD_B0ToKpPimMuMu_woHtl1cut";
const char *Bu_DECAY = "Hlt2RD_BuToKpMuMu_woHtl1cut";
const char *TITLE = Bu_DECAY;
const char *HIST_TITLE = "Hlt2RD_BuToKpMuMu w/o Hlt1 Decision Cut";
const char *X_AXIS = "m(K^{+}#mu^{+}#mu^{-})";
void CreateRooFitAndDraw(TH1D *hist, int fitting_entries);
int analysis_turbo()
{
std::string tree = "";
if (TITLE == B0_DECAY)
{
tree = "Hlt2RD_B0ToKpPimMuMu";
}
else
{
tree = "Hlt2RD_BuToKpMuMu";
}
TChain *data_chain = new TChain(TString::Format("%s/DecayTree", tree.c_str()).Data());
data_chain->Add("/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/Collision23_Beam6800GeV-VeloClosed-MagDown-Excl-UT_RealData_SprucingPass23r1_94000000_RD.root");
Double_t B_M, Jpsi_M, B0_M, Kst_M;
Bool_t Hlt1TrackMVADecision, Hlt1TwoTrackMVADecision;
if (TITLE == B0_DECAY)
{
data_chain->SetBranchAddress("B0_M", &B0_M);
data_chain->SetBranchAddress("Jpsi_M", &Jpsi_M);
data_chain->SetBranchAddress("Kst0_M", &Kst_M);
data_chain->SetBranchAddress("Hlt1TrackMVADecision", &Hlt1TrackMVADecision);
data_chain->SetBranchAddress("Hlt1TwoTrackMVADecision", &Hlt1TwoTrackMVADecision);
}
else
{
data_chain->SetBranchAddress("B_M", &B_M);
data_chain->SetBranchAddress("Jpsi_M", &Jpsi_M);
data_chain->SetBranchAddress("Hlt1TrackMVADecision", &Hlt1TrackMVADecision);
data_chain->SetBranchAddress("Hlt1TwoTrackMVADecision", &Hlt1TwoTrackMVADecision);
}
TH1D *h1_B_M = new TH1D("h1_B_M", HIST_TITLE, nBins, MASS_HIST_MIN, MASS_HIST_MAX);
h1_B_M->GetXaxis()->SetTitle(X_AXIS);
int fitting_entries = 0;
unsigned int entries = data_chain->GetEntries();
for (unsigned int i = 0; i < entries; i++)
{
data_chain->GetEntry(i);
if (TITLE == B0_DECAY)
{
if ((TMath::Abs(Jpsi_M - 3096.9) < 100) && (B0_M > 4500) && (B0_M < 6000) && (TMath::Abs(Kst_M - 895.55) < 50) /*&& ((Hlt1TrackMVADecision) || (Hlt1TwoTrackMVADecision))*/)
{
h1_B_M->Fill(B0_M);
if (MASS_HIST_MIN <= B0_M && B0_M <= MASS_HIST_MAX)
{
fitting_entries++;
}
}
}
else
{
if ((TMath::Abs(Jpsi_M - 3096.9) < 100.) && (B_M > 4500.) && (B_M < 6000.) /*&& ((Hlt1TrackMVADecision) || (Hlt1TwoTrackMVADecision))*/)
{
h1_B_M->Fill(B_M);
if (MASS_HIST_MIN <= B_M && B_M <= MASS_HIST_MAX)
{
fitting_entries++;
}
}
}
if (i % 10000 == 0)
{
std::cout << "["
<< TITLE
<< "] Processed event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 100.) << "%)" << std::endl;
}
}
std::cout << "["
<< TITLE
<< "] Processed event: " << entries << " (" << TString::Format("%.2f", 100.) << "%)" << std::endl;
TCanvas *c1 = new TCanvas("c1", "c1", 0, 0, 800, 600);
h1_B_M->Draw();
c1->Draw();
c1->SaveAs(TString::Format("images/root_hist_%s_bmass.pdf", TITLE).Data());
CreateRooFitAndDraw(h1_B_M, fitting_entries);
return 0;
}
void CreateRooFitAndDraw(TH1D *hist, int fitting_entries)
{
RooRealVar roo_var_mass("var_mass", "B Mass Variable", MASS_HIST_MIN, MASS_HIST_MAX);
roo_var_mass.setRange("fitting_range", MASS_HIST_MIN, MASS_HIST_MAX);
RooDataHist roohist_B_M("roohist_B_M", "B Mass Histogram", roo_var_mass, RooFit::Import(*hist));
RooPlot *roo_frame_mass = roo_var_mass.frame(RooFit::Title(HIST_TITLE));
roohist_B_M.plotOn(roo_frame_mass, RooFit::Binning(nBins), RooFit::Name("B Mass Distribution"));
roo_frame_mass->GetXaxis()->SetTitle(X_AXIS);
// Crystal Ball for Signal
RooRealVar var_mass_x0("var_mass_x0", "#mu", 5278., 5170., 5500.);
RooRealVar var_mass_sigmaLR("var_mass_sigmaLR", "#sigma_{LR}", 16., 5., 40.);
// Same Variables for Left and Right Tail
// RooRealVar var_mass_alphaL("var_mass_alphaL", "#alpha_{L}", 2., 0., 4.);
// RooRealVar var_mass_nL("var_mass_nL", "n_{L}", 5., 0., 15.);
// RooRealVar var_mass_alphaR("var_mass_alphaR", "#alpha_{R}", 2., 0., 4.);
// RooRealVar var_mass_nR("var_mass_nR", "n_{R}", 5., 0., 15.);
// B+/-
auto var_mass_alphaL = RooRealConstant::value(1.912);
auto var_mass_nL = RooRealConstant::value(1.125);
auto var_mass_alphaR = RooRealConstant::value(2.447);
auto var_mass_nR = RooRealConstant::value(1.491);
// B0
// auto var_mass_alphaL = RooRealConstant::value(1.948);
// auto var_mass_nL = RooRealConstant::value(0.618);
// auto var_mass_alphaR = RooRealConstant::value(2.320);
// auto var_mass_nR = RooRealConstant::value(0.473);
RooCrystalBall sig_cb("sig_cb", "Signal Crystal Ball", roo_var_mass, var_mass_x0, var_mass_sigmaLR, var_mass_alphaL, var_mass_nL, var_mass_alphaR, var_mass_nR);
// Exponential for Background
RooRealVar var_mass_bkg_c("var_mass_bkg_c", "#lambda", -0.0014, -0.004, -0.000);
RooExponential bkg_exp("bkg_exp", "Exp Background", roo_var_mass, var_mass_bkg_c);
RooRealVar var_mass_nsig("nsig", "Mass N Signal", 0., hist->GetEntries());
RooRealVar var_mass_nbkg("nbkg", "Mass N Background", 0., hist->GetEntries());
// TString pdf_name = TString::Format("%s_sigplusbkg", var_id.c_str());
RooAddPdf sigplusbkg("sigplusbkg", "Sig and Bkg PDF", RooArgList(sig_cb, bkg_exp), RooArgList(var_mass_nsig, var_mass_nbkg));
RooFitResult *fitres = sigplusbkg.fitTo(roohist_B_M, RooFit::Save(), RooFit::PrintLevel(1), RooFit::Range("fitting_range"));
sigplusbkg.plotOn(roo_frame_mass, RooFit::VisualizeError(*fitres, 1), RooFit::FillColor(kYellow -7), RooFit::FillStyle(3144));
sigplusbkg.plotOn(roo_frame_mass, RooFit::LineColor(kRed), RooFit::LineStyle(kSolid), RooFit::Range("fitting_range"), RooFit::Name("sigplusbkg"));
sigplusbkg.plotOn(roo_frame_mass, RooFit::Components(RooArgSet(bkg_exp)), RooFit::LineColor(kBlue - 7), RooFit::LineStyle(kDashed), RooFit::Range("fitting_range"), RooFit::Name("bkg_exp"));
sigplusbkg.plotOn(roo_frame_mass, RooFit::Components(RooArgSet(sig_cb)), RooFit::LineColor(kRed - 7), RooFit::LineStyle(kDashed), RooFit::Range("fitting_range"), RooFit::Name("sig_cb"));
TCanvas *c = new TCanvas("roofit_c", "roofit_c", 0, 0, 800, 600);
roo_frame_mass->Draw();
TLegend *leg1 = new TLegend(0.50, 0.58, 0.87, 0.89);
leg1->SetFillColor(kWhite);
leg1->SetLineColor(kBlack);
leg1->AddEntry(roo_frame_mass->findObject("sigplusbkg"), "Signal + Background", "LP");
leg1->AddEntry(roo_frame_mass->findObject("sig_cb"), "Signal", "LP");
leg1->AddEntry(roo_frame_mass->findObject("bkg_exp"), "Background", "LP");
leg1->AddEntry((TObject *)0, "", "");
leg1->AddEntry((TObject *)0, TString::Format("%s = %.3f #pm %.3f", var_mass_x0.getTitle().Data(), var_mass_x0.getVal(), var_mass_x0.getError()).Data(), "");
leg1->AddEntry((TObject *)0, TString::Format("%s = %.3f #pm %.3f", var_mass_sigmaLR.getTitle().Data(), var_mass_sigmaLR.getVal(), var_mass_sigmaLR.getError()).Data(), "");
leg1->AddEntry((TObject *)0, TString::Format("%s = %.6f #pm %.6f", var_mass_bkg_c.getTitle().Data(), var_mass_bkg_c.getVal(), var_mass_bkg_c.getError()).Data(), "");
leg1->AddEntry((TObject *)0, TString::Format("%s = %.3f #pm %.3f", "S", var_mass_nsig.getVal(), var_mass_nsig.getError()).Data(), "");
leg1->AddEntry((TObject *)0, TString::Format("%s = %.3f #pm %.3f", "B", var_mass_nbkg.getVal(), var_mass_nbkg.getError()).Data(), "");
leg1->AddEntry((TObject *)0, TString::Format("Entries: %d", fitting_entries), "");
leg1->Draw();
c->Draw();
c->SaveAs(TString::Format("images/data/roofit_hist_%s_fitted_bmass.pdf", TITLE).Data());
}