예제 #1
0
from __future__ import print_function

from AthenaCommon.AlgSequence import AlgSequence
topSequence = AlgSequence()

from AthenaCommon.AlgSequence import AthSequencer
condSequence = AthSequencer("AthCondSeq")
tileCheckDCS = hasattr(condSequence, 'TileDCSCondAlg')

from AthenaCommon.AppMgr import ServiceMgr as svcMgr

from AthenaCommon import CfgMgr

from TileRecUtils.TileDQstatusAlgDefault import TileDQstatusAlgDefault
TileDQstatusAlgDefault()

topSequence += CfgMgr.AthenaMonManager(name='ManagedAthenaTileMon',
                                       FileKey='SHIFT',
                                       ManualDataTypeSetup=True,
                                       DataType='cosmics',
                                       Environment='online',
                                       ManualRunLBSetup=True,
                                       Run=RunNumber,
                                       LumiBlock=1)

ManagedAthenaTileMon = topSequence.ManagedAthenaTileMon

TileDQFragMon = CfgMgr.TileDQFragMonTool(
    name='TileDQFragMon',
    OutputLevel=INFO,
예제 #2
0
    theTileDigitsToNtuple = TileDigitsToNtuple()
    topSequence += theTileDigitsToNtuple
    theTileDigitsToNtuple.TileDigitsContainer = 'TileDigitsCnt'
    theTileDigitsToNtuple.NTupleLoc = '/NTUP'

if doRawChannelNtuple:
    #--- Create TileCal h70 ntuple with all raw channels ---------
    from TileRec.TileRecConf import TileRawChannelToNtuple
    theTileRawChannelToNtuple = TileRawChannelToNtuple()
    topSequence += theTileRawChannelToNtuple
    theTileRawChannelToNtuple.TileRawChannelContainer = 'TileRawChannelFit'
    theTileRawChannelToNtuple.NTupleLoc = '/NTUP'

from TileRecUtils.TileDQstatusAlgDefault import TileDQstatusAlgDefault

dqStatus = TileDQstatusAlgDefault()

if doTileNtuple:
    doSim = True
    if TileTB:
        #--- Create TileCal h1000 ntuple with RawChannels ---------
        topSequence += CfgMgr.TileTBAANtuple(
            TBperiod=2003,
            NSamples=7,
            BSInput=False,
            CompleteNtuple=False,
            UnpackAdder=False,
            TileRawChannelContainerFlat="",
            TileRawChannelContainerOpt="TileRawChannelCnt",
            TileRawChannelContainerFit="TileRawChannelFit",
            TileBeamElemContainer="",
예제 #3
0
    def configure(self):
        from AthenaCommon.Logging import logging
        mlog = logging.getLogger('CaloCellGetter_DigiHSTruth::configure:')
        mlog.info('entering')

        doStandardCellReconstruction = True
        from CaloRec.CaloCellFlags import jobproperties

        # get handle to upstream object
        # handle tile

        if doStandardCellReconstruction:
            from LArROD.LArRODFlags import larRODFlags

        # now configure the algorithm, part of this could be done in a separate class
        # cannot have same name
        try:
            from CaloRec.CaloRecConf import CaloCellMaker
        except Exception:
            mlog.error("could not import CaloRec.CaloCellMaker")
            print(traceback.format_exc())
            return False

        theCaloCellMaker = CaloCellMaker("CaloCellMaker_DigiHSTruth")
        self._CaloCellMakerHandle = theCaloCellMaker

        from AthenaCommon.AppMgr import ToolSvc

        if doStandardCellReconstruction:
            # configure CaloCellMaker here
            # check LArCellMakerTool_jobOptions.py for full configurability
            # FIXME

            if rec.doLArg():
                from LArCabling.LArCablingAccess import LArOnOffIdMapping
                LArOnOffIdMapping()

                try:
                    from LArCellRec.LArCellRecConf import LArCellBuilderFromLArRawChannelTool
                    theLArCellBuilder = LArCellBuilderFromLArRawChannelTool(
                        "LArCellBuilder_DigiHSTruth")
                    theLArCellBuilder.RawChannelsName = "LArRawChannels_DigiHSTruth"
                except Exception:
                    mlog.error(
                        "could not get handle to LArCellBuilderFromLArRawChannel Quit"
                    )
                    print(traceback.format_exc())
                    return False

                if jobproperties.CaloCellFlags.doLArCreateMissingCells():
                    theLArCellBuilder.addDeadOTX = True

                # add the tool to list of tool ( should use ToolHandle eventually)
                theCaloCellMaker += theLArCellBuilder
                theCaloCellMaker.CaloCellMakerToolNames += [theLArCellBuilder]

            if rec.doTile():
                try:
                    from TileRecUtils.TileRecUtilsConf import TileCellBuilder
                    theTileCellBuilder = TileCellBuilder(
                        "TileCellBuilder_DigiHSTruth")
                    theTileCellBuilder.TileRawChannelContainer = "TileRawChannelCnt_DigiHSTruth"
                    theTileCellBuilder.E4prContainer = "E4prContainer2_DigiHSTruth"
                    theTileCellBuilder.MBTSContainer = "MBTSContainer2_DigiHSTruth"
                    theTileCellBuilder.TileDSPRawChannelContainer = "TileRawChannelCnt_DigiHSTruth"

                    theCaloCellMaker += theTileCellBuilder
                    theCaloCellMaker.CaloCellMakerToolNames += [
                        theTileCellBuilder
                    ]
                except Exception:
                    mlog.error("could not get handle to TileCellBuilder Quit")
                    print(traceback.format_exc())
                    return False

        #
        # CaloCellContainerFinalizerTool : closing container and setting up iterators
        #

        from CaloRec.CaloRecConf import CaloCellContainerFinalizerTool
        theCaloCellContainerFinalizerTool = CaloCellContainerFinalizerTool(
            "CaloCellContainerFinalizerTool_DigiHSTruth")
        theCaloCellMaker += theCaloCellContainerFinalizerTool
        theCaloCellMaker.CaloCellMakerToolNames += [
            theCaloCellContainerFinalizerTool
        ]

        #
        # Mergeing of calo cellcontainer with sparse raw channel container with improved energies
        #

        doLArMerge = False
        if doLArMerge:
            try:
                from LArCellRec.LArCellRecConf import LArCellMerger
                theLArCellMerger = LArCellMerger()
            except Exception:
                mlog.error("could not get handle to LArCellMerge Quit")
                print(traceback.format_exc())
                return False
            theLArCellMerger.RawChannelsName = larRODFlags.RawChannelFromDigitsContainerName(
            )
            theCaloCellMaker += theLArCellMerger
            theCaloCellMaker.CaloCellMakerToolNames += [theLArCellMerger]

        #
        # masking of noisy and sporadic noisy cells in LAr
        #

        doNoiseMask = False
        if jobproperties.CaloCellFlags.doLArNoiseMasking.statusOn and jobproperties.CaloCellFlags.doLArNoiseMasking(
        ):
            doNoiseMask = True
        doSporadicMask = False
        if jobproperties.CaloCellFlags.doLArSporadicMasking.statusOn and jobproperties.CaloCellFlags.doLArSporadicMasking(
        ):
            doSporadicMask = True

        if doNoiseMask or doSporadicMask:
            try:
                from LArCellRec.LArCellRecConf import LArCellNoiseMaskingTool
                theLArCellNoiseMaskingTool = LArCellNoiseMaskingTool()
            except Exception:
                mlog.error(
                    "could not get handle to LArCellNoiseMaskingTool Quit")
                print(traceback.format_exc())
                return False

            if doSporadicMask:
                try:
                    from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelMasker
                    theLArSporadicNoiseMasker = LArBadChannelMasker(
                        "LArSporadicNoiseMasker")
                except Exception:
                    mlog.error("could not access bad channel tool Quit")
                    print(traceback.format_exc())
                    return False
                theLArSporadicNoiseMasker.DoMasking = True
                theLArSporadicNoiseMasker.ProblemsToMask = [
                    "sporadicBurstNoise"
                ]
                ToolSvc += theLArSporadicNoiseMasker
                theLArCellNoiseMaskingTool.MaskingSporadicTool = theLArSporadicNoiseMasker

            if doNoiseMask:
                try:
                    from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelMasker
                    theLArNoiseMasker = LArBadChannelMasker("LArNoiseMasker")
                except Exception:
                    mlog.error("could not access bad channel tool Quit")
                    print(traceback.format_exc())
                    return False
                theLArNoiseMasker.DoMasking = True
                theLArNoiseMasker.ProblemsToMask = [
                    "highNoiseHG", "highNoiseMG", "highNoiseLG", "deadReadout",
                    "deadPhys"
                ]
                ToolSvc += theLArNoiseMasker
                theLArCellNoiseMaskingTool.MaskingTool = theLArNoiseMasker

            theLArCellNoiseMaskingTool.maskNoise = doNoiseMask
            theLArCellNoiseMaskingTool.maskSporadic = doSporadicMask
            # quality cut for sporadic noise masking
            theLArCellNoiseMaskingTool.qualityCut = 4000
            theCaloCellMaker += theLArCellNoiseMaskingTool
            theCaloCellMaker.CaloCellMakerToolNames += [
                theLArCellNoiseMaskingTool
            ]

        #
        #  masking of Feb problems
        #
        doBadFebMasking = False
        if doBadFebMasking:
            try:
                from LArCellRec.LArCellRecConf import LArBadFebMaskingTool
                theLArBadFebMaskingTool = LArBadFebMaskingTool()
                if (
                        rec.doExpressProcessing()
                        or athenaCommonFlags.isOnline()
                ):  # In online or express processing, EventInfo::LArError is triggered if >=4 FEB with data corrupted
                    theLArBadFebMaskingTool.minFebInError = 4
            except Exception:
                mlog.error("could not get handle to LArBadFebMaskingTool Quit")
                print(traceback.format_exc())
                return False
            theCaloCellMaker += theLArBadFebMaskingTool

            theCaloCellMaker.CaloCellMakerToolNames += [
                theLArBadFebMaskingTool
            ]

        #
        #  emulate gain pathologies on MC
        #
        doGainPathology = False
        if jobproperties.CaloCellFlags.doLArCellGainPathology.statusOn and jobproperties.CaloCellFlags.doLArCellGainPathology(
        ):
            if globalflags.DataSource() == 'geant4':
                doGainPathology = True

        if doGainPathology:
            try:
                from LArCellRec.LArCellRecConf import LArCellGainPathology
                theLArCellGainPathology = LArCellGainPathology()
            except Exception:
                mlog.error("could not get handle to LArCellGainPatholog< Quit")
                print(traceback.format_exc())
                return False
            theCaloCellMaker += theLArCellGainPathology

            theCaloCellMaker.CaloCellMakerToolNames += [
                theLArCellGainPathology
            ]

        # lar miscalibration if MC only  (should be done after finalisation)

        if not jobproperties.CaloCellFlags.doLArCellEmMisCalib.statusOn:
            # the flag has not been set, so decide a reasonable default
            # this is the old global flags should use the new one as
            # soon as monitoring does
            doLArCellEmMisCalib = True
            mlog.info(
                "jobproperties.CaloCellFlags.doLArMisCalib not set and Monte Carlo: apply LArCellEmMisCalibTool"
            )
        else:
            doLArCellEmMisCalib = jobproperties.CaloCellFlags.doLArCellEmMisCalib(
            )
            if doLArCellEmMisCalib:
                mlog.info("LArCellEmMisCalibTool requested")
            else:
                mlog.info("LArCellEmMisCalibTool explicitly not requested")

        if doLArCellEmMisCalib:
            try:
                from LArCellRec.LArCellRecConf import LArCellEmMiscalib
                theLArCellEmMiscalib = LArCellEmMiscalib("LArCellEmMiscalib")
            except Exception:
                mlog.error("could not get handle to LArCellEmMisCalib Quit")
                print(traceback.format_exc())
                return False

            # examples on how to change miscalibration. Default values are 0.005 and 0.007
            #        theLArCellEmMiscalib.SigmaPerRegion = 0.005
            #        theLArCellEmMiscalib.SigmaPerCell = 0.005

            ToolSvc += theLArCellEmMiscalib

            try:
                from CaloRec.CaloRecConf import CaloCellContainerCorrectorTool
                from CaloIdentifier import SUBCALO
                theMisCalibTool = CaloCellContainerCorrectorTool(
                    "MisCalibTool",
                    CaloNums=[SUBCALO.LAREM],
                    CellCorrectionToolNames=[theLArCellEmMiscalib])
            except Exception:
                mlog.error("could not get handle to MisCalibTool Quit")
                print(traceback.format_exc())
                return False

            theCaloCellMaker += theMisCalibTool
            theCaloCellMaker.CaloCellMakerToolNames += [theMisCalibTool]

        #
        # Pedestal shift correction
        #
        doPedestalCorr = False
        if jobproperties.CaloCellFlags.doPedestalCorr.statusOn:
            if jobproperties.CaloCellFlags.doPedestalCorr() and (
                    jobproperties.CaloCellFlags.doPileupOffsetBCIDCorr):
                doPedestalCorr = True
                mlog.info("Apply cell level pedestal shift correction")

        if doPedestalCorr:
            try:
                from CaloCellCorrection.CaloCellPedestalCorrDefault import CaloCellPedestalCorrDefault
                theCaloCellPedestalCorr = CaloCellPedestalCorrDefault()
                theCaloCellMaker += theCaloCellPedestalCorr
                theCaloCellMaker.CaloCellMakerToolNames += [
                    theCaloCellPedestalCorr
                ]
            except Exception:
                mlog.error("could not get handle to CaloCellPedestalCorr")
                print(traceback.format_exc())

        #
        # Correction for MinBias energy shift for MC pileup reco
        #
        doMinBiasAverage = False
        if jobproperties.CaloCellFlags.doMinBiasAverage.statusOn:
            from AthenaCommon.BeamFlags import jobproperties
            if jobproperties.CaloCellFlags.doMinBiasAverage(
            ) and globalflags.DataSource() == 'geant4' and (
                    not jobproperties.Beam.zeroLuminosity()):
                doMinBiasAverage = True

        if doMinBiasAverage:

            try:
                from CaloTools.CaloMBAverageToolDefault import CaloMBAverageToolDefault
                theCaloMBAverageTool = CaloMBAverageToolDefault()
            except Exception:
                mlog.error("could not get handle to CaloMBAverageTool  Quit")
                print(traceback.format_exc())
                return False
            ToolSvc += theCaloMBAverageTool

            try:
                from CaloCellCorrection.CaloCellCorrectionConf import CaloCellMBAverageCorr
                theCaloCellMBAverageCorr = CaloCellMBAverageCorr(
                    "CaloCellMBAverageCorr")
                theCaloCellMBAverageCorr.CaloMBAverageTool = theCaloMBAverageTool
            except Exception:
                mlog.error(
                    "could not get handle to  CaloCellMBAverageCorr  Quit")
                print(traceback.format_exc())
                return False
            ToolSvc += theCaloCellMBAverageCorr

            try:
                from CaloRec.CaloRecConf import CaloCellContainerCorrectorTool
                from CaloIdentifier import SUBCALO
                theMBAverageTool = CaloCellContainerCorrectorTool(
                    "MBAverageTool",
                    CaloNums=[SUBCALO.NSUBCALO],
                    CellCorrectionToolNames=[theCaloCellMBAverageCorr])
            except Exception:
                mlog.error(
                    "could not get handle to CaloCellContainerCorrectorTool/MBAverageTool Quit"
                )
                print(traceback.format_exc())
                return False

            theCaloCellMaker += theMBAverageTool
            theCaloCellMaker.CaloCellMakerToolNames += [theMBAverageTool]

        #
        # Correction for dead cells, where we average the energy density of neighbor cells
        #
        doNeighborsAverage = False
        if jobproperties.CaloCellFlags.doDeadCellCorr.statusOn:
            if jobproperties.CaloCellFlags.doDeadCellCorr():
                doNeighborsAverage = True

        if doNeighborsAverage:
            try:
                from CaloCellCorrection.CaloCellCorrectionConf import CaloCellNeighborsAverageCorr
                theCaloCellNeighborsAverageCorr = CaloCellNeighborsAverageCorr(
                    "CaloCellNeighborsAverageCorr")
                theCaloCellNeighborsAverageCorr.testMode = False
            except Exception:
                mlog.error(
                    "could not get handle to  CaloCellNeighborsAverageCorr  Quit"
                )
                print(traceback.format_exc())
                return False
            theCaloCellMaker += theCaloCellNeighborsAverageCorr
            theCaloCellMaker.CaloCellMakerToolNames += [
                theCaloCellNeighborsAverageCorr
            ]

        #
        # correction for missing Febs based on L1 readout
        doLArDeadOTXCorr = False
        if jobproperties.CaloCellFlags.doLArDeadOTXCorr.statusOn and jobproperties.CaloCellFlags.doLArCreateMissingCells.statusOn:
            if jobproperties.CaloCellFlags.doLArDeadOTXCorr(
            ) and jobproperties.CaloCellFlags.doLArCreateMissingCells(
            ) and doStandardCellReconstruction:
                if rec.doTrigger():
                    doLArDeadOTXCorr = True
                else:
                    mlog.warning(
                        "Trigger is switched off. Can't run deadOTX correction."
                    )

        if doLArDeadOTXCorr:

            try:
                from LArCellRec.LArCellDeadOTXCorrToolDefault import LArCellDeadOTXCorrToolDefault
                theLArCellDeadOTXCorr = LArCellDeadOTXCorrToolDefault()
            except Exception:
                mlog.error("could not get handle to LArCellDeadOTXCorr Quit")
                print(traceback.format_exc())

            theCaloCellMaker += theLArCellDeadOTXCorr
            theCaloCellMaker.CaloCellMakerToolNames += [theLArCellDeadOTXCorr]

        # make lots of checks (should not be necessary eventually)
        # to print the check add:

        from CaloRec.CaloRecConf import CaloCellContainerCheckerTool
        theCaloCellContainerCheckerTool = CaloCellContainerCheckerTool()
        # FIXME
        # theCaloCellContainerCheckerTool.OutputLevel=DEBUG

        theCaloCellMaker += theCaloCellContainerCheckerTool
        theCaloCellMaker.CaloCellMakerToolNames += [
            theCaloCellContainerCheckerTool
        ]

        # sets output key
        theCaloCellMaker.CaloCellsOutputName = self.outputKey()

        # register output in objKeyStore
        from RecExConfig.ObjKeyStore import objKeyStore
        objKeyStore.addStreamESD(self.outputType(), self.outputKey())

        # Also note that we produce it as a transient output.
        objKeyStore.addTransient(self.outputType(), self.outputKey())

        from TileRecUtils.TileDQstatusAlgDefault import TileDQstatusAlgDefault
        TileDQstatusAlgDefault()

        # now add algorithm to topSequence
        # this should always come at the end

        mlog.info(" now adding CaloCellMaker to topSequence")

        from AthenaCommon.AlgSequence import AlgSequence
        topSequence = AlgSequence()

        topSequence += theCaloCellMaker

        return True
예제 #4
0
    def configure(self):

        mlog = logging.getLogger( 'TileRawChannelGetter::configure:' )
        mlog.info ("entering")

        self._TileRawChannelBuilderFitFilter = None
        self._TileRawChannelBuilderFitFilterCool = None
        self._TileRawChannelBuilderMF = None
        self._TileRawChannelBuilderOF1 = None
        self._TileRawChannelBuilderOpt2Filter = None
        self._TileRawChannelBuilderOptATLAS = None
        self._TileRawChannelBuilderWienerFilter = None

        # Instantiation of the C++ algorithm
        try:        
            from TileRecUtils.TileRecUtilsConf import TileRawChannelMaker               
            theTileRawChannelMaker = TileRawChannelMaker("TileRChMaker")
        except Exception:
            mlog.error("could not import TileRecUtils.TileRawChannelMaker")
            traceback.print_exc()
            return False
    
        self._TileRChMaker = theTileRawChannelMaker

        # Configure TileInfoLoader
        from AthenaCommon.AppMgr import ServiceMgr

        from TileConditions.TileInfoConfigurator import TileInfoConfigurator
        tileInfoConfigurator = TileInfoConfigurator()

        from TileRecUtils.TileRecFlags import jobproperties

        # true for real data, false for MC - GlobalFlags.DataSource.is_data()
        # true for nominal ATLAS configuration - GlobalFlags.DetGeo.is_atlas()
        from AthenaCommon.GlobalFlags import globalflags
        if globalflags.DataSource() == 'data' and jobproperties.TileRecFlags.noiseFilter() < 0:
            # apply noise filter for real data (if this option was not set before)
            jobproperties.TileRecFlags.noiseFilter = 1

        if globalflags.DataSource() == 'data' and not globalflags.isOverlay():
            if jobproperties.TileRecFlags.TileRunType() == 1 :
                tileBeamElemContainer=""
            else:
                tileBeamElemContainer="TileBeamElemCnt"
            if jobproperties.TileRecFlags.readDigits():
                tileDigitsContainer="TileDigitsCnt"
            else:
                tileDigitsContainer=""
            tileRawChannelContainer="TileRawChannelCnt"
        else:
            tileBeamElemContainer=""
            tileDigitsContainer=""
            tileRawChannelContainer=""

        if not globalflags.isOverlay():
            from TileRecUtils.TileDQstatusAlgDefault import TileDQstatusAlgDefault
            TileDQstatusAlgDefault (TileRawChannelContainer = tileRawChannelContainer,
                                    TileDigitsContainer = tileDigitsContainer,
                                    TileBeamElemContainer = tileBeamElemContainer)

        # set time window for amplitude correction if it was not set correctly before
        if jobproperties.TileRecFlags.TimeMaxForAmpCorrection() <= jobproperties.TileRecFlags.TimeMinForAmpCorrection() :
            from AthenaCommon.BeamFlags import jobproperties
            mlog.info("adjusting min/max time of parabolic correction for %s", jobproperties.Beam.bunchSpacing)
            halfBS = jobproperties.Beam.bunchSpacing.get_Value()/2.
            if halfBS > 25.1:
                mlog.info("Bunch spacing is too big, keeping default limits for parabolic correction")
            else:
                jobproperties.TileRecFlags.TimeMinForAmpCorrection = -halfBS
                jobproperties.TileRecFlags.TimeMaxForAmpCorrection = halfBS

        TileFrameLength = ServiceMgr.TileInfoLoader.NSamples
        if TileFrameLength!=7:
            mlog.info("disabling reading of OFC from COOL because Nsamples!=7")
            jobproperties.TileRecFlags.OfcFromCOOL = False

        jobproperties.TileRecFlags.print_JobProperties('tree&value')
        
        # run optimal filter only if readDigits is set
        if jobproperties.TileRecFlags.readDigits():

            from AthenaCommon.AlgSequence import AlgSequence
            topSequence = AlgSequence()

            TilePulseTypes = {0 : 'PHY', 1 : 'PHY', 2 : 'LAS', 4 : 'PHY', 8 : 'CIS'}
            TilePulse = TilePulseTypes[jobproperties.TileRecFlags.TileRunType()]

            from TileConditions.TileCondToolConf import getTileCondToolOfcCool
            toolOfcCool = None
            toolOfcCoolOF1 = None

            NoiseFilterTools = []
            TileRawChannelContainerDSP = ''
            if jobproperties.TileRecFlags.noiseFilter() == 1:

                if globalflags.DataSource() == 'data':

                    # check if there are DSP thresholds in DB
                    if jobproperties.TileRecFlags.zeroAmplitudeWithoutDigits():
                        jobproperties.TileRecFlags.zeroAmplitudeWithoutDigits = False

                    if jobproperties.TileRecFlags.correctPedestalDifference():
                        # check if offline and there are OFCs in DB for OF1 method
                        toolOfcCoolOF1 = getTileCondToolOfcCool('COOL', TilePulse, 'OF1', 'TileCondToolOfcCoolOF1')
                        if athenaCommonFlags.isOnline() or not toolOfcCoolOF1:
                            jobproperties.TileRecFlags.correctPedestalDifference = False
                        #else:
                        #    tileInfoConfigurator.setupCOOLTIME(online = True)

                    if jobproperties.TileRecFlags.zeroAmplitudeWithoutDigits() or jobproperties.TileRecFlags.correctPedestalDifference():
                        from TileRecUtils.TileRecUtilsConf import TileRawChannelOF1Corrector
                        theTileRawChannelOF1Corrector = TileRawChannelOF1Corrector()
                        theTileRawChannelOF1Corrector.CorrectPedestalDifference = jobproperties.TileRecFlags.correctPedestalDifference()
                        theTileRawChannelOF1Corrector.ZeroAmplitudeWithoutDigits = jobproperties.TileRecFlags.zeroAmplitudeWithoutDigits()

                        if jobproperties.TileRecFlags.correctPedestalDifference():
                            from TileConditions.TileCondToolConf import getTileCondToolTiming
                            toolOnlineTiming = getTileCondToolTiming('COOL', TilePulse, True, 'TileCondToolOnlineTiming')
                            theTileRawChannelOF1Corrector.TileCondToolTiming = toolOnlineTiming
                            theTileRawChannelOF1Corrector.TileCondToolOfc = toolOfcCoolOF1

                        NoiseFilterTools += [theTileRawChannelOF1Corrector]


                from TileRecUtils.TileRecUtilsConf import TileRawChannelNoiseFilter
                theTileRawChannelNoiseFilter = TileRawChannelNoiseFilter()
                if not athenaCommonFlags.isOnline():
                    theTileRawChannelNoiseFilter.TileCondToolNoiseSample.TileOnlineSampleNoise = ''
                NoiseFilterTools += [theTileRawChannelNoiseFilter]

                if globalflags.DataSource() == 'data' and not globalflags.isOverlay():
                    from TileRecUtils.TileRecUtilsConf import TileRawChannelCorrectionAlg
                    theTileRawChannelCorrectionAlg = TileRawChannelCorrectionAlg()
                    theTileRawChannelCorrectionAlg.NoiseFilterTools= NoiseFilterTools
                    TileRawChannelContainerDSP = 'TileRawChannelCntCorrected'
                    topSequence += theTileRawChannelCorrectionAlg

            if (jobproperties.TileRecFlags.doTileMF()
                or (not jobproperties.TileRecFlags.OfcFromCOOL()
                    and (jobproperties.TileRecFlags.doTileOF1()
                         or jobproperties.TileRecFlags.doTileWiener()
                         or jobproperties.TileRecFlags.doTileOpt2()
                         or jobproperties.TileRecFlags.doTileOptATLAS()))):

                tileInfoConfigurator.setupCOOLPULSE(type = TilePulse)
                tileInfoConfigurator.setupCOOLAutoCr()

            elif jobproperties.TileRecFlags.doTileFitCool():
                tileInfoConfigurator.setupCOOLPULSE(type = TilePulse)

            if jobproperties.TileRecFlags.OfcFromCOOL():
                if (jobproperties.TileRecFlags.doTileMF()
                    or jobproperties.TileRecFlags.doTileWiener()
                    or jobproperties.TileRecFlags.doTileOpt2()
                    or jobproperties.TileRecFlags.doTileOptATLAS()):

                    tileInfoConfigurator.setupCOOLOFC(type = TilePulse)
                    toolOfcCool = getTileCondToolOfcCool('COOL', TilePulse)

                if jobproperties.TileRecFlags.doTileOF1():
                    tileInfoConfigurator.setupCOOLOFC(type = TilePulse, ofcType = 'OF1')

                    if not toolOfcCoolOF1:
                        toolOfcCoolOF1 = getTileCondToolOfcCool('COOL', TilePulse, 'OF1', 'TileCondToolOfcCoolOF1')


            if jobproperties.TileRecFlags.doTileQIE():
                try:
                    from TileRecUtils.TileRecUtilsConf import TileRawChannelBuilderQIEFilter
                    theTileRawChannelBuilderQIEFilter= TileRawChannelBuilderQIEFilter()
                except Exception:
                    mlog.error("could not get handle to TileRawChannelBuilderQIEFilter Quit")
                    traceback.print_exc()
                    return False
                    
                #TileRawChannelBuilderQIEFilter Options:
                jobproperties.TileRecFlags.TileRawChannelContainer = "TileRawChannelQIE"
                theTileRawChannelBuilderQIEFilter.TileRawChannelContainer = "TileRawChannelQIE"
                theTileRawChannelBuilderQIEFilter.RunType = jobproperties.TileRecFlags.TileRunType()
                theTileRawChannelBuilderQIEFilter.calibrateEnergy = jobproperties.TileRecFlags.calibrateEnergy()
                theTileRawChannelBuilderQIEFilter.correctTime     = jobproperties.TileRecFlags.correctTime()
                theTileRawChannelBuilderQIEFilter.NoiseFilterTools= NoiseFilterTools
                theTileRawChannelBuilderQIEFilter.PedestalMode = 1
                theTileRawChannelBuilderQIEFilter.DSPContainer = TileRawChannelContainerDSP
      
                mlog.info(" adding now TileRawChannelBuilderQIEFilter to the algorithm: %s", theTileRawChannelMaker.name())
      
                theTileRawChannelMaker.TileRawChannelBuilder += [theTileRawChannelBuilderQIEFilter]
            
            # fit with several amplitudes 
            if jobproperties.TileRecFlags.doTileManyAmps():
      
                try:
                    from TileRecUtils.TileRecUtilsConf import TileRawChannelBuilderManyAmps
                    theTileRawChannelBuilderManyAmps= TileRawChannelBuilderManyAmps()
                except Exception:
                    mlog.error("could not get handle to TileRawChannelBuilderManyAmps Quit")
                    traceback.print_exc()
                    return False
      
                #TileRawChannelBuilderManyAmps Options:
                jobproperties.TileRecFlags.TileRawChannelContainer = "TileRawChannelManyAmp"
                theTileRawChannelBuilderManyAmps.TileRawChannelContainer = "TileRawChannelManyAmp"
                theTileRawChannelBuilderManyAmps.RunType = jobproperties.TileRecFlags.TileRunType()
                theTileRawChannelBuilderManyAmps.calibrateEnergy = jobproperties.TileRecFlags.calibrateEnergy()
                theTileRawChannelBuilderManyAmps.correctTime     = jobproperties.TileRecFlags.correctTime()    
                theTileRawChannelBuilderManyAmps.NoiseFilterTools= NoiseFilterTools
                theTileRawChannelBuilderManyAmps.DSPContainer = TileRawChannelContainerDSP
                 
                mlog.info(" adding now TileRawChannelBuilderManyAmps to the algorithm: %s", theTileRawChannelMaker.name())
      
                theTileRawChannelMaker.TileRawChannelBuilder += [theTileRawChannelBuilderManyAmps]
      
            # flat filter - sum of 5 samples
            if jobproperties.TileRecFlags.doTileFlat():
      
                try:
                    from TileRecUtils.TileRecUtilsConf import TileRawChannelBuilderFlatFilter
                    theTileRawChannelBuilderFlatFilter= TileRawChannelBuilderFlatFilter()
                except Exception:
                    mlog.error("could not get handle to TileRawChannelBuilderFlatFilter Quit")
                    traceback.print_exc()
                    return False
      
                #TileRawChannelBuilderFlatFilter Options: 
                jobproperties.TileRecFlags.TileRawChannelContainer = "TileRawChannelFlat"
                theTileRawChannelBuilderFlatFilter.TileRawChannelContainer = "TileRawChannelFlat"
                theTileRawChannelBuilderFlatFilter.RunType = jobproperties.TileRecFlags.TileRunType()
                theTileRawChannelBuilderFlatFilter.calibrateEnergy = jobproperties.TileRecFlags.calibrateEnergy()
                theTileRawChannelBuilderFlatFilter.correctTime     = jobproperties.TileRecFlags.correctTime()    
                theTileRawChannelBuilderFlatFilter.NoiseFilterTools= NoiseFilterTools
                theTileRawChannelBuilderFlatFilter.FrameLength = TileFrameLength
                theTileRawChannelBuilderFlatFilter.SignalLength = TileFrameLength - 1
                theTileRawChannelBuilderFlatFilter.DSPContainer = TileRawChannelContainerDSP
      
                mlog.info(" adding now TileRawChannelBuilderFlatFilter to the algorithm: %s", theTileRawChannelMaker.name())
      
                theTileRawChannelMaker.TileRawChannelBuilder += [theTileRawChannelBuilderFlatFilter]
      
            # Fit method
            if jobproperties.TileRecFlags.doTileFit() or jobproperties.TileRecFlags.doTileOverflowFit():
          
                # configure TileRawChannelMaker here
                try:
                    from TileRecUtils.TileRecUtilsConf import TileRawChannelBuilderFitFilter
                    theTileRawChannelBuilderFitFilter= TileRawChannelBuilderFitFilter()
                except Exception:
                    mlog.error("could not get handle to TileRawChannelBuilderFitFilter Quit")
                    traceback.print_exc()
                    return False
                
                #TileRawChannelBuilderFitFilter Options: 
                theTileRawChannelBuilderFitFilter.RunType = jobproperties.TileRecFlags.TileRunType()
                theTileRawChannelBuilderFitFilter.calibrateEnergy = jobproperties.TileRecFlags.calibrateEnergy()
                theTileRawChannelBuilderFitFilter.correctTime     = jobproperties.TileRecFlags.correctTime()    
                theTileRawChannelBuilderFitFilter.NoiseFilterTools= NoiseFilterTools
                theTileRawChannelBuilderFitFilter.FrameLength = TileFrameLength
                theTileRawChannelBuilderFitFilter.DSPContainer = TileRawChannelContainerDSP
                if not athenaCommonFlags.isOnline():
                    theTileRawChannelBuilderFitFilter.TileCondToolNoiseSample.TileOnlineSampleNoise = ''
                
                # add the tool to list of tool ( should use ToolHandle eventually)
                mlog.info(" adding now TileRawChannelBuilderFitFilter to the algorithm: %s", theTileRawChannelMaker.name())

                if jobproperties.TileRecFlags.doTileFit():
                    jobproperties.TileRecFlags.TileRawChannelContainer = "TileRawChannelFit"
                    theTileRawChannelBuilderFitFilter.TileRawChannelContainer = "TileRawChannelFit"
                    theTileRawChannelMaker.TileRawChannelBuilder += [theTileRawChannelBuilderFitFilter]
                    self._TileRawChannelBuilderFitFilter = theTileRawChannelBuilderFitFilter
                    
                if jobproperties.TileRecFlags.doTileOverflowFit(): 
                    theTileRawChannelMaker.FitOverflow = True
                    theTileRawChannelMaker.TileRawChannelBuilderFitOverflow = theTileRawChannelBuilderFitFilter
                    mlog.info(" set up TileRawChannelBuilderFitOverflow to TileRawChannelBuilderFitFilter")
                
            # Fit method with reading from COOL
            if jobproperties.TileRecFlags.doTileFitCool():
          
                # configure TileRawChannelMaker here
                try:
                    from TileRecUtils.TileRecUtilsConf import TileRawChannelBuilderFitFilterCool
                    theTileRawChannelBuilderFitFilterCool= TileRawChannelBuilderFitFilterCool()
                except Exception:
                    mlog.error("could not get handle to TileRawChannelBuilderFitFilterCool Quit")
                    traceback.print_exc()
                    return False
                
                #TileRawChannelBuilderFitFilterCool Options: 
                jobproperties.TileRecFlags.TileRawChannelContainer = "TileRawChannelFitCool"
                theTileRawChannelBuilderFitFilterCool.TileRawChannelContainer = "TileRawChannelFitCool"
                theTileRawChannelBuilderFitFilterCool.RunType = jobproperties.TileRecFlags.TileRunType()
                theTileRawChannelBuilderFitFilterCool.calibrateEnergy = jobproperties.TileRecFlags.calibrateEnergy()
                theTileRawChannelBuilderFitFilterCool.correctTime     = jobproperties.TileRecFlags.correctTime()    
                theTileRawChannelBuilderFitFilterCool.NoiseFilterTools= NoiseFilterTools
                theTileRawChannelBuilderFitFilterCool.FrameLength = TileFrameLength
                theTileRawChannelBuilderFitFilterCool.DSPContainer = TileRawChannelContainerDSP
                
                # add the tool to list of tool ( should use ToolHandle eventually)
                mlog.info(" adding now TileRawChannelBuilderFitFilterCool to the algorithm: %s", theTileRawChannelMaker.name())
      
                theTileRawChannelMaker.TileRawChannelBuilder += [theTileRawChannelBuilderFitFilterCool]
                self._TileRawChannelBuilderFitFilterCool = theTileRawChannelBuilderFitFilterCool
                
            # matched filter 
            if jobproperties.TileRecFlags.doTileMF():
      
                try:
                    from TileRecUtils.TileRecUtilsConf import TileRawChannelBuilderMF
                    theTileRawChannelBuilderMF= TileRawChannelBuilderMF()
                except Exception:
                    mlog.error("could not get handle to TileRawChannelBuilderMF Quit")
                    traceback.print_exc()
                    return False
                                    
                # setup COOL to get OFCs, needed for COF to retrieve pulse shape and derivatives
                if jobproperties.TileRecFlags.OfcFromCOOL():
                    theTileRawChannelBuilderMF.TileCondToolOfc = toolOfcCool

                #TileRawChannelBuilderMF Options:
                jobproperties.TileRecFlags.TileRawChannelContainer = "TileRawChannelMF"
                theTileRawChannelBuilderMF.TileRawChannelContainer = "TileRawChannelMF"
                theTileRawChannelBuilderMF.RunType = jobproperties.TileRecFlags.TileRunType()
                theTileRawChannelBuilderMF.calibrateEnergy = jobproperties.TileRecFlags.calibrateEnergy()
                if jobproperties.TileRecFlags.BestPhaseFromCOOL(): # can't correct time and use best phase at the same time
                    theTileRawChannelBuilderMF.correctTime = False
                else:
                    theTileRawChannelBuilderMF.correctTime = jobproperties.TileRecFlags.correctTime()
                theTileRawChannelBuilderMF.BestPhase       = jobproperties.TileRecFlags.BestPhaseFromCOOL()
                theTileRawChannelBuilderMF.NoiseFilterTools = NoiseFilterTools
                theTileRawChannelBuilderMF.MaxIterations = 5 # iterative mode on
                theTileRawChannelBuilderMF.AmplitudeCorrection = False
                theTileRawChannelBuilderMF.TimeFromCOF = False
                theTileRawChannelBuilderMF.AmpMinForAmpCorrection = jobproperties.TileRecFlags.AmpMinForAmpCorrection()
                if jobproperties.TileRecFlags.TimeMaxForAmpCorrection() > jobproperties.TileRecFlags.TimeMinForAmpCorrection():
                    theTileRawChannelBuilderMF.TimeMinForAmpCorrection = jobproperties.TileRecFlags.TimeMinForAmpCorrection()
                    theTileRawChannelBuilderMF.TimeMaxForAmpCorrection = jobproperties.TileRecFlags.TimeMaxForAmpCorrection()

                theTileRawChannelBuilderMF.DSPContainer = TileRawChannelContainerDSP
                mlog.info(" adding now TileRawChannelBuilderMF to the algorithm: %s", theTileRawChannelMaker.name())
      
                theTileRawChannelMaker.TileRawChannelBuilder += [theTileRawChannelBuilderMF]
                self._TileRawChannelBuilderMF = theTileRawChannelBuilderMF

            if jobproperties.TileRecFlags.doTileOF1():
                try:
                    from TileRecUtils.TileRecUtilsConf import TileRawChannelBuilderOpt2Filter
                    theTileRawChannelBuilderOF1 = TileRawChannelBuilderOpt2Filter("TileRawChannelBuilderOF1")
                except Exception:
                    mlog.error("could not get handle to TileRawChannelBuilderOF1 Quit")
                    traceback.print_exc()
                    return False
                
                # setup COOL to get OFCs
                if jobproperties.TileRecFlags.OfcFromCOOL():
                    if toolOfcCoolOF1:
                        theTileRawChannelBuilderOF1.TileCondToolOfc = toolOfcCoolOF1
                    else:
                        # There are no OF1 OFC in the COOL
                        # OFC will be calculated on the fly
                        tileInfoConfigurator.setupCOOLPULSE(type = TilePulse)
                        tileInfoConfigurator.setupCOOLAutoCr()

                #TileRawChannelBuilderOF1 Options:
                jobproperties.TileRecFlags.TileRawChannelContainer = "TileRawChannelOF1"
                theTileRawChannelBuilderOF1.TileRawChannelContainer = "TileRawChannelOF1"
                theTileRawChannelBuilderOF1.RunType = jobproperties.TileRecFlags.TileRunType()
                theTileRawChannelBuilderOF1.calibrateEnergy = jobproperties.TileRecFlags.calibrateEnergy()
                if jobproperties.TileRecFlags.BestPhaseFromCOOL(): # can't correct time and use best phase at the same time
                    theTileRawChannelBuilderOF1.correctTime = False
                else:
                    theTileRawChannelBuilderOF1.correctTime = jobproperties.TileRecFlags.correctTime()
                theTileRawChannelBuilderOF1.BestPhase       = jobproperties.TileRecFlags.BestPhaseFromCOOL()
                theTileRawChannelBuilderOF1.NoiseFilterTools= NoiseFilterTools
                theTileRawChannelBuilderOF1.OF2 = False
                theTileRawChannelBuilderOF1.PedestalMode = -1
                theTileRawChannelBuilderOF1.MaxIterations = 1 # just one iteration
                theTileRawChannelBuilderOF1.Minus1Iteration = False # assume that max sample is at t=0
                theTileRawChannelBuilderOF1.AmplitudeCorrection = jobproperties.TileRecFlags.correctAmplitude()
                theTileRawChannelBuilderOF1.TimeCorrection = False
                theTileRawChannelBuilderOF1.AmpMinForAmpCorrection = jobproperties.TileRecFlags.AmpMinForAmpCorrection()
                if jobproperties.TileRecFlags.TimeMaxForAmpCorrection() > jobproperties.TileRecFlags.TimeMinForAmpCorrection():
                    theTileRawChannelBuilderOF1.TimeMinForAmpCorrection = jobproperties.TileRecFlags.TimeMinForAmpCorrection()
                    theTileRawChannelBuilderOF1.TimeMaxForAmpCorrection = jobproperties.TileRecFlags.TimeMaxForAmpCorrection()
      
                theTileRawChannelBuilderOF1.DSPContainer = TileRawChannelContainerDSP
                mlog.info(" adding now TileRawChannelBuilderOF1 to the algorithm: %s", theTileRawChannelMaker.name())
      
                theTileRawChannelMaker.TileRawChannelBuilder += [theTileRawChannelBuilderOF1]
                self._TileRawChannelBuilderOF1 = theTileRawChannelBuilderOF1

            if jobproperties.TileRecFlags.doTileOpt2():
                try:
                    from TileRecUtils.TileRecUtilsConf import TileRawChannelBuilderOpt2Filter
                    theTileRawChannelBuilderOpt2Filter= TileRawChannelBuilderOpt2Filter()
                except Exception:
                    mlog.error("could not get handle to TileRawChannelBuilderOpt2Filter Quit")
                    traceback.print_exc()
                    return False
                
                # setup COOL to get OFCs
                if jobproperties.TileRecFlags.OfcFromCOOL():
                    theTileRawChannelBuilderOpt2Filter.TileCondToolOfc = toolOfcCool
                    
                #TileRawChannelBuilderOpt2Filter Options:
                jobproperties.TileRecFlags.TileRawChannelContainer = "TileRawChannelOpt2"
                theTileRawChannelBuilderOpt2Filter.TileRawChannelContainer = "TileRawChannelOpt2"
                theTileRawChannelBuilderOpt2Filter.RunType = jobproperties.TileRecFlags.TileRunType()
                theTileRawChannelBuilderOpt2Filter.calibrateEnergy = jobproperties.TileRecFlags.calibrateEnergy()
                theTileRawChannelBuilderOpt2Filter.correctTime     = jobproperties.TileRecFlags.correctTime()
                theTileRawChannelBuilderOpt2Filter.NoiseFilterTools= NoiseFilterTools
                theTileRawChannelBuilderOpt2Filter.BestPhase       = False # no point to use best phase with interations
                theTileRawChannelBuilderOpt2Filter.OF2 = True
                theTileRawChannelBuilderOpt2Filter.PedestalMode = 1
                theTileRawChannelBuilderOpt2Filter.MaxIterations = 5
                theTileRawChannelBuilderOpt2Filter.Minus1Iteration = True
                theTileRawChannelBuilderOpt2Filter.AmplitudeCorrection = False # don't need correction after iterations
                theTileRawChannelBuilderOpt2Filter.TimeCorrection    = False # don't need correction after iterations
                theTileRawChannelBuilderOpt2Filter.DSPContainer = TileRawChannelContainerDSP
      
                mlog.info(" adding now TileRawChannelBuilderOpt2Filter to the algorithm: %s", theTileRawChannelMaker.name())
      
                theTileRawChannelMaker.TileRawChannelBuilder += [theTileRawChannelBuilderOpt2Filter]
                self._TileRawChannelBuilderOpt2Filter = theTileRawChannelBuilderOpt2Filter
      
      
            if jobproperties.TileRecFlags.doTileOptATLAS():
                try:
                    from TileRecUtils.TileRecUtilsConf import TileRawChannelBuilderOpt2Filter
                    theTileRawChannelBuilderOptATLAS= TileRawChannelBuilderOpt2Filter("TileRawChannelBuilderOptATLAS")
                except Exception:
                    mlog.error("could not get handle to TileRawChannelBuilderOpt2Filter Quit")
                    traceback.print_exc()
                    return False
                
                # setup COOL to get OFCs
                if jobproperties.TileRecFlags.OfcFromCOOL():
                    theTileRawChannelBuilderOptATLAS.TileCondToolOfc = toolOfcCool
                    
                #TileRawChannelBuilderOptATLAS Options:
                if globalflags.DataSource()=='data': # don't use the name which is used for reco data from DSP
                    if jobproperties.TileRecFlags.TileRawChannelContainer == "TileRawChannelCnt":
                        jobproperties.TileRecFlags.TileRawChannelContainer = "TileRawChannelFixed"
                    theTileRawChannelBuilderOptATLAS.TileRawChannelContainer = "TileRawChannelFixed"
                else:
                    jobproperties.TileRecFlags.TileRawChannelContainer = "TileRawChannelCnt"
                    theTileRawChannelBuilderOptATLAS.TileRawChannelContainer = "TileRawChannelCnt"
                theTileRawChannelBuilderOptATLAS.RunType         = jobproperties.TileRecFlags.TileRunType()
                theTileRawChannelBuilderOptATLAS.calibrateEnergy = jobproperties.TileRecFlags.calibrateEnergy()
                if jobproperties.TileRecFlags.BestPhaseFromCOOL(): # can't correct time and use best phase at the same time
                    theTileRawChannelBuilderOptATLAS.correctTime = False
                else:
                    theTileRawChannelBuilderOptATLAS.correctTime = jobproperties.TileRecFlags.correctTime()
                theTileRawChannelBuilderOptATLAS.BestPhase       = jobproperties.TileRecFlags.BestPhaseFromCOOL()
                theTileRawChannelBuilderOptATLAS.NoiseFilterTools= NoiseFilterTools
                theTileRawChannelBuilderOptATLAS.OF2 = True
                #theTileRawChannelBuilderOptATLAS.PedestalMode = 1 # not sure if we need this option here
                theTileRawChannelBuilderOptATLAS.MaxIterations = 1 # just one iteration
                theTileRawChannelBuilderOptATLAS.Minus1Iteration = False # assume that max sample is at t=0
                theTileRawChannelBuilderOptATLAS.AmplitudeCorrection = jobproperties.TileRecFlags.correctAmplitude()
                theTileRawChannelBuilderOptATLAS.TimeCorrection = jobproperties.TileRecFlags.correctTimeNI()
                theTileRawChannelBuilderOptATLAS.AmpMinForAmpCorrection = jobproperties.TileRecFlags.AmpMinForAmpCorrection()
                if jobproperties.TileRecFlags.TimeMaxForAmpCorrection() > jobproperties.TileRecFlags.TimeMinForAmpCorrection():
                    theTileRawChannelBuilderOptATLAS.TimeMinForAmpCorrection = jobproperties.TileRecFlags.TimeMinForAmpCorrection()
                    theTileRawChannelBuilderOptATLAS.TimeMaxForAmpCorrection = jobproperties.TileRecFlags.TimeMaxForAmpCorrection()

                theTileRawChannelBuilderOptATLAS.DSPContainer = TileRawChannelContainerDSP
                
                mlog.info(" adding now TileRawChannelBuilderOpt2Filter with name TileRawChannelBuilderOptATLAS to the algorithm: %s",
                          theTileRawChannelMaker.name())
                
                theTileRawChannelMaker.TileRawChannelBuilder += [theTileRawChannelBuilderOptATLAS]
                self._TileRawChannelBuilderOptATLAS = theTileRawChannelBuilderOptATLAS

            if jobproperties.TileRecFlags.doTileWiener():
                try:
                    from TileRecUtils.TileRecUtilsConf import TileRawChannelBuilderWienerFilter
                    theTileRawChannelBuilderWienerFilter= TileRawChannelBuilderWienerFilter()
                except Exception:
                    mlog.error("could not get handle to TileRawChannelBuilderWienerFilter Quit")
                    traceback.print_exc()
                    return False

                #TileRawChannelBuilderWienerFilter Options:
                jobproperties.TileRecFlags.TileRawChannelContainer           = "TileRawChannelWiener"
                theTileRawChannelBuilderWienerFilter.TileRawChannelContainer = "TileRawChannelWiener"
                theTileRawChannelBuilderWienerFilter.RunType                 = jobproperties.TileRecFlags.TileRunType()
                theTileRawChannelBuilderWienerFilter.calibrateEnergy         = jobproperties.TileRecFlags.calibrateEnergy()
                theTileRawChannelBuilderWienerFilter.correctTime             = jobproperties.TileRecFlags.correctTime()
                theTileRawChannelBuilderWienerFilter.NoiseFilterTools        = NoiseFilterTools
                theTileRawChannelBuilderWienerFilter.BestPhase               = False # no point to use best phase with interations
                theTileRawChannelBuilderWienerFilter.MC                      = globalflags.DataSource()!='data'
                theTileRawChannelBuilderWienerFilter.PedestalMode            = 1
                theTileRawChannelBuilderWienerFilter.MaxIterations           = 5
                theTileRawChannelBuilderWienerFilter.Minus1Iteration         = True
                theTileRawChannelBuilderWienerFilter.AmplitudeCorrection     = False # don't need correction after iterations
                theTileRawChannelBuilderWienerFilter.TimeCorrection          = False # don't need correction after iterations
                theTileRawChannelBuilderWienerFilter.DSPContainer            = TileRawChannelContainerDSP

                ServiceMgr.TileInfoLoader.LoadWienerFilterWeights            = True

                mlog.info(" adding now TileRawChannelBuilderWienerFilter to the algorithm: %s", theTileRawChannelMaker.name())

                theTileRawChannelMaker.TileRawChannelBuilder += [theTileRawChannelBuilderWienerFilter]
                self._TileRawChannelBuilderWienerFilter = theTileRawChannelBuilderWienerFilter
            

            # now add algorithm to topSequence
            # this should always come at the end

            mlog.info(" now adding to topSequence")        

            if jobproperties.TileRecFlags.noiseFilter() == 2:
                # Instantiation of the C++ algorithm
                try:
                    from TileRecUtils.TileRecUtilsConf import TileRawCorrelatedNoise
                    theTileRawCorrelatedNoise=TileRawCorrelatedNoise("TileRCorreNoise")
                except Exception:
                    mlog.error("could not import TileRecUtils.TileRawCorrelatedNoise")
                    traceback.print_exc()
                    return False
                #theTileRawCorrelatedNoise.UseMeanFiles = False
                #theTileRawCorrelatedNoise.PMTOrder = True
                jobproperties.TileRecFlags.TileDigitsContainer = "NewDigitsContainer"
                topSequence += theTileRawCorrelatedNoise

            jobproperties.TileRecFlags.print_JobProperties('tree&value')

            theTileRawChannelMaker.TileDigitsContainer = jobproperties.TileRecFlags.TileDigitsContainer()
            topSequence += theTileRawChannelMaker

        else:
            mlog.info(" Disable all OF methods because readDigits flag set to False ")
            jobproperties.TileRecFlags.doTileFlat = False
            jobproperties.TileRecFlags.doTileFit = False
            jobproperties.TileRecFlags.doTileFitCool = False
            jobproperties.TileRecFlags.doTileOpt2 = False
            jobproperties.TileRecFlags.doTileOptATLAS = False
            jobproperties.TileRecFlags.doTileManyAmps = False
            jobproperties.TileRecFlags.doTileMF = False
            jobproperties.TileRecFlags.doTileOF1 = False
            jobproperties.TileRecFlags.doTileWiener = False
            jobproperties.TileRecFlags.OfcFromCOOL = False
            jobproperties.TileRecFlags.print_JobProperties('tree&value')

        return True
예제 #5
0
    from __main__ import ALLOWBACKNAV

from AthenaCommon.Logging import logging
mlog = logging.getLogger('TileDigitiization')

if doTileHitToRawChannelDirect:

    from TileSimAlgs.TileRawChannelFromHitsGetter import *
    theTileRawChannelFromHitsGetter = TileRawChannelFromHitsGetter()

if doTileHitToDigit:
    # Change default parameters for TileDQstatusAlg.
    from AthenaCommon.GlobalFlags import globalflags
    if globalflags.isOverlay():
        from TileRecUtils.TileDQstatusAlgDefault import TileDQstatusAlgDefault
        dqstatus = TileDQstatusAlgDefault()
        dqstatus.TileBeamElemContainer = ""
        # disable reading of trigger type from BeamElem container

        from OverlayCommonAlgs.OverlayFlags import overlayFlags
        if overlayFlags.isDataOverlay():
            if overlayFlags.isOverlayMT():
                dqstatus.TileDigitsContainer = overlayFlags.bkgPrefix(
                ) + "TileDigitsCnt"
                dqstatus.TileRawChannelContainer = overlayFlags.bkgPrefix(
                ) + "TileRawChannelCnt"
            else:
                dqstatus.TileDigitsContainer = overlayFlags.dataStore(
                ) + "+TileDigitsCnt"
                dqstatus.TileRawChannelContainer = overlayFlags.dataStore(
                ) + "+TileRawChannelCnt"
예제 #6
0
    def configure(self):
        from AthenaCommon.Logging import logging
        mlog = logging.getLogger('CaloCellGetter::configure:')
        mlog.info('entering')

        doStandardCellReconstruction = True
        from CaloRec.CaloCellFlags import jobproperties
        from AthenaCommon.AppMgr import ToolSvc

        if not jobproperties.CaloCellFlags.doFastCaloSim.statusOn:
            doFastCaloSim = False
            mlog.info("doFastCaloSim not set, so not using it")
        else:
            doFastCaloSim = jobproperties.CaloCellFlags.doFastCaloSim()
            if doFastCaloSim:
                mlog.info("doFastCaloSim requested")
                doStandardCellReconstruction = False
                if jobproperties.CaloCellFlags.doFastCaloSimAddCells():
                    doStandardCellReconstruction = True
                    mlog.info(
                        "doFastCaloSimAddCells requested: FastCaloSim is added to fullsim calorimeter"
                    )
                else:
                    mlog.info(
                        "doFastCaloSimAddCells not requested: Stand alone FastCaloSim is running"
                    )
            else:
                mlog.info("doFastCaloSim explicitly not requested")

        # get handle to upstream object
        # handle tile

        if doStandardCellReconstruction:
            from LArROD.LArRODFlags import larRODFlags
            from AthenaCommon.GlobalFlags import globalflags
            if larRODFlags.readDigits() and globalflags.DataSource() == 'data':
                from LArROD.LArRawChannelBuilderDefault import LArRawChannelBuilderDefault
                LArRawChannelBuilderDefault()

        # writing of thinned digits
        if jobproperties.CaloCellFlags.doLArThinnedDigits.statusOn and jobproperties.CaloCellFlags.doLArThinnedDigits(
        ):
            from AthenaCommon.GlobalFlags import globalflags
            if globalflags.DataSource() == 'data':
                try:
                    from LArROD.LArDigits import DefaultLArDigitThinner
                    LArDigitThinner = DefaultLArDigitThinner(
                        'LArDigitThinner'
                    )  # automatically added to topSequence
                    LArDigitThinner.InputContainerName = "FREE"
                    LArDigitThinner.OutputContainerName = "LArDigitContainer_Thinned"
                except Exception:
                    treatException("Problem with LArDigitThinner ")

        # now configure the algorithm, part of this could be done in a separate class
        # cannot have same name
        try:
            from CaloRec.CaloRecConf import CaloCellMaker
        except Exception:
            mlog.error("could not import CaloRec.CaloCellMaker")
            print(traceback.format_exc())
            return False

        theCaloCellMaker = CaloCellMaker()
        self._CaloCellMakerHandle = theCaloCellMaker

        if doStandardCellReconstruction:
            # configure CaloCellMaker here
            # check LArCellMakerTool_jobOptions.py for full configurability
            # FIXME

            if rec.doLArg():
                from LArCabling.LArCablingAccess import LArOnOffIdMapping
                LArOnOffIdMapping()

                try:
                    from LArCellRec.LArCellRecConf import LArCellBuilderFromLArRawChannelTool
                    theLArCellBuilder = LArCellBuilderFromLArRawChannelTool()
                except Exception:
                    mlog.error(
                        "could not get handle to LArCellBuilderFromLArRawChannel Quit"
                    )
                    print(traceback.format_exc())
                    return False

                if jobproperties.CaloCellFlags.doLArCreateMissingCells():
                    theLArCellBuilder.addDeadOTX = True

                # add the tool to list of tool ( should use ToolHandle eventually)
                theCaloCellMaker += theLArCellBuilder
                theCaloCellMaker.CaloCellMakerToolNames += [theLArCellBuilder]

            if rec.doTile():

                from AthenaCommon.GlobalFlags import globalflags
                if globalflags.DataSource(
                ) == 'data' and globalflags.InputFormat() == 'bytestream':
                    try:
                        svcMgr.ByteStreamCnvSvc.ROD2ROBmap = ["-1"]
                        if "TileDigitsContainer/TileDigitsCnt" not in svcMgr.ByteStreamAddressProviderSvc.TypeNames:
                            svcMgr.ByteStreamAddressProviderSvc.TypeNames += [
                                "TileBeamElemContainer/TileBeamElemCnt",
                                "TileDigitsContainer/TileDigitsCnt",
                                "TileL2Container/TileL2Cnt",
                                "TileLaserObject/TileLaserObj",
                                "TileMuonReceiverContainer/TileMuRcvCnt"
                            ]
                    except Exception:
                        mlog.warning(
                            "Cannot add TileDigitsContainer/TileDigitsCnt et al. to bytestream list"
                        )

                    # set options for TileRawChannelMaker
                    from TileRecUtils.TileRecFlags import jobproperties
                    jobproperties.TileRecFlags.TileRunType = 1  # physics run type

                    # reading of digits can be disabled before calling CaloCellGetter
                    # if this is not done, but digits are not available in BS file
                    # reading of digits is automatically disabled at start of run
                    if jobproperties.TileRecFlags.readDigits()                \
                        and not (jobproperties.TileRecFlags.doTileFlat        \
                                 or jobproperties.TileRecFlags.doTileFit      \
                                 or jobproperties.TileRecFlags.doTileFitCool  \
                                 or jobproperties.TileRecFlags.doTileOF1      \
                                 or jobproperties.TileRecFlags.doTileOpt2     \
                                 or jobproperties.TileRecFlags.doTileOptATLAS \
                                 or jobproperties.TileRecFlags.doTileMF):

                        from AthenaCommon.BeamFlags import jobproperties
                        # run Opt filter with iterations by default, both for cosmics and collisions before 2011
                        # run Opt filter without iterations for collisions in 2011 and later
                        if 'doTileOpt2' not in dir():
                            from RecExConfig.AutoConfiguration import GetRunNumber
                            rn = GetRunNumber()
                            if not athenaCommonFlags.isOnline(
                            ) and rn > 0 and rn < 171194:
                                doTileOpt2 = True
                            elif jobproperties.Beam.beamType() == 'collisions':
                                doTileOpt2 = False  # use OF without iterations for collisions
                            else:
                                doTileOpt2 = True  # always run OF with iterations for cosmics

                        # jobproperties.TileRecFlags.calibrateEnergy=True # use pCb for RawChannels
                        # please, note that time correction and best phase are used only for collisions
                        if doTileOpt2:
                            jobproperties.TileRecFlags.doTileOpt2 = True  # run optimal filter with iterations
                            jobproperties.TileRecFlags.doTileOptATLAS = False  # disable optimal filter without iterations
                            jobproperties.TileRecFlags.correctAmplitude = False  # don't do parabolic correction
                            if jobproperties.Beam.beamType() == 'collisions':
                                jobproperties.TileRecFlags.correctTime = True  # apply time correction in physics runs
                                jobproperties.TileRecFlags.BestPhaseFromCOOL = False  # best phase is not needed for iterations
                        else:
                            jobproperties.TileRecFlags.doTileOpt2 = False  # disable optimal filter with iterations
                            jobproperties.TileRecFlags.doTileOptATLAS = True  # run optimal filter without iterations
                            jobproperties.TileRecFlags.correctAmplitude = True  # apply parabolic correction
                            if jobproperties.Beam.beamType() == 'collisions':
                                jobproperties.TileRecFlags.correctTime = False  # don't need time correction if best phase is used
                                jobproperties.TileRecFlags.BestPhaseFromCOOL = True  # use best phase stored in DB

                    try:
                        from TileRecUtils.TileRawChannelGetter import TileRawChannelGetter
                        theTileRawChannelGetter = TileRawChannelGetter(
                        )  # noqa: F841
                    except Exception:
                        mlog.error("could not load TileRawChannelGetter Quit")
                        print(traceback.format_exc())
                        return False

                    try:
                        from TileRecAlgs.TileRecAlgsConf import TileDigitsFilter
                        from AthenaCommon.AlgSequence import AlgSequence
                        topSequence = AlgSequence()
                        topSequence += TileDigitsFilter()
                    except Exception:
                        mlog.error("Could not configure TileDigitsFilter")

                from AthenaCommon.AlgSequence import AthSequencer
                condSequence = AthSequencer("AthCondSeq")
                checkDCS = hasattr(condSequence, 'TileDCSCondAlg')
                try:
                    from TileRecUtils.TileRecUtilsConf import TileCellBuilder
                    theTileCellBuilder = TileCellBuilder(CheckDCS=checkDCS)
                    from TileRecUtils.TileRecFlags import jobproperties
                    theTileCellBuilder.TileRawChannelContainer = jobproperties.TileRecFlags.TileRawChannelContainer(
                    )

                    if (jobproperties.TileRecFlags.noiseFilter() == 1
                            and jobproperties.TileRecFlags.readDigits()
                            and globalflags.DataSource() == 'data'
                            and not globalflags.isOverlay()):
                        theTileCellBuilder.TileDSPRawChannelContainer = 'TileRawChannelCntCorrected'

                    rawChannelContainer = ''
                    if globalflags.DataSource(
                    ) == 'data' and globalflags.InputFormat() == 'bytestream':
                        if jobproperties.TileRecFlags.readDigits():
                            # everything is already corrected at RawChannel level
                            theTileCellBuilder.correctTime = False
                            theTileCellBuilder.correctAmplitude = False
                        else:
                            rawChannelContainer = 'TileRawChannelCnt'
                            # by default parameters are tuned for opt.filter without iterations
                            theTileCellBuilder.correctTime = jobproperties.TileRecFlags.correctTime(
                            )
                            theTileCellBuilder.correctAmplitude = jobproperties.TileRecFlags.correctAmplitude(
                            )
                            theTileCellBuilder.AmpMinForAmpCorrection = jobproperties.TileRecFlags.AmpMinForAmpCorrection(
                            )
                            if jobproperties.TileRecFlags.TimeMaxForAmpCorrection(
                            ) <= jobproperties.TileRecFlags.TimeMinForAmpCorrection(
                            ):
                                from AthenaCommon.BeamFlags import jobproperties
                                mlog.info(
                                    "adjusting min/max time of parabolic correction for %s",
                                    jobproperties.Beam.bunchSpacing)
                                halfBS = jobproperties.Beam.bunchSpacing.get_Value(
                                ) / 2.
                                jobproperties.TileRecFlags.TimeMinForAmpCorrection = -halfBS
                                jobproperties.TileRecFlags.TimeMaxForAmpCorrection = halfBS
                            if jobproperties.TileRecFlags.TimeMaxForAmpCorrection(
                            ) > jobproperties.TileRecFlags.TimeMinForAmpCorrection(
                            ):
                                theTileCellBuilder.TimeMinForAmpCorrection = jobproperties.TileRecFlags.TimeMinForAmpCorrection(
                                )
                                theTileCellBuilder.TimeMaxForAmpCorrection = jobproperties.TileRecFlags.TimeMaxForAmpCorrection(
                                )

                    theCaloCellMaker += theTileCellBuilder
                    theCaloCellMaker.CaloCellMakerToolNames += [
                        theTileCellBuilder
                    ]
                except Exception:
                    mlog.error("could not get handle to TileCellBuilder Quit")
                    print(traceback.format_exc())
                    return False

        if doFastCaloSim:
            mlog.info('configuring FastCaloSim here')

            try:
                from FastCaloSim.FastCaloSimConf import EmptyCellBuilderTool
                theEmptyCellBuilderTool = EmptyCellBuilderTool()
                theCaloCellMaker += theEmptyCellBuilderTool
                theCaloCellMaker.CaloCellMakerToolNames += [
                    theEmptyCellBuilderTool
                ]

                print(theEmptyCellBuilderTool)
                mlog.info("configure EmptyCellBuilderTool worked")
            except Exception:
                mlog.error("could not get handle to EmptyCellBuilderTool Quit")
                print(traceback.format_exc())
                return False

            try:
                from FastCaloSim.FastCaloSimFactory import FastCaloSimFactory
                theFastShowerCellBuilderTool = FastCaloSimFactory()

                theCaloCellMaker += theFastShowerCellBuilderTool
                theCaloCellMaker.CaloCellMakerToolNames += [
                    theFastShowerCellBuilderTool
                ]
                mlog.info("configure FastShowerCellBuilderTool worked")
            except Exception:
                mlog.error(
                    "could not get handle to FastShowerCellBuilderTool Quit")
                print(traceback.format_exc())
                return False

            doFastCaloSimNoise = jobproperties.CaloCellFlags.doFastCaloSimNoise(
            )
            if doFastCaloSimNoise:
                try:
                    from FastCaloSim.AddNoiseCellBuilderToolDefault import AddNoiseCellBuilderToolDefault
                    theAddNoiseCellBuilderTool = AddNoiseCellBuilderToolDefault(
                    )

                    print(theAddNoiseCellBuilderTool)

                    theCaloCellMaker += theAddNoiseCellBuilderTool
                    theCaloCellMaker.CaloCellMakerToolNames += [
                        theAddNoiseCellBuilderTool
                    ]
                    mlog.info("configure AddNoiseCellBuilderTool worked")
                except Exception:
                    mlog.error(
                        "could not get handle to AddNoiseCellBuilderTool Quit")
                    print(traceback.format_exc())
                    return False

        #
        # CaloCellContainerFinalizerTool : closing container and setting up iterators
        #

        from CaloRec.CaloRecConf import CaloCellContainerFinalizerTool
        theCaloCellContainerFinalizerTool = CaloCellContainerFinalizerTool()
        theCaloCellMaker += theCaloCellContainerFinalizerTool
        theCaloCellMaker.CaloCellMakerToolNames += [
            theCaloCellContainerFinalizerTool
        ]

        #
        # Mergeing of calo cellcontainer with sparse raw channel container with improved energies
        #

        doLArMerge = False
        if globalflags.DataSource(
        ) == 'data' and jobproperties.CaloCellFlags.doLArRawChannelMerge.statusOn and jobproperties.CaloCellFlags.doLArRawChannelMerge(
        ):
            from LArROD.LArRODFlags import larRODFlags
            if larRODFlags.readDigits() and larRODFlags.keepDSPRaw():
                doLArMerge = True
        if doLArMerge:
            try:
                from LArCellRec.LArCellRecConf import LArCellMerger
                theLArCellMerger = LArCellMerger()
            except Exception:
                mlog.error("could not get handle to LArCellMerge Quit")
                print(traceback.format_exc())
                return False
            theLArCellMerger.RawChannelsName = larRODFlags.RawChannelFromDigitsContainerName(
            )
            theCaloCellMaker += theLArCellMerger
            theCaloCellMaker.CaloCellMakerToolNames += [theLArCellMerger]

        #
        # masking of noisy and sporadic noisy cells in LAr
        #

        doNoiseMask = False
        if jobproperties.CaloCellFlags.doLArNoiseMasking.statusOn and jobproperties.CaloCellFlags.doLArNoiseMasking(
        ):
            doNoiseMask = True
        doSporadicMask = False
        if jobproperties.CaloCellFlags.doLArSporadicMasking.statusOn and jobproperties.CaloCellFlags.doLArSporadicMasking(
        ):
            doSporadicMask = True

        if doNoiseMask or doSporadicMask:
            try:
                from LArCellRec.LArCellRecConf import LArCellNoiseMaskingTool
                theLArCellNoiseMaskingTool = LArCellNoiseMaskingTool()
            except Exception:
                mlog.error(
                    "could not get handle to LArCellNoiseMaskingTool Quit")
                print(traceback.format_exc())
                return False

            if doSporadicMask:
                try:
                    from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelMasker
                    theLArSporadicNoiseMasker = LArBadChannelMasker(
                        "LArSporadicNoiseMasker")
                except Exception:
                    mlog.error("could not access bad channel tool Quit")
                    print(traceback.format_exc())
                    return False
                theLArSporadicNoiseMasker.DoMasking = True
                theLArSporadicNoiseMasker.ProblemsToMask = [
                    "sporadicBurstNoise"
                ]
                #ToolSvc += theLArSporadicNoiseMasker
                theLArCellNoiseMaskingTool.MaskingSporadicTool = theLArSporadicNoiseMasker

            if doNoiseMask:
                try:
                    from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelMasker
                    theLArNoiseMasker = LArBadChannelMasker("LArNoiseMasker")
                except Exception:
                    mlog.error("could not access bad channel tool Quit")
                    print(traceback.format_exc())
                    return False
                theLArNoiseMasker.DoMasking = True
                theLArNoiseMasker.ProblemsToMask = [
                    "highNoiseHG", "highNoiseMG", "highNoiseLG", "deadReadout",
                    "deadPhys"
                ]
                #ToolSvc+=theLArNoiseMasker
                theLArCellNoiseMaskingTool.MaskingTool = theLArNoiseMasker

            theLArCellNoiseMaskingTool.maskNoise = doNoiseMask
            theLArCellNoiseMaskingTool.maskSporadic = doSporadicMask
            # quality cut for sporadic noise masking
            theLArCellNoiseMaskingTool.qualityCut = 4000
            theCaloCellMaker += theLArCellNoiseMaskingTool
            theCaloCellMaker.CaloCellMakerToolNames += [
                theLArCellNoiseMaskingTool
            ]

        #
        #  masking of Feb problems
        #
        doBadFebMasking = False
        if jobproperties.CaloCellFlags.doLArBadFebMasking.statusOn and jobproperties.CaloCellFlags.doLArBadFebMasking(
        ):
            from AthenaCommon.GlobalFlags import globalflags
            if globalflags.DataSource() == 'data':
                doBadFebMasking = True

        if doBadFebMasking:
            try:
                from LArCellRec.LArCellRecConf import LArBadFebMaskingTool
                theLArBadFebMaskingTool = LArBadFebMaskingTool()
                if (
                        rec.doExpressProcessing()
                        or athenaCommonFlags.isOnline()
                ):  # In online or express processing, EventInfo::LArError is triggered if >=4 FEB with data corrupted
                    theLArBadFebMaskingTool.minFebInError = 4
            except Exception:
                mlog.error("could not get handle to LArBadFebMaskingTool Quit")
                print(traceback.format_exc())
                return False
            theCaloCellMaker += theLArBadFebMaskingTool

            theCaloCellMaker.CaloCellMakerToolNames += [
                theLArBadFebMaskingTool
            ]

        #
        #  emulate gain pathologies on MC
        #
        doGainPathology = False
        if jobproperties.CaloCellFlags.doLArCellGainPathology.statusOn and jobproperties.CaloCellFlags.doLArCellGainPathology(
        ):
            from AthenaCommon.GlobalFlags import globalflags
            if globalflags.DataSource() == 'geant4':
                doGainPathology = True

        if doGainPathology:
            try:
                from LArCellRec.LArCellRecConf import LArCellGainPathology
                theLArCellGainPathology = LArCellGainPathology()
            except Exception:
                mlog.error("could not get handle to LArCellGainPatholog< Quit")
                print(traceback.format_exc())
                return False
            theCaloCellMaker += theLArCellGainPathology

            theCaloCellMaker.CaloCellMakerToolNames += [
                theLArCellGainPathology
            ]

        # lar miscalibration if MC only  (should be done after finalisation)

        if not jobproperties.CaloCellFlags.doLArCellEmMisCalib.statusOn:
            # the flag has not been set, so decide a reasonable default
            # this is the old global flags should use the new one as
            # soon as monitoring does
            from AthenaCommon.GlobalFlags import globalflags
            if globalflags.DataSource() == 'data':
                doLArCellEmMisCalib = False
                mlog.info(
                    "jobproperties.CaloCellFlags.doLArMisCalib not set and real data: do not apply LArCellEmMisCalibTool"
                )
            else:
                doLArCellEmMisCalib = True
                mlog.info(
                    "jobproperties.CaloCellFlags.doLArMisCalib not set and Monte Carlo: apply LArCellEmMisCalibTool"
                )
        else:
            doLArCellEmMisCalib = jobproperties.CaloCellFlags.doLArCellEmMisCalib(
            )
            if doLArCellEmMisCalib:
                mlog.info("LArCellEmMisCalibTool requested")
            else:
                mlog.info("LArCellEmMisCalibTool explicitly not requested")

        if doLArCellEmMisCalib:
            try:
                from LArCellRec.LArCellRecConf import LArCellEmMiscalib
                theLArCellEmMiscalib = LArCellEmMiscalib("LArCellEmMiscalib")
            except Exception:
                mlog.error("could not get handle to LArCellEmMisCalib Quit")
                print(traceback.format_exc())
                return False

            # examples on how to change miscalibration. Default values are 0.005 and 0.007
            #        theLArCellEmMiscalib.SigmaPerRegion = 0.005
            #        theLArCellEmMiscalib.SigmaPerCell = 0.005

            try:
                from CaloRec.CaloRecConf import CaloCellContainerCorrectorTool
                from CaloIdentifier import SUBCALO
                theMisCalibTool = CaloCellContainerCorrectorTool(
                    "MisCalibTool",
                    CaloNums=[SUBCALO.LAREM],
                    CellCorrectionToolNames=[theLArCellEmMiscalib])
            except Exception:
                mlog.error("could not get handle to MisCalibTool Quit")
                print(traceback.format_exc())
                return False

            theCaloCellMaker += theMisCalibTool
            theCaloCellMaker.CaloCellMakerToolNames += [theMisCalibTool]

        #
        # Pedestal shift correction
        #
        doPedestalCorr = False
        if jobproperties.CaloCellFlags.doPedestalCorr.statusOn:
            from AthenaCommon.GlobalFlags import globalflags
            if jobproperties.CaloCellFlags.doPedestalCorr() and (
                    globalflags.DataSource() == 'data'
                    or jobproperties.CaloCellFlags.doPileupOffsetBCIDCorr):
                doPedestalCorr = True
                mlog.info("Apply cell level pedestal shift correction")

        if doPedestalCorr:
            try:
                from CaloCellCorrection.CaloCellPedestalCorrDefault import CaloCellPedestalCorrDefault
                theCaloCellPedestalCorr = CaloCellPedestalCorrDefault()
                theCaloCellMaker += theCaloCellPedestalCorr
                theCaloCellMaker.CaloCellMakerToolNames += [
                    theCaloCellPedestalCorr
                ]
            except Exception:
                mlog.error("could not get handle to CaloCellPedestalCorr")
                print(traceback.format_exc())

        #
        # HV correction for offline reprocessing, reading HV from Cool-DCS database
        #
        doHVCorr = False
        from AthenaCommon.DetFlags import DetFlags
        if DetFlags.dcs.LAr_on():
            if jobproperties.CaloCellFlags.doLArHVCorr.statusOn:
                from AthenaCommon.GlobalFlags import globalflags
                if jobproperties.CaloCellFlags.doLArHVCorr(
                ) and globalflags.DataSource() == 'data':
                    doHVCorr = True
                    mlog.info(
                        "Redoing HV correction at cell level from COOL/DCS database"
                    )

        if doHVCorr:
            from LArCellRec.LArCellRecConf import LArCellContHVCorrTool
            theLArCellHVCorrTool = LArCellContHVCorrTool()

            #theCaloCellMaker += theHVCorrTool
            theCaloCellMaker.CaloCellMakerToolNames += [theLArCellHVCorrTool]

        #
        # correction to undo online calibration and apply new LAr electronics calibration for ADC->MeV conversion
        #
        doLArRecalibration = False
        if jobproperties.CaloCellFlags.doLArRecalibration.statusOn:
            from AthenaCommon.GlobalFlags import globalflags
            from LArConditionsCommon.LArCondFlags import larCondFlags
            if jobproperties.CaloCellFlags.doLArRecalibration(
            ) and globalflags.DataSource() == 'data' and (
                    not larCondFlags.SingleVersion()):
                doLArRecalibration = True
                mlog.info("Redoing LAr electronics calibration for ADC->MeV")

        if doLArRecalibration:

            # get tool for cell recalibration
            try:
                from LArCellRec.LArCellRecConf import LArCellRecalibration
                theLArCellRecalibration = LArCellRecalibration(
                    "LArCellRecalibration")
            except Exception:
                mlog.error("could not get handle to LArCellRecalibration Quit")
                print(traceback.format_exc())
                return False

            # get new ADC2MeVTool
            try:
                from LArRecUtils.LArADC2MeVToolDefault import LArADC2MeVToolDefault
                theLArADC2MeVToolDefault = LArADC2MeVToolDefault()
            except Exception:
                mlog.error(
                    "Could not get handle to LArADC2MeVToolDefault Quit")
                print(traceback.format_exc())
                return False
            ToolSvc += theLArADC2MeVToolDefault

            # get old  ADC2MeVTool
            try:
                from LArRecUtils.LArADC2MeVToolOnline import LArADC2MeVToolOnline
                theLArADC2MeVToolOnline = LArADC2MeVToolOnline()
            except Exception:
                mlog.error("Could not get handle to LArADC2MeVToolOnline Quit")
                print(traceback.format_exc())
                return False
            ToolSvc += theLArADC2MeVToolOnline

            theLArCellRecalibration.adc2MeVTool = theLArADC2MeVToolDefault
            theLArCellRecalibration.adc2MeVToolOnline = theLArADC2MeVToolOnline

            try:
                from CaloRec.CaloRecConf import CaloCellContainerCorrectorTool
                from CaloIdentifier import SUBCALO
                theLArRecalibrationTool = CaloCellContainerCorrectorTool(
                    "LArRecalibrationTool",
                    CaloNums=[SUBCALO.LAREM, SUBCALO.LARHEC, SUBCALO.LARFCAL],
                    CellCorrectionToolNames=[theLArCellRecalibration])
            except Exception:
                mlog.error("could not get handle to HVCorrTool Quit")
                print(traceback.format_exc())
                return False
            theCaloCellMaker += theLArRecalibrationTool
            theCaloCellMaker.CaloCellMakerToolNames += [
                theLArRecalibrationTool
            ]

        #
        # Correction for MinBias energy shift for MC pileup reco
        #
        doMinBiasAverage = False
        if jobproperties.CaloCellFlags.doMinBiasAverage.statusOn:
            from AthenaCommon.GlobalFlags import globalflags
            from AthenaCommon.BeamFlags import jobproperties
            if jobproperties.CaloCellFlags.doMinBiasAverage(
            ) and globalflags.DataSource() == 'geant4' and (
                    not jobproperties.Beam.zeroLuminosity()):
                doMinBiasAverage = True

        if doMinBiasAverage:

            try:
                from CaloTools.CaloMBAverageToolDefault import CaloMBAverageToolDefault
                theCaloMBAverageTool = CaloMBAverageToolDefault()
            except Exception:
                mlog.error("could not get handle to CaloMBAverageTool  Quit")
                print(traceback.format_exc())
                return False
            ToolSvc += theCaloMBAverageTool

            try:
                from CaloCellCorrection.CaloCellCorrectionConf import CaloCellMBAverageCorr
                theCaloCellMBAverageCorr = CaloCellMBAverageCorr(
                    "CaloCellMBAverageCorr")
                theCaloCellMBAverageCorr.CaloMBAverageTool = theCaloMBAverageTool
            except Exception:
                mlog.error(
                    "could not get handle to  CaloCellMBAverageCorr  Quit")
                print(traceback.format_exc())
                return False

            try:
                from CaloRec.CaloRecConf import CaloCellContainerCorrectorTool
                from CaloIdentifier import SUBCALO
                theMBAverageTool = CaloCellContainerCorrectorTool(
                    "MBAverageTool",
                    CaloNums=[SUBCALO.NSUBCALO],
                    CellCorrectionToolNames=[theCaloCellMBAverageCorr])
            except Exception:
                mlog.error(
                    "could not get handle to CaloCellContainerCorrectorTool/MBAverageTool Quit"
                )
                print(traceback.format_exc())
                return False

            theCaloCellMaker += theMBAverageTool
            theCaloCellMaker.CaloCellMakerToolNames += [theMBAverageTool]

        #
        # Correction for dead cells, where we average the energy density of neighbor cells
        #
        doNeighborsAverage = False
        if jobproperties.CaloCellFlags.doDeadCellCorr.statusOn:
            if jobproperties.CaloCellFlags.doDeadCellCorr():
                doNeighborsAverage = True

        if doNeighborsAverage:
            try:
                from CaloCellCorrection.CaloCellCorrectionConf import CaloCellNeighborsAverageCorr
                theCaloCellNeighborsAverageCorr = CaloCellNeighborsAverageCorr(
                    "CaloCellNeighborsAverageCorr")
                theCaloCellNeighborsAverageCorr.testMode = False
            except Exception:
                mlog.error(
                    "could not get handle to  CaloCellNeighborsAverageCorr  Quit"
                )
                print(traceback.format_exc())
                return False
            theCaloCellMaker += theCaloCellNeighborsAverageCorr
            theCaloCellMaker.CaloCellMakerToolNames += [
                theCaloCellNeighborsAverageCorr
            ]

        #
        # correction for missing Febs based on L1 readout
        doLArDeadOTXCorr = False
        if jobproperties.CaloCellFlags.doLArDeadOTXCorr.statusOn and jobproperties.CaloCellFlags.doLArCreateMissingCells.statusOn:
            if jobproperties.CaloCellFlags.doLArDeadOTXCorr(
            ) and jobproperties.CaloCellFlags.doLArCreateMissingCells(
            ) and doStandardCellReconstruction:
                if rec.doTrigger():
                    doLArDeadOTXCorr = True
                else:
                    if globalflags.DataSource.get_Value(
                    ) != 'geant4':  #warning only if not MC
                        mlog.warning(
                            "Trigger is switched off. Can't run deadOTX correction."
                        )

        if doLArDeadOTXCorr:

            try:
                from LArCellRec.LArCellDeadOTXCorrToolDefault import LArCellDeadOTXCorrToolDefault
                theLArCellDeadOTXCorr = LArCellDeadOTXCorrToolDefault()
            except Exception:
                mlog.error("could not get handle to LArCellDeadOTXCorr Quit")
                print(traceback.format_exc())

            theCaloCellMaker += theLArCellDeadOTXCorr
            theCaloCellMaker.CaloCellMakerToolNames += [theLArCellDeadOTXCorr]

        if jobproperties.CaloCellFlags.doCaloCellEnergyCorr(
        ) and globalflags.DataSource(
        ) == 'data' and not athenaCommonFlags.isOnline():

            try:
                from CaloCellCorrection.CaloCellCorrectionConf import CaloCellEnergyRescaler
                theCCERescalerTool = CaloCellEnergyRescaler()
                theCCERescalerTool.Folder = "/LAR/CellCorrOfl/EnergyCorr"
                from IOVDbSvc.CondDB import conddb
                # conddb.addFolder("","/LAR/CellCorrOfl/EnergyCorr<tag>EnergyScale-00</tag><db>sqlite://;schema=escale.db;dbname=COMP200</db>")
                conddb.addFolder("LAR_OFL",
                                 "/LAR/CellCorrOfl/EnergyCorr",
                                 className="AthenaAttributeList")
                theCaloCellMaker += theCCERescalerTool
                theCaloCellMaker.CaloCellMakerToolNames += [theCCERescalerTool]
            except Exception:
                mlog.error(
                    "could not get handle to CaloCellEnergyRescaler Quit")
                print(traceback.format_exc())
                return False
            pass

        if jobproperties.CaloCellFlags.doCaloCellTimeCorr(
        ) and globalflags.DataSource(
        ) == 'data' and not athenaCommonFlags.isOnline():
            try:
                from CaloCellCorrection.CaloCellCorrectionConf import CaloCellTimeCorrTool
                theLArTimeCorr = CaloCellTimeCorrTool()
                theLArTimeCorr.Folder = "/LAR/TimeCorrectionOfl/CellTimeOffset"
                from IOVDbSvc.CondDB import conddb
                # conddb.addFolder("","/LAR/TimeCorrectionOfl/CellTimeOffset<tag>LARTimeCorrectionOflCellTimeOffset-empty</tag><db>sqlite://;schema=timecorr.db;dbname=COMP200</db>")
                conddb.addFolder("LAR_OFL",
                                 "/LAR/TimeCorrectionOfl/CellTimeOffset",
                                 className="AthenaAttributeList")
                theCaloCellMaker.CaloCellMakerToolNames += [theLArTimeCorr]

            except Exception:
                mlog.error("could not get handle to CaloCellTimeCorrTool Quit")
                print(traceback.format_exc())
                return False

            pass

        # make lots of checks (should not be necessary eventually)
        # to print the check add:

        from CaloRec.CaloRecConf import CaloCellContainerCheckerTool
        theCaloCellContainerCheckerTool = CaloCellContainerCheckerTool()
        # FIXME
        # theCaloCellContainerCheckerTool.OutputLevel=DEBUG

        theCaloCellMaker += theCaloCellContainerCheckerTool
        theCaloCellMaker.CaloCellMakerToolNames += [
            theCaloCellContainerCheckerTool
        ]

        #

        # sets output key
        theCaloCellMaker.CaloCellsOutputName = self.outputKey()

        # register output in objKeyStore
        from RecExConfig.ObjKeyStore import objKeyStore
        objKeyStore.addStreamESD(self.outputType(), self.outputKey())

        # Also note that we produce it as a transient output.
        objKeyStore.addTransient(self.outputType(), self.outputKey())

        from TileRecUtils.TileDQstatusAlgDefault import TileDQstatusAlgDefault
        TileDQstatusAlgDefault(TileRawChannelContainer=rawChannelContainer)

        # now add algorithm to topSequence
        # this should always come at the end

        mlog.info(" now adding CaloCellMaker to topSequence")

        from AthenaCommon.AlgSequence import AlgSequence
        topSequence = AlgSequence()

        topSequence += theCaloCellMaker

        return True