From 3209f9c9aa27de859944851971ebf8e716987111 Mon Sep 17 00:00:00 2001 From: Marius Pfeiffer Date: Tue, 23 Jan 2024 16:36:19 +0100 Subject: [PATCH] macros for data and sim analysis --- analysis_fullstream_b02hphmmumu.cpp | 26 ++++++------- analysis_fullstream_bu2hpmumu.cpp | 6 +-- analysis_turbo.cpp | 53 ++++++++++++++----------- simulation.cpp | 60 ++++++++++++++--------------- 4 files changed, 76 insertions(+), 69 deletions(-) diff --git a/analysis_fullstream_b02hphmmumu.cpp b/analysis_fullstream_b02hphmmumu.cpp index fbbe8d7..a10174f 100644 --- a/analysis_fullstream_b02hphmmumu.cpp +++ b/analysis_fullstream_b02hphmmumu.cpp @@ -40,9 +40,9 @@ const Double_t MASS_HIST_MAX = 5700.; const Double_t MASS_HIST_FIT_MIN = 5100.; const Double_t MASS_HIST_FIT_MAX = 5700.; -const char* TITLE = "SpruceRD_B0ToHpHmMuMu (#pi^{+} #rightarrow K^{+})"; -const char* FILE_NAME = "SpruceRD_B0ToHpHmMuMu_Pip2Kp"; -const char* MASS_LITERAL = "m(#pi^{+}_{(#rightarrow K^{+})}#pi^{-}#mu^{+}#mu^{-})"; +const char* TITLE = "SpruceRD_B0ToHpHmMuMu (#pi^{-} #rightarrow K^{-})"; +const char* FILE_NAME = "SpruceRD_B0ToHpHmMuMu_Pim2Km"; +const char* MASS_LITERAL = "m(#pi^{+}#pi^{-}_{(#rightarrow K^{-})}#mu^{+}#mu^{-})"; const Double_t K_MASS = 493.677; @@ -173,14 +173,14 @@ int analysis_fullstream_b02hphmmumu() TLorentzVector l2_4v(L2_PX, L2_PY, L2_PZ, L2_ENERGY); // Pi+ -> K+ - TVector3 K_momentum(Hp_PX, Hp_PY, Hp_PZ); - double K_energy = TMath::Sqrt(TMath::Sq(K_MASS) + K_momentum.Mag2()); - TLorentzVector Pi_4v(Hm_PX, Hm_PY, Hm_PZ, Hm_ENERGY); + // TVector3 K_momentum(Hp_PX, Hp_PY, Hp_PZ); + // double K_energy = TMath::Sqrt(TMath::Sq(K_MASS) + K_momentum.Mag2()); + // TLorentzVector Pi_4v(Hm_PX, Hm_PY, Hm_PZ, Hm_ENERGY); // Pi- -> K- - // TVector3 K_momentum(Hm_PX, Hm_PY, Hm_PZ); - // double K_energy = TMath::Sqrt(TMath::Sq(K_MASS) + K_momentum.Mag2()); - // TLorentzVector Pi_4v(Hp_PX, Hp_PY, Hp_PZ, Hp_ENERGY); + TVector3 K_momentum(Hm_PX, Hm_PY, Hm_PZ); + double K_energy = TMath::Sqrt(TMath::Sq(K_MASS) + K_momentum.Mag2()); + TLorentzVector Pi_4v(Hp_PX, Hp_PY, Hp_PZ, Hp_ENERGY); TLorentzVector K_4v(K_momentum, K_energy); @@ -192,20 +192,20 @@ int analysis_fullstream_b02hphmmumu() // (Jpsi_MAXDOCACHI2 < 36) & // - (L1_BPVIPCHI2 > 9) & (L2_BPVIPCHI2 > 9) & (L1_PID_MU > -3) & (L2_PID_MU > -3) & (L1_ISMUON == 1) & (L2_ISMUON == 1) & (L1_PT > 350) & (L2_PT > 350) & + (L1_BPVIPCHI2 > 9) & (L2_BPVIPCHI2 > 9) & (L1_PID_MU > -3) & (L2_PID_MU > -3) & (L1_ISMUON) & (L2_ISMUON) & (L1_PT > 350) & (L2_PT > 350) & // (Jpsi_CHI2DOF < 9) & (Jpsi_BPVFDCHI2 > 16) & (Jpsi_M < 5500) & // (Res_PT > 400) & (Res_MAXDOCACHI2 < 36) & (reconstructed_Res_Mass < 2600) & (Res_CHI2DOF < 25) & (Res_BPVIPCHI2 > 4) & // - (Hm_BPVIPCHI2 > 6) & (Hm_PT > 250) & (Hm_P > 2000) & (Hm_PID_K < 0) & + (Hm_BPVIPCHI2 > 6) & (Hm_PT > 250) & (Hm_P > 2000) & (Hm_PID_K > 0) & // - (Hp_BPVIPCHI2 > 6) & (Hp_PT > 250) & (Hp_P > 2000) & (Hp_PID_K > 0) + (Hp_BPVIPCHI2 > 6) & (Hp_PT > 250) & (Hp_P > 2000) & (Hp_PID_K < 0) ) & // (Hlt2RD_B0ToKpPimMuMuDecision) & ((Hlt2_InclDetDiMuon_4BodyDecision) | (Hlt2_InclDetDiMuon_3BodyDecision) | (Hlt2_InclDetDiMuonDecision))) { - if ((TMath::Abs(Jpsi_M - 3096.9) < 100) & (Hlt1TrackMVADecision) & (Hlt1TwoTrackMVADecision)) + if ((TMath::Abs(Jpsi_M - 3096.9) < 100) & ((Hlt1TrackMVADecision) | (Hlt1TwoTrackMVADecision))) { h1_B0_M->Fill(reconstructed_B0_Mass); diff --git a/analysis_fullstream_bu2hpmumu.cpp b/analysis_fullstream_bu2hpmumu.cpp index ea1e5d5..489f4c0 100644 --- a/analysis_fullstream_bu2hpmumu.cpp +++ b/analysis_fullstream_bu2hpmumu.cpp @@ -157,7 +157,7 @@ int analysis_fullstream_bu2hpmumu() if (i % 10000 == 0) { std::cout << "[" - << "SpruceRD_BuToHpMuMu" + << FILE_NAME << "] Processed event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 100.) << "%)" << std::endl; } } @@ -165,7 +165,7 @@ int analysis_fullstream_bu2hpmumu() 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.png", FILE_NAME).Data()); + c1->SaveAs(TString::Format("images/root_hist_%s_bmass.pdf", FILE_NAME).Data()); CreateRooFitAndDraw(h1_B_M, fitting_entries); @@ -196,5 +196,5 @@ void CreateRooFitAndDraw(TH1D *hist, int fitting_entries) leg1->Draw(); c->Draw(); - c->SaveAs(TString::Format("images/roofit_hist_%s_bmass.png", FILE_NAME).Data()); + c->SaveAs(TString::Format("images/roofit_hist_%s_bmass.pdf", FILE_NAME).Data()); } \ No newline at end of file diff --git a/analysis_turbo.cpp b/analysis_turbo.cpp index 2ea4f9e..46f8638 100644 --- a/analysis_turbo.cpp +++ b/analysis_turbo.cpp @@ -34,29 +34,29 @@ 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); +const char *B0_DECAY = "Hlt2RD_B0ToKpPimMuMu"; +const char *Bu_DECAY = "Hlt2RD_BuToKpMuMu"; + +const char *TITLE = B0_DECAY; +const char *X_AXIS = "m(K^{+}#pi^{-}#mu^{+}#mu^{-})"; + + + +void CreateRooFitAndDraw(TH1D *hist, int fitting_entries); 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()); + TChain *data_chain = new TChain(TString::Format("%s/DecayTree", TITLE).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") + if (TITLE == B0_DECAY) { data_chain->SetBranchAddress("B0_M", &B0_M); data_chain->SetBranchAddress("Jpsi_M", &Jpsi_M); @@ -72,19 +72,24 @@ int analysis_turbo() 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()); + TH1D *h1_B_M = new TH1D("h1_B_M", TITLE, nBins, MASS_HIST_FIT_MIN, MASS_HIST_FIT_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 == "Hlt2RD_B0ToKpPimMuMu") + 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_FIT_MIN <= B0_M && B0_M <= MASS_HIST_FIT_MAX) + { + fitting_entries++; + } } } else @@ -92,13 +97,17 @@ int analysis_turbo() 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_FIT_MIN <= B_M && B_M <= MASS_HIST_FIT_MAX) + { + fitting_entries++; + } } } if (i % 10000 == 0) { std::cout << "[" - << title + << TITLE << "] Processed event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 100.) << "%)" << std::endl; } } @@ -106,23 +115,23 @@ int analysis_turbo() 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()); + c1->SaveAs(TString::Format("images/root_hist_%s_bmass.pdf", TITLE).Data()); - CreateRooFitAndDraw(h1_B_M, title.c_str(), x_axis.c_str()); + CreateRooFitAndDraw(h1_B_M, fitting_entries); return 0; } -void CreateRooFitAndDraw(TH1D *hist, const char *title, const char *x_axis) +void CreateRooFitAndDraw(TH1D *hist, int fitting_entries) { 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)); + 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); + roo_frame_mass->GetXaxis()->SetTitle(X_AXIS); TCanvas *c = new TCanvas("roofit_c", "roofit_c", 0, 0, 800, 600); @@ -132,10 +141,10 @@ void CreateRooFitAndDraw(TH1D *hist, const char *title, const char *x_axis) leg1->SetFillColor(kWhite); leg1->SetLineColor(kBlack); - leg1->AddEntry((TObject*)0, TString::Format("Entries: %d", (int)hist->GetEntries()), ""); + leg1->AddEntry((TObject *)0, TString::Format("Entries: %d", fitting_entries), ""); leg1->Draw(); c->Draw(); - c->SaveAs(TString::Format("images/roofit_hist_%s_bmass.pdf", title).Data()); + c->SaveAs(TString::Format("images/roofit_hist_%s_bmass.pdf", TITLE).Data()); } \ No newline at end of file diff --git a/simulation.cpp b/simulation.cpp index 8ed2575..41dae4c 100644 --- a/simulation.cpp +++ b/simulation.cpp @@ -33,29 +33,30 @@ #include #include -const int nBins = 70; +const int nBins = 170;//70; -const Double_t MASS_HIST_MIN = 5100.; +const Double_t MASS_HIST_MIN = 2000.; const Double_t MASS_HIST_MAX = 6000.; -const Double_t MASS_HIST_FIT_MIN = 5100.; +const Double_t MASS_HIST_FIT_MIN = 2000.; const Double_t MASS_HIST_FIT_MAX = 6000.; const Double_t K_MASS = 493.677; int simulation() { - const char *name = "BuToKpMuMu_Fullstream"; + const char *name = "BuToHpMuMu_Fullstream"; const bool use_hyp_replace = true; const char *b_name = "B"; - const bool has_H_minus = false; - auto quickformat_name = [name](const char * format) { + auto quickformat_name = [name](const char *format) + { return TString::Format(format, name); }; - TChain *data_chain = new TChain("B0ToHpHmMuMu_noPID/DecayTree"); + TChain *data_chain = new TChain("BuToHpMuMu_noPID/DecayTree"); data_chain->Add("/auto/data/pfeiffer/inclusive_detached_dilepton/MC/rd_btoxll_simulation_fullstream_v0r0p6671378_BuToKpMuMu_12143001_magdown.root"); + // TRUE ID: Muon sind Muons, Hadronen sind K, pi /* rd_btoxll_simulation_fullstream_v0r0p6671378_B0ToKpPimMuMu_11144002_magdown.root rd_btoxll_simulation_fullstream_v0r0p6671378_BuToKpMuMu_12143001_magdown.root @@ -66,12 +67,17 @@ int simulation() Int_t B_BKGCAT; data_chain->SetBranchAddress(TString::Format("%s_BKGCAT", b_name).Data(), &B_BKGCAT); - Float_t L1_PX, L1_PY, L1_PZ, L1_ENERGY, - L2_PX, L2_PY, L2_PZ, L2_ENERGY, - Hp_PX, Hp_PY, Hp_PZ, Hp_ENERGY, - Hm_PX, Hm_PY, Hm_PZ, Hm_ENERGY; + Float_t L1_PX, L1_PY, L1_PZ, L1_ENERGY, + L2_PX, L2_PY, L2_PZ, L2_ENERGY, + Hp_PX, Hp_PY, Hp_PZ, Hp_ENERGY; Double_t B_M; + Int_t L1_TRUEID, L2_TRUEID, Hp_TRUEID; + + data_chain->SetBranchAddress("L1_TRUEID", &L1_TRUEID); + data_chain->SetBranchAddress("L2_TRUEID", &L2_TRUEID); + data_chain->SetBranchAddress("Hp_TRUEID", &Hp_TRUEID); + if (use_hyp_replace) { data_chain->SetBranchAddress("L1_PX", &L1_PX); @@ -86,12 +92,6 @@ int simulation() data_chain->SetBranchAddress("Hp_PY", &Hp_PY); data_chain->SetBranchAddress("Hp_PZ", &Hp_PZ); data_chain->SetBranchAddress("Hp_ENERGY", &Hp_ENERGY); - if (has_H_minus) { - data_chain->SetBranchAddress("Hm_PX", &Hp_PX); - data_chain->SetBranchAddress("Hm_PY", &Hp_PY); - data_chain->SetBranchAddress("Hm_PZ", &Hp_PZ); - data_chain->SetBranchAddress("Hm_ENERGY", &Hp_ENERGY); - } } else { @@ -99,7 +99,7 @@ int simulation() } TH1D *h1_B_M = new TH1D("h1_B_M", "B Mass", nBins, MASS_HIST_MIN, MASS_HIST_MAX); - TH1D *h1_B_M_bkgcat = new TH1D("h1_B_M_bkgcat", "B Mass with BKGCAT <= 10", nBins, MASS_HIST_MIN, MASS_HIST_MAX); + TH1D *h1_B_M_trueid = new TH1D("h1_B_M_trueid", "B Mass, TrueID matched", nBins, MASS_HIST_MIN, MASS_HIST_MAX); TH1I *h1_B_BKGCAT = new TH1I("h1_B_BKGCAT", "B Background Category", nBins, 0, 120); TH2D *h2_B_M_vs_B_BKGCAT = new TH2D("h2_B_M_vs_B_BKGCAT", "B Mass vs Background Category", nBins, MASS_HIST_MIN, MASS_HIST_MAX, nBins, 0, 120); @@ -114,25 +114,23 @@ int simulation() if (use_hyp_replace) { TVector3 K_momentum(Hp_PX, Hp_PY, Hp_PZ); + double K_energy = TMath::Sqrt(TMath::Sq(K_MASS) + K_momentum.Mag2()); TLorentzVector K_4v(K_momentum, K_energy); TLorentzVector l1_4v(L1_PX, L1_PY, L1_PZ, L1_ENERGY); TLorentzVector l2_4v(L2_PX, L2_PY, L2_PZ, L2_ENERGY); - TLorentzVector sum = K_4v + l1_4v + l2_4v; - if (has_H_minus) { - TLorentzVector Hm_4v(Hm_PX, Hm_PY, Hm_PZ, Hm_ENERGY); - sum += Hm_4v; - } - reconstructed_B_Mass = sum.M(); + reconstructed_B_Mass = (K_4v + l1_4v + l2_4v).M(); } else { reconstructed_B_Mass = B_M; } - if (B_BKGCAT <= 10) + if (TMath::Abs(L1_TRUEID) == 13 && L2_TRUEID == -L1_TRUEID && TMath::Abs(Hp_TRUEID) == 321) { - h1_B_M_bkgcat->Fill(reconstructed_B_Mass); + std::cout << "L1: " << L1_TRUEID << ", L2: " << L2_TRUEID << ", Hp: " << Hp_TRUEID << std::endl; + std::cout << "Mass: " << reconstructed_B_Mass << std::endl; + h1_B_M_trueid->Fill(reconstructed_B_Mass); } h1_B_M->Fill(reconstructed_B_Mass); @@ -148,9 +146,9 @@ int simulation() } h1_B_M->SetLineColor(kBlue); - h1_B_M_bkgcat->SetLineColor(kMagenta + 2); - h1_B_M_bkgcat->SetFillColor(kMagenta + 2); - h1_B_M_bkgcat->SetFillStyle(3244); + h1_B_M_trueid->SetLineColor(kMagenta + 2); + h1_B_M_trueid->SetFillColor(kMagenta + 2); + h1_B_M_trueid->SetFillStyle(3244); h1_B_BKGCAT->SetLineColor(kBlue); h1_B_BKGCAT->SetFillColor(kBlue); @@ -160,9 +158,9 @@ int simulation() TCanvas *c1 = new TCanvas("c1", "c1", 0, 0, 800, 600); h1_B_M->SetStats(0); - h1_B_M_bkgcat->SetStats(0); + h1_B_M_trueid->SetStats(0); h1_B_M->Draw(); - h1_B_M_bkgcat->Draw("SAME"); + h1_B_M_trueid->Draw("SAME"); c1->BuildLegend(0.58, 0.65, 0.85, 0.87); c1->Draw(); c1->SaveAs(quickformat_name("images/sim/%s/h1_B_M.pdf"));