ATLAS Offline Software
TileJetMonitorAlgorithm.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 #
4 
5 '''
6 @file TileJetMonitorAlgorithm.py
7 @brief Python configuration of TileJetMonitorAlgorithm algorithm for the Run III
8 '''
9 
10 
11 def TileJetMonitoringConfig(flags, **kwargs):
12 
13  ''' Function to configure TileJetMonitorAlgorithm algorithm in the monitoring system.'''
14 
15  # Define one top-level monitoring algorithm. The new configuration
16  # framework uses a component accumulator.
17  from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
18  result = ComponentAccumulator()
19 
20  from TileGeoModel.TileGMConfig import TileGMCfg
21  result.merge(TileGMCfg(flags))
22 
23  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
24  result.merge(LArGMCfg(flags))
25 
26  from TileConditions.TileCablingSvcConfig import TileCablingSvcCfg
27  result.merge( TileCablingSvcCfg(flags) )
28 
29  from TileConditions.TileBadChannelsConfig import TileBadChanToolCfg
30  badChanTool = result.popToolsAndMerge( TileBadChanToolCfg(flags) )
31 
32  # The following class will make a sequence, configure algorithms, and link
33  # them to GenericMonitoringTools
34  from AthenaMonitoring import AthMonitorCfgHelper
35  helper = AthMonitorCfgHelper(flags,'TileMonitoring')
36 
37  # Adding an TileJetMonitorAlgorithm algorithm to the helper
38  from AthenaConfiguration.ComponentFactory import CompFactory
39  tileJetMonAlg = helper.addAlgorithm(CompFactory.TileJetMonitorAlgorithm, 'TileJetMonAlg')
40 
41  tileJetMonAlg.TileBadChanTool = badChanTool
42  tileJetMonAlg.TriggerChain = ''
43 
44  if flags.Tile.doTimingHistogramsForGain in [0, 1]:
45  kwargs.setdefault('Do1DHistograms', True)
46  if flags.Tile.doTimingHistogramsForGain == 0:
47  # Low Gain
48  kwargs.setdefault('ChannelEnergyMin', 15000)
49  kwargs.setdefault('ChannelEnergyMax', 50000)
50  kwargs.setdefault('Gain', 0)
51 
52  else:
53  # High Gain
54  kwargs.setdefault('ChannelEnergyMin', 2000)
55  kwargs.setdefault('ChannelEnergyMax', 4000)
56  kwargs.setdefault('Gain', 1)
57 
58  for k, v in kwargs.items():
59  setattr(tileJetMonAlg, k, v)
60 
61  DoEnergyProfiles = kwargs.get('DoEnergyProfiles', tileJetMonAlg._descriptors['DoEnergyProfiles'].default)
62 
63  Do1DHistograms = kwargs.get('Do1DHistograms', tileJetMonAlg._descriptors['Do1DHistograms'].default)
64  DoEnergyDiffHistograms = kwargs.get('DoEnergyDiffHistograms', tileJetMonAlg._descriptors['DoEnergyDiffHistograms'].default)
65 
66  from AthenaMonitoring.DQConfigFlags import DQDataType
67  if flags.DQ.DataType not in (DQDataType.HeavyIon, DQDataType.Cosmics):
68 
69  jvtTool = CompFactory.JetVertexTaggerTool()
70  jetContainer = kwargs.get('JetContainer', tileJetMonAlg._descriptors['JetContainer'].default)
71  jvtTool.JetContainer = str(jetContainer)
72  tileJetMonAlg.JVT = jvtTool
73 
74  jetCleaningTool = CompFactory.JetCleaningTool()
75  jetCleaningTool.CutLevel = "LooseBad"
76  jetCleaningTool.DoUgly = False
77  jetCleaningTool.JetContainer = str(jetContainer)
78 
79  tileJetMonAlg.JetCleaningTool = jetCleaningTool
80  result.addPublicTool(jetCleaningTool)
81 
82  jetPtMin = 20000
83  jetTrackingEtaLimit = 2.4
84  eventCleaningTool = CompFactory.ECUtils.EventCleaningTool()
85  eventCleaningTool.JetCleaningTool = jetCleaningTool
86  eventCleaningTool.PtCut = jetPtMin
87  eventCleaningTool.EtaCut = jetTrackingEtaLimit
88  eventCleaningTool.JvtDecorator = "passJvt"
89  eventCleaningTool.OrDecorator = "passOR"
90  eventCleaningTool.CleaningLevel = jetCleaningTool.CutLevel
91  eventCleaningTool.JetContainer = str(jetContainer)
92  eventCleaningTool.SuppressInputDependence = True
93  eventCleaningTool.SuppressOutputDependence = True
94 
95  tileJetMonAlg.EventCleaningTool = eventCleaningTool
96  tileJetMonAlg.JetTrackingEtaLimit = jetTrackingEtaLimit
97  tileJetMonAlg.JetPtMin = jetPtMin
98 
99  tileJetMonAlg.DoEventCleaning = True
100  tileJetMonAlg.DoJetCleaning = True
101 
102  else:
103 
104  tileJetMonAlg.DoEventCleaning = False
105  tileJetMonAlg.DoJetCleaning = False
106 
107  if flags.Reco.EnableHI:
108  if flags.Tracking.doUPC:
109  tileJetMonAlg.JetContainer = 'AntiKt4EMPFlowJets'
110  else:
111  tileJetMonAlg.JetContainer = 'AntiKt4HIJets'
112 
113  # 1) Configure histogram with TileJetMonAlg algorithm execution time
114  executeTimeGroup = helper.addGroup(tileJetMonAlg, 'TileJetMonExecuteTime', 'Tile/')
115  executeTimeGroup.defineHistogram('TIME_execute', path = 'Jet', type='TH1F',
116  title = 'Time for execute TileJetMonAlg algorithm;time [#mus]',
117  xbins = 300, xmin = 0, xmax = 300000)
118 
119 
120 
121  from TileMonitoring.TileMonitoringCfgHelper import addValueVsModuleAndChannelMaps, getPartitionName
122  runNumber = flags.Input.RunNumbers[0]
123 
124 
125  # 2) Configure 2D histograms (profiles/maps) with Tile channel time vs module and channel per partion (DQ summary)
126  channelTimeDQGroup = helper.addGroup(tileJetMonAlg, 'TileJetChanTimeDQ', 'Tile/Jet/')
127  addValueVsModuleAndChannelMaps(channelTimeDQGroup, name = 'tileJetChanTime', title = 'Average time with jets',
128  path = 'DQ', type = 'TProfile2D', value='time', run = str(runNumber))
129 
130 
131  gains = ['LG', 'HG']
132  partitions = ['LBA', 'LBC', 'EBA', 'EBC']
133 
134  # 3a) Configure 1D histograms with Tile channel time per partition
135  channelTimeGroup = helper.addGroup(tileJetMonAlg, 'TileJetChanTime', 'Tile/Jet/ChanTime/')
136  for partition in partitions:
137  title = 'Partition ' + partition + ': Tile Channel Time;time [ns];N'
138  name = 'channelTime' + partition
139  path = partition
140  channelTimeGroup.defineHistogram(name, title = title, path = path, type = 'TH1F',
141  xbins = 600, xmin = -30.0, xmax = 30.0)
142 
143  # 3b) Configure 1D histograms with Tile channel time per partition for extended barrels without scintillators
144  for partition in ['EBA', 'EBC']:
145  title = 'Partition ' + partition + ': Tile Channel Time (without scintillators);time [ns];N'
146  name = 'channelTime' + partition + '_NoScint'
147  path = partition
148  channelTimeGroup.defineHistogram(name, title = title, path = path, type = 'TH1F',
149  xbins = 600, xmin = -30.0, xmax = 30.0)
150 
151 
152  # Energy upper limits of the cell-time histograms
153  energiesHG = [500, 1000, 2000, 4000, 6000, 8000, 10000, 13000, 16000, 20000]
154  energiesLG = [25000, 30000, 40000, 50000, 65000, 80000]
155  energiesALL = {'LG' : energiesLG, 'HG' : energiesHG}
156  tileJetMonAlg.CellEnergyUpperLimitsHG = energiesHG
157  tileJetMonAlg.CellEnergyUpperLimitsLG = energiesLG
158 
159  samples_LB = ['A', 'BC', 'D', 'B9']
160  samples_EB = ['A', 'B', 'C10', 'D4', 'E1', 'E2', 'E3', 'E4']
161 
162  # 4) Configure histograms with Tile cell time in energy slices per partition and gain
163  cellTimeGroup = helper.addGroup(tileJetMonAlg, 'TileJetCellTime', 'Tile/Jet/CellTime/')
164  for partition in partitions:
165  for gain in gains:
166  index = 0
167  energies = energiesALL[gain]
168  for index in range(0, len(energies) + 1):
169  toEnergy = energies[index] if index < len(energies) else None
170  fromEnergy = energies[index - 1] if index > 0 else None
171  if not toEnergy:
172  title_suffix = ' > ' + str(fromEnergy) + ' MeV; time [ns]'
173  elif not fromEnergy:
174  title_suffix = ' < ' + str(toEnergy) + ' MeV; time [ns]'
175  else:
176  title_suffix = ' [' + str(fromEnergy) + ' .. ' + str(toEnergy) + ') MeV; time [ns]'
177 
178  # TD: add histograms per partition and per radial sampling
179  if (partition == 'LBA') or (partition == 'LBC'):
180  for samp in range(0,len(samples_LB)):
181  name = 'Cell_time_' + partition + '_' + samples_LB[samp] + '_' + gain + '_slice_' + str(index)
182  title = 'Partition ' + partition + ', sampling ' + samples_LB[samp] + ': ' + gain + ' Tile Cell time in energy range' + title_suffix
183  cellTimeGroup.defineHistogram(name, title = title, path = partition, type = 'TH1F',
184  xbins = 600, xmin = -30.0, xmax = 30.0)
185  else:
186  for samp in range(0,len(samples_EB)):
187  name = 'Cell_time_' + partition + '_' + samples_EB[samp] + '_' + gain + '_slice_' + str(index)
188  title = 'Partition ' + partition + ', sampling ' + samples_EB[samp] + ': ' + gain + ' Tile Cell time in energy range' + title_suffix
189  cellTimeGroup.defineHistogram(name, title = title, path = partition, type = 'TH1F',
190  xbins = 600, xmin = -30.0, xmax = 30.0)
191 
192 
193  if DoEnergyProfiles:
194 
195  # 5) Configure 1D histograms (profiles) with Tile cell energy profile in energy slices per partition and gain
196  cellEnergyProfileGroup = helper.addGroup(tileJetMonAlg, 'TileJetCellEnergyProfile', 'Tile/Jet/CellTime/')
197  for partition in partitions:
198  for gain in gains:
199  # TD: add profiles per partition and per sampling
200  if (partition == 'LBA') or (partition == 'LBC'):
201  for samp in range(0,len(samples_LB)):
202  name = 'index_' + partition + '_' + samples_LB[samp] + '_' + gain
203  name += ',energy_' + partition + '_' + samples_LB[samp] + '_' + gain
204  name += ';Cell_ene_' + partition + '_' + samples_LB[samp] + '_' + gain + '_prof'
205  title = 'Partition ' + partition + ', sampling ' + samples_LB[samp] + ': ' + gain + ' Tile Cell energy profile;Slice;Energy [MeV]'
206  xmax = len(energiesALL[gain]) + 0.5
207  nbins = len(energiesALL[gain]) + 1
208  cellEnergyProfileGroup.defineHistogram(name, title = title, path = partition, type = 'TProfile',
209  xbins = nbins, xmin = -0.5, xmax = xmax)
210  else:
211  for samp in range(0,len(samples_EB)):
212  name = 'index_' + partition + '_' + samples_EB[samp] + '_' + gain
213  name += ',energy_' + partition + '_' + samples_EB[samp] + '_' + gain
214  name += ';Cell_ene_' + partition + '_' + samples_EB[samp] + '_' + gain + '_prof'
215  title = 'Partition ' + partition + ', sampling ' + samples_EB[samp] + ': ' + gain + ' Tile Cell energy profile;Slice;Energy [MeV]'
216  xmax = len(energiesALL[gain]) + 0.5
217  nbins = len(energiesALL[gain]) + 1
218  cellEnergyProfileGroup.defineHistogram(name, title = title, path = partition, type = 'TProfile',
219  xbins = nbins, xmin = -0.5, xmax = xmax)
220 
221 
222  else:
223 
224  # 6) Configure 1D histograms with Tile cell energy in energy slices per partition, gain and slice
225  cellEnergyGroup = helper.addGroup(tileJetMonAlg, 'TileJetCellEnergy', 'Tile/Jet/CellTime/')
226  for partition in partitions:
227  for gain in gains:
228  energies = energiesALL[gain]
229  for index in range(0, len(energies) + 1):
230  toEnergy = energies[index] if index < len(energies) else 2 * energies[index - 1]
231  fromEnergy = energies[index - 1] if index > 0 else -1000
232  name = 'Cell_ene_' + partition + '_' + gain + '_slice_' + str(index)
233  title = 'Partition ' + partition + ': ' + gain + ' Tile Cell Energy'
234  title += ' in energy range [' + str(fromEnergy) + ' .. ' + str(toEnergy) + ') MeV;Energy [MeV]'
235  cellEnergyGroup.defineHistogram(name, title = title, path = partition, type = 'TH1F',
236  xbins = 100, xmin = fromEnergy, xmax = toEnergy)
237  # TD: add histograms per partition
238  if (partition == 'LBA') or (partition == 'LBC'):
239  for samp in range(0,len(samples_LB)):
240  name = 'Cell_ene_' + partition + '_' + samples_LB[samp] + '_' + gain + '_slice_' + str(index)
241  title = 'Partition ' + partition + ', sampling ' + samples_LB[samp] + ': ' + gain + ' Tile Cell Energy'
242  title += ' in energy range [' + str(fromEnergy) + ' .. ' + str(toEnergy) + ') MeV;Energy [MeV]'
243  cellEnergyGroup.defineHistogram(name, title = title, path = partition, type = 'TH1F',
244  xbins = 100, xmin = fromEnergy, xmax = toEnergy)
245  else:
246  for samp in range(0,len(samples_EB)):
247  name = 'Cell_ene_' + partition + '_' + samples_EB[samp] + '_' + gain + '_slice_' + str(index)
248  title = 'Partition ' + partition + ', sampling ' + samples_EB[samp] + ': ' + gain + ' Tile Cell Energy'
249  title += ' in energy range [' + str(fromEnergy) + ' .. ' + str(toEnergy) + ') MeV;Energy [MeV]'
250  cellEnergyGroup.defineHistogram(name, title = title, path = partition, type = 'TH1F',
251  xbins = 100, xmin = fromEnergy, xmax = toEnergy)
252 
253 
254 
255 
256  from TileCalibBlobObjs.Classes import TileCalibUtils as Tile
257 
258  if Do1DHistograms:
259 
260  # 7) Configure 1D histograms with Tile channel time per channel
261  channelTime1DGroup = helper.addGroup(tileJetMonAlg, 'TileJetChanTime1D', 'Tile/Jet/ChanTime/')
262 
263  for ros in range(1, Tile.MAX_ROS):
264  for module in range(0, Tile.MAX_DRAWER):
265  for channel in range(0, Tile.MAX_CHAN):
266  moduleName = Tile.getDrawerString(ros, module)
267  title = 'Time in ' + moduleName + ' channel ' + str(channel) + ';time [ns];N'
268  name = moduleName + '_ch_' + str(channel) + '_1d'
269  path = getPartitionName(ros) + '/' + moduleName
270  channelTime1DGroup.defineHistogram(name, title = title, path = path, type = 'TH1F',
271  xbins = 600, xmin = -30.0, xmax = 30.0)
272 
273 
274 
275  if DoEnergyDiffHistograms:
276 
277  # 7) Configure 1D histograms with Tile cell relative energy difference between two channels per even channel
278  energyDiffGroup = helper.addGroup(tileJetMonAlg, 'TileJetEnergyDiff', 'Tile/Jet/EnergyDiff/')
279 
280  for ros in range(1, Tile.MAX_ROS):
281  for module in range(0, Tile.MAX_DRAWER):
282  for channel in range(0, Tile.MAX_CHAN):
283  if not channel % 2:
284  for gain in gains:
285  moduleName = Tile.getDrawerString(ros, module)
286  title = 'Tile Cell Energy difference in ' + moduleName + ' channel ' + str(channel) + ' ' + gain
287  title += ';#frac{ene1 - ene2}{ene1 + ene2}'
288  name = moduleName + '_enediff_' + gain + '_ch1_' + str(channel)
289  path = getPartitionName(ros) + '/' + moduleName
290  energyDiffGroup.defineHistogram(name, title = title, path = path, type = 'TH1F',
291  xbins = 100, xmin = -1.0, xmax = 1.0)
292 
293 
294 
295  accumalator = helper.result()
296  result.merge(accumalator)
297  return result
298 
299 if __name__=='__main__':
300 
301  # Setup logs
302  from AthenaCommon.Logging import log
303  from AthenaCommon.Constants import INFO
304  log.setLevel(INFO)
305 
306  # Set the Athena configuration flags
307  from AthenaConfiguration.AllConfigFlags import initConfigFlags
308  from AthenaConfiguration.TestDefaults import defaultTestFiles
309  flags = initConfigFlags()
310  flags.Input.Files = defaultTestFiles.ESD
311  flags.Output.HISTFileName = 'TileJetMonitorOutput.root'
312  flags.DQ.useTrigger = False
313  flags.DQ.enableLumiAccess = False
314  flags.Exec.MaxEvents = 3
315  flags.fillFromArgs()
316  flags.lock()
317 
318  # Initialize configuration object, add accumulator, merge, and run.
319  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
320  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
321  cfg = MainServicesCfg(flags)
322  cfg.merge(PoolReadCfg(flags))
323 
324  tileJetMonitorAccumulator = TileJetMonitoringConfig(flags,
325  Do1DHistograms = True,
326  DoEnergyDiffHistograms = True)
327  cfg.merge(tileJetMonitorAccumulator)
328  #cfg.printConfig(withDetails = True, summariseProps = True)
329  flags.dump()
330 
331  cfg.store( open('TileJetMonitorAlgorithm.pkl','wb') )
332 
333  sc = cfg.run()
334 
335  import sys
336  # Success should be 0
337  sys.exit(not sc.isSuccess())
TileMonitoringCfgHelper.addValueVsModuleAndChannelMaps
def addValueVsModuleAndChannelMaps(group, name, title, path, subDirectory=False, type='TH2D', value='', trigger='', run='')
Definition: TileMonitoringCfgHelper.py:221
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
TileJetMonitorAlgorithm.TileJetMonitoringConfig
def TileJetMonitoringConfig(flags, **kwargs)
Definition: TileJetMonitorAlgorithm.py:11
python.TileBadChannelsConfig.TileBadChanToolCfg
def TileBadChanToolCfg(flags, **kwargs)
Definition: TileBadChannelsConfig.py:83
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
Constants
some useful constants -------------------------------------------------—
TileMonitoringCfgHelper.getPartitionName
def getPartitionName(ros)
Definition: TileMonitoringCfgHelper.py:40
LArGMConfig.LArGMCfg
def LArGMCfg(flags)
Definition: LArGMConfig.py:8
Trk::open
@ open
Definition: BinningType.h:40
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
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