Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-10 09:29:31

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/Material/Material.hpp"
0014 #include "Acts/Material/MaterialInteraction.hpp"
0015 #include "Acts/Material/MaterialSlab.hpp"
0016 #include "ActsPlugins/Root/RootMaterialTrackIo.hpp"
0017 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0018 
0019 #include <stdexcept>
0020 
0021 #include "TTree.h"
0022 
0023 using namespace Acts;
0024 using namespace Acts::UnitLiterals;
0025 using namespace ActsPlugins;
0026 
0027 namespace {
0028 
0029 /// A track with two steps through silicon along the x axis
0030 RecordedMaterialTrack makeTrack() {
0031   RecordedMaterialTrack track;
0032   track.first = {Vector3(0., 0., 0.), Vector3(1., 0., 0.)};
0033   Material silicon = Material::fromMassDensity(93.7_mm, 465.2_mm, 28.0855, 14.,
0034                                                2.329_g / 1_cm3);
0035   for (double x : {10_mm, 20_mm}) {
0036     MaterialInteraction interaction;
0037     interaction.position = Vector3(x, 0., 0.);
0038     interaction.direction = Vector3(1., 0., 0.);
0039     interaction.materialSlab = MaterialSlab(silicon, 1_mm);
0040     interaction.pathCorrection = 1_mm;
0041     track.second.materialInteractions.push_back(interaction);
0042   }
0043   return track;
0044 }
0045 
0046 }  // namespace
0047 
0048 namespace ActsTests {
0049 
0050 BOOST_AUTO_TEST_SUITE(RootSuite)
0051 
0052 BOOST_AUTO_TEST_CASE(RootMaterialTrackIoWriteWithoutContext) {
0053   RootMaterialTrackIo::Config cfg;
0054   cfg.prePostStepInfo = true;
0055   cfg.recalculateTotals = true;
0056 
0057   TTree tree("material_tracks", "material_tracks");
0058   tree.SetDirectory(nullptr);
0059   RootMaterialTrackIo writer(cfg);
0060   writer.connectForWrite(tree);
0061 
0062   const RecordedMaterialTrack track = makeTrack();
0063   writer.write(42, track);
0064   tree.Fill();
0065   BOOST_CHECK_EQUAL(tree.GetEntries(), 1);
0066 
0067   RootMaterialTrackIo reader(cfg);
0068   reader.connectForRead(tree);
0069   tree.GetEntry(0);
0070   BOOST_CHECK_EQUAL(reader.eventId(), 42u);
0071 
0072   RecordedMaterialTrack readBack = reader.read();
0073   CHECK_CLOSE_ABS(readBack.first.second, track.first.second, 1e-6);
0074   BOOST_REQUIRE_EQUAL(readBack.second.materialInteractions.size(), 2u);
0075   for (std::size_t i = 0; i < 2; ++i) {
0076     const auto& written = track.second.materialInteractions[i];
0077     const auto& read = readBack.second.materialInteractions[i];
0078     CHECK_CLOSE_ABS(read.position, written.position, 1e-4);
0079     CHECK_CLOSE_REL(read.materialSlab.thickness(),
0080                     written.materialSlab.thickness(), 1e-6);
0081     CHECK_CLOSE_REL(read.materialSlab.material().X0(),
0082                     written.materialSlab.material().X0(), 1e-6);
0083   }
0084   // The totals are recalculated from the steps
0085   CHECK_CLOSE_REL(readBack.second.materialInX0, 2_mm / 93.7_mm, 1e-5);
0086 }
0087 
0088 BOOST_AUTO_TEST_CASE(RootMaterialTrackIoWriteWithoutContextSurfaceInfo) {
0089   RootMaterialTrackIo::Config cfg;
0090   cfg.surfaceInfo = true;
0091 
0092   TTree tree("material_tracks", "material_tracks");
0093   tree.SetDirectory(nullptr);
0094   RootMaterialTrackIo writer(cfg);
0095   writer.connectForWrite(tree);
0096 
0097   // Surface information needs a geometry context
0098   BOOST_CHECK_THROW(writer.write(0, makeTrack()), std::invalid_argument);
0099 }
0100 
0101 BOOST_AUTO_TEST_SUITE_END()
0102 
0103 }  // namespace ActsTests