Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-07 08:11:40

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2021 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/TrackParametrization.hpp"
0013 #include "Acts/Utilities/BinUtility.hpp"
0014 #include "Acts/Utilities/BinningType.hpp"
0015 #include "ActsExamples/Digitization/DigitizationConfig.hpp"
0016 #include "ActsExamples/Digitization/Smearers.hpp"
0017 #include "ActsExamples/Io/Json/JsonDigitizationConfig.hpp"
0018 #include "ActsFatras/Digitization/UncorrelatedHitSmearer.hpp"
0019 
0020 #include <fstream>
0021 #include <string>
0022 #include <vector>
0023 
0024 #include <nlohmann/json.hpp>
0025 
0026 using namespace Acts;
0027 
0028 BOOST_AUTO_TEST_SUITE(JsonDigitizationConfig)
0029 
0030 BOOST_AUTO_TEST_CASE(DigitizationConfigRoundTrip) {
0031   std::ofstream out;
0032 
0033   // As all SurfaceBounds have the same streaming API only a one is
0034   // tested here, all others are tests are identical
0035 
0036   ActsExamples::DigiComponentsConfig dcf;
0037 
0038   ActsExamples::GeometricConfig gdc;
0039 
0040   Acts::BinUtility segmentation;
0041   segmentation += Acts::BinUtility(336, -8.4, 8.4, Acts::open, Acts::binX);
0042   segmentation += Acts::BinUtility(1280, -36, 36, Acts::open, Acts::binY);
0043 
0044   gdc.segmentation = segmentation;
0045   gdc.threshold = 0.01;
0046   gdc.thickness = 0.15;
0047   gdc.indices = {Acts::eBoundLoc0, Acts::eBoundLoc1};
0048   gdc.chargeSmearer = ActsExamples::Digitization::Gauss(1.0);
0049 
0050   ActsExamples::DigiComponentsConfig dcRef;
0051   dcRef.geometricDigiConfig = gdc;
0052 
0053   nlohmann::json dcJsonOut(dcRef);
0054   out.open("DigiComponentsConfig.json");
0055   out << dcJsonOut.dump(2);
0056   out.close();
0057 
0058   auto in = std::ifstream("DigiComponentsConfig.json",
0059                           std::ifstream::in | std::ifstream::binary);
0060   BOOST_CHECK(in.good());
0061   nlohmann::json dcJsonIn;
0062   in >> dcJsonIn;
0063   in.close();
0064 
0065   ActsExamples::DigiComponentsConfig dcTest(dcJsonIn);
0066   BOOST_CHECK(dcTest.geometricDigiConfig.indices ==
0067               dcRef.geometricDigiConfig.indices);
0068   BOOST_CHECK_EQUAL(dcTest.geometricDigiConfig.segmentation.dimensions(),
0069                     dcRef.geometricDigiConfig.segmentation.dimensions());
0070 }
0071 
0072 BOOST_AUTO_TEST_SUITE_END()