93 if (!truthParticles.isValid()) {
95 return StatusCode::FAILURE;
97 if (!truthVertices.isValid()) {
99 return StatusCode::FAILURE;
104 std::vector<int> recoParticleTruthIndices;
105 std::vector<int> egammaTruthIndices{};
116 recoParticleTruthIndices.push_back(truthMuon->index());
133 recoParticleTruthIndices.push_back(truthElectron->index());
146 recoParticleTruthIndices.push_back(truthElectron->index());
158 recoParticleTruthIndices.push_back(truthPhoton->index());
168 static const SG::AuxElement::ConstAccessor<int> accType(
"truthType");
170 if (!accType.isAvailable(*egTruthParticle) ||
177 static const SG::AuxElement::ConstAccessor<TruthLink_t> linkToTruth(
178 "truthParticleLink");
179 if (!linkToTruth.isAvailable(*egTruthParticle)) {
183 const TruthLink_t& truthegamma = linkToTruth(*egTruthParticle);
187 egammaTruthIndices.push_back((*truthegamma)->index());
192 std::vector<bool> particleMask, vertexMask;
193 int nTruthParticles = truthParticles->size();
194 int nTruthVertices = truthVertices->size();
197 particleMask.assign(nTruthParticles,
false);
198 vertexMask.assign(nTruthVertices,
false);
202 std::vector<std::pair<int, int>> vertexLinksCounts;
203 for (
const auto *vertex : *truthVertices) {
204 std::pair<int, int> tmpPair;
205 tmpPair.first = vertex->nIncomingParticles();
206 tmpPair.second = vertex->nOutgoingParticles();
207 vertexLinksCounts.push_back(tmpPair);
211 std::unordered_set<int> encounteredUniqueIDs;
212 for (
int i = 0; i < nTruthParticles; ++i) {
213 encounteredUniqueIDs.clear();
217 descendants(particle, particleMask, encounteredUniqueIDs);
218 encounteredUniqueIDs.clear();
222 int pdgId = abs(particle->pdgId());
226 if (particle->hasDecayVtx()) {
227 decayVtx = particle->decayVtx();
232 for (
int i = 0; i < nChildren; ++i) {
240 if (std::find(recoParticleTruthIndices.begin(),
241 recoParticleTruthIndices.end(),
242 i) != recoParticleTruthIndices.end()) {
245 ancestors(particle, particleMask, encounteredUniqueIDs);
246 encounteredUniqueIDs.clear();
247 descendants(particle, particleMask, encounteredUniqueIDs);
248 encounteredUniqueIDs.clear();
254 if (std::find(egammaTruthIndices.begin(), egammaTruthIndices.end(), i) !=
255 egammaTruthIndices.end()) {
256 descendants(particle, particleMask, encounteredUniqueIDs);
257 encounteredUniqueIDs.clear();
261 particleMask[i] =
true;
266 if (particle->hasProdVtx()) {
269 for (
int parent = 0; parent < nParents; ++parent) {
274 particleMask[i] =
true;
283 for (
int i = 0; i < nTruthParticles; ++i) {
284 if (!particleMask[i]) {
287 if (particle->hasProdVtx()) {
288 const auto *prodVertex = particle->prodVtx();
289 --vertexLinksCounts[prodVertex->index()].second;
291 if (particle->hasDecayVtx()) {
292 const auto *decayVertex = particle->decayVtx();
293 --vertexLinksCounts[decayVertex->index()].first;
301 unsigned int nVerticesThinned = 0;
302 for (
int i = 0; i < nTruthVertices; ++i) {
303 if (vertexLinksCounts[i].first != 0 || vertexLinksCounts[i].second != 0) {
304 vertexMask[i] =
true;
311 truthParticles.
keep(particleMask);
312 truthVertices.
keep(vertexMask);
314 return StatusCode::SUCCESS;
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
bool hasProdVtx() const
Check for a production vertex on this particle.
bool hasDecayVtx() const
Check for a decay vertex on this particle.
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.