ATLAS Offline Software
TrigEgammaTLAPhotonHypoAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 #include "AthViews/ViewHelper.h"
11 
12 using namespace TrigCompositeUtils;
13 
15 
16 
17 TrigEgammaTLAPhotonHypoAlg::TrigEgammaTLAPhotonHypoAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
18  :: HypoBase (name, pSvcLocator) {}
19 
20 
22 
23  ATH_CHECK( m_hypoTools.retrieve() );
24  ATH_CHECK( m_TLAPhotonsKey.initialize() );
25 
26  ATH_MSG_DEBUG("Initializing TrigEgammaTLAPhotonHypoAlg");
27  return StatusCode::SUCCESS;
28 
29 }
30 
31 StatusCode TrigEgammaTLAPhotonHypoAlg::execute( const EventContext& ctx) const
32 {
33  ATH_MSG_DEBUG("Executing " << name() << "...");
34 
35  ATH_MSG_DEBUG("Retrieving 'HLT' decision\" " << decisionInput().key() << "\"");
36 
37 
38  // create handles for TLA photons
40  //make the output photon container
41  ATH_CHECK(h_TLAPhotons.record(std::make_unique<xAOD::PhotonContainer>(),
42  std::make_unique<xAOD::PhotonAuxContainer>()));
43 
44 
45  // retrieves the HLT decision container for the TLA photons
46  auto previousDecisionHandle = SG::makeHandle(decisionInput(), ctx);
47  ATH_CHECK(previousDecisionHandle.isValid());
48 
49 
50  // get a pointer to the TLA Photons
51  ATH_MSG_DEBUG("Retrieving photons from the TLA container \"" <<m_TLAPhotonsKey << "\" ");
52 
53 
54  // creates (via SG handle) a DecisionContainer for the output decision
56  DecisionContainer* outputDecisions = outputHandle.ptr();
57 
58  // loops over previous decisions
59  int nDecision = 0;
60  for (const auto previousDecision : *previousDecisionHandle)
61  {
62 
63  // get photons from the decision
64  const xAOD::Photon *photonPrev = nullptr;
65  auto prevPhotons = TrigCompositeUtils::findLinks<xAOD::PhotonContainer>(previousDecision, TrigCompositeUtils::featureString(), TrigDefs::lastFeatureOfType);
66  ATH_MSG_DEBUG("This decision has " << prevPhotons.size() << " photons");
67 
68 
69  if (prevPhotons.size() != 1) {
70  ATH_MSG_ERROR("Did not locate exactly one photon for this Decision Object, found " << prevPhotons.size());
71  return StatusCode::FAILURE;
72  }
73 
74 
75  auto prevPhotonLink = prevPhotons.at(0).link;
76  ATH_CHECK(prevPhotonLink.isValid());
77  photonPrev = *prevPhotonLink;
78 
79  xAOD::Photon *copiedPhoton = new xAOD::Photon();
80  h_TLAPhotons->push_back(copiedPhoton);
81  *copiedPhoton = *photonPrev;
82 
83  // now go on with the normal Hypo, linking new decision with previous one
84  auto newDecision = newDecisionIn( outputDecisions, hypoAlgNodeName() );
85  TrigCompositeUtils::linkToPrevious( newDecision, previousDecision, ctx );
86  // do we need to re-link the feature?
87  newDecision->setObjectLink(featureString(), ElementLink<xAOD::PhotonContainer>(*h_TLAPhotons, h_TLAPhotons->size() - 1, ctx));
88 
89 
90  ATH_MSG_DEBUG("Copied photon with pT: " << copiedPhoton->pt() << " from decision " << nDecision);
91  }
92 
93 
94  for (const auto& tool : m_hypoTools)
95  {
96  ATH_MSG_DEBUG("Now computing decision for HypoTool: " << tool->name());
97  ATH_CHECK(tool->decide(outputDecisions));
98  }
99 
100  ATH_CHECK( hypoBaseOutputProcessing(outputHandle ));
101 
102 
103  return StatusCode::SUCCESS;
104 }
TrigCompositeUtils::newDecisionIn
Decision * newDecisionIn(DecisionContainer *dc, const std::string &name)
Helper method to create a Decision object, place it in the container and return a pointer to it.
Definition: TrigCompositeUtilsRoot.cxx:43
TrigCompositeUtils::hypoAlgNodeName
const std::string & hypoAlgNodeName()
Definition: TrigCompositeUtilsRoot.cxx:918
TrigEgammaTLAPhotonHypoAlg::initialize
virtual StatusCode initialize() override
Definition: TrigEgammaTLAPhotonHypoAlg.cxx:21
HypoBase::decisionInput
const SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > & decisionInput() const
methods for derived classes to access handles of the base class input other read/write handles may be...
Definition: HypoBase.cxx:16
ViewHelper.h
TrigCompositeUtils::createAndStore
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
Definition: TrigCompositeUtilsRoot.cxx:27
HypoBase::decisionOutput
const SG::WriteHandleKey< TrigCompositeUtils::DecisionContainer > & decisionOutput() const
methods for derived classes to access handles of the base class output other read/write handles may b...
Definition: HypoBase.cxx:20
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
TrigCompositeUtils.h
TrigEgammaTLAPhotonHypoAlg.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HypoBase::hypoBaseOutputProcessing
StatusCode hypoBaseOutputProcessing(SG::WriteHandle< TrigCompositeUtils::DecisionContainer > &outputHandle, MSG::Level lvl=MSG::DEBUG) const
Base class function to be called once slice specific code has finished. Handles debug printing and va...
Definition: HypoBase.cxx:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:898
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
xAOD::PhotonContainer
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/PhotonContainer.h:17
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:452
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
TrigCompositeUtils::linkToPrevious
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
Definition: TrigCompositeUtilsRoot.cxx:139
PhotonAuxContainer.h
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
xAOD::Photon_v1
Definition: Photon_v1.h:37
HLTIdentifier.h
TrigEgammaTLAPhotonHypoAlg::m_hypoTools
ToolHandleArray< TrigEgammaTLAPhotonHypoTool > m_hypoTools
Definition: TrigEgammaTLAPhotonHypoAlg.h:28
TrigEgammaTLAPhotonHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrigEgammaTLAPhotonHypoAlg.cxx:31
xAOD::Egamma_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: Egamma_v1.cxx:65
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
TrigEgammaTLAPhotonHypoAlg::m_TLAPhotonsKey
SG::WriteHandleKey< xAOD::PhotonContainer > m_TLAPhotonsKey
Definition: TrigEgammaTLAPhotonHypoAlg.h:33
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
PhotonContainer.h
TrigEgammaTLAPhotonHypoAlg::TrigEgammaTLAPhotonHypoAlg
TrigEgammaTLAPhotonHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigEgammaTLAPhotonHypoAlg.cxx:17
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37