ATLAS Offline Software
TrigMuonEFIdtpHypoAlg.cxx
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "TrigMuonEFIdtpCommon.h"
7 #include "AthViews/ViewHelper.h"
8 
9 using namespace TrigCompositeUtils;
10 
11 // --------------------------------------------------------------------------------
12 // --------------------------------------------------------------------------------
13 
15  ISvcLocator* pSvcLocator ) :
16  ::HypoBase( name, pSvcLocator ) { }
17 
18 // --------------------------------------------------------------------------------
19 // --------------------------------------------------------------------------------
20 
22 {
23  ATH_CHECK(m_hypoTools.retrieve());
24 
27 
30 
31  return StatusCode::SUCCESS;
32 }
33 
34 // --------------------------------------------------------------------------------
35 // --------------------------------------------------------------------------------
36 
37 StatusCode TrigMuonEFIdtpHypoAlg::execute( const EventContext& context ) const
38 {
39  ATH_MSG_DEBUG("StatusCode TrigMuonEFIdtpHypoAlg::execute start");
40 
41  // common for all hypos, to move in the base class
42  auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
43  ATH_CHECK( previousDecisionsHandle.isValid() );
44  ATH_MSG_DEBUG("Running with "<< previousDecisionsHandle->size() <<" previous decisions");
45 
46  // new output decisions
48  auto decisions = outputHandle.ptr();
49 
50  std::vector<TrigMuonEFIdtpHypoTool::MuonEFIdperfInfo> toolInput;
51  int counter = -1;
52 
53  // loop over previous decisions
54  for ( const auto previousDecision: *previousDecisionsHandle ) {
55 
56  ATH_MSG_VERBOSE("--- counter: "<<++counter<<" ---");
57 
58  // get view
59  auto viewEL = previousDecision->objectLink<ViewContainer>( viewString() );
60  ATH_CHECK( viewEL.isValid() );
61 
62  // get ID tracks
63  auto ptTrkHandle = ViewHelper::makeHandle( *viewEL, m_PTTracksKey, context );
64  ATH_CHECK( ptTrkHandle.isValid() );
65  if( ptTrkHandle->size()==0 ) {
66  ATH_MSG_VERBOSE("No PT track handle, skipping this decision");
67  continue;
68  }
69  auto ftfTrkHandle = ViewHelper::makeHandle( *viewEL, m_FTFTracksKey, context );
70  ATH_CHECK( ftfTrkHandle.isValid() );
71  if( ftfTrkHandle->size()==0 ) {
72  ATH_MSG_VERBOSE("No FTF track handle, skipping this decision");
73  continue;
74  }
75 
76  // get SA muon from the previous decision
77  const xAOD::Muon *muonSA = nullptr;
78  auto prevMuInfo = TrigCompositeUtils::findLinks<xAOD::MuonContainer>(previousDecision, TrigCompositeUtils::featureString(), TrigDefs::lastFeatureOfType);
79  ATH_CHECK(prevMuInfo.size()==1);
80  auto muonSALink = prevMuInfo.at(0).link;
81  ATH_CHECK( muonSALink.isValid() );
82  muonSA = *muonSALink;
83  if( muonSA->muonType() != xAOD::Muon::MuonType::MuonStandAlone ) {
84  ATH_MSG_VERBOSE("previous decision muon is not SA, skipping this decision");
85  continue;
86  }
87  const xAOD::TrackParticle* metrack = muonSA->trackParticle( xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle );
88  ATH_MSG_VERBOSE("muonSA: muonType="<<muonSA->muonType()<<", pT="<<muonSA->pt()/1000.0<<", eta="<<muonSA->eta()<<", phi="<<muonSA->phi()<<", author="<<muonSA->author());
89 
90  // select PT track
91  float dRmin = 999;
92  const xAOD::TrackParticle* thePTTrack = nullptr;
93  std::vector<ElementLink<xAOD::TrackParticleContainer>> thePTTrackLinks;
94  const xAOD::TrackParticleContainer * ptTracks = ptTrkHandle.get();
95  ATH_MSG_VERBOSE("PT tracks size: " << ptTracks->size());
96  for ( const xAOD::TrackParticle* idtrack : *ptTracks ) {
97  if (idtrack->pt()< 1*Gaudi::Units::GeV ) continue;
98  float dr = TrigMuonEFIdtpCommon::matchingMetric(metrack,idtrack);
99  if( dr < dRmin ) {
100  dRmin = dr;
101  thePTTrack = idtrack;
102  }
103  }
104  if( thePTTrack != nullptr ) {
105  auto idtrackLink = ElementLink<xAOD::TrackParticleContainer>(*ptTracks,thePTTrack->index());
106  ATH_CHECK( idtrackLink.isValid() );
107  thePTTrackLinks.push_back(idtrackLink);
108  ATH_MSG_VERBOSE("... best selected PT track pt / eta / phi / dr = " << thePTTrack->pt()/Gaudi::Units::GeV << " / " << thePTTrack->eta() << " / " << thePTTrack->phi() << " / " << dRmin << ", fitter=" << thePTTrack->trackFitter());
109  }
110 
111  // FTF track
112  dRmin = 999;
113  const xAOD::TrackParticle* theFTFTrack = nullptr;
114  std::vector<ElementLink<xAOD::TrackParticleContainer>> theFTFTrackLinks;
115  const xAOD::TrackParticleContainer * ftfTracks = ftfTrkHandle.get();
116  ATH_MSG_VERBOSE("FTF tracks size: " << ftfTracks->size());
117  for ( const xAOD::TrackParticle* idtrack : *ftfTracks ) {
118  if (idtrack->pt()< 1*Gaudi::Units::GeV ) continue;
119  float dr = TrigMuonEFIdtpCommon::matchingMetric(metrack,idtrack);
120  if( dr < dRmin ) {
121  dRmin = dr;
122  theFTFTrack = idtrack;
123  }
124  }
125  if( theFTFTrack != nullptr ) {
126  auto idtrackLink = ElementLink<xAOD::TrackParticleContainer>(*ftfTracks,theFTFTrack->index());
127  ATH_CHECK( idtrackLink.isValid() );
128  theFTFTrackLinks.push_back(idtrackLink);
129  ATH_MSG_VERBOSE("... best selected FTF track pt / eta / phi / dr = " << theFTFTrack->pt()/Gaudi::Units::GeV << " / " << theFTFTrack->eta() << " / " << theFTFTrack->phi() << " / " << dRmin << ", fitter=" << theFTFTrack->trackFitter());
130  }
131 
132  // create new decisions
133  auto newd = newDecisionIn( decisions, hypoAlgNodeName() );
134 
135  // push_back to toolInput
136  toolInput.emplace_back( newd, muonSA, thePTTrack, theFTFTrack, previousDecision );
137 
138  newd -> setObjectLink( featureString(), muonSALink );
139  newd -> addObjectCollectionLinks( m_PTTracksKey.key(), thePTTrackLinks );
140  newd -> addObjectCollectionLinks( m_FTFTracksKey.key(), theFTFTrackLinks );
141  ATH_MSG_VERBOSE("Setting object link for PT / FTF track: size="<<thePTTrackLinks.size()<<" / "<<theFTFTrackLinks.size());
142  TrigCompositeUtils::linkToPrevious( newd, previousDecision, context );
143  }
144 
145  ATH_MSG_DEBUG("Found "<<toolInput.size()<<" inputs to tools");
146 
147  // to TrigMuonEFIdtpHypoTool
148  StatusCode sc = StatusCode::SUCCESS;
149  for ( auto& tool: m_hypoTools ) {
150  ATH_MSG_DEBUG("Go to " << tool );
151  sc = tool->decide(toolInput);
152  if (!sc.isSuccess()) {
153  ATH_MSG_ERROR("MuonHypoTool is failed");
154  return StatusCode::FAILURE;
155  }
156  } // End of tool algorithms */
157 
158  ATH_CHECK(hypoBaseOutputProcessing(outputHandle));
159 
160  ATH_MSG_DEBUG("StatusCode TrigMuonEFIdtpHypoAlg::execute success");
161  return StatusCode::SUCCESS;
162 }
163 
164 // --------------------------------------------------------------------------------
165 // --------------------------------------------------------------------------------
xAOD::TrackParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TrackParticle_v1.cxx:73
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
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
TrigMuonEFIdtpHypoAlg::m_hypoTools
ToolHandleArray< TrigMuonEFIdtpHypoTool > m_hypoTools
Definition: TrigMuonEFIdtpHypoAlg.h:26
xAOD::TrackParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TrackParticle_v1.cxx:77
xAOD::Muon_v1::phi
virtual double phi() const
The azimuthal angle ( ) of the particle.
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
xAOD::Muon_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
TrigMuonEFIdtpHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrigMuonEFIdtpHypoAlg.cxx:37
DataVector::get
const T * get(size_type n) const
Access an element, as an rvalue.
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
TrigMuonEFIdtpHypoAlg::m_PTTracksKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_PTTracksKey
Definition: TrigMuonEFIdtpHypoAlg.h:28
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
xAOD::Muon_v1::author
Author author() const
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
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
xAOD::TrackParticle_v1::trackFitter
TrackFitter trackFitter() const
Returns the fitter.
Definition: TrackParticle_v1.cxx:698
TrigMuonEFIdtpCommon.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
xAOD::Muon_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
TrigMuonEFIdtpHypoAlg::initialize
virtual StatusCode initialize() override
Definition: TrigMuonEFIdtpHypoAlg.cxx:21
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
DataVector< xAOD::TrackParticle_v1 >
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:81
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:886
TrigMuonEFIdtpHypoAlg.h
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
TrigMuonEFIdtpHypoAlg::m_FTFTracksKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_FTFTracksKey
Definition: TrigMuonEFIdtpHypoAlg.h:29
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
TrigMuonEFIdtpHypoAlg::TrigMuonEFIdtpHypoAlg
TrigMuonEFIdtpHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigMuonEFIdtpHypoAlg.cxx:14
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
test_pyathena.counter
counter
Definition: test_pyathena.py:15
TrigMuonEFIdtpCommon::matchingMetric
float matchingMetric(const xAOD::TrackParticle *metrack, const xAOD::TrackParticle *idtrack)
Definition: TrigMuonEFIdtpCommon.cxx:36
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrigCompositeUtils::viewString
const std::string & viewString()
Definition: TrigCompositeUtilsRoot.cxx:882
xAOD::TrackParticle_v1::phi
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .)
xAOD::Muon_v1::muonType
MuonType muonType() const
ViewContainer
Definition: View.h:161