ATLAS Offline Software
Loading...
Searching...
No Matches
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
15namespace 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);
44 m_chainData[chain];
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)
101 std::transform(
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Helper class that provides access to information about individual legs.
AnaAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
void handle(const Incident &inc)
receive the given incident
Iterates over all combinations of the provided input iterators.
Definition ProductItr.h:43
bool exhausted() const
True if this iterator is past the end.
Gaudi::Property< std::vector< std::string > > m_chains
TrigMatchTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
ToolHandle< Trig::IMatchingTool > m_matchingTool
std::map< std::string, SG::ReadHandleKey< xAOD::IParticleContainer > > m_offlineKeys
virtual StatusCode execute() override
std::map< std::string, std::map< std::string, std::size_t > > m_chainInfos
ToolHandle< Trig::TrigDecisionTool > m_tdt
virtual StatusCode finalize() override
std::map< std::string, MatchData > m_chainData
This module defines the arguments passed from the BATCH driver to the BATCH worker.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
The common trigger namespace for trigger analysis tools.
Struct containing information on each leg of a chain.