diff --git a/Core/include/Acts/TrackFinding/TrackSelector.hpp b/Core/include/Acts/TrackFinding/TrackSelector.hpp index 459ab996857..6d938c03085 100644 --- a/Core/include/Acts/TrackFinding/TrackSelector.hpp +++ b/Core/include/Acts/TrackFinding/TrackSelector.hpp @@ -80,6 +80,10 @@ class TrackSelector { std::size_t maxSharedHits = std::numeric_limits::max(); double maxChi2 = inf; + /// Whether a reference surface is required for the track + /// If false, the parameter cuts are not evaluated + bool requireReferenceSurface = true; + // Defaults to: no cut MeasurementCounter measurementCounter; @@ -439,22 +443,33 @@ bool TrackSelector::isValidTrack(const track_proxy_t& track) const { const Config& cuts = *cutsPtr; - return track.hasReferenceSurface() && - within(track.transverseMomentum(), cuts.ptMin, cuts.ptMax) && - (!m_isUnbinned || (within(absEta(), cuts.absEtaMin, cuts.absEtaMax) && - within(_eta, cuts.etaMin, cuts.etaMax))) && - within(track.phi(), cuts.phiMin, cuts.phiMax) && - within(track.loc0(), cuts.loc0Min, cuts.loc0Max) && - within(track.loc1(), cuts.loc1Min, cuts.loc1Max) && - within(track.time(), cuts.timeMin, cuts.timeMax) && - checkMin(track.nMeasurements(), cuts.minMeasurements) && - checkMax(track.nHoles(), cuts.maxHoles) && - checkMax(track.nOutliers(), cuts.maxOutliers) && - checkMax(track.nHoles() + track.nOutliers(), - cuts.maxHolesAndOutliers) && - checkMax(track.nSharedHits(), cuts.maxSharedHits) && - checkMax(track.chi2(), cuts.maxChi2) && - cuts.measurementCounter.isValidTrack(track); + auto parameterCuts = [&]() { + return within(track.transverseMomentum(), cuts.ptMin, cuts.ptMax) && + (!m_isUnbinned || + (within(absEta(), cuts.absEtaMin, cuts.absEtaMax) && + within(_eta, cuts.etaMin, cuts.etaMax))) && + within(track.phi(), cuts.phiMin, cuts.phiMax) && + within(track.loc0(), cuts.loc0Min, cuts.loc0Max) && + within(track.loc1(), cuts.loc1Min, cuts.loc1Max) && + within(track.time(), cuts.timeMin, cuts.timeMax); + }; + + auto trackCuts = [&]() { + return checkMin(track.nMeasurements(), cuts.minMeasurements) && + checkMax(track.nHoles(), cuts.maxHoles) && + checkMax(track.nOutliers(), cuts.maxOutliers) && + checkMax(track.nHoles() + track.nOutliers(), + cuts.maxHolesAndOutliers) && + checkMax(track.nSharedHits(), cuts.maxSharedHits) && + checkMax(track.chi2(), cuts.maxChi2) && + cuts.measurementCounter.isValidTrack(track); + }; + + if (cuts.requireReferenceSurface) { + return track.hasReferenceSurface() && parameterCuts() && trackCuts(); + } else { + return trackCuts(); + } } inline TrackSelector::TrackSelector( diff --git a/Examples/Python/python/acts/examples/reconstruction.py b/Examples/Python/python/acts/examples/reconstruction.py index fd02c6bddac..922f5da55fc 100644 --- a/Examples/Python/python/acts/examples/reconstruction.py +++ b/Examples/Python/python/acts/examples/reconstruction.py @@ -123,10 +123,42 @@ "maxSharedHits", "maxChi2", "nMeasurementsGroupMin", + "requireReferenceSurface", ], - defaults=[(None, None)] * 7 + [None] * 7, + defaults=[(None, None)] * 7 + [None] * 8, ) + +def trackSelectorDefaultKWArgs(c): + """ + Encapsulate this boilerplate code into a function so different uses do not get out of sync + """ + return acts.examples.defaultKWArgs( + loc0Min=c.loc0[0], + loc0Max=c.loc0[1], + loc1Min=c.loc1[0], + loc1Max=c.loc1[1], + timeMin=c.time[0], + timeMax=c.time[1], + phiMin=c.phi[0], + phiMax=c.phi[1], + etaMin=c.eta[0], + etaMax=c.eta[1], + absEtaMin=c.absEta[0], + absEtaMax=c.absEta[1], + ptMin=c.pt[0], + ptMax=c.pt[1], + minMeasurements=c.nMeasurementsMin, + maxHoles=c.maxHoles, + maxOutliers=c.maxOutliers, + maxHolesAndOutliers=c.maxHolesAndOutliers, + maxSharedHits=c.maxSharedHits, + maxChi2=c.maxChi2, + measurementCounter=c.nMeasurementsGroupMin, + requireReferenceSurface=c.requireReferenceSurface, + ) + + CkfConfig = namedtuple( "CkfConfig", [ @@ -1418,32 +1450,10 @@ def addCKFTracks( else trackSelectorConfig ) ) + + overwriteArgs = dict() if len(tslist) == 1 else dict(absEtaMax=None) cutSets = [ - acts.TrackSelector.Config( - **acts.examples.defaultKWArgs( - loc0Min=c.loc0[0], - loc0Max=c.loc0[1], - loc1Min=c.loc1[0], - loc1Max=c.loc1[1], - timeMin=c.time[0], - timeMax=c.time[1], - phiMin=c.phi[0], - phiMax=c.phi[1], - etaMin=c.eta[0], - etaMax=c.eta[1], - absEtaMin=c.absEta[0], - absEtaMax=c.absEta[1] if len(tslist) == 1 else None, - ptMin=c.pt[0], - ptMax=c.pt[1], - minMeasurements=c.nMeasurementsMin, - maxHoles=c.maxHoles, - maxOutliers=c.maxOutliers, - maxHolesAndOutliers=c.maxHolesAndOutliers, - maxSharedHits=c.maxSharedHits, - maxChi2=c.maxChi2, - measurementCounter=c.nMeasurementsGroupMin, - ) - ) + acts.TrackSelector.Config(trackSelectorDefaultKWArgs(c).update(overwriteArgs)) for c in tslist ] if len(tslist) == 0: @@ -1696,23 +1706,7 @@ def addTrackSelection( # single cut config for implicit single bin eta configuration selectorConfig = acts.TrackSelector.Config( - **acts.examples.defaultKWArgs( - loc0Min=trackSelectorConfig.loc0[0], - loc0Max=trackSelectorConfig.loc0[1], - loc1Min=trackSelectorConfig.loc1[0], - loc1Max=trackSelectorConfig.loc1[1], - timeMin=trackSelectorConfig.time[0], - timeMax=trackSelectorConfig.time[1], - phiMin=trackSelectorConfig.phi[0], - phiMax=trackSelectorConfig.phi[1], - etaMin=trackSelectorConfig.eta[0], - etaMax=trackSelectorConfig.eta[1], - absEtaMin=trackSelectorConfig.absEta[0], - absEtaMax=trackSelectorConfig.absEta[1], - ptMin=trackSelectorConfig.pt[0], - ptMax=trackSelectorConfig.pt[1], - minMeasurements=trackSelectorConfig.nMeasurementsMin, - ) + trackSelectorDefaultKWArgs(trackSelectorConfig) ) trackSelector = acts.examples.TrackSelectorAlgorithm( diff --git a/Examples/Python/src/ExampleAlgorithms.cpp b/Examples/Python/src/ExampleAlgorithms.cpp index 598dde87b99..15e407a651c 100644 --- a/Examples/Python/src/ExampleAlgorithms.cpp +++ b/Examples/Python/src/ExampleAlgorithms.cpp @@ -109,6 +109,7 @@ void addExampleAlgorithms(Context& ctx) { ACTS_PYTHON_MEMBER(maxSharedHits); ACTS_PYTHON_MEMBER(maxChi2); ACTS_PYTHON_MEMBER(measurementCounter); + ACTS_PYTHON_MEMBER(requireReferenceSurface); ACTS_PYTHON_STRUCT_END(); pythonRangeProperty(c, "loc0", &Config::loc0Min, &Config::loc0Max);