MiniTree.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef minitree_cxx
  2. #define minitree_cxx
  3. #include <cstdio>
  4. #include <string>
  5. #include <map>
  6. #include <TStyle.h>
  7. #include "MiniTree.h"
  8. #include "HistCollection.h"
  9. HistCollection* build_histograms(const char* sample_name, const char* filename){
  10. HistCollection *hc = new HistCollection(sample_name);
  11. TFile *f = TFile::Open(filename);
  12. TTree *tree = (TTree*) f->Get("tree");
  13. MiniTree minitree(tree);
  14. minitree.Loop(hc);
  15. delete tree;
  16. f->Close();
  17. delete f;
  18. std::printf("Finished filling histograms for file %s\n", filename);
  19. return hc;
  20. }
  21. void set_branch_statuses(MiniTree *minitree){
  22. auto on = [minitree](const char* bname){
  23. minitree->fChain->SetBranchStatus(bname, true);
  24. };
  25. auto off = [minitree](const char* bname){
  26. minitree->fChain->SetBranchStatus(bname, false);
  27. };
  28. off("*");
  29. on("nLepGood");
  30. on("LepGood_pt");
  31. on("LepGood_eta");
  32. on("LepGood_phi");
  33. on("LepGood_mcPt");
  34. on("LepGood_charge");
  35. on("nJet");
  36. on("Jet_btagCMVA");
  37. on("Jet_pt");
  38. on("nGenTop");
  39. }
  40. void MiniTree::Loop(HistCollection* hc){
  41. // Implement the mini-isolation cut which utilizes a dynamic isolation cone size
  42. // based on lepton pt
  43. auto mini_isolation_cut = [this](int idx){
  44. double r0 = 0.5;
  45. double pt0 = 7.5; // GeV
  46. double r_cut2 = pow(min(r0, pt0/this->LepGood_pt[idx]), 2);
  47. for (int j = 0; j < this->nLepGood; j++){
  48. if (j == idx) continue;
  49. double delta_r2 = pow(this->LepGood_eta[idx] - this->LepGood_eta[j], 2) +
  50. pow(this->LepGood_phi[idx] - this->LepGood_phi[j], 2);
  51. if (delta_r2 < r_cut2) return false;
  52. }
  53. return true;
  54. };
  55. if (fChain == 0) return;
  56. set_branch_statuses(this);
  57. Long64_t nentries = fChain->GetEntriesFast();
  58. Long64_t nbytes = 0, nb = 0;
  59. for (Long64_t jentry=0; jentry<nentries;jentry++) {
  60. Long64_t ientry = LoadTree(jentry);
  61. if (ientry < 0) break;
  62. nb = fChain->GetEntry(jentry); nbytes += nb;
  63. // if (Cut(ientry) < 0) continue;
  64. // BEGIN ANALYSIS CODE
  65. hc->lepton_count->Fill(nLepGood);
  66. hc->top_quark_count->Fill(nGenTop);
  67. for(int i=0; i<nLepGood; i++){
  68. double delta_pt_val = LepGood_pt[i] - LepGood_mcPt[i];
  69. hc->delta_pt->Fill(delta_pt_val);
  70. hc->lepton_count_vs_delta_pt->Fill(nLepGood, delta_pt_val);
  71. }
  72. hc->jet_count->Fill(nJet);
  73. int b_jet_count = 0;
  74. for(int i=0; i<nJet; i++){
  75. hc->b_jet_discriminator->Fill(Jet_btagCMVA[i]);
  76. b_jet_count += (Jet_btagCMVA[i] > 0);
  77. }
  78. hc->b_jet_count->Fill(b_jet_count);
  79. for(int i=0; i<nJet; i++){
  80. hc->b_jet_pt_all->Fill(Jet_pt[i]);
  81. if (b_jet_count >= 3){
  82. hc->b_jet_pt_3_or_more->Fill(Jet_pt[i]);
  83. }
  84. }
  85. int lepton_count_pass_miniiso= 0;
  86. for(int i=0; i<nLepGood; i++){
  87. lepton_count_pass_miniiso += mini_isolation_cut(i);
  88. }
  89. hc->lepton_count_pass_miniiso->Fill(lepton_count_pass_miniiso);
  90. if (nLepGood == 3){
  91. hc->jet_count_trilepton->Fill(nJet);
  92. }
  93. if (nLepGood == 2 && (LepGood_charge[0] * LepGood_charge[1]) == 1){
  94. hc->jet_count_ss_dilepton->Fill(nJet);
  95. }
  96. if (nLepGood == 2 && (LepGood_charge[0] * LepGood_charge[1]) == -1){
  97. hc->jet_count_os_dilepton->Fill(nJet);
  98. }
  99. }
  100. }
  101. #endif // tree_cxx