24 #include <Eigen/Geometry>
33 m_SCTresidualTool(
"InDet::SCT_ResidualPullCalculator/SCT_ResidualPullCalculator"),
34 m_RPCresidualTool(
"Muon::RPC_ResidualPullCalculator/RPC_ResidualPullCalculator"),
35 m_TGCresidualTool(
"Muon::TGC_ResidualPullCalculator/TGC_ResidualPullCalculator"),
37 declareInterface<IResidualPullCalculator>(
this);
54 if ( ! m_SCTresidualTool.empty() ) {
57 ATH_MSG_DEBUG (
"No residual calculator for SCT given, will ignore SCT measurements!");
62 if ( ! m_RPCresidualTool.empty() ) {
65 ATH_MSG_DEBUG (
"No residual calculator for RPC given, will ignore RPC measurements!");
70 if ( ! m_TGCresidualTool.empty() ) {
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);
127 if ( ! m_SCTresidualTool.empty() ) {
131 ATH_MSG_WARNING (
"No SCT ResidualPullCalculator given, cannot calculate residual and pull for SCT measurement!");
136 if ( ! m_RPCresidualTool.empty() ) {
140 ATH_MSG_WARNING (
"No RPC ResidualPullCalculator given, cannot calculate residual and pull for RPC measurement!");
145 if ( ! m_TGCresidualTool.empty() ) {
149 ATH_MSG_WARNING (
"No TGC ResidualPullCalculator given, cannot calculate residual and pull for TGC measurement!");
161 for (
unsigned int i=0;
i<5; ++
i) {
165 - trkPar->parameters()[iPar];
183 if (!measurement || !trkPar)
return std::nullopt;
186 bool pullIsValid = trkPar->covariance();
191 measType = helper.defineType(measurement);
194 std::vector<double>
residual(dimOfLocPars);
195 std::vector<double>
pull(dimOfLocPars);
199 unsigned int iColRow=0;
201 ATH_MSG_VERBOSE (
"Calculating residual for type " << measType <<
" dimension " << dimOfLocPars);
245 if ( ! m_SCTresidualTool.empty() ) {
249 ATH_MSG_WARNING (
"No SCT ResidualPullCalculator given, cannot calculate residual and pull for SCT measurement!");
255 if ( ! m_RPCresidualTool.empty() ) {
259 ATH_MSG_WARNING (
"No RPC ResidualPullCalculator given, cannot calculate residual and pull for RPC measurement!");
265 if ( ! m_TGCresidualTool.empty() ) {
269 ATH_MSG_WARNING (
"No TGC ResidualPullCalculator given, cannot calculate residual and pull for TGC measurement!");
280 for (
unsigned int i=0;
i<5; ++
i) {
284 - trkPar->parameters()[iPar];
288 (*trkPar->covariance())(PDA.
pardef[iColRow],PDA.
pardef[iColRow]),
299 residual.resize(HEPresidual.rows());
300 pull.resize(HEPresidual.rows());
301 for (
int i = 0;
i < HEPresidual.rows();
i++) {
306 return std::make_optional<Trk::ResidualPull>(
307 std::move(
residual), std::move(
pull), pullIsValid, resType,
319 const std::vector<const Trk::AlignmentEffectsOnTrack*>& aeots)
const {
326 measType = helper.defineType(measurement);
336 std::unique_ptr<Trk::TrackParameters> trkPar = originalTrkPar->
uniqueClone();
342 <<
parameters[0] <<
" trkPar->parameters()[Trk::loc1] "
344 <<
" measurement->localParameters()[Trk::loc1] "
350 for (
const auto & aeot : aeots ){
351 ATH_MSG_VERBOSE(
" ResidualPullCalculator aeots deltaTranslation " << aeot->deltaTranslation() <<
" angle " << aeot->deltaAngle());
358 aeot->associatedSurface().center().x(),
360 aeot->associatedSurface().center().y(),
362 aeot->associatedSurface().center().z());
363 if (displacementVector.dot(originalTrkPar->
momentum().unit()) < 0)
370 const double originalPhi=originalTrkPar->
momentum().phi();
371 double distanceR =
std::cos(originalPhi)*distanceX +
std::sin(originalPhi)*distanceY;
373 << originalTrkPar->
position().x() <<
" y "
374 << originalTrkPar->
position().y() <<
" z "
377 << aeot->associatedSurface().center().x() <<
" y "
378 << aeot->associatedSurface().center().y() <<
" z "
379 << aeot->associatedSurface().center().z());
385 driftDirection = driftDirection.unit();
387 ATH_MSG_VERBOSE(
" sensorDirection x " << sensorDirection.x() <<
" y " << sensorDirection.y() <<
" z " << sensorDirection.z() );
388 ATH_MSG_VERBOSE(
" driftDirection x " << driftDirection.x() <<
" y " << driftDirection.y() <<
" z " << driftDirection.z() );
392 double projection = driftDirection.z();
394 const double originalTheta=originalTrkPar->
momentum().theta();
395 const double sinOriginalTheta=
std::sin(originalTheta);
396 double factor = (distanceR/sinOriginalTheta)/sinOriginalTheta;
397 const Surface& surface = aeot->associatedSurface();
399 if(std::fabs(surface.
normal().z()) > 0.5) {
401 projection = (driftDirection.x()*surface.
center().x() + driftDirection.y()*surface.
center().y()) /
411 localPos[0] += projection*aeot->deltaTranslation() - projection*factor*aeot->deltaAngle();
419 double projection = aeot->associatedSurface().normal().dot(originalTrkPar->
momentum().unit());
420 localPos[0] += aeot->deltaTranslation()*projection +
distance*aeot->deltaAngle();
424 <<
" proj " << projection <<
" new localPos "
425 << localPos[0] <<
" simple " << localPosSimple[0]);
434 const AmgSymMatrix(5)* originalCov = trkPar->covariance();
442 return residualPull(measurement, trkPar.get(), resType, detType );
451 const double locMesCov,
452 const double locTrkCov,
455 double CovarianceSum = 0.0;
457 CovarianceSum = locMesCov + locTrkCov;
459 CovarianceSum = locMesCov - locTrkCov;
460 }
else CovarianceSum = locMesCov;
462 if (CovarianceSum <= 0.0) {
463 ATH_MSG_DEBUG(
"instable calculation: total covariance is non-positive, MeasCov = "<<
464 locMesCov<<
", TrkCov = "<<locTrkCov<<
", resType = "<<resType);
467 return residual/sqrt(CovarianceSum);