ATLAS Offline Software
Loading...
Searching...
No Matches
TrackAnalysisAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
6
8#include "TrackAnalysisAlg.h"
9
10template <>
11struct Monitored::detail::get_value_type<ActsTrk::TrackContainer> { typedef typename ActsTrk::TrackContainer::TrackProxy value_type; };
12
13
14namespace ActsTrk {
15
16 TrackAnalysisAlg::TrackAnalysisAlg(const std::string& name, ISvcLocator* pSvcLocator)
17 : AthMonitorAlgorithm(name, pSvcLocator)
18 {}
19
21 ATH_MSG_INFO("Initializing " << name() << " ...");
22
23 ATH_MSG_DEBUG("Properties:");
25
26 ATH_CHECK(m_tracksKey.initialize());
27
28 ATH_MSG_DEBUG("Monitoring settings ...");
30
31 ATH_CHECK(detStore()->retrieve(m_pixelID,"PixelID"));
32 ATH_CHECK(detStore()->retrieve(m_stripID,"SCT_ID"));
33
35 }
36
37 namespace {
38 std::array<uint8_t,static_cast<unsigned int>(xAOD::UncalibMeasType::nTypes)> countHits(
39 const ActsTrk::TrackContainer &tracksContainer,
40 const typename ActsTrk::TrackContainer::ConstTrackProxy& track) {
41 std::array<uint8_t,static_cast<unsigned int>(xAOD::UncalibMeasType::nTypes)> hit_counts_out{};
42 tracksContainer.trackStateContainer().visitBackwards(
43 track.tipIndex(),
44 [
45 &hit_counts_out
46 ](const typename ActsTrk::TrackStateBackend::ConstTrackStateProxy &state) -> void
47 {
48
49 if (state.hasUncalibratedSourceLink()) {
50 const xAOD::UncalibratedMeasurement * measurement = detail::xAODUncalibMeasCalibrator::unpack(state.getUncalibratedSourceLink());
51 if (measurement) {
52 assert( static_cast<unsigned int >(measurement->type() < xAOD::UncalibMeasType::nTypes));
53 ++hit_counts_out[static_cast<unsigned int >(measurement->type())];
54 }
55
56 }
57 });
58 return hit_counts_out;
59 }
60 }
61
62 StatusCode TrackAnalysisAlg::fillHistograms(const EventContext& ctx) const {
63 ATH_MSG_DEBUG( "Filling Histograms for " << name() << " ... " );
64
65 // Retrieve the tracks
66 const ActsTrk::TrackContainer *tracks{nullptr};
67 ATH_CHECK(SG::get(tracks, m_tracksKey, ctx));
68 using ConstTrackProxy = ActsTrk::TrackContainer::ConstTrackProxy;
69
70 // TODO this copy will be eliminated once the TrackContainer has [] operator
71 std::vector<ConstTrackProxy> proxies;
72 for (auto proxy: *tracks ) {
73 proxies.push_back(proxy);
74 }
75
76 std::vector<int> nSharedPerTrack {};
77 nSharedPerTrack.reserve(tracks->size());
78
79 std::vector<int> nSharedPixelBarrelLayer;
80 std::vector<int> nSharedPixelEndCapLayer;
81 std::vector<int> nSharedStripBarrelLayer;
82 std::vector<int> nSharedStripEndCapLayer;
83 nSharedPixelBarrelLayer.reserve(5*tracks->size());
84 nSharedPixelEndCapLayer.reserve(5*tracks->size());
85 nSharedStripBarrelLayer.reserve(5*tracks->size());
86 nSharedStripEndCapLayer.reserve(5*tracks->size());
87
88 for (const auto track_proxy : proxies) {
89 int nShared = 0;
90 track_proxy.container().trackStateContainer()
91 .visitBackwards(track_proxy.tipIndex(),
92 [this,
93 &nShared,
94 &nSharedPixelBarrelLayer, &nSharedPixelEndCapLayer,
95 &nSharedStripBarrelLayer, &nSharedStripEndCapLayer]
96 (const auto& state)
97 {
98 auto flags = state.typeFlags();
99 if (not flags.isSharedHit()) return;
100 ++nShared;
101 // get measurement -> if barrel/endcap and layer number
102 auto cluster = detail::xAODUncalibMeasCalibrator::unpack(state.getUncalibratedSourceLink());
103 assert( cluster != nullptr);
104 xAOD::DetectorIDHashType idHash = cluster->identifierHash();
105
106 xAOD::UncalibMeasType clusterType = cluster->type();
107 if (clusterType == xAOD::UncalibMeasType::PixelClusterType) {
108 const Identifier& id = m_pixelID->wafer_id(idHash);
109 auto barrel_or_endcap = m_pixelID->barrel_ec(id);
110 auto layer = m_pixelID->layer_disk(id);
111 if (barrel_or_endcap == 0) {
112 nSharedPixelBarrelLayer.push_back(layer);
113 } else {
114 nSharedPixelEndCapLayer.push_back(layer);
115 }
116 } else if (clusterType == xAOD::UncalibMeasType::StripClusterType) {
117 const Identifier& id = m_stripID->wafer_id(idHash);
118 auto barrel_or_endcap = m_stripID->barrel_ec(id);
119 auto layer = m_stripID->layer_disk(id);
120 if (barrel_or_endcap == 0) {
121 nSharedStripBarrelLayer.push_back(layer);
122 } else {
123 nSharedStripEndCapLayer.push_back(layer);
124 }
125 }
126
127 } );
128 nSharedPerTrack.push_back(nShared);
129 }
130
131 auto monitor_nsharedpertrack = Monitored::Collection("nShared", nSharedPerTrack);
132 auto monitor_nsharedperlayer_pixelbarrel = Monitored::Collection("NsharedPerLayer_pixelBarrel", nSharedPixelBarrelLayer);
133 auto monitor_nsharedperlayer_pixelendcap = Monitored::Collection("NsharedPerLayer_pixelEndCap", nSharedPixelEndCapLayer);
134 auto monitor_nsharedperlayer_stripbarrel = Monitored::Collection("NsharedPerLayer_stripBarrel", nSharedStripBarrelLayer);
135 auto monitor_nsharedperlayer_stripendcap = Monitored::Collection("NsharedPerLayer_stripEndCap", nSharedStripEndCapLayer);
136
137 auto monitor_ntracks = Monitored::Scalar<int>("Ntracks", tracks->size());
138 auto monitor_theta = Monitored::Collection("theta", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.theta()); } );
139 auto monitor_eta = Monitored::Collection("eta", proxies,
140 [](const ConstTrackProxy& tp)
141 { return static_cast<double>( -std::log(std::tan(tp.theta() * 0.5)) ); } );
142 auto monitor_qoverp = Monitored::Collection("qoverp", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.qOverP()); } );
143 auto monitor_pt = Monitored::Collection("pt", proxies, [](const ConstTrackProxy& tp){ return tp.transverseMomentum(); } );
144 auto monitor_phi = Monitored::Collection("phi", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.phi()); } );
145 auto monitor_chi2 = Monitored::Collection("chi2", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.chi2()); } );
146 auto monitor_chi2OverNdof = Monitored::Collection("chi2OverNdof", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.chi2()/tp.nDoF()); } );
147 auto monitor_ndof = Monitored::Collection("ndof", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.nDoF()); } );
148 auto monitor_nstates = Monitored::Collection("nStates", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.nTrackStates()); } );
149 // @TODO not particular efficient to count the hits twice ...
150 auto monitor_nPixelHits = Monitored::Collection("nPixelHits", proxies, [&tracks](const ConstTrackProxy& tp){
151 return countHits(*tracks,tp)[static_cast<unsigned int>(xAOD::UncalibMeasType::PixelClusterType)]; } );
152 auto monitor_nStripHits = Monitored::Collection("nStripHits", proxies, [&tracks](const ConstTrackProxy& tp){
153 return countHits(*tracks,tp)[static_cast<unsigned int>(xAOD::UncalibMeasType::StripClusterType)]; } );
154 auto monitor_nmeas = Monitored::Collection("nMeasurements", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.nMeasurements()); } );
155 auto monitor_noutliers = Monitored::Collection("nOutliers", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.nOutliers()); } );
156 auto monitor_nholes = Monitored::Collection("nHoles", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.nHoles()); } );
157 auto monitor_surftype = Monitored::Collection("surfaceType", proxies, [](const ConstTrackProxy& tp){ return static_cast<double>(tp.referenceSurface().type()); } );
158
159
160 fill(m_monGroupName.value(),
161 monitor_nsharedpertrack,
162 monitor_nsharedperlayer_pixelbarrel, monitor_nsharedperlayer_pixelendcap,
163 monitor_nsharedperlayer_stripbarrel, monitor_nsharedperlayer_stripendcap,
164 monitor_ntracks, monitor_theta, monitor_eta, monitor_phi, monitor_pt,
165 monitor_qoverp, monitor_nstates, monitor_phi, monitor_chi2, monitor_chi2OverNdof,
166 monitor_ndof, monitor_nstates, monitor_nmeas, monitor_noutliers, monitor_nholes, monitor_surftype,
167 monitor_nPixelHits, monitor_nStripHits);
168
169 return StatusCode::SUCCESS;
170 }
171
172}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
if(pathvar)
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Gaudi::Property< std::string > m_monGroupName
virtual StatusCode initialize() override
initialize
TrackAnalysisAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< ActsTrk::TrackContainer > m_tracksKey
const ServiceHandle< StoreGateSvc > & detStore() const
virtual StatusCode initialize() override
initialize
AthMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Declare a monitored scalar variable.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Get element type for containers.
void fill(H5::Group &out_file, size_t iterations)