From 03a867e5b2c21e6ab7fc555c6bec4e5457c85d25 Mon Sep 17 00:00:00 2001 From: Tim Adye Date: Tue, 6 Feb 2024 18:43:47 +0000 Subject: [PATCH] full_chain_itk.py uses eta-dependent cuts and maxHoles, maxSharedHits --- .../Python/python/acts/examples/__init__.py | 1 + .../python/acts/examples/reconstruction.py | 77 +++++++++++++------ Examples/Python/src/ExampleAlgorithms.cpp | 6 ++ Examples/Scripts/Python/full_chain_itk.py | 8 +- 4 files changed, 64 insertions(+), 28 deletions(-) diff --git a/Examples/Python/python/acts/examples/__init__.py b/Examples/Python/python/acts/examples/__init__.py index be85a28e0f1..03021dc1899 100644 --- a/Examples/Python/python/acts/examples/__init__.py +++ b/Examples/Python/python/acts/examples/__init__.py @@ -159,6 +159,7 @@ def NamedTypeArgsWrapper(*args, **kwargs): cls is not None and v is not None and type(v).__module__ == int.__module__ # is v a 'builtins'? + and not (issubclass(type(v), Iterable) and all(type(e) is cls for e in v)) # not [cls] ): if issubclass(cls, Iterable): kwargs[k] = cls(*v) diff --git a/Examples/Python/python/acts/examples/reconstruction.py b/Examples/Python/python/acts/examples/reconstruction.py index a555061afd0..ab12a9d5871 100644 --- a/Examples/Python/python/acts/examples/reconstruction.py +++ b/Examples/Python/python/acts/examples/reconstruction.py @@ -125,9 +125,13 @@ "pt", "phi", "nMeasurementsMin", + "maxHoles", + "maxOutliers", + "maxSharedHits", + "maxChi2", "nMeasurementsGroupMin", ], - defaults=[(None, None)] * 7 + [None] * 2, + defaults=[(None, None)] * 7 + [None] * 6, ) CkfConfig = namedtuple( @@ -1125,7 +1129,7 @@ def addCKFTracks( s: acts.examples.Sequencer, trackingGeometry: acts.TrackingGeometry, field: acts.MagneticFieldProvider, - trackSelectorConfig: Optional[TrackSelectorConfig] = None, + trackSelectorConfig: Optional[Union[TrackSelectorConfig, List[TrackSelectorConfig]]] = None, ckfConfig: CkfConfig = CkfConfig(), outputDirCsv: Optional[Union[Path, str]] = None, outputDirRoot: Optional[Union[Path, str]] = None, @@ -1154,6 +1158,52 @@ def addCKFTracks( customLogLevel = acts.examples.defaultLogging(s, logLevel) + tslist = ( + [] + if trackSelectorConfig is None + else ( + [trackSelectorConfig] + if type(trackSelectorConfig) is TrackSelectorConfig + else trackSelectorConfig + ) + ) + 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, + maxSharedHits=c.maxSharedHits, + maxChi2=c.maxChi2, + measurementCounter=c.nMeasurementsGroupMin, + ) + ) + for c in tslist + ] + if len(tslist) == 0: + trkSelCfg = None + elif len(tslist) == 1: + trkSelCfg = cutSets[0] + else: + trkSelCfg = acts.TrackSelector.EtaBinnedConfig( + cutSets=cutSets, + absEtaEdges=[cutSets[0].absEtaMin] + [c.absEta[1] for c in tslist], + ) + # Setup the track finding algorithm with CKF # It takes all the source links created from truth hit smearing, seeds from # truth particle smearing and source link selection config @@ -1171,28 +1221,7 @@ def addCKFTracks( ) ] ), - trackSelectorCfg=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, - measurementCounter=trackSelectorConfig.nMeasurementsGroupMin, - ) - ) - if trackSelectorConfig is not None - else None, + trackSelectorCfg=trkSelCfg, inputMeasurements="measurements", inputSourceLinks="sourcelinks", inputInitialTrackParameters="estimatedparameters", diff --git a/Examples/Python/src/ExampleAlgorithms.cpp b/Examples/Python/src/ExampleAlgorithms.cpp index 513f20d7587..71d93d7f684 100644 --- a/Examples/Python/src/ExampleAlgorithms.cpp +++ b/Examples/Python/src/ExampleAlgorithms.cpp @@ -109,6 +109,10 @@ void addExampleAlgorithms(Context& ctx) { ACTS_PYTHON_MEMBER(ptMin); ACTS_PYTHON_MEMBER(ptMax); ACTS_PYTHON_MEMBER(minMeasurements); + ACTS_PYTHON_MEMBER(maxHoles); + ACTS_PYTHON_MEMBER(maxOutliers); + ACTS_PYTHON_MEMBER(maxSharedHits); + ACTS_PYTHON_MEMBER(maxChi2); ACTS_PYTHON_MEMBER(measurementCounter); ACTS_PYTHON_STRUCT_END(); @@ -126,6 +130,8 @@ void addExampleAlgorithms(Context& ctx) { .def(py::init<>()) .def(py::init()); + patchKwargsConstructor(c); + c.def_property_readonly("nEtaBins", &EtaBinnedConfig::nEtaBins); ACTS_PYTHON_STRUCT_BEGIN(c, EtaBinnedConfig); diff --git a/Examples/Scripts/Python/full_chain_itk.py b/Examples/Scripts/Python/full_chain_itk.py index 8af61383af7..feb5152b51d 100755 --- a/Examples/Scripts/Python/full_chain_itk.py +++ b/Examples/Scripts/Python/full_chain_itk.py @@ -109,10 +109,10 @@ s, trackingGeometry, field, - TrackSelectorConfig( - pt=(1.0 * u.GeV if ttbar_pu200 else 0.0, None), - absEta=(None, 4.0), - nMeasurementsMin=6, + trackSelectorConfig=( + TrackSelectorConfig(absEta=(None, 2.0), pt=(0.9 * u.GeV, None), nMeasurementsMin=9, maxHoles=2, maxSharedHits=2), + TrackSelectorConfig(absEta=(None, 2.6), pt=(0.4 * u.GeV, None), nMeasurementsMin=8, maxHoles=2, maxSharedHits=2), + TrackSelectorConfig(absEta=(None, 4.0), pt=(0.4 * u.GeV, None), nMeasurementsMin=7, maxHoles=2, maxSharedHits=2), ), outputDirRoot=outputDir, )