TTTT_Analysis.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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
  33. */
  34. #include <iostream>
  35. #include <vector>
  36. #include <utility>
  37. #include "TFile.h"
  38. #include "TTree.h"
  39. #include "TCanvas.h"
  40. #include "filval.hpp"
  41. #include "filval_root.hpp"
  42. #include "MiniTreeDataSet.hpp"
  43. using namespace std;
  44. using namespace fv;
  45. using namespace fv::root;
  46. using namespace fv::util;
  47. GenValue* lookup(const string& name){
  48. return GenValue::get_value(name);
  49. }
  50. Filter* lookup_filter(const string& name){
  51. return dynamic_cast<Filter*>(GenValue::get_value(name));
  52. }
  53. void enable_branches(MiniTreeDataSet& mt){
  54. mt.fChain->SetBranchStatus("*", false);
  55. mt.track_branch<int>("nLepGood");
  56. mt.track_branch_ptr<float>("LepGood_pt");
  57. mt.track_branch_ptr<float>("LepGood_eta");
  58. mt.track_branch_ptr<float>("LepGood_phi");
  59. mt.track_branch_ptr<float>("LepGood_mass");
  60. mt.track_branch_ptr<float>("LepGood_mcPt");
  61. mt.track_branch_ptr<int>("LepGood_charge");
  62. mt.track_branch<int>("nJet");
  63. mt.track_branch_ptr<float>("Jet_pt");
  64. mt.track_branch_ptr<float>("Jet_eta");
  65. mt.track_branch_ptr<float>("Jet_phi");
  66. mt.track_branch_ptr<float>("Jet_mass");
  67. mt.track_branch_ptr<float>("Jet_btagCMVA");
  68. mt.track_branch<int>("nGenTop");
  69. mt.track_branch<int>("ngenLep");
  70. mt.track_branch_ptr<int>("genLep_sourceId");
  71. mt.track_branch_ptr<float>("genLep_pt");
  72. }
  73. void declare_values(MiniTreeDataSet& mt){
  74. auto& get_energy = GenFunction::register_function<float(float,float,float,float)>("get_energy",
  75. FUNC(([](float pt, float eta, float phi, float m){
  76. TLorentzVector t;
  77. t.SetPtEtaPhiM(pt, eta, phi, m);
  78. return t.E();
  79. })));
  80. new WrapperVector<float>("nLepGood", "LepGood_pt", "LepGood_pt");
  81. new WrapperVector<float>("nLepGood", "LepGood_eta", "LepGood_eta");
  82. new WrapperVector<float>("nLepGood", "LepGood_phi", "LepGood_phi");
  83. new WrapperVector<float>("nLepGood", "LepGood_mass", "LepGood_mass");
  84. new WrapperVector<float>("nJet", "Jet_btagCMVA", "Jet_btagCMVA");
  85. new ZipMapFour<float, float>(get_energy, "LepGood_pt", "LepGood_eta", "LepGood_phi", "LepGood_mass",
  86. "lepton_energy");
  87. new Pair<vector<float>,vector<float>>("lepton_energy", "LepGood_pt", "lepton_energy_lepton_pt");
  88. new Max<float>("lepton_energy", "lepton_energy_max");
  89. new Min<float>("lepton_energy", "lepton_energy_min");
  90. new Range<float>("lepton_energy", "lepton_energy_range");
  91. new Mean<float>("lepton_energy", "lepton_energy_mean");
  92. new Count<float>(GenFunction::register_function<bool(float)>("bJet_Selection", FUNC(([](float x){return x>0;}))),
  93. "Jet_btagCMVA", "b_jet_count");
  94. new Filter("trilepton", FUNC(([nLepGood=lookup("nLepGood")](){
  95. return dynamic_cast<Value<int>*>(nLepGood)->get_value() ==3;})));
  96. new Filter("os-dilepton", FUNC(([nLepGood=lookup("nLepGood"), LepGood_charge=lookup("LepGood_charge")](){
  97. bool is_dilepton = dynamic_cast<Value<int>*>(nLepGood)->get_value()==2;
  98. int* charge = dynamic_cast<Value<int*>*>(LepGood_charge)->get_value();
  99. return is_dilepton && (charge[0] != charge[1]);})));
  100. new Filter("ss-dilepton", FUNC(([nLepGood=lookup("nLepGood"), LepGood_charge=lookup("LepGood_charge")](){
  101. bool is_dilepton = dynamic_cast<Value<int>*>(nLepGood)->get_value()==2;
  102. int* charge = dynamic_cast<Value<int*>*>(LepGood_charge)->get_value();
  103. return is_dilepton && (charge[0] == charge[1]);})));
  104. }
  105. void declare_containers(MiniTreeDataSet& mt){
  106. mt.register_container(new ContainerTH1I("lepton_count", "Lepton Multiplicity", lookup("nLepGood"), 8, 0, 8));
  107. mt.register_container(new ContainerTH1I("top_quark_count", "Top Quark Multiplicity", lookup("nGenTop"), 8, 0, 8));
  108. mt.register_container(new ContainerTH1FMany("lepton_energy_all", "Lepton Energy - All", lookup("lepton_energy"), 50, 0, 500));
  109. mt.register_container(new ContainerTH1F("lepton_energy_max", "Lepton Energy - Max", lookup("lepton_energy_max"), 50, 0, 500));
  110. mt.register_container(new ContainerTH1F("lepton_energy_min", "Lepton Energy - Min", lookup("lepton_energy_min"), 50, 0, 500));
  111. mt.register_container(new ContainerTH1F("lepton_energy_rng", "Lepton Energy - Range", lookup("lepton_energy_range"), 50, 0, 500));
  112. mt.register_container(new ContainerTGraph("nLepvsnJet", new Pair<int, int>("nLepGood", "nJet") ));
  113. mt.register_container(new ContainerTH2FMany("lepton_energy_vs_pt", "Lepton Energy - Range", lookup("lepton_energy_lepton_pt"),
  114. 50, 0, 500, 50, 0, 500));
  115. mt.register_container(new ContainerTH1I("b_jet_count", "B-Jet Multiplicity", lookup("b_jet_count"), 10, 0, 10));
  116. mt.register_container(new ContainerTH1I("jet_count_os_dilepton", "Jet Multiplicity - OS Dilepton Events", lookup("nJet"), 14, 0, 14));
  117. mt.get_container("jet_count_os_dilepton")->add_filter(lookup_filter("os-dilepton"));
  118. mt.register_container(new ContainerTH1I("jet_count_ss_dilepton", "Jet Multiplicity - SS Dilepton Events", lookup("nJet"), 14, 0, 14));
  119. mt.get_container("jet_count_ss_dilepton")->add_filter(lookup_filter("ss-dilepton"));
  120. mt.register_container(new ContainerTH1I("jet_count_trilepton", "Jet Multiplicity - Trilepton Events", lookup("nJet"), 14, 0, 14));
  121. mt.get_container("jet_count_trilepton")->add_filter(lookup_filter("trilepton"));
  122. }
  123. std::string replace_suffix(const std::string& input, const std::string& new_suffix){
  124. return input.substr(0, input.find_last_of(".")) + new_suffix;
  125. }
  126. void run_analysis(const std::string& input_filename, bool silent){
  127. string log_filename = replace_suffix(input_filename, "_result.log");
  128. Log::init_logger(log_filename, LogPriority::kLogDebug);
  129. string output_filename = replace_suffix(input_filename, "_result.root");
  130. MiniTreeDataSet mt(input_filename, output_filename);
  131. enable_branches(mt);
  132. declare_values(mt);
  133. declare_containers(mt);
  134. mt.process(silent);
  135. mt.save_all();
  136. }
  137. int main(int argc, char * argv[])
  138. {
  139. ArgParser args(argc, argv);
  140. if(!args.cmdOptionExists("-f")) {
  141. cout << "Usage: ./main -f input_minitree.root" << endl;
  142. return -1;
  143. }
  144. bool silent = args.cmdOptionExists("-s");
  145. string input_filename = args.getCmdOption("-f");
  146. run_analysis(input_filename, silent);
  147. }