TTTT_Analysis.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 ZipMapFour<float, float>(get_energy, "LepGood_pt", "LepGood_eta", "LepGood_phi", "LepGood_mass",
  85. "lepton_energy");
  86. new Pair<vector<float>,vector<float>>("lepton_energy", "LepGood_pt", "lepton_energy_lepton_pt");
  87. new Max<float>("lepton_energy", "lepton_energy_max");
  88. new Min<float>("lepton_energy", "lepton_energy_min");
  89. new Range<float>("lepton_energy", "lepton_energy_range");
  90. new Mean<float>("lepton_energy", "lepton_energy_mean");
  91. new Filter("nLepGood>=3", FUNC(([nLepGood=lookup("nLepGood")](){
  92. return dynamic_cast<Value<int>*>(nLepGood)->get_value() >=3;})));
  93. new Filter("nLepGood<=4", FUNC(([nLepGood=lookup("nLepGood")](){
  94. return dynamic_cast<Value<int>*>(nLepGood)->get_value() <=4;})));
  95. new RangeFilter<int>("3<=nLepGood<5", dynamic_cast<Value<int>*>(lookup("nLepGood")), 3, 5);
  96. }
  97. void declare_containers(MiniTreeDataSet& mt){
  98. mt.register_container(new ContainerTH1I("lepton_count", "Lepton Multiplicity", lookup("nLepGood"), 8, 0, 8));
  99. mt.register_container(new ContainerTH1I("top_quark_count", "Top Quark Multiplicity", lookup("nGenTop"), 8, 0, 8));
  100. mt.register_container(new ContainerTH1FMany("lepton_energy_all", "Lepton Energy - All", lookup("lepton_energy"), 50, 0, 500));
  101. mt.register_container(new ContainerTH1F("lepton_energy_max", "Lepton Energy - Max", lookup("lepton_energy_max"), 50, 0, 500));
  102. mt.register_container(new ContainerTH1F("lepton_energy_min", "Lepton Energy - Min", lookup("lepton_energy_min"), 50, 0, 500));
  103. mt.register_container(new ContainerTH1F("lepton_energy_rng", "Lepton Energy - Range", lookup("lepton_energy_range"), 50, 0, 500));
  104. mt.register_container(new ContainerTH1I("nLepGood2", "Lepton Multiplicity", lookup("nLepGood"), 10, 0, 10));
  105. mt.get_container("nLepGood2")->add_filter(lookup_filter("3<=nLepGood<5"));
  106. mt.register_container(new ContainerTH1I("nLepGood3", "Lepton Multiplicity", lookup("nLepGood"), 10, 0, 10));
  107. mt.get_container("nLepGood3")->add_filter(!(*lookup_filter("3<=nLepGood<5")));
  108. mt.register_container(new ContainerTGraph("nLepvsnJet", new Pair<int, int>("nLepGood", "nJet") ));
  109. mt.register_container(new ContainerTH2FMany("lepton_energy_vs_pt", "Lepton Energy - Range", lookup("lepton_energy_lepton_pt"),
  110. 50, 0, 500, 50, 0, 500));
  111. }
  112. void run_analysis(const std::string& filename){
  113. TFile *f = TFile::Open(filename.c_str());
  114. TTree *tree = (TTree*) f->Get("tree");
  115. MiniTreeDataSet mt(tree);
  116. enable_branches(mt);
  117. declare_values(mt);
  118. declare_containers(mt);
  119. mt.process();
  120. mt.save_all();
  121. }
  122. int main(int argc, char * argv[])
  123. {
  124. Log::init_logger("log.txt", LogPriority::kLogDebug);
  125. ArgParser args(argc, argv);
  126. if(args.cmdOptionExists("-f")) {
  127. run_analysis(args.getCmdOption("-f"));
  128. }
  129. else {
  130. cout << "Usage: ./main -f input_minitree.root" << endl;
  131. }
  132. return 0;
  133. }