58 ATH_MSG_FATAL(
"No key provided for the new truth particle collection");
59 return StatusCode::FAILURE;
72 return StatusCode::SUCCESS;
81 static const bool is_sherpa = [
this]() {
82 bool is_sherpa =
false;
92 if (
m_metaStore->retrieve(truthMetaData).isSuccess() && !truthMetaData->
empty()){
94 const std::string gens = truthMetaData->
at(0)->generators();
95 is_sherpa = (gens.find(
"sherpa")==std::string::npos &&
96 gens.find(
"Sherpa")==std::string::npos &&
97 gens.find(
"SHERPA")==std::string::npos) ? false :
true;
100 ATH_MSG_WARNING(
"Found xAODTruthMetaDataContainer empty! Configuring to be NOT Sherpa.");
102 ATH_MSG_INFO(
"From metadata configured: Sherpa? " << is_sherpa);
105 ATH_MSG_WARNING(
"Could not find metadata container in storegate; assuming NOT Sherpa");
112 if (!truthParticles.
isValid()) {
114 return StatusCode::FAILURE;
119 ATH_CHECK(newParticlesWriteHandle.
record(std::make_unique<xAOD::TruthParticleContainer>(),
120 std::make_unique<xAOD::TruthParticleAuxContainer>()));
135 for (
unsigned int i=0; i<truthParticles->size(); ++i) {
138 if (!theParticle)
continue;
139 if (!theParticle->
isLepton())
continue;
148 bool has_parent_of_same_flavour =
false;
150 for (
size_t p = 0; p < theParticle->
prodVtx()->nIncomingParticles(); ++p){
151 if (theParticle->
parent(p)->
pdg_id() == theParticle->
pdg_id()) has_parent_of_same_flavour =
true;
153 if (has_parent_of_same_flavour)
continue;
156 bool physical =
false, has_V =
false;
186 size_t bad_parent = 0;
188 if (!theParticle->
parent(p)) { bad_parent++;
continue;}
191 if (bad_parent != 0)
continue;
198 newParticlesWriteHandle->push_back( xTruthParticle );
200 *xTruthParticle=*theParticle;
202 typeDecorator(*xTruthParticle) = typeAccessor(*theParticle);
203 originDecorator(*xTruthParticle) = originAccessor(*theParticle);
204 outcomeDecorator(*xTruthParticle) = outcomeAccessor(*theParticle);
205 classificationDecorator(*xTruthParticle) = classificationAccessor(*theParticle);
208 return StatusCode::SUCCESS;
215 if (!p)
return false;
219 for (
size_t c=0;c<p->nChildren();++c){
220 if (!p->child(c))
continue;
221 if (p->pdgId()!=p->child(c)->pdgId())
continue;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Helper class to provide constant type-safe access to aux data.
ATLAS-specific HepMC functions.
Handle class for reading a decoration on an object.
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
Handle class for recording to StoreGate.
const T * at(size_type n) const
Access an element, as an rvalue.
bool empty() const noexcept
Returns true if the collection is empty.
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_particlesKey
< Input particle collection key
bool hasBareDescendent(const xAOD::TruthParticle *p) const
Helper function for finding bare descendents of born leptons.
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_originDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_typeDecoratorKey
ServiceHandle< StoreGateSvc > m_metaStore
Handle on the metadata store for init.
~TruthBornLeptonCollectionMaker()
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_classificationAccessorKey
Output particle collection key.
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_outcomeAccessorKey
virtual StatusCode addBranches(const EventContext &ctx) const
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_collectionName
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_outcomeDecoratorKey
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_originAccessorKey
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_typeAccessorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_classificationDecoratorKey
TruthBornLeptonCollectionMaker(const std::string &t, const std::string &n, const IInterface *p)
Handle class for reading a decoration on an object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
int pdg_id() const
PDG ID code.
const TruthParticle_v1 * parent(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
bool hasProdVtx() const
Check for a production vertex on this particle.
bool isLepton() const
Whether the particle is a lepton.
bool isW() const
Check if this particle is a W boson.
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
bool isZ() const
Check if this particle is a Z boson.
bool isHiggs() const
Check if this particle is a Higgs boson.
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 isConditionB(const T &p)
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.
TruthMetaDataContainer_v1 TruthMetaDataContainer
Declare the latest version of the truth vertex container.
TruthVertex_v1 TruthVertex
Typedef to implementation.
TruthParticle_v1 TruthParticle
Typedef to implementation.