68 def calcFromList(self,triggername,lblist):
69 """ Calculate the integrated luminosity for a list of LBs, returning
70 a list of (run,lb,lumiResult,evts) object tuples
71 (note, this is the only difference in functionality between coolLumiCalc and coolLumiResultsGetter)
72 """
73 lumiResults = []
74
75 triggerlevel=self.triggerLevel(triggername)
76 if triggerlevel != 1:
77 raise Exception("Please use a L1 trigger for this tool.")
78 totalL=0
79 totaltime=0.
80 totalacc=3*[0]
81 totalgoodblock=0
82 totalbadblock=0
83
84 folderLBCOUNTL1=self.cooldb.getFolder('/TRIGGER/LUMI/LVL1COUNTERS')
85 folderL1PRESCALE=self.cooldb.getFolder('/TRIGGER/LVL1/Prescales')
86 folderL1LB=self.cooldb.getFolder('/TRIGGER/LUMI/LBLB')
87
88 for lbinfo in lblist:
89
90 runstat,chainnums,hltprescale=self._getChains(lbinfo.run,triggername,triggerlevel)
91 if (self.loglevel>1):
92 print ("L1 chain number", chainnums[0])
93 if (runstat):
94 since,until=lbinfo.IOVRange()
95
96 if (self.detstatus!=""):
97 if (self.loglevel>0):
98 print (lbinfo, ": Applying detector status cuts: %s" % self.detstatus)
99 gooddetstatus=statusCutsToRange(self.detstatusdb,'/GLOBAL/DETSTATUS/LBSUMM',since,until,self.detstatustag,self.detstatus)
100 else:
101 gooddetstatus=RangeList(since,until)
102
103 if (self.loglevel>1):
104 print ("LumiB L1-Acc L1-pre LiveTime MeanInts IntL/ub-1")
105
106 l1precache=IOVCache()
107 itr=folderL1PRESCALE.browseObjects(since,until-1,cool.ChannelSelection(chainnums[0]))
108 while (itr.goToNext()):
109 obj=itr.currentRef()
110 l1precache.add(obj.since(),obj.until(),obj.payload()['Lvl1Prescale'])
111 itr.close()
112
113 lumicache=self.getLumiMuCache(since,until)
114
115
116
117 l1countitr=folderLBCOUNTL1.browseObjects(since,until-1,cool.ChannelSelection(chainnums[0]))
118 l1lbiter=folderL1LB.browseObjects(since,until-1,cool.ChannelSelection(0))
119 while l1countitr.goToNext():
120
121 l1countobj=l1countitr.currentRef()
122 lb=l1countobj.since() & 0xFFFFFFFF
123 l1lbiter.goToNext()
124 lblbobj=l1lbiter.currentRef()
125 if (lblbobj.since()!=l1countobj.since()):
126 raise Exception("L1 counter/lumiblock synchronisation error. Cannot get length of Lumiblocks!")
127 l1payload=l1countobj.payload()
128 lblbpayload =lblbobj.payload()
129 l1acc=l1payload['L1Accept']
130 l1dt=(lblbpayload['EndTime']-lblbpayload['StartTime'])*1.0e-09
131 l1tstart=lblbpayload['StartTime']
132
133
134 if (l1payload['AfterPrescale']>0):
135 livefrac=float(l1payload['L1Accept'])/float(l1payload['AfterPrescale'])
136 else:
137 livefrac=1.
138 pass
139 if (len(gooddetstatus.getAllowedRanges(l1countobj.since(),l1countobj.until()))>0):
140
141
142
143
144 try:
145 (lumi,evtsbx)=lumicache.find(l1countobj.since())
146 except TypeError:
147 if (self.lumimethod != 'EXTERNAL'):
148 print ("WARNING: No payload in", self.lumifoldername, "for run", lbinfo.run, "[", lb, "]!")
149 lumi=0
150 evtsbx=0
151 pass
152 l1prescale=l1precache.find(l1countobj.since())
153 if (lumi is not None and l1prescale is not None):
154
155
156
157 livetime=livefrac*l1dt
158 if self.useprescale:
159 intlumi=(lumi*livetime)/(1.0 * l1prescale)
160 if not (intlumi >= 0):
161 print ("WARNING:",lbinfo.run,"[",lb,"]: bad lumi, prescale or livetime found:(IL,LV):", lumi,livetime)
162 else:
163 intlumi=(lumi*livetime)
164 if not (intlumi >= 0):
165 print ("WARNING:",lbinfo.run,"[",lb,"]: bad lumi or livetime found:(IL,LV)", lumi,livetime)
166
167 if (self.loglevel>1):
168 print ("%5i %7i %8i %8.2f %8.7f %10.1f" % (lb,l1acc,l1prescale,livetime,evtsbx,intlumi))
169 elif (lumi is not None):
170 intlumi=(lumi*livetime)
171 if (self.loglevel>1):
172 print ("%5i %7i %8i %8s %8.7f %10.if <missing prescale>" %(lb,l1acc,"??",livetime,evtsbx,intlumi))
173 if not (intlumi >= 0):
174 print ("WARNING:",lbinfo.run,"[",lb,"]: bad lumi or livetime found:(IL,LV)", lumi,livetime)
175 else:
176 intlumi=0
177 if (self.loglevel>1):
178 print ("%5i %7i %8i %8s %8s %10s <missing prescale>" %(lb,l1acc,"??",livetime,"??","??"))
179 lumiResults.append( (lbinfo.run, int(lb), lumiResult(intlumi,l1acc,0,0,livetime,1,0), evtsbx, l1tstart ) )
180
181 totalacc[0]+=l1acc
182 totaltime+=livetime
183 totalL+=intlumi
184 totalgoodblock+=1
185 else:
186 totalbadblock+=1
187 pass
188 pass
189 l1countitr.close()
190 else:
191 print ("WARNING: Trigger not defined for run",lbinfo.run)
192 pass
193 if (self.loglevel>0):
194 print ("Running total after %24s:" % lbinfo, " %7i events; %8.2f seconds; %10.1f (nb^-1)" % (totalacc[0],totaltime,totalL))
195 pass
196 return lumiResults
197