ATLAS Offline Software
LumiDeadtimeHandler.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 #
5 # LumiDeadtimeHandler
6 #
7 # Eric Torrence - June 2011
8 #
9 # Contents:
10 #
11 # LumiDeadtimeHandler - function to determine L1 deadtime from trigger information
12 #
13 
14 # Get our global DB handler object
15 from __future__ import print_function
16 from CoolLumiUtilities.CoolDataReader import CoolDataReader
17 
18 from CoolLumiUtilities.LumiBlobConversion import unpackLiveFraction
19 
21 
22  # Constructor
23  def __init__(self):
24 
25  self.verbose = False
26 
27  # Data readers
28  self.vetoReader = None
29  self.menuReader = None
30  self.countsReader = None
31 
32  # Trigger channels to read for live fractions
33  self.trigList=['L1_EM30']
34 
35  # Storage of per-BCID deadtime (index by [runlb][bcid])
36  self.liveFracBCID = dict()
37 
38  # Storage of L1 trigger counts deadtime (index by [runlb][trigname])
39  self.liveFracTrig = dict()
40 
41  # Storage for L1 trigger name -> value mapping
42  self.trigChan = dict()
43 
44  def calculateAll(self, run):
45  self.loadData(run)
46  self.findBCIDDeadtime()
47 
48  def loadData(self, run):
49  self.loadVetoData(run)
50  self.loadTrigChannels(run)
51  self.loadTrigCounts(run)
52 
53  def loadVetoData(self, run):
54  if self.verbose: print('Loading trigger veto data')
55 
56  # Instantiate new COOL data reader if not already done
57  if self.vetoReader is None:
58  self.vetoReader = CoolDataReader('COOLONL_TRIGGER/COMP200', '/TRIGGER/LUMI/PerBcidDeadtime')
59 
60  self.vetoReader.setIOVRangeFromRun(run)
61  self.vetoReader.readData()
62 
63  if self.verbose:
64  print('Read %d Trig veto records' % len(self.vetoReader.data))
65 
66  # Read trigger channel mappings
67  # Fills self.trigChan based on values in self.trigList
68  def loadTrigChannels(self, run):
69  if self.verbose: print('Loading trigger channel data')
70 
71  self.trigChan = dict()
72  for trig in self.trigList:
73  self.trigChan[trig] = -1
74 
75  if self.menuReader is None:
76  self.menuReader = CoolDataReader('COOLONL_TRIGGER/COMP200', '/TRIGGER/LVL1/Menu')
77 
78  self.menuReader.setIOVRangeFromRun(run)
79  self.menuReader.readData()
80 
81  for obj in self.menuReader.data:
82  trigName = obj.payload()['ItemName']
83  if trigName in self.trigList:
84  self.trigChan[trigName] = int(obj.channelId())
85 
86  for trig in self.trigList:
87  if self.trigChan[trig] == -1:
88  print("Couldn't find", trig, "in run", run)
89 
90  if self.verbose:
91  print('Found', trig, 'in channel', self.trigChan[trig])
92 
93 
94  # Load all trigger counts for the given run
95  # Fills counts for all triggers with channels found in self.trigChan
96  def loadTrigCounts(self, run):
97 
98  if self.verbose:
99  print('loading Trigger Counts data')
100 
101  self.liveFracTrig = dict()
102 
103  if self.countsReader is None:
104  self.countsReader = CoolDataReader('COOLONL_TRIGGER/COMP200', '/TRIGGER/LUMI/LVL1COUNTERS')
105 
106  self.countsReader.setIOVRangeFromRun(run)
107 
108  # Build channel list
109  chanList = self.trigChan.values()
110  chanList.sort()
111 
112  # Skip any trigger we didn't find
113  tmpList = []
114  for chan in chanList:
115  if chan < 0: continue
116  tmpList.append( chan )
117  chanList = tmpList
118 
119  self.countsReader.setChannel(chanList)
120  self.countsReader.readData()
121 
122  for obj in self.countsReader.data:
123 
124  #if self.verbose:
125  # print obj.since()>>32, '/', obj.since()&0xFFFFFFFF, obj.channelId(), obj.payload()['BeforePrescale'], obj.payload()['AfterPrescale'], obj.payload()['L1Accept']
126 
127  # use the string as the dictionary key
128  ss = obj.since()
129 
130  if ss not in self.liveFracTrig:
131  self.liveFracTrig[ss] = dict()
132 
133  for (trig, chan) in self.trigChan.iteritems():
134  if chan != obj.channelId(): continue
135 
136  ratio = 0.
137  if obj.payload()['AfterPrescale'] > 0:
138  ratio = float(obj.payload()['L1Accept'])/obj.payload()['AfterPrescale']
139 
140  self.liveFracTrig[ss][trig] = ratio
141 
142  if self.verbose:
143  print(obj.since()>>32, '/', obj.since()&0xFFFFFFFF, trig, ratio)
144 
145  def findBCIDDeadtime(self):
146  if self.verbose: print('Calculating per-BCID deadtime')
147 
148  # First dictionary index is lumiblock IOV
149  self.liveFracBCID = dict()
150 
151  # Loop over each lumi block
152  for obj in self.vetoReader.data:
153 
154  key = obj.since()
155 
156  if self.verbose:
157  run = key >> 32
158  lb = key & 0xFFFFFFFF
159  bloblength = obj.payload()['HighPriority'].size()
160  print('%d %d Found trigger counter blob of length %d' % (run, lb, bloblength))
161 
162  # Unpack High Priority blob here
163  liveVec = unpackLiveFraction(obj.payload())
164  self.liveFracBCID[key] = liveVec
165 
166  # Each BCID is one 24-bit integer
167  #if self.verbose:
168  #
169  # for i in range(10):
170  # print('BICD: %d Live: %f' % (i+1, liveVec[i]))
171 
172 
173 if __name__ == '__main__':
175  odh.loadData(183128)
176  odh.findBCIDDeadtime()
177 
python.LumiBlobConversion.unpackLiveFraction
def unpackLiveFraction(trigPayload, priority='high')
Definition: LumiBlobConversion.py:271
python.Bindings.iteritems
iteritems
Definition: Control/AthenaPython/python/Bindings.py:820
python.LumiDeadtimeHandler.LumiDeadtimeHandler.trigList
trigList
Definition: LumiDeadtimeHandler.py:33
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.LumiDeadtimeHandler.LumiDeadtimeHandler.__init__
def __init__(self)
Definition: LumiDeadtimeHandler.py:23
python.LumiDeadtimeHandler.LumiDeadtimeHandler.vetoReader
vetoReader
Definition: LumiDeadtimeHandler.py:28
python.LumiDeadtimeHandler.LumiDeadtimeHandler.liveFracBCID
liveFracBCID
Definition: LumiDeadtimeHandler.py:36
python.LumiDeadtimeHandler.LumiDeadtimeHandler.calculateAll
def calculateAll(self, run)
Definition: LumiDeadtimeHandler.py:44
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
python.LumiDeadtimeHandler.LumiDeadtimeHandler.loadData
def loadData(self, run)
Definition: LumiDeadtimeHandler.py:48
python.LumiDeadtimeHandler.LumiDeadtimeHandler.liveFracTrig
liveFracTrig
Definition: LumiDeadtimeHandler.py:39
python.LumiDeadtimeHandler.LumiDeadtimeHandler.loadTrigChannels
def loadTrigChannels(self, run)
Definition: LumiDeadtimeHandler.py:68
python.LumiDeadtimeHandler.LumiDeadtimeHandler.verbose
verbose
Definition: LumiDeadtimeHandler.py:25
python.LumiDeadtimeHandler.LumiDeadtimeHandler.countsReader
countsReader
Definition: LumiDeadtimeHandler.py:30
python.LumiDeadtimeHandler.LumiDeadtimeHandler
Definition: LumiDeadtimeHandler.py:20
python.LumiDeadtimeHandler.LumiDeadtimeHandler.trigChan
trigChan
Definition: LumiDeadtimeHandler.py:42
python.LumiDeadtimeHandler.LumiDeadtimeHandler.menuReader
menuReader
Definition: LumiDeadtimeHandler.py:29
python.LumiDeadtimeHandler.LumiDeadtimeHandler.findBCIDDeadtime
def findBCIDDeadtime(self)
Definition: LumiDeadtimeHandler.py:145
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
readCCLHist.float
float
Definition: readCCLHist.py:83
python.LumiDeadtimeHandler.LumiDeadtimeHandler.loadVetoData
def loadVetoData(self, run)
Definition: LumiDeadtimeHandler.py:53
python.LumiDeadtimeHandler.LumiDeadtimeHandler.loadTrigCounts
def loadTrigCounts(self, run)
Definition: LumiDeadtimeHandler.py:96