Skip to content

Commit

Permalink
Add space point reader skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Junggeburth committed Feb 24, 2025
1 parent 56378e1 commit 9ed5ba9
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 50 deletions.
100 changes: 50 additions & 50 deletions Examples/Framework/include/ActsExamples/EventData/MuonSpacePoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<MuonSpacePoint>>;
}
1 change: 1 addition & 0 deletions Examples/Io/Csv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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-<stem>.csv
/// event000000002-<stem>.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<std::size_t, std::size_t> 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<std::size_t, std::size_t> m_eventsRange{};
std::unique_ptr<const Acts::Logger> m_logger{};

WriteDataHandle<Acts::SpacePointContainer> m_outputSpacePoints{this, "OutputMuonSpacePoints"};

const Acts::Logger& logger() const { return *m_logger; }
};

} // namespace ActsExamples

77 changes: 77 additions & 0 deletions Examples/Io/Csv/src/CsvMuonSpacePointReader.cpp
Original file line number Diff line number Diff line change
@@ -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 <array>
#include <stdexcept>

#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<std::size_t, std::size_t>
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<MuonSpacePointData> 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;
}

}

0 comments on commit 9ed5ba9

Please sign in to comment.