ATLAS Offline Software
ElectronLRTOverlapRemovalTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
8 #include "CxxUtils/phihelper.h"
9 
10 #include <algorithm>
11 
12 namespace CP
13 {
14 
16  {
17  }
18 
20  // Initialisation
23  {
24 
25  if (!m_isDAOD)
26  {
28  {
29  asg::AsgToolConfig config("AsgElectronLikelihoodTool/ElectronLHSelectorVeryLooseNoPix");
30  ATH_CHECK(config.setProperty("WorkingPoint", "VeryLooseLHElectron_LLP"));
32  }
33 
34  ATH_MSG_DEBUG("Retrieving electron selection tool");
36 
37  if (m_electronLLHToolLooseNoPix.empty())
38  {
39  asg::AsgToolConfig config("AsgElectronLikelihoodTool/ElectronLHSelectorLooseNoPix");
40  ATH_CHECK(config.setProperty("WorkingPoint", "LooseLHElectron_LLP"));
42  }
43 
44  ATH_MSG_DEBUG("Retrieving electron selection tool");
46 
47  if (m_electronLLHToolMediumNoPix.empty())
48  {
49  asg::AsgToolConfig config("AsgElectronLikelihoodTool/ElectronLHSelectorMediumNoPix");
50  ATH_CHECK(config.setProperty("WorkingPoint", "MediumLHElectron_LLP"));
52  }
53 
54  ATH_MSG_DEBUG("Retrieving electron selection tool");
56 
57  if (m_electronLLHToolTightNoPix.empty())
58  {
59  asg::AsgToolConfig config("AsgElectronLikelihoodTool/ElectronLHSelectorTightNoPix");
60  ATH_CHECK(config.setProperty("WorkingPoint", "TightLHElectron_LLP"));
62  }
63 
64  ATH_MSG_DEBUG("Retrieving electron selection tool");
66  }
67 
68  return StatusCode::SUCCESS;
69  }
70 
71 
73  // Check if electron passes ID
75  bool ElectronLRTOverlapRemovalTool::electronPassesID(const xAOD::Electron *electron, const std::string& IDWorkingPoint) const
76  {
77 
78  if (m_isDAOD)
79  {
80  SG::AuxElement::ConstAccessor<char> DFCommonElectronsWP(IDWorkingPoint);
81  return bool(DFCommonElectronsWP(*electron) );
82  } else
83  {
84  if (IDWorkingPoint == "DFCommonElectronsLHTightNoPix"){
85  return bool(m_electronLLHToolTightNoPix->accept(electron));
86  }
87  else if (IDWorkingPoint == "DFCommonElectronsLHMediumNoPix"){
89  }
90  else if (IDWorkingPoint == "DFCommonElectronsLHLooseNoPix"){
91  return bool(m_electronLLHToolLooseNoPix->accept(electron));
92  }
93  else if (IDWorkingPoint == "DFCommonElectronsLHVeryLooseNoPix"){
95  }
96  else{
97  ATH_MSG_ERROR("IDWorkingPoint provided is not a valid Working Point!");
98  return false;
99  }
100  }
101 
102  }
103 
104 
106  // Check overlap between the electron collections and save pointer of duplicates
107  // This removes the LRT electron in favor of prompt
110  const xAOD::ElectronContainer &LRTElectronCol,
111  std::set<const xAOD::Electron *> &ElectronsToRemove) const
112  {
113 
114  // Loop over lrt electrons to remove those that do not pass ID.
115  // Needed in case there are no prompt electrons passing ID
117  ATH_MSG_DEBUG("Implementing overlap removal strategy 1");
118  for (const xAOD::Electron *LRTElectron : LRTElectronCol)
119  {
120  if (!electronPassesID(LRTElectron,"DFCommonElectronsLHVeryLooseNoPix")) ElectronsToRemove.insert(LRTElectron);
121  }
122  }
124  ATH_MSG_DEBUG("Implementing overlap removal strategy 2");
125  ATH_MSG_DEBUG("Electrons with overlapping clusters will be kept");
126  }
127 
128 
129  // loop over prompt electrons
130  for (const xAOD::Electron *promptElectron : promptElectronCol)
131  {
132  const ElementLink promptClusterLink = promptElectron->caloClusterLink(0);
133  const xAOD::CaloCluster_v1 *prompt_cluster = (*promptClusterLink);
134 
135  // Skip electrons that do not pass ID threshold
137  if (!electronPassesID(promptElectron,m_IDWorkingPoint))
138  {
139  ElectronsToRemove.insert(promptElectron);
140  continue;
141  }
142  }
143 
144  // loop over lrt electrons
145  for (const xAOD::Electron *LRTElectron : LRTElectronCol)
146  {
147  const ElementLink LRTClusterLink = LRTElectron->caloClusterLink(0);
148  const xAOD::CaloCluster_v1 *lrt_cluster = (*LRTClusterLink);
149 
150  // Skip LRT electrons that do not pass ID threshold
152  if (!electronPassesID(LRTElectron,m_IDWorkingPoint)) continue;
153  }
154  // check that clusters exist (necessary? copied from MuonSpec overlap, but all electrons have clusters...)
155  // TODO: This should then fall back to delta R if clusters are missing
156  if (!lrt_cluster and !prompt_cluster)
157  continue;
158 
159  // matching based on hottest cell of cluster
160  // as in ambiguity res for el/ph
161 
162  const double prompt_elEta0 = prompt_cluster->eta0();
163  const double prompt_elPhi0 = prompt_cluster->phi0();
164 
165  const double lrt_elEta0 = lrt_cluster->eta0();
166  const double lrt_elPhi0 = lrt_cluster->phi0();
167  ATH_MSG_DEBUG("Prompt eta, phi: "<<prompt_elEta0<< ", "<<prompt_elPhi0);
168  ATH_MSG_DEBUG("LRT eta, phi: "<<lrt_elEta0<< ", "<<lrt_elPhi0);
169 
170  if (prompt_elEta0 == lrt_elEta0 && prompt_elPhi0 == lrt_elPhi0)
171  {
173  ATH_MSG_DEBUG("Found a Calo cluster shared by LRT electron and prompt electron !");
174  ATH_MSG_DEBUG("Removing LRT Electron");
175  // Save pointer to LRT electrons failing overlap
176  // This removes the LRT electron in favor of prompt
177  ElectronsToRemove.insert(LRTElectron);
178  }
179  else if (m_strategy == CP::IElectronLRTOverlapRemovalTool::defaultStrategy){ //use tighter electron, if both equally tight use std collection
180 
181  ATH_MSG_DEBUG("Removing Electron with looser WP");
182  if (electronPassesID(promptElectron,"DFCommonElectronsLHTightNoPix")){
183  ElectronsToRemove.insert(LRTElectron);
184  }
185  else if (electronPassesID(promptElectron,"DFCommonElectronsLHMediumNoPix") ) {
186  if (electronPassesID(LRTElectron,"DFCommonElectronsLHTightNoPix") ){
187  ElectronsToRemove.insert(promptElectron);
188  }
189  else ElectronsToRemove.insert(LRTElectron);
190  }
191  else if (electronPassesID(promptElectron,"DFCommonElectronsLHLooseNoPix") ) {
192  if (electronPassesID(LRTElectron,"DFCommonElectronsLHMediumNoPix") ){
193  ElectronsToRemove.insert(promptElectron);
194  }
195  else ElectronsToRemove.insert(LRTElectron);
196  }
197  else if (electronPassesID(promptElectron,"DFCommonElectronsLHVeryLooseNoPix") ) {
198  if (electronPassesID(LRTElectron,"DFCommonElectronsLHLooseNoPix") ){
199  ElectronsToRemove.insert(promptElectron);
200  }
201  else ElectronsToRemove.insert(LRTElectron);
202  }
203  else {
204  if (electronPassesID(LRTElectron,"DFCommonElectronsLHVeryLooseNoPix") ) {
205  ElectronsToRemove.insert(promptElectron);
206  }
207  else ElectronsToRemove.insert(LRTElectron);
208  }
209  }
210  }
211  } // end lrt loop
212  } // end prompt loop
213  }
214 
215 } // end namespace CP
xAOD::CaloCluster_v1::phi0
flt_t phi0() const
Returns raw of cluster seed.
CP::IElectronLRTOverlapRemovalTool::promptStrategy
@ promptStrategy
Definition: IElectronLRTOverlapRemovalTool.h:50
CP::IElectronLRTOverlapRemovalTool::defaultStrategy
@ defaultStrategy
Definition: IElectronLRTOverlapRemovalTool.h:49
asg
Definition: DataHandleTestTool.h:28
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
CP::ElectronLRTOverlapRemovalTool::m_strategy
Gaudi::Property< int > m_strategy
Definition: ElectronLRTOverlapRemovalTool.h:53
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
asg::AsgToolConfig
an object that can create a AsgTool
Definition: AsgToolConfig.h:22
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
CP::ElectronLRTOverlapRemovalTool::checkOverlap
virtual void checkOverlap(const xAOD::ElectronContainer &promptCollection, const xAOD::ElectronContainer &lrtCollection, std::set< const xAOD::Electron * > &ElectronsToRemove) const
Check the overlap between the prompt and LRT electron collections.
Definition: ElectronLRTOverlapRemovalTool.cxx:109
AsgToolConfig.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CP::ElectronLRTOverlapRemovalTool::electronPassesID
bool electronPassesID(const xAOD::Electron *electron, const std::string &IDWorkingPoint) const
Definition: ElectronLRTOverlapRemovalTool.cxx:75
CP::ElectronLRTOverlapRemovalTool::m_electronLLHToolMediumNoPix
ToolHandle< IAsgElectronLikelihoodTool > m_electronLLHToolMediumNoPix
Definition: ElectronLRTOverlapRemovalTool.h:60
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
CP::ElectronLRTOverlapRemovalTool::ElectronLRTOverlapRemovalTool
ElectronLRTOverlapRemovalTool(const std::string &name)
Standard algorithm methods:
Definition: ElectronLRTOverlapRemovalTool.cxx:15
CP::ElectronLRTOverlapRemovalTool::m_isDAOD
Gaudi::Property< bool > m_isDAOD
Delta R threshold for matching in overlap removal.
Definition: ElectronLRTOverlapRemovalTool.h:55
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
phihelper.h
Helper for azimuthal angle calculations.
CP::ElectronLRTOverlapRemovalTool::m_IDWorkingPoint
Gaudi::Property< std::string > m_IDWorkingPoint
Switches method for retrieving electron ID.
Definition: ElectronLRTOverlapRemovalTool.h:56
xAOD::Electron_v1
Definition: Electron_v1.h:34
xAOD::CaloCluster_v1::eta0
flt_t eta0() const
Returns raw of cluster seed.
CP::ElectronLRTOverlapRemovalTool::m_electronLLHToolLooseNoPix
ToolHandle< IAsgElectronLikelihoodTool > m_electronLLHToolLooseNoPix
Definition: ElectronLRTOverlapRemovalTool.h:59
CP::ElectronLRTOverlapRemovalTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: ElectronLRTOverlapRemovalTool.cxx:22
CP::ElectronLRTOverlapRemovalTool::m_electronLLHToolVeryLooseNoPix
ToolHandle< IAsgElectronLikelihoodTool > m_electronLLHToolVeryLooseNoPix
Switches method for retrieving electron ID.
Definition: ElectronLRTOverlapRemovalTool.h:58
config
std::vector< std::string > config
Definition: fbtTestBasics.cxx:72
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
CP::ElectronLRTOverlapRemovalTool::m_electronLLHToolTightNoPix
ToolHandle< IAsgElectronLikelihoodTool > m_electronLLHToolTightNoPix
Definition: ElectronLRTOverlapRemovalTool.h:61
ElectronLRTOverlapRemovalTool.h
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
CP::IElectronLRTOverlapRemovalTool::passThrough
@ passThrough
Definition: IElectronLRTOverlapRemovalTool.h:51