ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkLLP
src
VSITrackParticleThinning.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
// VSITrackParticleThinning.cxx, (c) ATLAS Detector software
8
// Authors: Amber Roepe (amber.rebecca.roepe@cern.ch)
9
// Jackson Burzynski (jackson.carl.burzynski@cern.ch)
10
// This is a trivial example of an implementation of a thinning tool
11
// which removes all ID tracks which do not pass a user-defined cut
12
13
#include "
DerivationFrameworkLLP/VSITrackParticleThinning.h
"
14
#include "
xAODTracking/VertexContainer.h
"
15
#include "
xAODTracking/TrackParticleContainer.h
"
16
#include "
StoreGate/ThinningHandle.h
"
17
#include <vector>
18
#include <string>
19
20
// Constructor
21
DerivationFramework::VSITrackParticleThinning::VSITrackParticleThinning
(
const
std::string& t,
22
const
std::string& n,
23
const
IInterface* p ) :
24
base_class(t,n,p)
25
{
26
}
27
28
// Destructor
29
DerivationFramework::VSITrackParticleThinning::~VSITrackParticleThinning
() {
30
}
31
32
// Athena initialize and finalize
33
StatusCode
DerivationFramework::VSITrackParticleThinning::initialize
()
34
{
35
36
// Decide which collections need to be checked for ID TrackParticles
37
ATH_MSG_VERBOSE
(
"initialize() ..."
);
38
ATH_CHECK
(
m_inDetSGKey
.initialize (
m_streamName
) );
39
40
// Set up the text-parsing machinery for selectiong the dv directly according to user cuts
41
if
(!
m_trackSelectionString
.empty()) {
42
// order must match enum order EJetTrPThinningParser
43
ATH_CHECK
( initializeParser( {
m_selectionString
,
m_trackSelectionString
} ));
44
}
45
46
return
StatusCode::SUCCESS;
47
}
48
49
StatusCode
DerivationFramework::VSITrackParticleThinning::finalize
()
50
{
51
ATH_MSG_VERBOSE
(
"finalize() ..."
);
52
ATH_MSG_INFO
(
"Processed "
<<
m_ntot
<<
" tracks, "
<<
m_npass
<<
" were retained "
);
53
return
StatusCode::SUCCESS;
54
}
55
56
// The thinning itself
57
StatusCode
DerivationFramework::VSITrackParticleThinning::doThinning
(
const
EventContext& ctx)
const
58
{
59
60
61
// Retrieve main TrackParticle collection
62
SG::ThinningHandle<xAOD::TrackParticleContainer>
importedTrackParticles
63
(
m_inDetSGKey
, ctx);
64
65
// Check the event contains tracks
66
unsigned
int
nTracks = importedTrackParticles->size();
67
if
(nTracks==0)
return
StatusCode::SUCCESS;
68
69
// Set up a mask with the same entries as the full TrackParticle collection
70
std::vector<bool> mask;
71
mask.assign(nTracks,
false
);
// default: don't keep any tracks
72
m_ntot
+= nTracks;
73
74
// Set elements in the mask to true if associated with a DV
75
for
(
const
auto
trkIt: *importedTrackParticles ) {
76
for
(
const
auto
&augVerString:
m_augVerStrings
) {
77
SG::ConstAccessor<char>
acc(
"is_svtrk_final"
+ augVerString);
78
if
(acc.withDefault (*trkIt,
false
)) {
79
int
index
= trkIt->index();
80
mask[
index
] =
true
;
81
}
82
}
83
}
84
85
// Apply a track selection string.
86
if
(!
m_trackSelectionString
.empty()) {
87
std::vector<int>
entries
= m_parser[
kdvTrackThinning
]->evaluateAsVector();
88
unsigned
int
nEntries =
entries
.size();
89
// check the sizes are compatible
90
if
(nTracks != nEntries ) {
91
ATH_MSG_ERROR
(
"Sizes incompatible! Are you sure your track selection string used tracks??"
);
92
return
StatusCode::FAILURE;
93
}
94
else
{
95
// identify which dvs to keep for the thinning check
96
for
(
unsigned
int
i=0; i<nEntries; ++i) {
97
if
(!mask[i])
continue
;
98
if
(!
entries
[i]) mask[i] =
false
;
99
}
100
}
101
}
102
103
104
// Count up the mask contents
105
unsigned
int
n_pass=0;
106
for
(
unsigned
int
i=0; i<nTracks; ++i) {
107
if
(mask[i]) ++n_pass;
108
}
109
m_npass
+= n_pass;
110
111
112
// Execute the thinning service based on the mask. Finish.
113
importedTrackParticles.
keep
(mask);
114
115
116
return
StatusCode::SUCCESS;
117
118
}
119
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
TrackParticleContainer.h
ThinningHandle.h
Handle for requesting thinning for a data object.
VSITrackParticleThinning.h
VertexContainer.h
DerivationFramework::VSITrackParticleThinning::m_npass
std::atomic< unsigned int > m_npass
Definition
VSITrackParticleThinning.h:39
DerivationFramework::VSITrackParticleThinning::finalize
virtual StatusCode finalize() override
Definition
VSITrackParticleThinning.cxx:49
DerivationFramework::VSITrackParticleThinning::VSITrackParticleThinning
VSITrackParticleThinning(const std::string &t, const std::string &n, const IInterface *p)
Definition
VSITrackParticleThinning.cxx:21
DerivationFramework::VSITrackParticleThinning::m_inDetSGKey
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_inDetSGKey
Definition
VSITrackParticleThinning.h:44
DerivationFramework::VSITrackParticleThinning::m_selectionString
StringProperty m_selectionString
Definition
VSITrackParticleThinning.h:46
DerivationFramework::VSITrackParticleThinning::m_augVerStrings
StringArrayProperty m_augVerStrings
Definition
VSITrackParticleThinning.h:51
DerivationFramework::VSITrackParticleThinning::m_ntot
std::atomic< unsigned int > m_ntot
Definition
VSITrackParticleThinning.h:38
DerivationFramework::VSITrackParticleThinning::~VSITrackParticleThinning
virtual ~VSITrackParticleThinning()
Definition
VSITrackParticleThinning.cxx:29
DerivationFramework::VSITrackParticleThinning::m_streamName
StringProperty m_streamName
Definition
VSITrackParticleThinning.h:42
DerivationFramework::VSITrackParticleThinning::m_trackSelectionString
StringProperty m_trackSelectionString
Definition
VSITrackParticleThinning.h:48
DerivationFramework::VSITrackParticleThinning::doThinning
virtual StatusCode doThinning(const EventContext &ctx) const override
Definition
VSITrackParticleThinning.cxx:57
DerivationFramework::VSITrackParticleThinning::initialize
virtual StatusCode initialize() override
Definition
VSITrackParticleThinning.cxx:33
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition
ConstAccessor.h:55
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
entries
double entries
Definition
listroot.cxx:49
DerivationFramework::kdvTrackThinning
@ kdvTrackThinning
Definition
VSITrackParticleThinning.h:28
index
Definition
index.py:1
Generated on
for ATLAS Offline Software by
1.17.0