ATLAS Offline Software
TrigEgammaEmulationToolMT.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 "boost/algorithm/string.hpp"
7 
8 using namespace Trig;
9 
10 
11 
12 //**********************************************************************
13 
15  : AsgTool(myname),
16  m_trigdec("Trig::TrigDecisionTool/TrigDecisionTool"),
17  m_matchTool("Trig::TrigEgammaMatchingToolMT/TrigEgammaMatchingToolMT")
18 {
19  declareProperty( "MatchTool" , m_matchTool );
20 }
21 
22 //**********************************************************************
23 
25 {
26  ATH_CHECK(m_matchTool.retrieve());
27 
28  //Enable expert methods
29  ATH_CHECK(m_trigdec.retrieve());
30 
31  // retrieve all hypo chains
32  ATH_CHECK( m_hypoTools.retrieve() );
33 
34 
35  ATH_CHECK( m_egammaPhotonCBTools.retrieve() );
36  ATH_CHECK( m_egammaElectronDNNTools.retrieve() );
37  ATH_CHECK( m_egammaElectronCBTools.retrieve() );
38  ATH_CHECK( m_egammaElectronLHTools.retrieve() );
39  ATH_CHECK( m_ringerTools.retrieve() );
40 
41 
42  //add cuts into TAccept
43  m_accept.addCut("L1Calo" , "Trigger L1Calo step" );
44  m_accept.addCut("L2Calo" , "Trigger L2Calo step" );
45  m_accept.addCut("L2" , "Trigger L2Electron step" );
46  m_accept.addCut("EFCalo" , "Trigger EFCalo step" );
47  m_accept.addCut("EFTrack" , "Trigger EFTrack step" );
48  m_accept.addCut("HLT" , "Trigger HLT decision" );
49 
50 
51  return StatusCode::SUCCESS;
52 }
53 
54 //**********************************************************************
55 
57  const std::string& trigger, bool &valid) const
58 {
59  asg::AcceptData acceptData (&m_accept);
60  valid=false;
61  for ( auto& tool : m_hypoTools )
62  {
63  if( tool->chain() == trigger )
64  {
65  Trig::TrigData input(trigger);
66  if(!match(roi, input)) return acceptData;
67 
68  // Check of the match procedure has all objects inside
69  if(!input.isValid()){
70  ATH_MSG_WARNING("Its not possible to find all trigger features for this RoI. Skip emulation.");
71  return acceptData;
72  }
73 
74  valid=true;
75  return tool->emulate(input);
76 
77  }// Tool
78 
79  }// Loop over all hypo tool chains
80 
81  return acceptData;
82 }
83 
84 
85 //**********************************************************************
86 
89  unsigned int condition) const
90 {
91  output.clear();
92 
93  if(!roi) {
94  ATH_MSG_DEBUG("no Roi!");
95  return false;
96  }
97 
98 
99  // Link all selectors with this trig object to easy acesss throut of the chain
100  // Avoid multiple selectors
101  output.egammaElectronCBTools=m_egammaElectronCBTools;
102  output.egammaElectronDNNTools=m_egammaElectronDNNTools;
103  output.egammaElectronLHTools=m_egammaElectronLHTools;
104  output.egammaPhotonCBTools=m_egammaPhotonCBTools;
105  output.ringerTools=m_ringerTools;
106 
107 
108  if(output.signature == "electron"){
109  for (auto& trigger : m_electronTrigList){
110 
111  if(boost::contains(output.trigger,"gsf") && !boost::contains(trigger,"gsf")) continue;
112  if(boost::contains(output.trigger,"lrt") && !boost::contains(trigger,"lrt")) continue;
113 
114  ATH_MSG_DEBUG("Matching with " << trigger );
115 
116 
117  auto vec_el_linkInfo = match()->getFeatures<xAOD::ElectronContainer>(roi,trigger,condition);
118 
119  if( !vec_el_linkInfo.empty() ){
120 
121  output.clear();
122 
123  // Step 5
124  {
125  for(auto&featLinkInfo : vec_el_linkInfo)
126  {
127  if(!featLinkInfo.isValid()) continue;
128  auto el = *featLinkInfo.link;
129  output.electrons.push_back(el);
130  }
131  }
132 
133  // Step 3
134  {
135  auto vec_feat = match()->getFeatures<xAOD::CaloClusterContainer>(roi,trigger,condition);
136  for(auto& featLinkInfo : vec_feat){
137  if(!featLinkInfo.isValid()) continue;
138  output.clusters.push_back(*featLinkInfo.link);
139  }
140  }
141 
142  // Step 2
143  {
144  auto vec_feat = match()->getFeatures<xAOD::TrigElectronContainer>(roi, trigger, condition);
145  for ( auto& featLinkInfo : vec_feat ){
146  if(!featLinkInfo.isValid()) continue;
147  output.trig_electrons.push_back(*featLinkInfo.link);
148  }
149  }
150 
151  // Step 1
152  {
153  // get rings from container access
154  output.rings = match()->getRingsFeature(roi);
155  if(output.rings){
156  output.emCluster = output.rings->emCluster();
157  }
158  }
159 
160 
161 
162  // Step 0
163  {
164  // L1Calo (step 0)
165  output.l1 = match()->getL1Feature(roi);
166  auto featLinkInfo = match()->getFeature<TrigRoiDescriptorCollection>(roi,trigger, condition);
167  if(featLinkInfo.isValid()){
168  output.roi = *featLinkInfo.link;
169  }
170  }
171 
172  ATH_MSG_DEBUG( "L1 RoI TDET = " << (output.roi?"Yes":"No"));
173  ATH_MSG_DEBUG( "L1 RoI EmTau = " << (output.l1?"Yes":"No"));
174  ATH_MSG_DEBUG( "L2 Cluster = " << (output.emCluster?"Yes":"No"));
175  ATH_MSG_DEBUG( "L2 Rings = " << (output.rings?"Yes":"No"));
176  ATH_MSG_DEBUG( "L2 Electrons = " << (output.trig_electrons.size()));
177  ATH_MSG_DEBUG( "HLT Cluster = " << output.clusters.size());
178  ATH_MSG_DEBUG( "HLT el = " << output.electrons.size());
179 
180  }// has electron
181 
182  // stop the trigger loop since we have all features inside
183  if(output.isValid())
184  return true;
185 
186  }// Loop over triggers
187 
188  }else if (output.signature == "photon"){
189 
190  for (auto& trigger : m_photonTrigList){
191 
192  auto vec_ph_linkInfo = match()->getFeatures<xAOD::PhotonContainer>(roi,trigger,condition);
193 
194  if( !vec_ph_linkInfo.empty() ){
195 
196  // clean all vectors before fill it
197  output.clear();
198 
199  // Step 5
200  {
201  for(auto&featLinkInfo : vec_ph_linkInfo){
202  if(!featLinkInfo.isValid()) continue;
203  output.photons.push_back(*featLinkInfo.link);
204  }
205  }
206 
207  // Step 3
208  {
209  auto vec_feat = match()->getFeatures<xAOD::CaloClusterContainer>(roi,trigger,condition);
210  for(auto& featLinkInfo : vec_feat){
211  if(!featLinkInfo.isValid()) continue;
212  output.clusters.push_back(*featLinkInfo.link);
213  }
214  }
215 
216  // Step 1
217  {
218  auto featLinkInfo = match()->getFeature<xAOD::TrigEMClusterContainer>(roi,trigger);
219  if(featLinkInfo.isValid()){
220  output.emCluster = *featLinkInfo.link;
221  }
222  // get rings from container access
223  output.rings = match()->getRingsFeature(roi);
224 
225  }
226 
227  // Step 0
228  {
229  // L1Calo (step 0)
230  output.l1 = match()->getL1Feature(roi);
231  auto featLinkInfo = match()->getFeature<TrigRoiDescriptorCollection>(roi,trigger);
232  if(featLinkInfo.isValid()){
233  output.roi = *featLinkInfo.link;
234  }
235  }
236 
237  ATH_MSG_DEBUG( "L1 RoI TDET = " << (output.roi?"Yes":"No"));
238  ATH_MSG_DEBUG( "L1 RoI EmTau = " << (output.l1?"Yes":"No"));
239  ATH_MSG_DEBUG( "L2 Cluster = " << (output.emCluster?"Yes":"No"));
240  ATH_MSG_DEBUG( "L2 Rings = " << (output.rings?"Yes":"No"));
241  ATH_MSG_DEBUG( "L2 Photon = " << (output.trig_photon?"Yes":"No"));
242  ATH_MSG_DEBUG( "HLT Cluster = " << output.clusters.size());
243  ATH_MSG_DEBUG( "HLT ph = " << output.photons.size());
244  }// has electron
245 
246  // stop the trigger loop since we have all features inside
247  if(output.isValid()) return true;
248 
249  }// Loop over triggers
250  }
251 
252 
253  return false;
254 }
255 
256 
257 //**********************************************************************
258 
259 
260 
261 TrigData::TrigData( const std::string& name )
262 {
263  this->signature = "electron"; // default
264  if(boost::contains(name,"HLT_e")) this->signature = "electron";
265  else if(boost::contains(name,"HLT_g")) this->signature = "photon";
266 }
267 
268 
270 {
271  this->electrons.clear();
272  this->trig_electrons.clear();
273  this->clusters.clear();
274  this->photons.clear();
275  this->roi = nullptr;
276  this->l1 = nullptr;
277  this->emCluster = nullptr;
278  this->rings = nullptr;
279  this->trig_photon = nullptr;
280 }
281 
282 
283 bool TrigData::isValid() const
284 {
285  bool passed = (this->roi && this->l1 && this->emCluster && this->rings);
286  if (this->signature == "photon"){
287  return (this->trig_photon && !this->photons.empty() && passed);
288  }else if (this->signature == "electron"){
289  return (!this->trig_electrons.empty() && !this->electrons.empty() && passed);
290  }else{
291  return false;
292  }
293 }
294 
295 
296 bool TrigData::isPassed( const xAOD::Photon *ph , const std::string& pidname ) const
297 {
298  if (pidname=="tight"){
299  return (bool)this->egammaPhotonCBTools[0]->accept(ph);
300  }else if (pidname=="medium"){
301  return (bool)this->egammaPhotonCBTools[1]->accept(ph);
302  }else if (pidname=="loose"){
303  return (bool)this->egammaPhotonCBTools[2]->accept(ph);
304  }else{
305  return true;
306  }
307 }
308 
309 bool TrigData::isPassed( const xAOD::Electron *el , float avgmu, const std::string& pidname ) const
310 {
311  if (pidname=="lhtight"){
312  return (bool)this->egammaElectronLHTools[0]->accept(Gaudi::Hive::currentContext(),el,avgmu );
313  }else if (pidname=="lhmedium"){
314  return (bool)this->egammaElectronLHTools[1]->accept(Gaudi::Hive::currentContext(),el,avgmu );
315  }else if (pidname=="lhloose"){
316  return (bool)this->egammaElectronLHTools[2]->accept(Gaudi::Hive::currentContext(),el,avgmu );
317  }else if (pidname=="lhvloose"){
318  return (bool)this->egammaElectronLHTools[3]->accept(Gaudi::Hive::currentContext(),el,avgmu );
319  }else if (pidname=="dnntight"){
320  return (bool)this->egammaElectronDNNTools[0]->accept(Gaudi::Hive::currentContext(),el,avgmu );
321  }else if (pidname=="dnnmedium"){
322  return (bool)this->egammaElectronDNNTools[1]->accept(Gaudi::Hive::currentContext(),el,avgmu );
323  }else if (pidname=="dnnloose"){
324  return (bool)this->egammaElectronDNNTools[2]->accept(Gaudi::Hive::currentContext(),el,avgmu );
325  }else if (pidname=="dnnvloose"){
326  return (bool)this->egammaElectronDNNTools[3]->accept(Gaudi::Hive::currentContext(),el,avgmu );
327  }else if (pidname=="tight"){
328  return (bool)this->egammaElectronCBTools[0]->accept(Gaudi::Hive::currentContext(),el );
329  }else if (pidname=="medium"){
330  return (bool)this->egammaElectronCBTools[1]->accept(Gaudi::Hive::currentContext(),el );
331  }else if (pidname=="loose"){
332  return (bool)this->egammaElectronCBTools[2]->accept(Gaudi::Hive::currentContext(),el );
333  }else{
334  return true;
335  }
336 }
337 
338 
339 bool TrigData::isPassed( const xAOD::TrigRingerRings *cl , float avgmu, const std::string& pidname ) const
340 {
341  if (pidname=="tight"){
342  float output = this->ringerTools[0]->predict(cl);
343  return (bool)this->ringerTools[0]->accept(cl, output, avgmu);
344  }else if (pidname=="medium"){
345  float output = this->ringerTools[1]->predict(cl);
346  return (bool)this->ringerTools[1]->accept(cl, output, avgmu);
347  }else if (pidname=="loose"){
348  float output = this->ringerTools[2]->predict(cl);
349  return (bool)this->ringerTools[2]->accept(cl, output, avgmu);
350  }else if (pidname=="vloose"){
351  float output = this->ringerTools[3]->predict(cl);
352  return (bool)this->ringerTools[3]->accept(cl, output, avgmu);
353  }else{
354  return true;
355  }
356 }
357 
358 
359 
Trig::TrigData::photons
std::vector< const xAOD::Photon * > photons
Definition: TrigEgammaEmulationToolMT.h:80
TrigCompositeUtils::passed
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
Definition: TrigCompositeUtilsRoot.cxx:117
Trig::TrigData::isPassed
bool isPassed(const xAOD::Photon *ph, const std::string &pidname) const
Definition: TrigEgammaEmulationToolMT.cxx:296
Trig
The common trigger namespace for trigger analysis tools.
Definition: LArCellMonAlg.h:33
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trig::TrigEgammaEmulationToolMT::match
const ToolHandle< TrigEgammaMatchingToolMT > & match() const
Definition: TrigEgammaEmulationToolMT.h:128
Trig::TrigEgammaEmulationToolMT::m_electronTrigList
Gaudi::Property< std::vector< std::string > > m_electronTrigList
Definition: TrigEgammaEmulationToolMT.h:125
Trig::TrigEgammaEmulationToolMT::m_accept
asg::AcceptInfo m_accept
Accept.
Definition: TrigEgammaEmulationToolMT.h:123
Trig::TrigData::egammaElectronCBTools
ToolHandleArray< IAsgElectronIsEMSelector > egammaElectronCBTools
Definition: TrigEgammaEmulationToolMT.h:87
Trig::TrigEgammaEmulationToolMT::m_photonTrigList
Gaudi::Property< std::vector< std::string > > m_photonTrigList
Definition: TrigEgammaEmulationToolMT.h:126
LArG4GenerateShowerLib.condition
condition
Definition: LArG4GenerateShowerLib.py:19
Trig::TrigData::egammaPhotonCBTools
ToolHandleArray< IAsgPhotonIsEMSelector > egammaPhotonCBTools
Definition: TrigEgammaEmulationToolMT.h:84
Trig::TrigEgammaEmulationToolMT::m_trigdec
ToolHandle< Trig::TrigDecisionTool > m_trigdec
Trigger decision tool.
Definition: TrigEgammaEmulationToolMT.h:119
Trig::TrigData::trig_electrons
std::vector< const xAOD::TrigElectron * > trig_electrons
Definition: TrigEgammaEmulationToolMT.h:76
Trig::TrigEgammaEmulationToolMT::m_egammaPhotonCBTools
ToolHandleArray< IAsgPhotonIsEMSelector > m_egammaPhotonCBTools
Definition: TrigEgammaEmulationToolMT.h:137
Trig::TrigData::signature
std::string signature
Definition: TrigEgammaEmulationToolMT.h:61
calibdata.valid
list valid
Definition: calibdata.py:45
Trig::TrigEgammaEmulationToolMT::m_egammaElectronLHTools
ToolHandleArray< IAsgElectronLikelihoodTool > m_egammaElectronLHTools
Definition: TrigEgammaEmulationToolMT.h:142
Trig::TrigEgammaEmulationToolMT::m_ringerTools
ToolHandleArray< Ringer::IAsgRingerSelectorTool > m_ringerTools
Definition: TrigEgammaEmulationToolMT.h:145
Trig::TrigData::ringerTools
ToolHandleArray< Ringer::IAsgRingerSelectorTool > ringerTools
Definition: TrigEgammaEmulationToolMT.h:90
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
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
Trig::TrigEgammaEmulationToolMT::emulate
asg::AcceptData emulate(const TrigCompositeUtils::Decision *dec, const std::string &trigger, bool &valid) const
Definition: TrigEgammaEmulationToolMT.cxx:56
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trig::TrigData::electrons
std::vector< const xAOD::Electron * > electrons
Definition: TrigEgammaEmulationToolMT.h:78
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
Trig::TrigData::egammaElectronLHTools
ToolHandleArray< IAsgElectronLikelihoodTool > egammaElectronLHTools
Definition: TrigEgammaEmulationToolMT.h:88
merge.output
output
Definition: merge.py:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Trig::TrigData::emCluster
const xAOD::TrigEMCluster * emCluster
Definition: TrigEgammaEmulationToolMT.h:68
Trig::TrigEgammaEmulationToolMT::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: TrigEgammaEmulationToolMT.cxx:24
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
Trig::TrigData::clear
void clear()
Definition: TrigEgammaEmulationToolMT.cxx:269
Trig::TrigEgammaEmulationToolMT::m_hypoTools
ToolHandleArray< Trig::ITrigEgammaEmulationChain > m_hypoTools
Definition: TrigEgammaEmulationToolMT.h:116
Trig::TrigData::clusters
std::vector< const xAOD::CaloCluster * > clusters
Definition: TrigEgammaEmulationToolMT.h:74
Trig::TrigData::rings
const xAOD::TrigRingerRings * rings
Definition: TrigEgammaEmulationToolMT.h:70
xAOD::Electron_v1
Definition: Electron_v1.h:34
xAOD::TrigRingerRings_v2
Definition: TrigRingerRings_v2.h:24
Trig::TrigData::egammaElectronDNNTools
ToolHandleArray< AsgElectronSelectorTool > egammaElectronDNNTools
Definition: TrigEgammaEmulationToolMT.h:86
Trig::TrigEgammaEmulationToolMT::m_matchTool
ToolHandle< TrigEgammaMatchingToolMT > m_matchTool
Definition: TrigEgammaEmulationToolMT.h:121
Trig::TrigEgammaEmulationToolMT::TrigEgammaEmulationToolMT
TrigEgammaEmulationToolMT(const std::string &myname)
Definition: TrigEgammaEmulationToolMT.cxx:14
Trig::TrigData::roi
const TrigRoiDescriptor * roi
Definition: TrigEgammaEmulationToolMT.h:64
xAOD::Photon_v1
Definition: Photon_v1.h:37
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TrigRoiDescriptorCollection
Definition: TrigRoiDescriptorCollection.h:21
Trig::TrigData
Definition: TrigEgammaEmulationToolMT.h:40
Trig::TrigEgammaEmulationToolMT::m_egammaElectronDNNTools
ToolHandleArray< AsgElectronSelectorTool > m_egammaElectronDNNTools
Definition: TrigEgammaEmulationToolMT.h:140
Trig::TrigData::l1
const xAOD::EmTauRoI * l1
Definition: TrigEgammaEmulationToolMT.h:66
asg::AcceptData
Definition: AcceptData.h:30
Trig::TrigEgammaEmulationToolMT::m_egammaElectronCBTools
ToolHandleArray< IAsgElectronIsEMSelector > m_egammaElectronCBTools
Definition: TrigEgammaEmulationToolMT.h:141
Trig::TrigData::isValid
bool isValid() const
Definition: TrigEgammaEmulationToolMT.cxx:283
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
Trig::TrigData::trig_photon
const xAOD::TrigPhoton * trig_photon
Definition: TrigEgammaEmulationToolMT.h:72
Trig::TrigData::TrigData
TrigData(const std::string &)
Definition: TrigEgammaEmulationToolMT.cxx:261
TrigEgammaEmulationToolMT.h
asg::AcceptInfo::addCut
int addCut(const std::string &cutName, const std::string &cutDescription)
Add a cut; returning the cut position.
Definition: AcceptInfo.h:53