ATLAS Offline Software
Loading...
Searching...
No Matches
TrigEgammaFastElectronHypoAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include <map>
9
22
23TrigEgammaFastElectronHypoAlg::TrigEgammaFastElectronHypoAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
24 ::HypoBase( name, pSvcLocator ),
25 m_lumiBlockMuTool("LumiBlockMuTool/LumiBlockMuTool")
26
27{
28 declareProperty("LumiBlockMuTool", m_lumiBlockMuTool, "Luminosity Tool" );
29}
30
31
33
34 ATH_CHECK( m_hypoTools.retrieve() );
35 ATH_CHECK(m_ringerNNTools.retrieve());
36 ATH_CHECK( m_electronsKey.initialize() );
37
38 if (m_runInView){
39 renounce( m_electronsKey );// electrons are made in views, so they are not in the EvtStore: hide them
40 }
41
42 if ( not m_monTool.name().empty() )
43 ATH_CHECK( m_monTool.retrieve() );
44
45 return StatusCode::SUCCESS;
46}
47
48StatusCode TrigEgammaFastElectronHypoAlg::execute( const EventContext& context ) const
49{
50 ATH_MSG_DEBUG ( "Executing " << name() << "..." );
51
52 auto timer = Monitored::Timer("TIME_exec");
53 auto timer_predict = Monitored::Timer("TIME_NN_exec");
54 auto monitoring = Monitored::Group( m_monTool, timer, timer_predict);
55
56
57 auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
58 ATH_CHECK( previousDecisionsHandle.isValid() );
59 ATH_MSG_DEBUG( "Running with "<< previousDecisionsHandle->size() <<" previous decisions");
60
61 //Printing event No.
62 ATH_MSG_DEBUG("Event No.: "<<context.eventID().event_number());
63
64 // new output decisions
66 auto decisions = outputHandle.ptr();
67
68
69 // // extract mapping of cluster pointer to an index in the cluster decision collection
70 // prepare decisions container and link back to the clusters, and decision on clusters
71 std::map<const xAOD::TrigEMCluster*, size_t> clusterToIndexMap;
72 size_t clusterCounter = 0;
73 for ( auto previousDecision : *previousDecisionsHandle){
74
77 clusterLink = linkInfo.link;
78 ATH_CHECK( clusterLink.isValid() );
79
80 const xAOD::TrigEMCluster* cluster = *clusterLink;
81 clusterToIndexMap.insert( std::make_pair( cluster, clusterCounter ) );
82 clusterCounter++;
83 }
84
85
86 ATH_MSG_DEBUG( "Cluster ptr to decision map has size " << clusterToIndexMap.size() );
87
88 // prepare imput for tools
89 std::vector<ITrigEgammaFastElectronHypoTool::ElectronInfo> hypoToolInput;
90
91 for ( auto previousDecision: *previousDecisionsHandle ) {
92 // get View
93 const auto viewEL = previousDecision->objectLink<ViewContainer>( viewString() );
94 ATH_CHECK( viewEL.isValid() );
95
96 // get electron from that view:
97 size_t electronCounter = 0;
98 auto electronsHandle = ViewHelper::makeHandle( *viewEL, m_electronsKey, context );
99 ATH_CHECK( electronsHandle.isValid() );
100 ATH_MSG_DEBUG ( "electron handle size: " << electronsHandle->size() << "..." );
101
102 for ( auto electronIter = electronsHandle->begin(); electronIter != electronsHandle->end(); ++electronIter, electronCounter++ ) {
103
104 auto d = newDecisionIn( decisions, hypoAlgNodeName() );
105 d->setObjectLink( featureString(), ViewHelper::makeLink<xAOD::TrigElectronContainer>( *viewEL, electronsHandle, electronCounter ) );
106
107 auto clusterPtr = (*electronIter)->emCluster();
108 ATH_CHECK( clusterPtr != nullptr );
109
110 // now find matching cluster
111 // could use geometric matching but in fact the cluster owned by the decision object and the cluster owned by the electron should be the same
112 // since we have a map made in advance we can make use of the index lookup w/o the need for additional loop
113 auto origCluster = clusterToIndexMap.find( clusterPtr );
114 ATH_CHECK( origCluster != clusterToIndexMap.end() );
115 //coverity[INVALIDATE_ITERATOR:FALSE]
116 linkToPrevious( d, decisionInput().key(), origCluster->second );
117
118
119 const xAOD::TrigRingerRings *rings=nullptr;
120 {
121 static const std::string ringerStr{"ringer"};
122 LinkInfo<xAOD::TrigRingerRingsContainer> linkInfo = findLink<xAOD::TrigRingerRingsContainer>(context, previousDecision, ringerStr);
123 auto ringerLink = linkInfo.link;
124 ATH_CHECK( ringerLink.isValid() );
125 rings = *ringerLink;
126 }
127
128
129 // now we have DecisionObject ready to be passed to hypo tool. it has link to electron,
130 // and decisions on clusters
131 // we shall avoid calling the tools for chains which were already rejected on certain cluster, but this is left to hypo tools
132 DecisionIDContainer clusterDecisionIDs;
133 decisionIDs( previousDecisionsHandle->at( origCluster->second ), clusterDecisionIDs );
134
135 auto el = *electronIter;
136 auto cl = origCluster->first;
137
138 ITrigEgammaFastElectronHypoTool::ElectronInfo info(d, el, cl, rings, clusterDecisionIDs);
139
140
141 float avgmu = m_lumiBlockMuTool->averageInteractionsPerCrossing(context);
142 info.valueDecorator["avgmu"] = avgmu;
143
144 // Decorate the info object with NN ringer decision
145 if(rings && cl && el){
146 int idx=0;
147 for (auto& pidname : m_pidNames ){
148 timer_predict.start();
149 float nnOutput = m_ringerNNTools[idx]->predict(rings, el);
150 timer_predict.stop();
151 info.pidDecorator[pidname] = static_cast<bool>(m_ringerNNTools[idx]->accept(rings, nnOutput, avgmu));
152 info.valueDecorator[pidname+"NNOutput"] = nnOutput;
153 idx++;
154 }
155 }
156
157 hypoToolInput.push_back(std::move(info));
158
159 }// loop over all electrons
160
161 }// loop over all decisions
162
163 for ( auto & tool: m_hypoTools ) {
164 ATH_CHECK( tool->decide( hypoToolInput ) );
165 }
166
167 ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
168
169 return StatusCode::SUCCESS;
170}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
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.
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
const std::string & hypoAlgNodeName()
void decisionIDs(const Decision *d, DecisionIDContainer &id)
Extracts DecisionIDs stored in the Decision object.
const std::string & featureString()
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
Header file to be included by clients of the Monitored infrastructure.
const std::string & viewString()
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...
DataVector< SG::View > ViewContainer
View container for recording in StoreGate.
Definition View.h:290
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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
Group of local monitoring quantities and retain correlation when filling histograms
A monitored timer.
pointer_type ptr()
Dereference the pointer.
ToolHandle< GenericMonitoringTool > m_monTool
SG::ReadHandleKey< xAOD::TrigElectronContainer > m_electronsKey
ToolHandle< ILumiBlockMuTool > m_lumiBlockMuTool
Gaudi::Property< std::vector< std::string > > m_pidNames
ToolHandleArray< Ringer::IAsgRingerSelectorTool > m_ringerNNTools
ToolHandleArray< ITrigEgammaFastElectronHypoTool > m_hypoTools
TrigEgammaFastElectronHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute(const EventContext &context) const 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()
xAOD::TrigCompositeAuxContainer DecisionAuxContainer
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.
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...
xAOD::TrigCompositeContainer DecisionContainer
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
TrigRingerRings_v2 TrigRingerRings
Define the latest version of the TrigRingerRings class.
TrigEMCluster_v1 TrigEMCluster
Define the latest version of the trigger EM cluster class.
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22
ElementLink< T > link
Link to the feature.
Definition LinkInfo.h:55