EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeometryIdentifierTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GeometryIdentifierTests.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 namespace Test {
15 
16 BOOST_AUTO_TEST_CASE(GeometryIdentifier_construct_default) {
18  BOOST_CHECK_EQUAL(id.volume(), 0u);
19  BOOST_CHECK_EQUAL(id.boundary(), 0u);
20  BOOST_CHECK_EQUAL(id.layer(), 0u);
21  BOOST_CHECK_EQUAL(id.approach(), 0u);
22  BOOST_CHECK_EQUAL(id.sensitive(), 0u);
23 }
24 
25 BOOST_AUTO_TEST_CASE(GeometryIdentifier_construct_encoded) {
26  // not sure if it is a good idea to test for the encoding since it should be
27  // an implementation detail. only the resulting functionality is relevant.
28  GeometryIdentifier id = 0xa0b00c00d00affe0u;
29  BOOST_CHECK_EQUAL(id.volume(), 0xa0u);
30  BOOST_CHECK_EQUAL(id.boundary(), 0xb0u);
31  BOOST_CHECK_EQUAL(id.layer(), 0x0c0u);
32  BOOST_CHECK_EQUAL(id.approach(), 0x0du);
33  BOOST_CHECK_EQUAL(id.sensitive(), 0x00affe0u);
34 }
35 
36 BOOST_AUTO_TEST_CASE(GeometryIdentifier_max_values) {
37  // compute maximum value for each component
38  constexpr GeometryIdentifier::Value volumeMax = (1u << 8) - 1;
39  constexpr GeometryIdentifier::Value boundaryMax = (1u << 8) - 1;
40  constexpr GeometryIdentifier::Value layerMax = (1u << 12) - 1;
41  constexpr GeometryIdentifier::Value approachMax = (1u << 8) - 1;
42  constexpr GeometryIdentifier::Value sensitiveMax = (1u << 28) - 1;
43  // reference values non-zero values everywhere
44  constexpr GeometryIdentifier ref = 0xdeadaffe01234567;
45  // values above the maximum are truncated
46  // max+1 has all available bits zeroed
47  BOOST_CHECK_EQUAL(GeometryIdentifier(ref).setVolume(volumeMax + 1),
48  GeometryIdentifier(ref).setVolume(0u));
49  BOOST_CHECK_EQUAL(GeometryIdentifier(ref).setBoundary(boundaryMax + 1),
50  GeometryIdentifier(ref).setBoundary(0u));
51  BOOST_CHECK_EQUAL(GeometryIdentifier(ref).setLayer(layerMax + 1),
52  GeometryIdentifier(ref).setLayer(0u));
53  BOOST_CHECK_EQUAL(GeometryIdentifier(ref).setApproach(approachMax + 1),
54  GeometryIdentifier(ref).setApproach(0u));
55  BOOST_CHECK_EQUAL(GeometryIdentifier(ref).setSensitive(sensitiveMax + 1),
56  GeometryIdentifier(ref).setSensitive(0u));
57 }
58 
59 BOOST_AUTO_TEST_CASE(GeometryIdentifier_order) {
60  auto vol1 = GeometryIdentifier().setVolume(1u).setLayer(14u).setSensitive(5u);
61  auto vol2 = GeometryIdentifier().setVolume(2u).setLayer(13u).setSensitive(3u);
62  // order uses volume first even if other components are larger
63  BOOST_CHECK_LT(vol1, vol2);
64  BOOST_CHECK_LT(GeometryIdentifier(vol1).setBoundary(64u), vol2);
65  BOOST_CHECK_LT(GeometryIdentifier(vol1).setLayer(64u), vol2);
66  BOOST_CHECK_LT(GeometryIdentifier(vol1).setApproach(64u), vol2);
67  BOOST_CHECK_LT(GeometryIdentifier(vol1).setSensitive(64u), vol2);
68  BOOST_CHECK_LT(vol2, GeometryIdentifier(vol1).setVolume(3u));
69  // other components are hierachical
70  BOOST_CHECK_LT(GeometryIdentifier(vol1).setVolume(1u).setBoundary(2u),
71  GeometryIdentifier(vol1).setVolume(2u).setBoundary(1u));
72  BOOST_CHECK_LT(GeometryIdentifier(vol1).setBoundary(1u).setLayer(2u),
73  GeometryIdentifier(vol1).setBoundary(2u).setLayer(1u));
74  BOOST_CHECK_LT(GeometryIdentifier(vol1).setLayer(1u).setApproach(2u),
75  GeometryIdentifier(vol1).setLayer(2u).setApproach(1u));
76  BOOST_CHECK_LT(GeometryIdentifier(vol1).setApproach(1u).setSensitive(2u),
77  GeometryIdentifier(vol1).setApproach(2u).setSensitive(1u));
78 }
79 
80 } // namespace Test
81 } // namespace Acts