TTTT_Analysis.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 "filval/filval.hpp"
  42. #include "filval_root/filval_root.hpp"
  43. #include "MiniTreeDataSet.hpp"
  44. using namespace std;
  45. using namespace fv;
  46. void enable_branches(MiniTreeDataSet& mt){
  47. mt.fChain->SetBranchStatus("*", false);
  48. mt.track_branch<int>("nLepGood");
  49. mt.track_branch_vec<float>("nLepGood", "LepGood_pt");
  50. mt.track_branch_vec<float>("nLepGood", "LepGood_eta");
  51. mt.track_branch_vec<float>("nLepGood", "LepGood_phi");
  52. mt.track_branch_vec<float>("nLepGood", "LepGood_mass");
  53. mt.track_branch_vec<float>("nLepGood", "LepGood_mcPt");
  54. mt.track_branch_vec<int>("nLepGood", "LepGood_charge");
  55. mt.track_branch<int>("nJet");
  56. mt.track_branch_vec<float>("nJet", "Jet_pt");
  57. mt.track_branch_vec<float>("nJet", "Jet_eta");
  58. mt.track_branch_vec<float>("nJet", "Jet_phi");
  59. mt.track_branch_vec<float>("nJet", "Jet_mass");
  60. mt.track_branch_vec<float>("nJet", "Jet_btagCMVA");
  61. mt.track_branch<int>("nGenTop");
  62. mt.track_branch_vec<int>("nGenTop", "GenTop_pdgId");
  63. mt.track_branch<int>("ngenLep");
  64. mt.track_branch_vec<int>("ngenLep", "genLep_sourceId");
  65. mt.track_branch_vec<float>("ngenLep", "genLep_pt");
  66. mt.track_branch<int>("nVert");
  67. }
  68. void declare_values(MiniTreeDataSet& mt){
  69. auto& get_energy = GenFunction::register_function<float(float, float, float, float)>("get_energy",
  70. FUNC(([](float pt, float eta, float phi, float mass){
  71. TLorentzVector lv;
  72. lv.SetPtEtaPhiM(pt, eta, phi, mass);
  73. return lv.E();
  74. })));
  75. /* lorentz_vectors("LepGood_pt", "LepGood_eta", "LepGood_phi", "LepGood_mass", "LepGood_4v") */
  76. auto lk = zip<float,float,float,float>(lookup<vector<float>>("LepGood_pt"),
  77. lookup<vector<float>>("LepGood_eta"),
  78. lookup<vector<float>>("LepGood_phi"),
  79. lookup<vector<float>>("LepGood_mass"),
  80. "lepton_kinematics");
  81. map_over(get_energy, lk, "lepton_energy");
  82. fv::pair<vector<float>,vector<float>>("lepton_energy", "LepGood_pt", "lepton_energy_lepton_pt");
  83. max<float>("lepton_energy", "lepton_energy_max");
  84. min<float>("lepton_energy", "lepton_energy_min");
  85. range<float>("lepton_energy", "lepton_energy_range");
  86. mean<float>("lepton_energy", "lepton_energy_mean");
  87. count<float>(GenFunction::register_function<bool(float)>("bJet_Selection", FUNC(([](float x){return x>0;}))),
  88. "Jet_btagCMVA", "b_jet_count");
  89. filter("trilepton", FUNC(([nLepGood=lookup<int>("nLepGood")](){
  90. return dynamic_cast<Value<int>*>(nLepGood)->get_value() == 3;})));
  91. filter("os-dilepton", FUNC(([LepGood_charge=lookup<vector<int>>("LepGood_charge")](){
  92. auto& charges = LepGood_charge->get_value();
  93. return charges.size()==2 && (charges[0] != charges[1]);})));
  94. filter("ss-dilepton", FUNC(([LepGood_charge=lookup<vector<int>>("LepGood_charge")](){
  95. auto& charges = LepGood_charge->get_value();
  96. return charges.size()==2 && (charges[0] == charges[1]); })));
  97. }
  98. void declare_containers(MiniTreeDataSet& mt){
  99. mt.register_container(new ContainerTH1<int>("lepton_count", "Lepton Multiplicity", lookup<int>("nLepGood"), 8, 0, 8));
  100. mt.register_container(new ContainerTH1<int>("top_quark_count", "Top Quark Multiplicity", lookup<int>("nGenTop"), 8, 0, 8));
  101. mt.register_container(new ContainerTH1Many<float>("lepton_energy_all", "Lepton Energy - All",
  102. lookup<vector<float>>("lepton_energy"), 50, 0, 500));
  103. mt.register_container(new ContainerTH1<float>("lepton_energy_max", "Lepton Energy - Max",
  104. lookup<float>("lepton_energy_max"), 50, 0, 500));
  105. mt.register_container(new ContainerTH1<float>("lepton_energy_min", "Lepton Energy - Min",
  106. lookup<float>("lepton_energy_min"), 50, 0, 500));
  107. mt.register_container(new ContainerTH1<float>("lepton_energy_rng", "Lepton Energy - Range",
  108. lookup<float>("lepton_energy_range"), 50, 0, 500));
  109. mt.register_container(new ContainerTGraph("nLepvsnJet", "Number of Leptons vs Number of Jets",
  110. fv::pair<int, int>("nLepGood", "nJet") ));
  111. mt.register_container(new ContainerTH2Many<float>("lepton_energy_vs_pt", "Lepton Energy - Range",
  112. lookup<std::pair<std::vector<float>,std::vector<float>>>("lepton_energy_lepton_pt"),
  113. 50, 0, 500, 50, 0, 500));
  114. mt.register_container(new ContainerTH1<int>("b_jet_count", "B-Jet Multiplicity", lookup<int>("b_jet_count"), 10, 0, 10));
  115. mt.register_container(new ContainerTH1<int>("jet_count_os_dilepton", "Jet Multiplicity - OS Dilepton Events",
  116. lookup<int>("nJet"), 14, 0, 14));
  117. mt.get_container("jet_count_os_dilepton")->add_filter(lookup_filter("os-dilepton"));
  118. mt.register_container(new ContainerTH1<int>("jet_count_ss_dilepton", "Jet Multiplicity - SS Dilepton Events",
  119. lookup<int>("nJet"), 14, 0, 14));
  120. mt.get_container("jet_count_ss_dilepton")->add_filter(lookup_filter("ss-dilepton"));
  121. mt.register_container(new ContainerTH1<int>("jet_count_trilepton", "Jet Multiplicity - Trilepton Events",
  122. lookup<int>("nJet"), 14, 0, 14));
  123. mt.get_container("jet_count_trilepton")->add_filter(lookup_filter("trilepton"));
  124. mt.register_container(new ContainerTH1<int>("primary_vert_count", "Number of Primary Vertices",
  125. lookup<int>("nVert"), 50, 0, 50));
  126. mt.register_container(new CounterMany<int>("GenTop_pdg_id", lookup<vector<int>>("GenTop_pdgId")));
  127. }
  128. void run_analysis(const std::string& input_filename, bool silent){
  129. auto replace_suffix = [](const std::string& input, const std::string& new_suffix){
  130. return input.substr(0, input.find_last_of(".")) + new_suffix;
  131. };
  132. string log_filename = replace_suffix(input_filename, "_result.log");
  133. fv::util::Log::init_logger(log_filename, fv::util::LogPriority::kLogDebug);
  134. string output_filename = replace_suffix(input_filename, "_result.root");
  135. MiniTreeDataSet mt(input_filename, output_filename);
  136. enable_branches(mt);
  137. declare_values(mt);
  138. declare_containers(mt);
  139. mt.process(silent);
  140. mt.save_all();
  141. }
  142. int main(int argc, char * argv[])
  143. {
  144. fv::util::ArgParser args(argc, argv);
  145. if(!args.cmdOptionExists("-f")) {
  146. cout << "Usage: ./main -f input_minitree.root" << endl;
  147. return -1;
  148. }
  149. bool silent = args.cmdOptionExists("-s");
  150. string input_filename = args.getCmdOption("-f");
  151. run_analysis(input_filename, silent);
  152. }