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.

192 lines
7.7 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 "TLegend.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 = 4500.;
  34. const Double_t MASS_HIST_MAX = 7000.;
  35. const Double_t MASS_HIST_FIT_MIN = 4500.;
  36. const Double_t MASS_HIST_FIT_MAX = 7000.;
  37. void CreateRooFitAndDraw(TH1D *hist, const char *title);
  38. int analysis_fullstream()
  39. {
  40. std::string title {"SpruceRD_BuToHpMuMu"};
  41. TChain *data_chain = new TChain("BuToHpMuMu/DecayTree");
  42. // data_chain->Add("/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/Collision23_Beam6800GeV-VeloClosed-MagDown-Excl-UT_RealData_Sprucing23r1_90000000_RD.root");
  43. data_chain->Add("/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/spruce_magdown_2023_v0r1_tuple_90000000_2023_v0r0p6288631.root");
  44. // data_chain->Add("/auto/data/pfeiffer/inclusive_detached_dilepton/data_samples/spruce_magdown_2023_v0_tuple_90000000_v0r0p6288631.root");
  45. Float_t B_BPVFDCHI2,
  46. B_BPVIPCHI2,
  47. L1_BPVIPCHI2,
  48. L2_BPVIPCHI2,
  49. L1_PT,
  50. L2_PT,
  51. Jpsi_BPVFDCHI2,
  52. Hp_PT,
  53. Hp_BPVIPCHI2,
  54. Hp_P;
  55. Double_t L1_PID_MU,
  56. L2_PID_MU,
  57. B_CHI2VXNDOF,
  58. Jpsi_MAXDOCACHI2,
  59. Jpsi_CHI2DOF,
  60. Hp_PID_K,
  61. Jpsi_M,
  62. B_M;
  63. Bool_t L1_ISMUON,
  64. L2_ISMUON,
  65. Hlt2RD_BuToKpMuMuDecision,
  66. Hlt2_InclDetDiMuon_4BodyDecision,
  67. Hlt2_InclDetDiMuon_3BodyDecision,
  68. Hlt2_InclDetDiMuonDecision,
  69. Hlt1TrackMVADecision,
  70. Hlt1TwoTrackMVADecision;
  71. data_chain->SetBranchAddress("B_M", &B_M);
  72. data_chain->SetBranchAddress("B_BPVFDCHI2", &B_BPVFDCHI2);
  73. data_chain->SetBranchAddress("B_BPVIPCHI2", &B_BPVIPCHI2);
  74. // data_chain->SetBranchAddress("L1_BPVIPCHI2", &L1_BPVIPCHI2);
  75. // data_chain->SetBranchAddress("L2_BPVIPCHI2", &L2_BPVIPCHI2);
  76. // data_chain->SetBranchAddress("L1_PID_MU", &L1_PID_MU);
  77. // data_chain->SetBranchAddress("L2_PID_MU", &L2_PID_MU);
  78. // data_chain->SetBranchAddress("L1_ISMUON", &L1_ISMUON);
  79. // data_chain->SetBranchAddress("L2_ISMUON", &L2_ISMUON);
  80. // data_chain->SetBranchAddress("L1_PT", &L1_PT);
  81. // data_chain->SetBranchAddress("L2_PT", &L2_PT);
  82. // data_chain->SetBranchAddress("Hp_PT", &Hp_PT);
  83. // data_chain->SetBranchAddress("Hp_BPVIPCHI2", &Hp_BPVIPCHI2);
  84. // data_chain->SetBranchAddress("Hp_P", &Hp_P);
  85. // data_chain->SetBranchAddress("Hp_PID_K", &Hp_PID_K);
  86. data_chain->SetBranchAddress("L1_BPVIPCHI2", &L1_BPVIPCHI2);
  87. data_chain->SetBranchAddress("L2_BPVIPCHI2", &L2_BPVIPCHI2);
  88. data_chain->SetBranchAddress("L1_PID_MU", &L1_PID_MU);
  89. data_chain->SetBranchAddress("L2_PID_MU", &L2_PID_MU);
  90. data_chain->SetBranchAddress("L1_ISMUON", &L1_ISMUON);
  91. data_chain->SetBranchAddress("L2_ISMUON", &L2_ISMUON);
  92. data_chain->SetBranchAddress("L1_PT", &L1_PT);
  93. data_chain->SetBranchAddress("L2_PT", &L2_PT);
  94. data_chain->SetBranchAddress("B_CHI2VXNDOF", &B_CHI2VXNDOF);
  95. data_chain->SetBranchAddress("Jpsi_MAXDOCACHI2", &Jpsi_MAXDOCACHI2);
  96. data_chain->SetBranchAddress("Jpsi_CHI2DOF", &Jpsi_CHI2DOF);
  97. data_chain->SetBranchAddress("Hp_PT", &Hp_PT);
  98. data_chain->SetBranchAddress("Hp_BPVIPCHI2", &Hp_BPVIPCHI2);
  99. data_chain->SetBranchAddress("Hp_P", &Hp_P);
  100. data_chain->SetBranchAddress("Hp_PID_K", &Hp_PID_K);
  101. data_chain->SetBranchAddress("Jpsi_BPVFDCHI2", &Jpsi_BPVFDCHI2);
  102. data_chain->SetBranchAddress("Jpsi_M", &Jpsi_M);
  103. data_chain->SetBranchAddress("Hlt2RD_BuToKpMuMuDecision", &Hlt2RD_BuToKpMuMuDecision);
  104. data_chain->SetBranchAddress("Hlt2_InclDetDiMuon_4BodyDecision", &Hlt2_InclDetDiMuon_4BodyDecision);
  105. data_chain->SetBranchAddress("Hlt2_InclDetDiMuon_3BodyDecision", &Hlt2_InclDetDiMuon_3BodyDecision);
  106. data_chain->SetBranchAddress("Hlt2_InclDetDiMuonDecision", &Hlt2_InclDetDiMuonDecision);
  107. data_chain->SetBranchAddress("Hlt1TrackMVADecision", &Hlt1TrackMVADecision);
  108. data_chain->SetBranchAddress("Hlt1TwoTrackMVADecision", &Hlt1TwoTrackMVADecision);
  109. TH1D *h1_B_M = new TH1D("h1_B_M", "B Mass", nBins, MASS_HIST_MIN, MASS_HIST_MAX);
  110. unsigned int entries = data_chain->GetEntries();
  111. for (unsigned int i = 0; i < entries; i++)
  112. {
  113. data_chain->GetEntry(i);
  114. // 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) && (L2_ISMUON) && (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) && (((Hlt2_InclDetDiMuon_4BodyDecision) || (Hlt2_InclDetDiMuon_3BodyDecision) || (Hlt2_InclDetDiMuonDecision))))
  115. // {
  116. // if (TMath::Abs(Jpsi_M - 3096.9) < 100 && ((Hlt1TrackMVADecision) || (Hlt1TwoTrackMVADecision)))
  117. // {
  118. // h1_B_M->Fill(B_M);
  119. // }
  120. // }
  121. 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))))&(abs(Jpsi_M - 3096.9) < 100) & ((Hlt1TrackMVADecision==1) | (Hlt1TwoTrackMVADecision==1)))
  122. {
  123. h1_B_M->Fill(B_M);
  124. }
  125. if (i % 10000 == 0)
  126. {
  127. std::cout << "["
  128. << "SpruceRD_BuToHpMuMu"
  129. << "] Processed event: " << i << " (" << TString::Format("%.2f", ((double)i / (double)entries) * 100.) << "%)" << std::endl;
  130. }
  131. }
  132. TCanvas *c1 = new TCanvas("c1", "c1", 0, 0, 800, 600);
  133. h1_B_M->Draw();
  134. c1->Draw();
  135. c1->SaveAs(TString::Format("images/root_hist_%s_bmass.png", title.c_str()).Data());
  136. CreateRooFitAndDraw(h1_B_M, title.c_str());
  137. return 0;
  138. }
  139. void CreateRooFitAndDraw(TH1D *hist, const char *title)
  140. {
  141. RooRealVar roo_var_mass("var_mass", "B Mass Variable", MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX);
  142. roo_var_mass.setRange("fitting_range", MASS_HIST_FIT_MIN, MASS_HIST_FIT_MAX);
  143. RooDataHist roohist_B_M("roohist_B_M", "B Mass Histogram", roo_var_mass, RooFit::Import(*hist));
  144. RooPlot *roo_frame_mass = roo_var_mass.frame(RooFit::Title("SpruceRD_BuToHpMuMu"));
  145. roohist_B_M.plotOn(roo_frame_mass, RooFit::Binning(nBins), RooFit::Name("B Mass Distribution"));
  146. roo_frame_mass->GetXaxis()->SetTitle("m(#pi^{+}#mu^{+}#mu^{-})");
  147. TCanvas *c = new TCanvas("roofit_c", "roofit_c", 0, 0, 800, 600);
  148. roo_frame_mass->Draw();
  149. TLegend *leg1 = new TLegend(0.65, 0.7, 0.87, 0.8);
  150. leg1->SetFillColor(kWhite);
  151. leg1->SetLineColor(kBlack);
  152. leg1->AddEntry((TObject*)0, TString::Format("Entries: %d", (int)hist->GetEntries()), "");
  153. leg1->Draw();
  154. c->Draw();
  155. c->SaveAs(TString::Format("images/roofit_hist_%s_bmass.png", title).Data());
  156. }