selection.hpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. * Define a set of common event selections
  33. */
  34. #ifndef SELECTION_HPP
  35. #define SELECTION_HPP
  36. #include <vector>
  37. #include <algorithm>
  38. #include "filval/filval.hpp"
  39. #include "filval/root/root_filval.hpp"
  40. #include "analysis/common/obj_types.hpp"
  41. struct EventSelection{
  42. ObsFilter* trilepton;
  43. ObsFilter* trilepton_eemu; // OS electron pair + muon+-
  44. ObsFilter* trilepton_mumue; // OS muon pair + electron+-
  45. ObsFilter* b_jet3;
  46. ObsFilter* z_mass_veto;
  47. ObsFilter* base_sel;
  48. ObsFilter* J4;
  49. ObsFilter* J5;
  50. ObsFilter* J6;
  51. ObsFilter* SR4j;
  52. ObsFilter* SR5j;
  53. ObsFilter* SR6j;
  54. };
  55. EventSelection event_selection;
  56. void init_selection(){
  57. auto leptons = lookup<std::vector<Particle>>("leptons");
  58. auto jets = lookup<std::vector<Particle>>("jets");
  59. // Require *exactly* three charged leptons
  60. event_selection.trilepton = obs_filter("trilepton",GenFunction::register_function<bool()>("trilepton",
  61. FUNC(([leptons](){
  62. return leptons->get_value().size() == 3;
  63. }))));
  64. // Require OS electron pair and a muon
  65. event_selection.trilepton_eemu = obs_filter("trilepton_eemu",GenFunction::register_function<bool()>("trilepton_eemu",
  66. FUNC(([leptons](){
  67. std::vector<Particle>& leps = leptons->get_value();
  68. if(leps.size() != 3) return false;
  69. auto check_id = [](int ref_id){
  70. auto fn = [ref_id](const Particle& p){
  71. return p.lepton.pdg_id == ref_id;
  72. };
  73. return fn;
  74. };
  75. bool has_ep = std::count_if(std::begin(leps), std::end(leps), check_id(-11)) == 1;
  76. bool has_en = std::count_if(std::begin(leps), std::end(leps), check_id( 11)) == 1;
  77. bool has_mup = std::count_if(std::begin(leps), std::end(leps), check_id(-13)) == 1;
  78. bool has_mun = std::count_if(std::begin(leps), std::end(leps), check_id( 13)) == 1;
  79. return has_ep && has_en && (has_mup != has_mun);
  80. }))));
  81. // Require OS muon pair and an electron
  82. event_selection.trilepton_mumue = obs_filter("trilepton_mumue",GenFunction::register_function<bool()>("trilepton_mumue",
  83. FUNC(([leptons](){
  84. std::vector<Particle>& leps = leptons->get_value();
  85. if(leps.size() != 3) return false;
  86. auto check_id = [](int ref_id){
  87. auto fn = [ref_id](const Particle& p){
  88. return p.lepton.pdg_id == ref_id;
  89. };
  90. return fn;
  91. };
  92. bool has_ep = std::count_if(std::begin(leps), std::end(leps), check_id(-11)) == 1;
  93. bool has_en = std::count_if(std::begin(leps), std::end(leps), check_id( 11)) == 1;
  94. bool has_mup = std::count_if(std::begin(leps), std::end(leps), check_id(-13)) == 1;
  95. bool has_mun = std::count_if(std::begin(leps), std::end(leps), check_id( 13)) == 1;
  96. return (has_ep != has_en) && has_mup && has_mun;
  97. }))));
  98. // Require at least three b-jets
  99. event_selection.b_jet3 = obs_filter("b_jet3",GenFunction::register_function<bool()>("b_jet3",
  100. FUNC(([jets](){
  101. int n_b_jets = 0;
  102. for(auto jet : jets->get_value()){
  103. if(jet.tag == Particle::JET && jet.jet.b_cmva > 0)
  104. n_b_jets++;
  105. }
  106. return n_b_jets >= 3;
  107. }))));
  108. // Require all same-flavour OS dilepton combinations are outside the Z mass
  109. // window (70,105)
  110. event_selection.z_mass_veto = obs_filter("z_mass_veto",GenFunction::register_function<bool()>("z_mass_veto",
  111. FUNC(([leptons](){
  112. auto& leps = leptons->get_value();
  113. int n = leps.size();
  114. for(int i = 0; i < n; i++){
  115. for(int j = i+1; j < n; j++){
  116. const Particle& p1 = leps[i];
  117. const Particle& p2 = leps[j];
  118. if(abs(p1.lepton.pdg_id) != abs(p2.lepton.pdg_id)) continue;
  119. if(p1.lepton.charge == p2.lepton.charge) continue;
  120. double m = (p1.v + p2.v).M();
  121. if(70 < m && m < 105)
  122. return false;
  123. }
  124. }
  125. return true;
  126. }))));
  127. event_selection.J4 = obs_filter("4jet_selection",GenFunction::register_function<bool()>("4jet_selection",
  128. FUNC(([jets](){
  129. return jets->get_value().size() >= 4;
  130. }))));
  131. event_selection.J5 = obs_filter("5jet_selection",GenFunction::register_function<bool()>("5jet_selection",
  132. FUNC(([jets](){
  133. return jets->get_value().size() >= 5;
  134. }))));
  135. event_selection.J6 = obs_filter("6jet_selection",GenFunction::register_function<bool()>("6jet_selection",
  136. FUNC(([jets](){
  137. return jets->get_value().size() >= 6;
  138. }))));
  139. /* event_selection.base_sel = ObsFilter::conj(event_selection.z_mass_veto, ObsFilter::conj(event_selection.trilepton, event_selection.b_jet3)); */
  140. event_selection.base_sel = all({event_selection.z_mass_veto, event_selection.trilepton_eemu, event_selection.b_jet3});
  141. event_selection.SR4j = all(event_selection.base_sel, event_selection.J4);
  142. event_selection.SR5j = all(event_selection.base_sel, event_selection.J5);
  143. event_selection.SR6j = all(event_selection.base_sel, event_selection.J6);
  144. }
  145. #endif // SELECTION_HPP