16 #include "GaudiKernel/ThreadLocalContext.h"
26 const IInterface*
p ) :
34 m_preserveDescendants(false),
35 m_preserveGeneratorDescendants(false),
36 m_preserveAncestors(false),
40 declareProperty(
"ParticleSelectionString",
m_partString);
56 ATH_CHECK( m_particlesKey.initialize (m_streamName) );
57 ATH_CHECK( m_verticesKey.initialize (m_streamName) );
58 ATH_MSG_INFO(
"Using " << m_particlesKey.key() <<
" and "<< m_verticesKey.key() <<
" as the source collections for truth thinning");
60 if (m_partString.empty()) {
61 ATH_MSG_FATAL(
"No selection string provided either for vertices or particles!");
62 return StatusCode::FAILURE;
63 }
else {
ATH_MSG_INFO(
"Truth thinning selection strings: " << m_partString );}
65 if (m_preserveDescendants && m_preserveGeneratorDescendants) {
66 ATH_MSG_FATAL(
"You are asking to keep both all descendants, and only those from the event generator. Please check your job options.");
67 return StatusCode::FAILURE;
70 if (!m_partString.empty()) {
71 ATH_CHECK( initializeParser(m_partString) );
73 return StatusCode::SUCCESS;
79 ATH_MSG_INFO(
"Processed "<< m_ntotvtx <<
" truth vertices, "<< m_npassvtx <<
" were retained ");
80 ATH_MSG_INFO(
"Processed "<< m_ntotpart <<
" truth particles, "<< m_npasspart <<
" were retained ");
82 return StatusCode::SUCCESS;
88 const EventContext& ctx = Gaudi::Hive::currentContext();
92 (m_particlesKey, ctx);
97 if (evtStore()->
retrieve(importedTruthEvents,m_eventsKey).isFailure()) {
98 ATH_MSG_ERROR(
"No TruthEventContainer with name " << m_eventsKey <<
" found in StoreGate!");
99 return StatusCode::FAILURE;
105 unsigned int nParticles = importedTruthParticles->size();
106 unsigned int nVertices = importedTruthVertices->size();
107 std::vector<bool> partMask, vertMask;
108 partMask.assign(nParticles,
false);
110 m_ntotvtx +=
nVertices; m_ntotpart += nParticles;
113 if (!m_partString.empty()) {
114 std::vector<int>
entries = m_parser->evaluateAsVector();
118 ATH_MSG_ERROR(
"Sizes incompatible! Are you sure your selection string used TruthParticles?");
119 return StatusCode::FAILURE;
122 for (
unsigned int i=0;
i<nParticles; ++
i)
if (
entries[
i]==1) partMask[
i]=
true;
130 for (
unsigned int i=0;
i<nParticles; ++
i) {
134 std::vector<int> tauDecayProducts;
135 std::unordered_set<int> tauDecayEncounteredUniqueIDs;
137 for (
unsigned int tauDecIt=0; tauDecIt<tauDecayProducts.size(); ++tauDecIt) {
138 if (abs(tauDecayProducts[tauDecIt])==15) {
143 if (!last) partMask[
i]=
false;
155 std::unordered_set<int> encounteredUniqueIDs;
156 if (m_preserveDescendants || m_preserveGeneratorDescendants || m_preserveAncestors) {
157 for (
unsigned int i=0;
i<nParticles; ++
i) {
158 bool toKeep = partMask[
i];
159 if (!toKeep)
continue;
161 encounteredUniqueIDs.clear();
162 if (m_preserveDescendants) decayHelper.
descendants(
particle,partMask,vertMask,encounteredUniqueIDs,
true);
163 encounteredUniqueIDs.clear();
164 if (m_preserveGeneratorDescendants) decayHelper.
descendants(
particle,partMask,vertMask,encounteredUniqueIDs,
false);
165 encounteredUniqueIDs.clear();
166 if (m_preserveAncestors) decayHelper.
ancestors(
particle,partMask,vertMask,encounteredUniqueIDs);
167 encounteredUniqueIDs.clear();
178 m_npasspart +=
std::count (partMask.begin(), partMask.end(),
true);
179 m_npassvtx +=
std::count (vertMask.begin(), vertMask.end(),
true);
182 importedTruthParticles.
keep (partMask);
183 importedTruthVertices.
keep (vertMask);
185 return StatusCode::SUCCESS;