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.

282 lines
7.0 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
  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 <string>
  26. #include <iostream>
  27. const int nBins = 200;
  28. template <typename TVar>
  29. class DrawVar
  30. {
  31. private:
  32. std::string _identifier;
  33. TVar _min;
  34. TVar _max;
  35. TVar _value = TVar{};
  36. TVar _cutAt = 0;
  37. bool _applyCut = false;
  38. TH1 *_histogram = nullptr;
  39. TH1 *_bkgHistogram = nullptr;
  40. public:
  41. DrawVar(std::string identifier, TVar min, TVar max)
  42. : _identifier{identifier}, _min{min}, _max{max}
  43. {
  44. }
  45. DrawVar(std::string identifier, TVar min, TVar max, TVar cutAt)
  46. : DrawVar(identifier, min, max)
  47. {
  48. _cutAt = cutAt;
  49. _applyCut = true;
  50. }
  51. std::string getId()
  52. {
  53. return _identifier;
  54. }
  55. const char *getIdStr()
  56. {
  57. return _identifier.c_str();
  58. }
  59. TVar getMin()
  60. {
  61. return _min;
  62. }
  63. TVar getMax()
  64. {
  65. return _max;
  66. }
  67. TVar *getValuePointer()
  68. {
  69. return &_value;
  70. }
  71. TVar getValue()
  72. {
  73. return _value;
  74. }
  75. bool cutAccepted()
  76. {
  77. if (!_applyCut)
  78. {
  79. return true;
  80. }
  81. return _value > _cutAt;
  82. }
  83. void initHistograms()
  84. {
  85. _histogram = new TH1D(TString::Format("h1_%s", this->getIdStr()).Data(), this->getIdStr(), nBins, _min, _max);
  86. _bkgHistogram = new TH1D(TString::Format("h1_bkg_%s", this->getIdStr()).Data(), this->getIdStr(), nBins, _min, _max);
  87. _bkgHistogram->SetLineColor(kRed);
  88. }
  89. TH1 *getHist()
  90. {
  91. return _histogram;
  92. }
  93. TH1 *getBkgHist()
  94. {
  95. return _bkgHistogram;
  96. }
  97. };
  98. int general_cuts()
  99. {
  100. // just some plotting options
  101. gROOT->SetStyle("Plain");
  102. TPad foo;
  103. const int NRGBs = 5;
  104. const int NCont = 250;
  105. double stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
  106. double red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
  107. double green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
  108. double blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
  109. TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
  110. gStyle->SetNumberContours(NCont);
  111. gStyle->SetLabelFont(132, "xyz");
  112. gStyle->SetTitleFont(132, "xyz");
  113. gStyle->SetLegendFont(132);
  114. gStyle->SetStatFont(132);
  115. gStyle->SetEndErrorSize(10.0);
  116. gStyle->SetOptStat(0);
  117. gStyle->SetOptFit(0);
  118. // Selectoin
  119. // Pre-Selection Cut-Based
  120. // IP Tochter, PT Tochter, FDCHI2 B, PT B
  121. // PID isMuon, PID K
  122. std::vector<DrawVar<Float_t>> float_vars{
  123. DrawVar<Float_t>("B0_PT", 0., 7000.),
  124. DrawVar<Float_t>("B0_FDCHI2_OWNPV", 0., 500., 15.),
  125. DrawVar<Float_t>("JPsi_PT", 0., 6000.),
  126. DrawVar<Float_t>("JPsi_IP_OWNPV", 0., 2., 0.15),
  127. DrawVar<Float_t>("Kstar0_PT", 0., 3500.),
  128. DrawVar<Float_t>("Kstar0_IP_OWNPV", 0., 3., 0.15),
  129. DrawVar<Float_t>("Kplus_PT", 0., 2000., 400.),
  130. DrawVar<Float_t>("Kplus_IP_OWNPV", 0., 3., 0.15),
  131. DrawVar<Float_t>("piminus_PT", 0., 2000., 200.),
  132. DrawVar<Float_t>("piminus_IP_OWNPV", 0., 3., 0.15)};
  133. std::vector<DrawVar<Double_t>> double_vars{
  134. DrawVar<Double_t>("JPsi_M", 400., 5000.)
  135. };
  136. // files to load
  137. std::vector<std::string> filenames =
  138. {
  139. "./B0ToKpPimMuMu_Collision23_Beam6800GeV-VeloClosed-MagDown-Excl-UT_RealData_Sprucing23r1_90000000_RD.root"};
  140. TChain *chain = new TChain("SpruceRD_B0ToKpPimMuMu/DecayTree");
  141. for (unsigned int i = 0; i < filenames.size(); i++)
  142. {
  143. chain->Add(filenames.at(i).c_str());
  144. }
  145. Double_t B0_M;
  146. chain->SetBranchAddress("B0_M", &B0_M);
  147. TH1D *h1_B0_M = new TH1D("h1_B0_M", "B+ Mass", nBins, 4500, 7500);
  148. TH1D *h1_bkg_B0_M = new TH1D("h1_bkg_B0_M", "B+ Mass Bkg", nBins, 4500, 7500);
  149. for (size_t i = 0; i < float_vars.size(); i++)
  150. {
  151. chain->SetBranchAddress(float_vars[i].getIdStr(), float_vars[i].getValuePointer());
  152. float_vars[i].initHistograms();
  153. }
  154. for (size_t i = 0; i < double_vars.size(); i++)
  155. {
  156. chain->SetBranchAddress(double_vars[i].getIdStr(), double_vars[i].getValuePointer());
  157. double_vars[i].initHistograms();
  158. }
  159. unsigned int entries = chain->GetEntries();
  160. // loop over all entries in the tree
  161. for (unsigned int i = 0; i < entries; i++)
  162. {
  163. chain->GetEntry(i);
  164. bool cutAccepted = true;
  165. for (size_t i = 0; i < float_vars.size(); i++)
  166. {
  167. cutAccepted = cutAccepted && float_vars[i].cutAccepted();
  168. }
  169. for (size_t i = 0; i < double_vars.size(); i++)
  170. {
  171. cutAccepted = cutAccepted && double_vars[i].cutAccepted();
  172. }
  173. if (cutAccepted)
  174. {
  175. h1_B0_M->Fill(B0_M);
  176. }
  177. else
  178. {
  179. h1_bkg_B0_M->Fill(B0_M);
  180. }
  181. if (B0_M > 5500.)
  182. {
  183. for (size_t i = 0; i < float_vars.size(); i++)
  184. {
  185. float_vars[i].getBkgHist()->Fill(float_vars[i].getValue());
  186. }
  187. for (size_t i = 0; i < double_vars.size(); i++)
  188. {
  189. double_vars[i].getBkgHist()->Fill(double_vars[i].getValue());
  190. }
  191. }
  192. else
  193. {
  194. for (size_t i = 0; i < float_vars.size(); i++)
  195. {
  196. float_vars[i].getHist()->Fill(float_vars[i].getValue());
  197. }
  198. for (size_t i = 0; i < double_vars.size(); i++)
  199. {
  200. double_vars[i].getHist()->Fill(double_vars[i].getValue());
  201. }
  202. }
  203. }
  204. TCanvas *c1 = new TCanvas("c1", "Canvas 1", 0, 0, 800, 600);
  205. h1_bkg_B0_M->SetLineColor(kRed);
  206. if (h1_bkg_B0_M->GetMaximum() >= h1_B0_M->GetMaximum())
  207. {
  208. h1_bkg_B0_M->Draw();
  209. h1_B0_M->Draw("SAME");
  210. }
  211. else
  212. {
  213. h1_B0_M->Draw();
  214. h1_bkg_B0_M->Draw("SAME");
  215. }
  216. c1->Draw();
  217. if (float_vars.size() > 0)
  218. {
  219. TCanvas *c2 = new TCanvas("c2", "Canvas 2", 0, 0, 1200, 600);
  220. c2->Divide(4, 3);
  221. for (size_t i = 0; i < float_vars.size(); i++)
  222. {
  223. c2->cd(i + 1);
  224. float_vars[i].getHist()->Draw();
  225. float_vars[i].getBkgHist()->Draw("SAME");
  226. }
  227. c2->Draw();
  228. }
  229. if (double_vars.size() > 0)
  230. {
  231. TCanvas *c3 = new TCanvas("c3", "Canvas 3", 0, 0, 1200, 600);
  232. c3->Divide(4, 3);
  233. for (size_t i = 0; i < double_vars.size(); i++)
  234. {
  235. c3->cd(i + 1);
  236. double_vars[i].getHist()->Draw();
  237. double_vars[i].getBkgHist()->Draw("SAME");
  238. }
  239. c3->Draw();
  240. }
  241. return 0;
  242. }