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  }
42 
43  if (!m_systematicsTool.empty())
44  {
45  ANA_CHECK (m_systematicsTool.retrieve());
47  }
48 
50 
51  return StatusCode::SUCCESS;
52  }
53 
54 
55 
57  execute ()
58  {
59  const xAOD::MissingETContainer* metcore {nullptr};
61 
62  const xAOD::MissingETAssociationMap* metMap {nullptr};
64 
65  // Helper keeps track of object selection flags for this map
66  xAOD::MissingETAssociationHelper metHelper(&(*metMap));
67 
68  for (const auto& sys : m_systematicsList.systematicsVector())
69  {
70  auto met = std::make_unique<xAOD::MissingETContainer> ();
71  auto aux = std::make_unique<xAOD::MissingETAuxContainer> ();
72  met->setStore (aux.get());
73 
74  metHelper.resetObjSelectionFlags();
75 
76  if (m_invisHandle) {
77  const xAOD::IParticleContainer* invisible = nullptr;
78  ATH_CHECK( m_invisHandle.retrieve(invisible, sys) );
79  ATH_CHECK( m_makerTool->markInvisible(invisible, metHelper, met.get() ) );
80  }
81 
82  // Lambda helping with calculating the MET terms coming from the leptons
83  // (and photons).
84  auto processParticles =
88  const std::string& term) -> StatusCode {
89  if (!handle) {
90  return StatusCode::SUCCESS;
91  }
92  const xAOD::IParticleContainer* particles = nullptr;
93  ANA_CHECK (handle.retrieve (particles, sys));
95  for (const xAOD::IParticle *particle : *particles)
96  if (selection.getBool(*particle, sys))
97  selected.push_back(particle);
98  ANA_CHECK (m_makerTool->rebuildMET (term, type, met.get(),
99  selected.asDataVector(), metHelper));
100  return StatusCode::SUCCESS;
101  };
102 
103  // Calculate the terms coming from the user's selected objects.
106  ANA_CHECK (processParticles (m_photonsHandle, m_photonsSelection,
108  ANA_CHECK (processParticles (m_tausHandle, m_tausSelection,
110  ANA_CHECK (processParticles (m_muonsHandle, m_muonsSelection,
112 
113  const xAOD::JetContainer *jets {nullptr};
115 
116  if (m_doTrackMet)
117  {
118  ANA_CHECK (m_makerTool->rebuildTrackMET (m_jetsKey, m_softTermKey, met.get(), jets, metcore, metHelper, m_doJetJVT));
119  } else
120  {
121  ANA_CHECK (m_makerTool->rebuildJetMET (m_jetsKey, m_softTermKey, met.get(), jets, metcore, metHelper, m_doJetJVT));
122  }
123 
124  // Systematics
125  if (!m_systematicsTool.empty())
126  {
127  ANA_CHECK (m_systematicsTool->applySystematicVariation (sys));
128 
129  xAOD::MissingET *softTerm = (*met)[m_softTermKey];
130  if (softTerm == nullptr)
131  {
132  ANA_MSG_ERROR ("failed to find MET soft-term \"" << m_softTermKey << "\"");
133  return StatusCode::FAILURE;
134  }
135 
136  // Set the seed for reproducibility
137  m_systematicsTool->setRandomSeed(static_cast<int>(1e6 * softTerm->phi()));
138 
139  // This returns a `CorrectionCode`, so in principle this could
140  // return an `OutOfValidity` result, but I have no idea what
141  // that would mean or how to handle it, so I'm implicitly
142  // converting it into a `FAILURE` instead.
143  ANA_CHECK (m_systematicsTool->applyCorrection (*softTerm, metHelper));
144  }
145 
146  ANA_CHECK (m_metHandle.record (std::move (met), std::move (aux), sys));
147  }
148 
149  return StatusCode::SUCCESS;
150  }
151 }
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:76
CP::MetMakerAlg::m_tausHandle
SysReadHandle< xAOD::IParticleContainer > m_tausHandle
the electron container to use
Definition: MetMakerAlg.h:110
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:87
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:137
CP::MetMakerAlg::m_muonsHandle
SysReadHandle< xAOD::IParticleContainer > m_muonsHandle
the muon container to use
Definition: MetMakerAlg.h:96
MetMakerAlg.h
CP::MetMakerAlg::m_electronsHandle
SysReadHandle< xAOD::IParticleContainer > m_electronsHandle
the electron container to use
Definition: MetMakerAlg.h:68
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:64
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:73
CP::MetMakerAlg::m_jetsKey
Gaudi::Property< std::string > m_jetsKey
the key for m_jetsHandle
Definition: MetMakerAlg.h:133
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
CP::MetMakerAlg::m_invisHandle
SysReadHandle< xAOD::IParticleContainer > m_invisHandle
Definition: MetMakerAlg.h:128
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:60
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:52
CP::MetMakerAlg::m_metCoreName
Gaudi::Property< std::string > m_metCoreName
the name of the core MissingETContainer
Definition: MetMakerAlg.h:56
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::MetMakerAlg::m_photonsHandle
SysReadHandle< xAOD::IParticleContainer > m_photonsHandle
the photon container to use
Definition: MetMakerAlg.h:82
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:124
CP::MetMakerAlg::m_metHandle
SysWriteHandle< xAOD::MissingETContainer, xAOD::MissingETAuxContainer > m_metHandle
the met collection we run on
Definition: MetMakerAlg.h:149
xAOD::MissingET_v1
Principal data object for Missing ET.
Definition: MissingET_v1.h:25
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CP::MetMakerAlg::m_doTrackMet
Gaudi::Property< bool > m_doTrackMet
whether to use track-met instead of jet-met
Definition: MetMakerAlg.h:141
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
CP::MetMakerAlg::m_tausSelection
SysReadSelectionHandle m_tausSelection
the selection on the input taus
Definition: MetMakerAlg.h:115
CP::MetMakerAlg::m_muonsSelection
SysReadSelectionHandle m_muonsSelection
the selection on the input muons
Definition: MetMakerAlg.h:101
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
selection
const std::string selection
Definition: fbtTestBasics.cxx:74
CP::MetMakerAlg::m_electronsKey
Gaudi::Property< std::string > m_electronsKey
the key for m_electronsHandle
Definition: MetMakerAlg.h:78
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
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:106
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
CP::MetMakerAlg::m_doJetJVT
Gaudi::Property< bool > m_doJetJVT
whether to do jet JVT
Definition: MetMakerAlg.h:145
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:57
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
xAOD::MissingETAssociationHelper::resetObjSelectionFlags
void resetObjSelectionFlags()
Definition: MissingETAssociationHelper.h:44
MissingETAssociationHelper.h
CP::MetMakerAlg::m_makerTool
ToolHandle< IMETMaker > m_makerTool
the maker tool
Definition: MetMakerAlg.h:48
CP::MetMakerAlg::m_tausKey
Gaudi::Property< std::string > m_tausKey
the key for m_tausHandle
Definition: MetMakerAlg.h:120
CP::MetMakerAlg::m_photonsKey
Gaudi::Property< std::string > m_photonsKey
the key for m_photonsHandle
Definition: MetMakerAlg.h:92