diff --git a/Reconstruction/tauRec/src/TauThinningAlg.cxx b/Reconstruction/tauRec/src/TauThinningAlg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..cc7bb45e63821ea08f14ec3eaee26c006e8fc46c --- /dev/null +++ b/Reconstruction/tauRec/src/TauThinningAlg.cxx @@ -0,0 +1,135 @@ +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration. +*/ + +#include "TauThinningAlg.h" +#include "StoreGate/ReadHandle.h" +#include "StoreGate/ThinningHandle.h" +#include "tauRecTools/HelperFunctions.h" + +/** + * @brief Gaudi initialize method. + */ +StatusCode TauThinningAlg::initialize() +{ + ATH_CHECK( m_taus.initialize(m_streamName) ); + ATH_CHECK( m_tauTracks.initialize(m_streamName) ); + ATH_CHECK( m_neutralPFOs.initialize(m_streamName) ); + ATH_CHECK( m_pi0clusters.initialize(m_streamName) ); + ATH_CHECK( m_pi0CellLinks.initialize(m_streamName) ); + ATH_CHECK( m_finalPi0s.initialize(m_streamName) ); + ATH_CHECK( m_shotPFOs.initialize(m_streamName) ); + ATH_CHECK( m_shotclusters.initialize(m_streamName) ); + ATH_CHECK( m_shotCellLinks.initialize(m_streamName) ); + ATH_CHECK( m_hadronicPFOs.initialize(m_streamName) ); + ATH_CHECK( m_secondaryVertices.initialize(m_streamName) ); + + return StatusCode::SUCCESS; +} + +/** + * @brief Execute the algorithm. + * @param ctx Current event context. + */ +StatusCode TauThinningAlg::execute (const EventContext& ctx) const +{ + SG::ThinningHandle<xAOD::TauJetContainer> taus (m_taus, ctx); + taus.thinAll(); + + SG::ThinningHandle<xAOD::TauTrackContainer> tauTracks (m_tauTracks, ctx); + tauTracks.thinAll(); + + SG::ThinningHandle<xAOD::PFOContainer> neutralPFOs (m_neutralPFOs, ctx); + neutralPFOs.thinAll(); + + SG::ThinningHandle<xAOD::CaloClusterContainer> pi0clusters (m_pi0clusters, ctx); + pi0clusters.thinAll(); + + SG::ThinningHandle<CaloClusterCellLinkContainer> pi0CellLinks (m_pi0CellLinks, ctx); + pi0CellLinks.thinAll(); + + SG::ThinningHandle<xAOD::ParticleContainer> finalPi0s (m_finalPi0s, ctx); + finalPi0s.thinAll(); + + SG::ThinningHandle<xAOD::PFOContainer> shotPFOs (m_shotPFOs, ctx); + shotPFOs.thinAll(); + + SG::ThinningHandle<xAOD::CaloClusterContainer> shotclusters (m_shotclusters, ctx); + shotclusters.thinAll(); + + SG::ThinningHandle<CaloClusterCellLinkContainer> shotCellLinks (m_shotCellLinks, ctx); + shotCellLinks.thinAll(); + + SG::ThinningHandle<xAOD::PFOContainer> hadronicPFOs (m_hadronicPFOs, ctx); + hadronicPFOs.thinAll(); + + SG::ThinningHandle<xAOD::VertexContainer> secondaryVertices (m_secondaryVertices, ctx); + secondaryVertices.thinAll(); + + for (const xAOD::TauJet* tau : *taus) { + + if(tau->pt() < m_minTauPt) continue; + + // keep tau + taus.keep(tau->index()); + + // keep tau tracks + for(const xAOD::TauTrack* track : tau->allTracks()) { + tauTracks.keep(track->index()); + } + + // keep neutral PFOs, pi0 clusters and cell links + for(size_t i=0; i<tau->nNeutralPFOs(); i++) { + neutralPFOs.keep(tau->neutralPFO(i)->index()); + + const xAOD::CaloCluster* cluster = tau->neutralPFO(i)->cluster(0); + pi0clusters.keep(cluster->index()); + + const CaloClusterCellLink* cellLinks = cluster->getCellLinks(); + CaloClusterCellLinkContainer::const_iterator cellLinks_it = std::find(pi0CellLinks->begin(), pi0CellLinks->end(), cellLinks); + if(cellLinks_it != pi0CellLinks->end()) { + size_t link_index = std::distance(pi0CellLinks->begin(), cellLinks_it); + pi0CellLinks.keep(link_index); + } + else { + ATH_MSG_WARNING( "Could not find cluster cell link in " << m_pi0CellLinks.key() << ", won't be saved in xAOD." ); + } + } + + // keep final pi0s + for(size_t i=0; i<tau->nPi0s(); i++) { + finalPi0s.keep(tau->pi0(i)->index()); + } + + // keep shot PFOs, clusters and cell links + for(size_t i=0; i<tau->nShotPFOs(); i++) { + shotPFOs.keep(tau->shotPFO(i)->index()); + + const xAOD::CaloCluster* cluster = tau->shotPFO(i)->cluster(0); + shotclusters.keep(cluster->index()); + + const CaloClusterCellLink* cellLinks = cluster->getCellLinks(); + CaloClusterCellLinkContainer::const_iterator cellLinks_it = std::find(shotCellLinks->begin(), shotCellLinks->end(), cellLinks); + if(cellLinks_it != shotCellLinks->end()) { + size_t link_index = std::distance(shotCellLinks->begin(), cellLinks_it); + shotCellLinks.keep(link_index); + } + else { + ATH_MSG_WARNING( "Could not find cluster cell link in " << m_shotCellLinks.key() << ", won't be saved in xAOD." ); + } + } + + // keep hadronic PFOs + for(size_t i=0; i<tau->nHadronicPFOs(); i++) { + hadronicPFOs.keep(tau->hadronicPFO(i)->index()); + } + + // keep secondary vertex when present + static const SG::AuxElement::ConstAccessor< ElementLink< xAOD::VertexContainer > > secondaryVertexAcc( "secondaryVertexLink" ); + if(secondaryVertexAcc(*tau)) { + secondaryVertices.keep(tau->secondaryVertex()->index()); + } + } + + return StatusCode::SUCCESS; +} diff --git a/Reconstruction/tauRec/src/TauThinningAlg.h b/Reconstruction/tauRec/src/TauThinningAlg.h new file mode 100644 index 0000000000000000000000000000000000000000..7636fa474c9585dc697e7e2bab12c258eb117409 --- /dev/null +++ b/Reconstruction/tauRec/src/TauThinningAlg.h @@ -0,0 +1,98 @@ +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration. +*/ + +#ifndef TAUREC_TAUTHINNING_H +#define TAUREC_TAUTHINNING_H + +#include "AthenaBaseComps/AthReentrantAlgorithm.h" +#include "xAODTau/TauJetContainer.h" +#include "xAODTau/TauTrackContainer.h" +#include "xAODPFlow/PFOContainer.h" +#include "xAODCaloEvent/CaloClusterContainer.h" +#include "CaloEvent/CaloClusterCellLinkContainer.h" +#include "xAODTracking/VertexContainer.h" +#include "xAODParticleEvent/ParticleContainer.h" +#include "StoreGate/ThinningHandleKey.h" +#include "GaudiKernel/SystemOfUnits.h" + +/** + * @brief Thin taus below a minimum pt threshold + * + * Thinning algorithm that removes entries from all tau-related containers for tau candidates below a minimum pt threshold + */ +class TauThinningAlg : public AthReentrantAlgorithm +{ + using AthReentrantAlgorithm::AthReentrantAlgorithm; + + public: + + /** + * @brief Gaudi initialize method. + */ + virtual StatusCode initialize() override; + + /** + * @brief Execute the algorithm. + * @param ctx Current event context. + */ + virtual StatusCode execute(const EventContext& ctx) const override; + + + private: + + // tau pt threshold (pt = ptFinalCalib as TauThinning is run after tau reconstruction) + Gaudi::Property<double> m_minTauPt + { this, "MinTauPt", 0.* Gaudi::Units::GeV, "Minimum tau pt" }; + + // Name of the stream being thinned + StringProperty m_streamName + { this, "StreamName", "StreamAOD", "Name of the stream being thinned" }; + + // Tau container to thin + SG::ThinningHandleKey<xAOD::TauJetContainer> m_taus + { this, "Taus", "TauJets", "Tau container to thin" }; + + // Tau track container to thin + SG::ThinningHandleKey<xAOD::TauTrackContainer> m_tauTracks + { this, "TauTracks", "TauTracks", "Tau track container to thin" }; + + // Tau neutral PFO container to thin + SG::ThinningHandleKey<xAOD::PFOContainer> m_neutralPFOs + { this, "TauNeutralPFOs", "TauNeutralParticleFlowObjects", "Tau neutral PFO container to thin" }; + + // Tau pi0 cluster container to thin + SG::ThinningHandleKey<xAOD::CaloClusterContainer> m_pi0clusters + { this, "TauPi0Clusters", "TauPi0Clusters", "Tau pi0 cluster container to thin" }; + + // Tau pi0 cluster cell link container to thin + SG::ThinningHandleKey<CaloClusterCellLinkContainer> m_pi0CellLinks + { this, "Pi0CellLinks", "TauPi0Clusters_links", "Tau pi0 cluster cell link container to thin" }; + + // Tau final pi0 container to thin + SG::ThinningHandleKey<xAOD::ParticleContainer> m_finalPi0s + { this, "TauFinalPi0s", "TauFinalPi0s", "Tau final pi0 container to thin" }; + + // Tau shot PFO container to thin + SG::ThinningHandleKey<xAOD::PFOContainer> m_shotPFOs + { this, "TauShotPFOs", "TauShotParticleFlowObjects", "Tau shot PFO container to thin" }; + + // Tau shot cluster container to thin + SG::ThinningHandleKey<xAOD::CaloClusterContainer> m_shotclusters + { this, "TauShotClusters", "TauShotClusters", "Tau shot cluster container to thin" }; + + // Tau shot cluster cell link container to thin + SG::ThinningHandleKey<CaloClusterCellLinkContainer> m_shotCellLinks + { this, "ShotCellLinks", "TauShotClusters_links", "Tau shot cluster cell link container to thin" }; + + // Tau hadronic PFO container to thin + SG::ThinningHandleKey<xAOD::PFOContainer> m_hadronicPFOs + { this, "TauHadronicPFOs", "TauHadronicParticleFlowObjects", "Tau hadronic PFO container to thin" }; + + // Tau secondary vertex container to thin + SG::ThinningHandleKey<xAOD::VertexContainer> m_secondaryVertices + { this, "TauSecondaryVertices", "TauSecondaryVertices", "Tau secondary vertex container to thin" }; + +}; + +#endif // not TAUREC_TAUTHINNING_H diff --git a/Reconstruction/tauRec/src/components/tauRec_entries.cxx b/Reconstruction/tauRec/src/components/tauRec_entries.cxx index b95afa30f2c1cbfe0e31416300252f613e446658..65c3f697d17e3b05642ffaa4cdd1416b667409b3 100644 --- a/Reconstruction/tauRec/src/components/tauRec_entries.cxx +++ b/Reconstruction/tauRec/src/components/tauRec_entries.cxx @@ -2,8 +2,10 @@ #include "../TauRunnerAlg.h" #include "../TauCellThinningAlg.h" #include "../ClusterCellRelinkAlg.h" +#include "../TauThinningAlg.h" DECLARE_COMPONENT( TauProcessorAlg ) DECLARE_COMPONENT( TauRunnerAlg ) DECLARE_COMPONENT( TauCellThinningAlg ) DECLARE_COMPONENT( ClusterCellRelinkAlg ) +DECLARE_COMPONENT( TauThinningAlg )