ATLAS Offline Software
Loading...
Searching...
No Matches
MatchingTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
8
10
11namespace Trig {
12
13MatchingTool::MatchingTool(const std::string& name) :
14 asg::AsgTool(name),
16 m_trigDecTool("Trig::TrigDecisionTool/TrigDecisionTool"),
18{
19 declareProperty( "TrigDecisionTool", m_trigDecTool);
20}
21
22#ifndef XAOD_STANDALONE
23void MatchingTool::updateThreshold(Gaudi::Details::PropertyBase& /*p*/) {
24 ATH_MSG_DEBUG("Matching Threshold is updated to:" << m_matchingThreshold);
25 m_impl->setThreshold( m_matchingThreshold );
26}
27#endif
28
32
34 m_impl->setThreshold( m_matchingThreshold );
35
36 ATH_CHECK( m_trigDecTool.retrieve() );
37 ATH_CHECK( m_scoreTool.retrieve() );
38
39 return StatusCode::SUCCESS;
40}
41
42 bool MatchingTool::matchCombination(const std::vector<const xAOD::IParticle*>& recoObjects, Trig::Combination& comb, const std::string& chain, double threshold) const {
43 std::map<xAOD::Type::ObjectType,std::vector<const xAOD::IParticle*> > typeSeparated;
44
45 for (const auto& obj : recoObjects){
46 if(typeSeparated.find(obj->type()) == typeSeparated.end()){
47 std::vector<const xAOD::IParticle*> typevec;
48 typeSeparated[obj->type()] = typevec;
49 }
50 typeSeparated[obj->type()].push_back(obj);
51 }
52
53 ATH_MSG_DEBUG("found: " << typeSeparated.size() << " unique objects types to match");
54 for(auto& [objType, recoObjs_thistype] : typeSeparated){
55 ATH_MSG_DEBUG("type: " << objType << "(" << recoObjs_thistype.size() << " elements)");
56 }
57
58 bool overall_status = true;
59 std::map<xAOD::Type::ObjectType,bool> status;
60 for(auto& [objType, recoObjs_thistype] : typeSeparated){
61 auto single_status = matchSingleType(recoObjs_thistype, comb, chain, threshold);
62 ATH_MSG_DEBUG("type: " << objType << " status: " << single_status);
63 status[objType] = single_status;
64 overall_status = overall_status && single_status;
65 }
66
67 return overall_status;
68}
69
70 bool MatchingTool::matchSingleType(const std::vector<const xAOD::IParticle*>& recoObjects, Trig::Combination& comb, const std::string& chain, double threshold) const {
71 ATH_MSG_DEBUG("matching combination with " << comb.tes().size() << " TEs");
72
73 auto recoType = recoObjects.at(0)->type();
74 ATH_MSG_DEBUG("reco type is " << recoType);
75
76 HLT::class_id_type clid = 0;
77 std::string container_typename("");
78
79 // This hack is to make Offline electrons to be matched to online HLT CaloClusters if HLT chain is _etcut type
80 if (recoType == xAOD::Type::Electron && chain.find("etcut") != std::string::npos && chain.find("trkcut") == std::string::npos){
81 ATH_MSG_DEBUG("Electron offline and matching electron etcut chain. Try to match to cluster instead!: " );
83 }
84
85 if(m_typeMap.isKnown(recoType)){
86
87 auto clid_container = m_typeMap.get(recoType);
88
89 clid = clid_container.first;
90 container_typename = clid_container.second;
91 ATH_MSG_DEBUG("getting trigger features (clid: " << clid << " and type: " << container_typename << ")");
92 }
93 else{
94 ATH_MSG_WARNING("could not find corresponding trigger type, can't match");
95 return false;
96 }
97
98 auto iparticle_feats = comb.getIParticle(clid,container_typename);
99
100 ATH_MSG_DEBUG("found: " << iparticle_feats.size() << " xAOD::IParticle");
101
102 for(auto& feat : iparticle_feats){
103 ATH_MSG_DEBUG(" ==> pt: " << feat.cptr()->pt() << " and eta: " << feat.cptr()->eta() << " address: " << feat.cptr());
104 }
105
106 if(recoObjects.size() > iparticle_feats.size()){
107 ATH_MSG_WARNING("more reco objects (" << recoObjects.size() << ") than trigger object (" << iparticle_feats.size() << "). no hope of matching!");
108 return false;
109 }
110
111 ATH_MSG_DEBUG("now matching: " << recoObjects.size() << " reco objects to " << iparticle_feats.size() << " trigger objects");
112
113 std::vector<const xAOD::IParticle*> trigObjects;
114 for(auto& feat : iparticle_feats){trigObjects.push_back(feat.cptr());}
115
116 std::vector<std::vector<double>> scoreMatrix;
117 scoreMatrix.reserve(recoObjects.size());
118 for (const xAOD::IParticle *reco : recoObjects)
119 {
120 scoreMatrix.emplace_back();
121 std::vector<double> &scores = scoreMatrix.back();
122 scores.reserve(trigObjects.size());
123 for (const xAOD::IParticle *trig: trigObjects)
124 // For historic reasons a lot of the interfaces here expect doubles
125 // It doesn't seem worth fixing this now
126 scores.push_back(static_cast<double>(m_scoreTool->score(*trig, *reco)));
127 }
128
129 ATH_MSG_DEBUG("made distance matrix");
130
131 bool match_result = impl()->matchDistanceMatrix(scoreMatrix, Trig::MatchingStrategy::MinimalSum,threshold);
132
133 ATH_MSG_DEBUG("got matching result: " << match_result);
134
135 return match_result;
136}
137
138 bool MatchingTool::match(const xAOD::IParticle& recoObject, const std::string& chain, double matchThreshold, bool rerun) const {
139 std::vector<const xAOD::IParticle*> recoObjects(1,&recoObject);
140 bool out = match(recoObjects, chain, matchThreshold, rerun);
141 return out;
142}
143
144 bool MatchingTool::match(const std::vector<const xAOD::IParticle*>& recoObjects, const std::string& chain, double matchThreshold, bool rerun) const {
145 ATH_MSG_DEBUG("matching " << recoObjects.size() << " reco objects to chain: " << chain );
146
147 auto chainGroup = impl()->tdt()->getChainGroup(chain);
148 bool decision;
149 if (!rerun)
150 decision = chainGroup->isPassed();
151 else
152 decision = chainGroup->isPassed(TrigDefs::Physics | TrigDefs::allowResurrectedDecision);
153 ATH_MSG_DEBUG(chain << " is passed: " << decision);
154 if(!decision) return false;
155
156 auto featureContainer = chainGroup->features();
157 auto combinations = featureContainer.getCombinations();
158
159 ATH_MSG_DEBUG("chain has: " << combinations.size() << " combos");
160
161
162 bool result = false;
163 for(auto& comb : combinations){
164 bool combResult = matchCombination(recoObjects,comb, chain, matchThreshold);
165 ATH_MSG_DEBUG("matching result for this combination: " << combResult);
166 result = result || combResult;
167 if(result) break; //no need to continue if result is true
168 }
169
170 ATH_MSG_DEBUG("overall matching result: " << result);
171
172 return result;
173}
174
178} //Trig namespace
179
180
181
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
bool isPassed(unsigned int condition=TrigDefs::Physics) const
tells if chain group passed
is a connector between chains and object It store single combination of trigger elements.
std::vector< Trig::Feature< xAOD::IParticle > > getIParticle(HLT::class_id_type clid, const std::string &container_name, const std::string &label="", unsigned int condition=TrigDefs::Physics, const std::string &teName="") const
Experimental flattened get for IParticle types.
const std::vector< const HLT::TriggerElement * > & tes() const
trigger elements in the combination can be used directly with ancestor method
const Trig::TrigDecisionTool * tdt() const
bool matchDistanceMatrix(const std::vector< std::vector< double > > &matrix, const Trig::MatchingStrategy::Strategy strategy=Trig::MatchingStrategy::MinimalSum, double threshold=0.0) const
ToolHandle< Trig::IMatchScoringTool > m_scoreTool
bool match(const std::vector< const xAOD::IParticle * > &recoObjects, const std::string &chain, double matchTreshold, bool rerun) const override
multi-object trigger matching
const MatchingImplementation * impl() const override
friend class MatchingImplementation
MatchingImplementation * m_impl
void updateThreshold(Gaudi::Details::PropertyBase &p)
bool matchCombination(const std::vector< const xAOD::IParticle * > &recoObjects, Trig::Combination &comb, const std::string &chain, double threshold) const
ToolHandle< Trig::TrigDecisionTool > m_trigDecTool
StatusCode initialize() override
Dummy implementation of the initialisation function.
bool matchSingleType(const std::vector< const xAOD::IParticle * > &subRecoObjects, Trig::Combination &comb, const std::string &chain, double threshold) const
MatchingTool(const std::string &name)
const Trig::ChainGroup * getChainGroup(const std::vector< std::string > &patterns, TrigDefs::Group props=TrigDefs::Group::Default) const
Create/get chain group (.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
Class providing the definition of the 4-vector interface.
The common trigger namespace for trigger analysis tools.
@ CaloCluster
The object is a calorimeter cluster.
Definition ObjectType.h:39
@ Electron
The object is an electron.
Definition ObjectType.h:46