ATLAS Offline Software
HLTMinBiasEffMonitoringAlg.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"
7 
8 HLTMinBiasEffMonitoringAlg::HLTMinBiasEffMonitoringAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthMonitorAlgorithm(name, pSvcLocator) {}
9 
11 
13 {
14  using namespace Monitored;
17  ATH_CHECK(m_trkCountsKey.initialize());
18  ATH_CHECK(m_vertexKey.initialize());
19  ATH_CHECK(m_refTriggerList.size() == m_triggerList.size());
20  std::set<std::string> temp(m_triggerList.begin(), m_triggerList.end());
21  m_uniqueTriggerList.insert(m_uniqueTriggerList.end(), temp.begin(), temp.end());
22 
23  ATH_CHECK(m_trackSelectionTool.retrieve());
24 
26 }
27 
29 {
30  return StatusCode::SUCCESS;
31 }
32 
33 StatusCode HLTMinBiasEffMonitoringAlg::fillHistograms(const EventContext& context) const
34 {
35  using namespace Monitored;
36 
37  const auto& trigDecTool = getTrigDecisionTool();
38 
39  auto vertexHandle = SG::makeHandle(m_vertexKey, context);
40  const xAOD::Vertex* priVtx = Utils::selectPV(vertexHandle);
41 
42  auto offlineTrkHandle = SG::makeHandle(m_offlineTrkKey, context);
43  int countPassing = 0;
44  int countPassingVtx = 0;
45  int countPassing_pt05 = 0; // count of tracks passing higher pt (here 0.5 GeV)
46  int countPassing_pt1 = 0; // count of tracks passing higher pt (here 1 GeV)
47  int countPassing_pt2 = 0; // ...
48  int countPassing_pt4 = 0;
49  int countPassing_pt6 = 0;
50  int countPassing_pt8 = 0;
51  auto leadingTrackPt = Scalar<double>("leadingTrackPt");
52  for (const auto trk : *offlineTrkHandle)
53  {
54  if (m_trackSelectionTool->accept(*trk) and std::fabs(trk->pt()) > m_minPt) {
55  ++countPassing;
56  if (priVtx and std::abs(Utils::z0wrtPV(trk, priVtx)) < m_z0
57  and std::abs(trk->d0()) < m_d0) {
58  ++countPassingVtx;
59  }
60 
61  const double pt = std::fabs(trk->pt()) * 1e-3; // fabs used in case the charge is encoded in pt ( i.e. it is really q * pt)
62 
63  if (pt > 0.5)
64  ++countPassing_pt05;
65  if (pt > 1.)
66  ++countPassing_pt1;
67  if (pt > 2.)
68  ++countPassing_pt2;
69  if (pt > 4.)
70  ++countPassing_pt4;
71  if (pt > 6.)
72  ++countPassing_pt6;
73  if (pt > 8.)
74  ++countPassing_pt8;
75  if (pt > leadingTrackPt) leadingTrackPt = pt;
76  }
77  }
78  ATH_MSG_DEBUG("::monitorTrkCounts countPassing = " << countPassing);
79  auto nTrkOffline = Scalar("nTrkOffline", countPassing);
80  auto nTrkOfflineVtx = Scalar("nTrkOfflineVtx", countPassingVtx);
81  auto nTrkOffline_pt05 = Scalar("nTrkOffline_pt05", countPassing_pt05);
82  auto nTrkOffline_pt1 = Scalar("nTrkOffline_pt1", countPassing_pt1);
83  auto nTrkOffline_pt2 = Scalar("nTrkOffline_pt2", countPassing_pt2);
84  auto nTrkOffline_pt4 = Scalar("nTrkOffline_pt4", countPassing_pt4);
85  auto nTrkOffline_pt6 = Scalar("nTrkOffline_pt6", countPassing_pt6);
86  auto nTrkOffline_pt8 = Scalar("nTrkOffline_pt8", countPassing_pt8);
87 
88 
89  auto passedL1 = [](unsigned int bits) { return (bits & TrigDefs::L1_isPassedBeforePrescale) != 0; };
90  auto passedHLT = [](unsigned int bits) { return (bits & TrigDefs::EF_passedRaw) != 0; };
91  auto activeHLT = [](unsigned int bits) { return (bits & TrigDefs::EF_prescaled) == 0; };
92  auto isL1 = [](const std::string& name) { return name.compare(0, 3, "L1_") == 0; };
93  auto isHLT = [](const std::string& name) { return name.compare(0, 4, "HLT_") == 0; };
94 
95 
96  for (size_t index = 0; index < m_refTriggerList.size(); ++index)
97  {
98  auto trig = m_triggerList[index];
99  auto ref = m_refTriggerList[index];
100 
101  ATH_MSG_DEBUG("checking " << trig << " vs " << ref);
102 
103  if (trigDecTool->isPassed(ref, TrigDefs::requireDecision))
104  {
105  ATH_MSG_DEBUG("ref passed for " << trig << " vs " << ref);
106 
107  const unsigned int passBits = trigDecTool->isPassedBits(trig);
108  const bool wasRun = isL1(trig) or (isHLT(trig) and activeHLT(passBits));
109 
110  if (wasRun) {
111  const auto decision = (isL1(trig) and passedL1(passBits)) or (isHLT(trig) and passedHLT(passBits));
112  ATH_MSG_DEBUG("chain " << trig << (decision ? " passed" : " failed"));
113 
114  auto effPassed = Scalar<int>("EffPassed", decision);
115  fill(trig + ref, effPassed, nTrkOffline, nTrkOfflineVtx, nTrkOffline_pt05, nTrkOffline_pt1, nTrkOffline_pt2, nTrkOffline_pt4, nTrkOffline_pt6, nTrkOffline_pt8, leadingTrackPt);
116  }
117  }
118  }
119 
120  for (auto& trig : m_uniqueTriggerList)
121  {
122  if (trigDecTool->isPassed(trig, TrigDefs::requireDecision))
123  {
124  auto whichtrigger = Scalar<std::string>("TrigCounts", trig);
125  auto nTrkOffline = Scalar("nTrkOffline_counts_" + trig, countPassing);
126  fill("TrigAll", whichtrigger, nTrkOffline);
127  }
128  }
129 
130  return StatusCode::SUCCESS;
131 }
HLTMinBiasEffMonitoringAlg::m_z0
Gaudi::Property< float > m_z0
Definition: HLTMinBiasEffMonitoringAlg.h:46
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
HLTMinBiasEffMonitoringAlg::m_triggerList
Gaudi::Property< std::vector< std::string > > m_triggerList
Definition: HLTMinBiasEffMonitoringAlg.h:35
temp
Definition: JetEventDict.h:21
HLTMinBiasEffMonitoringAlg::fillHistograms
virtual StatusCode fillHistograms(const EventContext &context) const override
adds event to the monitoring histograms
Definition: HLTMinBiasEffMonitoringAlg.cxx:33
HLTMinBiasEffMonitoringAlg::m_uniqueTriggerList
std::vector< std::string > m_uniqueTriggerList
Definition: HLTMinBiasEffMonitoringAlg.h:37
HLTMinBiasEffMonitoringAlg.h
index
Definition: index.py:1
HLTMinBiasEffMonitoringAlg::finalize
virtual StatusCode finalize() override
Definition: HLTMinBiasEffMonitoringAlg.cxx:28
HLTMinBiasEffMonitoringAlg::m_TrigT2MbtsBitsContainerKey
SG::ReadHandleKey< xAOD::TrigT2MbtsBitsContainer > m_TrigT2MbtsBitsContainerKey
Definition: HLTMinBiasEffMonitoringAlg.h:40
AthMonitorAlgorithm::getTrigDecisionTool
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
Definition: AthMonitorAlgorithm.cxx:189
test_pyathena.pt
pt
Definition: test_pyathena.py:11
HLTMinBiasEffMonitoringAlg::initialize
virtual StatusCode initialize() override
initialize
Definition: HLTMinBiasEffMonitoringAlg.cxx:12
xAOD::passBits
passBits
Definition: TrigPassBits_v1.cxx:115
HLTMinBiasEffMonitoringAlg::m_trkCountsKey
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_trkCountsKey
Definition: HLTMinBiasEffMonitoringAlg.h:39
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
HLTMinBiasEffMonitoringAlg::~HLTMinBiasEffMonitoringAlg
virtual ~HLTMinBiasEffMonitoringAlg() override
Definition: HLTMinBiasEffMonitoringAlg.cxx:10
HLTMinBiasEffMonitoringAlg::m_d0
Gaudi::Property< float > m_d0
Definition: HLTMinBiasEffMonitoringAlg.h:47
HLTMinBiasEffMonitoringAlg::m_offlineTrkKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_offlineTrkKey
Definition: HLTMinBiasEffMonitoringAlg.h:41
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
HLTMinBiasEffMonitoringAlg::m_trackSelectionTool
ToolHandle< InDet::IInDetTrackSelectionTool > m_trackSelectionTool
Definition: HLTMinBiasEffMonitoringAlg.h:44
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
HLTMinBiasEffMonitoringAlg::m_minPt
Gaudi::Property< float > m_minPt
Definition: HLTMinBiasEffMonitoringAlg.h:45
Utils.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
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:228
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
DeMoScan.index
string index
Definition: DeMoScan.py:364
HLTMinBiasEffMonitoringAlg::m_vertexKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexKey
Definition: HLTMinBiasEffMonitoringAlg.h:42
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ref
const boost::regex ref(r_ef)
HLTMinBiasEffMonitoringAlg::HLTMinBiasEffMonitoringAlg
HLTMinBiasEffMonitoringAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: HLTMinBiasEffMonitoringAlg.cxx:8
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
TrackingPrimitives.h
HLTMinBiasEffMonitoringAlg::m_refTriggerList
Gaudi::Property< std::vector< std::string > > m_refTriggerList
Definition: HLTMinBiasEffMonitoringAlg.h:36