10 #include "GaudiKernel/IDataProviderSvc.h"
11 #include "GaudiKernel/SmartDataPtr.h"
29 declareInterface<IMuTagMatchingTool>(
this);
108 ATH_MSG_ERROR(
"Could not retrieve a valid tracking geometry");
111 return StatusCode::SUCCESS;
115 int surfaceName)
const {
147 if (!MSEntranceVolume) {
return nullptr; }
149 std::unique_ptr<Trk::TrackParameters> exTrk{
153 ATH_MSG_DEBUG(
"Track could not be extrapolated to MS entrance...");
155 ATH_MSG_DEBUG(
"Track extrapolated to MS entrance Radius " << exTrk->position().perp() <<
" Z " << exTrk->position().z());
165 std::unique_ptr<Trk::TrackParameters> exTrk{
m_IExtrapolator->extrapolate(ctx, pTrack, pSurface, direction,
false,
Trk::muon)};
167 ATH_MSG_DEBUG(
" didn't manage to extrapolate TrackParameters to abstract surface Radius " << pSurface.
center().perp() <<
" Z "
168 << pSurface.
center().z());
177 if (flippedPhi >
M_PI) flippedPhi -= 2 *
M_PI;
178 double flippedTheta =
M_PI -
pars[3];
179 if (flippedTheta < 0.) flippedTheta +=
M_PI;
180 if (inputPars.covariance()) {
183 return std::make_unique<Trk::Perigee>(-
pars[0],
pars[1], flippedPhi, flippedTheta,
pars[4], perSurf, covMat);
185 ATH_MSG_DEBUG(
"flipDirection: no covariance associated to input parameters " << inputPars);
201 ATH_MSG_DEBUG(
"CSC segment is identified to be 2D. Not extrapolating.");
206 std::shared_ptr<Trk::TrackParameters> atap{
209 ATH_MSG_DEBUG(
" didn't manage to extrapolate TrackParameters to segment surface Radius"
210 <<
segment.associatedSurface().center().perp() <<
" Z " <<
segment.associatedSurface().center().z());
214 std::shared_ptr<Trk::AtaPlane> matap = std::dynamic_pointer_cast<Trk::AtaPlane>(atap);
217 ATH_MSG_DEBUG(
" didn't manage to extrapolate MeasuredTrackParameters to segment surface atap Radius "
218 << atap->position().perp() <<
" Z" << atap->position().z());
221 ATH_MSG_DEBUG(
" Succesfull extrapolation segment surface matap Radius " << matap->position().perp() <<
" Z"
222 << matap->position().z());
234 const double deltaPhi = exTrkPos.deltaPhi(segPos);
236 double sigma_phi = 0.;
238 const AmgSymMatrix(5)& covAtCyl = *atSurface.covariance();
242 const AmgSymMatrix(5)& covAtPlane = *atSurface.covariance();
245 const AmgSymMatrix(5)& covAtDisc = *atSurface.covariance();
248 double errPhi = std::hypot(PHI_CUT, sigma_phi);
253 <<
" while the cut is set on " << std::setw(10) << errPhi);
266 const double dTheta = std::abs(exTrkPos.theta() - segPos.theta());
267 if (dTheta < THETA_CUT)
270 ATH_MSG_DEBUG(std::setw(30) <<
"roughTheta failed: d_theta = " << std::setw(10) << dTheta <<
" while the cut is set on "
271 << std::setw(10) << THETA_CUT);
277 double L = exTrkPos.mag();
281 const double dPerp = std::abs(exTrkPos.perp() - segPos.perp());
285 ATH_MSG_DEBUG(std::setw(30) <<
"rough R failed: d_R = " << std::setw(10) << dPerp <<
" while the cut is set on "
286 << std::setw(10) << R_CUT);
291 double newError = exTrk_Err;
299 if (!
info.segment || !
info.trackAtSegment) {
300 ATH_MSG_DEBUG(
" No segment and or trackAtSegment pointer matchSegmentPosition ");
315 if (!
info.segment || !
info.trackAtSegment) {
316 ATH_MSG_DEBUG(
" No segment and or trackAtSegment pointer matchSegmentDirection ");
327 if (!
info.segment || !
info.trackAtSegment) {
328 ATH_MSG_DEBUG(
" No segment and or trackAtSegment pointer matchCombinedPull ");
335 <<
info.hasPhi <<
" minimumPullPhi " <<
info.minimumPullPhi <<
" pullChamber " <<
info.pullChamber <<
" cut "
343 if (!
info.segment || !
info.trackAtSegment) {
344 ATH_MSG_DEBUG(
" No segment and or trackAtSegment pointermatchPtDependentPull ");
352 double Pullcut = 2.0;
354 if (
pT > 2.) { Pullcut = 5.0 - 6.0 /
pT; }
357 if (std::abs(
info.pullCY) > Pullcut) pass =
false;
368 const EventContext& ctx = Gaudi::Hive::currentContext();
369 const AmgVector(5)& oripars = oriPerigee->parameters();
371 std::unique_ptr<Trk::Perigee> pPerigee = std::make_unique<Trk::Perigee>(oripars[0], oripars[1], oripars[2], oripars[3], 0., periSurf, std::nullopt);
376 ATH_MSG_DEBUG(
"==============================================================================");
379 ATH_MSG_DEBUG(
"=== global position " << startPos.x() <<
" " << startPos.y() <<
" " << startPos.z());
380 ATH_MSG_DEBUG(
"=== global directn " << startMom.phi() <<
" " << startMom.theta());
382 std::unique_ptr<Trk::TrackParameters> alongPars{
385 ATH_MSG_DEBUG(
"======= EXTRAPOLATED ALONG MOMENTUM ORIGINAL PERIGEE");
390 ATH_MSG_DEBUG(
"=== global position " << alongPos.x() <<
" " << alongPos.y() <<
" " << alongPos.z());
391 ATH_MSG_DEBUG(
"=== global position phi theta " << alongPos.phi() <<
" " << alongPos.theta());
392 ATH_MSG_DEBUG(
"=== global directn " << alongMom.phi() <<
" " << alongMom.theta());
396 ATH_MSG_DEBUG(
"======= EXTRAPOLATED OPPOSITE MOMENTUM ORIGINAL PERIGEE");
397 std::unique_ptr<const Trk::TrackParameters> oppositePars{
402 ATH_MSG_DEBUG(
"=== global position " << oppositePos.x() <<
" " << oppositePos.y() <<
" " << oppositePos.z());
403 ATH_MSG_DEBUG(
"=== global position phi theta " << oppositePos.phi() <<
" " << oppositePos.theta());
404 ATH_MSG_DEBUG(
"=== global directn " << oppositeMom.phi() <<
" " << oppositeMom.theta());
409 std::unique_ptr<const Trk::Perigee> flippedPerigee =
flipDirection(*pPerigee);
410 const AmgVector(5)& flipPars = flippedPerigee->parameters();
416 ATH_MSG_DEBUG(
"=== parameters are " << flipPars[0] <<
" " << flipPars[1] <<
" " << flipPars[2] <<
" " << flipPars[3] <<
" "
418 ATH_MSG_DEBUG(
"=== global position " << flipPos.x() <<
" " << flipPos.y() <<
" " << flipPos.z());
419 ATH_MSG_DEBUG(
"=== global directn " << flipMom.phi() <<
" " << flipMom.theta());
421 std::unique_ptr<const Trk::TrackParameters> alongFlipPars{
424 ATH_MSG_DEBUG(
"======= EXTRAPOLATED ALONGFLIP MOMENTUM ORIGINAL PERIGEE");
426 const Amg::Vector3D alongFlipPos = alongFlipPars->position();
427 const Amg::Vector3D alongFlipMom = alongFlipPars->momentum();
428 ATH_MSG_DEBUG(
"=== global position " << alongFlipPos.x() <<
" " << alongFlipPos.y() <<
" " << alongFlipPos.z());
429 ATH_MSG_DEBUG(
"=== global position phi theta " << alongFlipPos.phi() <<
" " << alongFlipPos.theta());
430 ATH_MSG_DEBUG(
"=== global directn " << alongFlipMom.phi() <<
" " << alongFlipMom.theta());
434 ATH_MSG_DEBUG(
"======= EXTRAPOLATED OPPOSITEFLIP MOMENTUM ORIGINAL PERIGEE");
435 std::unique_ptr<const Trk::TrackParameters> oppositeFlipPars{
437 if (oppositeFlipPars) {
438 const Amg::Vector3D oppositeFlipPos = oppositeFlipPars->position();
439 const Amg::Vector3D oppositeFlipMom = oppositeFlipPars->momentum();
440 ATH_MSG_DEBUG(
"=== global position " << oppositeFlipPos.x() <<
" " << oppositeFlipPos.y() <<
" " << oppositeFlipPos.z());
441 ATH_MSG_DEBUG(
"=== global position phi theta " << oppositeFlipPos.phi() <<
" " << oppositeFlipPos.theta());
442 ATH_MSG_DEBUG(
"=== global directn " << oppositeFlipMom.phi() <<
" " << oppositeFlipMom.theta());
446 ATH_MSG_DEBUG(
"==============================================================================");
460 if (!rot) {
continue; }
467 std::shared_ptr<const Trk::AtaPlane> exTrack)
const {
474 info.trackAtSegment = exTrack;
484 info.dtheta = exTrack->momentum().theta() -
segment.globalDirection().theta();
485 info.dphi = exTrack->momentum().deltaPhi(
segment.globalDirection());
489 info.dthetaPos = exTrack->position().theta() -
segment.globalPosition().theta();
490 info.dphiPos = exTrack->position().deltaPhi (
segment.globalPosition());
499 info.exCovYTheta = 0.;
500 if (exTrack->covariance()) {
509 info.exErrorX = -999.;
510 info.exErrorY = -999.;
527 exTrack->
associatedSurface().globalToLocalDirection(exTrack->momentum(), exTrkLocDir);
533 double exTrkErrXZ(0.), exTrkErrYZ(0.), segErrXZ(0.), segErrYZ(0.), covLocYYZ(0.);
536 info.exErrorXZ = exTrkErrXZ;
537 info.exErrorYZ = exTrkErrYZ;
538 info.exCovYZY = covLocYYZ;
540 info.segErrorXZ = segErrXZ;
541 info.segErrorYZ = segErrYZ;
548 ATH_MSG_DEBUG(
" info.exErrorYZ " <<
info.exErrorYZ <<
" info.segErrorYZ " <<
info.segErrorYZ <<
" info.exCovYZY " <<
info.exCovYZY);
566 ATH_MSG_ERROR(
"Null pointer to the read MuonDetectorManager conditions object");
569 double maxResXMdt{-1e9}, maxResPhi{-1e9}, maxPullPhi{-1e9}, minResPhi{1e9}, minPullPhi{1e9};
597 <<
" exPos " << exP->parameters()[
Trk::locR] <<
" y " << exP->parameters()[
Trk::locZ] <<
" tubeL " << tubeLen);
598 double exResidual = std::abs(exP->parameters()[
Trk::locZ]) - 0.5 * tubeLen;
599 if (maxResXMdt < exResidual) maxResXMdt = exResidual;
600 if (exResidual > 0.)
ATH_MSG_DEBUG(
"Extrapolated position outside tube, " << exResidual);
607 std::unique_ptr<Trk::TrackParameters> exP{
613 std::optional<Trk::ResidualPull> resPull{
620 const double residual = resPull->residual().front();
621 const double pull = resPull->pull().front();
631 ATH_MSG_DEBUG(
"Residual phi min " << minResPhi <<
" max " << maxResPhi <<
" pull min " << minPullPhi <<
" max " << maxPullPhi
632 <<
" dist from tube end " << maxResXMdt);
637 info.maximumResidualAlongTube = maxResXMdt;
638 info.maximumResidualPhi = maxResPhi;
639 info.maximumPullPhi = maxPullPhi;
641 info.minimumResidualPhi = minResPhi;
642 info.minimumPullPhi = minPullPhi;
644 info.pullChamber = maxResXMdt /
info.exErrorX;
650 constexpr
double matrix_cutoff = 1.e20;
652 double b = std::abs(
info.exCovYZY) < matrix_cutoff ?
info.exCovYZY : (
info.exCovYZY < 0 ? -1. : 1) * matrix_cutoff;
657 if (
det < 0.1 *
a *
d) {
658 scale = std::sqrt(0.9 *
a *
d) / std::abs(
b);
674 ATH_MSG_DEBUG(
" segment direction theta " <<
segment.globalDirection().theta() <<
" position theta "
679 if (error_rescy > 0) {
680 error_rescy = std::sqrt(error_rescy + error_segcy);
682 error_rescy = std::sqrt(
info.exErrorY *
info.exErrorY + error_segcy);
692 info.chi2Y = 0.5*( chi2Y /
det);
693 if (
info.chi2Y < 0)
ATH_MSG_DEBUG(
" NEGATIVE chi2Y " << chi2Y <<
" dydyz " << dydyz <<
" determinant " <<
det);
704 info.stationLayer = 0;
718 if (
q)
info.nholes =
q->numberOfHoles();
733 constexpr
double a_locY{13.8269}, b_locY{1.23548}, c_locY{2.73400}, a_AYZ{12.0655}, b_AYZ{1.87578}, c_AYZ{1.88660}, width_locY{20.},
736 double dlocY =
info.resY;
737 double dAYZ =
info.dangleYZ;
739 double logLocY =
std::log(1 + std::abs(dlocY / width_locY));
740 double logAYZ =
std::log(1 + std::abs(dAYZ / width_AYZ));
742 info.RLocY = a_locY / (1. + b_locY * (logLocY) * (logLocY) + c_locY * (logLocY) * (logLocY) * (logLocY));
743 info.RAYZ = a_AYZ / (1. + b_AYZ * (logAYZ) * (logAYZ) + c_AYZ * (logAYZ) * (logAYZ) * (logAYZ));
751 if (pass) selected = 1;
754 info.selected = selected;
775 double& covLocYYZ)
const {
777 if (!exTrack.covariance())
return;
782 const AmgVector(5)& exTrkParms = exTrack.parameters();
793 const AmgSymMatrix(2)& anglesCovLoc = anglesCovGlob.similarity(jacobianExTrk);
795 if (anglesCovLoc(0, 0) >= 0) angleXZerror = std::sqrt(anglesCovLoc(0, 0));
796 if (anglesCovLoc(1, 1) >= 0) angleYZerror = std::sqrt(anglesCovLoc(1, 1));
801 << jacobianExTrk(0, 1) <<
" J11 " << jacobianExTrk(0, 1));
803 ATH_MSG_DEBUG(std::setw(20) <<
"Angles Jacobian used for TRACK angle errors below: " << jacobianExTrk);
805 ATH_MSG_DEBUG(std::setw(20) <<
"NEW TRACK angleXZ error = " << std::setprecision(6) << std::setw(10) << angleXZerror << std::setw(20)
806 <<
" and angleYZ error = " << std::setw(10) << angleYZerror);
810 if (!
info.segment || !
info.trackAtSegment) {
811 ATH_MSG_DEBUG(
" No segment and or trackAtSegment pointer matchDistance ");
834 if (!rot) {
continue; }
842 unsigned int nrHits{0};
849 if (!rot) {
continue; }