ATLAS Offline Software
Loading...
Searching...
No Matches
TrigEgammaFastPhotonHypoAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10namespace TCU = TrigCompositeUtils;
11
13 ISvcLocator* pSvcLocator ) :
14 ::HypoBase( name, pSvcLocator ) {}
15
16
18{
19 ATH_CHECK( m_hypoTools.retrieve() );
20 ATH_CHECK( m_photonsKey.initialize() );
21 renounce( m_photonsKey );// clusters are made in views, so they are not in the EvtStore: hide them
22
23 return StatusCode::SUCCESS;
24}
25
26StatusCode TrigEgammaFastPhotonHypoAlg::execute( const EventContext& context ) const {
27
28 ATH_MSG_DEBUG ( "Executing " << name() << "..." );
29 auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
30 ATH_CHECK( previousDecisionsHandle.isValid() );
31 ATH_MSG_DEBUG( "Running with "<< previousDecisionsHandle->size() <<" previous decisions");
32
33
34 // map between cluster pointer and index
35
36 std::map<const xAOD::TrigEMCluster*, size_t> clusterToIndexMap;
37 size_t clusterCounter = 0;
38 const std::string featureStr{"feature"};
39 for ( auto previousDecision : *previousDecisionsHandle){
40 auto clusterELInfo = TCU::findLink<xAOD::TrigEMClusterContainer>(context, previousDecision, featureStr );
41
42 if( not clusterELInfo.isValid() ) {
43 ATH_MSG_ERROR("Can not obtain the link to Cluster");
44 ATH_MSG_ERROR( TCU::dump( previousDecision, [&featureStr](const xAOD::TrigComposite* tc){
45 return tc->name() + " " + (tc->object<xAOD::TrigEMCluster>(featureStr) == 0 ? "has no cluster": "has cluster");
46 }) );
47 return StatusCode::FAILURE;
48 }
49 const xAOD::TrigEMCluster* cluster = *(clusterELInfo.link);
50 clusterToIndexMap.insert( std::make_pair( cluster, clusterCounter ) );
51 clusterCounter++;
52 }
53 ATH_MSG_DEBUG( "Cluster ptr to decision map has size " << clusterToIndexMap.size() );
54
55 // new output decisions
57 auto decisions = outputHandle.ptr();
58
59 std::vector<TrigEgammaFastPhotonHypoTool::PhotonInfo> hypoToolInput;
60
61 for ( auto previousDecision: *previousDecisionsHandle ) {
62 //previousDecision->objectLink< ViewContainer >( "view" );
63 const auto viewEL = previousDecision->objectLink<ViewContainer>( TCU::viewString() );
64
65 ATH_CHECK( viewEL.isValid() );
66
67 // get electron from that view:
68 size_t photonCounter = 0;
69 auto photonsHandle = ViewHelper::makeHandle( *viewEL, m_photonsKey, context );
70
71 ATH_CHECK( photonsHandle.isValid() );
72 ATH_MSG_DEBUG ( "electron handle size: " << photonsHandle->size() << "..." );
73
74 for ( auto photonIter = photonsHandle->begin(); photonIter != photonsHandle->end(); ++photonIter, photonCounter++ ) {
75 auto d = TCU::newDecisionIn( decisions, TCU::hypoAlgNodeName() );
76 d->setObjectLink( TCU::featureString(), ViewHelper::makeLink<xAOD::TrigPhotonContainer>( *viewEL, photonsHandle, photonCounter ) );
77
78 auto clusterPtr = (*photonIter)->emCluster();
79 ATH_CHECK( clusterPtr != nullptr );
80
81 // now find matching cluster
82 // could use geometric matching but in fact the cluster owned by the decision object and the cluster owned by the photon should be the same
83 // since we have a map made in advance we can make use of the index lookup w/o the need for additional loop
84 auto origCluster = clusterToIndexMap.find( clusterPtr );
85 ATH_CHECK( origCluster != clusterToIndexMap.end() );
86 //coverity[deref_iterator:FALSE]
87 TCU::linkToPrevious( d, decisionInput().key(), origCluster->second );
88
89 // now we have DecisionObject ready to be passed to hypo tool. it has link to photon,
90 // and decisions on clusters
91 // we shall avoid calling the tools for chains which were already rejected on certain cluster, but this is left to hypo tools
92 TCU::DecisionIDContainer clusterDecisionIDs;
93 TCU::decisionIDs( previousDecisionsHandle->at( origCluster->second ), clusterDecisionIDs );
94
95 hypoToolInput.emplace_back( d, *photonIter, origCluster->first, std::move(clusterDecisionIDs) );
96 }
97 }
98
99 for ( auto & tool: m_hypoTools ) {
100 ATH_CHECK( tool->decide( hypoToolInput ) );
101 }
102
103
104 ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
105
106 return StatusCode::SUCCESS;
107}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
static Double_t tc
DataVector< SG::View > ViewContainer
View container for recording in StoreGate.
Definition View.h:290
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
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:18
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:22
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:35
HypoBase(const std::string &name, ISvcLocator *pSvcLocator)
constructor, to be called by sub-class constructors
Definition HypoBase.cxx:12
pointer_type ptr()
Dereference the pointer.
virtual StatusCode execute(const EventContext &context) const override
TrigEgammaFastPhotonHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< xAOD::TrigPhotonContainer > m_photonsKey
ToolHandleArray< TrigEgammaFastPhotonHypoTool > m_hypoTools
virtual StatusCode initialize() override
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
const std::string & viewString()
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.
const std::string & featureString()
std::set< DecisionID > DecisionIDContainer
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
std::string dump(const Decision *tc, const std::function< std::string(const Decision *)> &printerFnc)
Prints the Decision object including the linked seeds @warnign expensive call.
const std::string & hypoAlgNodeName()
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
LinkInfo< T > findLink(const EventContext &ctx, const Decision *start, const std::string &linkName, const bool suppressMultipleLinksWarning=false)
Perform a recursive search for ElementLinks of type T and name 'linkName', starting from Decision obj...
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
ElementLink< T > makeLink(const SG::View *view, const SG::ReadHandle< T > &handle, size_t index)
Create EL to a collection in view.
Definition ViewHelper.h:309
auto makeHandle(const SG::View *view, const KEY &key, const EventContext &ctx)
Create a view handle from a handle key.
Definition ViewHelper.h:273
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
TrigEMCluster_v1 TrigEMCluster
Define the latest version of the trigger EM cluster class.