29#include "Gaudi/Property.h"
43 return StatusCode::FAILURE;
75 return StatusCode::SUCCESS;
86 <<
" corresponding truth vertices ");
87 return StatusCode::SUCCESS;
99 if (!truthParticles.isValid()) {
101 return StatusCode::FAILURE;
103 if (!truthVertices.isValid()) {
105 return StatusCode::FAILURE;
110 std::vector<int> recoParticleTruthIndices;
111 std::vector<int> egammaTruthIndices{};
122 recoParticleTruthIndices.push_back(truthMuon->index());
136 recoParticleTruthIndices.push_back(truthMuon->index());
154 recoParticleTruthIndices.push_back(truthElectron->index());
167 recoParticleTruthIndices.push_back(truthElectron->index());
180 recoParticleTruthIndices.push_back(truthElectron->index());
192 recoParticleTruthIndices.push_back(truthPhoton->index());
212 "truthParticleLink");
217 const TruthLink_t& truthegamma = linkToTruth(*egTruthParticle);
221 egammaTruthIndices.push_back((*truthegamma)->index());
226 std::vector<bool> particleMask, vertexMask;
227 int nTruthParticles = truthParticles->size();
228 int nTruthVertices = truthVertices->size();
231 particleMask.assign(nTruthParticles,
false);
232 vertexMask.assign(nTruthVertices,
false);
236 std::vector<std::pair<int, int>> vertexLinksCounts;
237 for (
const auto *vertex : *truthVertices) {
238 std::pair<int, int> tmpPair;
239 tmpPair.first = vertex->nIncomingParticles();
240 tmpPair.second = vertex->nOutgoingParticles();
241 vertexLinksCounts.push_back(tmpPair);
245 std::unordered_set<int> encounteredUniqueIDs;
246 for (
int i = 0; i < nTruthParticles; ++i) {
247 encounteredUniqueIDs.clear();
251 descendants(particle, particleMask, encounteredUniqueIDs);
252 encounteredUniqueIDs.clear();
257 descendants(particle, particleMask, encounteredUniqueIDs);
258 encounteredUniqueIDs.clear();
263 int pdgId = abs(particle->pdgId());
267 if (particle->hasDecayVtx()) {
268 decayVtx = particle->decayVtx();
273 for (
int i = 0; i < nChildren; ++i) {
281 if (std::find(recoParticleTruthIndices.begin(),
282 recoParticleTruthIndices.end(),
283 i) != recoParticleTruthIndices.end()) {
286 ancestors(particle, particleMask, encounteredUniqueIDs);
287 encounteredUniqueIDs.clear();
288 descendants(particle, particleMask, encounteredUniqueIDs);
289 encounteredUniqueIDs.clear();
295 if (std::find(egammaTruthIndices.begin(), egammaTruthIndices.end(), i) !=
296 egammaTruthIndices.end()) {
297 descendants(particle, particleMask, encounteredUniqueIDs);
298 encounteredUniqueIDs.clear();
302 particleMask[i] =
true;
307 if (particle->hasProdVtx()) {
310 for (
int parent = 0; parent < nParents; ++parent) {
315 particleMask[i] =
true;
324 for (
int i = 0; i < nTruthParticles; ++i) {
325 if (!particleMask[i]) {
328 if (particle->hasProdVtx()) {
329 const auto *prodVertex = particle->prodVtx();
330 --vertexLinksCounts[prodVertex->index()].second;
332 if (particle->hasDecayVtx()) {
333 const auto *decayVertex = particle->decayVtx();
334 --vertexLinksCounts[decayVertex->index()].first;
342 unsigned int nVerticesThinned = 0;
343 for (
int i = 0; i < nTruthVertices; ++i) {
344 if (vertexLinksCounts[i].first != 0 || vertexLinksCounts[i].second != 0) {
345 vertexMask[i] =
true;
352 truthParticles.
keep(particleMask);
353 truthVertices.
keep(vertexMask);
355 return StatusCode::SUCCESS;
366 std::vector<bool>& particleMask,
367 std::unordered_set<int>& encounteredUniqueIDs)
const
371 std::unordered_set<int>::const_iterator found =
373 if (found != encounteredUniqueIDs.end())
378 int headIndex = pHead->index();
379 particleMask[headIndex] =
true;
391 for (
int i = 0; i < nParents; ++i)
402 std::vector<bool>& particleMask,
403 std::unordered_set<int>& encounteredUniqueIDs)
const
406 std::unordered_set<int>::const_iterator found =
408 if (found != encounteredUniqueIDs.end())
413 int headIndex = pHead->index();
414 particleMask[headIndex] =
true;
426 for (
int i = 0; i < nChildren; ++i) {
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
ATLAS-specific HepMC functions.
ElementLink< xAOD::TruthParticleContainer > TruthLink_t
Handle for requesting thinning for a data object.
ElementLink implementation for ROOT usage.
bool isValid() const
Check if the element can be found.
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Handle for requesting thinning for a data object.
SG::ReadHandleKey< xAOD::MuonContainer > m_muonsKey
std::atomic< unsigned long > m_nParticlesThinned
SG::ReadHandleKey< xAOD::MuonContainer > m_lrtMuonsKey
void ancestors(const xAOD::TruthParticle *, std::vector< bool > &, std::unordered_set< int > &) const
Inline method.
std::atomic< unsigned long > m_nVerticesProcessed
std::atomic< unsigned long > m_nVerticesThinned
Gaudi::Property< std::string > m_truthLinkDecor
Truth particle link decorations.
SG::ReadHandleKey< xAOD::PhotonContainer > m_photonsKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_egammaTruthKey
virtual StatusCode execute(const EventContext &ctx) const override final
SG::ThinningHandleKey< xAOD::TruthVertexContainer > m_truthVerticesKey
StringProperty m_streamName
virtual StatusCode initialize() override
void descendants(const xAOD::TruthParticle *, std::vector< bool > &, std::unordered_set< int > &) const
Gaudi::Property< std::vector< int > > m_longlived
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronsKey
std::atomic< unsigned long > m_nEventsProcessed
Counters.
SG::ReadDecorHandleKeyArray< xAOD::IParticleContainer > m_readDecorKeys
Schedule the algorithm's dependency on the truth particle link.
SG::ReadHandleKey< xAOD::ElectronContainer > m_lrtElectronsKey
virtual StatusCode finalize() override
Gaudi::Property< bool > m_keepMuons
Gaudi::Property< bool > m_keepEGamma
std::atomic< unsigned long > m_nParticlesProcessed
SG::ThinningHandleKey< xAOD::TruthParticleContainer > m_truthParticlesKey
Gaudi::Property< float > m_etaMaxEgTruth
SG::ReadHandleKey< xAOD::ElectronContainer > m_fwdElectronsKey
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.
const TruthParticle_v1 * outgoingParticle(size_t index) const
Get one of the outgoing particles.
const TruthParticle_v1 * incomingParticle(size_t index) const
Get one of the incoming particles.
size_t nOutgoingParticles() const
Get the number of outgoing particles.
size_t nIncomingParticles() const
Get the number of incoming particles.
::StatusCode StatusCode
StatusCode definition for legacy code.
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isDecayed(const T &p)
Identify if the particle decayed.
bool isBSM(const T &p)
APID: graviton and all Higgs extensions are BSM.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle &p)
Return the truthParticle associated to the given IParticle (if any).
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
TruthVertex_v1 TruthVertex
Typedef to implementation.
TruthParticle_v1 TruthParticle
Typedef to implementation.
Muon_v1 Muon
Reference the current persistent version:
Photon_v1 Photon
Definition of the current "egamma version".
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
Electron_v1 Electron
Definition of the current "egamma version".