ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkBPhys
src
Thin_vtxTrk.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
// Thin_vtxTrk.cxx
8
// Author: James Catmore (James.Catmore@cern.ch)
9
// This is a trivial example of an implementation of a thinning tool
10
// which removes all ID tracks which do not pass a user-defined cut
11
12
#include "
Thin_vtxTrk.h
"
13
14
#include "
xAODBPhys/BPhysHypoHelper.h
"
15
#include "
StoreGate/ThinningHandle.h
"
16
#include <vector>
17
#include <string>
18
// Constructor
19
DerivationFramework::Thin_vtxTrk::Thin_vtxTrk
(
const
std::string& t,
const
std::string& n,
const
IInterface* p ) :
20
base_class(t,n,p),
21
m_ntot
(0),
22
m_npass
(0),
23
m_acceptanceR
(-1.),
// Do not add tracks within a cone from the vertex by default
24
m_nVtxTot
(0),
25
m_nVtxPass
(0),
26
m_noFlags
(false)
27
{
28
declareProperty(
"TrackParticleContainerName"
,
m_trackParticleContainerName
=
"InDetTrackParticles"
);
29
declareProperty(
"VertexContainerNames"
,
m_vertexContainerName
);
30
declareProperty(
"PassFlags"
,
m_passFlags
);
31
declareProperty(
"AcceptanceRadius"
,
m_acceptanceR
);
32
declareProperty(
"IgnoreFlags"
,
m_noFlags
);
33
declareProperty(
"ThinTracks"
,
m_thinTracks
=
true
);
34
}
35
36
// Destructor
37
DerivationFramework::Thin_vtxTrk::~Thin_vtxTrk
() =
default
;
38
39
// Athena initialize and finalize
40
StatusCode
DerivationFramework::Thin_vtxTrk::initialize
()
41
{
42
// Decide which collections need to be checked for ID TrackParticles
43
ATH_MSG_VERBOSE
(
"initialize() ..."
);
44
ATH_CHECK
(
m_trackParticleContainerName
.initialize(
m_streamName
));
45
46
47
if
(
m_noFlags
){
48
ATH_MSG_INFO
(
"IgnoreFlags is set, all vertices in the container will be kept"
);
49
}
50
51
if
( !
m_noFlags
){
52
if
(
m_passFlags
.empty()) {
53
ATH_MSG_FATAL
(
"No pass flags provided for thinning."
);
54
return
StatusCode::FAILURE;
55
}
else
{
56
for
(
auto
itr =
m_passFlags
.begin(); itr!=
m_passFlags
.end(); ++itr) {
57
ATH_MSG_INFO
(
"Vertices must pass the \""
<< *itr <<
"\" selection"
);
58
}
59
}
60
}
61
62
if
(
m_acceptanceR
> 0.) {
63
ATH_MSG_INFO
(
"Extra tracks must be within cone of "
<<
m_acceptanceR
<<
" from vertex candidate."
);
64
}
65
66
for
(
auto
&handle :
m_vertexContainerName
){
67
ATH_CHECK
(handle.initialize(
m_streamName
));
68
}
69
for
(
const
auto
&tracknames :
m_vertexContainerName
){
70
for
(
const
auto
&
str
:
m_passFlags
){
71
m_passArray
.emplace_back(tracknames.key() +
'.'
+
str
);
72
}
73
}
74
ATH_CHECK
(
m_passArray
.initialize());
75
return
StatusCode::SUCCESS;
76
}
77
78
StatusCode
DerivationFramework::Thin_vtxTrk::finalize
()
79
{
80
ATH_MSG_VERBOSE
(
"finalize() ..."
);
81
ATH_MSG_INFO
(
"Processed "
<<
m_ntot
<<
" tracks, "
<<
m_npass
<<
" were retained "
);
82
ATH_MSG_INFO
(
"Processed "
<<
m_nVtxTot
<<
" vertices, "
<<
m_nVtxPass
<<
" were retained "
);
83
84
return
StatusCode::SUCCESS;
85
}
86
87
// The thinning itself
88
StatusCode
DerivationFramework::Thin_vtxTrk::doThinning
(
const
EventContext& ctx)
const
89
{
90
// Retrieve main TrackParticle collection
91
SG::ThinningHandle<xAOD::TrackParticleContainer>
importedTrackParticles(
m_trackParticleContainerName
, ctx);
92
93
// Check the event contains tracks
94
unsigned
int
nTracks = importedTrackParticles->size();
95
if
(nTracks==0)
return
StatusCode::SUCCESS;
96
97
// Set up a trackMask with the same entries as the full TrackParticle collection
98
std::vector<bool> trackMask(nTracks,
false
);
// default: don't keep any tracks
99
m_ntot
+= nTracks;
100
int
nVtxTot =0;
101
int
nVtxPass=0;
102
103
std::unordered_map<std::string, SG::ReadDecorHandle<xAOD::VertexContainer, Char_t>> handles;
104
handles.reserve(
m_passArray
.size());
105
for
(
const
auto
&key :
m_passArray
){
106
auto
it = handles.emplace(std::piecewise_construct, std::forward_as_tuple(key.key()), std::forward_as_tuple(key, ctx));
107
if
(!(*it.first).second.isPresent())
return
StatusCode::FAILURE;
108
}
109
110
// retieve vertex
111
for
(
const
auto
& name :
m_vertexContainerName
){
112
SG::ThinningHandle<xAOD::VertexContainer>
vertexContainer(name, ctx);
113
std::vector<bool> vtxMask(vertexContainer->size(),
false
);
// default: don't keep any vertices
114
115
// loop over vertices
116
int
k = 0;
117
for
(
auto
vtxItr = vertexContainer->begin(); vtxItr!=vertexContainer->end(); ++vtxItr, ++k) {
118
const
xAOD::Vertex
* vtx = *vtxItr;
119
nVtxTot++;
120
121
// check if the vertex passed the required selections criteria
122
bool
passed
=
false
;
123
for
(std::vector<std::string>::const_iterator flagItr =
m_passFlags
.begin(); flagItr!=
m_passFlags
.end(); ++flagItr) {
124
std::string lookupstr = name.key() +
'.'
+ (*flagItr);
125
const
auto
& handle = handles.at(lookupstr);
126
if
(handle(*vtx) != 0) {
127
passed
=
true
;
128
break
;
129
}
130
}
// end of loop over flags
131
132
if
(
passed
||
m_noFlags
) {
133
// vertex passed the selection
134
vtxMask[k] =
true
;
135
nVtxPass++;
136
137
// Add tracks according to DR selection
138
if
(
m_acceptanceR
> 0.){
139
140
// determine the sum of the tracks at vertex as centre for the cone
141
TLorentzVector centreCandidate;
142
for
(
uint
j=0; j<vtx->
nTrackParticles
(); ++j) {
143
centreCandidate += vtx->
trackParticle
(j)->
p4
();
144
}
145
146
for
(
uint
i=0; i<nTracks; ++i) {
147
if
(!trackMask[i]) {
// do this only for tracks that haven't been selected, yet
148
const
xAOD::TrackParticle
* track = (*importedTrackParticles)[i];
149
if
(centreCandidate.DeltaR(track->p4()) <
m_acceptanceR
) trackMask[i]=
true
;
150
}
151
}
152
}
// end adding tracks according to DR selection
153
154
if
(
m_thinTracks
) {
155
// loop over all tracks
156
for
(
uint
i=0; i<nTracks; ++i) {
157
if
(!trackMask[i]) {
// do this only for tracks that haven't been selected, yet
158
const
xAOD::TrackParticle
* track = (*importedTrackParticles)[i];
159
// loop over tracks at vertex
160
for
(
uint
j=0; j<vtx->
nTrackParticles
(); ++j) {
161
if
(vtx->
trackParticle
(j) == track) {
162
trackMask[i] =
true
;
// accept track
163
}
164
}
// end of loop over tracks at vertex
165
}
166
}
// end of loop over all tracks
167
}
168
}
169
}
// end of loop over vertices
170
171
// Execute the thinning service based on the vtxMask.
172
vertexContainer.
keep
(vtxMask);
173
}
174
175
// Count up the trackMask contents
176
m_npass
+= std::accumulate(trackMask.begin(), trackMask.end(), 0);
177
m_nVtxTot
+= nVtxTot;
178
m_nVtxPass
+= nVtxPass;
179
if
(
m_thinTracks
||
m_acceptanceR
> 0.) {
180
// Execute the thinning service based on the trackMask. Finish.
181
importedTrackParticles.
keep
(trackMask);
182
}
183
184
return
StatusCode::SUCCESS;
185
}
186
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
BPhysHypoHelper.h
: B-physics xAOD helpers.
passed
bool passed(DecisionID id, const DecisionIDContainer &)
checks if required decision ID is in the set of IDs in the container
Definition
TrigCompositeUtilsRoot.cxx:118
uint
unsigned int uint
Definition
LArOFPhaseFill.cxx:19
Thin_vtxTrk.h
ThinningHandle.h
Handle for requesting thinning for a data object.
DerivationFramework::Thin_vtxTrk::m_streamName
StringProperty m_streamName
Definition
Thin_vtxTrk.h:38
DerivationFramework::Thin_vtxTrk::m_nVtxTot
std::atomic< unsigned int > m_nVtxTot
Definition
Thin_vtxTrk.h:41
DerivationFramework::Thin_vtxTrk::m_noFlags
bool m_noFlags
Definition
Thin_vtxTrk.h:48
DerivationFramework::Thin_vtxTrk::m_npass
std::atomic< unsigned int > m_npass
Definition
Thin_vtxTrk.h:39
DerivationFramework::Thin_vtxTrk::m_passArray
SG::ReadDecorHandleKeyArray< xAOD::VertexContainer > m_passArray
Definition
Thin_vtxTrk.h:46
DerivationFramework::Thin_vtxTrk::m_nVtxPass
std::atomic< unsigned int > m_nVtxPass
Definition
Thin_vtxTrk.h:41
DerivationFramework::Thin_vtxTrk::initialize
StatusCode initialize()
Definition
Thin_vtxTrk.cxx:40
DerivationFramework::Thin_vtxTrk::m_thinTracks
bool m_thinTracks
Definition
Thin_vtxTrk.h:47
DerivationFramework::Thin_vtxTrk::m_acceptanceR
double m_acceptanceR
Definition
Thin_vtxTrk.h:40
DerivationFramework::Thin_vtxTrk::~Thin_vtxTrk
~Thin_vtxTrk()
DerivationFramework::Thin_vtxTrk::m_passFlags
std::vector< std::string > m_passFlags
Definition
Thin_vtxTrk.h:45
DerivationFramework::Thin_vtxTrk::doThinning
virtual StatusCode doThinning(const EventContext &ctx) const
Definition
Thin_vtxTrk.cxx:88
DerivationFramework::Thin_vtxTrk::m_ntot
std::atomic< unsigned int > m_ntot
Definition
Thin_vtxTrk.h:39
DerivationFramework::Thin_vtxTrk::finalize
StatusCode finalize()
Definition
Thin_vtxTrk.cxx:78
DerivationFramework::Thin_vtxTrk::Thin_vtxTrk
Thin_vtxTrk(const std::string &t, const std::string &n, const IInterface *p)
Definition
Thin_vtxTrk.cxx:19
DerivationFramework::Thin_vtxTrk::m_trackParticleContainerName
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_trackParticleContainerName
Definition
Thin_vtxTrk.h:43
DerivationFramework::Thin_vtxTrk::m_vertexContainerName
SG::ThinningHandleKeyArray< xAOD::VertexContainer > m_vertexContainerName
Definition
Thin_vtxTrk.h:44
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
xAOD::TrackParticle_v1::p4
virtual FourMom_t p4() const override final
The full 4-momentum of the particle.
Definition
TrackParticle_v1.cxx:122
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition
Vertex_v1.cxx:292
xAOD::Vertex_v1::trackParticle
const TrackParticle * trackParticle(size_t i) const
Get the pointer to a given track that was used in vertex reco.
Definition
Vertex_v1.cxx:271
str
Definition
BTagTrackIpAccessor.cxx:11
xAOD::TrackParticle
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Definition
Event/xAOD/xAODTracking/xAODTracking/TrackParticle.h:13
xAOD::Vertex
Vertex_v1 Vertex
Define the latest version of the vertex class.
Definition
Event/xAOD/xAODTracking/xAODTracking/Vertex.h:16
Generated on
for ATLAS Offline Software by
1.17.0