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.
 
 

141 lines
4.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 = 5100.;
const Double_t MASS_HIST_MAX = 6000.;
const Double_t MASS_HIST_FIT_MIN = 5100.;
const Double_t MASS_HIST_FIT_MAX = 6000.;
void CreateRooFitAndDraw(TH1D *hist, const char *title, const char *x_axis);
int analysis_turbo()
{
// std::string title{"Hlt2RD_B0ToKpPimMuMu"};
// std::string x_axis{"m(#pi^{+}_{(#rightarrow K^{+})} #pi^{-} #mu^{+}#mu^{-})"};
std::string title{"Hlt2RD_BuToKpMuMu"};
std::string x_axis{"m(#pi^{+}_{(#rightarrow K^{+})}#mu^{+}#mu^{-})"};
TChain *data_chain = new TChain(TString::Format("%s/DecayTree", title.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 == "Hlt2RD_B0ToKpPimMuMu")
{
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", title.c_str(), nBins, MASS_HIST_MIN, MASS_HIST_MAX);
h1_B_M->GetXaxis()->SetTitle(x_axis.c_str());
unsigned int entries = data_chain->GetEntries();
for (unsigned int i = 0; i < entries; i++)
{
data_chain->GetEntry(i);
if (title == "Hlt2RD_B0ToKpPimMuMu")
{
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);
}
}
else
{
if ((TMath::Abs(Jpsi_M - 3096.9) < 100.) && (B_M > 4500.) && (B_M < 6000.) && ((Hlt1TrackMVADecision) || (Hlt1TwoTrackMVADecision)))
{
h1_B_M->Fill(B_M);
}
}
if (i % 10000 == 0)
{
std::cout << "["
<< title
<< "] Processed event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 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.c_str()).Data());
CreateRooFitAndDraw(h1_B_M, title.c_str(), x_axis.c_str());
return 0;
}
void CreateRooFitAndDraw(TH1D *hist, const char *title, const char *x_axis)
{
RooRealVar roo_var_mass("var_mass", "B Mass Variable", MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX);
roo_var_mass.setRange("fitting_range", MASS_HIST_FIT_MIN, MASS_HIST_FIT_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(title));
roohist_B_M.plotOn(roo_frame_mass, RooFit::Binning(nBins), RooFit::Name("B Mass Distribution"));
roo_frame_mass->GetXaxis()->SetTitle(x_axis);
TCanvas *c = new TCanvas("roofit_c", "roofit_c", 0, 0, 800, 600);
roo_frame_mass->Draw();
TLegend *leg1 = new TLegend(0.65, 0.7, 0.87, 0.8);
leg1->SetFillColor(kWhite);
leg1->SetLineColor(kBlack);
leg1->AddEntry((TObject*)0, TString::Format("Entries: %d", (int)hist->GetEntries()), "");
leg1->Draw();
c->Draw();
c->SaveAs(TString::Format("images/roofit_hist_%s_bmass.pdf", title).Data());
}