diff --git a/Reconstruction/egamma/egammaAlgs/egammaAlgs/egammaRecBuilder.h b/Reconstruction/egamma/egammaAlgs/egammaAlgs/egammaRecBuilder.h new file mode 100755 index 0000000000000000000000000000000000000000..d1c74505f78fcfbfcca4169877527230afd2f9b0 --- /dev/null +++ b/Reconstruction/egamma/egammaAlgs/egammaAlgs/egammaRecBuilder.h @@ -0,0 +1,76 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef EGAMMAALGS_EGAMMARECBUILDER_H +#define EGAMMAALGS_EGAMMARECBUILDER_H +/** + @class egammaRecBuilder + + This is algorithm produces the initial egammaRecs as a step of the + egamma supercluster algorithms. + +*/ + +// INCLUDE HEADER FILES: +#include <vector> + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "GaudiKernel/ToolHandle.h" +#include "GaudiKernel/IChronoStatSvc.h" + +#include "xAODCaloEvent/CaloClusterContainer.h" +#include "StoreGate/ReadHandleKey.h" +#include "StoreGate/WriteHandleKey.h" +#include "egammaRecEvent/egammaRecContainer.h" + +class IEMTrackMatchBuilder; +class IEMConversionBuilder; + +class egammaRecBuilder : public AthAlgorithm +{ + public: + + /** @brief Default constructor*/ + egammaRecBuilder(const std::string& name, ISvcLocator* pSvcLocator); + + /** @brief initialize method*/ + StatusCode initialize(); + /** @brief finalize method*/ + StatusCode finalize(); + /** @brief execute method*/ + StatusCode execute(); + + private: + + /** @brief retrieve EMTrackMatchBuilder **/ + StatusCode RetrieveEMTrackMatchBuilder(); + /** @brief retrieve EMConversionBuilder **/ + StatusCode RetrieveEMConversionBuilder(); + /** @brief Key for the topo cluster input collection */ + SG::ReadHandleKey<xAOD::CaloClusterContainer> m_inputTopoClusterContainerKey; + /** @brief Key for egammaRec container */ + SG::WriteHandleKey<EgammaRecContainer> m_egammaRecContainerKey; + /** @brief Name of input super cluster electron egammaRec container */ + + // + // The tools + // + /** @brief Tool to perform track matching*/ + ToolHandle<IEMTrackMatchBuilder> m_trackMatchBuilder; + /** @brief Tool to retrieve the conversions*/ + ToolHandle<IEMConversionBuilder> m_conversionBuilder; + // + // All booleans + // + /** @brief private member flag to do the TrackMatching (and conversion building)*/ + bool m_doTrackMatching; + /** @brief private member flag to do the conversion building and matching */ + bool m_doConversions; + // + // Other properties. + // + IChronoStatSvc* m_timingProfile; +}; + +#endif diff --git a/Reconstruction/egamma/egammaAlgs/src/components/egammaAlgs_entries.cxx b/Reconstruction/egamma/egammaAlgs/src/components/egammaAlgs_entries.cxx index fdf1501299fb00a830b078e6f75310e7bba134e2..99e380bad6fc613866c5058d1ed5e85e5d9de828 100755 --- a/Reconstruction/egamma/egammaAlgs/src/components/egammaAlgs_entries.cxx +++ b/Reconstruction/egamma/egammaAlgs/src/components/egammaAlgs_entries.cxx @@ -1,5 +1,6 @@ #include "GaudiKernel/DeclareFactoryEntries.h" #include "egammaAlgs/egammaBuilder.h" +#include "egammaAlgs/egammaRecBuilder.h" #include "egammaAlgs/topoEgammaBuilder.h" #include "egammaAlgs/egammaForwardBuilder.h" #include "egammaAlgs/egammaTruthAssociationAlg.h" @@ -11,6 +12,7 @@ #include "egammaAlgs/egammaTopoClusterCopier.h" DECLARE_ALGORITHM_FACTORY( egammaBuilder ) +DECLARE_ALGORITHM_FACTORY( egammaRecBuilder ) DECLARE_ALGORITHM_FACTORY( topoEgammaBuilder ) DECLARE_ALGORITHM_FACTORY( egammaForwardBuilder ) DECLARE_ALGORITHM_FACTORY( egammaTruthAssociationAlg) @@ -23,6 +25,7 @@ DECLARE_ALGORITHM_FACTORY( egammaTopoClusterCopier ) DECLARE_FACTORY_ENTRIES(egammaAlgs) { DECLARE_ALGORITHM( egammaBuilder ) + DECLARE_ALGORITHM( egammaRecBuilder ) DECLARE_ALGORITHM( topoEgammaBuilder ) DECLARE_ALGORITHM( egammaForwardBuilder ) DECLARE_ALGORITHM( egammaTruthAssociationAlg ) diff --git a/Reconstruction/egamma/egammaAlgs/src/egammaRecBuilder.cxx b/Reconstruction/egamma/egammaAlgs/src/egammaRecBuilder.cxx new file mode 100755 index 0000000000000000000000000000000000000000..fff0923b79ff1180e93f21f6a80135b15c9a7924 --- /dev/null +++ b/Reconstruction/egamma/egammaAlgs/src/egammaRecBuilder.cxx @@ -0,0 +1,209 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + +#include "egammaAlgs/egammaRecBuilder.h" + +#include "AthenaKernel/errorcheck.h" +#include "GaudiKernel/IToolSvc.h" +#include "StoreGate/ReadHandle.h" +#include "StoreGate/WriteHandle.h" + +#include "xAODCaloEvent/CaloClusterContainer.h" +#include "egammaRecEvent/egammaRecContainer.h" +#include "egammaInterfaces/IEMTrackMatchBuilder.h" +#include "egammaInterfaces/IEMConversionBuilder.h" +#include "egammaInterfaces/IegammaCheckEnergyDepositTool.h" +#include "egammaUtils/egammaDuplicateRemoval.h" +#include "CaloUtils/CaloClusterStoreHelper.h" + +// INCLUDE GAUDI HEADER FILES: +#include <algorithm> +#include <cmath> + +using CLHEP::MeV; +using CLHEP::GeV; + +namespace{ + class smallChrono{ + public: + smallChrono(IChronoStatSvc* timingProfile, const std::string& name): + m_time(timingProfile), + m_name(name){ + if(m_time){ + m_time->chronoStart(m_name); + } + } + ~smallChrono(){ + if(m_time){ + m_time->chronoStop(m_name); + } + } + private: + IChronoStatSvc* m_time; + const std::string m_name; + }; +} + + +egammaRecBuilder::egammaRecBuilder(const std::string& name, + ISvcLocator* pSvcLocator): + AthAlgorithm(name, pSvcLocator), + m_doTrackMatching(true), + m_doConversions(true), + m_timingProfile(0){ + + //Containers + declareProperty("InputTopoClusterContainerName", + m_inputTopoClusterContainerKey = "egammaTopoCluster", + "Name of input cluster container"); + + declareProperty("egammaRecContainer", + m_egammaRecContainerKey="egammaRecCollection", + "Output container for egammaRec objects"); + + // Handle of TrackMatchBuilder + declareProperty("TrackMatchBuilderTool", m_trackMatchBuilder, + "Handle of TrackMatchBuilder"); + + // Handle of Conversion Builder + declareProperty("ConversionBuilderTool",m_conversionBuilder, + "Handle of Conversion Builder"); + + // All booleans + + // Boolean to do track matching + declareProperty("doTrackMatching",m_doTrackMatching= true, + "Boolean to do track matching (and conversion building)"); + + // Boolean to do conversion reconstruction + declareProperty("doConversions",m_doConversions= true, + "Boolean to do conversion building / matching"); + +} + +// ================================================================= +StatusCode egammaRecBuilder::initialize() +{ + // initialize method + + ATH_MSG_DEBUG("Initializing egammaRecBuilder"); + + // First the data handle keys + ATH_CHECK(m_inputTopoClusterContainerKey.initialize()); + ATH_CHECK(m_egammaRecContainerKey.initialize()); + + ////////////////////////////////////////////////// + // retrieve track match builder + CHECK( RetrieveEMTrackMatchBuilder() ); + // retrieve conversion builder + CHECK( RetrieveEMConversionBuilder() ); + + // retrieve timing profile + CHECK( service("ChronoStatSvc",m_timingProfile) ); + + ATH_MSG_DEBUG("Initialization completed successfully"); + return StatusCode::SUCCESS; +} + +// ==================================================================== +StatusCode egammaRecBuilder::RetrieveEMTrackMatchBuilder(){ + // retrieve EMTrackMatchBuilder tool + if (!m_doTrackMatching) { + return StatusCode::SUCCESS; + } + + if (m_trackMatchBuilder.empty()) { + ATH_MSG_ERROR("EMTrackMatchBuilder is empty, but track matching is enabled"); + return StatusCode::FAILURE; + } + + if(m_trackMatchBuilder.retrieve().isFailure()) { + ATH_MSG_ERROR("Unable to retrieve "<<m_trackMatchBuilder); + return StatusCode::FAILURE; + } + else ATH_MSG_DEBUG("Retrieved Tool "<<m_trackMatchBuilder); + + return StatusCode::SUCCESS; +} +// ==================================================================== +StatusCode egammaRecBuilder::RetrieveEMConversionBuilder(){ + // + // retrieve EMConversionBuilder tool + // + if (!m_doConversions) { + return StatusCode::SUCCESS; + } + if (m_conversionBuilder.empty()) { + ATH_MSG_ERROR("EMConversionBuilder is empty"); + return StatusCode::FAILURE; + } + if(m_conversionBuilder.retrieve().isFailure()) { + ATH_MSG_ERROR("Unable to retrieve "<<m_conversionBuilder); + return StatusCode::FAILURE; + } + else ATH_MSG_DEBUG("Retrieved Tool "<<m_conversionBuilder); + + return StatusCode::SUCCESS; +} + +// ==================================================================== +StatusCode egammaRecBuilder::finalize(){ + // finalize method + return StatusCode::SUCCESS; +} + +// ====================================================================== +StatusCode egammaRecBuilder::execute(){ + // athena execute method + + ATH_MSG_DEBUG("Executing egammaRecBuilder"); + + // Chrono name for each Tool + std::string chronoName; + + SG::ReadHandle<xAOD::CaloClusterContainer> topoclusters(m_inputTopoClusterContainerKey); + if (!topoclusters.isValid()) { + ATH_MSG_ERROR("Could not retrieve cluster container"); + return StatusCode::FAILURE; + } else { + ATH_MSG_DEBUG("Retrieved input cluster container"); + } + + //Build the initial egamma Rec objects for all copied Topo Clusters + SG::WriteHandle<EgammaRecContainer> egammaRecs(m_egammaRecContainerKey); + ATH_CHECK(egammaRecs.record(std::make_unique<EgammaRecContainer>())); + + for (size_t i(0); i < topoclusters->size(); i++) { + const ElementLink< xAOD::CaloClusterContainer > clusterLink( *topoclusters, i ); + const std::vector< ElementLink<xAOD::CaloClusterContainer> > ClusterLink {clusterLink}; + auto egRec = std::make_unique<egammaRec>(); + egRec->setCaloClusters( ClusterLink ); + egammaRecs->push_back( std::move(egRec) ); + } + + ///Append track Matching information + if (m_doTrackMatching){ + smallChrono timer(m_timingProfile, this->name()+"_"+m_trackMatchBuilder->name()+"_AllClusters"); + for (auto egRec : *egammaRecs) { + if (m_trackMatchBuilder->executeRec(egRec).isFailure()){ + ATH_MSG_ERROR("Problem executing TrackMatchBuilder"); + return StatusCode::FAILURE; + } + } + } + //Do the conversion matching + if (m_doConversions){ + ATH_MSG_DEBUG("Running ConversionBuilder"); + smallChrono timer(m_timingProfile, this->name()+"_"+m_conversionBuilder->name()+"_AllClusters"); + for (auto egRec : *egammaRecs) { + if (m_conversionBuilder->executeRec(egRec).isFailure()){ + ATH_MSG_ERROR("Problem executing " << m_conversionBuilder); + return StatusCode::FAILURE; + } + } + } + return StatusCode::SUCCESS; +} +//----------------------------------------------------------------- diff --git a/Reconstruction/egamma/egammaInterfaces/egammaInterfaces/IEMConversionBuilder.h b/Reconstruction/egamma/egammaInterfaces/egammaInterfaces/IEMConversionBuilder.h index 59895b42d655e6099200740a8fdc81a37835bc45..46f1b462501d40939031c66588f5224c243926fe 100755 --- a/Reconstruction/egamma/egammaInterfaces/egammaInterfaces/IEMConversionBuilder.h +++ b/Reconstruction/egamma/egammaInterfaces/egammaInterfaces/IEMConversionBuilder.h @@ -40,7 +40,7 @@ class IEMConversionBuilder : virtual public IegammaBaseTool /** @brief initialize method*/ virtual StatusCode initialize() = 0; /** @brief execute method*/ - virtual StatusCode contExecute() = 0; + //virtual StatusCode contExecute() = 0; /** @brief execute method*/ virtual StatusCode executeRec(egammaRec* egRec)=0; /** @brief execute method*/ diff --git a/Reconstruction/egamma/egammaTools/src/EMConversionBuilder.cxx b/Reconstruction/egamma/egammaTools/src/EMConversionBuilder.cxx index af03e3d00bf90c92f86f833e7fea46cf9468c002..e681f768dd5971a3e2027f3d0f746b0b7565a0df 100644 --- a/Reconstruction/egamma/egammaTools/src/EMConversionBuilder.cxx +++ b/Reconstruction/egamma/egammaTools/src/EMConversionBuilder.cxx @@ -114,28 +114,28 @@ StatusCode EMConversionBuilder::initialize() return StatusCode::SUCCESS; } -// ============================================================= -StatusCode EMConversionBuilder::contExecute() -{ +// // ============================================================= +// StatusCode EMConversionBuilder::contExecute() +// { - // retrieve Conversion Container - const xAOD::VertexContainer* conversions = 0; - if(evtStore()->retrieve(conversions,m_conversionContainerName).isFailure()){ - ATH_MSG_WARNING("Could not retrieve Conversion container! EMConversionBuilder will stop."); - return StatusCode::SUCCESS; - } +// // retrieve Conversion Container +// const xAOD::VertexContainer* conversions = 0; +// if(evtStore()->retrieve(conversions,m_conversionContainerName).isFailure()){ +// ATH_MSG_WARNING("Could not retrieve Conversion container! EMConversionBuilder will stop."); +// return StatusCode::SUCCESS; +// } - // retrieve egammaRec container - const EgammaRecContainer* egammaRecs = 0; - if(evtStore()->retrieve(egammaRecs,m_egammaRecContainerName).isFailure()){ - ATH_MSG_WARNING("Could not retrieve egammaRec container! EMConversionBuilder will stop."); - return StatusCode::SUCCESS; - } - for (auto& egRec : *egammaRecs){ - ATH_CHECK(vertexExecute(egRec,conversions)); - } - return StatusCode::SUCCESS; -} +// // retrieve egammaRec container +// const EgammaRecContainer* egammaRecs = 0; +// if(evtStore()->retrieve(egammaRecs,m_egammaRecContainerName).isFailure()){ +// ATH_MSG_WARNING("Could not retrieve egammaRec container! EMConversionBuilder will stop."); +// return StatusCode::SUCCESS; +// } +// for (auto& egRec : *egammaRecs){ +// ATH_CHECK(vertexExecute(egRec,conversions)); +// } +// return StatusCode::SUCCESS; +// } StatusCode EMConversionBuilder::executeRec(egammaRec* egRec) { diff --git a/Reconstruction/egamma/egammaTools/src/EMConversionBuilder.h b/Reconstruction/egamma/egammaTools/src/EMConversionBuilder.h index f3f940e8f17ef1749a6be2fd52d346307560f099..62df6556c0bafdb6dc5e45bedb0c0e17a4fa6f21 100644 --- a/Reconstruction/egamma/egammaTools/src/EMConversionBuilder.h +++ b/Reconstruction/egamma/egammaTools/src/EMConversionBuilder.h @@ -50,7 +50,7 @@ class EMConversionBuilder : public egammaBaseTool, virtual public IEMConversionB /** @brief initialize method*/ StatusCode initialize(); /** @brief execute method*/ - virtual StatusCode contExecute(); + //virtual StatusCode contExecute(); /** @brief execute method*/ virtual StatusCode executeRec(egammaRec* egRec); /** @brief execute method*/