11 #include <unordered_map>
20 #include "trg/klm/modules/klmtrigger/group_helper.h"
21 #include "trg/klm/modules/klmtrigger/KLMAxis.h"
22 #include "trg/klm/modules/klmtrigger/KLM_Trig.h"
23 #include "klm/dataobjects/KLMElementNumbers.h"
28 AXIS_NAME(layer_count,
int);
29 AXIS_NAME(layer_mask, uint64_t);
30 AXIS_NAME(n_triggered,
int);
31 AXIS_NAME(sector_mask,
int);
32 AXIS_NAME(sector_mask_or,
int);
34 AXIS_NAME(n_sections_trig,
int);
35 AXIS_NAME(back2back_t,
int);
41 using namespace Belle2::group_helper::KLM_Coordinates_n;
42 using namespace Belle2::group_helper::KLM_Generic;
43 using namespace Belle2::group_helper;
48 const int c_TotalSections_per_EKLM_BKLM = 2;
49 const int c_MaxSectorID = 7;
53 const int c_TotalLayers = 15;
60 constexpr isectors_t c_backward_eklm = isectors_t(KLM_TRG_definitions::c_backward_eklm);
61 constexpr isectors_t c_backward_bklm = isectors_t(KLM_TRG_definitions::c_backward_bklm);
63 constexpr isectors_t c_forward_bklm = isectors_t(KLM_TRG_definitions::c_forward_bklm);
64 constexpr isectors_t c_forward_eklm = isectors_t(KLM_TRG_definitions::c_forward_eklm);
67 std::size_t countBits(uint64_t n)
69 return std::bitset<64>(n).count();
75 template <
typename CONTAINER_T>
76 uint64_t to_bit_mask(
const CONTAINER_T& container)
80 for (let& e : container) {
82 ret |= (uint64_t(1) << e);
92 bool sectors_adjacent(
int e1,
int e2)
94 if (e1 == 0 && e2 == c_MaxSectorID) {
104 template <
typename CONTAINER_T>
105 auto to_sector_bit_mask(
const CONTAINER_T& container,
int TriggerCut_,
int vetoCut_ = 0)
108 auto back = container.back();
109 for (
const auto& e : container) {
110 int bitcount = countBits(layer_mask(e));
111 int bitcount_or = countBits(layer_mask(back) | layer_mask(e));
112 int bitcount_back = countBits(layer_mask(back));
113 if (bitcount >= TriggerCut_) {
114 ret |= (1 << sector(e));
116 bitcount_or >= TriggerCut_
117 && bitcount_back < vetoCut_
118 && bitcount < vetoCut_
119 && (sectors_adjacent(sector(e), sector(back)))
121 ret |= (1 << sector(e));
136 Belle2::group_helper::KLM_trg_summery Belle2::make_trg(
const std::vector<Belle2::group_helper::KLM_Digit_compact>& hits,
137 int eventNr,
int NLayerTrigger)
144 let bit_mask = to_bit_mask(project(e1, [](letref t) {
return (layer(t) + 1) * 2 + plane(t); }));
145 let layer_count_ = countBits(bit_mask);
146 return std::tuple(layer_count(layer_count_), layer_mask(bit_mask));
156 return (n_sections_trig) count_if(project<layer_count>(e1), [NLayerTrigger](letref e) {
return e >= NLayerTrigger; });
161 [&](letref e1) {
return (sector_mask) to_sector_bit_mask(e1, NLayerTrigger); },
162 [&](letref e1) {
return (sector_mask_or) to_sector_bit_mask(e1, NLayerTrigger, NLayerTrigger); }
168 return back2back_t(count_if(project<sector_mask>(e1)) >= c_TotalSections_per_EKLM_BKLM);
174 return std::make_tuple(
176 BKLM_n_trg_sectors(n_sections_trig(get_first(summery2, c_BKLM))),
177 EKLM_n_trg_sectors(n_sections_trig(get_first(summery2, c_EKLM))),
180 Sector_mask_Backward_Barrel(sector_mask(get_first(n_triggered_sectors2, c_backward_bklm))),
181 Sector_mask_Forward_Barrel(sector_mask(get_first(n_triggered_sectors2, c_forward_bklm))),
182 Sector_mask_Backward_Endcap(sector_mask(get_first(n_triggered_sectors2, c_backward_eklm))),
183 Sector_mask_Forward_Endcap(sector_mask(get_first(n_triggered_sectors2, c_forward_eklm))),
186 Sector_mask_OR_Backward_Barrel(sector_mask_or(get_first(n_triggered_sectors2, c_backward_bklm))),
187 Sector_mask_OR_Forward_Barrel(sector_mask_or(get_first(n_triggered_sectors2, c_forward_bklm))),
188 Sector_mask_OR_Backward_Endcap(sector_mask_or(get_first(n_triggered_sectors2, c_backward_eklm))),
189 Sector_mask_OR_Forward_Endcap(sector_mask_or(get_first(n_triggered_sectors2, c_forward_eklm))),
192 BKLM_back_to_back_flag(back2back_t(get_first(summery1, c_BKLM))),
193 EKLM_back_to_back_flag(back2back_t(get_first(summery1, c_EKLM)))
Abstract base class for different kinds of events.