ATLAS Offline Software
Loading...
Searching...
No Matches
PileUpProfile_muRange.py
Go to the documentation of this file.
1# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2
3from AthenaCommon.Logging import logging
4
5
6def setupProfile(flags, scaleTaskLength=1):
7 logger = logging.getLogger("PileUp")
8 customProfile = flags.Digitization.PU.CustomProfile
9 # customProfile={'run':195847, 'startmu':15.0, 'endmu':25.0, 'stepmu':1.0, 'startlb':1, 'timestamp':1328039085}
10
11 def _evts(x):
12 return int(scaleTaskLength * x)
13
14 try:
15 logger.info('Setting-up custom pile-up range with user-selected run(s) %s', customProfile.get('run', -1))
16 except AttributeError:
17 logger.error("Set ConfigFlags.Digitization.PU.CustomProfile=\'{\"run\":1234,...}\' in preExec!")
18 raise ValueError("Invalid ConfigFlags.Digitization.PU.CustomProfile provided. Run number is missing.")
19 keys=['run', 'startmu', 'endmu', 'stepmu', 'startlb', 'timestamp']
20 for key in customProfile.keys():
21 if key not in keys:
22 raise ValueError("Invalid ConfigFlags.Digitization.PU.CustomProfile provided, key: %s. Valid keys are: %s" % (key, keys))
23
24 startMu = customProfile.get('startmu', 0.0)
25 endMu = customProfile.get('endmu', 10.0)
26 stepMu = customProfile.get('stepmu', 1.0)
27 numberOfSteps = int(((endMu - startMu) / stepMu) + 1.0)
28 if numberOfSteps < 2:
29 raise RuntimeError("Step size too large!")
30
31 stepsWithExtraEvent = 5000 % numberOfSteps
32 eventsPerStep = (5000 - (5000 % numberOfSteps)) / numberOfSteps
33 if _evts(eventsPerStep) < 2: raise RuntimeError("Step size too small!")
34
35 runList = customProfile.get('run', 195847)
36 if not isinstance(runList, list): runList = [runList]
37 timestampList = customProfile.get('timestamp', 1328039085)
38 if not isinstance(timestampList, list): timestampList = [timestampList]
39 startlbList = customProfile.get('startlb', 1)
40 if not isinstance(startlbList, list): startlbList = [startlbList]
41
42 profile = []
43 for currentRun, currentTimestamp, currentStartlb in zip(runList, timestampList, startlbList):
44 for step in range(numberOfSteps):
45 events = eventsPerStep + 1 if step < stepsWithExtraEvent else eventsPerStep
46 mu = float(startMu + (step * stepMu))
47 profile += [{'run': currentRun, 'lb': currentStartlb + step, 'starttstamp': currentTimestamp,
48 'evts': _evts(events), 'mu': mu}]
49 return profile
setupProfile(flags, scaleTaskLength=1)