Belle II Software development
KLM_Trig.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9
10#include "trg/klm/modules/klmtrigger/ntuples_full.h"
11
12
13#include "trg/klm/modules/klmtrigger/KLM_Trig.h"
14#include "trg/klm/modules/klmtrigger/IO_csv.h"
15#include "trg/klm/modules/klmtrigger/bit_operations.h"
16
17
18#include <unordered_map>
19#include <algorithm>
20#include <numeric>
21#include <vector>
22#include <tuple>
23#include <iostream>
24#include <bitset>
25
26using namespace Belle2::KLM_TRG_definitions;
27
28
29
30
31
32
33namespace Belle2 {
39 void klmtrg_layer_counter_t::clear_layersUsed()
40 {
41 m_layersUsed.clear();
42 }
43
44 void klmtrg_layer_counter_t::add_layersUsed(int layersUsed)
45 {
46 m_layersUsed.emplace_back(layersUsed);
47 }
48
49 void klmtrg_layer_counter_t::set_NLayerTrigger(int NlayerTrigger)
50 {
51 m_NlayerTrigger = NlayerTrigger;
52 }
53
54 void klmtrg_layer_counter_t::run(const KLM_Digit_compact_ts& hits)
55 {
56
57
58 m_sections_trig.clear();
59 m_summary1.clear();
60
61 auto hits1 = nt::algorithms::join_vectors(
62 hits,
63 m_layersUsed,
64 nt::comparators::on_common_args,
65 [&](auto e1, const auto&) {
66 e1.layer = e1.layer * 2 + e1.plane;
67 return e1;
68 }
69 );
70
71 __CSV__WRITE__(hits1);
72
73
74 auto grouped = nt_group(
75 hits1[0].subdetector,
76 hits1[0].section,
77 hits1[0].sector
78 ).apply_append(
79 hits,
80 [](const auto & e1) {
81 auto bit_mask = to_bit_mask<layer>(e1);
82 return nt::ntuple(
83 ax_maker(layer_count) = countBits(bit_mask),
84 ax_maker(layer_mask) = bit_mask
85 );
86 });
87
88
89 __CSV__WRITE__(grouped);
90
91 nt::algorithms::filter(grouped, [&](const auto & e) { return e.layer_count >= m_NlayerTrigger; });
92
93
94
95
96
97 m_sections_trig = nt_group(
98 grouped[0].subdetector,
99 grouped[0].section
100 ).apply_append(
101 grouped,
102 [&](const auto & e1) {
103 auto bit_mask = to_bit_mask<sector>(e1);
104 n_sections_trig nsector = countBits(bit_mask);
105 return nt::ntuple(
106 sector_mask(bit_mask),
107 nsector
108 );
109 }
110 );
111
112 __CSV__WRITE__(m_sections_trig);
113
114
115
116 m_summary1 = nt_group(
117 m_sections_trig[0].subdetector
118 ).apply_append(
119 m_sections_trig,
120 [](const auto & e1) {
121 auto bit_mask = countBits(to_bit_mask<section>(e1));
122 n_sections_trig nsector = nt::algorithms::sum(e1, [](auto&& e) {return e.n_sections_trig; });
123
124 return nt::ntuple(
125 nsector,
126 back2back(bit_mask == 2)
127
128 );
129 }
130 );
131
132 __CSV__WRITE__(m_summary1);
133
134
135 }
136
137 int klmtrg_layer_counter_t::get_n_sections_trig(int subdetector)
138 {
139 for (const auto& e : m_summary1) {
140 if (e.subdetector == subdetector) {
141 return e.n_sections_trig;
142 }
143 }
144 return 0;
145 }
146
147 int klmtrg_layer_counter_t::get_triggermask(int subdetector, int section)
148 {
149 for (const auto& e : m_sections_trig) {
150 if (e.subdetector == subdetector && e.section == section) {
151 return e.sector_mask;
152 }
153 }
154 return 0;
155 }
156
157 int klmtrg_layer_counter_t::get_BKLM_back_to_back_flag(int subdetector)
158 {
159 for (const auto& e : m_summary1) {
160 if (e.subdetector == subdetector) {
161 return e.back2back;
162 }
163 }
164 return 0;
165 }
166
168}
Abstract base class for different kinds of events.