24#include <Eigen/Geometry>
37 declareInterface<IResidualPullCalculator>(
this);
57 ATH_MSG_DEBUG (
"No residual calculator for SCT given, will ignore SCT measurements!");
65 ATH_MSG_DEBUG (
"No residual calculator for RPC given, will ignore RPC measurements!");
73 ATH_MSG_DEBUG (
"No residual calculator for TGC given, will ignore TGC measurements!");
76 return StatusCode::SUCCESS;
81 return StatusCode::SUCCESS;
94 std::array<double,5>
residuals{-999.,-999.,-999.,-999.,-999};
98 measType =
helper.defineType(measurement);
131 ATH_MSG_WARNING (
"No SCT ResidualPullCalculator given, cannot calculate residual and pull for SCT measurement!");
140 ATH_MSG_WARNING (
"No RPC ResidualPullCalculator given, cannot calculate residual and pull for RPC measurement!");
149 ATH_MSG_WARNING (
"No TGC ResidualPullCalculator given, cannot calculate residual and pull for TGC measurement!");
159 for (
unsigned int i=0; i<5; ++i) {
163 - trkPar->parameters()[iPar];
181 if (!measurement || !trkPar)
return std::nullopt;
184 bool pullIsValid = trkPar->covariance();
189 measType =
helper.defineType(measurement);
192 std::vector<double> residual(dimOfLocPars);
193 std::vector<double> pull(dimOfLocPars);
195 unsigned int iColRow=0;
196 ATH_MSG_VERBOSE (
"Calculating residual for type " << measType <<
" dimension " << dimOfLocPars);
244 ATH_MSG_WARNING (
"No SCT ResidualPullCalculator given, cannot calculate residual and pull for SCT measurement!");
254 ATH_MSG_WARNING (
"No RPC ResidualPullCalculator given, cannot calculate residual and pull for RPC measurement!");
264 ATH_MSG_WARNING (
"No TGC ResidualPullCalculator given, cannot calculate residual and pull for TGC measurement!");
275 for (
unsigned int i=0; i<5; ++i) {
279 - trkPar->parameters()[iPar];
281 pull[iColRow] =
calcPull(residual[iColRow],
294 residual.resize(HEPresidual.rows());
295 pull.resize(HEPresidual.rows());
296 for (
int i = 0; i < HEPresidual.rows(); i++) {
297 residual[i] = HEPresidual[i];
301 return std::make_optional<Trk::ResidualPull>(
302 std::move(residual), std::move(pull), pullIsValid, resType,
314 const std::vector<const Trk::AlignmentEffectsOnTrack*>& aeots)
const {
321 measType =
helper.defineType(measurement);
331 std::unique_ptr<Trk::TrackParameters> trkPar = originalTrkPar->
uniqueClone();
332 parameters = trkPar->parameters();
334 ATH_MSG_VERBOSE(
" ResidualPullCalculator aeots size " << aeots.size() <<
" parameters[0] " << parameters[0] );
337 << parameters[0] <<
" trkPar->parameters()[Trk::loc1] "
339 <<
" measurement->localParameters()[Trk::loc1] "
343 localPos[0] = parameters[0];
344 localPosSimple[0] = parameters[0];
345 for (
const auto & aeot : aeots ){
346 ATH_MSG_VERBOSE(
" ResidualPullCalculator aeots deltaTranslation " << aeot->deltaTranslation() <<
" angle " << aeot->deltaAngle());
353 aeot->associatedSurface().center().x(),
355 aeot->associatedSurface().center().y(),
357 aeot->associatedSurface().center().z());
358 if (displacementVector.dot(originalTrkPar->
momentum().unit()) < 0)
359 distance = -distance;
363 double distanceX = distance*originalTrkPar->
momentum().unit().x();
364 double distanceY = distance*originalTrkPar->
momentum().unit().y();
365 const double originalPhi=originalTrkPar->
momentum().phi();
366 double distanceR = std::cos(originalPhi)*distanceX + std::sin(originalPhi)*distanceY;
368 << originalTrkPar->
position().x() <<
" y "
369 << originalTrkPar->
position().y() <<
" z "
372 << aeot->associatedSurface().center().x() <<
" y "
373 << aeot->associatedSurface().center().y() <<
" z "
374 << aeot->associatedSurface().center().z());
380 driftDirection = driftDirection.unit();
382 ATH_MSG_VERBOSE(
" sensorDirection x " << sensorDirection.x() <<
" y " << sensorDirection.y() <<
" z " << sensorDirection.z() );
383 ATH_MSG_VERBOSE(
" driftDirection x " << driftDirection.x() <<
" y " << driftDirection.y() <<
" z " << driftDirection.z() );
387 double projection = driftDirection.z();
389 const double originalTheta=originalTrkPar->
momentum().theta();
390 const double sinOriginalTheta=std::sin(originalTheta);
391 double factor = (distanceR/sinOriginalTheta)/sinOriginalTheta;
392 const Surface& surface = aeot->associatedSurface();
394 if(std::fabs(surface.
normal().z()) > 0.5) {
396 projection = (driftDirection.x()*surface.
center().x() + driftDirection.y()*surface.
center().y()) /
399 factor = -(distanceR/std::sin(originalTheta))/(std::cos(originalTheta));
400 ATH_MSG_VERBOSE(
" distance " << distance <<
" Endcap projection " << projection <<
" factor " << factor );
402 ATH_MSG_VERBOSE(
" distance " << distance <<
" Barrel projection " << projection <<
" factor " << factor );
406 localPos[0] += projection*aeot->deltaTranslation() - projection*factor*aeot->deltaAngle();
408 ATH_MSG_VERBOSE(
" MDT old localPos " << parameters[0] <<
" new localPos " << localPos[0] );
414 double projection = aeot->associatedSurface().normal().dot(originalTrkPar->
momentum().unit());
415 localPos[0] += aeot->deltaTranslation()*projection + distance*aeot->deltaAngle();
418 << parameters[0] <<
" distance " << distance
419 <<
" proj " << projection <<
" new localPos "
420 << localPos[0] <<
" simple " << localPosSimple[0]);
424 parameters[0] = localPos[0];
429 const AmgSymMatrix(5)* originalCov = trkPar->covariance();
431 trkPar->updateParameters(parameters,
AmgSymMatrix(5)( *originalCov ) );
433 trkPar->updateParameters(parameters);
437 return residualPull(measurement, trkPar.get(), resType, detType );
445 const double residual,
446 const double locMesCov,
447 const double locTrkCov,
450 double CovarianceSum = 0.0;
452 CovarianceSum = locMesCov + locTrkCov;
454 CovarianceSum = locMesCov - locTrkCov;
455 }
else CovarianceSum = locMesCov;
457 if (CovarianceSum <= 0.0) {
458 ATH_MSG_DEBUG(
"instable calculation: total covariance is non-positive, MeasCov = "<<
459 locMesCov<<
", TrkCov = "<<locTrkCov<<
", resType = "<<resType);
462 return residual/sqrt(CovarianceSum);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
#define AmgSymMatrix(dim)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Access to distance solutions.
double currentDistance(bool signedDist=false) const
Current distance to surface (spatial), signed (along/opposite to surface normal) if input argument tr...
int parameterKey() const
Identifier key for matrix expansion/reduction.
bool contains(ParamDefs par) const
The simple check for the clients whether the parameter is contained.
int dimension() const
Dimension of this localParameters() vector.
This class is the pure abstract base class for all fittable tracking measurements.
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
virtual const Surface & associatedSurface() const =0
Interface method to get the associated Surface.
const Amg::MatrixX & localCovariance() const
Interface method to get the localError.
classifies a MeasurementBase into one of the known inherited flavours or one of the detector types fo...
const Amg::Vector3D & momentum() const
Access method for the momentum.
const Amg::Vector3D & position() const
Access method for the position.
std::unique_ptr< ParametersBase< DIM, T > > uniqueClone() const
clone method for polymorphic deep copy returning unique_ptr; it is not overriden, but uses the existi...
double calcPull(const double residual, const double locMesCov, const double locTrkCov, const Trk::ResidualPull::ResidualType &resType) const
calc pull in 1 dimension
ResidualPullCalculator(const std::string &type, const std::string &name, const IInterface *parent)
constructor
virtual StatusCode initialize() override final
initialize
virtual std::array< double, 5 > residuals(const Trk::MeasurementBase *measurement, const Trk::TrackParameters *trkPar, const Trk::ResidualPull::ResidualType resType, const Trk::TrackState::MeasurementType) const override final
This function is a light-weight version of the function above, designed for track fitters where speed...
const AtlasDetectorID * m_idHelper
Used to know the sub-det from PRD->identify().
ToolHandle< IResidualPullCalculator > m_SCTresidualTool
the ResidualPullCalculator for the SCT
virtual std::optional< Trk::ResidualPull > residualPull(const Trk::MeasurementBase *measurement, const Trk::TrackParameters *trkPar, const Trk::ResidualPull::ResidualType resType, const Trk::TrackState::MeasurementType) const override final
This function returns (creates!) a Trk::ResidualPull object, which contains the values of residual an...
ToolHandle< IResidualPullCalculator > m_TGCresidualTool
the ResidualPullCalculator for the TGC
virtual StatusCode finalize() override final
ToolHandle< IResidualPullCalculator > m_RPCresidualTool
the ResidualPullCalculator for the RPC
@ Biased
RP with track state including the hit.
@ Unbiased
RP with track state that has measurement not included.
Abstract Base Class for tracking surfaces.
virtual const Amg::Vector3D & normal() const
Returns the normal vector of the Surface (i.e.
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
const Amg::Vector3D & center() const
Returns the center position of the Surface.
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
MeasurementType
enum describing the flavour of MeasurementBase
ParamDefs
This file defines the parameter enums in the Trk namespace.
@ loc2
generic first and second local coordinate
static const double helper[9]
ParametersBase< TrackParametersDim, Charged > TrackParameters
static constexpr std::array< ParamDefs, 6 > pardef
Constructor.