ATLAS Offline Software
Loading...
Searching...
No Matches
METMakerAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "METMakerAlg.h"
8
13
14#include "PATCore/AcceptData.h"
15
16using std::string;
17using namespace xAOD;
18
19namespace met {
20
21 //**********************************************************************
22
23 //**********************************************************************
24
25 METMakerAlg::~METMakerAlg() = default;
26
27 //**********************************************************************
28
30 ATH_MSG_INFO("Initializing " << name() << "...");
31 ATH_MSG_INFO("Retrieving tools...");
32
33 // retrieve tools
34 if( m_metmaker.retrieve().isFailure() ) {
35 ATH_MSG_ERROR("Failed to retrieve tool: " << m_metmaker->name());
36 return StatusCode::FAILURE;
37 };
38
39 if( m_muonSelTool.retrieve().isFailure() ) {
40 ATH_MSG_ERROR("Failed to retrieve tool: " << m_muonSelTool->name());
41 return StatusCode::FAILURE;
42 };
43
44 if( m_elecSelLHTool.retrieve().isFailure() ) {
45 ATH_MSG_ERROR("Failed to retrieve tool: " << m_elecSelLHTool->name());
46 return StatusCode::FAILURE;
47 };
48
49 if( m_photonSelIsEMTool.retrieve().isFailure() ) {
50 ATH_MSG_ERROR("Failed to retrieve tool: " << m_photonSelIsEMTool->name());
51 return StatusCode::FAILURE;
52 };
53
54 if( m_tauSelTool.retrieve().isFailure() ) {
55 ATH_MSG_ERROR("Failed to retrieve tool: " << m_tauSelTool->name());
56 return StatusCode::FAILURE;
57 };
58 ATH_CHECK( m_ElectronContainerKey.initialize() );
59 ATH_CHECK( m_PhotonContainerKey.initialize() );
60 ATH_CHECK( m_TauJetContainerKey.initialize() );
61 ATH_CHECK( m_MuonContainerKey.initialize() );
62 ATH_CHECK( m_JetContainerKey.initialize() );
63 ATH_CHECK( m_CoreMetKey.initialize() );
64 ATH_CHECK( m_metKey.initialize() );
65 ATH_CHECK( m_metMapKey.initialize() );
66
67 return StatusCode::SUCCESS;
68 }
69
70 //**********************************************************************
71
72 StatusCode METMakerAlg::finalize() {
73 ATH_MSG_INFO ("Finalizing " << name() << "...");
74 return StatusCode::SUCCESS;
75 }
76
77 //**********************************************************************
78
79 StatusCode METMakerAlg::execute(const EventContext& ctx) const {
80 ATH_MSG_VERBOSE("Executing " << name() << "...");
81
82 // Create a MissingETContainer with its aux store
83 auto metHandle= SG::makeHandle (m_metKey,ctx);
84 ATH_CHECK( metHandle.record (std::make_unique<xAOD::MissingETContainer>(),
85 std::make_unique<xAOD::MissingETAuxContainer>()) );
86 xAOD::MissingETContainer* newMet=metHandle.ptr();
87
89 if (!metMap.isValid()) {
90 ATH_MSG_WARNING("Unable to retrieve MissingETAssociationMap: " << m_metMapKey.key());
91 return StatusCode::FAILURE;
92 }
93
94 MissingETAssociationHelper metHelper(&(*metMap));
95 // Retrieve containers ***********************************************
96
99 if (!coreMet.isValid()) {
100 ATH_MSG_WARNING("Unable to retrieve MissingETContainer: " << m_CoreMetKey.key());
101 return StatusCode::FAILURE;
102 }
103
104
107 if (!Jets.isValid()) {
108 ATH_MSG_WARNING("Unable to retrieve JetContainer: " << Jets.key());
109 return StatusCode::FAILURE;
110 }
111
114 if (!Electrons.isValid()) {
115 ATH_MSG_WARNING("Unable to retrieve ElectronContainer: " << Electrons.key());
116 return StatusCode::FAILURE;
117 }
118
121 if (!Gamma.isValid()) {
122 ATH_MSG_WARNING("Unable to retrieve GammaContainer: " << Gamma.key());
123 return StatusCode::FAILURE;
124 }
125
128 if (!TauJets.isValid()) {
129 ATH_MSG_WARNING("Unable to retrieve TauJetContainer: " << TauJets.key());
130 return StatusCode::FAILURE;
131 }
132
135 if (!Muons.isValid()) {
136 ATH_MSG_WARNING("Unable to retrieve MuonContainer: " << Muons.key());
137 return StatusCode::FAILURE;
138 }
139
140 // Select and flag objects for final MET building ***************************
141
144 // Electrons
145 if(!m_ElectronContainerKey.empty()) {
147 for(const auto *const el : *Electrons) {
148 if(accept(el)) {
149 metElectrons.push_back(el);
150
151 }
152 }
153 if( m_metmaker->rebuildMET("RefEle", xAOD::Type::Electron, newMet,
154 metElectrons.asDataVector(),
155 metHelper, objScale).isFailure() ) {
156 ATH_MSG_WARNING("Failed to build electron term.");
157 }
158 ATH_MSG_DEBUG("Selected " << metElectrons.size() << " MET electrons. "
159 << getMETElements(*(*newMet)["RefEle"]).size() << " are non-overlapping.");
160 }
161
162 // Photons
163 if(!m_PhotonContainerKey.empty()) {
165 for(const auto *const ph : *Gamma) {
166 if(accept(ph)) {
167 metPhotons.push_back(ph);
168 }
169 }
170 if( m_metmaker->rebuildMET("RefGamma", xAOD::Type::Photon, newMet,
171 metPhotons.asDataVector(),
172 metHelper, objScale).isFailure() ) {
173 ATH_MSG_WARNING("Failed to build photon term.");
174 }
175 ATH_MSG_DEBUG("Selected " << metPhotons.size() << " MET photons. "
176 << getMETElements(*(*newMet)["RefGamma"]).size() << " are non-overlapping.");
177 }
178
179 // Taus
180 if(!m_TauJetContainerKey.empty()) {
182 for(const auto *const tau : *TauJets) {
183 if(accept(tau)) {
184 metTaus.push_back(tau);
185 }
186 }
187 if( m_metmaker->rebuildMET("RefTau", xAOD::Type::Tau, newMet,
188 metTaus.asDataVector(),
189 metHelper, objScale).isFailure() ){
190 ATH_MSG_WARNING("Failed to build tau term.");
191 }
192 ATH_MSG_DEBUG("Selected " << metTaus.size() << " MET taus. "
193 << getMETElements(*(*newMet)["RefTau"]).size() << " are non-overlapping.");
194 }
195
196 // Muons
197 if(!m_MuonContainerKey.empty()) {
199 for(const auto *const mu : *Muons) {
200 if(accept(mu)) {
201 metMuons.push_back(mu);
202 }
203 }
204
206 if( m_metmaker->rebuildMET("Muons", xAOD::Type::Muon, newMet,
207 metMuons.asDataVector(),
208 metHelper, objScale).isFailure() ) {
209 ATH_MSG_WARNING("Failed to build muon term.");
210 }
211 ATH_MSG_DEBUG("Selected " << metMuons.size() << " MET muons. "
212 << getMETElements(*(*newMet)["Muons"]).size() << " are non-overlapping.");
213 }
214
215 if( m_metmaker->rebuildJetMET("RefJet", m_softclname, m_softtrkname, newMet,
216 Jets.cptr(), coreMet.cptr(), metHelper, false ).isFailure() ) {
217 ATH_MSG_WARNING("Failed to build jet and soft terms.");
218 }
219 ATH_MSG_DEBUG("Of " << Jets.cptr()->size() << " jets, "
220 << getMETElements(*(*newMet)["RefJet"]).size() << " are non-overlapping, "
221 << getMETElements(*(*newMet)[m_softtrkname]).size() << " are soft");
222
223 auto jets_and_weights = getMETElementsWeights<xAOD::Jet>(*(*newMet)["RefJet"]);
224 for (const auto& [jet, weight] : jets_and_weights) {
225 ATH_MSG_VERBOSE(" Jet " << jet->index() << " with pt " << jet->pt()
226 << " contributes with weight " <<weight
227 );
228 }
229
230
232 if((*newMet)[m_softtrkname]) trksource = (*newMet)[m_softtrkname]->source();
233 if( buildMETSum("FinalTrk", newMet, trksource).isFailure() ){
234 ATH_MSG_WARNING("Building MET FinalTrk sum failed.");
235 }
237 if((*newMet)[m_softclname]) clsource = (*newMet)[m_softclname]->source();
238 if( buildMETSum("FinalClus", newMet, clsource).isFailure() ) {
239 ATH_MSG_WARNING("Building MET FinalClus sum failed.");
240 }
241
242 return StatusCode::SUCCESS;
243 }
244
245 //**********************************************************************
246
247 bool METMakerAlg::accept(const xAOD::Muon* mu) const
248 {
249 if( mu->pt()<2.5e3 || mu->pt()/cosh(mu->eta())<4e3 ) return false;
250 return static_cast<bool>(m_muonSelTool->accept(*mu));
251 }
252
254 {
255 if( fabs(el->eta())>2.47 || el->pt()<10e3 ) return false;
256 return static_cast<bool> (m_elecSelLHTool->accept(el));
257 }
258
259 bool METMakerAlg::accept(const xAOD::Photon* ph) const
260 {
261 if( !(ph->author()&20) || fabs(ph->eta())>2.47 || ph->pt()<10e3 ) return false;
262 return static_cast<bool> (m_photonSelIsEMTool->accept(ph));
263 }
264
265 bool METMakerAlg::accept(const xAOD::TauJet* tau) const
266 {
267 return static_cast<bool>(m_tauSelTool->accept( *tau ));
268 }
269
270}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
size_t size() const
Number of registered mappings.
DataVector adapter that acts like it holds const pointers.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
virtual ~METMakerAlg()
Destructor:
virtual bool accept(const xAOD::Electron *el) const
SG::ReadHandleKey< xAOD::TauJetContainer > m_TauJetContainerKey
Definition METMakerAlg.h:69
Gaudi::Property< bool > m_doTruthLep
Definition METMakerAlg.h:79
SG::WriteHandleKey< xAOD::MissingETContainer > m_metKey
Definition METMakerAlg.h:75
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< xAOD::MuonContainer > m_MuonContainerKey
Definition METMakerAlg.h:70
Gaudi::Property< std::string > m_softclname
Definition METMakerAlg.h:64
virtual StatusCode initialize() override
Athena algorithm's Hooks.
Gaudi::Property< std::string > m_softtrkname
Definition METMakerAlg.h:65
ToolHandle< IMETMaker > m_metmaker
Athena configured tools.
Definition METMakerAlg.h:82
ToolHandle< CP::IMuonSelectionTool > m_muonSelTool
Definition METMakerAlg.h:84
SG::ReadHandleKey< xAOD::MissingETAssociationMap > m_metMapKey
Definition METMakerAlg.h:76
ToolHandle< IAsgPhotonIsEMSelector > m_photonSelIsEMTool
Definition METMakerAlg.h:86
SG::ReadHandleKey< xAOD::PhotonContainer > m_PhotonContainerKey
Definition METMakerAlg.h:68
SG::ReadHandleKey< xAOD::JetContainer > m_JetContainerKey
Definition METMakerAlg.h:71
ToolHandle< IAsgElectronLikelihoodTool > m_elecSelLHTool
Definition METMakerAlg.h:85
ToolHandle< TauAnalysisTools::ITauSelectionTool > m_tauSelTool
Definition METMakerAlg.h:87
virtual StatusCode finalize() override
SG::ReadHandleKey< xAOD::ElectronContainer > m_ElectronContainerKey
Definition METMakerAlg.h:67
SG::ReadHandleKey< xAOD::MissingETContainer > m_CoreMetKey
Definition METMakerAlg.h:73
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition Egamma_v1.cxx:66
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition Egamma_v1.cxx:71
uint16_t author(uint16_t bitmask=EgammaParameters::AuthorALL) const
Get author.
Definition Jets.py:1
uint64_t bitmask_t
Type for status word bit mask.
Definition Muons.py:1
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
template std::vector< std::pair< const xAOD::Jet *, float > > getMETElementsWeights< xAOD::Jet >(const xAOD::MissingET &met)
StatusCode buildMETSum(const std::string &totalName, xAOD::MissingETContainer *metCont)
std::vector< const T * > getMETElements(const xAOD::MissingET &met)
@ Photon
The object is a photon.
Definition ObjectType.h:47
@ Muon
The object is a muon.
Definition ObjectType.h:48
@ Electron
The object is an electron.
Definition ObjectType.h:46
@ Tau
The object is a tau (jet).
Definition ObjectType.h:49
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
TauJet_v3 TauJet
Definition of the current "tau version".
Definition TauJet.h:17
Muon_v1 Muon
Reference the current persistent version:
Photon_v1 Photon
Definition of the current "egamma version".
Electron_v1 Electron
Definition of the current "egamma version".
@ LCTopo
Indicator for MET contribution from TopoClusters with LCW calibration applied.
@ Track
Indicator for MET contribution from reconstructed charged particle tracks.