ATLAS Offline Software
Loading...
Searching...
No Matches
AtlasMeasurementSelector.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
6
9
10#include "Acts/Definitions/Common.hpp"
11#include "Acts/Definitions/Algebra.hpp"
12#include "Acts/Utilities/VectorHelpers.hpp"
13#include "Acts/Utilities/Delegate.hpp"
14#include "Acts/Utilities/Result.hpp"
15#include "Acts/Geometry/GeometryContext.hpp"
16#include "Acts/Utilities/CalibrationContext.hpp"
17#include "Acts/EventData/BoundTrackParameters.hpp"
18#include "Acts/Surfaces/Surface.hpp"
19#include "Acts/Utilities/Logger.hpp"
20#include "Acts/TrackFinding/CombinatorialKalmanFilter.hpp"
21#include "Acts/TrackFinding/TrackStateCreator.hpp"
22#include "Acts/Surfaces/BoundaryTolerance.hpp"
23
29
34
35#include "boost/container/small_vector.hpp"
36
37#include <tuple>
38#include <type_traits>
39#include <span>
40#include <ranges>
41
43
44template <std::size_t NMeasMax, typename traj_t, typename measurement_container_variant_t>
46
47static constexpr bool s_fullPreCalibration=true;
48
49// need an "Eigen Map" which is default constructable and assignable
50// and where an assignment changes the data pointer not the contents of
51// the data it was pointing to.
52template <std::size_t DIM>
54 ConstVectorMapWithInvalidDef() : xAOD::ConstVectorMap<DIM>{nullptr} {}
56 this->m_data = a.m_data;
57 return *this;
58 }
60 this->m_data = a.m_data;
61 return *this;
62 }
64 this->m_data = a.data();
65 return *this;
66 }
67 using xAOD::ConstVectorMap<DIM>::ConstVectorMap;
68};
69
70// see above
71template <std::size_t DIM>
73 ConstMatrixMapWithInvalidDef() : xAOD::ConstMatrixMap<DIM>{nullptr} {}
75 this->m_data = a.m_data;
76 return *this;
77 }
79 this->m_data = a.m_data;
80 return *this;
81 }
83 this->m_data = a.data();
84 return *this;
85 }
86 using xAOD::ConstMatrixMap<DIM>::ConstMatrixMap;
87};
88
93template <std::size_t NMeasMax, typename traj_t, typename measurement_container_variant_t>
94struct MeasurementSelectorTraits< AtlasMeasurementSelector<NMeasMax, traj_t, measurement_container_variant_t> >
95{
96 // the measurement type after the selection e.g. a Matrix<N,1>
97 template <std::size_t N>
99
100 // the measurement covariance type after the selection e.g. a Matrix<N,N>
101 template <std::size_t N>
103
104 // the measurement type before the selection e.g. an Eigen::Map< Matrix<N,1> > if
105 // the calibration is performed after the selection
106 template <std::size_t N>
110
111 // the measurement covariance type before the selection e.g. an Eigen::Map<Matrix<N,N> > if
112 // the calibration is performed after the selection
113 template <std::size_t N>
117 // e.g. the same as CalibratedMeasurement
118 template <std::size_t N>
120
121 // e.g. the same as CalibratedMeasurementCovariance
122 template <std::size_t N>
124
125 // e.g. helper template to get the value_type from the measurement range iterator type
126 template <typename T_MeasurementRangeIterator>
128 using value_type = typename T_MeasurementRangeIterator::value_type;
129 };
130
131 using abstract_measurement_range_t = std::ranges::iota_view<unsigned int, unsigned int>;
132
133 // the trajectory type to which states for selected measurements are to be added
134 using trajectory_t = traj_t;
135 // the track state type for new track states
136 using TrackStateProxy = typename traj_t::TrackStateProxy;
137
138 // the value type usd for matrices
139 using MatrixFloatType = double;
140 using BoundTrackParameters = Acts::BoundTrackParameters;
141 using BoundMatrix = Acts::BoundMatrix;
142
143 using BoundState = std::tuple<BoundTrackParameters, BoundMatrix, double>;
144
145 // maximum dimension of measurements determined from the measurement "container" variant
147
148 // must be the same as what is used for the CKF
149 static constexpr std::size_t s_maxBranchesPerSurface = 10;
150};
151
153template <std::size_t NMeasMax, typename traj_t, typename measurement_container_variant_t>
155 : public MeasurementSelectorBaseImpl<NMeasMax,
156 AtlasMeasurementSelector<NMeasMax, traj_t, measurement_container_variant_t> ,
157 measurement_container_variant_t >
158{
159 // @TODO can these redundent definitions been avoided ?
162 measurement_container_variant_t >;
163 // BASE::trats are MeasurementSelectorTraits< ... decltype(*this) >
164 using traits = typename BASE::traits;
165
166 template <std::size_t DIM>
167 using Measurement = typename traits::template CalibratedMeasurement<DIM>;
168
170
171 // helper to determine the calibrator type from the measurement container tyoe
172 // and to define the types used for the calibrated measurement and covariance
174 // the types used for the calibrated measurement and covariance
175 template <std::size_t DIM>
176 using Measurement = typename traits::template CalibratedMeasurement<DIM>;
177 template <std::size_t DIM>
178 using MeasurementCovariance = typename traits::template CalibratedMeasurementCovariance<DIM>;
179
180 // helper to determine the measurement value type from the container type
181 template <typename T_Container>
182 using MeassurementContainerValueType = typename traits::template MeasurementContainerTraits<T_Container>::value_type;
183 };
184
185 // the delegate used for the final calibration
186 template <std::size_t DIM, typename measurement_t>
188 measurement_container_variant_t,
189 typename traits::BoundTrackParameters>::template Calibrator<DIM,measurement_t>;
190
191 template <std::size_t DIM, typename measurement_t>
193 measurement_container_variant_t,
194 typename traits::TrackStateProxy>::template Calibrator<DIM,measurement_t>;
195
196
199
201 m_measurementRangesForced = measurementRangesForced;
202 }
203
204 // Helper to provide the mapping between bound parameters and coordinates
205 // @TODO is the default projector always good enough or is there some dependency
206 // on the geoemtry ?
209 struct Empty {};
210 std::conditional<s_fullPreCalibration,
213
214
216 const ActsTrk::detail::MeasurementRangeList &measurementRanges)
217 : BASE{std::move(config)},
218 m_measurementRanges(&measurementRanges)
219 {}
220
221 // register a calibrator for the given measurement type and the measurement dimension i.e. number of coordinates
222 template <std::size_t DIM, typename T_ValueType>
225 }
226
227 template <std::size_t DIM>
228 static constexpr bool s_CanPreCalibrate = std::is_same< typename traits::template PreSelectionMeasurement<DIM>,
229 typename traits::template CalibratedMeasurement<DIM> >::value
230 && std::is_same< typename traits::template PreSelectionMeasurementCovariance<DIM>,
231 typename traits::template CalibratedMeasurementCovariance<DIM> >::value;
232
233 template < std::size_t DIM, typename T_ValueType >
234 void setPreCalibrator(typename std::enable_if<s_CanPreCalibrate<DIM>, const PreCalibrator<DIM, T_ValueType> &>::type calibrator) {
236 }
237
238
239 // helper to provide a map from bound parameters to coordinates
240 template <std::size_t DIM>
242 parameterMap(const Acts::GeometryContext& geometryContext,
243 const Acts::CalibrationContext& calibrationContext,
244 const Acts::Surface& surface) const {
245 return m_projector.parameterMap<DIM>(geometryContext,calibrationContext,surface);
246 }
247
248 // helper which returns a delegate to perform the post calibration for the given measurement type and dimension
249 template <std::size_t DIM, typename measurement_t>
252 return m_calibrators.template calibrator<DIM,measurement_t>();
253 }
254
255 // helper which returns a delegate or lambda to get the measurement and covariance used during the selection
256 template <std::size_t DIM, typename measurement_t>
257 auto
259 if constexpr(s_fullPreCalibration) {
260 // full calibration during selection
261 return m_preCalibrators.template calibrator<DIM,measurement_t>();
262 }
263 else {
264 // no calibration is performed before the measurement selection, so just Eigen maps to the stored location
265 // and covariance are returned.
266 // @TODO unfortunately the Eigen Maps cannot be used directly because they are incompatible with the
267 // temporary measurement storage used in the measurement selector, so need to convert to the
268 // above ConstVectorMapWithInvalidDef etc. Does this introduce some overhead ?
269 return []( [[maybe_unused]] const Acts::GeometryContext&,
270 [[maybe_unused]] const Acts::CalibrationContext&,
271 [[maybe_unused]] const Acts::Surface&,
272 const measurement_t &measurement,
273 [[maybe_unused]] const typename traits::BoundTrackParameters &) {
274 return std::make_tuple( measurement.template localPosition<DIM>(), measurement.template localCovariance<DIM>(), 0u );
275 };
276 }
277 }
278
279 std::tuple<const measurement_container_variant_t *, abstract_measurement_range_t, bool >
280 containerAndRange(const Acts::Surface &surface) const {
282 auto ret = containerAndRangeSingle(*m_measurementRangesForced, surface, true);
283 if (std::get<0>(ret)) return ret;
284 }
285 return containerAndRangeSingle(*m_measurementRanges, surface, false);
286 }
287
288
289 template <typename MeasurementRangeList_t>
290 static std::tuple<const measurement_container_variant_t *, abstract_measurement_range_t, bool >
291 containerAndRangeSingle(const MeasurementRangeList_t& measurementRanges, const Acts::Surface &surface, bool forced) {
292 typename MeasurementRangeList_t::const_iterator range_iter = measurementRanges.find(surface.geometryId().value());
293 if (range_iter == measurementRanges.end())
294 {
295 return {nullptr, abstract_measurement_range_t{}, forced};
296 }
297 else {
298 abstract_measurement_range_t range{range_iter->second.elementBeginIndex(),
299 range_iter->second.elementEndIndex()};
300 assert( !range_iter->second.isMeasurementExpected() || range.begin() <= range.end());
301 // if surface marked as defect
302 return { forced || range_iter->second.isMeasurementExpected() ? &(measurementRanges.container(range_iter->second.containerIndex())) : nullptr,
303 std::move(range), forced};
304 }
305 }
306
307 bool expectMeasurements([[maybe_unused]] const Acts::Surface &surface,
308 [[maybe_unused]] const measurement_container_variant_t *container_variant_ptr,
309 const abstract_measurement_range_t &abstract_range) const {
310 return (abstract_range.begin()<=abstract_range.end());
311 }
312
313 template <typename measurement_container_t>
314 auto
315 rangeForContainer(const measurement_container_t &concrete_container,
316 const abstract_measurement_range_t &abstract_range) const {
317 unsigned int begin_idx = abstract_range.front();
318 auto begin_iter = concrete_container.container().begin() + begin_idx;
319 auto end_iter = begin_iter + static_cast<unsigned int>(abstract_range.size());
320 return std::ranges::subrange(begin_iter, end_iter);
321 }
322};
323
324namespace {
325 // the track back-end used during track finding
326 using RecoTrackContainer = Acts::TrackContainer<Acts::VectorTrackContainer,
327 Acts::VectorMultiTrajectory>;
328
329 static constexpr std::size_t gAbsoluteMaxBranchesPerSurface = 3; // the absolute maximum number of branches per surface
330 // the actual value is configurable up to this number
331
332
333 // Wrapper class which provides the actual measurement selector and
334 // allows to connect it to the delegate used by the track finder
335 template <typename traj_t>
336 class AtlasActsMeasurmentSelector : public ActsTrk::IMeasurementSelector {
337 public:
338 using TheAtlasMeasurementSelector
339 = AtlasMeasurementSelector<
340 gAbsoluteMaxBranchesPerSurface,
341 traj_t,
343 // where measurement_container_variant_t is e.g.
344 // variant< ContainerRefWithDim<xAOD::PixelClusterContainer,2>, ... >
345 >;
346
347 using BoundState = std::tuple<Acts::BoundTrackParameters, Acts::BoundMatrix, double>;
348 // the delegate used by the track finder to which the measurement selector needs to be connected to
349
350 AtlasActsMeasurmentSelector(ActsTrk::MeasurementCalibrator<traj_t> &&calibrator,
351 const ActsTrk::detail::MeasurementRangeList &measurementRanges,
353 : m_calibrator( std::move(calibrator)),
354 m_measurementSelector(std::move(config),
355 measurementRanges)
356 {
357 // have to register one calibrator per measurement container type and associated dimension.
358 // @TODO unfortunately automatic type deduction does not work, so have to provide the type
359 // additionally
360 if constexpr( s_fullPreCalibration) {
361 m_measurementSelector.template setPreCalibrator<2,xAOD::PixelCluster>(m_calibrator.pixelPreCalibrator());
362 m_measurementSelector.template setPreCalibrator<1,xAOD::StripCluster>(m_calibrator.stripPreCalibrator());
363 m_measurementSelector.template setPreCalibrator<3,xAOD::HGTDCluster>(m_calibrator.hgtdPreCalibrator());
364 m_measurementSelector.template setCalibrator<2,xAOD::PixelCluster>(m_calibrator.pixelPostCalibrator());
365 m_measurementSelector.template setCalibrator<1,xAOD::StripCluster>(m_calibrator.stripPostCalibrator());
366 m_measurementSelector.template setCalibrator<3,xAOD::HGTDCluster>(m_calibrator.hgtdPostCalibrator());
367 }
368 else {
369 m_measurementSelector.template setCalibrator<2,xAOD::PixelCluster>(m_calibrator.pixelPostCalibrator());
370 m_measurementSelector.template setCalibrator<1,xAOD::StripCluster>(m_calibrator.stripPostCalibrator());
371 m_measurementSelector.template setCalibrator<3,xAOD::HGTDCluster>(m_calibrator.hgtdPostCalibrator());
372 }
373 }
374
375 // called by the track finder to connect this measurement selector to the ckf.
376 void connect(std::any delegate_ptr) const override {
377 using TrackStateCreator = Acts::CombinatorialKalmanFilterExtensions<RecoTrackContainer>::TrackStateCreator;
378
379 auto delegate = std::any_cast< TrackStateCreator *>(delegate_ptr);
380 delegate->template connect< & TheAtlasMeasurementSelector::createTrackStates >(&m_measurementSelector);
381 }
382
383 void setMeasurementRangesForced(const ActsTrk::detail::MeasurementRangeListFlat *measurementRangesForced) override {
384 m_measurementSelector.setMeasurementRangesForced(measurementRangesForced);
385 }
386
387 // provides the calibrators
388 ActsTrk::MeasurementCalibrator<traj_t> m_calibrator;
389
390 // the actual measurement selector
391 TheAtlasMeasurementSelector m_measurementSelector;
392 };
393}
394
395namespace ActsTrk::detail {
396// return a configured, wrapper for the measurement selector
397std::unique_ptr<ActsTrk::IMeasurementSelector> getMeasurementSelector(const EventContext &ctx,
401 const ActsTrk::detail::MeasurementRangeList &measurementRanges,
402 const std::vector<float> &etaBinsf,
403 const std::vector<std::pair<float, float> > &chi2CutOffOutlier,
404 const std::vector<size_t> &numMeasurementsCutOff,
405 double edge_hole_border_width) {
406
407 // set calibrators per measurement container type (order does not matter);
409 pixelOnTrackCalibratorTool,
410 stripOnTrackCalibratorTool,
411 hgtdOnTrackCalibratorTool);
412 using AtlMeasurementSelectorCuts = AtlasMeasurementSelectorCuts;
413
414 using AtlMeasurementSelector = AtlasActsMeasurmentSelector<detail::RecoTrackStateContainer>;
415 using AtlMeasurementSelectorConfig = AtlMeasurementSelector::TheAtlasMeasurementSelector::Config;
416
417 std::unique_ptr<ActsTrk::IMeasurementSelector>
418 selector(new AtlMeasurementSelector(
419 std::move(atl_measurement_calibrator),
420 measurementRanges,
421 AtlMeasurementSelectorConfig{
422 {Acts::GeometryIdentifier(),
423 AtlMeasurementSelectorCuts{ etaBinsf,
424 chi2CutOffOutlier,
425 numMeasurementsCutOff,
426 edge_hole_border_width==0.
427 ? std::optional<Acts::BoundaryTolerance>{}
428 : std::optional{Acts::BoundaryTolerance::AbsoluteEuclidean(-std::abs(edge_hole_border_width))}
429 }
430 }}));
431 return selector;
432}
433}
static constexpr bool s_fullPreCalibration
CalibratorRegistryBase< PreCalibratorTypeTraits< MeasurementTypeTraits, measurement_container_variant_t, bound_track_parameters_t >, measurement_container_variant_t > PreCalibratorRegistry
CalibratorRegistryBase< CalibratorTypeTraits< MeasurementTypeTraits, measurement_container_variant_t, track_state_proxy_t >, measurement_container_variant_t > CalibratorRegistry
static Double_t a
An instance of this class is created for each sub-level of the TRT by the TRTCalibrator.
Definition Calibrator.h:178
Hash functions to pack the source link into unordered_maps / unordered_sets.
std::unique_ptr< ActsTrk::IMeasurementSelector > getMeasurementSelector(const EventContext &ctx, const ActsTrk::IPixelOnTrackCalibratorTool< detail::RecoTrackStateContainer > *pixelOnTrackCalibratorTool, const ActsTrk::IStripOnTrackCalibratorTool< detail::RecoTrackStateContainer > *stripOnTrackCalibratorTool, const ActsTrk::IHGTDOnTrackCalibratorTool< detail::RecoTrackStateContainer > *hgtdOnTrackCalibratorTool, const ActsTrk::detail::MeasurementRangeList &measurementRanges, const std::vector< float > &etaBinsf, const std::vector< std::pair< float, float > > &chi2CutOffOutlier, const std::vector< size_t > &numMeasurementsCutOff, double edge_hole_border_width)
GenMeasurementRangeListFlat< AtlasMeasurementContainerList > MeasurementRangeListFlat
Acts::TrackContainer< Acts::VectorTrackContainer, Acts::VectorMultiTrajectory > RecoTrackContainer
GenMeasurementRangeList< AtlasMeasurementContainerList > MeasurementRangeList
STL namespace.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Eigen::Matrix< float, N, N > MeasMatrix
Eigen::Map< const MeasMatrix< N > > ConstMatrixMap
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.
Eigen::Map< const MeasVector< N > > ConstVectorMap
typename traits::template CalibratedMeasurement< DIM > Measurement
typename traits::template MeasurementContainerTraits< T_Container >::value_type MeassurementContainerValueType
typename traits::template CalibratedMeasurementCovariance< DIM > MeasurementCovariance
ATALS specific Implementation of the member functions needed by the measurement selector.
typename traits::template CalibratedMeasurement< DIM > Measurement
CalibratorTypeTraits< CalibratedMeasurementTraits, measurement_container_variant_t, typename traits::TrackStateProxy >::template Calibrator< DIM, measurement_t > Calibrator
void setCalibrator(const Calibrator< DIM, T_ValueType > &calibrator)
AtlasMeasurementSelector(typename BASE::Config &&config, const ActsTrk::detail::MeasurementRangeList &measurementRanges)
const Calibrator< DIM, measurement_t > & postCalibrator() const
BASE::abstract_measurement_range_t abstract_measurement_range_t
MeasurementSelectorBaseImpl< NMeasMax, AtlasMeasurementSelector< NMeasMax, traj_t, measurement_container_variant_t >, measurement_container_variant_t > BASE
void setMeasurementRangesForced(const ActsTrk::detail::MeasurementRangeListFlat *measurementRangesForced)
bool expectMeasurements(const Acts::Surface &surface, const measurement_container_variant_t *container_variant_ptr, const abstract_measurement_range_t &abstract_range) const
ParameterMapping::type< DIM > parameterMap(const Acts::GeometryContext &geometryContext, const Acts::CalibrationContext &calibrationContext, const Acts::Surface &surface) const
PreCalibratorTypeTraits< CalibratedMeasurementTraits, measurement_container_variant_t, typename traits::BoundTrackParameters >::template Calibrator< DIM, measurement_t > PreCalibrator
CalibratorRegistry< CalibratedMeasurementTraits, measurement_container_variant_t, typename traits::TrackStateProxy > m_calibrators
void setPreCalibrator(typename std::enable_if< s_CanPreCalibrate< DIM >, const PreCalibrator< DIM, T_ValueType > & >::type calibrator)
auto rangeForContainer(const measurement_container_t &concrete_container, const abstract_measurement_range_t &abstract_range) const
static std::tuple< const measurement_container_variant_t *, abstract_measurement_range_t, bool > containerAndRangeSingle(const MeasurementRangeList_t &measurementRanges, const Acts::Surface &surface, bool forced)
std::conditional< s_fullPreCalibration, PreCalibratorRegistry< CalibratedMeasurementTraits, measurement_container_variant_t, typenametraits::BoundTrackParameters >, Empty >::type m_preCalibrators
std::tuple< const measurement_container_variant_t *, abstract_measurement_range_t, bool > containerAndRange(const Acts::Surface &surface) const
ConstMatrixMapWithInvalidDef< DIM > & operator=(ConstMatrixMapWithInvalidDef< DIM > &&a)
ConstMatrixMapWithInvalidDef< DIM > & operator=(const xAOD::ConstMatrixMap< DIM > &a)
ConstMatrixMapWithInvalidDef< DIM > & operator=(const ConstMatrixMapWithInvalidDef< DIM > &a)
ConstVectorMapWithInvalidDef< DIM > & operator=(const ConstVectorMapWithInvalidDef< DIM > &a)
ConstVectorMapWithInvalidDef< DIM > & operator=(ConstVectorMapWithInvalidDef< DIM > &&a)
ConstVectorMapWithInvalidDef< DIM > & operator=(const xAOD::ConstVectorMap< DIM > &a)
MeasurementSelectorTraits< AtlasMeasurementSelector< NMeasMax, traj_t, measurement_container_variant_t > >::abstract_measurement_range_t abstract_measurement_range_t
MeasurementSelectorTraits< AtlasMeasurementSelector< NMeasMax, traj_t, measurement_container_variant_t > > traits
std::conditional< s_fullPreCalibration, CalibratedMeasurementCovariance< N >, ConstMatrixMapWithInvalidDef< N > >::type PreSelectionMeasurementCovariance
std::conditional< s_fullPreCalibration, CalibratedMeasurement< N >, ConstVectorMapWithInvalidDef< N > >::type PreSelectionMeasurement
std::array< unsigned char, N > type