Skip to content
Snippets Groups Projects
Commit e1f24d34 authored by Stefan Richter's avatar Stefan Richter
Browse files

Merge branch 'less_barcodes_in_derivation_framework' into '23.0'

Remove barcodes from derivation framework

See merge request atlas/athena!62937
parents 373d4657 7eb23c2c
No related branches found
No related tags found
No related merge requests found
......@@ -20,17 +20,11 @@
#include "MCTruthClassifier/MCTruthClassifier.h"
#include "HepPID/ParticleIDMethods.hh"
#include "AtlasHepMC/MagicNumbers.h"
#include<unordered_set>
#include <unordered_set>
namespace DerivationFramework {
struct DecayGraphHelper {
// Geant4 barcode offset
int g4BarcodeOffset;
DecayGraphHelper(int init_g4BarcodeOffset) {
g4BarcodeOffset = init_g4BarcodeOffset;
}
DecayGraphHelper(void) {
g4BarcodeOffset = HepMC::SIM_BARCODE_THRESHOLD;
DecayGraphHelper() {
}
// Immediate relatives (parents, siblings, children)
......@@ -164,7 +158,7 @@ namespace DerivationFramework {
// Save the particle position in the mask
// If user doesn't want Geant, check and reject Geant particles
if (!includeGeant && pHead->barcode()>g4BarcodeOffset) return;
if (!includeGeant && HepMC::is_simulation_particle(pHead->barcode()) ) return;
int headIndex = pHead->index();
particleMask[headIndex] = true;
......@@ -179,7 +173,7 @@ namespace DerivationFramework {
for (int i=0; i<nChildren; ++i) {
if (decayVtx->outgoingParticle(i)==nullptr) continue;
descendants(decayVtx->outgoingParticle(i),particleMask,vertexMask,encounteredBarcodes,includeGeant);
saveVertex = saveVertex || includeGeant || !(decayVtx->outgoingParticle(i)->barcode()>g4BarcodeOffset);
saveVertex = saveVertex || includeGeant || !(HepMC::is_simulation_particle(decayVtx->outgoingParticle(i)->barcode()));
}
// Save the decay vertex
......@@ -246,7 +240,7 @@ namespace DerivationFramework {
if (!skipPdgCheck && find(pdgId.begin(), pdgId.end(), abs(particle->pdgId())) == pdgId.end()) continue;
//ensure particles are not from GEANT
if (particle->barcode() >= g4BarcodeOffset) continue;
if ( HepMC::is_simulation_particle(particle->barcode())) continue;
//check if we have a neutral particle (threeCharge returns int)
if (chargedOnly && HepPID::threeCharge(particle->pdgId()) == 0) continue;
......
......@@ -48,7 +48,6 @@ namespace DerivationFramework {
bool m_preserveGeneratorDescendants;
bool m_preserveAncestors;
bool m_tauHandling;
int m_geantOffset;
};
}
......
......@@ -140,10 +140,7 @@ namespace DerivationFramework {
mutable std::atomic<unsigned int> m_totpart;
mutable std::atomic<unsigned int> m_removedpart;
mutable std::atomic<int> m_eventCount{};
/// Parameter: simulation barcode offset
int m_geantOffset;
};
}
......
......@@ -31,8 +31,7 @@ m_partString(""),
m_preserveDescendants(false),
m_preserveGeneratorDescendants(false),
m_preserveAncestors(false),
m_tauHandling(true),
m_geantOffset(200000)
m_tauHandling(true)
{
declareProperty("EventsKey", m_eventsKey);
declareProperty("ParticleSelectionString", m_partString);
......@@ -41,7 +40,6 @@ m_geantOffset(200000)
declareProperty("PreserveGeneratorDescendants", m_preserveGeneratorDescendants);
declareProperty("PreserveAncestors", m_preserveAncestors);
declareProperty("TauHandling", m_tauHandling);
declareProperty("SimBarcodeOffset", m_geantOffset);
}
// Destructor
......@@ -163,7 +161,7 @@ StatusCode DerivationFramework::GenericTruthThinning::doThinning() const
// - update the masks including the descendants/ancestors
// To ensure graph completeness, this over-rides anything set by the special treatment
// of taus in the section above
DerivationFramework::DecayGraphHelper decayHelper(m_geantOffset);
DerivationFramework::DecayGraphHelper decayHelper;
std::unordered_set<int> encounteredBarcodes; // to enable loop handling
if (m_preserveDescendants || m_preserveGeneratorDescendants || m_preserveAncestors) {
for (unsigned int i=0; i<nParticles; ++i) {
......
......@@ -28,15 +28,6 @@
using Gaudi::Units::GeV;
namespace {
const int PARTONPDGMAX = 43;
const int NPPDGMIN = 1000000;
const int NPPDGMAX = 8999999;
const int PHOTOSMIN = 10000;
} // anonymous namespace
// Constructor
DerivationFramework::MenuTruthThinning::MenuTruthThinning(const std::string& t,
const std::string& n,
......@@ -45,8 +36,7 @@ base_class(t,n,p),
m_eventsKey("TruthEvents"),
m_writeFirstN(-1),
m_totpart(0),
m_removedpart(0),
m_geantOffset(200000)
m_removedpart(0)
{
declareProperty ("EventsKey",
m_eventsKey = "TruthEvents",
......@@ -153,10 +143,6 @@ m_geantOffset(200000)
m_preserveHadVtx = false,
"Preserve hadronization vertices with parents/children.");
declareProperty("SimBarcodeOffset",
m_geantOffset = 200000,
"Barcode offset for simulation particles");
declareProperty ("WritettHFHadrons",
m_writettHFHadrons = false,
"Keep tt+HF hadrons?");
......@@ -264,7 +250,7 @@ StatusCode DerivationFramework::MenuTruthThinning::doThinning() const
// - update the masks including the descendants/ancestors
// To ensure graph completeness, this over-rides anything set by the special treatment
// of taus in the section above
DerivationFramework::DecayGraphHelper decayHelper(m_geantOffset);
DerivationFramework::DecayGraphHelper decayHelper;
std::unordered_set<int> encounteredBarcodes; // For loop handling
if (m_preserveDescendants || m_preserveGeneratorDescendants || m_preserveAncestors) {
for (int i=0; i<nTruthParticles; ++i) {
......@@ -318,7 +304,7 @@ bool DerivationFramework::MenuTruthThinning::isAccepted(const xAOD::TruthParticl
}
if (barcode > m_geantOffset && !m_writeGeant && !m_writeEverything && !ok) {
if (HepMC::is_simulation_particle(barcode) && !m_writeGeant && !m_writeEverything && !ok) {
if (! (pdg_id == 22/*PDG::gamma*/ &&
m_geantPhotonPtThresh >= 0 &&
p->pt() > m_geantPhotonPtThresh) )
......@@ -335,29 +321,29 @@ bool DerivationFramework::MenuTruthThinning::isAccepted(const xAOD::TruthParticl
// OK if we select partons and are at beginning of event record
if( m_writePartons &&
(pdg_id <= PARTONPDGMAX || (pdg_id >= NPPDGMIN && pdg_id <= NPPDGMAX) ) &&
(pdg_id <= HepMC::PARTONPDGMAX || (pdg_id >= HepMC::NPPDGMIN && pdg_id <= HepMC::NPPDGMAX) ) &&
(m_partonPtThresh<0 || p->pt()>m_partonPtThresh) )
ok = true;
// OK if we should select hadrons and are in hadron range
// JRC: cut changed from PHOTOSMIN to m_geantOffset
if( m_writeHadrons && HepPID::isHadron (pdg_id) && barcode < m_geantOffset )
if( m_writeHadrons && HepPID::isHadron (pdg_id) && !HepMC::is_simulation_particle(barcode) )
ok = true;
// OK if we should select b hadrons and are in hadron range
// JRC: cut changed from PHOTOSMIN to m_geantOffset
if( m_writeBHadrons && barcode < m_geantOffset && HepPID::isHadron (pdg_id) && HepPID::hasBottom (pdg_id) )
if( m_writeBHadrons && !HepMC::is_simulation_particle(barcode) && HepPID::isHadron (pdg_id) && HepPID::hasBottom (pdg_id) )
ok= true;
// OK if we should select c hadrons and are in hadron range
// JRC: cut changed from PHOTOSMIN to m_geantOffset
if( m_writeCHadrons && barcode < m_geantOffset && HepPID::isHadron (pdg_id) && HepPID::hasCharm (pdg_id) )
if( m_writeCHadrons && !HepMC::is_simulation_particle(barcode) && HepPID::isHadron (pdg_id) && HepPID::hasCharm (pdg_id) )
ok= true;
// PHOTOS range: check whether photons come from parton range or
// hadron range
int motherPDGID = 999999999;
if( barcode > PHOTOSMIN && barcode < m_geantOffset &&
if( barcode > HepMC::PHOTOSMIN && !HepMC::is_simulation_particle(barcode) &&
p->hasProdVtx() )
{
const xAOD::TruthVertex* vprod = p->prodVtx();
......@@ -372,7 +358,7 @@ bool DerivationFramework::MenuTruthThinning::isAccepted(const xAOD::TruthParticl
}
// OK if we should select G4 particles and are in G4 range
if( m_writeGeant && barcode > m_geantOffset )
if( m_writeGeant && HepMC::is_simulation_particle(barcode) )
ok = true;
if(isLeptonFromTau(p))
......@@ -409,7 +395,7 @@ bool DerivationFramework::MenuTruthThinning::isAccepted(const xAOD::TruthParticl
ok = true;
// All stable
if (m_writeAllStable && p->status()==1 && barcode<m_geantOffset)
if (m_writeAllStable && p->status()==1 && !HepMC::is_simulation_particle(barcode))
ok = true;
// All leptons not from hadron decays
......@@ -720,7 +706,7 @@ bool DerivationFramework::MenuTruthThinning::isBoson(const xAOD::TruthParticle*
bool DerivationFramework::MenuTruthThinning::isFsrFromLepton(const xAOD::TruthParticle* part) const {
int pdg = part->pdgId();
if(abs(pdg) != 22) return false; // photon
if(part->barcode() >= m_geantOffset) return false; // Geant photon
if(HepMC::is_simulation_particle(part->barcode()) ) return false; // Geant photon
const xAOD::TruthVertex* prod = part->prodVtx();
if(!prod) return false; // no parent.
// Simple loop check
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment