File indexing completed on 2025-01-18 09:13:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Plugins/Json/UtilitiesJsonConverter.hpp"
0013 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0014 #include "Acts/Utilities/BinUtility.hpp"
0015 #include "Acts/Utilities/BinningType.hpp"
0016
0017 #include <cmath>
0018 #include <fstream>
0019 #include <initializer_list>
0020 #include <numbers>
0021 #include <string>
0022 #include <utility>
0023 #include <vector>
0024
0025 #include <nlohmann/json.hpp>
0026
0027 #include "EqualityHelpers.hpp"
0028
0029 using namespace Acts;
0030
0031 BOOST_AUTO_TEST_SUITE(UtilitiesJsonConverter)
0032
0033 BOOST_AUTO_TEST_CASE(BinUtilityRoundTripTests) {
0034 BinUtility reference(2, 0., 4., open, AxisDirection::AxisR);
0035
0036 std::ofstream out;
0037
0038
0039 nlohmann::json joneDimOut;
0040 to_json(joneDimOut, reference);
0041 out.open("BinUtility_1D.json");
0042 out << joneDimOut.dump(2);
0043 out.close();
0044
0045 auto in = std::ifstream("BinUtility_1D.json",
0046 std::ifstream::in | std::ifstream::binary);
0047 BOOST_CHECK(in.good());
0048 nlohmann::json joneDimIn;
0049 in >> joneDimIn;
0050 in.close();
0051
0052 BinUtility test;
0053 from_json(joneDimIn, test);
0054
0055 BOOST_CHECK(isEqual(reference, test, 0.0001));
0056
0057
0058 reference += BinUtility(10., -std::numbers::pi, std::numbers::pi, closed,
0059 AxisDirection::AxisPhi);
0060 nlohmann::json jtwoDimOut;
0061 to_json(jtwoDimOut, reference);
0062 out.open("BinUtility_2D.json");
0063 out << jtwoDimOut.dump(2);
0064 out.close();
0065
0066 in = std::ifstream("BinUtility_2D.json",
0067 std::ifstream::in | std::ifstream::binary);
0068 BOOST_CHECK(in.good());
0069 nlohmann::json jtwoDimIn;
0070 in >> jtwoDimIn;
0071 in.close();
0072
0073 test = BinUtility();
0074 from_json(jtwoDimIn, test);
0075
0076 BOOST_CHECK(isEqual(reference, test, 0.0001));
0077
0078
0079 std::vector<float> boundaries = {-4., -1.5, 0., 10.};
0080 reference += BinUtility(boundaries, open, AxisDirection::AxisZ);
0081 nlohmann::json jthreeDimOut;
0082 to_json(jthreeDimOut, reference);
0083 out.open("BinUtility_3D.json");
0084 out << jthreeDimOut.dump(2);
0085 out.close();
0086
0087 in = std::ifstream("BinUtility_3D.json",
0088 std::ifstream::in | std::ifstream::binary);
0089 BOOST_CHECK(in.good());
0090 nlohmann::json jthreeDimIn;
0091 in >> jthreeDimIn;
0092 in.close();
0093
0094 test = BinUtility();
0095 from_json(jthreeDimIn, test);
0096
0097 BOOST_CHECK(isEqual(reference, test, 0.0001));
0098
0099
0100 Transform3 t;
0101 t = Eigen::AngleAxis(0.12334, Vector3(1., 2., 3).normalized());
0102 t.pretranslate(Vector3(1., 2., 3.));
0103
0104 auto bData = reference.binningData()[0];
0105
0106 reference = BinUtility(bData, t);
0107
0108 nlohmann::json jtransformOut;
0109 to_json(jtransformOut, reference);
0110 out.open("BinUtility_Transform.json");
0111 out << jtransformOut.dump(2);
0112 out.close();
0113
0114 in = std::ifstream("BinUtility_Transform.json",
0115 std::ifstream::in | std::ifstream::binary);
0116 BOOST_CHECK(in.good());
0117 nlohmann::json jtransformIn;
0118 in >> jtransformIn;
0119 in.close();
0120
0121 test = BinUtility();
0122 from_json(jtransformIn, test);
0123
0124 BOOST_CHECK(isEqual(reference, test, 0.0001));
0125 }
0126
0127 BOOST_AUTO_TEST_CASE(Range1DRoundTrip) {
0128 Range1D<double> r(-10., 100.);
0129
0130 nlohmann::json jrange;
0131 jrange["range"] = r;
0132
0133 Range1D<double> rIn = jrange["range"];
0134
0135 CHECK_CLOSE_ABS(rIn.min(), -10., 10e-5);
0136 CHECK_CLOSE_ABS(rIn.max(), 100., 10e-5);
0137 }
0138
0139 BOOST_AUTO_TEST_SUITE_END()