Skip to content

Commit

Permalink
CKF Redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Nov 21, 2024
1 parent eccfd02 commit ede6d39
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 84 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions source/extensions/spdlog/SpdlogToActs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <Acts/Utilities/Logger.hpp>
#include <JANA/JException.h>

namespace eicrecon {
namespace tdis {

using namespace Acts::Logging;

Expand Down Expand Up @@ -135,11 +135,11 @@ class SpdlogPrintPolicy final : public Acts::Logging::OutputPrintPolicy {
std::vector<std::tuple<std::string, std::regex, std::size_t, Acts::Logging::Level>> m_suppressions;
};

inline std::unique_ptr<const Acts::Logger> getSpdlogLogger(
inline std::unique_ptr<const Acts::Logger> makeActsLogger(
const std::string& name,
std::shared_ptr<spdlog::logger> log,
std::vector<std::string> suppressions = {}) {

std::vector<std::string> suppressions = {})
{
const Acts::Logging::Level lvl = SpdlogToActsLevel(log->level());
auto output = std::make_unique<Acts::Logging::NamedOutputDecorator>(
std::make_unique<SpdlogPrintPolicy>(log, suppressions),
Expand Down
10 changes: 7 additions & 3 deletions source/tdis/io/PodioWriteProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <podio/podioVersion.h>
#include <spdlog/logger.h>

#include <ActsExamples/EventData/Track.hpp>
#include <chrono>
#include <exception>
#include <memory>
Expand All @@ -74,10 +75,11 @@ class PodioWriteProcessor : public JEventProcessor {
"DigitizedMtpcMcTrack",
"DigitizedMtpcMcHit",

// Digitized hits

"TrackerHit",
"Measurement2D",
"TruthTrackInitParameters",
"ConstTrackContainer"
};

PodioWriteProcessor(JApplication * app);
Expand Down Expand Up @@ -141,7 +143,9 @@ inline void PodioWriteProcessor::Init() {

inline void PodioWriteProcessor::Process(const std::shared_ptr<const JEvent>& event) {
std::lock_guard<std::mutex> lock(m_mutex);
auto hits = event->GetCollection<edm4eic::TrackerHit>("TrackerHit");
// auto hits = event->GetCollection<edm4eic::TrackerHit>("TrackerHit");

[[maybe_unused]] auto tracks = event->Get<ActsExamples::ConstTrackContainer>("ConstTrackContainer");

m_log->info("PodioWriteProcessor::Process() All event collections:");
auto event_collections = event->GetAllCollectionNames();
Expand All @@ -161,6 +165,7 @@ inline void PodioWriteProcessor::Process(const std::shared_ptr<const JEvent>& 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
}
}
Expand Down Expand Up @@ -262,7 +267,6 @@ inline void PodioWriteProcessor::Process(const std::shared_ptr<const JEvent>& 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;
}
Expand Down
20 changes: 14 additions & 6 deletions source/tdis/tdis_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -117,19 +118,26 @@ int main(int argc, char* argv[]) {
app.ProvideService(std::make_shared<tdis::services::LogService>(&app));
app.ProvideService(std::make_shared<tdis::tracking::ActsGeometryService>());

auto reco_hit_generator = new JOmniFactoryGeneratorT<tdis::tracking::ReconstructedHitFactory>();
reco_hit_generator->AddWiring(
auto recoHitGenerator = new JOmniFactoryGeneratorT<tdis::tracking::ReconstructedHitFactory>();
recoHitGenerator->AddWiring(
"TrackerHitGenerator",
{"DigitizedMtpcMcHit"},
{"TrackerHit", "Measurement2D"});
app.Add(reco_hit_generator);
app.Add(recoHitGenerator);

auto truth_track_init_generator = new JOmniFactoryGeneratorT<tdis::tracking::TruthTrackParameterFactory>();
truth_track_init_generator->AddWiring(
auto truthTrackInitGenerator = new JOmniFactoryGeneratorT<tdis::tracking::TruthTrackParameterFactory>();
truthTrackInitGenerator->AddWiring(
"TruthTrackParameterGenerator",
{"DigitizedMtpcMcTrack"},
{"TruthTrackInitParameters"});
app.Add(truth_track_init_generator);
app.Add(truthTrackInitGenerator);

auto kalmanFitterGenerator = new JOmniFactoryGeneratorT<tdis::tracking::KalmanFittingFactory>();
kalmanFitterGenerator->AddWiring(
"KalmanFitterGenerator",
{"TruthTrackInitParameters", "Measurement2D"},
{"ConstTrackContainer"});
app.Add(kalmanFitterGenerator);

// auto measurement_2d_generator = new JOmniFactoryGeneratorT<tdis::tracking::Measurement2DFactory>();
// measurement_2d_generator->AddWiring("TrackerHitGenerator", {"TrackerHit"}, {"Measurement2D"});
Expand Down
4 changes: 2 additions & 2 deletions source/tdis/tracking/ActsGeometryService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<const Acts::IMaterialDecorator> materialDeco{nullptr};
Expand All @@ -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());
Expand Down
94 changes: 93 additions & 1 deletion source/tdis/tracking/KalmanFittingFactory.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,93 @@
#include "KalmanFittingFactory.h""
#include "KalmanFittingFactory.h"

#include <Acts/Definitions/Algebra.hpp>
#include <Acts/Definitions/TrackParametrization.hpp>
#include <Acts/Definitions/Units.hpp>
#include <Acts/EventData/GenericBoundTrackParameters.hpp>
#include <Acts/EventData/MultiTrajectory.hpp>
#include <Acts/EventData/ParticleHypothesis.hpp>
#include <Acts/EventData/ProxyAccessor.hpp>
#include <Acts/EventData/SourceLink.hpp>
#include <Acts/EventData/TrackContainer.hpp>
#include <Acts/EventData/TrackProxy.hpp>
#include <Acts/EventData/VectorMultiTrajectory.hpp>
#include <Acts/EventData/VectorTrackContainer.hpp>
#include <Acts/Geometry/GeometryIdentifier.hpp>
#include <Acts/MagneticField/ConstantBField.hpp>

#include "extensions/spdlog/SpdlogToActs.h"
//#include <Acts/Propagator/AbortList.hpp>
#include <Acts/Propagator/EigenStepper.hpp>
#include <Acts/Propagator/MaterialInteractor.hpp>
#include <Acts/Propagator/Navigator.hpp>
#include <Acts/Propagator/Propagator.hpp>
#include <Acts/Propagator/StandardAborters.hpp>
#include <Acts/Surfaces/PerigeeSurface.hpp>
#include <Acts/Surfaces/Surface.hpp>
#include <Acts/TrackFitting/GainMatrixSmoother.hpp>
#include <Acts/TrackFitting/GainMatrixUpdater.hpp>
#include <Acts/Utilities/Logger.hpp>
#include <Acts/Utilities/TrackHelpers.hpp>
#include <ActsExamples/EventData/IndexSourceLink.hpp>
#include <ActsExamples/EventData/Measurement.hpp>
#include <ActsExamples/EventData/MeasurementCalibration.hpp>
#include <ActsExamples/EventData/Track.hpp>
//#include <edm4eic/Cov3f.h>
//#include <edm4eic/Cov6f.h>
//#include <edm4eic/Measurement2DCollection.h>
//#include <edm4eic/TrackParametersCollection.h>
//#include <edm4hep/Vector2f.h>
#include <fmt/core.h>
#include <Eigen/Core>
#include <array>
#include <cmath>
#include <cstddef>
#include <functional>
#include <list>
#include <optional>
#include <utility>

#include <extensions/spdlog/SpdlogToActs.h>


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<const eicrecon::BField::DD4hepBField>(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 <typename stepper_t>
auto tdis::tracking::KalmanFittingFactory::makeConstantFieldPropagator(std::shared_ptr<const Acts::TrackingGeometry> 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::ConstantBField>(Acts::Vector3(0.0, 0.0, bz));
stepper_t stepper(std::move(field));
return Acts::Propagator<decltype(stepper), Acts::Navigator>(std::move(stepper), std::move(navigator));;
}
93 changes: 28 additions & 65 deletions source/tdis/tracking/KalmanFittingFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,84 +14,47 @@

namespace tdis::tracking {



struct KalmanFittingFactory : public JOmniFactory<KalmanFittingFactory> {

PodioInput<edm4eic::TrackParameters> m_parameters_input {this};
PodioInput<edm4eic::Measurement2D> m_measurements_input {this};
Output<ActsExamples::Trajectories> m_acts_trajectories_output {this};
Output<ActsExamples::ConstTrackContainer> m_acts_tracks_output {this};

ParameterRef<std::vector<double>> m_etaBins {this, "EtaBins", config().etaBins, "Eta Bins for ACTS CKF tracking reco"};
ParameterRef<std::vector<double>> m_chi2CutOff {this, "Chi2CutOff", config().chi2CutOff, "Chi2 Cut Off for ACTS CKF tracking"};
ParameterRef<std::vector<size_t>> m_numMeasurementsCutOff {this, "NumMeasurementsCutOff", config().numMeasurementsCutOff, "Number of measurements Cut Off for ACTS CKF tracking"};


// // Output<ActsExamples::Trajectories> m_acts_trajectories_output {this};
Output<ActsExamples::ConstTrackContainer> m_acts_tracks_output {this, "ConstTrackContainer"};
//
// Parameter<std::vector<double>> m_etaBins {this, "EtaBins", {}, "Eta Bins for ACTS CKF tracking reco"};
// Parameter<std::vector<double>> m_chi2CutOff {this, "Chi2CutOff", {15.}, "Chi2 Cut Off for ACTS CKF tracking"};
// Parameter<std::vector<size_t>> m_numMeasurementsCutOff {this, "NumMeasurementsCutOff", {10}, "Number of measurements Cut Off for ACTS CKF tracking"};
//
//
Service<ActsGeometryService> m_serviceGeometry{this};
Service<services::LogService> m_service_log{this};
Parameter<bool> 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<bool> 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 <typename stepper_t>
auto makeConstantFieldPropagator(
std::shared_ptr<const Acts::TrackingGeometry> 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::ConstantBField>(Acts::Vector3(0.0, 0.0, bz));
stepper_t stepper(std::move(field));
return Acts::Propagator<decltype(stepper), Acts::Navigator>(
std::move(stepper), std::move(navigator));
}
auto makeConstantFieldPropagator(std::shared_ptr<const Acts::TrackingGeometry> 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<const eicrecon::BField::DD4hepBField>(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<spdlog::logger> m_log;
std::shared_ptr<const Acts::Logger> m_acts_logger{nullptr};
// std::shared_ptr<CKFTrackingFunction> m_trackFinderFunc;


std::shared_ptr<const eicrecon::BField::DD4hepBField> 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<CKFTrackingFunction> m_trackFinderFunc;
//
//
std::shared_ptr<Acts::TrackingGeometry> 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; }

};

Expand Down
2 changes: 1 addition & 1 deletion tpc-tracking-display/src/utils/Geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const ringWidth = totalRadius / numRings;
export const deltaTheta = (2 * Math.PI) / numPadsPerRing;

export const planePositions = [

]


Expand Down

0 comments on commit ede6d39

Please sign in to comment.