ATLAS Offline Software
TrigMatchTestAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 
11 #include <algorithm>
12 #include <iterator>
13 #include <iomanip>
14 
15 namespace Trig {
16 
17  TrigMatchTestAlg::TrigMatchTestAlg(const std::string &name, ISvcLocator *pSvcLocator) :
18  EL::AnaAlgorithm(name, pSvcLocator)
19  {
20  declareProperty("TrigDecisionTool", m_tdt, "The TrigDecisionTool");
21  declareProperty("OfflineElectrons", m_offlineKeys["e"] = "Electrons", "The offline electrons");
22  declareProperty("OfflinePhotons", m_offlineKeys["g"] = "Photons", "The offline photons");
23  declareProperty("OfflineMuons", m_offlineKeys["mu"] = "Muons", "The offline muons");
24  declareProperty("OfflineTaus", m_offlineKeys["tau"] = "TauJets", "The offline taus");
25  }
26 
27 
29  {
30  ATH_CHECK(m_tdt.retrieve());
31  ATH_CHECK(m_matchingTool.retrieve());
32  for (auto &p : m_offlineKeys)
33  ATH_CHECK(p.second.initialize(SG::AllowEmpty));
34 
35  for (const std::string &chain : m_chains)
36  {
37  std::map<std::string, std::size_t> info;
39  if (m_offlineKeys.count(legInfo.signature) && !m_offlineKeys[legInfo.signature].empty())
40  info[legInfo.signature] += legInfo.multiplicity;
41  if (!info.empty())
42  {
43  m_chainInfos[chain] = std::move(info);
45  }
46  else
47  ATH_MSG_WARNING("No matchable items in chain " << chain);
48  }
49 
50  if (m_chainInfos.empty())
51  {
52  ATH_MSG_ERROR("No matchable chains provided!");
53  return StatusCode::FAILURE;
54  }
55 
56  return StatusCode::SUCCESS;
57  }
58 
60  {
61  ++m_nEvents;
62  // Retrieve the input containers
63  std::map<std::string, const xAOD::IParticleContainer *> offlineInputs;
64  for (const auto &p : m_offlineKeys)
65  {
66  if (p.second.empty())
67  continue;
68  auto handle = SG::makeHandle(p.second);
69  if (!handle.isValid())
70  {
71  ATH_MSG_ERROR("Failed to retrieve " << p.second.key());
72  return StatusCode::FAILURE;
73  }
74  offlineInputs[p.first] = handle.cptr();
75  }
76 
77  for (const auto &chainPair : m_chainInfos)
78  {
79  const std::string &chain = chainPair.first;
80  if (!m_tdt->isPassed(chain))
81  {
82  ATH_MSG_DEBUG("Chain " << chain << " not passed!");
83  continue;
84  }
85  ++m_chainData[chain].nEventsPassed;
86  // Now we have to build all the *offline* combinations
87  std::vector<TrigCompositeUtils::KFromNItr> idxItrs;
88  std::vector<const xAOD::IParticleContainer *> containers;
89  for (const auto &sigPair : chainPair.second)
90  {
91  containers.push_back(offlineInputs.at(sigPair.first));
92  idxItrs.emplace_back(sigPair.second, containers.back()->size());
93  }
95  idxItrs, std::vector<TrigCompositeUtils::KFromNItr>(idxItrs.size()));
96  bool matched = false;
97  for (; !idxItr.exhausted(); ++idxItr)
98  {
99  std::vector<const xAOD::IParticle *> particles;
100  for (std::size_t idx = 0; idx < containers.size(); ++idx)
102  idxItr->at(idx)->begin(), idxItr->at(idx)->end(), std::back_inserter(particles),
103  [container=containers.at(idx)] (std::size_t contIdx) { return container->at(contIdx); });
104  if (m_matchingTool->match(particles, chain))
105  {
106  matched = true;
107  ++m_chainData[chain].nEventsMatched;
108  break;
109  }
110  }
111  ATH_MSG_DEBUG("Chain " << chain << " is matched? " << std::boolalpha << matched);
112  }
113  return StatusCode::SUCCESS;
114  }
115 
117  {
118  ATH_MSG_INFO("Finalizing " << name() );
119  ATH_MSG_INFO("Saw " << m_nEvents << " events");
120  for (const auto &p : m_chainData)
121  ATH_MSG_INFO("Chain " << p.first << " had " << p.second.nEventsPassed << " passed events of which " << p.second.nEventsMatched << " were matched");
122  return StatusCode::SUCCESS;
123  }
124 
125 
126 } //> end namespace Trig
grepfile.info
info
Definition: grepfile.py:38
Trig::TrigMatchTestAlg::m_chainInfos
std::map< std::string, std::map< std::string, std::size_t > > m_chainInfos
Definition: TrigMatchTestAlg.h:36
ChainNameParser.h
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trig
The common trigger namespace for trigger analysis tools.
Definition: CaloTowerVecMon.h:44
TrigCompositeUtils::ProductItr< TrigCompositeUtils::KFromNItr >
Trig::TrigMatchTestAlg::m_nEvents
std::size_t m_nEvents
Definition: TrigMatchTestAlg.h:42
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trig::TrigMatchTestAlg::m_offlineKeys
std::map< std::string, SG::ReadHandleKey< xAOD::IParticleContainer > > m_offlineKeys
Definition: TrigMatchTestAlg.h:32
Trig::TrigMatchTestAlg::m_chainData
std::map< std::string, MatchData > m_chainData
Definition: TrigMatchTestAlg.h:43
ChainNameParser::HLTChainInfo
Helper class that provides access to information about individual legs.
Definition: ChainNameParser.h:82
Trig::TrigMatchTestAlg::m_chains
Gaudi::Property< std::vector< std::string > > m_chains
Definition: TrigMatchTestAlg.h:30
Trig::TrigMatchTestAlg::TrigMatchTestAlg
TrigMatchTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigMatchTestAlg.cxx:17
KFromNItr.h
Trig::TrigMatchTestAlg::m_tdt
ToolHandle< Trig::TrigDecisionTool > m_tdt
Definition: TrigMatchTestAlg.h:33
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:269
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::AnaAlgorithm::handle
void handle(const Incident &inc)
receive the given incident
Definition: AnaAlgorithm.cxx:521
IsoCloseByCorrectionTest.containers
containers
Associate the close-by pflow objects and the calorimeter clusters.
Definition: IsoCloseByCorrectionTest.py:82
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
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
Trig::TrigMatchTestAlg::m_matchingTool
ToolHandle< Trig::IMatchingTool > m_matchingTool
Definition: TrigMatchTestAlg.h:34
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
Trig::TrigMatchTestAlg::initialize
virtual StatusCode initialize() override
Definition: TrigMatchTestAlg.cxx:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
ReadHandle.h
Handle class for reading from StoreGate.
TrigCompositeUtils::ProductItr::exhausted
bool exhausted() const
True if this iterator is past the end.
python.ElectronD3PDObject.matched
matched
Definition: ElectronD3PDObject.py:138
TrigMatchTestAlg.h
ChainNameParser::LegInfo
Struct containing information on each leg of a chain.
Definition: ChainNameParser.h:16
Trig::TrigMatchTestAlg::execute
virtual StatusCode execute() override
Definition: TrigMatchTestAlg.cxx:59
Trig::TrigMatchTestAlg::finalize
virtual StatusCode finalize() override
Definition: TrigMatchTestAlg.cxx:116
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
ProductItr.h
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30