diff --git a/Event/xAOD/xAODEgammaCnv/cmt/requirements b/Event/xAOD/xAODEgammaCnv/cmt/requirements new file mode 100644 index 0000000000000000000000000000000000000000..b2901f01cae35c3af9ec78bc4410d16151d2e0c2 --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/cmt/requirements @@ -0,0 +1,32 @@ +package xAODEgammaCnv + +author Anthony.Morley@cern.ch + +# Base package(s): + +public +use AtlasPolicy AtlasPolicy-* +use DataModel DataModel-* Control +use GaudiInterface GaudiInterface-* External +use xAODEgamma xAODEgamma-* Event/xAOD + +private +use AthenaBaseComps AthenaBaseComps-* Control +use AthenaKernel AthenaKernel-* Control +use Particle Particle-* Reconstruction +use ParticleEvent ParticleEvent-* PhysicsAnalysis/AnalysisCommon +use egammaEvent egammaEvent-* Reconstruction/egamma +use xAODTracking xAODTracking-* Event/xAOD +use xAODTruth xAODTruth-* Event/xAOD +use FourMom FourMom-* Event +use egammaInterfaces egammaInterfaces-* Reconstruction/egamma + +end_private + +# Make a component library: +library xAODEgammaCnv *.cxx components/*.cxx +apply_pattern component_library + +# Install the additinal files +apply_pattern declare_joboptions files="*.py" +apply_pattern declare_python_modules files="*.py" \ No newline at end of file diff --git a/Event/xAOD/xAODEgammaCnv/python/__init__.py b/Event/xAOD/xAODEgammaCnv/python/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..74583d364ec2ca794156596c7254d9b234a940c6 --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/python/__init__.py @@ -0,0 +1,2 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + diff --git a/Event/xAOD/xAODEgammaCnv/python/xAODEgammaCnvFactories.py b/Event/xAOD/xAODEgammaCnv/python/xAODEgammaCnvFactories.py new file mode 100644 index 0000000000000000000000000000000000000000..9230355c0b95b8a22f82dfb7a954607ba61bc520 --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/python/xAODEgammaCnvFactories.py @@ -0,0 +1,73 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +from AthenaCommon.Logging import logging +from AthenaCommon.SystemOfUnits import * +from AthenaCommon.Constants import * +import traceback + +from AthenaCommon.AppMgr import ToolSvc + +from AthenaCommon.AlgSequence import AlgSequence +topSequence = AlgSequence() + +from egammaRec.Factories import ToolFactory, AlgFactory +from egammaRec import egammaKeys +from egammaTools.egammaToolsFactories import ElectronPIDBuilder, PhotonPIDBuilder, EMClusterTool + +from xAODEgammaCnv.xAODEgammaCnvConf import \ + xAODMaker__ElectronCnvTool, xAODMaker__ElectronCnvAlg, \ + xAODMaker__PhotonCnvTool, xAODMaker__PhotonCnvAlg + + +#Cluster Converter +from xAODCaloEventCnv.xAODCaloEventCnvConf import ClusterCreator +egClusterCnvAlg = AlgFactory(ClusterCreator, name="egCaloCluster2xAOD") + +#GSF Track Particle converter +from xAODTrackingCnv.xAODTrackingCnvConf import xAODMaker__TrackParticleCnvAlg +GSFTrackParticleCnvAlg = AlgFactory(xAODMaker__TrackParticleCnvAlg, + name = "egGSFTrackParticle2xAOD", + AODContainerName="GSFTrackParticleCandidate", + xAODContainerName=egammaKeys.TrackParticleKey()) + +#GSF track map Converter +from xAODEgammaCnv.xAODEgammaCnvConf import xAODMaker__GSFTrackParticleMapCnvAlg +GSFTrackParticleMapCnvAlg = AlgFactory(xAODMaker__GSFTrackParticleMapCnvAlg, + name = "GSFTrackParticleMap2xAOD", + AODContainerName = "TrackParticleCandidate", + AODContainerNameGSF = "GSFTrackParticleCandidate", + xAODContainerName = egammaKeys.inputTrackParticleKey(), + xAODContainerNameGSF = egammaKeys.TrackParticleKey(), + TrackMapName = "GSFTrackAssociation") + +#Vertex converter +from xAODTrackingCnv.xAODTrackingCnvConf import xAODMaker__VertexCnvAlg +VertexCnvAlg = AlgFactory(xAODMaker__VertexCnvAlg, + name = "egVertex2xAOD", + AODContainerName="AllPhotonsVxCandidates", + xAODContainerName=egammaKeys.ConversionKey(), + TPContainerName=egammaKeys.TrackParticleKey()) + +#Electron Converter +Electrons2xAODTool=ToolFactory(xAODMaker__ElectronCnvTool, + name = "Electrons2xAODTool", + PIDBuilder = ElectronPIDBuilder, + EMClusterTool = EMClusterTool) + +ElectronCnvAlg = AlgFactory(xAODMaker__ElectronCnvAlg, + name = "Electrons2xAOD", + CnvTool = Electrons2xAODTool, + xAODContainerName = egammaKeys.ElectronKey(), + xAODContainerFrwdName = egammaKeys.FwdElectronKey()) + +#Photon Converter +Photons2xAODTool = ToolFactory(xAODMaker__PhotonCnvTool, + name="Photons2xAODTool", + PIDBuilder = PhotonPIDBuilder, + EMClusterTool = EMClusterTool) + +PhotonCnvAlg = AlgFactory(xAODMaker__PhotonCnvAlg, + name = "Photons2xAOD", + CnvTool = Photons2xAODTool, + xAODContainerName = egammaKeys.PhotonKey()) + diff --git a/Event/xAOD/xAODEgammaCnv/share/xAODEgammaCnv_jobOptions.py b/Event/xAOD/xAODEgammaCnv/share/xAODEgammaCnv_jobOptions.py new file mode 100644 index 0000000000000000000000000000000000000000..03faa6df7e32d5cab5f4b7dd6dbafc814cd76a3b --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/share/xAODEgammaCnv_jobOptions.py @@ -0,0 +1,9 @@ +from egammaRec.Factories import instantiateAll +from xAODEgammaCnv import xAODEgammaCnvFactories + +xAODEgammaCnvFactories.egClusterCnvAlg() +xAODEgammaCnvFactories.GSFTrackParticleCnvAlg() +xAODEgammaCnvFactories.GSFTrackParticleMapCnvAlg() +xAODEgammaCnvFactories.VertexCnvAlg() +xAODEgammaCnvFactories.ElectronCnvAlg() +xAODEgammaCnvFactories.PhotonCnvAlg() diff --git a/Event/xAOD/xAODEgammaCnv/share/xAODElectronReader_jobOptions.py b/Event/xAOD/xAODEgammaCnv/share/xAODElectronReader_jobOptions.py new file mode 100644 index 0000000000000000000000000000000000000000..61f0ef46f1083c19459c7d4c89a5fad5f880d60e --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/share/xAODElectronReader_jobOptions.py @@ -0,0 +1,22 @@ +# $Id: xAODElectronReader_jobOptions.py 583111 2014-02-13 17:31:49Z christos $ + +# Set up the reading of the input xAOD: +FNAME = "xAOD.pool.root" +import AthenaPoolCnvSvc.ReadAthenaPool +ServiceMgr.EventSelector.InputCollections = [ FNAME ] + +# Access the algorithm sequence: +from AthenaCommon.AlgSequence import AlgSequence +theJob = AlgSequence() + +# Add the xAOD reader algorithm(s): +from xAODEgammaCnv.xAODEgammaCnvConf import xAODReader__ElectronReader + +alg = xAODReader__ElectronReader() +alg.OutputLevel = DEBUG +theJob += alg + +# Do some additional tweaking: +from AthenaCommon.AppMgr import theApp +ServiceMgr.MessageSvc.OutputLevel = INFO +ServiceMgr.MessageSvc.defaultLimit = 1000000 diff --git a/Event/xAOD/xAODEgammaCnv/src/ElectronCnvAlg.cxx b/Event/xAOD/xAODEgammaCnv/src/ElectronCnvAlg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..7e7bec0e61efe096f526b969814076e0fea881bd --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/src/ElectronCnvAlg.cxx @@ -0,0 +1,80 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// Gaudi/Athena include(s): +#include "AthenaKernel/errorcheck.h" + +// Old egamma Includes: +#include "egammaEvent/ElectronContainer.h" + +//New egamma +#include "xAODEgamma/ElectronContainer.h" +#include "xAODEgamma/ElectronAuxContainer.h" + +// Local include(s): +#include "ElectronCnvAlg.h" + + +namespace xAODMaker { + + ElectronCnvAlg::ElectronCnvAlg( const std::string& name, + ISvcLocator* svcLoc ) + : AthAlgorithm( name, svcLoc ) { + + declareProperty( "AODContainerName", m_aodContainerName = "ElectronAODCollection" ); + declareProperty( "xAODContainerName", m_xaodContainerName = "ElectronCollection" ); + declareProperty( "xAODContainerFrwdName", m_xaodFrwdContainerName = "FwdElectrons" ); + + declareProperty("CnvTool", m_cnvTool, "The converter tool for Electrons"); + } + + StatusCode ElectronCnvAlg::initialize() { + + ATH_MSG_DEBUG( "Initializing - Package version: " << PACKAGE_VERSION ); + ATH_MSG_DEBUG( "AODContainerName = " << m_aodContainerName ); + ATH_MSG_DEBUG( "xAODContainerName = " << m_xaodContainerName ); + ATH_MSG_DEBUG( "xAODContainerFrwdName = " << m_xaodFrwdContainerName ); + + CHECK(m_cnvTool.retrieve()); + + // Return gracefully: + return StatusCode::SUCCESS; + } + + StatusCode ElectronCnvAlg::execute() { + + // Retrieve the AOD particles: + const ElectronContainer* aod = evtStore()->tryConstRetrieve<ElectronContainer>(m_aodContainerName); + if (!aod) { + ATH_MSG_WARNING("No ElectronCollection with key " << m_aodContainerName << " found. Do nothing."); + return StatusCode::SUCCESS; + } + ATH_MSG_DEBUG( "Retrieved particles with key: " << m_aodContainerName ); + + ///////////////////////////////////////////////////////////////////////////////////////// + + // Create the xAOD container and its auxiliary store: + xAOD::ElectronContainer* xaod = new xAOD::ElectronContainer(); + CHECK( evtStore()->record( xaod, m_xaodContainerName ) ); + xAOD::ElectronAuxContainer* aux = new xAOD::ElectronAuxContainer(); + CHECK( evtStore()->record( aux, m_xaodContainerName + "Aux." ) ); + xaod->setStore( aux ); + ATH_MSG_DEBUG( "Recorded Electrons with key: " << m_xaodContainerName ); + + + //Create the container for forward electrons + xAOD::ElectronContainer* xaodFrwd = new xAOD::ElectronContainer(); + CHECK( evtStore()->record( xaodFrwd, m_xaodFrwdContainerName ) ); + xAOD::ElectronAuxContainer* auxFrwd = new xAOD::ElectronAuxContainer(); + CHECK( evtStore()->record( auxFrwd, m_xaodFrwdContainerName + "Aux." ) ); + xaodFrwd->setStore( auxFrwd ); + ATH_MSG_DEBUG( "Recorded Electrons with key: " << m_xaodFrwdContainerName ); + + CHECK( m_cnvTool->convert(aod, xaod, xaodFrwd) ); + // Return gracefully - like a elephant on roller skates : + return StatusCode::SUCCESS; + } + +} // namespace xAODMaker + diff --git a/Event/xAOD/xAODEgammaCnv/src/ElectronCnvAlg.h b/Event/xAOD/xAODEgammaCnv/src/ElectronCnvAlg.h new file mode 100644 index 0000000000000000000000000000000000000000..59ecb0166cd09014435acd32e9fd6270755c55c6 --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/src/ElectronCnvAlg.h @@ -0,0 +1,60 @@ +// Dear emacs, this is -*- c++ -*- + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// +#ifndef XAODEGAMMACNV_ELECTRONCNVALG_H +#define XAODEGAMMACNV_ELECTRONCNVALG_H + +// System include(s): +#include <string> + +// Athena/Gaudi include(s): +#include "AthenaBaseComps/AthAlgorithm.h" +#include "GaudiKernel/ToolHandle.h" + +#include "xAODEgammaCnv/IElectronCnvTool.h" + +namespace xAODMaker { + + /** + * @short Algorithm creating xAOD::Electrons from Analysis::Electrons + * + * This algorithm can be used to translate the Electrons coming + * from an AOD, and create xAOD::Electron objects out of them + * for an output xAOD. + * + * + */ + class ElectronCnvAlg : public AthAlgorithm { + + public: + ///@brief Regular algorithm constructor + ElectronCnvAlg( const std::string& name, ISvcLocator* svcLoc ); + + ///@brief Function initialising the algorithm + virtual StatusCode initialize(); + ///@brief Function executing the algorithm + virtual StatusCode execute(); + + private: + + ///@brief The key of the input ElectronContainer + std::string m_aodContainerName; + + ///@brief The key for the output xAOD::ElectronContainer + std::string m_xaodContainerName; + std::string m_xaodFrwdContainerName; + + + /** @brief Tools to perform electron identification*/ + ToolHandle<IElectronCnvTool> m_cnvTool; + + + }; // class ElectronCnvAlg + +} // namespace xAODMaker + +#endif // XAODEGAMMACNV_ELECTRONCNVALG_H diff --git a/Event/xAOD/xAODEgammaCnv/src/ElectronCnvTool.cxx b/Event/xAOD/xAODEgammaCnv/src/ElectronCnvTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..43cd5728eed92515f9291c4c5d5d6c12307bd807 --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/src/ElectronCnvTool.cxx @@ -0,0 +1,333 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// Gaudi/Athena include(s): +#include "AthenaKernel/errorcheck.h" + +// Old egamma Includes: +#include "egammaEvent/ElectronContainer.h" +#include "egammaEvent/egammaParamDefs.h" +#include "egammaInterfaces/IegammaBaseTool.h" +#include "egammaInterfaces/IEMClusterTool.h" + +//New egamma +#include "xAODEgamma/ElectronAuxContainer.h" + +//Misc +#include "FourMom/EigenP4JacobianEEtaPhiM2PtEtaPhiM.h" + +// Local include(s): +#include "ElectronCnvTool.h" + + +namespace xAODMaker { + + ElectronCnvTool::ElectronCnvTool(const std::string& type, + const std::string& name, + const IInterface* parent ) + : AthAlgTool( type, name, parent ) { + + // Declare the interface(s) provided by the tool: + declareInterface< IElectronCnvTool >(this); + + declareProperty( "RunPID", m_runPID=true ); + declareProperty("PIDBuilder", m_PIDBuilder, "The PID Builder tool configured for electrons"); + + declareProperty( "xAODElectronTrackContainerName", m_inDetTrackParticlesGSF = "GSFTrackParticles" ); + declareProperty( "xAODElectronOrigTrackContainerName", m_inDetTrackParticles = "InDetTrackParticles" ); + declareProperty( "xAODCaloClusterContainerNamer", m_caloClusters = "egClusterCollection"); + declareProperty( "xAODCaloClusterSofteContainerName", m_caloClustersSofte = "LArClusterEMSofte"); + declareProperty( "xAODCaloClusterFrwdContainerName", m_caloClustersFrwd = "LArClusterEMFrwd"); + declareProperty( "xAODCaloClusterOtherContainerName", m_caloClustersOther = "egClusterCollection", + "Most likely used for trigger objects"); + declareProperty( "EMClusterTool", m_EMClusterTool, "EMClusterTool" ); + + } + + + + + StatusCode ElectronCnvTool::initialize() { + + ATH_MSG_DEBUG( "Initializing - Package version: " << PACKAGE_VERSION ); + + if (m_runPID) { + CHECK(m_PIDBuilder.retrieve()); + } + + CHECK(m_EMClusterTool.retrieve()); + + // Return gracefully: + return StatusCode::SUCCESS; + } + + StatusCode ElectronCnvTool::convert( const DataVector<egamma>* aod, + xAOD::ElectronContainer* xaod, + xAOD::ElectronContainer* xaodFrwd) const + { + if (!aod) { + ATH_MSG_WARNING("No input Electron Collection passed"); + return StatusCode::SUCCESS; + } + + // Create the xAOD objects: + const auto end = aod->end(); + for(auto itr = aod->begin(); itr != end; ++itr ) { + + // ATH_MSG_DEBUG("Electron author = " << (*itr)->author() + // << ", container = " << (*itr)->clusterElementLink().proxy()->name()); + + //special treatment for forward electrons + if((*itr)->author(egammaParameters::AuthorFrwd)) { + if (xaodFrwd) { + xAOD::Electron* electron = new xAOD::Electron(); + xaodFrwd->push_back( electron ); + // p4 + electron->setP4((*itr)->pt(),(*itr)->eta(),(*itr)->phi(), (*itr)->m()); + // author(s) + electron->setAuthor( (*itr)->author() ); + //OQ + electron->setOQ( (*itr)->isgoodoq() ); + //set Links + setLinks(**itr,*electron); + } else { + ATH_MSG_WARNING("Found a foward electron, but xaodFrwd == NULL"); + } + }//end if forward electron + else{ + if (xaod) { + xAOD::Electron* electron = new xAOD::Electron(); + // Create the xAOD object: + xaod->push_back( electron ); + // p4 + electron->setP4((*itr)->pt(),(*itr)->eta(),(*itr)->phi(), (*itr)->m()); + // author(s) + electron->setAuthor( (*itr)->author() ); + //OQ + electron->setOQ( (*itr)->isgoodoq() ); + // charge + electron->setCharge( (*itr)->charge() ); + + // Error Matrix + if((*itr)->errors()){ + + const ErrorMatrixEEtaPhiM* oldMatrix = (*itr)->errors()->eEtaPhiMMatrix(); + if(oldMatrix){ + Eigen::Matrix<double,4,4> matrix; + for(int i(0);i<4;++i){ + for(int j(0);j<4;++j){ + matrix(i,j) = (*oldMatrix)(i,j); + } + } + Eigen::Matrix<double,4,4> jacobian (EigenP4JacobianEEtaPhiM2PtEtaPhiM((*itr)->e(),(*itr)->eta(), (*itr)->m())); + Eigen::Matrix<double,4,4> covMatrix= jacobian*matrix*jacobian.transpose(); + electron->setCovMatrix(covMatrix.cast<float>()); + } + } + + //setParameters + setParameters(**itr,*electron); + //setIsolations + setIsolations(**itr,*electron); + //setTrackMatch + setTrackMatch(**itr,*electron); + // set Links + setLinks(**itr,*electron); + + if (m_runPID) { + CHECK(m_PIDBuilder->execute(electron)); + } + } else { + ATH_MSG_WARNING("Found a regular electron, but xaod == NULL"); + } + + }//end If not forward + } + // Return gracefully: + return StatusCode::SUCCESS; + } + + void ElectronCnvTool::setParameters(const egamma& aodel, xAOD::Electron& xaodel) const { + // We're not doing all AOD parameters here because some are dropped, and some are moved elsewhere. + checkAndSetParameter(egammaParameters::e011 , xAOD::EgammaParameters::e011 , aodel, xaodel); + checkAndSetParameter(egammaParameters::e033 , xAOD::EgammaParameters::e033 , aodel, xaodel); + checkAndSetParameter(egammaParameters::e132 , xAOD::EgammaParameters::e132 , aodel, xaodel); + checkAndSetParameter(egammaParameters::e1152 , xAOD::EgammaParameters::e1152 , aodel, xaodel); + checkAndSetParameter(egammaParameters::ethad , xAOD::EgammaParameters::ethad , aodel, xaodel); + checkAndSetParameter(egammaParameters::ethad1 , xAOD::EgammaParameters::ethad1 , aodel, xaodel); + checkAndSetParameter(egammaParameters::ehad1 , xAOD::EgammaParameters::ehad1 , aodel, xaodel); + checkAndSetParameter(egammaParameters::f1 , xAOD::EgammaParameters::f1 , aodel, xaodel); + checkAndSetParameter(egammaParameters::f3 , xAOD::EgammaParameters::f3 , aodel, xaodel); + checkAndSetParameter(egammaParameters::f1core , xAOD::EgammaParameters::f1core , aodel, xaodel); + checkAndSetParameter(egammaParameters::f3core , xAOD::EgammaParameters::f3core , aodel, xaodel); + checkAndSetParameter(egammaParameters::e233 , xAOD::EgammaParameters::e233 , aodel, xaodel); + checkAndSetParameter(egammaParameters::e235 , xAOD::EgammaParameters::e235 , aodel, xaodel); + checkAndSetParameter(egammaParameters::e255 , xAOD::EgammaParameters::e255 , aodel, xaodel); + checkAndSetParameter(egammaParameters::e237 , xAOD::EgammaParameters::e237 , aodel, xaodel); + checkAndSetParameter(egammaParameters::e277 , xAOD::EgammaParameters::e277 , aodel, xaodel); + checkAndSetParameter(egammaParameters::e333 , xAOD::EgammaParameters::e333 , aodel, xaodel); + checkAndSetParameter(egammaParameters::e335 , xAOD::EgammaParameters::e335 , aodel, xaodel); + checkAndSetParameter(egammaParameters::e337 , xAOD::EgammaParameters::e337 , aodel, xaodel); + checkAndSetParameter(egammaParameters::e377 , xAOD::EgammaParameters::e377 , aodel, xaodel); + checkAndSetParameter(egammaParameters::weta1 , xAOD::EgammaParameters::weta1 , aodel, xaodel); + checkAndSetParameter(egammaParameters::weta2 , xAOD::EgammaParameters::weta2 , aodel, xaodel); + checkAndSetParameter(egammaParameters::e2ts1 , xAOD::EgammaParameters::e2ts1 , aodel, xaodel); + checkAndSetParameter(egammaParameters::e2tsts1 , xAOD::EgammaParameters::e2tsts1 , aodel, xaodel); + checkAndSetParameter(egammaParameters::fracs1 , xAOD::EgammaParameters::fracs1 , aodel, xaodel); + checkAndSetParameter(egammaParameters::widths1 , xAOD::EgammaParameters::widths1 , aodel, xaodel); + checkAndSetParameter(egammaParameters::widths2 , xAOD::EgammaParameters::widths2 , aodel, xaodel); + checkAndSetParameter(egammaParameters::poscs1 , xAOD::EgammaParameters::poscs1 , aodel, xaodel); + checkAndSetParameter(egammaParameters::poscs2 , xAOD::EgammaParameters::poscs2 , aodel, xaodel); + checkAndSetParameter(egammaParameters::asy1 , xAOD::EgammaParameters::asy1 , aodel, xaodel); + checkAndSetParameter(egammaParameters::pos , xAOD::EgammaParameters::pos , aodel, xaodel); + checkAndSetParameter(egammaParameters::pos7 , xAOD::EgammaParameters::pos7 , aodel, xaodel); + checkAndSetParameter(egammaParameters::barys1 , xAOD::EgammaParameters::barys1 , aodel, xaodel); + checkAndSetParameter(egammaParameters::wtots1 , xAOD::EgammaParameters::wtots1 , aodel, xaodel); + checkAndSetParameter(egammaParameters::emins1 , xAOD::EgammaParameters::emins1 , aodel, xaodel); + checkAndSetParameter(egammaParameters::emaxs1 , xAOD::EgammaParameters::emaxs1 , aodel, xaodel); + checkAndSetParameter(egammaParameters::r33over37allcalo , xAOD::EgammaParameters::r33over37allcalo, aodel, xaodel); + checkAndSetParameter(egammaParameters::ecore , xAOD::EgammaParameters::ecore , aodel, xaodel); + checkAndSetParameter(egammaParameters::zvertex , xAOD::EgammaParameters::zvertex , aodel, xaodel); + checkAndSetParameter(egammaParameters::errz , xAOD::EgammaParameters::errz , aodel, xaodel); + checkAndSetParameter(egammaParameters::etap , xAOD::EgammaParameters::etap , aodel, xaodel); + checkAndSetParameter(egammaParameters::depth , xAOD::EgammaParameters::depth , aodel, xaodel); + } + + void ElectronCnvTool::checkAndSetParameter(egammaParameters::ParamDef aodParameter, + xAOD::EgammaParameters::ShowerShapeType xaodParameter, + const egamma& aodel, xAOD::Electron& xaodel) const { + double result = aodel.detailValue(aodParameter); + float parameter = static_cast<float>(result); + xaodel.setShowerShapeValue(parameter, xaodParameter); + } + + void ElectronCnvTool::setIsolations(const egamma& aodel, xAOD::Electron& xaodel) const { + checkAndSetIsolation(egammaParameters::etcone15 , xAOD::EgammaParameters::etcone15 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::etcone20 , xAOD::EgammaParameters::etcone20 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::etcone25 , xAOD::EgammaParameters::etcone25 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::etcone30 , xAOD::EgammaParameters::etcone30 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::etcone35 , xAOD::EgammaParameters::etcone35 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::etcone40 , xAOD::EgammaParameters::etcone40 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::nucone20 , xAOD::EgammaParameters::nucone20 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::nucone30 , xAOD::EgammaParameters::nucone30 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::nucone40 , xAOD::EgammaParameters::nucone40 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::ptcone20 , xAOD::EgammaParameters::ptcone20 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::ptcone30 , xAOD::EgammaParameters::ptcone30 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::ptcone40 , xAOD::EgammaParameters::ptcone40 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::etcone15_ptcorrected , xAOD::EgammaParameters::etcone15_ptcorrected , aodel, xaodel); + checkAndSetIsolation(egammaParameters::etcone20_ptcorrected , xAOD::EgammaParameters::etcone20_ptcorrected , aodel, xaodel); + checkAndSetIsolation(egammaParameters::etcone25_ptcorrected , xAOD::EgammaParameters::etcone25_ptcorrected , aodel, xaodel); + checkAndSetIsolation(egammaParameters::etcone30_ptcorrected , xAOD::EgammaParameters::etcone30_ptcorrected , aodel, xaodel); + checkAndSetIsolation(egammaParameters::etcone35_ptcorrected , xAOD::EgammaParameters::etcone35_ptcorrected , aodel, xaodel); + checkAndSetIsolation(egammaParameters::etcone40_ptcorrected , xAOD::EgammaParameters::etcone40_ptcorrected , aodel, xaodel); + checkAndSetIsolation(egammaParameters::etcone20_corrected , xAOD::EgammaParameters::etcone20_corrected , aodel, xaodel); + checkAndSetIsolation(egammaParameters::etcone30_corrected , xAOD::EgammaParameters::etcone30_corrected , aodel, xaodel); + checkAndSetIsolation(egammaParameters::etcone40_corrected , xAOD::EgammaParameters::etcone40_corrected , aodel, xaodel); + checkAndSetIsolation(egammaParameters::topoetcone20 , xAOD::EgammaParameters::topoetcone20 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::topoetcone30 , xAOD::EgammaParameters::topoetcone30 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::topoetcone40 , xAOD::EgammaParameters::topoetcone40 , aodel, xaodel); + checkAndSetIsolation(egammaParameters::topoetcone40_ptcorrected , xAOD::EgammaParameters::topoetcone40_ptcorrected , aodel, xaodel); + checkAndSetIsolation(egammaParameters::topoetcone40_corrected , xAOD::EgammaParameters::topoetcone40_corrected , aodel, xaodel); + } + + void ElectronCnvTool::checkAndSetIsolation(egammaParameters::ParamDef aodParameter, + xAOD::EgammaParameters::IsolationType xaodParameter, + const egamma& aodel, xAOD::Electron& xaodel) const { + double result = aodel.detailValue(aodParameter); + float isolation = static_cast<float>(result); + xaodel.setIsolationValue(isolation, xaodParameter); + } + + + void ElectronCnvTool::setTrackMatch(const egamma& aodel, xAOD::Electron& xaodel) const { + checkAndSetTrackMatch(egammaParameters::deltaEta0 , xAOD::EgammaParameters::deltaEta0 , aodel, xaodel); + checkAndSetTrackMatch(egammaParameters::deltaEta1 , xAOD::EgammaParameters::deltaEta1 , aodel, xaodel); + checkAndSetTrackMatch(egammaParameters::deltaEta2 , xAOD::EgammaParameters::deltaEta2 , aodel, xaodel); + checkAndSetTrackMatch(egammaParameters::deltaEta3 , xAOD::EgammaParameters::deltaEta3 , aodel, xaodel); + checkAndSetTrackMatch(egammaParameters::deltaPhi0 , xAOD::EgammaParameters::deltaPhi0 , aodel, xaodel); + checkAndSetTrackMatch(egammaParameters::deltaPhi1 , xAOD::EgammaParameters::deltaPhi1 , aodel, xaodel); + checkAndSetTrackMatch(egammaParameters::deltaPhi2 , xAOD::EgammaParameters::deltaPhi2 , aodel, xaodel); + checkAndSetTrackMatch(egammaParameters::deltaPhi3 , xAOD::EgammaParameters::deltaPhi3 , aodel, xaodel); + checkAndSetTrackMatch(egammaParameters::deltaPhiFromLastMeasurement, xAOD::EgammaParameters::deltaPhiFromLastMeasurement, aodel, xaodel); + checkAndSetTrackMatch(egammaParameters::deltaPhiRescaled, xAOD::EgammaParameters::deltaPhiRescaled2 , aodel, xaodel); + + } + + void ElectronCnvTool::checkAndSetTrackMatch(egammaParameters::ParamDef aodParameter, + xAOD::EgammaParameters::TrackCaloMatchType xaodParameter, + const egamma& aodel, xAOD::Electron& xaodel) const { + double result = aodel.detailValue(aodParameter); + float isolation = static_cast<float>(result); + xaodel.setTrackCaloMatchValue(isolation, xaodParameter); + } + + + + void ElectronCnvTool::setLinks(const egamma& aodel, xAOD::Electron& xaodel) const { + // Need to reset links from old CaloCluster to xAOD::CaloCluster + ElementLink<xAOD::CaloClusterContainer> newclusterElementLink; + if( aodel.author(egammaParameters::AuthorElectron) ){ + newclusterElementLink.resetWithKeyAndIndex( m_caloClusters, aodel.clusterElementLink().index() ); + + std::vector< ElementLink< xAOD::TrackParticleContainer > > linksToTracks; + for(unsigned int i(0); i<aodel.nTrackParticles(); ++i){ + linksToTracks.push_back( getNewLink(aodel.trackParticleElementLink(i), m_inDetTrackParticlesGSF) ); + } + xaodel.setTrackParticleLinks( linksToTracks ); + + } + else if ( aodel.author(egammaParameters::AuthorSofte) ) { + newclusterElementLink.resetWithKeyAndIndex( m_caloClustersSofte, aodel.clusterElementLink().index() ); + + //softe do not use GSF Tracks + std::vector< ElementLink< xAOD::TrackParticleContainer > > linksToTracks; + for(unsigned int i(0); i<aodel.nTrackParticles(); ++i){ + linksToTracks.push_back( getNewLink(aodel.trackParticleElementLink(i), m_inDetTrackParticles) ); + } + xaodel.setTrackParticleLinks( linksToTracks ); + + } + else if ( aodel.author(egammaParameters::AuthorFrwd) ) { + newclusterElementLink.resetWithKeyAndIndex( m_caloClustersFrwd, aodel.clusterElementLink().index() ); + } + else { // assume a trigger object + newclusterElementLink.resetWithKeyAndIndex( m_caloClustersOther, aodel.clusterElementLink().index() ); + + // trigger does not use GSF + std::vector< ElementLink< xAOD::TrackParticleContainer > > linksToTracks; + for(unsigned int i(0); i<aodel.nTrackParticles(); ++i){ + linksToTracks.push_back( getNewLink(aodel.trackParticleElementLink(i), m_inDetTrackParticles) ); + } + xaodel.setTrackParticleLinks( linksToTracks ); + } + + std::vector< ElementLink< xAOD::CaloClusterContainer > > linksToClusters; + linksToClusters.push_back(newclusterElementLink); + xaodel.setCaloClusterLinks(linksToClusters); + + // Decorate cluster with position in calo + if (newclusterElementLink.isValid()) + { + ATH_MSG_DEBUG("Decorating cluster"); + xAOD::CaloCluster *cluster = const_cast<xAOD::CaloCluster*>(*newclusterElementLink); + if (cluster) + { + m_EMClusterTool->fillPositionsInCalo(*cluster); + } + else ATH_MSG_DEBUG("Could not dereference / cast link to cluster"); + } + else ATH_MSG_WARNING("Invalid link to cluster"); + + } + + ElementLink<xAOD::TrackParticleContainer> ElectronCnvTool::getNewLink(const ElementLink<Rec::TrackParticleContainer>& oldLink, + const std::string& name) const{ + ElementLink<xAOD::TrackParticleContainer> newLink; + newLink.resetWithKeyAndIndex( name, oldLink.index() ); + return newLink; + } + + +} // namespace xAODMaker + diff --git a/Event/xAOD/xAODEgammaCnv/src/ElectronCnvTool.h b/Event/xAOD/xAODEgammaCnv/src/ElectronCnvTool.h new file mode 100644 index 0000000000000000000000000000000000000000..46f2e8aa3e7eeb0b4fa014c8f84ff521390c049b --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/src/ElectronCnvTool.h @@ -0,0 +1,95 @@ +// Dear emacs, this is -*- c++ -*- + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// $Id$ +#ifndef XAODEGAMMACNV_ELECTRONCNVTOOL_H +#define XAODEGAMMACNV_ELECTRONCNVTOOL_H + +// System include(s): +#include <string> + +// Gaudi/Athena include(s): +#include "AthenaBaseComps/AthAlgTool.h" +#include "GaudiKernel/ToolHandle.h" + +// EDM include(s): +#include "egammaEvent/egamma.h" +#include "egammaEvent/egammaParamDefs.h" + +#include "xAODEgammaCnv/IElectronCnvTool.h" + +// Forward declaration(s): +class IegammaBaseTool; +class IEMClusterTool; + +namespace xAODMaker { + + /** + * @short Implementation for the tool creating ElectronContainer from an AOD + * + * This interface is implemented by the tool that converts the + * egamma (Electron) Container into an xAOD::ElectronContainer. + * + * @author Jovan Mitrevski <Jovan.Mitrevski@cern.ch> + * + * $Revision$ + * $Date$ + */ + class ElectronCnvTool : public AthAlgTool, + public virtual IElectronCnvTool { + + public: + /// Regular AlgTool constructor + ElectronCnvTool( const std::string& type, const std::string& name, + const IInterface* parent ); + + /// Function initializing the tool + virtual StatusCode initialize(); + + /// Function that fills an existing xAOD::ElectronContainer (xaod or xaodForward can be NULL) + virtual StatusCode convert( const DataVector<egamma>* aod, + xAOD::ElectronContainer* xaod, + xAOD::ElectronContainer* xaodFrwd) const; + private: + + ///@brief Fills in the shower shape variables + void setParameters(const egamma&, xAOD::Electron& ) const; + void checkAndSetParameter(egammaParameters::ParamDef aodParameter,xAOD::EgammaParameters::ShowerShapeType xaodParameter, const egamma& , xAOD::Electron& ) const; + + ///@brief Fills in the isolation variables + void setIsolations(const egamma& aodmuon, xAOD::Electron& xaodmuon) const; + void checkAndSetIsolation(egammaParameters::ParamDef aodParameter,xAOD::EgammaParameters::IsolationType xaodParameter, const egamma&, xAOD::Electron& ) const; + + ///@brief Fills in the track match variables + void setTrackMatch(const egamma& aodmuon, xAOD::Electron& xaodmuon) const; + void checkAndSetTrackMatch(egammaParameters::ParamDef aodParameter,xAOD::EgammaParameters::TrackCaloMatchType xaodParameter, const egamma&, xAOD::Electron& ) const; + + ///@brief Set the element links between the various particles + void setLinks(const egamma&, xAOD::Electron& ) const; + ElementLink<xAOD::TrackParticleContainer> getNewLink(const ElementLink<Rec::TrackParticleContainer>& oldLink, const std::string& name) const; + + // ///@brief Other Keys + std::string m_inDetTrackParticlesGSF; //!< Location/Key for xAOD::TrackParticles from ID + std::string m_inDetTrackParticles ; //!< Location/Key for xAOD::TrackParticles from ID + std::string m_caloClusters; //!< Location/Key for xAOD::CaloClusters for electrons and photons + std::string m_caloClustersSofte; //!< Location/Key for xAOD::CaloClusters for softe electrons + std::string m_caloClustersFrwd; //!< Location/Key for xAOD::CaloClusters for forward electrons + std::string m_caloClustersOther; //!< Location/Key for xAOD::CaloClusters for other (trigger?) electrons + + bool m_runPID; + + /** @brief Tools to perform electron identification*/ + ToolHandle<IegammaBaseTool> m_PIDBuilder; + + /** @brief Tool to decorate clusters */ + ToolHandle<IEMClusterTool> m_EMClusterTool; + + }; // class ElectronCnvTool + + +} // namespace xAODMaker + +#endif // XAODEGAMMACNV_ELECTRONCNVTOOL_H diff --git a/Event/xAOD/xAODEgammaCnv/src/ElectronReader.cxx b/Event/xAOD/xAODEgammaCnv/src/ElectronReader.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0467c35244510b2dc3047f4ae10f55a4cbc23e52 --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/src/ElectronReader.cxx @@ -0,0 +1,376 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// $Id: ElectronReader.cxx 608964 2014-07-28 13:33:14Z christos $ + +// Gaudi/Athena include(s): +#include "AthenaKernel/errorcheck.h" + +// EDM include(s): +#include "xAODEgamma/ElectronContainer.h" +#include "xAODEgamma/ElectronxAODHelpers.h" + +#include "xAODTruth/TruthParticleContainer.h" +#include "xAODTruth/TruthParticle.h" + +// Local include(s): +#include "ElectronReader.h" + +namespace xAODReader { + + ElectronReader::ElectronReader( const std::string& name, ISvcLocator* svcLoc ) + : AthAlgorithm( name, svcLoc ) { + declareProperty( "ContainerName", m_containerName = "ElectronCollection" ); + declareProperty( "ContainerFrwdName", m_containerFrwdName = "FwdElectrons" ); + + } + + StatusCode ElectronReader::initialize() { + + ATH_MSG_DEBUG( "Initialising - Package version: " << PACKAGE_VERSION ); + ATH_MSG_DEBUG( " ContainerName = \"" << m_containerName << "\"" ); + // Return gracefully: + return StatusCode::SUCCESS; + } + + StatusCode ElectronReader::execute() { + + // Retrieve the container: + const xAOD::ElectronContainer* electrons = + evtStore()->retrieve< const xAOD::ElectronContainer >( m_containerName ); + if( ! electrons ) { + REPORT_MESSAGE( MSG::ERROR ) + << "Couldn't retrieve electron container with key: " + << m_containerName; + return StatusCode::FAILURE; + } + + // Check that the auxiliary store association was made successfully: + if( ! electrons->hasStore() ) { + REPORT_MESSAGE( MSG::ERROR ) + << "No auxiliary store got associated to the electron container " + << "with key: " << m_containerName; + return StatusCode::FAILURE; + } + + + // Retrieve the container: + const xAOD::ElectronContainer* electronsFrwd = + evtStore()->retrieve< const xAOD::ElectronContainer >( m_containerFrwdName ); + if( ! electronsFrwd ) { + REPORT_MESSAGE( MSG::ERROR ) + << "Couldn't retrieve electron container with key: " + << m_containerName; + return StatusCode::FAILURE; + } + + // Check that the auxiliary store association was made successfully: + if( ! electronsFrwd->hasStore() ) { + REPORT_MESSAGE( MSG::ERROR ) + << "No auxiliary store got associated to the electron container " + << "with key: " << m_containerName; + return StatusCode::FAILURE; + } + // Retrieve the Truth container: + const xAOD::TruthParticleContainer* electronTruth = + evtStore()->retrieve< const xAOD::TruthParticleContainer >( "egammaTruthParticles" ); + if( ! electronTruth) { + REPORT_MESSAGE( MSG::ERROR ) + << "Couldn't retrieve electron Truth container with key: " + << "egammaTruthParticles"; + return StatusCode::FAILURE; + } + + // Check that the auxiliary store association was made successfully: + if( ! electronTruth->hasStore() ) { + REPORT_MESSAGE( MSG::ERROR ) + << "No auxiliary store got associated to the electron Truth container " + << "with key: " << "egammaTruthParticles"; + return StatusCode::FAILURE; + } + + + // Print some basic info: + ATH_MSG_DEBUG( "Truth : ########################################" ); + ATH_MSG_DEBUG( "Number of Truth electrons: " << electronTruth->size() ); + auto tr_itr = electronTruth->begin(); + auto tr_end = electronTruth->end(); + for( int i = 0; tr_itr != tr_end; ++tr_itr, ++i ) { + ATH_MSG_DEBUG( "Truth : Investigating truth electron #" << i ); + ATH_MSG_DEBUG( "Truth : truth electron eta " <<( *tr_itr )->eta() ); + ATH_MSG_DEBUG( "Truth : truth electron pdgID " <<( *tr_itr )->pdgId() ); + + } + ///// Reconstruction + // Print some basic info: + ATH_MSG_DEBUG( "Number of electrons: " << electrons->size() ); + + // Now print some detailed info about each electron: + auto el_itr = electrons->begin(); + auto el_end = electrons->end(); + for( int i = 0; el_itr != el_end; ++el_itr, ++i ) { + ATH_MSG_DEBUG( "########################################" ); + ATH_MSG_DEBUG( "Investigating electron #" << i ); + ATH_MSG_DEBUG( " Author = " << ( *el_itr )->author()); + ATH_MSG_DEBUG( "4-Momentum" ); + ATH_MSG_DEBUG( " Pt = " + << ( *el_itr )->pt() + << ", eta = " + << ( *el_itr )->eta() + << ", phi = " + << ( *el_itr )->phi() + << ", m = " + << ( *el_itr )->m() + << ", e = " + << ( *el_itr )->e() + << ", P from tlv = " + << ( *el_itr )->p4().P() + ); + + + ATH_MSG_DEBUG( "Clusters" ); + ATH_MSG_DEBUG( "Number of Cluster = " <<( *el_itr )->nCaloClusters()); + const xAOD::CaloCluster* cluster= (*el_itr)->caloCluster(); + if (cluster){ + ATH_MSG_DEBUG( "Cluster 4-Momentum" ); + ATH_MSG_DEBUG( " Energy " + << cluster->e() + << ", eta = " + << cluster->eta() + << ", phi = " + << cluster->phi() + ); + + } + + ATH_MSG_DEBUG( "TrackParticles" ); + ATH_MSG_DEBUG( "Number of TrackParticle = " <<( *el_itr )->nTrackParticles()); + const xAOD::TrackParticle* trackParticle= (*el_itr)->trackParticle(); + if (trackParticle){ + ATH_MSG_DEBUG( "TrackParticle 4-Momentum" ); + ATH_MSG_DEBUG( " pt " + << trackParticle->pt() + << ", eta = " + << trackParticle->eta() + << ", phi = " + << trackParticle->phi() + ); + ATH_MSG_DEBUG( "Track Fitter " << trackParticle->trackFitter() ); + + + } + + ATH_MSG_DEBUG( " Charge = " << ( *el_itr )->charge()); + + //Pass selection + ATH_MSG_DEBUG( "Pass selection variables" ); + + bool val_med=0; + if(( *el_itr )->passSelection(val_med, "Medium")) { + ATH_MSG_DEBUG( "Medium selection exists"); + ATH_MSG_DEBUG( "Medium value : " << static_cast<bool> (val_med)); + } + bool val_loose=0; + if(( *el_itr )->passSelection(val_loose, "Loose")) { + ATH_MSG_DEBUG( "Loose selection exists"); + ATH_MSG_DEBUG( "Loose value : " << static_cast<bool> (val_loose)); + } + bool val_tight=0; + if(( *el_itr )->passSelection(val_tight, "Tight")) { + ATH_MSG_DEBUG( "Tight selection exists"); + ATH_MSG_DEBUG( "Tight value : " << static_cast<bool> (val_tight)); + } + + //Shower Shapes + float val_float=0; + ATH_MSG_DEBUG( "Shower shape parameter" ); + if(( *el_itr )->showerShapeValue(val_float,xAOD::EgammaParameters::e237) ){ + ATH_MSG_DEBUG( "e237 = " <<val_float); + } + if(( *el_itr )->showerShapeValue(val_float,xAOD::EgammaParameters::e277) ){ + ATH_MSG_DEBUG( "e277 = " <<val_float); + } + if(( *el_itr )->showerShapeValue(val_float,xAOD::EgammaParameters::wtots1) ){ + ATH_MSG_DEBUG( "wtots1 = " <<val_float); + } + if(( *el_itr )->showerShapeValue(val_float,xAOD::EgammaParameters::weta1) ){ + ATH_MSG_DEBUG( "weta1 = " <<val_float); + } + if(( *el_itr )->showerShapeValue(val_float,xAOD::EgammaParameters::weta2) ){ + ATH_MSG_DEBUG( "weta2 = " <<val_float); + } + + + if(( *el_itr )->isolationValue(val_float,xAOD::EgammaParameters::ptcone20) ){ + ATH_MSG_DEBUG( "ptcone20 = " <<val_float); + } + + if(( *el_itr )->isolationValue(val_float,xAOD::EgammaParameters::ptcone30) ){ + ATH_MSG_DEBUG( "ptcone30 = " <<val_float); + } + + if(( *el_itr )->isolationValue(val_float,xAOD::EgammaParameters::ptcone40) ){ + ATH_MSG_DEBUG( "ptcone40 = " <<val_float); + } + + if(( *el_itr )->isolationValue(val_float,xAOD::EgammaParameters::topoetcone20) ){ + ATH_MSG_DEBUG( "topoetcone20 = " <<val_float); + } + + if(( *el_itr )->isolationValue(val_float,xAOD::EgammaParameters::topoetcone30) ){ + ATH_MSG_DEBUG( "topoetcone30 = " <<val_float); + } + + if(( *el_itr )->isolationValue(val_float,xAOD::EgammaParameters::topoetcone40) ){ + ATH_MSG_DEBUG( "topoetcone40 = " <<val_float); + } + + //Cluster-Track Match + ATH_MSG_DEBUG( "Track Match parameter" ); + if(( *el_itr )->trackCaloMatchValue(val_float,xAOD::EgammaParameters::deltaPhi2) ){ + ATH_MSG_DEBUG( "deltaPhi2 = " <<val_float); + } + if(( *el_itr )->trackCaloMatchValue(val_float,xAOD::EgammaParameters::deltaPhiRescaled2) ){ + ATH_MSG_DEBUG( "deltaPhiRescaled = " <<val_float); + } + if(( *el_itr )->trackCaloMatchValue(val_float,xAOD::EgammaParameters::deltaPhiFromLastMeasurement) ){ + ATH_MSG_DEBUG( "deltaPhiFromLastMeasurement = " <<val_float); + } + if(( *el_itr )->trackCaloMatchValue(val_float,xAOD::EgammaParameters::deltaEta2) ){ + ATH_MSG_DEBUG( "deltaEta2 = " <<val_float); + } + + ATH_MSG_DEBUG( "TrackParticle Summary" ); + + uint8_t val_uint8=0; + if(( *el_itr )->trackParticleSummaryValue(val_uint8,xAOD::numberOfBLayerHits) ){ + ATH_MSG_DEBUG( "numberOfBLayerHits = " <<static_cast<unsigned int> (val_uint8)); + } + + if(( *el_itr )->trackParticleSummaryValue(val_uint8,xAOD::numberOfPixelHits) ){ + ATH_MSG_DEBUG( "numberOfPixelHits = " <<static_cast<unsigned int> (val_uint8)); + } + + ATH_MSG_DEBUG( "Electron Covariance Matrix" ); + ATH_MSG_DEBUG( ( *el_itr )->covMatrix() ); + + const xAOD::TrackParticle* origTrack = xAOD::EgammaHelpers::getOriginalTrackParticle(*el_itr); + if(origTrack){ + ATH_MSG_DEBUG( "Original TrackParticle"); + ATH_MSG_DEBUG( "TrackParticle 4-Momentum" ); + ATH_MSG_DEBUG( " pt " + << origTrack->pt() + << ", eta = " + << origTrack->eta() + << ", phi = " + << origTrack->phi() + ); + + ATH_MSG_DEBUG( "Track Fitter "<< origTrack->trackFitter() ); + } + + //Truth info + ATH_MSG_DEBUG( "Reco Truth :# " <<i ); + //Truth info + if ((*el_itr)->isAvailable<ElementLink< xAOD::TruthParticleContainer > >("truthParticleLink") ) { + ATH_MSG_DEBUG( "truthParticleLink index " << (*el_itr)->auxdata< ElementLink< xAOD::TruthParticleContainer > >("truthParticleLink").index()); + if ((*el_itr)->auxdata< ElementLink< xAOD::TruthParticleContainer > >("truthParticleLink").isValid()){ + const xAOD::TruthParticle *truthParticle = *((*el_itr)->auxdata< ElementLink< xAOD::TruthParticleContainer > >("truthParticleLink")); + ATH_MSG_DEBUG( "Truth : Reco truth eta " << truthParticle->eta()); + ATH_MSG_DEBUG( "Truth : Reco truth pdgID " << truthParticle->pdgId()); + } + } + + if ((*el_itr)->isAvailable<int>("truthType") ) { + ATH_MSG_DEBUG( "Truth : Reco Truth Type " << (*el_itr)->auxdata<int>("truthType")); + } + if ((*el_itr)->isAvailable<int>("truthOrigin") ) { + ATH_MSG_DEBUG( "Truth : Reco Truth Origin " << (*el_itr)->auxdata<int>("truthOrigin")); + + } + + }//Loop over Electrons + + // Print some basic info: + ATH_MSG_DEBUG( "Number of electronsFrwd: " << electronsFrwd->size() ); + + // Now print some detailed info about each electron: + auto elFrwd_itr = electronsFrwd->begin(); + auto elFrwd_end = electronsFrwd->end(); + + for( int i = 0; elFrwd_itr != elFrwd_end; ++elFrwd_itr, ++i ) { + + ATH_MSG_DEBUG( "########################################" ); + ATH_MSG_DEBUG( "Investigating Frwd electron #" << i ); + ATH_MSG_DEBUG( " Author = " << ( *elFrwd_itr )->author()); + ATH_MSG_DEBUG( "4-Momentum" ); + ATH_MSG_DEBUG( " Pt = " + << ( *elFrwd_itr )->pt() + << ", eta = " + << ( *elFrwd_itr )->eta() + << ", phi = " + << ( *elFrwd_itr )->phi() + << ", m = " + << ( *elFrwd_itr )->m() + << ", e = " + << ( *elFrwd_itr )->e() + << ", P from tlv = " + << ( *elFrwd_itr )->p4().P() + ); + + ATH_MSG_DEBUG( "Clusters" ); + ATH_MSG_DEBUG( "Number of Cluster = " <<( *elFrwd_itr )->nCaloClusters()); + const xAOD::CaloCluster* cluster= (*elFrwd_itr)->caloCluster(); + if (cluster){ + ATH_MSG_DEBUG( "Cluster 4-Momentum" ); + ATH_MSG_DEBUG( " Energy " + << cluster->e() + << ", eta = " + << cluster->eta() + << ", phi = " + << cluster->phi() + ); + + ATH_MSG_DEBUG( "Electron Covariance Matrix" ); + ATH_MSG_DEBUG( ( *elFrwd_itr )->covMatrix() ); + + bool val_loose=0; + if(( *elFrwd_itr )->passSelection(val_loose, "Loose")) { + ATH_MSG_DEBUG( "Loose selection exists"); + ATH_MSG_DEBUG( "Loose value : " << static_cast<bool> (val_loose)); + } + bool val_tight=0; + if(( *elFrwd_itr )->passSelection(val_tight, "Tight")) { + ATH_MSG_DEBUG( "Tight selection exists"); + ATH_MSG_DEBUG( "Tight value : " << static_cast<bool> (val_tight)); + } + + //Truth info + ATH_MSG_DEBUG( "Reco Frwd Truth : #" << i ); + //Truth info + if ((*elFrwd_itr)->isAvailable<ElementLink< xAOD::TruthParticleContainer > >("truthParticleLink") ) { + ATH_MSG_DEBUG( "truthParticleLink index " << (*elFrwd_itr)->auxdata< ElementLink< xAOD::TruthParticleContainer > >("truthParticleLink").index()); + if ((*elFrwd_itr)->auxdata< ElementLink< xAOD::TruthParticleContainer > >("truthParticleLink").isValid()){ + const xAOD::TruthParticle *truthParticle = *((*elFrwd_itr)->auxdata< ElementLink< xAOD::TruthParticleContainer > >("truthParticleLink")); + ATH_MSG_DEBUG( "Truth : Reco Frwd truth pdgID " << truthParticle->pdgId()); + } + } + + if ((*elFrwd_itr)->isAvailable<int>("truthType") ) { + ATH_MSG_DEBUG( "Truth : Reco Frwd Truth Type " << (*elFrwd_itr)->auxdata<int>("truthType")); + } + if ((*elFrwd_itr)->isAvailable<int>("truthOrigin") ) { + ATH_MSG_DEBUG( "Truth : Reco Frwd Truth Origin " << (*elFrwd_itr)->auxdata<int>("truthOrigin")); + + } + + } + }//Forward electrons + + + // Return gracefully: + return StatusCode::SUCCESS; + } + +} // namespace xAODReader diff --git a/Event/xAOD/xAODEgammaCnv/src/ElectronReader.h b/Event/xAOD/xAODEgammaCnv/src/ElectronReader.h new file mode 100644 index 0000000000000000000000000000000000000000..9b283a31eaef195f0d6691a5c2feb0820ad27226 --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/src/ElectronReader.h @@ -0,0 +1,49 @@ +// Dear emacs, this is -*- c++ -*- + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// $Id: ElectronReader.h 581810 2014-02-06 08:45:23Z krasznaa $ +#ifndef XAODREADERALGS_ELECTRONREADER_H +#define XAODREADERALGS_ELECTRONREADER_H + +// System include(s): +#include <string> + +// Gaudi/Athena include(s): +#include "AthenaBaseComps/AthAlgorithm.h" + +namespace xAODReader { + + /** + * @short Algorithm reading xAOD::CaloElectrons + * + * This algorithm is used to test the ability to read + * xAOD::Electron objects from a file inside Athena. + * + * @author Christos Anastopoulos <Christos.Anastopoulos@cern.ch> + * + * $Revision: 581810 $ + * $Date: 2014-02-06 09:45:23 +0100 (Thu, 06 Feb 2014) $ + */ + class ElectronReader : public AthAlgorithm { + + public: + /// Regular Algorithm constructor + ElectronReader( const std::string& name, ISvcLocator* svcLoc ); + + /// Function initialising the algorithm + virtual StatusCode initialize(); + /// Function executing the algorithm + virtual StatusCode execute(); + + private: + /// Name of the container to investigate + std::string m_containerName; + std::string m_containerFrwdName; + }; // class ElectronReader + +} // namespace xAODReader + +#endif // XAODREADERALGS_ELECTRONREADER_H diff --git a/Event/xAOD/xAODEgammaCnv/src/GSFTrackParticleMapCnvAlg.cxx b/Event/xAOD/xAODEgammaCnv/src/GSFTrackParticleMapCnvAlg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d538d66f0abd15aa75142206f1efd7fd8a916972 --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/src/GSFTrackParticleMapCnvAlg.cxx @@ -0,0 +1,121 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// Gaudi/Athena include(s): +#include "AthenaKernel/errorcheck.h" + +// EDM include(s): +#include "Particle/TrackParticleContainer.h" +#include "xAODTracking/TrackParticleContainer.h" +#include "ParticleEvent/TrackParticleAssocs.h" + +// Local include(s): +#include "GSFTrackParticleMapCnvAlg.h" + +namespace xAODMaker { + + GSFTrackParticleMapCnvAlg::GSFTrackParticleMapCnvAlg( const std::string& name, + ISvcLocator* svcLoc ) + : AthAlgorithm( name, svcLoc ) { + + declareProperty( "AODContainerName", m_aodContainerName = "TrackParticleCandidate" ); + declareProperty( "xAODContainerName", m_xaodContainerName = "InDetTrackParticles" ); + declareProperty( "AODContainerNameGSF", m_aodContainerNameGSF = "GSFTrackParticleCandidate" ); + declareProperty( "xAODContainerNameGSF", m_xaodContainerNameGSF = "GSFTrackParticles" ); + declareProperty( "TrackMapName", m_trackMapName="GSFTrackAssociation", "Old new Track Map Name" ); + + } + + StatusCode GSFTrackParticleMapCnvAlg::initialize() { + + ATH_MSG_INFO( "Initializing - Package version: " << PACKAGE_VERSION ); + ATH_MSG_INFO( "AODContainerNameGSF = " << m_aodContainerNameGSF ); + ATH_MSG_INFO( "xAODContainerName = " << m_xaodContainerName ); + ATH_MSG_INFO( "AODContainerNameGSF = " << m_aodContainerNameGSF ); + ATH_MSG_INFO( "xAODContainerNameGSF = " << m_xaodContainerNameGSF ); + + + // Return gracefully: + return StatusCode::SUCCESS; + } + + ///////////////////////////////////////////////////////////////////////////////////////// + + StatusCode GSFTrackParticleMapCnvAlg::execute() { + + // Retrieve the track particles from AOD + const Rec::TrackParticleContainer* aodContainer = evtStore()->tryConstRetrieve<Rec::TrackParticleContainer>(m_aodContainerName ); + if( !aodContainer ) { + ATH_MSG_WARNING("No AOD TrackParticle container found in TES: StoreGate Key = " <<m_aodContainerName); + return StatusCode::SUCCESS; + } + ATH_MSG_DEBUG( "Retrieved particles with key: " << m_aodContainerName ); + + + // Retrieve the GSF track particles from AOD + const Rec::TrackParticleContainer* aodContainerGSF = evtStore()->tryConstRetrieve<Rec::TrackParticleContainer>(m_aodContainerNameGSF ); + if( !aodContainerGSF ) { + ATH_MSG_WARNING("No AOD GSFTrackParticle container found in TES: StoreGate Key = " << m_aodContainerNameGSF); + return StatusCode::SUCCESS; + } + ATH_MSG_DEBUG( "Retrieved particles with key: " << m_aodContainerNameGSF ); + + // Retrieve the GSF track particles from xAOD + const xAOD::TrackParticleContainer* xaodContainerGSF = evtStore()->tryConstRetrieve<xAOD::TrackParticleContainer>(m_xaodContainerNameGSF ); + if( !xaodContainerGSF ) { + ATH_MSG_WARNING("No xAOD GSFTrackParticle container found in TES: StoreGate Key = " << m_xaodContainerNameGSF); + return StatusCode::SUCCESS; + } + ATH_MSG_DEBUG( "Retrieved particles with key: " << m_xaodContainerNameGSF ); + + // Retrieve the GSF -> Trk associations + const TrackParticleAssocs *trkassocs = 0; + StatusCode sc=evtStore()->retrieve( trkassocs, m_trackMapName ) ; + + if( sc.isFailure()) { + ATH_MSG_WARNING( "Could not retrieve " << m_trackMapName); + return StatusCode::SUCCESS; + } + + Rec::TrackParticleContainer associatedElems(SG::VIEW_ELEMENTS); + ///////////////////////////////////////////////////////////////////////////////////////// + + // Loop over the GSF track particles from the AOD and the GSF ones from xAOD + // assuming they are aligned + Rec::TrackParticleContainer::const_iterator aod = aodContainerGSF->begin(); + Rec::TrackParticleContainer::const_iterator aodEnd = aodContainerGSF->end(); + + xAOD::TrackParticleContainer::const_iterator xaod = xaodContainerGSF->begin(); + xAOD::TrackParticleContainer::const_iterator xaodEnd = xaodContainerGSF->end(); + + for ( ; aod != aodEnd, xaod != xaodEnd; ++aod, ++xaod) + { + if ( !trkassocs->assocs(*aod, associatedElems) ) + { + ATH_MSG_WARNING("Missing link from GSF track particle to original TP"); + continue; + } + + // Old link to AOD container + ElementLink<Rec::TrackParticleContainer> oldLink(associatedElems.at(0), *aodContainer); + + // New link to xAOD container of non-GSF track particles + ElementLink<xAOD::TrackParticleContainer> newLink; + newLink.resetWithKeyAndIndex( m_xaodContainerName, oldLink.index() ); + + // Set new link as a decoration of the new GSF track particle + if(newLink.isValid()) + { + newLink.toPersistent(); + xAOD::TrackParticle* gsfTrack = const_cast<xAOD::TrackParticle*> (*xaod); + gsfTrack->auxdata< ElementLink< xAOD::TrackParticleContainer > >( "originalTrackParticle" ) = newLink; + } + } + + // Return gracefully: + return StatusCode::SUCCESS; + } + +} // namespace xAODMaker + diff --git a/Event/xAOD/xAODEgammaCnv/src/GSFTrackParticleMapCnvAlg.h b/Event/xAOD/xAODEgammaCnv/src/GSFTrackParticleMapCnvAlg.h new file mode 100644 index 0000000000000000000000000000000000000000..8a5e774a9befffaf504524b15850488b83a354ed --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/src/GSFTrackParticleMapCnvAlg.h @@ -0,0 +1,56 @@ +// Dear emacs, this is -*- c++ -*- + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// +#ifndef XAODMAKER_GSFTRACKPARTICLEMAPCREATOR_H +#define XAODMAKER_GSFTRACKPARTICLEMAPCREATOR_H + +// System include(s): +#include <string> + +// Athena/Gaudi include(s): +#include "AthenaBaseComps/AthAlgorithm.h" + +namespace xAODMaker { + + /** + * @short Algorithm creating xAOD::Electrons from Analysis::Electrons + * + * This algorithm can be used to translate the Electrons coming + * from an AOD, and create xAOD::Electron objects out of them + * for an output xAOD. + * + * + */ + class GSFTrackParticleMapCnvAlg : public AthAlgorithm { + + public: + /// Regular algorithm constructor + GSFTrackParticleMapCnvAlg( const std::string& name, ISvcLocator* svcLoc ); + + /// Function initialising the algorithm + virtual StatusCode initialize(); + /// Function executing the algorithm + virtual StatusCode execute(); + + private: + + /// The name of the AOD GSF TrackParticle container + std::string m_aodContainerName; + /// The name of the AOD GSF TrackParticle container + std::string m_aodContainerNameGSF; + /// The name of the xAOD GSF TrackParticle container + std::string m_xaodContainerNameGSF; + /// The name of the xAOD non-GSF TrackParticle container + std::string m_xaodContainerName; + /// The name of the map from AOD GSF TrackParticles to AOD TrackParticles + std::string m_trackMapName; + + }; // class GSFTrackParticleMapCnvAlg + +} // namespace xAODMaker + +#endif // XAODMAKER_GSFTRACKPARTICLEMAPCREATOR_H diff --git a/Event/xAOD/xAODEgammaCnv/src/PhotonCnvAlg.cxx b/Event/xAOD/xAODEgammaCnv/src/PhotonCnvAlg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..7596ba18e1f7d91368933d1e270a616efc4a47f2 --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/src/PhotonCnvAlg.cxx @@ -0,0 +1,68 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// Gaudi/Athena include(s): +#include "AthenaKernel/errorcheck.h" + +// EDM include(s): +#include "egammaEvent/PhotonContainer.h" +#include "xAODEgamma/PhotonContainer.h" +#include "xAODEgamma/PhotonAuxContainer.h" +#include "egammaInterfaces/IegammaBaseTool.h" + +// Local include(s): +#include "PhotonCnvAlg.h" + + +namespace xAODMaker { + + PhotonCnvAlg::PhotonCnvAlg( const std::string& name, + ISvcLocator* svcLoc ) + : AthAlgorithm( name, svcLoc ) { + + declareProperty( "AODContainerName", m_aodContainerName = "PhotonAODCollection" ); + declareProperty( "xAODContainerName", m_xaodContainerName = "PhotonCollection" ); + + declareProperty("CnvTool", m_cnvTool, "The converter tool for Photons"); + + } + + StatusCode PhotonCnvAlg::initialize() { + + ATH_MSG_DEBUG( "Initializing - Package version: " << PACKAGE_VERSION ); + ATH_MSG_DEBUG( "AODContainerName = " << m_aodContainerName ); + ATH_MSG_DEBUG( "xAODContainerName = " << m_xaodContainerName ); + + CHECK(m_cnvTool.retrieve()); + // Return gracefully: + return StatusCode::SUCCESS; + } + + StatusCode PhotonCnvAlg::execute() { + + // Retrieve the AOD particles: + const PhotonContainer* aod = evtStore()->tryConstRetrieve<PhotonContainer>(m_aodContainerName); + if (!aod) { + ATH_MSG_WARNING("No PhotonCollection with key " << m_aodContainerName << " found. Do nothing."); + return StatusCode::SUCCESS; + } + ATH_MSG_DEBUG( "Retrieved particles with key: " << m_aodContainerName ); + + // Create the xAOD container and its auxiliary store: + xAOD::PhotonContainer* xaod = new xAOD::PhotonContainer(); + CHECK( evtStore()->record( xaod, m_xaodContainerName ) ); + xAOD::PhotonAuxContainer* aux = new xAOD::PhotonAuxContainer(); + CHECK( evtStore()->record( aux, m_xaodContainerName + "Aux." ) ); + xaod->setStore( aux ); + ATH_MSG_DEBUG( "Recorded Photons with key: " << m_xaodContainerName ); + + CHECK( m_cnvTool->convert(aod, xaod) ); + // Return gracefully - like a elephant on roller skates : + return StatusCode::SUCCESS; + } + +} // namespace xAODMaker + + +// LocalWords: Gaudi diff --git a/Event/xAOD/xAODEgammaCnv/src/PhotonCnvAlg.h b/Event/xAOD/xAODEgammaCnv/src/PhotonCnvAlg.h new file mode 100644 index 0000000000000000000000000000000000000000..4e28ea2dd4dbb62abafe01047a14f20eaf1a2f98 --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/src/PhotonCnvAlg.h @@ -0,0 +1,55 @@ +// Dear emacs, this is -*- c++ -*- + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// +#ifndef XAODEGAMMACNV_PHOTONCNVALG_H +#define XAODEGAMMACNV_PHOTONCNVALG_H + +// System include(s): +#include <string> + +// Athena/Gaudi include(s): +#include "AthenaBaseComps/AthAlgorithm.h" +#include "GaudiKernel/ToolHandle.h" + +#include "xAODEgammaCnv/IPhotonCnvTool.h" + +namespace xAODMaker { + + /** + * @short Algorithm creating xAOD::Photons from Analysis::Photons + * + * This algorithm can be used to translate the Photons coming + * from an AOD, and create xAOD::Photon objects out of them + * for an output xAOD. + * + * + */ + class PhotonCnvAlg : public AthAlgorithm { + + public: + /// Regular algorithm constructor + PhotonCnvAlg( const std::string& name, ISvcLocator* svcLoc ); + + /// Function initialising the algorithm + virtual StatusCode initialize(); + /// Function executing the algorithm + virtual StatusCode execute(); + + private: + /// The key of the input PhotonContainer + std::string m_aodContainerName; + /// The key for the output xAOD::PhotonContainer + std::string m_xaodContainerName; + + /** @brief Tools to perform electron identification*/ + ToolHandle<IPhotonCnvTool> m_cnvTool; + + }; // class PhotonCnvAlg + +} // namespace xAODMaker + +#endif // XAODEGAMMACNV_PHOTONCNVALG_H diff --git a/Event/xAOD/xAODEgammaCnv/src/PhotonCnvTool.cxx b/Event/xAOD/xAODEgammaCnv/src/PhotonCnvTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..a73621e9e53eaf19569dc28e6b7fcf2cfcf3dd6f --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/src/PhotonCnvTool.cxx @@ -0,0 +1,260 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// Gaudi/Athena include(s): +#include "AthenaKernel/errorcheck.h" + +// EDM include(s): +#include "egammaEvent/PhotonContainer.h" +#include "egammaEvent/egammaParamDefs.h" +#include "egammaInterfaces/IegammaBaseTool.h" +#include "egammaInterfaces/IEMClusterTool.h" +#include "FourMom/EigenP4JacobianEEtaPhiM2PtEtaPhiM.h" + +// Local include(s): +#include "PhotonCnvTool.h" + + +namespace xAODMaker { + + PhotonCnvTool::PhotonCnvTool(const std::string& type, + const std::string& name, + const IInterface* parent ) + : AthAlgTool( type, name, parent ) { + + // Declare the interface(s) provided by the tool: + declareInterface< IPhotonCnvTool >(this); + + declareProperty( "RunPID", m_runPID=true ); + declareProperty("PIDBuilder", m_PIDBuilder, "The PID Builder tool configured for photons"); + + declareProperty( "xAODCaloClusterContainerName", m_caloClusters = "egClusterCollection"); + declareProperty( "xAODCaloClusterTopoContainerName", m_caloClustersTopo = "EMCaloClusters"); + declareProperty( "xAODConversionContainerName", m_vertexContainer = "GSFConversionVertices"); + declareProperty( "xAODCaloClusterOtherContainerName", m_caloClustersOther = "egClusterCollection", + "Most likely used for trigger objects"); + declareProperty( "EMClusterTool", m_EMClusterTool, "EMClusterTool" ); + + + } + + StatusCode PhotonCnvTool::initialize() { + + ATH_MSG_DEBUG( "Initializing - Package version: " << PACKAGE_VERSION ); + + if (m_runPID) { + CHECK(m_PIDBuilder.retrieve()); + } + + CHECK(m_EMClusterTool.retrieve()); + + // Return gracefully: + return StatusCode::SUCCESS; + } + + StatusCode PhotonCnvTool::convert( const DataVector<egamma>* aod, + xAOD::PhotonContainer* xaod ) const + { + + if (!aod) { + ATH_MSG_WARNING("No input Photon Collection passed"); + return StatusCode::SUCCESS; + } + if (!xaod) { + ATH_MSG_WARNING("No output Photon Collection passed"); + return StatusCode::SUCCESS; + } + // Create the xAOD objects: + const auto end = aod->end(); + for(auto itr = aod->begin(); itr != end; ++itr ) { + // Create the xAOD object: + xAOD::Photon* photon = new xAOD::Photon(); + xaod->push_back( photon ); + + // p4 + photon->setP4((*itr)->pt(),(*itr)->eta(),(*itr)->phi(),(*itr)->m()); + + // author(s) + photon->setAuthor( (*itr)->author() ); + + //OQ + photon->setOQ( (*itr)->isgoodoq() ); + + + // Error Matrix + if((*itr)->errors()){ + + const ErrorMatrixEEtaPhiM* oldMatrix = (*itr)->errors()->eEtaPhiMMatrix(); + if(oldMatrix){ + Eigen::Matrix<double,4,4> matrix; + for(int i(0);i<4;++i){ + for(int j(0);j<4;++j){ + matrix(i,j) = (*oldMatrix)(i,j); + } + } + Eigen::Matrix<double,4,4> jacobian (EigenP4JacobianEEtaPhiM2PtEtaPhiM((*itr)->e(),(*itr)->eta(),0)); + Eigen::Matrix<double,4,4> covMatrix= jacobian*matrix*jacobian.transpose(); + photon->setCovMatrix(covMatrix.cast<float>()); + } + } + + //setParameters + setParameters(**itr,*photon); + //setIsolations + setIsolations(**itr,*photon); + //setLinks + setLinks(**itr,*photon); + CHECK( m_PIDBuilder->execute(photon) ); + + } + + // Return gracefully - like a elephant on roller skates : + return StatusCode::SUCCESS; + } + + void PhotonCnvTool::setParameters(const egamma& aodph, xAOD::Photon& xaodph) const{ + // We're not doing all AOD parameters here because some are dropped, and some are moved elsewhere. + checkAndSetParameter(egammaParameters::e011 , xAOD::EgammaParameters::e011 , aodph, xaodph); + checkAndSetParameter(egammaParameters::e033 , xAOD::EgammaParameters::e033 , aodph, xaodph); + checkAndSetParameter(egammaParameters::e132 , xAOD::EgammaParameters::e132 , aodph, xaodph); + checkAndSetParameter(egammaParameters::e1152 , xAOD::EgammaParameters::e1152 , aodph, xaodph); + checkAndSetParameter(egammaParameters::ethad , xAOD::EgammaParameters::ethad , aodph, xaodph); + checkAndSetParameter(egammaParameters::ethad1 , xAOD::EgammaParameters::ethad1 , aodph, xaodph); + checkAndSetParameter(egammaParameters::ehad1 , xAOD::EgammaParameters::ehad1 , aodph, xaodph); + checkAndSetParameter(egammaParameters::f1 , xAOD::EgammaParameters::f1 , aodph, xaodph); + checkAndSetParameter(egammaParameters::f3 , xAOD::EgammaParameters::f3 , aodph, xaodph); + checkAndSetParameter(egammaParameters::f1core , xAOD::EgammaParameters::f1core , aodph, xaodph); + checkAndSetParameter(egammaParameters::f3core , xAOD::EgammaParameters::f3core , aodph, xaodph); + checkAndSetParameter(egammaParameters::e233 , xAOD::EgammaParameters::e233 , aodph, xaodph); + checkAndSetParameter(egammaParameters::e235 , xAOD::EgammaParameters::e235 , aodph, xaodph); + checkAndSetParameter(egammaParameters::e255 , xAOD::EgammaParameters::e255 , aodph, xaodph); + checkAndSetParameter(egammaParameters::e237 , xAOD::EgammaParameters::e237 , aodph, xaodph); + checkAndSetParameter(egammaParameters::e277 , xAOD::EgammaParameters::e277 , aodph, xaodph); + checkAndSetParameter(egammaParameters::e333 , xAOD::EgammaParameters::e333 , aodph, xaodph); + checkAndSetParameter(egammaParameters::e335 , xAOD::EgammaParameters::e335 , aodph, xaodph); + checkAndSetParameter(egammaParameters::e337 , xAOD::EgammaParameters::e337 , aodph, xaodph); + checkAndSetParameter(egammaParameters::e377 , xAOD::EgammaParameters::e377 , aodph, xaodph); + checkAndSetParameter(egammaParameters::weta1 , xAOD::EgammaParameters::weta1 , aodph, xaodph); + checkAndSetParameter(egammaParameters::weta2 , xAOD::EgammaParameters::weta2 , aodph, xaodph); + checkAndSetParameter(egammaParameters::e2ts1 , xAOD::EgammaParameters::e2ts1 , aodph, xaodph); + checkAndSetParameter(egammaParameters::e2tsts1 , xAOD::EgammaParameters::e2tsts1 , aodph, xaodph); + checkAndSetParameter(egammaParameters::fracs1 , xAOD::EgammaParameters::fracs1 , aodph, xaodph); + checkAndSetParameter(egammaParameters::widths1 , xAOD::EgammaParameters::widths1 , aodph, xaodph); + checkAndSetParameter(egammaParameters::widths2 , xAOD::EgammaParameters::widths2 , aodph, xaodph); + checkAndSetParameter(egammaParameters::poscs1 , xAOD::EgammaParameters::poscs1 , aodph, xaodph); + checkAndSetParameter(egammaParameters::poscs2 , xAOD::EgammaParameters::poscs2 , aodph, xaodph); + checkAndSetParameter(egammaParameters::asy1 , xAOD::EgammaParameters::asy1 , aodph, xaodph); + checkAndSetParameter(egammaParameters::pos , xAOD::EgammaParameters::pos , aodph, xaodph); + checkAndSetParameter(egammaParameters::pos7 , xAOD::EgammaParameters::pos7 , aodph, xaodph); + checkAndSetParameter(egammaParameters::barys1 , xAOD::EgammaParameters::barys1 , aodph, xaodph); + checkAndSetParameter(egammaParameters::wtots1 , xAOD::EgammaParameters::wtots1 , aodph, xaodph); + checkAndSetParameter(egammaParameters::emins1 , xAOD::EgammaParameters::emins1 , aodph, xaodph); + checkAndSetParameter(egammaParameters::emaxs1 , xAOD::EgammaParameters::emaxs1 , aodph, xaodph); + checkAndSetParameter(egammaParameters::r33over37allcalo , xAOD::EgammaParameters::r33over37allcalo, aodph, xaodph); + checkAndSetParameter(egammaParameters::ecore , xAOD::EgammaParameters::ecore , aodph, xaodph); + checkAndSetParameter(egammaParameters::zvertex , xAOD::EgammaParameters::zvertex , aodph, xaodph); + checkAndSetParameter(egammaParameters::errz , xAOD::EgammaParameters::errz , aodph, xaodph); + checkAndSetParameter(egammaParameters::etap , xAOD::EgammaParameters::etap , aodph, xaodph); + checkAndSetParameter(egammaParameters::depth , xAOD::EgammaParameters::depth , aodph, xaodph); + } + + void PhotonCnvTool::checkAndSetParameter(egammaParameters::ParamDef aodParameter,xAOD::EgammaParameters::ShowerShapeType xaodParameter, const egamma& aodph, xAOD::Photon& xaodph) const { + double result = aodph.detailValue(aodParameter); + float parameter = static_cast<float>(result); + xaodph.setShowerShapeValue(parameter, xaodParameter); + } + + void PhotonCnvTool::setIsolations(const egamma& aodph, xAOD::Photon& xaodph) const { + checkAndSetIsolation(egammaParameters::etcone15 , xAOD::EgammaParameters::etcone15 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::etcone20 , xAOD::EgammaParameters::etcone20 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::etcone25 , xAOD::EgammaParameters::etcone25 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::etcone30 , xAOD::EgammaParameters::etcone30 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::etcone35 , xAOD::EgammaParameters::etcone35 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::etcone40 , xAOD::EgammaParameters::etcone40 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::nucone20 , xAOD::EgammaParameters::nucone20 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::nucone30 , xAOD::EgammaParameters::nucone30 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::nucone40 , xAOD::EgammaParameters::nucone40 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::ptcone20 , xAOD::EgammaParameters::ptcone20 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::ptcone30 , xAOD::EgammaParameters::ptcone30 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::ptcone40 , xAOD::EgammaParameters::ptcone40 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::etcone15_ptcorrected , xAOD::EgammaParameters::etcone15_ptcorrected , aodph, xaodph); + checkAndSetIsolation(egammaParameters::etcone20_ptcorrected , xAOD::EgammaParameters::etcone20_ptcorrected , aodph, xaodph); + checkAndSetIsolation(egammaParameters::etcone25_ptcorrected , xAOD::EgammaParameters::etcone25_ptcorrected , aodph, xaodph); + checkAndSetIsolation(egammaParameters::etcone30_ptcorrected , xAOD::EgammaParameters::etcone30_ptcorrected , aodph, xaodph); + checkAndSetIsolation(egammaParameters::etcone35_ptcorrected , xAOD::EgammaParameters::etcone35_ptcorrected , aodph, xaodph); + checkAndSetIsolation(egammaParameters::etcone40_ptcorrected , xAOD::EgammaParameters::etcone40_ptcorrected , aodph, xaodph); + checkAndSetIsolation(egammaParameters::etcone20_corrected , xAOD::EgammaParameters::etcone20_corrected , aodph, xaodph); + checkAndSetIsolation(egammaParameters::etcone30_corrected , xAOD::EgammaParameters::etcone30_corrected , aodph, xaodph); + checkAndSetIsolation(egammaParameters::etcone40_corrected , xAOD::EgammaParameters::etcone40_corrected , aodph, xaodph); + checkAndSetIsolation(egammaParameters::topoetcone20 , xAOD::EgammaParameters::topoetcone20 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::topoetcone30 , xAOD::EgammaParameters::topoetcone30 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::topoetcone40 , xAOD::EgammaParameters::topoetcone40 , aodph, xaodph); + checkAndSetIsolation(egammaParameters::topoetcone40_ptcorrected , xAOD::EgammaParameters::topoetcone40_ptcorrected , aodph, xaodph); + checkAndSetIsolation(egammaParameters::topoetcone40_corrected , xAOD::EgammaParameters::topoetcone40_corrected , aodph, xaodph); + } + + void PhotonCnvTool::checkAndSetIsolation(egammaParameters::ParamDef aodParameter,xAOD::EgammaParameters::IsolationType xaodParameter, const egamma& aodph, xAOD::Photon& xaodph) const { + double result = aodph.detailValue(aodParameter); + float isolation = static_cast<float>(result); + xaodph.setIsolationValue(isolation, xaodParameter); + } + + + void PhotonCnvTool::setLinks(const egamma& aodph, xAOD::Photon& xaodph) const { + // Need to reset links from old CaloCluster to xAOD::CaloCluster + ElementLink<xAOD::CaloClusterContainer> newclusterElementLink; + + //Change link depending on the photon author + //Topo seeded photons + if( aodph.author(egammaParameters::AuthorCaloTopo35)) { + newclusterElementLink.resetWithKeyAndIndex( m_caloClustersTopo, aodph.clusterElementLink().index() ); + } + //Standard photons + else if (aodph.author(egammaParameters::AuthorPhoton | egammaParameters::AuthorRConv)) { + newclusterElementLink.resetWithKeyAndIndex( m_caloClusters, aodph.clusterElementLink().index() ); + } + // others (trigger) + else { + newclusterElementLink.resetWithKeyAndIndex( m_caloClustersOther, aodph.clusterElementLink().index() ); + } + + std::vector< ElementLink< xAOD::CaloClusterContainer > > linksToClusters; + linksToClusters.push_back(newclusterElementLink); + xaodph.setCaloClusterLinks(linksToClusters); + + // Decorate cluster with position in calo + if (newclusterElementLink.isValid()) + { + ATH_MSG_DEBUG("Decorating cluster"); + xAOD::CaloCluster *cluster = const_cast<xAOD::CaloCluster*>(*newclusterElementLink); + if (cluster) + { + m_EMClusterTool->fillPositionsInCalo(*cluster); + } + else ATH_MSG_DEBUG("Could not dereference / cast link to cluster"); + } + else ATH_MSG_WARNING("Invalid link to cluster"); + + // Need to reset links from old VxVertex to xAOD::Vertex + std::vector< ElementLink< xAOD::VertexContainer > > linksToVertices; + for(unsigned int i(0); i<aodph.nConversions(); ++i){ + linksToVertices.push_back( getNewLink(aodph.conversionElementLink(i), m_vertexContainer) ); + } + xaodph.setVertexLinks( linksToVertices ); + } + + ElementLink<xAOD::VertexContainer> PhotonCnvTool::getNewLink(const ElementLink<VxContainer>& oldLink, const std::string& name) const{ + ElementLink<xAOD::VertexContainer> newLink; + newLink.resetWithKeyAndIndex( name, oldLink.index() ); + // std::cout<<"Old link is "<<(oldLink.isValid()?"VALID":"INVALID") + // <<" and new link (pointing to"<<name<<") is "<<(newLink.isValid()?"VALID":"INVALID")<<std::endl; + return newLink; + } + + + +} // namespace xAODMaker + + +// LocalWords: Gaudi diff --git a/Event/xAOD/xAODEgammaCnv/src/PhotonCnvTool.h b/Event/xAOD/xAODEgammaCnv/src/PhotonCnvTool.h new file mode 100644 index 0000000000000000000000000000000000000000..1cfbeb6767ab49ba9cbb677d90717125d933a59b --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/src/PhotonCnvTool.h @@ -0,0 +1,83 @@ +// Dear emacs, this is -*- c++ -*- + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// $Id$ +#ifndef XAODEGAMMACNV_PHOTONCNVTOOL_H +#define XAODEGAMMACNV_PHOTONCNVTOOL_H + +// Gaudi/Athena include(s): +#include "AthenaBaseComps/AthAlgTool.h" +#include "GaudiKernel/ToolHandle.h" + +// EDM include(s): +#include "egammaEvent/egamma.h" +#include "egammaEvent/egammaParamDefs.h" + +#include "xAODEgammaCnv/IPhotonCnvTool.h" + +// Forward declaration(s): +class IegammaBaseTool; +class IEMClusterTool; + +namespace xAODMaker { + + /** + * @short Implementation for the tool creating PhotonContainer from an AOD + * + * This interface is implemented by the tool that converts the + * egamma (Photon) Container into an xAOD::PhotonContainer. + * + * @author Jovan Mitrevski <Jovan.Mitrevski@cern.ch> + * + * $Revision$ + * $Date$ + */ + class PhotonCnvTool : public AthAlgTool, + public virtual IPhotonCnvTool { + + public: + /// Regular AlgTool constructor + PhotonCnvTool( const std::string& type, const std::string& name, + const IInterface* parent ); + + /// Function initializing the tool + virtual StatusCode initialize(); + + /// Function that fills an existing xAOD::PhotonContainer + virtual StatusCode convert( const DataVector<egamma>* aod, + xAOD::PhotonContainer* xaod) const; + + private: + /// Fills in the shower shape variables + void setParameters(const egamma&, xAOD::Photon& ) const ; + void checkAndSetParameter(egammaParameters::ParamDef aodParameter,xAOD::EgammaParameters::ShowerShapeType xaodParameter, const egamma& , xAOD::Photon& ) const; + + /// Fills in the isolation variables + void setIsolations(const egamma& aodmuon, xAOD::Photon& xaodmuon) const; + void checkAndSetIsolation(egammaParameters::ParamDef aodParameter,xAOD::EgammaParameters::IsolationType xaodParameter, const egamma&, xAOD::Photon& ) const; + + void setLinks(const egamma& aodph, xAOD::Photon& xaodph) const; + ElementLink<xAOD::VertexContainer> getNewLink(const ElementLink<VxContainer>& oldLink, const std::string& name) const; + + + std::string m_vertexContainer; //!< Location/Key for xAOD::Vertex for photons + std::string m_caloClusters; //!< Location/Key for xAOD::CaloClusters for electrons and photons + std::string m_caloClustersTopo; //!< Location/Key for xAOD::CaloClusters for topo seeded photons + std::string m_caloClustersOther; //!< Location/Key for xAOD::CaloClusters for other (trigger?) electrons + + bool m_runPID; + + /** @brief Tools to perform identification*/ + ToolHandle<IegammaBaseTool> m_PIDBuilder; + + /** @brief Tool to decorate clusters */ + ToolHandle<IEMClusterTool> m_EMClusterTool; + + }; // class PhotonCnvTool + +} // namespace xAODMaker + +#endif // XAODEGAMMACNV_PHOTONCNVTOOL_H diff --git a/Event/xAOD/xAODEgammaCnv/src/components/xAODEgammaCnv_entries.cxx b/Event/xAOD/xAODEgammaCnv/src/components/xAODEgammaCnv_entries.cxx new file mode 100644 index 0000000000000000000000000000000000000000..96972a4897f1b7da219a8c3c7e855c6dc4204547 --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/src/components/xAODEgammaCnv_entries.cxx @@ -0,0 +1,31 @@ + + + +// Gaudi/Athena include(s): +#include "GaudiKernel/DeclareFactoryEntries.h" + +// Local include(s): +#include "../ElectronCnvAlg.h" +#include "../PhotonCnvAlg.h" +#include "../ElectronCnvTool.h" +#include "../PhotonCnvTool.h" +#include "../GSFTrackParticleMapCnvAlg.h" +#include "../ElectronReader.h" + + +DECLARE_NAMESPACE_ALGORITHM_FACTORY( xAODMaker, ElectronCnvAlg ) +DECLARE_NAMESPACE_ALGORITHM_FACTORY( xAODMaker, PhotonCnvAlg ) +DECLARE_NAMESPACE_TOOL_FACTORY( xAODMaker, ElectronCnvTool ) +DECLARE_NAMESPACE_TOOL_FACTORY( xAODMaker, PhotonCnvTool ) +DECLARE_NAMESPACE_ALGORITHM_FACTORY( xAODMaker, GSFTrackParticleMapCnvAlg ) +DECLARE_NAMESPACE_ALGORITHM_FACTORY( xAODReader, ElectronReader ) + +DECLARE_FACTORY_ENTRIES( xAODEgammaCnv ) { + DECLARE_NAMESPACE_ALGORITHM( xAODMaker, ElectronCnvAlg ) + DECLARE_NAMESPACE_ALGORITHM( xAODMaker, PhotonCnvAlg ) + DECLARE_NAMESPACE_TOOL( xAODMaker, ElectronCnvTool ) + DECLARE_NAMESPACE_TOOL( xAODMaker, PhotonCnvTool ) + DECLARE_NAMESPACE_ALGORITHM( xAODMaker, GSFTrackParticleMapCnvAlg ) + DECLARE_NAMESPACE_ALGORITHM( xAODReader, ElectronReader ) + +} diff --git a/Event/xAOD/xAODEgammaCnv/src/components/xAODEgammaCnv_load.cxx b/Event/xAOD/xAODEgammaCnv/src/components/xAODEgammaCnv_load.cxx new file mode 100644 index 0000000000000000000000000000000000000000..22785d76be2ae0030ab6c12b4eb0658d757c3599 --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/src/components/xAODEgammaCnv_load.cxx @@ -0,0 +1,4 @@ +#include "GaudiKernel/LoadFactoryEntries.h" + +LOAD_FACTORY_ENTRIES(xAODEgammaCnv) + diff --git a/Event/xAOD/xAODEgammaCnv/xAODEgammaCnv/IElectronCnvTool.h b/Event/xAOD/xAODEgammaCnv/xAODEgammaCnv/IElectronCnvTool.h new file mode 100644 index 0000000000000000000000000000000000000000..df3258c034a34b4fa1da5c765cd0b84b6a48bbc9 --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/xAODEgammaCnv/IElectronCnvTool.h @@ -0,0 +1,55 @@ +// Dear emacs, this is -*- c++ -*- + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// $Id$ +#ifndef XAODEGAMMACNV_IELECTRONCNVTOOL_H +#define XAODEGAMMACNV_IELECTRONCNVTOOL_H + +// Gaudi/Athena include(s): +#include "GaudiKernel/IAlgTool.h" +#include "DataModel/DataVector.h" + +// EDM include(s): +#include "xAODEgamma/ElectronContainer.h" + +// Forward declaration(s): +class egamma; + +namespace xAODMaker { + + /// The interface provided by IElectronCnvTool + static const InterfaceID + IID_IElectronCnvTool( "xAODMaker::IElectronCnvTool", 1, 0 ); + + /** + * @short Interface for the tool creating ElectronContainer from an AOD + * + * This interface is implemented by the tool that converts the + * egamma (Electron) Container into an xAOD::ElectronContainer. + * + * @author Jovan Mitrevski <Jovan.Mitrevski@cern.ch> + * + * $Revision$ + * $Date$ + */ + class IElectronCnvTool : public virtual IAlgTool { + + public: + /// Function that fills an existing xAOD::ElectronContainer + virtual StatusCode convert( const DataVector<egamma>* aod, + xAOD::ElectronContainer* xaod, + xAOD::ElectronContainer* xaodFrwd) const = 0; + + /// Gaudi interface definition + static const InterfaceID& interfaceID() { + return IID_IElectronCnvTool; + } + + }; // class IElectronCnvTool + +} // namespace xAODMaker + +#endif // XAODEGAMMACNV_IELECTRONCNVTOOL_H diff --git a/Event/xAOD/xAODEgammaCnv/xAODEgammaCnv/IPhotonCnvTool.h b/Event/xAOD/xAODEgammaCnv/xAODEgammaCnv/IPhotonCnvTool.h new file mode 100644 index 0000000000000000000000000000000000000000..bdb93637ba6dcca73c77e1f66a5a349432dcff0e --- /dev/null +++ b/Event/xAOD/xAODEgammaCnv/xAODEgammaCnv/IPhotonCnvTool.h @@ -0,0 +1,54 @@ +// Dear emacs, this is -*- c++ -*- + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// $Id$ +#ifndef XAODEGAMMACNV_IPHOTONCNVTOOL_H +#define XAODEGAMMACNV_IPHOTONCNVTOOL_H + +// Gaudi/Athena include(s): +#include "GaudiKernel/IAlgTool.h" +#include "DataModel/DataVector.h" + +// EDM include(s): +#include "xAODEgamma/PhotonContainer.h" + +// Forward declaration(s): +class egamma; + +namespace xAODMaker { + + /// The interface provided by IPhotonCnvTool + static const InterfaceID + IID_IPhotonCnvTool( "xAODMaker::IPhotonCnvTool", 1, 0 ); + + /** + * @short Interface for the tool creating PhotonContainer from an AOD + * + * This interface is implemented by the tool that converts the + * egamma (Photon) Container into an xAOD::PhotonContainer. + * + * @author Jovan Mitrevski <Jovan.Mitrevski@cern.ch> + * + * $Revision$ + * $Date$ + */ + class IPhotonCnvTool : public virtual IAlgTool { + + public: + /// Function that fills an existing xAOD::PhotonContainer + virtual StatusCode convert( const DataVector<egamma>* aod, + xAOD::PhotonContainer* xaod ) const = 0; + + /// Gaudi interface definition + static const InterfaceID& interfaceID() { + return IID_IPhotonCnvTool; + } + + }; // class IPhotonCnvTool + +} // namespace xAODMaker + +#endif // XAODEGAMMACNV_IPHOTONCNVTOOL_H