7#include "GaudiKernel/ServiceHandle.h"
8#include "GaudiKernel/IIncidentSvc.h"
21 using constAcc_t = SG::AuxElement::ConstAccessor<T>;
23 using acc_t = SG::AuxElement::Accessor<T>;
25 using vecLink_t = std::vector<ElementLink<T>>;
42 const std::string&
type,
43 const std::string& name,
44 const IInterface* pSvcLocator) :
45 base_class(
type, name, pSvcLocator)
47 declareProperty(
"ChainNames", m_chainNames,
48 "The list of trigger chains to match.");
50 "The tool to retrieve online particles from the navigation.");
51 declareProperty(
"InputElectrons",
53 "Offline electron candidates for matching.");
54 declareProperty(
"InputPhotons",
56 "Offline photon candidates for matching.");
57 declareProperty(
"InputMuons",
59 "Offline muon candidates for matching.");
60 declareProperty(
"InputTaus",
62 "Offline tau candidates for matching.");
64 "The maximum dR between an offline and an online particle to consider "
65 "a match between them.");
66 declareProperty(
"Rerun",
m_rerun =
true,
67 "Whether to match triggers in rerun mode.");
68 declareProperty(
"OutputContainerPrefix",
m_outputPrefix=
"TrigMatch_",
69 "The prefix to add to the output containers.");
71 "If set, discard any empty chain groups. Otherwise these will cause "
74 "Warn when a trigger is removed (if the configuration is dependent "
75 "on the inputs, removal is not expected).");
83 std::sort(m_chainNames.begin(), m_chainNames.end() );
84 m_chainNames.erase(
std::unique(m_chainNames.begin(), m_chainNames.end() ), m_chainNames.end() );
92 return StatusCode::SUCCESS;
97 [[maybe_unused]]
static const bool firstEvent = [&](){
98 auto itr = m_chainNames.begin();
99 while (itr != m_chainNames.end() ) {
103 ATH_MSG_WARNING(
"Removing trigger " << (*itr) <<
" -- suggests a bad tool configuration (asking for triggers not in the menu)");
106 itr = m_chainNames.erase(itr);
116 std::map<xAOD::Type::ObjectType, const xAOD::IParticleContainer *> offlineContainers;
117 std::map<xAOD::Type::ObjectType, particleVec_t> offlineCandidates;
121 if (p.second.empty() )
124 if (!handle.isValid())
127 return StatusCode::FAILURE;
129 offlineContainers[p.first] = handle.ptr();
130 offlineCandidates.emplace(std::make_pair(
139 std::map<const xAOD::IParticle*, particleVec_t> matches;
142 for (
const std::string& chain : m_chainNames) {
148 std::vector<particleVec_t> onlineCombinations;
152 onlineCombinations.size() <<
" combinations found for chain" << chain);
156 if (onlineCombinations.size() == 0)
161 std::vector<particleVec_t> offlineCombinations;
172 return std::accumulate (std::begin(
r), std::end(
r), 0);
176 for (
const particleVec_t& combination : onlineCombinations) {
181 std::vector<particleRange_t> matchCandidates;
184 part, offlineCandidates, matches);
185 matchCandidates.emplace_back(possibleMatches.begin(), possibleMatches.end() );
189 auto theseOfflineCombinations =
194 if (msgLvl(MSG::VERBOSE) ) {
197 "Checking matching for chain " << chain
198 <<
" with " << matchCandidates.size() <<
" legs");
200 for (
const particleRange_t& range : matchCandidates)
202 <<
" offline candidates." );
204 "Matching generated " << theseOfflineCombinations.size()
205 <<
" offline combinations");
216 for (
const particleVec_t& foundCombination : offlineCombinations) {
218 container->push_back(composite);
219 static const acc_t<vecLink_t<xAOD::IParticleContainer>> dec_links(
220 "TrigMatchedObjects");
221 vecLink_t<xAOD::IParticleContainer>& links = dec_links(*composite);
227 if (container->trackIndices())
231 extendedCtx.proxy());
233 links.push_back(makeLink<xAOD::IParticleContainer>(part, extendedCtx.proxy()));
237 return StatusCode::SUCCESS;
242 const std::string& chain)
const
244 auto uniqueContainer = std::make_unique<xAOD::TrigCompositeContainer>();
245 auto aux = std::make_unique<xAOD::AuxContainerBase>();
246 uniqueContainer->setStore(aux.get() );
247 container = uniqueContainer.get();
251 std::replace(name.begin(), name.end(),
'.',
'_');
252 ATH_CHECK( evtStore()->record(std::move(uniqueContainer), name) );
253 ATH_CHECK( evtStore()->record(std::move(aux), name+
"Aux.") );
254 return StatusCode::SUCCESS;
259 std::map<xAOD::Type::ObjectType, particleVec_t>& offlineParticles,
260 std::map<const xAOD::IParticle*, particleVec_t>& cache)
const
263 auto cacheItr = cache.find(part);
264 if (cacheItr == cache.end() ) {
270 static const constAcc_t<vecLink_t<xAOD::CaloClusterContainer>> acc_calo(
"caloClusterLinks");
275 const vecLink_t<xAOD::CaloClusterContainer>& links = acc_calo(*cand);
276 if (links.size() == 0 || !links.at(0).isValid() )
280 candidates.push_back(cand);
287 candidates.push_back(cand);
289 cacheItr = cache.emplace(
290 std::make_pair(part, std::move(candidates) ) ).first;
292 return cacheItr->second;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::vector< size_t > vec
Handle class for reading from StoreGate.
utility class that acts wraps a bidirectional iterator.
ElementLink implementation for ROOT usage.
virtual SG::DataProxy * proxy(const CLID &id, const std::string &key) const =0
Get proxy with given id and key.
std::vector< std::string > getListOfTriggers() const
Class providing the definition of the 4-vector interface.
virtual double pt() const =0
The transverse momentum ( ) of the particle.
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
std::vector< std::vector< T > > getAllDistinctCombinations(std::vector< RangedItr< typename std::vector< T >::const_iterator > > &inputs, INNERPROJ innerproj={}, OUTERPROJ outerproj={})
Get all valid, unique combinations of distinct elements from the input ranges.
bool insertIntoSortedVector(std::vector< T > &vec, const T &ele, PROJ proj={})
Helper function for inserting an element into a sorted vector.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
ElementLink< T > makeLink(const SG::View *view, const SG::ReadHandle< T > &handle, size_t index)
Create EL to a collection in view.
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
ObjectType
Type of objects that have a representation in the xAOD EDM.
@ Photon
The object is a photon.
@ CaloCluster
The object is a calorimeter cluster.
@ Muon
The object is a muon.
@ Electron
The object is an electron.
@ Tau
The object is a tau (jet).
TrigCompositeContainer_v1 TrigCompositeContainer
Declare the latest version of the container.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.