All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TriggerInfo_t_test.cc
Go to the documentation of this file.
1 /**
2  * @file TriggerInfo_t_test.cc
3  * @brief Unit test for utilities in `TriggerInfo_t.h`
4  * @date July 8, 2021
5  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
6  * @see icaruscode/PMT/Trigger/Algorithms/details/TriggerInfo_t.h
7  *
8  * Largely incomplete.
9  */
10 
11 // ICARUS libraries
14 
15 // LArSoft libraries
17 
18 // Boost libraries
19 #define BOOST_TEST_MODULE ( TriggerGateData_test )
20 #include <boost/test/unit_test.hpp>
21 
22 
23 // -----------------------------------------------------------------------------
24 // --- implementation detail tests
25 // -----------------------------------------------------------------------------
26 
28 
29  // prepare the input:
31 
32  BOOST_CHECK((gate.alwaysClosed()));
33 
34  /*
35  * ^ 12 34
36  * 4 | === 20 ===
37  * 3 | -4 4 10 == === 26
38  * 2 | === 2 === == 15 === === 40
39  * 1 | == 7=== 17 23=== 29== 37 ===
40  * 0-*=======---=|=---,----,----,----,----,----,===-,-===,--===============
41  * -10 -5 0 5 10 20 30 40 50
42  */
43 
44  gate.openBetween(-4, -1, 2); // -> 2
45  gate.openAt ( 2); // -> 1
46  gate.openAt ( 4); // -> 2
47  gate.closeAt( 7); // -> 1
48  gate.openAt (10); // -> 2
49  gate.openAt (12, 2); // -> 4
50  gate.closeAt(15); // -> 3
51  gate.closeAt(17); // -> 2
52  gate.openAt (20); // -> 3
53  gate.closeAt(23, 2); // -> 1
54  gate.openAt (26); // -> 2
55  gate.closeAt(29); // -> 1
56  gate.closeAt(31); // -> 0
57  gate.openAt (34, 4); // -> 4
58  gate.closeAt(37, 4); // -> 0
59  gate.openAt (40); // -> 1
60  gate.closeAt(43); // -> 0
61 
62  BOOST_CHECK((!gate.alwaysClosed()));
63  BOOST_TEST((gate.openingCount(-9) == 0));
64  BOOST_TEST((gate.openingCount(-8) == 0));
65  BOOST_TEST((gate.openingCount(-7) == 0));
66  BOOST_TEST((gate.openingCount(-6) == 0));
67  BOOST_TEST((gate.openingCount(-5) == 0));
68  BOOST_TEST((gate.openingCount(-4) == 2));
69  BOOST_TEST((gate.openingCount(-3) == 2));
70  BOOST_TEST((gate.openingCount(-2) == 2));
71  BOOST_TEST((gate.openingCount(-1) == 0));
72  BOOST_TEST((gate.openingCount( 0) == 0));
73  BOOST_TEST((gate.openingCount( 1) == 0));
74  BOOST_TEST((gate.openingCount( 2) == 1));
75  BOOST_TEST((gate.openingCount( 3) == 1));
76  BOOST_TEST((gate.openingCount( 4) == 2));
77  BOOST_TEST((gate.openingCount( 5) == 2));
78  BOOST_TEST((gate.openingCount( 6) == 2));
79  BOOST_TEST((gate.openingCount( 7) == 1));
80  BOOST_TEST((gate.openingCount( 8) == 1));
81  BOOST_TEST((gate.openingCount( 9) == 1));
82  BOOST_TEST((gate.openingCount(10) == 2));
83  BOOST_TEST((gate.openingCount(11) == 2));
84  BOOST_TEST((gate.openingCount(12) == 4));
85  BOOST_TEST((gate.openingCount(13) == 4));
86  BOOST_TEST((gate.openingCount(14) == 4));
87  BOOST_TEST((gate.openingCount(15) == 3));
88  BOOST_TEST((gate.openingCount(16) == 3));
89  BOOST_TEST((gate.openingCount(17) == 2));
90  BOOST_TEST((gate.openingCount(18) == 2));
91  BOOST_TEST((gate.openingCount(19) == 2));
92  BOOST_TEST((gate.openingCount(20) == 3));
93  BOOST_TEST((gate.openingCount(21) == 3));
94  BOOST_TEST((gate.openingCount(22) == 3));
95  BOOST_TEST((gate.openingCount(23) == 1));
96  BOOST_TEST((gate.openingCount(24) == 1));
97  BOOST_TEST((gate.openingCount(25) == 1));
98  BOOST_TEST((gate.openingCount(26) == 2));
99  BOOST_TEST((gate.openingCount(27) == 2));
100  BOOST_TEST((gate.openingCount(28) == 2));
101  BOOST_TEST((gate.openingCount(29) == 1));
102  BOOST_TEST((gate.openingCount(30) == 1));
103  BOOST_TEST((gate.openingCount(31) == 0));
104  BOOST_TEST((gate.openingCount(32) == 0));
105  BOOST_TEST((gate.openingCount(33) == 0));
106  BOOST_TEST((gate.openingCount(34) == 4));
107  BOOST_TEST((gate.openingCount(35) == 4));
108  BOOST_TEST((gate.openingCount(36) == 4));
109  BOOST_TEST((gate.openingCount(37) == 0));
110  BOOST_TEST((gate.openingCount(38) == 0));
111  BOOST_TEST((gate.openingCount(39) == 0));
112  BOOST_TEST((gate.openingCount(40) == 1));
113  BOOST_TEST((gate.openingCount(41) == 1));
114  BOOST_TEST((gate.openingCount(42) == 1));
115  BOOST_TEST((gate.openingCount(43) == 0));
116  BOOST_TEST((gate.openingCount(44) == 0));
117  BOOST_TEST((gate.openingCount(45) == 0));
118  BOOST_TEST((gate.openingCount(46) == 0));
119  BOOST_TEST((gate.openingCount(47) == 0));
120  BOOST_TEST((gate.openingCount(48) == 0));
121  BOOST_TEST((gate.openingCount(49) == 0));
122 
123  BOOST_TEST((gate.findMaxOpen( ) == 12));
124  BOOST_TEST((gate.findMaxOpen(12) == 12));
125  BOOST_TEST((gate.findMaxOpen(13) == 13));
126  BOOST_TEST((gate.findMaxOpen(14) == 14));
127  BOOST_TEST((gate.findMaxOpen(15) == 34));
128 
129  auto [ lower2031, upper2031 ] = gate.openingRange(20, 30);
130  BOOST_TEST((lower2031 == 1));
131  BOOST_TEST((upper2031 == 4));
132 
133  return gate;
134 } // TestedInputGate()
135 
136 
138 
139  // prepare the input:
141 
142  /*
143  * ^ 12 34
144  * 4 | === 20 ===
145  * 3 | -4 4 10 == === 26
146  * 2 | === 2 === == 15 === === 40
147  * 1 | == 7=== 17 23=== 29== 37 ===
148  * 0-*=======---=|=---,----,----,----,----,----,===-,-===,--===============
149  * -10 -5 0 5 10 20 30 40 50
150  */
151 
153 
154  BOOST_TEST((extract.openThreshold() == 2U));
155  BOOST_TEST((extract.closeThreshold() == 1U));
156  BOOST_TEST((extract.minGap() == 0U));
157  BOOST_TEST((extract.minWidth() == 1U));
158 
159  BOOST_CHECK((!extract.atEnd()));
160 
161  auto opening = extract.findNextOpening();
162  BOOST_CHECK((!!opening));
163  BOOST_TEST((opening.value().tick.value() == -4));
164  BOOST_TEST((opening.value().level == 2));
165  BOOST_CHECK((!extract.atEnd()));
166 
167  opening = extract.findNextOpening();
168  BOOST_CHECK((!!opening));
169  BOOST_TEST((opening.value().tick.value() == 4));
170  BOOST_TEST((opening.value().level == 2));
171  BOOST_CHECK((!extract.atEnd()));
172 
173  opening = extract.findNextOpening();
174  BOOST_CHECK((!!opening));
175  BOOST_TEST((opening.value().tick.value() == 10));
176  BOOST_TEST((opening.value().level == 4));
177  BOOST_CHECK((!extract.atEnd()));
178 
179  opening = extract.findNextOpening();
180  BOOST_CHECK((!!opening));
181  BOOST_TEST((opening.value().tick.value() == 26));
182  BOOST_TEST((opening.value().level == 2));
183  BOOST_CHECK((!extract.atEnd()));
184 
185  opening = extract.findNextOpening();
186  BOOST_CHECK((!!opening));
187  BOOST_TEST((opening.value().tick.value() == 34));
188  BOOST_TEST((opening.value().level == 4));
189  BOOST_CHECK((extract.atEnd()));
190 
191  opening = extract.findNextOpening();
192  BOOST_CHECK((!opening));
193  BOOST_CHECK((extract.atEnd()));
194 
195 } // GateOpeningInfoExtractor_test()
196 
197 
198 // -----------------------------------------------------------------------------
199 // BEGIN Test cases -----------------------------------------------------------
200 // -----------------------------------------------------------------------------
201 BOOST_AUTO_TEST_CASE(GateOpeningInfoExtractor_testcase) {
202 
204 
205 } // BOOST_AUTO_TEST_CASE(GateOpeningInfoExtractor_testcase)
206 
207 
208 // -----------------------------------------------------------------------------
209 // END Test cases -------------------------------------------------------------
210 // -----------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(AllTests)
void GateOpeningInfoExtractor_test()
void closeAt(ClockTick_t tick, OpeningDiff_t count)
Close this gate at the specified time (decrease the opening by count).
void openBetween(ClockTick_t start, ClockTick_t end, OpeningDiff_t count=1)
Open this gate at specified start tick, and close it at end tick.
A logical multilevel gate for triggering.
OpeningCount_t openingCount(ClockTick_t tick) const
Returns the opening count of the gate at the specified tick.
icarus::trigger::TriggerGateData< int, int > TestedInputGate()
void openAt(ClockTick_t tick, OpeningDiff_t count)
Open this gate at the specified time (increase the opening by count).
Helper class to store transient trigger result.
Data types for detinfo::DetectorTimings.
ClockTick_t findMaxOpen(ClockTick_t start=MinTick, ClockTick_t end=MaxTick) const
Returns the tick at which the gate has the maximum opening.
Logical multi-level gate.
bool alwaysClosed() const
Returns whether this gate never opened.
std::pair< OpeningCount_t, OpeningCount_t > openingRange(ClockTick_t start, ClockTick_t end) const
Returns the range of trigger opening values in the specified range.
Helper to extract OpeningInfo_t from a trigger gate.
Definition: TriggerInfo_t.h:30