31#include "Gaudi/Property.h"
45 return StatusCode::FAILURE;
69 return StatusCode::SUCCESS;
80 <<
" corresponding truth vertices ");
81 return StatusCode::SUCCESS;
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());
178 "truthParticleLink");
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;
325 std::vector<bool>& particleMask,
326 std::unordered_set<int>& encounteredUniqueIDs)
const
330 std::unordered_set<int>::const_iterator found =
332 if (found != encounteredUniqueIDs.end())
337 int headIndex = pHead->
index();
338 particleMask[headIndex] =
true;
350 for (
int i = 0; i < nParents; ++i)
361 std::vector<bool>& particleMask,
362 std::unordered_set<int>& encounteredUniqueIDs)
const
365 std::unordered_set<int>::const_iterator found =
367 if (found != encounteredUniqueIDs.end())
372 int headIndex = pHead->
index();
373 particleMask[headIndex] =
true;
385 for (
int i = 0; i < nChildren; ++i) {
#define ATH_CHECK
Evaluate an expression and check for errors.
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
Test to see if the link can be dereferenced.
SG::ConstAccessor< T, ALLOC > ConstAccessor
size_t index() const
Return the index of this element within its container.
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
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.
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.
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".