7 #include "GaudiKernel/MsgStream.h"
24 declareInterface<IMuonSegmentInOverlapResolvingTool>(
this);
38 return StatusCode::SUCCESS;
50 double road_dz = lphiDir.z();
51 double seg_dy = lsegDir.y();
52 double seg_dz = lsegDir.z();
53 if (road_dz * seg_dz < 0) {
57 if (std::abs(seg_dz) < 1
e-6) {
59 ATH_MSG_DEBUG(
" Unexpected local direction of segment " << lsegDir);
61 double scale = road_dz / seg_dz;
70 double& phi,
double& stereoangle)
const
101 Amg::Vector3D lDiro12 = gToLocal1.linear() * (gToGlobal2.linear() * segLocDiro);
103 Amg::Vector3D lDiro21 = gToLocal2.linear() * (gToGlobal1.linear() * segLocDiro);
105 stereoangle = std::acos(lDiro12.x());
112 double b = lDir1.y() * lDir12.z() - lDir1.z() * lDir12.y();
113 double a = lDir1.y() * lDiro12.z() - lDir1.z() * lDiro12.y();
114 double dxn = lDir12.x();
115 double dyn = lDir12.y();
116 double dzn = lDir12.z();
117 if (std::abs(
a) > 1
e-2) {
118 dxn = lDir12.x() -
b * lDiro12.x() /
a;
119 dyn = lDir12.y() -
b * lDiro12.y() /
a;
120 dzn = lDir12.z() -
b * lDiro12.z() /
a;
122 double norm = std::hypot(dxn, dyn, dzn);
127 if (dxn * lDir1.x() + dyn * lDir1.y() + dzn * lDir1.z() < 0)
norm = -
norm;
141 double theta = gDirn.theta();
151 double res21 = (lPos2.y() - lPos21.y()) * lDirn2.z() - (lPos2.z() - lPos21.z()) * lDirn2.y();
153 double step = (lDiro21.y() * lDirn2.z() - lDiro21.z() * lDirn2.y());
154 if (std::abs(
step) > 1
e-5) {
155 localx1 = res21 /
step;
160 Amg::Vector3D lPosn1(lPos1.x() + localx1, lPos1.y(), lPos1.z());
163 double res12 = (lPos1.y() - lPos12.y()) * lDirn1.z() - (lPos1.z() - lPos12.z()) * lDirn1.y();
164 step = (lDiro12.y() * lDirn1.z() - lDiro12.z() * lDirn1.y());
166 if (std::abs(
step) > 1
e-5) {
167 localx2 = res12 /
step;
172 Amg::Vector3D lPosn2(lPos2.x() + localx2, lPos2.y(), lPos2.z());
175 << lPos1 <<
" new " << lPosn1 << std::endl
176 <<
" segment 1 global position " << gPos1 <<
" new " << gPosn1 << std::endl
177 <<
" segment 2 local position " << lPos2 <<
" new " << lPosn2 << std::endl
178 <<
" segment 2 global position " << gPos2 <<
" new " << gPosn2);
182 if (gDir1.x() * gDirPos.x() + gDir1.y() * gDirPos.y() + gDir1.z() * gDirPos.z() < 0) {
183 gDirPos = -gPosn2 + gPosn1;
185 double dtheta = theta - gDirPos.theta();
186 double dphi = phi - gDirPos.phi();
187 ATH_MSG_DEBUG(
" theta " << theta <<
" gDirPos theta " << gDirPos.theta() <<
" dtheta " << dtheta <<
" phi " << phi
188 <<
" gDirPos phi " << gDirPos.phi() <<
" dphi " << dphi);
228 Amg::Vector3D lDiro12 = gToLocal1.linear() * (gToGlobal2.linear() * segLocDiro);
239 double b = lDir1.y() * lDir12.z() - lDir1.z() * lDir12.y();
240 double a = lDir1.y() * lDiro12.z() - lDir1.z() * lDiro12.y();
241 double dxn = lDir12.x();
242 double dyn = lDir12.y();
243 double dzn = lDir12.z();
244 if (std::abs(
a) > 1
e-2) {
245 dxn = lDir12.x() -
b * lDiro12.x() /
a;
246 dyn = lDir12.y() -
b * lDiro12.y() /
a;
247 dzn = lDir12.z() -
b * lDiro12.z() /
a;
249 double norm = std::hypot(dxn, dyn, dzn);
254 if (dxn * lDir1.x() + dyn * lDir1.y() + dzn * lDir1.z() < 0)
norm = -
norm;
270 double dyz = std::abs(segLocDir1.
angleYZ() - segLocDir2.
angleYZ());
271 return {segDir1Min, segDir2Min, dyz};
278 unsigned int nbins = 11;
280 double scanRange = 1.;
281 double scanStep = scanRange / (
nbins - 1);
284 double dthetaMin = 1e9;
288 for (
unsigned int i = 0;
i <
nbins; ++
i) {
289 double phi = phiStart + scanStep *
i;
293 double dyz = std::abs(segLocDir12.
angleYZ() - segLocDir2.
angleYZ());
294 if (dyz < dthetaMin) {
296 segDir1Min = segDir1;
308 bool goodMatch =
true;
317 double posStep = tubeStep / (
nbins - 1);
319 double resfirst{1e9}, reslast{1e9}, posfirst{1e9}, poslast{1e9};
322 for (
int j = 0; j <
nbins; ++j) {
340 << segDir1Min.phi() <<
" theta "
341 << segDir1Min.theta());
351 if (j ==
nbins - 1) {
358 double distPosMin2{1e9}, distPosInTube2{1e9}, distPosMin{1e9}, distPosInTube{1e9}, resyMin{1e9};
360 double rangeCut = 1e5;
361 if (resfirst < rangeCut && reslast < rangeCut && posfirst < rangeCut && poslast < rangeCut) {
362 double resDif = reslast - resfirst;
363 double posDif = poslast - posfirst;
364 if (std::abs(resDif) < 1
e-6) {
366 resDif = resDif < 0. ? -1
e-6 : 1
e-6;
368 if (std::abs(posDif) < 1
e-6) {
370 posDif = posDif < 0. ? -1
e-6 : 1
e-6;
372 distPosMin = posfirst - resfirst / (resDif) * (posDif);
374 resyMin = resfirst + (resDif) * (distPosInTube - posfirst) / (posDif);
376 double locx = distPosInTube;
394 << segDir1Min.phi() <<
" theta "
395 << segDir1Min.theta());
399 distPosMin2 = locExSeg2.x();
421 double shortestTubeLen = 1e9;
434 if (tubelen < shortestTubeLen) {
435 shortestTubeLen = tubelen;
448 double distTubeCenterFromRO = (
summary.globalToSeg * tubeCenter).
x() -
summary.roPosInSegFrame;
449 summary.hvPosInSegFrame =
summary.roPosInSegFrame + 2 * distTubeCenterFromRO;
450 summary.shortestChannelLength = std::abs(2 * distTubeCenterFromRO);
460 <<
" Second segment " <<
m_printer->print(seg2));
474 if (
result.segmentResult1.goodMatch &&
result.segmentResult2.goodMatch) {
480 if (
result.phiResult.segmentDirection1.y() * difPos.y() < 0.) {
485 result.angularDifferencePhi = difPos.deltaPhi(
result.phiResult.segmentDirection1);
498 unsigned int nphiMeas = 0;
499 double averagePull = 0.;
506 0.,
segment.associatedSurface());
512 if (!
id.is_valid() || !
m_idHelperSvc->measuresPhi(
id))
continue;
515 const Trk::Surface& measSurf = meas->associatedSurface();
518 std::unique_ptr<const Trk::TrackParameters> exPars {
527 ATH_MSG_WARNING(
" Failed to propagate parameter to segment surface" << std::endl
535 ATH_MSG_DEBUG(
" calculation of residual/pull failed !!!!! ");
540 if (resPull->pull().size() != 1) {
544 const double pull = resPull->pull().front();
549 if (nphiMeas != 0) averagePull /= nphiMeas;