ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkBPhys
src
BPhysPVThinningTool.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
// ThinningToolExample.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 "
BPhysPVThinningTool.h
"
13
#include "
xAODTracking/TrackParticleContainer.h
"
14
#include "
xAODTracking/TrackParticle.h
"
15
#include "
StoreGate/ThinningHandle.h
"
16
#include "
xAODBPhys/BPhysHelper.h
"
17
#include "
StoreGate/ThinningHandle.h
"
18
#include <algorithm>
19
#include <numeric>
20
#include <vector>
21
#include <string>
22
23
using namespace
std
;
24
using namespace
xAOD
;
25
// Constructor
26
DerivationFramework::BPhysPVThinningTool::BPhysPVThinningTool
(
const
std::string& t,
27
const
std::string& n,
28
const
IInterface* p ) :
29
base_class(t,n,p),
30
m_TrackContainerName
(
"InDetTrackParticles"
),
31
m_PVContainerName
(
"PrimaryVertices"
),
32
m_ntot
(0),
33
m_npass
(0),
m_tracks_kept
(0),
m_keepTracks
(false)
34
{
35
declareProperty(
"CandidateCollections"
,
m_BPhyCandList
);
36
declareProperty(
"KeepPVTracks"
,
m_keepTracks
);
37
declareProperty(
"TrackParticleContainerName"
,
m_TrackContainerName
);
38
declareProperty(
"PrimaryVertexContainerName"
,
m_PVContainerName
);
39
}
40
41
// Destructor
42
DerivationFramework::BPhysPVThinningTool::~BPhysPVThinningTool
() {
43
}
44
45
// Athena initialize and finalize
46
StatusCode
DerivationFramework::BPhysPVThinningTool::initialize
()
47
{
48
ATH_MSG_VERBOSE
(
"initialize() ..."
);
49
ATH_CHECK
(
m_BPhyCandList
.initialize());
50
if
(not
m_TrackContainerName
.key().empty())
ATH_CHECK
(
m_TrackContainerName
.initialize(
m_streamName
));
51
ATH_CHECK
(
m_PVContainerName
.initialize(
m_streamName
));
52
53
return
StatusCode::SUCCESS;
54
}
55
StatusCode
DerivationFramework::BPhysPVThinningTool::finalize
()
56
{
57
ATH_MSG_VERBOSE
(
"finalize() ..."
);
58
ATH_MSG_INFO
(
"Processed "
<<
m_ntot
<<
" PV, "
<<
m_npass
<<
" were retained "
);
59
if
(
m_keepTracks
)
ATH_MSG_INFO
(
"Additional tracks kept "
<<
m_tracks_kept
);
60
return
StatusCode::SUCCESS;
61
}
62
63
// The thinning itself
64
StatusCode
DerivationFramework::BPhysPVThinningTool::doThinning
(
const
EventContext& ctx)
const
65
{
66
// Get the track container
67
SG::ThinningHandle<xAOD::VertexContainer>
PV_col(
m_PVContainerName
, ctx);
68
if
(!PV_col.isValid()) {
69
ATH_MSG_ERROR
(
"Couldn't retrieve VertexContainer with key PrimaryVertices"
);
70
return
StatusCode::FAILURE;
71
}
72
m_ntot
+=PV_col->size();
73
// Loop over tracks, see if they pass, set mask
74
std::vector<bool> mask(PV_col->size(),
false
);
75
76
BPhysHelper::pv_type
pvtypes[] = {
BPhysHelper::PV_MAX_SUM_PT2
,
77
BPhysHelper::PV_MIN_A0
,
78
BPhysHelper::PV_MIN_Z0
,
79
BPhysHelper::PV_MIN_Z0_BA
};
80
81
82
83
for
(
auto
&
str
:
m_BPhyCandList
) {
84
SG::ReadHandle<xAOD::VertexContainer>
Container
(
str
, ctx);
85
ATH_CHECK
(
Container
.isValid());
86
size_t
s =
Container
->size();
87
for
(
size_t
i = 0; i<s; i++) {
88
xAOD::BPhysHelper
vtx(
Container
->at(i));
89
90
for
(
size_t
i =0; i < 4; i++) {
91
const
xAOD::Vertex
* origPv = vtx.
origPv
(pvtypes[i]);
92
if
(origPv==
nullptr
)
continue
;
93
auto
pvit = std::find (PV_col->begin(), PV_col->end(), origPv);
94
if
(pvit == PV_col->end()) {
95
ATH_MSG_WARNING
(
"PV not found in container"
);
96
continue
;
97
}
98
size_t
x
= std::distance(PV_col->begin(), pvit);
99
mask.at(
x
) =
true
;
100
}
101
102
}
103
}
104
105
m_npass
+= std::accumulate(mask.begin(), mask.end(), 0);
106
107
if
(
m_keepTracks
){
108
SG::ThinningHandle<xAOD::TrackParticleContainer>
importedTrackParticles(
m_TrackContainerName
, ctx);
109
std::vector<bool> trackmask(importedTrackParticles->size(),
false
);
110
size_t
pvnum = mask.size();
111
for
(
size_t
i =0; i<pvnum;i++){
112
if
(mask[i] ==
false
)
continue
;
113
auto
vtx = PV_col->at(i);
114
size_t
s = vtx->nTrackParticles();
115
for
(
size_t
j=0;j<s;j++){
116
auto
trackit = std::find(importedTrackParticles->begin(), importedTrackParticles->end(), vtx->trackParticle(j));
117
if
(trackit == importedTrackParticles->end()){
118
ATH_MSG_WARNING
(
"track not found in container"
);
119
continue
;
120
}
121
size_t
x
= std::distance(importedTrackParticles->begin(), trackit);
122
trackmask.at(
x
) =
true
;
123
}
124
}
125
importedTrackParticles.
keep
(trackmask);
126
m_tracks_kept
+= std::accumulate(trackmask.begin(), trackmask.end(), 0);
127
}
128
PV_col.
keep
(mask);
129
130
return
StatusCode::SUCCESS;
131
}
132
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
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_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
BPhysHelper.h
: B-physics xAOD helpers.
BPhysPVThinningTool.h
TrackParticleContainer.h
TrackParticle.h
ThinningHandle.h
Handle for requesting thinning for a data object.
x
#define x
DerivationFramework::BPhysPVThinningTool::m_ntot
std::atomic< unsigned int > m_ntot
Definition
BPhysPVThinningTool.h:44
DerivationFramework::BPhysPVThinningTool::initialize
virtual StatusCode initialize() override
Definition
BPhysPVThinningTool.cxx:46
DerivationFramework::BPhysPVThinningTool::m_BPhyCandList
SG::ReadHandleKeyArray< xAOD::VertexContainer > m_BPhyCandList
Definition
BPhysPVThinningTool.h:41
DerivationFramework::BPhysPVThinningTool::BPhysPVThinningTool
BPhysPVThinningTool(const std::string &t, const std::string &n, const IInterface *p)
Constructor with parameters.
Definition
BPhysPVThinningTool.cxx:26
DerivationFramework::BPhysPVThinningTool::m_PVContainerName
SG::ThinningHandleKey< xAOD::VertexContainer > m_PVContainerName
Definition
BPhysPVThinningTool.h:43
DerivationFramework::BPhysPVThinningTool::~BPhysPVThinningTool
~BPhysPVThinningTool()
Destructor.
Definition
BPhysPVThinningTool.cxx:42
DerivationFramework::BPhysPVThinningTool::m_npass
std::atomic< unsigned int > m_npass
Definition
BPhysPVThinningTool.h:45
DerivationFramework::BPhysPVThinningTool::m_TrackContainerName
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_TrackContainerName
Definition
BPhysPVThinningTool.h:42
DerivationFramework::BPhysPVThinningTool::m_tracks_kept
std::atomic< unsigned int > m_tracks_kept
Definition
BPhysPVThinningTool.h:46
DerivationFramework::BPhysPVThinningTool::m_keepTracks
bool m_keepTracks
Definition
BPhysPVThinningTool.h:47
DerivationFramework::BPhysPVThinningTool::m_streamName
StringProperty m_streamName
Definition
BPhysPVThinningTool.h:40
DerivationFramework::BPhysPVThinningTool::doThinning
virtual StatusCode doThinning(const EventContext &ctx) const override
Check that the current event passes this filter.
Definition
BPhysPVThinningTool.cxx:64
DerivationFramework::BPhysPVThinningTool::finalize
virtual StatusCode finalize() override
Definition
BPhysPVThinningTool.cxx:55
Container
storage of the time histories of all the cells
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
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::BPhysHelper
Definition
BPhysHelper.h:71
xAOD::BPhysHelper::origPv
const xAOD::Vertex * origPv(const pv_type vertexType=BPhysHelper::PV_MIN_A0)
original PV
Definition
BPhysHelper.cxx:807
xAOD::BPhysHelper::pv_type
pv_type
: Enum type of the PV
Definition
BPhysHelper.h:475
xAOD::BPhysHelper::PV_MIN_Z0
@ PV_MIN_Z0
Definition
BPhysHelper.h:475
xAOD::BPhysHelper::PV_MIN_Z0_BA
@ PV_MIN_Z0_BA
Definition
BPhysHelper.h:475
xAOD::BPhysHelper::PV_MIN_A0
@ PV_MIN_A0
Definition
BPhysHelper.h:475
xAOD::BPhysHelper::PV_MAX_SUM_PT2
@ PV_MAX_SUM_PT2
Definition
BPhysHelper.h:475
std
STL namespace.
str
Definition
BTagTrackIpAccessor.cxx:11
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition
ICaloAffectedTool.h:24
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