ATLAS Offline Software
HLTMinBiasTrkMonAlg.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
5 #include "Utils.h"
6 #include "HLTMinBiasTrkMonAlg.h"
7 
8 HLTMinBiasTrkMonAlg::HLTMinBiasTrkMonAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthMonitorAlgorithm(name, pSvcLocator)
9 {
10 }
11 
13 {
14 }
15 
17 {
18  ATH_CHECK(m_spCountsKey.initialize());
19  ATH_CHECK(m_trkCountsKey.initialize());
22  ATH_CHECK(m_lvl1EnergySumROIKey.initialize());
24  ATH_CHECK(m_vertexKey.initialize());
25 
27 }
28 
30 {
31 
32  return StatusCode::SUCCESS;
33 }
34 
35 StatusCode HLTMinBiasTrkMonAlg::fillHistograms(const EventContext& context) const
36 {
37 
38  ATH_CHECK(monitorPurities(context));
39  ATH_CHECK(monitorSPCounts(context));
40  ATH_CHECK(monitorTrkCounts(context));
41  ATH_CHECK(m_trackSelectionTool.retrieve());
42  return StatusCode::SUCCESS;
43 }
44 
45 StatusCode HLTMinBiasTrkMonAlg::monitorPurities(const EventContext& /*context*/) const
46 {
47 
48  return StatusCode::SUCCESS;
49 }
50 
51 StatusCode 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 
94 StatusCode 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  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 
206 
207  auto nMBTrkTrkOfflineRatio = Scalar("trkSelOfflineRatio", (offlineTrkHandle->size() == 0 ? -1 : static_cast<double>(nTrkOffline) / offlineTrkHandle->size()));
208 
209  auto L1TEHandle = SG::makeHandle(m_lvl1EnergySumROIKey, context);
210  ATH_MSG_DEBUG("L1TE monitoring, handle validity " << L1TEHandle.isValid());
211  float sum_roi_sumEt = 0.;
212  if (!L1TEHandle.isValid()) sum_roi_sumEt = -1.;
213  else sum_roi_sumEt = static_cast<float>(L1TEHandle->energyT()) * 1.e-3;
214  auto L1sumEt = Scalar("L1sumEt", sum_roi_sumEt);
215 
216  auto spCountsHandle = SG::makeHandle(m_spCountsKey, context);
217  ATH_MSG_DEBUG("SP monitoring, handle validity " << spCountsHandle.isValid());
218  if (!spCountsHandle.isValid())
219  {
220  ATH_MSG_DEBUG("Could not retrieve spCountsHandle ");
221  return StatusCode::SUCCESS;
222  }
223  if (spCountsHandle->size() == 0)
224  { // trigger did not run, no monitoring
225  return StatusCode::SUCCESS;
226  }
227  ATH_CHECK(spCountsHandle->size() == 1); // if object is present then it should have size == 1
228  for (auto& trig : m_triggerListTrackingMon)
229  {
230  if (trigDecTool->isPassed(trig, TrigDefs::requireDecision))
231  {
232  ATH_MSG_DEBUG("Chain " << trig << " is passed: YES");
233  auto pixelCL = Scalar("PixelCL", spCountsHandle->at(0)->getDetail<int>("pixCL"));
234  auto PixBarr_SP = Scalar("PixBarr_SP", spCountsHandle->at(0)->getDetail<int>("pixCLBarrel"));
235  auto PixECA_SP = Scalar("PixECA_SP", spCountsHandle->at(0)->getDetail<int>("pixCLEndcapA"));
236  auto PixECC_SP = Scalar("PixECC_SP", spCountsHandle->at(0)->getDetail<int>("pixCLEndcapC"));
237 
238  auto SctTot = Scalar("SctTot", spCountsHandle->at(0)->getDetail<int>("sctSP"));
239  auto SctBarr_SP = Scalar("SctBarr_SP", spCountsHandle->at(0)->getDetail<int>("sctSPBarrel"));
240  auto SctECA_SP = Scalar("SctECA_SP", spCountsHandle->at(0)->getDetail<int>("sctSPEndcapA"));
241  auto SctECC_SP = Scalar("SctECC_SP", spCountsHandle->at(0)->getDetail<int>("sctSPEndcapC"));
242 
243  ATH_MSG_DEBUG("::monitorTrkCounts Chain " << trig << " " << (trigDecTool->isPassed(trig, TrigDefs::requireDecision) ? "passed" : "did not pass"));
244 
245 
246  double nTrkRatio = offlineTrkHandle->size() > 0 ? static_cast<double>(offlineTrkHandle->size()) / static_cast<double>(trkCountsHandle->at(0)->getDetail<int>("ntrks")) : -1.0;
247  auto trkRatio = Scalar("nTrkRatio", nTrkRatio);
248  fill(trig + "_Tracking", nTrkOffline, nTrkOfflineVtx, nAllTrkOffline, nTrkOnline, trkRatio, nMBTrkTrkOfflineRatio, pixelCL,
249  PixBarr_SP, PixECA_SP, PixECC_SP,
250  SctTot, SctBarr_SP, SctECA_SP, SctECC_SP,
251  L1sumEt,
252  countsOnline, countsOnlineNames,
253  trkMask, trkPt, trkEta, trkPhi, trkD0, trkZ0, trkZ0wrtPV, trkHits,
254  onlTrkPt, onlTrkEta, onlTrkPhi, onlTrkHits, onlTrkD0, onlTrkZ0,
255  zFinderWeight, zFinderVtxZ, offlineVtxZ, onlineOfflineVtxDelta,
256  nTrkOnlineVtx);
257  }
258 
259  // measure eff wrt the L1
260  const unsigned int passBits = trigDecTool->isPassedBits(trig);
261  if ((!(passBits & TrigDefs::EF_prescaled)) && (passBits & TrigDefs::L1_isPassedAfterVeto)) { // HLT did run
262  auto decision = Scalar<int>("decision", trigDecTool->isPassed(trig, TrigDefs::requireDecision) ? 1 : 0); // HLT did pass
263  fill(trig + "_Tracking", nTrkOffline, nAllTrkOffline, nTrkOnline, decision);
264  }
265 
266 
267  }
268  return StatusCode::SUCCESS;
269 }
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
max
#define max(a, b)
Definition: cfImp.cxx:41
HLTMinBiasTrkMonAlg::m_zFinderDataKey
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_zFinderDataKey
Definition: HLTMinBiasTrkMonAlg.h:42
HLTMinBiasTrkMonAlg::m_z0
Gaudi::Property< float > m_z0
Definition: HLTMinBiasTrkMonAlg.h:50
HLTMinBiasTrkMonAlg::finalize
virtual StatusCode finalize() override
Definition: HLTMinBiasTrkMonAlg.cxx:29
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
HLTMinBiasTrkMonAlg::monitorPurities
StatusCode monitorPurities(const EventContext &context) const
Definition: HLTMinBiasTrkMonAlg.cxx:45
HLTMinBiasTrkMonAlg::monitorSPCounts
StatusCode monitorSPCounts(const EventContext &context) const
Definition: HLTMinBiasTrkMonAlg.cxx:51
HLTMinBiasTrkMonAlg::m_triggerListTrackingMon
Gaudi::Property< std::vector< std::string > > m_triggerListTrackingMon
Definition: HLTMinBiasTrkMonAlg.h:46
AthMonitorAlgorithm::getTrigDecisionTool
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
Definition: AthMonitorAlgorithm.cxx:189
xAOD::passBits
passBits
Definition: TrigPassBits_v1.cxx:115
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
HLTMinBiasTrkMonAlg::m_offlineTrkKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_offlineTrkKey
Definition: HLTMinBiasTrkMonAlg.h:38
HLTMinBiasTrkMonAlg::m_spCountsKey
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_spCountsKey
Definition: HLTMinBiasTrkMonAlg.h:36
HLTMinBiasTrkMonAlg::m_onlineTrkKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_onlineTrkKey
Definition: HLTMinBiasTrkMonAlg.h:39
dq_defect_copy_defect_database.descriptions
descriptions
Definition: dq_defect_copy_defect_database.py:73
lumiFormat.i
int i
Definition: lumiFormat.py:85
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Utils.h
HLTMinBiasTrkMonAlg::m_triggerListSpacePointsMon
Gaudi::Property< std::vector< std::string > > m_triggerListSpacePointsMon
Definition: HLTMinBiasTrkMonAlg.h:45
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
HLTMinBiasTrkMonAlg::m_trackSelectionTool
ToolHandle< InDet::IInDetTrackSelectionTool > m_trackSelectionTool
Definition: HLTMinBiasTrkMonAlg.h:48
xAOD::Vertex_v1::z
float z() const
Returns the z position.
AthMonitorAlgorithm::fill
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.
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
HLTMinBiasTrkMonAlg::monitorTrkCounts
StatusCode monitorTrkCounts(const EventContext &context) const
Definition: HLTMinBiasTrkMonAlg.cxx:94
HLTMinBiasTrkMonAlg::~HLTMinBiasTrkMonAlg
virtual ~HLTMinBiasTrkMonAlg() override
Definition: HLTMinBiasTrkMonAlg.cxx:12
Utils::z0wrtPV
double z0wrtPV(const xAOD::TrackParticle *trk, const xAOD::Vertex *vtx)
Provide the trk DCA w.r.t. the PV.
Definition: Trigger/TrigMonitoring/TrigMinBiasMonitoring/src/Utils.cxx:8
Utils::selectPV
const xAOD::Vertex * selectPV(SG::ReadHandle< xAOD::VertexContainer > &container)
Finds the Primary Vertex.
Definition: Trigger/TrigMonitoring/TrigMinBiasMonitoring/src/Utils.cxx:12
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
HLTMinBiasTrkMonAlg::m_vertexKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexKey
Definition: HLTMinBiasTrkMonAlg.h:43
HLTMinBiasTrkMonAlg::m_lvl1EnergySumROIKey
SG::ReadHandleKey< xAOD::EnergySumRoI > m_lvl1EnergySumROIKey
Definition: HLTMinBiasTrkMonAlg.h:41
HLTMinBiasTrkMonAlg::initialize
virtual StatusCode initialize() override
initialize
Definition: HLTMinBiasTrkMonAlg.cxx:16
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
HLTMinBiasTrkMonAlg::m_d0
Gaudi::Property< float > m_d0
Definition: HLTMinBiasTrkMonAlg.h:51
HLTMinBiasTrkMonAlg::m_minPt
Gaudi::Property< float > m_minPt
Definition: HLTMinBiasTrkMonAlg.h:49
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
HLTMinBiasTrkMonAlg::m_trkCountsKey
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_trkCountsKey
Definition: HLTMinBiasTrkMonAlg.h:37
HLTMinBiasTrkMonAlg::fillHistograms
virtual StatusCode fillHistograms(const EventContext &context) const override
adds event to the monitoring histograms
Definition: HLTMinBiasTrkMonAlg.cxx:35
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
TrackingPrimitives.h
HLTMinBiasTrkMonAlg::HLTMinBiasTrkMonAlg
HLTMinBiasTrkMonAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: HLTMinBiasTrkMonAlg.cxx:8
HLTMinBiasTrkMonAlg.h