268 lines
11 KiB
C++
268 lines
11 KiB
C++
#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 Double_t PSI2S_MASS = 3686.093;
|
|
const Double_t JPSI_MASS = 3096.9;
|
|
|
|
const char *B0_DECAY = "Hlt2RD_B0ToKpPimMuMu";
|
|
const char *Bu_DECAY = "Hlt2RD_BuToKpMuMu";
|
|
|
|
const char *TITLE = Bu_DECAY;
|
|
const char *HIST_TITLE = Bu_DECAY; // "Hlt2RD_BuToKpMuMu";
|
|
const char *X_AXIS = "m(K^{+}#mu^{+}#mu^{-})"; // "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;
|
|
|
|
UInt_t runNumber;
|
|
ULong64_t eventNumber;
|
|
|
|
data_chain->SetBranchAddress("RUNNUMBER", &runNumber);
|
|
data_chain->SetBranchAddress("EVENTNUMBER", &eventNumber);
|
|
|
|
if (TITLE == B0_DECAY)
|
|
{
|
|
data_chain->SetBranchAddress("B0_M", &B0_M);
|
|
data_chain->SetBranchAddress("Kst0_M", &Kst_M);
|
|
}
|
|
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_jpsi = new TH1D("h1_B_M_jpsi", TString::Format("%s (J/#psi)", HIST_TITLE), nBins, MASS_HIST_MIN, MASS_HIST_MAX);
|
|
TH1D *h1_B_M_psi2s = new TH1D("h1_B_M_psi2s", TString::Format("%s (#psi(2S))", HIST_TITLE), nBins, MASS_HIST_MIN, MASS_HIST_MAX);
|
|
h1_B_M_jpsi->GetXaxis()->SetTitle(X_AXIS);
|
|
h1_B_M_psi2s->GetXaxis()->SetTitle(X_AXIS);
|
|
|
|
std::map<std::pair<unsigned int, unsigned long>, int> run_event_num_dict;
|
|
|
|
int fitting_entries = 0;
|
|
unsigned int entries = data_chain->GetEntries();
|
|
unsigned int selected_entries = 0;
|
|
for (unsigned int i = 0; i < entries; i++)
|
|
{
|
|
data_chain->GetEntry(i);
|
|
|
|
if (TITLE == B0_DECAY)
|
|
{
|
|
if ((B0_M > 4500) && (B0_M < 6000) && (TMath::Abs(Kst_M - 895.55) < 50) && ((Hlt1TrackMVADecision) || (Hlt1TwoTrackMVADecision)))
|
|
{
|
|
// check for unique run/event number
|
|
selected_entries++;
|
|
auto run_event_pair = std::make_pair((unsigned int)runNumber, (unsigned long)eventNumber);
|
|
int &run_event_unique_num = run_event_num_dict[run_event_pair];
|
|
if (run_event_unique_num)
|
|
{
|
|
run_event_unique_num = run_event_unique_num + 1;
|
|
std::cout << "R: " << runNumber << " / E: " << eventNumber << " / # " << run_event_unique_num
|
|
<< ", M = " << B0_M << " MeV"
|
|
<< std::endl;
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
run_event_unique_num = 1;
|
|
}
|
|
if (TMath::Abs(Jpsi_M - JPSI_MASS) < 100)
|
|
{
|
|
h1_B_M_jpsi->Fill(B0_M);
|
|
}
|
|
else if (TMath::Abs(Jpsi_M - PSI2S_MASS) < 100)
|
|
{
|
|
h1_B_M_psi2s->Fill(B0_M);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ((B_M > 4500.) && (B_M < 6000.) && ((Hlt1TrackMVADecision) || (Hlt1TwoTrackMVADecision)))
|
|
{
|
|
// check for unique run/event number
|
|
selected_entries++;
|
|
auto run_event_pair = std::make_pair((unsigned int)runNumber, (unsigned long)eventNumber);
|
|
int &run_event_unique_num = run_event_num_dict[run_event_pair];
|
|
if (run_event_unique_num)
|
|
{
|
|
run_event_unique_num = run_event_unique_num + 1;
|
|
std::cout << "R: " << runNumber << " / E: " << eventNumber << " / # " << run_event_unique_num
|
|
<< ", M = " << B_M << " MeV"
|
|
<< std::endl;
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
run_event_unique_num = 1;
|
|
}
|
|
if (TMath::Abs(Jpsi_M - JPSI_MASS) < 100)
|
|
{
|
|
h1_B_M_jpsi->Fill(B_M);
|
|
}
|
|
else if (TMath::Abs(Jpsi_M - PSI2S_MASS) < 100)
|
|
{
|
|
h1_B_M_psi2s->Fill(B_M);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ((i + 1) % 10000 == 0 || i + 1 == entries)
|
|
{
|
|
std::cout << "["
|
|
<< TITLE
|
|
<< "] Processed event: " << i + 1 << " (" << TString::Format("%.2f", ((double)(i + 1) / (double)entries) * 100.) << "%)" << std::endl;
|
|
}
|
|
}
|
|
|
|
std::cout << "#### " << run_event_num_dict.size() << " out of " << selected_entries << " unique ("
|
|
<< TString::Format("%.2f", ((double)(run_event_num_dict.size()) / (double)selected_entries) * 100.) << "%)." << std::endl;
|
|
|
|
TCanvas *c1 = new TCanvas("c1", "c1", 0, 0, 1400, 600);
|
|
c1->Divide(2, 1);
|
|
c1->cd(1);
|
|
h1_B_M_jpsi->Draw();
|
|
c1->cd(2);
|
|
h1_B_M_psi2s->Draw();
|
|
c1->Draw();
|
|
c1->SaveAs(TString::Format("images/root_hist_%s_bmass.pdf", TITLE).Data());
|
|
|
|
CreateRooFitAndDraw(h1_B_M_jpsi, 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: %.2f", var_mass_nsig.getVal() + var_mass_nbkg.getVal()), "");
|
|
leg1->AddEntry((TObject *)0, TString::Format("Entries: %.0f", roohist_B_M.sumEntries()), "");
|
|
|
|
leg1->Draw();
|
|
|
|
c->Draw();
|
|
c->SaveAs(TString::Format("images/data/roofit_hist_%s_fitted_bmass.pdf", TITLE).Data());
|
|
} |