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