14#include "GaudiKernel/IInterface.h"
41#include "Acts/Surfaces/StrawSurface.hpp"
42#include "Acts/Surfaces/PerigeeSurface.hpp"
43#include "Acts/Surfaces/PlaneSurface.hpp"
45#include "Acts/Surfaces/RectangleBounds.hpp"
46#include "Acts/Surfaces/TrapezoidBounds.hpp"
47#include "Acts/Surfaces/CylinderBounds.hpp"
48#include "Acts/Surfaces/DiscBounds.hpp"
49#include "Acts/Surfaces/LineBounds.hpp"
50#include "Acts/Surfaces/RadialBounds.hpp"
51#include "Acts/Surfaces/DiamondBounds.hpp"
53#include "Acts/Definitions/Units.hpp"
54#include "Acts/EventData/BoundTrackParameters.hpp"
55#include "Acts/EventData/VectorTrackContainer.hpp"
56#include "Acts/EventData/TransformationHelpers.hpp"
57#include "Acts/Geometry/TrackingGeometry.hpp"
58#include "Acts/Propagator/detail/JacobianEngine.hpp"
59#include "Acts/Surfaces/detail/PlanarHelper.hpp"
62#include "Acts/EventData/TrackStatePropMask.hpp"
63#include "Acts/EventData/SourceLink.hpp"
82using namespace Acts::UnitLiterals;
88 using namespace Acts::PlanarHelper;
90 const auto isect = intersectPlane(pos, mom.normalized(), target.normal(), target.center());
92 if (inPars.covariance()) {
94 rot.block<2,2>(0,0) =
AmgSymMatrix(2){Eigen::Rotation2D{90._degree}};
95 cov = rot.transpose() * (*inPars.covariance()) * rot;
97 return target.createUniqueTrackParameters(isect.position(), mom,
98 std::copysign(1., inPars.parameters()[
Trk::qOverP]),
121 return StatusCode::SUCCESS;
124std::vector<Acts::SourceLink>
126 std::vector<Acts::SourceLink> sourceLinks{};
127 sourceLinks.reserve(track.measurementsOnTrack()->size() +
128 track.outliersOnTrack()->size());
138 << trackColl.
size() <<
" tracks.");
139 unsigned int trkCount = 0;
140 std::vector<Identifier> failedIds;
145 auto actsTrack = outTrackcoll.getTrack(outTrackcoll.addTrack());
146 auto& trackStateContainer = outTrackcoll.trackStateContainer();
149 <<
" track states on surfaces.");
151 actsTrack.chi2() = trk->fitQuality()->chiSquared();
152 actsTrack.nDoF() = trk->fitQuality()->numberDoF();
156 bool first_tsos =
true;
157 int measurementsCount = 0;
161 Acts::TrackStatePropMask mask = Acts::TrackStatePropMask::None;
162 if (tsos->measurementOnTrack()) {
163 mask |= Acts::TrackStatePropMask::Calibrated;
165 if (tsos->trackParameters()) {
166 mask |= Acts::TrackStatePropMask::Smoothed;
170 auto index = Acts::kTrackIndexInvalid;
172 index = actsTrack.tipIndex();
174 auto actsTSOS = trackStateContainer.getTrackState(trackStateContainer.addTrackState(mask,
index));
175 ATH_MSG_VERBOSE(
"TipIndex: " << actsTrack.tipIndex() <<
" TSOS index within trajectory: "<< actsTSOS.index());
176 actsTrack.tipIndex() = actsTSOS.index();
178 if (tsos->trackParameters()) {
183 const Acts::BoundTrackParameters parameters =
m_geometryConvTool->convertTrackParametersToActs(ctx, *tsos->trackParameters());
187 failedIds.push_back(tsos->trackParameters()->associatedSurface().associatedDetectorElementIdentifier());
193 actsTrack.parameters() = parameters.parameters();
194 actsTrack.covariance() = *parameters.covariance();
195 actsTrack.setReferenceSurface(parameters.referenceSurface().getSharedPtr());
198 actsTSOS.setReferenceSurface(parameters.referenceSurface().getSharedPtr());
200 actsTSOS.smoothed() = parameters.parameters();
201 actsTSOS.smoothedCovariance() = *parameters.covariance();
204 if (!(actsTSOS.hasSmoothed() && actsTSOS.hasReferenceSurface())) {
206 << actsTSOS.hasSmoothed()
207 <<
"] or reference surface ["
208 << actsTSOS.hasReferenceSurface() <<
"].");
210 ATH_MSG_VERBOSE(
"TrackState has smoothed state and reference surface.");
213 }
catch (
const std::exception& e){
214 ATH_MSG_ERROR(
"Unable to convert TrackParameter with exception ["<<e.what()<<
"]. Will be missing from ACTS track."
215 <<(*tsos->trackParameters()));
218 if (tsos->measurementOnTrack()) {
219 auto &measurement = *(tsos->measurementOnTrack());
220 actsTSOS.typeFlags().setIsMeasurement();
228 int dim = measurement.localParameters().dimension();
229 actsTSOS.allocateCalibrated(dim);
231 actsTSOS.calibrated<1>() = measurement.localParameters();
232 actsTSOS.calibratedCovariance<1>() = measurement.localCovariance();
233 }
else if (dim == 2) {
234 actsTSOS.calibrated<2>() = measurement.localParameters();
235 actsTSOS.calibratedCovariance<2>() = measurement.localCovariance();
237 throw std::domain_error(
"Cannot handle measurement dim>2");
243 actsTrack.nMeasurements() = measurementsCount;
245 <<
" track states on surfaces.");
249 if (!failedIds.empty()){
250 ATH_MSG_WARNING(
"Failed to convert "<<failedIds.size()<<
" track parameters.");
251 for (
auto id : failedIds){
255 ATH_MSG_VERBOSE(
"ACTS Track container has " << outTrackcoll.size() <<
" tracks.");
258 const Acts::BoundTrackParameters ¶meters,
260 const Acts::GeometryContext &gctx)
const {
261 auto actsPos = parameters.position(gctx);
263 if ( (actsPos - trkparameters.
position()).mag() > 0.1) {
265 << actsPos <<
" vs Trk \n"
277 TrackFitResult_t& fitResult,
280 if (not fitResult.ok()) {
287template <
typename Proxy_t>
288 std::unique_ptr<Trk::Track>
290 const Proxy_t& acts_track,
297 auto finalTrajectory = std::make_unique<Trk::TrackStates>();
303 acts_track.container().trackStateContainer().visitBackwards(acts_track.tipIndex(),
304 [&] (
const auto &state) ->
void {
305 if (!state.hasReferenceSurface()) {
314 state.referenceSurface().surfacePlacement());
315 associatedDetEl !=
nullptr) {
316 ATH_MSG_VERBOSE(
"Associated det: "<<associatedDetEl->detectorType());
319 auto flag = state.typeFlags();
320 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - "<<
", hole: "<<flag.isHole()
321 <<
", outlier: "<<flag.isOutlier()<<
", measurement: "<<flag.isMeasurement()<<
"/"
323 <<
", has SL: "<<state.hasUncalibratedSourceLink());
326 std::unique_ptr<Trk::TrackParameters> trkPars =
m_geometryConvTool->convertTrackParametersToTrk(ctx,
327 acts_track.createParametersFromState(state));
328 std::unique_ptr<Trk::MeasurementBase> trkMeasurement{};
333 if (!m_convertHoles) { return; }
335 }
if (flag.isOutlier()) {
336 if (!m_convertOutliers) { return; }
339 if (flag.hasMeasurement()) {
340 typePattern.set(Trk::TrackStateOnSurface::Measurement);
341 nDoF = state.calibratedSize();
343 const auto slType = detail::MeasurementCalibratorBase::getType(state.getUncalibratedSourceLink());
345 using enum detail::SourceLinkType;
347 trkMeasurement = m_measCalib.unpack(state.getUncalibratedSourceLink())->uniqueClone();
350 trkMeasurement = m_prdCalib.createROT(tgContext, cctx, state.getUncalibratedSourceLink(), state);
352 case xAODUnCalibMeas:
353 appendMeasTSOS(ctx, detail::xAODUncalibMeasCalibrator::unpack(state.getUncalibratedSourceLink()),
354 typePattern, Trk::FitQualityOnSurface{chi2, nDoF},
355 std::move(trkPars), *finalTrajectory);
358 THROW_EXCEPTION(
"Invalid "<<slType<<
" type parsed.");
362 std::move(trkMeasurement),
363 std::move(trkPars),
nullptr, typePattern);
365 ATH_MSG_VERBOSE(
"State succesfully created, adding it to the trajectory");
366 finalTrajectory->insert(finalTrajectory->begin(), std::move(perState));
369 std::unique_ptr<Trk::TrackParameters> per = m_geometryConvTool->convertTrackParametersToTrk(ctx, acts_track.createParametersAtReference());
370 TrkTSOSMask typePattern;
372 finalTrajectory->insert(finalTrajectory->begin(),
373 std::make_unique<Trk::TrackStateOnSurface>(
nullptr, std::move(per),
nullptr, typePattern));
375 Trk::TrackInfo newInfo{fitAuthor, ParticleHypothesis::convertTrk(acts_track.particleHypothesis())};
376 auto newtrack = std::make_unique<Trk::Track>(newInfo, std::move(finalTrajectory),
nullptr);
377 constexpr bool suppressHoleSearch =
false;
378 m_trkSummaryTool->updateTrackSummary(ctx, *newtrack, suppressHoleSearch);
383 std::unique_ptr<TrackCollection>
386 auto outColl = std::make_unique<TrackCollection>();
387 for (
const ActsTrk::TrackContainer::ConstTrackProxy& trk : trackCont) {
396 std::unique_ptr<Trk::TrackParameters> trkPars,
398 std::unique_ptr<Trk::MeasurementBase> rot{};
399 switch (meas->
type()) {
401 case PixelClusterType: {
402 static const SG::AuxElement::ConstAccessor<ElementLink<InDet::PixelClusterCollection>> acc_prdLink(
"pixelClusterLink");
403 if (acc_prdLink.isAvailable(*meas) && acc_prdLink(*meas).isValid()) {
404 rot.reset(
m_ROTcreator->correct(**acc_prdLink(*meas), *trkPars, ctx));
406 ATH_MSG_WARNING(__func__<<
" () "<<__LINE__<<
" - The pixel xAOD -> prd accessor is invalid");
409 }
case StripClusterType: {
410 static const SG::AuxElement::ConstAccessor<ElementLink<InDet::SCT_ClusterCollection>> acc_prdLink(
"sctClusterLink");
411 if (acc_prdLink.isAvailable(*meas) && acc_prdLink(*meas).isValid()) {
412 rot.reset(
m_ROTcreator->correct(**acc_prdLink(*meas), *trkPars, ctx));
414 ATH_MSG_WARNING(__func__<<
" () "<<__LINE__<<
" - The strip xAOD -> prd accessor is invalid");
417 }
case MdtDriftCircleType:
418 case MMClusterType: {
423 assert(prd !=
nullptr);
428 case sTgcStripType: {
436 if (meas->
type() == RpcStripType) {
438 prd1 =
fetchPrd(ctx,
m_keyRpc, muonMeas->secondaryStrip()->identify(), modHash);
439 }
else if (meas->
type() == TgcStripType) {
441 prd1 =
fetchPrd(ctx,
m_keyTgc, muonMeas->secondaryStrip()->identify(), modHash);
444 prd1 =
fetchPrd(ctx,
m_keyStgc, muonMeas->secondaryStrip()->identify(), modHash);
446 assert(prd !=
nullptr);
447 assert(prd1 !=
nullptr);
450 const Trk::Surface& phiSurface = prd1->detectorElement()->surface(prd1->identify());
452 assert(phiPars !=
nullptr);
453 std::unique_ptr<Trk::MeasurementBase> phiRot{};
454 if (meas->
type() != sTgcStripType) {
458 phiRot.reset(
m_ROTcreator->correct(*prd1, *phiPars, ctx));
461 assert(phiRot !=
nullptr);
462 states.insert(states.begin(),
463 std::make_unique<Trk::TrackStateOnSurface>(quality,
465 std::move(phiPars),
nullptr, typePattern));
471 assert(prd !=
nullptr);
487 assert(rot !=
nullptr);
488 assert(trkPars !=
nullptr);
489 states.insert(states.begin(),
490 std::make_unique<Trk::TrackStateOnSurface>(std::move(quality), std::move(rot),
491 std::move(trkPars),
nullptr, typePattern));
494 template <
typename PrdType_t>
499 const PrdType_t* container{
nullptr};
500 if (key.empty() || !
SG::get(container, key, ctx).isSuccess()) {
503 const auto* coll = container->indexFindPtr(hash);
504 if (coll ==
nullptr){
505 ATH_MSG_WARNING(
"fetchPrd() - Failed to find a valid collection for "<<prdId.
getString()<<
", key: "<<key.fullKey());
509 if (prd->identify() == prdId) {
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define AmgSymMatrix(dim)
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
base class interface providing the bare minimal interface extension.
static Acts::SourceLink pack(const Ptr_t &measurement)
Pack the measurement type pointer to an Acts::SourceLink including the intermediate conversion into a...
Class to calibrate the Acts track states with uncalibrated Trk::PrepRaw data objects.
size_type size() const noexcept
Returns the number of elements in the collection.
This is a "hash" representation of an Identifier.
std::string getString() const
Provide a string form of the identifier - hexadecimal.
Property holding a SG store/key/clid from which a ReadHandle is made.
const Amg::Vector3D & momentum() const
Access method for the momentum.
const Amg::Vector3D & position() const
Access method for the position.
virtual const Surface & associatedSurface() const override=0
Access to the Surface associated to the Parameters.
virtual const TrkDetElementBase * detectorElement() const =0
return the detector element corresponding to this PRD The pointer will be zero if the det el is not d...
Abstract Base Class for tracking surfaces.
Contains information about the 'fitter' of this track.
TrackFitter
enums to identify who created this track and what propertis does it have.
represents the track state (measurement, material, fit parameters and quality) at a surface.
@ Perigee
This represents a perigee, and so will contain a Perigee object only.
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
@ Hole
A hole on the track - this is defined in the following way.
virtual Identifier identify() const =0
Identifier.
virtual const Surface & surface() const =0
Return surface associated with this detector element.
virtual unsigned int numDimensions() const =0
Returns the number of dimensions of the measurement.
virtual xAOD::UncalibMeasType type() const =0
Returns the type of the measurement type as a simple enumeration.
double chi2(TH1 *h0, TH1 *h1)
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Acts::TrackContainer< MutableTrackBackend, MutableTrackStateBackend, Acts::detail::ValueHolder > MutableTrackContainer
Acts::CalibrationContext getCalibrationContext(const EventContext &ctx)
The Acts::Calibration context is piped through the Acts fitters to (re)calibrate the Acts::SourceLink...
std::unique_ptr< Trk::TrackParameters > rotateParams(const Trk::TrackParameters &inPars, const Trk::Surface &target)
Eigen::Matrix< double, 3, 1 > Vector3D
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
DataVector< const Trk::TrackStateOnSurface > TrackStates
ParametersBase< TrackParametersDim, Charged > TrackParameters
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.
MuonMeasurement_v1 MuonMeasurement
UncalibMeasType
Define the type of the uncalibrated measurement.
CombinedMuonStrip_v1 CombinedMuonStrip
#define THROW_EXCEPTION(MESSAGE)