Ejemplo n.º 1
0
def checkDoElectronIdentification():
    """ 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.doElectronIdentification():
        if not caloRingerFlags.buildElectronCaloRings():
            if not ( inputAvailable(outputCaloRingsType(), outputElectronCaloRingsKey())       or \
                     inputAvailable(outputCaloRingsType(), outputElectronCaloAsymRingsKey()) ) or \
               not ( inputAvailable(outputRingSetType(),   outputElectronRingSetsKey())        or \
                     inputAvailable(outputRingSetType(),   outputElectronAsymRingSetsKey()) ):

                mlog.warning((
                    "Requested to do 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.buildElectronCaloRings = True
                if not checkBuildElectronCaloRings():
                    mlog.error(
                        ("Couldn't add ElectronCaloRings reconstruction to "
                         "joboptions."))
                    raise RuntimeError(
                        "Can't add ElectronCaloRings to reconstruction.")
            else:
                mlog.verbose(
                    "All Electron identification discrimination input "
                    "available in the file.")
        else:
            mlog.verbose(
                ("It will be used the ElectronCaloRings build within this "
                 "reconstruction to make the classification."))
        return True
    else:
        return False
Ejemplo n.º 2
0
def getElectronCaloRingsBuilder():
    "Return the electrons CaloRings builder "
    if caloRingerFlags.buildElectronCaloRings():
        from CaloRingerTools.CaloRingerBuilderFactories import ElectronCaloRingsBuilder, \
                                                               ElectronCaloAsymRingsBuilder
        if caloRingerFlags.useAsymBuilder():
            return ElectronCaloAsymRingsBuilder()
        else:
            return ElectronCaloRingsBuilder()
    else:
        return PublicToolHandle('')
Ejemplo n.º 3
0
def getCaloRingerInputReaderTools():
    """ Returns a list with the CaloRinger tools to get the input objects to be
  decorated and pass them to their CaloRingerTools"""

    inputReaders = []

    try:
        if checkBuildElectronCaloRings() or checkDoElectronIdentification():
            from CaloRingerTools.CaloRingerInputReaderFactories \
                import CaloRingerElectronsReaderTool
            inputReaders.append(CaloRingerElectronsReaderTool())
            mlog.verbose("Added Ringer Electrons reader successfully.")
    except Exception:
        if caloRingerFlags.buildElectronCaloRings():
            mlog.error(("It won't be possible to build ElectronCaloRings!"
                        " Switching it off!"))
            caloRingerFlags.buildElectronCaloRings = False
        if caloRingerFlags.doElectronIdentification():
            mlog.error(("It won't be possible to do Electron identification!"
                        " Switching it off!"))
            caloRingerFlags.doElectronIdentification = False
        treatException("Could not set up Ringer Electrons reader!")

    try:
        if checkBuildPhotonCaloRings() or checkDoPhotonIdentification():
            from CaloRingerTools.CaloRingerInputReaderFactories \
                import CaloRingerPhotonsReaderTool
            inputReaders.append(CaloRingerPhotonsReaderTool())
            mlog.verbose("Added Ringer Photon reader successfully.")
    except Exception:
        if caloRingerFlags.buildPhotonCaloRings():
            mlog.error(("It won't be possible to build PhotonCaloRings!"
                        " Switching it off!"))
            caloRingerFlags.buildPhotonCaloRings = False
        if caloRingerFlags.doPhotonIdentification():
            mlog.error(
                ("It won't be possible to build do Photon identification!"
                 " Switching it off!"))
            caloRingerFlags.doPhotonIdentification = False
        treatException("Could not set up CaloRingerAlgorithm for Photons!")

    return inputReaders
Ejemplo n.º 4
0
def checkBuildElectronCaloRings():
    """ 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.buildElectronCaloRings():
        if not rec.doESD():
            mlog.info(
                "Turning off ringer algorithm electron reconstruction since not doing ESD."
            )
            caloRingerFlags.buildElectronCaloRings = False
            return False
        if not inputAvailable(inputElectronType(), inputElectronKey()):
            if not jobproperties.egammaRecFlags.doEgammaCaloSeeded():
                mlog.warning((
                    "Requested to build ElectronCaloRings but egamma"
                    " calo seeded is off. Deactivating ElectronCaloRings and electron selection."
                ))
                caloRingerFlags.buildElectronCaloRings = False
                caloRingerFlags.doElectronIdentification = 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 Electron CaloRings.")
        return False
Ejemplo n.º 5
0
def checkBuildElectronCaloRings():
    """ 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.buildElectronCaloRings():
        if not inputAvailable(inputElectronType(), inputElectronKey()):

            # Try to force egammaBuilder startup if it is not already started:
            if not egammaBuilderAvailable():
                mlog.warning((
                    "Requested to build ElectronCaloRings but egamma"
                    " builder was not available. Deactivating ElectronCaloRings and electron selection."
                ))
                #if rec.doEgamma():
                #__enableEgamma()
                #else
                caloRingerFlags.buildElectronCaloRings = False
                caloRingerFlags.doElectronIdentification = 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 egammaBuilderAvailable():
                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 Electron CaloRings.")
        return False
Ejemplo n.º 6
0
from AthenaCommon.Logging import logging

from CaloRingerAlgs.CaloRingerFlags import caloRingerFlags
from CaloRingerAlgs.CaloRingerAlgorithmBuilder import CaloRingerAlgorithmBuilder

mlog = logging.getLogger('CaloRinger_joboptions.py')
mlog.info('Entering')

ringerOutputLevel = caloRingerFlags.OutputLevel()

# Check if we have our other algorithm dependencies enabled, otherwise disable
# ringer:
if caloRingerFlags.buildCaloRingsOn():
    # Check egamma related objects:
    if not rec.doEgamma():
        if caloRingerFlags.buildElectronCaloRings():
            caloRingerFlags.buildElectronCaloRings.set_Value(False)
            caloRingerFlags.doElectronIdentification.set_Value(False)
            if not caloRingerFlags.buildElectronCaloRings():
                mlog.info(
                    'No egamma builder available... disabling ElectronCaloRings reconstruction and electron selection.'
                )
        if caloRingerFlags.buildPhotonCaloRings():
            caloRingerFlags.buildPhotonCaloRings.set_Value(False)
            #caloRingerFlags.doPhotonIdentification.set_Value( False )
            if not caloRingerFlags.buildPhotonCaloRings():
                mlog.info(
                    'No egamma builder available... disabling PhotonCaloRings reconstruction and electron selection.'
                )

# To build CaloRings it is required to have doESD flag set to on.
Ejemplo n.º 7
0
    def configure(self):
        "This method will be called when object is initialized"

        mlog = logging.getLogger( 'CaloRingerAlgorithmBuilder::configure:%s:' \
            % self.__class__.__name__.replace( ".", '_' )  )
        mlog.info('entering')
        try:

            # Instantiate the main algorithm:
            MainCaloRingerAlgorithm = AlgFactory(
                CaloRingerAlgsConf.Ringer__CaloRingerAlgorithm,
                name="MainCaloRingerAlgorithm",
                inputReaderTools=FcnWrapper(getCaloRingerInputReaderTools))

            self._caloRingerAlg = MainCaloRingerAlgorithm()

            if caloRingerFlags.buildCaloRingsOn():
                # Egamma locker not being used anymore.
                #postponeEgammaLock(self._caloRingerAlg)
                pass

            # Check if CaloRingerAlgorithm has readers:
            if not self._caloRingerAlg.inputReaderTools:
                raise RuntimeError(("Cannot instantiate CaloRingerAlgorithm "
                                    "without readers."))

            if caloRingerFlags.buildCaloRingsOn():
                self._eventOutputs = { outputCaloRingsType() : \
            getCaloRingerOutputs(self._caloRingerAlg.inputReaderTools,addRingSetsContainers=False), \
                                       outputRingSetType() : \
            getCaloRingerOutputs(self._caloRingerAlg.inputReaderTools,addCaloRingsContainers=False) \
                                     }
                self._output.update(self._eventOutputs)

            # Check for existing output:
            self.checkExistingOutput()

            if not self.ignoreExistingDataObject()                                                     \
               and ( (  caloRingerFlags.buildElectronCaloRings()                                   and \
                  ( inputAvailable(outputCaloRingsType(), outputElectronCaloRingsKey())            or  \
                         inputAvailable(outputCaloRingsType(), outputElectronCaloAsymRingsKey()) ) or  \
                  ( inputAvailable(outputRingSetType(),   outputElectronRingSetsKey())             or  \
                         inputAvailable(outputRingSetType(), outputElectronAsymRingSetsKey()) ) )      \
               or  ( caloRingerFlags.buildPhotonCaloRings()                                        and \
                  ( inputAvailable(outputCaloRingsType(), outputPhotonCaloRingsKey())              or  \
                         inputAvailable(outputCaloRingsType(), outputPhotonCaloAsymRingsKey()) )   or  \
                  ( inputAvailable(outputRingSetType(),   outputPhotonRingSetsKey())               or  \
                         inputAvailable(outputRingSetType(), outputPhotonAsymRingSetsKey()) ) ) ):
                raise RuntimeError((
                    "Already existing input will be overwriten and not set Ringer flag "
                    "ignoreExistingDataObject."))

        except Exception:
            removeFromTopSequence(self._caloRingerAlg)
            caloRingerFlags.Enabled = False
            self._disabled = True
            treatException(("Could not get handle to CaloRingerAlgorithm."
                            " Reason:\n%s") % traceback.format_exc())
            return False

        return True
Ejemplo n.º 8
0
if rec.doESD() and caloRingerFlags.buildCaloRingsOn() and CRAlgBuilder.usable(
):
    LastCRWriter = CRMetaDataBuilder.getLastWriterHandle()
    CRMainAlg = CRAlgBuilder.getCaloRingerAlgHandle()
    CRMetaDataWriterAlg = CRMetaDataBuilder.getMetaDataWriterHandle()
    try:
        # FIXME: It seems that the python implementation takes a lot of memory
        # (https://its.cern.ch/jira/browse/ATLASRECTS-2769?filter=-1),
        # replace it as egamma is doing to use a C++ implementation
        pass
        # Make sure we add it before streams:
        for pos, alg in enumerate(topSequence):
            if LastCRWriter.getName() == alg.getName():
                from CaloRingerAlgs.CaloRingerLocker import CaloRingerLocker
                CRLocker = CaloRingerLocker(name = "CaloRingerLocker", \
                        doElectron = caloRingerFlags.buildElectronCaloRings(), \
                        doPhoton = caloRingerFlags.buildPhotonCaloRings(), \
                        EvtStoreName = CRMainAlg.EvtStore.getName(), \
                        MetaDataStoreName = CRMetaDataWriterAlg.MetaDataStore.getName(), \
                        CaloRingerDict = CRAlgBuilder.eventOutputs(), \
                        CaloRingerMetaDict = CRMetaDataBuilder.metaDataOutputs() \
                        )
                topSequence.insert(pos + 1, CRLocker)
                mlog.verbose(
                    "Successfully added CaloRingerLocker to TopSequence.")
                break
        else:
            treatException("Could not find CaloRingerDecorator algorithm.")
    except Exception, e:
        treatException(
            "Could not set up CaloRingerLocker. Switched off ! Reason:\n %s" %