From 9ed5ba99c3647e33e3c81926e7086726dcac3dbf Mon Sep 17 00:00:00 2001 From: Johannes Junggeburth Date: Mon, 24 Feb 2025 23:11:14 +0100 Subject: [PATCH] Add space point reader skeleton --- .../ActsExamples/EventData/MuonSpacePoint.hpp | 100 +++++++++--------- Examples/Io/Csv/CMakeLists.txt | 1 + .../Io/Csv/CsvMuonSpacePointReader.hpp | 68 ++++++++++++ .../Io/Csv/src/CsvMuonSpacePointReader.cpp | 77 ++++++++++++++ 4 files changed, 196 insertions(+), 50 deletions(-) create mode 100644 Examples/Io/Csv/include/ActsExamples/Io/Csv/CsvMuonSpacePointReader.hpp create mode 100644 Examples/Io/Csv/src/CsvMuonSpacePointReader.cpp diff --git a/Examples/Framework/include/ActsExamples/EventData/MuonSpacePoint.hpp b/Examples/Framework/include/ActsExamples/EventData/MuonSpacePoint.hpp index faffdd35160..3deadf7d239 100644 --- a/Examples/Framework/include/ActsExamples/EventData/MuonSpacePoint.hpp +++ b/Examples/Framework/include/ActsExamples/EventData/MuonSpacePoint.hpp @@ -4,55 +4,55 @@ #include "Acts/EventData/StationSpacePoint.hpp" namespace Acts{ - class MuonSpacePoint { - public: - /** @brief Return the local meaurement position */ - const Acts::Vector3& localPosition() const{ - return m_pos; - } - /** @brief Return the local sensor direction */ - const Acts::Vector3& sensorDirection() const{ - return m_dir; - } - /** @brief Return the normal vector to the plane */ - const Acts::Vector3& stripPlaneNormal() const { - return m_pos; - } - /** @brief Return the drift radius */ - double driftRadius() const{ - return m_radius; - } - /** @brief Return the measurement time */ - double time() const { - return m_time; - } - /** @brief Define the space point coordinates. - * @param pos: Space point position - * @param sensorDir: Direction of the sensor */ - void defineCoordinates(Acts::Vector3&& pos, - Acts::Vector3&& sensorDir){ - m_pos = std::move(pos); - m_dir = std::move(sensorDir); - } - /** @brief Define the space point normal*/ - void defineNormal(Acts::Vector3&& norm) { - m_norm = std::move(norm); - } - /** @brief Define the space point radius */ - void setRadius(const double r) { - m_radius = r; - } - /** @brief Define the time of the space point measurement */ - void setTime(const double t){ - m_time = t; - } - private: - Acts::Vector3 m_pos{Acts::Vector3::Zero()}; - Acts::Vector3 m_dir{Acts::Vector3::Zero()}; - Acts::Vector3 m_norm{Acts::Vector3::Zero()}; - double m_radius{0.}; - double m_time{0.}; - - }; + class MuonSpacePoint { + public: + /** @brief Return the local meaurement position */ + const Acts::Vector3& localPosition() const{ + return m_pos; + } + /** @brief Return the local sensor direction */ + const Acts::Vector3& sensorDirection() const{ + return m_dir; + } + /** @brief Return the normal vector to the plane */ + const Acts::Vector3& stripPlaneNormal() const { + return m_pos; + } + /** @brief Return the drift radius */ + double driftRadius() const{ + return m_radius; + } + /** @brief Return the measurement time */ + double time() const { + return m_time; + } + /** @brief Define the space point coordinates. + * @param pos: Space point position + * @param sensorDir: Direction of the sensor */ + void defineCoordinates(Acts::Vector3&& pos, + Acts::Vector3&& sensorDir){ + m_pos = std::move(pos); + m_dir = std::move(sensorDir); + } + /** @brief Define the space point normal*/ + void defineNormal(Acts::Vector3&& norm) { + m_norm = std::move(norm); + } + /** @brief Define the space point radius */ + void setRadius(const double r) { + m_radius = r; + } + /** @brief Define the time of the space point measurement */ + void setTime(const double t){ + m_time = t; + } + private: + Acts::Vector3 m_pos{Acts::Vector3::Zero()}; + Acts::Vector3 m_dir{Acts::Vector3::Zero()}; + Acts::Vector3 m_norm{Acts::Vector3::Zero()}; + double m_radius{0.}; + double m_time{0.}; + }; + using SpacePointContainer = std::vector>; } \ No newline at end of file diff --git a/Examples/Io/Csv/CMakeLists.txt b/Examples/Io/Csv/CMakeLists.txt index f57275ee915..710eafc8c6f 100644 --- a/Examples/Io/Csv/CMakeLists.txt +++ b/Examples/Io/Csv/CMakeLists.txt @@ -16,6 +16,7 @@ add_library( src/CsvSeedWriter.cpp src/CsvTrackWriter.cpp src/CsvDriftCircleReader.cpp + src/CsvMuonSpacePointReader.cpp src/CsvMuonSimHitReader.cpp src/CsvProtoTrackWriter.cpp src/CsvSpacePointWriter.cpp diff --git a/Examples/Io/Csv/include/ActsExamples/Io/Csv/CsvMuonSpacePointReader.hpp b/Examples/Io/Csv/include/ActsExamples/Io/Csv/CsvMuonSpacePointReader.hpp new file mode 100644 index 00000000000..075dc9aaaa6 --- /dev/null +++ b/Examples/Io/Csv/include/ActsExamples/Io/Csv/CsvMuonSpacePointReader.hpp @@ -0,0 +1,68 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma once +#include "ActsExamples/Framework/DataHandle.hpp" +#include "ActsExamples/Framework/IReader.hpp" +#include "ActsExamples/Framework/ProcessCode.hpp" + +#include "ActsExamples/EventData/MuonSpacePoint.hpp" + +namespace ActsExamples { + struct AlgorithmContext; + +// Read in a simhit collection in comma-separated-value format. +/// +/// This reads one files per event in the configured input directory. By default +/// it reads files in the current working directory. Files are assumed to be +/// named using the following schema +/// +/// event000000001-.csv +/// event000000002-.csv +/// +/// and each line in the file corresponds to one simhit. +class CsvMuonSpacePointReader final : public IReader { + public: + struct Config { + /// Where to read input files from. + std::string inputDir{}; + /// Input filename stem. + std::string inputStem{}; + /// Output simulated (truth) hits collection. + std::string outputSpacePoints{}; + }; + + /// Construct the simhit reader. + /// + /// @param config is the configuration object + /// @param level is the logging level + CsvMuonSpacePointReader(const Config& config, Acts::Logging::Level level); + + std::string name() const override; + + /// Return the available events range. + std::pair availableEvents() const override; + + /// Read out data from the input stream. + ProcessCode read(const ActsExamples::AlgorithmContext& ctx) override; + + /// Readonly access to the config + const Config& config() const { return m_cfg; } + + private: + Config m_cfg{}; + std::pair m_eventsRange{}; + std::unique_ptr m_logger{}; + + WriteDataHandle m_outputSpacePoints{this, "OutputMuonSpacePoints"}; + + const Acts::Logger& logger() const { return *m_logger; } + }; + +} // namespace ActsExamples + diff --git a/Examples/Io/Csv/src/CsvMuonSpacePointReader.cpp b/Examples/Io/Csv/src/CsvMuonSpacePointReader.cpp new file mode 100644 index 00000000000..5b9ebc2ad00 --- /dev/null +++ b/Examples/Io/Csv/src/CsvMuonSpacePointReader.cpp @@ -0,0 +1,77 @@ + +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +#include "ActsExamples/Io/Csv/CsvMuonSpacePointReader.hpp" + + +#include "Acts/Definitions/Units.hpp" +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "ActsExamples/EventData/MuonSpacePoint.hpp" +#include "ActsExamples/Framework/AlgorithmContext.hpp" +#include "ActsExamples/Io/Csv/CsvInputOutput.hpp" +#include "ActsExamples/Utilities/Paths.hpp" +#include "ActsFatras/EventData/Barcode.hpp" +#include "ActsFatras/EventData/Hit.hpp" + +#include +#include + +#include "CsvOutputData.hpp" + + + +namespace ActsExamples{ +CsvMuonSpacePointReader::CsvMuonSpacePointReader(const Config& config, + Acts::Logging::Level level): + m_cfg{config}, + // TODO check that all files (hits,cells,truth) exists + m_eventsRange{determineEventFilesRange(m_cfg.inputDir, m_cfg.inputStem + ".csv")}, + m_logger{Acts::getDefaultLogger("CsvMuonSpacePointReader", level)} { + + if (m_cfg.inputStem.empty()) { + throw std::invalid_argument("Missing input filename stem"); + } + if (m_cfg.outputSpacePoints.empty()) { + throw std::invalid_argument("Missing space point output collection"); + } + + m_outputSpacePoints.initialize(m_cfg.outputSpacePoints); +} + +std::string CsvMuonSpacePointReader::CsvMuonSpacePointReader::name() const { + return "CsvMuonSpacePointReader"; +} + +std::pair +CsvMuonSpacePointReader::availableEvents() const { + return m_eventsRange; +} + +ProcessCode CsvMuonSpacePointReader::read(const AlgorithmContext& ctx) { + auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".csv", + ctx.eventNumber); + + NamedTupleCsvReader reader(path); + + MuonSpacePointData data; + +// SimHitContainer::sequence_type unordered; + Acts::SpacePointContainer spacePoints{}; + + while (reader.read(data)) { + // unordered.push_back(SimHit(compressId(f), data.pdgId, pos, mom, mom, -1)); + } +// simHits.insert(unordered.begin(), unordered.end()); + + // write the ordered data to the EventStore (according to geometry_id). + m_outputSpacePoints(ctx, std::move(spacePoints)); + + return ProcessCode::SUCCESS; +} + +} \ No newline at end of file