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
17#include "PATCore/AcceptData.h"
19
20using std::string;
21using namespace xAOD;
22
23namespace met {
24
25 //**********************************************************************
26
27 METMakerAlg::METMakerAlg(const std::string& name,
28 ISvcLocator* pSvcLocator )
29 : ::AthReentrantAlgorithm( name, pSvcLocator ),
30 m_metKey(""),
31 m_metmaker(this),
32 m_muonSelTool(this,""),
33 m_elecSelLHTool(this,""),
34 m_photonSelIsEMTool(this,""),
35 m_tauSelTool(this,"")
36
37 {
38 declareProperty( "Maker", m_metmaker );
39 declareProperty( "METCoreName", m_CoreMetKey = "MET_Core" );
40 declareProperty("METName", m_metKey = std::string("MET_Reference"),"MET container");
41 declareProperty("METMapName", m_metMapKey = "METAssoc" );
42
43 declareProperty( "METSoftClName", m_softclname = "SoftClus" );
44 declareProperty( "METSoftTrkName", m_softtrkname = "PVSoftTrk" );
45
46 declareProperty( "InputJets", m_JetContainerKey = "AntiKt4LCTopoJets" );
47 declareProperty( "InputElectrons", m_ElectronContainerKey = "Electrons" );
48 declareProperty( "InputPhotons", m_PhotonContainerKey = "Photons" );
49 declareProperty( "InputTaus", m_TauJetContainerKey = "TauJets" );
50 declareProperty( "InputMuons", m_MuonContainerKey = "Muons" );
51
52 declareProperty( "MuonSelectionTool", m_muonSelTool );
53 declareProperty( "ElectronLHSelectionTool", m_elecSelLHTool );
54 declareProperty( "PhotonIsEMSelectionTool" , m_photonSelIsEMTool );
55 declareProperty( "TauSelectionTool", m_tauSelTool );
56
57 declareProperty( "DoTruthLeptons", m_doTruthLep = false );
58
59 }
60
61 //**********************************************************************
62
63 METMakerAlg::~METMakerAlg() = default;
64
65 //**********************************************************************
66
68 ATH_MSG_INFO("Initializing " << name() << "...");
69 ATH_MSG_INFO("Retrieving tools...");
70
71 // retrieve tools
72 if( m_metmaker.retrieve().isFailure() ) {
73 ATH_MSG_ERROR("Failed to retrieve tool: " << m_metmaker->name());
74 return StatusCode::FAILURE;
75 };
76
77 if( m_muonSelTool.retrieve().isFailure() ) {
78 ATH_MSG_ERROR("Failed to retrieve tool: " << m_muonSelTool->name());
79 return StatusCode::FAILURE;
80 };
81
82 if( m_elecSelLHTool.retrieve().isFailure() ) {
83 ATH_MSG_ERROR("Failed to retrieve tool: " << m_elecSelLHTool->name());
84 return StatusCode::FAILURE;
85 };
86
87 if( m_photonSelIsEMTool.retrieve().isFailure() ) {
88 ATH_MSG_ERROR("Failed to retrieve tool: " << m_photonSelIsEMTool->name());
89 return StatusCode::FAILURE;
90 };
91
92 if( m_tauSelTool.retrieve().isFailure() ) {
93 ATH_MSG_ERROR("Failed to retrieve tool: " << m_tauSelTool->name());
94 return StatusCode::FAILURE;
95 };
96 ATH_CHECK( m_ElectronContainerKey.initialize() );
97 ATH_CHECK( m_PhotonContainerKey.initialize() );
98 ATH_CHECK( m_TauJetContainerKey.initialize() );
99 ATH_CHECK( m_MuonContainerKey.initialize() );
100 ATH_CHECK( m_JetContainerKey.initialize() );
101 ATH_CHECK( m_CoreMetKey.initialize() );
102 ATH_CHECK( m_metKey.initialize() );
103 ATH_CHECK( m_metMapKey.initialize() );
104
105 return StatusCode::SUCCESS;
106 }
107
108 //**********************************************************************
109
111 ATH_MSG_INFO ("Finalizing " << name() << "...");
112 return StatusCode::SUCCESS;
113 }
114
115 //**********************************************************************
116
117 StatusCode METMakerAlg::execute(const EventContext& ctx) const {
118 ATH_MSG_VERBOSE("Executing " << name() << "...");
119
120 // Create a MissingETContainer with its aux store
121 auto metHandle= SG::makeHandle (m_metKey,ctx);
122 ATH_CHECK( metHandle.record (std::make_unique<xAOD::MissingETContainer>(),
123 std::make_unique<xAOD::MissingETAuxContainer>()) );
124 xAOD::MissingETContainer* newMet=metHandle.ptr();
125
127 if (!metMap.isValid()) {
128 ATH_MSG_WARNING("Unable to retrieve MissingETAssociationMap: " << m_metMapKey.key());
129 return StatusCode::FAILURE;
130 }
131
132 MissingETAssociationHelper metHelper(&(*metMap));
133 // Retrieve containers ***********************************************
134
137 if (!coreMet.isValid()) {
138 ATH_MSG_WARNING("Unable to retrieve MissingETContainer: " << m_CoreMetKey.key());
139 return StatusCode::FAILURE;
140 }
141
142
145 if (!Jets.isValid()) {
146 ATH_MSG_WARNING("Unable to retrieve JetContainer: " << Jets.key());
147 return StatusCode::FAILURE;
148 }
149
152 if (!Electrons.isValid()) {
153 ATH_MSG_WARNING("Unable to retrieve ElectronContainer: " << Electrons.key());
154 return StatusCode::FAILURE;
155 }
156
159 if (!Gamma.isValid()) {
160 ATH_MSG_WARNING("Unable to retrieve GammaContainer: " << Gamma.key());
161 return StatusCode::FAILURE;
162 }
163
166 if (!TauJets.isValid()) {
167 ATH_MSG_WARNING("Unable to retrieve TauJetContainer: " << TauJets.key());
168 return StatusCode::FAILURE;
169 }
170
173 if (!Muons.isValid()) {
174 ATH_MSG_WARNING("Unable to retrieve MuonContainer: " << Muons.key());
175 return StatusCode::FAILURE;
176 }
177
178 // Select and flag objects for final MET building ***************************
179
182 // Electrons
183 if(!m_ElectronContainerKey.empty()) {
185 for(const auto *const el : *Electrons) {
186 if(accept(el)) {
187 metElectrons.push_back(el);
188
189 }
190 }
191 if( m_metmaker->rebuildMET("RefEle", xAOD::Type::Electron, newMet,
192 metElectrons.asDataVector(),
193 metHelper, objScale).isFailure() ) {
194 ATH_MSG_WARNING("Failed to build electron term.");
195 }
196 ATH_MSG_DEBUG("Selected " << metElectrons.size() << " MET electrons. "
197 << getMETElements(*(*newMet)["RefEle"]).size() << " are non-overlapping.");
198 }
199
200 // Photons
201 if(!m_PhotonContainerKey.empty()) {
203 for(const auto *const ph : *Gamma) {
204 if(accept(ph)) {
205 metPhotons.push_back(ph);
206 }
207 }
208 if( m_metmaker->rebuildMET("RefGamma", xAOD::Type::Photon, newMet,
209 metPhotons.asDataVector(),
210 metHelper, objScale).isFailure() ) {
211 ATH_MSG_WARNING("Failed to build photon term.");
212 }
213 ATH_MSG_DEBUG("Selected " << metPhotons.size() << " MET photons. "
214 << getMETElements(*(*newMet)["RefGamma"]).size() << " are non-overlapping.");
215 }
216
217 // Taus
218 if(!m_TauJetContainerKey.empty()) {
220 for(const auto *const tau : *TauJets) {
221 if(accept(tau)) {
222 metTaus.push_back(tau);
223 }
224 }
225 if( m_metmaker->rebuildMET("RefTau", xAOD::Type::Tau, newMet,
226 metTaus.asDataVector(),
227 metHelper, objScale).isFailure() ){
228 ATH_MSG_WARNING("Failed to build tau term.");
229 }
230 ATH_MSG_DEBUG("Selected " << metTaus.size() << " MET taus. "
231 << getMETElements(*(*newMet)["RefTau"]).size() << " are non-overlapping.");
232 }
233
234 // Muons
235 if(!m_MuonContainerKey.empty()) {
237 for(const auto *const mu : *Muons) {
238 if(accept(mu)) {
239 metMuons.push_back(mu);
240 }
241 }
242
244 if( m_metmaker->rebuildMET("Muons", xAOD::Type::Muon, newMet,
245 metMuons.asDataVector(),
246 metHelper, objScale).isFailure() ) {
247 ATH_MSG_WARNING("Failed to build muon term.");
248 }
249 ATH_MSG_DEBUG("Selected " << metMuons.size() << " MET muons. "
250 << getMETElements(*(*newMet)["Muons"]).size() << " are non-overlapping.");
251 }
252
253 if( m_metmaker->rebuildJetMET("RefJet", m_softclname, m_softtrkname, newMet,
254 Jets.cptr(), coreMet.cptr(), metHelper, false ).isFailure() ) {
255 ATH_MSG_WARNING("Failed to build jet and soft terms.");
256 }
257 ATH_MSG_DEBUG("Of " << Jets.cptr()->size() << " jets, "
258 << getMETElements(*(*newMet)["RefJet"]).size() << " are non-overlapping, "
259 << getMETElements(*(*newMet)[m_softtrkname]).size() << " are soft");
260
261 auto jets_and_weights = getMETElementsWeights<xAOD::Jet>(*(*newMet)["RefJet"]);
262 for (const auto& [jet, weight] : jets_and_weights) {
263 ATH_MSG_VERBOSE(" Jet " << jet->index() << " with pt " << jet->pt()
264 << " contributes with weight " <<weight
265 );
266 }
267
268
270 if((*newMet)[m_softtrkname]) trksource = (*newMet)[m_softtrkname]->source();
271 if( buildMETSum("FinalTrk", newMet, trksource).isFailure() ){
272 ATH_MSG_WARNING("Building MET FinalTrk sum failed.");
273 }
275 if((*newMet)[m_softclname]) clsource = (*newMet)[m_softclname]->source();
276 if( buildMETSum("FinalClus", newMet, clsource).isFailure() ) {
277 ATH_MSG_WARNING("Building MET FinalClus sum failed.");
278 }
279
280 return StatusCode::SUCCESS;
281 }
282
283 //**********************************************************************
284
285 bool METMakerAlg::accept(const xAOD::Muon* mu) const
286 {
287 if( mu->pt()<2.5e3 || mu->pt()/cosh(mu->eta())<4e3 ) return false;
288 return static_cast<bool>(m_muonSelTool->accept(*mu));
289 }
290
292 {
293 if( fabs(el->eta())>2.47 || el->pt()<10e3 ) return false;
294 return static_cast<bool> (m_elecSelLHTool->accept(el));
295 }
296
297 bool METMakerAlg::accept(const xAOD::Photon* ph) const
298 {
299 if( !(ph->author()&20) || fabs(ph->eta())>2.47 || ph->pt()<10e3 ) return false;
300 return static_cast<bool> (m_photonSelIsEMTool->accept(ph));
301 }
302
303 bool METMakerAlg::accept(const xAOD::TauJet* tau) const
304 {
305 return static_cast<bool>(m_tauSelTool->accept( *tau ));
306 }
307
308}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
size_t size() const
Number of registered mappings.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
An algorithm that can be simultaneously executed in multiple threads.
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.
std::string m_softclname
Definition METMakerAlg.h:63
virtual ~METMakerAlg()
Destructor:
virtual bool accept(const xAOD::Electron *el) const
SG::ReadHandleKey< xAOD::TauJetContainer > m_TauJetContainerKey
Definition METMakerAlg.h:69
std::string m_softtrkname
Definition METMakerAlg.h:64
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
virtual StatusCode initialize() override
Athena algorithm's Hooks.
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
METMakerAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
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".
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.