Commit c75dca55 authored by Christos Anastopoulos's avatar Christos Anastopoulos Committed by Frank Winklmeier
Browse files

egammaOQFlagsBuilder clean up 1st try

parent 64decc5c
......@@ -8,6 +8,7 @@
#include "xAODCaloEvent/CaloClusterContainer.h"
#include "xAODCaloEvent/CaloClusterAuxContainer.h"
#include "xAODCaloEvent/CaloCluster.h"
#include "CaloDetDescr/CaloDetDescrManager.h"
#include "xAODEgamma/ElectronContainer.h"
#include "xAODEgamma/ElectronAuxContainer.h"
......@@ -17,18 +18,10 @@
#include "PATCore/AcceptData.h"
#include <algorithm>
#include <math.h>
#include <cmath>
// END OF HEADER FILES INCLUDE
/////////////////////////////////////////////////////////////////
// CONSTRUCTOR:
egammaForwardBuilder::egammaForwardBuilder(const std::string& name, ISvcLocator* pSvcLocator):
AthReentrantAlgorithm(name, pSvcLocator),
m_timingProfile("ChronoStatSvc", name)
AthReentrantAlgorithm(name, pSvcLocator)
{
}
......@@ -36,20 +29,11 @@ egammaForwardBuilder::egammaForwardBuilder(const std::string& name, ISvcLocator*
// ================================================================
egammaForwardBuilder::~egammaForwardBuilder()
{
//
// destructor
//
}
// =================================================================
StatusCode egammaForwardBuilder::initialize()
{
//
// initialize method
//
ATH_MSG_DEBUG(" Initializing egammaForwardBuilder ");
// the data handle keys
ATH_CHECK(m_topoClusterKey.initialize());
ATH_CHECK(m_electronOutputKey.initialize());
......@@ -61,7 +45,6 @@ StatusCode egammaForwardBuilder::initialize()
if (!m_objectQualityTool.empty()) {
ATH_CHECK(m_objectQualityTool.retrieve());
} else {
ATH_MSG_DEBUG("egammaOQFlagsBuilder is disabled");
m_objectQualityTool.disable();
}
......@@ -78,31 +61,25 @@ StatusCode egammaForwardBuilder::initialize()
ATH_MSG_ERROR("The number of selectors does not match the number of given fwd-electron selector names");
return StatusCode::FAILURE;
}
if (m_doChrono) ATH_CHECK( m_timingProfile.retrieve() );
ATH_MSG_DEBUG("Initialization completed successfully");
return StatusCode::SUCCESS;
}
// ====================================================================
StatusCode egammaForwardBuilder::finalize()
{
return StatusCode::SUCCESS;
}
// ======================================================================
StatusCode egammaForwardBuilder::execute(const EventContext& ctx) const
{
ATH_MSG_DEBUG("Executing egammaForwardBuilder ");
// create an egamma container and register it
SG::WriteHandle<xAOD::ElectronContainer> xaodFrwd(m_electronOutputKey, ctx);
ATH_CHECK(xaodFrwd.record(std::make_unique<xAOD::ElectronContainer>(),
std::make_unique<xAOD::ElectronAuxContainer>()));
ATH_MSG_DEBUG( "Recorded Electrons with key: " << m_electronOutputKey.key() );
//cluster
SG::WriteHandle<xAOD::CaloClusterContainer> outClusterContainer(m_outClusterContainerKey, ctx);
......@@ -121,7 +98,6 @@ StatusCode egammaForwardBuilder::execute(const EventContext& ctx) const
return StatusCode::FAILURE;
}
//loop over cluster container
xAOD::CaloClusterContainer::const_iterator clus_begin = cluster->begin();
xAOD::CaloClusterContainer::const_iterator clus_end = cluster->end();
......@@ -171,7 +147,6 @@ StatusCode egammaForwardBuilder::execute(const EventContext& ctx) const
}
}
// Now finalize the cluster: based on code in CaloClusterStoreHelper::finalizeClusters
// Note: I don't specifically set the IProxyDict, since I also don't set it when I create
// data handles, either.
......@@ -180,8 +155,6 @@ StatusCode egammaForwardBuilder::execute(const EventContext& ctx) const
cl->setLink(outClusterContainerCellLink.ptr(), sg);
}
ATH_MSG_VERBOSE("egammaForward execute completed successfully");
return StatusCode::SUCCESS;
}
......@@ -194,19 +167,11 @@ StatusCode egammaForwardBuilder::ExecObjectQualityTool(const EventContext& ctx,
// protection in case tool is not available
// return success as algorithm may be able to run without it
// in degraded mode
if (m_objectQualityTool.name().empty()) return StatusCode::SUCCESS;
// setup chrono for this tool
std::string chronoName=this->name()+"_"+m_objectQualityTool->name() ;
if (m_doChrono) m_timingProfile->chronoStart(chronoName);
const CaloDetDescrManager* calodetdescrmgr = nullptr;
ATH_CHECK(detStore()->retrieve(calodetdescrmgr, "CaloMgr"));
// execute the tool
StatusCode sc = m_objectQualityTool->execute(ctx, eg);
if ( sc.isFailure() ) {
ATH_MSG_DEBUG("failure returned by object quality tool");
}
if (m_doChrono) m_timingProfile->chronoStop(chronoName);
return sc;
return m_objectQualityTool->execute(ctx, *calodetdescrmgr,*eg);
}
......@@ -24,7 +24,6 @@
//
#include "AthenaBaseComps/AthReentrantAlgorithm.h"
#include "GaudiKernel/ToolHandle.h"
#include "GaudiKernel/IChronoStatSvc.h"
#include "GaudiKernel/ServiceHandle.h"
#include "GaudiKernel/EventContext.h"
......@@ -39,6 +38,7 @@
#include "xAODEgamma/Egamma.h"
#include "xAODEgamma/ElectronContainer.h"
#include "egammaInterfaces/IegammaOQFlagsBuilder.h"
#include "egammaInterfaces/IegammaBaseTool.h"
#include "egammaInterfaces/IEMFourMomBuilder.h"
#include "EgammaAnalysisInterfaces/IAsgForwardElectronIsEMSelector.h"
......@@ -69,7 +69,7 @@ class egammaForwardBuilder : public AthReentrantAlgorithm
StatusCode ExecObjectQualityTool(const EventContext &ctx, xAOD::Egamma *eg) const;
/** @brief Tool to perform object quality*/
ToolHandle<IegammaBaseTool> m_objectQualityTool {this,
ToolHandle<IegammaOQFlagsBuilder> m_objectQualityTool {this,
"ObjectQualityTool", "",
"Name of the object quality tool (empty tool name ignored)"};
......@@ -102,11 +102,6 @@ class egammaForwardBuilder : public AthReentrantAlgorithm
/** @brief eta cut */
Gaudi::Property<double> m_etacut {this, "EtaCut", 2.5, "eta cut"};
/** @brief do chrono service */
Gaudi::Property<bool> m_doChrono {this, "doChrono", false, "do Chrono Service"};
// to measure speed of the algorithm
ServiceHandle<IChronoStatSvc> m_timingProfile;
protected:
/** Handle to the selectors */
ToolHandleArray<IAsgForwardElectronIsEMSelector> m_forwardElectronIsEMSelectors {this,
......
......@@ -33,6 +33,7 @@
#include "EgammaAnalysisInterfaces/IEGammaAmbiguityTool.h"
#include "egammaInterfaces/IEMClusterTool.h"
#include "egammaInterfaces/IEMShowerBuilder.h"
#include "egammaInterfaces/IegammaOQFlagsBuilder.h"
#include "egammaInterfaces/IegammaBaseTool.h"
class egammaRec;
......@@ -51,6 +52,30 @@ public:
StatusCode execute(const EventContext& ctx) const override final;
private:
/** Given an egammaRec object, a pointer to the electron container and the author,
* create and dress an electron, pushing it back to the container and
* calling the relevant tools **/
bool getElectron(const egammaRec* egRec, xAOD::ElectronContainer *electronContainer,
const unsigned int author, const uint8_t type) const;
/** Given an egammaRec object, a pointer to the photon container and the author,
* create and dress a photon, pushing it back to the container and
* calling the relevant tools **/
bool getPhoton(const egammaRec* egRec, xAOD::PhotonContainer *photonContainer,
const unsigned int author, uint8_t type) const;
/** @brief Do the final ambiguity **/
StatusCode doAmbiguityLinks(xAOD::ElectronContainer *electronContainer,
xAOD::PhotonContainer *photonContainer) const ;
/** @brief Call a tool using contExecute and electrons, photon containers if given **/
StatusCode CallTool(const EventContext& ctx,
const ToolHandle<IegammaBaseTool>& tool,
xAOD::ElectronContainer *electronContainer = nullptr,
xAOD::PhotonContainer *photonContainer = nullptr) const;
/** @brief Vector of tools for dressing electrons and photons **/
ToolHandleArray<IegammaBaseTool> m_egammaTools {this,
......@@ -76,33 +101,15 @@ private:
/** @brief Tool to resolve electron/photon ambiguity */
ToolHandle<IEGammaAmbiguityTool> m_ambiguityTool {this,
"AmbiguityTool", "egammaTools/EGammaAmbiguityTool",
"AmbiguityTool", "ElectronPhotonSelectorTools/EGammaAmbiguityTool",
"Tool that does electron/photon ambiguity resolution"};
/** @brief Tool to resolve electron/photon ambiguity */
ToolHandle<IegammaOQFlagsBuilder> m_egammaOQTool {this,
"ObjectQualityTool", {},
"Tool that adds electron/photon Object Quality info"};
/** Given an egammaRec object, a pointer to the electron container and the author,
* create and dress an electron, pushing it back to the container and
* calling the relevant tools **/
bool getElectron(const egammaRec* egRec, xAOD::ElectronContainer *electronContainer,
const unsigned int author, const uint8_t type) const;
/** Given an egammaRec object, a pointer to the photon container and the author,
* create and dress a photon, pushing it back to the container and
* calling the relevant tools **/
bool getPhoton(const egammaRec* egRec, xAOD::PhotonContainer *photonContainer,
const unsigned int author, uint8_t type) const;
/** @brief Do the final ambiguity **/
StatusCode doAmbiguityLinks(xAOD::ElectronContainer *electronContainer,
xAOD::PhotonContainer *photonContainer) const ;
/** @brief Call a tool using contExecute and electrons, photon containers if given **/
StatusCode CallTool(const EventContext& ctx,
const ToolHandle<IegammaBaseTool>& tool,
xAOD::ElectronContainer *electronContainer = nullptr,
xAOD::PhotonContainer *photonContainer = nullptr) const;
/** @brief Name of the electron output collection*/
SG::WriteHandleKey<xAOD::ElectronContainer> m_electronOutputKey {this,
......@@ -128,11 +135,10 @@ private:
//
// Other properties.
//
// others:
ServiceHandle<IChronoStatSvc> m_timingProfile;
Gaudi::Property<bool> m_doChrono {this, "doChrono", false, "do Chrono Service"};
Gaudi::Property<bool> m_doPhotons {this, "doPhotons", true, "Run the Photon reconstruction"};
Gaudi::Property<bool> m_doElectrons {this, "doElectrons", true, "Run the Electron reconstruction"};
bool m_doAmbiguity;
bool m_doOQ;
};
#endif
......@@ -2,22 +2,18 @@
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
// IegammaBackShape.h, (c) ATLAS Detector software 2009
///////////////////////////////////////////////////////////////////
#ifndef EGAMMAINTERFACES_IEGAMMABACKSHAPE_H
#define EGAMMAINTERFACES_IEGAMMABACKSHAPE_H
/// @class IegammaBackShape
/// @brief Interface for the Reconstruction/egamma/egammaCaloTools/egammaBackrShape
///
/// @author Frederic Derue derue@lpnhe.in2p3.fr
/// @author Christos Anastopoulos
///
/// $Revision:$
/// $Date: 2014-02-11 17:40:48 +0100 (Tue, 11 Feb 2014) $
///
/*
* @name IegammaBackShape.h, (c) ATLAS Detector software 2009
* @class IegammaBackShape
* @brief Interface for the Reconstruction/egamma/egammaCaloTools/egammaBackShape
*
* @author Frederic Derue derue@lpnhe.in2p3.fr
* @author Christos Anastopoulos
*/
// Gaudi
#include "GaudiKernel/IAlgTool.h"
......
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#ifndef EGAMMAINTERFACES_IEGAMMABACKSHAPE_H
#define EGAMMAINTERFACES_IEGAMMABACKSHAPE_H
/*
* @name IegammaOQFlagsBuilder.h, (c) ATLAS Detector software 2009
* @class IegammaOQFlagsBuilder
* @brief Interface for the
* Reconstruction/egamma/egammaTools/egammaOQFlagsBuilder
*
* @author Christos Anastopoulos
*/
// Gaudi
#include "GaudiKernel/IAlgTool.h"
#include "GaudiKernel/EventContext.h"
// Forward declarations
#include "xAODEgamma/EgammaFwd.h"
class CaloDetDescrManager;
static const InterfaceID IID_IegammaOQFlagsBuilder("IegammaOQFlagsBuilder",
1,
0);
class IegammaOQFlagsBuilder : virtual public IAlgTool
{
public:
/** @brief Virtual destructor */
virtual ~IegammaOQFlagsBuilder(){};
/** @brief AlgTool interface methods */
static const InterfaceID& interfaceID();
/** @brief AlgTool method.*/
virtual StatusCode execute(const EventContext& ctx,
const CaloDetDescrManager& cmgr,
xAOD::Egamma& egamma) const = 0;
};
inline const InterfaceID&
IegammaOQFlagsBuilder::interfaceID()
{
return IID_IegammaOQFlagsBuilder;
}
#endif // EGAMMAINTERFACES_IEGAMMABACKSHAPE_H
......@@ -33,4 +33,5 @@
#include "egammaInterfaces/IegammaSwTool.h"
#include "egammaInterfaces/IegammaTrkRefitterTool.h"
#include "egammaInterfaces/IegammaMVASvc.h"
#include "egammaInterfaces/IegammaOQFlagsBuilder.h"
#endif // EGAMMAINTERFACES_EGAMMAINTERFACESDICT_H
......@@ -17,5 +17,6 @@
<class name="IegammaSwTool" />
<class name="IegammaTrkRefitterTool" />
<class name="IegammaMVASvc" />
<class name="IegammaOQFlagsBuilder" />
</lcgdict>
# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
from __future__ import print_function
from egammaTools.egammaToolsFactories import \
EMClusterTool, EMFourMomBuilder, EMShowerBuilder, egammaOQFlagsBuilder, \
ElectronPIDBuilder, PhotonPIDBuilder
# specifies standard (supercluster) egamma.
from AthenaCommon.Logging import logging
from AthenaCommon.SystemOfUnits import *
from AthenaCommon.Constants import *
from AthenaCommon.DetFlags import DetFlags
from RecExConfig.Configured import Configured
#
from egammaRec import egammaKeys
from egammaAlgs import egammaAlgsConf
from egammaRec.Factories import AlgFactory, FcnWrapper
from egammaRec.Factories import FcnWrapper
from egammaRec import egammaRecFlags as egRecFlags
egammaRecFlags = egRecFlags.jobproperties.egammaRecFlags
#Some handy flags
def doConversions() :
return DetFlags.detdescr.ID_on() and egammaRecFlags.doConversions()
################
def doConversions():
return DetFlags.detdescr.ID_on() and egammaRecFlags.doConversions()
# The tools used to add properties
# Import the tool factories
from egammaTools.egammaToolsFactories import \
EMClusterTool, EMFourMomBuilder, EMShowerBuilder, egammaOQFlagsBuilder, \
ElectronPIDBuilder, PhotonPIDBuilder
#The tools used to add properties
def egammaDecorationTools():
"Return a list with the tools that decorate both electrons and photons"
return [ EMFourMomBuilder(), egammaOQFlagsBuilder()]
"Return a list with the tools that decorate both electrons and photons"
return [EMFourMomBuilder()]
def electronDecorationTools():
"Return a list with the tools that decorate only electrons"
return [ ElectronPIDBuilder() ]
"Return a list with the tools that decorate only electrons"
return [ElectronPIDBuilder()]
def photonDecorationTools():
"Return a list with the tools that decorate only photons"
return [ PhotonPIDBuilder() ]
"Return a list with the tools that decorate only photons"
return [PhotonPIDBuilder()]
#
class topoEgammaGetter ( Configured ) :
class topoEgammaGetter (Configured):
def configure(self):
mlog = logging.getLogger ('topoEgammaGetter.py::configure:')
mlog = logging.getLogger('topoEgammaGetter.py::configure:')
mlog.info('entering')
# # the egammaTopoClusterCopier
......@@ -58,52 +53,51 @@ class topoEgammaGetter ( Configured ) :
# return False
# print self._egammaTopoClusterCopierHandle
# the egammaRecBuilder
from egammaAlgs.egammaRecBuilder import egammaRecBuilder
try:
self._egammaRecBuilder = egammaRecBuilder(doTrackMatching = DetFlags.detdescr.ID_on(),
doConversions = doConversions())
self._egammaRecBuilder = egammaRecBuilder(doTrackMatching=DetFlags.detdescr.ID_on(),
doConversions=doConversions())
except Exception:
mlog.error("could not get handle to egammaRecBuilder")
import traceback
traceback.print_exc()
return False
print (self._egammaRecBuilder)
print(self._egammaRecBuilder)
# the supercluster builders
from egammaAlgs.egammaSuperClusterBuilder import \
electronSuperClusterBuilder, photonSuperClusterBuilder
try:
self._electronSuperClusterBuilder = electronSuperClusterBuilder(
doTrackMatching = DetFlags.detdescr.ID_on())
self._photonSuperClusterBuilder = photonSuperClusterBuilder(
doConversions = doConversions())
self._electronSuperClusterBuilder = electronSuperClusterBuilder(
doTrackMatching=DetFlags.detdescr.ID_on())
self._photonSuperClusterBuilder = photonSuperClusterBuilder(
doConversions=doConversions())
except Exception:
mlog.error("could not get handle to supcluster builders")
import traceback
traceback.print_exc()
return False
print (self._electronSuperClusterBuilder)
print (self._photonSuperClusterBuilder)
print(self._electronSuperClusterBuilder)
print(self._photonSuperClusterBuilder)
# the topoEgammaBuilder (the part that puts everything together
from egammaAlgs.topoEgammaBuilder import topoEgammaBuilder
try:
self._topoEgammaBuilder = topoEgammaBuilder(
EMClusterTool=EMClusterTool,
EMShowerTool=EMShowerBuilder,
# Decoration tools
egammaTools = FcnWrapper(egammaDecorationTools),
ElectronTools = FcnWrapper(electronDecorationTools),
PhotonTools = FcnWrapper(photonDecorationTools)
)
self._topoEgammaBuilder = topoEgammaBuilder(
EMClusterTool=EMClusterTool,
EMShowerTool=EMShowerBuilder,
ObjectQualityTool=egammaOQFlagsBuilder,
# Decoration tools
egammaTools=FcnWrapper(egammaDecorationTools),
ElectronTools=FcnWrapper(electronDecorationTools),
PhotonTools=FcnWrapper(photonDecorationTools)
)
except Exception:
mlog.error("could not get handle to topoEgammaBuilder")
import traceback
traceback.print_exc()
return False
print (self._topoEgammaBuilder)
print(self._topoEgammaBuilder)
# the egammaLargeClusterMaker (Which chooses the cells to store in the AOD)
from egammaAlgs.egammaLargeClusterMakerAlg import egammaLargeClusterMakerAlg
......@@ -114,7 +108,6 @@ class topoEgammaGetter ( Configured ) :
import traceback
traceback.print_exc()
return False
print (self._egammaLargeClusterMaker)
print(self._egammaLargeClusterMaker)
return True
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
# default configuration of the EMPIDBuilder
from ROOT import LikeEnum
from ROOT import egammaPID
from AthenaCommon.Logging import logging
from AthenaCommon.DetFlags import DetFlags
import traceback
from ElectronPhotonSelectorTools.ElectronIsEMSelectorMapping import electronPIDmenu
from ElectronPhotonSelectorTools.PhotonIsEMSelectorMapping import photonPIDmenu
#import base class
# import base class
from egammaTools.egammaToolsConf import EMPIDBuilder
import cppyy
cppyy.loadDictionary('ElectronPhotonSelectorToolsDict')
from ROOT import egammaPID
from ROOT import LikeEnum
class EMPIDBuilderElectronBase ( EMPIDBuilder ) :
class EMPIDBuilderElectronBase (EMPIDBuilder):
__slots__ = ()
def __init__(self, name="EMPIDBuilderElectronBase"):
EMPIDBuilder.__init__(self,name)
EMPIDBuilder.__init__(self, name)
mlog = logging.getLogger(name+'::__init__')
mlog.debug("entering")
# Electron Selectors
try:
# Cut based
# Cut based
from ElectronPhotonSelectorTools.ConfiguredAsgElectronIsEMSelectors import ConfiguredAsgElectronIsEMSelector
LooseElectronSelector = ConfiguredAsgElectronIsEMSelector("LooseElectronSelector", egammaPID.ElectronIDLoosePP)
MediumElectronSelector = ConfiguredAsgElectronIsEMSelector("MediumElectronSelector", egammaPID.ElectronIDMediumPP)
TightElectronSelector = ConfiguredAsgElectronIsEMSelector("TightElectronSelector", egammaPID.ElectronIDTightPP)
LooseElectronSelector = ConfiguredAsgElectronIsEMSelector(
"LooseElectronSelector", egammaPID.ElectronIDLoosePP)
MediumElectronSelector = ConfiguredAsgElectronIsEMSelector(
"MediumElectronSelector", egammaPID.ElectronIDMediumPP)
TightElectronSelector = ConfiguredAsgElectronIsEMSelector(
"TightElectronSelector", egammaPID.ElectronIDTightPP)
# Likelihood
from ElectronPhotonSelectorTools.ConfiguredAsgElectronLikelihoodTools import ConfiguredAsgElectronLikelihoodTool
LooseLHSelector = ConfiguredAsgElectronLikelihoodTool("LooseLHSelector", LikeEnum.Loose)
LooseLHSelector.primaryVertexContainer="PrimaryVertices"
MediumLHSelector = ConfiguredAsgElectronLikelihoodTool("MediumLHSelector", LikeEnum.Medium)
MediumLHSelector.primaryVertexContainer="PrimaryVertices"
TightLHSelector = ConfiguredAsgElectronLikelihoodTool("TightLHSelector", LikeEnum.Tight)
TightLHSelector.primaryVertexContainer="PrimaryVertices"
LooseLHSelector = ConfiguredAsgElectronLikelihoodTool(
"LooseLHSelector", LikeEnum.Loose)
LooseLHSelector.primaryVertexContainer = "PrimaryVertices"
MediumLHSelector = ConfiguredAsgElectronLikelihoodTool(
"MediumLHSelector", LikeEnum.Medium)
MediumLHSelector.primaryVertexContainer = "PrimaryVertices"
TightLHSelector = ConfiguredAsgElectronLikelihoodTool(
"TightLHSelector", LikeEnum.Tight)
TightLHSelector.primaryVertexContainer = "PrimaryVertices"
# Multi Lepton
from ElectronPhotonSelectorTools.ElectronPhotonSelectorToolsConf import AsgElectronMultiLeptonSelector
MultiLeptonSelector=AsgElectronMultiLeptonSelector("MultiLeptonSelector")
MultiLeptonSelector = AsgElectronMultiLeptonSelector(
"MultiLeptonSelector")
except:
mlog.error("could not get configure tools")
traceback.print_exc()
return False
self.electronIsEMselectors = [LooseElectronSelector, MediumElectronSelector, TightElectronSelector]
self.electronIsEMselectors = [
LooseElectronSelector, MediumElectronSelector, TightElectronSelector]
self.electronIsEMselectorResultNames = ["Loose", "Medium", "Tight"]
self.electronLHselectors = [LooseLHSelector, MediumLHSelector, TightLHSelector]
self.electronLHselectorResultNames= ["LHLoose","LHMedium","LHTight"]