TTTT_Analysis.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /**
  2. * @file
  3. * @author Caleb Fangmeier <caleb@fangmeier.tech>
  4. * @version 0.1
  5. *
  6. * @section LICENSE
  7. *
  8. *
  9. * MIT License
  10. *
  11. * Copyright (c) 2017 Caleb Fangmeier
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining a copy
  14. * of this software and associated documentation files (the "Software"), to deal
  15. * in the Software without restriction, including without limitation the rights
  16. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17. * copies of the Software, and to permit persons to whom the Software is
  18. * furnished to do so, subject to the following conditions:
  19. *
  20. * The above copyright notice and this permission notice shall be included in all
  21. * copies or substantial portions of the Software.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  29. * SOFTWARE.
  30. *
  31. * @section DESCRIPTION
  32. * Main analysis routine file. This file declares the Histogram/Graph objects
  33. * that will end up in the final root file. It also declares the values that
  34. * are used to populate the histogram, as well as how these values are
  35. * calculated. See the Fil-Val documentation for how the system works.
  36. */
  37. #include <iostream>
  38. #include <vector>
  39. #include <tuple>
  40. #include <utility>
  41. #include <limits>
  42. #include "filval/filval.hpp"
  43. #include "filval_root/filval_root.hpp"
  44. #include "MiniTreeDataSet.hpp"
  45. #include <TSystem.h>
  46. using namespace std;
  47. using namespace fv;
  48. using namespace fv::root;
  49. void enable_branches(MiniTreeDataSet& mt){
  50. mt.fChain->SetBranchStatus("*", false);
  51. mt.track_branch<int>("nLepGood");
  52. mt.track_branch_vec<float>("nLepGood", "LepGood_pt");
  53. mt.track_branch_vec<float>("nLepGood", "LepGood_eta");
  54. mt.track_branch_vec<float>("nLepGood", "LepGood_phi");
  55. mt.track_branch_vec<float>("nLepGood", "LepGood_mass");
  56. mt.track_branch_vec<float>("nLepGood", "LepGood_mcPt");
  57. mt.track_branch_vec<int>("nLepGood", "LepGood_charge");
  58. mt.track_branch<int>("nJet");
  59. mt.track_branch_vec<float>("nJet", "Jet_pt");
  60. mt.track_branch_vec<float>("nJet", "Jet_eta");
  61. mt.track_branch_vec<float>("nJet", "Jet_phi");
  62. mt.track_branch_vec<float>("nJet", "Jet_mass");
  63. mt.track_branch_vec<float>("nJet", "Jet_btagCMVA");
  64. mt.track_branch<int>("nGenTop");
  65. mt.track_branch_vec<int>("nGenTop", "GenTop_pdgId");
  66. mt.track_branch<int>("nGenPart");
  67. mt.track_branch_vec<int>("nGenPart", "GenPart_pdgId");
  68. mt.track_branch_vec<int>("nGenPart", "GenPart_motherIndex");
  69. mt.track_branch_vec<float>("nGenPart", "GenPart_pt");
  70. mt.track_branch_vec<float>("nGenPart", "GenPart_eta");
  71. mt.track_branch_vec<float>("nGenPart", "GenPart_phi");
  72. mt.track_branch_vec<float>("nGenPart", "GenPart_mass");
  73. /*
  74. GenPart_motherId : Int_t pdgId of the mother of the particle for Hard scattering particles, with ancestry and links
  75. GenPart_grandmotherId : Int_t pdgId of the grandmother of the particle for Hard scattering particles, with ancestry and links
  76. GenPart_sourceId : Int_t origin of the particle (heaviest ancestor) : 6=t, 25=h, 23/24=W/Z for Hard scattering particles, with ancestry and links
  77. GenPart_charge : Float_t charge for Hard scattering particles, with ancestry and links
  78. GenPart_status : Int_t status for Hard scattering particles, with ancestry and links
  79. GenPart_isPromptHard : Int_t isPromptHard for Hard scattering particles, with ancestry and links
  80. GenPart_pdgId : Int_t pdgId for Hard scattering particles, with ancestry and links
  81. GenPart_pt : Float_t pt for Hard scattering particles, with ancestry and links
  82. GenPart_eta : Float_t eta for Hard scattering particles, with ancestry and links
  83. GenPart_phi : Float_t phi for Hard scattering particles, with ancestry and links
  84. GenPart_mass : Float_t mass for Hard scattering particles, with ancestry and links
  85. GenPart_motherIndex : Int_t index of the mother in the generatorSummary for Hard scattering particles, with ancestry and links
  86. */
  87. mt.track_branch<int>("ngenLep");
  88. mt.track_branch_vec<int>("ngenLep", "genLep_sourceId");
  89. mt.track_branch_vec<float>("ngenLep", "genLep_pt");
  90. mt.track_branch<int>("nVert");
  91. }
  92. void declare_values(MiniTreeDataSet& mt){
  93. energies(lorentz_vectors("LepGood_pt", "LepGood_eta", "LepGood_phi", "LepGood_mass", "LepGood_4v"), "LepGood_energy");
  94. energies(lorentz_vectors("GenPart_pt", "GenPart_eta", "GenPart_phi", "GenPart_mass", "GenPart_4v"), "GenPart_energy");
  95. fv::pair<vector<float>,vector<float>>("LepGood_energy", "LepGood_pt", "LepGood_energy_LepGood_pt");
  96. max<float>("LepGood_energy", "LepGood_energy_max");
  97. min<float>("LepGood_energy", "LepGood_energy_min");
  98. range<float>("LepGood_energy", "LepGood_energy_range");
  99. mean<float>("LepGood_energy", "LepGood_energy_mean");
  100. count<float>(GenFunction::register_function<bool(float)>("bJet_Selection", FUNC(([](float x){return x>0;}))),
  101. "Jet_btagCMVA", "b_jet_count");
  102. filter("trilepton", FUNC(([nLepGood=lookup<int>("nLepGood")](){
  103. return dynamic_cast<Value<int>*>(nLepGood)->get_value() == 3;})));
  104. filter("os-dilepton", FUNC(([LepGood_charge=lookup<vector<int>>("LepGood_charge")](){
  105. auto& charges = LepGood_charge->get_value();
  106. return charges.size()==2 && (charges[0] != charges[1]);})));
  107. filter("ss-dilepton", FUNC(([LepGood_charge=lookup<vector<int>>("LepGood_charge")](){
  108. auto& charges = LepGood_charge->get_value();
  109. return charges.size()==2 && (charges[0] == charges[1]); })));
  110. }
  111. void declare_containers(MiniTreeDataSet& mt){
  112. mt.register_container(new ContainerTH1<int>("lepton_count", "Lepton Multiplicity", lookup<int>("nLepGood"), 8, 0, 8));
  113. mt.register_container(new ContainerTH1<int>("top_quark_count", "Top Quark Multiplicity", lookup<int>("nGenTop"), 8, 0, 8));
  114. mt.register_container(new ContainerTH1Many<float>("LepGood_energy_all", "Lepton Energy - All",
  115. lookup<vector<float>>("LepGood_energy"), 50, 0, 500));
  116. mt.register_container(new ContainerTH1<float>("LepGood_energy_max", "Lepton Energy - Max",
  117. lookup<float>("LepGood_energy_max"), 50, 0, 500,
  118. "Lepton Energy Max(GeV)"));
  119. mt.register_container(new ContainerTH1<float>("LepGood_energy_min", "Lepton Energy - Min",
  120. lookup<float>("LepGood_energy_min"), 50, 0, 500,
  121. "Lepton Energy Min(GeV)"));
  122. mt.register_container(new ContainerTH1<float>("LepGood_energy_range", "Lepton Energy - Range",
  123. lookup<float>("LepGood_energy_range"), 50, 0, 500,
  124. "Lepton Energy Range(GeV)"));
  125. mt.register_container(new ContainerTGraph("nLepvsnJet", "Number of Leptons vs Number of Jets",
  126. fv::pair<int, int>("nLepGood", "nJet") ));
  127. mt.register_container(new ContainerTH2Many<float>("LepGood_energy_vs_pt", "Lepton Energy vs Lepton Pt",
  128. lookup<std::pair<std::vector<float>,std::vector<float>>>("LepGood_energy_LepGood_pt"),
  129. 50, 0, 500, 50, 0, 500,
  130. "lepton energy","lepton Pt"));
  131. mt.register_container(new ContainerTH1<int>("b_jet_count", "B-Jet Multiplicity", lookup<int>("b_jet_count"), 10, 0, 10));
  132. mt.register_container(new ContainerTH1<int>("jet_count_os_dilepton", "Jet Multiplicity - OS Dilepton Events",
  133. lookup<int>("nJet"), 14, 0, 14));
  134. mt.get_container("jet_count_os_dilepton")->add_filter(lookup_filter("os-dilepton"));
  135. mt.register_container(new ContainerTH1<int>("jet_count_ss_dilepton", "Jet Multiplicity - SS Dilepton Events",
  136. lookup<int>("nJet"), 14, 0, 14));
  137. mt.get_container("jet_count_ss_dilepton")->add_filter(lookup_filter("ss-dilepton"));
  138. mt.register_container(new ContainerTH1<int>("jet_count_trilepton", "Jet Multiplicity - Trilepton Events",
  139. lookup<int>("nJet"), 14, 0, 14));
  140. mt.get_container("jet_count_trilepton")->add_filter(lookup_filter("trilepton"));
  141. mt.register_container(new ContainerTH1<int>("primary_vert_count", "Number of Primary Vertices",
  142. lookup<int>("nVert"), 50, 0, 50));
  143. mt.register_container(new CounterMany<int>("GenTop_pdg_id", lookup<vector<int>>("GenTop_pdgId")));
  144. mt.register_container(new CounterMany<int>("GenPart_pdg_id", lookup<vector<int>>("GenPart_pdgId")));
  145. mt.register_container(new Vector<vector<int>>("GenPart_pdgId", lookup<vector<int>>("GenPart_pdgId")));
  146. mt.register_container(new Vector<vector<int>>("GenPart_motherIndex", lookup<vector<int>>("GenPart_motherIndex")));
  147. mt.register_container(new Vector<vector<float>>("GenPart_pt", lookup<vector<float>>("GenPart_pt")));
  148. mt.register_container(new Vector<vector<float>>("GenPart_energy", lookup<vector<float>>("GenPart_energy")));
  149. }
  150. void run_analysis(const std::string& input_filename, bool silent){
  151. gSystem->Load("libfilval.so");
  152. auto replace_suffix = [](const std::string& input, const std::string& new_suffix){
  153. return input.substr(0, input.find_last_of(".")) + new_suffix;
  154. };
  155. string log_filename = replace_suffix(input_filename, "_result.log");
  156. fv::util::Log::init_logger(log_filename, fv::util::LogPriority::kLogDebug);
  157. string output_filename = replace_suffix(input_filename, "_result.root");
  158. MiniTreeDataSet mt(input_filename, output_filename);
  159. enable_branches(mt);
  160. declare_values(mt);
  161. declare_containers(mt);
  162. mt.process(silent);
  163. mt.save_all();
  164. }
  165. int main(int argc, char * argv[])
  166. {
  167. fv::util::ArgParser args(argc, argv);
  168. if(!args.cmdOptionExists("-f")) {
  169. cout << "Usage: ./main -f input_minitree.root" << endl;
  170. return -1;
  171. }
  172. bool silent = args.cmdOptionExists("-s");
  173. string input_filename = args.getCmdOption("-f");
  174. run_analysis(input_filename, silent);
  175. }