ATLAS Offline Software
Loading...
Searching...
No Matches
TrigEgammaFastPhotonHypoAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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 for ( auto previousDecision : *previousDecisionsHandle){
39 auto clusterELInfo = TCU::findLink<xAOD::TrigEMClusterContainer>( previousDecision, "feature" );
40
41 if( not clusterELInfo.isValid() ) {
42 ATH_MSG_ERROR("Can not obtain the link to Cluster");
43 ATH_MSG_ERROR( TCU::dump( previousDecision, [](const xAOD::TrigComposite* tc){
44 return tc->name() + " " + (tc->object<xAOD::TrigEMCluster>("feature") == 0 ? "has no cluster": "has cluster");
45 }) );
46 return StatusCode::FAILURE;
47 }
48 const xAOD::TrigEMCluster* cluster = *(clusterELInfo.link);
49 clusterToIndexMap.insert( std::make_pair( cluster, clusterCounter ) );
50 clusterCounter++;
51 }
52 ATH_MSG_DEBUG( "Cluster ptr to decision map has size " << clusterToIndexMap.size() );
53
54 // new output decisions
56 auto decisions = outputHandle.ptr();
57
58 std::vector<TrigEgammaFastPhotonHypoTool::PhotonInfo> hypoToolInput;
59
60 for ( auto previousDecision: *previousDecisionsHandle ) {
61 //previousDecision->objectLink< ViewContainer >( "view" );
62 const auto viewEL = previousDecision->objectLink<ViewContainer>( TCU::viewString() );
63
64 ATH_CHECK( viewEL.isValid() );
65
66 // get electron from that view:
67 size_t photonCounter = 0;
68 auto photonsHandle = ViewHelper::makeHandle( *viewEL, m_photonsKey, context );
69
70 ATH_CHECK( photonsHandle.isValid() );
71 ATH_MSG_DEBUG ( "electron handle size: " << photonsHandle->size() << "..." );
72
73 for ( auto photonIter = photonsHandle->begin(); photonIter != photonsHandle->end(); ++photonIter, photonCounter++ ) {
74 auto d = TCU::newDecisionIn( decisions, TCU::hypoAlgNodeName() );
75 d->setObjectLink( TCU::featureString(), ViewHelper::makeLink<xAOD::TrigPhotonContainer>( *viewEL, photonsHandle, photonCounter ) );
76
77 auto clusterPtr = (*photonIter)->emCluster();
78 ATH_CHECK( clusterPtr != nullptr );
79
80 // now find matching cluster
81 // 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
82 // since we have a map made in advance we can make use of the index lookup w/o the need for additional loop
83 auto origCluster = clusterToIndexMap.find( clusterPtr );
84 ATH_CHECK( origCluster != clusterToIndexMap.end() );
85 //coverity[deref_iterator:FALSE]
86 TCU::linkToPrevious( d, decisionInput().key(), origCluster->second );
87
88 // now we have DecisionObject ready to be passed to hypo tool. it has link to photon,
89 // and decisions on clusters
90 // we shall avoid calling the tools for chains which were already rejected on certain cluster, but this is left to hypo tools
91 TCU::DecisionIDContainer clusterDecisionIDs;
92 TCU::decisionIDs( previousDecisionsHandle->at( origCluster->second ), clusterDecisionIDs );
93
94 hypoToolInput.emplace_back( d, *photonIter, origCluster->first, std::move(clusterDecisionIDs) );
95 }
96 }
97
98 for ( auto & tool: m_hypoTools ) {
99 ATH_CHECK( tool->decide( hypoToolInput ) );
100 }
101
102
103 ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
104
105 return StatusCode::SUCCESS;
106}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(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 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.