ATLAS Offline Software
Loading...
Searching...
No Matches
TrigEgammaMatchingToolMT.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5
10#include "boost/algorithm/string.hpp"
11#include <typeinfo>
12#include <string>
13
14using namespace TrigCompositeUtils;
15using namespace Trig;
16
17
18
19
20/*
21 * TrigEgammaMatchinTool API
22 */
23
24
26 asg::AsgTool( name ),
27 m_trigDecTool("Trig::TrigDecisionTool/TrigDecisionTool")
28{;}
29
30
32
34{
35 ATH_CHECK(tdt().retrieve());
36
37 ATH_CHECK( m_emTauRoIKey.initialize() );
38 ATH_CHECK( m_ringerKey.initialize() );
39
40
41 m_keys[ "Electrons"] = "HLT_egamma_Electrons" ;
42 m_keys[ "Electrons_GSF"] = "HLT_egamma_Electrons_GSF" ; // gsf
43 m_keys[ "Electrons_LRT"] = "HLT_egamma_Electrons_LRT" ; // lrt
44 m_keys[ "Photons"] = "HLT_egamma_Photons" ;
45
46 // intermediate steps
47 m_keys[ "PrecisionCalo_Electron"] = "HLT_CaloEMClusters_Electron";
48 m_keys[ "PrecisionCalo_Photon"] = "HLT_CaloEMClusters_Photon";
49 m_keys[ "PrecisionCalo_LRT"] = "HLT_CaloEMClusters_LRT" ; // lrt
50 m_keys[ "PrecisionCalo_HI"] = "HLT_HICaloEMClusters" ; // ion chains
51
52 // Fast steps
53 m_keys[ "FastElectrons"] = "HLT_FastElectrons" ;
54 m_keys[ "FastElectrons_LRT"] = "HLT_FastElectrons_LRT" ; // lrt
55 m_keys[ "FastPhotons"] = "HLT_FastPhotons" ;
56 m_keys[ "FastCalo"] = "HLT_FastCaloEMClusters" ;
57 // L1
58 m_keys[ "L1Calo"] = "LVL1EmTauRoIs" ;
59 m_keys[ "L1eEM"] = "L1_eEMRoI";
60
61 return StatusCode::SUCCESS;
62}
63
64
66
67std::string TrigEgammaMatchingToolMT::key( const std::string& key) const
68{
69 return m_keys.at(key);
70}
71
73
74bool TrigEgammaMatchingToolMT::isPassed(const xAOD::Egamma *eg,const std::string &trigger, unsigned int condition ) const
75{
76 const TrigCompositeUtils::Decision *dec=nullptr;
77 if( match( eg, trigger, dec ) ){
78 if( dec ){
80 std::string key = this->key("Electrons_GSF");
81 if(boost::contains(trigger,"nogsf")) key=this->key("Electrons");
82 if(boost::contains(trigger,"lrt")) key=this->key("Electrons_LRT");
83 return ancestorPassed<xAOD::ElectronContainer>(dec, trigger,key, condition);
84 }
86 return ancestorPassed<xAOD::PhotonContainer>(dec, trigger, key("Photons"), condition);
87 }
88 }
89 }
90 return false;
91}
92
94
95bool TrigEgammaMatchingToolMT::match(const xAOD::Egamma *eg,const std::string &trigger, const TrigCompositeUtils::Decision *&dec, unsigned int condition ) const
96{
97
98 ATH_MSG_DEBUG("Match decec with trigger " << trigger);
100 const xAOD::Electron* el =static_cast<const xAOD::Electron*> (eg);
101 if( matchHLTElectron(el,trigger,dec, condition) ) {
102 ATH_MSG_DEBUG("Matched!");
103 return true;
104 }
105 }else if(xAOD::EgammaHelpers::isPhoton(eg)){
106 const xAOD::Photon* ph =static_cast<const xAOD::Photon*> (eg);
107 if( matchHLTPhoton(ph,trigger,dec, condition) ) return true;
108 }
109
110 if( matchHLTCalo(eg,trigger,dec) ) return true;
111
113 const xAOD::Electron* el =static_cast<const xAOD::Electron*> (eg);
114 if( matchL2Electron(el,trigger,dec, condition) ) return true;
115
116 }else if(xAOD::EgammaHelpers::isPhoton(eg)){
117 const xAOD::Photon* ph =static_cast<const xAOD::Photon*> (eg);
118 if( matchL2Photon(ph,trigger,dec, condition) ) return true;
119 }
120
121 if( matchL2Calo(eg,trigger,dec, condition) ) return true;
122
123 if( matchL1(eg,trigger,dec, condition) ) return true;
124 ATH_MSG_DEBUG("match() failed!");
125 return false;
126}
127
128
130
131bool TrigEgammaMatchingToolMT::matchHLTPhoton(const xAOD::Photon *eg,const std::string &trigger, const TrigCompositeUtils::Decision *&dec, unsigned int condition ) const
132{
133 ATH_MSG_DEBUG("Match HLT Photon");
134 return closestObject<xAOD::PhotonContainer>( eg, dec, trigger, key("Photons"), m_dR, condition );
135}
136
138
139bool TrigEgammaMatchingToolMT::matchHLTElectron(const xAOD::Electron *eg,const std::string &trigger, const TrigCompositeUtils::Decision *&dec, unsigned int condition ) const
140{
141 if (boost::contains(trigger,"nogsf")){
142 ATH_MSG_DEBUG("Matched HLT Electron noGSF");
143 return closestObject<xAOD::ElectronContainer>( eg, dec , trigger, key("Electrons"), m_dR, condition );
144 }else if(boost::contains(trigger,"lrt")){
145 ATH_MSG_DEBUG("Matched HLT Electron LRT");
146 return closestObject<xAOD::ElectronContainer>( eg, dec , trigger, key("Electrons_LRT"), m_dR, condition );
147 }else {
148 ATH_MSG_DEBUG("Matched HLT Electron");
149 return closestObject<xAOD::ElectronContainer>( eg, dec , trigger, key("Electrons_GSF"), m_dR, condition );
150 }
151}
152
154
155bool TrigEgammaMatchingToolMT::matchHLTCalo(const xAOD::Egamma *eg,const std::string &trigger, const TrigCompositeUtils::Decision *&dec, unsigned int condition ) const
156{
157 ATH_MSG_DEBUG("Match HLT PrecisionCalo");
158 if(boost::contains(trigger,"lrt")){
159 ATH_MSG_DEBUG("Matched HLT PrecisionCalo LRT");
160 return closestObject<xAOD::CaloClusterContainer>( eg, dec, trigger, key("PrecisionCalo_LRT"), m_dR, condition );
161 }else if(boost::contains(trigger,"ion")){
162 ATH_MSG_DEBUG("Matched HLT PrecisionCalo Heavy Ion");
163 return closestObject<xAOD::CaloClusterContainer>( eg, dec, trigger, key("PrecisionCalo_HI"), m_dR, condition );
165 ATH_MSG_DEBUG("Matched HLT PrecisionCalo Electron");
166 return closestObject<xAOD::CaloClusterContainer>( eg, dec, trigger, key("PrecisionCalo_Electron"), m_dR, condition );
167 }else if(xAOD::EgammaHelpers::isPhoton(eg)){
168 ATH_MSG_DEBUG("Matched HLT PrecisionCalo Photon");
169 return closestObject<xAOD::CaloClusterContainer>( eg, dec, trigger, key("PrecisionCalo_Photon"), m_dR, condition );
170 }else{
171 ATH_MSG_DEBUG("Match HLT PrecisionCalo failed!");
172 return false;
173 }
174}
175
177
178bool TrigEgammaMatchingToolMT::matchL2Photon(const xAOD::Photon *eg,const std::string &trigger, const TrigCompositeUtils::Decision *&dec, unsigned int condition ) const
179{
180 ATH_MSG_DEBUG("Match L2 Photon");
181 return closestObject<xAOD::TrigPhotonContainer>( eg, dec, trigger, key("FastPhotons"), m_dR, condition );
182}
183
185
186bool TrigEgammaMatchingToolMT::matchL2Electron(const xAOD::Electron *eg,const std::string &trigger, const TrigCompositeUtils::Decision *&dec, unsigned int condition ) const
187{
188 ATH_MSG_DEBUG("Match L2 Electron");
189 if(boost::contains(trigger,"lrt")){
190 return closestObject<xAOD::TrigElectronContainer>( eg, dec, trigger, key("FastElectrons_LRT"), m_dR, condition );
191 }else{
192 return closestObject<xAOD::TrigElectronContainer>( eg, dec, trigger, key("FastElectrons"), m_dR, condition );
193 }
194}
195
197
198bool TrigEgammaMatchingToolMT::matchL2Calo(const xAOD::Egamma *eg,const std::string &trigger, const TrigCompositeUtils::Decision *&dec, unsigned int condition ) const
199{
200 ATH_MSG_DEBUG("Match L2 Calo");
201 return closestObject<xAOD::TrigEMClusterContainer>( eg, dec, trigger, key("FastCalo") , m_dR, condition);
202}
203
205
206bool TrigEgammaMatchingToolMT::matchL1( const xAOD::Egamma* eg, const std::string &trigger, const TrigCompositeUtils::Decision *&dec, unsigned int condition ) const
207{
208 ATH_MSG_DEBUG("Match L1 Calo");
209
210 double deltaR=0.0;
211 auto initRois = tdt()->features<TrigRoiDescriptorCollection>(trigger,condition,"",TrigDefs::allFeaturesOfType,"initialRoI");
212 if( initRois.size() < 1) return false;
213 for( auto &initRoi: initRois ){
214 if( !initRoi.link.isValid() ) continue;
215 deltaR = dR(eg->eta(),eg->phi(), (*initRoi.link)->eta(),(*initRoi.link)->phi());
216 if(deltaR < (float)m_dRL1){
217 dec=initRoi.source;
218 return true;
219 }
220 }
221
222 return false;
223}
224
226
228{
229 if( !dec ) return nullptr;
230 auto initRoi = TrigCompositeUtils::findLink<TrigRoiDescriptorCollection>(dec, "initialRoI");
231 if( !initRoi.isValid() ) return nullptr;
232
233 SG::ReadHandle<xAOD::EmTauRoIContainer> l1_cont( m_emTauRoIKey, Gaudi::Hive::currentContext());
234 if( !l1_cont.isValid() ) return nullptr;
235
236 for( const auto *l1 : *l1_cont ){
237 if ( l1->roiType() != xAOD::EmTauRoI::RoIType::EMRoIWord) continue;
238 if((*initRoi.link)->roiWord()==l1->roiWord()){
239 return l1;
240 }
241 }
242 return nullptr;
243}
244
246
248{
249 if( !dec ) return nullptr;
250 auto initRoi = TrigCompositeUtils::findLink<xAOD::eFexEMRoIContainer>(dec, "initialRecRoI");
251 if( !initRoi.isValid() ) return nullptr;
252 return *(initRoi.link);
253}
254
256
258{
259 if( !dec ) return nullptr;
260 auto initRoi = TrigCompositeUtils::findLink<TrigRoiDescriptorCollection>(dec, "initialRoI");
261 if( !initRoi.isValid() ) return nullptr;
262
263 SG::ReadHandle<xAOD::TrigRingerRingsContainer> rg_cont( m_ringerKey, Gaudi::Hive::currentContext() );
264
265 if( !rg_cont.isValid() ) return nullptr;
266
267 for( const auto *rg : *rg_cont ){
268 const xAOD::TrigEMCluster *cl = rg->emCluster();
269 if(!cl) continue;
270 if(cl->RoIword()==(*initRoi.link)->roiWord())
271 return rg;
272 }
273 return nullptr;
274}
275
Scalar deltaR(const MatrixBase< Derived > &vec) const
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::map< std::string, std::string > m_keys
SG::ReadHandleKey< xAOD::EmTauRoIContainer > m_emTauRoIKey
bool matchHLTPhoton(const xAOD::Photon *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
bool matchL2Calo(const xAOD::Egamma *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
StatusCode initialize()
=======================================================================
const xAOD::EmTauRoI * getL1Feature(const TrigCompositeUtils::Decision *) const
=======================================================================
bool matchL2Photon(const xAOD::Photon *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
bool isPassed(const xAOD::Egamma *, const std::string &, unsigned int condition=TrigDefs::Physics) const
=======================================================================
const ToolHandle< Trig::TrigDecisionTool > & tdt() const
std::string key(const std::string &) const
=======================================================================
bool matchHLTElectron(const xAOD::Electron *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
TrigEgammaMatchingToolMT(const std::string &name)
bool matchL2Electron(const xAOD::Electron *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
SG::ReadHandleKey< xAOD::TrigRingerRingsContainer > m_ringerKey
bool matchHLTCalo(const xAOD::Egamma *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
bool match(const xAOD::Egamma *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
bool matchL1(const xAOD::Egamma *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
double dR(const double eta1, const double phi1, const double eta2, const double phi2) const
const xAOD::TrigRingerRings * getRingsFeature(const TrigCompositeUtils::Decision *) const
=======================================================================
Gaudi::Property< float > m_dR
bool closestObject(const xAOD::Egamma *, const TrigCompositeUtils::Decision *&, const std::string &trigger, const std::string &key, float dR_value, unsigned int condition=TrigDefs::Physics) const
bool ancestorPassed(const TrigCompositeUtils::Decision *, const std::string &trigger, const std::string &key, unsigned int condition=TrigDefs::Physics) const
const xAOD::eFexEMRoI * getL1eEMFeature(const TrigCompositeUtils::Decision *) const
=======================================================================
Gaudi::Property< float > m_dRL1
ToolHandle< Trig::TrigDecisionTool > m_trigDecTool
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
@ EMRoIWord
This is a Run 2 EM RoI word.
Definition EmTauRoI_v2.h:47
LinkInfo< T > findLink(const Decision *start, const std::string &linkName, const bool suppressMultipleLinksWarning=false)
Perform a recursive search for ElementLinks of type T and name 'linkName', starting from Decision obj...
static const unsigned int allFeaturesOfType
Run 3 "enum". Return all features along legs (still with type and container checks)
The common trigger namespace for trigger analysis tools.
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
eFexEMRoI_v1 eFexEMRoI
Define the latest version of the eFexEMRoI class.
Definition eFexEMRoI.h:17
TrigRingerRings_v2 TrigRingerRings
Define the latest version of the TrigRingerRings class.
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
TrigEMCluster_v1 TrigEMCluster
Define the latest version of the trigger EM cluster class.
Photon_v1 Photon
Definition of the current "egamma version".
Electron_v1 Electron
Definition of the current "egamma version".
EmTauRoI_v2 EmTauRoI
Definition EmTauRoI.h:16