ATLAS Offline Software
PFMLNeutralFlowElementCreatorAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "xAODCore/ShallowCopy.h"
8 
10 {
11 
14 
15  return StatusCode::SUCCESS;
16 }
17 
19 {
20 
21  ATH_MSG_DEBUG("Executing");
22 
23  /* Create Neutral PFOs from all eflowCaloObjects */
25 
26  std::pair<xAOD::FlowElementContainer *, xAOD::ShallowAuxContainer *> shallowCopyPair = xAOD::shallowCopyContainer(*neutralFEContainerReadHandle);
27  std::unique_ptr<xAOD::FlowElementContainer> neutralFEMLContainer{shallowCopyPair.first};
28  std::unique_ptr<xAOD::ShallowAuxContainer> neutralFEMLContainerAux{shallowCopyPair.second};
30  ATH_CHECK(neutralFEMLContainerWriteHandle.record(std::move(neutralFEMLContainer), std::move(neutralFEMLContainerAux)));
31 
32  for (unsigned int counter = 0; counter < (*neutralFEContainerReadHandle).size(); counter++)
33  {
34  const xAOD::FlowElement *thisFE = (*neutralFEContainerReadHandle)[counter];
35  xAOD::FlowElement *theCopiedFE = (*neutralFEMLContainerWriteHandle)[counter];
36 
37  const ElementLink<xAOD::IParticleContainer> clusterLink = getClusterLink(*thisFE);
38  // Correction is applied only if a valid cluster link exists
39  if (clusterLink.isValid())
40  {
41  const xAOD::CaloCluster *cls = static_cast<const xAOD::CaloCluster *>(*clusterLink); // Safe cast since we checked the type in getClusterLink
43  }
44  }
45 
46  return StatusCode::SUCCESS;
47 }
48 
50 {
51  // Scale factor is defined as the ratio of the cluster energy in the alternative
52  // calibration state (ALTCALIBRATED) to the energy in the EM calibration
53  // state (UNCALIBRATED). This scale factor is then applied to the PFO energy.
54  // If the EM energy is zero, no scaling is applied.
55  const double clusterEMEnergy = cls.rawE();
56  const double clusterAltEnergy = cls.altE();
57  const double scaleFactor = clusterEMEnergy != 0 ? clusterAltEnergy / clusterEMEnergy : 1.0;
58 
59  pfo.setP4(pfo.pt() * scaleFactor, pfo.eta(), pfo.phi(), pfo.m() * scaleFactor);
60 }
61 
63 {
64  // Returns xAOD::Type::CaloCluster type link. There should be at most one such link.
65  // It can happen that no such link exists. This can happen due to negative cells subtraction.
66  // Empty link is returned if no valid cluster link is found.
67  const std::vector<ElementLink<xAOD::IParticleContainer>> &otherObjectLinks = pfo.otherObjectLinks();
68  if (otherObjectLinks.size() > 1)
69  ATH_MSG_ERROR("Multiple links found for neutral FlowElement with index " << pfo.index());
70 
71  bool hasValidLink = !otherObjectLinks.empty() && otherObjectLinks[0].isValid();
72  if (hasValidLink)
73  {
74  if ((**otherObjectLinks[0]).type() != xAOD::Type::CaloCluster)
75  ATH_MSG_ERROR("Link for neutral FlowElement with index " << pfo.index() << " is not of type CaloCluster");
76  return otherObjectLinks[0];
77  }
78  else
80 }
ShallowCopy.h
xAOD::FlowElement_v1::m
virtual double m() const override
The invariant mass of the particle.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
PFMLNeutralFlowElementCreatorAlgorithm::scaleEnergyToAlternativeSignalState
void scaleEnergyToAlternativeSignalState(xAOD::FlowElement &pfo, const xAOD::CaloCluster &cls) const
Definition: PFMLNeutralFlowElementCreatorAlgorithm.cxx:49
PFMLNeutralFlowElementCreatorAlgorithm.h
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
xAOD::FlowElement_v1::otherObjectLinks
const std::vector< ElementLink< IParticleContainer > > & otherObjectLinks() const
xAOD::FlowElement_v1::phi
virtual double phi() const override
The azimuthal angle ( ) of the particle.
xAOD::FlowElement_v1::pt
virtual double pt() const override
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
PFMLNeutralFlowElementCreatorAlgorithm::m_neutralFEMLContainerWriteHandleKey
SG::WriteHandleKey< xAOD::FlowElementContainer > m_neutralFEMLContainerWriteHandleKey
WriteHandleKey for neutral FE.
Definition: PFMLNeutralFlowElementCreatorAlgorithm.h:45
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
PFMLNeutralFlowElementCreatorAlgorithm::execute
StatusCode execute(const EventContext &ctx) const
Definition: PFMLNeutralFlowElementCreatorAlgorithm.cxx:18
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
xAOD::FlowElement_v1::eta
virtual double eta() const override
The pseudorapidity ( ) of the particle.
PFMLNeutralFlowElementCreatorAlgorithm::m_neutralFEContainerReadHandleKey
SG::ReadHandleKey< xAOD::FlowElementContainer > m_neutralFEContainerReadHandleKey
ReadHandleKey for eflowCaloObjectContainer.
Definition: PFMLNeutralFlowElementCreatorAlgorithm.h:42
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
PFMLNeutralFlowElementCreatorAlgorithm::initialize
StatusCode initialize()
Definition: PFMLNeutralFlowElementCreatorAlgorithm.cxx:9
CaloClusterContainer.h
xAOD::FlowElement_v1::setP4
void setP4(float pt, float eta, float phi, float m)
Definition: FlowElement_v1.cxx:39
PFMLNeutralFlowElementCreatorAlgorithm::getClusterLink
ElementLink< xAOD::IParticleContainer > getClusterLink(const xAOD::FlowElement &pfo) const
Definition: PFMLNeutralFlowElementCreatorAlgorithm.cxx:62
test_pyathena.counter
counter
Definition: test_pyathena.py:15
xAOD::FlowElement_v1
A detector object made of other lower level object(s)
Definition: FlowElement_v1.h:25