Analysis Software
Documentation for sPHENIX simulation 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(), 0x00affu);
34  BOOST_CHECK_EQUAL(id.extra(), 0xe0u);
35 }
36 
37 BOOST_AUTO_TEST_CASE(GeometryIdentifier_max_values) {
38  // compute maximum value for each component
39  constexpr GeometryIdentifier::Value volumeMax = (1u << 8) - 1;
40  constexpr GeometryIdentifier::Value boundaryMax = (1u << 8) - 1;
41  constexpr GeometryIdentifier::Value layerMax = (1u << 12) - 1;
42  constexpr GeometryIdentifier::Value approachMax = (1u << 8) - 1;
43  constexpr GeometryIdentifier::Value sensitiveMax = (1u << 20) - 1;
44  constexpr GeometryIdentifier::Value extraMax = (1u << 8) - 1;
45  // reference values non-zero values everywhere
46  constexpr GeometryIdentifier ref = 0xdeadaffe01234567;
47  // values above the maximum are truncated
48  // max+1 has all available bits zeroed
49  BOOST_CHECK_EQUAL(GeometryIdentifier(ref).setVolume(volumeMax + 1),
50  GeometryIdentifier(ref).setVolume(0u));
51  BOOST_CHECK_EQUAL(GeometryIdentifier(ref).setBoundary(boundaryMax + 1),
52  GeometryIdentifier(ref).setBoundary(0u));
53  BOOST_CHECK_EQUAL(GeometryIdentifier(ref).setLayer(layerMax + 1),
54  GeometryIdentifier(ref).setLayer(0u));
55  BOOST_CHECK_EQUAL(GeometryIdentifier(ref).setApproach(approachMax + 1),
56  GeometryIdentifier(ref).setApproach(0u));
57  BOOST_CHECK_EQUAL(GeometryIdentifier(ref).setSensitive(sensitiveMax + 1),
58  GeometryIdentifier(ref).setSensitive(0u));
59  BOOST_CHECK_EQUAL(GeometryIdentifier(ref).setExtra(extraMax + 1),
60  GeometryIdentifier(ref).setExtra(0u));
61 }
62 
63 BOOST_AUTO_TEST_CASE(GeometryIdentifier_order) {
64  auto vol1 = GeometryIdentifier()
65  .setVolume(1u)
66  .setLayer(14u)
67  .setSensitive(5u)
68  .setExtra(42u);
69  auto vol2 = GeometryIdentifier()
70  .setVolume(2u)
71  .setLayer(13u)
72  .setSensitive(3u)
73  .setExtra(43u);
74  // order uses volume first even if other components are larger
75  BOOST_CHECK_LT(vol1, vol2);
76  BOOST_CHECK_LT(GeometryIdentifier(vol1).setBoundary(64u), vol2);
77  BOOST_CHECK_LT(GeometryIdentifier(vol1).setLayer(64u), vol2);
78  BOOST_CHECK_LT(GeometryIdentifier(vol1).setApproach(64u), vol2);
79  BOOST_CHECK_LT(GeometryIdentifier(vol1).setSensitive(64u), vol2);
80  BOOST_CHECK_LT(GeometryIdentifier(vol1).setSensitive(64u), vol2);
81  BOOST_CHECK_LT(vol2, GeometryIdentifier(vol1).setVolume(3u));
82  // other components are hierarchical
83  BOOST_CHECK_LT(GeometryIdentifier(vol1).setVolume(1u).setBoundary(2u),
84  GeometryIdentifier(vol1).setVolume(2u).setBoundary(1u));
85  BOOST_CHECK_LT(GeometryIdentifier(vol1).setBoundary(1u).setLayer(2u),
86  GeometryIdentifier(vol1).setBoundary(2u).setLayer(1u));
87  BOOST_CHECK_LT(GeometryIdentifier(vol1).setLayer(1u).setApproach(2u),
88  GeometryIdentifier(vol1).setLayer(2u).setApproach(1u));
89  BOOST_CHECK_LT(GeometryIdentifier(vol1).setApproach(1u).setSensitive(2u),
90  GeometryIdentifier(vol1).setApproach(2u).setSensitive(1u));
91  BOOST_CHECK_LT(GeometryIdentifier(vol1).setSensitive(1u).setExtra(2u),
92  GeometryIdentifier(vol1).setSensitive(2u).setExtra(1u));
93 }
94 
95 } // namespace Test
96 } // namespace Acts