ATLAS Offline Software
Loading...
Searching...
No Matches
EleMuSharedTrkOverlapTool.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
8// Framework includes
10
11// EDM includes
13
14// Local includes
16
17namespace ORUtils
18{
19
20 //---------------------------------------------------------------------------
21 // Constructor
22 //---------------------------------------------------------------------------
24 : BaseOverlapTool(name)
25 {
26 declareProperty("RemoveCaloMuons", m_removeCaloMuons = true,
27 "Turn on removal of overlapping calo muons");
28 declareProperty("UseDRMatching", m_useDRMatching = false,
29 "Remove electrons in DR cone of muons");
30 declareProperty("DR", m_maxDR = 0.01,
31 "Delta-R cone for flagging overlaps");
32 declareProperty("UseRapidity", m_useRapidity = true,
33 "Calculate delta-R using rapidity");
34 }
35
36 //---------------------------------------------------------------------------
37 // Initialize the tool
38 //---------------------------------------------------------------------------
40 {
41
43 ATH_MSG_DEBUG("Configuring removal of overlapping calo muons");
44 }
45
47 ATH_MSG_DEBUG("Configuring removal of electrons in delta R cone of " << m_maxDR);
48 m_dRMatcher = std::make_unique<DeltaRMatcher>(m_maxDR, m_useRapidity);
50 addSubtool(*m_dRMatcher);
51 }
52
53 return StatusCode::SUCCESS;
54 }
55
56 //---------------------------------------------------------------------------
57 // Identify overlaps
58 //---------------------------------------------------------------------------
62 columnar::EventContextId /*eventContext*/) const
63 {
64 // Check the container types
65 ATH_CHECK( checkForXAODContainer<xAOD::ElectronContainer>(cont1, "First container arg is not of type ElectronContainer!") );
66 ATH_CHECK( checkForXAODContainer<xAOD::MuonContainer>(cont2, "Second container arg is not of type MuonContainer!") );
67
68 ATH_CHECK( internalFindOverlaps(cont1, cont2) );
69 return StatusCode::SUCCESS;
70 }
71
72 //---------------------------------------------------------------------------
73 // Identify overlaps between electrons and muons
74 //---------------------------------------------------------------------------
77 columnar::Particle2Range muons) const
78 {
79 ATH_MSG_DEBUG("Removing overlapping electrons and muons");
80 auto& acc = *m_accessors;
81
82 // Initialize output decorations if necessary
83 initializeDecorations(electrons);
85
86 // If removing calo-muons that overlap with electrons,
87 // then we need to do it in a separate loop first.
89
90 // Loop over electrons
91 for(const auto electron : electrons){
92 if(!isSurvivingObject(electron)) continue;
93
94 // Get the original ID track
95 auto elTrk = getOriginalTrackParticle(electron);
96
97 // Loop over input calo muons
98 for(const auto muon : muons) {
99 if(!isSurvivingObject(muon)) continue;
100 if(muon(acc.m_muonTypeAcc) != xAOD::Muon::CaloTagged) continue;
101
102 // Get the muon ID track
103 auto muTrk = muon(acc.m_muonTrkAcc);
104 // Flag the calo muon as overlapping if they share the track
105 if(elTrk == muTrk) {
106 ATH_CHECK( handleOverlap(muon, electron) );
107 }
108 }
109 }
110 }
111
112 // Loop over muons
113 for(const auto muon : muons){
114 if(!isSurvivingObject(muon)) continue;
115
116 // Get the muon ID track
117 auto muTrk = muon(acc.m_muonTrkAcc);
118
119 // Loop over electrons
120 for(const auto electron : electrons) {
121 if(!isSurvivingObject(electron)) continue;
122
123 // Get the original ID track
124 auto elTrk = getOriginalTrackParticle(electron);
125
126 // Flag the electron as overlapping if they share the track
127 // or if they are DR matched
128 bool removeEle = (elTrk == muTrk);
129 if( (m_useDRMatching)
130 && (m_dRMatcher->objectsMatch(electron, muon)) ){
131 removeEle = true;
132 }
133 if(removeEle){
134 ATH_CHECK( handleOverlap(electron, muon) );
135 }
136 }
137 }
138 return StatusCode::SUCCESS;
139 }
140
143 {
144 auto& acc = *m_accessors;
145 auto elGsfTrk = electron(acc.m_eleTrackAcc);
146 if (elGsfTrk.size() == 0 || !elGsfTrk[0].has_value())
147 throw std::runtime_error("Electron has no associated track");
148 return elGsfTrk[0].value()(acc.m_gsfOriginalTrackAcc);
149 }
150
151} // namespace ORUtils
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
DataVector adapter that acts like it holds const pointers.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
void initializeDecorations(columnar::Particle1Range container) const
BaseOverlapTool(const std::string &name)
Create proper constructor for Athena.
StatusCode handleOverlap(const columnar::ObjectId< CI1, CM > &testParticle, const columnar::ObjectId< CI2, CM > &refParticle) const
Common helper method to handle an overlap result.
bool isSurvivingObject(columnar::Particle1Id obj) const
StatusCode checkForXAODContainer(columnar::ObjectRange< CI, CM > cont, std::string_view message) const
check whether the container is of the right type
StatusCode internalFindOverlaps(columnar::Particle1Range electrons, columnar::Particle2Range muons) const
Alternate method taking actual container types.
bool m_useDRMatching
Flag to remove electrons in a dR cone of muons (default: false)
EleMuSharedTrkOverlapTool(const std::string &name)
Create proper constructor for Athena.
std::unique_ptr< DeltaRMatcher > m_dRMatcher
Delta-R matcher.
virtual StatusCode findOverlaps(columnar::Particle1Range cont1, columnar::Particle2Range cont2, columnar::EventContextId eventContext) const override
Identify overlaps via shared ID track.
bool m_useRapidity
Calculate delta-R using rapidity.
virtual StatusCode initializeDerived() override
Initialize the tool.
float m_maxDR
Maximum dR between electrons and muons if m_useDRMatching is used.
columnar::ObjectLink< MyTrackDef > getOriginalTrackParticle(columnar::Particle1Id electron) const
bool m_removeCaloMuons
Flag to remove calo-muons overlapping with electrons.
ObjectId< ContainerId::particle1 > Particle1Id
Definition ParticleDef.h:48
ObjectId< ContainerId::eventContext > EventContextId
ObjectRange< ContainerId::particle2 > Particle2Range
Definition ParticleDef.h:53
ObjectRange< ContainerId::particle1 > Particle1Range
Definition ParticleDef.h:47
@ Muon
The object is a muon.
Definition ObjectType.h:48
@ Electron
The object is an electron.
Definition ObjectType.h:46