Skip to content
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

562 detailed trajectory information writer #563

Closed
wants to merge 7 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ struct TrackingResultTrajectory final {
/// (Reconstructed) trajectory with multiple states.
using MultiTrajectory = Acts::VectorMultiTrajectory;
/// Fitted parameters identified by indices in the multi trajectory.
using IndexedParameters =
std::unordered_map<Acts::MultiTrajectoryTraits::IndexType,
TrackParameters>;
using IndexedParameters = std::unordered_map<Acts::MultiTrajectoryTraits::IndexType, TrackParameters>;

/// Default construct an empty object. Required for container compatibility
/// and to signal an error.
Expand Down
38 changes: 32 additions & 6 deletions src/algorithms/tracking/ParticlesFromTrackFit.cc
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
#include "ParticlesFromTrackFit.h"
#include <algorithm>


#include "DDRec/CellIDPositionConverter.h"
#include "DDRec/SurfaceManager.h"
#include "DDRec/Surface.h"



#include "Acts/EventData/MultiTrajectory.hpp"
#include "Acts/EventData/MultiTrajectoryHelpers.hpp"

// Event Model related classes
#include "edm4eic/ReconstructedParticleCollection.h"
#include "edm4eic/TrackerHitCollection.h"
#include "edm4eic/TrackParametersCollection.h"
#include "edm4eic/Trajectory.h"
#include "JugTrack/IndexSourceLink.hpp"
#include "JugTrack/Track.hpp"


#include "Acts/Utilities/Helpers.hpp"

#include "edm4eic/vector_utils.h"
Expand All @@ -34,6 +31,7 @@ ParticlesFromTrackFitResultNew eicrecon::Reco::ParticlesFromTrackFit::execute(co
// create output collections
auto rec_parts = std::make_unique<edm4eic::ReconstructedParticleCollection >();
auto track_pars = std::make_unique<edm4eic::TrackParametersCollection>();
auto edm4eic_trajectories = std::make_unique<edm4eic::TrajectoryCollection>();

m_log->debug("Trajectories size: {}", std::size(trajectories));

Expand All @@ -48,11 +46,33 @@ ParticlesFromTrackFitResultNew eicrecon::Reco::ParticlesFromTrackFit::execute(co
m_log->debug("Empty multiTrajectory.");
continue;
}

const auto& trackTip = trackTips.front();

// Collect the trajectory summary info
auto trajState = Acts::MultiTrajectoryHelpers::trajectoryState(mj, trackTip);
auto trajState = Acts::MultiTrajectoryHelpers::trajectoryState(mj, trackTip);

// Collect the trajectory summary info
unsigned int m_nStates = trajState.nStates;
unsigned int m_nMeasurements = trajState.nMeasurements;
unsigned int m_nOutliers = trajState.nOutliers;
unsigned int m_nHoles = trajState.nHoles;
float m_chi2Sum = trajState.chi2Sum;
unsigned int m_ndf = trajState.NDF;
unsigned int m_nSharedHits = trajState.nSharedHits;

bool hasFit = traj->hasTrackParameters(trackTip);

auto edm4eic_traj = edm4eic_trajectories->create(
hasFit,
m_nStates,
m_nMeasurements,
m_nOutliers,
m_nHoles,
m_chi2Sum,
m_ndf,
m_nSharedHits
);

//int m_nMeasurements = trajState.nMeasurements;
//int m_nStates = trajState.nStates;

Expand Down Expand Up @@ -105,6 +125,8 @@ ParticlesFromTrackFitResultNew eicrecon::Reco::ParticlesFromTrackFit::execute(co
timeError,
static_cast<float>(boundParam.charge())};
track_pars->push_back(pars);

edm4eic_traj.setTrackParameters(pars);
}

auto tsize = trackTips.size();
Expand Down Expand Up @@ -137,5 +159,9 @@ ParticlesFromTrackFitResultNew eicrecon::Reco::ParticlesFromTrackFit::execute(co
});
}

return new ParticlesFromTrackFitResult(
std::move(rec_parts),
std::move(track_pars),
std::move(edm4eic_trajectories));
return std::make_pair(std::move(rec_parts), std::move(track_pars));
}
11 changes: 8 additions & 3 deletions src/algorithms/tracking/ParticlesFromTrackFitResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@
#include <memory>
#include <edm4eic/ReconstructedParticleCollection.h>
#include <edm4eic/TrackParametersCollection.h>
#include <edm4eic/TrajectoryCollection.h>

class ParticlesFromTrackFitResult {
public:
ParticlesFromTrackFitResult(
std::unique_ptr<edm4eic::ReconstructedParticleCollection> particles,
std::unique_ptr<edm4eic::TrackParametersCollection> track_parameters):
m_particles(std::move(particles)),
m_track_parameters(std::move(track_parameters))
std::unique_ptr<edm4eic::TrackParametersCollection> track_parameters,
std::unique_ptr<edm4eic::TrajectoryCollection> trajectories):
m_particles(std::move(particles)),
m_track_parameters(std::move(track_parameters)),
m_trajectories(std::move(trajectories))
{}

[[nodiscard]] edm4eic::ReconstructedParticleCollection* particles() const {return m_particles.get();}
[[nodiscard]] edm4eic::TrackParametersCollection* trackParameters() const {return m_track_parameters.get();}
[[nodiscard]] edm4eic::TrajectoryCollection* trajectories() const {return m_trajectories.get();}

private:
std::unique_ptr<edm4eic::ReconstructedParticleCollection> m_particles;
std::unique_ptr<edm4eic::TrackParametersCollection> m_track_parameters;
std::unique_ptr<edm4eic::TrajectoryCollection> m_trajectories;
};
46 changes: 46 additions & 0 deletions src/global/tracking/Trajectory_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Created by Shyam Kumar; INFN Bari, [email protected]; [email protected]
// Subject to the terms in the LICENSE file found in the top-level directory.

#include "Trajectory_factory.h"
#include <edm4eic/Trajectory.h>
#include "extensions/string/StringHelpers.h"
#include <JANA/JEvent.h>
#include <services/log/Log_service.h>
#include <extensions/spdlog/SpdlogExtensions.h>

namespace eicrecon {
void Trajectory_factory::Init() {
auto app = GetApplication();

// This prefix will be used for parameters
std::string plugin_name = eicrecon::str::ReplaceAll(GetPluginName(), ".so", "");
std::string param_prefix = plugin_name+ ":" + GetTag();

// Set input data tags properly
InitDataTags(param_prefix);

// SpdlogMixin logger initialization, sets m_log
InitLogger(param_prefix, "info");
}

void Trajectory_factory::ChangeRun(const std::shared_ptr<const JEvent> &event) {
// Nothing to do here
}

void Trajectory_factory::Process(const std::shared_ptr<const JEvent> &event) {

auto trajectories = event->Get<edm4eic::Trajectory>("outputTrajectories");

try {
std::vector<edm4eic::Trajectory *> result;
for (const auto *trajectory: trajectories) {
auto trajectory_params = (*trajectory_info->Trajectory())[i];
result.push_back(new edm4eic::Trajectory(trajectory_params));
}
Set(result);
}
catch(std::exception &e) {
m_log->warn("Exception in underlying algorithm: {}. Event data will be skipped", e.what());
}
}
} // eicrecon
35 changes: 35 additions & 0 deletions src/global/tracking/Trajectory_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Created by Shyam Kumar; INFN Bari, [email protected]; [email protected]
// Subject to the terms in the LICENSE file found in the top-level directory.
//

#pragma once

#include <edm4eic/Trajectory.h>
#include <extensions/jana/JChainFactoryT.h>
#include <extensions/spdlog/SpdlogMixin.h>

namespace eicrecon {

class Trajectory_factory : public JChainFactoryT<edm4eic::Trajectory>,
public SpdlogMixin<Trajectory_factory> {

public:
Trajectory_factory(std::vector<std::string> default_input_tags):
JChainFactoryT<edm4eic::Trajectory>( std::move(default_input_tags) ) {
}

/** One time initialization **/
void Init() override;

/** On run change preparations **/
void ChangeRun(const std::shared_ptr<const JEvent> &event) override;

/** Event by event processing **/
void Process(const std::shared_ptr<const JEvent> &event) override;

private:

std::vector<std::string> m_input_tags;
};

} // eicrecon
6 changes: 6 additions & 0 deletions src/global/tracking/tracking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "TrackSeeding_factory.h"
#include "TrackerHitCollector_factory.h"
#include "TrackProjector_factory.h"
#include "Trajectory_factory.h"
#include "ParticlesWithTruthPID_factory.h"

//
Expand Down Expand Up @@ -63,6 +64,11 @@ void InitPlugin(JApplication *app) {
"outputTrackParameters"}, // edm4eic::TrackParameters
app));

app->Add(new JChainFactoryGeneratorT<Trajectory_factory>(
{"CentralCKFTrajectories"}, "CentralTrackingTrajectories"));

app->Add(new JChainFactoryGeneratorT<TrackerReconstructedParticle_factory>(
{"CentralTrackingParticles"}, "outputParticles"));
app->Add(new JChainMultifactoryGeneratorT<ParticlesWithTruthPID_factory>(
"ChargedParticlesWithAssociations", // Tag name for multifactory
{"MCParticles", // edm4hep::MCParticle
Expand Down