Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:11

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include <boost/test/unit_test.hpp>
0012 
0013 #include "Acts/Geometry/Extent.hpp"
0014 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0015 #include "Acts/Utilities/BinUtility.hpp"
0016 #include "Acts/Utilities/BinningData.hpp"
0017 
0018 #include <iostream>
0019 
0020 namespace Acts {
0021 
0022 /// Check whether the BinningData objects are equal
0023 ///
0024 /// @param ba The first BinningData object
0025 /// @param bb The second BinningData object
0026 /// @param tolerance a tolerance parameter
0027 ///
0028 /// @return a boolean
0029 inline static bool isEqual(const BinningData& ba, const BinningData& bb,
0030                            float tolerance) {
0031   bool equalBool = (ba.type == bb.type) && (ba.option == bb.option) &&
0032                    (ba.binvalue == bb.binvalue) && (ba.zdim == bb.zdim) &&
0033                    (ba.subBinningAdditive == bb.subBinningAdditive);
0034 
0035   BOOST_CHECK(equalBool);
0036   bool equalRange = (std::abs(ba.min - bb.min) < tolerance) &&
0037                     (std::abs(ba.max - bb.max) < tolerance) &&
0038                     (std::abs(ba.step - bb.step) < tolerance);
0039 
0040   BOOST_CHECK(equalRange);
0041   bool euqalStructure =
0042       (ba.subBinningData != nullptr)
0043           ? isEqual(*ba.subBinningData, *bb.subBinningData, tolerance)
0044           : (bb.subBinningData == nullptr);
0045 
0046   BOOST_CHECK(euqalStructure);
0047 
0048   bool equalBoundaries = (ba.boundaries().size() == bb.boundaries().size());
0049   if (equalBoundaries) {
0050     for (std::size_t ib = 0; ib < ba.boundaries().size(); ++ib) {
0051       equalBoundaries =
0052           (std::abs(ba.boundaries()[ib] - bb.boundaries()[ib]) < tolerance);
0053       if (!equalBoundaries) {
0054         break;
0055       }
0056     }
0057   }
0058   BOOST_CHECK(equalBoundaries);
0059 
0060   return equalBool && equalRange && euqalStructure;
0061 }
0062 
0063 /// Check whether the BinUtility objects are equal
0064 ///
0065 /// @param ba The first BinUtility object
0066 /// @param bb the second BinUtility object
0067 /// @param tolerance a tolerance parameter
0068 ///
0069 /// @return a bollean if equal
0070 inline static bool isEqual(const BinUtility& ba, const BinUtility& bb,
0071                            float tolerance) {
0072   bool equal = (ba.binningData().size() == bb.binningData().size());
0073   BOOST_CHECK(equal);
0074   if (equal) {
0075     for (std::size_t ib = 0; ib < ba.binningData().size(); ++ib) {
0076       equal = isEqual(ba.binningData()[ib], bb.binningData()[ib], tolerance);
0077       BOOST_CHECK(equal);
0078     }
0079   }
0080   return equal;
0081 }
0082 
0083 /// check whether Extnet objects are equal - with tolerance
0084 ///
0085 /// @param ea the first extent object
0086 /// @param eb the second extent object
0087 /// @param tolerance the tolerance parameter
0088 ///
0089 /// @return bool for euqal
0090 inline static bool isEqual(const Acts::Extent& ea, const Acts::Extent& eb,
0091                            double tolerance = 0.) {
0092   bool equalConstrains = true;
0093   bool equalRange = true;
0094   for (auto& bVal : allAxisDirections()) {
0095     equalConstrains =
0096         equalConstrains && (ea.constrains(bVal) == eb.constrains(bVal));
0097     BOOST_CHECK(equalConstrains);
0098     if (ea.constrains(bVal) && eb.constrains(bVal)) {
0099       equalRange =
0100           equalRange && std::abs(ea.min(bVal) - eb.min(bVal)) < tolerance;
0101       equalRange =
0102           equalRange && std::abs(ea.max(bVal) - eb.max(bVal)) < tolerance;
0103       BOOST_CHECK(equalRange);
0104     }
0105   }
0106   BOOST_CHECK(equalConstrains);
0107   BOOST_CHECK(equalRange);
0108   return equalRange && equalConstrains;
0109 }
0110 
0111 }  // namespace Acts