Skip to content
Snippets Groups Projects
Commit bb954486 authored by Johannes Junggeburth's avatar Johannes Junggeburth :dog2: Committed by Duc Ta
Browse files

ThinGeant4Algs - Fix TruthThinning for muons & declare dependency on the truth decorations

ThinGeant4Algs -  Fix TruthThinning for muons & declare dependency on the truth decorations
parent fefa3f71
Branches
Tags
2 merge requests!796892025-05-01: merge of 24.0 into main,!79346ThinGeant4Algs - Fix TruthThinning for muons & declare dependency on the truth decorations
......@@ -24,7 +24,7 @@
namespace {
const SG::AuxElement::Decorator<int> dec_truthOrigin{"truthOrigin"};
const SG::AuxElement::Decorator<int> dec_truthType{"truthType"};
const std::vector<float> emptyVec;
const SG::Accessor<ElementLink<xAOD::TruthParticleContainer>> dec_truthLink{"truthParticleLink"};
// Only reject muons from light quark deays
const std::set<int> bad_origins{
......@@ -82,12 +82,8 @@ namespace Muon {
// Execute method:
StatusCode MuonTruthDecorationAlg::execute(const EventContext& ctx) const {
// skip if no input data found
SG::ReadHandle<xAOD::TruthParticleContainer> truthContainer(m_truthParticleContainerName, ctx);
if (!truthContainer.isPresent()) return StatusCode::SUCCESS;
if (!truthContainer.isValid()) {
ATH_MSG_WARNING("truth container " << truthContainer.name() << " not valid");
return StatusCode::FAILURE;
}
const xAOD::TruthParticleContainer* truthContainer{nullptr};
ATH_CHECK(SG::get(truthContainer, m_truthParticleContainerName, ctx));
// create output container
SG::WriteHandle<xAOD::TruthParticleContainer> muonTruthContainer(m_muonTruthParticleContainerName, ctx);
......@@ -116,6 +112,9 @@ namespace Muon {
truthParticle->setE(truth->e());
truthParticle->setM(truth->m());
if (truth->hasProdVtx()) truthParticle->setProdVtxLink(truth->prodVtxLink());
dec_truthLink(*truthParticle) = ElementLink<xAOD::TruthParticleContainer>{*truthContainer, truth->index()};
ElementLink<xAOD::TruthParticleContainer> truthLink(*muonTruthContainer, muonTruthContainer->size() - 1);
truthLink.toPersistent();
ATH_MSG_DEBUG("Found stable muon: " << truth->pt() << " eta " << truth->eta() << " phi " << truth->phi() << " mass "
......@@ -357,7 +356,7 @@ namespace Muon {
float& epx = truthParticle.auxdata<float>(r_name + "_px_extr");
float& epy = truthParticle.auxdata<float>(r_name + "_py_extr");
float& epz = truthParticle.auxdata<float>(r_name + "_pz_extr");
truthParticle.auxdata<std::vector<float> >(r_name + "_cov_extr") = emptyVec;
truthParticle.auxdata<std::vector<float> >(r_name + "_cov_extr") = std::vector<float>{};
truthParticle.auxdata<bool>(r_name+"_is_extr") = false;
ex = ey = ez = epx = epy = epz = dummy_val;
......
......@@ -52,6 +52,19 @@ ThinGeantTruthAlg::initialize()
ATH_CHECK(m_photonsKey.initialize(m_keepEGamma));
ATH_CHECK(m_muonsKey.initialize(m_keepMuons));
ATH_CHECK(m_egammaTruthKey.initialize(m_keepEGamma));
if (m_keepEGamma) {
m_readDecorKeys.emplace_back(m_electronsKey, m_truthLinkDecor);
m_readDecorKeys.emplace_back(m_photonsKey, m_truthLinkDecor);
if (!m_fwdElectronsKey.empty()){
m_readDecorKeys.emplace_back(m_fwdElectronsKey, m_truthLinkDecor);
}
}
if (!m_muonsKey.empty()){
m_readDecorKeys.emplace_back(m_muonsKey, m_truthLinkDecor);
}
ATH_CHECK(m_readDecorKeys.initialize());
return StatusCode::SUCCESS;
}
......@@ -75,10 +88,8 @@ ThinGeantTruthAlg::execute(const EventContext& ctx) const
++m_nEventsProcessed;
// Retrieve truth and vertex containers
SG::ThinningHandle<xAOD::TruthParticleContainer> truthParticles(
m_truthParticlesKey, ctx);
SG::ThinningHandle<xAOD::TruthVertexContainer> truthVertices(
m_truthVerticesKey, ctx);
SG::ThinningHandle truthParticles{m_truthParticlesKey, ctx};
SG::ThinningHandle truthVertices{m_truthVerticesKey, ctx};
if (!truthParticles.isValid()) {
ATH_MSG_FATAL("No TruthParticleContainer with key " << m_truthParticlesKey.key() << " found.");
return StatusCode::FAILURE;
......@@ -95,16 +106,15 @@ ThinGeantTruthAlg::execute(const EventContext& ctx) const
// Muons
if (m_keepMuons) {
SG::ReadHandle<xAOD::MuonContainer> muons(m_muonsKey, ctx);
// Retrieve muons, electrons and photons
if (!muons.isValid()) {
ATH_MSG_WARNING("No muon container with key " << m_muonsKey.key() << " found.");
}
const xAOD::MuonContainer* muons{nullptr};
ATH_CHECK(SG::get(muons, m_muonsKey, ctx));
for (const xAOD::Muon* muon : *muons) {
const xAOD::TruthParticle* truthMuon =
xAOD::TruthHelpers::getTruthParticle(*muon);
const xAOD::TruthParticle* truthMuon = xAOD::TruthHelpers::getTruthParticle(*muon);
if (truthMuon) {
recoParticleTruthIndices.push_back(truthMuon->index());
truthMuon = xAOD::TruthHelpers::getTruthParticle(*truthMuon);
if (truthMuon) {
recoParticleTruthIndices.push_back(truthMuon->index());
}
}
}
}
......@@ -113,10 +123,9 @@ ThinGeantTruthAlg::execute(const EventContext& ctx) const
if (m_keepEGamma) {
// Electrons
SG::ReadHandle<xAOD::ElectronContainer> electrons(m_electronsKey, ctx);
if (!electrons.isValid()) {
ATH_MSG_WARNING("No electron container with key " << m_electronsKey.key() << " found.");
}
const xAOD::ElectronContainer* electrons{nullptr};
ATH_CHECK(SG::get(electrons, m_electronsKey, ctx));
for (const xAOD::Electron* electron : *electrons) {
const xAOD::TruthParticle* truthElectron =
xAOD::TruthHelpers::getTruthParticle(*electron);
......@@ -126,13 +135,10 @@ ThinGeantTruthAlg::execute(const EventContext& ctx) const
}
// Forward Electrons
if (!m_fwdElectronsKey.empty()) {
SG::ReadHandle<xAOD::ElectronContainer> fwdElectrons(m_fwdElectronsKey,
ctx);
if (!fwdElectrons.isValid()) {
ATH_MSG_WARNING("No forward electron container with key "
<< m_fwdElectronsKey.key() << " found.");
}
const xAOD::ElectronContainer* fwdElectrons{nullptr};
ATH_CHECK(SG::get(fwdElectrons, m_fwdElectronsKey, ctx));
if (fwdElectrons) {
for (const xAOD::Electron* electron : *fwdElectrons) {
const xAOD::TruthParticle* truthElectron =
xAOD::TruthHelpers::getTruthParticle(*electron);
......@@ -143,11 +149,8 @@ ThinGeantTruthAlg::execute(const EventContext& ctx) const
}
// Photons
SG::ReadHandle<xAOD::PhotonContainer> photons(m_photonsKey, ctx);
if (!photons.isValid()) {
ATH_MSG_WARNING("No photon container with key " << m_photonsKey.key() << " found.");
}
const xAOD::PhotonContainer* photons{nullptr};
ATH_CHECK(SG::get(photons, m_photonsKey, ctx));
for (const xAOD::Photon* photon : *photons) {
const xAOD::TruthParticle* truthPhoton =
xAOD::TruthHelpers::getTruthParticle(*photon);
......@@ -157,11 +160,8 @@ ThinGeantTruthAlg::execute(const EventContext& ctx) const
}
// egamma Truth Particles
SG::ReadHandle<xAOD::TruthParticleContainer> egammaTruthParticles(
m_egammaTruthKey, ctx);
if (!egammaTruthParticles.isValid()) {
ATH_MSG_WARNING("No e-gamma truth container with key " << m_egammaTruthKey.key() << " found.");
}
const xAOD::TruthParticleContainer* egammaTruthParticles{nullptr};
ATH_CHECK(SG::get(egammaTruthParticles, m_egammaTruthKey, ctx));
for (const xAOD::TruthParticle* egTruthParticle : *egammaTruthParticles) {
......
......@@ -25,6 +25,7 @@
#include "xAODMuon/MuonContainer.h"
#include "xAODTruth/TruthParticleContainer.h"
#include "xAODTruth/TruthVertexContainer.h"
#include "StoreGate/ReadDecorHandleKeyArray.h"
class ThinGeantTruthAlg final: public AthReentrantAlgorithm
{
......@@ -56,6 +57,11 @@ private:
Gaudi::Property<bool> m_keepMuons{ this, "keepMuons", true };
Gaudi::Property<bool> m_keepEGamma{ this, "keepEGamma", true };
/** @brief Truth particle link decorations */
Gaudi::Property<std::string> m_truthLinkDecor{this, "TruthLinkDecor", "truthParticleLink"};
/** @brief Schedule the algorithm's dependency on the truth particle link */
SG::ReadDecorHandleKeyArray<xAOD::IParticleContainer> m_readDecorKeys{this, "DecorKeys", {}};
Gaudi::Property<std::vector<int>> m_longlived{
this,
"LongLivedParticleList",
......
......@@ -923,6 +923,7 @@ MuonTruthParticlesAuxDyn.recoMuonLinkLRT
MuonTruthParticlesAuxDyn.truthCscHits
MuonTruthParticlesAuxDyn.truthMdtHits
MuonTruthParticlesAuxDyn.truthOrigin
MuonTruthParticlesAuxDyn.truthParticleLink
MuonTruthParticlesAuxDyn.truthRpcHits
MuonTruthParticlesAuxDyn.truthTgcHits
MuonTruthParticlesAuxDyn.truthType
......
......@@ -1883,6 +1883,7 @@ MuonTruthParticlesAuxDyn.recoMuonLinkLRT
MuonTruthParticlesAuxDyn.truthMMHits
MuonTruthParticlesAuxDyn.truthMdtHits
MuonTruthParticlesAuxDyn.truthOrigin
MuonTruthParticlesAuxDyn.truthParticleLink
MuonTruthParticlesAuxDyn.truthRpcHits
MuonTruthParticlesAuxDyn.truthStgcHits
MuonTruthParticlesAuxDyn.truthTgcHits
......
......@@ -24,8 +24,8 @@ references_map = {
# Reco
"q442": "v11",
"q449": "v33",
"q452": "v12",
"q454": "v25",
"q452": "v14",
"q454": "v27",
# Derivations
"data_PHYS_Run2": "v3",
"data_PHYS_Run3": "v5",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment