12#include "Acts/Definitions/Units.hpp"
17#include "GaudiKernel/PhysicalConstants.h"
26#include <Acts/Definitions/TrackParametrization.hpp>
27#include <Acts/Utilities/Helpers.hpp>
28#include <Acts/Utilities/MathHelpers.hpp>
29#include <Acts/Definitions/Tolerance.hpp>
33 constexpr float toFloat(
const double x) {
35 if (std::abs(
x) < Acts::s_epsilon) {
38 constexpr double min = 3.*
static_cast<double>(std::numeric_limits<float>::min());
39 constexpr double max =
static_cast<double>(std::numeric_limits<float>::max());
40 const double clampedX = std::copysign(std::clamp(std::abs(
x),
min,
max),
x);
42 return static_cast<float>(clampedX);
44 template <
int nRowsMax,
int nMatSize>
45 inline void lowerTriangleToVector(
const Acts::SquareMatrix<nMatSize>& covMatrix,
46 std::vector<float>&
vec) {
48 static_assert(nRowsMax > 0);
49 static_assert(nMatSize > 0);
50 constexpr int nRows = std::min(nRowsMax, nMatSize);
52 vec.reserve(Acts::sumUpToN(nRows));
53 for (
int i = 0;
i <
nRows; ++
i) {
54 for (
int j = 0;
j <=
i; ++
j) {
60 template <
int nRowsMax,
int nMatSize>
61 inline void lowerTriangleToVectorScaleQOverP(
const Acts::SquareMatrix<nMatSize>& covMatrix,
62 std::vector<float>&
vec,
63 const double qOverPScale) {
65 static_assert(nRowsMax > 0);
66 static_assert(nMatSize > 0);
67 constexpr int nRows = std::min(nRowsMax, nMatSize);
68 vec.reserve(Acts::sumUpToN(nRows));
69 for (
int i = 0;
i <
nRows; ++
i) {
70 for (
int j = 0;
j <=
i; ++
j) {
73 (
i == Acts::eBoundQOverP ? qOverPScale : 1.) *
74 (j == Acts::eBoundQOverP ? qOverPScale : 1.);
75 vec.emplace_back(toFloat(covVal));
87 for (
unsigned short& elm : ret) {
105 return StatusCode::SUCCESS;
109 const EventContext& ctx,
110 const ActsTrk::TrackContainer::ConstTrackProxy& track,
111 const Acts::Surface& perigeeSurface,
113 using namespace Acts::UnitLiterals;
122 const Acts::GeometryContext tgContext =
m_ctxProvider.getGeometryContext(ctx);
128 std::vector<float> tmp_cov_vector;
129 std::vector<ActsTrk::TrackStateBackend::ConstTrackStateProxy::IndexType> tmp_param_state_idx;
130 tmp_param_state_idx.reserve(30);
132 std::vector<std::vector<float>> parametersVec;
136 Acts::BoundTrackParameters perigeeParam = [&] {
137 if (&perigeeSurface == &track.referenceSurface()) {
138 return track.createParametersAtReference();
144 Acts::BoundVector boundParams = perigeeParam.parameters();
146 boundParams[Acts::eBoundLoc1],
147 boundParams[Acts::eBoundPhi],
148 boundParams[Acts::eBoundTheta],
149 boundParams[Acts::eBoundQOverP] * 1_MeV);
156 if (perigeeParam.covariance().has_value()) {
157 lowerTriangleToVectorScaleQOverP<5>(perigeeParam.covariance().value(), tmp_cov_vector, 1_MeV);
161 perigeeTimeResolution(track_particle) =
ActsTrk::timeToAthena(perigeeParam.covariance().value()(Acts::eBoundTime,Acts::eBoundTime));
181 const Acts::ParticleHypothesis& hypothesis = track.particleHypothesis();
183 constexpr float inv_1_MeV = 1 / 1_MeV;
190 gatherTrackSummaryData(track,
191 measurementToSummaryType,
199 static constexpr std::array<std::tuple<uint8_t, uint8_t, uint8_t, bool>, 5> copy_summary {
223 for (
auto [src_region, dest_xaod_summary_layer, dest_xaod_summary_hits, add_outlier] : std::span(copy_summary.begin(),
226 : copy_summary.begin()+3)) {
227 setSummaryValue(track_particle,
230 setSummaryValue(track_particle,
239 static constexpr std::array<std::array<std::array<xAOD::SummaryType,4>,2>,2> summaryTypeMap
241 std::array<std::array<xAOD::SummaryType,4>,2>{
242 std::array<xAOD::SummaryType,4>{
247 std::array<xAOD::SummaryType,4>{
253 std::array<std::array<xAOD::SummaryType,4>,2>{
254 std::array<xAOD::SummaryType,4>{
259 std::array<xAOD::SummaryType,4>{
267 std::array< std::array< std::array<uint8_t,4>,3>, 2> pixel_counts {
268 std::array< std::array<uint8_t,4>,3>{
271 std::array<std::uint8_t,4>{}},
272 std::array< std::array<uint8_t,4>,3>{
278 static constexpr std::array<std::array<std::array<unsigned int,2>,2>,2> innerlayer_range{
279 std::array<std::array<unsigned int,2>,2> {
280 std::array<unsigned int,2>{0u,1u},
281 std::array<unsigned int,2>{1u,2u}
283 std::array<std::array<unsigned int,2>,2> {
284 std::array<unsigned int,2>{0u,1u},
285 std::array<unsigned int,2>{1u,3u}
290 for (
unsigned int barrel_endcap_i=0; barrel_endcap_i<2; ++barrel_endcap_i) {
292 for (
unsigned int innerlayer_range_i=0; innerlayer_range_i<2; ++innerlayer_range_i) {
294 for (
unsigned int count_type_i=0;
297 unsigned int count=0;
299 for (
unsigned int innerlayer_i=innerlayer_range[barrel_endcap_i][innerlayer_range_i][0];
300 innerlayer_i < innerlayer_range[barrel_endcap_i][innerlayer_range_i][1];
302 assert( barrel_endcap_i < pixel_counts.size());
303 assert( innerlayer_i < pixel_counts[barrel_endcap_i].
size());
304 assert( count_type_i < pixel_counts[barrel_endcap_i][innerlayer_i].
size());
305 count += pixel_counts[barrel_endcap_i][innerlayer_i][count_type_i];
307 if (barrel_endcap_i==1) {
310 for (
unsigned int innerlayer_i=innerlayer_range[barrel_endcap_i][innerlayer_range_i][0];
311 innerlayer_i < innerlayer_range[barrel_endcap_i][innerlayer_range_i][1];
318 assert( barrel_endcap_i < summaryTypeMap.size());
319 assert( innerlayer_range_i < summaryTypeMap[barrel_endcap_i].
size());
320 assert( count_type_i < summaryTypeMap[barrel_endcap_i][innerlayer_range_i].
size());
321 setSummaryValue(track_particle,
count, summaryTypeMap[barrel_endcap_i][innerlayer_range_i][count_type_i]);
326 setSummaryValue(track_particle,
329 setSummaryValue(track_particle,
334 std::array<unsigned int, 4> expect_layer_pattern{};
345 : std::array<unsigned int, 4>{0u, 0u, 0u, 0u});
349 setSummaryValue(track_particle,
350 static_cast<uint8_t
>((expect_layer_pattern[0] & (1<<0)) != 0),
352 setSummaryValue(track_particle,
353 static_cast<uint8_t
>((expect_layer_pattern[0] & (1<<1)) != 0),
374 for (
auto [region,count_type,dest_summary_type] : std::span(copy_summary_types.begin(),
376 ? copy_summary_types.size()
377 : copy_summary_types.size()-3) )) {
378 setSummaryValue(track_particle,hitInfo.
contributingHits(region, count_type),dest_summary_type);
380 setSummaryValue(track_particle,
383 setSummaryValue(track_particle,
394 setSummaryValue(track_particle,
395 static_cast<uint8_t
>(biased_chi2_variance > 0.
396 ? std::min(
static_cast<unsigned int>(std::sqrt(biased_chi2_variance) * 100), 255u)
400 setSummaryValue(track_particle,
409 unsigned int n_hgtd_hits = hitInfo.
contributingHits(
static_cast<HitSummaryData::DetectorRegion
>(HitSummaryData::hgtdTotal));
410 unsigned int n_hgtd_outliers = hitInfo.
contributingOutlierHits(
static_cast<HitSummaryData::DetectorRegion
>(HitSummaryData::hgtdTotal));
411 hasValidTime(track_particle) = n_hgtd_hits > 2 || n_hgtd_hits>n_hgtd_outliers;
412 unsigned int hgtd_hit_pattern = (n_hgtd_hits>0u
413 ? hitInfo.
layerPattern(
static_cast<HitSummaryData::DetectorRegion
>(HitSummaryData::hgtdTotal),
416 hgtdSummary(track_particle) = hgtd_hit_pattern;
421 meanTime(track_particle) = time_info.
mean;
422 timeResolution(track_particle) = time_info.
resolution;
423 hgtdChi2(track_particle) =
static_cast<float>(time_info.
chi2);
429 tmp_param_state_idx[1] = tmp_param_state_idx.back();
430 tmp_param_state_idx.erase(tmp_param_state_idx.begin() + 2, tmp_param_state_idx.end());
434 parametersVec.clear();
435 parametersVec.reserve(tmp_param_state_idx.size());
439 bool isSeedTrack = tmp_param_state_idx.empty() ? false
440 : track.container().trackStateContainer().getTrackState(tmp_param_state_idx.front()).getMask() == Acts::TrackStatePropMask::None;
443 ATH_MSG_DEBUG(
"Seed track detected, skipping per-TSOS parameter extraction");
446 for (std::vector<ActsTrk::TrackStateBackend::ConstTrackStateProxy::IndexType>::const_reverse_iterator
447 idx_iter = tmp_param_state_idx.rbegin();
448 idx_iter != tmp_param_state_idx.rend();
450 ActsTrk::TrackStateBackend::ConstTrackStateProxy
451 state = track.container().trackStateContainer().getTrackState(*idx_iter);
452 const Acts::BoundTrackParameters actsParam = track.createParametersFromState(state);
454 Acts::Vector3 position = actsParam.position(tgContext);
455 Acts::Vector3 momentum = actsParam.momentum();
458 for (
unsigned int i = 0; i < momentum.rows(); ++i) {
459 momentum(i) *= inv_1_MeV;
462 if (actsParam.covariance()) {
463 const Acts::MagneticFieldContext mfContext =
m_ctxProvider.getMagneticFieldContext(ctx);
466 magnFieldVect.setZero();
467 fieldCache.
getField(position.data(), magnFieldVect.data());
470 using namespace Acts::UnitLiterals;
471 magnFieldVect *= 1000_T;
475 if (curvilinear_cov_result.has_value()) {
476 Acts::BoundMatrix& curvilinear_cov = curvilinear_cov_result.value();
479 for (
unsigned int col_i = 0; col_i < 4; ++col_i) {
480 curvilinear_cov(col_i, 4) *= 1_MeV;
481 curvilinear_cov(4, col_i) *= 1_MeV;
483 curvilinear_cov(4, 4) *= (1_MeV * 1_MeV);
485 std::size_t param_idx = parametersVec.size();
487 lowerTriangleToVector<5>(curvilinear_cov, tmp_cov_vector);
488 if (tmp_cov_vector.size() != 15) {
489 ATH_MSG_ERROR(
"Invalid size of lower triangle cov " << tmp_cov_vector.size() <<
" != 15"
490 <<
" input matrix : " << curvilinear_cov.rows() <<
" x " << curvilinear_cov.cols());
495 parametersVec.emplace_back(std::vector<float>{
496 static_cast<float>(position[0]),
static_cast<float>(position[1]),
static_cast<float>(position[2]),
497 static_cast<float>(momentum[0]),
static_cast<float>(momentum[1]),
static_cast<float>(momentum[2]) });
500 for (
const std::vector<float>& param : parametersVec) {
501 if (param.size() != 6) {
502 ATH_MSG_ERROR(
"Invalid size of param element " << param.size() <<
" != 6");
507 if( !parametersVec.empty() ) {
513 return StatusCode::SUCCESS;
517 const ActsTrk::TrackContainer::ConstTrackProxy& track,
518 const Acts::Surface& perigee_surface)
const {
519 const Acts::BoundTrackParameters trackParam = track.createParametersAtReference();
521 Acts::Result<Acts::BoundTrackParameters>
525 Acts::Direction::Backward(),
527 if (!perigeeParam.ok()) {
528 ATH_MSG_WARNING(
"Failed to extrapolate to perigee, started from \n" << trackParam <<
" " << trackParam.referenceSurface().name());
532 return perigeeParam.value();
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
std::vector< size_t > vec
size_t size() const
Number of registered mappings.
#define ATLAS_THREAD_SAFE
Acts::BoundTrackParameters parametersAtPerigee(const EventContext &ctx, const ActsTrk::TrackContainer::ConstTrackProxy &track, const Acts::Surface &perigee_surface) const
Gaudi::Property< double > m_paramExtrapolationParLimit
ToolHandle< ActsTrk::IExtrapolationTool > m_extrapolationTool
Gaudi::Property< bool > m_firstAndLastParamOnly
Gaudi::Property< bool > m_expectIfPixelContributes
Gaudi::Property< double > m_pixelExpectLayerPathLimitInMM
Gaudi::Property< int > m_trackFitter
ContextUtility m_ctxProvider
Utility to fetch the geometry, magnetic field and calibration context in the event.
static constexpr int s_expertLevel
Gaudi::Property< int > m_itkDecorationLevel
PublicToolHandle< MuonR4::ITrackSummaryTool > m_muonSummaryTool
virtual StatusCode convert(xAOD::TrackParticle &trackParticle, const EventContext &ctx, const ActsTrk::TrackContainer::ConstTrackProxy &track, const Acts::Surface &perigeeSurface, const InDet::BeamSpotData *beamspotData=nullptr) const override
Gaudi::Property< unsigned long > m_patternRecognitionInfo
virtual StatusCode initialize() override
Gaudi::Property< int > m_hgtdDecorationLevel
Gaudi::Property< bool > m_computeExpectedLayerPattern
Helper class to gather hit summary information for e.g.
unsigned int layerPattern(DetectorRegion region, bool include_outlier) const
Get a bit pattern with one bit set per layer which is set if the layer has a hit or optionally an out...
DetectorRegion
Regions for which hit counts are computed.
std::array< uint8_t, 4 > sumPerCountType(DetectorRegion region, uint8_t layer) const
return the total number of hits, outliers, shared hits and split hits in the given detector region an...
uint8_t contributingHits(DetectorRegion region, CountType hit_type=CountType::Hit) const
return the number of hits in a certain detector region.
uint8_t contributingOutlierHits(DetectorRegion region) const
return the number of outliers in a certain detector region.
uint8_t contributingLayers(DetectorRegion region) const
return the number of layers contributing to the hit collection in the given detector region.
Helper class to gather statistics and compute the biased variance.
double biasedVariance() const
float beamTilt(int i) const noexcept
Returns the beam sigma for the i+3-th error matrix element (the 'tilt').
Local cache for magnetic field (based on MagFieldServices/AtlasFieldSvcTLS.h).
void getField(const double *ATH_RESTRICT xyz, double *ATH_RESTRICT bxyz, double *ATH_RESTRICT deriv=nullptr)
get B field value at given position xyz[3] is in mm, bxyz[3] is in kT if deriv[9] is given,...
Helper class to provide type-safe access to aux data.
void setTrackParameterCovarianceMatrix(unsigned int index, std::vector< float > &cov)
Set the cov matrix of the parameter at 'index', using a vector of floats.
void setTrackParameters(std::vector< std::vector< float > > ¶meters)
Set the parameters via the passed vector of vectors.
void setBeamlineTiltX(float tiltX)
void setParameterPosition(unsigned int index, ParameterPosition pos)
Set the 'position' (i.e. where it is in ATLAS) of the parameter at 'index', using the ParameterPositi...
void setFitQuality(float chiSquared, float numberDoF)
Set the 'Fit Quality' information.
void setBeamlineTiltY(float tiltY)
void setDefiningParameters(float d0, float z0, float phi0, float theta, float qOverP)
Set the defining parameters.
void setParticleHypothesis(const ParticleHypothesis hypo)
Method for setting the particle type, using the ParticleHypothesis enum.
void setSummaryValue(uint8_t &value, const SummaryType &information)
Set method for TrackSummary values.
void setTrackFitter(const TrackFitter fitter)
Method for setting the fitter, using the TrackFitter enum.
void setPatternRecognitionInfo(const std::bitset< xAOD::NumberOfTrackRecoInfo > &patternReco)
Method setting the pattern recognition algorithm, using a bitset.
void setDefiningParametersCovMatrixVec(const std::vector< float > &cov)
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
xAOD::ParticleHypothesis convert(Acts::ParticleHypothesis h)
std::array< unsigned int, 4 > expectedLayerPattern(const EventContext &ctx, const ActsTrk::IExtrapolationTool &extrapolator, const Acts::BoundTrackParameters &perigee_parameters, double pathLimit)
Extrapolate from the perigee outwards and gather information which detector layers should have hits.
std::optional< Acts::BoundMatrix > convertActsBoundCovToCurvilinearParam(const Acts::GeometryContext &tgContext, const Acts::BoundTrackParameters ¶m, const Acts::Vector3 &magnFieldVect, const Acts::ParticleHypothesis &particle_hypothesis)
Convert the covariance of the given Acts track parameters into curvilinear parameterisation.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
constexpr double timeToAthena(T actsT)
Converts a time unit from Acts to Athena units.
Eigen::Matrix< double, 3, 1 > Vector3D
unsigned int constexpr nRows
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)
TrackFitter
Enums to identify who created this track and which properties does it have.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
SummaryType
Enumerates the different types of information stored in Summary.
@ numberOfInnermostPixelLayerSharedEndcapHits
number of Pixel 0th layer endcap hits shared by several tracks.
@ expectInnermostPixelLayerHit
Do we expect a 0th-layer barrel hit for this track?
@ numberOfHGTDHoles
number of HGTD layers on track with absence of hits [unit8_t].
@ numberOfHGTDSharedHits
number of HGTD all-layer hits shared by several tracks [unit8_t].
@ numberOfPixelHoles
number of pixel layers on track with absence of hits [unit8_t].
@ numberOfInnermostPixelLayerEndcapHits
these are the hits in the 0th pixel layer endcap [unit8_t].
@ numberOfNextToInnermostPixelLayerSharedHits
number of Pixel 1st layer barrel hits shared by several tracks.
@ numberOfNextToInnermostPixelLayerSharedEndcapHits
number of Pixel 1st layer endcap hits shared by several tracks.
@ numberOfContribPixelLayers
number of contributing layers of the pixel detector [unit8_t].
@ standardDeviationOfChi2OS
100 times the standard deviation of the chi2 from the surfaces [unit8_t].
@ numberOfNextToInnermostPixelLayerSplitHits
number of Pixel 1st layer barrel hits split by cluster splitting
@ numberOfPixelSplitHits
number of Pixel all-layer hits split by cluster splitting [unit8_t].
@ numberOfInnermostPixelLayerEndcapOutliers
number of 0th layer endcap outliers
@ numberOfPixelBarrelHits
these are the pixel hits, in the barrel flat layers [unit8_t].
@ numberOfInnermostPixelLayerSharedHits
number of Pixel 0th layer barrel hits shared by several tracks.
@ numberOfPixelOutliers
these are the pixel outliers, including the b-layer [unit8_t].
@ numberOfContribPixelBarrelFlatLayers
number of contributing barrel flat layers of the pixel detector [unit8_t].
@ numberOfTrackSummaryTypes
@ numberOfNextToInnermostPixelLayerHits
these are the hits in the 1st pixel barrel layer
@ numberOfContribPixelBarrelInclinedLayers
number of contributing barrel inclined layers of the pixel detector [unit8_t].
@ numberOfSCTDeadSensors
number of dead SCT sensors crossed [unit8_t].
@ numberOfInnermostPixelLayerSplitHits
number of Pixel 0th layer barrel hits split by cluster splitting
@ numberOfPixelEndcapHits
these are the pixel hits, in the endcap layers [unit8_t].
@ numberOfInnermostPixelLayerOutliers
number of 0th layer barrel outliers
@ numberOfNextToInnermostPixelLayerSplitEndcapHits
number of Pixel 1st layer endcap hits split by cluster splitting
@ numberOfOutliersOnTrack
number of measurements flaged as outliers in TSOS [unit8_t].
@ numberOfNextToInnermostPixelLayerEndcapHits
these are the hits in the 0.5th and 1st pixel layer endcap rings [unit8_t].
@ expectNextToInnermostPixelLayerHit
Do we expect a 1st-layer barrel hit for this track?
@ numberOfContribPixelEndcap
number of contributing endcap layers of the pixel detector [unit8_t].
@ numberOfNextToInnermostPixelLayerEndcapOutliers
number of 1st layer endcap disk outliers
@ numberOfSCTHits
number of hits in SCT [unit8_t].
@ numberOfPixelBarrelInclinedHits
these are the pixel hits, in the barrel inclined layers [unit8_t].
@ numberOfSCTOutliers
number of SCT outliers [unit8_t].
@ numberOfPixelBarrelFlatHits
these are the pixel hits, in the barrel flat layers [unit8_t].
@ numberOfInnermostPixelLayerHits
these are the hits in the 0th pixel barrel layer
@ numberOfHGTDHits
number of HGTD hits [unit8_t].
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].
@ numberOfPixelSharedHits
number of Pixel all-layer hits shared by several tracks [unit8_t].
@ numberOfSCTSharedHits
number of SCT hits shared by several tracks [unit8_t].
@ numberOfInnermostPixelLayerSplitEndcapHits
number of Pixel 0th layer endcap hits shared by several tracks.
@ numberOfHGTDOutliers
number of HGTD outliers [unit8_t].
@ numberOfContribPixelBarrelLayers
number of contributing barrel flat layers of the pixel detector [unit8_t].
@ numberOfPixelDeadSensors
number of dead pixel sensors crossed [unit8_t].
@ numberOfNextToInnermostPixelLayerOutliers
number of 1st pixel layer barrel outliers
@ numberOfSCTHoles
number of SCT holes [unit8_t].
@ FirstMeasurement
Parameter defined at the position of the 1st measurement.
@ LastMeasurement
Parameter defined at the position of the last measurement.
static xAOD::TrackFitter fitterType(const consttrackproxy_t &trackProxy)
get fitter type of a track
static bool hasFitterType(const consttrackproxy_t &trackProxy)
test whether a track has a fitter type
static std::array< unsigned int, 4 > get(const track_proxy_t &track)
static bool exists(track_container_t &trackContainer)