Skip to content

feat: switch TrackerHitReconstruction algorithm/factories to algorithms interface #1966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions src/algorithms/tracking/TrackerHitReconstruction.cc
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2022 Whitney Armstrong, Sylvester Joosten, Wouter Deconinck, Dmitry Romanov
// Copyright (C) 2022 - 2025 Whitney Armstrong, Sylvester Joosten, Wouter Deconinck, Dmitry Romanov

#include "TrackerHitReconstruction.h"

#include <Evaluator/DD4hepUnits.h>
#include <Math/GenVector/Cartesian3D.h>
#include <Math/GenVector/DisplacementVector3D.h>
#include <algorithms/logger.h>
#include <edm4eic/CovDiag3f.h>
#include <edm4hep/Vector3f.h>
#include <fmt/core.h>
#include <spdlog/common.h>
#include <cstddef>
#include <iterator>
#include <vector>
Expand All @@ -27,21 +27,13 @@ namespace {
}
} // namespace

void TrackerHitReconstruction::init(const dd4hep::rec::CellIDPositionConverter* converter,
std::shared_ptr<spdlog::logger>& logger) {

m_log = logger;

m_converter = converter;
}

std::unique_ptr<edm4eic::TrackerHitCollection>
TrackerHitReconstruction::process(const edm4eic::RawTrackerHitCollection& raw_hits) {
void TrackerHitReconstruction::process(const Input& input, const Output& output) const {
using dd4hep::mm;

auto rec_hits{std::make_unique<edm4eic::TrackerHitCollection>()};
const auto [raw_hits] = input;
auto [rec_hits] = output;

for (const auto& raw_hit : raw_hits) {
for (const auto& raw_hit : *raw_hits) {

auto id = raw_hit.getCellID();

Expand All @@ -50,12 +42,11 @@ TrackerHitReconstruction::process(const edm4eic::RawTrackerHitCollection& raw_hi
auto dim = m_converter->cellDimensions(id);

// >oO trace
if (m_log->level() == spdlog::level::trace) {
m_log->trace("position x={:.2f} y={:.2f} z={:.2f} [mm]: ", pos.x() / mm, pos.y() / mm,
pos.z() / mm);
m_log->trace("dimension size: {}", dim.size());
if (level() == algorithms::LogLevel::kTrace) {
trace("position x={:.2f} y={:.2f} z={:.2f} [mm]: ", pos.x() / mm, pos.y() / mm, pos.z() / mm);
trace("dimension size: {}", dim.size());
for (std::size_t j = 0; j < std::size(dim); ++j) {
m_log->trace(" - dimension {:<5} size: {:.2}", j, dim[j]);
trace(" - dimension {:<5} size: {:.2}", j, dim[j]);
}
}

Expand All @@ -81,8 +72,6 @@ TrackerHitReconstruction::process(const edm4eic::RawTrackerHitCollection& raw_hi
0.0F); // Error on the energy
rec_hit.setRawHit(raw_hit);
}

return rec_hits;
}

} // namespace eicrecon
45 changes: 23 additions & 22 deletions src/algorithms/tracking/TrackerHitReconstruction.h
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2022 Whitney Armstrong, Sylvester Joosten, Wouter Deconinck, Dmitry Romanov
// Copyright (C) 2022 - 2025 Whitney Armstrong, Sylvester Joosten, Wouter Deconinck, Dmitry Romanov

#pragma once

#include <DDRec/CellIDPositionConverter.h>
#include <algorithms/algorithm.h>
#include <algorithms/geo.h>
#include <edm4eic/RawTrackerHitCollection.h>
#include <edm4eic/TrackerHitCollection.h>
#include <spdlog/logger.h>
#include <memory>
#include <gsl/pointers>
#include <string>
#include <string_view>

#include "TrackerHitReconstructionConfig.h"
#include "algorithms/interfaces/WithPodConfig.h"

namespace eicrecon {

using TrackerHitReconstructionAlgorithm =
algorithms::Algorithm<algorithms::Input<edm4eic::RawTrackerHitCollection>,
algorithms::Output<edm4eic::TrackerHitCollection>>;

/**
* Produces edm4eic::TrackerHit with geometric info from edm4eic::RawTrackerHit
*/
class TrackerHitReconstruction : public WithPodConfig<TrackerHitReconstructionConfig> {
* Produces edm4eic::TrackerHit with geometric info from edm4eic::RawTrackerHit
*/
class TrackerHitReconstruction : public TrackerHitReconstructionAlgorithm,
public WithPodConfig<TrackerHitReconstructionConfig> {

public:
TrackerHitReconstruction(std::string_view name)
: TrackerHitReconstructionAlgorithm{
name, {"inputRawHits"}, {"outputHits"}, "reconstruct raw hits into tracker hits."} {}

/// Once in a lifetime initialization
void init(const dd4hep::rec::CellIDPositionConverter* converter,
std::shared_ptr<spdlog::logger>& logger);
void init() final{};

/// Processes RawTrackerHit and produces a TrackerHit
std::unique_ptr<edm4eic::TrackerHitCollection>
process(const edm4eic::RawTrackerHitCollection& raw_hits);

/// Set a configuration
eicrecon::TrackerHitReconstructionConfig&
applyConfig(eicrecon::TrackerHitReconstructionConfig& cfg) {
m_cfg = cfg;
return m_cfg;
}
void process(const Input&, const Output&) const final;

private:
/** algorithm logger */
std::shared_ptr<spdlog::logger> m_log;

/// Cell ID position converter
const dd4hep::rec::CellIDPositionConverter* m_converter;
const algorithms::GeoSvc& m_geo{algorithms::GeoSvc::instance()};
const dd4hep::rec::CellIDPositionConverter* m_converter{m_geo.cellIDPositionConverter()};
};

} // namespace eicrecon
15 changes: 10 additions & 5 deletions src/factories/tracking/TrackerHitReconstruction_factory.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2023 Wouter Deconinck
// Copyright (C) 2023 - 2025 Wouter Deconinck

#pragma once

Expand All @@ -12,7 +12,11 @@ namespace eicrecon {
class TrackerHitReconstruction_factory
: public JOmniFactory<TrackerHitReconstruction_factory, TrackerHitReconstructionConfig> {

TrackerHitReconstruction m_algo;
public:
using AlgoT = eicrecon::TrackerHitReconstruction;

private:
std::unique_ptr<AlgoT> m_algo;

PodioInput<edm4eic::RawTrackerHit> m_raw_hits_input{this};
PodioOutput<edm4eic::TrackerHit> m_rec_hits_output{this};
Expand All @@ -23,14 +27,15 @@ class TrackerHitReconstruction_factory

public:
void Configure() {
m_algo.applyConfig(config());
m_algo.init(m_geoSvc().converter(), logger());
m_algo = std::make_unique<AlgoT>(GetPrefix());
m_algo->applyConfig(config());
m_algo->init();
}

void ChangeRun(int32_t /* run_number */) {}

void Process(int32_t /* run_number */, uint64_t /* event_number */) {
m_rec_hits_output() = m_algo.process(*m_raw_hits_input());
m_algo->process({m_raw_hits_input()}, {m_rec_hits_output().get()});
}
};

Expand Down
Loading