Warning, file /acts/Tests/UnitTests/Examples/Io/Json/JsonDigitizationConfigTests.cpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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/Definitions/TrackParametrization.hpp"
0013 #include "Acts/EventData/detail/GenerateParameters.hpp"
0014 #include "Acts/Surfaces/StrawSurface.hpp"
0015 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0016 #include "Acts/Utilities/BinUtility.hpp"
0017 #include "Acts/Utilities/BinningType.hpp"
0018 #include "ActsExamples/Digitization/DigitizationConfig.hpp"
0019 #include "ActsExamples/Digitization/Smearers.hpp"
0020 #include "ActsExamples/Io/Json/JsonDigitizationConfig.hpp"
0021 #include "ActsFatras/Digitization/UncorrelatedHitSmearer.hpp"
0022
0023 #include <fstream>
0024 #include <string>
0025 #include <vector>
0026
0027 #include <nlohmann/json.hpp>
0028
0029 using namespace Acts;
0030
0031 namespace {
0032 template <typename generator_t>
0033 struct Fixture {
0034 generator_t rng;
0035
0036 Acts::GeometryIdentifier gid;
0037 ActsFatras::Barcode pid;
0038
0039 std::shared_ptr<Acts::Surface> surface;
0040 Acts::GeometryContext geoCtx;
0041
0042 Acts::BoundVector boundParams;
0043 Acts::FreeVector freeParams;
0044
0045 ActsFatras::Hit hit;
0046
0047 Fixture(std::uint64_t rngSeed, std::shared_ptr<Acts::Surface> surf)
0048 : rng(rngSeed),
0049 gid(Acts::GeometryIdentifier().withVolume(1).withLayer(2).withSensitive(
0050 3)),
0051 pid(ActsFatras::Barcode().setVertexPrimary(12).setParticle(23)),
0052 surface(std::move(surf)) {
0053 using namespace Acts::UnitLiterals;
0054 using Acts::VectorHelpers::makeVector4;
0055
0056 surface->assignGeometryId(gid);
0057
0058
0059 auto [par, cov] =
0060 Acts::detail::Test::generateBoundParametersCovariance(rng, {});
0061 boundParams = par;
0062
0063 freeParams =
0064 Acts::transformBoundToFreeParameters(*surface, geoCtx, boundParams);
0065
0066
0067 Acts::Vector4 r4;
0068 r4.segment<3>(Acts::ePos0) = freeParams.segment<3>(Acts::eFreePos0);
0069 r4[Acts::eTime] = freeParams[Acts::eFreeTime];
0070
0071 Acts::Vector4 p4;
0072 p4.segment<3>(Acts::eMom0) =
0073 freeParams.segment<3>(Acts::eFreeDir0).normalized();
0074 p4[Acts::eEnergy] = 1;
0075 p4 *= std::abs(1_e / freeParams[Acts::eFreeQOverP]);
0076
0077 hit = ActsFatras::Hit(gid, pid, r4, p4, p4, 13);
0078 }
0079 };
0080 }
0081
0082 BOOST_AUTO_TEST_SUITE(JsonDigitizationConfig)
0083
0084 BOOST_AUTO_TEST_CASE(GaussianSmearing) {
0085 nlohmann::json djson = nlohmann::json::parse(R"(
0086 {
0087 "acts-geometry-hierarchy-map" : {
0088 "format-version" : 0,
0089 "value-identifier" : "digitization-configuration"
0090 },
0091
0092 "entries"
0093 : [
0094 {
0095 "volume" : 1,
0096 "value" : {
0097 "smearing" : [
0098 {"index" : 0, "mean" : 0.0, "stddev" : 0.05, "type" : "Gauss", "forcePositiveValues" : true}
0099
0100
0101 ]
0102 }
0103 }
0104 ]
0105 })");
0106 double radius = 5.;
0107 double halfZ = 8.;
0108 Fixture<ActsExamples::RandomEngine> f(
0109 123567,
0110 Acts::Surface::makeShared<Acts::StrawSurface>(
0111 Acts::Transform3(Acts::Translation3(0., 0., 0.)), radius, halfZ));
0112
0113
0114 auto digiConfig =
0115 ActsExamples::DigiConfigConverter("digitization-configuration")
0116 .fromJson(djson);
0117 ActsFatras::BoundParametersSmearer<ActsExamples::RandomEngine, 1u> s;
0118
0119 for (auto& el : digiConfig) {
0120 for (auto& smearing : el.smearingDigiConfig) {
0121
0122 BOOST_CHECK(smearing.forcePositiveValues);
0123 std::fill(std::begin(s.indices), std::end(s.indices),
0124 static_cast<Acts::BoundIndices>(smearing.index));
0125 std::fill(std::begin(s.smearFunctions), std::end(s.smearFunctions),
0126 smearing.smearFunction);
0127 std::fill(std::begin(s.forcePositive), std::end(s.forcePositive),
0128 smearing.forcePositiveValues);
0129 }
0130 }
0131
0132 auto ret = s(f.rng, f.hit, *f.surface, f.geoCtx);
0133
0134 BOOST_CHECK(ret.ok());
0135 auto [par, cov] = ret.value();
0136 for (std::size_t i = 0; i < s.indices.size(); i++) {
0137 BOOST_TEST_INFO("Comparing smeared measurement "
0138 << i << " originating from bound parameter "
0139 << s.indices[i]);
0140 double ref = f.boundParams[s.indices[i]];
0141 if (s.forcePositive[i]) {
0142 ref = std::abs(ref);
0143 }
0144 CHECK_CLOSE_REL(par[i], ref, 0.15);
0145 }
0146 }
0147
0148 BOOST_AUTO_TEST_CASE(DigitizationConfigRoundTrip) {
0149 std::ofstream out;
0150
0151
0152
0153
0154 ActsExamples::DigiComponentsConfig dcf;
0155
0156 ActsExamples::GeometricConfig gdc;
0157
0158 Acts::BinUtility segmentation;
0159 segmentation +=
0160 Acts::BinUtility(336, -8.4, 8.4, Acts::open, Acts::AxisDirection::AxisX);
0161 segmentation +=
0162 Acts::BinUtility(1280, -36, 36, Acts::open, Acts::AxisDirection::AxisY);
0163
0164 gdc.segmentation = segmentation;
0165 gdc.threshold = 0.01;
0166 gdc.thickness = 0.15;
0167 gdc.indices = {Acts::eBoundLoc0, Acts::eBoundLoc1};
0168 gdc.chargeSmearer = ActsExamples::Digitization::Gauss(1.0);
0169
0170 ActsExamples::DigiComponentsConfig dcRef;
0171 dcRef.geometricDigiConfig = gdc;
0172
0173 nlohmann::json dcJsonOut(dcRef);
0174 out.open("DigiComponentsConfig.json");
0175 out << dcJsonOut.dump(2);
0176 out.close();
0177
0178 auto in = std::ifstream("DigiComponentsConfig.json",
0179 std::ifstream::in | std::ifstream::binary);
0180 BOOST_CHECK(in.good());
0181 nlohmann::json dcJsonIn;
0182 in >> dcJsonIn;
0183 in.close();
0184
0185 ActsExamples::DigiComponentsConfig dcTest(dcJsonIn);
0186 BOOST_CHECK(dcTest.geometricDigiConfig.indices ==
0187 dcRef.geometricDigiConfig.indices);
0188 BOOST_CHECK_EQUAL(dcTest.geometricDigiConfig.segmentation.dimensions(),
0189 dcRef.geometricDigiConfig.segmentation.dimensions());
0190 }
0191
0192 BOOST_AUTO_TEST_SUITE_END()