theApp.EventLoop = "PileUpEventLoopMgr"

pileUpEventLoopMgr = PileUpEventLoopMgr()
from Digitization.DigitizationFlags import jobproperties
pupStream = "PileUpCollXingStream"
jobproperties.Digitization.rndmSeedList.addSeed( pupStream, 123, 345 )
#define inputs
pileUpEventLoopMgr.OrigSelector="EventSelector"

from PileUpComps.PileUpCompsConf import BkgStreamsCache
from Digitization import PileUpEventType
from EventSelectorAthenaPool.EventSelectorAthenaPoolConf import EventSelectorAthenaPool
minBiasCache = BkgStreamsCache("MinBiasCache")
minBiasCache.CollPerXing=Ncoll
minBiasCache.CollDistribution="Poisson"
minBiasCache.ReadDownscaleFactor=1  # read one new event every event
minBiasCache.RndmGenSvc=jobproperties.Digitization.rndmSvc()
minBiasCache.RndmStreamName=pupStream
minBiasEvtSel = EventSelectorAthenaPool("minBiasEventSelector")
minBiasEvtSel.InputCollections = minBiasInputCols
minBiasEvtSel.KeepInputFilesOpen = True
ServiceMgr += minBiasEvtSel
minBiasCache.EventSelector="minBiasEventSelector"
pileUpEventLoopMgr.bkgCaches += [ minBiasCache ]

#define output stream
pileUpEventLoopMgr.OutStreamType = "AthenaOutputStream"

#define time range to be studied. t0 at t=0, xing=0
pileUpEventLoopMgr.XingFrequency=25;
from AthenaCommon.AppMgr import ServiceMgr
from PileUpComps.PileUpCompsConf import PileUpEventLoopMgr

# ad-hoc configuration of pileup event loop manager
theApp.EventLoop = "PileUpEventLoopMgr"
pileUpEventLoopMgr = PileUpEventLoopMgr()
from Digitization.DigitizationFlags import jobproperties
pupStream = "PileUpCollXingStream"
jobproperties.Digitization.rndmSeedList.addSeed(pupStream, 123, 345)
pileUpEventLoopMgr.OrigSelector = "EventSelector"

from PileUpComps.PileUpCompsConf import BkgStreamsCache
from EventSelectorAthenaPool.EventSelectorAthenaPoolConf import EventSelectorAthenaPool
minBiasCache = BkgStreamsCache("MinBiasCache")
minBiasCache.CollPerXing = 1
minBiasCache.CollDistribution = "Fixed"
minBiasCache.ReadDownscaleFactor = 1  # read one new event every event
#minBiasCache.RndmGenSvc=digitizationRndmSvc
minBiasCache.RndmStreamName = pupStream
minBiasEvtSel = EventSelectorAthenaPool("minBiasEventSelector")
minBiasEvtSel.InputCollections = minBiasInputCols
minBiasEvtSel.KeepInputFilesOpen = True
ServiceMgr += minBiasEvtSel
minBiasCache.EventSelector = "minBiasEventSelector"
pileUpEventLoopMgr.bkgCaches += [minBiasCache]

from AthenaCommon.AppMgr import ToolSvc
from LArRecUtils.LArRecUtilsConf import LArAutoCorrTotalTool
try:
    ToolSvc.LArAutoCorrTotalTool.NMinBias = 1.
    # FIXME  <ncol> per crossing