43 {
46 const ActsTrk::GeometryContext* gctx{nullptr};
48 const Acts::GeometryContext tgContext{gctx->
context()};
49
51 const MuonR4::SpacePoint&
sp) {
55 Amg::Vector3D::Zero(),
56 Amg::Vector3D::Zero());
57
59 trf.linear() *
sp.sensorDirection(),
60 start.position(tgContext),
65
66 const auto* detEl =
static_cast<const ActsTrk::IDetectorElementBase*
>(
target.surfacePlacement());
70 <<
" geoId: "<<
target.geometryId()<<
", "<<( lambda.value_or(0.) > 0 ?
"forward" :
"backward"));
71
73 ? Acts::Direction::Forward()
74 : Acts::Direction::Backward(), 100._m);
75
76 };
78
79 SeedingAux::Config
cfg{};
80 cfg.parsToUse.clear();
82
83 SeedingAux::Line_t
line{};
84
87
89
90
91 const MuonGMR4::SpectrometerSector* sector =
m_detMgr->getSectorEnvelope(segment->chamberIndex(),
92 segment->sector(),
93 segment->etaIndex());
95
96 Acts::ObjVisualization3D visualHelper{};
100 Acts::ViewConfig{.color = {220, 0, 0}});
102 }
103
104 if (
msgLvl(MSG::VERBOSE)) {
105 std::stringstream sstr{};
108 <<", chi2/nDoF: "<<segment->chiSquared() / segment->numberDoF()
109 <<", nDoF: "<<segment->numberDoF()<<", "
110 <<segment->nPrecisionHits()<<", "<<segment->nPhiLayers()<<std::endl;
112 sstr<<" **** "<<(*meas)<<", chi2: "<<SeedingAux::chi2Term(line, *meas)
113 <<", sign: "<<(meas->isStraw() ?
114 (SeedingAux::strawSign(line, *meas) == 1 ? "R" : "L") : "-")
117 : Acts::GeometryIdentifier{})
118 <<std::endl;
119 }
121 }
123 if (!meas->spacePoint() ||
124 meas->fitState() != MuonR4::CalibratedSpacePoint::State::Valid) {
125 continue;
126 }
127 const auto sp = meas->spacePoint();
129
130 const auto& bounds = targetSurf.bounds();
131 Amg::Vector2D lPos{Amg::Vector2D::Zero()}, mPos{Amg::Vector2D::Zero()};
132 const Amg::Transform3D toSurf = targetSurf.localToGlobalTransform(tgContext).inverse() *
133 sector->
surface().localToGlobalTransform(tgContext);
134 if (targetSurf.type() == Acts::Surface::SurfaceType::Plane) {
135 lPos = (toSurf * SeedingAux::extrapolateToPlane(line, *meas)).block<2,1>(0,0);
136 if (!bounds.inside(lPos, Acts::BoundaryTolerance::AbsoluteEuclidean(-2._mm))){
138 <<" is outside the trapezoid "<<bounds
140 continue;
141 }
142 mPos = (toSurf * meas->localPosition()).block<2,1>(0,0);
143 } else if (targetSurf.type() == Acts::Surface::SurfaceType::Straw) {
144 const auto cIsect = lineIntersect<3>(meas->localPosition(), meas->sensorDirection(),
146 const auto cIsectPos = cIsect.position();
148 lPos[0] = Acts::copySign(closePos.perp(), SeedingAux::strawSign(line, *meas));
149 lPos[1] = closePos.z();
150 mPos[0] = Acts::copySign(meas->driftRadius(), lPos[0]);
151 if (meas->measuresPhi()) {
152 mPos[1] = meas->localPosition().x();
153 }
154 const auto& lBounds = static_cast<const Acts::LineBounds&>(bounds);
155 if (std::abs(closePos.z()) > lBounds.get(Acts::LineBounds::eHalfLengthZ) - 2._cm ||
156 closePos.perp() >lBounds.get(Acts::LineBounds::eR) - 0.2_mm) {
160 continue;
161 }
162 }
164 if (!extpPars.ok()) {
166 <<
",\n lPos: "<<
Amg::toString(toSurf * meas->localPosition())
167 <<
", expected: "<<
Amg::toString(lPos)<<
", "<<targetSurf.bounds());
168 retCode = StatusCode::FAILURE;
169 continue;
170 }
174 Acts::ViewConfig{.color = {0, 0, 220}}, 6._cm);
175 }
176
177 if (targetSurf.type() == Acts::Surface::SurfaceType::Plane) {
181 const Amg::Vector2D dPos = (*extpPars).localPosition() - lPos;
182 if (dPos.mag() > 0.1_mm) {
185 retCode = StatusCode::FAILURE;
186 }
187 } else if (targetSurf.type() == Acts::Surface::SurfaceType::Straw) {
188 const double dist = lPos[0];
189 const double extDist = (*extpPars).parameters()[Acts::eBoundLoc0];
190 const double extLocZ = (*extpPars).parameters()[Acts::eBoundLoc1];
191 const double cov = meas->covariance()[Acts::toUnderlying(AxisDefs::etaCov)];
193 <<" straight: "<<dist<<", extrapolated: "<<extDist
194 <<"--> "<<(extDist - dist ) / std::sqrt(cov)
195 <<", along the tube: "<<lPos[1]<<", extrapolated: "<<extLocZ);
196 if (std::abs(dist - extDist) / std::sqrt(cov) > 0.05 ||
197 std::abs(lPos[1] - extLocZ) > 0.1_mm) {
199 <<
", "<<
Amg::toString(lPos)<<
" vs. ("<<extDist<<
", "<<extLocZ<<
")"
200 <<", deviate R: "<<(std::abs(dist -extDist) / std::sqrt(cov))
201 <<", deviate Z: "<<std::abs(lPos[1] - extLocZ));
202 retCode = StatusCode::FAILURE;
203 }
204 }
205
206 pullCalculator.updateSpatialResidual(line, *meas);
208 <<
" / "<<targetSurf.geometryId()<<
" --- measurement: "<<
Amg::toString(mPos)<<
", extraploated: "
211 }
213 visualHelper.write(std::format("ExtTpTest_{:}_{:}_{:}.obj",
214 ctx.eventID().event_number(), segment->index(),
216 }
217 }
218
219 return retCode;
220 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
Acts::GeometryContext context() const
bool msgLvl(const MSG::Level lvl) const
std::string identString() const
Returns a string encoding the chamber index & the sector of the MS sector.
const Acts::PlaneSurface & surface() const
Returns the associated surface.
const MeasVec & measurements() const
Returns the associated measurements.
SG::ReadHandleKey< ActsTrk::GeometryContext > m_geoCtxKey
Dependency on the geometry alignment.
Gaudi::Property< bool > m_drawEvent
Option to draw every extrapolation asan obj file.
const MuonGMR4::MuonDetectorManager * m_detMgr
Detector manager to fetch the sector surfaces.
ToolHandle< ActsTrk::IExtrapolationTool > m_extrapolationTool
Track extrapolation tool.
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_readKey
Declare the data dependency on the standard Mdt+Rpc+Tgc segment container.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
IdHelperSvc to decode the Identifiers.
std::optional< double > intersect(const AmgVector(N)&posA, const AmgVector(N)&dirA, const AmgVector(N)&posB, const AmgVector(N)&dirB)
Calculates the point B' along the line B that's closest to a second line A.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
::StatusCode StatusCode
StatusCode definition for legacy code.
float extrapolate(const MuonLayerHough::Maximum &ref, const MuonLayerHough::Maximum &ex, bool doparabolic=false)
SpacePoint::SeedingAux SeedingAux
Abrivation of the CompSpacePointAuxiliaries.
Parameters localSegmentPars(const xAOD::MuonSegment &seg)
Returns the localSegPars decoration from a xAODMuon::Segment.
Acts::BoundTrackParameters boundSegmentPars(const MuonGMR4::MuonDetectorManager &detMgr, const xAOD::MuonSegment &segment, std::optional< Acts::BoundMatrix > cov=std::nullopt, Acts::ParticleHypothesis hypot=Acts::ParticleHypothesis::muon())
Returns the segment parameters as boundTrackParameters.
std::string printID(const xAOD::MuonSegment &seg)
Print the chamber ID of a segment, e.g.
const Segment * detailedSegment(const xAOD::MuonSegment &seg)
Helper function to navigate from the xAOD::MuonSegment to the MuonR4::Segment.
void drawBoundParameters(const ActsTrk::GeometryContext &gctx, const Acts::BoundTrackParameters &pars, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewLine, const double standardLength=3.*Gaudi::Units::cm)
Draw a line representing the bound track parameters.
void drawSegmentMeasurements(const ActsTrk::GeometryContext &gctx, const xAOD::MuonSegment &segment, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewSensitive)
Draw all uncalibrated measurements associated to the segment.
void drawSegmentLine(const ActsTrk::GeometryContext &gctx, const xAOD::MuonSegment &segment, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewLine, const double standardLength=1.*Gaudi::Units::m)
Draw a segment line inside the obj file.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
dot(G, fn, nodesToHighlight=[])
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
MuonSegment_v1 MuonSegment
Reference the current persistent version:
const Acts::Surface & muonSurface(const UncalibratedMeasurement *meas)
Returns the associated Acts surface to the measurement.