16 #include "GaudiKernel/ThreadLocalContext.h"
26 const IInterface*
p ) :
34 m_preserveDescendants(false),
35 m_preserveGeneratorDescendants(false),
36 m_preserveAncestors(false),
39 declareProperty(
"ParticleSelectionString",
m_partString);
55 ATH_CHECK( m_particlesKey.initialize (m_streamName) );
56 ATH_CHECK( m_verticesKey.initialize (m_streamName) );
57 ATH_MSG_INFO(
"Using " << m_particlesKey.key() <<
" and "<< m_verticesKey.key() <<
" as the source collections for truth thinning");
59 if (m_partString.empty()) {
60 ATH_MSG_FATAL(
"No selection string provided either for vertices or particles!");
61 return StatusCode::FAILURE;
62 }
else {
ATH_MSG_INFO(
"Truth thinning selection strings: " << m_partString );}
64 if (m_preserveDescendants && m_preserveGeneratorDescendants) {
65 ATH_MSG_FATAL(
"You are asking to keep both all descendants, and only those from the event generator. Please check your job options.");
66 return StatusCode::FAILURE;
69 if (!m_partString.empty()) {
70 ATH_CHECK( initializeParser(m_partString) );
72 return StatusCode::SUCCESS;
78 ATH_MSG_INFO(
"Processed "<< m_ntotvtx <<
" truth vertices, "<< m_npassvtx <<
" were retained ");
79 ATH_MSG_INFO(
"Processed "<< m_ntotpart <<
" truth particles, "<< m_npasspart <<
" were retained ");
81 return StatusCode::SUCCESS;
87 const EventContext& ctx = Gaudi::Hive::currentContext();
91 (m_particlesKey, ctx);
96 unsigned int nParticles = importedTruthParticles->size();
97 unsigned int nVertices = importedTruthVertices->size();
98 std::vector<bool> partMask, vertMask;
99 partMask.assign(nParticles,
false);
101 m_ntotvtx +=
nVertices; m_ntotpart += nParticles;
104 if (!m_partString.empty()) {
105 std::vector<int>
entries = m_parser->evaluateAsVector();
109 ATH_MSG_ERROR(
"Sizes incompatible! Are you sure your selection string used TruthParticles?");
110 return StatusCode::FAILURE;
113 for (
unsigned int i=0;
i<nParticles; ++
i)
if (
entries[
i]==1) partMask[
i]=
true;
121 for (
unsigned int i=0;
i<nParticles; ++
i) {
125 std::vector<int> tauDecayProducts;
126 std::unordered_set<int> tauDecayEncounteredUniqueIDs;
128 for (
unsigned int tauDecIt=0; tauDecIt<tauDecayProducts.size(); ++tauDecIt) {
129 if (std::abs(tauDecayProducts[tauDecIt])==15) {
134 if (!last) partMask[
i]=
false;
146 std::unordered_set<int> encounteredUniqueIDs;
147 if (m_preserveDescendants || m_preserveGeneratorDescendants || m_preserveAncestors) {
148 for (
unsigned int i=0;
i<nParticles; ++
i) {
149 bool toKeep = partMask[
i];
150 if (!toKeep)
continue;
152 encounteredUniqueIDs.clear();
153 if (m_preserveDescendants) decayHelper.
descendants(
particle,partMask,vertMask,encounteredUniqueIDs,
true);
154 encounteredUniqueIDs.clear();
155 if (m_preserveGeneratorDescendants) decayHelper.
descendants(
particle,partMask,vertMask,encounteredUniqueIDs,
false);
156 encounteredUniqueIDs.clear();
157 if (m_preserveAncestors) decayHelper.
ancestors(
particle,partMask,vertMask,encounteredUniqueIDs);
158 encounteredUniqueIDs.clear();
169 m_npasspart +=
std::count (partMask.begin(), partMask.end(),
true);
170 m_npassvtx +=
std::count (vertMask.begin(), vertMask.end(),
true);
173 importedTruthParticles.
keep (partMask);
174 importedTruthVertices.
keep (vertMask);
176 return StatusCode::SUCCESS;