ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigAnalysis
TriggerMatchingTool
Root
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
5
#include "
TriggerMatchingTool/TrigMatchTestAlg.h
"
6
#include "
AsgDataHandles/ReadHandle.h
"
7
#include "
TrigCompositeUtils/KFromNItr.h
"
8
#include "
TrigCompositeUtils/ChainNameParser.h
"
9
#include "
TrigCompositeUtils/ProductItr.h
"
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
28
StatusCode
TrigMatchTestAlg::initialize
()
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;
38
for
(
const
ChainNameParser::LegInfo
&legInfo :
ChainNameParser::HLTChainInfo
(chain))
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
59
StatusCode
TrigMatchTestAlg::execute
()
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
}
94
TrigCompositeUtils::ProductItr<TrigCompositeUtils::KFromNItr>
idxItr(
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
116
StatusCode
TrigMatchTestAlg::finalize
()
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
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
ReadHandle.h
Handle class for reading from StoreGate.
ChainNameParser.h
KFromNItr.h
ProductItr.h
TrigMatchTestAlg.h
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
ChainNameParser::HLTChainInfo
Helper class that provides access to information about individual legs.
Definition
ChainNameParser.h:83
EL::AnaAlgorithm::AnaAlgorithm
AnaAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
Definition
AnaAlgorithm.cxx:40
EL::AnaAlgorithm::handle
void handle(const Incident &inc)
receive the given incident
Definition
AnaAlgorithm.cxx:524
TrigCompositeUtils::ProductItr
Iterates over all combinations of the provided input iterators.
Definition
ProductItr.h:43
TrigCompositeUtils::ProductItr::exhausted
bool exhausted() const
True if this iterator is past the end.
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
Trig::TrigMatchTestAlg::initialize
virtual StatusCode initialize() override
Definition
TrigMatchTestAlg.cxx:28
Trig::TrigMatchTestAlg::m_matchingTool
ToolHandle< Trig::IMatchingTool > m_matchingTool
Definition
TrigMatchTestAlg.h:34
Trig::TrigMatchTestAlg::m_offlineKeys
std::map< std::string, SG::ReadHandleKey< xAOD::IParticleContainer > > m_offlineKeys
Definition
TrigMatchTestAlg.h:32
Trig::TrigMatchTestAlg::m_nEvents
std::size_t m_nEvents
Definition
TrigMatchTestAlg.h:42
Trig::TrigMatchTestAlg::execute
virtual StatusCode execute() override
Definition
TrigMatchTestAlg.cxx:59
Trig::TrigMatchTestAlg::m_chainInfos
std::map< std::string, std::map< std::string, std::size_t > > m_chainInfos
Definition
TrigMatchTestAlg.h:36
Trig::TrigMatchTestAlg::m_tdt
ToolHandle< Trig::TrigDecisionTool > m_tdt
Definition
TrigMatchTestAlg.h:33
Trig::TrigMatchTestAlg::finalize
virtual StatusCode finalize() override
Definition
TrigMatchTestAlg.cxx:116
Trig::TrigMatchTestAlg::m_chainData
std::map< std::string, MatchData > m_chainData
Definition
TrigMatchTestAlg.h:43
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition
AsgComponentFactories.h:16
SG::AllowEmpty
@ AllowEmpty
Definition
StoreGate/StoreGate/VarHandleKey.h:27
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition
ReadCondHandle.h:269
Trig
The common trigger namespace for trigger analysis tools.
Definition
LArCellMonAlg.h:33
ChainNameParser::LegInfo
Struct containing information on each leg of a chain.
Definition
ChainNameParser.h:17
Generated on
for ATLAS Offline Software by
1.17.0