ATLAS Offline Software
TrigMuonEFHypoAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TrigMuonEFHypoAlg.h"
6 #include "AthViews/ViewHelper.h"
7 
8 using namespace TrigCompositeUtils;
9 
10 // --------------------------------------------------------------------------------
11 // --------------------------------------------------------------------------------
12 
14  ISvcLocator* pSvcLocator ) :
15  ::HypoBase( name, pSvcLocator )
16 {
17 
18 }
19 
20 // --------------------------------------------------------------------------------
21 // --------------------------------------------------------------------------------
22 
24 {
25  ATH_CHECK(m_hypoTools.retrieve());
26 
28  ATH_CHECK(m_muonKey.initialize());
29 
30  return StatusCode::SUCCESS;
31 }
32 
33 // --------------------------------------------------------------------------------
34 // --------------------------------------------------------------------------------
35 
36 StatusCode TrigMuonEFHypoAlg::execute( const EventContext& context ) const
37 {
38  ATH_MSG_DEBUG("StatusCode TrigMuonEFHypoAlg::execute start");
39 
40  // common for all hypos, to move in the base class
41  auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
42  ATH_CHECK( previousDecisionsHandle.isValid() );
43  ATH_MSG_DEBUG( "Running with "<< previousDecisionsHandle->size() <<" previous decisions");
44 
45  // new output decisions
47  auto decisions = outputHandle.ptr();
48  // end of common
49 
50  std::vector<TrigMuonEFHypoTool::MuonEFInfo> toolInput;
51  size_t counter = 0; // view counter
52 
53  // loop over previous decisions
54  for ( const auto previousDecision: *previousDecisionsHandle ) {
55 
56  // get View
57  auto viewEL = previousDecision->objectLink<ViewContainer>( viewString() );
58  ATH_CHECK( viewEL.isValid() );
59 
60  // get muons
61  auto muonHandle = ViewHelper::makeHandle( *viewEL, m_muonKey, context );
62  ATH_CHECK( muonHandle.isValid() );
63  ATH_MSG_DEBUG( "Muinfo handle size: " << muonHandle->size() << " ..." );
64 
65  // It is posisble that no muons are found, in this case we go to the next decision
66  if(muonHandle->size()==0) continue;
67 
68  //In cases where IM is using mergeByFeature, and since we can have multiple
69  //muons per view, need to check that we are considering the corresponding muon
70  //from the previous decision. Relevant for combined muons only.
71 
72  const xAOD::Muon *muonPrev = nullptr;
73  if(m_mapToPrevDec){
74  auto prevMuInfo = TrigCompositeUtils::findLinks<xAOD::MuonContainer>(previousDecision, TrigCompositeUtils::featureString(), TrigDefs::lastFeatureOfType);
75  ATH_CHECK(prevMuInfo.size()==1);
76  auto prevMuLink = prevMuInfo.at(0).link;
77  ATH_CHECK(prevMuLink.isValid());
78  muonPrev = *prevMuLink;
79  }
80 
81  //loop over muons (more than one muon can be found by EF algos)
82  for(uint i=0; i<muonHandle->size(); i++){
83  auto muonEL = ViewHelper::makeLink( *viewEL, muonHandle, i );
84  ATH_CHECK( muonEL.isValid() );
85 
86  const xAOD::Muon* muon = *muonEL;
87  //skip SA muons if we are looking only for combined muons
88  if(muon->author()==5 && !m_inclSAmuons) continue;
89 
90  //Map muons to the correct decisions from previous step
91  bool matchedToDec = false;
92  if(m_mapToPrevDec){
93  //Check if the combined muon has an extrapolated track particle
94  //and if so whether it matches the SA track from the previous decision's muon
95  //This won't work for inside-out muons
96  if(muon->author()!=6){
97  auto trk1 = muon->trackParticle(xAOD::Muon::TrackParticleType::MuonSpectrometerTrackParticle);
98  auto trk2 = muonPrev->trackParticle(xAOD::Muon::TrackParticleType::MuonSpectrometerTrackParticle);
99  if(trk1 && trk2){
100  if(trk1->p4()==trk2->p4()){
101  matchedToDec = true;
102  }
103  }
104  }
105  else{
106  //For muons reconstructed by InsideOutRecoAlg, extrapolated track will
107  //not be identical to standard SA muon from previous step so
108  //do dR matching. dR<0.05 should be sufficient to get correct matching
109  double dr = muon->p4().DeltaR(muonPrev->p4());
110  if(dr<0.05) matchedToDec = true;
111  }
112  }
113  else matchedToDec = true;
114 
115  //skip muons not corresponding to previous decisions
116  if(!matchedToDec) continue;
117 
118  // create new decisions
119  auto newd = newDecisionIn( decisions, hypoAlgNodeName() );
120 
121  // push_back to toolInput
122  toolInput.emplace_back( newd, muon, previousDecision );
123 
124  newd -> setObjectLink( featureString(), muonEL );
125  TrigCompositeUtils::linkToPrevious( newd, previousDecision, context );
126 
127  ATH_MSG_DEBUG("REGTEST: " << m_muonKey.key() << " pT = " << (*muonEL)->pt()/Gaudi::Units::GeV << " GeV, author: "<<(*muonEL)->author());
128  ATH_MSG_DEBUG("REGTEST: " << m_muonKey.key() << " eta/phi = " << (*muonEL)->eta() << "/" << (*muonEL)->phi());
129  ATH_MSG_DEBUG("Added view, feature, previous decision to new decision "<<counter <<" for view "<<(*viewEL)->name() );
130 
131  //found muon partnered to previous decision, so don't need to consider the other muons
132  if(m_mapToPrevDec) break;
133  }
134  counter++;
135  }
136 
137  ATH_MSG_DEBUG("Found "<<toolInput.size()<<" inputs to tools");
138 
139  // to TrigMuonEFHypoTool
140  StatusCode sc = StatusCode::SUCCESS;
141  for ( auto& tool: m_hypoTools ) {
142  ATH_MSG_DEBUG("Go to " << tool );
143  sc = tool->decide(toolInput);
144  if (!sc.isSuccess()) {
145  ATH_MSG_ERROR("MuonHypoTool is failed");
146  return StatusCode::FAILURE;
147  }
148  } // End of tool algorithms */
149 
150  ATH_CHECK(hypoBaseOutputProcessing(outputHandle));
151 
152  ATH_MSG_DEBUG("StatusCode TrigMuonEFHypoAlg::execute success");
153  return StatusCode::SUCCESS;
154 }
155 
156 
157 // --------------------------------------------------------------------------------
158 // --------------------------------------------------------------------------------
159 
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
xAOD::Muon_v1::trackParticle
const TrackParticle * trackParticle(TrackParticleType type) const
Returns a pointer (which can be NULL) to the TrackParticle used in identification of this muon.
Definition: Muon_v1.cxx:504
xAOD::Muon_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: Muon_v1.cxx:79
TrigMuonEFHypoAlg::m_inclSAmuons
Gaudi::Property< bool > m_inclSAmuons
Definition: TrigMuonEFHypoAlg.h:33
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
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
TrigMuonEFHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrigMuonEFHypoAlg.cxx:36
TrigMuonEFHypoAlg::m_hypoTools
ToolHandleArray< TrigMuonEFHypoTool > m_hypoTools
Definition: TrigMuonEFHypoAlg.h:27
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
TrigMuonEFHypoAlg::initialize
virtual StatusCode initialize() override
Definition: TrigMuonEFHypoAlg.cxx:23
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
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrigMuonEFHypoAlg::m_muonKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonKey
Definition: TrigMuonEFHypoAlg.h:29
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:81
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:886
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
TrigMuonEFHypoAlg.h
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
TrigMuonEFHypoAlg::m_mapToPrevDec
Gaudi::Property< bool > m_mapToPrevDec
Definition: TrigMuonEFHypoAlg.h:31
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
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
TrigMuonEFHypoAlg::TrigMuonEFHypoAlg
TrigMuonEFHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigMuonEFHypoAlg.cxx:13
ViewContainer
Definition: View.h:161