397 if (not fitResult.ok())
400 std::unique_ptr<Trk::Track> newtrack =
nullptr;
402 const auto& acts_track = fitResult.value();
403 auto finalTrajectory = std::make_unique<Trk::TrackStates>();
405 int numberOfDeadPixel = 0;
406 int numberOfDeadSCT = 0;
408 std::vector<std::unique_ptr<const Acts::BoundTrackParameters>> actsSmoothedParam;
410 tracks.trackStateContainer().visitBackwards(acts_track.tipIndex(),
411 [&] (
const auto &state) ->
void
414 auto flag = state.typeFlags();
415 const auto* associatedDetEl = state.referenceSurface().associatedDetectorElement();
416 if (not associatedDetEl)
419 const auto* actsElement = dynamic_cast<const ActsDetectorElement*>(associatedDetEl);
423 const auto* upstreamDetEl = actsElement->upstreamDetectorElement();
424 if (not upstreamDetEl)
427 ATH_MSG_VERBOSE(
"Try casting to TRT for if");
428 if (dynamic_cast<const InDetDD::TRT_BaseElement*>(upstreamDetEl))
431 const auto* trkDetElem = dynamic_cast<const Trk::TrkDetElementBase*>(upstreamDetEl);
435 ATH_MSG_VERBOSE(
"trkDetElem type: " << static_cast<std::underlying_type_t<Trk::DetectorElemType>>(trkDetElem->detectorType()));
437 ATH_MSG_VERBOSE(
"Try casting to SiDetectorElement");
438 const auto* detElem = dynamic_cast<const InDetDD::SiDetectorElement*>(upstreamDetEl);
441 ATH_MSG_VERBOSE(
"detElem = " << detElem);
444 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
445 std::unique_ptr<Trk::TrackParameters> parm;
448 if (flag.test(Acts::TrackStateFlag::HoleFlag)){
449 ATH_MSG_VERBOSE(
"State is a hole (no associated measurement), use predicted parameters");
450 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
452 state.predictedCovariance(),
453 acts_track.particleHypothesis());
454 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
455 auto boundaryCheck = m_boundaryCheckTool->boundaryCheck(*parm);
457 ATH_MSG_VERBOSE(
"Check if this is a hole, a dead sensors or a state outside the sensor boundary");
458 if(boundaryCheck == Trk::BoundaryCheckResult::DeadElement){
459 if (detElem->isPixel()) {
462 else if (detElem->isSCT()) {
467 } else if (boundaryCheck != Trk::BoundaryCheckResult::Candidate){
471 typePattern.set(Trk::TrackStateOnSurface::Hole);
474 else if (
flag.test(Acts::TrackStateFlag::OutlierFlag) or not state.hasSmoothed()) {
475 ATH_MSG_VERBOSE(
"The state was tagged as an outlier or was missed in the reverse filtering, use filtered parameters");
476 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
478 state.filteredCovariance(),
479 acts_track.particleHypothesis());
480 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
481 typePattern.set(Trk::TrackStateOnSurface::Outlier);
485 ATH_MSG_VERBOSE(
"The state is a measurement state, use smoothed parameters");
487 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
489 state.smoothedCovariance(),
490 acts_track.particleHypothesis());
492 actsSmoothedParam.push_back(std::make_unique<const Acts::BoundTrackParameters>(Acts::BoundTrackParameters(actsParam)));
493 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
494 typePattern.set(Trk::TrackStateOnSurface::Measurement);
497 std::unique_ptr<Trk::MeasurementBase> measState;
498 if (state.hasUncalibratedSourceLink()){
499 auto sl = state.getUncalibratedSourceLink().template get<ATLASSourceLink>();
501 measState = sl->uniqueClone();
503 double nDoF = state.calibratedSize();
508 ATH_MSG_VERBOSE(
"State succesfully creates, adding it to the trajectory");
509 finalTrajectory->insert(finalTrajectory->begin(), perState);
514 const Acts::BoundTrackParameters actsPer(acts_track.referenceSurface().getSharedPtr(),
515 acts_track.parameters(),
516 acts_track.covariance(),
517 acts_track.particleHypothesis());
518 std::unique_ptr<Trk::TrackParameters> per =
m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsPer, tgContext);
519 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
522 if (perState) finalTrajectory->insert(finalTrajectory->begin(), perState);
527 newtrack = std::make_unique<Trk::Track>(newInfo, std::move(finalTrajectory),
nullptr);