ATLAS Offline Software
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"
8 #include "AthViews/ViewHelper.h"
9 
10 
23 
24 TrigEgammaFastElectronHypoAlg::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 
49 StatusCode 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 
77  LinkInfo<xAOD::TrigEMClusterContainer> linkInfo = findLink<xAOD::TrigEMClusterContainer>(previousDecision, featureString());
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 
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  {
121  LinkInfo<xAOD::TrigRingerRingsContainer> linkInfo = findLink<xAOD::TrigRingerRingsContainer>(previousDecision, "ringer");
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 }
grepfile.info
info
Definition: grepfile.py:38
TrigEgammaFastElectronHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrigEgammaFastElectronHypoAlg.cxx:49
TrigEgammaFastElectronHypoAlg::TrigEgammaFastElectronHypoAlg
TrigEgammaFastElectronHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigEgammaFastElectronHypoAlg.cxx:24
TrigEgammaFastElectronHypoAlg::m_runInView
Gaudi::Property< bool > m_runInView
Definition: TrigEgammaFastElectronHypoAlg.h:46
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
TrigCompositeUtils::LinkInfo::link
ElementLink< T > link
Link to the feature.
Definition: LinkInfo.h:61
TrigCompositeUtils::DecisionContainer
xAOD::TrigCompositeContainer DecisionContainer
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigCompositeContainer.h:21
TrigEgammaFastElectronHypoAlg::m_ringerNNTools
ToolHandleArray< Ringer::IAsgRingerSelectorTool > m_ringerNNTools
Definition: TrigEgammaFastElectronHypoAlg.h:43
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:46
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
hist_file_dump.d
d
Definition: hist_file_dump.py:137
TrigCompositeUtils::hypoAlgNodeName
const std::string & hypoAlgNodeName()
Definition: TrigCompositeUtilsRoot.cxx:904
ViewHelper::makeHandle
SG::ReadHandle< T > makeHandle(const SG::View *view, const SG::ReadHandleKey< T > &rhKey, const EventContext &context)
navigate from the TrigComposite to nearest view and fetch object from it
Definition: ViewHelper.h:259
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::renounce
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)
Definition: AthCommonDataStore.h:380
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
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:30
TrigEgammaFastElectronHypoAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: TrigEgammaFastElectronHypoAlg.h:44
ViewHelper.h
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
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
TrigEgammaFastElectronHypoAlg.h
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
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrigEgammaFastElectronHypoAlg::initialize
virtual StatusCode initialize() override
Definition: TrigEgammaFastElectronHypoAlg.cxx:33
TrigEgammaFastElectronHypoAlg::m_pidNames
Gaudi::Property< std::vector< std::string > > m_pidNames
Definition: TrigEgammaFastElectronHypoAlg.h:45
TrigEgammaFastElectronHypoAlg::m_hypoTools
ToolHandleArray< ITrigEgammaFastElectronHypoTool > m_hypoTools
Definition: TrigEgammaFastElectronHypoAlg.h:42
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:101
TrigCompositeUtils::DecisionAuxContainer
xAOD::TrigCompositeAuxContainer DecisionAuxContainer
Definition: TrigCompositeAuxContainer.h:20
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:884
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
HypoBase
Hypothesis algorithms take the output of reco algorithms and the decision from the preceeding InputMa...
Definition: HypoBase.h:13
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
TrigEgammaFastElectronHypoAlg::m_electronsKey
SG::ReadHandleKey< xAOD::TrigElectronContainer > m_electronsKey
Definition: TrigEgammaFastElectronHypoAlg.h:41
xAOD::TrigRingerRings_v2
Definition: TrigRingerRings_v2.h:24
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
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
ITrigEgammaFastElectronHypoTool::ElectronInfo
Definition: ITrigEgammaFastElectronHypoTool.h:31
TrigCompositeUtils::LinkInfo
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition: LinkInfo.h:28
TrigCompositeUtils::DecisionIDContainer
std::set< DecisionID > DecisionIDContainer
Definition: TrigComposite_v1.h:28
TrigEgammaFastElectronHypoAlg::m_lumiBlockMuTool
ToolHandle< ILumiBlockMuTool > m_lumiBlockMuTool
Definition: TrigEgammaFastElectronHypoAlg.h:39
TrigCompositeUtils::findLink
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...
TrigCompositeUtils::decisionIDs
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
Definition: TrigCompositeUtilsRoot.cxx:67
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
xAOD::TrigEMCluster_v1
Description of a trigger EM cluster.
Definition: TrigEMCluster_v1.h:28
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
TrigCompositeUtils::viewString
const std::string & viewString()
Definition: TrigCompositeUtilsRoot.cxx:880
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
ViewContainer
Definition: View.h:158