ATLAS Offline Software
MdtSegmentFitter.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef MUONPATTERNHELPERS_MDTSEGMENTFITTER_H
5 #define MUONPATTERNHELPERS_MDTSEGMENTFITTER_H
6 
8 
14 #include <GaudiKernel/SystemOfUnits.h>
15 
16 
17 namespace MuonR4{
18  class ISpacePointCalibrator;
20  public:
23  using HitType = std::unique_ptr<CalibratedSpacePoint>;
24  using HitVec = std::vector<HitType>;
25 
26  struct Config{
28  unsigned int nMaxCalls{100};
30  double tolerance{1.e-7};
32  bool doTimeFit{true};
34  bool reCalibrate{false};
36  bool useSecOrderDeriv{false};
38  unsigned int nParsOutOfBounds{1};
42  unsigned int noMoveIter{2};
44  using RangeArray = std::array<std::array<double,2>, SegmentFit::toInt(ParamDefs::nPars)>;
46  static RangeArray defaultRanges();
47 
49 
50  };
56  static constexpr unsigned nPars{4};
62  std::array<Amg::Vector3D, nPars> gradient{make_array<Amg::Vector3D, nPars>(Amg::Vector3D::Zero())};
64  std::array<Amg::Vector3D, sumUp(nPars)> hessian{make_array<Amg::Vector3D, sumUp(nPars)>(Amg::Vector3D::Zero())};
65  };
69  static constexpr unsigned nPars{toInt(ParamDefs::nPars)};
71  bool evalPhiPars{true};
75  std::array<Amg::Vector3D, nPars> gradient{make_array<Amg::Vector3D, nPars>(Amg::Vector3D::Zero())};
77  std::array<Amg::Vector3D, sumUp(nPars)> hessian{make_array<Amg::Vector3D, sumUp(nPars)>(Amg::Vector3D::Zero())};
78  };
79 
83  MdtSegmentFitter(const std::string& name,
84  Config&& config);
85 
86  SegmentFitResult fitSegment(const EventContext& ctx,
87  HitVec&& calibHits,
88  const Parameters& startPars,
89  const Amg::Transform3D& localToGlobal) const;
90  private:
100  bool recalibrate(const EventContext& ctx,
101  SegmentFitResult& fitResult) const;
104  bool updateHitSummary(SegmentFitResult& fitResult) const;
105  public:
110  static void updateLinePartials(const Parameters& fitPars,
111  LineWithPartials& line);
118  void calculateWireResiduals(const LineWithPartials& line,
119  const CalibratedSpacePoint& spacePoint,
120  ResidualWithPartials& residual) const;
128  void calculateStripResiduals(const LineWithPartials& line,
129  const CalibratedSpacePoint& spacePoint,
130  ResidualWithPartials& residual) const;
131 
139  const double offset,
140  const LineWithPartials& line,
141  const ParamDefs fitPar);
142  private:
144  void updateDriftSigns(const Amg::Vector3D& segPos, const Amg::Vector3D& segDir,
145  SegmentFitResult& fitRes)const;
155  void updateDerivatives(const ResidualWithPartials& fitMeas,
156  const MeasCov_t& measCovariance,
157  AmgVector(5)& gradient,
158  AmgSymMatrix(5)& hessian,
159  double& chi2,
160  int startPar) const;
161 
162 
163  enum class UpdateStatus{
164  allOkay = 0,
165  outOfBounds = 1,
166  noChange = 2,
167  };
178  template <unsigned int nDim>
180  Parameters& previousPars,
181  Parameters& currGrad,
182  Parameters& prevGrad,
183  const AmgSymMatrix(5)& hessian) const;
184 
185  template <unsigned int nDim>
186  void blockCovariance(const AmgSymMatrix(5)& hessian,
187  SegmentFit::Covariance& covariance) const;
188 
189 
190  };
191 }
192 
193 
194 #endif
MuonR4::MdtSegmentFitter::ResidualWithPartials::residual
Amg::Vector3D residual
Vector carrying the residual.
Definition: MdtSegmentFitter.h:73
MuonR4::MdtSegmentFitter::updateDriftSigns
void updateDriftSigns(const Amg::Vector3D &segPos, const Amg::Vector3D &segDir, SegmentFitResult &fitRes) const
Update the signs of the measurement.
Definition: MdtSegmentFitter.cxx:55
MuonR4::MdtSegmentFitter
Definition: MdtSegmentFitter.h:19
MuonR4::SegmentFit::ParamDefs
ParamDefs
This file defines the parameter enums in the Trk namespace.
Definition: MuonHoughDefs.h:29
checkFileSG.line
line
Definition: checkFileSG.py:75
MuonR4::MdtSegmentFitter::blockCovariance
void blockCovariance(const AmgSymMatrix(5)&hessian, SegmentFit::Covariance &covariance) const
Definition: MdtSegmentFitter.cxx:638
MuonR4::MdtSegmentFitter::updateHitSummary
bool updateHitSummary(SegmentFitResult &fitResult) const
Brief updates the hit summary from the contributing hits.
Definition: MdtSegmentFitter.cxx:90
MuonR4::MdtSegmentFitter::calculateStripResiduals
void calculateStripResiduals(const LineWithPartials &line, const CalibratedSpacePoint &spacePoint, ResidualWithPartials &residual) const
Calculates the residual together with hte correspdonding derivatives for strip measurements.
Definition: MdtSegmentFitter.cxx:320
MuonR4::MdtSegmentFitter::LineWithPartials::nPars
static constexpr unsigned nPars
Free parameters of the line (x0,y0,theta,phi)
Definition: MdtSegmentFitter.h:56
MuonR4::SegmentFit::Parameters
AmgVector(toInt(ParamDefs::nPars)) Parameters
Definition: MuonHoughDefs.h:48
MuonR4::MdtSegmentFitter::ResidualWithPartials
Helper struct carrying the residual with its derivatives.
Definition: MdtSegmentFitter.h:67
MuonR4::MdtSegmentFitter::UpdateStatus
UpdateStatus
Definition: MdtSegmentFitter.h:163
ClusterSeg::residual
@ residual
Definition: ClusterNtuple.h:20
MuonR4::MdtSegmentFitter::Parameters
SegmentFit::Parameters Parameters
Definition: MdtSegmentFitter.h:22
SegmentSeed.h
MuonR4::MdtSegmentFitter::UpdateStatus::outOfBounds
@ outOfBounds
MuonR4::MdtSegmentFitter::LineWithPartials::dir
Amg::Vector3D dir
Segment direction
Definition: MdtSegmentFitter.h:60
MuonR4::HitVec
SpacePointPerLayerSorter::HitVec HitVec
Definition: SpacePointPerLayerSorter.cxx:9
MuonR4::MdtSegmentFitter::LineWithPartials::gradient
std::array< Amg::Vector3D, nPars > gradient
First order derivatives.
Definition: MdtSegmentFitter.h:62
MuonR4::MdtSegmentFitter::Config::noMoveIter
unsigned int noMoveIter
How many iterations with changes below tolerance.
Definition: MdtSegmentFitter.h:42
MatrixUtils.h
MuonR4::MdtSegmentFitter::fitSegment
SegmentFitResult fitSegment(const EventContext &ctx, HitVec &&calibHits, const Parameters &startPars, const Amg::Transform3D &localToGlobal) const
Definition: MdtSegmentFitter.cxx:389
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
MuonR4::MdtSegmentFitter::Config::calibrator
const ISpacePointCalibrator * calibrator
Pointer to the calibrator tool.
Definition: MdtSegmentFitter.h:40
MuonR4::MdtSegmentFitter::ResidualWithPartials::gradient
std::array< Amg::Vector3D, nPars > gradient
First order derivatives.
Definition: MdtSegmentFitter.h:75
CalibratedSpacePoint.h
MuonR4::MdtSegmentFitter::Config::ranges
RangeArray ranges
Definition: MdtSegmentFitter.h:48
GeoPrimitives.h
MuonR4::sumUp
constexpr unsigned int sumUp(unsigned k)
Calculates the sum of 1 + 2 +3 +4 +...
Definition: MatrixUtils.h:15
MuonR4::MdtSegmentFitter::ResidualWithPartials::evalPhiPars
bool evalPhiPars
Flag whether the the residuals w.r.t phi shall be evaluated.
Definition: MdtSegmentFitter.h:71
MuonR4::MdtSegmentFitter::UpdateStatus::noChange
@ noChange
MuonR4::MdtSegmentFitter::ResidualWithPartials::nPars
static constexpr unsigned nPars
Number of parameters.
Definition: MdtSegmentFitter.h:69
MuonR4::MdtSegmentFitter::MeasCov_t
CalibratedSpacePoint::Covariance_t MeasCov_t
Updates the chi2, its Gradient & Hessian from the measurement residual.
Definition: MdtSegmentFitter.h:154
AmgVector
AmgVector(4) T2BSTrackFilterTool
Definition: T2BSTrackFilterTool.cxx:114
MuonR4::MdtSegmentFitter::LineWithPartials::hessian
std::array< Amg::Vector3D, sumUp(nPars)> hessian
Second order derivatives.
Definition: MdtSegmentFitter.h:64
MuonR4::MdtSegmentFitter::HitType
std::unique_ptr< CalibratedSpacePoint > HitType
Definition: MdtSegmentFitter.h:23
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:523
MuonR4::MdtSegmentFitter::Config
Definition: MdtSegmentFitter.h:26
MuonR4::MdtSegmentFitter::Config::useSecOrderDeriv
bool useSecOrderDeriv
Switch toggling whether the second order derivative shall be included.
Definition: MdtSegmentFitter.h:36
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
MuonR4::MdtSegmentFitter::Config::nParsOutOfBounds
unsigned int nParsOutOfBounds
Abort the fit as soon as more than n parameters leave the fit range.
Definition: MdtSegmentFitter.h:38
MuonR4::MdtSegmentFitter::calculateWireResiduals
void calculateWireResiduals(const LineWithPartials &line, const CalibratedSpacePoint &spacePoint, ResidualWithPartials &residual) const
Calculates the residuals together with the corresponding derivatives for a drift-circle measurement.
Definition: MdtSegmentFitter.cxx:184
Config
Definition: dumpNPs.cxx:47
MuonR4::MdtSegmentFitter::updateDerivatives
void updateDerivatives(const ResidualWithPartials &fitMeas, const MeasCov_t &measCovariance, AmgVector(5)&gradient, AmgSymMatrix(5)&hessian, double &chi2, int startPar) const
Definition: MdtSegmentFitter.cxx:616
lumiFormat.array
array
Definition: lumiFormat.py:91
tolerance
Definition: suep_shower.h:17
MuonR4::MdtSegmentFitter::m_cfg
Config m_cfg
Definition: MdtSegmentFitter.h:91
MuonR4::MdtSegmentFitter::MdtSegmentFitter
MdtSegmentFitter(const std::string &name, Config &&config)
Standard constructor.
Definition: MdtSegmentFitter.cxx:51
MuonR4::MdtSegmentFitter::Config::nMaxCalls
unsigned int nMaxCalls
How many calls shall be executed.
Definition: MdtSegmentFitter.h:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MuonR4::SegmentFit::toInt
constexpr int toInt(const ParamDefs p)
Definition: MuonHoughDefs.h:42
MuonR4::MdtSegmentFitter::Config::reCalibrate
bool reCalibrate
Switch toggling whether the calibrator shall be called at each iteration.
Definition: MdtSegmentFitter.h:34
MuonR4::MdtSegmentFitter::UpdateStatus::allOkay
@ allOkay
MuonR4::ISpacePointCalibrator
Interface class to refine the space point calibration with an external seed.
Definition: ISpacePointCalibrator.h:19
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonR4::MdtSegmentFitter::LineWithPartials
Store the partial derivative of the line w.r.t.
Definition: MdtSegmentFitter.h:54
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
MuonR4::MdtSegmentFitter::Config::RangeArray
std::array< std::array< double, 2 >, SegmentFit::toInt(ParamDefs::nPars)> RangeArray
Allowed parameter ranges.
Definition: MdtSegmentFitter.h:44
MuonR4::SegmentFit::Covariance
AmgSymMatrix(toInt(ParamDefs::nPars)) Covariance
Definition: MuonHoughDefs.h:49
SegmentFitterEventData.h
MuonR4::MdtSegmentFitter::Config::doTimeFit
bool doTimeFit
Switch toggling whether the T0 shall be fitted or not.
Definition: MdtSegmentFitter.h:32
MuonR4::MdtSegmentFitter::HitVec
std::vector< HitType > HitVec
Definition: MdtSegmentFitter.h:24
MuonR4::CalibratedSpacePoint
The calibrated Space point is created during the calibration process.
Definition: CalibratedSpacePoint.h:15
AthMessaging.h
MuonR4::MdtSegmentFitter::LineWithPartials::pos
Amg::Vector3D pos
segment position
Definition: MdtSegmentFitter.h:58
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
MuonR4::SegmentFitResult
Definition: SegmentFitterEventData.h:46
MuonR4::MdtSegmentFitter::partialPlaneIntersect
static Amg::Vector3D partialPlaneIntersect(const Amg::Vector3D &normal, const double offset, const LineWithPartials &line, const ParamDefs fitPar)
Calculates the partial derivative of the intersection point between the segment line and the measurem...
Definition: MdtSegmentFitter.cxx:120
MuonR4::MdtSegmentFitter::Config::defaultRanges
static RangeArray defaultRanges()
Function that returns a set of predefined ranges for testing.
Definition: MdtSegmentFitter.cxx:40
MuonR4::AmgSymMatrix
const AmgSymMatrix(2) &SpacePoint
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/SpacePoint.cxx:150
MuonR4::MdtSegmentFitter::recalibrate
bool recalibrate(const EventContext &ctx, SegmentFitResult &fitResult) const
Recalibrate the measurements participating in the fit & shift them into the centre-of gravity frame.
Definition: MdtSegmentFitter.cxx:62
MuonR4::MdtSegmentFitter::updateParameters
UpdateStatus updateParameters(Parameters &currentPars, Parameters &previousPars, Parameters &currGrad, Parameters &prevGrad, const AmgSymMatrix(5)&hessian) const
Update step of the segment parameters using the Hessian and the gradient.
Definition: MdtSegmentFitter.cxx:654
MuonR4::MdtSegmentFitter::ResidualWithPartials::hessian
std::array< Amg::Vector3D, sumUp(nPars)> hessian
Second order derivatives.
Definition: MdtSegmentFitter.h:77
MuonR4::SegmentFit::ParamDefs::nPars
@ nPars
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
MuonR4::CalibratedSpacePoint::Covariance_t
std::variant< AmgSymMatrix(2), AmgSymMatrix(3)> Covariance_t
The spatial covariance matrix of the calibrated space point.
Definition: CalibratedSpacePoint.h:49
MuonR4::MdtSegmentFitter::updateLinePartials
static void updateLinePartials(const Parameters &fitPars, LineWithPartials &line)
Updates the line parameters together with its first & second order partial derivatives.
Definition: MdtSegmentFitter.cxx:142