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.

483 lines
24 KiB

  1. #include "TH1D.h"
  2. #include "TH2D.h"
  3. #include "THStack.h"
  4. #include "TGraph.h"
  5. #include "TTree.h"
  6. #include "TF1.h"
  7. #include "TChain.h"
  8. #include "TFile.h"
  9. #include "TCanvas.h"
  10. #include "TROOT.h"
  11. #include "TStyle.h"
  12. #include "TColor.h"
  13. #include "TLorentzVector.h"
  14. #include "TRandom3.h"
  15. #include "TLorentzVector.h"
  16. #include "RooDataHist.h"
  17. #include "RooRealVar.h"
  18. #include "RooPlot.h"
  19. #include "RooGaussian.h"
  20. #include "RooExponential.h"
  21. #include "RooRealConstant.h"
  22. #include "RooAddPdf.h"
  23. #include "RooFitResult.h"
  24. #include "RooProduct.h"
  25. #include "RooCrystalBall.h"
  26. #include "RooBreitWigner.h"
  27. #include "RooArgSet.h"
  28. #include "RooFFTConvPdf.h"
  29. #include "RooNovosibirsk.h"
  30. #include <string>
  31. #include <iostream>
  32. #include <cmath>
  33. const int nBins = 70;
  34. // const Double_t MASS_HIST_MIN = 5150.;
  35. // const Double_t MASS_HIST_MAX = 5450.;
  36. // const Double_t MASS_HIST_FIT_MIN = 5150.;
  37. // const Double_t MASS_HIST_FIT_MAX = 5450.;
  38. const Double_t MASS_HIST_MIN = 4000.;
  39. const Double_t MASS_HIST_MAX = 8500.;
  40. const Double_t MASS_HIST_FIT_MIN = 5100.;
  41. const Double_t MASS_HIST_FIT_MAX = 6000.;
  42. // PDG Values
  43. const Double_t J_PSI_MASS = 3096.916;
  44. const Double_t PSI_2S_MASS = 3686.09;
  45. const Double_t K_MASS = 493.677;
  46. const Double_t K_STAR_0_MASS = 891.67;
  47. const std::string SAVE_PATH = "/work/pfeiffer/inclusive_detached_dilepton/status_report";
  48. struct FitParams
  49. {
  50. Double_t lambda;
  51. Double_t mean;
  52. Double_t sigma;
  53. Double_t sig_yield;
  54. Double_t bkg_yield;
  55. FitParams(Double_t lambda, Double_t mean, Double_t sigma, Double_t sig_yield, Double_t bkg_yield)
  56. {
  57. this->lambda = lambda;
  58. this->mean = mean;
  59. this->sigma = sigma;
  60. this->sig_yield = sig_yield;
  61. this->bkg_yield = bkg_yield;
  62. }
  63. };
  64. struct AnalysisOutput
  65. {
  66. std::string title;
  67. std::string name;
  68. std::string root_file;
  69. std::string root_file_tree;
  70. std::string B_name;
  71. int k_charge;
  72. const std::string suf(std::string input)
  73. {
  74. return TString::Format("%s_%s", input.c_str(), name.c_str()).Data();
  75. }
  76. const std::string title_suf(std::string input)
  77. {
  78. return TString::Format("%s [%s]", input.c_str(), title.c_str()).Data();
  79. }
  80. };
  81. void CreateRooFitAndSavePDF(TH1D *hist, AnalysisOutput ana, const char *name);
  82. std::vector<RooPlot *> PlotWithParams(TH1D *hist, AnalysisOutput ana);
  83. bool inRange(double value, double center, double low_intvl, double up_intvl)
  84. {
  85. return center - low_intvl < value && value < center + up_intvl;
  86. }
  87. bool inRange(double value, double center, double intvl)
  88. {
  89. return inRange(value, center, intvl, intvl);
  90. }
  91. void savePDF(TObject *o, const char *decay, const char *name, Option_t *opt = "")
  92. {
  93. auto cname = TString::Format("%s_%s", decay, name);
  94. std::cout << " ----- " << cname.Data() << " - " << decay << " - " << name << std::endl;
  95. auto c = new TCanvas(cname.Data(), cname.Data(), 0, 0, 800, 600);
  96. o->Draw(opt);
  97. c->SaveAs(TString::Format("%s/%s.jpg", SAVE_PATH.c_str(), cname.Data()));
  98. // c->Draw();
  99. }
  100. RooHelpers::LocalChangeMsgLevel changeMsgLvl(RooFit::WARNING);
  101. int status_report_plots()
  102. {
  103. // gROOT->ProcessLine(".x /work/pfeiffer/lhcbStyle.C");
  104. std::vector<AnalysisOutput> anas{
  105. AnalysisOutput{"SpruceRD_BuToHpMuMu", "BuToKpMuMu_incl", "/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/Collision23_Beam6800GeV-VeloClosed-MagDown-Excl-UT_RealData_Sprucing23r1_90000000_RD.root", "SpruceRD_BuToHpMuMu/DecayTree", "B", 0},
  106. // AnalysisOutput{"SpruceRD_BuToHpMuMu (ap)", "BuToKpMuMu_incl_ap", "/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/spruce_magdown_2023_v0r1_tuple_90000000_2023_v0r0p6288631.root", "BuToHpMuMu/DecayTree", "B", "1395.27 +/- 58"},
  107. // AnalysisOutput{"Hlt2RD_BuToKpMuMu_2023", "BuToKpMuMu_excl", "/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/Collision23_Beam6800GeV-VeloClosed-MagDown-Excl-UT_RealData_SprucingPass23r1_94000000_RD.root", "Hlt2RD_BuToKpMuMu_2023/DecayTree", "B", 0 },
  108. // // AnalysisOutput{"Hlt2RD_", "BuToKpMuMu_excl_ap23", "/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/turbopass_magdown_2023_v1_tuple_94000000_2023_v0r0p6201764.root", "BuToKpMuMu23/DecayTree", "B", "803.769 +/- 34"},
  109. // AnalysisOutput{"SpruceRD_B0ToHpHmMuMu K+", "B0ToKpPimMuMu_Kp_incl", "/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/Collision23_Beam6800GeV-VeloClosed-MagDown-Excl-UT_RealData_Sprucing23r1_90000000_RD.root", "SpruceRD_B0ToHpHmMuMu/DecayTree", "B0", 1 },
  110. // AnalysisOutput{"SpruceRD_B0ToHpHmMuMu K-", "B0ToKpPimMuMu_Km_incl", "/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/Collision23_Beam6800GeV-VeloClosed-MagDown-Excl-UT_RealData_Sprucing23r1_90000000_RD.root", "SpruceRD_B0ToHpHmMuMu/DecayTree", "B0", -1 },
  111. // AnalysisOutput{"SpruceRD_B0ToHpHmMuMu (ap)", "B0ToKpPimMuMu_incl_ap", "/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/spruce_magdown_2023_v0r1_tuple_90000000_2023_v0r0p6288631.root", "B0ToHpHmMuMu/DecayTree", "B0", ""},
  112. // AnalysisOutput{"Hlt2RD_B0ToKpPimMuMu_2023", "B0ToKpPimMuMu_excl", "/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/Collision23_Beam6800GeV-VeloClosed-MagDown-Excl-UT_RealData_SprucingPass23r1_94000000_RD.root", "Hlt2RD_B0ToKpPimMuMu_2023/DecayTree", "B0", 0 },
  113. // AnalysisOutput{"Hlt2RD_B0ToKpPimMuMu_2023 AP", "B0ToKpPimMuMu_excl_ap23", "/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/turbopass_magdown_2023_v1_tuple_94000000_2023_v0r0p6201764.root", "B0ToKpPimMuMu23/DecayTree", "B0", ""},
  114. // AnalysisOutput{"Hlt2B2CC_BuToJpsiKplus_JpsiToMuMu_Detached", "BuToJpsiKplus_det", "/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/Collision23_Beam6800GeV-VeloClosed-MagDown-Excl-UT_RealData_SprucingPass23r1_94000000_B2CC.root", "Hlt2B2CC_BuToJpsiKplus_JpsiToMuMu_Detached/DecayTree", "B", 0 },
  115. };
  116. for (size_t a = 0; a < anas.size(); a++)
  117. {
  118. auto ana = anas[a];
  119. TChain *data_chain = new TChain(ana.root_file_tree.c_str());
  120. data_chain->Add(ana.root_file.c_str());
  121. Double_t B_M, // 4400 -> 8200
  122. Jpsi_M, // 200 -> 6600
  123. muminus_PID_MU,
  124. muplus_PID_MU,
  125. muminus_PID_K,
  126. muplus_PID_K,
  127. Kplus_PID_K;
  128. Float_t muminus_PT,
  129. muplus_PT,
  130. Kplus_PT,
  131. Kplus_P;
  132. Int_t Kplus_Q;
  133. Bool_t muplus_ISMUON, muminus_ISMUON, Hlt1TrackMVADecision, Hlt1TwoTrackMVADecision;
  134. data_chain->SetBranchAddress(TString::Format("%s_M", ana.B_name.c_str()).Data(), &B_M);
  135. data_chain->SetBranchAddress("Jpsi_M", &Jpsi_M);
  136. data_chain->SetBranchAddress("muplus_ISMUON", &muplus_ISMUON);
  137. data_chain->SetBranchAddress("muminus_ISMUON", &muminus_ISMUON);
  138. data_chain->SetBranchAddress("Hlt1TrackMVADecision", &Hlt1TrackMVADecision);
  139. data_chain->SetBranchAddress("Hlt1TwoTrackMVADecision", &Hlt1TwoTrackMVADecision);
  140. data_chain->SetBranchAddress("Kplus_Q", &Kplus_Q);
  141. // manually sub mass hyp
  142. Double_t L1_M, L2_M, Hp_M;
  143. 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;
  144. if (ana.name == "BuToKpMuMu_incl_ap" || ana.name == "B0ToKpPimMuMu_incl_ap")
  145. {
  146. data_chain->SetBranchAddress("L1_M", &L1_M);
  147. data_chain->SetBranchAddress("L2_M", &L2_M);
  148. data_chain->SetBranchAddress("Hp_M", &Hp_M);
  149. data_chain->SetBranchAddress("L1_PX", &L1_PX);
  150. data_chain->SetBranchAddress("L1_PY", &L1_PY);
  151. data_chain->SetBranchAddress("L1_PZ", &L1_PZ);
  152. data_chain->SetBranchAddress("L1_ENERGY", &L1_ENERGY);
  153. data_chain->SetBranchAddress("L2_PX", &L2_PX);
  154. data_chain->SetBranchAddress("L2_PY", &L2_PY);
  155. data_chain->SetBranchAddress("L2_PZ", &L2_PZ);
  156. data_chain->SetBranchAddress("L2_ENERGY", &L2_ENERGY);
  157. data_chain->SetBranchAddress("Hp_PX", &Hp_PX);
  158. data_chain->SetBranchAddress("Hp_PY", &Hp_PY);
  159. data_chain->SetBranchAddress("Hp_PZ", &Hp_PZ);
  160. data_chain->SetBranchAddress("Hp_ENERGY", &Hp_ENERGY);
  161. }
  162. Float_t muplus_PX, muplus_PY, muplus_PZ, muplus_ENERGY, muminus_PX, muminus_PY, muminus_PZ, muminus_ENERGY;
  163. data_chain->SetBranchAddress("muplus_PX", &muplus_PX);
  164. data_chain->SetBranchAddress("muplus_PY", &muplus_PY);
  165. data_chain->SetBranchAddress("muplus_PZ", &muplus_PZ);
  166. data_chain->SetBranchAddress("muplus_ENERGY", &muplus_ENERGY);
  167. data_chain->SetBranchAddress("muminus_PX", &muminus_PX);
  168. data_chain->SetBranchAddress("muminus_PY", &muminus_PY);
  169. data_chain->SetBranchAddress("muminus_PZ", &muminus_PZ);
  170. data_chain->SetBranchAddress("muminus_ENERGY", &muminus_ENERGY);
  171. Double_t Kst0_M, Kplus_M, piminus_M;
  172. Float_t Kst0_PX, Kst0_PY, Kst0_PZ, Kst0_ENERGY, Kplus_PX, Kplus_PY, Kplus_PZ, Kplus_ENERGY, piminus_PX, piminus_PY, piminus_PZ, piminus_ENERGY;
  173. if (ana.B_name == "B0")
  174. {
  175. data_chain->SetBranchAddress("Kst0_M", &Kst0_M);
  176. data_chain->SetBranchAddress("Kst0_PX", &Kst0_PX);
  177. data_chain->SetBranchAddress("Kst0_PY", &Kst0_PY);
  178. data_chain->SetBranchAddress("Kst0_PZ", &Kst0_PZ);
  179. data_chain->SetBranchAddress("Kst0_ENERGY", &Kst0_ENERGY);
  180. data_chain->SetBranchAddress("Kplus_M", &Kplus_M);
  181. data_chain->SetBranchAddress("Kplus_PX", &Kplus_PX);
  182. data_chain->SetBranchAddress("Kplus_PY", &Kplus_PY);
  183. data_chain->SetBranchAddress("Kplus_PZ", &Kplus_PZ);
  184. data_chain->SetBranchAddress("Kplus_ENERGY", &Kplus_ENERGY);
  185. data_chain->SetBranchAddress("piminus_M", &piminus_M);
  186. data_chain->SetBranchAddress("piminus_PX", &piminus_PX);
  187. data_chain->SetBranchAddress("piminus_PY", &piminus_PY);
  188. data_chain->SetBranchAddress("piminus_PZ", &piminus_PZ);
  189. data_chain->SetBranchAddress("piminus_ENERGY", &piminus_ENERGY);
  190. }
  191. TH1D *h1_B_M = new TH1D(ana.suf("h1_B_M").c_str(), ana.title_suf("B Mass").c_str(), nBins, MASS_HIST_MIN, MASS_HIST_MAX);
  192. TH1D *h1_B_M_JPsi_cut = new TH1D(ana.suf("h1_B_M_JPsi_cut").c_str(), ana.title_suf("B Mass").c_str(), nBins, MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX);
  193. TH1D *h1_B_M_Psi2s_cut = new TH1D(ana.suf("h1_B_M_Psi2s_cut").c_str(), ana.title_suf("B Mass").c_str(), nBins, MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX);
  194. TH1D *h1_Jpsi_M = new TH1D(ana.suf("h1_Jpsi_M").c_str(), ana.title_suf("J/#psi Mass").c_str(), nBins, 200., 5500.);
  195. TH1D *h1_Jpsi_M_align = new TH1D(ana.suf("h1_Jpsi_M_align").c_str(), ana.title_suf("J/#psi Mass Align").c_str(), nBins, J_PSI_MASS - 200., J_PSI_MASS + 200.);
  196. TH2D *h2_B_M_Jpsi_M = new TH2D(ana.suf("h2_B_M_Jpsi_M").c_str(), ana.title_suf("B Mass vs. J/#psi Mass").c_str(), nBins, MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX, nBins, 200., 5500.);
  197. TH1D *h1_Kst0_M = new TH1D(ana.suf("h1_Kst0_M").c_str(), ana.title_suf("K*0 Mass").c_str(), nBins, 600., 3000.);
  198. TH1D *h1_Kpi_M = new TH1D(ana.suf("h1_Kpi_M").c_str(), ana.title_suf("K #pi Mass").c_str(), nBins, 600., 3000.);
  199. h1_B_M->GetXaxis()->SetTitle(TString::Format("m(%s) / MeV", ana.B_name.c_str()).Data());
  200. h1_B_M_JPsi_cut->GetXaxis()->SetTitle(TString::Format("m(%s) / MeV", ana.B_name.c_str()).Data());
  201. h1_Jpsi_M->GetXaxis()->SetTitle("m(#mu#mu) / MeV");
  202. unsigned int entries = data_chain->GetEntries();
  203. for (unsigned int i = 0; i < entries; i++)
  204. {
  205. if (i % 10000 == 0)
  206. {
  207. std::cout << "[" << ana.name << "] Processing event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 100.) << "%)" << std::endl;
  208. }
  209. data_chain->GetEntry(i);
  210. if (ana.k_charge != 0 && Kplus_Q != ana.k_charge)
  211. {
  212. continue;
  213. }
  214. // if (!(muplus_ISMUON && muminus_ISMUON && (Hlt1TrackMVADecision | Hlt1TwoTrackMVADecision)))
  215. // {
  216. // continue;
  217. // }
  218. Double_t used_B_Mass = 0;
  219. // manually sub mass hyp
  220. if (ana.name == "BuToKpMuMu_incl_ap")
  221. {
  222. TVector3 K_momentum(Hp_PX, Hp_PY, Hp_PZ);
  223. double K_energy = TMath::Sqrt(TMath::Sq(K_MASS) + K_momentum.Mag2());
  224. TLorentzVector K_4v(K_momentum, K_energy);
  225. TLorentzVector l1_4v(L1_PX, L1_PY, L1_PZ, L1_ENERGY);
  226. TLorentzVector l2_4v(L2_PX, L2_PY, L2_PZ, L2_ENERGY);
  227. used_B_Mass = (K_4v + l1_4v + l2_4v).M();
  228. }
  229. else
  230. {
  231. used_B_Mass = B_M;
  232. }
  233. TLorentzVector muplus_4v(muplus_PX, muplus_PY, muplus_PZ, muplus_ENERGY);
  234. TLorentzVector muminus_4v(muminus_PX, muminus_PY, muminus_PZ, muminus_ENERGY);
  235. Double_t calc_q2 =
  236. h1_B_M->Fill(used_B_Mass);
  237. h1_Jpsi_M->Fill(Jpsi_M);
  238. h1_Jpsi_M_align->Fill(Jpsi_M);
  239. h2_B_M_Jpsi_M->Fill(used_B_Mass, Jpsi_M);
  240. if (ana.B_name == "B0")
  241. {
  242. TLorentzVector kplus_4v(Kplus_PX, Kplus_PY, Kplus_PZ, Kplus_ENERGY);
  243. TLorentzVector piminus_4v(piminus_PX, piminus_PY, piminus_PZ, piminus_ENERGY);
  244. TLorentzVector kst0_4v(Kst0_PX, Kst0_PY, Kst0_PZ, Kst0_ENERGY);
  245. Double_t kpi_mass = (kplus_4v + piminus_4v).M();
  246. Double_t kst0_mass = kst0_4v.M();
  247. if (TMath::Abs(kpi_mass - K_STAR_0_MASS) < 100.)
  248. {
  249. h1_Kst0_M->Fill(kst0_mass);
  250. h1_Kpi_M->Fill(kpi_mass);
  251. if (TMath::Abs(Jpsi_M - J_PSI_MASS) < 60.)
  252. {
  253. h1_B_M_JPsi_cut->Fill(used_B_Mass);
  254. }
  255. else if (TMath::Abs(Jpsi_M - PSI_2S_MASS) < 60.)
  256. {
  257. h1_B_M_Psi2s_cut->Fill(used_B_Mass);
  258. }
  259. }
  260. }
  261. else
  262. {
  263. if (TMath::Abs(Jpsi_M - J_PSI_MASS) < 60.)
  264. {
  265. h1_B_M_JPsi_cut->Fill(used_B_Mass);
  266. }
  267. else if (TMath::Abs(Jpsi_M - PSI_2S_MASS) < 60.)
  268. {
  269. h1_B_M_Psi2s_cut->Fill(used_B_Mass);
  270. }
  271. }
  272. }
  273. h1_B_M->GetYaxis()->SetTitle(TString::Format("Events").Data());
  274. h1_B_M_JPsi_cut->GetYaxis()->SetTitle(TString::Format("Events").Data());
  275. h1_Jpsi_M->GetYaxis()->SetTitle(TString::Format("Events").Data());
  276. h1_B_M->SetMinimum(0);
  277. h1_B_M_JPsi_cut->SetMinimum(0);
  278. h1_Jpsi_M->SetMinimum(0);
  279. h2_B_M_Jpsi_M->SetMinimum(0);
  280. h1_B_M->SetStats(0);
  281. h1_B_M_JPsi_cut->SetStats(0);
  282. h1_Jpsi_M->SetStats(0);
  283. h2_B_M_Jpsi_M->SetStats(0);
  284. // auto fitRes = CreateRooFit(h1_B_M_JPsi_cut, ana);
  285. // auto paramsPlot = PlotWithParams(h1_B_M_JPsi_cut, ana);
  286. // savePDF(h1_B_M, ana.name.c_str(), "B_M_uncut");
  287. // savePDF(h1_Jpsi_M, ana.name.c_str(), "JPsi_M_uncut");
  288. // savePDF(h1_B_M_JPsi_cut, ana.name.c_str(), "B_M_JPsi_cut");
  289. // savePDF(h1_Jpsi_M_align, ana.name.c_str(), "JPsi_M_uncut_al");
  290. // savePDF(h2_B_M_Jpsi_M, ana.name.c_str(), "B_M_vs_Jpsi_M");
  291. CreateRooFitAndSavePDF(h1_B_M_JPsi_cut, ana, "B_mass_JPsi_cut_fit");
  292. CreateRooFitAndSavePDF(h1_B_M_Psi2s_cut, ana, "B_mass_Psi2s_cut_fit");
  293. if (ana.B_name == "B0")
  294. {
  295. savePDF(h1_Kst0_M, ana.name.c_str(), "Kst0_M_uncut");
  296. savePDF(h1_Kpi_M, ana.name.c_str(), "Kpi_M_uncut");
  297. }
  298. }
  299. return 0;
  300. }
  301. void CreateRooFitAndSavePDF(TH1D *hist, AnalysisOutput ana, const char *name)
  302. {
  303. RooRealVar roo_var_mass(ana.suf("var_mass").c_str(), TString::Format("m(%s)", ana.B_name.c_str()).Data(), MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX);
  304. roo_var_mass.setRange("fitting_range", MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX);
  305. std::string hist_name = ana.suf("hist_B_M");
  306. RooDataHist roohist_B_M(hist_name.c_str(), "B Mass Histogram", roo_var_mass, RooFit::Import(*hist));
  307. // RooRealVar roo_sig_bw_mean(ana.suf("sig_mean").c_str(), "Mass BW Mean", 5250., 5100., 5400.);
  308. // RooRealVar roo_sig_bw_with(ana.suf("sig_width").c_str(), "Mass BW Width", 20., 0., 50.);
  309. // RooBreitWigner roo_sig_bw(ana.suf("roo_sig_bw").c_str(), "B Signal Breit Wigner", roo_var_mass, roo_sig_bw_mean, roo_sig_bw_with);
  310. RooRealVar roo_sig_gauss_mean(ana.suf("sig_mean").c_str(), "#mu", 5250., 5100., 5400.);
  311. RooRealVar roo_sig_gauss_sigma(ana.suf("sig_sigma").c_str(), "#sigma", 20., 0., 50.);
  312. RooGaussian roo_sig_gauss(ana.suf("sig_gauss").c_str(), "B Signal Gaussian", roo_var_mass, roo_sig_gauss_mean, roo_sig_gauss_sigma);
  313. // RooRealVar roo_sig_tail(ana.suf("sig_tail").c_str(), "#lambda_{sig}", -0.5, -1., 0.);
  314. // RooNovosibirsk roo_sig_nov(ana.suf("sig_nov").c_str(), "B Signal Nov", roo_var_mass, roo_sig_gauss_mean, roo_sig_gauss_sigma, roo_sig_tail);
  315. // RooRealVar roo_sig_add_gau_exp_frac(ana.suf("sig_add_gau_exp_frac").c_str(), "sig exp gau frac", 0.5, 0., 1.);
  316. // RooAddPdf roo_sig_add_gau_exp(ana.suf("sig_add_gau_exp").c_str(), "B Mass Signal Gaus + Exp", roo_sig_gauss, roo_sig_exp, roo_sig_add_gau_exp_frac);
  317. // RooFFTConvPdf roo_sig_conv_gau_exp(ana.suf("sig_conv_gau_exp").c_str(), "Exp (x) Gauss", roo_var_mass, roo_sig_gauss, roo_sig_exp);
  318. RooRealVar roo_bkg_exp_c(ana.suf("bkg_exp_c").c_str(), "#lambda_{bkg}", -0.001145, -0.00199, -0.00100);
  319. RooExponential roo_bkg_exp(ana.suf("bkg_exp").c_str(), "B Mass Background Exp", roo_var_mass, roo_bkg_exp_c);
  320. roo_bkg_exp.asTF()
  321. RooRealVar roo_var_mass_sig_yield(ana.suf("sig_yield").c_str(), "N_{Sig}", 0., hist->GetEntries());
  322. RooRealVar roo_var_mass_bkg_yield(ana.suf("bkg_yield").c_str(), "N_{Bkg}", 0., hist->GetEntries());
  323. std::string pdf_name = ana.suf("pdf_sig_plus_bkg");
  324. RooAddPdf roo_pdf_sig_plus_bkg(pdf_name.c_str(), "Sig + Bkg PDF",
  325. RooArgList(roo_sig_gauss, roo_bkg_exp),
  326. RooArgList(roo_var_mass_sig_yield, roo_var_mass_bkg_yield));
  327. RooPlot *roo_frame_mass = roo_var_mass.frame(RooFit::Title(ana.title_suf("B Mass Fit").c_str()));
  328. roohist_B_M.plotOn(roo_frame_mass, RooFit::Binning(nBins), RooFit::Name(hist_name.c_str()));
  329. RooFitResult *fitres = roo_pdf_sig_plus_bkg.fitTo(roohist_B_M, RooFit::Save(), RooFit::PrintLevel(1), RooFit::Range("fitting_range"));
  330. auto name_fit_func_sig = ana.suf("fit_fsig");
  331. auto name_fit_func_bkg = ana.suf("fit_fbkg");
  332. roo_pdf_sig_plus_bkg.plotOn(roo_frame_mass, RooFit::LineColor(kRed), RooFit::LineStyle(kSolid), RooFit::Range("fitting_range"), RooFit::Name(pdf_name.c_str()));
  333. roo_pdf_sig_plus_bkg.plotOn(roo_frame_mass, RooFit::Name(name_fit_func_bkg.c_str()), RooFit::Components(RooArgSet(roo_bkg_exp)), RooFit::LineColor(kBlue), RooFit::LineStyle(kDashed), RooFit::Range("fitting_range"));
  334. roo_pdf_sig_plus_bkg.plotOn(roo_frame_mass, RooFit::Name(name_fit_func_sig.c_str()), RooFit::Components(RooArgSet(roo_sig_gauss)), RooFit::FillStyle(3244), RooFit::LineColor(kRed - 7), RooFit::LineStyle(kDashed), RooFit::Range("fitting_range"));
  335. // roo_pdf_sig_plus_bkg.paramOn(roo_frame_mass, RooFit::Layout(0.45, 0.99, 0.90));
  336. // roo_frame_mass->getAttText()->SetTextSize(0.030);
  337. RooPlot *roo_frame_pull = roo_var_mass.frame(RooFit::Title("."));
  338. roo_frame_pull->addPlotable(roo_frame_mass->pullHist(hist_name.c_str(), pdf_name.c_str()), "P");
  339. Float_t title_size = 0.083;
  340. Float_t label_size = 0.073;
  341. roo_frame_pull->GetXaxis()->SetTitle(TString::Format("m(%s)", ana.B_name.c_str()).Data());
  342. roo_frame_pull->GetXaxis()->SetTitleSize(title_size);
  343. roo_frame_pull->GetYaxis()->SetTitleSize(title_size);
  344. roo_frame_pull->GetXaxis()->SetLabelSize(label_size);
  345. roo_frame_pull->GetYaxis()->SetLabelSize(label_size);
  346. auto cname = TString::Format("%s_%s", ana.name.c_str(), name);
  347. auto c = new TCanvas(cname.Data(), cname.Data(), 0, 0, 800, 600);
  348. auto p2 = new TPad(TString::Format("%s_p2", name), "Lower Pad", 0., 0., 1., 0.3);
  349. p2->Draw();
  350. p2->SetTopMargin(0.001);
  351. p2->SetBottomMargin(0.3);
  352. p2->SetGrid();
  353. auto *p1 = new TPad(TString::Format("%s_p1", name), "Upper Pad", 0., 0.32, 1., 1.);
  354. p1->Draw();
  355. p1->SetBottomMargin(0.001);
  356. p1->cd();
  357. roo_frame_mass->Draw();
  358. TLegend *leg1 = new TLegend(0.58, 0.50, 0.96, 0.87);
  359. // leg1->SetFillColor(kWhite);
  360. leg1->SetLineColor(kWhite);
  361. leg1->AddEntry(roo_frame_mass->findObject(pdf_name.c_str()), "Signal + Background", "LP");
  362. leg1->AddEntry(roo_frame_mass->findObject(name_fit_func_sig.c_str()), "Signal", "LP");
  363. leg1->AddEntry(roo_frame_mass->findObject(name_fit_func_bkg.c_str()), "Background", "LP");
  364. leg1->AddEntry((TObject *)0, TString::Format("%s = %.2f #pm %.2f", roo_sig_gauss_mean.getTitle().Data(), roo_sig_gauss_mean.getVal(), roo_sig_gauss_mean.getError()).Data(), "");
  365. leg1->AddEntry((TObject *)0, TString::Format("%s = %.2f #pm %.2f", roo_sig_gauss_sigma.getTitle().Data(), roo_sig_gauss_sigma.getVal(), roo_sig_gauss_sigma.getError()).Data(), "");
  366. // leg1->AddEntry((TObject *)0, TString::Format("%s = %.8f #pm %.8f", roo_sig_tail.getTitle().Data(), roo_sig_tail.getVal(), roo_sig_tail.getError()).Data(), "");
  367. leg1->AddEntry((TObject *)0, TString::Format("%s = %.8f #pm %.8f", roo_bkg_exp_c.getTitle().Data(), roo_bkg_exp_c.getVal(), roo_bkg_exp_c.getError()).Data(), "");
  368. leg1->AddEntry((TObject *)0, TString::Format("%s = %.2f #pm %.2f", roo_var_mass_sig_yield.getTitle().Data(), roo_var_mass_sig_yield.getVal(), roo_var_mass_sig_yield.getError()).Data(), "");
  369. leg1->AddEntry((TObject *)0, TString::Format("%s = %.2f #pm %.2f", roo_var_mass_bkg_yield.getTitle().Data(), roo_var_mass_bkg_yield.getVal(), roo_var_mass_bkg_yield.getError()).Data(), "");
  370. leg1->Draw();
  371. p2->cd();
  372. roo_frame_pull->Draw();
  373. c->SaveAs(TString::Format("%s/%s.png", SAVE_PATH.c_str(), cname.Data()));
  374. }
  375. // std::vector<RooPlot *> PlotWithParams(TH1D *hist, AnalysisOutput ana)
  376. // {
  377. // RooRealVar roo_var_mass(ana.suf("var_mass").c_str(), TString::Format("m(%s)", ana.B_name).Data(), MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX);
  378. // roo_var_mass.setRange("fitting_range", MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX);
  379. // std::string hist_name = ana.suf("hist_B_M");
  380. // RooDataHist roohist_B_M(hist_name.c_str(), "B Mass Histogram", roo_var_mass, RooFit::Import(*hist));
  381. // // RooRealVar roo_sig_bw_mean(ana.suf("sig_mean").c_str(), "Mass BW Mean", 5250., 5100., 5400.);
  382. // // RooRealVar roo_sig_bw_with(ana.suf("sig_width").c_str(), "Mass BW Width", 20., 0., 50.);
  383. // // RooBreitWigner roo_sig_bw(ana.suf("roo_sig_bw").c_str(), "B Signal Breit Wigner", roo_var_mass, roo_sig_bw_mean, roo_sig_bw_with);
  384. // RooGaussian roo_sig_gauss(ana.suf("sig_gauss").c_str(), "B Signal Breit Wigner", roo_var_mass, RooRealConstant::value(ana.fit_params.mean), RooRealConstant::value(ana.fit_params.sigma));
  385. // RooExponential roo_bkg_exp(ana.suf("bkg_exp").c_str(), "B Mass Background Exp", roo_var_mass, RooRealConstant::value(ana.fit_params.lambda));
  386. // std::string pdf_name = ana.suf("pdf_sig_plus_bkg");
  387. // RooAddPdf roo_pdf_sig_plus_bkg(pdf_name.c_str(), "Sig + Bkg PDF",
  388. // RooArgList(roo_sig_gauss, roo_bkg_exp),
  389. // RooArgList(RooRealConstant::value(ana.fit_params.sig_yield), RooRealConstant::value(ana.fit_params.bkg_yield)));
  390. // RooPlot *roo_frame_mass = roo_var_mass.frame(RooFit::Title(TString::Format("%s [%s]", ana.name.c_str(), ana.title.c_str()).Data()));
  391. // roohist_B_M.plotOn(roo_frame_mass, RooFit::Binning(nBins), RooFit::Name(hist_name.c_str()));
  392. // roo_pdf_sig_plus_bkg.plotOn(roo_frame_mass, RooFit::LineColor(kRed), RooFit::LineStyle(kDashed), RooFit::Range("fitting_range"), RooFit::Name(pdf_name.c_str()));
  393. // roo_pdf_sig_plus_bkg.plotOn(roo_frame_mass, RooFit::Components(RooArgSet(roo_bkg_exp)), RooFit::LineColor(kBlue), RooFit::LineStyle(kDashed), RooFit::Range("fitting_range"));
  394. // roo_pdf_sig_plus_bkg.plotOn(roo_frame_mass, RooFit::Components(RooArgSet(roo_sig_gauss)), RooFit::FillStyle(3244), RooFit::LineColor(kRed - 7), RooFit::LineStyle(kDashed), RooFit::Range("fitting_range"));
  395. // return std::vector<RooPlot *>{roo_frame_mass};
  396. // }