Commit 7c4f6bde authored by Bernardo Sotto-Maior Peralva's avatar Bernardo Sotto-Maior Peralva
Browse files

Merge branch 'jlieberm/athena-CaloRingsFwd'

parents e79374cd 72ae0b61
......@@ -103,6 +103,68 @@ def checkDoElectronIdentification():
else:
return False
def checkBuildForwardElectronCaloRings():
""" Return true if it can build CaloRings for Electrons. Raise if it was
expected to build electrons and it won't be possible. Return false if not
asked to build."""
if caloRingerFlags.buildForwardElectronCaloRings():
if not rec.doESD():
mlog.info("Turning off ringer algorithm forward electron reconstruction since not doing ESD.")
caloRingerFlags.buildForwardElectronCaloRings = False
return False
if not inputAvailable(ringer.inputForwardElectronType(), ringer.inputForwardElectronKey()):
if not jobproperties.egammaRecFlags.doEgammaCaloSeeded():
mlog.warning(("Requested to build ForwardElectronCaloRings but egamma"
" calo seeded is off. Deactivating ElectronCaloRings and electron selection.")
)
caloRingerFlags.buildFowardElectronCaloRings = False
caloRingerFlags.doForwardElectronIdentification = False
return False
else:
mlog.verbose(("Input not available in the file, but it is requested"
" to be reconstructed so it will be build during reconstruction."))
else:
if jobproperties.egammaRecFlags.doEgammaCaloSeeded():
mlog.verbose(("There already exists the egamma objects in file, but"
" they will be updated during reconstruction to new ones."))
else:
mlog.verbose(("Ringer will use the egamma objects available "
"in the file to build its patterns."))
return True
else:
mlog.verbose("It wasn't requested to build Forward Electron CaloRings.")
return False
def checkDoForwardElectronIdentification():
""" Return true if it can doElectronIdentification. Raise if it was
expected to build electrons and it won't be possible. Return false if not
asked to run electron identification."""
if caloRingerFlags.doForwardElectronIdentification():
if not caloRingerFlags.buildForwardElectronCaloRings():
if not ( inputAvailable(ringer.outputCaloRingsType(), ringer.outputForwardElectronCaloRingsKey()) or \
inputAvailable(ringer.outputCaloRingsType(), ringer.outputForwardElectronCaloAsymRingsKey()) ) or \
not ( inputAvailable(ringer.outputRingSetType(), ringer.outputForwardElectronRingSetsKey()) ):
mlog.warning(("Requested to do Forward Electron identification using "
"Ringer discrimination, but one or more of the Ringer needed "
"discrimination inputs are not available. We will request to "
"build ElectronCaloRings using default configuration."))
# In this case, the input file does not have CaloRings, we need to build them:
caloRingerFlags.buildForwardElectronCaloRings = True
if not checkBuildForwardElectronCaloRings():
mlog.error(("Couldn't add ElectronCaloRings reconstruction to "
"joboptions."))
raise RuntimeError("Can't add ForwardElectronCaloRings to reconstruction.")
else:
mlog.verbose("All ForwardElectron identification discrimination input "
"available in the file.")
else:
mlog.verbose(("It will be used the ForwardElectronCaloRings build within this "
"reconstruction to make the classification."))
return True
else:
return False
def checkBuildPhotonCaloRings():
""" Return true if it can build CaloRings for Photons. Raise if it was
expected to build electrons and it won't be possible. Return false if not
......@@ -208,6 +270,22 @@ def getCaloRingerInputReaderTools():
caloRingerFlags.doPhotonIdentification = False
treatException("Could not set up CaloRingerAlgorithm for Photons!")
try:
if checkBuildForwardElectronCaloRings() or checkDoForwardElectronIdentification():
from CaloRingerTools.CaloRingerInputReaderFactories \
import CaloRingerForwardElectronsReaderTool
inputReaders.append(CaloRingerForwardElectronsReaderTool())
mlog.verbose("Added Ringer Forward Electrons reader successfully.")
except Exception:
if caloRingerFlags.buildForwardElectronCaloRings():
mlog.error(("It won't be possible to build ElectronCaloRings!"
" Switching it off!"))
caloRingerFlags.buildForwardElectronCaloRings = False
if caloRingerFlags.doForwardElectronIdentification():
mlog.error(("It won't be possible to do Electron identification!"
" Switching it off!"))
caloRingerFlags.doForwardElectronIdentification = False
treatException("Could not set up Ringer Electrons reader!")
return inputReaders
def getCaloRingerOutputs(inputReaders,addCaloRingsContainers=True,
......@@ -258,7 +336,8 @@ def transformGaudiTo(inputList, typeList):
def transformGaudiToReaders(inputList):
"Transform GaudiHandle into a list of configurable input readers"
return transformGaudiTo(inputList, ['Ringer::CaloRingerElectronsReader',
'Ringer::CaloRingerPhotonsReader'])
'Ringer::CaloRingerPhotonsReader',
'Ringer::CaloRingerForwardElectronsReader'])
def transformGaudiToBuilders(inputList):
"Transform GaudiHandle into a list of configurable builders"
......@@ -437,7 +516,10 @@ class CaloRingerAlgorithmBuilder ( Configured ):
( inputAvailable(ringer.outputCaloRingsType(), ringer.outputPhotonCaloRingsKey()) or \
inputAvailable(ringer.outputCaloRingsType(), ringer.outputPhotonCaloAsymRingsKey()) ) or \
( inputAvailable(ringer.outputRingSetType(), ringer.outputPhotonRingSetsKey()) or \
inputAvailable(ringer.outputRingSetType(), ringer.outputPhotonAsymRingSetsKey()) ) ) ):
inputAvailable(ringer.outputRingSetType(), ringer.outputPhotonAsymRingSetsKey()) ) )
or ( caloRingerFlags.buildForwardElectronCaloRings() and \
( inputAvailable(ringer.outputCaloRingsType(), ringer.outputForwardElectronCaloRingsKey()) ) or \
( inputAvailable(ringer.outputRingSetType(), ringer.outputForwardElectronRingSetsKey()) ) ) ):
raise RuntimeError(("Already existing input will be overwriten and not set Ringer flag "
"ignoreExistingDataObject."))
......
......@@ -80,6 +80,25 @@ class doElectronIdentification(CaloRingerFlagsJobProperty):
StoredValue = False
jobproperties.CaloRingerFlags.add_JobProperty(doElectronIdentification)
class buildForwardElectronCaloRings(CaloRingerFlagsJobProperty):
""" switch for building the CaloRings for forward electron candidates
"""
statusOn = True
allowedTypes = ['bool']
StoredValue = False
jobproperties.CaloRingerFlags.add_JobProperty(buildForwardElectronCaloRings)
class doForwardElectronIdentification(CaloRingerFlagsJobProperty):
""" switch for electron particle identification (PID), that is, whether to
run or not Ringer selector for Electrons.
"""
statusOn = True
allowedTypes = ['bool']
StoredValue = False
jobproperties.CaloRingerFlags.add_JobProperty(doForwardElectronIdentification)
#=======================================================================
class buildPhotonCaloRings(CaloRingerFlagsJobProperty):
""" switch for building the CaloRings for electron candidates
......
......@@ -32,6 +32,8 @@ class CaloRingerKeysDict:
inputs = dict(
Electron = egammaKeysDict.outputs.get ( "Electron" ),
Photon = egammaKeysDict.outputs.get ( "Photon" ),
ForwardElectron = egammaKeysDict.outputs.get ( "FwdElectron" ),
)
# Define new outputs here:
......@@ -44,6 +46,8 @@ class CaloRingerKeysDict:
[outputRingSetType(), 'PhotonAsymRingSets', ''],
[outputCaloRingsType(), 'PhotonCaloRings', ''],
[outputCaloRingsType(), 'PhotonCaloAsymRings', ''],
[outputRingSetType(), 'ForwardElectronRingSets', ''],
[outputCaloRingsType(), 'ForwardElectronCaloRings', ''],
]
# This will keep dict key equal to Container key:
......@@ -55,6 +59,7 @@ class CaloRingerKeysDict:
_outputMetaData_values = [
[outputRingSetConfType(), 'ElectronRingSetsConf' , ''],
[outputRingSetConfType(), 'PhotonRingSetsConf' , ''],
[outputRingSetConfType(), 'ForwardElectronRingSetsConf' , ''],
]
# This will keep dict key equal to Container key:
......
......@@ -85,6 +85,11 @@ class CaloRingerMetaDataBuilder ( Configured ):
electronMetaAvailable = metaDataInputAvailable(ringer.outputRingSetConfType(), ringer.outputElectronRingSetsConfKey())
if electronMetaAvailable:
self._overwriting = True
if any(['ForwardElectron' in builderName for builderName in builderNames]):
outputList.append(ringer.outputForwardElectronRingSetsConfKey())
forwardElectronMetaAvailable = metaDataInputAvailable(ringer.outputRingSetConfType(), ringer.outputForwardElectronRingSetsConfKey())
if forwardElectronMetaAvailable:
self._overwriting = True
if any(['Photon' in builderName for builderName in builderNames]):
outputList.append(ringer.outputPhotonRingSetsConfKey())
photonMetaAvailable = metaDataInputAvailable(ringer.outputRingSetConfType(), ringer.outputPhotonRingSetsConfKey())
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
// $Id: ICaloRingerPhotonsReader.h 667886 2015-05-18 17:26:59Z wsfreund $
#ifndef CALORINGERTOOLS_ICALORINGERFORWARDELECTRONSREADER
#define CALORINGERTOOLS_ICALORINGERFORWARDELECTRONSREADER
/**
@class ICaloRingerForwardElectronsReader
@brief Interface for tool CaloRingerForwardReader
@author Werner S. Freund <wsfreund@cern.ch>
@author Juan L. Marin <juan.lieber.marin@cern.ch>
$Revision: 667886 $
$$$
*/
// Core Include
#include "GaudiKernel/IAlgTool.h"
// Interface Includes:
#include "ICaloRingerInputReader.h"
namespace Ringer {
static const InterfaceID IID_ICaloRingerForwardElectronsReader("ICaloRingerForwardElectronsReader", 1, 0);
class ICaloRingerForwardElectronsReader : virtual public ICaloRingerInputReader
{
public:
/** @brief Virtual destructor*/
virtual ~ICaloRingerForwardElectronsReader() {};
/** @brief AlgTool interface methods */
static const InterfaceID& interfaceID();
/** @brief initialize method*/
virtual StatusCode initialize() = 0;
/** @brief execute method **/
virtual StatusCode execute() = 0;
/** @brief finalize method*/
virtual StatusCode finalize() = 0;
};
inline const InterfaceID& ICaloRingerForwardElectronsReader::interfaceID()
{
return IID_ICaloRingerForwardElectronsReader;
}
} // namespace Ringer
#endif
......@@ -102,6 +102,24 @@ class ConfigurePhotonCaloRings( ConfigureEgammaCaloRings ):
from AthenaCommon.SystemOfUnits import GeV
crBuilder.MinPartEnergy = minEnergy * GeV
class ConfigureForwardElectronCaloRings( ConfigureEgammaCaloRings ):
"""
Configure the ForwardElectronCaloRingsBuilder default values
"""
def __init__(self):
ConfigureEgammaCaloRings.__init__(self)
self.CaloRingsContainerName = CaloRingerKeys.outputForwardElectronCaloRingsKey()
self.RingSetContainerName = CaloRingerKeys.outputForwardElectronRingSetsKey()
def __call__( self, crBuilder):
ConfigureEgammaCaloRings.__call__( self, crBuilder )
# from CaloRingerAlgs.CaloRingerFlags import caloRingerFlags
# minEnergy = caloRingerFlags.minPhotonEnergy()
# if minEnergy is not None:
# from AthenaCommon.SystemOfUnits import GeV
# crBuilder.MinPartEnergy = minEnergy * GeV
ElectronCaloRingsBuilder = PublicToolFactory(CaloRingerToolsConf.Ringer__CaloRingsBuilder,
name = "ElectronCaloRingsBuilder",
postInit = [ConfigureElectronCaloRings().__call__])
......@@ -119,3 +137,7 @@ PhotonCaloAsymRingsBuilder = PublicToolFactory(CaloRingerToolsConf.Ringer__CaloA
name = "PhotonCaloAsymRingsBuilder",
postInit = [ConfigurePhotonCaloRings().__call__
, AsymRings(doEtaAxesDivision = True, doPhiAxesDivision = True).__call__])
ForwardElectronCaloRingsBuilder = PublicToolFactory(CaloRingerToolsConf.Ringer__CaloRingsBuilder,
name = "ForwardElectronCaloRingsBuilder",
postInit = [ConfigureForwardElectronCaloRings().__call__])
......@@ -32,6 +32,16 @@ def getPhotonCaloRingsBuilder():
else:
return PublicToolHandle('')
def getForwardElectronCaloRingsBuilder():
"Return the forward electrons CaloRings builder "
if caloRingerFlags.buildForwardElectronCaloRings():
from CaloRingerTools.CaloRingerBuilderFactories import ForwardElectronCaloRingsBuilder
#to do: implement asym?
return ForwardElectronCaloRingsBuilder()
else:
return PublicToolHandle('')
def getCaloRingerElectronSelectorsBuilder():
"Return the Electron Selectors"
if caloRingerFlags.doElectronIdentification():
......@@ -40,6 +50,16 @@ def getCaloRingerElectronSelectorsBuilder():
else:
return PublicToolHandleArray([])
def getCaloRingerForwardElectronSelectorsBuilder():
# "Return the Electron Selectors"
# if caloRingerFlags.doElectronIdentification():
# from CaloRingerTools.CaloRingerSelectorsBuilders import CaloRingerElectronSelectorsBuilder
# return CaloRingerElectronSelectorsBuilder().getAllSelectorHandles()
# else:
return PublicToolHandleArray([])
def getCaloRingerPhotonSelectorsBuilder():
"Return the Photon Selectors"
#if caloRingerFlags.doPhotonIdentification:
......@@ -68,7 +88,16 @@ CaloRingerPhotonsReaderTool = PublicToolFactory(CaloRingerToolsConf.Ringer__Calo
PhotonSelectors = FcnWrapper(getCaloRingerPhotonSelectorsBuilder),
#selectorsAvailable = FcnWrapper(checkDoPhotonIdentification)
)
from CaloRingerAlgs.CaloRingerAlgorithmBuilder import checkBuildForwardElectronCaloRings
CaloRingerForwardElectronsReaderTool = PublicToolFactory(CaloRingerToolsConf.Ringer__CaloRingerForwardElectronsReader, #unsolved, prepare C++ code?
name = "CaloRingerForwardElectronsReaderTool",
inputKey = CaloRingerKeys.inputForwardElectronKey(),
crBuilder = FcnWrapper(getForwardElectronCaloRingsBuilder),
builderAvailable = FcnWrapper(checkBuildForwardElectronCaloRings),
ForwardElectronSelectors = FcnWrapper(getCaloRingerForwardElectronSelectorsBuilder),
# selectorsAvailable = FcnWrapper(checkDoForwardElectronIdentification),
)
# Noise retrievers build rings on random calorimeter positions to simulate
# noise conditions affecting the CaloRings. Their instatiations have the shape
# used to build the rings for the original particles
......
/*
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/
// $Id: CaloRingerForwardElectronsReader.cxx 752568 2016-06-03 16:03:21Z ssnyder $
// =============================================================================
#include "CaloRingerForwardElectronsReader.h"
#include "StoreGate/ReadHandle.h"
#include <algorithm>
namespace Ringer {
// =============================================================================
CaloRingerForwardElectronsReader::CaloRingerForwardElectronsReader(const std::string& type,
const std::string& name,
const ::IInterface* parent)
: CaloRingerInputReader(type, name, parent),
m_clRingsBuilderForwardElectronFctor(0)
//m_selectorAvailable(false)
{
// declare interface
declareInterface<ICaloRingerForwardElectronsReader>(this);
}
// =============================================================================
CaloRingerForwardElectronsReader::~CaloRingerForwardElectronsReader()
{
if(m_clRingsBuilderForwardElectronFctor) delete m_clRingsBuilderForwardElectronFctor;
}
// =============================================================================
StatusCode CaloRingerForwardElectronsReader::initialize()
{
ATH_CHECK( CaloRingerInputReader::initialize() );
ATH_CHECK(m_inputElectronContainerFwdKey.initialize());
if ( m_builderAvailable ) {
// Initialize our fctor
m_clRingsBuilderForwardElectronFctor =
new BuildCaloRingsFctor<xAOD::ElectronContainer>(
m_inputElectronContainerFwdKey.key(),
m_crBuilder,
msg(),
this);
ATH_CHECK( m_clRingsBuilderForwardElectronFctor->initialize() );
}
return StatusCode::SUCCESS;
}
// =============================================================================
StatusCode CaloRingerForwardElectronsReader::finalize()
{
return StatusCode::SUCCESS;
}
// =============================================================================
StatusCode CaloRingerForwardElectronsReader::execute()
{
ATH_MSG_DEBUG("Entering " << name() << " execute.");
// Retrieve photons
SG::ReadHandle<xAOD::ElectronContainer> electronsfwd(m_inputElectronContainerFwdKey);
// check is only used for serial running; remove when MT scheduler used
if(!electronsfwd.isValid()) {
ATH_MSG_FATAL("Failed to retrieve "<< m_inputElectronContainerFwdKey.key());
return StatusCode::FAILURE;
}
if ( m_builderAvailable ) {
ATH_CHECK( m_clRingsBuilderForwardElectronFctor->prepareToLoopFor(electronsfwd->size()) );
// loop over our particles:
for ( const auto electronfwd : *electronsfwd ){
m_clRingsBuilderForwardElectronFctor->operator()( electronfwd );
}
}
return StatusCode::SUCCESS;
}
} // namespace Ringer
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
// $Id: CaloRingerPhotonsReader.h 752568 2016-06-03 16:03:21Z ssnyder $
#ifndef CALORINGERTOOLS_CALORINGERFORWARDELECTRONSREADER_H
#define CALORINGERTOOLS_CALORINGERFORWARDELECTRONSREADER_H
// STL includes:
#include <string>
// Base includes:
#include "CaloRingerInputReader.h"
#include "CaloRingerTools/ICaloRingerForwardElectronsReader.h"
#include "CaloRingerReaderUtils.h"
// xAOD includes:
#include "xAODEgamma/ElectronContainerFwd.h"
#include "xAODEgamma/Electron.h"
#include "xAODEgamma/ElectronContainer.h"
// Asg selectors include:
#include "RingerSelectorTools/IAsgElectronRingerSelector.h"
#include "StoreGate/ReadHandleKey.h"
namespace Ringer {
class CaloRingerForwardElectronsReader : public CaloRingerInputReader,
public ICaloRingerForwardElectronsReader
{
public:
/// @name CaloRingerForwardElectronsReader ctors and dtors:
/// @{
/**
* @brief Default constructor
**/
CaloRingerForwardElectronsReader(const std::string& type,
const std::string& name,
const ::IInterface* parent);
/**
* @brief Destructor
**/
~CaloRingerForwardElectronsReader();
/// @}
/// Tool main methods:
/// @{
/**
* @brief initialize method
**/
virtual StatusCode initialize() override;
/**
* @brief read electrons and populates @name decoMap with them and their
* respective CaloRings.
**/
virtual StatusCode execute() override;
/**
* @brief finalize method
**/
virtual StatusCode finalize() override;
/// @}
private:
/// Tool CaloRingerElectronsReader props (python configurables):
/// @{
/**
* @brief Electron selectors.
* TODO Change it to Forward Electrons Selector
**/
PublicToolHandleArray<IAsgElectronRingerSelector> m_ringerSelectors {this,
"ForwardElectronSelectors", {}, "The ASG Forward Electron Selectors."};
/**
* @brief Hold selectors result names.
**/
Gaudi::Property<std::vector<std::string> > m_ringerSelectorResultNames {this,
"ResultNames", {}, "The ASG Selectors result names."};
/** @brief forward electron collection input name*/
SG::ReadHandleKey<xAOD::ElectronContainer> m_inputElectronContainerFwdKey {this,
"inputKey",
"ElectronFwd",
"Name of the input electron forward container"};
/// @}
/// Tool CaloRingerForwardsReader props (non configurables):
/// @{
/// The CaloRings Builder functor:
BuildCaloRingsFctor<xAOD::ElectronContainer> *m_clRingsBuilderForwardElectronFctor;
/// Whether selectors are available
//bool m_selectorAvailable;
/// @}
};
}
#endif
......@@ -3,6 +3,8 @@
#include "../CaloRingerInputReader.h"
#include "../CaloRingerElectronsReader.h"
#include "../CaloRingerPhotonsReader.h"
#include "../CaloRingerForwardElectronsReader.h"
using namespace Ringer;
......@@ -11,4 +13,4 @@ DECLARE_COMPONENT( CaloAsymRingsBuilder )
DECLARE_COMPONENT( CaloRingerInputReader )
DECLARE_COMPONENT( CaloRingerElectronsReader )
DECLARE_COMPONENT( CaloRingerPhotonsReader )
DECLARE_COMPONENT( CaloRingerForwardElectronsReader )
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment