ATLAS Offline Software
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 
24 namespace CP
25 {
26 
28  initialize ()
29  {
30  ANA_CHECK (m_makerTool.retrieve());
31 
32  for (auto* handle : {&m_electronsHandle, &m_photonsHandle,
35  }
41  //ANA_CHECK (m_invisSelections.initialize(m_systematicsList, m_invisHandles));
42  // Initialize invisible selections - need to pair each selection with its corresponding handle
43  if (m_invisSelections.size() != m_invisHandles.size()) {
44  ATH_MSG_ERROR("Number of invisible selections (" << m_invisSelections.size()
45  << ") doesn't match number of invisible handles (" << m_invisHandles.size() << ")");
46  return StatusCode::FAILURE;
47  }
48  for (size_t i = 0; i < m_invisHandles.size(); ++i) {
50  }
53 
54  if (!m_systematicsTool.empty())
55  {
56  ANA_CHECK (m_systematicsTool.retrieve());
58  }
59 
61 
62  return StatusCode::SUCCESS;
63  }
64 
65 
66 
68  execute ()
69  {
70  const xAOD::MissingETContainer* metcore {nullptr};
72 
73  const xAOD::MissingETAssociationMap* metMap {nullptr};
75 
76  // Helper keeps track of object selection flags for this map
77  xAOD::MissingETAssociationHelper metHelper(&(*metMap));
78 
79  for (const auto& sys : m_systematicsList.systematicsVector())
80  {
81  auto met = std::make_unique<xAOD::MissingETContainer> ();
82  auto aux = std::make_unique<xAOD::MissingETAuxContainer> ();
83  met->setStore (aux.get());
84 
85  metHelper.resetObjSelectionFlags();
86 
87  for (size_t i = 0; i < m_invisHandles.size(); ++i) {
88  const xAOD::IParticleContainer* invisible = nullptr;
89  ATH_CHECK( m_invisHandles.at(i).retrieve(invisible, sys) );
91  for (const xAOD::IParticle *invisParticle : *invisible)
92  if (m_invisSelections.at(i).getBool(*invisParticle, sys))
93  invisSelected.push_back(invisParticle);
94  ANA_CHECK (m_makerTool->markInvisible (invisSelected.asDataVector(), metHelper, met.get() ) );
95  }
96 
97  // Lambda helping with calculating the MET terms coming from the leptons
98  // (and photons).
99  auto processParticles =
103  const std::string& term) -> StatusCode {
104  if (!handle) {
105  return StatusCode::SUCCESS;
106  }
107  const xAOD::IParticleContainer* particles = nullptr;
108  ANA_CHECK (handle.retrieve (particles, sys));
110  for (const xAOD::IParticle *particle : *particles)
111  if (selection.getBool(*particle, sys))
112  selected.push_back(particle);
113  ANA_CHECK (m_makerTool->rebuildMET (term, type, met.get(),
114  selected.asDataVector(), metHelper));
115  return StatusCode::SUCCESS;
116  };
117 
118  // Calculate the terms coming from the user's selected objects.
121  ANA_CHECK (processParticles (m_photonsHandle, m_photonsSelection,
123  ANA_CHECK (processParticles (m_tausHandle, m_tausSelection,
125  ANA_CHECK (processParticles (m_muonsHandle, m_muonsSelection,
127 
128  const xAOD::JetContainer *jets {nullptr};
130 
131  if (m_doTrackMet)
132  {
133  ANA_CHECK (m_makerTool->rebuildTrackMET (m_jetsKey, m_softTermKey, met.get(), jets, metcore, metHelper, m_doJetJVT));
134  } else
135  {
136  ANA_CHECK (m_makerTool->rebuildJetMET (m_jetsKey, m_softTermKey, met.get(), jets, metcore, metHelper, m_doJetJVT));
137  }
138 
139  // Systematics
140  if (!m_systematicsTool.empty())
141  {
142  ANA_CHECK (m_systematicsTool->applySystematicVariation (sys));
143 
144  xAOD::MissingET *softTerm = (*met)[m_softTermKey];
145  if (softTerm == nullptr)
146  {
147  ANA_MSG_ERROR ("failed to find MET soft-term \"" << m_softTermKey << "\"");
148  return StatusCode::FAILURE;
149  }
150 
151  // Set the seed for reproducibility
152  m_systematicsTool->setRandomSeed(static_cast<int>(1e6 * softTerm->phi()));
153 
154  // This returns a `CorrectionCode`, so in principle this could
155  // return an `OutOfValidity` result, but I have no idea what
156  // that would mean or how to handle it, so I'm implicitly
157  // converting it into a `FAILURE` instead.
158  ANA_CHECK (m_systematicsTool->applyCorrection (*softTerm, metHelper));
159  }
160 
161  ANA_CHECK (m_metHandle.record (std::move (met), std::move (aux), sys));
162  }
163 
164  return StatusCode::SUCCESS;
165  }
166 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:79
CP::MetMakerAlg::m_tausHandle
SysReadHandle< xAOD::IParticleContainer > m_tausHandle
the electron container to use
Definition: MetMakerAlg.h:111
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
CP::MetMakerAlg::m_photonsSelection
SysReadSelectionHandle m_photonsSelection
the selection on the input photons
Definition: MetMakerAlg.h:88
ObjectType
ObjectType
Definition: BaseObject.h:11
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
xAOD::MissingET_v1::phi
float phi() const
Returns .
CP::MetMakerAlg::m_softTermKey
Gaudi::Property< std::string > m_softTermKey
the soft term key
Definition: MetMakerAlg.h:144
CP::MetMakerAlg::m_muonsHandle
SysReadHandle< xAOD::IParticleContainer > m_muonsHandle
the muon container to use
Definition: MetMakerAlg.h:97
MetMakerAlg.h
defineDB.jets
jets
Definition: JetTagCalibration/share/defineDB.py:24
CP::MetMakerAlg::m_electronsHandle
SysReadHandle< xAOD::IParticleContainer > m_electronsHandle
the electron container to use
Definition: MetMakerAlg.h:69
CP::SysListHandle::addSystematics
StatusCode addSystematics(const CP::SystematicSet &recommended, const CP::SystematicSet &affecting)
register a set of affecting variables for the current algorithm (usually obtained from an CP::ISystem...
Definition: SysListHandle.cxx:48
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
CP::SysReadHandle::retrieve
::StatusCode retrieve(const T *&object, const CP::SystematicSet &sys) const
retrieve the object for the given name
CP::SysListHandle::systematicsVector
const std::vector< CP::SystematicSet > & systematicsVector() const
the list of systematics to loop over
Definition: SysListHandle.cxx:96
CP::MetMakerAlg::m_systematicsList
SysListHandle m_systematicsList
the systematics list we run
Definition: MetMakerAlg.h:65
CP::SysReadHandle
a data handle for reading systematics varied input data
Definition: SysReadHandle.h:32
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
CP::MetMakerAlg::m_electronsSelection
SysReadSelectionHandle m_electronsSelection
the selection on the input electrons
Definition: MetMakerAlg.h:74
CP::MetMakerAlg::m_jetsKey
Gaudi::Property< std::string > m_jetsKey
the key for m_jetsHandle
Definition: MetMakerAlg.h:140
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:49
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
xAOD::MissingETAssociationMap_v1
Definition: MissingETAssociationMap_v1.h:29
ConstDataVector::asDataVector
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
CP::MetMakerAlg::m_metAssociationName
Gaudi::Property< std::string > m_metAssociationName
the name of the MissingETAssociationMap
Definition: MetMakerAlg.h:61
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
CP::SysReadHandle::initialize
StatusCode initialize(SysListHandle &sysListHandle)
initialize this handle
met
Definition: IMETSignificance.h:24
CP::MetMakerAlg::m_systematicsTool
ToolHandle< IMETSystematicsTool > m_systematicsTool
the systematics tool
Definition: MetMakerAlg.h:53
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CP::MetMakerAlg::m_metCoreName
Gaudi::Property< std::string > m_metCoreName
the name of the core MissingETContainer
Definition: MetMakerAlg.h:57
CP::MetMakerAlg::m_invisSelections
SysReadSelectionHandleArray m_invisSelections
the selection on the invisible container
Definition: MetMakerAlg.h:135
EL::AnaAlgorithm::handle
void handle(const Incident &inc)
receive the given incident
Definition: AnaAlgorithm.cxx:521
CP::SysListHandle::initialize
::StatusCode initialize()
intialize this property
Definition: SysListHandle.cxx:69
CP::SysReadSelectionHandle::getBool
bool getBool(const SG::AuxElement &element, const CP::SystematicSet &sys) const
get the selection as a bool
lumiFormat.i
int i
Definition: lumiFormat.py:85
CP::MetMakerAlg::m_photonsHandle
SysReadHandle< xAOD::IParticleContainer > m_photonsHandle
the photon container to use
Definition: MetMakerAlg.h:83
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MissingETAuxContainer.h
CP::MetMakerAlg::initialize
StatusCode initialize() override
Definition: MetMakerAlg.cxx:28
CP::MetMakerAlg::m_jetsHandle
SysReadHandle< xAOD::JetContainer > m_jetsHandle
the input jet collection we run on
Definition: MetMakerAlg.h:125
CP::MetMakerAlg::m_metHandle
SysWriteHandle< xAOD::MissingETContainer, xAOD::MissingETAuxContainer > m_metHandle
the met collection we run on
Definition: MetMakerAlg.h:156
xAOD::MissingET_v1
Principal data object for Missing ET.
Definition: MissingET_v1.h:25
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CP::SysHandleArray::size
std::size_t size() const noexcept
The number of defined handles.
CP::MetMakerAlg::m_doTrackMet
Gaudi::Property< bool > m_doTrackMet
whether to use track-met instead of jet-met
Definition: MetMakerAlg.h:148
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
CP::MetMakerAlg::m_tausSelection
SysReadSelectionHandle m_tausSelection
the selection on the input taus
Definition: MetMakerAlg.h:116
CP::MetMakerAlg::m_muonsSelection
SysReadSelectionHandle m_muonsSelection
the selection on the input muons
Definition: MetMakerAlg.h:102
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
selection
const std::string selection
Definition: fbtTestBasics.cxx:75
CP::MetMakerAlg::m_electronsKey
Gaudi::Property< std::string > m_electronsKey
the key for m_electronsHandle
Definition: MetMakerAlg.h:79
ConstDataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::MissingETAssociationHelper
Definition: MissingETAssociationHelper.h:22
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
Muon
struct TBPatternUnitContext Muon
CP::MetMakerAlg::m_muonsKey
Gaudi::Property< std::string > m_muonsKey
the key for m_muonsHandle
Definition: MetMakerAlg.h:107
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
CP::MetMakerAlg::m_doJetJVT
Gaudi::Property< bool > m_doJetJVT
whether to do jet JVT
Definition: MetMakerAlg.h:152
CP::SysReadSelectionHandle::initialize
StatusCode initialize(SysListHandle &sysListHandle, const ISysHandleBase &objectHandle)
initialize the accessor
Definition: SysReadSelectionHandle.cxx:34
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
CP::SysReadSelectionHandle
a data handle for reading systematically varied selection properties from objects
Definition: SysReadSelectionHandle.h:32
xAODType::Tau
@ Tau
The object is a tau (jet)
Definition: ObjectType.h:49
CP::MetMakerAlg::execute
StatusCode execute() override
Definition: MetMakerAlg.cxx:68
CP::SysHandleArray::at
HANDLE & at(std::size_t idx)
Retrieve the handle at the specified index.
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
xAOD::MissingETAssociationHelper::resetObjSelectionFlags
void resetObjSelectionFlags()
Definition: MissingETAssociationHelper.h:40
MissingETAssociationHelper.h
CP::MetMakerAlg::m_invisHandles
SysHandleArray< SysReadHandle< xAOD::IParticleContainer > > m_invisHandles
the container to be marked as invisible particles
Definition: MetMakerAlg.h:130
CP::MetMakerAlg::m_makerTool
ToolHandle< IMETMaker > m_makerTool
the maker tool
Definition: MetMakerAlg.h:49
CP::MetMakerAlg::m_tausKey
Gaudi::Property< std::string > m_tausKey
the key for m_tausHandle
Definition: MetMakerAlg.h:121
CP::MetMakerAlg::m_photonsKey
Gaudi::Property< std::string > m_photonsKey
the key for m_photonsHandle
Definition: MetMakerAlg.h:93