ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AxesTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AxesTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
12 
13 namespace Acts {
14 
15 using namespace detail;
16 
17 namespace Test {
18 
19 BOOST_AUTO_TEST_CASE(equidistant_axis) {
20  EquidistantAxis a(0.0, 10.0, 10u);
21 
22  // general binning properties
23  BOOST_CHECK_EQUAL(a.getNBins(), 10u);
24  BOOST_CHECK_EQUAL(a.getMax(), 10.);
25  BOOST_CHECK_EQUAL(a.getMin(), 0.);
26  BOOST_CHECK_EQUAL(a.getBinWidth(), 1.);
27 
28  // bin index calculation
29  BOOST_CHECK_EQUAL(a.getBin(-0.3), 0u);
30  BOOST_CHECK_EQUAL(a.getBin(-0.), 1u);
31  BOOST_CHECK_EQUAL(a.getBin(0.), 1u);
32  BOOST_CHECK_EQUAL(a.getBin(0.7), 1u);
33  BOOST_CHECK_EQUAL(a.getBin(1), 2u);
34  BOOST_CHECK_EQUAL(a.getBin(1.2), 2u);
35  BOOST_CHECK_EQUAL(a.getBin(2.), 3u);
36  BOOST_CHECK_EQUAL(a.getBin(2.7), 3u);
37  BOOST_CHECK_EQUAL(a.getBin(3.), 4u);
38  BOOST_CHECK_EQUAL(a.getBin(3.6), 4u);
39  BOOST_CHECK_EQUAL(a.getBin(4.), 5u);
40  BOOST_CHECK_EQUAL(a.getBin(4.98), 5u);
41  BOOST_CHECK_EQUAL(a.getBin(5.), 6u);
42  BOOST_CHECK_EQUAL(a.getBin(5.12), 6u);
43  BOOST_CHECK_EQUAL(a.getBin(6.), 7u);
44  BOOST_CHECK_EQUAL(a.getBin(6.00001), 7u);
45  BOOST_CHECK_EQUAL(a.getBin(7.), 8u);
46  BOOST_CHECK_EQUAL(a.getBin(7.5), 8u);
47  BOOST_CHECK_EQUAL(a.getBin(8.), 9u);
48  BOOST_CHECK_EQUAL(a.getBin(8.1), 9u);
49  BOOST_CHECK_EQUAL(a.getBin(9.), 10u);
50  BOOST_CHECK_EQUAL(a.getBin(9.999), 10u);
51  BOOST_CHECK_EQUAL(a.getBin(10.), 11u);
52  BOOST_CHECK_EQUAL(a.getBin(100.3), 11u);
53 
54  // lower bin boundaries
55  BOOST_CHECK_EQUAL(a.getBinLowerBound(1), 0.);
56  BOOST_CHECK_EQUAL(a.getBinLowerBound(2), 1.);
57  BOOST_CHECK_EQUAL(a.getBinLowerBound(3), 2.);
58  BOOST_CHECK_EQUAL(a.getBinLowerBound(4), 3.);
59  BOOST_CHECK_EQUAL(a.getBinLowerBound(5), 4.);
60  BOOST_CHECK_EQUAL(a.getBinLowerBound(6), 5.);
61  BOOST_CHECK_EQUAL(a.getBinLowerBound(7), 6.);
62  BOOST_CHECK_EQUAL(a.getBinLowerBound(8), 7.);
63  BOOST_CHECK_EQUAL(a.getBinLowerBound(9), 8.);
64  BOOST_CHECK_EQUAL(a.getBinLowerBound(10), 9.);
65 
66  // upper bin boundaries
67  BOOST_CHECK_EQUAL(a.getBinUpperBound(1), 1.);
68  BOOST_CHECK_EQUAL(a.getBinUpperBound(2), 2.);
69  BOOST_CHECK_EQUAL(a.getBinUpperBound(3), 3.);
70  BOOST_CHECK_EQUAL(a.getBinUpperBound(4), 4.);
71  BOOST_CHECK_EQUAL(a.getBinUpperBound(5), 5.);
72  BOOST_CHECK_EQUAL(a.getBinUpperBound(6), 6.);
73  BOOST_CHECK_EQUAL(a.getBinUpperBound(7), 7.);
74  BOOST_CHECK_EQUAL(a.getBinUpperBound(8), 8.);
75  BOOST_CHECK_EQUAL(a.getBinUpperBound(9), 9.);
76  BOOST_CHECK_EQUAL(a.getBinUpperBound(10), 10.);
77 
78  // bin centers
79  BOOST_CHECK_EQUAL(a.getBinCenter(1), 0.5);
80  BOOST_CHECK_EQUAL(a.getBinCenter(2), 1.5);
81  BOOST_CHECK_EQUAL(a.getBinCenter(3), 2.5);
82  BOOST_CHECK_EQUAL(a.getBinCenter(4), 3.5);
83  BOOST_CHECK_EQUAL(a.getBinCenter(5), 4.5);
84  BOOST_CHECK_EQUAL(a.getBinCenter(6), 5.5);
85  BOOST_CHECK_EQUAL(a.getBinCenter(7), 6.5);
86  BOOST_CHECK_EQUAL(a.getBinCenter(8), 7.5);
87  BOOST_CHECK_EQUAL(a.getBinCenter(9), 8.5);
88  BOOST_CHECK_EQUAL(a.getBinCenter(10), 9.5);
89 
90  // inside check
91  BOOST_CHECK(not a.isInside(-0.2));
92  BOOST_CHECK(a.isInside(0.));
93  BOOST_CHECK(a.isInside(3.));
94  BOOST_CHECK(not a.isInside(10.));
95  BOOST_CHECK(not a.isInside(12.));
96 }
97 
98 BOOST_AUTO_TEST_CASE(variable_axis) {
99  VariableAxis a({0, 0.5, 3, 4.5, 6});
100 
101  // general binning properties
102  BOOST_CHECK_EQUAL(a.getNBins(), 4u);
103  BOOST_CHECK_EQUAL(a.getMax(), 6.);
104  BOOST_CHECK_EQUAL(a.getMin(), 0.);
105 
106  // bin index calculation
107  BOOST_CHECK_EQUAL(a.getBin(-0.3), 0u);
108  BOOST_CHECK_EQUAL(a.getBin(-0.), 1u);
109  BOOST_CHECK_EQUAL(a.getBin(0.), 1u);
110  BOOST_CHECK_EQUAL(a.getBin(0.3), 1u);
111  BOOST_CHECK_EQUAL(a.getBin(0.5), 2u);
112  BOOST_CHECK_EQUAL(a.getBin(1.2), 2u);
113  BOOST_CHECK_EQUAL(a.getBin(2.7), 2u);
114  BOOST_CHECK_EQUAL(a.getBin(3.), 3u);
115  BOOST_CHECK_EQUAL(a.getBin(4.49999), 3u);
116  BOOST_CHECK_EQUAL(a.getBin(4.5), 4u);
117  BOOST_CHECK_EQUAL(a.getBin(5.12), 4u);
118  BOOST_CHECK_EQUAL(a.getBin(6.), 5u);
119  BOOST_CHECK_EQUAL(a.getBin(6.00001), 5u);
120  BOOST_CHECK_EQUAL(a.getBin(7.5), 5u);
121 
122  // lower bin boundaries
123  BOOST_CHECK_EQUAL(a.getBinLowerBound(1), 0.);
124  BOOST_CHECK_EQUAL(a.getBinLowerBound(2), 0.5);
125  BOOST_CHECK_EQUAL(a.getBinLowerBound(3), 3.);
126  BOOST_CHECK_EQUAL(a.getBinLowerBound(4), 4.5);
127 
128  // upper bin boundaries
129  BOOST_CHECK_EQUAL(a.getBinUpperBound(1), 0.5);
130  BOOST_CHECK_EQUAL(a.getBinUpperBound(2), 3.);
131  BOOST_CHECK_EQUAL(a.getBinUpperBound(3), 4.5);
132  BOOST_CHECK_EQUAL(a.getBinUpperBound(4), 6.);
133 
134  // bin centers
135  BOOST_CHECK_EQUAL(a.getBinCenter(1), 0.25);
136  BOOST_CHECK_EQUAL(a.getBinCenter(2), 1.75);
137  BOOST_CHECK_EQUAL(a.getBinCenter(3), 3.75);
138  BOOST_CHECK_EQUAL(a.getBinCenter(4), 5.25);
139 
140  // inside check
141  BOOST_CHECK(not a.isInside(-0.2));
142  BOOST_CHECK(a.isInside(0.));
143  BOOST_CHECK(a.isInside(3.));
144  BOOST_CHECK(not a.isInside(6.));
145  BOOST_CHECK(not a.isInside(12.));
146 }
147 
150 
151  // normal inside
152  BOOST_CHECK_EQUAL(a.getBin(0.5), 1u);
153  BOOST_CHECK_EQUAL(a.getBin(9.5), 10u);
154 
155  // out of bounds, but is open
156  // -> should clamp
157  BOOST_CHECK_EQUAL(a.getBin(-0.5), 1u);
158  BOOST_CHECK_EQUAL(a.getBin(10.5), 10u);
159 
161  {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
162 
163  // normal inside
164  BOOST_CHECK_EQUAL(b.getBin(0.5), 1u);
165  BOOST_CHECK_EQUAL(b.getBin(9.5), 10u);
166 
167  // out of bounds, but is open
168  // -> should clamp
169  BOOST_CHECK_EQUAL(b.getBin(-0.5), 1u);
170  BOOST_CHECK_EQUAL(b.getBin(10.5), 10u);
171 }
172 
173 BOOST_AUTO_TEST_CASE(closed_axis) {
175 
176  // normal inside
177  BOOST_CHECK_EQUAL(a.getBin(0.5), 1u);
178  BOOST_CHECK_EQUAL(a.getBin(9.5), 10u);
179 
180  // out of bounds, but is closed
181  // -> should wrap to opposite side bin
182  BOOST_CHECK_EQUAL(a.getBin(-0.5), 10u);
183  BOOST_CHECK_EQUAL(a.getBin(10.5), 1u);
184 
186  {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
187 
188  // normal inside
189  BOOST_CHECK_EQUAL(b.getBin(0.5), 1u);
190  BOOST_CHECK_EQUAL(b.getBin(9.5), 10u);
191 
192  // out of bounds, but is closed
193  // -> should wrap to opposite side bin
194  BOOST_CHECK_EQUAL(b.getBin(-0.5), 10u);
195  BOOST_CHECK_EQUAL(b.getBin(10.5), 1u);
196 }
197 
198 BOOST_AUTO_TEST_CASE(neighborhood) {
199  using bins_t = std::vector<size_t>;
201 
202  BOOST_CHECK(a1.neighborHoodIndices(0, 1).collect() == bins_t({0, 1}));
203  BOOST_CHECK(a1.neighborHoodIndices(1, 1).collect() == bins_t({0, 1, 2}));
204  BOOST_CHECK(a1.neighborHoodIndices(11, 1).collect() == bins_t({10, 11}));
205  BOOST_CHECK(a1.neighborHoodIndices(10, 1).collect() == bins_t({9, 10, 11}));
206  BOOST_CHECK(a1.neighborHoodIndices(5, 1).collect() == bins_t({4, 5, 6}));
207  BOOST_CHECK(a1.neighborHoodIndices(5, {1, 0}).collect() == bins_t({4, 5}));
208  BOOST_CHECK(a1.neighborHoodIndices(5, {0, 1}).collect() == bins_t({5, 6}));
209 
210  BOOST_CHECK(a1.neighborHoodIndices(0, 2).collect() == bins_t({0, 1, 2}));
211  BOOST_CHECK(a1.neighborHoodIndices(1, 2).collect() == bins_t({0, 1, 2, 3}));
212  BOOST_CHECK(a1.neighborHoodIndices(11, 2).collect() == bins_t({9, 10, 11}));
213  BOOST_CHECK(a1.neighborHoodIndices(10, 2).collect() ==
214  bins_t({8, 9, 10, 11}));
215  BOOST_CHECK(a1.neighborHoodIndices(5, 2).collect() ==
216  bins_t({3, 4, 5, 6, 7}));
217 
219  {0.0, 2.0, 4.0, 9.0, 10.0});
220  BOOST_CHECK(a2.neighborHoodIndices(0, 1).collect() == bins_t({0, 1}));
221  BOOST_CHECK(a2.neighborHoodIndices(1, 1).collect() == bins_t({0, 1, 2}));
222  BOOST_CHECK(a2.neighborHoodIndices(5, 1).collect() == bins_t({4, 5}));
223  BOOST_CHECK(a2.neighborHoodIndices(4, 1).collect() == bins_t({3, 4, 5}));
224  BOOST_CHECK(a2.neighborHoodIndices(4, {1, 0}).collect() == bins_t({3, 4}));
225  BOOST_CHECK(a2.neighborHoodIndices(2, 1).collect() == bins_t({1, 2, 3}));
226  BOOST_CHECK(a2.neighborHoodIndices(2, {0, 1}).collect() == bins_t({2, 3}));
227 
228  BOOST_CHECK(a2.neighborHoodIndices(0, 2).collect() == bins_t({0, 1, 2}));
229  BOOST_CHECK(a2.neighborHoodIndices(1, 2).collect() == bins_t({0, 1, 2, 3}));
230  BOOST_CHECK(a2.neighborHoodIndices(5, 2).collect() == bins_t({3, 4, 5}));
231  BOOST_CHECK(a2.neighborHoodIndices(4, 2).collect() == bins_t({2, 3, 4, 5}));
232  BOOST_CHECK(a2.neighborHoodIndices(3, 2).collect() ==
233  bins_t({1, 2, 3, 4, 5}));
234 
236 
237  BOOST_CHECK(a3.neighborHoodIndices(0, 1).collect() == bins_t({}));
238  BOOST_CHECK(a3.neighborHoodIndices(1, 1).collect() == bins_t({1, 2}));
239  BOOST_CHECK(a3.neighborHoodIndices(11, 1).collect() == bins_t({}));
240  BOOST_CHECK(a3.neighborHoodIndices(10, 1).collect() == bins_t({9, 10}));
241  BOOST_CHECK(a3.neighborHoodIndices(10, {0, 1}).collect() == bins_t({10}));
242  BOOST_CHECK(a3.neighborHoodIndices(5, 1).collect() == bins_t({4, 5, 6}));
243  BOOST_CHECK(a3.neighborHoodIndices(5, {1, 0}).collect() == bins_t({4, 5}));
244  BOOST_CHECK(a3.neighborHoodIndices(5, {0, 1}).collect() == bins_t({5, 6}));
245 
246  BOOST_CHECK(a3.neighborHoodIndices(0, 2).collect() == bins_t({}));
247  BOOST_CHECK(a3.neighborHoodIndices(1, 2).collect() == bins_t({1, 2, 3}));
248  BOOST_CHECK(a3.neighborHoodIndices(11, 2).collect() == bins_t({}));
249  BOOST_CHECK(a3.neighborHoodIndices(10, 2).collect() == bins_t({8, 9, 10}));
250  BOOST_CHECK(a3.neighborHoodIndices(5, 2).collect() ==
251  bins_t({3, 4, 5, 6, 7}));
252 
254 
255  BOOST_CHECK(a4.neighborHoodIndices(0, 1).collect() == bins_t({}));
256  BOOST_CHECK(a4.neighborHoodIndices(1, 1).collect() == bins_t({10, 1, 2}));
257  BOOST_CHECK(a4.neighborHoodIndices(11, 1).collect() == bins_t({}));
258  BOOST_CHECK(a4.neighborHoodIndices(10, 1).collect() == bins_t({9, 10, 1}));
259  BOOST_CHECK(a4.neighborHoodIndices(10, {0, 1}).collect() == bins_t({10, 1}));
260  BOOST_CHECK(a4.neighborHoodIndices(5, 1).collect() == bins_t({4, 5, 6}));
261  BOOST_CHECK(a4.neighborHoodIndices(5, {1, 0}).collect() == bins_t({4, 5}));
262  BOOST_CHECK(a4.neighborHoodIndices(5, {0, 1}).collect() == bins_t({5, 6}));
263 
264  BOOST_CHECK(a4.neighborHoodIndices(0, 2).collect() == bins_t({}));
265  BOOST_CHECK(a4.neighborHoodIndices(1, 2).collect() ==
266  bins_t({9, 10, 1, 2, 3}));
267  BOOST_CHECK(a4.neighborHoodIndices(11, 2).collect() == bins_t({}));
268  BOOST_CHECK(a4.neighborHoodIndices(10, 2).collect() ==
269  bins_t({8, 9, 10, 1, 2}));
270  BOOST_CHECK(a4.neighborHoodIndices(5, 2).collect() ==
271  bins_t({3, 4, 5, 6, 7}));
272 
274  {0.0, 2.0, 4.0, 9.0, 9.5, 10.0});
275  BOOST_CHECK(a5.neighborHoodIndices(0, 1).collect() == bins_t({}));
276  BOOST_CHECK(a5.neighborHoodIndices(1, 1).collect() == bins_t({1, 2}));
277  BOOST_CHECK(a5.neighborHoodIndices(6, 1).collect() == bins_t({}));
278  BOOST_CHECK(a5.neighborHoodIndices(5, 1).collect() == bins_t({4, 5}));
279  BOOST_CHECK(a5.neighborHoodIndices(5, {0, 1}).collect() == bins_t({5}));
280  BOOST_CHECK(a5.neighborHoodIndices(2, 1).collect() == bins_t({1, 2, 3}));
281  BOOST_CHECK(a5.neighborHoodIndices(2, {1, 0}).collect() == bins_t({1, 2}));
282  BOOST_CHECK(a5.neighborHoodIndices(2, {0, 1}).collect() == bins_t({2, 3}));
283 
284  BOOST_CHECK(a5.neighborHoodIndices(0, 2).collect() == bins_t({}));
285  BOOST_CHECK(a5.neighborHoodIndices(1, 2).collect() == bins_t({1, 2, 3}));
286  BOOST_CHECK(a5.neighborHoodIndices(6, 2).collect() == bins_t({}));
287  BOOST_CHECK(a5.neighborHoodIndices(5, 2).collect() == bins_t({3, 4, 5}));
288  BOOST_CHECK(a5.neighborHoodIndices(3, 2).collect() ==
289  bins_t({1, 2, 3, 4, 5}));
290 
292  {0.0, 2.0, 4.0, 9.0, 9.5, 10.0});
293  BOOST_CHECK(a6.neighborHoodIndices(0, 1).collect() == bins_t({}));
294  BOOST_CHECK(a6.neighborHoodIndices(1, 1).collect() == bins_t({5, 1, 2}));
295  BOOST_CHECK(a6.neighborHoodIndices(6, 1).collect() == bins_t({}));
296  BOOST_CHECK(a6.neighborHoodIndices(5, 1).collect() == bins_t({4, 5, 1}));
297  BOOST_CHECK(a6.neighborHoodIndices(5, {0, 1}).collect() == bins_t({5, 1}));
298  BOOST_CHECK(a6.neighborHoodIndices(2, 1).collect() == bins_t({1, 2, 3}));
299  BOOST_CHECK(a6.neighborHoodIndices(2, {1, 0}).collect() == bins_t({1, 2}));
300  BOOST_CHECK(a6.neighborHoodIndices(2, {0, 1}).collect() == bins_t({2, 3}));
301 
302  BOOST_CHECK(a6.neighborHoodIndices(0, 2).collect() == bins_t({}));
303  BOOST_CHECK(a6.neighborHoodIndices(1, 2).collect() ==
304  bins_t({4, 5, 1, 2, 3}));
305  BOOST_CHECK(a6.neighborHoodIndices(6, 2).collect() == bins_t({}));
306  BOOST_CHECK(a6.neighborHoodIndices(5, 2).collect() ==
307  bins_t({3, 4, 5, 1, 2}));
308  BOOST_CHECK(a6.neighborHoodIndices(3, 2).collect() ==
309  bins_t({1, 2, 3, 4, 5}));
310  BOOST_CHECK(a6.neighborHoodIndices(3, {0, 2}).collect() == bins_t({3, 4, 5}));
311 
312  BOOST_CHECK(a6.neighborHoodIndices(1, 3).collect() ==
313  bins_t({3, 4, 5, 1, 2}));
314  BOOST_CHECK(a6.neighborHoodIndices(5, 3).collect() ==
315  bins_t({2, 3, 4, 5, 1}));
316 }
317 
320  BOOST_CHECK_EQUAL(a1.wrapBin(0), 0u);
321  BOOST_CHECK_EQUAL(a1.wrapBin(1), 1u);
322  BOOST_CHECK_EQUAL(a1.wrapBin(-1), 0u);
323  BOOST_CHECK_EQUAL(a1.wrapBin(10), 10u);
324  BOOST_CHECK_EQUAL(a1.wrapBin(11), 11u);
325  BOOST_CHECK_EQUAL(a1.wrapBin(12), 11u);
326 
328  BOOST_CHECK_EQUAL(a2.wrapBin(0), 1u);
329  BOOST_CHECK_EQUAL(a2.wrapBin(1), 1u);
330  BOOST_CHECK_EQUAL(a2.wrapBin(-1), 1u);
331  BOOST_CHECK_EQUAL(a2.wrapBin(10), 10u);
332  BOOST_CHECK_EQUAL(a2.wrapBin(11), 10u);
333  BOOST_CHECK_EQUAL(a2.wrapBin(12), 10u);
334 
336  BOOST_CHECK_EQUAL(a3.wrapBin(0), 10u);
337  BOOST_CHECK_EQUAL(a3.wrapBin(1), 1u);
338  BOOST_CHECK_EQUAL(a3.wrapBin(-1), 9u);
339  BOOST_CHECK_EQUAL(a3.wrapBin(10), 10u);
340  BOOST_CHECK_EQUAL(a3.wrapBin(11), 1u);
341  BOOST_CHECK_EQUAL(a3.wrapBin(12), 2u);
342 
344  {0.0, 2.0, 4.0, 9.0, 10.0});
345  BOOST_CHECK_EQUAL(a4.wrapBin(0), 0u);
346  BOOST_CHECK_EQUAL(a4.wrapBin(1), 1u);
347  BOOST_CHECK_EQUAL(a4.wrapBin(-1), 0u);
348  BOOST_CHECK_EQUAL(a4.wrapBin(4), 4u);
349  BOOST_CHECK_EQUAL(a4.wrapBin(5), 5u);
350  BOOST_CHECK_EQUAL(a4.wrapBin(6), 5u);
351 
353  {0.0, 2.0, 4.0, 9.0, 9.5, 10.0});
354  BOOST_CHECK_EQUAL(a5.wrapBin(0), 1u);
355  BOOST_CHECK_EQUAL(a5.wrapBin(1), 1u);
356  BOOST_CHECK_EQUAL(a5.wrapBin(-1), 1u);
357  BOOST_CHECK_EQUAL(a5.wrapBin(4), 4u);
358  BOOST_CHECK_EQUAL(a5.wrapBin(5), 5u);
359  BOOST_CHECK_EQUAL(a5.wrapBin(6), 5u);
360 
362  {0.0, 2.0, 4.0, 9.0, 9.5, 10.0});
363  BOOST_CHECK_EQUAL(a6.wrapBin(0), 5u);
364  BOOST_CHECK_EQUAL(a6.wrapBin(1), 1u);
365  BOOST_CHECK_EQUAL(a6.wrapBin(-1), 4u);
366  BOOST_CHECK_EQUAL(a6.wrapBin(4), 4u);
367  BOOST_CHECK_EQUAL(a6.wrapBin(5), 5u);
368  BOOST_CHECK_EQUAL(a6.wrapBin(6), 1u);
369  BOOST_CHECK_EQUAL(a6.wrapBin(7), 2u);
370 }
371 
372 } // namespace Test
373 
374 } // namespace Acts