Project
Loading...
Searching...
No Matches
CathodeSegmentation.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#define BOOST_TEST_MODULE Test MCHMappingTest CathodeSegmentation
16#define BOOST_TEST_DYN_LINK
17#define BOOST_TEST_MAIN
18
19#include <boost/test/unit_test.hpp>
20
21#include "boost/format.hpp"
26#include <boost/test/data/monomorphic.hpp>
27#include <boost/test/data/monomorphic/generators/xrange.hpp>
28#include <boost/test/data/test_case.hpp>
29#include <limits>
30#include <fstream>
31#include <iostream>
32#include "TestParameters.h"
33#include <fmt/format.h>
34
35using namespace o2::mch::mapping;
36namespace bdata = boost::unit_test::data;
37
38BOOST_AUTO_TEST_SUITE(o2_mch_mapping)
39BOOST_AUTO_TEST_SUITE(cathode_segmentation)
40
41BOOST_AUTO_TEST_CASE(NumberOfDetectionElementsIs156)
42{
43 std::vector<int> des;
44 forEachDetectionElement([&des](int detElemId) { des.push_back(detElemId); });
45 BOOST_CHECK_EQUAL(des.size(), 156);
46}
47
48BOOST_AUTO_TEST_CASE(GetCathodeSegmentationMustNotThrowIfDetElemIdIsValid)
49{
53 });
54}
55
56BOOST_AUTO_TEST_CASE(GetCathodeSegmentationThrowsIfDetElemIdIsNotValid)
57{
58 BOOST_CHECK_THROW(CathodeSegmentation(-1, true), std::runtime_error);
59 BOOST_CHECK_THROW(CathodeSegmentation(121, true), std::runtime_error);
60}
61
62BOOST_AUTO_TEST_CASE(NofBendingPads)
63{
64 // we explicitly don't make a loop
65 // we prefer this solution to more clearly document the number of pads per DE-type
66 // sorted by number of pads.
67
68 BOOST_CHECK_EQUAL(CathodeSegmentation(100, true).nofPads(), 14392);
69 BOOST_CHECK_EQUAL(CathodeSegmentation(300, true).nofPads(), 13947);
70 BOOST_CHECK_EQUAL(CathodeSegmentation(902, true).nofPads(), 4480);
71 BOOST_CHECK_EQUAL(CathodeSegmentation(702, true).nofPads(), 4160);
72 BOOST_CHECK_EQUAL(CathodeSegmentation(701, true).nofPads(), 4096);
73 BOOST_CHECK_EQUAL(CathodeSegmentation(601, true).nofPads(), 3648);
74 BOOST_CHECK_EQUAL(CathodeSegmentation(501, true).nofPads(), 3568);
75 BOOST_CHECK_EQUAL(CathodeSegmentation(602, true).nofPads(), 3200);
76 BOOST_CHECK_EQUAL(CathodeSegmentation(700, true).nofPads(), 3200);
77 BOOST_CHECK_EQUAL(CathodeSegmentation(502, true).nofPads(), 3120);
78 BOOST_CHECK_EQUAL(CathodeSegmentation(600, true).nofPads(), 3008);
79 BOOST_CHECK_EQUAL(CathodeSegmentation(500, true).nofPads(), 2928);
80 BOOST_CHECK_EQUAL(CathodeSegmentation(903, true).nofPads(), 2880);
81 BOOST_CHECK_EQUAL(CathodeSegmentation(703, true).nofPads(), 2560);
82 BOOST_CHECK_EQUAL(CathodeSegmentation(904, true).nofPads(), 2240);
83 BOOST_CHECK_EQUAL(CathodeSegmentation(503, true).nofPads(), 1920);
84 BOOST_CHECK_EQUAL(CathodeSegmentation(704, true).nofPads(), 1920);
85 BOOST_CHECK_EQUAL(CathodeSegmentation(504, true).nofPads(), 1280);
86 BOOST_CHECK_EQUAL(CathodeSegmentation(905, true).nofPads(), 1280);
87 BOOST_CHECK_EQUAL(CathodeSegmentation(705, true).nofPads(), 960);
88 BOOST_CHECK_EQUAL(CathodeSegmentation(706, true).nofPads(), 640);
89}
90
91BOOST_AUTO_TEST_CASE(NofNonBendingPads)
92{
93 BOOST_CHECK_EQUAL(CathodeSegmentation(100, false).nofPads(), 14280);
94#if MCH_MAPPING_RUN3_AND_ABOVE
95 BOOST_CHECK_EQUAL(CathodeSegmentation(300, false).nofPads(), 13926);
96#else
97 BOOST_CHECK_EQUAL(CathodeSegmentation(300, false).nofPads(), 13986);
98#endif
99
100 BOOST_CHECK_EQUAL(CathodeSegmentation(902, false).nofPads(), 3136);
101 BOOST_CHECK_EQUAL(CathodeSegmentation(702, false).nofPads(), 2912);
102 BOOST_CHECK_EQUAL(CathodeSegmentation(701, false).nofPads(), 2880);
103 BOOST_CHECK_EQUAL(CathodeSegmentation(601, false).nofPads(), 2560);
104 BOOST_CHECK_EQUAL(CathodeSegmentation(501, false).nofPads(), 2496);
105 BOOST_CHECK_EQUAL(CathodeSegmentation(602, false).nofPads(), 2240);
106 BOOST_CHECK_EQUAL(CathodeSegmentation(700, false).nofPads(), 2240);
107 BOOST_CHECK_EQUAL(CathodeSegmentation(502, false).nofPads(), 2176);
108 BOOST_CHECK_EQUAL(CathodeSegmentation(600, false).nofPads(), 2112);
109 BOOST_CHECK_EQUAL(CathodeSegmentation(500, false).nofPads(), 2048);
110 BOOST_CHECK_EQUAL(CathodeSegmentation(903, false).nofPads(), 2016);
111 BOOST_CHECK_EQUAL(CathodeSegmentation(703, false).nofPads(), 1792);
112 BOOST_CHECK_EQUAL(CathodeSegmentation(904, false).nofPads(), 1568);
113 BOOST_CHECK_EQUAL(CathodeSegmentation(503, false).nofPads(), 1344);
114 BOOST_CHECK_EQUAL(CathodeSegmentation(704, false).nofPads(), 1344);
115 BOOST_CHECK_EQUAL(CathodeSegmentation(504, false).nofPads(), 896);
116 BOOST_CHECK_EQUAL(CathodeSegmentation(905, false).nofPads(), 896);
117 BOOST_CHECK_EQUAL(CathodeSegmentation(705, false).nofPads(), 672);
118 BOOST_CHECK_EQUAL(CathodeSegmentation(706, false).nofPads(), 448);
119}
120
121BOOST_AUTO_TEST_CASE(TotalNofBendingFECInSegTypes)
122{
123 int nb{0};
124 int nnb{0};
126 nb += CathodeSegmentation(detElemId, true).nofDualSampas();
127 nnb += CathodeSegmentation(detElemId, false).nofDualSampas();
128 });
129 BOOST_CHECK_EQUAL(nb, 1246);
130#if MCH_MAPPING_RUN3_AND_ABOVE
131 BOOST_CHECK_EQUAL(nnb, 1018);
132#else
133 BOOST_CHECK_EQUAL(nnb, 1019);
134#endif
135}
136
137BOOST_AUTO_TEST_CASE(BendingBoundingBox)
138{
160}
161
162BOOST_AUTO_TEST_CASE(NonBendingBoundingBox)
163{
164 BOOST_CHECK_EQUAL(getBBox(CathodeSegmentation(100, false)), o2::mch::contour::BBox<double>(-0.315, 0.21, 89.145, 89.25));
165 BOOST_CHECK_EQUAL(getBBox(CathodeSegmentation(300, false)), o2::mch::contour::BBox<double>(-0.625, -0.5, 115.625, 117.5));
166 BOOST_CHECK_EQUAL(getBBox(CathodeSegmentation(500, false)), o2::mch::contour::BBox<double>(-74.2857, -20, 58.5714, 20));
185}
186
188{
210}
211
212BOOST_AUTO_TEST_CASE(NofNonBendingFEC)
213{
215#if MCH_MAPPING_RUN3_AND_ABOVE
217#else
219#endif
239}
240
241BOOST_AUTO_TEST_CASE(CountPadsInCathodeSegmentations)
242{
243 int n{0};
245 for (auto plane : {true, false}) {
246 CathodeSegmentation seg{detElemId, plane};
247 n += seg.nofPads();
248 }
249 });
250#if MCH_MAPPING_RUN3_AND_ABOVE
251 BOOST_CHECK_EQUAL(n, 143409);
252#else
253 BOOST_CHECK_EQUAL(n, 143469);
254#endif
255}
256
257BOOST_AUTO_TEST_CASE(LoopOnCathodeSegmentations)
258{
259 int n{0};
261 n += 2; // two planes (bending, non-bending)
262 });
263 BOOST_CHECK_EQUAL(n, 42);
264}
265
266BOOST_AUTO_TEST_CASE(DualSampasWithLessThan64Pads)
267{
268 std::map<int, int> non64;
269 forOneDetectionElementOfEachSegmentationType([&non64](int detElemId) {
270 for (auto plane : {true, false}) {
271 CathodeSegmentation seg{detElemId, plane};
272 for (int i = 0; i < seg.nofDualSampas(); ++i) {
273 int n{0};
274 seg.forEachPadInDualSampa(seg.dualSampaId(i), [&n](int /*catPadIndex*/) { ++n; });
275 if (n != 64) {
276 non64[n]++;
277 }
278 }
279 }
280 });
281
282 BOOST_CHECK_EQUAL(non64[31], 1);
283 BOOST_CHECK_EQUAL(non64[32], 2);
284 BOOST_CHECK_EQUAL(non64[39], 1);
285 BOOST_CHECK_EQUAL(non64[40], 3);
286 BOOST_CHECK_EQUAL(non64[46], 2);
287 BOOST_CHECK_EQUAL(non64[48], 10);
288 BOOST_CHECK_EQUAL(non64[49], 1);
289 BOOST_CHECK_EQUAL(non64[50], 1);
290 BOOST_CHECK_EQUAL(non64[52], 3);
291 BOOST_CHECK_EQUAL(non64[54], 2);
292 BOOST_CHECK_EQUAL(non64[55], 3);
293 BOOST_CHECK_EQUAL(non64[56], 114);
294 BOOST_CHECK_EQUAL(non64[57], 3);
295 BOOST_CHECK_EQUAL(non64[58], 2);
296 BOOST_CHECK_EQUAL(non64[59], 1);
297#if MCH_MAPPING_RUN3_AND_ABOVE
298 BOOST_CHECK_EQUAL(non64[60], 5);
299#else
300 BOOST_CHECK_EQUAL(non64[60], 6);
301#endif
302 BOOST_CHECK_EQUAL(non64[62], 4);
303 BOOST_CHECK_EQUAL(non64[63], 7);
304
305 int n{0};
306 for (auto p : non64) {
307 n += p.second;
308 }
309
310#if MCH_MAPPING_RUN3_AND_ABOVE
311 BOOST_CHECK_EQUAL(n, 165);
312#else
313 BOOST_CHECK_EQUAL(n, 166);
314#endif
315}
316
317struct SEG {
319};
320
321BOOST_FIXTURE_TEST_SUITE(HasPadBy, SEG)
322
323BOOST_AUTO_TEST_CASE(ThrowsIfDualSampaChannelIsNotBetween0And63)
324{
325 BOOST_CHECK_THROW(seg.findPadByFEE(102, -1), std::out_of_range);
326 BOOST_CHECK_THROW(seg.findPadByFEE(102, 64), std::out_of_range);
327}
328
329BOOST_AUTO_TEST_CASE(ReturnsFalseIfCatPadIdIsOutOfRange)
330{
332 for (auto plane : {true, false}) {
333 CathodeSegmentation seg{detElemId, plane};
334 BOOST_TEST_INFO_SCOPE(fmt::format("DeId {} Bending {}", detElemId, plane));
335 BOOST_CHECK_EQUAL(seg.isValid(0), true);
337 BOOST_CHECK_EQUAL(seg.isValid(-1), false);
339 }
340 });
341}
342
343BOOST_AUTO_TEST_CASE(ReturnsTrueIfPadIsConnected)
344{
346}
347
348BOOST_AUTO_TEST_CASE(ReturnsFalseIfPadIsNotConnected)
349{
351 int testChannel{14};
352 if (params.isSegmentationRun3) {
353 testChannel = 39;
354 }
355 BOOST_CHECK_EQUAL(seg.isValid(seg.findPadByFEE(214, testChannel)), false);
356}
357
358BOOST_AUTO_TEST_CASE(HasPadByPosition)
359{
361}
362
363BOOST_AUTO_TEST_CASE(CheckPositionOfOnePadInDE100Bending)
364{
366 int testChannel{9};
367 if (params.isSegmentationRun3) {
368 testChannel = 47;
369 }
370 BOOST_CHECK_EQUAL(seg.findPadByFEE(76, testChannel), seg.findPadByPosition(1.575, 18.69));
371}
372
374{
376 BOOST_TEST((copy == seg));
377 BOOST_TEST(copy.nofPads() == seg.nofPads());
378}
379
380BOOST_AUTO_TEST_CASE(CheckAssignment)
381{
382 CathodeSegmentation copy{200, true};
383 copy = seg;
384 BOOST_TEST((copy == seg));
385 BOOST_TEST(copy.nofPads() == seg.nofPads());
386}
387BOOST_AUTO_TEST_SUITE_END()
388BOOST_AUTO_TEST_SUITE_END()
389BOOST_AUTO_TEST_SUITE_END()
o2::mch::mapping::CathodeSegmentation seg
BOOST_AUTO_TEST_CASE(NumberOfDetectionElementsIs156)
int32_t i
A CathodeSegmentation lets you find pads on a given plane (cathode) of a detection element and then i...
int dualSampaId(int dualSampaIndex) const
void forEachPadInDualSampa(int dualSampaId, CALLABLE &&func) const
int findPadByPosition(double x, double y) const
int findPadByFEE(int dualSampaId, int dualSampaChannel) const
bool isValid(int catPadIndex) const
Not every integer is a valid catPadIndex. This method will tell if catPadIndex is a valid one.
GLdouble n
Definition glcorearb.h:1982
GLenum const GLfloat * params
Definition glcorearb.h:272
void forOneDetectionElementOfEachSegmentationType(CALLABLE &&func)
o2::mch::contour::BBox< double > getBBox(const CathodeSegmentation &seg)
void forEachDetectionElement(CALLABLE &&func)
CathodeSegmentation seg
std::set< int > nofDualSampas(std::array< int, N > deIds)
BOOST_CHECK_NO_THROW(algorithm::merge(target, other))
BOOST_TEST(digits==digitsD, boost::test_tools::per_element())
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())