Skip to content

Commit

Permalink
Moved function in helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
pandreetto committed Mar 7, 2024
1 parent e57ed85 commit 1d0bc2c
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 87 deletions.
14 changes: 0 additions & 14 deletions ACTSTracking/ACTSTruthTrackingProc.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@

#include "ACTSProcBase.hxx"

#include <Acts/MagneticField/MagneticFieldProvider.hpp>
#include "Acts/EventData/TrackContainer.hpp"
#include "Acts/EventData/VectorTrackContainer.hpp"
#include "Acts/EventData/VectorMultiTrajectory.hpp"

using TrackResult =
Acts::TrackContainer<Acts::VectorTrackContainer,
Acts::VectorMultiTrajectory,
std::shared_ptr>::TrackProxy;

/**
* This code performs a true pattern recognition by looping over all MC
* particles and adding all hits associated to them onto a prototrack. This is
Expand Down Expand Up @@ -60,10 +50,6 @@ class ACTSTruthTrackingProc : public ACTSProcBase {
*/
LCCollection* getCollection(const std::string&, LCEvent*);

EVENT::Track* convert_track(
const TrackResult& fitter_res,
Acts::MagneticFieldProvider::Cache& magCache);

protected:
// Encoder
std::shared_ptr<UTIL::BitField64> _encoder;
Expand Down
15 changes: 14 additions & 1 deletion ACTSTracking/Helpers.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
#include <Acts/MagneticField/MagneticFieldProvider.hpp>
#include <Acts/TrackFinding/CombinatorialKalmanFilter.hpp>
#include <Acts/TrackFitting/KalmanFitter.hpp>
#include <Acts/EventData/VectorTrackContainer.hpp>
#include <Acts/EventData/VectorMultiTrajectory.hpp>

#include "SourceLink.hxx"

namespace ACTSTracking {

using TrackResult = Acts::TrackContainer<Acts::VectorTrackContainer,
Acts::VectorMultiTrajectory,
std::shared_ptr>::TrackProxy;

//! Get path to a resource file
/**
* Get absolute file of a file `inpath` by looking in the following places:
Expand Down Expand Up @@ -45,13 +51,14 @@ std::string findFile(const std::string& inpath);
*
* \return Track with equivalent parameters of the ACTS track
*/
/*
EVENT::Track* ACTS2Marlin_track(
const Acts::CombinatorialKalmanFilterResult<ACTSTracking::SourceLink>&
fitOutput,
std::size_t trackTip,
std::shared_ptr<Acts::MagneticFieldProvider> magneticField,
Acts::MagneticFieldProvider::Cache& magCache);

*/
//! Convert ACTS KF result to LCIO track class
/**
* Converted propertie are:
Expand All @@ -65,10 +72,16 @@ EVENT::Track* ACTS2Marlin_track(
*
* \return Track with equivalent parameters of the ACTS track
*/
/*
EVENT::Track* ACTS2Marlin_track(
const Acts::KalmanFitterResult<ACTSTracking::SourceLink>& fitOutput,
std::shared_ptr<Acts::MagneticFieldProvider> magneticField,
Acts::MagneticFieldProvider::Cache& magCache);
*/
EVENT::Track* ACTS2Marlin_track(
const TrackResult& fitter_res,
std::shared_ptr<Acts::MagneticFieldProvider> magneticField,
Acts::MagneticFieldProvider::Cache& magCache);

//! Convert ACTS track state class to Marlin class
/**
Expand Down
20 changes: 17 additions & 3 deletions src/ACTSTruthCKFTrackingProc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ using namespace Acts::UnitLiterals;
using TrackFinderOptions =
Acts::CombinatorialKalmanFilterOptions<ACTSTracking::SourceLinkAccessor::Iterator,
Acts::VectorMultiTrajectory>;

/*
using TrackFinderResult = Acts::Result<
Acts::CombinatorialKalmanFilterResult<ACTSTracking::SourceLink>>;
using TrackFinderResultContainer = std::vector<TrackFinderResult>;

*/
ACTSTruthCKFTrackingProc aACTSTruthCKFTrackingProc;

ACTSTruthCKFTrackingProc::ACTSTruthCKFTrackingProc()
Expand Down Expand Up @@ -310,7 +310,21 @@ void ACTSTruthCKFTrackingProc::processEvent(LCEvent* evt) {
TrackContainer tracks(trackContainer, trackStateContainer);

for (std::size_t iseed = 0; iseed < seeds.size(); ++iseed) {
auto results = trackFinder.findTracks(seeds.at(iseed), ckfOptions, tracks);
auto result = trackFinder.findTracks(seeds.at(iseed), ckfOptions, tracks);
if (result.ok()) {
const auto& fitOutput = result.value();
for (const auto& trackTip : fitOutput)
{
std::cout << trackTip.chi2() << std::endl;
EVENT::Track* track = ACTSTracking::ACTS2Marlin_track(
trackTip, magneticField(), magCache);
trackCollection->addElement(track);
}
} else {
streamlog_out(WARNING) << "Track fit error: " << result.error() << std::endl;
_fitFails++;
}

}
/*
auto t1 = std::chrono::high_resolution_clock::now();
Expand Down
70 changes: 2 additions & 68 deletions src/ACTSTruthTrackingProc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ void ACTSTruthTrackingProc::processEvent(LCEvent* evt) {
*/
if (fitOutput.hasReferenceSurface())
{
EVENT::Track* track = convert_track(fitOutput, magCache);
EVENT::Track* track = ACTSTracking::ACTS2Marlin_track(
fitOutput, magneticField(), magCache);
trackCollection->addElement(track);

IMPL::LCRelationImpl* relationTrack = new IMPL::LCRelationImpl;
Expand Down Expand Up @@ -465,70 +466,3 @@ void ACTSTruthTrackingProc::removeHitsSameLayer(
}
}
}

EVENT::Track* ACTSTruthTrackingProc::convert_track(
const TrackResult& fitter_res,
Acts::MagneticFieldProvider::Cache& magCache)
{
IMPL::TrackImpl* track = new IMPL::TrackImpl;

track->setChi2(fitter_res.chi2());
track->setNdf(fitter_res.nDoF());

const Acts::Vector3 zeroPos(0, 0, 0);
Acts::Result<Acts::Vector3> fieldRes = magneticField()->getField(zeroPos, magCache);
if (!fieldRes.ok()) {
throw std::runtime_error("Field lookup error: " + fieldRes.error().value());
}
Acts::Vector3 field = *fieldRes;

const Acts::BoundVector& params = fitter_res.parameters();
const Acts::BoundMatrix& covariance = fitter_res.covariance();
EVENT::TrackState* trackStateAtIP = ACTSTracking::ACTS2Marlin_trackState(
EVENT::TrackState::AtIP, params, covariance, field[2] / Acts::UnitConstants::T);
track->trackStates().push_back(trackStateAtIP);

EVENT::TrackerHitVec hitsOnTrack;
EVENT::TrackStateVec statesOnTrack;

for (const auto& trk_state : fitter_res.trackStatesReversed())
{
if (!trk_state.hasUncalibratedSourceLink()) continue;

auto sl = trk_state.getUncalibratedSourceLink()
.get<ACTSTracking::SourceLink>();
EVENT::TrackerHit* curr_hit = sl.lciohit();
hitsOnTrack.push_back(curr_hit);

const Acts::Vector3 hitPos(curr_hit->getPosition()[0],
curr_hit->getPosition()[1],
curr_hit->getPosition()[2]);

EVENT::TrackState* trackState = ACTSTracking::ACTS2Marlin_trackState(
EVENT::TrackState::AtOther, trk_state.smoothed(),
trk_state.smoothedCovariance(), hitPos[2] / Acts::UnitConstants::T);
statesOnTrack.push_back(trackState);
}

std::reverse(hitsOnTrack.begin(), hitsOnTrack.end());
std::reverse(statesOnTrack.begin(), statesOnTrack.end());

for (EVENT::TrackerHit* hit : hitsOnTrack) {
track->addHit(hit);
}

if (statesOnTrack.size() > 0) {
dynamic_cast<IMPL::TrackStateImpl*>(statesOnTrack.back())
->setLocation(EVENT::TrackState::AtLastHit);
dynamic_cast<IMPL::TrackStateImpl*>(statesOnTrack.front())
->setLocation(EVENT::TrackState::AtFirstHit);
}

EVENT::TrackStateVec& myTrackStates = track->trackStates();
myTrackStates.insert(myTrackStates.end(), statesOnTrack.begin(),
statesOnTrack.end());

return track;
}


72 changes: 71 additions & 1 deletion src/Helpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ std::string findFile(const std::string& inpath) {
// nothing was found :(
return inpath;
}

/*
EVENT::Track* ACTS2Marlin_track(
const Acts::CombinatorialKalmanFilterResult<ACTSTracking::SourceLink>&
fitOutput,
Expand Down Expand Up @@ -225,6 +225,76 @@ EVENT::Track* ACTS2Marlin_track(
return track;
}
*/

EVENT::Track* ACTS2Marlin_track(
const TrackResult& fitter_res,
std::shared_ptr<Acts::MagneticFieldProvider> magneticField,
Acts::MagneticFieldProvider::Cache& magCache)
{
IMPL::TrackImpl* track = new IMPL::TrackImpl;

track->setChi2(fitter_res.chi2());
track->setNdf(fitter_res.nDoF());

const Acts::Vector3 zeroPos(0, 0, 0);
Acts::Result<Acts::Vector3> fieldRes = magneticField->getField(zeroPos, magCache);
if (!fieldRes.ok()) {
throw std::runtime_error("Field lookup error: " + fieldRes.error().value());
}
Acts::Vector3 field = *fieldRes;

const Acts::BoundVector& params = fitter_res.parameters();
const Acts::BoundMatrix& covariance = fitter_res.covariance();
EVENT::TrackState* trackStateAtIP = ACTSTracking::ACTS2Marlin_trackState(
EVENT::TrackState::AtIP, params, covariance, field[2] / Acts::UnitConstants::T);
track->trackStates().push_back(trackStateAtIP);

EVENT::TrackerHitVec hitsOnTrack;
EVENT::TrackStateVec statesOnTrack;

for (const auto& trk_state : fitter_res.trackStatesReversed())
{
if (!trk_state.hasUncalibratedSourceLink()) continue;

auto sl = trk_state.getUncalibratedSourceLink()
.get<ACTSTracking::SourceLink>();
EVENT::TrackerHit* curr_hit = sl.lciohit();
hitsOnTrack.push_back(curr_hit);

const Acts::Vector3 hitPos(curr_hit->getPosition()[0],
curr_hit->getPosition()[1],
curr_hit->getPosition()[2]);

EVENT::TrackState* trackState = ACTSTracking::ACTS2Marlin_trackState(
EVENT::TrackState::AtOther, trk_state.smoothed(),
trk_state.smoothedCovariance(), hitPos[2] / Acts::UnitConstants::T);
statesOnTrack.push_back(trackState);
}

std::reverse(hitsOnTrack.begin(), hitsOnTrack.end());
std::reverse(statesOnTrack.begin(), statesOnTrack.end());

for (EVENT::TrackerHit* hit : hitsOnTrack) {
track->addHit(hit);
}

if (statesOnTrack.size() > 0) {
dynamic_cast<IMPL::TrackStateImpl*>(statesOnTrack.back())
->setLocation(EVENT::TrackState::AtLastHit);
dynamic_cast<IMPL::TrackStateImpl*>(statesOnTrack.front())
->setLocation(EVENT::TrackState::AtFirstHit);
}

EVENT::TrackStateVec& myTrackStates = track->trackStates();
myTrackStates.insert(myTrackStates.end(), statesOnTrack.begin(),
statesOnTrack.end());

return track;
}



EVENT::TrackState* ACTS2Marlin_trackState(
int location, const Acts::BoundTrackParameters& params, double Bz) {
return ACTS2Marlin_trackState(location, params.parameters(),
Expand Down

0 comments on commit 1d0bc2c

Please sign in to comment.