ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkBPhys
src
Thin_vtxDuplicates.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_vtxDuplicates.cxx
8
// Matteo Bedognetti (matteo.bedognetti@cern.ch)
9
//Based on Thin_vtxTrk.cxx, by
10
11
12
13
#include "
Thin_vtxDuplicates.h
"
14
#include "
xAODTracking/TrackParticleContainer.h
"
15
#include "
xAODBPhys/BPhysHypoHelper.h
"
16
#include <vector>
17
#include <string>
18
#include <algorithm>
// for the sort function
19
#include <iomanip>
20
#include "
StoreGate/ThinningHandle.h
"
21
// Constructor
22
DerivationFramework::Thin_vtxDuplicates::Thin_vtxDuplicates
(
const
std::string& t,
const
std::string& n,
const
IInterface* p ) :
23
base_class(t,n,p),
24
// m_acceptanceR(-1.),
25
m_noFlags
(false),
26
m_nVtxTot
(0),
27
m_nVtxPass
(0)
28
{
29
declareProperty(
"VertexContainerName"
,
m_vertexContainerNames
);
30
declareProperty(
"PassFlags"
,
m_passFlags
);
31
//declareProperty("AcceptanceRadius" , m_acceptanceR);
32
declareProperty(
"IgnoreFlags"
,
m_noFlags
);
33
//declareProperty("ApplyAndForTracks" , m_trackAnd = false);
34
//declareProperty("ThinTracks" , m_thinTracks = true);
35
}
36
37
// Destructor
38
DerivationFramework::Thin_vtxDuplicates::~Thin_vtxDuplicates
() =
default
;
39
40
// Athena initialize and finalize
41
StatusCode
DerivationFramework::Thin_vtxDuplicates::initialize
()
42
{
43
// Decide which collections need to be checked for ID TrackParticles
44
ATH_MSG_VERBOSE
(
"initialize() ..."
);
45
ATH_CHECK
(
m_vertexContainerNames
.initialize(
m_streamName
));
46
47
48
if
(
m_passFlags
.empty()) {
49
ATH_MSG_FATAL
(
"No pass flags provided for thinning."
);
50
return
StatusCode::FAILURE;
51
}
else
{
52
for
(
auto
itr =
m_passFlags
.cbegin(); itr!=
m_passFlags
.cend(); ++itr) {
53
ATH_MSG_INFO
(
"Vertices must pass the \""
<< itr->key() <<
"\" selection"
);
54
}
55
}
56
57
for
(
auto
&key :
m_passFlags
){
58
key =
m_vertexContainerNames
.key() +
'.'
+ key.key();
59
}
60
ATH_CHECK
(
m_passFlags
.initialize());
61
return
StatusCode::SUCCESS;
62
}
63
64
StatusCode
DerivationFramework::Thin_vtxDuplicates::finalize
()
65
{
66
ATH_MSG_VERBOSE
(
"finalize() ..."
);
67
ATH_MSG_INFO
(
"Processed "
<<
m_nVtxTot
<<
" vertices, "
<<
m_nVtxPass
<<
" were retained "
);
68
69
return
StatusCode::SUCCESS;
70
}
71
72
// The thinning itself
73
StatusCode
DerivationFramework::Thin_vtxDuplicates::doThinning
(
const
EventContext& ctx)
const
74
{
75
// retieve vertex
76
SG::ThinningHandle< xAOD::VertexContainer >
vertexContainer(
m_vertexContainerNames
, ctx);
77
std::vector<bool> vtxMask(vertexContainer->size(),
true
);
// default: keep all vertices
78
int
vtxTot = 0;
79
int
nVtxPass = 0;
80
// loop over vertices
81
int
k = 0;
82
std::vector<SG::ReadDecorHandle<xAOD::VertexContainer, Char_t>> handles;
83
handles.reserve(
m_passFlags
.size());
84
for
(
const
auto
&key :
m_passFlags
){
85
handles.emplace_back(key, ctx);
86
if
(!handles.back().isPresent())
return
StatusCode::FAILURE;
87
}
88
for
(
auto
vtxItr = vertexContainer->cbegin(); vtxItr!=vertexContainer->cend(); ++vtxItr, ++k) {
89
const
xAOD::Vertex
* vtx = *vtxItr;
90
// check if the vertex passed the required selections criteria (is run when the vertex is already excluded, because the counter needs the info)
91
bool
passed
=
false
;
92
if
(
m_noFlags
){
passed
=
true
; vtxTot++; }
93
else
{
94
for
(
auto
&flagAcc : handles) {
95
if
(flagAcc(*vtx) != 0) {
96
passed
=
true
;
97
vtxTot++;
//Have to count the ones which are accepted to start with
98
break
;
99
}
100
}
// end of loop over flags
101
}
102
103
// Skip if it has already been identified as duplicate
104
if
(vtxMask[k] ==
false
)
continue
;
//After the flag-check to have the total-passed work correctly
105
106
if
(!
passed
)vtxMask[k]=
false
;
107
108
if
(
passed
) {
109
// vertex passed the selection
110
nVtxPass++;
111
112
// determine the sum of the tracks at vertex as centre for the cone
113
std::vector<const xAOD::TrackParticle*> presentVertex, compareVertex;
114
115
//Fill in the present vertex, for later comparison against other vertices
116
presentVertex.clear();
117
for
(
uint
j=0; j<vtx->
nTrackParticles
(); ++j) {
118
presentVertex.push_back(vtx->
trackParticle
(j));
119
}
120
sort
( presentVertex.begin(), presentVertex.end() );
//Sort the trackparticles BY POINTER ADDRESS
121
122
//Loop over the remaining vertices and remove them if needed
123
int
loop_k = k+1;
124
for
(
auto
vtxLoopItr = vtxItr+1; vtxLoopItr!=vertexContainer->cend(); vtxLoopItr++, loop_k++){
125
126
const
xAOD::Vertex
* loop_vtx = *vtxLoopItr;
127
128
//Vertices are distinct if have different size
129
if
(vtx->
nTrackParticles
() != loop_vtx->
nTrackParticles
())
continue
;
130
131
//If the vertex is still active load and compare
132
if
(vtxMask[loop_k]){
133
134
compareVertex.clear();
135
for
(
uint
j=0; j<loop_vtx->
nTrackParticles
(); ++j) {
136
compareVertex.push_back(loop_vtx->
trackParticle
(j));
137
}
138
139
std::sort
( compareVertex.begin(), compareVertex.end());
140
141
vtxMask[loop_k] =
false
;
142
143
ATH_MSG_DEBUG
(
"Compared tracks: "
);
144
ATH_MSG_DEBUG
(std::setw(14)<<compareVertex[0]<<std::setw(14) << compareVertex[1]<<std::setw(14)<<compareVertex[2]);
145
ATH_MSG_DEBUG
(std::setw(14)<<presentVertex[0]<<std::setw(14) << presentVertex[1]<<std::setw(14)<<presentVertex[2]);
146
147
for
(
uint
j=0; j<loop_vtx->
nTrackParticles
(); ++j) {
148
if
( compareVertex[j] != presentVertex[j] ){vtxMask[loop_k] =
true
;
break
;}
149
}
150
ATH_MSG_DEBUG
(
"Verdict:"
<<(vtxMask[loop_k]?
"keep"
:
"erase"
) );
151
}
152
153
}
// Endo of extra loop over remaining vertices
154
155
}
// if( passed )
156
}
// end of loop over vertices
157
158
// Execute the thinning service based on the vtxMask.
159
vertexContainer.
keep
(vtxMask);
160
161
m_nVtxTot
.fetch_add( vtxTot, std::memory_order_relaxed);
162
m_nVtxPass
.fetch_add( nVtxPass, std::memory_order_relaxed);
163
164
165
166
return
StatusCode::SUCCESS;
167
}
168
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
BPhysHypoHelper.h
: B-physics xAOD helpers.
TrackParticleContainer.h
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
sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition
DVL_algorithms.h:554
Thin_vtxDuplicates.h
ThinningHandle.h
Handle for requesting thinning for a data object.
DerivationFramework::Thin_vtxDuplicates::~Thin_vtxDuplicates
~Thin_vtxDuplicates()
DerivationFramework::Thin_vtxDuplicates::doThinning
virtual StatusCode doThinning(const EventContext &ctx) const
Definition
Thin_vtxDuplicates.cxx:73
DerivationFramework::Thin_vtxDuplicates::m_nVtxPass
std::atomic< unsigned int > m_nVtxPass
Definition
Thin_vtxDuplicates.h:29
DerivationFramework::Thin_vtxDuplicates::m_vertexContainerNames
SG::ThinningHandleKey< xAOD::VertexContainer > m_vertexContainerNames
Definition
Thin_vtxDuplicates.h:31
DerivationFramework::Thin_vtxDuplicates::m_passFlags
SG::ReadDecorHandleKeyArray< xAOD::VertexContainer > m_passFlags
Definition
Thin_vtxDuplicates.h:32
DerivationFramework::Thin_vtxDuplicates::initialize
virtual StatusCode initialize()
Definition
Thin_vtxDuplicates.cxx:41
DerivationFramework::Thin_vtxDuplicates::m_noFlags
bool m_noFlags
Definition
Thin_vtxDuplicates.h:27
DerivationFramework::Thin_vtxDuplicates::finalize
virtual StatusCode finalize()
Definition
Thin_vtxDuplicates.cxx:64
DerivationFramework::Thin_vtxDuplicates::Thin_vtxDuplicates
Thin_vtxDuplicates(const std::string &t, const std::string &n, const IInterface *p)
Definition
Thin_vtxDuplicates.cxx:22
DerivationFramework::Thin_vtxDuplicates::m_nVtxTot
std::atomic< unsigned int > m_nVtxTot
Definition
Thin_vtxDuplicates.h:29
DerivationFramework::Thin_vtxDuplicates::m_streamName
StringProperty m_streamName
Definition
Thin_vtxDuplicates.h:28
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::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
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition
DVL_algorithms.h:554
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