Exemple #1
0
    def __init__(self, name = "EFCaloHypoNoiseConfig",ef_thr=20*GeV,etaMin=0,etaMax=10):
        super( EFCaloHypoNoiseConfig, self ).__init__( name )

        self.Etcut = ef_thr
        self.BadFEBCut=3
        if 'COMP200' not in conddb.GetInstance() and not conddb.isMC:
           if not hasattr(svcMgr.ToolSvc, "KnownBADFEBsTool"):
              theBadFebTool=LArBadChanTool("KnownBADFEBsTool")
              theBadFebTool.CoolMissingFEBsFolder="/LAR/BadChannels/KnownBADFEBs"
              havefolder=False
              for fld in conddb.iovdbsvc.Folders:
                 if "KnownBADFEBs" in fld: havefolder=True
              pass
              if not havefolder:
                 conddb.addFolder("LAR_ONL","/LAR/BadChannels/KnownBADFEBs")   
              svcMgr.ToolSvc+=theBadFebTool
           else:
              theBadFebTool=svcMgr.ToolSvc.KnownBADFEBsTool
           if not hasattr(svcMgr.ToolSvc, "KnownMNBFEBsTool"):
              theMNBFebTool=LArBadChanTool("KnownMNBFEBsTool")
              theMNBFebTool.CoolMissingFEBsFolder="/LAR/BadChannels/KnownMNBFEBs"
              havefolder=False
              for fld in conddb.iovdbsvc.Folders:
                 if "KnownMNBFEBs" in fld: havefolder=True
              pass
              if not havefolder:
                 conddb.addFolder("LAR_ONL","/LAR/BadChannels/KnownMNBFEBs")   
              svcMgr.ToolSvc+=theMNBFebTool
           else:
              theMNBFebTool=svcMgr.ToolSvc.KnownMNBFEBsTool
           theLArNoisyROTool=LArNoisyROTool(SaturatedCellTightCut=20,MNBLooseCut=5,MNBTightCut=17,KnownBADFEBsTool=theBadFebTool,KnownMNBFEBsTool=theMNBFebTool)
        else:   
           theLArNoisyROTool=LArNoisyROTool(SaturatedCellTightCut=20,MNBLooseCut=5,MNBTightCut=17)
        self.NoiseTool = theLArNoisyROTool
def make_bad_channel_tool(name, badfebs=[]):
    from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
    febfile = ''
    if badfebs:
        febfile = name + '.badfebs'
        f = open(febfile, 'w')
        for (feb, err) in badfebs:
            print >> f, feb[0], feb[1], feb[2], feb[3], err
        f.close()
    return LArBadChanTool(name,
                          ReadFromASCII=True,
                          WriteEmptyFolders=True,
                          CoolFolder='',
                          ComplementaryCoolFolder='',
                          CoolMissingFEBsFolder='',
                          FEBfile=febfile)
Exemple #3
0
include.block("TrigT2CaloCommon/CaloCellMasking.py")

from AthenaCommon.AppMgr import ToolSvc  #if not already imported
from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool, LArBadChannelMasker

ToolSvc += LArBadChanTool("MyBadChanTool")
ToolSvc.MyBadChanTool.ReadFromASCII = False  #Not necessary if you have already produced a database file
ToolSvc.MyBadChanTool.ComplementaryCoolFolder = "/LAR/BadChannels/BadChannelsOnl"
#ToolSvc.MyBadChanTool.OutputLevel=VERBOSE
#ToolSvc.MyBadChanTool.OutputLevel=DEBUG

#The masker tool name must be "LArBadChannelMasker", the same as retrieved in LArCellCont.cxx
ToolSvc += LArBadChannelMasker("LArBadChannelMasker")
ToolSvc.LArBadChannelMasker.ProblemsToMask = [
    "unstable", "short", "highNoiseHG", "highNoiseMG", "highNoiseLG",
    "problematicForUnknownReason"
]  #See LArBadChanBitPacking.cxx for the list of strings that can be used.
ToolSvc.LArBadChannelMasker.DoMasking = True  #Masking can easily be turned on and off here.
#ToolSvc.LArBadChannelMasker.OutputLevel=DEBUG
ToolSvc.LArBadChannelMasker.TheLArBadChanTool = ToolSvc.MyBadChanTool  #Tell the Masker to use the LArBadChanTool that was just configured.

#IOVDbSvc=theApp.service('IOVDbSvc')
#if ( svcMgr.IOVDbSvc.GlobalTag!="COMCOND-002-00" and svcMgr.IOVDbSvc.GlobalTag!="COMCOND-003-00" and svcMgr.IOVDbSvc.GlobalTag!="COMCOND-004-00" and svcMgr.IOVDbSvc.GlobalTag!="COMCOND-005-00" ):
#else:
if not conddb.folderRequested('/LAR/BadChannels/BadChannels'):
    conddb.addFolder(LArDB, "/LAR/BadChannels/BadChannels")
conddb.addFolder(LArDB, "/LAR/BadChannels/BadChannelsOnl")

from TileConditions.TileInfoConfigurator import TileInfoConfigurator
tIC = TileInfoConfigurator()
tIC.setupCOOL()
Exemple #4
0
#                          Correction                                #
#                                                                    #
######################################################################
# Not done on splitted caliwaves yet
if CorrectBadChannels:

    from LArCalibUtils.LArCalibUtilsConf import LArCalibPatchingAlg_LArCaliWaveContainer_
    theLArCaliWavePatcher = LArCalibPatchingAlg_LArCaliWaveContainer_(
        "LArCaliWavePatcher")
    theLArCaliWavePatcher.ContainerKey = KeyOutput
    #theLArCaliWavePatcher.PatchMethod="PhiNeighbor" ##take the first neigbour
    theLArCaliWavePatcher.PatchMethod = "PhiAverage"  ##do an aveage in phi after removing bad and empty event
    theLArCaliWavePatcher.OutputLevel = INFO

    from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
    theLArBadChannelTool = LArBadChanTool()
    theLArBadChannelTool.OutputLevel = DEBUG
    theLArBadChannelTool.CoolFolder = BadChannelsFolder
    theLArBadChannelTool.CoolMissingFEBsFolder = MissingFEBsFolder
    ToolSvc += theLArBadChannelTool

    from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelMasker
    theLArRCBMasker = LArBadChannelMasker("LArRCBMasker")
    theLArRCBMasker.DoMasking = True
    theLArRCBMasker.ProblemsToMask = [
        "deadCalib",
        "deadReadout",
        "deadPhys",
        "almostDead",
        "short",
    ]
from CaloRec.CaloRecConf import CBNTAA_CaloCell
CBNT_LArCell = CBNTAA_CaloCell("CBNT_LArCell")
CBNT_AthenaAware += CBNT_LArCell
from CaloIdentifier import SUBCALO
CBNT_LArCell.CaloNums = [SUBCALO.LAREM, SUBCALO.LARHEC, SUBCALO.LARFCAL]
# cell by cell info
CBNT_LArCell.MaxNCells = 200000
CBNT_LArCell.Suffix = "LAr"
CBNT_LArCell.SaveDetInfo = True
CBNT_LArCell.SaveTimeInfo = True
CBNT_LArCell.SaveId = True
CBNT_LArCell.SaveQualityInfo = True
CBNT_LArCell.CellSigmaCut = 3.
from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
from AthenaCommon.AppMgr import ToolSvc
ToolSvc += LArBadChanTool()
from CaloTools.CaloNoiseToolDefault import CaloNoiseToolDefault
theCaloNoiseTool = CaloNoiseToolDefault()
ToolSvc += theCaloNoiseTool
CBNT_LArCell.NoiseTool = theCaloNoiseTool

#CBNT for digits
from LArROD.LArRODConf import CBNTAA_LArDigits
theCBNTAA_LArDigits = CBNTAA_LArDigits("CBNTAA_LArDigits")
theCBNTAA_LArDigits.MaxChannels = 200000
theCBNTAA_LArDigits.NEvents = -1
theCBNTAA_LArDigits.DumpIterResults = True
theCBNTAA_LArDigits.SaveId = True
theCBNTAA_LArDigits.SaveSCAAddress = False
theCBNTAA_LArDigits.DumpCut = 0
theCBNTAA_LArDigits.ContainerKey = "LArDigitContainer_Thinned"
Exemple #6
0
    from AthenaCommon.GlobalFlags import GlobalFlags
    #need this set_data() uncommented for real data, commented for monte carlo
    GlobalFlags.DataSource.set_data()
    include( "RecExCond/AllDet_detDescr.py")

    if MissingETData.UseCaloNoiseTool == True:
        from CaloTools.CaloNoiseToolDefault import CaloNoiseToolDefault
        theCaloNoiseTool=CaloNoiseToolDefault()
        from AthenaCommon.AppMgr import ToolSvc 		        	   
        ToolSvc+=theCaloNoiseTool
        MissingETData.CaloNoiseTool = theCaloNoiseTool
        #theCaloNoiseTool.OutputLevel = 1

    if MissingETData.UseBadChannelTool == True:
        from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
        theLArBadChanTool=LArBadChanTool("LArBadChanTool")
        theLArBadChanTool.OutputLevel=DEBUG
        #can put in bad channels by hand in text files by setting this true and specifying names of text files, see LArBadChanTool documentation
        theLArBadChanTool.ReadFromASCII=False
        #have to specify the these names iff ReadFromASCII=True
        #theLArBadChanTool.EMBAfile   = 'EMBA.txt'
        #theLArBadChanTool.EMBCfile   = 'EMBC.txt'
        #theLArBadChanTool.EMECAfile  = 'EMECA.txt'
        #theLArBadChanTool.EMECCfile  = 'EMECC.txt'
        #theLArBadChanTool.HECAfile   = 'HECA.txt'
        #theLArBadChanTool.HECCfile   = 'HECC.txt'
        #theLArBadChanTool.FCALAfile  = 'FCALA.txt'
        #theLArBadChanTool.FCALCfile  = 'FCALC.txt'
        #theLArBadChanTool.FEBfile    = 'FEB.txt'
        ToolSvc+=theLArBadChanTool
        MissingETData.BadChannelTool = theLArBadChanTool
Exemple #7
0
pass
##LAr####################################################################################
#preopts
#conddb.addFolderWithTag('LAR_OFL','/LAR/BadChannelsOfl/BadChannels','LArBadChannelsOflBadChannels-IOVDEP-00',forceData=True)
#conddb.addFolderWithTag('LAR_OFL','/LAR/BadChannelsOfl/MissingFEBs','LArBadChannelsOflMissingFEBs-IOVDEP-00',forceData=True)
#if not hasattr (ServiceMgr.ToolSvc, 'LArBadChanTool'):
#    from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
#    ServiceMgr.ToolSvc += LArBadChanTool()
#    ServiceMgr.ToolSvc.LArBadChanTool.CoolFolder="/LAR/BadChannelsOfl/BadChannels"
#    ServiceMgr.ToolSvc.LArBadChanTool.CoolMissingFEBsFolder="/LAR/BadChannelsOfl/MissingFEBs"
conddb.blockFolder('/LAR/BadChannels/BadChannels')
conddb.addFolderWithTag('LAR_OFL',
                        '/LAR/BadChannels/BadChannels',
                        'LArBadChannelsBadChannels-IOVDEP-01',
                        force=True)
conddb.blockFolder('/LAR/BadChannels/MissingFEBs')
conddb.addFolderWithTag('LAR_OFL',
                        '/LAR/BadChannels/MissingFEBs',
                        'LArBadChannelsMissingFEBs-IOVDEP-01',
                        force=True)
if not hasattr(ServiceMgr.ToolSvc, 'LArBadChanTool'):
    from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
    ServiceMgr.ToolSvc += LArBadChanTool()
    ServiceMgr.ToolSvc.LArBadChanTool.CoolFolder = "/LAR/BadChannels/BadChannels"
    ServiceMgr.ToolSvc.LArBadChanTool.CoolMissingFEBsFolder = "/LAR/BadChannels/MissingFEBs"
##Tile####################################################################################
pass
##Muons###################################################################################
#from MDT_Digitization.MDT_DigitizationConf import MdtDigitizationTool as mdt
#mdt.UseDeadChamberSvc = True
Exemple #8
0
# --- for athena online running ---
if 'EventBlockSize' not in dir():
    EventBlockSize = 0

###### LAr FEBMon Tool Configuration ###############
from LArMonTools.LArMonToolsConf import LArFEBMon

conddb.addFolder('LAR', '/LAR/Configuration/DSPThreshold/Thresholds')

theLArFEBMon = LArFEBMon(name="LArFEBMon",
                         ProcessNEvents=EventBlockSize,
                         IgnoreMissingHeaderPS=False,
                         IgnoreMissingHeaderEMB=False)
ToolSvc += theLArFEBMon
LArMon.AthenaMonTools += [theLArFEBMon]

# BadChannelTool configuration
from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
theLArBadChannelTool = LArBadChanTool()
theLArBadChannelTool.ReadFromASCII = False
ToolSvc += theLArBadChannelTool
ToolSvc.LArFEBMon.LArBadChannelTool = theLArBadChannelTool

#to change an option later, do e.g
#ToolSvc.LArFEBMon.maxOfTimingHisto =100
#ToolSvc.LArFEBMon.OutputLevel =DEBUG
## get a handle to the ApplicationManager, to the ServiceManager and to the ToolSvc
from AthenaCommon.AppMgr import (theApp, ServiceMgr as svcMgr,ToolSvc)

BadChanTag=join(split(BadChanFolder, '/'),'') + TagPostfix
FEBTag=join(split(FEBFolder, '/'),'') + TagPostfix

DBConnection = "<dbConnection>sqlite://;schema=BadChannels.db;dbname=CONDBR2</dbConnection>"
DBBadChanFolder = BadChanFolder + "<tag>" + BadChanTag + "</tag>" + DBConnection
DBFebFolder     = FEBFolder     + "<tag>" + FEBTag     + "</tag>" + DBConnection

svcMgr.IOVDbSvc.Folders+=[DBBadChanFolder]
svcMgr.IOVDbSvc.Folders+=[DBFebFolder]

#svcMgr.IOVDbSvc.Folders+=["/LAR/BadChannels/BadChannels<tag>LARBadChannelsBadChannels-M6-01</tag><dbConnection>sqlite://;schema=BadChannels.db;dbname=CONDBR2</dbConnection>" ]
#svcMgr.IOVDbSvc.Folders+=["/LAR/BadChannels/MissingFEBs<tag>LARBadChannelsMissingFEBs-M6-01</tag><dbConnection>sqlite://;schema=BadChannels.db;dbname=CONDBR2</dbConnection>" ]
#conddb.addFolder("LAR","/LAR/BadChannels/BadChannels")
svcMgr.IOVDbSvc.GlobalTag=GlobalTag

from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelToolTest
theLArBadChannels=LArBadChannelToolTest()
#theLArBadChannels.FileName="bc_out.txt"
topSequence+=theLArBadChannels

from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
theLArBadChannelTool=LArBadChanTool()
theLArBadChannelTool.OutputLevel=DEBUG
theLArBadChannelTool.DumpCache = True
theLArBadChannelTool.CoolMissingFEBsFolder = "/LAR/BadChannels/MissingFEBs" # read missing FEBs folder
#theLArBadChannelTool.CoolMissingFEBsFolder = "" # deactivate missing FEBs folder
ToolSvc+=theLArBadChannelTool
Exemple #10
0
## theByteStreamInputSvc.FullFileName=["/home/wlampl/LArOFIter/ramp/inputs/daq.Ramp.0029146.No.Streaming.LB0000.EB-EMBA._0001.data"]

## theByteStreamInputSvc.MaxBadEvents=0

#That's the dumper, keep for now
from LArCalibTest.LArCalibTestConf import DumpCaloBadChannels
theDumper = DumpCaloBadChannels()
theDumper.FileName = "list.txt"
topSequence += theDumper

#Thats the registration algo
#from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelDBAlg
#topSequence += LArBadChannelDBAlg( "BadChanAlg" )

from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
theLArBadChannelTool = LArBadChanTool()
theLArBadChannelTool.ReadFromASCII = False
theLArBadChannelTool.DumpCache = True
#theLArBadChannelTool.ASCIIFileName="/home/wlampl/LArCondPatcher/dead_dummy.txt"
#theLArBadChannelTool.EMBAfile ="/afs/cern.ch/user/t/todorov/scratch0/testarea/rel_5/LArCalorimeter/LArBadChannelTool/share/noisePb_29142.txt"
#theLArBadChannelTool.EMBCfile ="/afs/cern.ch/user/t/todorov/scratch0/testarea/rel_5/LArCalorimeter/LArBadChannelTool/share/noisePb_29142.txt"
theLArBadChannelTool.OutputLevel = DEBUG
ToolSvc += theLArBadChannelTool

svcMgr.IOVDbSvc.Folders += [
    "/LAR/BadChannels/BadChannels<tag>LARBadChannelsBadChannels-M6-01</tag><dbConnection>sqlite://;schema=BadChannels.db;dbname=CONDBR2</dbConnection>"
]
svcMgr.IOVDbSvc.Folders += [
    "/LAR/BadChannels/MissingFEBs<tag>LARBadChannelsMissingFEBs-M6-01</tag><dbConnection>sqlite://;schema=BadChannels.db;dbname=CONDBR2</dbConnection>"
]
svcMgr.IOVDbSvc.GlobalTag = "CONDBR2-ES1PA-2014-01"
if 'EventBlockSize' not in dir():
    EventBlockSize = 0

###### LAr Coverage Tool Configuration ###############
from LArMonTools.LArMonToolsConf import LArCoverage
theLArCoverage = LArCoverage(name="LArCoverage",
                             ProcessNEvents=EventBlockSize,
                             LArDigitContainerKey=LArMonFlags.LArDigitKey(),
                             LArBadChannelMask=theLArBadChannelsMasker,
                             Nevents=40)
ToolSvc += theLArCoverage
LArMon.AthenaMonTools += [theLArCoverage]

# BadChannelTool configuration
from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
theLArBadChannelTool = LArBadChanTool()
theLArBadChannelTool.ReadFromASCII = False
ToolSvc += theLArBadChannelTool
ToolSvc.LArCoverage.LArBadChannelTool = theLArBadChannelTool

# KnownMNBFEBsTool configuration
if 'COMP200' not in conddb.GetInstance():
    theMNBFebTool = LArBadChanTool("KnownMNBFEBsTool")
    theMNBFebTool.CoolMissingFEBsFolder = "/LAR/BadChannels/KnownMNBFEBs"
    ToolSvc += theMNBFebTool
    ToolSvc.LArCoverage.LArKnownMNBFEBsTool = theMNBFebTool

# CaloNoiseTool configuration
from CaloTools.CaloNoiseToolDefault import CaloNoiseToolDefault
theLArCoverageCaloNoiseTool = CaloNoiseToolDefault()
ToolSvc += theLArCoverageCaloNoiseTool
Exemple #12
0
svcMgr.EventSelector.FirstLB           = LBNumber

## get a handle to the default top-level algorithm sequence
from AthenaCommon.AlgSequence import AlgSequence 
topSequence = AlgSequence()  

## get a handle to the ApplicationManager, to the ServiceManager and to the ToolSvc
from AthenaCommon.AppMgr import (theApp, ServiceMgr as svcMgr,ToolSvc)


if "sqlite" in dir():
    conddb.addFolder("","/LAR/BadChannelsOfl/MissingFEBs<db>sqlite://;schema="+sqlite+";dbname="+DBInstance+"</db><tag>LARBadChannelsOflMissingFEBs-RUN2-UPD3-01</tag>")
else:
    conddb.addFolder("LAR_OFL","/LAR/BadChannelsOfl/MissingFEBs")#<tag>LARBadChannelsMissingFEBs-empty</tag>")
                 
svcMgr.IOVDbSvc.GlobalTag="CONDBR2-ES1PA-2017-04" 


from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
theLArBadChannelTool=LArBadChanTool()
theLArBadChannelTool.CoolFolder=""
theLArBadChannelTool.CoolMissingFEBsFolder="/LAR/BadChannelsOfl/MissingFEBs"
ToolSvc+=theLArBadChannelTool



from LArBadChannelTool.LArBadChannelToolConf import LArBadFeb2Ascii
theLArBadFeb2Ascii=LArBadFeb2Ascii()
theLArBadFeb2Ascii.FileName=OutputFile
topSequence+=theLArBadFeb2Ascii
Exemple #13
0
    def configure(self):
        from AthenaCommon.Logging import logging
        mlog = logging.getLogger('CaloCellGetter_DigiHSTruth::configure:')
        mlog.info('entering')
        from CaloRec.CaloCellFlags import jobproperties
        doStandardCellReconstruction = True

        # get handle to upstream object
        # handle tile

        if doStandardCellReconstruction:
            # handle LAr
            import traceback
            try:
                from LArROD.LArRawChannelGetter_DigiHSTruth import LArRawChannelGetter_DigiHSTruth
                theLArRawChannelGetter = LArRawChannelGetter_DigiHSTruth()
            except:
                mlog.error(
                    "could not get handle to LArRawChannel_DigiHSTruth Quit")
                print traceback.format_exc()
                return False

            if not theLArRawChannelGetter.usable():
                if not self.ignoreConfigError():
                    mlog.error(
                        "LArRawChannelGetter_DigiHSTruth unusable. Quit.")
                    return False
                else:
                    mlog.error(
                        "LArRawChannelGetter_DigiHSTruth unusable. Continue nevertheless"
                    )

        # 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:
            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

            from RecExConfig.RecFlags import rec

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

                if jobproperties.CaloCellFlags.doLArCreateMissingCells():
                    # bad channel tools
                    try:
                        from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
                        theLArBadChannelTool = LArBadChanTool()
                    except:
                        mlog.error("could not access bad channel tool Quit")
                        print traceback.format_exc()
                        return False
                    ToolSvc += theLArBadChannelTool
                    theLArCellBuilder.addDeadOTX = True
                    theLArCellBuilder.badChannelTool = theLArBadChannelTool

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

                from AthenaCommon.GlobalFlags import globalflags
                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"
                    if not hasattr(ToolSvc, "TileBeamInfoProvider"):
                        from TileRecUtils.TileRecUtilsConf import TileBeamInfoProvider
                        ToolSvc += TileBeamInfoProvider()
                    ToolSvc += theTileCellBuilder
                    theCaloCellMaker.CaloCellMakerToolNames += [
                        theTileCellBuilder
                    ]
                except:
                    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()
        ToolSvc += theCaloCellContainerFinalizerTool
        theCaloCellMaker.CaloCellMakerToolNames += [
            theCaloCellContainerFinalizerTool
        ]
        from RecExConfig.RecFlags import rec

        #
        # 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:
                mlog.error(
                    "could not get handle to LArCellNoiseMaskingTool Quit")
                print traceback.format_exc()
                return False

            # bad channel tools
            try:
                from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
                theLArBadChannelTool = LArBadChanTool()
            except:
                mlog.error("could not access bad channel tool Quit")
                print traceback.format_exc()
                return False
            ToolSvc += theLArBadChannelTool

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

            if doNoiseMask:
                try:
                    from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelMasker
                    theLArNoiseMasker = LArBadChannelMasker("LArNoiseMasker")
                except:
                    mlog.error("could not access bad channel tool Quit")
                    print traceback.format_exc()
                    return False
                theLArNoiseMasker.TheLArBadChanTool = theLArBadChannelTool
                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
            ToolSvc += theLArCellNoiseMaskingTool
            theCaloCellMaker.CaloCellMakerToolNames += [
                theLArCellNoiseMaskingTool
            ]

        #
        #  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:
                mlog.error("could not get handle to LArCellGainPatholog< Quit")
                print traceback.format_exc()
                return False
            ToolSvc += 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
        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:
                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:
                mlog.error("could not get handle to MisCalibTool Quit")
                print traceback.format_exc()
                return False

            ToolSvc += 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")

        import os
        #if doPedestalCorr and os.getenv("CMTPATH") and "AtlasTrigger" in os.getenv("CMTPATH"):
        if doPedestalCorr:
            try:
                from CaloCellCorrection.CaloCellPedestalCorrDefault import CaloCellPedestalCorrDefault
                theCaloCellPedestalCorr = CaloCellPedestalCorrDefault()
                ToolSvc += theCaloCellPedestalCorr
                theCaloCellMaker.CaloCellMakerToolNames += [
                    theCaloCellPedestalCorr
                ]
            except:
                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.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:
                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:
                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:
                mlog.error(
                    "could not get handle to CaloCellContainerCorrectorTool/MBAverageTool Quit"
                )
                print traceback.format_exc()
                return False

            ToolSvc += 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:
                mlog.error(
                    "could not get handle to  CaloCellNeighborsAverageCorr  Quit"
                )
                print traceback.format_exc()
                return False
            ToolSvc += 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:
                mlog.error("could not get handle to LArCellDeadOTXCorr Quit")
                print traceback.format_exc()

            ToolSvc += 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()

        ToolSvc += 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())

        # 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
Exemple #14
0
def getLArPileUpTool(name='LArPileUpTool', **kwargs): ## useLArFloat()=True,isOverlay()=False,outputKey='LArDigitContainer_MC'):
    from AthenaCommon.Logging import logging
    mlog = logging.getLogger( 'LArPileUpToolDefault:' )
    mlog.info(" ---- in getLArPileUpTool " )
    # the LAr and Calo detector description package
    ## FIXME includes to be replaced by confGetter configuration.
    if not isOverlay():
        from AthenaCommon.Resilience import protectedInclude
        protectedInclude( "CaloDetMgrDetDescrCnv/CaloDetMgrDetDescrCnv_joboptions.py" )
        protectedInclude( "LArDetDescr/LArDetDescr_joboptions.py" )
        protectedInclude("LArConditionsCommon/LArConditionsCommon_MC_jobOptions.py")
    from Digitization.DigitizationFlags import digitizationFlags
    kwargs.setdefault('NoiseOnOff', digitizationFlags.doCaloNoise.get_Value() )
    kwargs.setdefault('RndmSvc', digitizationFlags.rndmSvc.get_Value() )
    digitizationFlags.rndmSeedList.addSeed("LArDigitization", 1234, 5678 )
    kwargs.setdefault('DoDigiTruthReconstruction',digitizationFlags.doDigiTruth())

    if digitizationFlags.doXingByXingPileUp():
        kwargs.setdefault('FirstXing', -751 )
        kwargs.setdefault('LastXing', 101 )

    from LArDigitization.LArDigitizationFlags import jobproperties
    # check if using high gain for Fcal or not
    if  (not jobproperties.LArDigitizationFlags.useFcalHighGain()) and (not isOverlay()):
        mlog.info("do not use high gain in Fcal digitization ")
        kwargs.setdefault('HighGainThreshFCAL', 0 )
    else:
        mlog.info("use high gain in Fcal digitization or overlay job")

    # check if using high gain for EMEC IW or not
    if (not jobproperties.LArDigitizationFlags.useEmecIwHighGain()) and (not isOverlay()):
       mlog.info("do not use high gain in EMEC IW digitization ")
       kwargs.setdefault('HighGainThreshEMECIW',0)

    kwargs.setdefault('RndmEvtOverlay', isOverlay() )
    kwargs.setdefault('DigitContainer', 'LArDigitContainer_MC' ) ##FIXME - should not be hard-coded

    # if doing MC+MC overlay
    from AthenaCommon.GlobalFlags import globalflags
    if isOverlay() and globalflags.DataSource() == 'geant4':
        kwargs.setdefault('isMcOverlay',True)

    from LArROD.LArRODFlags import larRODFlags
    kwargs.setdefault('Nsamples', larRODFlags.nSamples() )
    kwargs.setdefault('firstSample', larRODFlags.firstSample() )

    if  isOverlay() :
         kwargs.setdefault('RandomDigitContainer', 'LArDigitContainer_MC' )

    # ADC2MeVTool
    mlog.info(" ----  set LArADC2MeVToolDefault")
    kwargs.setdefault('ADC2MeVTool', 'LArADC2MeVToolDefault')

    # Tool for noise autocorrelation generation
    kwargs.setdefault('AutoCorrNoiseTool', 'LArAutoCorrNoiseToolDefault')

    # bad channel masking
    from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
    theLArBadChannelTool=LArBadChanTool()
    from AthenaCommon.AppMgr import ToolSvc
    ToolSvc+=theLArBadChannelTool
    from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelMasker
    theLArRCBMasker=LArBadChannelMasker("LArRCBMasker")
    theLArRCBMasker.TheLArBadChanTool = theLArBadChannelTool
    theLArRCBMasker.DoMasking=True
    theLArRCBMasker.ProblemsToMask=[
         "deadReadout","deadPhys"]
    ToolSvc+=theLArRCBMasker
    kwargs.setdefault('MaskingTool', theLArRCBMasker )
    kwargs.setdefault('BadChannelTool', theLArBadChannelTool )

    # CosmicTriggerTimeTool for cosmics digitization
    from AthenaCommon.BeamFlags import jobproperties
    if jobproperties.Beam.beamType == "cosmics" :
        from CommissionUtils.CommissionUtilsConf import CosmicTriggerTimeTool
        theTriggerTimeTool = CosmicTriggerTimeTool()
        ToolSvc += theTriggerTimeTool
        kwargs.setdefault('UseTriggerTime', True )
        kwargs.setdefault('TriggerTimeToolName', theTriggerTimeTool )


    # pileup configuration "algorithm" way
    if not digitizationFlags.doXingByXingPileUp():
        from AthenaCommon.DetFlags import DetFlags
        if DetFlags.pileup.LAr_on() or isOverlay():
            kwargs.setdefault('PileUp', True )

    kwargs.setdefault('useLArFloat', useLArFloat() )
    if useLArFloat():
        from AthenaCommon.AppMgr import ServiceMgr as svcMgr
        from SGComps.SGCompsConf import AddressRemappingSvc
        AddressRemappingSvc = AddressRemappingSvc()
        svcMgr += AddressRemappingSvc
        from AthenaCommon.ConfigurableDb import getConfigurable
        svcMgr += getConfigurable( "ProxyProviderSvc" )()
        svcMgr.ProxyProviderSvc.ProviderNames += [ "AddressRemappingSvc" ]
        svcMgr.AddressRemappingSvc.TypeKeyOverwriteMaps = [ "LArHitContainer#LArHitEMB->LArHitFloatContainer#LArHitEMB" ,
                                                            "LArHitContainer#LArHitEMEC->LArHitFloatContainer#LArHitEMEC",
                                                            "LArHitContainer#LArHitHEC->LArHitFloatContainer#LArHitHEC",
                                                            "LArHitContainer#LArHitFCAL->LArHitFloatContainer#LArHitFCAL"]
        svcMgr.AddressRemappingSvc.ProxyDict="ActiveStoreSvc"


    return CfgMgr.LArPileUpTool(name, **kwargs)
def LArCellDeadOTXCorrToolDefault(name='LArCellDeadOTXCorr'):

    import traceback
    try:
        from LArCellRec.LArCellRecConf import LArCellDeadOTXCorr
        theLArCellDeadOTXCorr = LArCellDeadOTXCorr(name)
    except:
        mlog.error("could not get handle to LArCellDeadOTXCorr Quit")
        print traceback.format_exc()
        return False
    try:
        from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
        theLArBadChannelTool = LArBadChanTool()
    except:
        mlog.error("could not access bad channel tool Quit")
        print traceback.format_exc()
        return False

    from AthenaCommon.AppMgr import ToolSvc
    ToolSvc += theLArBadChannelTool
    theLArCellDeadOTXCorr.badChannelTool = theLArBadChannelTool
    from AthenaCommon.GlobalFlags import globalflags

    ignoredTTs = []
    deadOTXCorrDbFolder = "/LAR/CellCorrOfl/deadOTX"
    if globalflags.DataSource() == 'data':
        #deadOTXCorrDbTag = "<tag>LARCellCorrOflDeadOTX-UPD1-00</tag>"
        #deadOTXCorrDbConnection = "<dbConnection>oracle://ATLAS_COOLPROD;schema=ATLAS_COOLOFL_LAR;dbname=COMP200</dbConnection>"
        ignoredTTs = [0x11d0101]
        from AthenaCommon.BeamFlags import jobproperties
        if jobproperties.Beam.beamType() == "cosmics":
            theLArCellDeadOTXCorr.useL1CaloDB = False
        else:
            theLArCellDeadOTXCorr.useL1CaloDB = True
    else:
        #deadOTXCorrDbTag = "<tag>LARCellCorrOflDeadOTX-000-00</tag>"
        #deadOTXCorrDbConnection = "<dbConnection>oracle://ATLAS_COOLPROD;schema=ATLAS_COOLOFL_LAR;dbname=OFLP200</dbConnection>"
        theLArCellDeadOTXCorr.useL1CaloDB = False

    theLArCellDeadOTXCorr.triggerNoiseCut = [2., 0.265, 0.45, 0.16, 0.87]
    theLArCellDeadOTXCorr.ignoredTTs = ignoredTTs
    theLArCellDeadOTXCorr.COOLFolder = deadOTXCorrDbFolder
    theLArCellDeadOTXCorr.detStoreKey = "deadOTXCorrCtes"

    from IOVDbSvc.CondDB import conddb
    #conddb.addFolder("", deadOTXCorrDbConnection + deadOTXCorrDbFolder + deadOTXCorrDbTag)
    conddb.addFolder("LAR_OFL", deadOTXCorrDbFolder)

    if theLArCellDeadOTXCorr.useL1CaloDB:
        # Setup the L1CaloCondSvc
        from AthenaCommon.AppMgr import ServiceMgr
        from TrigT1CaloCondSvc.TrigT1CaloCondSvcConf import L1CaloCondSvc
        ServiceMgr += L1CaloCondSvc()

        L1CaloDb = ""
        if not 'L1CaloDbConnection' in dir():
            if 'L1CaloSqliteDB' in dir():
                L1CaloDbConnection = "<dbConnection>sqlite://;schema=" + L1CaloSqliteDB + ";dbname=L1CALO</dbConnection>"
            else:
                L1CaloDb = "TRIGGER"
                L1CaloDbConnection = ""

        L1CaloDbTag = "<tag>HEAD</tag>"

        L1CaloFolderList = []
        L1CaloFolderList += [
            "/TRIGGER/L1Calo/V1/Calibration/Physics/PprChanCalib"
        ]

        for l1calofolder in L1CaloFolderList:
            if not conddb.folderRequested(l1calofolder):
                conddb.addFolder(
                    L1CaloDb, L1CaloDbConnection + l1calofolder + L1CaloDbTag)

    return theLArCellDeadOTXCorr
Exemple #16
0
from AthenaCommon.AppMgr import (theApp, ServiceMgr as svcMgr, ToolSvc)

theApp.EvtMax = 1

## theByteStreamInputSvc=svcMgr.ByteStreamInputSvc
## theByteStreamInputSvc.FullFileName=["/home/wlampl/LArOFIter/ramp/inputs/daq.Ramp.0029146.No.Streaming.LB0000.EB-EMBA._0001.data"]

## theByteStreamInputSvc.MaxBadEvents=0

from LArCalibTest.LArCalibTestConf import DumpCaloBadChannels
theDumper = DumpCaloBadChannels()
theDumper.FileName = "list.txt"
topSequence += theDumper

from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
theLArBadChannelTool = LArBadChanTool()
theLArBadChannelTool.ReadFromASCII = True
theLArBadChannelTool.ASCIIFileName = "/home/wlampl/LArCondPatcher/dead_dummy.txt"
theLArBadChannelTool.OutputLevel = DEBUG
ToolSvc += theLArBadChannelTool

svcMgr += CfgMgr.AthenaEventLoopMgr(OutputLevel=WARNING)

from AthenaCommon.AppMgr import theAuditorSvc
from AthenaCommon.ConfigurableDb import getConfigurable
theAuditorSvc += getConfigurable("MemStatAuditor")(OutputLevel=WARNING)
theAuditorSvc += getConfigurable("ChronoAuditor")()
theAuditorSvc += getConfigurable("NameAuditor")()

###########################################################################
Exemple #17
0
BadChannelsFolder = "/LAR/BadChannelsOfl/BadChannels"
MissingFEBsFolder = "/LAR/BadChannelsOfl/MissingFEBs"

from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool

theLArBadChanTool = LArBadChanTool(
    CoolFolder=BadChannelsFolder,
    CoolMissingFEBsFolder=MissingFEBsFolder,
)

ToolSvc += theLArBadChanTool
# Set an int property
#BadChanTest.MyInt = 42

#--------------------------------------------------------------
# Algorithms Tool Usage Private Options (advanced and optional)
#--------------------------------------------------------------

# Import configurable for using our HelloTool
#from AthExHelloWorld.AthExHelloWorldConf import HelloTool
from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool

# Setup a public tool so that it can be used (again, note name)
#ToolSvc += HelloTool( "PublicHello" )
#ToolSvc.PublicHello.MyMessage = "A Public Message!"
ToolSvc += LArBadChanTool("BadChanTool")
#ToolSvc.BadChanTool.EMBAfile = "noisePb_29142.txt"
ToolSvc.BadChanTool.EMBAfile = "badchannels.txt"
ToolSvc.BadChanTool.EMBCfile = "badchannels.txt"
ToolSvc.BadChanTool.OutputLevel = DEBUG

# Tell "HelloWorld" to use this tool ("MyPublicHelloTool" is a
# ToolHandle property of LArBadChannelToolTest)
#HelloWorld.MyPublicHelloTool = ToolSvc.PublicHello
BadChanTest.BadChannelTool = ToolSvc.BadChanTool

#==============================================================
#
# End of job options file
#
###############################################################
topSequence = AlgSequence()  

## get a handle to the ApplicationManager, to the ServiceManager and to the ToolSvc
from AthenaCommon.AppMgr import (theApp, ServiceMgr as svcMgr,ToolSvc)

theApp.EvtMax=1

#Thats the registration algo
from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelDBAlg
theLArDBAlg=LArBadChannelDBAlg()
theLArDBAlg.WritingMode = 1
theLArDBAlg.FEBFolder=Folder
topSequence += theLArDBAlg

from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
theLArBadChannelTool=LArBadChanTool()
theLArBadChannelTool.ReadFromASCII=True
theLArBadChannelTool.CoolFolder=""

theLArBadChannelTool.CoolMissingFEBsFolder = ""#FEBFolder
theLArBadChannelTool.FEBfile = InputFile
#theLArBadChannelTool.WriteEmptyFolders = False
theLArBadChannelTool.OutputLevel=DEBUG
ToolSvc+=theLArBadChannelTool

OutputList=[ "AthenaAttributeList#"+Folder ]
FEBTag=join(split(Folder, '/'),'') + TagPostfix
OutputTagList=[FEBTag]

WriteIOV=True
from RegistrationServices.OutputConditionsAlg import OutputConditionsAlg
    def configure(self):
        from AthenaCommon.Logging import logging
        mlog = logging.getLogger('CaloCellGetter::configure:')
        mlog.info('entering')

        doStandardCellReconstruction = True
        from CaloRec.CaloCellFlags import jobproperties

        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:
            # handle LAr
            import traceback
            try:
                from LArROD.LArRODFlags import larRODFlags
                from AthenaCommon.GlobalFlags import globalflags
                if larRODFlags.readDigits() and globalflags.DataSource(
                ) == 'data':
                    from AthenaCommon.KeyStore import CfgItemList
                    CfgItemList("KeyStore_inputFile").removeItem(
                        "LArRawChannelContainer#LArRawChannels")
                if (not larRODFlags.readDigits()
                    ) and globalflags.InputFormat() == 'bytestream':
                    from AthenaCommon.AppMgr import ServiceMgr as svcMgr
                    try:
                        if not "LArRawChannelContainer/LArRawChannels" in svcMgr.ByteStreamAddressProviderSvc.TypeNames:
                            svcMgr.ByteStreamAddressProviderSvc.TypeNames += [
                                "LArRawChannelContainer/LArRawChannels"
                            ]
                    except:
                        mlog.warning(
                            "Cannot remove LArRawChannelContainer/LArRawChannels from bytestream list"
                        )
                from LArROD.LArRawChannelGetter import LArRawChannelGetter
                theLArRawChannelGetter = LArRawChannelGetter()
            except:
                mlog.error("could not get handle to LArRawChannel Quit")
                print traceback.format_exc()
                return False

            if not theLArRawChannelGetter.usable():
                if not self.ignoreConfigError():
                    mlog.error("LArRawChannelGetter unusable. Quit.")
                    return False
                else:
                    mlog.error(
                        "LArRawChannelGetter unusable. Continue nevertheless")

        # 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:
            mlog.error("could not import CaloRec.CaloCellMaker")
            print traceback.format_exc()
            return False

        theCaloCellMaker = CaloCellMaker()
        self._CaloCellMakerHandle = theCaloCellMaker

        from AthenaCommon.AppMgr import ToolSvc

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

            from RecExConfig.RecFlags import rec

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

                if jobproperties.CaloCellFlags.doLArCreateMissingCells():
                    # bad channel tools
                    try:
                        from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
                        theLArBadChannelTool = LArBadChanTool()
                    except:
                        mlog.error("could not access bad channel tool Quit")
                        print traceback.format_exc()
                        return False
                    ToolSvc += theLArBadChannelTool
                    theLArCellBuilder.addDeadOTX = True
                    theLArCellBuilder.badChannelTool = theLArBadChannelTool

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

            if rec.doTile():

                from AthenaCommon.GlobalFlags import globalflags
                if globalflags.DataSource(
                ) == 'data' and globalflags.InputFormat() == 'bytestream':
                    from AthenaCommon.AppMgr import ServiceMgr as svcMgr
                    try:
                        svcMgr.ByteStreamCnvSvc.ROD2ROBmap = ["-1"]
                        if not "TileDigitsContainer/TileDigitsCnt" in svcMgr.ByteStreamAddressProviderSvc.TypeNames:
                            svcMgr.ByteStreamAddressProviderSvc.TypeNames += [
                                "TileBeamElemContainer/TileBeamElemCnt",
                                "TileDigitsContainer/TileDigitsCnt",
                                "TileL2Container/TileL2Cnt",
                                "TileLaserObject/TileLaserObj",
                                "TileMuonReceiverContainer/TileMuRcvCnt"
                            ]
                    except:
                        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.doTileOpt      \
                                 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 not 'doTileOpt2' in dir():
                            from RecExConfig.AutoConfiguration import GetRunNumber
                            rn = GetRunNumber()
                            if 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()
                    except:
                        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:
                        mlog.error("Could not configure TileDigitsFilter")

                try:
                    from TileRecUtils.TileRecUtilsConf import TileCellBuilder
                    theTileCellBuilder = TileCellBuilder()
                    from TileRecUtils.TileRecFlags import jobproperties
                    theTileCellBuilder.TileRawChannelContainer = jobproperties.TileRecFlags.TileRawChannelContainer(
                    )

                    if not hasattr(ToolSvc, "TileBeamInfoProvider"):
                        from TileRecUtils.TileRecUtilsConf import TileBeamInfoProvider
                        ToolSvc += TileBeamInfoProvider()

                    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:
                            ToolSvc.TileBeamInfoProvider.TileRawChannelContainer = "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(
                                )

                    ToolSvc += theTileCellBuilder
                    theCaloCellMaker.CaloCellMakerToolNames += [
                        theTileCellBuilder
                    ]
                except:
                    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()
                ToolSvc += theEmptyCellBuilderTool
                theCaloCellMaker.CaloCellMakerToolNames += [
                    theEmptyCellBuilderTool
                ]

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

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

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

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

                    from CaloTools.CaloNoiseToolDefault import CaloNoiseToolDefault
                    theCaloNoiseTool = CaloNoiseToolDefault()
                    from AthenaCommon.AppMgr import ToolSvc
                    ToolSvc += theCaloNoiseTool

                    theAddNoiseCellBuilderTool.CaloNoiseTool = theCaloNoiseTool.getFullName(
                    )

                    print theAddNoiseCellBuilderTool

                    ToolSvc += theAddNoiseCellBuilderTool
                    theCaloCellMaker.CaloCellMakerToolNames += [
                        theAddNoiseCellBuilderTool
                    ]
                    mlog.info("configure AddNoiseCellBuilderTool worked")
                except:
                    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()
        ToolSvc += 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:
                mlog.error("could not get handle to LArCellMerge Quit")
                print traceback.format_exc()
                return False
            theLArCellMerger.RawChannelsName = larRODFlags.RawChannelFromDigitsContainerName(
            )
            ToolSvc += 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:
                mlog.error(
                    "could not get handle to LArCellNoiseMaskingTool Quit")
                print traceback.format_exc()
                return False

            # bad channel tools
            try:
                from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
                theLArBadChannelTool = LArBadChanTool()
            except:
                mlog.error("could not access bad channel tool Quit")
                print traceback.format_exc()
                return False
            ToolSvc += theLArBadChannelTool

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

            if doNoiseMask:
                try:
                    from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelMasker
                    theLArNoiseMasker = LArBadChannelMasker("LArNoiseMasker")
                except:
                    mlog.error("could not access bad channel tool Quit")
                    print traceback.format_exc()
                    return False
                theLArNoiseMasker.TheLArBadChanTool = theLArBadChannelTool
                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
            ToolSvc += 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:
                mlog.error("could not get handle to LArBadFebMaskingTool Quit")
                print traceback.format_exc()
                return False
            ToolSvc += theLArBadFebMaskingTool

            # bad channel tools
            try:
                from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
                theLArBadChannelTool = LArBadChanTool()
            except:
                mlog.error("could not access bad channel tool Quit")
                print traceback.format_exc()
                return False
            ToolSvc += theLArBadChannelTool

            theLArBadFebMaskingTool.badChannelTool = theLArBadChannelTool
            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:
                mlog.error("could not get handle to LArCellGainPatholog< Quit")
                print traceback.format_exc()
                return False
            ToolSvc += 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:
                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:
                mlog.error("could not get handle to MisCalibTool Quit")
                print traceback.format_exc()
                return False

            ToolSvc += 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")

        import os
        if doPedestalCorr:
            try:
                from CaloCellCorrection.CaloCellPedestalCorrDefault import CaloCellPedestalCorrDefault
                theCaloCellPedestalCorr = CaloCellPedestalCorrDefault()
                ToolSvc += theCaloCellPedestalCorr
                theCaloCellMaker.CaloCellMakerToolNames += [
                    theCaloCellPedestalCorr
                ]
            except:
                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.LArCellHVCorrDefault import LArCellHVCorrDefault
            theLArCellHVCorr = LArCellHVCorrDefault()

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

        #
        # 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:
                mlog.error("could not get handle to LArCellRecalibration Quit")
                print traceback.format_exc()
                return False
            ToolSvc += theLArCellRecalibration

            # get new ADC2MeVTool
            try:
                from LArRecUtils.LArADC2MeVToolDefault import LArADC2MeVToolDefault
                theLArADC2MeVToolDefault = LArADC2MeVToolDefault()
            except:
                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:
                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:
                mlog.error("could not get handle to HVCorrTool Quit")
                print traceback.format_exc()
                return False
            ToolSvc += 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:
                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:
                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:
                mlog.error(
                    "could not get handle to CaloCellContainerCorrectorTool/MBAverageTool Quit"
                )
                print traceback.format_exc()
                return False

            ToolSvc += 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:
                mlog.error(
                    "could not get handle to  CaloCellNeighborsAverageCorr  Quit"
                )
                print traceback.format_exc()
                return False
            ToolSvc += 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:
                mlog.error("could not get handle to LArCellDeadOTXCorr Quit")
                print traceback.format_exc()

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

        doCaloEnergyRescaler = False
        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"
                ToolSvc += theCCERescalerTool
                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")
                ToolSvc += theCCERescalerTool
                theCaloCellMaker.CaloCellMakerToolNames += [theCCERescalerTool]
            except:
                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 CaloRec.CaloRecConf import CaloCellContainerCorrectorTool
                from CaloCellCorrection.CaloCellCorrectionConf import CaloCellTimeCorrTool
                theLArTimeCorr = CaloCellTimeCorrTool()
                theLArTimeCorr.Folder = "/LAR/TimeCorrectionOfl/CellTimeOffset"
                ToolSvc += theLArTimeCorr
                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")
                theCaloTimeCorrTool = CaloCellContainerCorrectorTool(
                    "LArTimeCorrTool",
                    CellCorrectionToolNames=[theLArTimeCorr])
                ToolSvc += theCaloTimeCorrTool
                theCaloCellMaker.CaloCellMakerToolNames += [
                    theCaloTimeCorrTool
                ]

            except:
                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

        ToolSvc += 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())

        # 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
PoolSvc.ReadCatalog += ["prfile:poolcond/PoolCat_comcond_castor.xml"]

theApp.EvtMax = 1
svcMgr.EventSelector.RunNumber = RunNumber

from LArCalibUtils.LArCalibUtilsConf import LArCalibPatchingAlg_LArCaliWaveContainer_
theLArCaliWavePatcher = LArCalibPatchingAlg_LArCaliWaveContainer_(
    "LArCaliWavePatcher")
theLArCaliWavePatcher.ContainerKey = "LArCaliWave"
theLArCaliWavePatcher.NewContainerKey = "LArCaliWaveOut"
theLArCaliWavePatcher.PatchMethod = "PhiNeighbor"
theLArCaliWavePatcher.OutputLevel = DEBUG
topSequence += theLArCaliWavePatcher

from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
theLArBadChannelTool = LArBadChanTool()
theLArBadChannelTool.OutputLevel = DEBUG
ToolSvc += theLArBadChannelTool

from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelMasker
theLArRCBMasker = LArBadChannelMasker("LArRCBMasker")
theLArRCBMasker.DoMasking = True
theLArRCBMasker.ProblemsToMask = [
    "deadCalib",
    "deadReadout",
    "deadPhys",
    "almostDead",
    "short",
]
ToolSvc += theLArRCBMasker
theLArCaliWavePatcher.MaskingTool = theLArRCBMasker
if IOVEndLB <= 0:
    svcMgr.EventSelector.FirstEvent = 1
else:
    svcMgr.EventSelector.FirstEvent = 0
    svcMgr.EventSelector.FirstLB = IOVEndLB

## get a handle to the default top-level algorithm sequence
from AthenaCommon.AlgSequence import AlgSequence
topSequence = AlgSequence()

## get a handle to the ApplicationManager, to the ServiceManager and to the ToolSvc
from AthenaCommon.AppMgr import (theApp, ServiceMgr as svcMgr, ToolSvc)

conddb.addFolder("", folderStr + tagStr + dbStr)
#conddb.addFolder("LAR_OFL","/LAR/BadChannelsOfl/MissingFEBs")

svcMgr.IOVDbSvc.GlobalTag = "CONDBR2-ES1PA-2014-01"

from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
theLArBadChannelTool = LArBadChanTool()
theLArBadChannelTool.CoolFolder = folderStr
theLArBadChannelTool.CoolMissingFEBsFolder = ""
ToolSvc += theLArBadChannelTool

from LArBadChannelTool.LArBadChannelToolConf import LArBadChannel2Ascii
theLArBadChannels2Ascii = LArBadChannel2Ascii()
theLArBadChannels2Ascii.FileName = OutputFile
theLArBadChannels2Ascii.WithMissing = False
theLArBadChannels2Ascii.ExecutiveSummaryFile = ""
topSequence += theLArBadChannels2Ascii
    def configure(self):
        from AthenaCommon.Logging import logging
        mlog = logging.getLogger('LArNoisyROSummaryGetter::configure:')
        mlog.info('entering')

        # get handle to upstream CaloCell object
        import traceback
        try:
            from CaloRec.CaloCellGetter import CaloCellGetter
            theCaloCellGetter = CaloCellGetter()
        except:
            mlog.error("could not get handle to CaloCell Quit")
            print traceback.format_exc()
            return False
        if not theCaloCellGetter.usable():
            if not self.ignoreConfigError():
                mlog.error("CaloCellGetter unusable. Quit.")
                return False
            else:
                mlog.error("CaloCellGetter unusable. Continue nevertheless")

        # now configure the algorithm
        # cannot have same name
        try:
            from LArCellRec.LArCellRecConf import LArNoisyROAlg, LArNoisyROTool
        except:
            mlog.error("could not import LArNoisyROAlg or LArNoisyROTool")
            print traceback.format_exc()
            return False

        from AthenaCommon.AppMgr import ToolSvc
        # Noise and MNB Febs from COOL only for data
        from AthenaCommon.GlobalFlags import globalflags
        from IOVDbSvc.CondDB import conddb
        if globalflags.DataSource.get_Value() != 'geant4' and (
                'COMP200' not in conddb.GetInstance()):
            from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
            theBadFebTool = LArBadChanTool("KnownBADFEBsTool")
            theBadFebTool.CoolMissingFEBsFolder = "/LAR/BadChannels/KnownBADFEBs"
            ToolSvc += theBadFebTool
            theMNBFebTool = LArBadChanTool("KnownMNBFEBsTool")
            theMNBFebTool.CoolMissingFEBsFolder = "/LAR/BadChannels/KnownMNBFEBs"
            ToolSvc += theMNBFebTool
            theLArNoisyROTool = LArNoisyROTool(
                PrintSummary=True,
                CellQualityCut=larNoisyROFlags.CellQualityCut(),
                BadChanPerFEB=larNoisyROFlags.BadChanPerFEB(),
                BadFEBCut=larNoisyROFlags.BadFEBCut(),
                MNBLooseCut=larNoisyROFlags.MNBLooseCut(),
                MNBTightCut=larNoisyROFlags.MNBTightCut(),
                MNBTight_PsVetoCut=larNoisyROFlags.MNBTight_PsVetoCut(),
                KnownBADFEBsTool=theBadFebTool,
                KnownMNBFEBsTool=theMNBFebTool)
        else:
            theLArNoisyROTool = LArNoisyROTool(
                PrintSummary=True,
                CellQualityCut=larNoisyROFlags.CellQualityCut(),
                BadChanPerFEB=larNoisyROFlags.BadChanPerFEB(),
                BadFEBCut=larNoisyROFlags.BadFEBCut(),
            )
        pass

        theLArNoisyROAlg = LArNoisyROAlg()
        theLArNoisyROAlg.Tool = theLArNoisyROTool

        self._LArNoisyROMakerHandle = theLArNoisyROAlg
        theLArNoisyROAlg.OutputKey = self.outputKey()

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

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

        from AthenaCommon.AlgSequence import AlgSequence
        topSequence = AlgSequence()

        topSequence += theLArNoisyROAlg

        return True
Exemple #24
0
topSequence += theLArRampBuilder

######################################################################
#                                                                    #
#                          Correction                                #
#                                                                    #
######################################################################

if CorrectBadChannels:
    from LArCalibUtils.LArCalibUtilsConf import LArCalibPatchingAlg_LArRampComplete_
    theLArRampPatcher = LArCalibPatchingAlg_LArRampComplete_("LArRampPatcher")
    theLArRampPatcher.ContainerKey = KeyOutput
    theLArRampPatcher.PatchMethod = "PhiAverage"

    from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
    theLArBadChannelTool = LArBadChanTool()
    ToolSvc += theLArBadChannelTool
    theLArRampPatcher.MaskingTool = theLArRCBMasker
    theLArRampPatcher.UseCorrChannels = False
    topSequence += theLArRampPatcher

if (ApplyAdHocCorrection):
    from LArCalibUtils.LArCalibUtilsConf import LArRampAdHocPatchingAlg
    LArRampAdHocPatchingAlg = LArRampAdHocPatchingAlg(
        "LArRampAdHocPatchingAlg")
    LArRampAdHocPatchingAlg.ContainerKey = KeyOutput

    if ('ChannelsToBePatchedHG' in dir() and 'PatchesToBeAppliedHG' in dir()):
        if (len(ChannelsToBePatchedHG)
                and len(ChannelsToBePatchedHG) == len(PatchesToBeAppliedHG)):
            LArRampAdHocPatchingAlg.ChannelsToBePatchedHG = ChannelsToBePatchedHG
## get a handle to the default top-level algorithm sequence
from AthenaCommon.AlgSequence import AlgSequence
topSequence = AlgSequence()

## get a handle to the ApplicationManager, to the ServiceManager and to the ToolSvc
from AthenaCommon.AppMgr import (theApp, ServiceMgr as svcMgr, ToolSvc)

theApp.EvtMax = 10

from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelTimingAlg
theTester = LArBadChannelTimingAlg()
theTester.ReallyCheck = True
topSequence += theTester

from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
theLArBadChannelTool = LArBadChanTool()
theLArBadChannelTool.ReadFromASCII = False
theLArBadChannelTool.DumpCache = False

#theLArBadChannelTool.EMBAfile = "badchan1.txt"
theLArBadChannelTool.EMBCfile = "badchan1.txt"

theLArBadChannelTool.OutputLevel = DEBUG
ToolSvc += theLArBadChannelTool

svcMgr.IOVDbSvc.Folders += [
    "/LAR/ElecCalib/BadChannels<tag>TestTag</tag><dbConnection>sqlite://;schema=BadChannels.db;dbname=CONDBR2</dbConnection>"
]

svcMgr += CfgMgr.AthenaEventLoopMgr(OutputLevel=WARNING)
## get a handle to the ApplicationManager, to the ServiceManager and to the ToolSvc
from AthenaCommon.AppMgr import (theApp, ServiceMgr as svcMgr, ToolSvc)

theApp.EvtMax = 1

#Thats the registration algo
from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelDBAlg
theLArDBAlg = LArBadChannelDBAlg()
theLArDBAlg.WritingMode = 0
theLArDBAlg.DBFolder = Folder
theLArDBAlg.OutputLevel = DEBUG
topSequence += theLArDBAlg

from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
theLArBadChannelTool = LArBadChanTool()
theLArBadChannelTool.ReadFromASCII = True

theLArBadChannelTool.EMECAfile = InputFile
theLArBadChannelTool.HECAfile = InputFile
theLArBadChannelTool.FCALAfile = InputFile

theLArBadChannelTool.EMECCfile = InputFile
theLArBadChannelTool.HECCfile = InputFile
theLArBadChannelTool.FCALCfile = InputFile

theLArBadChannelTool.EMBAfile = InputFile
theLArBadChannelTool.EMBCfile = InputFile

theLArBadChannelTool.CoolFolder = ""
theLArBadChannelTool.CoolMissingFEBsFolder = ""
    def configure(self):
        mlog = logging.getLogger('Py:LArRawChannelGetter::configure %s:' %
                                 self.__class__)

        from AthenaCommon.AlgSequence import AlgSequence
        topSequence = AlgSequence()
        from AthenaCommon.AppMgr import ToolSvc

        # get LArDigitGetter in MC case
        from AthenaCommon.DetFlags import DetFlags
        if DetFlags.digitize.LAr_on():
            try:
                from LArDigitization.LArDigitGetter import LArDigitGetter
                theLArDigitGetter = LArDigitGetter()
            except Exception as configException:
                print configException
                mlog.error("could not get handle to LArDigitGetter Quit")
                return False
            if not theLArDigitGetter.usable():
                mlog.error("LArDigitGetter unusable. Quite")
                return False

        from LArROD.LArRODFlags import larRODFlags

        from AthenaCommon.GlobalFlags import globalflags
        if globalflags.DataSource() == 'data' or larRODFlags.forceIter():

            # ADC2MeV tool
            from LArRecUtils.LArADC2MeVToolDefault import LArADC2MeVToolDefault
            theADC2MeVTool = LArADC2MeVToolDefault()
            ToolSvc += theADC2MeVTool

            from AthenaCommon.AppMgr import ServiceMgr as svcMgr

            # Data case

            if larRODFlags.readDigits():

                from AthenaCommon.GlobalFlags import globalflags
                if globalflags.InputFormat() == 'bytestream':
                    if not "LArDigitContainer/FREE" in svcMgr.ByteStreamAddressProviderSvc.TypeNames:
                        svcMgr.ByteStreamAddressProviderSvc.TypeNames += [
                            "LArDigitContainer/FREE"
                        ]
                    if not larRODFlags.keepDSPRaw():
                        if "LArRawChannelContainer/LArRawChannels" in svcMgr.ByteStreamAddressProviderSvc.TypeNames:
                            svcMgr.ByteStreamAddressProviderSvc.TypeNames.remove(
                                "LArRawChannelContainer/LArRawChannels")
                    else:
                        if not "LArRawChannelContainer/LArRawChannels" in svcMgr.ByteStreamAddressProviderSvc.TypeNames:
                            svcMgr.ByteStreamAddressProviderSvc.TypeNames += [
                                "LArRawChannelContainer/LArRawChannels"
                            ]

                if globalflags.DetGeo() == 'ctbh6' or globalflags.DetGeo(
                ) == 'ctbh8':
                    from LArROD.LArRODConf import LArRawChannelBuilder
                    theLArRawChannelBuilder = LArRawChannelBuilder()
                    topSequence += theLArRawChannelBuilder
                    return True

                from LArROD.LArRODConf import LArRawChannelBuilderDriver

                theLArRawChannelBuilder = LArRawChannelBuilderDriver(
                    "LArRawChannelBuilder")
                topSequence += theLArRawChannelBuilder

                if larRODFlags.keepDSPRaw():
                    theLArRawChannelBuilder.LArRawChannelContainerName = larRODFlags.RawChannelFromDigitsContainerName(
                    )

                # bad channel masking if required
                if not larRODFlags.doBuildBadChannel():
                    # The first tool filters out bad channels
                    from LArROD.LArRODConf import LArRawChannelBuilderToolBadChannelTool
                    theLArRawChannelBuilderToolBadChannel = LArRawChannelBuilderToolBadChannelTool(
                    )
                    from LArBadChannelTool.LArBadChannelToolConf import LArBadChannelMasker
                    theLArRCBMasker = LArBadChannelMasker("LArRCBMasker")
                    theLArRCBMasker.DoMasking = True
                    theLArRCBMasker.ProblemsToMask = [
                        "deadReadout", "deadPhys", "almostDead", "short",
                        "lowNoiseHG", "highNoiseHG", "unstableNoiseHG",
                        "lowNoiseMG", "highNoiseMG", "unstableNoiseMG",
                        "lowNoiseLG", "highNoiseLG", "unstableNoiseLG"
                    ]
                    #ToolSvc+=theLArRCBMasker
                    from LArBadChannelTool.LArBadChannelToolConf import LArBadChanTool
                    ToolSvc += LArBadChanTool()
                    theLArRawChannelBuilderToolBadChannel.BadChannelMask = theLArRCBMasker
                    theLArRawChannelBuilder.BuilderTools += [
                        theLArRawChannelBuilderToolBadChannel
                    ]
                    ToolSvc += theLArRawChannelBuilderToolBadChannel

                # Pulse reconstruction
                # main method: OFC iteration
                from LArROD.LArRODConf import LArRawChannelBuilderToolOFCIter
                theLArRawChannelBuilderToolOFCIter = LArRawChannelBuilderToolOFCIter(
                )
                theLArRawChannelBuilderToolOFCIter.minSample = 2
                theLArRawChannelBuilderToolOFCIter.maxSample = 12
                theLArRawChannelBuilderToolOFCIter.minADCforIterInSigma = 4  # ADCmax at least 4 sigma above noise for iteration
                theLArRawChannelBuilderToolOFCIter.minADCforIter = 15  # min adc for iteration (only if no pedestalRMS found)
                theLArRawChannelBuilderToolOFCIter.defaultPhase = 0  # starting delay, also the fixed delay for ADC below min.
                theLArRawChannelBuilderToolOFCIter.ECut = 250.  # Energy to save quality
                theLArRawChannelBuilder.BuilderTools += [
                    theLArRawChannelBuilderToolOFCIter
                ]
                theLArRawChannelBuilder += theLArRawChannelBuilderToolOFCIter

                # no fallback when emulating exactly DSP computation
                if not larRODFlags.doDSP():
                    # fallback(1): cubic method
                    from LArROD.LArRODConf import LArRawChannelBuilderToolCubic
                    theLArRawChannelBuilderToolCubic = LArRawChannelBuilderToolCubic(
                    )
                    theLArRawChannelBuilderToolCubic.minADCforCubic = 30
                    theLArRawChannelBuilder.BuilderTools += [
                        theLArRawChannelBuilderToolCubic
                    ]
                    theLArRawChannelBuilder += theLArRawChannelBuilderToolCubic

                    # fallback(2) averageing
                    from LArROD.LArRODConf import LArRawChannelBuilderToolAverage
                    theLArRawChannelBuilderToolAverage = LArRawChannelBuilderToolAverage(
                    )
                    theLArRawChannelBuilderToolAverage.NScan = 0
                    theLArRawChannelBuilder.BuilderTools += [
                        theLArRawChannelBuilderToolAverage
                    ]
                    theLArRawChannelBuilder += theLArRawChannelBuilderToolAverage

                # Pedestal
                # main method from database
                from LArROD.LArRODConf import LArRawChannelBuilderPedestalDataBase
                theLArRawChannelBuilderPedestalDataBase = LArRawChannelBuilderPedestalDataBase(
                )
                theLArRawChannelBuilderPedestalDataBase.LArPedestalKey = "Pedestal"
                theLArRawChannelBuilder.PedestalTools = [
                    theLArRawChannelBuilderPedestalDataBase
                ]
                theLArRawChannelBuilder += theLArRawChannelBuilderPedestalDataBase

                # no fallback when emulating exactly DSP computation
                if not larRODFlags.doDSP():
                    # fallback. sample 0
                    from LArROD.LArRODConf import LArRawChannelBuilderPedestalSampleZero
                    theLArRawChannelBuilderPedestalSampleZero = LArRawChannelBuilderPedestalSampleZero(
                    )
                    theLArRawChannelBuilder.PedestalTools += [
                        theLArRawChannelBuilderPedestalSampleZero
                    ]
                    theLArRawChannelBuilder += theLArRawChannelBuilderPedestalSampleZero

                # ADC to energy
                # main method from database
                from LArROD.LArRODConf import LArRawChannelBuilderADC2EDataBase
                theLArRawChannelBuilderADC2EDataBase = LArRawChannelBuilderADC2EDataBase(
                )
                theLArRawChannelBuilder.ADCtoEnergyTools = [
                    theLArRawChannelBuilderADC2EDataBase
                ]
                theLArRawChannelBuilderADC2EDataBase.ADC2MeVTool = theADC2MeVTool
                theLArRawChannelBuilder += theLArRawChannelBuilderADC2EDataBase

                # no fallback when emulating exactly DSP computation
                if not larRODFlags.doDSP():
                    # fallback, constant conversion factors
                    from LArROD.LArRODConf import LArRawChannelBuilderADC2EConstants
                    theLArRawChannelBuilderADC2EConstants = LArRawChannelBuilderADC2EConstants(
                    )
                    theLArRawChannelBuilder.ADCtoEnergyTools += [
                        theLArRawChannelBuilderADC2EConstants
                    ]
                    theLArRawChannelBuilder += theLArRawChannelBuilderADC2EConstants

                #more tools to be configured
                from LArRecUtils.LArRecUtilsConf import LArOFPeakRecoTool
                theLArOFPeakRecoTool = LArOFPeakRecoTool()
                from LArConditionsCommon.LArCondFlags import larCondFlags
                theLArOFPeakRecoTool.UseShape = larCondFlags.useShape()
                if larCondFlags.LArCoolChannelSelection.statusOn:
                    if len(larCondFlags.LArCoolChannelSelection()) > 0:
                        theLArOFPeakRecoTool.forceHighGain = larCondFlags.useOFCOnlyCoolChannelSelection(
                        )
                ToolSvc += theLArOFPeakRecoTool

                #
                # adjust default timing to match first sample information written in cool from Lar online configuration
                #
                nominalPeakSample = 2
                if globalflags.DataSource() == 'data':
                    from LArConditionsCommon.LArCool import larcool
                    if (larcool is not None):
                        nominalPeakSample = larcool.firstSample()
                        # don't use ramp intercept in calibration if gain type is not auto
                        if larcool.gainType() > 0:
                            mlog.info(
                                " Gain Type: %d  don't use intercept in ADC to Energy ramp calibration",
                                larcool.gainType())
                            theLArRawChannelBuilderADC2EDataBase.UseHighGainRampIntercept = False
                            theLArRawChannelBuilderADC2EDataBase.UseMedGainRampIntercept = False
                            theLArRawChannelBuilderADC2EDataBase.UseLowGainRampIntercept = False
                        else:
                            mlog.info(
                                " Gain Type: %d   use intercept in ADC to energy ramp calibraion ",
                                larcool.gainType())
                if (nominalPeakSample > 1):
                    theLArRawChannelBuilder.DefaultShiftTimeSample = nominalPeakSample - 2
                else:
                    theLArRawChannelBuilder.DefaultShiftTimeSample = 0
                theLArRawChannelBuilder.DataLocation = "FREE"

            else:

                from AthenaCommon.GlobalFlags import globalflags
                if globalflags.InputFormat() == 'bytestream':
                    if not "LArRawChannelContainer/LArRawChannels" in svcMgr.ByteStreamAddressProviderSvc.TypeNames:
                        svcMgr.ByteStreamAddressProviderSvc.TypeNames += [
                            "LArRawChannelContainer/LArRawChannels"
                        ]

            # In the case of DSP monitoring and reading rawchannels, need to give a different name to the LArRawChannels container
            # read from the bytestream ...
            # This name has to be coherent with the name in LArMonTools/LArRODMonTool_jobOptions.py
            if larRODFlags.doDSP() and larRODFlags.readRawChannels(
            ):  #Reading LArRawChannel
                print "Reading RawChannels in DSP physics mode"
                # !!! The name of the LArRawChannels container read from the Bytestream is LArRawChannels_fB !!!
                if not "LArRawChannelContainer/LArRawChannels_fB" in svcMgr.ByteStreamAddressProviderSvc.TypeNames:
                    svcMgr.ByteStreamAddressProviderSvc.TypeNames += [
                        "LArRawChannelContainer/LArRawChannels_fB"
                    ]
                print svcMgr.ByteStreamAddressProviderSvc.TypeNames

        else:

            # MC Case
            try:
                from AthenaCommon import CfgGetter
                topSequence += CfgGetter.getAlgorithm(
                    "LArRawChannelBuilder", tryDefaultConfigurable=True)
            except Exception as cfgException:
                print cfgException
                mlog.error("Failed to retrieve LArRawChannelBuilder. Quit")
                return False

        return True