ATLAS Offline Software
EleEleOverlapTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // System includes
6 #include <typeinfo>
7 #include <exception>
8 
9 // Framework includes
12 
13 // EDM includes
14 #include "xAODEgamma/EgammaDefs.h"
15 
16 // Local includes
18 
19 namespace
20 {
21 
24  bool isDummyVal(float x)
25  {
26  const float epsilon = 1e-5;
27  const float dummyVal = -999;
28  return std::abs(x - dummyVal) < epsilon;
29  }
30 
31  // Define simple exception for Dummy/missing values
32  class DummyValError : public std::exception
33  {};
34 
35 }
36 
37 namespace ORUtils
38 {
39 
40  //---------------------------------------------------------------------------
41  // Constructor
42  //---------------------------------------------------------------------------
45  m_useTrackMatch(true),
46  m_useClusterMatch(false),
47  m_clusterDeltaEta(3*0.025),
48  m_clusterDeltaPhi(5*0.025)
49  {
50  declareProperty("UseTrackMatch", m_useTrackMatch,
51  "Match electrons by shared track");
52  declareProperty("UseClusterMatch", m_useClusterMatch,
53  "Match electrons by cluster proximity");
54  declareProperty("ClusterDeltaEta", m_clusterDeltaEta,
55  "Cluster matching delta eta");
56  declareProperty("ClusterDeltaPhi", m_clusterDeltaPhi,
57  "Cluster matching delta phi");
58  }
59 
60  //---------------------------------------------------------------------------
61  // Initialize
62  //---------------------------------------------------------------------------
64  {
65  ATH_MSG_DEBUG("UseTrackMatch " << m_useTrackMatch <<
66  " UseClusterMatch " << m_useClusterMatch <<
67  " ClusterDeltaEta " << m_clusterDeltaEta <<
68  " ClusterDeltaPhi " << m_clusterDeltaPhi);
69 
70  // Sanity check
72  ATH_MSG_ERROR("You must enable at least one: UseTrackMatch or UseClusterMatch");
73  return StatusCode::FAILURE;
74  }
75 
76  return StatusCode::SUCCESS;
77  }
78 
79  //---------------------------------------------------------------------------
80  // Identify overlaps
81  //---------------------------------------------------------------------------
84  const xAOD::IParticleContainer& cont2) const
85  {
86  // I require that the two containers are the same so that I can
87  // arbitrarily pick one of them to use.
88  if(&cont1 != &cont2) {
89  ATH_MSG_ERROR("This tool expects both electron containers to be the " <<
90  "same for now");
91  return StatusCode::FAILURE;
92  }
93  // Check the container type
94  if(typeid(cont1) != typeid(xAOD::ElectronContainer) &&
95  typeid(cont1) != typeid(ConstDataVector<xAOD::ElectronContainer>)) {
96  ATH_MSG_ERROR("Container is not an ElectronContainer!");
97  return StatusCode::FAILURE;
98  }
99  // Call the type-specific method
100  ATH_CHECK( findOverlaps(static_cast<const xAOD::ElectronContainer&>(cont1)) );
101  return StatusCode::SUCCESS;
102  }
103 
104  //---------------------------------------------------------------------------
105  // Identify overlaps
106  //---------------------------------------------------------------------------
109  {
110  ATH_MSG_DEBUG("Removing overlapping electrons");
111 
112  // Initialize output decorations if necessary
113  m_decHelper->initializeDecorations(electrons);
114 
115  // TODO: consider adding cluster-based matching also
116 
117  // Loop over surviving electron pairs
118  for(const auto el1 : electrons) {
119  if(!m_decHelper->isSurvivingObject(*el1)) continue;
120  for(const auto el2 : electrons) {
121  if(el1 == el2) continue;
122  if(!m_decHelper->isSurvivingObject(*el2)) continue;
123 
124  // Perform the match and decide whether to reject el1
125  try {
126  if(electronsMatch(*el1, *el2) && rejectFirst(*el1, *el2)) {
127  ATH_CHECK( handleOverlap(el1, el2) );
128  }
129  }
130  catch(const DummyValError& e) {
131  ATH_MSG_ERROR("Cluster 2nd sampling eta/phi values are -999. " <<
132  "It seems you are missing the neccesary variables to "
133  "do the requested electron-electron cluster matching");
134  return StatusCode::FAILURE;
135  }
136  }
137  }
138 
139  return StatusCode::SUCCESS;
140  }
141 
142  //---------------------------------------------------------------------------
143  // Apply the ele-ele matching criteria
144  //---------------------------------------------------------------------------
146  electronsMatch(const xAOD::Electron& el1, const xAOD::Electron& el2) const
147  {
148  // Look for a shared track
150  return true;
151 
152  // Look for overlapping clusters
153  if(m_useClusterMatch) {
154  const auto& clus1 = *el1.caloCluster();
155  const auto& clus2 = *el2.caloCluster();
157 
158  // We use coordinates from 2nd sampling
159  const unsigned layer = 2;
160  const float eta1 = clus1.etaBE(layer);
161  const float eta2 = clus2.etaBE(layer);
162  const float phi1 = clus1.phiBE(layer);
163  const float phi2 = clus2.phiBE(layer);
164 
165  // Check validity of the eta/phi (no dummy -999 values)
166  if(isDummyVal(eta1) || isDummyVal(eta2) ||
167  isDummyVal(phi1) || isDummyVal(phi2)) {
168  throw DummyValError();
169  }
170 
171  const float dEta = clus1.etaBE(layer) - clus2.etaBE(layer);
172  const float dPhi = deltaPhi(clus1.phiBE(layer), clus2.phiBE(layer));
173 
174  if( std::abs(dEta) < m_clusterDeltaEta &&
175  std::abs(dPhi) < m_clusterDeltaPhi )
176  {
177  return true;
178  }
179  }
180 
181  return false;
182  }
183 
184  //---------------------------------------------------------------------------
185  // Decide whether to reject the first electron compared to the 2nd.
186  // This function assumes a matching criteria has already been applied.
187  //---------------------------------------------------------------------------
189  rejectFirst(const xAOD::Electron& el1, const xAOD::Electron& el2) const
190  {
191  // TODO: consider incorporating track-match information in the priority
192  // selection.
193 
194  // Always reject author "Ambiguous" when compared to author "Electron"
197  return true;
200  return false;
201 
202  // Reject the softer electron
203  if(el1.pt() < el2.pt()) return true;
204 
205  return false;
206  }
207 
208 } // namespace ORUtils
ORUtils::EleEleOverlapTool::m_clusterDeltaEta
double m_clusterDeltaEta
Cluster-matching dEta.
Definition: EleEleOverlapTool.h:80
ORUtils::EleEleOverlapTool::m_clusterDeltaPhi
double m_clusterDeltaPhi
Cluster-matching dPhi.
Definition: EleEleOverlapTool.h:83
ParticleGun_SamplingFraction.eta2
eta2
Definition: ParticleGun_SamplingFraction.py:96
ORUtils::EleEleOverlapTool::initializeDerived
virtual StatusCode initializeDerived() override
Initialize the tool.
Definition: EleEleOverlapTool.cxx:63
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
xAODP4Helpers.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
ORUtils::EleEleOverlapTool::rejectFirst
bool rejectFirst(const xAOD::Electron &el1, const xAOD::Electron &el2) const
Helper method to decide which electron to reject.
Definition: EleEleOverlapTool.cxx:189
xAOD::Egamma_v1::author
uint16_t author(uint16_t bitmask=EgammaParameters::AuthorALL) const
Get author.
Definition: Egamma_v1.cxx:166
xAOD::P4Helpers::deltaPhi
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition: xAODP4Helpers.h:69
xAOD::eta1
setEt setPhi setE277 setWeta2 eta1
Definition: TrigEMCluster_v1.cxx:41
ORUtils::EleEleOverlapTool::EleEleOverlapTool
EleEleOverlapTool(const std::string &name)
Create proper constructor for Athena.
Definition: EleEleOverlapTool.cxx:43
ORUtils
Definition: AltMuJetOverlapTool.h:20
x
#define x
ORUtils::EleEleOverlapTool::m_useTrackMatch
bool m_useTrackMatch
Match electrons by shared track (on by default)
Definition: EleEleOverlapTool.h:74
xAOD::Electron_v1::trackParticleLink
const ElementLink< TrackParticleContainer > & trackParticleLink(size_t index=0) const
ElementLink to the xAOD::TrackParticle/s that match the electron candidate.
Definition: Electron_v1.cxx:68
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ORUtils::EleEleOverlapTool::electronsMatch
bool electronsMatch(const xAOD::Electron &el1, const xAOD::Electron &el2) const
Helper method for matching electrons.
Definition: EleEleOverlapTool.cxx:146
xAOD::EgammaParameters::AuthorAmbiguous
const uint16_t AuthorAmbiguous
Object Reconstructed by standard cluster-based algorithm.
Definition: EgammaDefs.h:32
ORUtils::BaseOverlapTool
Common base class tool for overlap tools.
Definition: BaseOverlapTool.h:38
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
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
TauGNNUtils::Variables::Track::dPhi
bool dPhi(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:530
xAOD::Egamma_v1::caloCluster
const xAOD::CaloCluster * caloCluster(size_t index=0) const
Pointer to the xAOD::CaloCluster/s that define the electron candidate.
Definition: Egamma_v1.cxx:388
calibdata.exception
exception
Definition: calibdata.py:496
ORUtils::BaseOverlapTool::m_decHelper
std::unique_ptr< OverlapDecorationHelper > m_decHelper
Helper for handling input/output decorations.
Definition: BaseOverlapTool.h:95
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
EleEleOverlapTool.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::Electron_v1
Definition: Electron_v1.h:34
ORUtils::BaseOverlapTool::handleOverlap
virtual StatusCode handleOverlap(const xAOD::IParticle *testParticle, const xAOD::IParticle *refParticle) const
Common helper method to handle an overlap result.
Definition: BaseOverlapTool.cxx:64
ORUtils::EleEleOverlapTool::m_useClusterMatch
bool m_useClusterMatch
Match electrons by cluster distance (off by default)
Definition: EleEleOverlapTool.h:77
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
EgammaDefs.h
xAOD::Egamma_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: Egamma_v1.cxx:65
TauGNNUtils::Variables::Track::dEta
bool dEta(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:525
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
ORUtils::EleEleOverlapTool::findOverlaps
virtual StatusCode findOverlaps(const xAOD::IParticleContainer &cont1, const xAOD::IParticleContainer &cont2) const override
Identify overlapping electrons.
Definition: EleEleOverlapTool.cxx:83
xAOD::EgammaParameters::AuthorElectron
const uint16_t AuthorElectron
Object Reconstructed by standard cluster-based algorithm.
Definition: EgammaDefs.h:24