TTTT_Analysis.cpp 7.7 KB

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