ATLAS Offline Software
Loading...
Searching...
No Matches
TrackParticleAnalysisAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
9#include <iostream>
10#include <sstream>
11#include <iomanip>
12
13namespace {
14 int getSummaryValue(const xAOD::TrackParticle &track_particle, xAOD::SummaryType summary_type) {
16 return track_particle.summaryValue(tmp, summary_type) ? static_cast<int>(tmp) : -1;
17 }
18}
19
20
21namespace ActsTrk {
22
23 TrackParticleAnalysisAlg::TrackParticleAnalysisAlg(const std::string& name, ISvcLocator* pSvcLocator)
24 : AthMonitorAlgorithm(name, pSvcLocator)
25 {}
26
28 ATH_MSG_DEBUG("Initializing " << name() << " ...");
29
30 ATH_MSG_VERBOSE("Properties:");
32
33 ATH_CHECK(m_tracksKey.initialize());
34
35 ATH_MSG_VERBOSE("Monitoring settings ...");
37
39 }
40
41 StatusCode TrackParticleAnalysisAlg::fillHistograms(const EventContext& ctx) const {
42 ATH_MSG_DEBUG( "Filling Histograms for " << name() << " ... " );
43
44 // Retrieve the tracks
46 ATH_CHECK(trackParticlesHandle.isValid());
47 const xAOD::TrackParticleContainer *track_particles = trackParticlesHandle.cptr();
48
50 for (const xAOD::TrackParticle *track_particle : *track_particles) {
51 ATH_CHECK( monitorTrackStateCounts(*track_particle) );
52 }
53 }
54 auto monitor_pt = Monitored::Collection("pt", *track_particles,
55 [](const xAOD::TrackParticle *tp){return static_cast<double>(tp->pt()); } );
56 auto monitor_eta = Monitored::Collection("eta", *track_particles,
57 [](const xAOD::TrackParticle *tp){return static_cast<double>(tp->eta()); } );
58
59 auto monitor_pixelHits = Monitored::Collection("pixelHits", *track_particles,
60 [](const xAOD::TrackParticle *tp){
61 return getSummaryValue(*tp,xAOD::numberOfPixelHits); });
62
63 auto monitor_innermostHits = Monitored::Collection("innermostHits", *track_particles,
64 [](const xAOD::TrackParticle *tp){
65 return getSummaryValue(*tp,xAOD::numberOfInnermostPixelLayerHits); });
66
67 auto monitor_nextToInnermostHits = Monitored::Collection("nextToInnermostHits", *track_particles,
68 [](const xAOD::TrackParticle *tp){
69 return getSummaryValue(*tp,xAOD::numberOfNextToInnermostPixelLayerHits);});
70
71 auto monitor_expectInnermost = Monitored::Collection("expectInnermostHit", *track_particles,
72 [](const xAOD::TrackParticle *tp){
73 return getSummaryValue(*tp,xAOD::expectInnermostPixelLayerHit); });
74
75 auto monitor_expectNextToInnermost = Monitored::Collection("expectNextToInnermostHit", *track_particles,
76 [](const xAOD::TrackParticle *tp){
77 return getSummaryValue(*tp,xAOD::expectNextToInnermostPixelLayerHit); });
78
79 fill(m_monGroupName.value(),monitor_pt,monitor_eta, monitor_pixelHits, monitor_innermostHits, monitor_nextToInnermostHits,
80 monitor_expectInnermost, monitor_expectNextToInnermost);
81 return StatusCode::SUCCESS;
82 }
83
85 std::optional<ActsTrk::TrackContainer::ConstTrackProxy> optional_track = getActsTrack(track_particle);
86 if ( not optional_track.has_value() ) {
87 ATH_MSG_WARNING("Invalid track link for particle " << track_particle.index());
88 return StatusCode::SUCCESS;
89 }
90
91 ActsTrk::TrackContainer::ConstTrackProxy track = optional_track.value();
92 std::array<uint8_t, Acts::toUnderlying(Acts::TrackStateFlag::NumFlags)+1> counts{};
93
94 const ActsTrk::TrackContainer::ConstTrackProxy::IndexType
95 lastMeasurementIndex = track.tipIndex();
96
97 track.container().trackStateContainer().visitBackwards(lastMeasurementIndex,
98 [&counts] (const typename ActsTrk::TrackStateBackend::ConstTrackStateProxy &state) -> void
99 {
100 auto flags = state.typeFlags();
101 ++counts[Acts::toUnderlying(Acts::TrackStateFlag::NumFlags)];
102
103 for (unsigned int flag_i=0; flag_i<Acts::toUnderlying(Acts::TrackStateFlag::NumFlags); ++flag_i) {
104 if (flags.test(flag_i)) {
105 if (flag_i == Acts::toUnderlying(Acts::TrackStateFlag::IsHole)) {
106 if (!state.hasReferenceSurface() || !state.referenceSurface().isSensitive()) continue;
107 }
108 ++counts[flag_i];
109 }
110 }
111 });
112
113 auto monitor_states = Monitored::Scalar<int>("States",counts[Acts::toUnderlying(Acts::TrackStateFlag::NumFlags)]);
114 auto monitor_measurement = Monitored::Scalar<int>("Measurements",counts[Acts::toUnderlying(Acts::TrackStateFlag::HasMeasurement)]);
115 auto monitor_parameter = Monitored::Scalar<int>("Parameters",counts[Acts::toUnderlying(Acts::TrackStateFlag::HasParameters)]);
116 auto monitor_outlier = Monitored::Scalar<int>("Outliers",counts[Acts::toUnderlying(Acts::TrackStateFlag::IsOutlier)]);
117 auto monitor_hole = Monitored::Scalar<int>("Holes",counts[Acts::toUnderlying(Acts::TrackStateFlag::IsHole)]);
118 auto monitor_material = Monitored::Scalar<int>("MaterialStates",counts[Acts::toUnderlying(Acts::TrackStateFlag::HasMaterial)]);
119 auto monitor_sharedHit = Monitored::Scalar<int>("SharedHits",counts[Acts::toUnderlying(Acts::TrackStateFlag::IsSharedHit)]);
120
121 fill(m_monGroupName.value(),
122 monitor_states, monitor_measurement, monitor_parameter, monitor_outlier, monitor_hole,
123 monitor_material, monitor_sharedHit);
124 return StatusCode::SUCCESS;
125 }
126
127}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Hold a pointer to the current event store.
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].