131 const std::shared_ptr<const Acts::TrackingGeometry> trackingGeo =
m_trackingGeometryTool->trackingGeometry();
132 const Acts::GeometryContext tgContext = gctx.
context();
133 const Acts::MagneticFieldContext mfContext =
m_extrapolationTool->getMagneticFieldContext(ctx);
138 rngWrapper->
setSeed(name(), ctx);
139 CLHEP::HepRandomEngine* randEngine = rngWrapper->
getEngine(ctx);
142 ATH_CHECK(outHandle.
record(std::make_unique<xAOD::MuonSegmentContainer>(),
143 std::make_unique<xAOD::MuonSegmentAuxContainer>()));
146 auto handleCreation =
m_auxMeasProv.makeHandle(ctx, tgContext);
147 if (!handleCreation.ok()){
148 ATH_MSG_ERROR(
"Auxiliary measurement containers cannot be made");
149 return StatusCode::FAILURE;
151 auto& auxMeasHandle{*handleCreation};
161 SeedingAux::Config cfg{};
162 cfg.parsToUse.clear();
165 SeedingAux::Line_t line{};
167 Acts::PropagatorPlainOptions propagationOption{tgContext, mfContext};
170 constexpr bool doScat =
false;
171 constexpr bool doEloss =
false;
173 std::move(propagationOption),
174 nullptr, doScat, doEloss,
181 Acts::ObjVisualization3D visualHelper{};
185 auto saveDisplay = [&](
const std::string& state) {
189 const auto objFile = std::format(
"SegmentReFitTest_{:}_{:}_{:}_{:}.obj",
190 state, ctx.eventID().event_number(), reFitMe->index(),
192 visualHelper.write(objFile);
194 visualHelper = Acts::ObjVisualization3D{};
198 m_detMgr->getSectorEnvelope(reFitMe->chamberIndex(),
200 reFitMe->etaIndex());
213 auto& seedPars = dec_seedPars(*reFitMe);
214 seedPars[Acts::toUnderlying(ParamDefs::x0)] = locSeedPos.x();
215 seedPars[Acts::toUnderlying(ParamDefs::y0)] = locSeedPos.y();
216 seedPars[Acts::toUnderlying(ParamDefs::theta)] = locSeedDir.theta();
217 seedPars[Acts::toUnderlying(ParamDefs::phi)] = locSeedDir.phi();
220 const GeoTrf::CoordEulerAngles sectorAngles = GeoTrf::getCoordRotationAngles(sectorTrf);
228 hitsToFit.front() : hitsToFit.at(1);
230 const Acts::Surface* entrancePortal =
portalSurface(entrance,
true);
231 const Acts::Surface* exitPortal =
portalSurface(hitsToFit.back(),
false);
236 using namespace Acts::PlanarHelper;
238 const Acts::Intersection3D isectEntrance = intersectPlane(seedPos, seedDir, planeNormal,
239 entrancePortal->center(tgContext));
240 const Acts::Intersection3D isectFirst = intersectPlane(seedPos, seedDir, planeNormal,
243 if (reFitMe->nPhiLayers() < 1) {
245 const Acts::Intersection3D isectExit = intersectPlane(seedPos, seedDir, planeNormal,
246 exitPortal->center(tgContext));
247 const Acts::Intersection3D isectLast = intersectPlane(seedPos, seedDir, planeNormal,
252 const Amg::Transform3D trfBeneath = GeoTrf::GeoTransformRT{sectorAngles, 0.5*isectFirst.position() +
253 0.5*isectEntrance.position()};
254 const Amg::Transform3D trfAbove = GeoTrf::GeoTransformRT{sectorAngles, 0.85*isectExit.position() +
255 0.15*isectLast.position() };
257 auto surfBeneath = Acts::Surface::makeShared<Acts::PlaneSurface>(trfBeneath);
258 auto surfAbove = Acts::Surface::makeShared<Acts::PlaneSurface>(trfAbove);
262 constexpr double covVal = Acts::square(1._cm);
263 hitsToFit.push_back(auxMeasHandle.newMeasurement<1>(surfBeneath, ProjectorType::e1DimNoTime,
AmgSymMatrix(1){covVal}));
267 hitsToFit.push_back(auxMeasHandle.newMeasurement<1>(surfAbove, ProjectorType::e1DimNoTime,
AmgSymMatrix(1){covVal}));
274 Acts::GeometryView3D::drawSurface(visualHelper, *entrancePortal, tgContext,
275 Amg::Transform3D::Identity(), Acts::s_viewPortal);
276 Acts::GeometryView3D::drawSurface(visualHelper, *exitPortal, tgContext,
277 Amg::Transform3D::Identity(), Acts::s_viewPortal);
281 Acts::ViewConfig{.color = {220, 0, 0}});
285 <<
", path length: "<<isectEntrance.pathLength()<<
", "
286 <<
" - First surface position: "<<
Amg::toString(isectFirst.position())
287 <<
", path length: "<<isectFirst.pathLength());
291 + 0.15 * isectFirst.position();
293 if (
msgLvl(MSG::VERBOSE)) {
296 std::stringstream sstr{};
298 <<reFitMe->chiSquared() / reFitMe->numberDoF()<<
", nDoF: "<<reFitMe->numberDoF()
299 <<
", prec: "<<reFitMe->nPrecisionHits()<<
", phi: "<<reFitMe->nPhiLayers()<<std::endl;
301 pullCalculator.updateSpatialResidual(line, *meas);
302 const Acts::Surface* surface = meas->spacePoint() ?
m_surfAccessor.get(meas->spacePoint()->primaryMeasurement()) :
nullptr;
303 const Acts::GeometryIdentifier geoId = surface ? surface->geometryId() : Acts::GeometryIdentifier{};
304 sstr<<
" **** "<<(*meas)<<
", chi2: "<<SeedingAux::chi2Term(locPos, locDir, *meas)
305 <<
", sign: "<<(meas->isStraw() ?
306 (SeedingAux::strawSign(locPos,locDir, *meas) == 1 ?
"R" :
"L") :
"X")
307 <<
", geoId: "<<geoId;
308 if (geoId != Acts::GeometryIdentifier{}){
309 const Amg::Vector3D globPos = meas->spacePoint()->msSector()->localToGlobalTransform(gctx) *
310 meas->localPosition();
311 const Acts::GeometryIdentifier volId = geoId.withSensitive(0);
313 const Acts::Vector2 lPos = (*surface->globalToLocal(tgContext,globPos, reFitMe->direction()));
314 sstr<<
", inside volume: "<<volume->inside(tgContext, globPos);
315 sstr<<
", inside surface: "<<surface->bounds().inside(lPos);
323 <<
", refPoint: "<<
Amg::toString(trf.inverse()*refPos)<<std::endl;
327 std::shared_ptr<const Acts::Surface> target{};
330 using namespace Acts::detail::LineHelper;
331 const Acts::Intersection3D lineIsect =
332 lineIntersect<3>(target->center(tgContext),
333 Amg::Vector3D::UnitZ(),
337 refPos = lineIsect.position();
340 target = Acts::Surface::makeShared<Acts::PlaneSurface>(trf,
341 std::make_unique<Acts::RectangleBounds>(1._m, 1._m));
344 Acts::GeometryView3D::drawSurface(visualHelper, *target,
345 tgContext, Amg::Transform3D::Identity(),
346 Acts::ViewConfig{.color={0,0,220}});
350 Acts::BoundMatrix initialCov{Acts::BoundMatrix::Identity()};
352 auto initialPars = Acts::BoundTrackParameters::create(tgContext, target, fourPos, seedDir, straightQoverP,
353 initialCov, Acts::ParticleHypothesis::muon());
354 if (!initialPars.ok()) {
356 saveDisplay(
"invalidPars");
361 Acts::ViewConfig{.color={0,220,0}});
364 <<
", "<<std::format(
"theta: {:.2f}, ", (*initialPars).theta() / 1._degree)
365 <<std::format(
"phi: {:.2f}", (*initialPars).phi() / 1._degree));
367 std::vector<Acts::SourceLink> sourceLinks{};
368 std::ranges::transform(hitsToFit, std::back_inserter(sourceLinks),
372 fitOptions.referenceSurface = target.get();
374 auto fitTraject =
m_fitter->fit(sourceLinks.begin(), sourceLinks.end(),
375 *initialPars, fitOptions, tracks);
376 if (!fitTraject.ok()) {
377 saveDisplay(
"failed");
382 ATH_MSG_ERROR(
"Segment refit failed. Albeit start parameters are taken from segment");
383 return StatusCode::FAILURE;
387 auto track = *fitTraject;
390 Acts::BoundTrackParameters parameters = track.createParametersAtReference();
393 Acts::ViewConfig{.color={0,220,220}});
396 saveDisplay(
"goodone");
400 std::vector<const xAOD::UncalibratedMeasurement*> goodMeas{};
402 tracks.trackStateContainer().visitBackwards(track.tipIndex(),[&](
const auto& state){
403 if (!state.hasUncalibratedSourceLink()){
406 goodMeas.insert(goodMeas.begin(),
418 summary.nPrecHits += isPrecHit;
423 summary.nEtaTrigHits += !isPrecHit;
431 const Amg::Vector3D refitPos = globToLoc * parameters.position(tgContext);
435 const Amg::Vector3D globPos{msSector->localToGlobalTransform(gctx) * refitSeg};
437 xAOD::MuonSegment* newSegment = outHandle->push_back(std::make_unique<xAOD::MuonSegment>());
438 dec_segLink(*newSegment) =
Link_t{*segments, reFitMe->index(), ctx};
440 newSegment->
setDirection(globDir.x(), globDir.y(), globDir.z());
441 newSegment->
setPosition(globPos.x(), globPos.y(), globPos.z());
444 newSegment->
setNHits(summary.nPrecHits, summary.nPhiHits, summary.nEtaTrigHits);
445 auto& locFitPars = dec_locPars(*newSegment);
446 locFitPars[Acts::toUnderlying(ParamDefs::x0)] = refitSeg.x();
447 locFitPars[Acts::toUnderlying(ParamDefs::y0)] = refitSeg.y();
448 locFitPars[Acts::toUnderlying(ParamDefs::theta)] = refitDir.theta();
449 locFitPars[Acts::toUnderlying(ParamDefs::phi)] = refitDir.phi();
451 return StatusCode::SUCCESS;