File indexing completed on 2025-12-16 09:25:36
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/Geometry/GeometryIdentifier.hpp"
0014 #include "ActsPlugins/Root/RootMeasurementIo.hpp"
0015 #include "ActsTests/CommonHelpers/TemporaryDirectory.hpp"
0016
0017 #include <filesystem>
0018
0019 #include "TFile.h"
0020 #include "TTree.h"
0021
0022 using namespace Acts;
0023 using namespace ActsPlugins;
0024
0025 namespace ActsTests {
0026
0027 BOOST_AUTO_TEST_SUITE(RootSuite)
0028
0029 BOOST_AUTO_TEST_CASE(RootMeasurementIoTestsWrite) {
0030
0031 TemporaryDirectory tmpDir{};
0032
0033
0034 std::vector<BoundIndices> recoIndices = {eBoundLoc0, eBoundLoc1};
0035 std::vector<BoundIndices> clusterIndices = {eBoundLoc0, eBoundLoc1};
0036 RootMeasurementIo::Config cfg{recoIndices, clusterIndices};
0037 RootMeasurementIo accessor(cfg);
0038
0039 const std::filesystem::path filePath =
0040 tmpDir.path() / "RootMeasurementIoTests.root";
0041
0042 auto rFile = TFile::Open(filePath.c_str(), "RECREATE");
0043 rFile->cd();
0044 BOOST_REQUIRE(rFile != nullptr);
0045
0046 TTree measurementTree("measurements", "measurements");
0047 accessor.connectForWrite(measurementTree);
0048
0049
0050 auto geoId = GeometryIdentifier()
0051 .withVolume(1)
0052 .withLayer(2)
0053 .withSensitive(4)
0054 .withExtra(5);
0055
0056 accessor.fillIdentification(1, geoId);
0057 accessor.fillTruthParameters(Vector2(0.1, 0.2), Vector4(1.1, 2.2, 3.3, 4.4),
0058 Vector3(0.1, 0.2, 0.3),
0059 std::make_pair(0.01, 0.02));
0060 accessor.fillBoundMeasurement({0.11, 0.22}, {0.01, 0.02}, {0, 1});
0061 accessor.fillGlobalPosition(Vector3(1.0, 2.0, 3.0));
0062 accessor.fillCluster(std::vector<std::tuple<int, int, float>>{
0063 {1, 2, 0.5}, {2, 3, 1.5}, {3, 4, 2.5}});
0064
0065 measurementTree.Fill();
0066 measurementTree.Write();
0067 accessor.clear();
0068 rFile->Close();
0069
0070
0071 rFile = TFile::Open(filePath.c_str(), "READ");
0072 BOOST_REQUIRE(rFile != nullptr);
0073 auto readTree = dynamic_cast<TTree*>(rFile->Get("measurements"));
0074 BOOST_REQUIRE(readTree != nullptr);
0075
0076 BOOST_CHECK_EQUAL(readTree->GetEntries(), 1);
0077 }
0078
0079 BOOST_AUTO_TEST_CASE(RootMeasurementIoExceptions) {
0080
0081 std::vector<BoundIndices> recoIndices = {eBoundLoc0};
0082 std::vector<BoundIndices> clusterIndices = {eBoundLoc0};
0083 RootMeasurementIo::Config cfg{recoIndices, clusterIndices};
0084 RootMeasurementIo accessor(cfg);
0085
0086 BOOST_CHECK_THROW(accessor.fillBoundMeasurement({0.1, 0.2}, {0.01}, {0, 1}),
0087 std::invalid_argument);
0088 }
0089
0090 BOOST_AUTO_TEST_SUITE_END()
0091
0092 }