ATLAS Offline Software
Loading...
Searching...
No Matches
TrigEgammaFastElectronHypoAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4#include <map>
5#include "Gaudi/Property.h"
9
10
23
24TrigEgammaFastElectronHypoAlg::TrigEgammaFastElectronHypoAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
25 ::HypoBase( name, pSvcLocator ),
26 m_lumiBlockMuTool("LumiBlockMuTool/LumiBlockMuTool")
27
28{
29 declareProperty("LumiBlockMuTool", m_lumiBlockMuTool, "Luminosity Tool" );
30}
31
32
34
35 ATH_CHECK( m_hypoTools.retrieve() );
36 ATH_CHECK(m_ringerNNTools.retrieve());
37 ATH_CHECK( m_electronsKey.initialize() );
38
39 if (m_runInView){
40 renounce( m_electronsKey );// electrons are made in views, so they are not in the EvtStore: hide them
41 }
42
43 if ( not m_monTool.name().empty() )
44 ATH_CHECK( m_monTool.retrieve() );
45
46 return StatusCode::SUCCESS;
47}
48
49StatusCode TrigEgammaFastElectronHypoAlg::execute( const EventContext& context ) const
50{
51 ATH_MSG_DEBUG ( "Executing " << name() << "..." );
52
53 auto timer = Monitored::Timer("TIME_exec");
54 auto timer_predict = Monitored::Timer("TIME_NN_exec");
55 auto monitoring = Monitored::Group( m_monTool, timer, timer_predict);
56
57
58 auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
59 ATH_CHECK( previousDecisionsHandle.isValid() );
60 ATH_MSG_DEBUG( "Running with "<< previousDecisionsHandle->size() <<" previous decisions");
61
62 //Printing event No.
63 ATH_MSG_DEBUG("Event No.: "<<context.eventID().event_number());
64
65 // new output decisions
67 auto decisions = outputHandle.ptr();
68
69
70 // // extract mapping of cluster pointer to an index in the cluster decision collection
71 // prepare decisions container and link back to the clusters, and decision on clusters
72 std::map<const xAOD::TrigEMCluster*, size_t> clusterToIndexMap;
73 size_t clusterCounter = 0;
74 for ( auto previousDecision : *previousDecisionsHandle){
75
78 clusterLink = linkInfo.link;
79 ATH_CHECK( clusterLink.isValid() );
80
81 const xAOD::TrigEMCluster* cluster = *clusterLink;
82 clusterToIndexMap.insert( std::make_pair( cluster, clusterCounter ) );
83 clusterCounter++;
84 }
85
86
87 ATH_MSG_DEBUG( "Cluster ptr to decision map has size " << clusterToIndexMap.size() );
88
89 // prepare imput for tools
90 std::vector<ITrigEgammaFastElectronHypoTool::ElectronInfo> hypoToolInput;
91
92 for ( auto previousDecision: *previousDecisionsHandle ) {
93 // get View
94 const auto viewEL = previousDecision->objectLink<ViewContainer>( viewString() );
95 ATH_CHECK( viewEL.isValid() );
96
97 // get electron from that view:
98 size_t electronCounter = 0;
99 auto electronsHandle = ViewHelper::makeHandle( *viewEL, m_electronsKey, context );
100 ATH_CHECK( electronsHandle.isValid() );
101 ATH_MSG_DEBUG ( "electron handle size: " << electronsHandle->size() << "..." );
102
103 for ( auto electronIter = electronsHandle->begin(); electronIter != electronsHandle->end(); ++electronIter, electronCounter++ ) {
104
105 auto d = newDecisionIn( decisions, hypoAlgNodeName() );
106 d->setObjectLink( featureString(), ViewHelper::makeLink<xAOD::TrigElectronContainer>( *viewEL, electronsHandle, electronCounter ) );
107
108 auto clusterPtr = (*electronIter)->emCluster();
109 ATH_CHECK( clusterPtr != nullptr );
110
111 // now find matching cluster
112 // 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
113 // since we have a map made in advance we can make use of the index lookup w/o the need for additional loop
114 auto origCluster = clusterToIndexMap.find( clusterPtr );
115 ATH_CHECK( origCluster != clusterToIndexMap.end() );
116 linkToPrevious( d, decisionInput().key(), origCluster->second );
117
118
119 const xAOD::TrigRingerRings *rings=nullptr;
120 {
122 auto ringerLink = linkInfo.link;
123 ATH_CHECK( ringerLink.isValid() );
124 rings = *ringerLink;
125 }
126
127
128 // now we have DecisionObject ready to be passed to hypo tool. it has link to electron,
129 // and decisions on clusters
130 // we shall avoid calling the tools for chains which were already rejected on certain cluster, but this is left to hypo tools
131 DecisionIDContainer clusterDecisionIDs;
132 decisionIDs( previousDecisionsHandle->at( origCluster->second ), clusterDecisionIDs );
133
134 auto el = *electronIter;
135 auto cl = origCluster->first;
136
137 ITrigEgammaFastElectronHypoTool::ElectronInfo info(d, el, cl, rings, clusterDecisionIDs);
138
139
140 float avgmu = m_lumiBlockMuTool->averageInteractionsPerCrossing(context);
141 info.valueDecorator["avgmu"] = avgmu;
142
143 // Decorate the info object with NN ringer decision
144 if(rings && cl && el){
145 int idx=0;
146 for (auto& pidname : m_pidNames ){
147 timer_predict.start();
148 float nnOutput = m_ringerNNTools[idx]->predict(rings, el);
149 timer_predict.stop();
150 info.pidDecorator[pidname] = static_cast<bool>(m_ringerNNTools[idx]->accept(rings, nnOutput, avgmu));
151 info.valueDecorator[pidname+"NNOutput"] = nnOutput;
152 idx++;
153 }
154 }
155
156 hypoToolInput.push_back(info);
157
158 }// loop over all electrons
159
160 }// loop over all decisions
161
162 for ( auto & tool: m_hypoTools ) {
163 ATH_CHECK( tool->decide( hypoToolInput ) );
164 }
165
166 ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
167
168 return StatusCode::SUCCESS;
169}
#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 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 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
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