ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
PrimaryDPDMaker
src
muonTrkTrackThinTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 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/ThinningHandle.h
"
19
20
21
#include "
PrimaryDPDMaker/muonTrkTrackThinTool.h
"
22
//#include "AthenaKernel/errorcheck.h"
23
#include <vector>
24
#include <string>
25
26
// xAOD containers
27
#include "
xAODMuon/MuonContainer.h
"
28
#include "
xAODTracking/TrackParticleContainer.h
"
29
30
// Constructor
31
muonTrkTrackThinTool::muonTrkTrackThinTool
(
const
std::string& name,ISvcLocator* pSvcLocator):
32
AthReentrantAlgorithm
(name, pSvcLocator) {
33
}
34
// Athena initialize and finalize
35
StatusCode
muonTrkTrackThinTool::initialize
()
36
{
37
ATH_MSG_VERBOSE
(
"initialize() ..."
);
38
ATH_CHECK
(
m_trackCollKey
.initialize (
m_streamName
) );
39
ATH_CHECK
(
m_muonReadKey
.initialize());
40
return
StatusCode::SUCCESS;
41
}
42
43
StatusCode
muonTrkTrackThinTool::finalize
()
44
{
45
ATH_MSG_VERBOSE
(
"finalize() ..."
);
46
ATH_MSG_INFO
(
"muonTrkTrackThinTool Filter number of muons PASSED "
<<
m_pass
<<
" FROM "
<<
m_All
);
47
ATH_MSG_INFO
(
"muonTrkTrackThinTool Filter number of Trk::Track PASSED "
<<
m_trackpass
<<
" FROM "
<<
m_trackAll
);
48
return
StatusCode::SUCCESS;
49
}
50
51
// The thinning itself
52
StatusCode
muonTrkTrackThinTool::execute
(
const
EventContext& ctx )
const
{
53
54
SG::ThinningHandle<TrackCollection>
alltracks (
m_trackCollKey
, ctx);
55
56
if
(alltracks->empty()){
57
ATH_MSG_DEBUG
(
"------------- Track Collection is empty, collection type: "
<<
m_trackCollKey
.key());
58
return
StatusCode::SUCCESS;
59
}
60
61
std::vector<bool> mask_t;
62
mask_t.resize(alltracks->size(),
false
);
63
m_trackAll
+= alltracks->size();
64
65
// Retrieve the muons:
66
SG::ReadHandle<xAOD::MuonContainer>
muonHandle(
m_muonReadKey
, ctx);
67
if
(!muonHandle.
isValid
()){
68
ATH_MSG_ERROR
(
"Could not read "
<<
m_muonReadKey
);
69
return
StatusCode::FAILURE;
70
}
71
72
const
xAOD::MuonContainer
* muons = muonHandle.
cptr
();
73
74
75
m_All
+= muons->
size
();
76
77
// Loop over muon:
78
for
(
const
auto
* muon : *muons ) {
79
m_pass
++;
80
const
xAOD::TrackParticle
* muon_tp = 0;
81
//Needed the below 'if' statements to separate trackparticle cases
82
if
(
m_trackCollKey
.key() ==
"MuonSpectrometerTracks"
)
83
muon_tp = muon->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle);
84
85
if
(
m_trackCollKey
.key() ==
"CombinedMuonTracks"
)
86
muon_tp = muon->trackParticle(xAOD::Muon::CombinedTrackParticle);
87
88
if
(
m_trackCollKey
.key() ==
"MSOnlyExtrapolatedTracks"
)
89
muon_tp = muon->trackParticle(xAOD::Muon::MSOnlyExtrapolatedMuonSpectrometerTrackParticle);
90
91
if
(
m_trackCollKey
.key() ==
"ExtrapolatedMuonTracks"
)
92
muon_tp = muon->trackParticle(xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle);
93
94
95
if
(!muon_tp) {
96
ATH_MSG_DEBUG
(
"------------- No muon track particle "
);
97
continue
;
// segtagged muons
98
}
99
100
//using element link rather than "const Trk::Track* muontr = muontp->track();"
101
//avoids an additional loop over track collection
102
const
ElementLink< TrackCollection >
& muontr_link = muon_tp->
trackLink
();
103
if
(!muontr_link.
isValid
()){
104
ATH_MSG_DEBUG
(
"------------- Elementlink from trackparticle to trk::track not valid"
);
105
continue
;
//This shouldn't happen
106
}
107
108
int
trIndex = muontr_link.
index
();
109
if
(trIndex <
int
(mask_t.size())){
110
mask_t[trIndex] =
true
;
111
m_trackpass
++;
112
}
113
}
//close muon loop
114
115
116
alltracks.
keep
(mask_t);
117
118
return
StatusCode::SUCCESS;
119
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x,...)
Definition
AthMsgStreamMacros.h:43
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x,...)
Definition
AthMsgStreamMacros.h:42
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
MuonContainer.h
TrackParticleContainer.h
ThinningHandle.h
Handle for requesting thinning for a data object.
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
ElementLink< TrackCollection >
ElementLink::index
index_type index() const
Get the index of the element inside of its container.
Definition
A/AthLinks/ElementLink.h:164
ElementLink::isValid
bool isValid() const
Check if the element can be found.
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ThinningHandleBase::keep
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Definition
ThinningHandleBase.cxx:75
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition
ThinningHandle.h:84
muonTrkTrackThinTool::finalize
virtual StatusCode finalize() override
Definition
muonTrkTrackThinTool.cxx:43
muonTrkTrackThinTool::m_All
std::atomic< int > m_All
Definition
muonTrkTrackThinTool.h:36
muonTrkTrackThinTool::muonTrkTrackThinTool
muonTrkTrackThinTool(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters.
Definition
muonTrkTrackThinTool.cxx:31
muonTrkTrackThinTool::m_muonReadKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonReadKey
Definition
muonTrkTrackThinTool.h:47
muonTrkTrackThinTool::m_trackCollKey
SG::ThinningHandleKey< TrackCollection > m_trackCollKey
Definition
muonTrkTrackThinTool.h:44
muonTrkTrackThinTool::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
muonTrkTrackThinTool.cxx:52
muonTrkTrackThinTool::m_trackAll
std::atomic< int > m_trackAll
Definition
muonTrkTrackThinTool.h:38
muonTrkTrackThinTool::initialize
virtual StatusCode initialize() override
Definition
muonTrkTrackThinTool.cxx:35
muonTrkTrackThinTool::m_pass
std::atomic< int > m_pass
Definition
muonTrkTrackThinTool.h:37
muonTrkTrackThinTool::m_trackpass
std::atomic< int > m_trackpass
Definition
muonTrkTrackThinTool.h:39
muonTrkTrackThinTool::m_streamName
StringProperty m_streamName
Definition
muonTrkTrackThinTool.h:42
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:730
muonTrkTrackThinTool.h
xAOD::TrackParticle
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Definition
Event/xAOD/xAODTracking/xAODTracking/TrackParticle.h:13
xAOD::MuonContainer
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
Definition
Event/xAOD/xAODMuon/xAODMuon/MuonContainer.h:14
Generated on
for ATLAS Offline Software by
1.17.0