ATLAS Offline Software
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 
14 using namespace TrigCompositeUtils;
15 using 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 
67 std::string TrigEgammaMatchingToolMT::key( const std::string& key) const
68 {
69  return m_keys.at(key);
70 }
71 
73 
74 bool 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 
95 bool 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  }
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 
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 
131 bool 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 
139 bool 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 
155 bool 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 );
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 
178 bool 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 
186 bool 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 
198 bool 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 
206 bool 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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TrigEgammaMatchingToolMT::m_keys
std::map< std::string, std::string > m_keys
Definition: TrigEgammaMatchingToolMT.h:88
TrigEgammaMatchingToolMT.h
ParticleTest.eg
eg
Definition: ParticleTest.py:29
TrigEgammaMatchingToolMT::getL1eEMFeature
const xAOD::eFexEMRoI * getL1eEMFeature(const TrigCompositeUtils::Decision *) const
=======================================================================
Definition: TrigEgammaMatchingToolMT.cxx:247
Trig
The common trigger namespace for trigger analysis tools.
Definition: CaloTowerVecMon.h:44
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TrigEgammaMatchingToolMT::matchHLTPhoton
bool matchHLTPhoton(const xAOD::Photon *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
Definition: TrigEgammaMatchingToolMT.cxx:131
asg
Definition: DataHandleTestTool.h:28
LArG4GenerateShowerLib.condition
condition
Definition: LArG4GenerateShowerLib.py:19
TrigCompositeUtils.h
TrigEgammaMatchingToolMT::dR
double dR(const double eta1, const double phi1, const double eta2, const double phi2) const
Definition: TrigEgammaMatchingToolMT.h:83
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
xAOD::eFexEMRoI_v1
Class describing a LVL1 eFEX EM region of interest.
Definition: eFexEMRoI_v1.h:33
TrigEgammaMatchingToolMT::match
bool match(const xAOD::Egamma *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
Definition: TrigEgammaMatchingToolMT.cxx:95
TrigEgammaMatchingToolMT::matchL2Calo
bool matchL2Calo(const xAOD::Egamma *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
Definition: TrigEgammaMatchingToolMT.cxx:198
TrigEgammaMatchingToolMT::matchHLTCalo
bool matchHLTCalo(const xAOD::Egamma *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
Definition: TrigEgammaMatchingToolMT.cxx:155
xAOD::EmTauRoI_v2
Class describing a LVL1 em/tau region of interest.
Definition: EmTauRoI_v2.h:35
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:12
TrigEgammaMatchingToolMT::getL1Feature
const xAOD::EmTauRoI * getL1Feature(const TrigCompositeUtils::Decision *) const
=======================================================================
Definition: TrigEgammaMatchingToolMT.cxx:227
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrigEgammaMatchingToolMT::getRingsFeature
const xAOD::TrigRingerRings * getRingsFeature(const TrigCompositeUtils::Decision *) const
=======================================================================
Definition: TrigEgammaMatchingToolMT.cxx:257
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
TrigEgammaMatchingToolMT::m_emTauRoIKey
SG::ReadHandleKey< xAOD::EmTauRoIContainer > m_emTauRoIKey
Definition: TrigEgammaMatchingToolMT.h:98
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrigEgammaMatchingToolMT::initialize
StatusCode initialize()
=======================================================================
Definition: TrigEgammaMatchingToolMT.cxx:33
TrigEgammaMatchingToolMT::TrigEgammaMatchingToolMT
TrigEgammaMatchingToolMT(const std::string &name)
Definition: TrigEgammaMatchingToolMT.cxx:25
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::Electron_v1
Definition: Electron_v1.h:34
TrigEgammaMatchingToolMT::m_dRL1
Gaudi::Property< float > m_dRL1
Definition: TrigEgammaMatchingToolMT.h:97
xAOD::TrigRingerRings_v2
Definition: TrigRingerRings_v2.h:24
TrigEgammaMatchingToolMT::matchHLTElectron
bool matchHLTElectron(const xAOD::Electron *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
Definition: TrigEgammaMatchingToolMT.cxx:139
TrigEgammaMatchingToolMT::m_dR
Gaudi::Property< float > m_dR
Definition: TrigEgammaMatchingToolMT.h:96
xAOD::Photon_v1
Definition: Photon_v1.h:37
TrigRoiDescriptorCollection
Definition: TrigRoiDescriptorCollection.h:21
xAOD::EgammaHelpers::isPhoton
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Definition: EgammaxAODHelpers.cxx:21
TrigEgammaMatchingToolMT::matchL2Electron
bool matchL2Electron(const xAOD::Electron *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
Definition: TrigEgammaMatchingToolMT.cxx:186
TrigEgammaMatchingToolMT::m_ringerKey
SG::ReadHandleKey< xAOD::TrigRingerRingsContainer > m_ringerKey
Definition: TrigEgammaMatchingToolMT.h:99
TrigEgammaMatchingToolMT::matchL2Photon
bool matchL2Photon(const xAOD::Photon *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
Definition: TrigEgammaMatchingToolMT.cxx:178
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
TrigRoiDescriptor.h
TrigEgammaMatchingToolMT::tdt
const ToolHandle< Trig::TrigDecisionTool > & tdt() const
Definition: TrigEgammaMatchingToolMT.h:94
skel.l1
l1
Definition: skel.GENtoEVGEN.py:425
xAOD::TrigEMCluster_v1
Description of a trigger EM cluster.
Definition: TrigEMCluster_v1.h:28
TrigEgammaMatchingToolMT::matchL1
bool matchL1(const xAOD::Egamma *, const std::string &, const TrigCompositeUtils::Decision *&, unsigned int condition=TrigDefs::Physics) const
=======================================================================
Definition: TrigEgammaMatchingToolMT.cxx:206
TrigEgammaMatchingToolMT::key
std::string key(const std::string &) const
=======================================================================
Definition: TrigEgammaMatchingToolMT.cxx:67
makeComparison.deltaR
float deltaR
Definition: makeComparison.py:36
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
TrigEgammaMatchingToolMT::isPassed
bool isPassed(const xAOD::Egamma *, const std::string &, unsigned int condition=TrigDefs::Physics) const
=======================================================================
Definition: TrigEgammaMatchingToolMT.cxx:74
PhysDESDM_Quirks.trigger
trigger
Definition: PhysDESDM_Quirks.py:27
HLTIdentifier.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37