ATLAS Offline Software
Loading...
Searching...
No Matches
METMakerAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 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 using iplink_t = ElementLink<xAOD::IParticleContainer>;
27
28 //**********************************************************************
29
30 METMakerAlg::METMakerAlg(const std::string& name,
31 ISvcLocator* pSvcLocator )
32 : ::AthAlgorithm( name, pSvcLocator ),
33 m_metKey(""),
34 m_metmaker(this),
35 m_muonSelTool(this,""),
36 m_elecSelLHTool(this,""),
37 m_photonSelIsEMTool(this,""),
38 m_tauSelTool(this,"")
39
40 {
41 declareProperty( "Maker", m_metmaker );
42 declareProperty( "METCoreName", m_CoreMetKey = "MET_Core" );
43 declareProperty("METName", m_metKey = std::string("MET_Reference"),"MET container");
44 declareProperty("METMapName", m_metMapKey = "METAssoc" );
45
46 declareProperty( "METSoftClName", m_softclname = "SoftClus" );
47 declareProperty( "METSoftTrkName", m_softtrkname = "PVSoftTrk" );
48
49 declareProperty( "InputJets", m_JetContainerKey = "AntiKt4LCTopoJets" );
50 declareProperty( "InputElectrons", m_ElectronContainerKey = "Electrons" );
51 declareProperty( "InputPhotons", m_PhotonContainerKey = "Photons" );
52 declareProperty( "InputTaus", m_TauJetContainerKey = "TauJets" );
53 declareProperty( "InputMuons", m_MuonContainerKey = "Muons" );
54
55 declareProperty( "MuonSelectionTool", m_muonSelTool );
56 declareProperty( "ElectronLHSelectionTool", m_elecSelLHTool );
57 declareProperty( "PhotonIsEMSelectionTool" , m_photonSelIsEMTool );
58 declareProperty( "TauSelectionTool", m_tauSelTool );
59
60 declareProperty( "DoTruthLeptons", m_doTruthLep = false );
61
62 }
63
64 //**********************************************************************
65
66 METMakerAlg::~METMakerAlg() = default;
67
68 //**********************************************************************
69
71 ATH_MSG_INFO("Initializing " << name() << "...");
72 ATH_MSG_INFO("Retrieving tools...");
73
74 // retrieve tools
75 if( m_metmaker.retrieve().isFailure() ) {
76 ATH_MSG_ERROR("Failed to retrieve tool: " << m_metmaker->name());
77 return StatusCode::FAILURE;
78 };
79
80 if( m_muonSelTool.retrieve().isFailure() ) {
81 ATH_MSG_ERROR("Failed to retrieve tool: " << m_muonSelTool->name());
82 return StatusCode::FAILURE;
83 };
84
85 if( m_elecSelLHTool.retrieve().isFailure() ) {
86 ATH_MSG_ERROR("Failed to retrieve tool: " << m_elecSelLHTool->name());
87 return StatusCode::FAILURE;
88 };
89
90 if( m_photonSelIsEMTool.retrieve().isFailure() ) {
91 ATH_MSG_ERROR("Failed to retrieve tool: " << m_photonSelIsEMTool->name());
92 return StatusCode::FAILURE;
93 };
94
95 if( m_tauSelTool.retrieve().isFailure() ) {
96 ATH_MSG_ERROR("Failed to retrieve tool: " << m_tauSelTool->name());
97 return StatusCode::FAILURE;
98 };
99 ATH_CHECK( m_ElectronContainerKey.initialize() );
100 ATH_CHECK( m_PhotonContainerKey.initialize() );
101 ATH_CHECK( m_TauJetContainerKey.initialize() );
102 ATH_CHECK( m_MuonContainerKey.initialize() );
103 ATH_CHECK( m_JetContainerKey.initialize() );
104 ATH_CHECK( m_CoreMetKey.initialize() );
105 ATH_CHECK( m_metKey.initialize() );
106 ATH_CHECK( m_metMapKey.initialize() );
107
108 return StatusCode::SUCCESS;
109 }
110
111 //**********************************************************************
112
114 ATH_MSG_INFO ("Finalizing " << name() << "...");
115 return StatusCode::SUCCESS;
116 }
117
118 //**********************************************************************
119
120 StatusCode METMakerAlg::execute() {
121 ATH_MSG_VERBOSE("Executing " << name() << "...");
122
123 // Create a MissingETContainer with its aux store
124 auto ctx = getContext();
125 auto metHandle= SG::makeHandle (m_metKey,ctx);
126 ATH_CHECK( metHandle.record (std::make_unique<xAOD::MissingETContainer>(), std::make_unique<xAOD::MissingETAuxContainer>()) );
127 xAOD::MissingETContainer* newMet=metHandle.ptr();
128
130 if (!metMap.isValid()) {
131 ATH_MSG_WARNING("Unable to retrieve MissingETAssociationMap: " << m_metMapKey.key());
132 return StatusCode::FAILURE;
133 }
134
135 MissingETAssociationHelper metHelper(&(*metMap));
136 // Retrieve containers ***********************************************
137
140 if (!coreMet.isValid()) {
141 ATH_MSG_WARNING("Unable to retrieve MissingETContainer: " << m_CoreMetKey.key());
142 return StatusCode::FAILURE;
143 }
144
145
148 if (!Jets.isValid()) {
149 ATH_MSG_WARNING("Unable to retrieve JetContainer: " << Jets.key());
150 return StatusCode::FAILURE;
151 }
152
155 if (!Electrons.isValid()) {
156 ATH_MSG_WARNING("Unable to retrieve ElectronContainer: " << Electrons.key());
157 return StatusCode::FAILURE;
158 }
159
162 if (!Gamma.isValid()) {
163 ATH_MSG_WARNING("Unable to retrieve GammaContainer: " << Gamma.key());
164 return StatusCode::FAILURE;
165 }
166
169 if (!TauJets.isValid()) {
170 ATH_MSG_WARNING("Unable to retrieve TauJetContainer: " << TauJets.key());
171 return StatusCode::FAILURE;
172 }
173
176 if (!Muons.isValid()) {
177 ATH_MSG_WARNING("Unable to retrieve MuonContainer: " << Muons.key());
178 return StatusCode::FAILURE;
179 }
180
181 // Select and flag objects for final MET building ***************************
182
185 // Electrons
186 if(!m_ElectronContainerKey.empty()) {
188 for(const auto *const el : *Electrons) {
189 if(accept(el)) {
190 metElectrons.push_back(el);
191
192 }
193 }
194 if( m_metmaker->rebuildMET("RefEle", xAOD::Type::Electron, newMet,
195 metElectrons.asDataVector(),
196 metHelper, objScale).isFailure() ) {
197 ATH_MSG_WARNING("Failed to build electron term.");
198 }
199 ATH_MSG_DEBUG("Selected " << metElectrons.size() << " MET electrons. "
200 << acc_constitObjLinks(*(*newMet)["RefEle"]).size() << " are non-overlapping.");
201 }
202
203 // Photons
204 if(!m_PhotonContainerKey.empty()) {
206 for(const auto *const ph : *Gamma) {
207 if(accept(ph)) {
208 metPhotons.push_back(ph);
209 }
210 }
211 if( m_metmaker->rebuildMET("RefGamma", xAOD::Type::Photon, newMet,
212 metPhotons.asDataVector(),
213 metHelper, objScale).isFailure() ) {
214 ATH_MSG_WARNING("Failed to build photon term.");
215 }
216 ATH_MSG_DEBUG("Selected " << metPhotons.size() << " MET photons. "
217 << acc_constitObjLinks(*(*newMet)["RefGamma"]).size() << " are non-overlapping.");
218 }
219
220 // Taus
221 if(!m_TauJetContainerKey.empty()) {
223 for(const auto *const tau : *TauJets) {
224 if(accept(tau)) {
225 metTaus.push_back(tau);
226 }
227 }
228 if( m_metmaker->rebuildMET("RefTau", xAOD::Type::Tau, newMet,
229 metTaus.asDataVector(),
230 metHelper, objScale).isFailure() ){
231 ATH_MSG_WARNING("Failed to build tau term.");
232 }
233 ATH_MSG_DEBUG("Selected " << metTaus.size() << " MET taus. "
234 << acc_constitObjLinks(*(*newMet)["RefTau"]).size() << " are non-overlapping.");
235 }
236
237 // Muons
238 if(!m_MuonContainerKey.empty()) {
240 for(const auto *const mu : *Muons) {
241 if(accept(mu)) {
242 metMuons.push_back(mu);
243 }
244 }
245
247 if( m_metmaker->rebuildMET("Muons", xAOD::Type::Muon, newMet,
248 metMuons.asDataVector(),
249 metHelper, objScale).isFailure() ) {
250 ATH_MSG_WARNING("Failed to build muon term.");
251 }
252 ATH_MSG_DEBUG("Selected " << metMuons.size() << " MET muons. "
253 << acc_constitObjLinks(*(*newMet)["Muons"]).size() << " are non-overlapping.");
254 }
255
256 if( m_metmaker->rebuildJetMET("RefJet", m_softclname, m_softtrkname, newMet,
257 Jets.cptr(), coreMet.cptr(), metHelper, false ).isFailure() ) {
258 ATH_MSG_WARNING("Failed to build jet and soft terms.");
259 }
260 ATH_MSG_DEBUG("Of " << Jets.cptr()->size() << " jets, "
261 << acc_constitObjLinks(*(*newMet)["RefJet"]).size() << " are non-overlapping, "
262 << acc_constitObjLinks(*(*newMet)[m_softtrkname]).size() << " are soft");
263
265 if((*newMet)[m_softtrkname]) trksource = (*newMet)[m_softtrkname]->source();
266 if( buildMETSum("FinalTrk", newMet, trksource).isFailure() ){
267 ATH_MSG_WARNING("Building MET FinalTrk sum failed.");
268 }
270 if((*newMet)[m_softclname]) clsource = (*newMet)[m_softclname]->source();
271 if( buildMETSum("FinalClus", newMet, clsource).isFailure() ) {
272 ATH_MSG_WARNING("Building MET FinalClus sum failed.");
273 }
274
275 return StatusCode::SUCCESS;
276 }
277
278 //**********************************************************************
279
281 {
282 if( mu->pt()<2.5e3 || mu->pt()/cosh(mu->eta())<4e3 ) return false;
283 return static_cast<bool>(m_muonSelTool->accept(*mu));
284 }
285
287 {
288 if( fabs(el->eta())>2.47 || el->pt()<10e3 ) return false;
289 return static_cast<bool> (m_elecSelLHTool->accept(el));
290 }
291
293 {
294 if( !(ph->author()&20) || fabs(ph->eta())>2.47 || ph->pt()<10e3 ) return false;
295 return static_cast<bool> (m_photonSelIsEMTool->accept(ph));
296 }
297
299 {
300 // std::cout<<"Just checking this works -> tau pt is "<<tau->pt()<<std::endl;
301
302 return static_cast<bool>(m_tauSelTool->accept( *tau ));
303 }
304
305}
#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)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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.
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
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:67
virtual ~METMakerAlg()
Destructor:
SG::ReadHandleKey< xAOD::TauJetContainer > m_TauJetContainerKey
Definition METMakerAlg.h:73
virtual bool accept(const xAOD::Electron *el)
std::string m_softtrkname
Definition METMakerAlg.h:68
SG::WriteHandleKey< xAOD::MissingETContainer > m_metKey
Definition METMakerAlg.h:79
SG::ReadHandleKey< xAOD::MuonContainer > m_MuonContainerKey
Definition METMakerAlg.h:74
virtual StatusCode initialize() override
Athena algorithm's Hooks.
ToolHandle< IMETMaker > m_metmaker
Athena configured tools.
Definition METMakerAlg.h:86
ToolHandle< CP::IMuonSelectionTool > m_muonSelTool
Definition METMakerAlg.h:88
METMakerAlg()
Default constructor:
SG::ReadHandleKey< xAOD::MissingETAssociationMap > m_metMapKey
Definition METMakerAlg.h:80
ToolHandle< IAsgPhotonIsEMSelector > m_photonSelIsEMTool
Definition METMakerAlg.h:90
SG::ReadHandleKey< xAOD::PhotonContainer > m_PhotonContainerKey
Definition METMakerAlg.h:72
virtual StatusCode execute() override
SG::ReadHandleKey< xAOD::JetContainer > m_JetContainerKey
Definition METMakerAlg.h:75
ToolHandle< IAsgElectronLikelihoodTool > m_elecSelLHTool
Definition METMakerAlg.h:89
ToolHandle< TauAnalysisTools::ITauSelectionTool > m_tauSelTool
Definition METMakerAlg.h:91
virtual StatusCode finalize() override
SG::ReadHandleKey< xAOD::ElectronContainer > m_ElectronContainerKey
Definition METMakerAlg.h:71
SG::ReadHandleKey< xAOD::MissingETContainer > m_CoreMetKey
Definition METMakerAlg.h:77
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())
ElementLink< xAOD::IParticleContainer > iplink_t
StatusCode buildMETSum(const std::string &totalName, xAOD::MissingETContainer *metCont)
static const SG::AuxElement::ConstAccessor< std::vector< iplink_t > > acc_constitObjLinks("ConstitObjectLinks")
@ 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.