selection.hpp 6.6 KB

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