1 import os,coral,datetime,fnmatch
2 from RecoLuminosity.LumiDB
import nameDealer,revisionDML,dataDML,lumiTime,CommonUtil,selectionParser,hltTrgSeedMapper
4 def runList(schema,fillnum=None,runmin=None,runmax=None,startT=None,stopT=None,l1keyPattern=None,hltkeyPattern=None,amodetag=None,nominalEnergy=None,energyFlut=0.2,requiretrg=True,requirehlt=True):
5 return dataDML.runList(schema,fillnum,runmin,runmax,startT,stopT,l1keyPattern,hltkeyPattern,amodetag,nominalEnergy,energyFlut,requiretrg,requirehlt)
10 numorbit : number of orbit in the lumi section
11 numbx : number of orbits
13 lumi section length in sec
15 l = numorbit * numbx * 25.0e-09
19 input: runlist [run], (required)
20 datatag: data version (optional)
21 output : {runnumber,{hltpath:(l1bitname,l1seedexpr)}}
24 if isinstance(inputRange,list):
28 for hltpath,l1seedexpr
in hlttrgmap.items():
30 extendedmap[hltpath]=(l1bitname,l1seedexpr)
31 result[run]=extendedmap
35 input: runlist [run],(required)
36 datatag: data version (optional)
37 output: {runnumber:bitzeroname,[bitnames]}
41 def hltForRange(schema,inputRange,hltpathname=None,hltpathpattern=None,datatag=None):
44 inputRange: {run:[cmsls]} (required)
45 hltpathname: exact match hltpathname (optional)
46 hltpathpattern: regex match hltpathpattern (optional)
47 datatag : data version
48 output: {runnumber:{hltpath:[[cmslsnum,l1pass,hltaccept,hltprescale]]})}
52 def trgForRange(schema,inputRange,trgbitname=None,trgbitnamepattern=None,datatag=None):
55 inputRange {run:[cmsls]} (required)
56 trgbitname exact match trgbitname (optional)
57 trgbitnamepattern regex match trgbitname (optional)
58 datatag : data version
60 result {run,{cmslsnum:[deadtimecount,bitzero_count,bitzero_prescale,deadfraction,{bitname:[prescale,counts]}]}}
64 def instLumiForRange(schema,inputRange,beamstatus=None,withBXInfo=False,bxAlgo='OCC1',xingMinLum=1.0e-4,withBeamIntensity=False,datatag=None):
67 inputRange {run:[cmsls]} (required)
68 beamstatus: LS filter on beamstatus (optional)
69 beamenergy: LS filter on beamenergy (optional) beamenergy+-beamenergyFluc
70 withBXInfo: get per bunch info (optional)
71 bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
72 xingMinLum: cut on bx lumi value (optional)
73 withBeamInfo: get beam intensity info (optional)
76 result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,instlumi,instlumierr,startorbit,numorbit,(bxvalues,bxerrs),(bxidx,b1intensities,b2intensities)]}}
81 def instCalibratedLumiForRange(schema,inputRange,amodetag='PROTPHYS',nominalegev=3500,beamstatus=None,withBXInfo=False,bxAlgo='OCC1',xingMinLum=1.0e-4,withBeamInfo=False,normname=None,datatag=None):
83 Inst luminosity after calibration
85 inputRange {run:[cmsls]} (required)
86 amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','HIPHYS']
87 beamstatus: LS filter on beamstatus (optional)
88 beamenergy: LS filter on beamenergy (optional) beamenergy+-beamenergyFluc
89 withBXInfo: get per bunch info (optional)
90 bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
91 xingMinLum: cut on bx lumi value (optional)
92 withBeamInfo: get beam intensity info (optional)
93 normname: norm factor name to use (optional)
96 result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,calibratedlumi,calibratedlumierr,startorbit,numorbit,(bxvalues,bxerrs),(bxidx,b1intensities,b2intensities)]}}
104 raise ValueError(
'cannot find a normalization factor for the combined condition '+amodetag+
' '+nominalegev)
106 perbunchnormval=float(normval)/float(1000)
107 instresult=
instLumiForRange(schema,inputRange,beamstatus,withBXInfo,bxAlgo,withBeamIntensity,datatag)
108 for run,lsdict
in instresult.items():
110 for (lumilsnum,cmslsnum),perlsdata
in lsdict.items():
111 timestamp=perlsdata[0]
112 beamstatus=perlsdata[1]
113 beamenergy=perlsdata[2]
114 calibratedlumi=perlsdata[3]*normval
115 calibratedlumierr=perlsdata[4]*normval
116 startorbit=perlsdata[5]
117 numorbit=perlsdata[6]
119 calibfatedbxdata=
None
121 calibratedbxdata=([x*perbunchnormval
for x
in bxdata[0]],[x*perbunchnormval
for x
in bxdata[1]])
122 intensitydata=perlsdata[8]
123 result[run][(lumilsnum,cmslsnum)]=[timestamp,beamstatus,beamenergy,calibratedlumi,calibratedlumierr,startorbit,numorbit,calibfatedbxdata,intensitydata]
126 def deliveredLumiForRange(schema,inputRange,amodetag='PROTPHYS',nominalegev=3500,beamstatus=None,withBXInfo=False,bxAlgo='OCC1',xingMinLum=1.0e-4,withBeamIntensity=False,normname=None,datatag=None):
129 inputRange {run:[lsnum]} (required) [lsnum]==None means all ; [lsnum]==[] means selected ls
130 amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','HIPHYS']
131 beamstatus: LS filter on beamstatus (optional)
132 beamenergy: LS filter on beamenergy (optional) beamenergy+-beamenergyFluc
133 withBXInfo: get per bunch info (optional)
134 bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
135 xingMinLum: cut on bx lumi value (optional)
136 withBeamInfo: get beam intensity info (optional)
137 normname: norm factor name to use (optional)
138 datatag: data version
140 result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,deliveredlumi,calibratedlumierr,(bxvalues,bxerrs),(bxidx,b1intensities,b2intensities)]}}
148 raise ValueError(
'cannot find a normalization factor for the combined condition '+amodetag+
' '+nominalegev)
150 perbunchnormval=float(normval)/float(1000)
151 instresult=
instLumiForRange(schema,inputRange,beamstatus,withBXInfo,bxAlgo,withBeamIntensity,datatag)
152 for run,lslist
in inputRange.items():
154 for (lumilsnum,cmslsnum),perlsdata
in lsdict.items():
155 timestamp=perlsdata[0]
156 beamstatus=perlsdata[1]
157 beamenergy=perlsdata[2]
158 calibratedlumi=perlsdata[3]*normval
159 calibratedlumierr=perlsdata[4]*normval
160 numorbit=perlsdata[6]
163 deliveredlumi=calibratedlumi*lslen
165 calibratedbxdata=
None
167 calibratedbxdata=([x*perbunchnormval
for x
in bxdata[0]],[x*perbunchnormval
for x
in bxdata[1]])
168 intensitydata=perlsdata[8]
169 result[run][(lumilsnum,cmslsnum)]=[timestamp,beamstatus,beamenergy,deliveredlumi,calibratedlumierr,calibratedbxdata,intensitydata]
172 def lumiForRange(schema,inputRange,amodetag='PROTPHYS',beamstatus=None,beamenergy=None,beamenergyFluc=0.2,withBXInfo=False,bxAlgo='OCC1',xingMinLum=1.0e-4,withBeamInfo=False,normname=None,datatag=None):
175 inputRange {run:[cmsls]} (required)
176 amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','HIPHYS']
177 beamstatus: LS filter on beamstatus (optional)
178 beamenergy: LS filter on beamenergy (optional) beamenergy+-beamenergyFluc
179 withBXInfo: get per bunch info (optional)
180 bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
181 xingMinLum: cut on bx lumi value (optional)
182 withBeamInfo: get beam intensity info (optional)
183 normname: norm factor name to use (optional)
184 datatag: data version
186 result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,deliveredlumi,recordedlumi,calibratedlumierror,((bxidx,bxvalues,bxerrs),(bxidx,b1intensities,b2intensities)]}}
194 raise ValueError(
'cannot find a normalization factor for the combined condition '+amodetag+
' '+nominalegev)
196 perbunchnormval=float(normval)/float(1000)
198 for run,lslist
in inputRange.items():
199 if lslist
is not None and len(lslist)==0:
203 startTimeStr=cmsrunsummary[6]
208 (lumirunnum,lumidata)=
dataDML.lumiLSById(schema,lumidataid,beamstatus,beamenergy,beamenergyFluc,withBXInfo,bxAlgo,withBeamInfo)
211 for lumilsnum,perlsdata
in lumidata.items():
212 cmslsnum=perlsdata[0]
213 if lslist
is not None and cmslsnum
not in lslist:
215 instlumi=perlsdata[1]
216 instlumierror=perlsdata[2]
217 calibratedlumi=instlumi*normval
218 calibratedlumierror=instlumierror*normval
219 beamstatus=perlsdata[4]
220 beamenergy=perlsdata[5]
221 numorbit=perlsdata[6]
222 startorbit=perlsdata[7]
223 timestamp=c.OrbitToUTCTimestamp(startTimeStr,numorbit,startorbit+numorbit,0)
226 deliveredlumi=calibratedlumi*lslen
229 deadcount=trgdata[cmslsnum][0]
230 bitzerocount=trgdata[cmslsnum][1]
231 bitzeroprescale=trgdata[cmslsnum][2]
232 deadfrac=float(deadcount)/(float(bitzerocount)*float(bitzeroprescale))
235 recordedlumi=deliveredlumi*(1.0-deadfrac)
238 bxvalueblob=lumidata[8]
239 bxerrblob=lumidata[9]
243 if bxvalueblob
is not None and bxerrblob
is not None:
246 for idx,bxval
in enumerate(bxvaluearray):
247 if bxval*perbunchnormval>xingMinLum:
248 bxidxlist.append(idx)
249 bxvaluelist.append(bxval*perbunchnormval)
250 bxerrorlist.append(bxerrorarray[idx]*perbunchnormval)
251 bxdata=(bxidxlist,bxvaluelist,bxerrorlist)
254 bxindexblob=lumidata[10]
255 beam1intensityblob=lumidata[11]
256 beam2intensityblob=lumidata[12]
260 if bxindexblob
is not None and beam1intensity
is not None and beam2intensity
is not None:
264 beamdata=(bxindexlist,b1intensitylist,b2intensitylist)
265 perrunresult[(lumilsnum,cmslsnum)]=[timestamp,beamstatus,beamenergy,deliveredlumi,recordedlumi,calibratedlumierror,bxdata,beamdata]
268 result[run]=perrunresult
271 def effectiveLumiForRange(schema,inputRange,hltpathname=None,hltpathpattern=None,amodetag='PROTPHYS',beamstatus=None,beamenergy=None,beamenergyFluc=0.2,withBXInfo=False,xingMinLum=1.0e-4,bxAlgo='OCC1',withBeamInfo=False,normname=None,datatag=None):
274 inputRange {run:[cmsls]} (required)
275 hltpathname: selected hltpathname
276 hltpathpattern: regex select hltpaths
277 amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','HIPHYS']
278 beamstatus: LS filter on beamstatus (optional)
279 beamenergy: LS filter on beamenergy (optional) beamenergy+-beamenergyFluc
280 withBXInfo: get per bunch info (optional)
281 bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
282 xingMinLum: cut on bx lumi value (optional)
283 withBeamInfo: get beam intensity info (optional)
284 normname: norm factor name to use (optional)
285 datatag: data version
287 result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,deliveredlumi,recordedlumi,calibratedlumierror,{hltpath:[l1name,l1prescale,hltprescale,efflumi]},bxdata,beamdata]}}
295 raise ValueError(
'cannot find a normalization factor for the combined condition '+amodetag+
' '+nominalegev)
297 perbunchnormval=float(normval)/float(1000)
299 for run,lslist
in inputRange.items():
300 if lslist
is not None and len(lslist)==0:
304 startTimeStr=cmsrunsummary[6]
309 (lumirunnum,lumidata)=
dataDML.lumiLSById(schema,lumidataid,beamstatus,beamenergy,beamenergyFluc,withBXInfo,bxAlgo,withBeamInfo)
314 bitnames=trgrundata[3].
split(
',')
316 pathnames=hltrundata[3].
split(
',')
318 for lumilsnum,perlsdata
in lumidata.items():
319 cmslsnum=perlsdata[0]
320 if lslist
is not None and cmslsnum
not in lslist:
322 instlumi=perlsdata[1]
323 instlumierror=perlsdata[2]
324 calibratedlumi=instlumi*normval
325 calibratedlumierror=instlumierror*normval
326 beamstatus=perlsdata[4]
327 beamenergy=perlsdata[5]
328 numorbit=perlsdata[6]
329 startorbit=perlsdata[7]
330 timestamp=c.OrbitToUTCTimestamp(startTimeStr,numorbit)
333 deliveredlumi=calibratedlumi*lslen
336 if cmslsnum==0:
continue
338 deadcount=trgdata[cmslsnum][0]
339 bitzerocount=trgdata[cmslsnum][1]
340 bitzeroprescale=trgdata[cmslsnum][2]
341 deadfrac=float(deadcount)/(float(bitzerocount)*float(bitzeroprescale))
344 recordedlumi=deliveredlumi*(1.0-deadfrac)
346 l1prescaleblob=trgdata[cmslsnum][4]
348 hltprescaleblob=hltdata[cmslsnum][0]
351 for bitnum,bitprescale
in enumerate(l1prescalearray):
352 thisbitname=bitnames[bitnum]
353 trgprescalemap[thisbitname]=bitprescale
355 if hltpathname
is None and hltpathpattern
is None:
356 for hpath,l1seedexpr
in hlttrgmap.items():
360 for pathidx,nm
in enumerate(hltpathnames):
362 hltprescale=hltprescalearray[pathidx]
367 l1prescale=trgprescalemap[l1bitname]
370 if l1prescale
and hltprescale:
371 efflumi=recordedlumi*l1prescale*hltprescale
372 efflumidict[hpath]=[l1bitname,l1prescale,hltprescale,efflumi]
373 elif hltpathname
is not None:
377 for pathidx,nm
in enumerate(hltpathnames):
379 hltprescale=hltprescalearray[pathidx]
384 l1prescale=trgprescalemap[l1bitname]
387 if l1prescale
and hltprescale:
388 efflumi=recordedlumi*l1prescale*hltprescale
389 efflumidict[hpath]=[l1bitname,l1prescale,hltprescale,efflumi]
390 elif hltpathpattern
is not None:
391 for hpath,l1seexexpr
in hlttrgmap.items():
395 if fnmatch.fnmatch(hpath,hltpathpattern):
396 for pathidx,nm
in enumerate(hltpathnames):
398 hltprescale=hltprescalearray[pathidx]
403 l1prescale=trgprescalemap[l1bitname]
406 if l1prescale
and hltprescale:
407 efflumi=recordedlumi*l1prescale*hltprescale
408 efflumidict[hpath]=[l1bitname,l1prescale,hltprescale,efflumi]
411 bxvalueblob=lumidata[8]
412 bxerrblob=lumidata[9]
416 if bxvalueblob
is not None and bxerrblob
is not None:
419 for idx,bxval
in enumerate(bxvaluearray):
420 if bxval*perbunchnormval>xingMinLum:
421 bxidxlist.append(idx)
422 bxvaluelist.append(bxval*perbunchnormval)
423 bxerrorlist.append(bxerrorarray[idx]*perbunchnormval)
424 bxdata=(bxidxlist,bxvaluelist,bxerrorlist)
427 bxindexblob=lumidata[10]
428 beam1intensityblob=lumidata[11]
429 beam2intensityblob=lumidata[12]
433 if bxindexblob
is not None and beam1intensity
is not None and beam2intensity
is not None:
437 beamdata=(bxindexlist,b1intensitylist,b2intensitylist)
438 perrunresult[(lumilsnum,cmslsnum)]=[timestamp,beamstatus,beamenergy,deliveredlumi,recordedlumi,calibratedlumierror,efflumidict,bxdata,beamdata]
442 result[run]=perrunresult
def effectiveLumiForRange
def deliveredLumiForRange
def instCalibratedLumiForRange