ATLAS Offline Software
Loading...
Searching...
No Matches
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"
7
8using namespace TrigCompositeUtils;
9
10// --------------------------------------------------------------------------------
11// --------------------------------------------------------------------------------
12
13TrigMuonEFHypoAlg::TrigMuonEFHypoAlg( const std::string& name,
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
36StatusCode 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;
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;
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
unsigned int uint
static Double_t sc
DataVector< SG::View > ViewContainer
View container for recording in StoreGate.
Definition View.h:290
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
pointer_type ptr()
Dereference the pointer.
SG::ReadHandleKey< xAOD::MuonContainer > m_muonKey
Gaudi::Property< bool > m_mapToPrevDec
virtual StatusCode execute(const EventContext &context) const override
TrigMuonEFHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
ToolHandleArray< TrigMuonEFHypoTool > m_hypoTools
Gaudi::Property< bool > m_inclSAmuons
virtual StatusCode initialize() override
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition Muon_v1.cxx:71
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:482
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()
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
void findLinks(const Decision *start, const std::string &linkName, std::vector< LinkInfo< T > > &links, unsigned int behaviour=TrigDefs::allFeaturesOfType, std::set< const xAOD::TrigComposite * > *fullyExploredFrom=nullptr)
search back the TC links for the object of type T linked to the one of TC (recursively) Populates pro...
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.
static const unsigned int lastFeatureOfType
Run 3 "enum". Only return the final feature along each route through the navigation.
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
Muon_v1 Muon
Reference the current persistent version: