diff --git a/old_analysis_macros/analysis_fullstream_b02hphmmumu.cpp b/analysis_fullstream_b02hphmmumu.cpp similarity index 77% rename from old_analysis_macros/analysis_fullstream_b02hphmmumu.cpp rename to analysis_fullstream_b02hphmmumu.cpp index c269fd8..b51e6d5 100644 --- a/old_analysis_macros/analysis_fullstream_b02hphmmumu.cpp +++ b/analysis_fullstream_b02hphmmumu.cpp @@ -40,13 +40,16 @@ 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^{+}, w/o excl Hlt2 decision cut)"; -const char* FILE_NAME = "SpruceRD_B0ToHpHmMuMu_Pip2Kp_wohlt2cut"; -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_Pip2Kp"; +const char *MASS_LITERAL = "m(#pi^{+}#pi^{-}_{(#rightarrow K^{-})}#mu^{+}#mu^{-})"; const Double_t K_MASS = 493.677; +const Double_t PSI2S_MASS = 3686.093; +const Double_t JPSI_MASS = 3096.9; +const Double_t KSTAR_MASS = 891.76; -void CreateRooFitAndDraw(TH1D *hist, int fitting_entries); +void CreateRooFitAndDraw(TH1D *hist); int analysis_fullstream_b02hphmmumu() { @@ -127,7 +130,6 @@ int analysis_fullstream_b02hphmmumu() data_chain->SetBranchAddress("Res_MAXDOCACHI2", &Res_MAXDOCACHI2); data_chain->SetBranchAddress("Res_M", &Res_M); - data_chain->SetBranchAddress("Jpsi_BPVFDCHI2", &Jpsi_BPVFDCHI2); data_chain->SetBranchAddress("Jpsi_M", &Jpsi_M); @@ -138,12 +140,13 @@ int analysis_fullstream_b02hphmmumu() data_chain->SetBranchAddress("Hlt1TrackMVADecision", &Hlt1TrackMVADecision); data_chain->SetBranchAddress("Hlt1TwoTrackMVADecision", &Hlt1TwoTrackMVADecision); - Float_t - L1_PX, L1_PY, L1_PZ, L1_ENERGY, - L2_PX, L2_PY, L2_PZ, L2_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, Hm_PX, Hm_PY, Hm_PZ, Hm_ENERGY; - + data_chain->SetBranchAddress("L1_PX", &L1_PX); data_chain->SetBranchAddress("L1_PY", &L1_PY); data_chain->SetBranchAddress("L1_PZ", &L1_PZ); @@ -162,6 +165,9 @@ int analysis_fullstream_b02hphmmumu() data_chain->SetBranchAddress("Hm_ENERGY", &Hm_ENERGY); TH1D *h1_B0_M = new TH1D("h1_B0_M", TITLE, nBins, MASS_HIST_MIN, MASS_HIST_MAX); + TH1D *h1_Res_M = new TH1D("h1_Res_M", "K^{*0} Mass", nBins, 0., 3500.); + TH1D *h1_Hm_PID_K = new TH1D("h1_Hm_PID_K", "H^{-} PID K", nBins, -10., 10.); + TH1D *h1_Hp_PID_K = new TH1D("h1_Hp_PID_K", "H^{+} PID K", nBins, -10., 10.); unsigned int entries = data_chain->GetEntries(); unsigned int fitting_entries = 0; @@ -173,19 +179,25 @@ 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 Kp_momentum(Hp_PX, Hp_PY, Hp_PZ); + double Kp_energy = TMath::Sqrt(TMath::Sq(K_MASS) + Kp_momentum.Mag2()); + TLorentzVector Pim_4v(Hm_PX, Hm_PY, Hm_PZ, Hm_ENERGY); + TLorentzVector Kp_4v(Kp_momentum, Kp_energy); + Double_t reconstructed_Kp_Pim_Mass = (Kp_4v + Pim_4v).M(); + Double_t reconstructed_B0_Kp_Pim_Mass = (Kp_4v + Pim_4v + l1_4v + l2_4v).M(); // 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 Km_momentum(Hm_PX, Hm_PY, Hm_PZ); + double Km_energy = TMath::Sqrt(TMath::Sq(K_MASS) + Km_momentum.Mag2()); + TLorentzVector Pip_4v(Hp_PX, Hp_PY, Hp_PZ, Hp_ENERGY); + TLorentzVector Km_4v(Km_momentum, Km_energy); + Double_t reconstructed_Km_Pip_Mass = (Km_4v + Pip_4v).M(); + Double_t reconstructed_B0_Km_Pip_Mass = (Km_4v + Pip_4v + l1_4v + l2_4v).M(); + + h1_Res_M->Fill(reconstructed_Kp_Pim_Mass); - TLorentzVector K_4v(K_momentum, K_energy); - - Double_t reconstructed_Res_Mass = (K_4v + Pi_4v).M(); - Double_t reconstructed_B0_Mass = (K_4v + Pi_4v + l1_4v + l2_4v).M(); + h1_Hm_PID_K->Fill(Hm_PID_K); + h1_Hp_PID_K->Fill(Hp_PID_K); if (( (B0_BPVFDCHI2 > 64) & (B0_CHI2VXNDOF < 9) & (B0_BPVIPCHI2 < 25) & @@ -196,31 +208,26 @@ int analysis_fullstream_b02hphmmumu() // (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) & + (Res_PT > 400) & (Res_MAXDOCACHI2 < 36) & (reconstructed_Kp_Pim_Mass < 2600) & (reconstructed_Km_Pip_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))) + (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 - JPSI_MASS) < 100) & ((Hlt1TrackMVADecision) | (Hlt1TwoTrackMVADecision))) { - h1_B0_M->Fill(reconstructed_B0_Mass); - - if (MASS_HIST_FIT_MIN <= reconstructed_B0_Mass && reconstructed_B0_Mass <= MASS_HIST_FIT_MAX) - { - fitting_entries++; - } + h1_B0_M->Fill(reconstructed_B0_Km_Pip_Mass); } } - if (i % 10000 == 0) + if ((i + 1) % 10000 == 0 || i + 1 == entries) { std::cout << "[" << FILE_NAME - << "] Processed event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 100.) << "%)" << std::endl; + << "] Processed event: " << i + 1 << " (" << TString::Format("%.2f", ((double)(i + 1) / (double)entries) * 100.) << "%)" << std::endl; } } @@ -231,12 +238,29 @@ int analysis_fullstream_b02hphmmumu() c1->Draw(); c1->SaveAs(TString::Format("images/root_hist_%s_bmass.pdf", FILE_NAME).Data()); - CreateRooFitAndDraw(h1_B0_M, fitting_entries); + TCanvas *c2 = new TCanvas("c2", "c2", 0, 0, 800, 600); + h1_Res_M->Draw(); + c2->Draw(); + + TCanvas *c3 = new TCanvas("c3", "c3", 0, 0, 800, 600); + + h1_Hm_PID_K->SetStats(0); + h1_Hm_PID_K->SetLineColor(kRed); + + h1_Hp_PID_K->SetStats(0); + + h1_Hm_PID_K->Draw(); + h1_Hp_PID_K->Draw("SAME"); + + c3->BuildLegend(); + c3->Draw(); + + CreateRooFitAndDraw(h1_B0_M); return 0; } -void CreateRooFitAndDraw(TH1D *hist, int fitting_entries) +void CreateRooFitAndDraw(TH1D *hist) { RooRealVar roo_var_mass("var_mass", "B0 Mass Variable", MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX); roo_var_mass.setRange("fitting_range", MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX); @@ -279,8 +303,8 @@ void CreateRooFitAndDraw(TH1D *hist, int fitting_entries) sigplusbkg.plotOn(roo_frame_mass, RooFit::VisualizeError(*fitres, 1), RooFit::FillColor(kOrange + 1), 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")); + 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); @@ -300,7 +324,7 @@ void CreateRooFitAndDraw(TH1D *hist, int fitting_entries) 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->AddEntry((TObject *)0, TString::Format("Entries: %.1f", var_mass_nsig.getVal() + var_mass_nbkg.getVal()), ""); leg1->Draw(); diff --git a/old_analysis_macros/analysis_fullstream_bu2hpmumu.cpp b/analysis_fullstream_bu2hpmumu.cpp similarity index 52% rename from old_analysis_macros/analysis_fullstream_bu2hpmumu.cpp rename to analysis_fullstream_bu2hpmumu.cpp index a460fa4..748004d 100644 --- a/old_analysis_macros/analysis_fullstream_bu2hpmumu.cpp +++ b/analysis_fullstream_bu2hpmumu.cpp @@ -40,13 +40,76 @@ const Double_t MASS_HIST_FIT_MIN = 5100.; const Double_t MASS_HIST_FIT_MAX = 6000.; const Double_t K_MASS = 493.677; +const Double_t PSI2S_MASS = 3686.093; +const Double_t JPSI_MASS = 3096.900; +const Double_t KSTAR_MASS = 891.760; -void CreateRooFitAndDraw(TH1D *hist, int fitting_entries); +void CreateRooFitAndDraw(TH1D *hist, const char *name); const char *TITLE = "SpruceRD_BuToHpMuMu (#pi^{+} #rightarrow K^{+}, w/o excl Hlt2 decision cut)"; const char *FILE_NAME = "SpruceRD_BuToHpMuMu_Pip2Kp_wohlt2cut"; const char *MASS_LITERAL = "m(#pi^{+}_{(#rightarrow K^{+})}#mu^{+}#mu^{-})"; +struct Hlt1Decision +{ + std::string name; + int index; + int flag; + Bool_t value; + + std::string GetName() const + { + return TString::Format("Hlt1%sDecision", name.c_str()).Data(); + } + + Bool_t *GetValuePointer() + { + return &value; + } +}; + +const int FLAG_TrackMVA = 0b0000100000000000; +const int FLAG_TwoTrackMVA = 0b0001000000000000; +std::vector Hlt1Decisions{ + Hlt1Decision{"DiMuonHighMass", 1, 0b0000000000000001}, // 0001 + Hlt1Decision{"DiMuonLowMass", 2, 0b0000000000000010}, // 0002 + Hlt1Decision{"DiMuonNoIP", 3, 0b0000000000000100}, // 0004 + Hlt1Decision{"DiMuonSoft", 4, 0b0000000000001000}, // 0008 + Hlt1Decision{"DisplacedLeptons", 5, 0b0000000000010000}, // 0016 + Hlt1Decision{"LowPtDiMuon", 6, 0b0000000000100000}, // 0032 + Hlt1Decision{"LowPtMuon", 7, 0b0000000001000000}, // 0064 + Hlt1Decision{"OneMuonTrackLine", 8, 0b0000000010000000}, // 0128 + Hlt1Decision{"SingleHighEt", 9, 0b0000000100000000}, // 0256 + Hlt1Decision{"SingleHighPtMuon", 10, 0b0000001000000000}, // 0512 + Hlt1Decision{"TrackMVA", 11, FLAG_TrackMVA}, // 1024 + Hlt1Decision{"TrackMuonMVA", 12, 0b0000100000000000}, // 2048 + Hlt1Decision{"TwoTrackMVA", 13, FLAG_TwoTrackMVA}, // 4096 +}; +// 0b0001000000000000 +// 0b0001000000110111 + +void ConnectHlt1Decisions(TChain *chain) +{ + for (auto &var : Hlt1Decisions) + { + chain->SetBranchAddress(var.GetName().c_str(), var.GetValuePointer()); + } +} + +int CombineHlt1DecisionFlags() +{ + int result = 0; + for (const auto &var : Hlt1Decisions) + { + if (var.value) + { + result = result | var.flag; + } + } + + return result; +} + int analysis_fullstream_bu2hpmumu() { TChain *data_chain = new TChain("BuToHpMuMu/DecayTree"); @@ -113,8 +176,8 @@ int analysis_fullstream_bu2hpmumu() data_chain->SetBranchAddress("Hlt2_InclDetDiMuon_4BodyDecision", &Hlt2_InclDetDiMuon_4BodyDecision); data_chain->SetBranchAddress("Hlt2_InclDetDiMuon_3BodyDecision", &Hlt2_InclDetDiMuon_3BodyDecision); data_chain->SetBranchAddress("Hlt2_InclDetDiMuonDecision", &Hlt2_InclDetDiMuonDecision); - data_chain->SetBranchAddress("Hlt1TrackMVADecision", &Hlt1TrackMVADecision); - data_chain->SetBranchAddress("Hlt1TwoTrackMVADecision", &Hlt1TwoTrackMVADecision); + // data_chain->SetBranchAddress("Hlt1TrackMVADecision", &Hlt1TrackMVADecision); + // data_chain->SetBranchAddress("Hlt1TwoTrackMVADecision", &Hlt1TwoTrackMVADecision); 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; data_chain->SetBranchAddress("L1_PX", &L1_PX); @@ -130,7 +193,17 @@ int analysis_fullstream_bu2hpmumu() data_chain->SetBranchAddress("Hp_PZ", &Hp_PZ); data_chain->SetBranchAddress("Hp_ENERGY", &Hp_ENERGY); - TH1D *h1_B_M = new TH1D("h1_B_M", "B Mass", nBins, MASS_HIST_MIN, MASS_HIST_MAX); + ConnectHlt1Decisions(data_chain); + + TH1D *h1_B_M_jpsi = new TH1D("h1_B_M_jpsi", "B Mass, J/#psi Mode", nBins, MASS_HIST_MIN, MASS_HIST_MAX); + TH1D *h1_B_M_psi2s = new TH1D("h1_B_M_psi2s", "B Mass, #psi(2S) Mode", nBins, MASS_HIST_MIN, MASS_HIST_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.); + h2_Hlt1_flags_B_Mass->SetCanExtend(TH1::kYaxis); + + for (const auto &var : Hlt1Decisions) + { + h2_Hlt1_flags_B_Mass->Fill(0., var.name.c_str(), 0.); + } unsigned int entries = data_chain->GetEntries(); unsigned int fitting_entries = 0; @@ -145,51 +218,97 @@ int analysis_fullstream_bu2hpmumu() TLorentzVector l2_4v(L2_PX, L2_PY, L2_PZ, L2_ENERGY); Double_t reconstructed_B_Mass = (K_4v + l1_4v + l2_4v).M(); - if ((((B_BPVFDCHI2 > 36) & (B_CHI2VXNDOF < 16) & (B_BPVIPCHI2 < 25) & (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) & (Jpsi_CHI2DOF < 9) & (Jpsi_BPVFDCHI2 > 16) & (Jpsi_M < 5500) & (Hp_PT > 400) & (Hp_BPVIPCHI2 > 6) & (Hp_PT > 400) & (Hp_BPVIPCHI2 > 6) & (Hp_P > 2000) & (Hp_PID_K > -4)) /*& (Hlt2RD_BuToKpMuMuDecision == 1)*/ & (((Hlt2_InclDetDiMuon_4BodyDecision == 1) | (Hlt2_InclDetDiMuon_3BodyDecision == 1) | (Hlt2_InclDetDiMuonDecision == 1))))) + int combinedFlags = CombineHlt1DecisionFlags(); + bool trackMVADec = (((combinedFlags & FLAG_TrackMVA) == FLAG_TrackMVA) | ((combinedFlags & FLAG_TwoTrackMVA) == FLAG_TwoTrackMVA)); + if (TMath::Abs(Jpsi_M - JPSI_MASS) < 100 && trackMVADec) { - if ((TMath::Abs(Jpsi_M - 3096.9) < 100) & ((Hlt1TrackMVADecision == 1) | (Hlt1TwoTrackMVADecision == 1))) + for (const auto &var : Hlt1Decisions) { - h1_B_M->Fill(reconstructed_B_Mass); - - if (MASS_HIST_FIT_MIN <= reconstructed_B_Mass && reconstructed_B_Mass <= MASS_HIST_FIT_MAX) + if (var.value) { - fitting_entries++; + h2_Hlt1_flags_B_Mass->Fill(reconstructed_B_Mass, var.name.c_str(), 1); } } } + // std::cout << "HLT1 Decision Flags: " << combinedFlags << std::endl; + + if (trackMVADec) + { + if (TMath::Abs(Jpsi_M - JPSI_MASS) < 100) + { + h1_B_M_jpsi->Fill(reconstructed_B_Mass); + } + else if (TMath::Abs(Jpsi_M - PSI2S_MASS) < 100) + { + h1_B_M_psi2s->Fill(reconstructed_B_Mass); + } + } + + // if ((((B_BPVFDCHI2 > 36) & (B_CHI2VXNDOF < 16) & (B_BPVIPCHI2 < 25) & (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) & (Jpsi_CHI2DOF < 9) & (Jpsi_BPVFDCHI2 > 16) & (Jpsi_M < 5500) & (Hp_PT > 400) & (Hp_BPVIPCHI2 > 6) & (Hp_PT > 400) & (Hp_BPVIPCHI2 > 6) & (Hp_P > 2000) & (Hp_PID_K > -4)) /*& (Hlt2RD_BuToKpMuMuDecision == 1)*/ & (((Hlt2_InclDetDiMuon_4BodyDecision == 1) | (Hlt2_InclDetDiMuon_3BodyDecision == 1) | (Hlt2_InclDetDiMuonDecision == 1))))) + // { + // if ((TMath::Abs(Jpsi_M - 3096.9) < 100) & ((Hlt1TrackMVADecision == 1) | (Hlt1TwoTrackMVADecision == 1))) + // { + // h1_B_M->Fill(reconstructed_B_Mass); - if (i % 10000 == 0) + // if (MASS_HIST_FIT_MIN <= reconstructed_B_Mass && reconstructed_B_Mass <= MASS_HIST_FIT_MAX) + // { + // fitting_entries++; + // } + // } + // } + + if ((i + 1) % 10000 == 0 || i + 1 == entries) { std::cout << "[" << FILE_NAME - << "] Processed event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 100.) << "%)" << std::endl; + << "] Processed event: " << i + 1 << " (" << TString::Format("%.2f", ((double)(i + 1) / (double)entries) * 100.) << "%)" << std::endl; } } TCanvas *c1 = new TCanvas("c1", "c1", 0, 0, 800, 600); - h1_B_M->Draw(); + h1_B_M_jpsi->Draw(); c1->Draw(); - c1->SaveAs(TString::Format("images/root_hist_%s_bmass.pdf", FILE_NAME).Data()); + c1->SaveAs(TString::Format("images/root_hist_%s_%s_bmass.pdf", FILE_NAME, "jpsi").Data()); + + TCanvas *c2 = new TCanvas("c2", "c2", 0, 0, 800, 600); + h1_B_M_psi2s->Draw(); + c2->Draw(); + c2->SaveAs(TString::Format("images/root_hist_%s_%s_bmass.pdf", FILE_NAME, "psi2s").Data()); + + TCanvas *c3 = new TCanvas("c3", "c3", 0, 0, 800, 600); + c3->SetLeftMargin(0.20); + h2_Hlt1_flags_B_Mass->SetStats(0); + h2_Hlt1_flags_B_Mass->Draw("COLZ"); + c3->Draw(); - CreateRooFitAndDraw(h1_B_M, fitting_entries); + // CreateRooFitAndDraw(h1_B_M_jpsi, "jpsi"); + // CreateRooFitAndDraw(h1_B_M_psi2s, "psi2s"); return 0; } -void CreateRooFitAndDraw(TH1D *hist, int fitting_entries) +void CreateRooFitAndDraw(TH1D *hist, const char *name) { - RooRealVar roo_var_mass("var_mass", "B Mass Variable", MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX); + auto suffix = [name](const char *text) + { + return TString::Format("%s_%s", text, name); + }; + + std::cout << " ###### " << suffix("AABB") << std::endl; + + RooRealVar roo_var_mass(suffix("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)); + TString hist_name = suffix("roohist_B_M"); + RooDataHist roohist_B_M(hist_name, "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")); + roohist_B_M.plotOn(roo_frame_mass, RooFit::Binning(nBins), RooFit::Name(hist_name)); roo_frame_mass->GetXaxis()->SetTitle(MASS_LITERAL); // 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.); + RooRealVar var_mass_x0(suffix("var_mass_x0"), "#mu", 5278., 5170., 5500.); + RooRealVar var_mass_sigmaLR(suffix("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.); @@ -203,34 +322,48 @@ void CreateRooFitAndDraw(TH1D *hist, int fitting_entries) auto var_mass_alphaR = RooRealConstant::value(2.446); auto var_mass_nR = RooRealConstant::value(1.146); - 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); + RooCrystalBall sig_cb(suffix("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_bkg_c(suffix("var_mass_bkg_c"), "#lambda", -0.0014, -0.004, -0.000); + RooExponential bkg_exp(suffix("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()); + RooRealVar var_mass_nsig(suffix("nsig"), "Mass N Signal", 0., hist->GetEntries()); + RooRealVar var_mass_nbkg(suffix("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)); + TString pdf_name = suffix("sigplusbkg"); + RooAddPdf sigplusbkg(pdf_name, "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(kOrange + 1), 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::LineColor(kRed), RooFit::LineStyle(kSolid), RooFit::Range("fitting_range"), RooFit::Name(pdf_name)); 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); + RooPlot *roo_frame_pull = roo_var_mass.frame(RooFit::Title("Pull Distribution")); + roo_frame_pull->addPlotable(roo_frame_mass->pullHist(hist_name, pdf_name), "P"); + + TCanvas *c = new TCanvas(suffix("roofit_c"), "roofit_c", 0, 0, 800, 600); + + auto *p2 = new TPad(suffix("p2"), "Pull", 0., 0., 1., 0.3); + p2->Draw(); + p2->SetTopMargin(0.001); + p2->SetBottomMargin(0.3); + p2->SetGrid(); + + auto *p1 = new TPad(suffix("p1"), "Fit", 0., 0.32, 1., 1.); + p1->Draw(); + p1->SetBottomMargin(0.001); + p1->cd(); roo_frame_mass->Draw(); - TLegend *leg1 = new TLegend(0.50, 0.58, 0.87, 0.89); + TLegend *leg1 = new TLegend(0.50, 0.50, 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(pdf_name), "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, "", ""); @@ -240,10 +373,14 @@ void CreateRooFitAndDraw(TH1D *hist, int fitting_entries) 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->AddEntry((TObject *)0, TString::Format("Entries: %.1f", var_mass_nsig.getVal() + var_mass_nbkg.getVal()), ""); leg1->Draw(); + p2->cd(); + + roo_frame_pull->Draw(); + c->Draw(); - c->SaveAs(TString::Format("images/data/roofit_hist_%s_bmass.pdf", FILE_NAME).Data()); + c->SaveAs(TString::Format("images/data/roofit_hist_%s_bmass.pdf", suffix(FILE_NAME).Data()).Data()); } \ No newline at end of file diff --git a/old_analysis_macros/analysis_turbo.cpp b/analysis_turbo.cpp similarity index 75% rename from old_analysis_macros/analysis_turbo.cpp rename to analysis_turbo.cpp index 72179dc..0afbf56 100644 --- a/old_analysis_macros/analysis_turbo.cpp +++ b/analysis_turbo.cpp @@ -37,11 +37,11 @@ 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 *B0_DECAY = "Hlt2RD_B0ToKpPimMuMu"; +const char *Bu_DECAY = "Hlt2RD_BuToKpMuMu"; -const char *TITLE = Bu_DECAY; -const char *HIST_TITLE = "Hlt2RD_BuToKpMuMu w/o Hlt1 Decision Cut"; +const char *TITLE = B0_DECAY; +const char *HIST_TITLE = "Hlt2RD_BuToKpMuMu"; const char *X_AXIS = "m(K^{+}#mu^{+}#mu^{-})"; void CreateRooFitAndDraw(TH1D *hist, int fitting_entries); @@ -67,19 +67,17 @@ int analysis_turbo() 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); } + 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); @@ -91,7 +89,7 @@ int analysis_turbo() 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))*/) + 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) @@ -102,7 +100,7 @@ int analysis_turbo() } else { - if ((TMath::Abs(Jpsi_M - 3096.9) < 100.) && (B_M > 4500.) && (B_M < 6000.) /*&& ((Hlt1TrackMVADecision) || (Hlt1TwoTrackMVADecision))*/) + 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) @@ -112,18 +110,14 @@ int analysis_turbo() } } - if (i % 10000 == 0) + if ((i + 1) % 10000 == 0 || i + 1 == entries) { std::cout << "[" << TITLE - << "] Processed event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 100.) << "%)" << std::endl; + << "] Processed event: " << i + 1 << " (" << TString::Format("%.2f", ((double)(i + 1) / (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(); @@ -182,10 +176,10 @@ void CreateRooFitAndDraw(TH1D *hist, int fitting_entries) 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")); + // 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); @@ -195,10 +189,10 @@ void CreateRooFitAndDraw(TH1D *hist, int fitting_entries) 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(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(), ""); diff --git a/old_analysis_macros/simulation.cpp b/simulation.cpp similarity index 71% rename from old_analysis_macros/simulation.cpp rename to simulation.cpp index 2166ddb..d03e5d7 100644 --- a/old_analysis_macros/simulation.cpp +++ b/simulation.cpp @@ -40,24 +40,28 @@ const Double_t MASS_HIST_MAX = 6000.; const Double_t K_MASS = 493.677; -const char *NAME = "B0ToKpPimMuMu_Trubo"; -const char *X_AXIS = "m(K^{+}#pi^{-}#mu^{+}#mu^{-})"; -const bool USE_HYP_REPLACE = false; -const char *B_NAME = "B0"; +const int PID_KAON = 321; +const int PID_PION = 211; +const int PID_MUON = 13; + +const char *NAME = "BuToKpMuMu"; +const char *X_AXIS = "m(K^{+}#mu^{+}#mu^{-})";//"m(K^{+}#pi^{-}#mu^{+}#mu^{-})"; +const char *B_NAME = "B"; +const bool HAS_PI = false; TString quickformat_name(const char *format) { return TString::Format(format, NAME); }; -void CreateRooFitAndDraw(TH1D *hist); +void CreateRooFitAndDraw(TH1D *hist, double selected_entries, double total_entries); int simulation() { - TChain *data_chain = new TChain("B0ToKpPimMuMu_noPID/DecayTree"); + TChain *data_chain = new TChain(TString::Format("%s_noPID/DecayTree", NAME)); // data_chain->Add("/auto/data/pfeiffer/inclusive_detached_dilepton/MC/rd_btoxll_simulation_fullstream_v0r0p6671378_BuToKpMuMu_12143001_magdown.root"); - // data_chain->Add("/auto/data/pfeiffer/inclusive_detached_dilepton/MC/rd_btoxll_simulation_turbo_v0r0p6657752_BuToKpMuMu_12143001_magdown.root"); - data_chain->Add("/auto/data/pfeiffer/inclusive_detached_dilepton/MC/rd_btoxll_simulation_turbo_v0r0p6657752_B0ToKpPimMuMu_11144002_magdown.root"); + data_chain->Add("/auto/data/pfeiffer/inclusive_detached_dilepton/MC/rd_btoxll_simulation_turbo_v0r0p6657752_BuToKpMuMu_12143001_magdown.root"); + // data_chain->Add("/auto/data/pfeiffer/inclusive_detached_dilepton/MC/rd_btoxll_simulation_turbo_v0r0p6657752_B0ToKpPimMuMu_11144002_magdown.root"); /* rd_btoxll_simulation_fullstream_v0r0p6671378_B0ToKpPimMuMu_11144002_magdown.root @@ -69,39 +73,18 @@ 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; Double_t B_M; - Int_t L1_TRUEID, L2_TRUEID, Hp_TRUEID, Hm_TRUEID; + Int_t L1_TRUEID, L2_TRUEID, K_TRUEID, Pi_TRUEID; data_chain->SetBranchAddress("L1_TRUEID", &L1_TRUEID); data_chain->SetBranchAddress("L2_TRUEID", &L2_TRUEID); - - if (USE_HYP_REPLACE) - { - data_chain->SetBranchAddress("L1_PX", &L1_PX); - data_chain->SetBranchAddress("L1_PY", &L1_PY); - data_chain->SetBranchAddress("L1_PZ", &L1_PZ); - data_chain->SetBranchAddress("L1_ENERGY", &L1_ENERGY); - data_chain->SetBranchAddress("L2_PX", &L2_PX); - data_chain->SetBranchAddress("L2_PY", &L2_PY); - data_chain->SetBranchAddress("L2_PZ", &L2_PZ); - data_chain->SetBranchAddress("L2_ENERGY", &L2_ENERGY); - data_chain->SetBranchAddress("Hp_PX", &Hp_PX); - data_chain->SetBranchAddress("Hp_PY", &Hp_PY); - data_chain->SetBranchAddress("Hp_PZ", &Hp_PZ); - data_chain->SetBranchAddress("Hp_ENERGY", &Hp_ENERGY); - - data_chain->SetBranchAddress("Hp_TRUEID", &Hp_TRUEID); - } - else + data_chain->SetBranchAddress(TString::Format("%s_M", B_NAME).Data(), &B_M); + data_chain->SetBranchAddress("K_TRUEID", &K_TRUEID); + if (HAS_PI) { - data_chain->SetBranchAddress(TString::Format("%s_M", B_NAME).Data(), &B_M); - data_chain->SetBranchAddress("K_TRUEID", &Hp_TRUEID); - // data_chain->SetBranchAddress("Pi_TRUEID", &Hm_TRUEID); + data_chain->SetBranchAddress("Pi_TRUEID", &Pi_TRUEID); } TH1D *h1_B_M = new TH1D("h1_B_M", "B Mass", nBins, MASS_HIST_MIN, MASS_HIST_MAX); @@ -113,50 +96,36 @@ int simulation() h1_B_M_trueid->GetXaxis()->SetTitle(X_AXIS); unsigned int entries = data_chain->GetEntries(); + unsigned int selected_entries = 0; for (size_t i = 0; i < entries; i++) { data_chain->GetEntry(i); - // std::cout << B_BKGCAT << std::endl; - - Double_t reconstructed_B_Mass = 0; - - 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); - reconstructed_B_Mass = (K_4v + l1_4v + l2_4v).M(); - } - else - { - reconstructed_B_Mass = B_M; - } - - // std::cout << "L1: " << L1_TRUEID << ", L2: " << L2_TRUEID << ", Hp: " << Hp_TRUEID << std::endl; - if (TMath::Abs(L1_TRUEID) == 13 && L2_TRUEID == -L1_TRUEID && TMath::Abs(Hp_TRUEID) == 321/* && TMath::Abs(Hm_TRUEID) == 211*/) + if (B_BKGCAT == 0 && TMath::Abs(L1_TRUEID) == 13 && L2_TRUEID == -L1_TRUEID) { - // std::cout << "Mass: " << reconstructed_B_Mass << std::endl; - h1_B_M_trueid->Fill(reconstructed_B_Mass); + if (((HAS_PI) && (TMath::Abs(K_TRUEID) == PID_KAON) && (TMath::Abs(Pi_TRUEID) == PID_PION)) || ((!HAS_PI) && (TMath::Abs(K_TRUEID) == PID_KAON))) + { + h1_B_M_trueid->Fill(B_M); + selected_entries++; + } } - h1_B_M->Fill(reconstructed_B_Mass); + h1_B_M->Fill(B_M); h1_B_BKGCAT->Fill(B_BKGCAT); - h2_B_M_vs_B_BKGCAT->Fill(reconstructed_B_Mass, B_BKGCAT); + h2_B_M_vs_B_BKGCAT->Fill(B_M, B_BKGCAT); if (i % 10000 == 0) { std::cout << "[" << NAME - << "] Processed event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 100.) << "%)" << std::endl; + << "] Processed event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 100.) << "%), " + << "Current Efficiency: " << TString::Format("%.2f%%", ((double)selected_entries / (double)entries) * 100.) + << std::endl; } } std::cout << "[" - << NAME - << "] Processed event: " << entries << " (" << TString::Format("%.2f", 100.) << "%)" << std::endl; + << NAME + << "] Processed event: " << entries << " (" << TString::Format("%.2f", 100.) << "%)" << std::endl; h1_B_M->SetLineColor(kBlue); h1_B_M_trueid->SetLineColor(kMagenta + 2); @@ -167,7 +136,7 @@ int simulation() h1_B_BKGCAT->SetFillColor(kBlue); h1_B_BKGCAT->SetFillStyle(3351); - std::filesystem::create_directory(TString::Format("images/sim/%s", NAME).Data()); + std::filesystem::create_directory(TString::Format("images/sim/%s_Turbo", NAME).Data()); TCanvas *c1 = new TCanvas("c1", "c1", 0, 0, 800, 600); h1_B_M->SetStats(0); @@ -191,13 +160,17 @@ int simulation() c3->Draw(); c3->SaveAs(quickformat_name("images/sim/%s/h2_B_M_vs_B_BKGCAT.pdf")); - CreateRooFitAndDraw(h1_B_M_trueid); + CreateRooFitAndDraw(h1_B_M_trueid, selected_entries, entries); return 0; } -void CreateRooFitAndDraw(TH1D *hist) +void CreateRooFitAndDraw(TH1D *hist, double selected_entries, double total_entries) { + if (hist->GetEntries() == 0) { + std::cout << "### Histogram for RooFit has not entries." << std::endl; + return; + } // std::cout << "### Entries: " << hist->GetEntries() << std::endl; 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); @@ -245,9 +218,9 @@ void CreateRooFitAndDraw(TH1D *hist) // leg1->SetFillColor(kWhite); leg1->SetLineColor(kWhite); - //leg1->AddEntry(roo_frame_mass->findObject(pdf_name.c_str()), "Signal + Background", "LP"); + // leg1->AddEntry(roo_frame_mass->findObject(pdf_name.c_str()), "Signal + Background", "LP"); leg1->AddEntry(roo_frame_mass->findObject("sig_cb"), "Signal", "LP"); - //leg1->AddEntry(roo_frame_mass->findObject(name_fit_func_bkg.c_str()), "Background", "LP"); + // leg1->AddEntry(roo_frame_mass->findObject(name_fit_func_bkg.c_str()), "Background", "LP"); 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 = %.8f #pm %.8f", roo_sig_tail.getTitle().Data(), roo_sig_tail.getVal(), roo_sig_tail.getError()).Data(), ""); @@ -255,6 +228,7 @@ void CreateRooFitAndDraw(TH1D *hist) leg1->AddEntry((TObject *)0, TString::Format("%s = %.3f #pm %.3f", var_mass_nL.getTitle().Data(), var_mass_nL.getVal(), var_mass_nL.getError()).Data(), ""); leg1->AddEntry((TObject *)0, TString::Format("%s = %.3f #pm %.3f", var_mass_alphaR.getTitle().Data(), var_mass_alphaR.getVal(), var_mass_alphaR.getError()).Data(), ""); leg1->AddEntry((TObject *)0, TString::Format("%s = %.3f #pm %.3f", var_mass_nR.getTitle().Data(), var_mass_nR.getVal(), var_mass_nR.getError()).Data(), ""); + leg1->AddEntry((TObject *)0, TString::Format("#epsilon = %.2f%%", (selected_entries / total_entries) * 100).Data(), ""); leg1->Draw(); diff --git a/old_analysis_macros/simulation_fullstream_B02KpPimMuMu.cpp b/simulation_fullstream_B02KpPimMuMu.cpp similarity index 87% rename from old_analysis_macros/simulation_fullstream_B02KpPimMuMu.cpp rename to simulation_fullstream_B02KpPimMuMu.cpp index f47885f..e1774e4 100644 --- a/old_analysis_macros/simulation_fullstream_B02KpPimMuMu.cpp +++ b/simulation_fullstream_B02KpPimMuMu.cpp @@ -39,6 +39,9 @@ const Double_t MASS_HIST_MIN = 5100.; const Double_t MASS_HIST_MAX = 6000.; const Double_t K_MASS = 493.677; +const Double_t PSI2S_MASS = 3686.093; +const Double_t JPSI_MASS = 3096.9; +const Double_t KSTAR_MASS = 891.76; const int PID_KAON = 321; const int PID_PION = 211; @@ -54,7 +57,7 @@ TString quickformat_name(const char *format) return TString::Format(format, NAME); }; -void CreateRooFitAndDraw(TH1D *hist); +void CreateRooFitAndDraw(TH1D *hist, double total_entries, double selected_entries); int simulation_fullstream_B02KpPimMuMu() { @@ -105,6 +108,7 @@ int simulation_fullstream_B02KpPimMuMu() data_chain->SetBranchAddress("Hm_TRUEID", &Hm_TRUEID); TH1D *h1_B_M = new TH1D("h1_B_M", "B Mass", nBins, MASS_HIST_MIN, MASS_HIST_MAX); + TH1D *h1_Dimuon_M = new TH1D("h1_Dimuon_M", "#mu #mu Mass", nBins, JPSI_MASS - 200., JPSI_MASS + 200.); 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); @@ -113,25 +117,28 @@ int simulation_fullstream_B02KpPimMuMu() h1_B_M_trueid->GetXaxis()->SetTitle(X_AXIS); unsigned int entries = data_chain->GetEntries(); + unsigned int selected_entries = 0; for (size_t i = 0; i < entries; i++) { data_chain->GetEntry(i); // std::cout << B_BKGCAT << std::endl; Double_t reconstructed_B_Mass = 0; + TLorentzVector l1_4v(L1_PX, L1_PY, L1_PZ, L1_ENERGY); + TLorentzVector l2_4v(L2_PX, L2_PY, L2_PZ, L2_ENERGY); if (B_BKGCAT == 30 && TMath::Abs(L1_TRUEID) == PID_MUON && L2_TRUEID == -L1_TRUEID) { if (TMath::Abs(Hp_TRUEID) == PID_KAON && TMath::Abs(Hm_TRUEID) == PID_PION) { 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 Pi_4v(Hm_PX, Hm_PY, Hm_PZ, Hm_ENERGY); reconstructed_B_Mass = (K_4v + l1_4v + l2_4v + Pi_4v).M(); + + selected_entries++; } else if (TMath::Abs(Hp_TRUEID) == PID_PION && TMath::Abs(Hm_TRUEID) == PID_KAON) { @@ -139,33 +146,34 @@ int simulation_fullstream_B02KpPimMuMu() 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 Pi_4v(Hp_PX, Hp_PY, Hp_PZ, Hp_ENERGY); reconstructed_B_Mass = (K_4v + l1_4v + l2_4v + Pi_4v).M(); + + selected_entries++; } } + TLorentzVector dimuon = l1_4v + l2_4v; + if (reconstructed_B_Mass != 0) { + h1_Dimuon_M->Fill(dimuon.M()); h1_B_M_trueid->Fill(reconstructed_B_Mass); h1_B_M->Fill(reconstructed_B_Mass); h1_B_BKGCAT->Fill(B_BKGCAT); h2_B_M_vs_B_BKGCAT->Fill(reconstructed_B_Mass, B_BKGCAT); } - if (i % 10000 == 0) + if ((i + 1) % 10000 == 0 || i + 1 == entries) { std::cout << "[" << NAME - << "] Processed event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 100.) << "%)" << std::endl; + << "] Processed event: " << i + 1 << " (" << TString::Format("%.2f", ((double)(i + 1) / (double)entries) * 100.) << "%), " + << "Current Efficiency: " << TString::Format("%.2f%%, with %d", ((double)selected_entries / (double)entries) * 100., selected_entries) + << std::endl; } } - std::cout << "[" - << NAME - << "] Processed event: " << entries << " (" << TString::Format("%.2f", 100.) << "%)" << std::endl; - h1_B_M->SetLineColor(kBlue); h1_B_M_trueid->SetLineColor(kMagenta + 2); h1_B_M_trueid->SetFillColor(kMagenta + 2); @@ -199,12 +207,20 @@ int simulation_fullstream_B02KpPimMuMu() c3->Draw(); c3->SaveAs(quickformat_name("images/sim/%s/h2_B_M_vs_B_BKGCAT.pdf")); - CreateRooFitAndDraw(h1_B_M_trueid); + TCanvas *c4 = new TCanvas("c4", "c4", 0, 0, 800, 600); + h1_Dimuon_M->SetStats(0); + h1_Dimuon_M->Draw(); + c4->BuildLegend(0.58, 0.77, 0.85, 0.87); + c4->Draw(); + + CreateRooFitAndDraw(h1_B_M_trueid, entries, selected_entries); + + return 0; } -void CreateRooFitAndDraw(TH1D *hist) +void CreateRooFitAndDraw(TH1D *hist, double total_entries, double selected_entries) { // std::cout << "### Entries: " << hist->GetEntries() << std::endl; RooRealVar roo_var_mass("var_mass", "B Mass Variable", MASS_HIST_MIN, MASS_HIST_MAX); @@ -261,6 +277,7 @@ void CreateRooFitAndDraw(TH1D *hist) leg1->AddEntry((TObject *)0, TString::Format("%s = %.3f #pm %.3f", var_mass_nL.getTitle().Data(), var_mass_nL.getVal(), var_mass_nL.getError()).Data(), ""); leg1->AddEntry((TObject *)0, TString::Format("%s = %.3f #pm %.3f", var_mass_alphaR.getTitle().Data(), var_mass_alphaR.getVal(), var_mass_alphaR.getError()).Data(), ""); leg1->AddEntry((TObject *)0, TString::Format("%s = %.3f #pm %.3f", var_mass_nR.getTitle().Data(), var_mass_nR.getVal(), var_mass_nR.getError()).Data(), ""); + leg1->AddEntry((TObject *)0, TString::Format("#epsilon = %.2f%%", (selected_entries / total_entries) * 100).Data(), ""); leg1->Draw(); diff --git a/old_analysis_macros/simulation_fullstream_Bu2KpMuMu.cpp b/simulation_fullstream_Bu2KpMuMu.cpp similarity index 93% rename from old_analysis_macros/simulation_fullstream_Bu2KpMuMu.cpp rename to simulation_fullstream_Bu2KpMuMu.cpp index 267eb6b..2458377 100644 --- a/old_analysis_macros/simulation_fullstream_Bu2KpMuMu.cpp +++ b/simulation_fullstream_Bu2KpMuMu.cpp @@ -53,7 +53,7 @@ TString quickformat_name(const char *format) return TString::Format(format, NAME); }; -void CreateRooFitAndDraw(TH1D *hist); +void CreateRooFitAndDraw(TH1D *hist, double total_entries, double selected_entries); int simulation_fullstream_Bu2KpMuMu() { @@ -84,6 +84,7 @@ int simulation_fullstream_Bu2KpMuMu() data_chain->SetBranchAddress("L1_PY", &L1_PY); data_chain->SetBranchAddress("L1_PZ", &L1_PZ); data_chain->SetBranchAddress("L1_ENERGY", &L1_ENERGY); + data_chain->SetBranchAddress("L2_PX", &L2_PX); data_chain->SetBranchAddress("L2_PY", &L2_PY); data_chain->SetBranchAddress("L2_PZ", &L2_PZ); @@ -105,14 +106,14 @@ int simulation_fullstream_Bu2KpMuMu() h1_B_M_trueid->GetXaxis()->SetTitle(X_AXIS); unsigned int entries = data_chain->GetEntries(); + unsigned int selected_entries = 0; for (size_t i = 0; i < entries; i++) { data_chain->GetEntry(i); - // std::cout << B_BKGCAT << std::endl; Double_t reconstructed_B_Mass = 0; - if (TMath::Abs(L1_TRUEID) == PID_MUON && L2_TRUEID == -L1_TRUEID/* && TMath::Abs(Hp_TRUEID) == PID_KAON*/) + if (B_BKGCAT == 30 && TMath::Abs(L1_TRUEID) == PID_MUON && L2_TRUEID == -L1_TRUEID && TMath::Abs(Hp_TRUEID) == PID_KAON) { TVector3 K_momentum(Hp_PX, Hp_PY, Hp_PZ); @@ -122,6 +123,7 @@ int simulation_fullstream_Bu2KpMuMu() TLorentzVector l2_4v(L2_PX, L2_PY, L2_PZ, L2_ENERGY); reconstructed_B_Mass = (K_4v + l1_4v + l2_4v).M(); + selected_entries++; h1_B_M_trueid->Fill(reconstructed_B_Mass); h1_B_M->Fill(reconstructed_B_Mass); h1_B_BKGCAT->Fill(B_BKGCAT); @@ -132,7 +134,9 @@ int simulation_fullstream_Bu2KpMuMu() { std::cout << "[" << NAME - << "] Processed event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 100.) << "%)" << std::endl; + << "] Processed event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 100.) << "%), " + << "Current Efficiency: " << TString::Format("%.2f%%", ((double)selected_entries / (double)entries) * 100.) + << std::endl; } } @@ -173,12 +177,12 @@ int simulation_fullstream_Bu2KpMuMu() c3->Draw(); c3->SaveAs(quickformat_name("images/sim/%s/h2_B_M_vs_B_BKGCAT.pdf")); - CreateRooFitAndDraw(h1_B_M_trueid); + CreateRooFitAndDraw(h1_B_M_trueid, entries, selected_entries); return 0; } -void CreateRooFitAndDraw(TH1D *hist) +void CreateRooFitAndDraw(TH1D *hist, double total_entries, double selected_entries) { // std::cout << "### Entries: " << hist->GetEntries() << std::endl; RooRealVar roo_var_mass("var_mass", "B Mass Variable", MASS_HIST_MIN, MASS_HIST_MAX); @@ -235,6 +239,7 @@ void CreateRooFitAndDraw(TH1D *hist) leg1->AddEntry((TObject *)0, TString::Format("%s = %.3f #pm %.3f", var_mass_nL.getTitle().Data(), var_mass_nL.getVal(), var_mass_nL.getError()).Data(), ""); leg1->AddEntry((TObject *)0, TString::Format("%s = %.3f #pm %.3f", var_mass_alphaR.getTitle().Data(), var_mass_alphaR.getVal(), var_mass_alphaR.getError()).Data(), ""); leg1->AddEntry((TObject *)0, TString::Format("%s = %.3f #pm %.3f", var_mass_nR.getTitle().Data(), var_mass_nR.getVal(), var_mass_nR.getError()).Data(), ""); + leg1->AddEntry((TObject *)0, TString::Format("#epsilon = %.2f%%", (selected_entries / total_entries) * 100).Data(), ""); leg1->Draw();