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