ATLAS Offline Software
Loading...
Searching...
No Matches
TrackParticleAnalysisAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include <iostream>
9#include <sstream>
10#include <iomanip>
11
12namespace {
13 int getSummaryValue(const xAOD::TrackParticle &track_particle, xAOD::SummaryType summary_type) {
15 return track_particle.summaryValue(tmp, summary_type) ? static_cast<int>(tmp) : -1;
16 }
17}
18
19
20namespace ActsTrk {
21
22 TrackParticleAnalysisAlg::TrackParticleAnalysisAlg(const std::string& name, ISvcLocator* pSvcLocator)
23 : AthMonitorAlgorithm(name, pSvcLocator)
24 {}
25
27 ATH_MSG_DEBUG("Initializing " << name() << " ...");
28
29 ATH_MSG_VERBOSE("Properties:");
31
32 ATH_CHECK(m_tracksKey.initialize());
33
34 ATH_MSG_VERBOSE("Monitoring settings ...");
36
38 }
39
40 StatusCode TrackParticleAnalysisAlg::fillHistograms(const EventContext& ctx) const {
41 ATH_MSG_DEBUG( "Filling Histograms for " << name() << " ... " );
42
43 // Retrieve the tracks
45 ATH_CHECK(trackParticlesHandle.isValid());
46 const xAOD::TrackParticleContainer *track_particles = trackParticlesHandle.cptr();
47
49 for (const xAOD::TrackParticle *track_particle : *track_particles) {
50 ATH_CHECK( monitorTrackStateCounts(*track_particle) );
51 }
52 }
53 auto monitor_pt = Monitored::Collection("pt", *track_particles,
54 [](const xAOD::TrackParticle *tp){return static_cast<double>(tp->pt()); } );
55 auto monitor_eta = Monitored::Collection("eta", *track_particles,
56 [](const xAOD::TrackParticle *tp){return static_cast<double>(tp->eta()); } );
57
58 auto monitor_pixelHits = Monitored::Collection("pixelHits", *track_particles,
59 [](const xAOD::TrackParticle *tp){
60 return getSummaryValue(*tp,xAOD::numberOfPixelHits); });
61
62 auto monitor_innermostHits = Monitored::Collection("innermostHits", *track_particles,
63 [](const xAOD::TrackParticle *tp){
64 return getSummaryValue(*tp,xAOD::numberOfInnermostPixelLayerHits); });
65
66 auto monitor_nextToInnermostHits = Monitored::Collection("nextToInnermostHits", *track_particles,
67 [](const xAOD::TrackParticle *tp){
68 return getSummaryValue(*tp,xAOD::numberOfNextToInnermostPixelLayerHits);});
69
70 auto monitor_expectInnermost = Monitored::Collection("expectInnermostHit", *track_particles,
71 [](const xAOD::TrackParticle *tp){
72 return getSummaryValue(*tp,xAOD::expectInnermostPixelLayerHit); });
73
74 auto monitor_expectNextToInnermost = Monitored::Collection("expectNextToInnermostHit", *track_particles,
75 [](const xAOD::TrackParticle *tp){
76 return getSummaryValue(*tp,xAOD::expectNextToInnermostPixelLayerHit); });
77
78 fill(m_monGroupName.value(),monitor_pt,monitor_eta, monitor_pixelHits, monitor_innermostHits, monitor_nextToInnermostHits,
79 monitor_expectInnermost, monitor_expectNextToInnermost);
80 return StatusCode::SUCCESS;
81 }
82
84 std::optional<ActsTrk::TrackContainer::ConstTrackProxy> optional_track = getActsTrack(track_particle);
85 if ( not optional_track.has_value() ) {
86 ATH_MSG_WARNING("Invalid track link for particle " << track_particle.index());
87 return StatusCode::SUCCESS;
88 }
89
90 ActsTrk::TrackContainer::ConstTrackProxy track = optional_track.value();
91 std::array<uint8_t, Acts::toUnderlying(Acts::TrackStateFlag::NumFlags)+1> counts{};
92
93 const ActsTrk::TrackContainer::ConstTrackProxy::IndexType
94 lastMeasurementIndex = track.tipIndex();
95
96 track.container().trackStateContainer().visitBackwards(lastMeasurementIndex,
97 [&counts] (const typename ActsTrk::TrackStateBackend::ConstTrackStateProxy &state) -> void
98 {
99 auto flags = state.typeFlags();
100 ++counts[Acts::toUnderlying(Acts::TrackStateFlag::NumFlags)];
101
102 for (unsigned int flag_i=0; flag_i<Acts::toUnderlying(Acts::TrackStateFlag::NumFlags); ++flag_i) {
103 if (flags.test(flag_i)) {
104 if (flag_i == Acts::toUnderlying(Acts::TrackStateFlag::IsHole)) {
105 if (!state.hasReferenceSurface() || !state.referenceSurface().isSensitive()) continue;
106 }
107 ++counts[flag_i];
108 }
109 }
110 });
111
112 auto monitor_states = Monitored::Scalar<int>("States",counts[Acts::toUnderlying(Acts::TrackStateFlag::NumFlags)]);
113 auto monitor_measurement = Monitored::Scalar<int>("Measurements",counts[Acts::toUnderlying(Acts::TrackStateFlag::HasMeasurement)]);
114 auto monitor_parameter = Monitored::Scalar<int>("Parameters",counts[Acts::toUnderlying(Acts::TrackStateFlag::HasParameters)]);
115 auto monitor_outlier = Monitored::Scalar<int>("Outliers",counts[Acts::toUnderlying(Acts::TrackStateFlag::IsOutlier)]);
116 auto monitor_hole = Monitored::Scalar<int>("Holes",counts[Acts::toUnderlying(Acts::TrackStateFlag::IsHole)]);
117 auto monitor_material = Monitored::Scalar<int>("MaterialStates",counts[Acts::toUnderlying(Acts::TrackStateFlag::HasMaterial)]);
118 auto monitor_sharedHit = Monitored::Scalar<int>("SharedHits",counts[Acts::toUnderlying(Acts::TrackStateFlag::IsSharedHit)]);
119
120 fill(m_monGroupName.value(),
121 monitor_states, monitor_measurement, monitor_parameter, monitor_outlier, monitor_hole,
122 monitor_material, monitor_sharedHit);
123 return StatusCode::SUCCESS;
124 }
125
126}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
virtual StatusCode initialize() override
initialize
TrackParticleAnalysisAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Gaudi::Property< bool > m_monitorTrackStateCounts
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_tracksKey
Gaudi::Property< std::string > m_monGroupName
StatusCode monitorTrackStateCounts(const xAOD::TrackParticle &track_particle) const
virtual StatusCode initialize() override
initialize
AthMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Declare a monitored scalar variable.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
bool summaryValue(uint8_t &value, const SummaryType &information) const
Accessor for TrackSummary values.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable > > &&variables) const
Fills a vector of variables to a group by reference.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::optional< ActsTrk::TrackContainer::ConstTrackProxy > getActsTrack(const xAOD::TrackParticle &trkPart)
Return the proxy to the Acts track from which the track particle was made frome.
Definition Decoration.cxx:9
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
SummaryType
Enumerates the different types of information stored in Summary.
@ expectInnermostPixelLayerHit
Do we expect a 0th-layer barrel hit for this track?
@ numberOfNextToInnermostPixelLayerHits
these are the hits in the 1st pixel barrel layer
@ expectNextToInnermostPixelLayerHit
Do we expect a 1st-layer barrel hit for this track?
@ numberOfInnermostPixelLayerHits
these are the hits in the 0th pixel barrel layer
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].