From bd9c7b5f8f83ef653dd60f7b54c58978f03304df Mon Sep 17 00:00:00 2001 From: Marius Pfeiffer Date: Thu, 22 Feb 2024 16:53:48 +0100 Subject: [PATCH] hlt1 decision overview, simulation start, abstraction --- new_analysis.cpp | 412 +++++++++++++++++++++++++++++------------------ 1 file changed, 253 insertions(+), 159 deletions(-) diff --git a/new_analysis.cpp b/new_analysis.cpp index 7126da6..0b552d1 100644 --- a/new_analysis.cpp +++ b/new_analysis.cpp @@ -43,6 +43,10 @@ const Double_t PSI2S_MASS = 3686.093; const Double_t JPSI_MASS = 3096.900; const Double_t KSTAR_MASS = 891.760; +const int PID_KAON = 321; +const int PID_PION = 211; +const int PID_MUON = 13; + class FourVect { private: @@ -130,6 +134,28 @@ std::vector Hlt1Decisions{ Hlt1Decision{"TwoTrackMVA", 13}, }; +const std::vector> Hlt1DecisionSets{ + std::set{ + "TwoTrackMVA", "TrackMuonMVA", "TrackMVA"}, + + std::set{ + "TwoTrackMVA", "TrackMuonMVA", "TrackMVA", "LowPtMuon", "LowPtDiMuon", "DisplacedLeptons"}, + + std::set{ + "TwoTrackMVA", "TrackMuonMVA", "TrackMVA", "DiMuonNoIP", "DiMuonLowMass", "DiMuonHighMass"}, + + std::set{ + "TwoTrackMVA", "TrackMuonMVA", "TrackMVA", "LowPtMuon", "LowPtDiMuon", "DisplacedLeptons", "DiMuonNoIP", "DiMuonLowMass", "DiMuonHighMass"}, + + std::set{ + "LowPtMuon", "LowPtDiMuon", "DisplacedLeptons"}, + + std::set{ + "LowPtMuon", "LowPtDiMuon", "DisplacedLeptons", "DiMuonNoIP", "DiMuonLowMass", "DiMuonHighMass"}, + + std::set{ + "DiMuonNoIP", "DiMuonLowMass", "DiMuonHighMass"}}; + bool CutHlt1DecisionsAnd(const std::set &decision_list) { bool okay = true; @@ -156,6 +182,27 @@ bool CutHlt1DecisionsOr(const std::set &decision_list) return okay; } +bool CutHlt1DecisionsOrOnly(const std::set &decision_list) +{ + bool okay = false; + for (const auto &var : Hlt1Decisions) + { + if (decision_list.find(var.name) != decision_list.end()) + { + okay = okay || var.value; + } + else + { + if (var.value) + { + okay = false; + continue; + } + } + } + return okay; +} + void ConnectHlt1Decisions(TChain *chain) { for (auto &var : Hlt1Decisions) @@ -198,22 +245,113 @@ void PrintProgress(const char *title, unsigned int total, unsigned int every, un } } -RooPlot* CreateRooFitHistogram(TH1D* hist) { - RooRealVar roo_var_mass("var_mass", "B Mass Variable", B_MASS_VAR_MIN, B_MASS_VAR_MAX); - roo_var_mass.setRange("fitting_range", B_MASS_VAR_MIN, B_MASS_VAR_MAX); +RooPlot *CreateRooFitHistogram(TH1D *hist) +{ + RooRealVar roo_var_mass("var_mass", "B Mass Variable", B_MASS_VAR_MIN, B_MASS_VAR_MAX); + roo_var_mass.setRange("fitting_range", B_MASS_VAR_MIN, B_MASS_VAR_MAX); - RooDataHist roohist_B_M("roohist_B_M", "B Mass Histogram", roo_var_mass, RooFit::Import(*hist)); + 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->GetTitle())); - roohist_B_M.plotOn(roo_frame_mass, RooFit::Binning(B_MASS_HIST_BINS), RooFit::Name("B Mass Distribution")); - roo_frame_mass->GetXaxis()->SetTitle(hist->GetXaxis()->GetTitle()); + RooPlot *roo_frame_mass = roo_var_mass.frame(RooFit::Title(hist->GetTitle())); + roohist_B_M.plotOn(roo_frame_mass, RooFit::Binning(B_MASS_HIST_BINS), RooFit::Name("B Mass Distribution")); + roo_frame_mass->GetXaxis()->SetTitle(hist->GetXaxis()->GetTitle()); - return roo_frame_mass; + return roo_frame_mass; +} + +void CheckHlt1Decisioins(TH2D *incl_hist, TH2D *excl_hist, std::map &exclusive_hits, const double reco_mass) +{ + for (const auto &var : Hlt1Decisions) + { + if (var.value) + { + incl_hist->Fill(reco_mass, var.name.c_str(), 1); + } + } + + bool exclusive = true; + std::string line{}; + for (const auto &var : Hlt1Decisions) + { + if (var.value) + { + if (!line.empty()) + { + exclusive = false; + } + + line = var.name; + } + } + + if (!line.empty() && exclusive) + { + int &hits = exclusive_hits[line]; + if (hits) + { + hits += 1; + } + else + { + hits = 1; + } + excl_hist->Fill(reco_mass, line.c_str(), 1); + } +} + +std::vector CreateHlt1DecisionHistos(const char *analysis_name) +{ + TH1D *h1_B_Mass_hlt1_1 = new TH1D("h1_B_Mass_hlt1_1", TString::Format("B Mass (1), J/#psi Mode (%s)", analysis_name), B_MASS_HIST_BINS, B_MASS_VAR_MIN, B_MASS_VAR_MAX); + TH1D *h1_B_Mass_hlt1_12 = new TH1D("h1_B_Mass_hlt1_12", TString::Format("B Mass (12), J/#psi Mode (%s)", analysis_name), B_MASS_HIST_BINS, B_MASS_VAR_MIN, B_MASS_VAR_MAX); + TH1D *h1_B_Mass_hlt1_13 = new TH1D("h1_B_Mass_hlt1_13", TString::Format("B Mass (13), J/#psi Mode (%s)", analysis_name), B_MASS_HIST_BINS, B_MASS_VAR_MIN, B_MASS_VAR_MAX); + TH1D *h1_B_Mass_hlt1_123 = new TH1D("h1_B_Mass_hlt1_123", TString::Format("B Mass (123), J/#psi Mode (%s)", analysis_name), B_MASS_HIST_BINS, B_MASS_VAR_MIN, B_MASS_VAR_MAX); + TH1D *h1_B_Mass_hlt1_2 = new TH1D("h1_B_Mass_hlt1_2", TString::Format("B Mass (2), J/#psi Mode (%s)", analysis_name), B_MASS_HIST_BINS, B_MASS_VAR_MIN, B_MASS_VAR_MAX); + TH1D *h1_B_Mass_hlt1_23 = new TH1D("h1_B_Mass_hlt1_23", TString::Format("B Mass (23), J/#psi Mode (%s)", analysis_name), B_MASS_HIST_BINS, B_MASS_VAR_MIN, B_MASS_VAR_MAX); + TH1D *h1_B_Mass_hlt1_3 = new TH1D("h1_B_Mass_hlt1_3", TString::Format("B Mass (3), J/#psi Mode (%s)", analysis_name), B_MASS_HIST_BINS, B_MASS_VAR_MIN, B_MASS_VAR_MAX); + + return {h1_B_Mass_hlt1_1, h1_B_Mass_hlt1_12, h1_B_Mass_hlt1_13, h1_B_Mass_hlt1_123, h1_B_Mass_hlt1_2, h1_B_Mass_hlt1_23, h1_B_Mass_hlt1_3}; +} + +void FillHlt1DecisionHistos(std::vector histos, double reco_mass) +{ + for (int i = 0; i < Hlt1DecisionSets.size(); i++) + { + if (CutHlt1DecisionsOrOnly(Hlt1DecisionSets[i])) + { + histos[i]->Fill(reco_mass); + // std::cout << " ### Filled " << histos[indx]->GetName() << ". Now: " << histos[indx]->GetEntries() << "." << std::endl; + } + } +} + +void DrawHlt1DecisionHistos(const char *folder, std::vector histos) +{ + std::filesystem::create_directory(TString::Format("output_files/analysis/%s", folder).Data()); + TString name = TString::Format("%s_canvas", "hlt1_decisions"); + TCanvas *c = new TCanvas(name, "HLT 1 Decisions", 0, 0, 1200, 700); + c->Divide(4, 2); + for (int i = 0; i < histos.size(); i++) + { + c->cd(i + 1); + histos[i]->SetStats(0); + histos[i]->Draw(); + + TLegend *leg1 = new TLegend(0.58, 0.89 - (0.05 * (Hlt1DecisionSets[i].size() + 1)), 0.88, 0.89); + leg1->SetFillColor(kWhite); + leg1->SetLineColor(kBlack); + leg1->SetMargin(0.1); + std::for_each(Hlt1DecisionSets[i].begin(), Hlt1DecisionSets[i].end(), [leg1](std::string s) + { leg1->AddEntry((TObject *)0, s.c_str(), ""); }); + leg1->AddEntry((TObject *)0, TString::Format("# Entries: %d", (int)histos[i]->GetEntries()), ""); + leg1->Draw(); + } + c->Draw(); + c->SaveAs(TString::Format("output_files/analysis/%s/%s.pdf", folder, name.Data()).Data()); } // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Bu To Hp Mu Mu %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -int analyze_bu2hpmumu() +int analyze_bu2hpmumu_data() { const char *analysis_name = "BuToHpMuMu"; const char *end_state_mass_literal = "m(#pi^{+}_{(#rightarrow K^{+})}#mu^{+}#mu^{-})"; @@ -247,6 +385,8 @@ int analyze_bu2hpmumu() } } + auto hlt1_decision_histos = CreateHlt1DecisionHistos(analysis_name); + std::map exclusive_hits{}; unsigned int entries = data_chain->GetEntries(); @@ -259,53 +399,114 @@ int analyze_bu2hpmumu() if (TMath::Abs(dimuon.M() - JPSI_MASS) < 100.) { - for (const auto &var : Hlt1Decisions) - { - if (var.value) - { - h2_Hlt1_flags_B_Mass->Fill(reconstructed_B_Mass, var.name.c_str(), 1); - } - } + CheckHlt1Decisioins(h2_Hlt1_flags_B_Mass, h2_Hlt1_flags_excl_B_Mass, exclusive_hits, reconstructed_B_Mass); + FillHlt1DecisionHistos(hlt1_decision_histos, reconstructed_B_Mass); + } - bool exclusive = true; - std::string line{}; - for (const auto &var : Hlt1Decisions) + if (CutHlt1DecisionsOr({"TwoTrackMuonMVA", "DiMuonHighMass"})) + { + if (TMath::Abs(dimuon.M() - JPSI_MASS) < 100.) { - if (var.value) - { - if (!line.empty()) - { - exclusive = false; - } - - line = var.name; - } + h1_B_Mass_jpsi->Fill(reconstructed_B_Mass); } - - if (!line.empty() && exclusive) + else if (TMath::Abs(dimuon.M() - PSI2S_MASS) < 100.) { - int &hits = exclusive_hits[line]; - if (hits) - { - hits += 1; - } - else - { - hits = 1; - } - h2_Hlt1_flags_excl_B_Mass->Fill(reconstructed_B_Mass, line.c_str(), 1); + h1_B_Mass_psi2s->Fill(reconstructed_B_Mass); } } - if (CutHlt1DecisionsOr({"TwoTrackMuonMVA", "TrackMuonMVA"})) + PrintProgress(analysis_name, entries, 10000, i); + } + + std::cout << "# Exclusive Hits" << std::endl; + for (const auto &[line, hits] : exclusive_hits) + { + std::cout << line << ": " << hits << std::endl; + } + + DrawInDefaultCanvas(h2_Hlt1_flags_B_Mass, analysis_name, 0.16, "COLZ"); + DrawInDefaultCanvas(h2_Hlt1_flags_excl_B_Mass, analysis_name, 0.16, "COLZ"); + DrawInDefaultCanvas(h1_B_Mass_jpsi, analysis_name, 0.1); + DrawInDefaultCanvas(h1_B_Mass_psi2s, analysis_name, 0.1); + + auto roofit_hist_jpsi = CreateRooFitHistogram(h1_B_Mass_jpsi); + auto roofit_hist_psi2s = CreateRooFitHistogram(h1_B_Mass_psi2s); + DrawInDefaultCanvas(roofit_hist_jpsi, analysis_name, 0.1); + DrawInDefaultCanvas(roofit_hist_psi2s, analysis_name, 0.1); + + DrawHlt1DecisionHistos(analysis_name, hlt1_decision_histos); + + return 0; +} + +int analyze_bu2hpmumu_simulation() +{ + const char *analysis_name = "BuToHpMuMu_noPID"; + const char *end_state_mass_literal = "m(#pi^{+}_{(#rightarrow K^{+})}#mu^{+}#mu^{-})"; + + TChain *sim_chain = new TChain(TString::Format("%s/DecayTree", analysis_name)); + sim_chain->Add("/auto/data/pfeiffer/inclusive_detached_dilepton/MC/rd_btoxll_simulation_fullstream_v0r0p6671378_BuToKpMuMu_12143001_magdown.root"); + + FourVect *l14v = FourVect::Init(sim_chain, "L1"); + FourVect *l24v = FourVect::Init(sim_chain, "L2"); + FourVect *hp4v = FourVect::Init(sim_chain, "Hp"); + + Int_t B_BKGCAT, L1_TRUEID, L2_TRUEID, Hp_TRUEID; + + sim_chain->SetBranchAddress("L1_TRUEID", &L1_TRUEID); + sim_chain->SetBranchAddress("L2_TRUEID", &L2_TRUEID); + sim_chain->SetBranchAddress("Hp_TRUEID", &Hp_TRUEID); + sim_chain->SetBranchAddress("B_BKGCAT", &B_BKGCAT); + + TH1D *h1_B_Mass_jpsi = new TH1D("h1_B_Mass_jpsi", TString::Format("B Mass, J/#psi Mode (%s)", analysis_name), B_MASS_HIST_BINS, B_MASS_VAR_MIN, B_MASS_VAR_MAX); + TH1D *h1_B_Mass_psi2s = new TH1D("h1_B_Mass_psi2s", TString::Format("B Mass, #psi(2S) Mode (%s)", analysis_name), B_MASS_HIST_BINS, B_MASS_VAR_MIN, B_MASS_VAR_MAX); + TH2D *h2_Hlt1_flags_B_Mass = new TH2D("h2_Hlt1_flags_B_Mass", "Hlt1 Decision vs B Mass", 50, 5100, 5400, 13, 1., 14.); + TH2D *h2_Hlt1_flags_excl_B_Mass = new TH2D("h2_Hlt1_flags_excl_B_Mass", "Excl Hlt1 Decision vs B Mass", 50, 5100, 5400, 13, 1., 14.); + + h1_B_Mass_jpsi->GetXaxis()->SetTitle(end_state_mass_literal); + h1_B_Mass_psi2s->GetXaxis()->SetTitle(end_state_mass_literal); + h2_Hlt1_flags_B_Mass->GetXaxis()->SetTitle(end_state_mass_literal); + h2_Hlt1_flags_excl_B_Mass->GetXaxis()->SetTitle(end_state_mass_literal); + + ConnectHlt1Decisions(sim_chain); + + for (const auto &var : Hlt1Decisions) + { + if (sim_chain->FindBranch(var.GetName().c_str())) + { + h2_Hlt1_flags_B_Mass->Fill(0., var.name.c_str(), 0.); + h2_Hlt1_flags_excl_B_Mass->Fill(0., var.name.c_str(), 0.); + } + } + + std::map exclusive_hits{}; + + unsigned int entries = sim_chain->GetEntries(); + for (unsigned int i = 0; i < entries; i++) + { + sim_chain->GetEntry(i); + + if (B_BKGCAT == 30 && TMath::Abs(L1_TRUEID) == PID_MUON && L2_TRUEID == -L1_TRUEID && TMath::Abs(Hp_TRUEID) == PID_KAON) { + + TLorentzVector dimuon = l14v->LorentzVector() + l24v->LorentzVector(); + Double_t reconstructed_B_Mass = (hp4v->LorentzVector(K_MASS) + dimuon).M(); + if (TMath::Abs(dimuon.M() - JPSI_MASS) < 100.) { - h1_B_Mass_jpsi->Fill(reconstructed_B_Mass); + CheckHlt1Decisioins(h2_Hlt1_flags_B_Mass, h2_Hlt1_flags_excl_B_Mass, exclusive_hits, reconstructed_B_Mass); } - else if (TMath::Abs(dimuon.M() - PSI2S_MASS) < 100.) + + if (CutHlt1DecisionsOr({"TwoTrackMuonMVA", "DiMuonHighMass"})) { - h1_B_Mass_psi2s->Fill(reconstructed_B_Mass); + if (TMath::Abs(dimuon.M() - JPSI_MASS) < 100.) + { + h1_B_Mass_jpsi->Fill(reconstructed_B_Mass); + } + else if (TMath::Abs(dimuon.M() - PSI2S_MASS) < 100.) + { + h1_B_Mass_psi2s->Fill(reconstructed_B_Mass); + } } } @@ -386,12 +587,12 @@ int analyze_b02hphmmumu() if (Hp_PID_K > 0 && Hm_PID_K < 0) { + continue; lv_hp = hp4v->LorentzVector(K_MASS); lv_hm = hm4v->LorentzVector(); } else if (Hp_PID_K < 0 && Hm_PID_K > 0) { - continue; lv_hp = hp4v->LorentzVector(); lv_hm = hm4v->LorentzVector(K_MASS); } @@ -405,45 +606,10 @@ int analyze_b02hphmmumu() if (TMath::Abs(dimuon.M() - JPSI_MASS) < 100.) { - for (const auto &var : Hlt1Decisions) - { - if (var.value) - { - h2_Hlt1_flags_B_Mass->Fill(reconstructed_B_Mass, var.name.c_str(), 1); - } - } - - bool exclusive = true; - std::string line{}; - for (const auto &var : Hlt1Decisions) - { - if (var.value) - { - if (!line.empty()) - { - exclusive = false; - } - - line = var.name; - } - } - - if (!line.empty() && exclusive) - { - int &hits = exclusive_hits[line]; - if (hits) - { - hits += 1; - } - else - { - hits = 1; - } - h2_Hlt1_flags_excl_B_Mass->Fill(reconstructed_B_Mass, line.c_str(), 1); - } + CheckHlt1Decisioins(h2_Hlt1_flags_B_Mass, h2_Hlt1_flags_excl_B_Mass, exclusive_hits, reconstructed_B_Mass); } - if (CutHlt1DecisionsOr({"TwoTrackMuonMVA", "TrackMuonMVA"})) + if (CutHlt1DecisionsOr({"TwoTrackMuonMVA", "DiMuonHighMass"})) { if (TMath::Abs(reconstructed_Kstar_Mass - KSTAR_MASS) < 50.) { @@ -467,8 +633,6 @@ int analyze_b02hphmmumu() std::cout << line << ": " << hits << std::endl; } - - DrawInDefaultCanvas(h2_Hlt1_flags_B_Mass, analysis_name, 0.16, "COLZ"); DrawInDefaultCanvas(h2_Hlt1_flags_excl_B_Mass, analysis_name, 0.16, "COLZ"); DrawInDefaultCanvas(h1_B_Mass_jpsi, analysis_name, 0.1); @@ -529,45 +693,10 @@ int analyze_Hlt2RD_BuToKpMuMu() if (TMath::Abs(dimuon.M() - JPSI_MASS) < 100.) { - for (const auto &var : Hlt1Decisions) - { - if (var.value) - { - h2_Hlt1_flags_B_Mass->Fill(reconstructed_B_Mass, var.name.c_str(), 1); - } - } - - bool exclusive = true; - std::string line{}; - for (const auto &var : Hlt1Decisions) - { - if (var.value) - { - if (!line.empty()) - { - exclusive = false; - } - - line = var.name; - } - } - - if (!line.empty() && exclusive) - { - int &hits = exclusive_hits[line]; - if (hits) - { - hits += 1; - } - else - { - hits = 1; - } - h2_Hlt1_flags_excl_B_Mass->Fill(reconstructed_B_Mass, line.c_str(), 1); - } + CheckHlt1Decisioins(h2_Hlt1_flags_B_Mass, h2_Hlt1_flags_excl_B_Mass, exclusive_hits, reconstructed_B_Mass); } - if (CutHlt1DecisionsOr({"TwoTrackMuonMVA", "TrackMuonMVA"})) + if (CutHlt1DecisionsOr({"TwoTrackMuonMVA", "DiMuonHighMass"})) { if (TMath::Abs(dimuon.M() - JPSI_MASS) < 100.) { @@ -651,45 +780,10 @@ int analyze_Hlt2RD_B0ToKpPimMuMu() if (TMath::Abs(dimuon.M() - JPSI_MASS) < 100.) { - for (const auto &var : Hlt1Decisions) - { - if (var.value) - { - h2_Hlt1_flags_B_Mass->Fill(reconstructed_B_Mass, var.name.c_str(), 1); - } - } - - bool exclusive = true; - std::string line{}; - for (const auto &var : Hlt1Decisions) - { - if (var.value) - { - if (!line.empty()) - { - exclusive = false; - } - - line = var.name; - } - } - - if (!line.empty() && exclusive) - { - int &hits = exclusive_hits[line]; - if (hits) - { - hits += 1; - } - else - { - hits = 1; - } - h2_Hlt1_flags_excl_B_Mass->Fill(reconstructed_B_Mass, line.c_str(), 1); - } + CheckHlt1Decisioins(h2_Hlt1_flags_B_Mass, h2_Hlt1_flags_excl_B_Mass, exclusive_hits, reconstructed_B_Mass); } - if (CutHlt1DecisionsOr({"TwoTrackMuonMVA", "TrackMuonMVA"})) + if (CutHlt1DecisionsOr({"TwoTrackMuonMVA", "DiMuonHighMass"})) { if (TMath::Abs(reconstructed_Kstar_Mass - KSTAR_MASS) < 50.) { @@ -728,5 +822,5 @@ int analyze_Hlt2RD_B0ToKpPimMuMu() int new_analysis() { - return analyze_Hlt2RD_B0ToKpPimMuMu(); + return analyze_bu2hpmumu_data(); } \ No newline at end of file