ATLAS Offline Software
TrigMuonEFTrackIsolationHypoAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "AthViews/ViewHelper.h"
8 
9 using namespace TrigCompositeUtils;
10 
11 // --------------------------------------------------------------------------------
12 // --------------------------------------------------------------------------------
13 
15  ISvcLocator* pSvcLocator ) :
16  ::HypoBase( name, pSvcLocator )
17 {}
18 
19 
20 // --------------------------------------------------------------------------------
21 // --------------------------------------------------------------------------------
22 
24 {
25  ATH_CHECK( m_hypoTools.retrieve() );
26 
30  ATH_CHECK( m_muonKey.initialize() );
31  ATH_CHECK( m_muonIso20Key.initialize() );
32  ATH_CHECK( m_muonIso30Key.initialize() );
33 
34  return StatusCode::SUCCESS;
35 }
36 
37 // --------------------------------------------------------------------------------
38 // --------------------------------------------------------------------------------
39 
40 StatusCode TrigMuonEFTrackIsolationHypoAlg::execute( const EventContext& context ) const
41 {
42 
43  ATH_MSG_DEBUG("Executing ...");
44 
45  auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
46  ATH_CHECK( previousDecisionsHandle.isValid() );
47  ATH_MSG_DEBUG( "Running with "<< previousDecisionsHandle->size() <<" previous decisions");
48 
49  // prepare output decisions
51  auto decisions = outputHandle.ptr();
52 
53  std::vector<TrigMuonEFTrackIsolationHypoTool::EFIsolationMuonInfo> toolInput;
54  size_t counter = 0;
55  for ( const auto previousDecision: *previousDecisionsHandle ) {
56 
57  // get View
58  auto viewEL = previousDecision->objectLink<ViewContainer>(viewString());
59  ATH_CHECK( viewEL.isValid() );
60 
61  // get Muon and isolation
62  auto muonHandle = ViewHelper::makeHandle( *viewEL, m_muonKey, context );
65  ATH_CHECK( muonHandle.isValid() );
66  ATH_MSG_DEBUG( "Muinfo handle size: " << muonHandle->size() << " ..." );
67 
68  // It is posisble that no muons are found, in this case we go to the next decision
69  if ( muonHandle->size()==0 ) continue;
70 
71  // this code only gets muon 0, since we build the views centered on a single muon
72  auto muonEL = ViewHelper::makeLink( *viewEL, muonHandle, 0 );
73  ATH_CHECK( muonEL.isValid() );
74  const xAOD::Muon* muon = *muonEL;
75 
76  // create new dicions
77  auto newd = newDecisionIn( decisions, hypoAlgNodeName() );
78 
79  toolInput.emplace_back( newd, muon, previousDecision, muonIso20(*muon), muonIso30(*muon) );
80 
81  newd -> setObjectLink( featureString(), muonEL );
82  TrigCompositeUtils::linkToPrevious( newd, previousDecision, context );
83 
84 
85  ATH_MSG_DEBUG("REGTEST: " << m_muonKey.key() << " pT = " << (*muonEL)->pt()/Gaudi::Units::GeV << " GeV");
86  ATH_MSG_DEBUG("REGTEST: " << m_muonKey.key() << " eta/phi = " << (*muonEL)->eta() << "/" << (*muonEL)->phi());
87  ATH_MSG_DEBUG("Added view, feature, previous decision to new decision "<<counter <<" for view "<<(*viewEL)->name() );
88 
89  counter++;
90  }
91 
92  ATH_MSG_DEBUG("Found "<<toolInput.size()<<" inputs to tools");
93 
94  StatusCode sc = StatusCode::SUCCESS;
95  for ( auto& tool: m_hypoTools ) {
96  ATH_MSG_DEBUG("Go to " << tool );
97  sc = tool->decide(toolInput);
98  if (!sc.isSuccess()) {
99  ATH_MSG_ERROR("MuonHypoTool is failed");
100  return StatusCode::FAILURE;
101  }
102  } // End of tool algorithm
103 
104  ATH_CHECK(hypoBaseOutputProcessing(outputHandle));
105 
106  return StatusCode::SUCCESS;
107 }
108 
109 // --------------------------------------------------------------------------------
110 // --------------------------------------------------------------------------------
111 
TrigMuonEFTrackIsolationHypoAlg::TrigMuonEFTrackIsolationHypoAlg
TrigMuonEFTrackIsolationHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigMuonEFTrackIsolationHypoAlg.cxx:14
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
TrigMuonEFTrackIsolationHypoAlg.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
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
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
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
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
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
TrigMuonEFTrackIsolationHypoAlg::m_hypoTools
ToolHandleArray< TrigMuonEFTrackIsolationHypoTool > m_hypoTools
Definition: TrigMuonEFTrackIsolationHypoAlg.h:26
TrigMuonEFTrackIsolationHypoAlg::m_muonIso20Key
SG::ReadDecorHandleKey< xAOD::MuonContainer > m_muonIso20Key
Definition: TrigMuonEFTrackIsolationHypoAlg.h:31
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:81
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:886
TrigMuonEFTrackIsolationHypoAlg::m_muonIso30Key
SG::ReadDecorHandleKey< xAOD::MuonContainer > m_muonIso30Key
Definition: TrigMuonEFTrackIsolationHypoAlg.h:34
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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
TrigMuonEFTrackIsolationHypoAlg::initialize
virtual StatusCode initialize() override
Definition: TrigMuonEFTrackIsolationHypoAlg.cxx:23
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
TrigMuonEFTrackIsolationHypoAlg::m_muonKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonKey
Definition: TrigMuonEFTrackIsolationHypoAlg.h:28
ReadDecorHandle.h
Handle class for reading a decoration on an object.
test_pyathena.counter
counter
Definition: test_pyathena.py:15
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
TrigCompositeUtils::viewString
const std::string & viewString()
Definition: TrigCompositeUtilsRoot.cxx:882
TrigMuonEFTrackIsolationHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrigMuonEFTrackIsolationHypoAlg.cxx:40
ViewContainer
Definition: View.h:161