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.

140 lines
4.6 KiB

  1. #include "TH1D.h"
  2. #include "TH2D.h"
  3. #include "THStack.h"
  4. #include "TGraph.h"
  5. #include "TTree.h"
  6. #include "TChain.h"
  7. #include "TFile.h"
  8. #include "TCanvas.h"
  9. #include "TROOT.h"
  10. #include "TStyle.h"
  11. #include "TColor.h"
  12. #include "TLorentzVector.h"
  13. #include "TRandom3.h"
  14. #include "TLorentzVector.h"
  15. #include "RooDataHist.h"
  16. #include "RooRealVar.h"
  17. #include "RooPlot.h"
  18. #include "RooGaussian.h"
  19. #include "RooExponential.h"
  20. #include "RooRealConstant.h"
  21. #include "RooAddPdf.h"
  22. #include "RooFitResult.h"
  23. #include "RooProduct.h"
  24. #include "RooCrystalBall.h"
  25. #include "RooBreitWigner.h"
  26. #include "RooArgSet.h"
  27. #include "RooFFTConvPdf.h"
  28. #include "RooNovosibirsk.h"
  29. #include <string>
  30. #include <iostream>
  31. #include <cmath>
  32. const int nBins = 70;
  33. const Double_t MASS_HIST_MIN = 5100.;
  34. const Double_t MASS_HIST_MAX = 6000.;
  35. const Double_t MASS_HIST_FIT_MIN = 5100.;
  36. const Double_t MASS_HIST_FIT_MAX = 6000.;
  37. void CreateRooFitAndDraw(TH1D *hist, const char *title, const char *x_axis);
  38. int analysis_turbo()
  39. {
  40. // std::string title{"Hlt2RD_B0ToKpPimMuMu"};
  41. // std::string x_axis{"m(#pi^{+}_{(#rightarrow K^{+})} #pi^{-} #mu^{+}#mu^{-})"};
  42. std::string title{"Hlt2RD_BuToKpMuMu"};
  43. std::string x_axis{"m(#pi^{+}_{(#rightarrow K^{+})}#mu^{+}#mu^{-})"};
  44. TChain *data_chain = new TChain(TString::Format("%s/DecayTree", title.c_str()).Data());
  45. data_chain->Add("/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/Collision23_Beam6800GeV-VeloClosed-MagDown-Excl-UT_RealData_SprucingPass23r1_94000000_RD.root");
  46. Double_t B_M, Jpsi_M, B0_M, Kst_M;
  47. Bool_t Hlt1TrackMVADecision, Hlt1TwoTrackMVADecision;
  48. if (title == "Hlt2RD_B0ToKpPimMuMu")
  49. {
  50. data_chain->SetBranchAddress("B0_M", &B0_M);
  51. data_chain->SetBranchAddress("Jpsi_M", &Jpsi_M);
  52. data_chain->SetBranchAddress("Kst0_M", &Kst_M);
  53. data_chain->SetBranchAddress("Hlt1TrackMVADecision", &Hlt1TrackMVADecision);
  54. data_chain->SetBranchAddress("Hlt1TwoTrackMVADecision", &Hlt1TwoTrackMVADecision);
  55. }
  56. else
  57. {
  58. data_chain->SetBranchAddress("B_M", &B_M);
  59. data_chain->SetBranchAddress("Jpsi_M", &Jpsi_M);
  60. data_chain->SetBranchAddress("Hlt1TrackMVADecision", &Hlt1TrackMVADecision);
  61. data_chain->SetBranchAddress("Hlt1TwoTrackMVADecision", &Hlt1TwoTrackMVADecision);
  62. }
  63. TH1D *h1_B_M = new TH1D("h1_B_M", title.c_str(), nBins, MASS_HIST_MIN, MASS_HIST_MAX);
  64. h1_B_M->GetXaxis()->SetTitle(x_axis.c_str());
  65. unsigned int entries = data_chain->GetEntries();
  66. for (unsigned int i = 0; i < entries; i++)
  67. {
  68. data_chain->GetEntry(i);
  69. if (title == "Hlt2RD_B0ToKpPimMuMu")
  70. {
  71. if ((TMath::Abs(Jpsi_M - 3096.9) < 100) && (B0_M > 4500) && (B0_M < 6000) && (TMath::Abs(Kst_M - 895.55) < 50) && ((Hlt1TrackMVADecision) || (Hlt1TwoTrackMVADecision)))
  72. {
  73. h1_B_M->Fill(B0_M);
  74. }
  75. }
  76. else
  77. {
  78. if ((TMath::Abs(Jpsi_M - 3096.9) < 100.) && (B_M > 4500.) && (B_M < 6000.) && ((Hlt1TrackMVADecision) || (Hlt1TwoTrackMVADecision)))
  79. {
  80. h1_B_M->Fill(B_M);
  81. }
  82. }
  83. if (i % 10000 == 0)
  84. {
  85. std::cout << "["
  86. << title
  87. << "] Processed event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 100.) << "%)" << std::endl;
  88. }
  89. }
  90. TCanvas *c1 = new TCanvas("c1", "c1", 0, 0, 800, 600);
  91. h1_B_M->Draw();
  92. c1->Draw();
  93. c1->SaveAs(TString::Format("images/root_hist_%s_bmass.pdf", title.c_str()).Data());
  94. CreateRooFitAndDraw(h1_B_M, title.c_str(), x_axis.c_str());
  95. return 0;
  96. }
  97. void CreateRooFitAndDraw(TH1D *hist, const char *title, const char *x_axis)
  98. {
  99. RooRealVar roo_var_mass("var_mass", "B Mass Variable", MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX);
  100. roo_var_mass.setRange("fitting_range", MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX);
  101. RooDataHist roohist_B_M("roohist_B_M", "B Mass Histogram", roo_var_mass, RooFit::Import(*hist));
  102. RooPlot *roo_frame_mass = roo_var_mass.frame(RooFit::Title(title));
  103. roohist_B_M.plotOn(roo_frame_mass, RooFit::Binning(nBins), RooFit::Name("B Mass Distribution"));
  104. roo_frame_mass->GetXaxis()->SetTitle(x_axis);
  105. TCanvas *c = new TCanvas("roofit_c", "roofit_c", 0, 0, 800, 600);
  106. roo_frame_mass->Draw();
  107. TLegend *leg1 = new TLegend(0.65, 0.7, 0.87, 0.8);
  108. leg1->SetFillColor(kWhite);
  109. leg1->SetLineColor(kBlack);
  110. leg1->AddEntry((TObject*)0, TString::Format("Entries: %d", (int)hist->GetEntries()), "");
  111. leg1->Draw();
  112. c->Draw();
  113. c->SaveAs(TString::Format("images/roofit_hist_%s_bmass.pdf", title).Data());
  114. }