11#include "Acts/Definitions/Units.hpp"
12#include "Acts/Propagator/detail/JacobianEngine.hpp"
18#include "GaudiKernel/PhysicalConstants.h"
24#include <Acts/Definitions/TrackParametrization.hpp>
29 template <
typename T,
class T_SquareMatrix>
30 inline void lowerTriangleToVector(
const T_SquareMatrix& covMatrix,
31 std::vector<T>&
vec,
unsigned int n_rows_max) {
34 unsigned int n_rows = std::min(n_rows_max,
static_cast<unsigned int>(
covMatrix.rows()));
35 vec.reserve((n_rows+1)*n_rows/2);
36 for (
unsigned int i = 0;
i < n_rows; ++
i) {
37 for (
unsigned int j = 0;
j <=
i; ++
j) {
43 template <
typename T,
class T_SquareMatrix>
44 inline void lowerTriangleToVectorScaleLastRow(
const T_SquareMatrix& covMatrix,
45 std::vector<T>&
vec,
unsigned int n_rows_max,
46 typename T_SquareMatrix::Scalar last_element_scale) {
49 unsigned int n_rows = std::min(n_rows_max,
static_cast<unsigned int>(
covMatrix.rows()));
50 vec.reserve((n_rows+1)*n_rows/2);
51 for (
unsigned int i = 0;
i < n_rows; ++
i) {
52 for (
unsigned int j = 0;
j <=
i; ++
j) {
56 typename std::vector<T>::iterator cov_iter =
vec.end();
58 *cov_iter *= last_element_scale;
59 for (
unsigned int i=0;
i<n_rows_max; ++
i) {
60 *cov_iter *= last_element_scale;
72 for (
unsigned short& elm : ret) {
84 static const std::array
map {
93 auto iter = std::find_if(
95 [abs_pdg_id](
const auto& elm) {
96 return abs_pdg_id == elm.first;
102 const std::string& name,
103 const IInterface* parent)
104 : base_class(
type, name, parent)
116 unsigned int collection_idx = 0;
118 if (type < 1 || type > 2) {
119 ATH_MSG_ERROR(
"Invalid measurement type (" <<
type <<
") given for collection " << collection_idx <<
" : "
121 <<
". Expected 1 for pixel, 2 for strips.");
122 return StatusCode::FAILURE;
127 ATH_MSG_ERROR(
"Expected exactly one value in SiDetEleCollToMeasurementType per SiDetectorElementCollection. But got "
129 return StatusCode::FAILURE;
136 cfg.resolvePassive =
false;
137 cfg.resolveMaterial =
true;
138 cfg.resolveSensitive =
true;
139 auto navigtor_logger =
logger->cloneWithSuffix(
"Navigator");
140 m_propagator = std::make_unique<Propagator>(
Stepper(std::make_shared<ATLASMagneticFieldWrapper>()),
141 Navigator(cfg, std::move(navigtor_logger)),
145 return StatusCode::SUCCESS;
150 const EventContext& ctx,
151 const ActsTrk::TrackContainer::ConstTrackProxy& track,
152 const Acts::PerigeeSurface* perigeeSurface,
155 using namespace Acts::UnitLiterals;
176 std::vector<float> tmp_cov_vector;
177 std::vector<ActsTrk::TrackStateBackend::ConstTrackStateProxy::IndexType> tmp_param_state_idx;
178 tmp_param_state_idx.reserve(30);
180 std::vector<std::vector<float>> parametersVec;
184 Acts::BoundTrackParameters perigeeParam = [&] {
185 if (perigeeSurface ==
nullptr) {
186 return track.createParametersAtReference();
192 Acts::BoundVector boundParams = perigeeParam.parameters();
194 boundParams[Acts::eBoundLoc1],
195 boundParams[Acts::eBoundPhi],
196 boundParams[Acts::eBoundTheta],
197 boundParams[Acts::eBoundQOverP] * 1_MeV);
199 if (perigeeParam.covariance().has_value()) {
200 lowerTriangleToVectorScaleLastRow(perigeeParam.covariance().value(), tmp_cov_vector, 5, 1_MeV);
215 const Acts::ParticleHypothesis& hypothesis = track.particleHypothesis();
217 constexpr float inv_1_MeV = 1 / 1_MeV;
223 gatherTrackSummaryData(track,
225 measurementToSummaryType,
232 std::array<std::tuple<uint8_t, uint8_t, uint8_t, bool>, 4> copy_summary {
253 for (
auto [src_region, dest_xaod_summary_layer, dest_xaod_summary_hits, add_outlier] : copy_summary) {
254 setSummaryValue(track_particle,
257 setSummaryValue(track_particle,
264 setSummaryValue(track_particle,
268 setSummaryValue(track_particle,
271 setSummaryValue(track_particle,
277 setSummaryValue(track_particle,
281 setSummaryValue(track_particle,
284 setSummaryValue(track_particle,
287 setSummaryValue(track_particle,
290 setSummaryValue(track_particle,
294 setSummaryValue(track_particle,
299 std::array<unsigned int, 4> expect_layer_pattern{};
310 : std::array<unsigned int, 4>{0u, 0u, 0u, 0u});
314 setSummaryValue(track_particle,
315 static_cast<uint8_t
>((expect_layer_pattern[0] & (1<<0)) != 0),
317 setSummaryValue(track_particle,
318 static_cast<uint8_t
>((expect_layer_pattern[0] & (1<<1)) != 0),
320 setSummaryValue(track_particle,
323 setSummaryValue(track_particle,
326 setSummaryValue(track_particle,
329 setSummaryValue(track_particle,
332 setSummaryValue(track_particle,
335 setSummaryValue(track_particle,
340 setSummaryValue(track_particle,
343 setSummaryValue(track_particle,
346 setSummaryValue(track_particle,
349 setSummaryValue(track_particle,
354 setSummaryValue(track_particle,
355 static_cast<uint8_t
>(biased_chi2_variance > 0.
356 ? std::min(
static_cast<unsigned int>(std::sqrt(biased_chi2_variance) * 100), 255u)
360 setSummaryValue(track_particle,
367 tmp_param_state_idx[1] = tmp_param_state_idx.back();
368 tmp_param_state_idx.erase(tmp_param_state_idx.begin() + 2, tmp_param_state_idx.end());
372 parametersVec.clear();
373 parametersVec.reserve(tmp_param_state_idx.size());
375 for (std::vector<ActsTrk::TrackStateBackend::ConstTrackStateProxy::IndexType>::const_reverse_iterator
376 idx_iter = tmp_param_state_idx.rbegin();
377 idx_iter != tmp_param_state_idx.rend();
379 ActsTrk::TrackStateBackend::ConstTrackStateProxy
380 state = track.container().trackStateContainer().getTrackState(*idx_iter);
381 const Acts::BoundTrackParameters actsParam = track.createParametersFromState(state);
383 Acts::Vector3 position = actsParam.position(gctx.
context());
384 Acts::Vector3 momentum = actsParam.momentum();
387 for (
unsigned int i = 0; i < momentum.rows(); ++i) {
388 momentum(i) *= inv_1_MeV;
391 if (actsParam.covariance()) {
393 Acts::GeometryContext tgContext = gctx.
context();
395 magnFieldVect.setZero();
396 fieldCache.
getField(position.data(), magnFieldVect.data());
399 using namespace Acts::UnitLiterals;
400 magnFieldVect *= 1000_T;
404 if (curvilinear_cov_result.has_value()) {
405 Acts::BoundMatrix& curvilinear_cov = curvilinear_cov_result.value();
408 for (
unsigned int col_i = 0; col_i < 4; ++col_i) {
409 curvilinear_cov(col_i, 4) *= 1_MeV;
410 curvilinear_cov(4, col_i) *= 1_MeV;
412 curvilinear_cov(4, 4) *= (1_MeV * 1_MeV);
414 std::size_t param_idx = parametersVec.size();
416 lowerTriangleToVector(curvilinear_cov, tmp_cov_vector, 5);
417 if (tmp_cov_vector.size() != 15) {
418 ATH_MSG_ERROR(
"Invalid size of lower triangle cov " << tmp_cov_vector.size() <<
" != 15"
419 <<
" input matrix : " << curvilinear_cov.rows() <<
" x " << curvilinear_cov.cols());
424 parametersVec.emplace_back(std::vector<float>{
425 static_cast<float>(position[0]),
static_cast<float>(position[1]),
static_cast<float>(position[2]),
426 static_cast<float>(momentum[0]),
static_cast<float>(momentum[1]),
static_cast<float>(momentum[2]) });
428 for (
const std::vector<float>& param : parametersVec) {
429 if (param.size() != 6) {
430 ATH_MSG_ERROR(
"Invalid size of param element " << param.size() <<
" != 6");
435 if( !parametersVec.empty() ) {
441 return StatusCode::SUCCESS;
445 const EventContext& ctx,
446 const ActsTrk::TrackContainer::ConstTrackProxy& track,
447 const Acts::PerigeeSurface& perigee_surface)
const
449 const Acts::BoundTrackParameters trackParam = track.createParametersAtReference();
451 Acts::Result<Acts::BoundTrackParameters>
455 Acts::Direction::Backward(),
457 if (!perigeeParam.ok()) {
458 ATH_MSG_WARNING(
"Failed to extrapolate to perigee, started from \n" << trackParam <<
" " << trackParam.referenceSurface().name());
462 return perigeeParam.value();
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
std::vector< size_t > vec
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
#define ATLAS_THREAD_SAFE
Acts::GeometryContext context() const
Gaudi::Property< double > m_paramExtrapolationParLimit
ToolHandle< ActsTrk::IExtrapolationTool > m_extrapolationTool
TrackToTrackParticleCnvTool(const std::string &type, const std::string &name, const IInterface *parent)
Acts::BoundTrackParameters parametersAtPerigee(const EventContext &ctx, const ActsTrk::TrackContainer::ConstTrackProxy &track, const Acts::PerigeeSurface &perigee_surface) const
Gaudi::Property< bool > m_firstAndLastParamOnly
Gaudi::Property< bool > m_expectIfPixelContributes
std::unique_ptr< Propagator > m_propagator
Gaudi::Property< double > m_pixelExpectLayerPathLimitInMM
Acts::EigenStepper<> Stepper
Gaudi::Property< int > m_trackFitter
SG::ReadCondHandleKeyArray< InDetDD::SiDetectorElementCollection > m_siDetEleCollKey
Gaudi::Property< unsigned long > m_patternRecognitionInfo
virtual StatusCode initialize() override
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCacheCondObjInputKey
Gaudi::Property< std::vector< unsigned int > > m_siDetEleCollToMeasurementType
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
static xAOD::ParticleHypothesis convertParticleHypothesis(Acts::PdgParticle abs_pdg_id)
Acts::Navigator Navigator
virtual StatusCode convert(xAOD::TrackParticle &trackParticle, const EventContext &ctx, const ActsTrk::TrackContainer::ConstTrackProxy &track, const Acts::PerigeeSurface *perigeeSurface=nullptr, const InDet::BeamSpotData *beamspotData=nullptr) const override
Gaudi::Property< bool > m_computeExpectedLayerPattern
Helper class to gather hit summary information for e.g.
DetectorRegion
Regions for which hit counts are computed.
uint8_t contributingSharedHits(DetectorRegion region) const
return the number of shared hits in a certain detector region.
uint8_t sum(DetectorRegion region, uint8_t layer) const
return the total number of hits, outliers, and/or shared hits in the givrn detector region and layer.
uint8_t contributingOutlierHits(DetectorRegion region) const
return the number of outliers in a certain detector region.
uint8_t contributingHits(DetectorRegion region) const
return the number of hits 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
void getInitializedCache(MagField::AtlasFieldCache &cache) const
get B field cache for evaluation as a function of 2-d or 3-d position.
Class to hold the SiDetectorElement objects to be put in the detector store.
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,...
const_pointer_type cptr()
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)
static Root::TMsgLogger logger("iLumiCalc")
constexpr std::underlying_type< T_EnumClass >::type to_underlying(T_EnumClass an_enum)
Helper to convert class enum into an integer.
std::array< unsigned int, 4 > expectedLayerPattern(const EventContext &ctx, const 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...
Eigen::Matrix< double, 3, 1 > Vector3D
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
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:
@ noHypothesis
For material collection.
@ neutron
for Fatras usage
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?
@ 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].
@ numberOfInnermostPixelLayerEndcapOutliers
number of 0th layer endcap outliers
@ 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].
@ numberOfPixelEndcapHits
these are the pixel hits, in the endcap layers [unit8_t].
@ numberOfInnermostPixelLayerOutliers
number of 0th layer barrel outliers
@ 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
@ 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].
@ 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 std::array< unsigned int, 4 > get(const track_proxy_t &track)
static bool exists(track_container_t &trackContainer)