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.

238 lines
6.5 KiB

  1. #ifndef HLT1_DECISION_ANALYSIS
  2. #define HLT1_DECISION_ANALYSIS
  3. #include <string>
  4. #include <iostream>
  5. #include <cmath>
  6. #include <algorithm>
  7. #include <filesystem>
  8. #include <string_view>
  9. struct Hlt1Decision
  10. {
  11. std::string name;
  12. int index;
  13. Bool_t value;
  14. std::string GetName() const
  15. {
  16. return TString::Format("Hlt1%sDecision", name.c_str()).Data();
  17. }
  18. Bool_t *GetValuePointer()
  19. {
  20. return &value;
  21. }
  22. };
  23. std::vector<Hlt1Decision> Hlt1Decisions{
  24. Hlt1Decision{"DiMuonHighMass", 1},
  25. Hlt1Decision{"DiMuonLowMass", 2},
  26. Hlt1Decision{"DiMuonNoIP", 3},
  27. Hlt1Decision{"DiMuonSoft", 4},
  28. Hlt1Decision{"DisplacedLeptons", 5},
  29. Hlt1Decision{"LowPtDiMuon", 6},
  30. Hlt1Decision{"LowPtMuon", 7},
  31. Hlt1Decision{"OneMuonTrackLine", 8},
  32. Hlt1Decision{"SingleHighEt", 9},
  33. Hlt1Decision{"SingleHighPtMuon", 10},
  34. Hlt1Decision{"TrackMVA", 11},
  35. Hlt1Decision{"TrackMuonMVA", 12},
  36. Hlt1Decision{"TwoTrackMVA", 13},
  37. };
  38. struct Hlt1DecisionPlot
  39. {
  40. std::string name;
  41. bool exclusive;
  42. std::set<std::string> lines;
  43. };
  44. const std::vector<Hlt1DecisionPlot>
  45. Hlt1DecisionSets{
  46. Hlt1DecisionPlot{"mva_excl", true, std::set<std::string>{"TwoTrackMVA", "TrackMuonMVA", "TrackMVA"}},
  47. Hlt1DecisionPlot{"mva_incl", false, std::set<std::string>{"TwoTrackMVA", "TrackMuonMVA", "TrackMVA"}},
  48. Hlt1DecisionPlot{"pt_excl", true, std::set<std::string>{"LowPtMuon", "LowPtDiMuon", "DisplacedLeptons"}},
  49. Hlt1DecisionPlot{"pt_incl", false, std::set<std::string>{"LowPtMuon", "LowPtDiMuon", "DisplacedLeptons"}},
  50. Hlt1DecisionPlot{"dimu_excl", true, std::set<std::string>{"DiMuonNoIP", "DiMuonLowMass", "DiMuonHighMass"}},
  51. Hlt1DecisionPlot{"dimu_incl", false, std::set<std::string>{"DiMuonNoIP", "DiMuonLowMass", "DiMuonHighMass"}},
  52. Hlt1DecisionPlot{"mvapt_incl", false, std::set<std::string>{"TwoTrackMVA", "TrackMuonMVA", "TrackMVA", "LowPtMuon", "LowPtDiMuon", "DisplacedLeptons"}},
  53. Hlt1DecisionPlot{"mvadimu_incl", false, std::set<std::string>{"TwoTrackMVA", "TrackMuonMVA", "TrackMVA", "DiMuonNoIP", "DiMuonLowMass", "DiMuonHighMass"}},
  54. Hlt1DecisionPlot{"mvadimupt_incl", false, std::set<std::string>{"TwoTrackMVA", "TrackMuonMVA", "TrackMVA", "LowPtMuon", "LowPtDiMuon", "DisplacedLeptons", "DiMuonNoIP", "DiMuonLowMass", "DiMuonHighMass"}},
  55. Hlt1DecisionPlot{"ptdimu_incl", false, std::set<std::string>{"LowPtMuon", "LowPtDiMuon", "DisplacedLeptons", "DiMuonNoIP", "DiMuonLowMass", "DiMuonHighMass"}},
  56. };
  57. bool CutHlt1DecisionsAnd(const std::set<std::string> &decision_list)
  58. {
  59. bool okay = true;
  60. for (const auto &var : Hlt1Decisions)
  61. {
  62. if (decision_list.find(var.name) != decision_list.end())
  63. {
  64. okay = okay && var.value;
  65. }
  66. }
  67. return okay;
  68. }
  69. bool CutHlt1DecisionsOr(const std::set<std::string> &decision_list)
  70. {
  71. bool okay = false;
  72. for (const auto &var : Hlt1Decisions)
  73. {
  74. if (decision_list.find(var.name) != decision_list.end())
  75. {
  76. okay = okay || var.value;
  77. }
  78. }
  79. return okay;
  80. }
  81. bool CutHlt1DecisionsOrOnly(const std::set<std::string> &decision_list)
  82. {
  83. bool okay = false;
  84. for (const auto &var : Hlt1Decisions)
  85. {
  86. if (decision_list.find(var.name) != decision_list.end())
  87. {
  88. okay = okay || var.value;
  89. }
  90. else
  91. {
  92. if (var.value)
  93. {
  94. okay = false;
  95. break;
  96. }
  97. }
  98. }
  99. return okay;
  100. }
  101. void ConnectHlt1Decisions(TChain *chain, TH2D *incl_hist, TH2D *excl_hist)
  102. {
  103. for (auto &var : Hlt1Decisions)
  104. {
  105. if (chain->FindBranch(var.GetName().c_str())) {
  106. chain->SetBranchAddress(var.GetName().c_str(), var.GetValuePointer());
  107. incl_hist->Fill(0., var.name.c_str(), 0.);
  108. excl_hist->Fill(0., var.name.c_str(), 0.);
  109. }
  110. }
  111. }
  112. void CheckHlt1Decisioins(TH2D *incl_hist, TH2D *excl_hist, std::map<std::string, int> &exclusive_hits, const double reco_mass)
  113. {
  114. for (const auto &var : Hlt1Decisions)
  115. {
  116. if (var.value)
  117. {
  118. incl_hist->Fill(reco_mass, var.name.c_str(), 1);
  119. }
  120. }
  121. bool exclusive = true;
  122. std::string line{};
  123. for (const auto &var : Hlt1Decisions)
  124. {
  125. if (var.value)
  126. {
  127. if (!line.empty())
  128. {
  129. exclusive = false;
  130. }
  131. line = var.name;
  132. }
  133. }
  134. if (!line.empty() && exclusive)
  135. {
  136. int &hits = exclusive_hits[line];
  137. if (hits)
  138. {
  139. hits += 1;
  140. }
  141. else
  142. {
  143. hits = 1;
  144. }
  145. excl_hist->Fill(reco_mass, line.c_str(), 1);
  146. }
  147. }
  148. std::vector<TH1D *> CreateHlt1DecisionHistos(const char *analysis_name)
  149. {
  150. std::vector<TH1D *> histos{};
  151. for (int i = 0; i < Hlt1DecisionSets.size(); i++)
  152. {
  153. TH1D *h1_B_Mass_hlt1 = new TH1D(TString::Format("h1_B_Mass_hlt1_%s", Hlt1DecisionSets[i].name.c_str()), TString::Format("(%s) (%s)", Hlt1DecisionSets[i].name.c_str(), analysis_name), B_MASS_HIST_BINS, B_MASS_VAR_MIN, B_MASS_VAR_MAX);
  154. histos.push_back(h1_B_Mass_hlt1);
  155. }
  156. return histos;
  157. }
  158. void FillHlt1DecisionHistos(std::vector<TH1D *> histos, double reco_mass)
  159. {
  160. for (int i = 0; i < Hlt1DecisionSets.size(); i++)
  161. {
  162. if (Hlt1DecisionSets[i].exclusive)
  163. {
  164. if (CutHlt1DecisionsOrOnly(Hlt1DecisionSets[i].lines))
  165. {
  166. histos[i]->Fill(reco_mass);
  167. }
  168. }
  169. else
  170. {
  171. if (CutHlt1DecisionsOr(Hlt1DecisionSets[i].lines))
  172. {
  173. histos[i]->Fill(reco_mass);
  174. }
  175. }
  176. }
  177. }
  178. void DrawHlt1DecisionHistos(const char *folder, std::vector<TH1D *> histos)
  179. {
  180. std::filesystem::create_directory(TString::Format("output_files/analysis/%s", folder).Data());
  181. TString name = TString::Format("%s_canvas", "hlt1_decisions");
  182. TCanvas *c = new TCanvas(name, "HLT 1 Decisions", 0, 0, 1200, 700);
  183. c->Divide(4, 3);
  184. for (int i = 0; i < histos.size(); i++)
  185. {
  186. c->cd(i + 1);
  187. histos[i]->SetStats(0);
  188. histos[i]->Draw();
  189. TLegend *leg1 = new TLegend(0.58, 0.89 - (0.05 * (Hlt1DecisionSets[i].lines.size() + (int)(Hlt1DecisionSets[i].lines.size() / 3))), 0.88, 0.89);
  190. leg1->SetFillStyle(0);
  191. leg1->SetLineStyle(0);
  192. leg1->SetMargin(0.1);
  193. int index = 1;
  194. std::for_each(Hlt1DecisionSets[i].lines.begin(), Hlt1DecisionSets[i].lines.end(), [leg1, i, &index](std::string s)
  195. {
  196. leg1->AddEntry((TObject *)0, s.c_str(), "");
  197. if (index != Hlt1DecisionSets[i].lines.size() && index % 3 == 0) {
  198. leg1->AddEntry((TObject *)0, "", "");
  199. }
  200. index++; });
  201. leg1->AddEntry((TObject *)0, TString::Format("# Entries: %d", (int)histos[i]->GetEntries()), "");
  202. leg1->Draw();
  203. }
  204. c->Draw();
  205. c->SaveAs(TString::Format("output_files/analysis/%s/%s.pdf", folder, name.Data()).Data());
  206. }
  207. #endif