Back to home page

EIC code displayed by LXR

 
 

    


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