ATLAS Offline Software
muonTrkTrackThinTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // muonTrkTrackThinTool.cxx, (c) ATLAS Detector software
8 // Author: Saminder Dhaliwal (s.dhaliwal@cern.ch)
9 // Follows closely from dimuonTaggingTool and DerviationFrameworkExamples
10 
11 // STL includes
12 #include <algorithm>
13 #include <iostream>
14 
15 // FrameWork includes
16 #include "Gaudi/Property.h"
17 // StoreGate
18 #include "StoreGate/DataHandle.h"
20 #include "GaudiKernel/ThreadLocalContext.h"
21 
22 
24 //#include "AthenaKernel/errorcheck.h"
25 #include <vector>
26 #include <string>
27 
28 // xAOD containers
29 #include "xAODMuon/MuonContainer.h"
31 
32 // Constructor
33 muonTrkTrackThinTool::muonTrkTrackThinTool(const std::string& name,ISvcLocator* pSvcLocator):
34  AthReentrantAlgorithm (name, pSvcLocator) {
35 }
36 // Athena initialize and finalize
38 {
39  ATH_MSG_VERBOSE("initialize() ...");
40  ATH_CHECK( m_trackCollKey.initialize (m_streamName) );
41  ATH_CHECK( m_muonReadKey.initialize());
42  return StatusCode::SUCCESS;
43 }
44 
46 {
47  ATH_MSG_VERBOSE("finalize() ...");
48  ATH_MSG_INFO("muonTrkTrackThinTool Filter number of muons PASSED "<<m_pass<<" FROM "<< m_All);
49  ATH_MSG_INFO("muonTrkTrackThinTool Filter number of Trk::Track PASSED "<<m_trackpass<<" FROM "<< m_trackAll);
50  return StatusCode::SUCCESS;
51 }
52 
53 // The thinning itself
54 StatusCode muonTrkTrackThinTool::execute(const EventContext& ctx ) const {
55 
57 
58  if (alltracks->empty()){
59  ATH_MSG_DEBUG( "------------- Track Collection is empty, collection type: " << m_trackCollKey.key());
60  return StatusCode::SUCCESS;
61  }
62 
63  std::vector<bool> mask_t;
64  mask_t.resize(alltracks->size(), false);
65  m_trackAll+= alltracks->size();
66 
67  // Retrieve the muons:
69  if(!muonHandle.isValid()){
70  ATH_MSG_ERROR("Could not read "<< m_muonReadKey);
71  return StatusCode::FAILURE;
72  }
73 
74  const xAOD::MuonContainer* muons = muonHandle.cptr();
75 
76 
77  m_All+= muons->size();
78 
79  // Loop over muon:
80  for( const auto* muon : *muons ) {
81  m_pass++;
82  const xAOD::TrackParticle* muon_tp = 0;
83  //Needed the below 'if' statements to separate trackparticle cases
84  if (m_trackCollKey.key() == "MuonSpectrometerTracks")
85  muon_tp = muon->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle);
86 
87  if (m_trackCollKey.key() == "CombinedMuonTracks")
88  muon_tp = muon->trackParticle(xAOD::Muon::CombinedTrackParticle);
89 
90  if (m_trackCollKey.key() == "MSOnlyExtrapolatedTracks")
91  muon_tp = muon->trackParticle(xAOD::Muon::MSOnlyExtrapolatedMuonSpectrometerTrackParticle);
92 
93  if (m_trackCollKey.key() == "ExtrapolatedMuonTracks")
94  muon_tp = muon->trackParticle(xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle);
95 
96 
97  if (!muon_tp) {
98  ATH_MSG_DEBUG( "------------- No muon track particle " );
99  continue; // segtagged muons
100  }
101 
102  //using element link rather than "const Trk::Track* muontr = muontp->track();"
103  //avoids an additional loop over track collection
104  const ElementLink< TrackCollection >& muontr_link = muon_tp->trackLink();
105  if (!muontr_link.isValid()){
106  ATH_MSG_DEBUG("------------- Elementlink from trackparticle to trk::track not valid");
107  continue; //This shouldn't happen
108  }
109 
110  int trIndex = muontr_link.index();
111  if (trIndex < int(mask_t.size())){
112  mask_t[trIndex] = true;
113  m_trackpass++;
114  }
115  }//close muon loop
116 
117 
118  alltracks.keep (mask_t);
119 
120  return StatusCode::SUCCESS;
121 }
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
ThinningHandle.h
Handle for requesting thinning for a data object.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
muonTrkTrackThinTool::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: muonTrkTrackThinTool.cxx:54
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
DataHandle.h
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
muonTrkTrackThinTool::m_pass
std::atomic< int > m_pass
Definition: muonTrkTrackThinTool.h:37
Run1::Chip::mask_t
cool::Int32 mask_t
Definition: openCoraCool.cxx:63
SG::ThinningHandleBase::keep
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Definition: ThinningHandleBase.cxx:68
muonTrkTrackThinTool::m_All
std::atomic< int > m_All
Definition: muonTrkTrackThinTool.h:36
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
muonTrkTrackThinTool::initialize
virtual StatusCode initialize() override
Definition: muonTrkTrackThinTool.cxx:37
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
muonTrkTrackThinTool.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
muonTrkTrackThinTool::m_trackCollKey
SG::ThinningHandleKey< TrackCollection > m_trackCollKey
Definition: muonTrkTrackThinTool.h:44
xAOD::TrackParticle_v1::trackLink
const ElementLink< TrackCollection > & trackLink() const
Returns a link (which can be invalid) to the Trk::Track which was used to make this TrackParticle.
Definition: TrackParticle_v1.cxx:779
muonTrkTrackThinTool::m_trackAll
std::atomic< int > m_trackAll
Definition: muonTrkTrackThinTool.h:38
MuonContainer.h
muonTrkTrackThinTool::m_trackpass
std::atomic< int > m_trackpass
Definition: muonTrkTrackThinTool.h:39
muonTrkTrackThinTool::muonTrkTrackThinTool
muonTrkTrackThinTool(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters.
Definition: muonTrkTrackThinTool.cxx:33
muonTrkTrackThinTool::finalize
virtual StatusCode finalize() override
Definition: muonTrkTrackThinTool.cxx:45
muonTrkTrackThinTool::m_streamName
StringProperty m_streamName
Definition: muonTrkTrackThinTool.h:42
muonTrkTrackThinTool::m_muonReadKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonReadKey
Definition: muonTrkTrackThinTool.h:47
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrackParticleContainer.h