134 const std::shared_ptr<const Acts::TrackingGeometry> trackingGeo =
m_trackingGeometrySvc->trackingGeometry();
135 const Acts::GeometryContext tgContext =
m_ctxProvider.getGeometryContext(ctx);
136 const Acts::MagneticFieldContext mfContext =
m_ctxProvider.getMagneticFieldContext(ctx);
137 const Acts::CalibrationContext calContext =
m_ctxProvider.getCalibrationContext(ctx);
141 rngWrapper->
setSeed(name(), ctx);
142 CLHEP::HepRandomEngine* randEngine = rngWrapper->
getEngine(ctx);
145 ATH_CHECK(outHandle.
record(std::make_unique<xAOD::MuonSegmentContainer>(),
146 std::make_unique<xAOD::MuonSegmentAuxContainer>()));
149 auto handleCreation =
m_auxMeasProv.makeHandle(ctx, tgContext);
150 if (!handleCreation.ok()){
151 ATH_MSG_ERROR(
"Auxiliary measurement containers cannot be made");
152 return StatusCode::FAILURE;
154 auto& auxMeasHandle{*handleCreation};
164 SeedingAux::Config cfg{};
165 cfg.parsToUse.clear();
168 SeedingAux::Line_t line{};
170 Acts::PropagatorPlainOptions propagationOption{tgContext, mfContext};
173 constexpr bool doScat =
false;
174 constexpr bool doEloss =
false;
176 std::move(propagationOption),
177 nullptr, doScat, doEloss,
184 Acts::ObjVisualization3D visualHelper{};
188 auto saveDisplay = [&](
const std::string& state) {
192 const auto objFile = std::format(
"SegmentReFitTest_{:}_{:}_{:}_{:}.obj",
193 state, ctx.eventID().event_number(), reFitMe->index(),
195 visualHelper.write(objFile);
197 visualHelper = Acts::ObjVisualization3D{};
201 m_detMgr->getSectorEnvelope(reFitMe->chamberIndex(),
203 reFitMe->etaIndex());
216 auto& seedPars = dec_seedPars(*reFitMe);
217 seedPars[Acts::toUnderlying(ParamDefs::x0)] = locSeedPos.x();
218 seedPars[Acts::toUnderlying(ParamDefs::y0)] = locSeedPos.y();
219 seedPars[Acts::toUnderlying(ParamDefs::theta)] = locSeedDir.theta();
220 seedPars[Acts::toUnderlying(ParamDefs::phi)] = locSeedDir.phi();
223 const GeoTrf::CoordEulerAngles sectorAngles = GeoTrf::getCoordRotationAngles(sectorTrf);
231 hitsToFit.front() : hitsToFit.at(1);
233 const Acts::Surface* entrancePortal =
portalSurface(entrance,
true);
234 const Acts::Surface* exitPortal =
portalSurface(hitsToFit.back(),
false);
239 using namespace Acts::PlanarHelper;
241 const Acts::Intersection3D isectEntrance = intersectPlane(seedPos, seedDir, planeNormal,
242 entrancePortal->center(tgContext));
243 const Acts::Intersection3D isectFirst = intersectPlane(seedPos, seedDir, planeNormal,
246 if (reFitMe->nPhiLayers() < 1) {
248 const Acts::Intersection3D isectExit = intersectPlane(seedPos, seedDir, planeNormal,
249 exitPortal->center(tgContext));
250 const Acts::Intersection3D isectLast = intersectPlane(seedPos, seedDir, planeNormal,
255 const Amg::Transform3D trfBeneath = GeoTrf::GeoTransformRT{sectorAngles, 0.5*isectFirst.position() +
256 0.5*isectEntrance.position()};
257 const Amg::Transform3D trfAbove = GeoTrf::GeoTransformRT{sectorAngles, 0.85*isectExit.position() +
258 0.15*isectLast.position() };
260 auto surfBeneath = Acts::Surface::makeShared<Acts::PlaneSurface>(trfBeneath);
261 auto surfAbove = Acts::Surface::makeShared<Acts::PlaneSurface>(trfAbove);
265 constexpr double covVal = Acts::square(1._cm);
266 hitsToFit.push_back(auxMeasHandle.newMeasurement<1>(surfBeneath, ProjectorType::e1DimNoTime,
AmgSymMatrix(1){covVal}));
270 hitsToFit.push_back(auxMeasHandle.newMeasurement<1>(surfAbove, ProjectorType::e1DimNoTime,
AmgSymMatrix(1){covVal}));
277 Acts::GeometryView3D::drawSurface(visualHelper, *entrancePortal, tgContext,
278 Amg::Transform3D::Identity(), Acts::s_viewPortal);
279 Acts::GeometryView3D::drawSurface(visualHelper, *exitPortal, tgContext,
280 Amg::Transform3D::Identity(), Acts::s_viewPortal);
284 Acts::ViewConfig{.color = {220, 0, 0}});
288 <<
", path length: "<<isectEntrance.pathLength()<<
", "
289 <<
" - First surface position: "<<
Amg::toString(isectFirst.position())
290 <<
", path length: "<<isectFirst.pathLength());
294 + 0.15 * isectFirst.position();
296 if (
msgLvl(MSG::VERBOSE)) {
299 std::stringstream sstr{};
301 <<reFitMe->chiSquared() / reFitMe->numberDoF()<<
", nDoF: "<<reFitMe->numberDoF()
302 <<
", prec: "<<reFitMe->nPrecisionHits()<<
", phi: "<<reFitMe->nPhiLayers()<<std::endl;
304 pullCalculator.updateSpatialResidual(line, *meas);
305 const Acts::Surface* surface = meas->spacePoint() ?
m_surfAccessor.get(meas->spacePoint()->primaryMeasurement()) :
nullptr;
306 const Acts::GeometryIdentifier geoId = surface ? surface->geometryId() : Acts::GeometryIdentifier{};
307 sstr<<
" **** "<<(*meas)<<
", chi2: "<<SeedingAux::chi2Term(locPos, locDir, *meas)
308 <<
", sign: "<<(meas->isStraw() ?
309 (SeedingAux::strawSign(locPos,locDir, *meas) == 1 ?
"R" :
"L") :
"X")
310 <<
", geoId: "<<geoId;
311 if (geoId != Acts::GeometryIdentifier{}){
312 const Amg::Vector3D globPos = meas->spacePoint()->msSector()->localToGlobalTransform(tgContext) *
313 meas->localPosition();
314 const Acts::GeometryIdentifier volId = geoId.withSensitive(0);
316 const Acts::Vector2 lPos = (*surface->globalToLocal(tgContext,globPos, reFitMe->direction()));
317 sstr<<
", inside volume: "<<volume->inside(tgContext, globPos);
318 sstr<<
", inside surface: "<<surface->bounds().inside(lPos);
326 <<
", refPoint: "<<
Amg::toString(trf.inverse()*refPos)<<std::endl;
330 std::shared_ptr<const Acts::Surface> target{};
333 using namespace Acts::detail::LineHelper;
334 const Acts::Intersection3D lineIsect =
335 lineIntersect<3>(target->center(tgContext),
336 Amg::Vector3D::UnitZ(),
340 refPos = lineIsect.position();
343 target = Acts::Surface::makeShared<Acts::PlaneSurface>(trf,
344 std::make_unique<Acts::RectangleBounds>(1._m, 1._m));
347 Acts::GeometryView3D::drawSurface(visualHelper, *target,
348 tgContext, Amg::Transform3D::Identity(),
349 Acts::ViewConfig{.color={0,0,220}});
353 Acts::BoundMatrix initialCov{Acts::BoundMatrix::Identity()};
355 auto initialPars = Acts::BoundTrackParameters::create(tgContext, target, fourPos, seedDir, straightQoverP,
356 initialCov, Acts::ParticleHypothesis::muon());
357 if (!initialPars.ok()) {
359 saveDisplay(
"invalidPars");
364 Acts::ViewConfig{.color={0,220,0}});
367 <<
", "<<std::format(
"theta: {:.2f}, ", (*initialPars).theta() / 1._degree)
368 <<std::format(
"phi: {:.2f}", (*initialPars).phi() / 1._degree));
370 std::vector<Acts::SourceLink> sourceLinks{};
371 std::ranges::transform(hitsToFit, std::back_inserter(sourceLinks),
375 fitOptions.referenceSurface = target.get();
377 auto fitTraject =
m_fitter->fit(sourceLinks.begin(), sourceLinks.end(),
378 *initialPars, fitOptions, tracks);
379 if (!fitTraject.ok()) {
380 saveDisplay(
"failed");
385 ATH_MSG_ERROR(
"Segment refit failed. Albeit start parameters are taken from segment");
386 return StatusCode::FAILURE;
390 auto track = *fitTraject;
393 Acts::BoundTrackParameters parameters = track.createParametersAtReference();
396 Acts::ViewConfig{.color={0,220,220}});
399 saveDisplay(
"goodone");
401 std::uint8_t nPrecHits{0}, nTrigEtaHits{0}, nTrigPhiHits{0};
403 std::vector<const xAOD::UncalibratedMeasurement*> goodMeas{};
405 for (
const auto state :track.trackStatesReversed()) {
406 if (!state.hasUncalibratedSourceLink()){
409 goodMeas.insert(goodMeas.begin(),
418 nTrigPhiHits += m->numDimensions() == 2;
424 assert(M !=
nullptr);
426 nTrigEtaHits += (M->numDimensions() == 2 || !M->measuresPhi());
427 nTrigPhiHits += (M->numDimensions() == 2 || M->measuresPhi());
436 const Amg::Vector3D refitPos = globToLoc * parameters.position(tgContext);
442 xAOD::MuonSegment* newSegment = outHandle->push_back(std::make_unique<xAOD::MuonSegment>());
443 dec_segLink(*newSegment) =
Link_t{*segments, reFitMe->index(), ctx};
445 newSegment->
setDirection(globDir.x(), globDir.y(), globDir.z());
446 newSegment->
setPosition(globPos.x(), globPos.y(), globPos.z());
449 newSegment->
setNHits(nPrecHits, nTrigPhiHits, nTrigEtaHits);
450 newSegment->
setIdentifier(reFitMe->sector(), reFitMe->chamberIndex(),
451 reFitMe->etaIndex(), reFitMe->technology());
453 auto& locFitPars = dec_locPars(*newSegment);
454 locFitPars[Acts::toUnderlying(ParamDefs::x0)] = refitSeg.x();
455 locFitPars[Acts::toUnderlying(ParamDefs::y0)] = refitSeg.y();
456 locFitPars[Acts::toUnderlying(ParamDefs::theta)] = refitDir.theta();
457 locFitPars[Acts::toUnderlying(ParamDefs::phi)] = refitDir.phi();
459 return StatusCode::SUCCESS;