ATLAS Offline Software
Loading...
Searching...
No Matches
HLTMinBiasTrkMonAlg.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
5#include "Utils.h"
7
8HLTMinBiasTrkMonAlg::HLTMinBiasTrkMonAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthMonitorAlgorithm(name, pSvcLocator)
9{
10}
11
15
17{
18 ATH_CHECK(m_spCountsKey.initialize());
19 ATH_CHECK(m_trkCountsKey.initialize());
20 ATH_CHECK(m_offlineTrkKey.initialize());
21 ATH_CHECK(m_onlineTrkKey.initialize());
22 ATH_CHECK(m_lvl1EnergySumROIKey.initialize());
24 ATH_CHECK(m_vertexKey.initialize());
26
28}
29
31{
32
33 return StatusCode::SUCCESS;
34}
35
36StatusCode HLTMinBiasTrkMonAlg::fillHistograms(const EventContext& context) const
37{
38 ATH_CHECK(monitorPurities(context));
39 ATH_CHECK(monitorSPCounts(context));
41
42 return StatusCode::SUCCESS;
43}
44
45StatusCode HLTMinBiasTrkMonAlg::monitorPurities(const EventContext& /*context*/) const
46{
47
48 return StatusCode::SUCCESS;
49}
50
51StatusCode HLTMinBiasTrkMonAlg::monitorSPCounts(const EventContext& context) const
52{
53 auto spCountsHandle = SG::makeHandle(m_spCountsKey, context);
54 ATH_MSG_DEBUG("SP monitoring, handle validity " << spCountsHandle.isValid());
55 if (!spCountsHandle.isValid())
56 {
57 ATH_MSG_DEBUG("Could not retrieve spCountsHandle");
58 return StatusCode::SUCCESS;
59 }
60 if (spCountsHandle->size() == 0)
61 { // trigger did not run, no monitoring
62 return StatusCode::SUCCESS;
63 }
64 ATH_CHECK(spCountsHandle->size() == 1); // if object is present then it should have size == 1
65
66 using namespace Monitored;
67 const auto& trigDecTool = getTrigDecisionTool();
68
69 for (auto& trig : m_triggerListSpacePointsMon)
70 {
71 if (trigDecTool->isPassed(trig, TrigDefs::requireDecision))
72 {
73 ATH_MSG_DEBUG("Chain " << trig << " is passed: YES");
74 auto pixelCL = Scalar("PixelCL", spCountsHandle->at(0)->getDetail<int>("pixCL"));
75 auto PixBarr_SP = Scalar("PixBarr_SP", spCountsHandle->at(0)->getDetail<int>("pixCLBarrel"));
76 auto PixECA_SP = Scalar("PixECA_SP", spCountsHandle->at(0)->getDetail<int>("pixCLEndcapA"));
77 auto PixECC_SP = Scalar("PixECC_SP", spCountsHandle->at(0)->getDetail<int>("pixCLEndcapC"));
78
79 auto SctTot = Scalar("SctTot", spCountsHandle->at(0)->getDetail<int>("sctSP"));
80 auto SctBarr_SP = Scalar("SctBarr_SP", spCountsHandle->at(0)->getDetail<int>("sctSPBarrel"));
81 auto SctECA_SP = Scalar("SctECA_SP", spCountsHandle->at(0)->getDetail<int>("sctSPEndcapA"));
82 auto SctECC_SP = Scalar("SctECC_SP", spCountsHandle->at(0)->getDetail<int>("sctSPEndcapC"));
83
84 fill(trig + "_SpacePoints", pixelCL, PixBarr_SP, PixECA_SP, PixECC_SP, SctTot, SctBarr_SP, SctECA_SP, SctECC_SP);
85 }
86 else
87 ATH_MSG_DEBUG("Chain " << trig << " is passed: NO");
88 }
89
90 return StatusCode::SUCCESS;
91}
92
93
94StatusCode HLTMinBiasTrkMonAlg::monitorTrkCounts(const EventContext& context) const
95{
96 using namespace Monitored;
97 const auto& trigDecTool = getTrigDecisionTool();
98
99 auto trkCountsHandle = SG::makeHandle(m_trkCountsKey, context);
100 if (!trkCountsHandle.isValid())
101 {
102 ATH_MSG_DEBUG("Could not retrieve track counts");
103 return StatusCode::SUCCESS;
104 }
105
106 if (trkCountsHandle->size() == 0)
107 { // trigger did not run, no monitoring
108 return StatusCode::SUCCESS;
109 }
110 ATH_CHECK(trkCountsHandle->size() == 1); // if object is present then it should have size == 1
111 auto nTrkOnline = Scalar("nTrkOnline", trkCountsHandle->at(0)->getDetail<int>("ntrks"));
112 const std::vector<int>& counts = trkCountsHandle->at(0)->getDetail<std::vector<int>>("counts");
113
114 int countTrkVtxOnline = -1;
115 auto countsOnline = Collection("countsOnline", counts);
116 const std::vector<float>& ptCutValues = trkCountsHandle->at(0)->getDetail<std::vector<float>>("pTcuts");
117 const std::vector<float>& z0CutValues = trkCountsHandle->at(0)->getDetail<std::vector<float>>("z0cuts");
118 const std::vector<float>& vtxCutValues = trkCountsHandle->at(0)->getDetail<std::vector<float>>("vertexZcuts");
119 std::vector<std::string> descriptions(counts.size());
120
121 for (size_t i = 0; i < countsOnline.size(); ++i) {
122 std::ostringstream s;
123 s << "pt: " << ptCutValues[i];
124 s << " z0: " << z0CutValues[i];
125 auto vtxCut = vtxCutValues[i];
126 s << " vtx-z: " << vtxCut;
127 descriptions[i] = s.str();
128 if (vtxCut < 100) { // online counter that uses vertex cut
129 countTrkVtxOnline = counts[i];
130 }
131 }
132 auto countsOnlineNames = Collection("countsOnlineNames", descriptions);
133 auto nTrkOnlineVtx = Scalar("nTrkOnlineVtx", countTrkVtxOnline);
134
135 auto vertexHandle = SG::makeHandle(m_vertexKey, context);
136 const xAOD::Vertex* priVtx = Utils::selectPV(vertexHandle);
137 const float priVtxZ = priVtx == nullptr ? 999 : priVtx->z();
138
139 auto offlineVtxZ = Scalar("offlineVtxZ", priVtxZ);
140
141 auto offlineTrkHandle = SG::makeHandle(m_offlineTrkKey, context);
142 int countPassing = 0;
143 int countPassingVtx = 0;
144
145 auto track_selector = [this](const xAOD::TrackParticle* trk) {
146 return static_cast<bool>(m_trackSelectionTool->accept(*trk));
147 };
148
149 for (const auto trk : *offlineTrkHandle) {
150 if (track_selector(trk) and std::abs(trk->pt()) > m_minPt) {
151 ++countPassing;
152 if (priVtx and std::abs(Utils::z0wrtPV(trk, priVtx)) < m_z0 and std::abs(trk->d0()) < m_d0) {
153 ++countPassingVtx;
154 }
155 }
156 }
157 ATH_MSG_DEBUG("::monitorTrkCounts countPassing = " << countPassing);
158
159 auto onlineTrkHandle = SG::makeHandle(m_onlineTrkKey, context);
160
161 float maxWeight = -1;
162 float zPos = -999;
163 if (not m_zFinderDataKey.empty()) {
164 auto zFinderDataHandle = SG::makeHandle(m_zFinderDataKey, context);
165 for (auto vertex : *zFinderDataHandle) {
166 float weight = vertex->getDetail<float>("zfinder_vtx_weight");
167 if (weight > maxWeight) {
168 maxWeight = std::max(weight, maxWeight);
169 zPos = vertex->getDetail<float>("zfinder_vtx_z");
170 }
171 }
172 }
173 auto zFinderWeight = Scalar("zFinderWeight", maxWeight);
174 auto zFinderVtxZ = Scalar("zFinderVtxZ", zPos);
175 auto onlineOfflineVtxDelta = Scalar("onlineOfflineVtxDelta", priVtxZ - zPos);
176
177 auto nTrkOffline = Scalar("nTrkOffline", countPassing);
178 auto nTrkOfflineVtx = Scalar("nTrkOfflineVtx", countPassingVtx);
179 auto nAllTrkOffline = Scalar("nAllTrkOffline", offlineTrkHandle->size());
180 auto trkMask = Collection("trkMask", *offlineTrkHandle, [&](const auto& trk) { return track_selector(trk); });
181 auto trkPt = Collection("trkPt", *offlineTrkHandle, [](const auto& trk) { return trk->pt() * 1.e-3; });
182 auto trkEta = Collection("trkEta", *offlineTrkHandle, [](const auto& trk) { return trk->eta(); });
183 auto trkPhi = Collection("trkPhi", *offlineTrkHandle, [](const auto& trk) { return trk->phi(); });
184 auto trkD0 = Collection("trkD0", *offlineTrkHandle, [](const auto& trk) { return trk->d0(); });
185 auto trkZ0 = Collection("trkZ0", *offlineTrkHandle, [](const auto& trk) { return trk->z0(); });
186 auto trkZ0wrtPV = Collection("trkZ0wrtPV", *offlineTrkHandle, [priVtx](const auto& trk) {
187 return (priVtx != nullptr) ? Utils::z0wrtPV(trk, priVtx) : -999; });
188
189 auto getNhits = [](const xAOD::TrackParticle* trk) {
190 int nhits = 0;
191 uint32_t pattern = trk->hitPattern();
192 for (int bit = 0; bit < 32; bit++)
193 nhits += (pattern & (1u << bit) ? 1 : 0);
194 return nhits;
195 };
196 auto trkHits = Collection("trkHits", *offlineTrkHandle, getNhits);
197
198 auto onlTrkPt = Collection("onlTrkPt", *onlineTrkHandle, [](const auto& trk) { return trk->pt() * 1.e-3; });
199 auto onlTrkEta = Collection("onlTrkEta", *onlineTrkHandle, [](const auto& trk) { return trk->eta(); });
200 auto onlTrkPhi = Collection("onlTrkPhi", *onlineTrkHandle, [](const auto& trk) { return trk->phi(); });
201 auto onlTrkD0 = Collection("onlTrkD0", *onlineTrkHandle, [](const auto& trk) { return trk->d0(); });
202 auto onlTrkZ0 = Collection("onlTrkZ0", *onlineTrkHandle, [](const auto& trk) { return trk->z0(); });
203 auto onlTrkHits = Collection("onlTrkHits", *onlineTrkHandle, getNhits);
204
205 auto nMBTrkTrkOfflineRatio = Scalar("trkSelOfflineRatio", (offlineTrkHandle->size() == 0 ? -1 : static_cast<double>(nTrkOffline) / offlineTrkHandle->size()));
206
207 auto L1TEHandle = SG::makeHandle(m_lvl1EnergySumROIKey, context);
208 ATH_MSG_DEBUG("L1TE monitoring, handle validity " << L1TEHandle.isValid());
209 float sum_roi_sumEt = 0.;
210 if (!L1TEHandle.isValid()) sum_roi_sumEt = -1.;
211 else sum_roi_sumEt = static_cast<float>(L1TEHandle->energyT()) * 1.e-3;
212 auto L1sumEt = Scalar("L1sumEt", sum_roi_sumEt);
213
214 auto spCountsHandle = SG::makeHandle(m_spCountsKey, context);
215 ATH_MSG_DEBUG("SP monitoring, handle validity " << spCountsHandle.isValid());
216 if (!spCountsHandle.isValid())
217 {
218 ATH_MSG_DEBUG("Could not retrieve spCountsHandle ");
219 return StatusCode::SUCCESS;
220 }
221 if (spCountsHandle->size() == 0)
222 { // trigger did not run, no monitoring
223 return StatusCode::SUCCESS;
224 }
225 ATH_CHECK(spCountsHandle->size() == 1); // if object is present then it should have size == 1
226 for (auto& trig : m_triggerListTrackingMon)
227 {
228 if (trigDecTool->isPassed(trig, TrigDefs::requireDecision))
229 {
230 ATH_MSG_DEBUG("Chain " << trig << " is passed: YES");
231 auto pixelCL = Scalar("PixelCL", spCountsHandle->at(0)->getDetail<int>("pixCL"));
232 auto PixBarr_SP = Scalar("PixBarr_SP", spCountsHandle->at(0)->getDetail<int>("pixCLBarrel"));
233 auto PixECA_SP = Scalar("PixECA_SP", spCountsHandle->at(0)->getDetail<int>("pixCLEndcapA"));
234 auto PixECC_SP = Scalar("PixECC_SP", spCountsHandle->at(0)->getDetail<int>("pixCLEndcapC"));
235
236 auto SctTot = Scalar("SctTot", spCountsHandle->at(0)->getDetail<int>("sctSP"));
237 auto SctBarr_SP = Scalar("SctBarr_SP", spCountsHandle->at(0)->getDetail<int>("sctSPBarrel"));
238 auto SctECA_SP = Scalar("SctECA_SP", spCountsHandle->at(0)->getDetail<int>("sctSPEndcapA"));
239 auto SctECC_SP = Scalar("SctECC_SP", spCountsHandle->at(0)->getDetail<int>("sctSPEndcapC"));
240
241 ATH_MSG_DEBUG("::monitorTrkCounts Chain " << trig << " " << (trigDecTool->isPassed(trig, TrigDefs::requireDecision) ? "passed" : "did not pass"));
242
243 double nTrkRatio = nTrkOnline > 0 ? static_cast<double>(offlineTrkHandle->size()) / static_cast<double>(nTrkOnline) : -1.0;
244 auto trkRatio = Scalar("nTrkRatio", nTrkRatio);
245 fill(trig + "_Tracking", nTrkOffline, nTrkOfflineVtx, nAllTrkOffline, nTrkOnline, trkRatio, nMBTrkTrkOfflineRatio, pixelCL,
246 PixBarr_SP, PixECA_SP, PixECC_SP,
247 SctTot, SctBarr_SP, SctECA_SP, SctECC_SP,
248 L1sumEt,
249 countsOnline, countsOnlineNames,
250 trkMask, trkPt, trkEta, trkPhi, trkD0, trkZ0, trkZ0wrtPV, trkHits,
251 onlTrkPt, onlTrkEta, onlTrkPhi, onlTrkHits, onlTrkD0, onlTrkZ0,
252 zFinderWeight, zFinderVtxZ, offlineVtxZ, onlineOfflineVtxDelta,
253 nTrkOnlineVtx);
254 }
255
256 // measure eff wrt the L1
257 const unsigned int passBits = trigDecTool->isPassedBits(trig);
258 if ((!(passBits & TrigDefs::EF_prescaled)) && (passBits & TrigDefs::L1_isPassedAfterVeto)) { // HLT did run
259 auto decision = Scalar<int>("decision", trigDecTool->isPassed(trig, TrigDefs::requireDecision) ? 1 : 0); // HLT did pass
260 fill(trig + "_Tracking", nTrkOffline, nAllTrkOffline, nTrkOnline, decision);
261 }
262
263
264 }
265 return StatusCode::SUCCESS;
266}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
virtual StatusCode initialize() override
initialize
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
AthMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
ToolHandle< InDet::IInDetTrackSelectionTool > m_trackSelectionTool
StatusCode monitorTrkCounts(const EventContext &context) const
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_trkCountsKey
Gaudi::Property< float > m_z0
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexKey
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_spCountsKey
HLTMinBiasTrkMonAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< float > m_minPt
Gaudi::Property< std::vector< std::string > > m_triggerListSpacePointsMon
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_zFinderDataKey
virtual StatusCode finalize() override
Gaudi::Property< float > m_d0
StatusCode monitorPurities(const EventContext &context) const
virtual StatusCode fillHistograms(const EventContext &context) const override
adds event to the monitoring histograms
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_onlineTrkKey
StatusCode monitorSPCounts(const EventContext &context) const
Gaudi::Property< std::vector< std::string > > m_triggerListTrackingMon
virtual StatusCode initialize() override
initialize
SG::ReadHandleKey< xAOD::EnergySumRoI > m_lvl1EnergySumROIKey
virtual ~HLTMinBiasTrkMonAlg() override
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_offlineTrkKey
Declare a monitored scalar variable.
float z() const
Returns the z position.
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.
Generic monitoring tool for athena components.
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())
const xAOD::Vertex * selectPV(SG::ReadHandle< xAOD::VertexContainer > &container)
Finds the Primary Vertex.
double z0wrtPV(const xAOD::TrackParticle *trk, const xAOD::Vertex *vtx)
Provide the trk DCA w.r.t. the PV.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.