Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-15 08:04: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 "ActsExamples/Io/Csv/CsvSimHitReader.hpp"
0010 
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Geometry/GeometryIdentifier.hpp"
0013 #include "ActsExamples/EventData/SimHit.hpp"
0014 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0015 #include "ActsExamples/Io/Csv/CsvInputOutput.hpp"
0016 #include "ActsExamples/Utilities/Paths.hpp"
0017 #include "ActsFatras/EventData/Barcode.hpp"
0018 #include "ActsFatras/EventData/Hit.hpp"
0019 
0020 #include <array>
0021 #include <stdexcept>
0022 
0023 #include "CsvOutputData.hpp"
0024 
0025 ActsExamples::CsvSimHitReader::CsvSimHitReader(
0026     const ActsExamples::CsvSimHitReader::Config& config,
0027     Acts::Logging::Level level)
0028     : m_cfg(config),
0029       // TODO check that all files (hits,cells,truth) exists
0030       m_eventsRange(
0031           determineEventFilesRange(m_cfg.inputDir, m_cfg.inputStem + ".csv")),
0032       m_logger(Acts::getDefaultLogger("CsvSimHitReader", level)) {
0033   if (m_cfg.inputStem.empty()) {
0034     throw std::invalid_argument("Missing input filename stem");
0035   }
0036   if (m_cfg.outputSimHits.empty()) {
0037     throw std::invalid_argument("Missing simulated hits output collection");
0038   }
0039 
0040   m_outputSimHits.initialize(m_cfg.outputSimHits);
0041 }
0042 
0043 std::string ActsExamples::CsvSimHitReader::CsvSimHitReader::name() const {
0044   return "CsvSimHitReader";
0045 }
0046 
0047 std::pair<std::size_t, std::size_t>
0048 ActsExamples::CsvSimHitReader::availableEvents() const {
0049   return m_eventsRange;
0050 }
0051 
0052 ActsExamples::ProcessCode ActsExamples::CsvSimHitReader::read(
0053     const ActsExamples::AlgorithmContext& ctx) {
0054   auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv",
0055                                ctx.eventNumber);
0056 
0057   ActsExamples::NamedTupleCsvReader<SimHitData> reader(path);
0058 
0059   SimHitContainer::sequence_type unordered;
0060   SimHitData data;
0061 
0062   ACTS_DEBUG("start to read hits ");
0063   while (reader.read(data)) {
0064     ACTS_DEBUG("found a sim hit");
0065     const auto geometryId = Acts::GeometryIdentifier(data.geometry_id);
0066     // TODO validate geo id consistency
0067 
0068     const auto particleId = ActsFatras::Barcode()
0069                                 .withVertexPrimary(data.particle_id_pv)
0070                                 .withVertexSecondary(data.particle_id_sv)
0071                                 .withParticle(data.particle_id_part)
0072                                 .withGeneration(data.particle_id_gen)
0073                                 .withSubParticle(data.particle_id_subpart);
0074 
0075     Acts::Vector4 pos4{
0076         data.tx * Acts::UnitConstants::mm,
0077         data.ty * Acts::UnitConstants::mm,
0078         data.tz * Acts::UnitConstants::mm,
0079         data.tt * Acts::UnitConstants::mm,
0080     };
0081     Acts::Vector4 mom4{
0082         data.tpx * Acts::UnitConstants::GeV,
0083         data.tpy * Acts::UnitConstants::GeV,
0084         data.tpz * Acts::UnitConstants::GeV,
0085         data.te * Acts::UnitConstants::GeV,
0086     };
0087     Acts::Vector4 delta4{
0088         data.deltapx * Acts::UnitConstants::GeV,
0089         data.deltapy * Acts::UnitConstants::GeV,
0090         data.deltapz * Acts::UnitConstants::GeV,
0091         data.deltae * Acts::UnitConstants::GeV,
0092     };
0093 
0094     ActsFatras::Hit hit(geometryId, particleId, pos4, mom4, mom4 + delta4,
0095                         data.index);
0096     unordered.push_back(std::move(hit));
0097   }
0098 
0099   // write the ordered data to the EventStore (according to geometry_id).
0100   SimHitContainer simHits;
0101   simHits.insert(unordered.begin(), unordered.end());
0102   m_outputSimHits(ctx, std::move(simHits));
0103 
0104   return ActsExamples::ProcessCode::SUCCESS;
0105 }