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::MuonType::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 bool removeMu = false;
106 if (elTrk.has_value() && muTrk.has_value()) removeMu = (elTrk == muTrk);
107 if (removeMu) {
108 ATH_CHECK( handleOverlap(muon, electron) );
109 }
110 }
111 }
112 }
113
114 // Loop over muons
115 for(const auto muon : muons){
116 if(!isSurvivingObject(muon)) continue;
117
118 // Get the muon ID track
119 auto muTrk = muon(acc.m_muonTrkAcc);
120
121 // Loop over electrons
122 for(const auto electron : electrons) {
123 if(!isSurvivingObject(electron)) continue;
124
125 // Get the original ID track
126 auto elTrk = getOriginalTrackParticle(electron);
127
128 // Flag the electron as overlapping if they share the track
129 // or if they are DR matched
130 bool removeEle = false;
131 if (elTrk.has_value() && muTrk.has_value()) removeEle = (elTrk == muTrk);
132 if( (m_useDRMatching)
133 && (m_dRMatcher->objectsMatch(electron, muon)) ){
134 removeEle = true;
135 }
136 if(removeEle){
137 ATH_CHECK( handleOverlap(electron, muon) );
138 }
139 }
140 }
141 return StatusCode::SUCCESS;
142 }
143
146 {
147 auto& acc = *m_accessors;
148 auto elGsfTrk = electron(acc.m_eleTrackAcc);
149 if (elGsfTrk.size() == 0 || !elGsfTrk[0].has_value())
150 throw std::runtime_error("Electron has no associated track");
151 return elGsfTrk[0].value()(acc.m_gsfOriginalTrackAcc);
152 }
153
154} // 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< Particle1Def > Particle1Id
Definition ParticleDef.h:45
ObjectId< EventContextDef > EventContextId
ObjectRange< Particle2Def > Particle2Range
Definition ParticleDef.h:50
ObjectRange< Particle1Def > Particle1Range
Definition ParticleDef.h:44
@ Muon
The object is a muon.
Definition ObjectType.h:48
@ Electron
The object is an electron.
Definition ObjectType.h:46