Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:22:27

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2021-2026 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 // Project include(s).
0009 #include "traccc/geometry/detector.hpp"
0010 #include "traccc/io/read_cells.hpp"
0011 #include "traccc/io/read_detector.hpp"
0012 #include "traccc/io/read_detector_description.hpp"
0013 #include "traccc/io/read_digitization_config.hpp"
0014 #include "traccc/io/read_measurements.hpp"
0015 #include "traccc/io/read_particles.hpp"
0016 #include "traccc/io/read_spacepoints.hpp"
0017 #include "traccc/io/write.hpp"
0018 
0019 // Test include(s).
0020 #include "tests/data_test.hpp"
0021 
0022 // VecMem include(s).
0023 #include <vecmem/memory/host_memory_resource.hpp>
0024 
0025 // GTest include(s).
0026 #include <gtest/gtest.h>
0027 
0028 // System include(s).
0029 #include <filesystem>
0030 
0031 class io : public traccc::tests::data_test {};
0032 
0033 // This defines the local frame test suite
0034 TEST_F(io, csv_read_single_module) {
0035   vecmem::host_memory_resource resource;
0036 
0037   traccc::edm::silicon_cell_collection::host cells{resource};
0038   traccc::io::read_cells(cells, get_datafile("single_module/cells.csv"),
0039                          traccc::getDummyLogger().clone());
0040 
0041   ASSERT_EQ(cells.size(), 6u);
0042 
0043   EXPECT_EQ(cells.channel0().at(0), 123u);
0044   EXPECT_EQ(cells.channel1().at(0), 32u);
0045   EXPECT_FLOAT_EQ(static_cast<float>(cells.activation().at(0)), 0.002f);
0046   EXPECT_EQ(cells.module_index().at(0), 0u);
0047 
0048   EXPECT_EQ(cells.channel0().at(5), 174u);
0049   EXPECT_EQ(cells.channel1().at(5), 880u);
0050   EXPECT_FLOAT_EQ(static_cast<float>(cells.activation().at(5)), 0.23f);
0051   EXPECT_EQ(cells.module_index().at(5), 0u);
0052 }
0053 
0054 // This defines the local frame test suite
0055 TEST_F(io, csv_read_two_modules) {
0056   vecmem::host_memory_resource resource;
0057 
0058   traccc::edm::silicon_cell_collection::host cells{resource};
0059   traccc::io::read_cells(cells, get_datafile("two_modules/cells.csv"),
0060                          traccc::getDummyLogger().clone());
0061 
0062   ASSERT_EQ(cells.size(), 14u);
0063 
0064   // Check cells in first module
0065   EXPECT_EQ(cells.channel0().at(0), 123u);
0066   EXPECT_EQ(cells.channel1().at(0), 32u);
0067   EXPECT_EQ(cells.channel0().at(5), 174u);
0068   EXPECT_EQ(cells.channel1().at(5), 880u);
0069 
0070   // Check cells in second module
0071   EXPECT_EQ(cells.channel0().at(6), 0u);
0072   EXPECT_EQ(cells.channel1().at(6), 4u);
0073   EXPECT_EQ(cells.channel0().at(13), 5u);
0074   EXPECT_EQ(cells.channel1().at(13), 98u);
0075 }
0076 
0077 // This reads in the tml pixel barrel first event
0078 TEST_F(io, csv_read_tml_pixelbarrel) {
0079   vecmem::host_memory_resource resource;
0080 
0081   traccc::edm::silicon_cell_collection::host cells{resource};
0082   traccc::io::read_cells(
0083       cells, get_datafile("tml_pixel_barrel/event000000000-cells.csv"),
0084       traccc::getDummyLogger().clone(), nullptr, traccc::data_format::csv,
0085       false);
0086 
0087   EXPECT_EQ(cells.size(), 179961u);
0088 }
0089 
0090 /// Tests with ODD "single" muon events.
0091 TEST_F(io, csv_read_odd_single_muon) {
0092   // Memory resource used by the test.
0093   vecmem::host_memory_resource mr;
0094 
0095   traccc::host_detector detector;
0096   traccc::io::read_detector(detector, mr,
0097                             "geometries/odd/odd-detray_geometry_detray.json");
0098 
0099   // Read the truth particles for the first event.
0100   traccc::particle_container_types::host particles{&mr};
0101   traccc::edm::measurement_collection::host measurements{mr};
0102   traccc::io::read_particles(particles, measurements, 0u,
0103                              "odd/geant4_1muon_1GeV/", &detector,
0104                              traccc::data_format::csv);
0105 
0106   // Look at the read container.
0107   ASSERT_EQ(particles.size(), 265u);
0108   std::size_t n_muons = 0u;
0109   for (std::size_t i = 0; i < particles.size(); ++i) {
0110     // The muon(s) must have measurements associated to it/them.
0111     if (std::abs(particles.at(i).header.particle_type) == 13) {
0112       ++n_muons;
0113       EXPECT_GT(particles.at(i).items.size(), 0u);
0114     }
0115   }
0116   EXPECT_EQ(n_muons, 4u);
0117 }
0118 
0119 TEST_F(io, csv_write_odd_single_muon_cells) {
0120   // Memory resource used by the test.
0121   vecmem::host_memory_resource mr;
0122 
0123   // Read the ODD detector description.
0124   traccc::detector_design_description::host det_desc{mr};
0125   traccc::detector_conditions_description::host det_cond{mr};
0126   traccc::io::read_detector_description(
0127       det_desc, det_cond, "geometries/odd/odd-detray_geometry_detray.json",
0128       "geometries/odd/odd-digi-geometric-config.json",
0129       "geometries/odd/odd-digi-geometric-config.json");
0130 
0131   // Lambda comparing two cell collections.
0132   auto compare_cells =
0133       [](const traccc::edm::silicon_cell_collection::host& a,
0134          const traccc::edm::silicon_cell_collection::host& b) -> void {
0135     ASSERT_EQ(a.size(), b.size());
0136     for (traccc::edm::silicon_cell_collection::host::size_type i = 0;
0137          i < a.size(); ++i) {
0138       EXPECT_EQ(a.at(i), b.at(i));
0139     }
0140   };
0141 
0142   // Cell collections to use in the test.
0143   traccc::edm::silicon_cell_collection::host orig{mr}, copy{mr};
0144 
0145   // Lambda performing the test with either using "Acts geometry IDs" or
0146   // "Detray ones".
0147   auto perform_test = [&](bool use_acts_geometry_id) {
0148     // Test the I/O for 10 events.
0149     for (std::size_t event = 0; event < 10; ++event) {
0150       // Read the cells for the current event.
0151       traccc::io::read_cells(orig, event, "odd/geant4_1muon_1GeV/",
0152                              traccc::getDummyLogger().clone(), &det_cond);
0153       // Write the cells into a temporary file.
0154       traccc::io::write(event, std::filesystem::temp_directory_path().native(),
0155                         traccc::data_format::csv, vecmem::get_data(orig),
0156                         vecmem::get_data(det_desc), vecmem::get_data(det_cond),
0157                         use_acts_geometry_id);
0158 
0159       // Read the cells back in.
0160       traccc::io::read_cells(
0161           copy, event, std::filesystem::temp_directory_path().native(),
0162           traccc::getDummyLogger().clone(), &det_cond, traccc::data_format::csv,
0163           false, use_acts_geometry_id);
0164 
0165       // Compare the two cell collections.
0166       compare_cells(orig, copy);
0167     }
0168   };
0169 
0170   // Perform the test with both "Acts geometry IDs" and "Detray ones".
0171   perform_test(true);
0172   perform_test(false);
0173 }