ATLAS Offline Software
TileTBCellMonitorAlgorithm.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 #
4 '''
5 @file TileTBCellMonitorAlgorithm.py
6 @brief Python configuration of TileTBCellMonitorAlgorithm algorithm for the Run III
7 '''
8 
9 from AthenaCommon.SystemOfUnits import GeV
10 
11 
12 def TileTBCellMonitoringConfig(flags, timeRange=[-100, 100], fragIDs=[0x100, 0x101, 0x200, 0x201, 0x402], useDemoCabling=2018, useFELIX=False, **kwargs):
13 
14  ''' Function to configure TileTBCellMonitorAlgorithm algorithm in the monitoring system.'''
15 
16  suffix = "Flx" if useFELIX else ""
17  basePath = 'TestBeam/' + ('Felix' if useFELIX else 'Legacy') + '/Cell'
18 
19  cellContainer = kwargs.pop('CaloCellContainer', f'AllCalo{suffix}')
20  kwargs.setdefault('ScaleFactor', 0.25 if useFELIX else 1.0)
21  kwargs.setdefault('EnergyThresholdForTime', 1 * GeV)
22 
23  from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
24  result = ComponentAccumulator()
25 
26  from TileGeoModel.TileGMConfig import TileGMCfg
27  result.merge(TileGMCfg(flags))
28 
29  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
30  result.merge(LArGMCfg(flags))
31 
32  from TileConditions.TileCablingSvcConfig import TileCablingSvcCfg
33  result.merge(TileCablingSvcCfg(flags))
34 
35  from TileConditions.TileInfoLoaderConfig import TileInfoLoaderCfg
36  result.merge(TileInfoLoaderCfg(flags))
37 
38  from AthenaMonitoring import AthMonitorCfgHelper
39  helper = AthMonitorCfgHelper(flags, f'TileTBCell{suffix}Monitoring')
40 
41  demoCabling = kwargs.pop('useDemoCabling', 2018)
42  from TileCalibBlobObjs.Classes import TileCalibUtils as Tile
43 
44  modules = []
45  if fragIDs:
46  for fragID in fragIDs:
47  ros = fragID >> 8
48  drawer = fragID & 0x3F
49  modules += [Tile.getDrawerString(ros, drawer)]
50  else:
51  for ros in range(1, Tile.MAX_ROS):
52  for drawer in range(0, Tile.MAX_DRAWER):
53  fragIDs += [(ros << 8) | drawer]
54  modules += [Tile.getDrawerString(ros, drawer)]
55 
56  cellMonAlgorithms = []
57  gains = ['HG', 'LG'] if flags.Tile.RunType.isBiGain() else [""]
58  from AthenaConfiguration.ComponentFactory import CompFactory
59  for gain in gains:
60  cellMonAlg = helper.addAlgorithm(CompFactory.TileTBCellMonitorAlgorithm, f'TileTBCell{suffix}{gain}MonAlg')
61  cellMonAlg.CaloCellContainer = f'{cellContainer}{gain}'
62  cellMonAlg.TriggerChain = ''
63  cellMonAlg.TileFragIDs = fragIDs
64 
65  for k, v in kwargs.items():
66  setattr(cellMonAlg, k, v)
67 
68  cellMonAlgorithms += [cellMonAlg]
69 
70  towersLB = [[tower for tower in range(0, 10)], # Sample A
71  [tower for tower in range(0, 9)], # Sample BC/B
72  [tower*2 for tower in range(0, 4)]] # Sample D
73 
74  towersEB = [[tower for tower in range(11, 16)], # Sample A
75  [tower for tower in range(9, 15)], # Sample B/C
76  [tower*2 for tower in range(4, 7)]] # Sample D
77 
78  def getCellNameFromSampleAndTower(sample, tower):
79  ''' The function to get Tile cell name from sample and tower'''
80  sampleName = {0: 'A', 1: 'B', 2: 'D'}[sample]
81  if sample == 1:
82  if tower < 8:
83  sampleName += 'C' # BC1 ... BC8 in LB
84  elif tower == 9:
85  sampleName = 'C' # C10 in EB
86  cellName = f'{sampleName}{tower + 1}' if sample < 2 else f'{sampleName}{int(tower / 2)}'
87  return cellName
88 
89  def addCellHistogramsArray(helper, modules, algorithm, name, title, path='', type='TH1D',
90  xbins=100, xmin=-100, xmax=100, ybins=None, ymin=None, ymax=None,
91  run='', xvalue='', yvalue=None, aliasPrefix='', xtitle='', ytitle=''):
92  ''' This function configures 1D or 2D histograms with monitored value per Tile module and cell '''
93 
94  cellArray = helper.addArray([modules], algorithm, name, topPath=path)
95  for postfix, tool in cellArray.Tools.items():
96  moduleName = postfix[1:]
97  partition = moduleName[:3]
98  towers = towersLB if moduleName.startswith('L') else towersEB
99  for sample in range(0, 3):
100  for tower in towers[sample]:
101  cellName = getCellNameFromSampleAndTower(sample, tower)
102  fullPath = f'{partition}/{moduleName}'
103  name = f'{xvalue}_{sample}_{tower}'
104  if yvalue:
105  name += f',{yvalue}_{sample}_{tower}'
106  name += f';{aliasPrefix}{cellName}_{moduleName}'
107  fullTitle = f'Run {run} {moduleName} {cellName}: {title};{xtitle};{ytitle}'
108  tool.defineHistogram(name, title=fullTitle, path=fullPath, type=type,
109  xbins=xbins, xmin=xmin, xmax=xmax,
110  ybins=ybins, ymin=ymin, ymax=ymax)
111  return cellArray
112 
113  from TileMonitoring.TileMonitoringCfgHelper import getCellName
114  from TileMonitoring.TileMonitoringCfgHelper import getLegacyChannelForDemonstrator
115 
116  def addChannelHistogramsArray(helper, modules, algorithm, name, title, path='', type='TH1D',
117  xbins=100, xmin=-100, xmax=100, xvalue='', xtitle='', ytitle='',
118  run='', aliasPrefix='', useDemoCabling=demoCabling):
119  ''' This function configures 1D histograms with Tile monitored value per module and channel '''
120 
121  channelArray = helper.addArray([modules], algorithm, name, topPath=path)
122  for postfix, tool in channelArray.Tools.items():
123  moduleName = postfix[1:]
124  partition = moduleName[:3]
125  module = int(moduleName[3:]) - 1
126  for channel in range(0, Tile.MAX_CHAN):
127  legacyChannel = getLegacyChannelForDemonstrator(useDemoCabling, partition, module, channel)
128  cell = getCellName(partition, legacyChannel)
129  if cell:
130  cellName = cell.replace('B', 'BC') if (partition in ['LBA','LBC'] and cell and cell[0] == 'B' and cell != 'B9') else cell
131  fullPath = f'{partition}/{moduleName}'
132  name = f'{xvalue}_{channel};{aliasPrefix}_{moduleName}_{cellName}_ch_{channel}'
133  fullTitle = f'Run {run} {moduleName} {cellName} Channel {channel}: {title};{xtitle};{ytitle}'
134  tool.defineHistogram(name, title=fullTitle, path=fullPath, type=type,
135  xbins=xbins, xmin=xmin, xmax=xmax)
136  return channelArray
137 
138  totalEnergy = min(flags.Beam.Energy / GeV, 300)
139  nEnergyBins = int(totalEnergy * 2)
140  run = str(flags.Input.RunNumbers[0])
141  nTimeBins = timeRange[1] - timeRange[0]
142 
143  for cellMonAlg in cellMonAlgorithms:
144  topPath = f'{basePath}/LG' if 'LG' in cellMonAlg.name else basePath
145 
146  # Configure histogram with TileTBCellMonAlg algorithm execution time
147  executeTimeGroup = helper.addGroup(cellMonAlg, 'TileTBCellMonExecuteTime', topPath)
148  executeTimeGroup.defineHistogram('TIME_execute', path='', type='TH1F',
149  title=f'Time for execute TileTBCell{suffix}MonAlg algorithm;time [#mus]',
150  xbins=100, xmin=0, xmax=10000)
151 
152  sampleEnergyArray = helper.addArray([modules], cellMonAlg, 'TileSampleEnergy', topPath=topPath)
153  for postfix, tool in sampleEnergyArray.Tools.items():
154  moduleName = postfix[1:]
155  partition = moduleName[:3]
156  fullPath = f'{partition}/{moduleName}'
157  titlePrefix = f'Run {run} {moduleName}:'
158 
159  tool.defineHistogram(f'energy;EnergyTotal_{moduleName}', path=fullPath, type='TH1D',
160  title=f'{titlePrefix} Total energy;Energy [pC];Entries',
161  xbins=nEnergyBins, xmin=0.0, xmax=totalEnergy)
162 
163  tool.defineHistogram(f'energyA,energyBC;EnergyTotalSampleBCVsA_{moduleName}', path=fullPath, type='TH2D',
164  title=f'{titlePrefix} Total energy in sample BC vs sample A;Sample A Energy [pC];Sample B Energy [pC]',
165  xbins=nEnergyBins, xmin=0.0, xmax=totalEnergy, ybins=nEnergyBins, ymin=0.0, ymax=totalEnergy)
166 
167  tool.defineHistogram(f'energyD;EnergyTotalSampleD_{moduleName}', path=fullPath, type='TH1D',
168  title=f'{titlePrefix} Total energy in sample D;Sample D Energy [pC];Entries',
169  xbins=nEnergyBins, xmin=0.0, xmax=totalEnergy)
170 
171  addCellHistogramsArray(helper, modules, cellMonAlg, name='TileCellEnergy', path=topPath, xvalue='energy',
172  title='Tile Cell Energy', xbins=nEnergyBins, xmin=0, xmax=totalEnergy,
173  run=run, aliasPrefix='CellEnergy', xtitle='Energy [pC]', ytitle='Entries')
174 
175  addCellHistogramsArray(helper, modules, cellMonAlg, name='TileCellEnergyDiff', path=topPath, xvalue='energyDiff',
176  title='Tile Cell Energy difference between PMTs', xbins=nEnergyBins, xmin=-totalEnergy, xmax=totalEnergy,
177  run=run, aliasPrefix='CellEnergyDiff', xtitle='Energy [pC]', ytitle='Entries')
178 
179  addCellHistogramsArray(helper, modules, cellMonAlg, name='TileCellTime', path=topPath, xvalue='time',
180  title='Tile Cell Time', xbins=nTimeBins, xmin=timeRange[0], xmax=timeRange[1],
181  run=run, aliasPrefix='CellTime', xtitle='Time [ns]', ytitle='Entries')
182 
183  addCellHistogramsArray(helper, modules, cellMonAlg, name='TileCellTimeDiff', path=topPath,
184  xvalue='timeDiff', title='Tile Cell Time difference between PMTs',
185  xbins=nTimeBins, xmin=timeRange[0], xmax=timeRange[1],
186  run=run, aliasPrefix='CellTimeDiff', xtitle='Time [ns]', ytitle='Entries')
187 
188  addCellHistogramsArray(helper, modules, cellMonAlg, name='TileCellEnergyLeftVsRightPMT', path=topPath, type='TH2D',
189  xvalue='energy1', yvalue='energy2', title='Tile Cell PMT2 vs PMT1 Energy',
190  xbins=nEnergyBins, xmin=0, xmax=totalEnergy, ybins=nEnergyBins, ymin=0, ymax=totalEnergy,
191  run=run, aliasPrefix='CellEnergyLeftVsRightPMT',
192  xtitle='Energy [pC]', ytitle='Energy [pC]')
193 
194  addCellHistogramsArray(helper, modules, cellMonAlg, name='TileCellTimeLeftVsRightPMT', path=topPath, type='TH2D',
195  xvalue='time1', yvalue='time2', title='Tile Cell PMT2 vs PMT1 Time',
196  xbins=nTimeBins, xmin=timeRange[0], xmax=timeRange[1], ybins=nTimeBins, ymin=timeRange[0], ymax=timeRange[1],
197  run=run, aliasPrefix='CellTimeLeftVsRightPMT', xtitle='Time [ns]', ytitle='Time [ns]')
198 
199  addChannelHistogramsArray(helper, modules, cellMonAlg, name='TileChannelEnergy', path=f'{topPath}/ChannelEnergy', type='TH1D',
200  xvalue='energy', title='Tile channel energy', xbins=nEnergyBins, xmin=0, xmax=totalEnergy,
201  run=run, aliasPrefix='ChannelEnergy', xtitle='Energy [pC]', ytitle='Entries')
202 
203  addChannelHistogramsArray(helper, modules, cellMonAlg, name='TileChannelTime', path=f'{topPath}/ChannelTime', type='TH1D',
204  xvalue='time', title='Tile channel time', xbins=nTimeBins, xmin=timeRange[0], xmax=timeRange[1],
205  run=run, aliasPrefix='ChannelTime', xtitle='Time [ns]', ytitle='Entries')
206 
207  accumalator = helper.result()
208  result.merge(accumalator)
209  return result
210 
211 
212 if __name__=='__main__':
213 
214  # Setup logs
215  from AthenaCommon.Logging import log
216  from AthenaCommon.Constants import INFO
217  log.setLevel(INFO)
218 
219  # Set the Athena configuration flags
220  from AthenaConfiguration.AllConfigFlags import initConfigFlags
221  from AthenaConfiguration.TestDefaults import defaultTestFiles
222 
223  flags = initConfigFlags()
224  parser = flags.getArgumentParser()
225  parser.add_argument('--postExec', help='Code to execute after setup')
226  parser.add_argument('--time-range', dest='timeRange', nargs=2, default=[-200, 200], help='Time range for pulse shape histograms')
227  parser.add_argument('--frag-ids', dest='fragIDs', nargs="*", default=['0x100', '0x101', '0x200', '0x201', '0x402'],
228  help='Tile Frag IDs of modules to be monitored. Empty=ALL')
229  parser.add_argument('--demo-cabling', dest='demoCabling', type=int, default=2018, help='Time Demonatrator cabling to be used')
230  args, _ = parser.parse_known_args()
231 
232  fragIDs = [int(fragID, base=16) for fragID in args.fragIDs]
233  timeRange = [int(time) for time in args.timeRange]
234 
235  flags.Input.Files = defaultTestFiles.ESD
236  flags.Output.HISTFileName = 'TileTBCellMonitorOutput.root'
237  flags.DQ.useTrigger = False
238  flags.DQ.enableLumiAccess = False
239  flags.Exec.MaxEvents = 3
240  flags.Common.isOnline = True
241 
242  flags.fillFromArgs(parser=parser)
243  flags.lock()
244 
245  # Initialize configuration object, add accumulator, merge, and run.
246  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
247  cfg = MainServicesCfg(flags)
248 
249  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
250  cfg.merge(PoolReadCfg(flags))
251 
252  cfg.merge(TileTBCellMonitoringConfig(flags,
253  fragIDs=fragIDs,
254  timeRange=timeRange,
255  useDemoCabling=args.demoCabling))
256 
257  # Any last things to do?
258  if args.postExec:
259  log.info('Executing postExec: %s', args.postExec)
260  exec(args.postExec)
261 
262  cfg.printConfig(withDetails=True, summariseProps=True)
263 
264  cfg.store(open('TileTBCellMonitorAlgorithm.pkl', 'wb'))
265 
266  sc = cfg.run()
267 
268  import sys
269  # Success should be 0
270  sys.exit(not sc.isSuccess())
SystemOfUnits
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
TileMonitoringCfgHelper.getLegacyChannelForDemonstrator
def getLegacyChannelForDemonstrator(useDemoCabling, partition, drawer, channel)
Definition: TileMonitoringCfgHelper.py:201
python.TileInfoLoaderConfig.TileInfoLoaderCfg
def TileInfoLoaderCfg(flags, **kwargs)
Definition: TileInfoLoaderConfig.py:12
TileTBCellMonitorAlgorithm.int
int
Definition: TileTBCellMonitorAlgorithm.py:229
LArG4FSStartPointFilter.exec
exec
Definition: LArG4FSStartPointFilter.py:103
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:256
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
Constants
some useful constants -------------------------------------------------—
LArGMConfig.LArGMCfg
def LArGMCfg(flags)
Definition: LArGMConfig.py:8
min
#define min(a, b)
Definition: cfImp.cxx:40
Trk::open
@ open
Definition: BinningType.h:40
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
TileMonitoringCfgHelper.getCellName
def getCellName(partition, channel)
Definition: TileMonitoringCfgHelper.py:29
str
Definition: BTagTrackIpAccessor.cxx:11
TileTBCellMonitorAlgorithm.TileTBCellMonitoringConfig
def TileTBCellMonitoringConfig(flags, timeRange=[-100, 100], fragIDs=[0x100, 0x101, 0x200, 0x201, 0x402], useDemoCabling=2018, useFELIX=False, **kwargs)
Definition: TileTBCellMonitorAlgorithm.py:12
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69
python.TileCablingSvcConfig.TileCablingSvcCfg
def TileCablingSvcCfg(flags)
Definition: TileCablingSvcConfig.py:11
TileGMConfig.TileGMCfg
def TileGMCfg(flags)
Definition: TileGMConfig.py:7