ATLAS Offline Software
TileTBBeamMonitorAlgorithm.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 TileTBBeamMonitorAlgorithm.py
6 @brief Python configuration of TileTBBeamMonitorAlgorithm algorithm for the Run III
7 '''
8 
9 from AthenaConfiguration.Enums import Format
10 
11 
12 def TileTBBeamMonitoringConfig(flags, fragIDs=[0x100,0x101,0x200,0x201,0x402], **kwargs):
13 
14  ''' Function to configure TileTBBeamMonitorAlgorithm algorithm in the monitoring system.'''
15 
16  from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
17  result = ComponentAccumulator()
18 
19  from TileGeoModel.TileGMConfig import TileGMCfg
20  result.merge(TileGMCfg(flags))
21 
22  from TileConditions.TileCablingSvcConfig import TileCablingSvcCfg
23  result.merge(TileCablingSvcCfg(flags))
24 
25  from AthenaMonitoring import AthMonitorCfgHelper
26  helper = AthMonitorCfgHelper(flags, 'TileTBBeamMonitoring')
27 
28  from AthenaConfiguration.ComponentFactory import CompFactory
29  tileTBBeamMonAlg = helper.addAlgorithm(CompFactory.TileTBBeamMonitorAlgorithm, 'TileTBBeamMonAlg')
30 
31  tileTBBeamMonAlg.TriggerChain = ''
32 
33  kwargs.setdefault('CaloCellContainer', 'AllCalo')
34  cellContainer = kwargs['CaloCellContainer']
35 
36  kwargs.setdefault('TBperiod', 2023)
37  kwargs.setdefault('MaskMuonPMTs', [7])
38  kwargs.setdefault('TOFDifferencePairs', [[2, 1], [2, 3], [3, 1]])
39 
40  from TileCalibBlobObjs.Classes import TileCalibUtils as Tile
41 
42  modules = []
43  if fragIDs:
44  for fragID in fragIDs:
45  ros = fragID >> 8
46  drawer = fragID & 0x3F
47  modules += [Tile.getDrawerString(ros, drawer)]
48  else:
49  for ros in range(1, Tile.MAX_ROS):
50  for drawer in range(0, Tile.MAX_DRAWER):
51  fragIDs += [(ros << 8) | drawer]
52  modules += [Tile.getDrawerString(ros, drawer)]
53 
54  tileTBBeamMonAlg.TileFragIDs = fragIDs
55 
56  for k, v in kwargs.items():
57  setattr(tileTBBeamMonAlg, k, v)
58 
59  from TileMonitoring.TileTBBeamChambersCalibration import updateBeamChambersCalibrations
60  updateBeamChambersCalibrations(tileTBBeamMonAlg, flags.Input.RunNumbers[0])
61 
62  run = str(flags.Input.RunNumbers[0])
63 
64  # Configure histogram with TileTBBeamMonAlg algorithm execution time
65  executeTimeGroup = helper.addGroup(tileTBBeamMonAlg, 'TileTBBeamMonExecuteTime', 'TestBeam')
66  executeTimeGroup.defineHistogram('TIME_execute', path='BeamElements', type='TH1F',
67  title='Time for execute TileTBBeamMonAlg algorithm;time [#mus]',
68  xbins=100, xmin=0, xmax=10000)
69 
70  nMuonWallPMT = 12
71  muonWallPMTArray = helper.addArray([nMuonWallPMT], tileTBBeamMonAlg, 'MuonWallPMT', topPath='TestBeam')
72  for postfix, tool in muonWallPMTArray.Tools.items():
73  pmt = int(postfix[1:]) + 1
74  title = f'Run {run}: Muon Wall PMT{pmt} Amplitude;Amplitude [ADC];Counts'
75  name = f'amplitude;MuonWallPMT{pmt}'
76  tool.defineHistogram(name, title=title, path='BeamElements', type='TH1F',
77  xbins=410, xmin=0, xmax=4096)
78 
79  totalMuEnergyGroup = helper.addGroup(tileTBBeamMonAlg, 'TileTBTotalMuonEnergy', 'TestBeam')
80  totalMuEnergyGroup.defineHistogram('TotalMuonEnergy', path='BeamElements', type='TH1F',
81  title=f'Run {run}: Muon Wall Total Energy; [ADC]',
82  xbins=1500, xmin=0, xmax=10000)
83 
84  nScounters = 3
85  sCountersArray = helper.addArray([nScounters], tileTBBeamMonAlg, 'Scounter', topPath='TestBeam')
86  for postfix, tool in sCountersArray.Tools.items():
87  counter = int(postfix[1:]) + 1
88  title = f'Run {run}: S{counter} Counter Amplitude;Amplitude [ADC];Counts'
89  name = f'amplitude;S{counter}hist'
90  tool.defineHistogram(name, title=title, path='BeamElements', type='TH1F',
91  xbins=410, xmin=0, xmax=4096)
92 
93  nCherenkov = 3
94  cherenkovArray = helper.addArray([nCherenkov], tileTBBeamMonAlg, 'Cherenkov', topPath='TestBeam')
95  for postfix, tool in cherenkovArray.Tools.items():
96  cherenkov = int(postfix[1:]) + 1
97  title = f'Run {run}: Cherenkov {cherenkov} Amplitude;Amplitude [ADC];Counts'
98  name = f'amplitude;Cher{cherenkov}hist'
99  tool.defineHistogram(name, title=title, path='BeamElements', type='TH1F',
100  xbins=410, xmin=0, xmax=4096)
101 
102 
103  cherCompGroup = helper.addGroup(tileTBBeamMonAlg, 'CherCompare', 'TestBeam')
104  cherCompGroup.defineHistogram('amplitude1,amplitude2;CherCompare', path='BeamElements', type='TH2F',
105  title=f'Run {run}: Cherenkov2 vs Cherenkov1;Amplitude [ADC];Amplitude [ADC]',
106  xbins=410, xmin=0, xmax=4096, ybins=410, ymin=0, ymax=4096)
107 
108  nTOF = 3
109  tofArray = helper.addArray([nTOF], tileTBBeamMonAlg, 'TOF', topPath='TestBeam')
110  for postfix, tool in tofArray.Tools.items():
111  tof = int(postfix[1:]) + 1
112  title = f'Run {run}: TOF{tof};[ADC];Counts'
113  name = f'amplitude;TOF{tof}'
114  tool.defineHistogram(name, title=title, path='BeamElements', type='TH1F',
115  xbins=4096, xmin=-0.5, xmax=4095.5)
116 
117  tofDiffPairs = kwargs['TOFDifferencePairs']
118  tofDiffArray = helper.addArray([len(tofDiffPairs)], tileTBBeamMonAlg, 'TOFDiff', topPath='TestBeam')
119  for postfix, tool in tofDiffArray.Tools.items():
120  pairIdx = int(postfix.split('_').pop())
121  tof1,tof2 = tofDiffPairs[pairIdx]
122  title = f'Run {run}: TOF{tof1} - TOF{tof2} Amplitude difference;[ADC];Counts'
123  tool.defineHistogram(f'TOFDiff;TOFDiff{tof1}{tof2}', title=title, path='BeamElements',
124  type='TH1F', xbins=4096, xmin=-0.5, xmax=4095.5)
125 
126  cherenkovVsTOFArray = helper.addArray([nTOF, nCherenkov], tileTBBeamMonAlg, 'CherenkovVsTOF', topPath='TestBeam')
127  for postfix, tool in cherenkovVsTOFArray.Tools.items():
128  cherenkovTof = postfix.split('_')
129  cherenkov = int(cherenkovTof.pop()) + 1
130  tof = int(cherenkovTof.pop()) + 1
131  title = f'Run {run}: Cherenkov {cherenkov} Amplitude vs TOF{tof} Amplitude'
132  title += f';TOF{tof} Amplitude [ADC];Cherenkov{cherenkov} Amplitude [ADC]'
133  name = f'amplitudeTOF,amplitudeCherenkov;Cher{cherenkov}TOF{tof}'
134  tool.defineHistogram(name, title=title, path='BeamElements', type='TH2F',
135  xbins=410, xmin=0, xmax=4096, ybins=410, ymin=0, ymax=4096)
136 
137  pmtHitMapGroup = helper.addGroup(tileTBBeamMonAlg, 'PMTHitMap', 'TestBeam')
138  pmtHitMapGroup.defineHistogram('column,row,amplitude;PMTHitMap', path='BeamElements', type='TProfile2D',
139  title=f'Run {run}: Muon Wall PMT Hit Map',
140  xbins=4, xmin=0, xmax=4, ybins=2, ymin=0, ymax=2)
141 
142  nScaler = 3
143  scalerArray = helper.addArray([nScaler], tileTBBeamMonAlg, 'Scaler', topPath='TestBeam')
144  for postfix, tool in scalerArray.Tools.items():
145  scaler = int(postfix[1:]) + 1
146  title = f'Run {run}: Scaler S{scaler};Counts;# Events'
147  name = f'counts;Scaler{scaler}'
148  tool.defineHistogram(name, title=title, path='BeamElements', type='TH1F',
149  xbins=20000, xmin=-0.5, xmax=19999.5)
150 
151  scalerCoincedenceGroup = helper.addGroup(tileTBBeamMonAlg, 'Scaler12', 'TestBeam')
152  scalerCoincedenceGroup.defineHistogram('counts12;Scaler12', path='BeamElements', type='TH1F',
153  title=f'Run {run}: Scaler S1 and S2 coincedence;counts;# Events',
154  xbins=20000, xmin=-0.5, xmax=19999.5)
155 
156 
157  beamChambers = ['BC1', 'BC2']
158  beamChambersArray = helper.addArray([beamChambers], tileTBBeamMonAlg, 'BeamChamber', topPath='TestBeam')
159  for postfix, tool in beamChambersArray.Tools.items():
160  beamChamber = postfix[1:]
161 
162  for coordinate in ['X', 'Y']:
163  title = f'Run {run}: {beamChamber}{coordinate} Coordinate;{coordinate}[mm];Counts'
164  name = f'{beamChamber}{coordinate};{beamChamber}{coordinate}hist'
165  tool.defineHistogram(name, title=title, path='BeamElements', type='TH1F',
166  xbins=201, xmin=-100.5, xmax=100.5)
167 
168  tool.defineHistogram(f'{beamChamber}X,{beamChamber}Y;{beamChamber}Profile', path='BeamElements',
169  type='TH2D', title=f'Run {run}: {beamChamber} Beam Profile;X[mm];Y[mm]',
170  xbins=1000, xmin=-100, xmax=100, ybins=1000, ymin=-100, ymax=100)
171 
172  tool.defineHistogram(f'{beamChamber}Xsum,{beamChamber}Ysum;{beamChamber}ProfileSum', path='BeamElements',
173  type='TH2D', title=f'Run {run}: {beamChamber} Beam Profile Sum;X [mm];Y [mm]',
174  xbins=1000, xmin=-300, xmax=0, ybins=1000, ymin=-300, ymax=0)
175 
176 
177  impactProfileGroup = helper.addGroup(tileTBBeamMonAlg, 'ImpactProfile', 'TestBeam')
178  impactProfileGroup.defineHistogram('Ximp,Yimp;ImpactProfile', path='BeamElements', type='TH2F',
179  title=f'Run {run}: {beamChamber} Impact Profile;X [mm];Y [mm]',
180  xbins=200, xmin=-100, xmax=100, ybins=200, ymin=-100, ymax=100)
181 
182 
183  if cellContainer:
184  cherenkovEnergyArray = helper.addArray([nCherenkov], tileTBBeamMonAlg, 'CherenkovVsEnergy', topPath='TestBeam')
185  for postfix, tool in cherenkovEnergyArray.Tools.items():
186  cherenkov = int(postfix[1:]) + 1
187  title = f'Run {run}: Cherenkov {cherenkov} Amplitude vs Total Energy;Energy [pC]; Amplitude [ADC]'
188  name = f'totalEnergy,amplitude;Cher{cherenkov}Energy'
189  tool.defineHistogram(name, title=title, path='BeamElements', type='TH2F',
190  xbins=150, xmin=0, xmax=150, ybins=410, ymin=0, ymax=4096)
191 
192  cellEneXimpGroup = helper.addGroup(tileTBBeamMonAlg, 'CellEnergyImpactX', 'TestBeam')
193  cellEneXimpGroup.defineHistogram('Ximp,cellEnergy;CellEnergyImpactX', path='BeamElements', type='TH2F',
194  title=f'Run {run}: Maximum Cell Energy vs Impact X;X [mm];Cell Energy [pc]',
195  xbins=200, xmin=-100, xmax=100, ybins=150, ymin=0, ymax=150)
196 
197  cellEneYimpGroup = helper.addGroup(tileTBBeamMonAlg, 'CellEnergyImpactY', 'TestBeam')
198  cellEneYimpGroup.defineHistogram('Yimp,cellEnergy;CellEnergyImpactY', path='BeamElements', type='TH2F',
199  title=f'Run {run}: Maximum Cell Energy vs Impact Y;Y [mm];Cell Energy [pc]',
200  xbins=200, xmin=-100, xmax=100, ybins=150, ymin=0, ymax=150)
201 
202  totalEneXimpGroup = helper.addGroup(tileTBBeamMonAlg, 'TotalEnergyImpactX', 'TestBeam')
203  totalEneXimpGroup.defineHistogram('Ximp,totalEnergy;TotalEnergyImpactX', path='BeamElements', type='TH2F',
204  title=f'Run {run}: Total Energy vs Impact X;X [mm];Total Energy [pc]',
205  xbins=200, xmin=-100, xmax=100, ybins=150, ymin=0, ymax=150)
206 
207  totalEneYimpGroup = helper.addGroup(tileTBBeamMonAlg, 'TotalEnergyImpactY', 'TestBeam')
208  totalEneYimpGroup.defineHistogram('Yimp,totalEnergy;TotalEnergyImpactY', path='BeamElements', type='TH2F',
209  title=f'Run {run}: Total Energy vs Impact Y;Y [mm];Total Energy [pc]',
210  xbins=200, xmin=-100, xmax=100, ybins=150, ymin=0, ymax=150)
211 
212 
213  totalEneS1Group = helper.addGroup(tileTBBeamMonAlg, 'ScinCalEnergy', 'TestBeam')
214  totalEneS1Group.defineHistogram('amplitude,totalEnergy;ScinCalEnergy', path='BeamElements', type='TH2F',
215  title=f'Run {run}: Total Energy vs S1 amplitude; Amplitude [ADC];Total Energy [pc]',
216  xbins=410, xmin=0, xmax=4096, ybins=150, ymin=0, ymax=150)
217 
218 
219  accumalator = helper.result()
220  result.merge(accumalator)
221  return result
222 
223 
224 if __name__=='__main__':
225 
226  # Setup logs
227  from AthenaCommon.Logging import log
228  from AthenaCommon.Constants import INFO
229  log.setLevel(INFO)
230 
231  # Set the Athena configuration flags
232  from AthenaConfiguration.AllConfigFlags import initConfigFlags
233  from AthenaConfiguration.TestDefaults import defaultTestFiles, defaultGeometryTags
234 
235  flags = initConfigFlags()
236  parser = flags.getArgumentParser()
237  parser.add_argument('--postExec', help='Code to execute after setup')
238  parser.add_argument('--digits', default="TileDigitsCnt", help='Tile digits container')
239  parser.add_argument('--channels', default="TileRawChannelCnt",
240  help='Tile raw channel container, if empty they will be reconstructed from digits')
241  parser.add_argument('--cells', default="AllCalo",
242  help='Calo Cells container, if empty they will be reconstructed from channels')
243  parser.add_argument('--frag-ids', dest='fragIDs', nargs="*", default=['0x100', '0x101', '0x200', '0x201','0x402'],
244  help='Tile Frag IDs of modules to be monitored. Empty=ALL')
245  parser.add_argument('--demo-cabling', dest='demoCabling', type=int, default=2018, help='Time Demonatrator cabling to be used')
246  parser.add_argument('--nsamples', type=int, default=15, help='Number of samples')
247  parser.add_argument('--use-sqlite', dest='useSqlite', default='/afs/cern.ch/user/t/tiledemo/public/efmon/condb/tileSqlite.db',
248  help='Providing local SQlite file, conditions constants will be used from it')
249  args, _ = parser.parse_known_args()
250 
251  fragIDs = [int(fragID, base=16) for fragID in args.fragIDs]
252 
253  flags.Input.Files = defaultTestFiles.RAW_RUN2
254  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN2
255  flags.Output.HISTFileName = 'TileTBBeamMonitorOutput.root'
256  flags.DQ.useTrigger = False
257  flags.DQ.enableLumiAccess = False
258  flags.Exec.MaxEvents = 3
259  flags.Common.isOnline = True
260 
261  flags.Tile.doFit = True
262  flags.Tile.useDCS = False
263  flags.Tile.NoiseFilter = 0
264  flags.Tile.correctTime = False
265  flags.Tile.correctTimeJumps = False
266  flags.Tile.BestPhaseFromCOOL = False
267  flags.Tile.doOverflowFit = False
268 
269  if args.channels:
270  flags.Tile.RawChannelContainer = args.channels
271 
272  flags.fillFromArgs(parser=parser)
273  flags.lock()
274 
275  flags.dump(pattern='Tile.*|Input.*|Exec.*|IOVDb.[D|G].*', evaluate=True)
276 
277  # Initialize configuration object, add accumulator, merge, and run.
278  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
279  cfg = MainServicesCfg(flags)
280 
281  rawChannels = args.channels
282  cells = args.cells
283  if flags.Input.Format is Format.BS:
284  readDigitsFlx = 'Flx' in args.digits
285  from TileByteStream.TileByteStreamConfig import TileRawDataReadingCfg
286  cfg.merge( TileRawDataReadingCfg(flags, readMuRcv=False,
287  readDigits=(not readDigitsFlx),
288  readDigitsFlx=readDigitsFlx,
289  readBeamElem=True) )
290  else:
291  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
292  cfg.merge(PoolReadCfg(flags))
293 
294  if not rawChannels:
295  # Run reconstruction to produce Tile raw channels
296  rawChannels = flags.Tile.RawChannelContainer
297 
298  from TileRecUtils.TileRawChannelMakerConfig import TileRawChannelMakerCfg
299  cfg.merge(TileRawChannelMakerCfg(flags))
300  if args.threads and (args.threads > 1):
301  rawChMaker = cfg.getEventAlgo('TileRChMaker')
302  rawChMaker.Cardinality = args.threads
303 
304  if args.useSqlite:
305  cfg.getService('IOVDbSvc').overrideTags += [
306  f'<prefix>/TILE</prefix> <db>sqlite://;schema={args.useSqlite};dbname={flags.IOVDb.DatabaseInstance}</db>'
307  ]
308 
309 
310  if not cells:
311  # Run reconstruction to produce Tile cells
312  cells = 'AllCalo'
313  from TileRecUtils.TileCellMakerConfig import TileCellMakerCfg
314  cfg.merge(TileCellMakerCfg(flags, maskBadChannels=False, mergeChannels=False, UseDemoCabling=args.demoCabling))
315 
316 
317  cfg.merge(TileTBBeamMonitoringConfig(flags, TBperiod=2021, fragIDs=fragIDs))
318 
319  from TileConditions.TileInfoLoaderConfig import TileInfoLoaderCfg
320  cfg.merge(TileInfoLoaderCfg(flags))
321  tileInfoLoader = cfg.getService('TileInfoLoader')
322  tileInfoLoader.NSamples = args.nsamples
323  tileInfoLoader.TrigSample = (args.nsamples - 1) // 2 # Floor division
324 
325  # Any last things to do?
326  if args.postExec:
327  log.info('Executing postExec: %s', args.postExec)
328  exec(args.postExec)
329 
330  cfg.printConfig(withDetails=True, summariseProps=True)
331 
332  cfg.store(open('TileTBBeamMonitorAlgorithm.pkl', 'wb'))
333 
334  sc = cfg.run()
335 
336  import sys
337  # Success should be 0
338  sys.exit(not sc.isSuccess())
TileTBBeamMonitorAlgorithm.int
int
Definition: TileTBBeamMonitorAlgorithm.py:245
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
TileCellMakerConfig.TileCellMakerCfg
def TileCellMakerCfg(flags, mergeChannels=True, **kwargs)
Definition: TileCellMakerConfig.py:32
python.TileInfoLoaderConfig.TileInfoLoaderCfg
def TileInfoLoaderCfg(flags, **kwargs)
Definition: TileInfoLoaderConfig.py:12
TileTBBeamMonitorAlgorithm.TileTBBeamMonitoringConfig
def TileTBBeamMonitoringConfig(flags, fragIDs=[0x100, 0x101, 0x200, 0x201, 0x402], **kwargs)
Definition: TileTBBeamMonitorAlgorithm.py:12
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 -------------------------------------------------—
TileTBBeamChambersCalibration.updateBeamChambersCalibrations
def updateBeamChambersCalibrations(alg, run)
Definition: TileTBBeamChambersCalibration.py:92
Trk::open
@ open
Definition: BinningType.h:40
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
TileByteStreamConfig.TileRawDataReadingCfg
def TileRawDataReadingCfg(flags, readDigits=True, readRawChannel=True, readMuRcv=None, readMuRcvDigits=False, readMuRcvRawCh=False, readBeamElem=None, readLaserObj=None, readDigitsFlx=False, readL2=False, stateless=False, **kwargs)
Definition: TileByteStreamConfig.py:87
TileRawChannelMakerConfig.TileRawChannelMakerCfg
def TileRawChannelMakerCfg(flags, **kwargs)
Definition: TileRawChannelMakerConfig.py:10
str
Definition: BTagTrackIpAccessor.cxx:11
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