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
6
7
8
9//
10// includes
11//
12
14
17
21
22//
23// method implementations
24//
25
26namespace CP
27{
28
29 StatusCode MetMakerAlg ::
30 initialize ()
31 {
32 ANA_CHECK (m_makerTool.retrieve());
33 ANA_CHECK (m_metCoreKey.initialize());
34 ANA_CHECK (m_metAssociationKey.initialize());
35
39 }
45
46 // Initialize invisible selections - need to pair each selection with its corresponding handle
47 if (m_invisSelectionKeys.size() != m_invisHandles.size()) {
48 ATH_MSG_ERROR("Number of invisible selections (" << m_invisSelectionKeys.size()
49 << ") doesn't match number of invisible handles (" << m_invisHandles.size() << ")");
50 return StatusCode::FAILURE;
51 }
52 m_invisSelections.clear();
53 m_invisSelections.reserve(m_invisHandles.size());
54 for (size_t i = 0; i < m_invisHandles.size(); ++i) {
55 m_invisSelections.emplace_back(m_invisSelectionKeys[i], this);
57 }
58
61
62 if (!m_systematicsTool.empty())
63 {
64 ANA_CHECK (m_systematicsTool.retrieve());
66 }
67
68 ANA_CHECK (m_systematicsList.initialize());
69
70 return StatusCode::SUCCESS;
71 }
72
73
74
75 StatusCode MetMakerAlg ::
76 execute (const EventContext& ctx)
77 {
79 ANA_CHECK (metcoreHandle.isValid());
80 const xAOD::MissingETContainer* metcore = metcoreHandle.cptr();
81
83 ANA_CHECK (metMapHandle.isValid());
84 const xAOD::MissingETAssociationMap* metMap = metMapHandle.cptr();
85
86 // Helper keeps track of object selection flags for this map
87 xAOD::MissingETAssociationHelper metHelper(metMap);
88
89 for (const auto& sys : m_systematicsList.systematicsVector())
90 {
91 auto met = std::make_unique<xAOD::MissingETContainer> ();
92 auto aux = std::make_unique<xAOD::MissingETAuxContainer> ();
93 met->setStore (aux.get());
94
95 metHelper.resetObjSelectionFlags();
96
98 for (size_t i = 0; i < m_invisHandles.size(); ++i) {
99 const xAOD::IParticleContainer* invisible = nullptr;
100 ATH_CHECK( m_invisHandles.at(i).retrieve(invisible, sys, ctx) );
101 for (const xAOD::IParticle *invisParticle : *invisible) {
102 if (m_invisSelections.at(i).getBool(*invisParticle, sys))
103 invisSelected.push_back(invisParticle);
104 }
105 }
106 if (!invisSelected.empty())
107 ANA_CHECK (m_makerTool->markInvisible (invisSelected.asDataVector(), metHelper, met.get() ) );
108
109 // Lambda helping with calculating the MET terms coming from the leptons
110 // (and photons).
111 auto processParticles =
115 const std::string& term) -> StatusCode {
116 if (!handle) {
117 // The NN MET input vector needs a term for every hard-object type,
118 // so a missing handle is a configuration error on the NN path.
119 if (m_evaluateNNMET) {
120 ANA_MSG_ERROR ("evaluateNNMET requires a container for every "
121 "hard-object type, but the handle for term \""
122 << term << "\" is not configured");
123 return StatusCode::FAILURE;
124 }
125 return StatusCode::SUCCESS;
126 }
127 const xAOD::IParticleContainer* particles = nullptr;
128 ANA_CHECK (handle.retrieve (particles, sys, ctx));
130 for (const xAOD::IParticle *particle : *particles)
131 if (selection.getBool(*particle, sys))
132 selected.push_back(particle);
133 ANA_CHECK (m_makerTool->rebuildMET (term, type, met.get(),
134 selected.asDataVector(), metHelper));
135 return StatusCode::SUCCESS;
136 };
137
138 // Calculate the terms coming from the user's selected objects.
141 ANA_CHECK (processParticles (m_photonsHandle, m_photonsSelection,
143 // a muon overlapping with tau is not removed. So if a true muon passes an (extremely loose) tau ID selection, it is double-counted. # https://its.cern.ch/jira/browse/ATLHMBS-651
145 {
146 ANA_CHECK (processParticles (m_tausHandle, m_tausSelection,
148 }
149 ANA_CHECK (processParticles (m_muonsHandle, m_muonsSelection,
152 {
153 ANA_CHECK (processParticles (m_tausHandle, m_tausSelection,
155 }
156
157
158 const xAOD::JetContainer *jets {nullptr};
159 ANA_CHECK (m_jetsHandle.retrieve (jets, sys, ctx));
160
161 if (m_doTrackMet)
162 {
163 ANA_CHECK (m_makerTool->rebuildTrackMET (m_jetsKey, m_softTermKey, met.get(), jets, metcore, metHelper, m_doJetJVT));
164 } else
165 {
166 ANA_CHECK (m_makerTool->rebuildJetMET (m_jetsKey, m_softTermKey, met.get(), jets, metcore, metHelper, m_doJetJVT));
167 }
168
169 // Optionally run the NN-based MET (e.g. met::METNet). For NN tools,
170 // rebuildJetMET only assembles the network inputs; evaluateNNMET runs the
171 // inference and adds the total term directly. We then decorate met/phi on
172 // every term exactly as MetBuilderAlg would, so the NN path needs no
173 // builder afterwards (a builder sum would clobber the NN Final term).
174 if (m_evaluateNNMET)
175 {
176 ANA_CHECK (m_makerTool->evaluateNNMET (m_finalKey, met.get()));
177 static const SG::Decorator<float> met_met_dec ("met");
178 static const SG::Decorator<float> met_phi_dec ("phi");
179 for (const xAOD::MissingET *metTerm : *met)
180 {
181 if (!metTerm) continue;
182 met_met_dec (*metTerm) = metTerm->met();
183 met_phi_dec (*metTerm) = metTerm->phi();
184 }
185 }
186
187 // Systematics
188 if (!m_systematicsTool.empty())
189 {
190 ANA_CHECK (m_systematicsTool->applySystematicVariation (sys));
191
192 xAOD::MissingET *softTerm = (*met)[m_softTermKey];
193 if (softTerm == nullptr)
194 {
195 ANA_MSG_ERROR ("failed to find MET soft-term \"" << m_softTermKey << "\"");
196 return StatusCode::FAILURE;
197 }
198
199 // Set the seed for reproducibility
200 m_systematicsTool->setRandomSeed(static_cast<int>(1e6 * softTerm->phi()));
201
202 // This returns a `CorrectionCode`, so in principle this could
203 // return an `OutOfValidity` result, but I have no idea what
204 // that would mean or how to handle it, so I'm implicitly
205 // converting it into a `FAILURE` instead.
206 ANA_CHECK (m_systematicsTool->applyCorrection (*softTerm, metHelper));
207 }
208
209 ANA_CHECK (m_metHandle.record (std::move (met), std::move (aux), sys, ctx));
210 }
211
212 return StatusCode::SUCCESS;
213 }
214}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
Handle class for reading from StoreGate.
DataVector adapter that acts like it holds const pointers.
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
Helper class to provide type-safe access to aux data.
Gaudi::Property< bool > m_doTrackMet
whether to use track-met instead of jet-met
SysReadSelectionHandle m_muonsSelection
the selection on the input muons
SysReadHandle< xAOD::IParticleContainer > m_tausHandle
the tau container to use
SysWriteHandle< xAOD::MissingETContainer, xAOD::MissingETAuxContainer > m_metHandle
the met collection we run on
SysReadHandle< xAOD::IParticleContainer > m_electronsHandle
the electron container to use
Definition MetMakerAlg.h:71
SG::ReadHandleKey< xAOD::MissingETAssociationMap > m_metAssociationKey
the name of the MissingETAssociationMap
Definition MetMakerAlg.h:63
Gaudi::Property< std::vector< std::string > > m_invisSelectionKeys
the selection on the invisible container
Gaudi::Property< std::string > m_electronsKey
the key for m_electronsHandle
Definition MetMakerAlg.h:81
Gaudi::Property< std::string > m_photonsKey
the key for m_photonsHandle
Definition MetMakerAlg.h:95
ToolHandle< IMETSystematicsTool > m_systematicsTool
the systematics tool
Definition MetMakerAlg.h:55
Gaudi::Property< std::string > m_softTermKey
the soft term key
SysReadSelectionHandle m_photonsSelection
the selection on the input photons
Definition MetMakerAlg.h:90
std::vector< SysReadSelectionHandle > m_invisSelections
ToolHandle< IMETMaker > m_makerTool
the maker tool
Definition MetMakerAlg.h:51
SysHandleArray< SysReadHandle< xAOD::IParticleContainer > > m_invisHandles
the container to be marked as invisible particles
Gaudi::Property< std::string > m_tausKey
the key for m_tausHandle
Gaudi::Property< std::string > m_finalKey
the name of the total MET term written by evaluateNNMET
Gaudi::Property< std::string > m_jetsKey
the key for m_jetsHandle
SysReadHandle< xAOD::IParticleContainer > m_photonsHandle
the photon container to use
Definition MetMakerAlg.h:85
Gaudi::Property< bool > m_doJetJVT
whether to do jet JVT
SysReadHandle< xAOD::IParticleContainer > m_muonsHandle
the muon container to use
Definition MetMakerAlg.h:99
SysReadSelectionHandle m_tausSelection
the selection on the input taus
Gaudi::Property< bool > m_switchTauMuonOrder
whether to switch order of taus and muons
SG::ReadHandleKey< xAOD::MissingETContainer > m_metCoreKey
the name of the core MissingETContainer
Definition MetMakerAlg.h:59
Gaudi::Property< bool > m_evaluateNNMET
whether to run NN-based MET inference (evaluateNNMET) after rebuildJetMET
SysReadSelectionHandle m_electronsSelection
the selection on the input electrons
Definition MetMakerAlg.h:76
SysReadHandle< xAOD::JetContainer > m_jetsHandle
the input jet collection we run on
Gaudi::Property< std::string > m_muonsKey
the key for m_muonsHandle
SysListHandle m_systematicsList
the systematics list we run
Definition MetMakerAlg.h:67
a data handle for reading systematics varied input data
a data handle for reading systematically varied selection properties from objects
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.
void handle(const Incident &inc)
receive the given incident
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Class providing the definition of the 4-vector interface.
float phi() const
Returns .
const std::string selection
Select isolated Photons, Electrons and Muons.
static const SG::Decorator< float > met_phi_dec("phi")
static const SG::Decorator< float > met_met_dec("met")
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
Definition AuxElement.h:576
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition ObjectType.h:32
@ 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
MissingET_v1 MissingET
Version control by type defintion.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
MissingETAssociationMap_v1 MissingETAssociationMap
Version control by type defintion.
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.