ATLAS Offline Software
KalmanFitterTool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ACTSTRACKRECONSTRUCTION_KALMANFITTERTOOL_H
6 #define ACTSTRACKRECONSTRUCTION_KALMANFITTERTOOL_H
7 
9 
10 #include "GaudiKernel/ToolHandle.h"
11 
12 
15 
20 
21 
23 #include "GaudiKernel/ToolHandle.h"
24 #include "GaudiKernel/EventContext.h"
25 
26 // ACTS
27 #include "Acts/EventData/TrackParameters.hpp"
28 #include "Acts/TrackFitting/KalmanFitter.hpp"
29 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
30 #include "Acts/Propagator/SympyStepper.hpp"
31 #include "Acts/Propagator/Propagator.hpp"
32 #include "Acts/Propagator/Navigator.hpp"
33 #include "Acts/EventData/TrackProxy.hpp"
34 #include "Acts/EventData/VectorTrackContainer.hpp"
35 #include "Acts/Geometry/GeometryIdentifier.hpp"
36 
37 
38 // PACKAGE
39 
44 
46 
47 // STL
48 #include <string>
49 #include <memory>//unique_ptr
50 #include <limits>//for numeric_limits
51 #include <cmath> //std::abs
52 
53 
55 
56 class EventContext;
57 
58 namespace Trk{
59  class Track;
60  class PrepRawData;
61 }
62 
63 namespace ActsTrk {
64 
66  const Trk::PrepRawData* prd {nullptr};
67 };
68 
70  template <typename trajectory_t>
71  void calibrate(const Acts::GeometryContext& gctx,
72  const Acts::CalibrationContext& cctx,
73  const Acts::SourceLink& sl,
74  typename trajectory_t::TrackStateProxy trackState) const;
75 
79 };
80 
83 
84  const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const;
85 };
86 
88  : public extends<AthAlgTool, Trk::ITrackFitter, ActsTrk::IFitterTool> {
89 public:
90 
91  KalmanFitterTool(const std::string&,const std::string&,const IInterface*);
92  virtual ~KalmanFitterTool() = default;
93 
94  // standard Athena methods
95  virtual StatusCode initialize() override;
96 
98  virtual std::unique_ptr<Trk::Track> fit(
99  const EventContext& ctx,
100  const Trk::Track&,
101  const Trk::RunOutlierRemoval runOutlier = false,
102  const Trk::ParticleHypothesis matEffects = Trk::nonInteracting) const override;
103 
105  virtual std::unique_ptr<Trk::Track> fit(
106  const EventContext& ctx,
107  const Trk::PrepRawDataSet&,
108  const Trk::TrackParameters&,
109  const Trk::RunOutlierRemoval runOutlier = false,
110  const Trk::ParticleHypothesis matEffects = Trk::nonInteracting) const override;
111 
113  virtual std::unique_ptr<Trk::Track> fit(
114  const EventContext& ctx,
115  const Trk::MeasurementSet&,
116  const Trk::TrackParameters&,
117  const Trk::RunOutlierRemoval runOutlier = false,
118  const Trk::ParticleHypothesis matEffects = Trk::nonInteracting) const override;
119 
121  virtual std::unique_ptr<Trk::Track> fit(
122  const EventContext& ctx,
123  const Trk::Track&,
124  const Trk::PrepRawDataSet&,
125  const Trk::RunOutlierRemoval runOutlier = false,
126  const Trk::ParticleHypothesis matEffects = Trk::nonInteracting) const override;
127 
129  virtual
130  std::unique_ptr< ActsTrk::MutableTrackContainer >
131  fit(const EventContext& ctx,
132  const std::vector<ActsTrk::ATLASUncalibSourceLink> & clusterList,
133  const Acts::BoundTrackParameters& initialParams,
134  const Acts::GeometryContext& tgContext,
135  const Acts::MagneticFieldContext& mfContext,
136  const Acts::CalibrationContext& calContext,
137  const DetectorElementToActsGeometryIdMap &detectorElementToGeometryIdMap,
138  const Acts::Surface* targetSurface = nullptr // optional target surface - defaults to perigee in global origin
139  ) const override;
140 
142  virtual std::unique_ptr<Trk::Track> fit(
143  const EventContext& ctx,
144  const Trk::Track&,
145  const Trk::MeasurementSet&,
146  const Trk::RunOutlierRemoval runOutlier = false,
147  const Trk::ParticleHypothesis matEffects = Trk::nonInteracting) const override;
148 
150  virtual std::unique_ptr<Trk::Track> fit(
151  const EventContext& ctx,
152  const Trk::Track& intrk1,
153  const Trk::Track& intrk2,
154  const Trk::RunOutlierRemoval runOutlier = false,
155  const Trk::ParticleHypothesis matEffects = Trk::nonInteracting) const override;
156 
158  virtual
159  std::unique_ptr< ActsTrk::MutableTrackContainer >
160  fit(const EventContext& ctx,
161  const ActsTrk::Seed &seed,
162  const Acts::BoundTrackParameters& initialParams,
163  const Acts::GeometryContext& tgContext,
164  const Acts::MagneticFieldContext& mfContext,
165  const Acts::CalibrationContext& calContext,
166  const DetectorElementToActsGeometryIdMap &detectorElementToGeometryIdMap) const override;
167 
169  // Private methods:
171 private:
172 
173  // Create a track from the fitter result
174  std::unique_ptr<Trk::Track> makeTrack(const EventContext& ctx,
175  Acts::GeometryContext& tgContext,
177  Acts::Result<ActsTrk::MutableTrackContainer::TrackProxy, std::error_code>& fitResult, bool SourceLinkType = false) const;
178  //parameter (bool) SourceLinkType to distinguish between ATLASSourceLink and PRDSourceLink implementation.
179  //bool SourceLinkType = false for ATLASSourceLink
180  //bool SourceLinkType = true for PRDSourceLink
181 
182  ToolHandle<IActsExtrapolationTool> m_extrapolationTool{this, "ExtrapolationTool", ""};
183  ToolHandle<IActsTrackingGeometryTool> m_trackingGeometryTool{this, "TrackingGeometryTool", ""};
184  ToolHandle<ActsTrk::IActsToTrkConverterTool> m_ATLASConverterTool{this, "ATLASConverterTool", ""};
185  ToolHandle<Trk::IExtendedTrackSummaryTool> m_trkSummaryTool {this, "SummaryTool", "", "ToolHandle for track summary tool"};
186  ToolHandle<Trk::IBoundaryCheckTool> m_boundaryCheckTool {this,
187  "BoundaryCheckTool",
188  "",
189  "Boundary checking tool for detector sensitivities"};
190  // the settable job options
191  Gaudi::Property< double > m_option_outlierChi2Cut {this, "OutlierChi2Cut", 12.5,
192  "Chi2 cut used by the outlier finder" };
193  Gaudi::Property< double > m_option_ReverseFilteringPt {this, "ReverseFilteringPt", 1.0 * Acts::UnitConstants::GeV,
194  "Pt cut used for the ReverseFiltering logic"};
195  Gaudi::Property< int > m_option_maxPropagationStep {this, "MaxPropagationStep", 5000,
196  "Maximum number of steps for one propagate call"};
197  Gaudi::Property< double > m_option_seedCovarianceScale {this, "SeedCovarianceScale", 100.,
198  "Scale factor for the input seed covariance when doing refitting"};
199 
200  std::unique_ptr<ActsTrk::detail::TrkMeasurementCalibrator> m_calibrator {nullptr};
201 
203  using Fitter = Acts::KalmanFitter<Acts::Propagator<Acts::SympyStepper, Acts::Navigator>, ActsTrk::MutableTrackStateBackend>;
204  std::unique_ptr<Fitter> m_fitter {nullptr};
205 
206  using DirectFitter = Acts::KalmanFitter<Acts::Propagator<Acts::SympyStepper, Acts::DirectNavigator>, ActsTrk::MutableTrackStateBackend>;
207  std::unique_ptr<DirectFitter> m_directFitter {nullptr};
208 
209  Acts::KalmanFitterExtensions<ActsTrk::MutableTrackStateBackend> m_kfExtensions;
210 
213 
215  const Acts::Logger& logger() const {
216  return *m_logger;
217  }
218 
220  std::unique_ptr<const Acts::Logger> m_logger;
221 
222  ToolHandle<Trk::IRIO_OnTrackCreator> m_broadROTcreator {this, "BroadRotCreatorTool", ""};
223  ToolHandle<Trk::IRIO_OnTrackCreator> m_ROTcreator {this, "RotCreatorTool", ""};
224  //Gaudi Property to choose from PRD or ROT measurment ReFit
225  Gaudi::Property<bool> m_doReFitFromPRD{this, "DoReFitFromPRD", false, "Do Refit From PRD instead of ROT"};
226 }; // end of namespace
227 
228 }
229 #endif
230 
ActsTrk::PRDSourceLinkSurfaceAccessor::converterTool
const ActsTrk::IActsToTrkConverterTool * converterTool
Definition: KalmanFitterTool.h:82
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
Trk::PrepRawDataSet
std::vector< const PrepRawData * > PrepRawDataSet
vector of clusters and drift circles
Definition: FitterTypes.h:26
ActsTrk::KalmanFitterTool::m_option_maxPropagationStep
Gaudi::Property< int > m_option_maxPropagationStep
Definition: KalmanFitterTool.h:195
ActsTrk::KalmanFitterTool::logger
const Acts::Logger & logger() const
Private access to the logger.
Definition: KalmanFitterTool.h:215
ActsTrk::DetectorElementToActsGeometryIdMap
Definition: DetectorElementToActsGeometryIdMap.h:31
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
ActsTrk::PRDSourceLinkCalibrator::rotCreator
const Trk::IRIO_OnTrackCreator * rotCreator
Definition: KalmanFitterTool.h:76
ActsTrk::KalmanFitterTool::KalmanFitterTool
KalmanFitterTool(const std::string &, const std::string &, const IInterface *)
Definition: KalmanFitterTool.cxx:169
ActsTrk::KalmanFitterTool::Fitter
Acts::KalmanFitter< Acts::Propagator< Acts::SympyStepper, Acts::Navigator >, ActsTrk::MutableTrackStateBackend > Fitter
Type erased track fitter function.
Definition: KalmanFitterTool.h:203
ActsTrk::PRDSourceLinkCalibrator::converterTool
const ActsTrk::IActsToTrkConverterTool * converterTool
Definition: KalmanFitterTool.h:78
ActsTrk::KalmanFitterTool::m_fitter
std::unique_ptr< Fitter > m_fitter
Definition: KalmanFitterTool.h:204
IRIO_OnTrackCreator.h
ActsTrk::KalmanFitterTool::m_ROTcreator
ToolHandle< Trk::IRIO_OnTrackCreator > m_ROTcreator
Definition: KalmanFitterTool.h:223
ActsTrk::PRDSourceLinkCalibrator::broadRotCreator
const Trk::IRIO_OnTrackCreator * broadRotCreator
Definition: KalmanFitterTool.h:77
ActsTrk::KalmanFitterTool::initialize
virtual StatusCode initialize() override
Definition: KalmanFitterTool.cxx:175
ActsTrk::detail::FitterHelperFunctions::ATLASOutlierFinder
Outlier finder using a Chi2 cut.
Definition: FitterHelperFunctions.h:49
PdgToParticleHypothesis.h
PrepRawData.h
ActsTrk::KalmanFitterTool::DirectFitter
Acts::KalmanFitter< Acts::Propagator< Acts::SympyStepper, Acts::DirectNavigator >, ActsTrk::MutableTrackStateBackend > DirectFitter
Definition: KalmanFitterTool.h:206
Trk::RunOutlierRemoval
bool RunOutlierRemoval
switch to toggle quality processing after fit
Definition: FitterTypes.h:22
ActsTrk::KalmanFitterTool::m_directFitter
std::unique_ptr< DirectFitter > m_directFitter
Definition: KalmanFitterTool.h:207
ActsTrk::KalmanFitterTool::fit
virtual std::unique_ptr< Trk::Track > fit(const EventContext &ctx, const Trk::Track &, const Trk::RunOutlierRemoval runOutlier=false, const Trk::ParticleHypothesis matEffects=Trk::nonInteracting) const override
refit a track
Definition: KalmanFitterTool.cxx:228
ActsTrk::KalmanFitterTool::m_outlierFinder
ActsTrk::detail::FitterHelperFunctions::ATLASOutlierFinder m_outlierFinder
Definition: KalmanFitterTool.h:211
Trk::ParticleHypothesis
ParticleHypothesis
Definition: ParticleHypothesis.h:25
ActsTrk::MutableMultiTrajectory
Athena implementation of ACTS::MultiTrajectory (ReadWrite version) The data is stored in 4 external b...
Definition: MultiTrajectory.h:81
ActsTrk::KalmanFitterTool::m_extrapolationTool
ToolHandle< IActsExtrapolationTool > m_extrapolationTool
Definition: KalmanFitterTool.h:182
ActsTrk::KalmanFitterTool::m_trkSummaryTool
ToolHandle< Trk::IExtendedTrackSummaryTool > m_trkSummaryTool
Definition: KalmanFitterTool.h:185
ActsTrk::KalmanFitterTool::m_logger
std::unique_ptr< const Acts::Logger > m_logger
logging instance
Definition: KalmanFitterTool.h:220
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ActsTrk::KalmanFitterTool::m_calibrator
std::unique_ptr< ActsTrk::detail::TrkMeasurementCalibrator > m_calibrator
Definition: KalmanFitterTool.h:200
ActsTrk::KalmanFitterTool::m_option_outlierChi2Cut
Gaudi::Property< double > m_option_outlierChi2Cut
Definition: KalmanFitterTool.h:191
ActsTrk::IActsToTrkConverterTool
Definition: IActsToTrkConverterTool.h:43
AthAlgTool.h
ActsTrk::KalmanFitterTool::m_option_seedCovarianceScale
Gaudi::Property< double > m_option_seedCovarianceScale
Definition: KalmanFitterTool.h:197
ActsTrk::Seed
Acts::Seed< xAOD::SpacePoint, 3ul > Seed
Definition: Seed.h:12
ActsTrk::KalmanFitterTool::makeTrack
std::unique_ptr< Trk::Track > makeTrack(const EventContext &ctx, Acts::GeometryContext &tgContext, ActsTrk::MutableTrackContainer &tracks, Acts::Result< ActsTrk::MutableTrackContainer::TrackProxy, std::error_code > &fitResult, bool SourceLinkType=false) const
Definition: KalmanFitterTool.cxx:696
ActsTrk::PRDSourceLinkCalibrator
Definition: KalmanFitterTool.h:69
Trk::ParametersBase
Definition: ParametersBase.h:55
ActsTrk::KalmanFitterTool::m_ATLASConverterTool
ToolHandle< ActsTrk::IActsToTrkConverterTool > m_ATLASConverterTool
Definition: KalmanFitterTool.h:184
ActsTrk::KalmanFitterTool::m_doReFitFromPRD
Gaudi::Property< bool > m_doReFitFromPRD
Definition: KalmanFitterTool.h:225
ActsTrk::KalmanFitterTool::m_kfExtensions
Acts::KalmanFitterExtensions< ActsTrk::MutableTrackStateBackend > m_kfExtensions
Definition: KalmanFitterTool.h:209
ActsTrk::KalmanFitterTool::m_broadROTcreator
ToolHandle< Trk::IRIO_OnTrackCreator > m_broadROTcreator
Definition: KalmanFitterTool.h:222
Trk::MeasurementSet
std::vector< const MeasurementBase * > MeasurementSet
vector of fittable measurements
Definition: FitterTypes.h:30
Trk::PrepRawData
Definition: PrepRawData.h:62
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::nonInteracting
@ nonInteracting
Definition: ParticleHypothesis.h:25
IFitterTool.h
ActsTrk::KalmanFitterTool::m_reverseFilteringLogic
ActsTrk::detail::FitterHelperFunctions::ReverseFilteringLogic m_reverseFilteringLogic
Definition: KalmanFitterTool.h:212
ActsTrk::detail::FitterHelperFunctions::ReverseFilteringLogic
Determine if the smoothing of a track should be done with or without reverse filtering.
Definition: FitterHelperFunctions.h:89
FitterHelperFunctions.h
ActsTrk::KalmanFitterTool::m_boundaryCheckTool
ToolHandle< Trk::IBoundaryCheckTool > m_boundaryCheckTool
Definition: KalmanFitterTool.h:186
IExtendedTrackSummaryTool.h
ActsTrk::PRDSourceLinkCalibrator::calibrate
void calibrate(const Acts::GeometryContext &gctx, const Acts::CalibrationContext &cctx, const Acts::SourceLink &sl, typename trajectory_t::TrackStateProxy trackState) const
Definition: KalmanFitterTool.cxx:61
ActsTrk::KalmanFitterTool
Definition: KalmanFitterTool.h:88
ActsTrk::PRDSourceLinkSurfaceAccessor::operator()
const Acts::Surface * operator()(const Acts::SourceLink &sourceLink) const
Definition: KalmanFitterTool.cxx:162
IBoundaryCheckTool.h
TrkMeasurementCalibrator.h
ActsTrk::PRDSourceLinkSurfaceAccessor
Definition: KalmanFitterTool.h:81
IActsToTrkConverterTool.h
ActsTrk::KalmanFitterTool::m_trackingGeometryTool
ToolHandle< IActsTrackingGeometryTool > m_trackingGeometryTool
Definition: KalmanFitterTool.h:183
Track
Definition: TriggerChamberClusterOnTrackCreator.h:21
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:54
ActsTrk::KalmanFitterTool::~KalmanFitterTool
virtual ~KalmanFitterTool()=default
ActsTrk::KalmanFitterTool::m_option_ReverseFilteringPt
Gaudi::Property< double > m_option_ReverseFilteringPt
Definition: KalmanFitterTool.h:193
Trk::IRIO_OnTrackCreator
Interface class for transforming Trk::PrepRawData to Trk::RIO_OnTrack using a local track hypothesis.
Definition: IRIO_OnTrackCreator.h:33
ActsTrk::MutableTrackContainer
Definition: TrackContainer.h:122
ITrackFitter.h
TrackContainer.h
IActsTrackingGeometryTool.h
IActsExtrapolationTool.h