ATLAS Offline Software
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 
20 using std::string;
21 using namespace xAOD;
22 
23 namespace met {
24 
26  static const SG::AuxElement::ConstAccessor< std::vector<iplink_t > > acc_constitObjLinks("ConstitObjectLinks");
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  };
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 
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
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 }
xAOD::name
name
Definition: TriggerMenuJson_v1.cxx:29
met::METMakerAlg::m_softclname
std::string m_softclname
Definition: METMakerAlg.h:67
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
met::METMakerAlg::m_photonSelIsEMTool
ToolHandle< IAsgPhotonIsEMSelector > m_photonSelIsEMTool
Definition: METMakerAlg.h:90
MissingETBase::UsageHandler::PhysicsObject
@ PhysicsObject
Physics object based.
Definition: MissingETCompositionBase.h:187
MissingETBase::UsageHandler::TruthParticle
@ TruthParticle
Truth particle based.
Definition: MissingETCompositionBase.h:189
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
IAsgPhotonIsEMSelector.h
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
met::METMakerAlg::execute
virtual StatusCode execute() override
Definition: METMakerAlg.cxx:120
Jets
Definition: Jets.py:1
met::METMakerAlg::~METMakerAlg
virtual ~METMakerAlg()
Destructor:
xAOD::Egamma_v1::author
uint16_t author(uint16_t bitmask=EgammaParameters::AuthorALL) const
Get author.
Definition: Egamma_v1.cxx:166
met::METMakerAlg::m_PhotonContainerKey
SG::ReadHandleKey< xAOD::PhotonContainer > m_PhotonContainerKey
Definition: METMakerAlg.h:72
IMETMaker.h
MissingETBase::Source::Signal::LCTopo
@ LCTopo
Indicator for MET contribution from TopoClusters with LCW calibration applied.
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
VP1PartSpect::Gamma
@ Gamma
Definition: VP1PartSpectFlags.h:22
met::METMakerAlg::finalize
virtual StatusCode finalize() override
Definition: METMakerAlg.cxx:113
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
ITauSelectionTool.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MissingETBase::Types::bitmask_t
uint64_t bitmask_t
Type for status word bit mask.
Definition: MissingETBase.h:39
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
ConstDataVector::asDataVector
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
met::METMakerAlg::m_tauSelTool
ToolHandle< TauAnalysisTools::ITauSelectionTool > m_tauSelTool
Definition: METMakerAlg.h:91
met::buildMETSum
StatusCode buildMETSum(const std::string &totalName, xAOD::MissingETContainer *metCont)
Definition: METHelpers.cxx:64
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
IMuonSelectionTool.h
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
IAsgElectronLikelihoodTool.h
METHelpers.h
met
Definition: IMETSignificance.h:24
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
met::METMakerAlg::m_elecSelLHTool
ToolHandle< IAsgElectronLikelihoodTool > m_elecSelLHTool
Definition: METMakerAlg.h:89
met::METMakerAlg::m_softtrkname
std::string m_softtrkname
Definition: METMakerAlg.h:68
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MissingETAuxContainer.h
met::METMakerAlg::m_metKey
SG::WriteHandleKey< xAOD::MissingETContainer > m_metKey
Definition: METMakerAlg.h:79
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
met::METMakerAlg::accept
virtual bool accept(const xAOD::Electron *el)
Definition: METMakerAlg.cxx:286
met::METMakerAlg::m_TauJetContainerKey
SG::ReadHandleKey< xAOD::TauJetContainer > m_TauJetContainerKey
Definition: METMakerAlg.h:73
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
met::METMakerAlg::m_metMapKey
SG::ReadHandleKey< xAOD::MissingETAssociationMap > m_metMapKey
Definition: METMakerAlg.h:80
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
met::METMakerAlg::initialize
virtual StatusCode initialize() override
Athena algorithm's Hooks.
Definition: METMakerAlg.cxx:70
met::METMakerAlg::m_MuonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_MuonContainerKey
Definition: METMakerAlg.h:74
AcceptData.h
AthAlgorithm
Definition: AthAlgorithm.h:47
METMakerAlg.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
met::METMakerAlg::m_CoreMetKey
SG::ReadHandleKey< xAOD::MissingETContainer > m_CoreMetKey
Definition: METMakerAlg.h:77
MissingETBase::UsageHandler::Policy
Policy
Policies on usage checks.
Definition: MissingETCompositionBase.h:182
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
met::METMakerAlg::m_muonSelTool
ToolHandle< CP::IMuonSelectionTool > m_muonSelTool
Definition: METMakerAlg.h:88
MissingETBase::UsageHandler::OnlyTrack
@ OnlyTrack
Track based only.
Definition: MissingETCompositionBase.h:185
ConstDataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::MissingETAssociationHelper
Definition: MissingETAssociationHelper.h:26
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
xAOD::Electron_v1
Definition: Electron_v1.h:34
met::METMakerAlg::m_doTruthLep
bool m_doTruthLep
Definition: METMakerAlg.h:83
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
Muon
struct TBPatternUnitContext Muon
MissingETBase::Source::Signal::Track
@ Track
Indicator for MET contribution from reconstructed charged particle tracks.
xAOD::Photon_v1
Definition: Photon_v1.h:37
Muons
Definition: Muons.py:1
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
met::METMakerAlg::m_JetContainerKey
SG::ReadHandleKey< xAOD::JetContainer > m_JetContainerKey
Definition: METMakerAlg.h:75
xAOD::Egamma_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: Egamma_v1.cxx:65
xAODType::Tau
@ Tau
The object is a tau (jet)
Definition: ObjectType.h:49
xAOD::Egamma_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: Egamma_v1.cxx:70
MissingETAssociationMap.h
met::METMakerAlg::m_ElectronContainerKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_ElectronContainerKey
Definition: METMakerAlg.h:71
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
MissingETAssociationHelper.h
MissingETComposition.h
met::METMakerAlg::m_metmaker
ToolHandle< IMETMaker > m_metmaker
Athena configured tools.
Definition: METMakerAlg.h:86