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};
160 SeedingAux::Config cfg{};
161 cfg.parsToUse.clear();
164 SeedingAux::Line_t line{};
166 Acts::PropagatorPlainOptions propagationOption{tgContext, mfContext};
169 constexpr bool doScat =
false;
170 constexpr bool doEloss =
false;
172 std::move(propagationOption),
173 nullptr, doScat, doEloss,
180 Acts::ObjVisualization3D visualHelper{};
184 auto saveDisplay = [&](
const std::string& state) {
188 const auto objFile = std::format(
"SegmentReFitTest_{:}_{:}_{:}_{:}.obj",
189 state, ctx.eventID().event_number(), reFitMe->index(),
191 visualHelper.write(objFile);
193 visualHelper = Acts::ObjVisualization3D{};
197 m_detMgr->getSectorEnvelope(reFitMe->chamberIndex(),
199 reFitMe->etaIndex());
212 auto& seedPars = dec_seedPars(*reFitMe);
213 seedPars[Acts::toUnderlying(ParamDefs::x0)] = locSeedPos.x();
214 seedPars[Acts::toUnderlying(ParamDefs::y0)] = locSeedPos.y();
215 seedPars[Acts::toUnderlying(ParamDefs::theta)] = locSeedDir.theta();
216 seedPars[Acts::toUnderlying(ParamDefs::phi)] = locSeedDir.phi();
219 const GeoTrf::CoordEulerAngles sectorAngles = GeoTrf::getCoordRotationAngles(sectorTrf);
227 hitsToFit.front() : hitsToFit.at(1);
229 const Acts::Surface* entrancePortal =
portalSurface(entrance,
true);
230 const Acts::Surface* exitPortal =
portalSurface(hitsToFit.back(),
false);
235 using namespace Acts::PlanarHelper;
237 const Acts::Intersection3D isectEntrance = intersectPlane(seedPos, seedDir, planeNormal,
238 entrancePortal->center(tgContext));
239 const Acts::Intersection3D isectFirst = intersectPlane(seedPos, seedDir, planeNormal,
242 if (reFitMe->nPhiLayers() < 1) {
244 const Acts::Intersection3D isectExit = intersectPlane(seedPos, seedDir, planeNormal,
245 exitPortal->center(tgContext));
246 const Acts::Intersection3D isectLast = intersectPlane(seedPos, seedDir, planeNormal,
251 const Amg::Transform3D trfBeneath = GeoTrf::GeoTransformRT{sectorAngles, 0.5*isectFirst.position() +
252 0.5*isectEntrance.position()};
253 const Amg::Transform3D trfAbove = GeoTrf::GeoTransformRT{sectorAngles, 0.85*isectExit.position() +
254 0.15*isectLast.position() };
256 auto surfBeneath = Acts::Surface::makeShared<Acts::PlaneSurface>(trfBeneath);
257 auto surfAbove = Acts::Surface::makeShared<Acts::PlaneSurface>(trfAbove);
261 constexpr double covVal = Acts::square(1._cm);
262 hitsToFit.push_back(auxMeasHandle.newMeasurement<1>(surfBeneath, ProjectorType::e1DimNoTime,
AmgSymMatrix(1){covVal}));
266 hitsToFit.push_back(auxMeasHandle.newMeasurement<1>(surfAbove, ProjectorType::e1DimNoTime,
AmgSymMatrix(1){covVal}));
273 Acts::GeometryView3D::drawSurface(visualHelper, *entrancePortal, tgContext,
274 Amg::Transform3D::Identity(), Acts::s_viewPortal);
275 Acts::GeometryView3D::drawSurface(visualHelper, *exitPortal, tgContext,
276 Amg::Transform3D::Identity(), Acts::s_viewPortal);
280 Acts::ViewConfig{.color = {220, 0, 0}});
284 <<
", path length: "<<isectEntrance.pathLength()<<
", "
285 <<
" - First surface position: "<<
Amg::toString(isectFirst.position())
286 <<
", path length: "<<isectFirst.pathLength());
290 + 0.15 * isectFirst.position();
292 if (
msgLvl(MSG::VERBOSE)) {
295 std::stringstream sstr{};
297 <<reFitMe->chiSquared() / reFitMe->numberDoF()<<
", nDoF: "<<reFitMe->numberDoF()
298 <<
", prec: "<<reFitMe->nPrecisionHits()<<
", phi: "<<reFitMe->nPhiLayers()<<std::endl;
300 pullCalculator.updateSpatialResidual(line, *meas);
301 const Acts::Surface* surface = meas->spacePoint() ?
m_surfAccessor.get(meas->spacePoint()->primaryMeasurement()) :
nullptr;
302 const Acts::GeometryIdentifier geoId = surface ? surface->geometryId() : Acts::GeometryIdentifier{};
303 sstr<<
" **** "<<(*meas)<<
", chi2: "<<SeedingAux::chi2Term(locPos, locDir, *meas)
304 <<
", sign: "<<(meas->isStraw() ?
305 (SeedingAux::strawSign(locPos,locDir, *meas) == 1 ?
"R" :
"L") :
"X")
306 <<
", geoId: "<<geoId;
307 if (geoId != Acts::GeometryIdentifier{}){
308 const Amg::Vector3D globPos = meas->spacePoint()->msSector()->localToGlobalTransform(gctx) *
309 meas->localPosition();
310 const Acts::GeometryIdentifier volId = geoId.withSensitive(0);
312 const Acts::Vector2 lPos = (*surface->globalToLocal(tgContext,globPos, reFitMe->direction()));
313 sstr<<
", inside volume: "<<volume->inside(tgContext, globPos);
314 sstr<<
", inside surface: "<<surface->bounds().inside(lPos);
322 <<
", refPoint: "<<
Amg::toString(trf.inverse()*refPos)<<std::endl;
326 std::shared_ptr<const Acts::Surface> target{};
329 using namespace Acts::detail::LineHelper;
330 const Acts::Intersection3D lineIsect =
331 lineIntersect<3>(target->center(tgContext),
332 Amg::Vector3D::UnitZ(),
336 refPos = lineIsect.position();
339 target = Acts::Surface::makeShared<Acts::PlaneSurface>(trf,
340 std::make_unique<Acts::RectangleBounds>(1._m, 1._m));
343 Acts::GeometryView3D::drawSurface(visualHelper, *target,
344 tgContext, Amg::Transform3D::Identity(),
345 Acts::ViewConfig{.color={0,0,220}});
349 Acts::BoundMatrix initialCov{Acts::BoundMatrix::Identity()};
351 auto initialPars = Acts::BoundTrackParameters::create(tgContext, target, fourPos, seedDir, straightQoverP,
352 initialCov, Acts::ParticleHypothesis::muon());
353 if (!initialPars.ok()) {
355 saveDisplay(
"invalidPars");
360 Acts::ViewConfig{.color={0,220,0}});
363 <<
", "<<std::format(
"theta: {:.2f}, ", (*initialPars).theta() / 1._degree)
364 <<std::format(
"phi: {:.2f}", (*initialPars).phi() / 1._degree));
366 std::vector<Acts::SourceLink> sourceLinks{};
367 std::ranges::transform(hitsToFit, std::back_inserter(sourceLinks),
371 fitOptions.referenceSurface = target.get();
373 auto fitTraject =
m_fitter->fit(sourceLinks.begin(), sourceLinks.end(),
374 *initialPars, fitOptions, tracks);
375 if (!fitTraject.ok()) {
376 saveDisplay(
"failed");
381 ATH_MSG_ERROR(
"Segment refit failed. Albeit start parameters are taken from segment");
382 return StatusCode::FAILURE;
386 auto track = *fitTraject;
389 Acts::BoundTrackParameters parameters = track.createParametersAtReference();
392 Acts::ViewConfig{.color={0,220,220}});
395 saveDisplay(
"goodone");
399 std::vector<const xAOD::UncalibratedMeasurement*> goodMeas{};
401 tracks.trackStateContainer().visitBackwards(track.tipIndex(),[&](
const auto& state){
402 if (!state.hasUncalibratedSourceLink()){
405 goodMeas.insert(goodMeas.begin(),
417 summary.nPrecHits += isPrecHit;
422 summary.nEtaTrigHits += !isPrecHit;
430 const Amg::Vector3D refitPos = globToLoc * parameters.position(tgContext);
434 const Amg::Vector3D globPos{msSector->localToGlobalTransform(gctx) * refitSeg};
436 xAOD::MuonSegment* newSegment = outHandle->push_back(std::make_unique<xAOD::MuonSegment>());
437 dec_segLink(*newSegment) = Link_t{*segments, reFitMe->index(), ctx};
439 newSegment->
setDirection(globDir.x(), globDir.y(), globDir.z());
440 newSegment->
setPosition(globPos.x(), globPos.y(), globPos.z());
443 newSegment->
setNHits(summary.nPrecHits, summary.nPhiHits, summary.nEtaTrigHits);
444 auto& locFitPars = dec_locPars(*newSegment);
445 locFitPars[Acts::toUnderlying(ParamDefs::x0)] = refitSeg.x();
446 locFitPars[Acts::toUnderlying(ParamDefs::y0)] = refitSeg.y();
447 locFitPars[Acts::toUnderlying(ParamDefs::theta)] = refitDir.theta();
448 locFitPars[Acts::toUnderlying(ParamDefs::phi)] = refitDir.phi();
450 return StatusCode::SUCCESS;