ATLAS Offline Software
Loading...
Searching...
No Matches
MetMakerAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
9//
10// includes
11//
12
14
17
19
20//
21// method implementations
22//
23
24namespace CP
25{
26
27 StatusCode MetMakerAlg ::
28 initialize ()
29 {
30 ANA_CHECK (m_makerTool.retrieve());
31
35 }
41
42 // Initialize invisible selections - need to pair each selection with its corresponding handle
43 if (m_invisSelectionKeys.size() != m_invisHandles.size()) {
44 ATH_MSG_ERROR("Number of invisible selections (" << m_invisSelectionKeys.size()
45 << ") doesn't match number of invisible handles (" << m_invisHandles.size() << ")");
46 return StatusCode::FAILURE;
47 }
48 m_invisSelections.clear();
49 m_invisSelections.reserve(m_invisHandles.size());
50 for (size_t i = 0; i < m_invisHandles.size(); ++i) {
51 m_invisSelections.emplace_back(m_invisSelectionKeys[i], this);
53 }
54
57
58 if (!m_systematicsTool.empty())
59 {
60 ANA_CHECK (m_systematicsTool.retrieve());
62 }
63
64 ANA_CHECK (m_systematicsList.initialize());
65
66 return StatusCode::SUCCESS;
67 }
68
69
70
71 StatusCode MetMakerAlg ::
72 execute ()
73 {
74 const xAOD::MissingETContainer* metcore {nullptr};
75 ANA_CHECK (evtStore()->retrieve(metcore, m_metCoreName));
76
77 const xAOD::MissingETAssociationMap* metMap {nullptr};
78 ANA_CHECK (evtStore()->retrieve(metMap, m_metAssociationName));
79
80 // Helper keeps track of object selection flags for this map
81 xAOD::MissingETAssociationHelper metHelper(&(*metMap));
82
83 for (const auto& sys : m_systematicsList.systematicsVector())
84 {
85 auto met = std::make_unique<xAOD::MissingETContainer> ();
86 auto aux = std::make_unique<xAOD::MissingETAuxContainer> ();
87 met->setStore (aux.get());
88
89 metHelper.resetObjSelectionFlags();
90
92 for (size_t i = 0; i < m_invisHandles.size(); ++i) {
93 const xAOD::IParticleContainer* invisible = nullptr;
94 ATH_CHECK( m_invisHandles.at(i).retrieve(invisible, sys) );
95 for (const xAOD::IParticle *invisParticle : *invisible) {
96 if (m_invisSelections.at(i).getBool(*invisParticle, sys))
97 invisSelected.push_back(invisParticle);
98 }
99 }
100 if (invisSelected.size() > 0)
101 ANA_CHECK (m_makerTool->markInvisible (invisSelected.asDataVector(), metHelper, met.get() ) );
102
103 // Lambda helping with calculating the MET terms coming from the leptons
104 // (and photons).
105 auto processParticles =
109 const std::string& term) -> StatusCode {
110 if (!handle) {
111 return StatusCode::SUCCESS;
112 }
113 const xAOD::IParticleContainer* particles = nullptr;
114 ANA_CHECK (handle.retrieve (particles, sys));
116 for (const xAOD::IParticle *particle : *particles)
117 if (selection.getBool(*particle, sys))
118 selected.push_back(particle);
119 ANA_CHECK (m_makerTool->rebuildMET (term, type, met.get(),
120 selected.asDataVector(), metHelper));
121 return StatusCode::SUCCESS;
122 };
123
124 // Calculate the terms coming from the user's selected objects.
127 ANA_CHECK (processParticles (m_photonsHandle, m_photonsSelection,
129 ANA_CHECK (processParticles (m_tausHandle, m_tausSelection,
131 ANA_CHECK (processParticles (m_muonsHandle, m_muonsSelection,
133
134 const xAOD::JetContainer *jets {nullptr};
135 ANA_CHECK (m_jetsHandle.retrieve (jets, sys));
136
137 if (m_doTrackMet)
138 {
139 ANA_CHECK (m_makerTool->rebuildTrackMET (m_jetsKey, m_softTermKey, met.get(), jets, metcore, metHelper, m_doJetJVT));
140 } else
141 {
142 ANA_CHECK (m_makerTool->rebuildJetMET (m_jetsKey, m_softTermKey, met.get(), jets, metcore, metHelper, m_doJetJVT));
143 }
144
145 // Systematics
146 if (!m_systematicsTool.empty())
147 {
148 ANA_CHECK (m_systematicsTool->applySystematicVariation (sys));
149
150 xAOD::MissingET *softTerm = (*met)[m_softTermKey];
151 if (softTerm == nullptr)
152 {
153 ANA_MSG_ERROR ("failed to find MET soft-term \"" << m_softTermKey << "\"");
154 return StatusCode::FAILURE;
155 }
156
157 // Set the seed for reproducibility
158 m_systematicsTool->setRandomSeed(static_cast<int>(1e6 * softTerm->phi()));
159
160 // This returns a `CorrectionCode`, so in principle this could
161 // return an `OutOfValidity` result, but I have no idea what
162 // that would mean or how to handle it, so I'm implicitly
163 // converting it into a `FAILURE` instead.
164 ANA_CHECK (m_systematicsTool->applyCorrection (*softTerm, metHelper));
165 }
166
167 ANA_CHECK (m_metHandle.record (std::move (met), std::move (aux), sys));
168 }
169
170 return StatusCode::SUCCESS;
171 }
172}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
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
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 electron 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:69
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:79
Gaudi::Property< std::string > m_photonsKey
the key for m_photonsHandle
Definition MetMakerAlg.h:93
ToolHandle< IMETSystematicsTool > m_systematicsTool
the systematics tool
Definition MetMakerAlg.h:53
Gaudi::Property< std::string > m_softTermKey
the soft term key
SysReadSelectionHandle m_photonsSelection
the selection on the input photons
Definition MetMakerAlg.h:88
std::vector< SysReadSelectionHandle > m_invisSelections
ToolHandle< IMETMaker > m_makerTool
the maker tool
Definition MetMakerAlg.h:49
SysHandleArray< SysReadHandle< xAOD::IParticleContainer > > m_invisHandles
the container to be marked as invisible particles
Gaudi::Property< std::string > m_metCoreName
the name of the core MissingETContainer
Definition MetMakerAlg.h:57
Gaudi::Property< std::string > m_tausKey
the key for m_tausHandle
Gaudi::Property< std::string > m_jetsKey
the key for m_jetsHandle
SysReadHandle< xAOD::IParticleContainer > m_photonsHandle
the photon container to use
Definition MetMakerAlg.h:83
Gaudi::Property< bool > m_doJetJVT
whether to do jet JVT
SysReadHandle< xAOD::IParticleContainer > m_muonsHandle
the muon container to use
Definition MetMakerAlg.h:97
SysReadSelectionHandle m_tausSelection
the selection on the input taus
Gaudi::Property< std::string > m_metAssociationName
the name of the MissingETAssociationMap
Definition MetMakerAlg.h:61
SysReadSelectionHandle m_electronsSelection
the selection on the input electrons
Definition MetMakerAlg.h:74
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:65
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
Class providing the definition of the 4-vector interface.
float phi() const
Returns .
const std::string selection
Select isolated Photons, Electrons and Muons.
@ 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.