FairShip
Loading...
Searching...
No Matches
SHiP::ActsStrawTracker::Impl Struct Reference
Collaboration diagram for SHiP::ActsStrawTracker::Impl:
[legend]

Public Member Functions

 Impl (const TGeoManager &geometry, TVirtualMagField *magField)
std::vector< PatRecHit > patRecHits (const std::vector< Int_t > &indices) const
 Hits for the pattern recognition, from measurement indices.
Acts::BoundTrackParameters seed (const TrackCandidate &candidate, const StrawMeasurement &first) const
 Seed for the fit of a candidate, on the surface of its first hit.
Int_t fit (const TrackCandidate &candidate, const std::vector< PatRecHit > &hits)
std::optional< std::size_t > fitOnce (const std::vector< Int_t > &indices, const Acts::BoundTrackParameters &start)
 One Kalman fit of the given measurements, appended to the tracks.
std::pair< double, double > fieldIntegral (const LineSegment &line) const
const Acts::Surface * surfaceOf (const Acts::SourceLink &sourceLink) const
void calibrate (const Acts::GeometryContext &, const Acts::CalibrationContext &, const Acts::SourceLink &sourceLink, Trajectory::TrackStateProxy state) const
Acts::BoundTrackParameters trackParameters (Int_t track) const
std::optional< Acts::BoundTrackParameters > extrapolate (const Extrapolator &propagator, const Acts::BoundTrackParameters &start, const Acts::Surface &target) const
 Propagate to target in whichever direction reaches it.

Public Attributes

ActsStrawGeometry straws
TVirtualMagField * shipField
std::shared_ptr< const ActsShipField > field
double magnetStart = -std::numeric_limits<double>::infinity()
double magnetEnd = std::numeric_limits<double>::infinity()
std::optional< StrawPatRec > patRec
KalmanFitter fitter
Extrapolator extrapolator
Acts::GainMatrixUpdater updater
Acts::GainMatrixSmoother smoother
Acts::KalmanFitterExtensions< Trajectory > extensions
Acts::GeometryContext gctx
Acts::MagneticFieldContext mctx
Acts::CalibrationContext cctx
std::vector< StrawMeasurement > measurements
TrackContainer tracks
std::vector< std::vector< Int_t > > trackMeasurements
 Measurements used in each track.

Detailed Description

Definition at line 256 of file ActsStrawTracker.cxx.

Constructor & Destructor Documentation

◆ Impl()

SHiP::ActsStrawTracker::Impl::Impl ( const TGeoManager & geometry,
TVirtualMagField * magField )
inline

Definition at line 257 of file ActsStrawTracker.cxx.

258 : straws(geometry),
259 shipField(magField),
260 field(std::make_shared<ActsShipField>(magField)),
261 fitter(DirectPropagator(Stepper(field), Acts::DirectNavigator(),
262 Acts::getDefaultLogger("Propagator",
263 Acts::Logging::WARNING)),
264 Acts::getDefaultLogger("KalmanFitter", Acts::Logging::WARNING)),
266 Stepper(field), Acts::VoidNavigator(),
267 Acts::getDefaultLogger("Extrapolator", Acts::Logging::WARNING)),
268 tracks(std::make_shared<Acts::VectorTrackContainer>(),
269 std::make_shared<Trajectory>()) {
270 extensions.surfaceAccessor.connect<&Impl::surfaceOf>(this);
271 extensions.calibrator.connect<&Impl::calibrate>(this);
272 extensions.updater
273 .connect<&Acts::GainMatrixUpdater::operator()<Trajectory>>(&updater);
274 extensions.smoother
275 .connect<&Acts::GainMatrixSmoother::operator()<Trajectory>>(&smoother);
276
277 // The magnet sits between stations 2 and 3
278 for (const auto& [id, wire] : straws.wires()) {
279 if (wire.station == 2) {
280 magnetStart = std::max(magnetStart, wire.z);
281 } else if (wire.station == 3) {
282 magnetEnd = std::min(magnetEnd, wire.z);
283 }
284 }
285 LineSegment axis;
286 const auto [integral, centre] = fieldIntegral(axis);
287 patRec.emplace(StrawPatRec::Config{}, centre, integral);
288 }
Acts::GainMatrixSmoother smoother
std::pair< double, double > fieldIntegral(const LineSegment &line) const
std::shared_ptr< const ActsShipField > field
void calibrate(const Acts::GeometryContext &, const Acts::CalibrationContext &, const Acts::SourceLink &sourceLink, Trajectory::TrackStateProxy state) const
const Acts::Surface * surfaceOf(const Acts::SourceLink &sourceLink) const
std::optional< StrawPatRec > patRec
Acts::KalmanFitterExtensions< Trajectory > extensions
Acts::GainMatrixUpdater updater

Member Function Documentation

◆ calibrate()

void SHiP::ActsStrawTracker::Impl::calibrate ( const Acts::GeometryContext & ,
const Acts::CalibrationContext & ,
const Acts::SourceLink & sourceLink,
Trajectory::TrackStateProxy state ) const
inline

Definition at line 326 of file ActsStrawTracker.cxx.

329 {
330 const auto& measurement = measurements.at(sourceLink.get<std::size_t>());
331 state.allocateCalibrated(1);
332 state.template calibrated<1>()(0) =
333 measurement.sign * measurement.driftRadius;
334 state.template calibratedCovariance<1>()(0, 0) = measurement.variance;
335 state.setProjectorSubspaceIndices(std::array{Acts::eBoundLoc0});
336 state.setUncalibratedSourceLink(Acts::SourceLink(sourceLink));
337 }
std::vector< StrawMeasurement > measurements

◆ extrapolate()

std::optional< Acts::BoundTrackParameters > SHiP::ActsStrawTracker::Impl::extrapolate ( const Extrapolator & propagator,
const Acts::BoundTrackParameters & start,
const Acts::Surface & target ) const
inline

Propagate to target in whichever direction reaches it.

Definition at line 347 of file ActsStrawTracker.cxx.

349 {
350 for (const auto direction :
351 {Acts::Direction::Forward(), Acts::Direction::Backward()}) {
352 Extrapolator::Options<> options(gctx, mctx);
353 options.pathLimit = kPathLimit;
354 options.direction = direction;
355 auto result = propagator.propagate(start, target, options);
356 if (result.ok() && result.value().endParameters.has_value()) {
357 return result.value().endParameters.value();
358 }
359 }
360 return std::nullopt;
361 }
Acts::MagneticFieldContext mctx

◆ fieldIntegral()

std::pair< double, double > SHiP::ActsStrawTracker::Impl::fieldIntegral ( const LineSegment & line) const
inline

Integral of Bx along a straight line through the magnet (T m), and the z of its centre (cm)

Definition at line 305 of file ActsStrawTracker.cxx.

305 {
306 double integral = 0.;
307 double moment = 0.;
308 for (double z = magnetStart; z < magnetEnd; z += kFieldStep) {
309 const double zMid = z + kFieldStep / 2.;
310 const double x[3] = {line.x(zMid), line.y(zMid), zMid};
311 double b[3] = {0., 0., 0.};
312 shipField->Field(x, b);
313 // kGauss to T, cm to m
314 const double bx = 0.1 * b[0] * 0.01 * kFieldStep;
315 integral += bx;
316 moment += bx * zMid;
317 }
318 return {integral, integral != 0. ? moment / integral
319 : 0.5 * (magnetStart + magnetEnd)};
320 }

◆ fit()

Int_t SHiP::ActsStrawTracker::Impl::fit ( const TrackCandidate & candidate,
const std::vector< PatRecHit > & hits )

Fit a candidate, refining the sides of the wires and dropping outliers; returns the track index or -1

Definition at line 495 of file ActsStrawTracker.cxx.

496 {
497 // The measurements, ordered in z, with the sides of the wires from the
498 // segment fits
499 std::vector<std::pair<double, Int_t>> ordered;
500 for (const LineSegment* segment :
501 {&candidate.upstream, &candidate.downstream}) {
502 for (std::size_t k = 0; k < segment->hits.size(); ++k) {
503 const PatRecHit& hit = hits[segment->hits[k]];
504 measurements[hit.index].sign = segment->signs[k];
505 ordered.emplace_back(hit.wire->z, hit.index);
506 }
507 }
508 std::sort(ordered.begin(), ordered.end());
509 std::vector<Int_t> indices;
510 for (const auto& [z, index] : ordered) {
511 indices.push_back(index);
512 }
513
514 // Momentum from the kink, with the field integral along this track
515 TrackCandidate refined = candidate;
516 const auto [integral, centre] = fieldIntegral(candidate.upstream);
517 const double kink = candidate.downstream.ty - candidate.upstream.ty;
518 if (integral != 0. && kink != 0.) {
519 const LineSegment& up = candidate.upstream;
520 const double pz =
521 std::min(std::abs(kKick * integral / kink), kMaxSeedMomentum);
522 refined.momentum = pz * std::sqrt(1. + up.tx * up.tx + up.ty * up.ty);
523 refined.charge = kink / integral > 0. ? 1 : -1;
524 }
525 Acts::BoundTrackParameters start =
526 seed(refined, measurements[indices.front()]);
527
528 for (int refit = 0;; ++refit) {
529 if (static_cast<int>(indices.size()) < kMinFitMeasurements) {
530 return -1;
531 }
532 const auto track = fitOnce(indices, start);
533 if (!track) {
534 return -1;
535 }
536 // Check each hit against the fitted track: take the side of the wire it
537 // passes on, and drop hits that are too far from it
538 bool changed = false;
539 std::vector<std::pair<double, Int_t>> kept;
540 const auto proxy = tracks.getTrack(*track);
541 for (const auto state : proxy.trackStatesReversed()) {
542 if (!state.hasUncalibratedSourceLink() || !state.hasSmoothed()) {
543 continue;
544 }
545 const auto index = static_cast<Int_t>(
546 state.getUncalibratedSourceLink().template get<std::size_t>());
547 auto& m = measurements[index];
548 const double predicted = state.smoothed()[Acts::eBoundLoc0];
549 const double sigma =
550 std::sqrt(m.variance + state.smoothedCovariance()(Acts::eBoundLoc0,
551 Acts::eBoundLoc0));
552 if (std::abs(std::abs(predicted) - m.driftRadius) >
553 kOutlierPull * sigma) {
554 changed = true;
555 continue;
556 }
557 const int side = predicted >= 0. ? 1 : -1;
558 if (side != m.sign && std::abs(predicted) > std::sqrt(m.variance)) {
559 m.sign = side;
560 changed = true;
561 }
562 kept.emplace_back(m.wire->z, index);
563 }
564 if (!changed || refit == kMaxRefits) {
565 trackMeasurements.push_back(indices);
566 return static_cast<Int_t>(*track);
567 }
568 // Refit from the fitted parameters, with the seed uncertainties so the
569 // previous fit does not bias the next
570 auto params = proxy.createParametersAtReference();
571 start = Acts::BoundTrackParameters(
572 params.referenceSurface().getSharedPtr(), params.parameters(),
573 seed(refined, measurements[indices.front()]).covariance(),
574 params.particleHypothesis());
575 tracks.removeTrack(*track);
576 std::sort(kept.begin(), kept.end());
577 indices.clear();
578 for (const auto& [z, index] : kept) {
579 indices.push_back(index);
580 }
581 }
582}
constexpr Double_t m
std::vector< std::vector< Int_t > > trackMeasurements
Measurements used in each track.
std::optional< std::size_t > fitOnce(const std::vector< Int_t > &indices, const Acts::BoundTrackParameters &start)
One Kalman fit of the given measurements, appended to the tracks.
Acts::BoundTrackParameters seed(const TrackCandidate &candidate, const StrawMeasurement &first) const
Seed for the fit of a candidate, on the surface of its first hit.

◆ fitOnce()

std::optional< std::size_t > SHiP::ActsStrawTracker::Impl::fitOnce ( const std::vector< Int_t > & indices,
const Acts::BoundTrackParameters & start )

One Kalman fit of the given measurements, appended to the tracks.

Definition at line 466 of file ActsStrawTracker.cxx.

468 {
469 std::vector<Acts::SourceLink> sourceLinks;
470 std::vector<const Acts::Surface*> surfaces;
471 for (const Int_t index : indices) {
472 sourceLinks.emplace_back(static_cast<std::size_t>(index));
473 surfaces.push_back(measurements[index].surface);
474 }
475 Acts::PropagatorPlainOptions propagatorOptions(gctx, mctx);
476 Acts::KalmanFitterOptions<Trajectory> options(gctx, mctx, std::cref(cctx),
477 extensions, propagatorOptions,
478 surfaces.front());
479 options.referenceSurfaceStrategy = Acts::TrackExtrapolationStrategy::first;
480
481 const std::size_t nTracksBefore = tracks.size();
482 auto result = fitter.fit(sourceLinks.begin(), sourceLinks.end(), start,
483 options, surfaces, tracks);
484 if (!result.ok() || !result.value().hasReferenceSurface()) {
485 // A failed fit may leave a partial track behind. Drop it, so that track
486 // indices stay contiguous.
487 while (tracks.size() > nTracksBefore) {
488 tracks.removeTrack(tracks.size() - 1);
489 }
490 return std::nullopt;
491 }
492 return result.value().index();
493}
Acts::CalibrationContext cctx

◆ patRecHits()

std::vector< PatRecHit > SHiP::ActsStrawTracker::Impl::patRecHits ( const std::vector< Int_t > & indices) const

Hits for the pattern recognition, from measurement indices.

Definition at line 414 of file ActsStrawTracker.cxx.

415 {
416 std::vector<PatRecHit> hits;
417 hits.reserve(indices.size());
418 for (const Int_t index : indices) {
419 if (index < 0 || static_cast<std::size_t>(index) >= measurements.size()) {
420 throw std::out_of_range("ActsStrawTracker: measurement out of range");
421 }
422 const auto& m = measurements[index];
423 hits.push_back({index, m.wire, m.driftRadius / ActsFrame::kShipLength,
424 std::sqrt(m.variance) / ActsFrame::kShipLength});
425 }
426 return hits;
427}
constexpr double kShipLength
Length unit of the SHiP frame, in ACTS units.
Definition ActsFrame.hpp:36

◆ seed()

Acts::BoundTrackParameters SHiP::ActsStrawTracker::Impl::seed ( const TrackCandidate & candidate,
const StrawMeasurement & first ) const

Seed for the fit of a candidate, on the surface of its first hit.

Definition at line 429 of file ActsStrawTracker.cxx.

430 {
431 const LineSegment& line = candidate.upstream;
432 const double z = first.wire->z;
433 const Acts::Vector3 position =
434 ActsFrame::positionToActs(line.x(z), line.y(z), z);
435 const Acts::Vector3 direction =
436 (ActsFrame::toActsRotation() * Acts::Vector3(line.tx, line.ty, 1.))
437 .normalized();
438 const auto hypothesis = Acts::ParticleHypothesis::muon();
439 const double qOverP = hypothesis.qOverP(
440 candidate.momentum * u::GeV, static_cast<double>(candidate.charge));
441
442 // Local coordinates at the point of closest approach to the first straw
443 const Acts::Surface& surface = *first.surface;
444 const auto intersection =
445 surface.intersect(gctx, position, direction).closest();
446 const Acts::Vector3 onSurface =
447 intersection.isValid() ? intersection.position() : position;
448 auto local = surface.globalToLocal(gctx, onSurface, direction);
449 const Acts::Vector2 localPosition =
450 local.ok() ? local.value() : Acts::Vector2::Zero();
451
452 Acts::BoundVector parameters = Acts::BoundVector::Zero();
453 parameters[Acts::eBoundLoc0] = localPosition[0];
454 parameters[Acts::eBoundLoc1] = localPosition[1];
455 parameters[Acts::eBoundPhi] = Acts::VectorHelpers::phi(direction);
456 parameters[Acts::eBoundTheta] = Acts::VectorHelpers::theta(direction);
457 parameters[Acts::eBoundQOverP] = qOverP;
458 Acts::BoundVector sigmas;
459 sigmas << kSeedSigmaLoc0, kSeedSigmaLoc1, kSeedSigmaAngle, kSeedSigmaAngle,
460 kSeedRelativeSigmaP * std::abs(qOverP), kSeedSigmaTime;
461 const Acts::BoundMatrix covariance = sigmas.cwiseProduct(sigmas).asDiagonal();
462 return Acts::BoundTrackParameters(surface.getSharedPtr(), parameters,
463 covariance, hypothesis);
464}
Acts::RotationMatrix3 toActsRotation()
Rotation taking SHiP-frame vectors to the ACTS frame.
Definition ActsFrame.hpp:31
Acts::Vector3 positionToActs(double x, double y, double z)
Definition ActsFrame.hpp:38

◆ surfaceOf()

const Acts::Surface * SHiP::ActsStrawTracker::Impl::surfaceOf ( const Acts::SourceLink & sourceLink) const
inline

Definition at line 322 of file ActsStrawTracker.cxx.

322 {
323 return measurements.at(sourceLink.get<std::size_t>()).surface;
324 }

◆ trackParameters()

Acts::BoundTrackParameters SHiP::ActsStrawTracker::Impl::trackParameters ( Int_t track) const
inline

Definition at line 339 of file ActsStrawTracker.cxx.

339 {
340 if (track < 0 || static_cast<std::size_t>(track) >= tracks.size()) {
341 throw std::out_of_range("ActsStrawTracker: track index out of range");
342 }
343 return tracks.getTrack(track).createParametersAtReference();
344 }

Member Data Documentation

◆ cctx

Acts::CalibrationContext SHiP::ActsStrawTracker::Impl::cctx

Definition at line 377 of file ActsStrawTracker.cxx.

◆ extensions

Acts::KalmanFitterExtensions<Trajectory> SHiP::ActsStrawTracker::Impl::extensions

Definition at line 373 of file ActsStrawTracker.cxx.

◆ extrapolator

Extrapolator SHiP::ActsStrawTracker::Impl::extrapolator

Definition at line 370 of file ActsStrawTracker.cxx.

◆ field

std::shared_ptr<const ActsShipField> SHiP::ActsStrawTracker::Impl::field

Definition at line 365 of file ActsStrawTracker.cxx.

◆ fitter

KalmanFitter SHiP::ActsStrawTracker::Impl::fitter

Definition at line 369 of file ActsStrawTracker.cxx.

◆ gctx

Acts::GeometryContext SHiP::ActsStrawTracker::Impl::gctx
Initial value:
=
Acts::GeometryContext::dangerouslyDefaultConstruct()

Definition at line 374 of file ActsStrawTracker.cxx.

◆ magnetEnd

double SHiP::ActsStrawTracker::Impl::magnetEnd = std::numeric_limits<double>::infinity()

Definition at line 367 of file ActsStrawTracker.cxx.

◆ magnetStart

double SHiP::ActsStrawTracker::Impl::magnetStart = -std::numeric_limits<double>::infinity()

Definition at line 366 of file ActsStrawTracker.cxx.

◆ mctx

Acts::MagneticFieldContext SHiP::ActsStrawTracker::Impl::mctx

Definition at line 376 of file ActsStrawTracker.cxx.

◆ measurements

std::vector<StrawMeasurement> SHiP::ActsStrawTracker::Impl::measurements

Definition at line 378 of file ActsStrawTracker.cxx.

◆ patRec

std::optional<StrawPatRec> SHiP::ActsStrawTracker::Impl::patRec

Definition at line 368 of file ActsStrawTracker.cxx.

◆ shipField

TVirtualMagField* SHiP::ActsStrawTracker::Impl::shipField

Definition at line 364 of file ActsStrawTracker.cxx.

◆ smoother

Acts::GainMatrixSmoother SHiP::ActsStrawTracker::Impl::smoother

Definition at line 372 of file ActsStrawTracker.cxx.

◆ straws

ActsStrawGeometry SHiP::ActsStrawTracker::Impl::straws

Definition at line 363 of file ActsStrawTracker.cxx.

◆ trackMeasurements

std::vector<std::vector<Int_t> > SHiP::ActsStrawTracker::Impl::trackMeasurements

Measurements used in each track.

Definition at line 381 of file ActsStrawTracker.cxx.

◆ tracks

TrackContainer SHiP::ActsStrawTracker::Impl::tracks

Definition at line 379 of file ActsStrawTracker.cxx.

◆ updater

Acts::GainMatrixUpdater SHiP::ActsStrawTracker::Impl::updater

Definition at line 371 of file ActsStrawTracker.cxx.


The documentation for this struct was generated from the following file: