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
10
11#include "Acts/Definitions/Common.hpp"
12#include "Acts/Definitions/Algebra.hpp"
13#include "Acts/Utilities/VectorHelpers.hpp"
14#include "Acts/Utilities/Delegate.hpp"
15#include "Acts/Utilities/Result.hpp"
16#include "Acts/Geometry/GeometryContext.hpp"
17#include "Acts/Utilities/CalibrationContext.hpp"
18#include "Acts/EventData/BoundTrackParameters.hpp"
19#include "Acts/Surfaces/Surface.hpp"
20#include "Acts/Utilities/Logger.hpp"
21#include "Acts/TrackFinding/CombinatorialKalmanFilter.hpp"
22#include "Acts/TrackFinding/TrackStateCreator.hpp"
23#include "Acts/Surfaces/BoundaryTolerance.hpp"
24
30
35
36#include "boost/container/small_vector.hpp"
37
38#include <tuple>
39#include <type_traits>
40#include <span>
41#include <ranges>
42
44
45template <std::size_t NMeasMax, typename traj_t, typename measurement_container_variant_t>
47
48static constexpr bool s_fullPreCalibration=true;
49
50// need an "Eigen Map" which is default constructable and assignable
51// and where an assignment changes the data pointer not the contents of
52// the data it was pointing to.
53template <std::size_t DIM>
55 ConstVectorMapWithInvalidDef() : xAOD::ConstVectorMap<DIM>{nullptr} {}
57 this->m_data = a.m_data;
58 return *this;
59 }
61 this->m_data = a.m_data;
62 return *this;
63 }
65 this->m_data = a.data();
66 return *this;
67 }
68 using xAOD::ConstVectorMap<DIM>::ConstVectorMap;
69};
70
71// see above
72template <std::size_t DIM>
74 ConstMatrixMapWithInvalidDef() : xAOD::ConstMatrixMap<DIM>{nullptr} {}
76 this->m_data = a.m_data;
77 return *this;
78 }
80 this->m_data = a.m_data;
81 return *this;
82 }
84 this->m_data = a.data();
85 return *this;
86 }
87 using xAOD::ConstMatrixMap<DIM>::ConstMatrixMap;
88};
89
94template <std::size_t NMeasMax, typename traj_t, typename measurement_container_variant_t>
95struct MeasurementSelectorTraits< AtlasMeasurementSelector<NMeasMax, traj_t, measurement_container_variant_t> >
96{
97 // the measurement type after the selection e.g. a Matrix<N,1>
98 template <std::size_t N>
100
101 // the measurement covariance type after the selection e.g. a Matrix<N,N>
102 template <std::size_t N>
104
105 // the measurement type before the selection e.g. an Eigen::Map< Matrix<N,1> > if
106 // the calibration is performed after the selection
107 template <std::size_t N>
111
112 // the measurement covariance type before the selection e.g. an Eigen::Map<Matrix<N,N> > if
113 // the calibration is performed after the selection
114 template <std::size_t N>
118 // e.g. the same as CalibratedMeasurement
119 template <std::size_t N>
121
122 // e.g. the same as CalibratedMeasurementCovariance
123 template <std::size_t N>
125
126 // e.g. helper template to get the value_type from the measurement range iterator type
127 template <typename T_MeasurementRangeIterator>
129 using value_type = typename T_MeasurementRangeIterator::value_type;
130 };
131
132 using abstract_measurement_range_t = std::ranges::iota_view<unsigned int, unsigned int>;
133
134 // the trajectory type to which states for selected measurements are to be added
135 using trajectory_t = traj_t;
136 // the track state type for new track states
137 using TrackStateProxy = typename traj_t::TrackStateProxy;
138
139 // the value type usd for matrices
140 using MatrixFloatType = double;
141 using BoundTrackParameters = Acts::BoundTrackParameters;
142 using BoundMatrix = Acts::BoundMatrix;
143
144 using BoundState = std::tuple<BoundTrackParameters, BoundMatrix, double>;
145
146 // maximum dimension of measurements determined from the measurement "container" variant
148
149 // must be the same as what is used for the CKF
150 static constexpr std::size_t s_maxBranchesPerSurface = 10;
151};
152
154template <std::size_t NMeasMax, typename traj_t, typename measurement_container_variant_t>
156 : public MeasurementSelectorBaseImpl<NMeasMax,
157 AtlasMeasurementSelector<NMeasMax, traj_t, measurement_container_variant_t> ,
158 measurement_container_variant_t >
159{
160 // @TODO can these redundent definitions been avoided ?
163 measurement_container_variant_t >;
164 // BASE::trats are MeasurementSelectorTraits< ... decltype(*this) >
165 using traits = typename BASE::traits;
166
167 template <std::size_t DIM>
168 using Measurement = typename traits::template CalibratedMeasurement<DIM>;
169
171
172 // the delegate used for the final calibration
173 template <std::size_t DIM, typename measurement_t>
174 using Calibrator = Acts::Delegate<
175 std::pair < typename traits::template CalibratedMeasurement<DIM>,
176 typename traits::template CalibratedMeasurementCovariance<DIM> >
177 (const Acts::GeometryContext&,
178 const Acts::CalibrationContext&,
179 const Acts::Surface&,
180 const measurement_t &,
181 const typename traits::BoundTrackParameters &)>;
182
183 // helper to determine the calibrator type from the measurement container tyoe
184 // and to define the types used for the calibrated measurement and covariance
186 // the types used for the calibrated measurement and covariance
187 template <std::size_t DIM>
188 using Measurement = typename traits::template CalibratedMeasurement<DIM>;
189 template <std::size_t DIM>
190 using MeasurementCovariance = typename traits::template CalibratedMeasurementCovariance<DIM>;
191
192 // helper to determine the measurement value type from the container type
193 template <typename T_Container>
194 using MeassurementContainerValueType = typename traits::template MeasurementContainerTraits<T_Container>::value_type;
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 Calibrator<DIM, T_ValueType> &>::type calibrator) {
236 }
237
238 // helper to create a Acts::SourceLink from an uncalibrated measurement pointer
239 template <typename T_Value>
240 static Acts::SourceLink makeSourceLink(T_Value &&value) {
241 // value is pointer
242 static_assert( !std::is_same<std::remove_pointer_t<T_Value>, T_Value>::value );
243 // ... and pointer to xAOD::UncalibgratedMeasurement
244 static_assert(std::is_base_of_v< xAOD::UncalibratedMeasurement, std::remove_cv_t<std::remove_pointer_t<T_Value> > > );
245 return Acts::SourceLink{ ActsTrk::makeATLASUncalibSourceLink(value) };
246 }
247
248 // helper to provide a map from bound parameters to coordinates
249 template <std::size_t DIM>
251 parameterMap(const Acts::GeometryContext& geometryContext,
252 const Acts::CalibrationContext& calibrationContext,
253 const Acts::Surface& surface) const {
254 return m_projector.parameterMap<DIM>(geometryContext,calibrationContext,surface);
255 }
256
257 // helper which returns a delegate to perform the post calibration for the given measurement type and dimension
258 template <std::size_t DIM, typename measurement_t>
261 return m_calibrators.template calibrator<DIM,measurement_t>();
262 }
263
264 // helper which returns a delegate or lambda to get the measurement and covariance used during the selection
265 template <std::size_t DIM, typename measurement_t>
266 auto
268 if constexpr(s_fullPreCalibration) {
269 // full calibration during selection
270 return m_preCalibrators.template calibrator<DIM,measurement_t>();
271 }
272 else {
273 // no calibration is performed before the measurement selection, so just Eigen maps to the stored location
274 // and covariance are returned.
275 // @TODO unfortunately the Eigen Maps cannot be used directly because they are incompatible with the
276 // temporary measurement storage used in the measurement selector, so need to convert to the
277 // above ConstVectorMapWithInvalidDef etc. Does this introduce some overhead ?
278 return []( [[maybe_unused]] const Acts::GeometryContext&,
279 [[maybe_unused]] const Acts::CalibrationContext&,
280 [[maybe_unused]] const Acts::Surface&,
281 const measurement_t &measurement,
282 [[maybe_unused]] const typename traits::BoundTrackParameters &) {
283 return std::make_pair( measurement.template localPosition<DIM>(), measurement.template localCovariance<DIM>() );
284 };
285 }
286 }
287
288 std::tuple<const measurement_container_variant_t *, abstract_measurement_range_t, bool >
289 containerAndRange(const Acts::Surface &surface) const {
291 auto ret = containerAndRangeSingle(*m_measurementRangesForced, surface, true);
292 if (std::get<0>(ret)) return ret;
293 }
294 return containerAndRangeSingle(*m_measurementRanges, surface, false);
295 }
296
297
298 template <typename MeasurementRangeList_t>
299 static std::tuple<const measurement_container_variant_t *, abstract_measurement_range_t, bool >
300 containerAndRangeSingle(const MeasurementRangeList_t& measurementRanges, const Acts::Surface &surface, bool forced) {
301 typename MeasurementRangeList_t::const_iterator range_iter = measurementRanges.find(surface.geometryId().value());
302 if (range_iter == measurementRanges.end())
303 {
304 return {nullptr, abstract_measurement_range_t{}, forced};
305 }
306 else {
307 abstract_measurement_range_t range{range_iter->second.elementBeginIndex(),
308 range_iter->second.elementEndIndex()};
309 assert( !range_iter->second.isMeasurementExpected() || range.begin() <= range.end());
310 // if surface marked as defect
311 return { forced || range_iter->second.isMeasurementExpected() ? &(measurementRanges.container(range_iter->second.containerIndex())) : nullptr,
312 std::move(range), forced};
313 }
314 }
315
316 bool expectMeasurements([[maybe_unused]] const Acts::Surface &surface,
317 [[maybe_unused]] const measurement_container_variant_t *container_variant_ptr,
318 const abstract_measurement_range_t &abstract_range) const {
319 return (abstract_range.begin()<=abstract_range.end());
320 }
321
322 template <typename measurement_container_t>
323 auto
324 rangeForContainer(const measurement_container_t &concrete_container,
325 const abstract_measurement_range_t &abstract_range) const {
326 unsigned int begin_idx = abstract_range.front();
327 auto begin_iter = concrete_container.container().begin() + begin_idx;
328 auto end_iter = begin_iter + static_cast<unsigned int>(abstract_range.size());
329 return std::ranges::subrange(begin_iter, end_iter);
330 }
331};
332
333namespace {
334 // the track back-end used during track finding
335 using RecoTrackContainer = Acts::TrackContainer<Acts::VectorTrackContainer,
336 Acts::VectorMultiTrajectory>;
337
338 static constexpr std::size_t gAbsoluteMaxBranchesPerSurface = 3; // the absolute maximum number of branches per surface
339 // the actual value is configurable up to this number
340
341
342 // Wrapper class which provides the actual measurement selector and
343 // allows to connect it to the delegate used by the track finder
344 template <typename track_container_t>
345 class AtlasActsMeasurmentSelector : public ActsTrk::IMeasurementSelector {
346 public:
347 using TheAtlasMeasurementSelector
348 = AtlasMeasurementSelector<
349 gAbsoluteMaxBranchesPerSurface,
350 typename track_container_t::TrackStateContainerBackend,
352 // where measurement_container_variant_t is e.g.
353 // variant< ContainerRefWithDim<xAOD::PixelClusterContainer,2>, ... >
354 >;
355
356 using BoundState = std::tuple<Acts::BoundTrackParameters, Acts::BoundMatrix, double>;
357 // the delegate used by the track finder to which the measurement selector needs to be connected to
358
359 AtlasActsMeasurmentSelector(ActsTrk::MeasurementCalibrator &&calibrator,
360 const ActsTrk::detail::MeasurementRangeList &measurementRanges,
362 : m_calibrator( std::move(calibrator)),
363 m_measurementSelector(std::move(config),
364 measurementRanges)
365 {
366 // have to register one calibrator per measurement container type and associated dimension.
367 // @TODO unfortunately automatic type deduction does not work, so have to provide the type
368 // additionally
369 if constexpr( s_fullPreCalibration) {
370 m_measurementSelector.template setPreCalibrator<2,xAOD::PixelCluster>(m_calibrator.pixelPreCalibrator());
371 m_measurementSelector.template setPreCalibrator<1,xAOD::StripCluster>(m_calibrator.stripPreCalibrator());
372 m_measurementSelector.template setPreCalibrator<3,xAOD::HGTDCluster>(m_calibrator.hgtdPreCalibrator());
373 m_measurementSelector.template setCalibrator<2,xAOD::PixelCluster>(m_calibrator.pixelPostCalibrator());
374 m_measurementSelector.template setCalibrator<1,xAOD::StripCluster>(m_calibrator.stripPostCalibrator());
375 m_measurementSelector.template setCalibrator<3,xAOD::HGTDCluster>(m_calibrator.hgtdPostCalibrator());
376 }
377 else {
378 m_measurementSelector.template setCalibrator<2,xAOD::PixelCluster>(m_calibrator.pixelPostCalibrator());
379 m_measurementSelector.template setCalibrator<1,xAOD::StripCluster>(m_calibrator.stripPostCalibrator());
380 m_measurementSelector.template setCalibrator<3,xAOD::HGTDCluster>(m_calibrator.hgtdPostCalibrator());
381 }
382 }
383
384 // called by the track finder to connect this measurement selector to the ckf.
385 void connect(std::any delegate_ptr) const override {
386 using TrackStateCreator = Acts::CombinatorialKalmanFilterExtensions<RecoTrackContainer>::TrackStateCreator;
387
388 auto delegate = std::any_cast< TrackStateCreator *>(delegate_ptr);
389 delegate->template connect< & TheAtlasMeasurementSelector::createTrackStates >(&m_measurementSelector);
390 }
391
392 void setMeasurementRangesForced(const ActsTrk::detail::MeasurementRangeListFlat *measurementRangesForced) override {
393 m_measurementSelector.setMeasurementRangesForced(measurementRangesForced);
394 }
395
396 // provides the calibrators
397 ActsTrk::MeasurementCalibrator m_calibrator;
398
399 // the actual measurement selector
400 TheAtlasMeasurementSelector m_measurementSelector;
401 };
402}
403
404namespace ActsTrk::detail {
405// return a configured, wrapper for the measurement selector
406std::unique_ptr<ActsTrk::IMeasurementSelector> getMeasurementSelector(const EventContext &ctx,
407 const ActsTrk::IPixelOnBoundStateCalibratorTool *pixelOnTrackCalibratorTool,
408 const ActsTrk::IStripOnBoundStateCalibratorTool *stripOnTrackCalibratorTool,
409 const ActsTrk::IHGTDOnBoundStateCalibratorTool *hgtdOnTrackCalibratorTool,
410 const ActsTrk::detail::MeasurementRangeList &measurementRanges,
411 const std::vector<float> &etaBinsf,
412 const std::vector<std::pair<float, float> > &chi2CutOffOutlier,
413 const std::vector<size_t> &numMeasurementsCutOff,
414 double edge_hole_border_width) {
415
416 // set calibrators per measurement container type (order does not matter);
417 ActsTrk::MeasurementCalibrator atl_measurement_calibrator(ctx,
418 pixelOnTrackCalibratorTool,
419 stripOnTrackCalibratorTool,
420 hgtdOnTrackCalibratorTool);
421 using AtlMeasurementSelectorCuts = AtlasMeasurementSelectorCuts;
422
423 using AtlMeasurementSelector = AtlasActsMeasurmentSelector<RecoTrackContainer>;
424 using AtlMeasurementSelectorConfig = AtlMeasurementSelector::TheAtlasMeasurementSelector::Config;
425
426 std::unique_ptr<ActsTrk::IMeasurementSelector>
427 selector(new AtlMeasurementSelector(
428 std::move(atl_measurement_calibrator),
429 measurementRanges,
430 AtlMeasurementSelectorConfig{
431 {Acts::GeometryIdentifier(),
432 AtlMeasurementSelectorCuts{ etaBinsf,
433 chi2CutOffOutlier,
434 numMeasurementsCutOff,
435 edge_hole_border_width==0.
436 ? std::optional<Acts::BoundaryTolerance>{}
437 : std::optional{Acts::BoundaryTolerance::AbsoluteEuclidean(-std::abs(edge_hole_border_width))}
438 }
439 }}));
440 return selector;
441}
442}
static constexpr bool s_fullPreCalibration
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
Athena definition of the Eigen plugin.
GenMeasurementRangeListFlat< AtlasMeasurementContainerList > MeasurementRangeListFlat
Acts::TrackContainer< Acts::VectorTrackContainer, Acts::VectorMultiTrajectory > RecoTrackContainer
GenMeasurementRangeList< AtlasMeasurementContainerList > MeasurementRangeList
std::unique_ptr< ActsTrk::IMeasurementSelector > getMeasurementSelector(const EventContext &ctx, const ActsTrk::IPixelOnBoundStateCalibratorTool *pixelOnTrackCalibratorTool, const ActsTrk::IStripOnBoundStateCalibratorTool *stripOnTrackCalibratorTool, const ActsTrk::IHGTDOnBoundStateCalibratorTool *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)
ATLASUncalibSourceLink makeATLASUncalibSourceLink(const xAOD::UncalibratedMeasurementContainer *container, std::size_t index, const EventContext &ctx)
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
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)
std::conditional< s_fullPreCalibration, CalibratorRegistry< CalibratedMeasurementTraits, typenametraits::BoundTrackParameters, measurement_container_variant_t >, Empty >::type m_preCalibrators
static Acts::SourceLink makeSourceLink(T_Value &&value)
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
void setPreCalibrator(typename std::enable_if< s_CanPreCalibrate< DIM >, const Calibrator< DIM, T_ValueType > & >::type calibrator)
Acts::Delegate< std::pair< typename traits::template CalibratedMeasurement< DIM >, typename traits::template CalibratedMeasurementCovariance< DIM > >(const Acts::GeometryContext &, const Acts::CalibrationContext &, const Acts::Surface &, const measurement_t &, const typename traits::BoundTrackParameters &)> 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::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