ATLAS Offline Software
TrigEgammaFastCaloHypoAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <algorithm>
10 #include "AthViews/ViewHelper.h"
12 #include "GaudiKernel/SystemOfUnits.h"
14 
15 
16 namespace TCU = TrigCompositeUtils;
17 
19  ISvcLocator* pSvcLocator ) :
20  ::HypoBase( name, pSvcLocator ),
21  m_lumiBlockMuTool("LumiBlockMuTool/LumiBlockMuTool")
22  {
23  declareProperty("LumiBlockMuTool", m_lumiBlockMuTool, "Luminosity Tool" );
24  }
25 
26 
28 
29  ATH_CHECK( m_hypoTools.retrieve() );
30  ATH_CHECK( m_ringerNNTools.retrieve());
31  ATH_CHECK( m_clustersKey.initialize() );
32  ATH_CHECK( m_ringsKey.initialize(SG::AllowEmpty));
33 
34  renounce( m_clustersKey );// clusters are made in views, so they are not in the EvtStore: hide them
36 
37  if ( not m_monTool.name().empty() )
38  CHECK( m_monTool.retrieve() );
39 
40 
41  ATH_MSG_DEBUG( "Initialization of FastCaloHypoAlg completed successfully");
42  return StatusCode::SUCCESS;
43 }
44 
45 
46 
47 StatusCode TrigEgammaFastCaloHypoAlg::execute( const EventContext& context ) const
48 {
49  ATH_MSG_DEBUG ( "Executing " << name() << "..." );
50 
51  auto timer = Monitored::Timer("TIME_exec");
52  auto timer_predict = Monitored::Timer("TIME_NN_exec");
53  auto monitoring = Monitored::Group( m_monTool, timer, timer_predict);
54 
55  auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
56  ATH_CHECK( previousDecisionsHandle.isValid() );
57  ATH_MSG_DEBUG( "Running with "<< previousDecisionsHandle->size() <<" previous decisions");
58 
59  // new decisions
60  // new output decisions
62  auto decisions = outputHandle.ptr();
63 
64  // input for decision
65  std::vector<ITrigEgammaFastCaloHypoTool::FastClusterInfo> toolInput;
66 
67  // loop over previous decisions
68  size_t counter=0;
69  for ( const auto previousDecision: *previousDecisionsHandle )
70  {
71  //get RoI
72  auto roiELInfo = TCU::findLink<TrigRoiDescriptorCollection>( previousDecision, TCU::initialRoIString() );
73 
74  ATH_CHECK( roiELInfo.isValid() );
75  const TrigRoiDescriptor* roi = *(roiELInfo.link);
76 
77  // get View
78  const auto viewEL = previousDecision->objectLink<ViewContainer>( TCU::viewString() );
79  ATH_CHECK( viewEL.isValid() );
80 
81  // get cluster
82  auto clusterHandle = ViewHelper::makeHandle( *viewEL, m_clustersKey, context);
83  ATH_CHECK( clusterHandle.isValid() );
84  ATH_MSG_DEBUG ( "Cluster handle size: " << clusterHandle->size() << "..." );
85  auto emCluster = clusterHandle.cptr()->at(0);
86  ATH_MSG_DEBUG("Event cluster with eta = "<< emCluster->eta());
87 
88  // get rings
89  auto ringsHandle = ViewHelper::makeHandle( *viewEL, m_ringsKey, context);
90  ATH_CHECK( ringsHandle.isValid());
91  ATH_MSG_DEBUG ( "Rings handle size: " << ringsHandle->size() << "..." );
92 
93  auto ringsCluster = ringsHandle.cptr()->at(0);
94 
95  // create new decision (node)
97 
98 
99  ITrigEgammaFastCaloHypoTool::FastClusterInfo info(d, roi, emCluster, ringsCluster , previousDecision);
100 
101  float avgmu = m_lumiBlockMuTool->averageInteractionsPerCrossing();
102  info.valueDecorator["avgmu"] = avgmu;
103 
104  // Decorate the info object with NN ringer decision. if rings size is zero, this object is a dummy and
105  // should not compute any decision. the hypo tool will not found any pid name and will reprove this.
106  if(ringsCluster && emCluster && !ringsCluster->rings().empty() )
107  {
108  int idx=0;
109  for (auto& pidname : m_pidNames ){
110  timer_predict.start();
111  float nnOutput = m_ringerNNTools[idx]->predict(ringsCluster);
112  timer_predict.stop();
113  info.pidDecorator[pidname] = (bool)m_ringerNNTools[idx]->accept(ringsCluster, nnOutput, avgmu);
114  info.valueDecorator[pidname+"NNOutput"] = nnOutput;
115  idx++;
116  }
117  }
118 
119  toolInput.push_back( info );
120 
121 
122  // link the cluster
123  {
124  auto clus = ViewHelper::makeLink( *viewEL, clusterHandle, 0 );
125  ATH_CHECK( clus.isValid() );
126  d->setObjectLink( TCU::featureString(), clus );
127  }
128 
129  // link the rings
130  {
131  auto rings = ViewHelper::makeLink( *viewEL, ringsHandle, 0 );
132  ATH_CHECK( rings.isValid() );
133  d->setObjectLink( "ringer", rings );
134  }
135 
136  // link the RoI
137  {
138  d->setObjectLink( TCU::roiString(), roiELInfo.link );
139  }
140 
141  TCU::linkToPrevious( d, previousDecision, context );
142 
143  ATH_MSG_DEBUG( "Added view, roi, cluster, previous decision to new decision " << counter << " for view " << (*viewEL)->name() );
144  counter++;
145  }
146 
147  ATH_MSG_DEBUG( "Found "<<toolInput.size()<<" inputs to tools");
148 
149 
150  for ( auto& tool: m_hypoTools ) {
151  ATH_CHECK( tool->decide( toolInput ) );
152  }
153 
154  ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
155 
156  return StatusCode::SUCCESS;
157 }
grepfile.info
info
Definition: grepfile.py:38
ITrigEgammaFastCaloHypoTool::FastClusterInfo
Definition: ITrigEgammaFastCaloHypoTool.h:28
TrigEgammaFastCaloHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrigEgammaFastCaloHypoAlg.cxx:47
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
TrigCompositeUtils.h
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
TrigEgammaFastCaloHypoAlg::TrigEgammaFastCaloHypoAlg
TrigEgammaFastCaloHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigEgammaFastCaloHypoAlg.cxx:18
TrigEgammaFastCaloHypoAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: TrigEgammaFastCaloHypoAlg.h:39
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
ViewHelper::makeLink
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:276
TrigCompositeUtils::hypoAlgNodeName
const std::string & hypoAlgNodeName()
Definition: TrigCompositeUtilsRoot.cxx:906
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
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:258
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
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
ViewHelper.h
TrigEgammaFastCaloHypoAlg::m_lumiBlockMuTool
ToolHandle< ILumiBlockMuTool > m_lumiBlockMuTool
Definition: TrigEgammaFastCaloHypoAlg.h:38
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
TrigEgammaFastCaloHypoAlg::m_ringsKey
SG::ReadHandleKey< xAOD::TrigRingerRingsContainer > m_ringsKey
Definition: TrigEgammaFastCaloHypoAlg.h:35
TrigCompositeUtils::initialRoIString
const std::string & initialRoIString()
Definition: TrigCompositeUtilsRoot.cxx:870
TrigEgammaFastCaloHypoAlg::initialize
virtual StatusCode initialize() override
Definition: TrigEgammaFastCaloHypoAlg.cxx:27
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:81
TrigCompositeContainer.h
TrigEgammaFastCaloHypoAlg::m_clustersKey
SG::ReadHandleKey< xAOD::TrigEMClusterContainer > m_clustersKey
Definition: TrigEgammaFastCaloHypoAlg.h:34
TrigEgammaFastCaloHypoAlg.h
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:886
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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
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
HLTIdentifier.h
TrigEgammaFastCaloHypoAlg::m_pidNames
Gaudi::Property< std::vector< std::string > > m_pidNames
Definition: TrigEgammaFastCaloHypoAlg.h:40
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
TrigCompositeUtils::roiString
const std::string & roiString()
Definition: TrigCompositeUtilsRoot.cxx:878
test_pyathena.counter
counter
Definition: test_pyathena.py:15
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
TrigCompositeUtils::viewString
const std::string & viewString()
Definition: TrigCompositeUtilsRoot.cxx:882
TrigRoiDescriptorCollection.h
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
TrigEgammaFastCaloHypoAlg::m_hypoTools
ToolHandleArray< ITrigEgammaFastCaloHypoTool > m_hypoTools
Definition: TrigEgammaFastCaloHypoAlg.h:36
TrigEgammaFastCaloHypoAlg::m_ringerNNTools
ToolHandleArray< Ringer::IAsgRingerSelectorTool > m_ringerNNTools
Definition: TrigEgammaFastCaloHypoAlg.h:37
ViewContainer
Definition: View.h:161