Back to home page

EIC code displayed by LXR

 
 

    


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

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 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/Geometry/ConeVolumeBounds.hpp"
0014 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0015 #include "Acts/Geometry/CutoutCylinderVolumeBounds.hpp"
0016 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0017 #include "Acts/Geometry/GenericCuboidVolumeBounds.hpp"
0018 #include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
0019 #include "Acts/Plugins/Json/VolumeBoundsJsonConverter.hpp"
0020 
0021 #include <algorithm>
0022 #include <array>
0023 #include <cmath>
0024 #include <fstream>
0025 #include <memory>
0026 #include <numbers>
0027 #include <string>
0028 #include <vector>
0029 
0030 #include <nlohmann/json.hpp>
0031 
0032 using namespace Acts;
0033 
0034 BOOST_AUTO_TEST_SUITE(VolumeBoundsJsonConversion)
0035 
0036 BOOST_AUTO_TEST_CASE(Cuboid) {
0037   std::ofstream out("CuboidVolumeBounds.json");
0038 
0039   auto cuboidRef = std::make_shared<const CuboidVolumeBounds>(2., 4., 6.);
0040   nlohmann::json cuboidOut = VolumeBoundsJsonConverter::toJson(*cuboidRef);
0041   out << cuboidOut.dump(2);
0042   out.close();
0043 
0044   // Read in json file
0045   auto in = std::ifstream("CuboidVolumeBounds.json",
0046                           std::ifstream::in | std::ifstream::binary);
0047   BOOST_CHECK(in.good());
0048   nlohmann::json cuboidIn;
0049   in >> cuboidIn;
0050   in.close();
0051 
0052   auto cuboidTest =
0053       VolumeBoundsJsonConverter::fromJson<CuboidVolumeBounds>(cuboidIn);
0054   BOOST_CHECK(cuboidRef->values() == cuboidTest->values());
0055 }
0056 
0057 BOOST_AUTO_TEST_CASE(Cylinder) {
0058   std::ofstream out("CylinderVolumeBounds.json");
0059 
0060   auto cylinderRef = std::make_shared<const CylinderVolumeBounds>(
0061       10., 20., 30., std::numbers::pi / 4., 0);
0062   nlohmann::json cylinderOut = VolumeBoundsJsonConverter::toJson(*cylinderRef);
0063   out << cylinderOut.dump(2);
0064   out.close();
0065 
0066   // Read in json file
0067   auto in = std::ifstream("CylinderVolumeBounds.json",
0068                           std::ifstream::in | std::ifstream::binary);
0069   BOOST_CHECK(in.good());
0070   nlohmann::json cylinderIn;
0071   in >> cylinderIn;
0072   in.close();
0073 
0074   auto cylinderTest =
0075       VolumeBoundsJsonConverter::fromJson<CylinderVolumeBounds>(cylinderIn);
0076   BOOST_CHECK(cylinderRef->values() == cylinderTest->values());
0077 }
0078 
0079 BOOST_AUTO_TEST_CASE(Cone) {
0080   std::ofstream out("ConeVolumeBounds.json");
0081 
0082   auto coneRef = std::make_shared<const ConeVolumeBounds>(
0083       0., 0., 0.45, 0.050, 0.050, 0., std::numbers::pi);
0084   nlohmann::json coneOut = VolumeBoundsJsonConverter::toJson(*coneRef);
0085   out << coneOut.dump(2);
0086   out.close();
0087 
0088   // Read in json file
0089   auto in = std::ifstream("ConeVolumeBounds.json",
0090                           std::ifstream::in | std::ifstream::binary);
0091   BOOST_CHECK(in.good());
0092   nlohmann::json coneIn;
0093   in >> coneIn;
0094   in.close();
0095 
0096   auto coneTest = VolumeBoundsJsonConverter::fromJson<ConeVolumeBounds>(coneIn);
0097   BOOST_CHECK(coneRef->values() == coneTest->values());
0098 }
0099 
0100 BOOST_AUTO_TEST_CASE(CutoutCylinder) {
0101   std::ofstream out("CutoutCylinderVolumeBounds.json");
0102 
0103   auto cutoutCylinderRef =
0104       std::make_shared<const CutoutCylinderVolumeBounds>(5, 10, 15, 30, 25);
0105   nlohmann::json cutoutCylinderOut =
0106       VolumeBoundsJsonConverter::toJson(*cutoutCylinderRef);
0107   out << cutoutCylinderOut.dump(2);
0108   out.close();
0109 
0110   // Read in json file
0111   auto in = std::ifstream("CutoutCylinderVolumeBounds.json",
0112                           std::ifstream::in | std::ifstream::binary);
0113   BOOST_CHECK(in.good());
0114   nlohmann::json cutoutCylinderIn;
0115   in >> cutoutCylinderIn;
0116   in.close();
0117 
0118   auto cutoutCylinderTest =
0119       VolumeBoundsJsonConverter::fromJson<CutoutCylinderVolumeBounds>(
0120           cutoutCylinderIn);
0121   BOOST_CHECK(cutoutCylinderRef->values() == cutoutCylinderTest->values());
0122 }
0123 
0124 BOOST_AUTO_TEST_CASE(GenericCuboid) {
0125   std::ofstream out("GenericCuboidVolumeBounds.json");
0126   std::array<Vector3, 8> vertices;
0127   vertices = {{{0, 0, 0},
0128                {2, 0, 0},
0129                {2, 1, 0},
0130                {0, 1, 0},
0131                {0, 0, 1},
0132                {2, 0, 1},
0133                {2, 1, 1},
0134                {0, 1, 1}}};
0135 
0136   auto genericCuboidRef =
0137       std::make_shared<const GenericCuboidVolumeBounds>(vertices);
0138   nlohmann::json genericCuboidOut =
0139       VolumeBoundsJsonConverter::toJson(*genericCuboidRef);
0140   out << genericCuboidOut.dump(2);
0141   out.close();
0142 
0143   // Read in json file
0144   auto in = std::ifstream("GenericCuboidVolumeBounds.json",
0145                           std::ifstream::in | std::ifstream::binary);
0146   BOOST_CHECK(in.good());
0147   nlohmann::json genericCuboidIn;
0148   in >> genericCuboidIn;
0149   in.close();
0150 
0151   auto genericCuboidTest = VolumeBoundsJsonConverter::fromJson(genericCuboidIn);
0152   BOOST_CHECK(genericCuboidRef->values() == genericCuboidTest->values());
0153 }
0154 
0155 BOOST_AUTO_TEST_CASE(Trapezoid) {
0156   std::ofstream out("TrapezoidVolumeBounds.json");
0157 
0158   auto trapezoidRef =
0159       std::make_shared<const TrapezoidVolumeBounds>(2., 4., 6., 8.);
0160   nlohmann::json trapezoidOut =
0161       VolumeBoundsJsonConverter::toJson(*trapezoidRef);
0162   out << trapezoidOut.dump(2);
0163   out.close();
0164 
0165   // Read in json file
0166   auto in = std::ifstream("TrapezoidVolumeBounds.json",
0167                           std::ifstream::in | std::ifstream::binary);
0168   BOOST_CHECK(in.good());
0169   nlohmann::json trapezoidIn;
0170   in >> trapezoidIn;
0171   in.close();
0172 
0173   auto trapezoidTest =
0174       VolumeBoundsJsonConverter::fromJson<TrapezoidVolumeBounds>(trapezoidIn);
0175   BOOST_CHECK(trapezoidRef->values() == trapezoidTest->values());
0176 }
0177 BOOST_AUTO_TEST_SUITE_END()