ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkTools
src
GenericObjectThinning.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
// GenericObjectThinning.cxx, (c) ATLAS Detector software
8
// Author: James Catmore (James.Catmore@cern.ch)
9
// Removes all ID tracks which do not pass a user-defined cut
10
11
#include "
DerivationFrameworkTools/GenericObjectThinning.h
"
12
#include "
StoreGate/ThinningHandle.h
"
13
#include <vector>
14
#include <string>
15
16
// Constructor
17
DerivationFramework::GenericObjectThinning::GenericObjectThinning
(
const
std::string& t,
18
const
std::string& n,
19
const
IInterface* p ) :
20
base_class(t,n,p),
21
m_selectionString
(
""
),
22
m_ntot
(0),
23
m_npass
(0)
24
{
25
declareProperty(
"SelectionString"
,
m_selectionString
);
26
}
27
28
// Destructor
29
DerivationFramework::GenericObjectThinning::~GenericObjectThinning
() {
30
}
31
32
// Athena initialize and finalize
33
StatusCode
DerivationFramework::GenericObjectThinning::initialize
()
34
{
35
ATH_MSG_VERBOSE
(
"initialize() ..."
);
36
if
(
m_selectionString
.empty()) {
37
ATH_MSG_FATAL
(
"No selection string provided!"
);
38
return
StatusCode::FAILURE;
39
}
else
{
ATH_MSG_INFO
(
"Selection string: "
<<
m_selectionString
);}
40
41
// Set up the text-parsing machinery for thinning the tracks directly according to user cuts
42
if
(!
m_selectionString
.empty()) {
43
ATH_CHECK
(initializeParser(
m_selectionString
) );
44
}
45
46
//check xAOD::InDetTrackParticle collection
47
ATH_CHECK
(
m_SGKey
.initialize (
m_streamName
) );
48
ATH_MSG_INFO
(
"Using "
<<
m_SGKey
<<
"as the source collection"
);
49
50
return
StatusCode::SUCCESS;
51
}
52
53
StatusCode
DerivationFramework::GenericObjectThinning::finalize
()
54
{
55
ATH_MSG_VERBOSE
(
"finalize() ..."
);
56
ATH_MSG_INFO
(
"Processed "
<<
m_ntot
<<
" objects, "
<<
m_npass
<<
" were retained "
);
57
ATH_CHECK
(finalizeParser());
58
return
StatusCode::SUCCESS;
59
}
60
61
// The thinning itself
62
StatusCode
DerivationFramework::GenericObjectThinning::doThinning
(
const
EventContext& ctx)
const
63
{
64
65
// Retrieve main object collection
66
SG::ThinningHandle<xAOD::IParticleContainer>
particles (
m_SGKey
, ctx);
67
68
// Check the event contains objects
69
unsigned
int
nObjects = particles->size();
70
if
(nObjects==0)
return
StatusCode::SUCCESS;
71
72
// Set up a mask with the same entries as the full collection
73
std::vector<bool> mask;
74
mask.assign(nObjects,
false
);
// default: don't keep any tracks
75
m_ntot
+= nObjects;
76
77
// Execute the text parser and update the mask
78
if
(m_parser) {
79
std::vector<int>
entries
= m_parser->evaluateAsVector();
80
unsigned
int
nEntries =
entries
.size();
81
// check the sizes are compatible
82
if
(nObjects != nEntries ) {
83
ATH_MSG_ERROR
(
"Sizes incompatible! Are you sure your selection string used the same collection as the input collection??"
);
84
return
StatusCode::FAILURE;
85
}
else
{
86
// set mask
87
for
(
unsigned
int
i=0; i<nObjects; ++i)
if
(
entries
[i]==1) mask[i]=
true
;
88
}
89
}
90
// Count the mask
91
m_npass
+= std::count (mask.begin(), mask.end(),
true
);
92
93
// Execute the thinning based on the mask. Finish.
94
particles.keep (mask);
95
96
return
StatusCode::SUCCESS;
97
}
98
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_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
GenericObjectThinning.h
ThinningHandle.h
Handle for requesting thinning for a data object.
DerivationFramework::GenericObjectThinning::m_SGKey
SG::ThinningHandleKey< xAOD::IParticleContainer > m_SGKey
Definition
GenericObjectThinning.h:38
DerivationFramework::GenericObjectThinning::finalize
virtual StatusCode finalize() override
Definition
GenericObjectThinning.cxx:53
DerivationFramework::GenericObjectThinning::~GenericObjectThinning
~GenericObjectThinning()
Definition
GenericObjectThinning.cxx:29
DerivationFramework::GenericObjectThinning::m_ntot
std::atomic< unsigned int > m_ntot
Definition
GenericObjectThinning.h:44
DerivationFramework::GenericObjectThinning::m_streamName
StringProperty m_streamName
Definition
GenericObjectThinning.h:36
DerivationFramework::GenericObjectThinning::m_npass
std::atomic< unsigned int > m_npass
Definition
GenericObjectThinning.h:44
DerivationFramework::GenericObjectThinning::m_selectionString
std::string m_selectionString
Definition
GenericObjectThinning.h:41
DerivationFramework::GenericObjectThinning::GenericObjectThinning
GenericObjectThinning(const std::string &t, const std::string &n, const IInterface *p)
Definition
GenericObjectThinning.cxx:17
DerivationFramework::GenericObjectThinning::doThinning
virtual StatusCode doThinning(const EventContext &ctx) const override
Definition
GenericObjectThinning.cxx:62
DerivationFramework::GenericObjectThinning::initialize
virtual StatusCode initialize() override
Definition
GenericObjectThinning.cxx:33
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition
ThinningHandle.h:84
entries
double entries
Definition
listroot.cxx:49
Generated on
for ATLAS Offline Software by
1.17.0