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.

195 lines
4.6 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
  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. TH1 *_histogram = nullptr;
  37. public:
  38. DrawVar(std::string identifier, TVar min, TVar max)
  39. : _identifier{identifier}, _min{min}, _max{max}
  40. {
  41. }
  42. std::string getId()
  43. {
  44. return _identifier;
  45. }
  46. const char *getIdStr()
  47. {
  48. return _identifier.c_str();
  49. }
  50. TVar getMin()
  51. {
  52. return _min;
  53. }
  54. TVar getMax()
  55. {
  56. return _max;
  57. }
  58. TVar *getValuePointer()
  59. {
  60. return &_value;
  61. }
  62. TVar getValue()
  63. {
  64. return _value;
  65. }
  66. TH1 *getHist()
  67. {
  68. return _histogram;
  69. }
  70. void setHist(TH1D *hist)
  71. {
  72. _histogram = hist;
  73. }
  74. };
  75. int general_cuts()
  76. {
  77. // just some plotting options
  78. gROOT->SetStyle("Plain");
  79. TPad foo;
  80. const int NRGBs = 5;
  81. const int NCont = 250;
  82. double stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
  83. double red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
  84. double green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
  85. double blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
  86. TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
  87. gStyle->SetNumberContours(NCont);
  88. gStyle->SetLabelFont(132, "xyz");
  89. gStyle->SetTitleFont(132, "xyz");
  90. gStyle->SetLegendFont(132);
  91. gStyle->SetStatFont(132);
  92. gStyle->SetEndErrorSize(10.0);
  93. gStyle->SetOptStat(0);
  94. gStyle->SetOptFit(0);
  95. std::vector<DrawVar<Float_t>> float_vars{
  96. DrawVar<Float_t>("B0_PT", 0., 20000.)};
  97. std::vector<DrawVar<Double_t>> double_vars{
  98. };
  99. // files to load
  100. std::vector<std::string> filenames =
  101. {
  102. "./B0ToKpPimMuMu_Collision23_Beam6800GeV-VeloClosed-MagDown-Excl-UT_RealData_Sprucing23r1_90000000_RD.root"};
  103. TChain *chain = new TChain("SpruceRD_B0ToKpPimMuMu/DecayTree");
  104. for (unsigned int i = 0; i < filenames.size(); i++)
  105. {
  106. chain->Add(filenames.at(i).c_str());
  107. }
  108. Double_t B0_M;
  109. chain->SetBranchAddress("B0_M", &B0_M);
  110. TH1D *h1_B0_M = new TH1D("h1_B0_M", "B+ Mass", nBins, 4500, 7500);
  111. for (size_t i = 0; i < float_vars.size(); i++)
  112. {
  113. chain->SetBranchAddress(float_vars[i].getIdStr(), float_vars[i].getValuePointer());
  114. float_vars[i].setHist(new TH1D(TString::Format("h1_%s", float_vars[i].getIdStr()).Data(), float_vars[i].getIdStr(), nBins, float_vars[i].getMin(), float_vars[i].getMax()));
  115. }
  116. for (size_t i = 0; i < double_vars.size(); i++)
  117. {
  118. chain->SetBranchAddress(double_vars[i].getIdStr(), double_vars[i].getValuePointer());
  119. double_vars[i].setHist(new TH1D(TString::Format("h1_%s", double_vars[i].getIdStr()).Data(), double_vars[i].getIdStr(), nBins, double_vars[i].getMin(), double_vars[i].getMax()));
  120. }
  121. unsigned int entries = chain->GetEntries();
  122. // loop over all entries in the tree
  123. for (unsigned int i = 0; i < entries; i++)
  124. {
  125. chain->GetEntry(i);
  126. h1_B0_M->Fill(B0_M);
  127. for (size_t i = 0; i < float_vars.size(); i++)
  128. {
  129. float_vars[i].getHist()->Fill(float_vars[i].getValue());
  130. }
  131. for (size_t i = 0; i < double_vars.size(); i++)
  132. {
  133. double_vars[i].getHist()->Fill(double_vars[i].getValue());
  134. }
  135. }
  136. TCanvas *c1 = new TCanvas("c1", "Canvas 1", 0, 0, 800, 600);
  137. h1_B0_M->Draw();
  138. c1->Draw();
  139. if (float_vars.size() > 0)
  140. {
  141. TCanvas *c2 = new TCanvas("c2", "Canvas 2", 0, 0, 1200, 600);
  142. c2->Divide(4, 2);
  143. for (size_t i = 0; i < float_vars.size(); i++)
  144. {
  145. c2->cd(i + 1);
  146. float_vars[i].getHist()->Draw();
  147. }
  148. c2->Draw();
  149. }
  150. if (double_vars.size() > 0)
  151. {
  152. TCanvas *c3 = new TCanvas("c3", "Canvas 3", 0, 0, 1200, 600);
  153. c3->Divide(4, 2);
  154. for (size_t i = 0; i < double_vars.size(); i++)
  155. {
  156. c3->cd(i + 1);
  157. double_vars[i].getHist()->Draw();
  158. }
  159. c3->Draw();
  160. }
  161. return 0;
  162. }