CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
lumiCalcAPI Namespace Reference

Functions

def deliveredLumiForRange
 
def effectiveLumiForRange
 
def hltForRange
 
def hltpathsForRange
 
def instCalibratedLumiForRange
 
def instLumiForRange
 
def lslengthsec
 
def lumiForRange
 
def runList
 
def trgbitsForRange
 
def trgForRange
 

Function Documentation

def lumiCalcAPI.deliveredLumiForRange (   schema,
  inputRange,
  amodetag = 'PROTPHYS',
  nominalegev = 3500,
  beamstatus = None,
  withBXInfo = False,
  bxAlgo = 'OCC1',
  xingMinLum = 1.0e-4,
  withBeamIntensity = False,
  normname = None,
  datatag = None 
)
input:
       inputRange  {run:[lsnum]} (required) [lsnum]==None means all ; [lsnum]==[] means selected ls 
       amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','HIPHYS']
       beamstatus: LS filter on beamstatus (optional)
       beamenergy: LS filter on beamenergy (optional)  beamenergy+-beamenergyFluc
       withBXInfo: get per bunch info (optional)
       bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
       xingMinLum: cut on bx lumi value (optional)
       withBeamInfo: get beam intensity info (optional)
       normname: norm factor name to use (optional)
       datatag: data version
output:
       result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,deliveredlumi,calibratedlumierr,(bxvalues,bxerrs),(bxidx,b1intensities,b2intensities)]}}
       avg lumi unit: 1/ub

Definition at line 126 of file lumiCalcAPI.py.

References dataDML.guessnormIdByContext(), instLumiForRange(), lslengthsec(), and dataDML.luminormById().

127 def deliveredLumiForRange(schema,inputRange,amodetag='PROTPHYS',nominalegev=3500,beamstatus=None,withBXInfo=False,bxAlgo='OCC1',xingMinLum=1.0e-4,withBeamIntensity=False,normname=None,datatag=None):
128  '''
129  input:
130  inputRange {run:[lsnum]} (required) [lsnum]==None means all ; [lsnum]==[] means selected ls
131  amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','HIPHYS']
132  beamstatus: LS filter on beamstatus (optional)
133  beamenergy: LS filter on beamenergy (optional) beamenergy+-beamenergyFluc
134  withBXInfo: get per bunch info (optional)
135  bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
136  xingMinLum: cut on bx lumi value (optional)
137  withBeamInfo: get beam intensity info (optional)
138  normname: norm factor name to use (optional)
139  datatag: data version
140  output:
141  result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,deliveredlumi,calibratedlumierr,(bxvalues,bxerrs),(bxidx,b1intensities,b2intensities)]}}
142  avg lumi unit: 1/ub
143  '''
144  result = {}
145  normid=None
146  if not normname:
147  normid=dataDML.guessnormIdByContext(schema,amodetag,nominalegev)
148  if not normid:
149  raise ValueError('cannot find a normalization factor for the combined condition '+amodetag+' '+nominalegev)
150  normval=dataDML.luminormById(schema,normid)[2]
151  perbunchnormval=float(normval)/float(1000)
152  instresult=instLumiForRange(schema,inputRange,beamstatus,withBXInfo,bxAlgo,withBeamIntensity,datatag)
153  for run,lslist in inputRange.items():
154  result[run]={}
155  for (lumilsnum,cmslsnum),perlsdata in lsdict.items():
156  timestamp=perlsdata[0]
157  beamstatus=perlsdata[1]
158  beamenergy=perlsdata[2]
159  calibratedlumi=perlsdata[3]*normval
160  calibratedlumierr=perlsdata[4]*normval
161  numorbit=perlsdata[6]
162  numbx=3564
163  lslen=lslengthsec(numorbit,numbx)
164  deliveredlumi=calibratedlumi*lslen
165  bxdata=perlsdata[7]
166  calibratedbxdata=None
167  if bxdata:
168  calibratedbxdata=([x*perbunchnormval for x in bxdata[0]],[x*perbunchnormval for x in bxdata[1]])
169  intensitydata=perlsdata[8]
170  result[run][(lumilsnum,cmslsnum)]=[timestamp,beamstatus,beamenergy,deliveredlumi,calibratedlumierr,calibratedbxdata,intensitydata]
171  return result
def deliveredLumiForRange
Definition: lumiCalcAPI.py:126
def instLumiForRange
Definition: lumiCalcAPI.py:64
def guessnormIdByContext
Definition: dataDML.py:725
def lslengthsec
Definition: lumiCalcAPI.py:7
def luminormById
Definition: dataDML.py:199
def lumiCalcAPI.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 
)
input:
       inputRange  {run:[cmsls]} (required)
       hltpathname: selected hltpathname
       hltpathpattern: regex select hltpaths
       amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','HIPHYS']
       beamstatus: LS filter on beamstatus (optional)
       beamenergy: LS filter on beamenergy (optional)  beamenergy+-beamenergyFluc
       withBXInfo: get per bunch info (optional)
       bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
       xingMinLum: cut on bx lumi value (optional)
       withBeamInfo: get beam intensity info (optional)
       normname: norm factor name to use (optional)
       datatag: data version
output:
result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,deliveredlumi,recordedlumi,calibratedlumierror,{hltpath:[l1name,l1prescale,hltprescale,efflumi]},bxdata,beamdata]}}
       lumi unit: 1/ub

Definition at line 271 of file lumiCalcAPI.py.

References hltTrgSeedMapper.findUniqueSeed(), dataDML.guessDataIdByRun(), dataDML.guessnormIdByContext(), dataDML.hltLSById(), dataDML.hltRunById(), dataDML.hlttrgMappingByrun(), lslengthsec(), dataDML.lumiLSById(), dataDML.luminormById(), dataDML.runsummary(), split, dataDML.trgLSById(), dataDML.trgRunById(), and CommonUtil.unpackBlobtoArray().

272 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):
273  '''
274  input:
275  inputRange {run:[cmsls]} (required)
276  hltpathname: selected hltpathname
277  hltpathpattern: regex select hltpaths
278  amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','HIPHYS']
279  beamstatus: LS filter on beamstatus (optional)
280  beamenergy: LS filter on beamenergy (optional) beamenergy+-beamenergyFluc
281  withBXInfo: get per bunch info (optional)
282  bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
283  xingMinLum: cut on bx lumi value (optional)
284  withBeamInfo: get beam intensity info (optional)
285  normname: norm factor name to use (optional)
286  datatag: data version
287  output:
288  result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,deliveredlumi,recordedlumi,calibratedlumierror,{hltpath:[l1name,l1prescale,hltprescale,efflumi]},bxdata,beamdata]}}
289  lumi unit: 1/ub
290  '''
291  result = {}
292  normid=None
293  if not normname:
294  normid=dataDML.guessnormIdByContext(schema,amodetag,nominalegev)
295  if not normid:
296  raise ValueError('cannot find a normalization factor for the combined condition '+amodetag+' '+nominalegev)
297  normval=dataDML.luminormById(schema,normid)[2]
298  perbunchnormval=float(normval)/float(1000)
300  for run,lslist in inputRange.items():
301  if lslist is not None and len(lslist)==0:#no selected ls, do nothing for this run
302  result[run]={}
303  continue
304  cmsrunsummary=dataDML.runsummary(schema,run)
305  startTimeStr=cmsrunsummary[6]
306  lumidataid=None
307  trgdataid=None
308  hltdataid=None
309  (lumidataid,trgdataid,hltdataid)=dataDML.guessDataIdByRun(schema,run)
310  (lumirunnum,lumidata)=dataDML.lumiLSById(schema,lumidataid,beamstatus,beamenergy,beamenergyFluc,withBXInfo,bxAlgo,withBeamInfo)
311  (trgrunnum,trgdata)=dataDML.trgLSById(schema,trgdataid,withblobdata=True)
312  (hltrunnum,hltdata)=dataDML.hltLSById(schema,hltdataid)
313  trgrundata=dataDML.trgRunById(schema,trgdataid)
314  hltrundata=dataDML.hltRunById(schema,hltdataid)
315  bitnames=trgrundata[3].split(',')
316  hlttrgmap=dataDML.hlttrgMappingByrun(schema,run)
317  pathnames=hltrundata[3].split(',')
318  perrunresult={}
319  for lumilsnum,perlsdata in lumidata.items():
320  cmslsnum=perlsdata[0]
321  if lslist is not None and cmslsnum not in lslist:
322  continue
323  instlumi=perlsdata[1]
324  instlumierror=perlsdata[2]
325  calibratedlumi=instlumi*normval
326  calibratedlumierror=instlumierror*normval
327  beamstatus=perlsdata[4]
328  beamenergy=perlsdata[5]
329  numorbit=perlsdata[6]
330  startorbit=perlsdata[7]
331  timestamp=c.OrbitToUTCTimestamp(startTimeStr,numorbit)
332  numbx=3564
333  lslen=lslengthsec(numorbit,numbx)
334  deliveredlumi=calibratedlumi*lslen
335  recordedlumi=0.0
336 
337  if cmslsnum==0: continue # skip lumils
338 
339  deadcount=trgdata[cmslsnum][0] ##subject to change !!
340  bitzerocount=trgdata[cmslsnum][1]
341  bitzeroprescale=trgdata[cmslsnum][2]
342  deadfrac=float(deadcount)/(float(bitzerocount)*float(bitzeroprescale))
343  if deadfrac>1.0:
344  deadfrac=0.0 #artificial correction in case of trigger wrong prescale
345  recordedlumi=deliveredlumi*(1.0-deadfrac)
346  efflumidict={}
347  l1prescaleblob=trgdata[cmslsnum][4]
348  l1prescalearray=CommonUtil.unpackBlobtoArray(l1prescaleblob,'h')
349  hltprescaleblob=hltdata[cmslsnum][0]
350  hltprescalearray=CommonUtil.unpackBlobtoArray(hltprescaleblob,'h')
351  trgprescalemap={} #build trg prescale map {bitname:l1prescale}
352  for bitnum,bitprescale in enumerate(l1prescalearray):
353  thisbitname=bitnames[bitnum]
354  trgprescalemap[thisbitname]=bitprescale
355 
356  if hltpathname is None and hltpathpattern is None: #get all paths
357  for hpath,l1seedexpr in hlttrgmap.items():
358  hltprescale=None
359  l1prescale=None
360  efflumi=None
361  for pathidx,nm in enumerate(hltpathnames):
362  if nm==hpath:
363  hltprescale=hltprescalearray[pathidx]
364  break
365  try:
366  l1bitname=hltTrgSeedMapper.findUniqueSeed(hpath,l1seedexpr)
367  if l1bitname:
368  l1prescale=trgprescalemap[l1bitname]
369  except KeyError:
370  l1prescale=None
371  if l1prescale and hltprescale:
372  efflumi=recordedlumi*l1prescale*hltprescale
373  efflumidict[hpath]=[l1bitname,l1prescale,hltprescale,efflumi]
374  elif hltpathname is not None: #get one path
375  hltprescale=None
376  l1prescale=None
377  efflumi=None
378  for pathidx,nm in enumerate(hltpathnames):
379  if nm==hltpathname:
380  hltprescale=hltprescalearray[pathidx]
381  break
382  try:
383  l1bitname=hltTrgSeedMapper.findUniqueSeed(hltpathname,l1seedexpr)
384  if l1bitname:
385  l1prescale=trgprescalemap[l1bitname]
386  except KeyError:
387  l1prescale=None
388  if l1prescale and hltprescale:
389  efflumi=recordedlumi*l1prescale*hltprescale
390  efflumidict[hpath]=[l1bitname,l1prescale,hltprescale,efflumi]
391  elif hltpathpattern is not None: #get paths matching pattern
392  for hpath,l1seexexpr in hlttrgmap.items():
393  hltprescale=None
394  l1prescale=None
395  efflumi=None
396  if fnmatch.fnmatch(hpath,hltpathpattern):#use fnmatch rules
397  for pathidx,nm in enumerate(hltpathnames):
398  if nm==hpath:
399  hltprescale=hltprescalearray[pathidx]
400  break
401  try:
402  l1bitname=hltTrgSeedMapper.findUniqueSeed(hpath,l1seedexpr)
403  if l1bitname:
404  l1prescale=trgprescalemap[l1bitname]
405  except KeyError:
406  l1prescale=None
407  if l1prescale and hltprescale:
408  efflumi=recordedlumi*l1prescale*hltprescale
409  efflumidict[hpath]=[l1bitname,l1prescale,hltprescale,efflumi]
410  bxdata=None
411  if withBXInfo:
412  bxvalueblob=lumidata[8]
413  bxerrblob=lumidata[9]
414  bxidxlist=[]
415  bxvaluelist=[]
416  bxerrorlist=[]
417  if bxvalueblob is not None and bxerrblob is not None:
418  bxvaluearray=CommonUtil.unpackBlobtoArray(bxvalueblob,'f')
419  bxerrorarray=CommonUtil.unpackBlobtoArray(bxerrblob,'f')
420  for idx,bxval in enumerate(bxvaluearray):
421  if bxval*perbunchnormval>xingMinLum:
422  bxidxlist.append(idx)
423  bxvaluelist.append(bxval*perbunchnormval)
424  bxerrorlist.append(bxerrorarray[idx]*perbunchnormval)
425  bxdata=(bxidxlist,bxvaluelist,bxerrorlist)
426  beamdata=None
427  if withBeamInfo:
428  bxindexblob=lumidata[10]
429  beam1intensityblob=lumidata[11]
430  beam2intensityblob=lumidata[12]
431  bxindexlist=[]
432  b1intensitylist=[]
433  b2intensitylist=[]
434  if bxindexblob is not None and beam1intensity is not None and beam2intensity is not None:
435  bxindexlist=CommonUtil.unpackBlobtoArray(bxindexblob,'h').tolist()
436  beam1intensitylist=CommonUtil.unpackBlobtoArray(beam1intensityblob,'f').tolist()
437  beam2intensitylist=CommonUtil.unpackBlobtoArray(beam2intensityblob,'f').tolist()
438  beamdata=(bxindexlist,b1intensitylist,b2intensitylist)
439  perrunresult[(lumilsnum,cmslsnum)]=[timestamp,beamstatus,beamenergy,deliveredlumi,recordedlumi,calibratedlumierror,efflumidict,bxdata,beamdata]
440  lumidata.clear() #clean lumi memory
441  trgdata.clear()
442  hltdata.clear()
443  result[run]=perrunresult
return result
def hlttrgMappingByrun
Definition: dataDML.py:608
def effectiveLumiForRange
Definition: lumiCalcAPI.py:271
def hltRunById
Definition: dataDML.py:572
def trgRunById
Definition: dataDML.py:245
def unpackBlobtoArray
Definition: CommonUtil.py:134
def runsummary
Definition: dataDML.py:85
def guessnormIdByContext
Definition: dataDML.py:725
def hltLSById
Definition: dataDML.py:645
def lslengthsec
Definition: lumiCalcAPI.py:7
def trgLSById
Definition: dataDML.py:286
def lumiLSById
Definition: dataDML.py:374
def guessDataIdByRun
Definition: dataDML.py:685
double split
Definition: MVATrainer.cc:139
def luminormById
Definition: dataDML.py:199
def lumiCalcAPI.hltForRange (   schema,
  inputRange,
  hltpathname = None,
  hltpathpattern = None,
  datatag = None 
)
input:
       inputRange: {run:[cmsls]} (required)
       hltpathname: exact match hltpathname  (optional) 
       hltpathpattern: regex match hltpathpattern (optional)
       datatag : data version
output: {runnumber:{hltpath:[[cmslsnum,l1pass,hltaccept,hltprescale]]})}

Definition at line 41 of file lumiCalcAPI.py.

41 
42 def hltForRange(schema,inputRange,hltpathname=None,hltpathpattern=None,datatag=None):
43  '''
44  input:
45  inputRange: {run:[cmsls]} (required)
46  hltpathname: exact match hltpathname (optional)
47  hltpathpattern: regex match hltpathpattern (optional)
48  datatag : data version
49  output: {runnumber:{hltpath:[[cmslsnum,l1pass,hltaccept,hltprescale]]})}
50  '''
51  pass
def hltForRange
Definition: lumiCalcAPI.py:41
def lumiCalcAPI.hltpathsForRange (   schema,
  runlist 
)
input: runlist [run],     (required)      
       datatag: data version (optional)
output : {runnumber,{hltpath:(l1bitname,l1seedexpr)}}

Definition at line 17 of file lumiCalcAPI.py.

References dataDML.hlttrgMappingByrun().

17 
18 def hltpathsForRange(schema,runlist):
19  '''
20  input: runlist [run], (required)
21  datatag: data version (optional)
22  output : {runnumber,{hltpath:(l1bitname,l1seedexpr)}}
23  '''
24  result={}
25  if isinstance(inputRange,list):
26  for run in runlist:
27  extendedmap={}
28  hlttrgmap=dataDML.hlttrgMappingByrun(run)
29  for hltpath,l1seedexpr in hlttrgmap.items():
30  l1bitname=hltTrgSeedMapper(hltpath,l1seedexpr)
31  extendedmap[hltpath]=(l1bitname,l1seedexpr)
32  result[run]=extendedmap
return result
def hlttrgMappingByrun
Definition: dataDML.py:608
def hltpathsForRange
Definition: lumiCalcAPI.py:17
def lumiCalcAPI.instCalibratedLumiForRange (   schema,
  inputRange,
  amodetag = 'PROTPHYS',
  nominalegev = 3500,
  beamstatus = None,
  withBXInfo = False,
  bxAlgo = 'OCC1',
  xingMinLum = 1.0e-4,
  withBeamInfo = False,
  normname = None,
  datatag = None 
)
Inst luminosity after calibration
input:
       inputRange  {run:[cmsls]} (required)
       amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','HIPHYS']
       beamstatus: LS filter on beamstatus (optional)
       beamenergy: LS filter on beamenergy (optional)  beamenergy+-beamenergyFluc
       withBXInfo: get per bunch info (optional)
       bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
       xingMinLum: cut on bx lumi value (optional)
       withBeamInfo: get beam intensity info (optional)
       normname: norm factor name to use (optional)
       datatag: data version
output:
       result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,calibratedlumi,calibratedlumierr,startorbit,numorbit,(bxvalues,bxerrs),(bxidx,b1intensities,b2intensities)]}}
       lumi unit: HZ/ub

Definition at line 81 of file lumiCalcAPI.py.

81 
82 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  '''
84  Inst luminosity after calibration
85  input:
86  inputRange {run:[cmsls]} (required)
87  amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','HIPHYS']
88  beamstatus: LS filter on beamstatus (optional)
89  beamenergy: LS filter on beamenergy (optional) beamenergy+-beamenergyFluc
90  withBXInfo: get per bunch info (optional)
91  bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
92  xingMinLum: cut on bx lumi value (optional)
93  withBeamInfo: get beam intensity info (optional)
94  normname: norm factor name to use (optional)
95  datatag: data version
96  output:
97  result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,calibratedlumi,calibratedlumierr,startorbit,numorbit,(bxvalues,bxerrs),(bxidx,b1intensities,b2intensities)]}}
98  lumi unit: HZ/ub
99  '''
100  result = {}
101  normid=None
102  if not normname:
103  normid=dataDML.guessnormIdByContext(schema,amodetag,nominalegev)
104  if not normid:
105  raise ValueError('cannot find a normalization factor for the combined condition '+amodetag+' '+nominalegev)
106  normval=dataDML.luminormById(schema,normid)[2]
107  perbunchnormval=float(normval)/float(1000)
108  instresult=instLumiForRange(schema,inputRange,beamstatus,withBXInfo,bxAlgo,withBeamIntensity,datatag)
109  for run,lsdict in instresult.items():
110  result[run]={}
111  for (lumilsnum,cmslsnum),perlsdata in lsdict.items():
112  timestamp=perlsdata[0]
113  beamstatus=perlsdata[1]
114  beamenergy=perlsdata[2]
115  calibratedlumi=perlsdata[3]*normval
116  calibratedlumierr=perlsdata[4]*normval
117  startorbit=perlsdata[5]
118  numorbit=perlsdata[6]
119  bxdata=perlsdata[7]
120  calibfatedbxdata=None
121  if bxdata:
122  calibratedbxdata=([x*perbunchnormval for x in bxdata[0]],[x*perbunchnormval for x in bxdata[1]])
123  intensitydata=perlsdata[8]
124  result[run][(lumilsnum,cmslsnum)]=[timestamp,beamstatus,beamenergy,calibratedlumi,calibratedlumierr,startorbit,numorbit,calibfatedbxdata,intensitydata]
125  return result
def instLumiForRange
Definition: lumiCalcAPI.py:64
def guessnormIdByContext
Definition: dataDML.py:725
def instCalibratedLumiForRange
Definition: lumiCalcAPI.py:81
def luminormById
Definition: dataDML.py:199
def lumiCalcAPI.instLumiForRange (   schema,
  inputRange,
  beamstatus = None,
  withBXInfo = False,
  bxAlgo = 'OCC1',
  xingMinLum = 1.0e-4,
  withBeamIntensity = False,
  datatag = None 
)
input:
       inputRange  {run:[cmsls]} (required)
       beamstatus: LS filter on beamstatus (optional)
       beamenergy: LS filter on beamenergy (optional)  beamenergy+-beamenergyFluc
       withBXInfo: get per bunch info (optional)
       bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
       xingMinLum: cut on bx lumi value (optional)
       withBeamInfo: get beam intensity info (optional)
       datatag: data version
output:
       result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,instlumi,instlumierr,startorbit,numorbit,(bxvalues,bxerrs),(bxidx,b1intensities,b2intensities)]}}
       lumi unit: HZ/ub

Definition at line 64 of file lumiCalcAPI.py.

Referenced by deliveredLumiForRange(), and instCalibratedLumiForRange().

64 
65 def instLumiForRange(schema,inputRange,beamstatus=None,withBXInfo=False,bxAlgo='OCC1',xingMinLum=1.0e-4,withBeamIntensity=False,datatag=None):
66  '''
67  input:
68  inputRange {run:[cmsls]} (required)
69  beamstatus: LS filter on beamstatus (optional)
70  beamenergy: LS filter on beamenergy (optional) beamenergy+-beamenergyFluc
71  withBXInfo: get per bunch info (optional)
72  bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
73  xingMinLum: cut on bx lumi value (optional)
74  withBeamInfo: get beam intensity info (optional)
75  datatag: data version
76  output:
77  result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,instlumi,instlumierr,startorbit,numorbit,(bxvalues,bxerrs),(bxidx,b1intensities,b2intensities)]}}
78  lumi unit: HZ/ub
79  '''
80  pass
def instLumiForRange
Definition: lumiCalcAPI.py:64
def lumiCalcAPI.lslengthsec (   numorbit,
  numbx 
)
input:
   numorbit : number of orbit in the lumi section
   numbx : number of orbits
output:
   lumi section length in sec

Definition at line 7 of file lumiCalcAPI.py.

Referenced by deliveredLumiForRange(), effectiveLumiForRange(), and lumiForRange().

7 
8 def lslengthsec(numorbit, numbx):
9  '''
10  input:
11  numorbit : number of orbit in the lumi section
12  numbx : number of orbits
13  output:
14  lumi section length in sec
15  '''
16  l = numorbit * numbx * 25.0e-09
return l
def lslengthsec
Definition: lumiCalcAPI.py:7
def lumiCalcAPI.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 
)
input:
       inputRange  {run:[cmsls]} (required)
       amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','HIPHYS']
       beamstatus: LS filter on beamstatus (optional)
       beamenergy: LS filter on beamenergy (optional)  beamenergy+-beamenergyFluc
       withBXInfo: get per bunch info (optional)
       bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
       xingMinLum: cut on bx lumi value (optional)
       withBeamInfo: get beam intensity info (optional)
       normname: norm factor name to use (optional)
       datatag: data version
output:
       result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,deliveredlumi,recordedlumi,calibratedlumierror,((bxidx,bxvalues,bxerrs),(bxidx,b1intensities,b2intensities)]}}
       lumi unit: 1/ub

Definition at line 172 of file lumiCalcAPI.py.

References dataDML.guessDataIdByRun(), dataDML.guessnormIdByContext(), lslengthsec(), dataDML.lumiLSById(), dataDML.luminormById(), dataDML.runsummary(), dataDML.trgLSById(), and CommonUtil.unpackBlobtoArray().

173 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):
174  '''
175  input:
176  inputRange {run:[cmsls]} (required)
177  amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','HIPHYS']
178  beamstatus: LS filter on beamstatus (optional)
179  beamenergy: LS filter on beamenergy (optional) beamenergy+-beamenergyFluc
180  withBXInfo: get per bunch info (optional)
181  bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
182  xingMinLum: cut on bx lumi value (optional)
183  withBeamInfo: get beam intensity info (optional)
184  normname: norm factor name to use (optional)
185  datatag: data version
186  output:
187  result {run:{(lumilsnum,cmslsnum):[timestamp,beamstatus,beamenergy,deliveredlumi,recordedlumi,calibratedlumierror,((bxidx,bxvalues,bxerrs),(bxidx,b1intensities,b2intensities)]}}
188  lumi unit: 1/ub
189  '''
190  result = {}
191  normid=None
192  if not normname:
193  normid=dataDML.guessnormIdByContext(schema,amodetag,nominalegev)
194  if not normid:
195  raise ValueError('cannot find a normalization factor for the combined condition '+amodetag+' '+nominalegev)
196  normval=dataDML.luminormById(schema,normid)[2]
197  perbunchnormval=float(normval)/float(1000)
199  for run,lslist in inputRange.items():
200  if lslist is not None and len(lslist)==0:#no selected ls, do nothing for this run
201  result[run]={}
202  continue
203  cmsrunsummary=dataDML.runsummary(schema,run)
204  startTimeStr=cmsrunsummary[6]
205  lumidataid=None
206  trgdataid=None
207  hltdataid=None
208  (lumidataid,trgdataid,hltdataid)=dataDML.guessDataIdByRun(schema,run)
209  (lumirunnum,lumidata)=dataDML.lumiLSById(schema,lumidataid,beamstatus,beamenergy,beamenergyFluc,withBXInfo,bxAlgo,withBeamInfo)
210  (trgrunnum,trgdata)=dataDML.trgLSById(schema,trgdataid,withblobdata=False)
211  perrunresult={}
212  for lumilsnum,perlsdata in lumidata.items():
213  cmslsnum=perlsdata[0]
214  if lslist is not None and cmslsnum not in lslist:
215  continue
216  instlumi=perlsdata[1]
217  instlumierror=perlsdata[2]
218  calibratedlumi=instlumi*normval
219  calibratedlumierror=instlumierror*normval
220  beamstatus=perlsdata[4]
221  beamenergy=perlsdata[5]
222  numorbit=perlsdata[6]
223  startorbit=perlsdata[7]
224  timestamp=c.OrbitToUTCTimestamp(startTimeStr,numorbit,startorbit+numorbit,0)
225  numbx=3564
226  lslen=lslengthsec(numorbit,numbx)
227  deliveredlumi=calibratedlumi*lslen
228  recordedlumi=0.0
229  if cmslsnum!=0:
230  deadcount=trgdata[cmslsnum][0] ##subject to change !!
231  bitzerocount=trgdata[cmslsnum][1]
232  bitzeroprescale=trgdata[cmslsnum][2]
233  deadfrac=float(deadcount)/(float(bitzerocount)*float(bitzeroprescale))
234  if deadfrac>1.0:
235  deadfrac=0.0 #artificial correction in case of trigger wrong prescale
236  recordedlumi=deliveredlumi*(1.0-deadfrac)
237  bxdata=None
238  if withBXInfo:
239  bxvalueblob=lumidata[8]
240  bxerrblob=lumidata[9]
241  bxidxlist=[]
242  bxvaluelist=[]
243  bxerrorlist=[]
244  if bxvalueblob is not None and bxerrblob is not None:
245  bxvaluearray=CommonUtil.unpackBlobtoArray(bxvalueblob,'f')
246  bxerrorarray=CommonUtil.unpackBlobtoArray(bxerrblob,'f')
247  for idx,bxval in enumerate(bxvaluearray):
248  if bxval*perbunchnormval>xingMinLum:
249  bxidxlist.append(idx)
250  bxvaluelist.append(bxval*perbunchnormval)
251  bxerrorlist.append(bxerrorarray[idx]*perbunchnormval)
252  bxdata=(bxidxlist,bxvaluelist,bxerrorlist)
253  beamdata=None
254  if withBeamInfo:
255  bxindexblob=lumidata[10]
256  beam1intensityblob=lumidata[11]
257  beam2intensityblob=lumidata[12]
258  bxindexlist=[]
259  b1intensitylist=[]
260  b2intensitylist=[]
261  if bxindexblob is not None and beam1intensity is not None and beam2intensity is not None:
262  bxindexlist=CommonUtil.unpackBlobtoArray(bxindexblob,'h').tolist()
263  beam1intensitylist=CommonUtil.unpackBlobtoArray(beam1intensityblob,'f').tolist()
264  beam2intensitylist=CommonUtil.unpackBlobtoArray(beam2intensityblob,'f').tolist()
265  beamdata=(bxindexlist,b1intensitylist,b2intensitylist)
266  perrunresult[(lumilsnum,cmslsnum)]=[timestamp,beamstatus,beamenergy,deliveredlumi,recordedlumi,calibratedlumierror,bxdata,beamdata]
267  lumidata.clear() #clean lumi memory
268  trgdata.clear()
269  result[run]=perrunresult
270  return result
def lumiForRange
Definition: lumiCalcAPI.py:172
def unpackBlobtoArray
Definition: CommonUtil.py:134
def runsummary
Definition: dataDML.py:85
def guessnormIdByContext
Definition: dataDML.py:725
def lslengthsec
Definition: lumiCalcAPI.py:7
def trgLSById
Definition: dataDML.py:286
def lumiLSById
Definition: dataDML.py:374
def guessDataIdByRun
Definition: dataDML.py:685
def luminormById
Definition: dataDML.py:199
def lumiCalcAPI.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 
)

Definition at line 4 of file lumiCalcAPI.py.

References dataDML.runList().

4 
5 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):
6  return dataDML.runList(schema,fillnum,runmin,runmax,startT,stopT,l1keyPattern,hltkeyPattern,amodetag,nominalEnergy,energyFlut,requiretrg,requirehlt)
def runList
Definition: dataDML.py:12
def lumiCalcAPI.trgbitsForRange (   schema,
  runlist,
  datatag = None 
)
input: runlist [run],(required)
       datatag: data version (optional)
output: {runnumber:bitzeroname,[bitnames]}

Definition at line 33 of file lumiCalcAPI.py.

33 
34 def trgbitsForRange(schema,runlist,datatag=None):
35  '''
36  input: runlist [run],(required)
37  datatag: data version (optional)
38  output: {runnumber:bitzeroname,[bitnames]}
39  '''
40  pass
def trgbitsForRange
Definition: lumiCalcAPI.py:33
def lumiCalcAPI.trgForRange (   schema,
  inputRange,
  trgbitname = None,
  trgbitnamepattern = None,
  datatag = None 
)
input :
        inputRange  {run:[cmsls]} (required)
        trgbitname exact match  trgbitname (optional)
        trgbitnamepattern regex match trgbitname (optional)
        datatag : data version
output
        result {run,{cmslsnum:[deadtimecount,bitzero_count,bitzero_prescale,deadfraction,{bitname:[prescale,counts]}]}}

Definition at line 52 of file lumiCalcAPI.py.

52 
53 def trgForRange(schema,inputRange,trgbitname=None,trgbitnamepattern=None,datatag=None):
54  '''
55  input :
56  inputRange {run:[cmsls]} (required)
57  trgbitname exact match trgbitname (optional)
58  trgbitnamepattern regex match trgbitname (optional)
59  datatag : data version
60  output
61  result {run,{cmslsnum:[deadtimecount,bitzero_count,bitzero_prescale,deadfraction,{bitname:[prescale,counts]}]}}
62  '''
63  pass
def trgForRange
Definition: lumiCalcAPI.py:52