202 {
204 if (wh_track_particles.record(std::make_unique<xAOD::TrackParticleContainer>(),
205 std::make_unique<xAOD::TrackParticleAuxContainer>()).isFailure()) {
207 return StatusCode::FAILURE;
208 }
209
210 SG::WriteDecorHandle<xAOD::TrackParticleContainer, ElementLink<ActsTrk::TrackContainer>> trackLink(
m_decorator_actsTracks, ctx);
211
213
214 const InDet::BeamSpotData *beamspot_data {nullptr};
217
221 beamspot_data = beamSpotHandle.
cptr();
222 }
223
227 vertexContainer = vertexHandle.
cptr();
228 if (vertexContainer->
size() == 0) {
229 ATH_MSG_ERROR(
"Retrieved an empty vertex container. This is totally wrong!");
230 return StatusCode::FAILURE;
231 }
232
235 primaryVertex = vtx;
236 break;
237 }
238 }
239
240 if (not primaryVertex) {
241 ATH_MSG_WARNING(
"Requested to compute track particles wrt primary vertex, but no primary vertex is found. Using dummy vertex");
242 primaryVertex = vertexContainer->front();
243 }
244 }
245
246 std::size_t nTracks = 0
ul;
247 std::vector<const ActsTrk::TrackContainer *> trackContainers;
249 SG::ReadHandle<ActsTrk::TrackContainer> handle =
SG::makeHandle( handleKey, ctx );
251 trackContainers.push_back( handle.
cptr() );
252 nTracks += trackContainers.back()->size();
253 }
254
255
256 std::vector<xAOD::TrackParticle*> toAddParticles;
257 toAddParticles.reserve(nTracks);
258 for (std::size_t
i(0);
i<nTracks; ++
i) {
260 }
261 track_particles->
insert(track_particles->
end(),
262 toAddParticles.begin(),
263 toAddParticles.end());
264
267 const AtlasFieldCacheCondObj *field_cond_data = fieldHandle.
cptr();
268 MagField::AtlasFieldCache fieldCache;
270
272 std::shared_ptr<Acts::PerigeeSurface> perigee_surface {nullptr};
277 }
278
284 }
285
288
289
290
291
292 std::vector<float> tmp_cov_vector;
293 std::vector<ActsTrk::TrackStateBackend::ConstTrackStateProxy::IndexType > tmp_param_state_idx;
294 tmp_param_state_idx.reserve(30);
296 std::vector<std::vector<float>> parametersVec;
297 ActsTrk::detail::HitSummaryData hitInfo;
298
299 unsigned int converted_track_states=0;
300
301 std::size_t particleCounter = 0
ul;
302 using namespace Acts::UnitLiterals;
303 for (const ActsTrk::TrackContainer *tracksContainer : trackContainers) {
304
306
307 for (const typename ActsTrk::TrackContainer::ConstTrackProxy track : *tracksContainer) {
309
310
311
312 Acts::BoundTrackParameters perigeeParam = [&] {
314
315
316
317 return track.createParametersAtReference();
318 }
319 else {
321 }
322 }();
323
324 Acts::BoundVector boundParams = perigeeParam.parameters();
326 boundParams[Acts::eBoundLoc1],
327 boundParams[Acts::eBoundPhi],
328 boundParams[Acts::eBoundTheta],
329 boundParams[Acts::eBoundQOverP] * 1_MeV);
330
331 if (perigeeParam.covariance().has_value()) {
332
333 lowerTriangleToVectorScaleLastRow(perigeeParam.covariance().value(),tmp_cov_vector,5, 1_MeV);
335 }
336
337 if (beamspot_data) {
340 }
341
342
346
347 const Acts::ParticleHypothesis &hypothesis =
track.particleHypothesis();
349 constexpr float inv_1_MeV = 1/1_MeV;
350
351
352
353
356
357 ActsTrk::detail::SumOfValues chi2_stat;
359 track,
360 siDetEleColl,
361 measurementToSummaryType,
362 chi2_stat,
363 hitInfo,
364 tmp_param_state_idx,
365 specialHitCounts);
366
367
368
369
370
371
372
373
374
375 std::array< std::tuple< uint8_t, uint8_t, uint8_t, bool >, 4> copy_summary {
379 false),
380
384 true),
385
389 true),
390
394 true) };
395
396 for (auto [src_region, dest_xaod_summary_layer, dest_xaod_summary_hits, add_outlier] : copy_summary ) {
397 setSummaryValue(*track_particle,
400 setSummaryValue(*track_particle,
402 + ( add_outlier
404 : 0),
406 }
407 setSummaryValue(*track_particle,
411 setSummaryValue(*track_particle,
414 setSummaryValue(*track_particle,
420 setSummaryValue(*track_particle,
424 setSummaryValue(*track_particle,
427 setSummaryValue(*track_particle,
430 setSummaryValue(*track_particle,
433 setSummaryValue(*track_particle,
437 setSummaryValue(*track_particle,
440
441
442 std::array<unsigned int,4> expect_layer_pattern{};
443 if (precalculatedLayerPattern) {
444
446 }
447 else {
448
449
455 perigeeParam,
457 : std::array<unsigned int,4> {0u,0u, 0u,0u} );
458 }
459
460
461 setSummaryValue(*track_particle,
462 static_cast<uint8_t>((expect_layer_pattern[0] & (1<<0)) != 0 ),
464 setSummaryValue(*track_particle,
465 static_cast<uint8_t>((expect_layer_pattern[0] & (1<<1)) != 0 ),
467 setSummaryValue(*track_particle,
470 setSummaryValue(*track_particle,
473 setSummaryValue(*track_particle,
476 setSummaryValue(*track_particle,
479 setSummaryValue(*track_particle,
482 setSummaryValue(*track_particle,
485
486
487 setSummaryValue(*track_particle,
490 setSummaryValue(*track_particle,
493 setSummaryValue(*track_particle,
496 setSummaryValue(*track_particle,
499
501 setSummaryValue(*track_particle,
502 static_cast<uint8_t> (biased_chi2_variance>0.
503 ? std::min(static_cast<unsigned int>(std::sqrt(biased_chi2_variance) * 100),255u)
504 : 0u),
506
507 setSummaryValue(*track_particle,
511
512
513
515 tmp_param_state_idx[1]=tmp_param_state_idx.back();
516 tmp_param_state_idx.erase(tmp_param_state_idx.begin()+2,tmp_param_state_idx.end());
517 }
518
519
520 parametersVec.clear();
521 parametersVec.reserve(tmp_param_state_idx.size());
522
523 for(std::vector<ActsTrk::TrackStateBackend::ConstTrackStateProxy::IndexType>::const_reverse_iterator
524 idx_iter = tmp_param_state_idx.rbegin();
525 idx_iter != tmp_param_state_idx.rend();
526 ++idx_iter) {
527
528 ActsTrk::TrackStateBackend::ConstTrackStateProxy
529 state = tracksContainer->trackStateContainer().getTrackState(*idx_iter);
530 const Acts::BoundTrackParameters actsParam =
track.createParametersFromState(state);
531
532 Acts::Vector3 position = actsParam.position(gctx.context());
533 Acts::Vector3
momentum = actsParam.momentum();
534
535
536 for (
unsigned int i=0;
i<
momentum.rows(); ++
i) {
538 }
539
540
541 if (actsParam.covariance()) {
543 Acts::GeometryContext tgContext = gctx.context();
544
545 magnFieldVect.setZero();
546 fieldCache.
getField(position.data(), magnFieldVect.data());
547
548 {
549 using namespace Acts::UnitLiterals;
550 magnFieldVect *= 1000_T;
551 }
552
554 if (curvilinear_cov_result.has_value()) {
555 Acts::BoundSquareMatrix &curvilinear_cov = curvilinear_cov_result.value();
556
557
558 for (unsigned int col_i=0; col_i<4; ++col_i) {
559 curvilinear_cov(col_i,4) *= 1_MeV;
560 curvilinear_cov(4,col_i) *= 1_MeV;
561 }
562 curvilinear_cov(4,4) *= (1_MeV * 1_MeV);
563
564 std::size_t param_idx = parametersVec.size();
565
566 lowerTriangleToVector(curvilinear_cov,tmp_cov_vector,5);
567 if (tmp_cov_vector.size() != 15) {
568 ATH_MSG_ERROR(
"Invalid size of lower triangle cov " << tmp_cov_vector.size() <<
" != 15"
569 << " input matrix : " << curvilinear_cov.rows() << " x " << curvilinear_cov.cols() );
570 }
572 }
573 }
574 parametersVec.emplace_back(std::vector<float>{
575 static_cast<float>(position[0]),static_cast<float>(position[1]),static_cast<float>(position[2]),
576 static_cast<float>(momentum[0]),
static_cast<float>(
momentum[1]),
static_cast<float>(momentum[2]) });
577 ++converted_track_states;
578
579
580 }
581 for (const std::vector<float> ¶m : parametersVec) {
582 if (param.size() != 6) {
583 ATH_MSG_ERROR(
"Invalid size of param element " << param.size() <<
" != 6" );
584 }
585 }
586
588
589
590 trackLink(*track_particle)
591 = ElementLink<ActsTrk::TrackContainer>( tracksContainer,
594 }
595 }
596 ATH_MSG_DEBUG(
"Converted " << nTracks <<
" acts tracks into " << track_particles->
size()
597 << " track particles with parameters for " << converted_track_states << " track states.");
598
599 return StatusCode::SUCCESS;
600 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
static std::vector< std::pair< Acts::PdgParticle, xAOD::ParticleHypothesis > > s_actsHypothesisToxAOD ATLAS_THREAD_SAFE
static xAOD::ParticleHypothesis convertParticleHypothesis(Acts::PdgParticle abs_pdg_id)
static std::shared_ptr< Acts::PerigeeSurface > makePerigeeSurface(const InDet::BeamSpotData *beamspotptr)
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_decorator_actsTracks
SG::ReadCondHandleKeyArray< InDetDD::SiDetectorElementCollection > m_siDetEleCollKey
Gaudi::Property< double > m_pixelExpectLayerPathLimitInMM
Gaudi::Property< bool > m_expectIfPixelContributes
expressionStrategy m_expression_strategy
Acts::BoundTrackParameters parametersAtPerigee(const EventContext &ctx, const typename ActsTrk::TrackContainer::ConstTrackProxy &track, const Acts::PerigeeSurface &perigee_surface) const
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_trackParticlesOutKey
Gaudi::Property< bool > m_firstAndLastParamOnly
Gaudi::Property< std::vector< unsigned int > > m_siDetEleCollToMeasurementType
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
Gaudi::Property< bool > m_computeExpectedLayerPattern
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexHandle
ToolHandle< ActsTrk::IExtrapolationTool > m_extrapolationTool
SG::ReadHandleKeyArray< ActsTrk::TrackContainer > m_tracksContainerKey
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCacheCondObjInputKey
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.
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.
const T * at(size_type n) const
Access an element, as an rvalue.
iterator insert(iterator position, value_type pElem)
Add a new element to the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
float beamTilt(int i) const noexcept
Returns the beam sigma for the i+3-th error matrix element (the 'tilt')
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()
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
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 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 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)
void gatherTrackSummaryData(const ActsTrk::TrackContainer &tracksContainer, const typename ActsTrk::TrackContainer::ConstTrackProxy &track, const std::array< const InDetDD::SiDetectorElementCollection *, to_underlying(xAOD::UncalibMeasType::nTypes)> &siDetEleColl, const std::array< unsigned short, to_underlying(xAOD::UncalibMeasType::nTypes)> &measurement_to_summary_type, SumOfValues &chi2_stat_out, HitSummaryData &hit_info_out, std::vector< ActsTrk::TrackStateBackend::ConstTrackStateProxy::IndexType > ¶m_state_idx_out, std::array< std::array< uint8_t, to_underlying(HitCategory::N)>, to_underlying(xAOD::UncalibMeasType::nTypes)> &special_hit_counts_out)
Helper to gather track summary information from the track states of the specified track.
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.
Eigen::Matrix< double, 3, 1 > Vector3D
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
@ KalmanFitter
tracks produced by the Kalman Fitter
TrackParticle_v1 TrackParticle
Reference the current persistent version:
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container 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?
@ 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].
@ 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].
@ SiSPSeededFinder
Tracks from SiSPSeedFinder.
static std::array< unsigned int, 4 > get(const track_proxy_t &track)
static bool exists(track_container_t &trackContainer)