From ede6d397653e84b318297b7fa08be30808a0bda0 Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Thu, 21 Nov 2024 16:54:06 -0500 Subject: [PATCH] CKF Redesign --- README.md | 12 ++- source/extensions/spdlog/SpdlogToActs.h | 8 +- source/tdis/io/PodioWriteProcessor.hpp | 10 +- source/tdis/tdis_main.cpp | 20 ++-- source/tdis/tracking/ActsGeometryService.cc | 4 +- source/tdis/tracking/KalmanFittingFactory.cpp | 94 ++++++++++++++++++- source/tdis/tracking/KalmanFittingFactory.h | 93 ++++++------------ tpc-tracking-display/src/utils/Geometry.ts | 2 +- 8 files changed, 159 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index 84e7725..7546f01 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,19 @@ tdis -pnthreads=1 -pjana:nevents=10 -ppodio:output_file=/mnt/data/test_output_v01.root --ppodio:print_collections=McHits --pacts:geometry=/mnt/data/ +-pacts:geometry=/mnt/data/g4sbs_mtpc.root +-pacts:round_tgeo_values=0 +-pacts:output_obj=/mnt/data/acts_geom.obj +-pacts:output_ply=/mnt/data/acts_geom.ply +-ptracking:hit_reco:log_level=trace /mnt/data/g4sbsout_EPCEvents_200000.txt ``` +To print specific collection before the output +```bash +-ppodio:print_collections=TrackerHit +``` + ## ## Geometry IDs diff --git a/source/extensions/spdlog/SpdlogToActs.h b/source/extensions/spdlog/SpdlogToActs.h index b3b5216..00cf13a 100644 --- a/source/extensions/spdlog/SpdlogToActs.h +++ b/source/extensions/spdlog/SpdlogToActs.h @@ -22,7 +22,7 @@ #include #include -namespace eicrecon { +namespace tdis { using namespace Acts::Logging; @@ -135,11 +135,11 @@ class SpdlogPrintPolicy final : public Acts::Logging::OutputPrintPolicy { std::vector> m_suppressions; }; -inline std::unique_ptr getSpdlogLogger( +inline std::unique_ptr makeActsLogger( const std::string& name, std::shared_ptr log, - std::vector suppressions = {}) { - + std::vector suppressions = {}) +{ const Acts::Logging::Level lvl = SpdlogToActsLevel(log->level()); auto output = std::make_unique( std::make_unique(log, suppressions), diff --git a/source/tdis/io/PodioWriteProcessor.hpp b/source/tdis/io/PodioWriteProcessor.hpp index ba11c75..e26d7f7 100644 --- a/source/tdis/io/PodioWriteProcessor.hpp +++ b/source/tdis/io/PodioWriteProcessor.hpp @@ -49,6 +49,7 @@ #include #include +#include #include #include #include @@ -74,10 +75,11 @@ class PodioWriteProcessor : public JEventProcessor { "DigitizedMtpcMcTrack", "DigitizedMtpcMcHit", - // Digitized hits + "TrackerHit", "Measurement2D", "TruthTrackInitParameters", + "ConstTrackContainer" }; PodioWriteProcessor(JApplication * app); @@ -141,7 +143,9 @@ inline void PodioWriteProcessor::Init() { inline void PodioWriteProcessor::Process(const std::shared_ptr& event) { std::lock_guard lock(m_mutex); - auto hits = event->GetCollection("TrackerHit"); + // auto hits = event->GetCollection("TrackerHit"); + + [[maybe_unused]] auto tracks = event->Get("ConstTrackContainer"); m_log->info("PodioWriteProcessor::Process() All event collections:"); auto event_collections = event->GetAllCollectionNames(); @@ -161,6 +165,7 @@ inline void PodioWriteProcessor::Process(const std::shared_ptr& ev [[maybe_unused]] const auto* coll_ptr = event->GetCollectionBase(coll_name); m_collections_to_write.push_back(coll_name); } catch (std::exception& e) { + m_log->warn("Exception trying to produce: {}, message: {}", coll_name, e.what()); // chomp } } @@ -262,7 +267,6 @@ inline void PodioWriteProcessor::Process(const std::shared_ptr& ev m_log->info("PODIO checkConsistency missing_names: {}", missing_names.size()); for (const auto& coll_name : missing_names) { m_log->info(" {}", coll_name); - } m_is_first_event = false; } diff --git a/source/tdis/tdis_main.cpp b/source/tdis/tdis_main.cpp index 33de276..2569e92 100644 --- a/source/tdis/tdis_main.cpp +++ b/source/tdis/tdis_main.cpp @@ -22,6 +22,7 @@ #include "tracking/ActsGeometryService.h" #include "tracking/ReconstructedHitFactory.h" #include "tracking/TruthTrackParameterFactory.h" +#include "tracking/KalmanFittingFactory.h" // #include "tracking/Measurement2DFactory.h" struct ProgramArguments { @@ -117,19 +118,26 @@ int main(int argc, char* argv[]) { app.ProvideService(std::make_shared(&app)); app.ProvideService(std::make_shared()); - auto reco_hit_generator = new JOmniFactoryGeneratorT(); - reco_hit_generator->AddWiring( + auto recoHitGenerator = new JOmniFactoryGeneratorT(); + recoHitGenerator->AddWiring( "TrackerHitGenerator", {"DigitizedMtpcMcHit"}, {"TrackerHit", "Measurement2D"}); - app.Add(reco_hit_generator); + app.Add(recoHitGenerator); - auto truth_track_init_generator = new JOmniFactoryGeneratorT(); - truth_track_init_generator->AddWiring( + auto truthTrackInitGenerator = new JOmniFactoryGeneratorT(); + truthTrackInitGenerator->AddWiring( "TruthTrackParameterGenerator", {"DigitizedMtpcMcTrack"}, {"TruthTrackInitParameters"}); - app.Add(truth_track_init_generator); + app.Add(truthTrackInitGenerator); + + auto kalmanFitterGenerator = new JOmniFactoryGeneratorT(); + kalmanFitterGenerator->AddWiring( + "KalmanFitterGenerator", + {"TruthTrackInitParameters", "Measurement2D"}, + {"ConstTrackContainer"}); + app.Add(kalmanFitterGenerator); // auto measurement_2d_generator = new JOmniFactoryGeneratorT(); // measurement_2d_generator->AddWiring("TrackerHitGenerator", {"TrackerHit"}, {"Measurement2D"}); diff --git a/source/tdis/tracking/ActsGeometryService.cc b/source/tdis/tracking/ActsGeometryService.cc index 2e901f7..a47c437 100644 --- a/source/tdis/tracking/ActsGeometryService.cc +++ b/source/tdis/tracking/ActsGeometryService.cc @@ -275,7 +275,7 @@ void tdis::tracking::ActsGeometryService::Init() { // Set ACTS logging level - auto acts_init_log_level = eicrecon::SpdlogToActsLevel(m_init_log->level()); + auto acts_init_log_level = tdis::SpdlogToActsLevel(m_init_log->level()); // Load ACTS materials maps std::shared_ptr materialDeco{nullptr}; @@ -295,7 +295,7 @@ void tdis::tracking::ActsGeometryService::Init() { // Convert DD4hep geometry to ACTS m_init_log->info("Converting TGeo geometry to ACTS..."); - auto logger = eicrecon::getSpdlogLogger("CONV", m_log); + auto logger = tdis::makeActsLogger("CONV", m_log); m_log->info("Loading geometry file: "); m_log->info(" '{}'", m_tgeo_file()); diff --git a/source/tdis/tracking/KalmanFittingFactory.cpp b/source/tdis/tracking/KalmanFittingFactory.cpp index 9f1a46e..45e05e7 100644 --- a/source/tdis/tracking/KalmanFittingFactory.cpp +++ b/source/tdis/tracking/KalmanFittingFactory.cpp @@ -1 +1,93 @@ -#include "KalmanFittingFactory.h"" \ No newline at end of file +#include "KalmanFittingFactory.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "extensions/spdlog/SpdlogToActs.h" +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include +//#include +//#include +//#include +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +void tdis::tracking::KalmanFittingFactory::Configure() +{ + + m_log = m_service_log().logger("tracking:ckf"); + m_acts_logger = makeActsLogger("CKF", m_log); + +// m_geoSvc = m_serviceGeometry->GetActsGeometryContext(); +// +// m_BField = std::dynamic_pointer_cast(m_geoSvc->getFieldProvider()); +// m_fieldctx = eicrecon::BField::BFieldVariant(m_BField); +// +// // eta bins, chi2 and #sourclinks per surface cutoffs +// m_sourcelinkSelectorCfg = { +// {Acts::GeometryIdentifier(), +// {m_cfg.etaBins, m_cfg.chi2CutOff, +// {m_cfg.numMeasurementsCutOff.begin(), m_cfg.numMeasurementsCutOff.end()} +// } +// }, +// }; +// m_trackFinderFunc = CKFTracking::makeCKFTrackingFunction(m_geoSvc->trackingGeometry(), m_BField, logger()); + +} + +void tdis::tracking::KalmanFittingFactory::Execute(int32_t runNumber, uint64_t evtNumber) +{ + + m_log->debug("{}::Execute", this->GetTypeName()); + +} + +template +auto tdis::tracking::KalmanFittingFactory::makeConstantFieldPropagator(std::shared_ptr geo, double bz) { + Acts::Navigator::Config cfg{std::move(geo)}; + cfg.resolvePassive = false; + cfg.resolveMaterial = true; + cfg.resolveSensitive = true; + Acts::Navigator navigator(cfg, Acts::getDefaultLogger("Navigator", Acts::Logging::INFO)); + auto field = std::make_shared(Acts::Vector3(0.0, 0.0, bz)); + stepper_t stepper(std::move(field)); + return Acts::Propagator(std::move(stepper), std::move(navigator));; +} diff --git a/source/tdis/tracking/KalmanFittingFactory.h b/source/tdis/tracking/KalmanFittingFactory.h index 57eda1e..aead3dd 100644 --- a/source/tdis/tracking/KalmanFittingFactory.h +++ b/source/tdis/tracking/KalmanFittingFactory.h @@ -14,84 +14,47 @@ namespace tdis::tracking { - - struct KalmanFittingFactory : public JOmniFactory { - PodioInput m_parameters_input {this}; PodioInput m_measurements_input {this}; - Output m_acts_trajectories_output {this}; - Output m_acts_tracks_output {this}; - - ParameterRef> m_etaBins {this, "EtaBins", config().etaBins, "Eta Bins for ACTS CKF tracking reco"}; - ParameterRef> m_chi2CutOff {this, "Chi2CutOff", config().chi2CutOff, "Chi2 Cut Off for ACTS CKF tracking"}; - ParameterRef> m_numMeasurementsCutOff {this, "NumMeasurementsCutOff", config().numMeasurementsCutOff, "Number of measurements Cut Off for ACTS CKF tracking"}; - - +// // Output m_acts_trajectories_output {this}; + Output m_acts_tracks_output {this, "ConstTrackContainer"}; +// +// Parameter> m_etaBins {this, "EtaBins", {}, "Eta Bins for ACTS CKF tracking reco"}; +// Parameter> m_chi2CutOff {this, "Chi2CutOff", {15.}, "Chi2 Cut Off for ACTS CKF tracking"}; +// Parameter> m_numMeasurementsCutOff {this, "NumMeasurementsCutOff", {10}, "Number of measurements Cut Off for ACTS CKF tracking"}; +// +// Service m_serviceGeometry{this}; Service m_service_log{this}; - Parameter m_cfg_use_true_pos{this, "acts:use_true_position", true, "Use true hits xyz instead of digitized one"}; - - - // Construct a propagator using a constant magnetic field along z. +// Parameter m_cfg_use_true_pos{this, "acts:use_true_position", true, "Use true hits xyz instead of digitized one"}; +// +// +// // Construct a propagator using a constant magnetic field along z. template - auto makeConstantFieldPropagator( - std::shared_ptr geo, double bz) { - Acts::Navigator::Config cfg{std::move(geo)}; - cfg.resolvePassive = false; - cfg.resolveMaterial = true; - cfg.resolveSensitive = true; - Acts::Navigator navigator( - cfg, Acts::getDefaultLogger("Navigator", Acts::Logging::INFO)); - auto field = - std::make_shared(Acts::Vector3(0.0, 0.0, bz)); - stepper_t stepper(std::move(field)); - return Acts::Propagator( - std::move(stepper), std::move(navigator)); - } + auto makeConstantFieldPropagator(std::shared_ptr geo, double bz); - void Configure() { - m_log = log; - m_acts_logger = eicrecon::getSpdlogLogger("CKF", m_log); + void Configure(); - m_geoSvc = geo_svc; + void ChangeRun(int32_t runNumber) override {/*nothin here*/}; - m_BField = std::dynamic_pointer_cast(m_geoSvc->getFieldProvider()); - m_fieldctx = eicrecon::BField::BFieldVariant(m_BField); + void Execute(int32_t runNumber, uint64_t evtNumber); - // eta bins, chi2 and #sourclinks per surface cutoffs - m_sourcelinkSelectorCfg = { - {Acts::GeometryIdentifier(), - {m_cfg.etaBins, m_cfg.chi2CutOff, - {m_cfg.numMeasurementsCutOff.begin(), m_cfg.numMeasurementsCutOff.end()} - } - }, - }; - m_trackFinderFunc = CKFTracking::makeCKFTrackingFunction(m_geoSvc->trackingGeometry(), m_BField, logger()); - } - - void ChangeRun(int32_t /*run_nr*/) { - } - - void Execute(int32_t /*run_nr*/, uint64_t /*evt_nr*/) { - - - } private: std::shared_ptr m_log; std::shared_ptr m_acts_logger{nullptr}; - // std::shared_ptr m_trackFinderFunc; - - - std::shared_ptr m_BField = nullptr; - Acts::GeometryContext m_geoctx; - Acts::CalibrationContext m_calibctx; - Acts::MagneticFieldContext m_fieldctx; - - Acts::MeasurementSelector::Config m_sourcelinkSelectorCfg; - - /// Private access to the logging instance - const Acts::Logger& logger() const { return *m_acts_logger; } +// // std::shared_ptr m_trackFinderFunc; +// +// + std::shared_ptr m_geometry{nullptr}; +// Acts::GeometryContext m_geoctx; +// Acts::CalibrationContext m_calibctx; +// Acts::MagneticFieldContext m_fieldctx; +// +// Acts::MeasurementSelector::Config m_sourcelinkSelectorCfg; +// +// /// Private access to the logging instance +// const Acts::Logger& logger() const { return *m_acts_logger; } }; diff --git a/tpc-tracking-display/src/utils/Geometry.ts b/tpc-tracking-display/src/utils/Geometry.ts index 5cc6da0..ea81d48 100644 --- a/tpc-tracking-display/src/utils/Geometry.ts +++ b/tpc-tracking-display/src/utils/Geometry.ts @@ -8,7 +8,7 @@ export const ringWidth = totalRadius / numRings; export const deltaTheta = (2 * Math.PI) / numPadsPerRing; export const planePositions = [ - + ]