CMS 3D CMS Logo

Functions

lumiCalcAPI Namespace Reference

Functions

def _decidenormForRun
def _decidenormFromContext
def _getnorm
def beamForRange
def deliveredLumiForRange
def effectiveLumiForRange
def fillInRange
def fillrunMap
def hltForRange
def hltpathsForRange
def instCalibratedLumiForRange
def instLumiForRange
def lumiForRange
def runList
def runsummary
def trgbitsForRange
def trgForRange
def validation

Function Documentation

def lumiCalcAPI::_decidenormForRun (   schema,
  run 
) [private]

Definition at line 20 of file lumiCalcAPI.py.

00021                                  :
00022     rundata=dataDML.runsummary(schema,run)
00023     amodetagForRun=rundata[1]
00024     egevForRun=rundata[2]
00025     normdataid=dataDML.guessnormIdByContext(schema,amodetagForRun,egevForRun)
00026     normresult=dataDML.luminormById(schema,normdataid)
00027     return normresult[2]
#public functions
def lumiCalcAPI::_decidenormFromContext (   schema,
  amodetag,
  egev 
) [private]

Definition at line 16 of file lumiCalcAPI.py.

00017                                                 :
00018     normdataid=dataDML.guessnormIdByContext(schema,amodetag,egev)
00019     normresult=dataDML.luminormById(schema,normdataid)
    return normresult[2]
def lumiCalcAPI::_getnorm (   schema,
  norm 
) [private]

Definition at line 8 of file lumiCalcAPI.py.

00009                          :
00010     if isinstance(norm,int) or isinstance(norm,float) or CommonUtil.is_floatstr(norm) or CommonUtil.is_intstr(norm):
00011         return float(norm)
00012     if not isinstance(norm,str):
00013         raise ValueError('wrong parameter type')
00014     normdataid=dataDML.guessnormIdByName(schema,norm)
00015     normresult=dataDML.luminormById(schema,normdataid)
    return normresult[2]
def lumiCalcAPI::beamForRange (   schema,
  inputRange,
  withBeamIntensity = False,
  minIntensity = 0.1,
  tableName = None,
  branchName = None 
)
input:
       inputRange: {run:[cmsls]} (required)
output : {runnumber:[(lumicmslnum,cmslsnum,beamenergy,beamstatus,[(ibx,b1,b2)])...](4)}

Definition at line 93 of file lumiCalcAPI.py.

00094                                                                                                            :
00095     '''
00096     input:
00097            inputRange: {run:[cmsls]} (required)
00098     output : {runnumber:[(lumicmslnum,cmslsnum,beamenergy,beamstatus,[(ibx,b1,b2)])...](4)}
00099     '''
00100     if tableName is None:
00101         tableName=nameDealer.lumidataTableName()
00102     if branchName is None:
00103         branchName='DATA'
00104     result={}
00105     for run in inputRange.keys():
00106         lslist=inputRange[run]
00107         if lslist is not None and len(lslist)==0:
00108             result[run]=[]#if no LS is selected for a run
00109             continue
00110         lumidataid=dataDML.guessLumiDataIdByRun(schema,run,tableName)
00111         if lumidataid is None:
00112             result[run]=None
00113             continue #run non exist
00114         lumidata=dataDML.beamInfoById(schema,lumidataid,withBeamIntensity=withBeamIntensity,minIntensity=minIntensity)
00115         #(runnum,[(lumilsnum(0),cmslsnum(1),beamstatus(2),beamenergy(3),beaminfolist(4)),..])
00116         result[run]=[]
00117         perrundata=lumidata[1]
00118         if not perrundata:
00119             result[run]=[]
00120             continue
00121         for perlsdata in perrundata:
00122             lumilsnum=perlsdata[0]
00123             cmslsnum=perlsdata[1]
00124             if lslist is not None and cmslsnum not in lslist:
00125                 continue
00126             beamstatus=perlsdata[2]
00127             beamenergy=perlsdata[3]
00128             beamintInfolist=[]
00129             if withBeamIntensity:
00130                 beamintInfolist=perlsdata[4]
00131             result[run].append((lumilsnum,cmslsnum,beamstatus,beamenergy,beamintInfolist))        
00132     return result

def lumiCalcAPI::deliveredLumiForRange (   schema,
  inputRange,
  beamstatus = None,
  amodetag = None,
  egev = None,
  withBXInfo = False,
  bxAlgo = None,
  xingMinLum = 0.0,
  withBeamIntensity = False,
  norm = None,
  datatag = 'DATA',
  finecorrections = None,
  driftcorrections = None,
  usecorrectionv2 = False,
  lumitype = 'HF',
  branchName = None 
)
delivered lumi (including calibration,time integral)
input:
       inputRange  {run:[lsnum]} (required) [lsnum]==None means all ; [lsnum]==[] means selected ls 
       amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','IONPHYS']
       beamstatus: LS filter on beamstatus (optional)
       amodetag: amodetag for  picking norm(optional)
       egev: beamenergy for picking norm(optional)
       withBXInfo: get per bunch info (optional)
       bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
       xingMinLum: cut on bx lumi value (optional)
       withBeamIntensity: get beam intensity info (optional)
       norm: norm factor name to use: if float, apply directly, if str search norm by name (optional)
       branchName: data version or branch name
output:
       result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),calibratedlumierr(6),(bxvalues,bxerrs)(7),(bxidx,b1intensities,b2intensities)(8),fillnum(9)]}
       avg lumi unit: 1/ub

Definition at line 433 of file lumiCalcAPI.py.

00434                                                                                                                                                                                                                                                                                 :
00435     '''
00436     delivered lumi (including calibration,time integral)
00437     input:
00438            inputRange  {run:[lsnum]} (required) [lsnum]==None means all ; [lsnum]==[] means selected ls 
00439            amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','IONPHYS']
00440            beamstatus: LS filter on beamstatus (optional)
00441            amodetag: amodetag for  picking norm(optional)
00442            egev: beamenergy for picking norm(optional)
00443            withBXInfo: get per bunch info (optional)
00444            bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
00445            xingMinLum: cut on bx lumi value (optional)
00446            withBeamIntensity: get beam intensity info (optional)
00447            norm: norm factor name to use: if float, apply directly, if str search norm by name (optional)
00448            branchName: data version or branch name
00449     output:
00450            result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),calibratedlumierr(6),(bxvalues,bxerrs)(7),(bxidx,b1intensities,b2intensities)(8),fillnum(9)]}
00451            avg lumi unit: 1/ub
00452     '''
00453     lumip=lumiParameters.ParametersObject()
00454     result = {}
00455     normval=None
00456     perbunchnormval=None
00457     if norm:
00458         normval=_getnorm(schema,norm)
00459         perbunchnormval=float(normval)/float(1000)
00460     elif amodetag and egev:
00461         normval=_decidenormFromContext(schema,amodetag,egev)
00462         perbunchnormval=float(normval)/float(1000)
00463     instresult=instLumiForRange(schema,inputRange,beamstatusfilter=beamstatus,withBXInfo=withBXInfo,bxAlgo=bxAlgo,xingMinLum=xingMinLum,withBeamIntensity=withBeamIntensity,lumitype=lumitype,branchName=branchName)
00464     #instLumiForRange should have aleady handled the selection,unpackblob    
00465     for run,perrundata in instresult.items():
00466         if perrundata is None:
00467             result[run]=None
00468             continue
00469         result[run]=[]
00470         if not normval:#if norm cannot be decided , look for it according to context per run
00471             normval=_decidenormForRun(schema,run)
00472             perbunchnormval=float(normval)/float(1000)
00473         if not normval:#still not found? resort to global default (should never come here)
00474             normval=6370
00475             perbunchnormval=6.37
00476             print '[Warning] using default normalization '+str(normval)
00477         for perlsdata in perrundata:#loop over ls
00478             lumilsnum=perlsdata[0]
00479             cmslsnum=perlsdata[1]
00480             timestamp=perlsdata[2]
00481             bs=perlsdata[3]
00482             beamenergy=perlsdata[4]
00483             calibratedlumi=perlsdata[5]*normval#inst lumi
00484             fillnum=perlsdata[11]
00485             if lumitype=='HF' and finecorrections and finecorrections[run]:
00486                 if usecorrectionv2:
00487                     if driftcorrections and driftcorrections[run]:
00488                         calibratedlumi=lumiCorrections.applyfinecorrectionV2(calibratedlumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
00489                     else:
00490                         calibratedlumi=lumiCorrections.applyfinecorrectionV2(calibratedlumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
00491                 else:
00492                     calibratedlumi=lumiCorrections.applyfinecorrection(calibratedlumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
00493             if lumitype=='PIXEL' and finecorrections is not None:
00494                 calibratedlumi=finecorrections[run]*calibratedlumi
00495             calibratedlumierr=perlsdata[6]*normval
00496             numorbit=perlsdata[8]
00497             numbx=lumip.NBX
00498             lslen=lumip.lslengthsec()
00499             deliveredlumi=calibratedlumi*lslen
00500             calibratedbxdata=None
00501             beamdata=None
00502             if withBXInfo:
00503                 bxdata=perlsdata[9]
00504                 if bxdata:
00505                     calibratedbxdata=(bxdata[0],[x*perbunchnormval for x in bxdata[1]],[x*perbunchnormval for x in bxdata[2]])
00506                 del bxdata[1][:]
00507                 del bxdata[2][:]
00508             if withBeamIntensity:
00509                 beamdata=perlsdata[10]             
00510             result[run].append([lumilsnum,cmslsnum,timestamp,bs,beamenergy,deliveredlumi,calibratedlumierr,calibratedbxdata,beamdata,fillnum])
00511             del perlsdata[:]
00512     return result
                       
def lumiCalcAPI::effectiveLumiForRange (   schema,
  inputRange,
  hltpathname = None,
  hltpathpattern = None,
  amodetag = None,
  beamstatus = None,
  egev = None,
  withBXInfo = False,
  xingMinLum = 0.0,
  bxAlgo = None,
  withBeamIntensity = False,
  norm = None,
  finecorrections = None,
  driftcorrections = None,
  usecorrectionv2 = False,
  lumitype = 'HF',
  branchName = None 
)
input:
       inputRange  {run:[cmsls]} (required)
       hltpathname: selected hltpathname
       hltpathpattern: regex select hltpaths           
       amodetag: amodetag for  picking norm(optional)
       egev: beamenergy for picking norm(optional)
       withBXInfo: get per bunch info (optional)
       bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
       xingMinLum: cut on bx lumi value (optional)
       withBeamIntensity: get beam intensity info (optional)
       normname: norm factor name to use (optional)
       branchName: data version
output:
result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),{hltpath:[l1name,l1prescale,hltprescale,efflumi]},bxdata,beamdata,fillnum]}
       lumi unit: 1/ub

Definition at line 690 of file lumiCalcAPI.py.

00691                                                                                                                                                                                                                                                                                                       :
00692     '''
00693     input:
00694            inputRange  {run:[cmsls]} (required)
00695            hltpathname: selected hltpathname
00696            hltpathpattern: regex select hltpaths           
00697            amodetag: amodetag for  picking norm(optional)
00698            egev: beamenergy for picking norm(optional)
00699            withBXInfo: get per bunch info (optional)
00700            bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
00701            xingMinLum: cut on bx lumi value (optional)
00702            withBeamIntensity: get beam intensity info (optional)
00703            normname: norm factor name to use (optional)
00704            branchName: data version
00705     output:
00706     result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),{hltpath:[l1name,l1prescale,hltprescale,efflumi]},bxdata,beamdata,fillnum]}
00707            lumi unit: 1/ub
00708     '''
00709     if lumitype not in ['HF','PIXEL']:
00710         raise ValueError('unknown lumitype '+lumitype)
00711     if branchName is None:
00712         branchName='DATA'
00713     lumitableName=''
00714     lumilstableName=''
00715     if lumitype=='HF':
00716         lumitableName=nameDealer.lumidataTableName()
00717         lumilstableName=nameDealer.lumisummaryv2TableName()
00718     else:
00719         lumitableName=nameDealer.pixellumidataTableName()
00720         lumilstableName=nameDealer.pixellumisummaryv2TableName()
00721     numbx=3564
00722     result = {}
00723     normval=None
00724     perbunchnormval=None
00725     if norm:
00726         normval=_getnorm(schema,norm)
00727         perbunchnormval=float(normval)/float(1000)
00728     elif amodetag and egev:
00729         normval=_decidenormFromContext(schema,amodetag,egev)
00730         perbunchnormval=float(normval)/float(1000)
00731     c=lumiTime.lumiTime()
00732     lumip=lumiParameters.ParametersObject()
00733     for run in inputRange.keys():
00734         lslist=inputRange[run]
00735         if lslist is not None and len(lslist)==0:#no selected ls, do nothing for this run
00736             result[run]=[]
00737             continue
00738         cmsrunsummary=dataDML.runsummary(schema,run)
00739         if len(cmsrunsummary)==0:#non existing run
00740             result[run]=None
00741             continue
00742         startTimeStr=cmsrunsummary[6]
00743         fillnum=cmsrunsummary[4]
00744         lumidataid=None
00745         trgdataid=None
00746         hltdataid=None
00747         lumidataid=dataDML.guessLumiDataIdByRun(schema,run,lumitableName)
00748         trgdataid=dataDML.guessTrgDataIdByRun(schema,run)
00749         hltdataid=dataDML.guessHltDataIdByRun(schema,run)
00750         if lumidataid is None or trgdataid is None or hltdataid is None:
00751             result[run]=None
00752             continue
00753         (lumirunnum,lumidata)=dataDML.lumiLSById(schema,lumidataid,beamstatus,tableName=lumilstableName)
00754         (trgrunnum,trgdata)=dataDML.trgLSById(schema,trgdataid,withPrescale=True)
00755         (hltrunnum,hltdata)=dataDML.hltLSById(schema,hltdataid,hltpathname=hltpathname,hltpathpattern=hltpathpattern)
00756         hlttrgmap=dataDML.hlttrgMappingByrun(schema,run)
00757         if not normval:#if norm cannot be decided , look for it according to context per run
00758             normval=_decidenormForRun(schema,run)
00759             perbunchnormval=float(normval)/float(1000)
00760         if not normval:#still not found? resort to global default (should never come here)
00761             normval=6370
00762             perbunchnormval=6.37
00763             print '[Warning] using default normalization '+str(normval)
00764 
00765         perrunresult=[]
00766         for lumilsnum,perlsdata in lumidata.items():
00767             cmslsnum=perlsdata[0]            
00768             triggeredls=perlsdata[0] 
00769             if lslist is not None and cmslsnum not in lslist:
00770                 #cmslsnum=0
00771                 triggeredls=0
00772                 recordedlumi=0.0
00773             instlumi=perlsdata[1]
00774             instlumierror=perlsdata[2]
00775             avglumi=instlumi*normval
00776             calibratedlumi=avglumi 
00777             if lumitype=='HF' and finecorrections and finecorrections[run]:
00778                 if usecorrectionv2:
00779                     if driftcorrections and driftcorrections[run]:
00780                         calibratedlumi=lumiCorrections.applyfinecorrectionV2(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
00781                     else:
00782                         calibratedlumi=lumiCorrections.applyfinecorrectionV2(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
00783                 else:
00784                     calibratedlumi=lumiCorrections.applyfinecorrection(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
00785             if lumitype=='PIXEL' and finecorrections is not None:
00786                 calibratedlumi=finecorrections[run]*avglumi
00787             calibratedlumierror=instlumierror*normval
00788             bstatus=perlsdata[4]
00789             begev=perlsdata[5]
00790             numorbit=perlsdata[6]
00791             startorbit=perlsdata[7]
00792             timestamp=c.OrbitToTime(startTimeStr,startorbit,0)
00793             lslen=lumip.lslengthsec()
00794             deliveredlumi=calibratedlumi*lslen
00795             recordedlumi=0.0
00796             trgprescalemap={}#trgprescalemap for this ls
00797             efflumidict={}
00798             if triggeredls!=0:
00799                 if not trgdata.has_key(cmslsnum):
00800                     #triggeredls=0 #if no trigger, set back to non-cms-active ls
00801                     recordedlumi=0.0 # no trigger->nobeam recordedlumi=None
00802                 else:
00803                     deadcount=trgdata[cmslsnum][0] ##subject to change !!
00804                     bitzerocount=trgdata[cmslsnum][1]
00805                     bitzeroprescale=trgdata[cmslsnum][2]
00806                     deadfrac=trgdata[cmslsnum][3]
00807                     if deadfrac<0 or deadfrac>1.0:
00808                         deadfrac=1.0
00809                     #if float(bitzerocount)*float(bitzeroprescale)==0.0:
00810                     #    deadfrac=1.0
00811                     #else:
00812                     #    deadfrac=float(deadcount)/(float(bitzerocount)*float(bitzeroprescale))
00813                     #if deadfrac>1.0:
00814                     #    deadfrac=1.0  #artificial correction in case of deadfrac>1
00815                     recordedlumi=deliveredlumi*(1.0-deadfrac)
00816                     l1bitinfo=trgdata[cmslsnum][4]
00817                     if l1bitinfo:
00818                         for thisbitinfo in l1bitinfo:
00819                             thisbitname=thisbitinfo[0]
00820                             thisbitprescale=thisbitinfo[2]
00821                             trgprescalemap['"'+thisbitname+'"']=thisbitprescale#note:need to double quote bit name!                    
00822                     del trgdata[cmslsnum][:]
00823                 if hltdata.has_key(cmslsnum):                
00824                     hltpathdata=hltdata[cmslsnum]
00825                     #print 'hltpathdata ',hltpathdata
00826                     for pathidx,thispathinfo in enumerate(hltpathdata):
00827                         efflumi=0.0                    
00828                         thispathname=thispathinfo[0]
00829                         thisprescale=thispathinfo[1]
00830                         thisl1seed=None
00831                         l1bitname=None
00832                         l1prescale=None
00833                         try:
00834                             thisl1seed=hlttrgmap[thispathname]
00835                         except KeyError:
00836                             thisl1seed=None
00837                             # print 'hltpath, l1seed, hltprescale ',thispathname,thisl1seed,thisprescale
00838                         if thisl1seed:                            
00839                             try:
00840                                 l1bitname=hltTrgSeedMapper.findUniqueSeed(thispathname,thisl1seed)
00841                                 if l1bitname :
00842                                     l1prescale=trgprescalemap[l1bitname]#need to match double quoted string!
00843                             except KeyError:
00844                                 l1prescale=None                           
00845                         if l1prescale and thisprescale :#normal both prescaled
00846                             efflumi=recordedlumi/(float(l1prescale)*float(thisprescale))
00847                             efflumidict[thispathname]=[l1bitname,l1prescale,thisprescale,efflumi]
00848                         elif l1prescale and thisprescale==0: #hltpath in menu but masked
00849                             efflumi=0.0
00850                             efflumidict[thispathname]=[l1bitname,l1prescale,thisprescale,efflumi]
00851                 
00852             bxvaluelist=[]
00853             bxerrorlist=[]
00854             bxdata=None
00855             beamdata=None
00856             if withBXInfo:
00857                 bxinfo=lumidata[8]
00858                 bxvalueArray=None
00859                 bxerrArray=None
00860                 if bxinfo:
00861                     bxvalueArray=bxinfo[0]
00862                     bxerrArray=bxinfo[1]
00863                     for idx,bxval in enumerate(bxvalueArray):
00864                         if finecorrections and finecorrections[run]:
00865                             if usecorrectionv2:
00866                                 if driftcorrections and driftcorrections[run]:
00867                                     mybxval=lumiCorrections.applyfinecorrectionBXV2(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
00868                                 else:
00869                                     mybxval=lumiCorrections.applyfinecorrectionBXV2(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
00870                             else:
00871                                 mybxval=lumiCorrections.applyfinecorrectionBX(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
00872                         else:
00873                             mybxval=bxval*perbunchnormval
00874                         if mybxval>xingMinLum:
00875                             bxidxlist.append(idx)
00876                             bxvaluelist.append(bxval)
00877                             bxerrorlist.append(bxerrArray[idx])
00878                     del bxvalueArray[:]
00879                     del bxerrArray[:]
00880                 bxdata=(bxidxlist,bxvaluelist,bxerrorlist)    
00881             if withBeamIntensity:
00882                 beaminfo=perlsdata[9]
00883                 bxindexlist=[]
00884                 b1intensitylist=[]
00885                 b2intensitylist=[]
00886                 if beaminfo:
00887                     bxindexarray=beaminfo[0]
00888                     beam1intensityarray=beaminfo[1]
00889                     beam2intensityarray=beaminfo[2]                    
00890                     bxindexlist=bxindexarray.tolist()
00891                     b1intensitylist=beam1intensityarray.tolist()
00892                     b2intensitylist=beam2intensityarray.tolist()
00893                     del bxindexarray[:]
00894                     del beam1intensityarray[:]
00895                     del beam2intensityarray[:]
00896                 beamdata=(bxindexlist,b1intensitylist,b2intensitylist)
00897 #            print cmslsnum,deliveredlumi,recordedlumi,efflumidict
00898             perrunresult.append([lumilsnum,triggeredls,timestamp,bstatus,begev,deliveredlumi,recordedlumi,calibratedlumierror,efflumidict,bxdata,beamdata,fillnum])
00899             del perlsdata[:]
00900         result[run]=perrunresult
00901     #print result
00902     return result

def lumiCalcAPI::fillInRange (   schema,
  fillmin = 1000,
  fillmax = 9999,
  amodetag = 'PROTPHYS',
  startT = None,
  stopT = None 
)
output [fill]

Definition at line 38 of file lumiCalcAPI.py.

00039                                                                                             :
00040     '''
00041     output [fill]
00042     '''
00043     fills=dataDML.fillInRange(schema,fillmin,fillmax,amodetag,startT,stopT)
    return fills
def lumiCalcAPI::fillrunMap (   schema,
  fillnum = None,
  runmin = None,
  runmax = None,
  startT = None,
  stopT = None,
  l1keyPattern = None,
  hltkeyPattern = None,
  amodetag = None 
)
output: {fill:[runnum,...]}

Definition at line 44 of file lumiCalcAPI.py.

00045                                                                                                                                      :
00046     '''
00047     output: {fill:[runnum,...]}
00048     '''
00049     return dataDML.fillrunMap(schema,fillnum=fillnum,runmin=runmin,runmax=runmax,startT=startT,stopT=stopT,l1keyPattern=l1keyPattern,hltkeyPattern=hltkeyPattern,amodetag=amodetag)
             
def lumiCalcAPI::hltForRange (   schema,
  inputRange,
  hltpathname = None,
  hltpathpattern = None,
  withL1Pass = False,
  withHLTAccept = False,
  tableName = None,
  branchName = None 
)
input:
       inputRange: {run:[cmsls]} (required)
       hltpathname: exact match hltpathname  (optional) 
       hltpathpattern: regex match hltpathpattern (optional)
       branchName : data version
output: {runnumber:[(cmslsnum,[(hltpath,hltprescale,l1pass,hltaccept),...]),(cmslsnum,[])})}

Definition at line 133 of file lumiCalcAPI.py.

00134                                                                                                                                            :
00135     '''
00136     input:
00137            inputRange: {run:[cmsls]} (required)
00138            hltpathname: exact match hltpathname  (optional) 
00139            hltpathpattern: regex match hltpathpattern (optional)
00140            branchName : data version
00141     output: {runnumber:[(cmslsnum,[(hltpath,hltprescale,l1pass,hltaccept),...]),(cmslsnum,[])})}
00142     '''
00143     #if tableName is None:
00144     #    tableName=nameDealer.hltdataTableName()
00145     #if branchName is None:
00146     #    branchName='DATA'
00147     result={}
00148     for run in inputRange.keys():
00149         lslist=inputRange[run]
00150         if lslist is not None and len(lslist)==0:
00151             result[run]=[]#if no LS is selected for a run
00152             continue
00153         hltdataid=dataDML.guessHltDataIdByRun(schema,run)
00154         if hltdataid is None:
00155             result[run]=None
00156             continue #run non exist
00157         hltdata=dataDML.hltLSById(schema,hltdataid,hltpathname=hltpathname,hltpathpattern=hltpathpattern,withL1Pass=withL1Pass,withHLTAccept=withHLTAccept)
00158         #(runnum,{cmslsnum:[(pathname,prescale,l1pass,hltaccept),...]})
00159         result[run]=[]
00160         if hltdata and hltdata[1]:
00161             for cmslsnum in sorted(hltdata[1]):
00162                 if lslist is not None and cmslsnum not in lslist:
00163                     continue
00164                 lsdata=[]
00165                 for perpathdata in hltdata[1][cmslsnum]:
00166                     pathname=perpathdata[0]
00167                     prescale=perpathdata[1]
00168                     l1pass=None
00169                     hltaccept=None
00170                     if withL1Pass:
00171                         l1pass=perpathdata[2]
00172                     if withHLTAccept:
00173                         hltaccept=perpathdata[3]
00174                     lsdata.append((pathname,prescale,l1pass,hltaccept))
00175                 result[run].append((cmslsnum,lsdata))
00176     return result

def lumiCalcAPI::hltpathsForRange (   schema,
  runlist,
  hltpathname = None,
  hltpathpattern = None 
)
input: runlist [run],     (required)      
       datatag: data version (optional)
output : {runnumber,[(hltpath,l1seedexpr,l1bitname)...]}

Definition at line 56 of file lumiCalcAPI.py.

00057                                                                          :
00058     '''
00059     input: runlist [run],     (required)      
00060            datatag: data version (optional)
00061     output : {runnumber,[(hltpath,l1seedexpr,l1bitname)...]}
00062     '''
00063     result={}
00064     for run in runlist:
00065         hlttrgmap=dataDML.hlttrgMappingByrun(schema,run,hltpathname=hltpathname,hltpathpattern=hltpathpattern)
00066         result[run]=[]
00067         for hltpath in sorted(hlttrgmap):
00068             l1seedexpr=hlttrgmap[hltpath]
00069             l1bitname=hltTrgSeedMapper.findUniqueSeed(hltpath,l1seedexpr)
00070             result[run].append((hltpath,l1seedexpr,l1bitname))
    return result
def lumiCalcAPI::instCalibratedLumiForRange (   schema,
  inputRange,
  beamstatus = None,
  amodetag = None,
  egev = None,
  withBXInfo = False,
  bxAlgo = None,
  xingMinLum = 0.0,
  withBeamIntensity = False,
  norm = None,
  finecorrections = None,
  driftcorrections = None,
  usecorrectionv2 = False,
  lumitype = 'HF',
  branchName = None 
)
Inst luminosity after calibration, not time integrated
input:
       inputRange  {run:[cmsls]} (required)
       amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','IONPHYS']
       beamstatus: LS filter on beamstatus (optional)
       amodetag: amodetag for  picking norm(optional)
       egev: beamenergy for picking norm(optional)
       withBXInfo: get per bunch info (optional)
       bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
       xingMinLum: cut on bx lumi value (optional)
       withBeamIntensity: get beam intensity info (optional)
       norm: if norm is a float, use it directly; if it is a string, consider it norm factor name to use (optional)
       lumitype : HF or PIXEL
       branchName: data version
       finecorrections: const and non-linear corrections
       driftcorrections: driftcorrections
output:
       result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),calibratedlumi(5),calibratedlumierr(6),startorbit(7),numorbit(8),(bxidx,bxvalues,bxerrs)(9),(bxidx,b1intensities,b2intensities)(10),fillnum(11)]}}
       lumi unit: HZ/ub

Definition at line 332 of file lumiCalcAPI.py.

00333                                                                                                                                                                                                                                                                       :
00334     '''
00335     Inst luminosity after calibration, not time integrated
00336     input:
00337            inputRange  {run:[cmsls]} (required)
00338            amodetag : accelerator mode for all the runs (optional) ['PROTPHYS','IONPHYS']
00339            beamstatus: LS filter on beamstatus (optional)
00340            amodetag: amodetag for  picking norm(optional)
00341            egev: beamenergy for picking norm(optional)
00342            withBXInfo: get per bunch info (optional)
00343            bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
00344            xingMinLum: cut on bx lumi value (optional)
00345            withBeamIntensity: get beam intensity info (optional)
00346            norm: if norm is a float, use it directly; if it is a string, consider it norm factor name to use (optional)
00347            lumitype : HF or PIXEL
00348            branchName: data version
00349            finecorrections: const and non-linear corrections
00350            driftcorrections: driftcorrections
00351     output:
00352            result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),calibratedlumi(5),calibratedlumierr(6),startorbit(7),numorbit(8),(bxidx,bxvalues,bxerrs)(9),(bxidx,b1intensities,b2intensities)(10),fillnum(11)]}}
00353            lumi unit: HZ/ub
00354     '''
00355     result = {}
00356     normval=None
00357     perbunchnormval=None
00358     if norm:
00359         normval=_getnorm(schema,norm)
00360         perbunchnormval=float(normval)/float(1000)
00361     elif amodetag and egev:
00362         normval=_decidenormFromContex(schema,amodetag,egev)
00363         perbunchnormval=float(normval)/float(1000)
00364     instresult=instLumiForRange(schema,inputRange,beamstatusfilter=beamstatus,withBXInfo=withBXInfo,bxAlgo=bxAlgo,xingMinLum=xingMinLum,withBeamIntensity=withBeamIntensity,lumitype=lumitype,branchName=branchName)
00365     for run,perrundata in instresult.items():
00366         if perrundata is None:
00367             result[run]=None
00368             continue
00369         result[run]=[]
00370         if not normval:#if norm cannot be decided , look for it according to context per run
00371             normval=_decidenormForRun(schema,run)
00372             perbunchnormval=float(normval)/float(1000)
00373         if not normval:#still not found? resort to global default (should never come here)
00374             normval=6370
00375             perbunchnormval=6.37
00376             print '[Warning] using default normalization '+str(normval)
00377         for perlsdata in perrundata:
00378             lumilsnum=perlsdata[0]
00379             cmslsnum=perlsdata[1]
00380             timestamp=perlsdata[2]
00381             bs=perlsdata[3]
00382             beamenergy=perlsdata[4]
00383             fillnum=perlsdata[11]
00384             avglumi=perlsdata[5]*normval
00385             calibratedlumi=avglumi
00386             bxdata=perlsdata[9]
00387             if lumitype=='HF' and finecorrections and finecorrections[run]:
00388                 if usecorrectionv2:
00389                     if driftcorrections and driftcorrections[run]:
00390                         calibratedlumi=lumiCorrections.applyfinecorrectionV2(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
00391                     else:
00392                         calibratedlumi=lumiCorrections.applyfinecorrectionV2(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
00393                 else:
00394                     calibratedlumi=lumiCorrections.applyfinecorrection(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
00395             if lumitype=='PIXEL' and finecorrections is not None:
00396                 calibratedlumi=finecorrections[run]*avglumi
00397             calibratedlumierr=perlsdata[6]*normval
00398             startorbit=perlsdata[7]
00399             numorbit=perlsdata[8]
00400             bxidxlistResult=[]
00401             bxvaluelistResult=[]
00402             bxerrorlistResult=[]
00403             calibratedbxdata=None
00404             beamdata=None
00405             if withBXInfo:
00406                 if bxdata:
00407                     bxidxlist=bxdata[0]
00408                     bxvaluelist=bxdata[1]
00409                     #avglumiBX=sum(bxvaluelist)*normval*1.0e-03
00410                     bxlumierrlist=bxdata[2]
00411                     for idx,bxidx in enumerate(bxidxlist):
00412                         bxval=bxvaluelist[idx]
00413                         bxlumierr=bxlumierrlist[idx]
00414                         if finecorrections and finecorrections[run]:
00415                             if usecorrectionv2:
00416                                 if driftcorrections and driftcorrections[run]:
00417                                     mybxval=lumiCorrections.applyfinecorrectionBXV2(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
00418                                 else:
00419                                     mybxval=lumiCorrections.applyfinecorrectionBXV2(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
00420                             else:
00421                                 mybxval=lumiCorrections.applyfinecorrectionBX(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
00422                         bxidxlistResult.append(bxidx)
00423                         bxvaluelistResult.append(mybxval)
00424                         bxerrorlistResult.append(bxlumierr*perbunchnormval)#no correciton on errors
00425                     del bxdata[1][:]
00426                     del bxdata[2][:]
00427             calibratedbxdata=(bxidxlistResult,bxvaluelistResult,bxerrorlistResult)
00428             if withBeamIntensity:
00429                 beamdata=perlsdata[10]                
00430             result[run].append([lumilsnum,cmslsnum,timestamp,bs,beamenergy,calibratedlumi,calibratedlumierr,startorbit,numorbit,calibratedbxdata,beamdata,fillnum])
00431             del perlsdata[:]
00432     return result
         
def lumiCalcAPI::instLumiForRange (   schema,
  inputRange,
  beamstatusfilter = None,
  withBXInfo = False,
  bxAlgo = None,
  xingMinLum = 0.0,
  withBeamIntensity = False,
  lumitype = 'HF',
  branchName = None 
)
DIRECTLY FROM ROOT FIME NO CORRECTION AT ALL 
lumi raw data. beofore normalization and time integral
input:
       inputRange  {run:[cmsls]} (required)
       beamstatus: LS filter on beamstatus (optional)
       withBXInfo: get per bunch info (optional)
       bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
       xingMinLum: cut on bx lumi value (optional)
       withBeamIntensity: get beam intensity info (optional)
       branchName: data version
output:
       result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),instlumi(5),instlumierr(6),startorbit(7),numorbit(8),(bxidx,bxvalues,bxerrs)(9),(bxidx,b1intensities,b2intensities)(10),fillnum(11)]}}
       lumi unit: HZ/ub

Definition at line 233 of file lumiCalcAPI.py.

00234                                                                                                                                                                :
00235     '''
00236     DIRECTLY FROM ROOT FIME NO CORRECTION AT ALL 
00237     lumi raw data. beofore normalization and time integral
00238     input:
00239            inputRange  {run:[cmsls]} (required)
00240            beamstatus: LS filter on beamstatus (optional)
00241            withBXInfo: get per bunch info (optional)
00242            bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
00243            xingMinLum: cut on bx lumi value (optional)
00244            withBeamIntensity: get beam intensity info (optional)
00245            branchName: data version
00246     output:
00247            result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),instlumi(5),instlumierr(6),startorbit(7),numorbit(8),(bxidx,bxvalues,bxerrs)(9),(bxidx,b1intensities,b2intensities)(10),fillnum(11)]}}
00248            lumi unit: HZ/ub
00249     '''
00250     if lumitype not in ['HF','PIXEL']:
00251         raise ValueError('unknown lumitype '+lumitype)
00252     lumitableName=''
00253     lumilstableName=''
00254     if lumitype=='HF':
00255         lumitableName=nameDealer.lumidataTableName()
00256         lumilstableName=nameDealer.lumisummaryv2TableName()
00257     else:
00258         lumitableName=nameDealer.pixellumidataTableName()
00259         lumilstableName=nameDealer.pixellumisummaryv2TableName()
00260         
00261     result={}
00262     for run in inputRange.keys():
00263         lslist=inputRange[run]
00264         if lslist is not None and len(lslist)==0:
00265             result[run]=[]#if no LS is selected for a run
00266             continue
00267         runsummary=dataDML.runsummary(schema,run)
00268         if len(runsummary)==0:#if run not found in runsummary
00269             result[run]=None
00270             continue
00271         fillnum=runsummary[4]
00272         runstarttimeStr=runsummary[6]
00273         lumidataid=dataDML.guessLumiDataIdByRun(schema,run,lumitableName)
00274         if lumidataid is None: #if run not found in lumidata
00275             result[run]=None
00276             continue
00277         (lumirunnum,perlsresult)=dataDML.lumiLSById(schema,lumidataid,beamstatusfilter,withBXInfo=withBXInfo,bxAlgo=bxAlgo,withBeamIntensity=withBeamIntensity,tableName=lumilstableName)
00278         lsresult=[]
00279         c=lumiTime.lumiTime()
00280         for lumilsnum in perlsresult.keys():
00281             perlsdata=perlsresult[lumilsnum]
00282             cmslsnum=perlsdata[0]
00283             if lslist is not None and lumilsnum not in lslist:
00284                 cmslsnum=0
00285             numorbit=perlsdata[6]
00286             startorbit=perlsdata[7]
00287             orbittime=c.OrbitToTime(runstarttimeStr,startorbit,0)
00288             instlumi=perlsdata[1]
00289             instlumierr=perlsdata[2]
00290             beamstatus=perlsdata[4]
00291             beamenergy=perlsdata[5]
00292             bxidxlist=[]
00293             bxvaluelist=[]
00294             bxerrorlist=[]
00295             bxdata=None
00296             beamdata=None
00297             if withBXInfo:
00298                 bxinfo=perlsdata[8]                
00299                 bxvalueArray=None
00300                 bxerrArray=None
00301                 if bxinfo:
00302                     bxvalueArray=bxinfo[0]
00303                     bxerrArray=bxinfo[1]
00304                     for idx,bxval in enumerate(bxvalueArray):
00305                         if bxval>xingMinLum:
00306                             bxidxlist.append(idx)
00307                             bxvaluelist.append(bxval)
00308                             bxerrorlist.append(bxerrArray[idx])
00309                     del bxvalueArray[:]
00310                     del bxerrArray[:]
00311                 bxdata=(bxidxlist,bxvaluelist,bxerrorlist)
00312             if withBeamIntensity:
00313                 beaminfo=perlsdata[9]
00314                 bxindexlist=[]
00315                 b1intensitylist=[]
00316                 b2intensitylist=[]
00317                 if beaminfo[0] and beaminfo[1] and beaminfo[2]:
00318                     bxindexarray=beaminfo[0]
00319                     beam1intensityarray=beaminfo[1]
00320                     beam2intensityarray=beaminfo[2]                    
00321                     bxindexlist=bxindexarray.tolist()
00322                     b1intensitylist=beam1intensityarray.tolist()
00323                     b2intensitylist=beam2intensityarray.tolist()
00324                     del bxindexarray[:]
00325                     del beam1intensityarray[:]
00326                     del beam2intensityarray[:]                    
00327                 beamdata=(bxindexlist,b1intensitylist,b2intensitylist)
00328             lsresult.append([lumilsnum,cmslsnum,orbittime,beamstatus,beamenergy,instlumi,instlumierr,startorbit,numorbit,bxdata,beamdata,fillnum])         
00329             del perlsdata[:]
00330         result[run]=lsresult
00331     return result

def lumiCalcAPI::lumiForRange (   schema,
  inputRange,
  beamstatus = None,
  amodetag = None,
  egev = None,
  withBXInfo = False,
  bxAlgo = None,
  xingMinLum = 0.0,
  withBeamIntensity = False,
  norm = None,
  datatag = 'DATA',
  finecorrections = None,
  driftcorrections = None,
  usecorrectionv2 = False,
  lumitype = 'HF',
  branchName = None 
)
delivered/recorded lumi
input:
       inputRange  {run:[cmsls]} (required)
       beamstatus: LS filter on beamstatus (optional)
       amodetag: amodetag for  picking norm(optional)
       egev: beamenergy for picking norm(optional)
       withBXInfo: get per bunch info (optional)
       bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
       xingMinLum: cut on bx lumi value (optional)
       withBeamIntensity: get beam intensity info (optional)
       normname: norm factor name to use (optional)
       branchName: data version
output:
       result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),(bxidx,bxvalues,bxerrs)(8),(bxidx,b1intensities,b2intensities)(9),fillnum(10)]}
       lumi unit: 1/ub

Definition at line 513 of file lumiCalcAPI.py.

00514                                                                                                                                                                                                                                                                        :
00515     '''
00516     delivered/recorded lumi
00517     input:
00518            inputRange  {run:[cmsls]} (required)
00519            beamstatus: LS filter on beamstatus (optional)
00520            amodetag: amodetag for  picking norm(optional)
00521            egev: beamenergy for picking norm(optional)
00522            withBXInfo: get per bunch info (optional)
00523            bxAlgo: algoname for bx values (optional) ['OCC1','OCC2','ET']
00524            xingMinLum: cut on bx lumi value (optional)
00525            withBeamIntensity: get beam intensity info (optional)
00526            normname: norm factor name to use (optional)
00527            branchName: data version
00528     output:
00529            result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),(bxidx,bxvalues,bxerrs)(8),(bxidx,b1intensities,b2intensities)(9),fillnum(10)]}
00530            lumi unit: 1/ub
00531     '''
00532     if lumitype not in ['HF','PIXEL']:
00533         raise ValueError('unknown lumitype '+lumitype)
00534     #if branchName is None:
00535     #    branchName='DATA'
00536     lumip=lumiParameters.ParametersObject()
00537     lumitableName=''
00538     lumilstableName=''
00539     if lumitype=='HF':
00540         lumitableName=nameDealer.lumidataTableName()
00541         lumilstableName=nameDealer.lumisummaryv2TableName()
00542     else:
00543         lumitableName=nameDealer.pixellumidataTableName()
00544         lumilstableName=nameDealer.pixellumisummaryv2TableName()
00545     numbx=lumip.NBX
00546     result = {}
00547     normval=None
00548     perbunchnormval=None
00549     if norm:
00550         normval=_getnorm(schema,norm)
00551         perbunchnormval=float(normval)/float(1000)
00552     elif amodetag and egev:
00553         normval=_decidenormFromContext(schema,amodetag,egev)
00554         perbunchnormval=float(normval)/float(1000)
00555     c=lumiTime.lumiTime()
00556     for run in inputRange.keys():#loop over run
00557         lslist=inputRange[run]
00558         if lslist is not None and len(lslist)==0:#no selected ls, do nothing for this run
00559             result[run]=[]
00560             continue
00561         cmsrunsummary=dataDML.runsummary(schema,run)
00562         if len(cmsrunsummary)==0:#non existing run
00563             result[run]=None
00564             continue
00565         startTimeStr=cmsrunsummary[6]
00566         fillnum=cmsrunsummary[4]
00567         lumidataid=None
00568         trgdataid=None
00569         lumidataid=dataDML.guessLumiDataIdByRun(schema,run,lumitableName)
00570         if lumidataid is None :
00571             result[run]=None
00572             continue
00573         trgdataid=dataDML.guessTrgDataIdByRun(schema,run)
00574         (lumirunnum,lumidata)=dataDML.lumiLSById(schema,lumidataid,beamstatus=beamstatus,withBXInfo=withBXInfo,bxAlgo=bxAlgo,withBeamIntensity=withBeamIntensity,tableName=lumilstableName)
00575         if trgdataid is None :
00576             trgdata={}
00577         else:
00578             (trgrunnum,trgdata)=dataDML.trgLSById(schema,trgdataid)
00579             
00580         if not normval:#if norm cannot be decided , look for it according to context per run
00581             normval=_decidenormForRun(schema,run)
00582             perbunchnormval=float(normval)/float(1000)
00583         if not normval:#still not found? resort to global default (should never come here)
00584             normval=6370
00585             perbunchnormval=6.37
00586             print '[Warning] using default normalization '+str(normval)
00587         
00588         perrunresult=[]
00589         for lumilsnum,perlsdata in lumidata.items():
00590             cmslsnum=perlsdata[0]
00591             triggeredls=perlsdata[0]
00592             if lslist is not None and cmslsnum not in lslist:
00593                 #cmslsnum=0
00594                 triggeredls=0
00595                 recordedlumi=0.0
00596             instlumi=perlsdata[1]
00597             instlumierror=perlsdata[2]
00598             avglumi=instlumi*normval
00599             calibratedlumi=avglumi
00600             if lumitype=='HF' and finecorrections and finecorrections[run]:
00601                 if usecorrectionv2:
00602                     if driftcorrections and driftcorrections[run]:
00603                         calibratedlumi=lumiCorrections.applyfinecorrectionV2(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
00604                     else:
00605                         calibratedlumi=lumiCorrections.applyfinecorrectionV2(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
00606                 else:
00607                     calibratedlumi=lumiCorrections.applyfinecorrection(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
00608             if lumitype=='PIXEL' and finecorrections is not None:
00609                 calibratedlumi=finecorrections[run]*avglumi
00610             calibratedlumierror=instlumierror*normval
00611             bstatus=perlsdata[4]
00612             begev=perlsdata[5]
00613             numorbit=perlsdata[6]
00614             startorbit=perlsdata[7]
00615             timestamp=c.OrbitToTime(startTimeStr,startorbit,0)
00616             lslen=lumip.lslengthsec()
00617             deliveredlumi=calibratedlumi*lslen
00618             recordedlumi=0.0
00619             if triggeredls!=0:
00620                 if not trgdata.has_key(cmslsnum):                    
00621                    # triggeredls=0 #if no trigger, set back to non-cms-active ls
00622                     recordedlumi=0.0 # no trigger->nobeam recordedlumi=None
00623                 else:
00624                     deadcount=trgdata[cmslsnum][0] ##subject to change !!
00625                     bitzerocount=trgdata[cmslsnum][1]
00626                     bitzeroprescale=trgdata[cmslsnum][2]
00627                     deadfrac=trgdata[cmslsnum][3]
00628                     if deadfrac<0 or deadfrac>1.0:
00629                         deadfrac=1.0
00630                     #if float(bitzerocount)*float(bitzeroprescale)==0.0:
00631                     #    deadfrac=1.0
00632                     #else:
00633                     #    deadfrac=float(deadcount)/(float(bitzerocount)*float(bitzeroprescale))
00634                     #if deadfrac>1.0:
00635                     #    deadfrac=1.0  #artificial correction in case of deadfrac>1
00636                     recordedlumi=deliveredlumi*(1.0-deadfrac)
00637                     del trgdata[cmslsnum][:]
00638             bxdata=None
00639             if withBXInfo:
00640                 bxinfo=perlsdata[8]
00641                 bxvalueArray=None
00642                 bxerrArray=None
00643                 bxidxlist=[]
00644                 bxvaluelist=[]
00645                 bxerrorlist=[]
00646                 if bxinfo:
00647                     bxvalueArray=bxinfo[0]
00648                     bxerrArray=bxinfo[1]
00649                     #if cmslsnum==1:
00650                     #    print 'bxvalueArray ',bxvalueArray
00651                     for idx,bxval in enumerate(bxvalueArray):                    
00652                         if finecorrections and finecorrections[run]:
00653                             if usecorrectionv2:
00654                                 if driftcorrections and driftcorrections[run]:
00655                                     mybxval=lumiCorrections.applyfinecorrectionBXV2(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
00656                                 else:
00657                                     mybxval=lumiCorrections.applyfinecorrectionBXV2(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
00658                             else:
00659                                 mybxval=lumiCorrections.applyfinecorrectionBX(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
00660                         else:
00661                             mybxval=bxval*perbunchnormval
00662                         if mybxval>xingMinLum:
00663                             bxidxlist.append(idx)
00664                             bxvaluelist.append(mybxval)
00665                             bxerrorlist.append(bxerrArray[idx]*perbunchnormval)#no correciton on errors
00666                     del bxvalueArray[:]
00667                     del bxerrArray[:]
00668                 bxdata=(bxidxlist,bxvaluelist,bxerrorlist)
00669             beamdata=None
00670             if withBeamIntensity:
00671                 beaminfo=perlsdata[9]
00672                 bxindexlist=[]
00673                 b1intensitylist=[]
00674                 b2intensitylist=[]                
00675                 if beaminfo:
00676                     bxindexarray=beaminfo[0]
00677                     beam1intensityarray=beaminfo[1]
00678                     beam2intensityarray=beaminfo[2]                    
00679                     bxindexlist=bxindexarray.tolist()
00680                     b1intensitylist=beam1intensityarray.tolist()
00681                     b2intensitylist=beam2intensityarray.tolist()
00682                     del bxindexarray[:]
00683                     del beam1intensityarray[:]
00684                     del beam2intensityarray[:]
00685                 beamdata=(bxindexlist,b1intensitylist,b2intensitylist)
00686             perrunresult.append([lumilsnum,triggeredls,timestamp,bstatus,begev,deliveredlumi,recordedlumi,calibratedlumierror,bxdata,beamdata,fillnum])
00687             del perlsdata[:]
00688         result[run]=perrunresult    
00689     return result
       
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,
  lumitype = 'HF' 
)
output: [runnumber,...]

Definition at line 50 of file lumiCalcAPI.py.

00051                                                                                                                                                                                                                   :
00052     '''
00053     output: [runnumber,...]
00054     '''
00055     return dataDML.runList(schema,fillnum,runmin,runmax,startT,stopT,l1keyPattern,hltkeyPattern,amodetag,nominalEnergy,energyFlut,requiretrg,requirehlt,lumitype)

def lumiCalcAPI::runsummary (   schema,
  irunlsdict 
)
output  [[run,l1key,amodetag,egev,hltkey,fillnum,sequence,starttime,stoptime]]

Definition at line 28 of file lumiCalcAPI.py.

00029                                  :
00030     '''
00031     output  [[run,l1key,amodetag,egev,hltkey,fillnum,sequence,starttime,stoptime]]
00032     '''
00033     result=[]
00034     for run in sorted(irunlsdict):
00035         runinfo=dataDML.runsummary(schema,run)
00036         runinfo.insert(0,run)
00037         result.append(runinfo)
    return result
def lumiCalcAPI::trgbitsForRange (   schema,
  runlist,
  datatag = None 
)
input: runlist [run],(required)
       datatag: data version (optional)
output: {runnumber:[datasource,normbit,[bitname,..]]}

Definition at line 71 of file lumiCalcAPI.py.

00072                                                 :
00073     '''
00074     input: runlist [run],(required)
00075            datatag: data version (optional)
00076     output: {runnumber:[datasource,normbit,[bitname,..]]}
00077     '''
00078     result={}
00079     for run in runlist:
00080         trgdataid=dataDML.guessTrgDataIdByRun(schema,run)
00081         if not trgdataid :
00082             result[run]=None
00083             continue
00084         if not result.has_key(run):
00085             result[run]=[]
00086         trgconf=dataDML.trgRunById(schema,trgdataid)
00087         datasource=trgconf[1]
00088         bitzeroname=trgconf[2]
00089         bitnamedict=trgconf[3]
00090         bitnames=[x[1] for x in bitnamedict if x[1]!='False']
00091         result[run].extend([datasource,bitzeroname,bitnames])
00092     return result

def lumiCalcAPI::trgForRange (   schema,
  inputRange,
  trgbitname = None,
  trgbitnamepattern = None,
  withL1Count = False,
  withPrescale = False,
  tableName = None,
  branchName = None 
)
input :
        inputRange  {run:[cmsls]} (required)
        trgbitname exact match  trgbitname (optional)
        trgbitnamepattern match trgbitname (optional)
        tableName : trgdata table name
        branchName : data version
output
        result {run:[cmslsnum,deadfrac,deadtimecount,bitzero_count,bitzero_prescale,[(bitname,prescale,counts)]]}

Definition at line 177 of file lumiCalcAPI.py.

00178                                                                                                                                              :
00179     '''
00180     input :
00181             inputRange  {run:[cmsls]} (required)
00182             trgbitname exact match  trgbitname (optional)
00183             trgbitnamepattern match trgbitname (optional)
00184             tableName : trgdata table name
00185             branchName : data version
00186     output
00187             result {run:[cmslsnum,deadfrac,deadtimecount,bitzero_count,bitzero_prescale,[(bitname,prescale,counts)]]}
00188     '''
00189     #if tableName is None:
00190     #    tableName=nameDealer.trgdataTableName()
00191     #if branchName is None:
00192     #    branchName='DATA'
00193     result={}
00194     withprescaleblob=True
00195     withtrgblob=True    
00196     for run in inputRange.keys():
00197         lslist=inputRange[run]
00198         if lslist is not None and len(lslist)==0:
00199             result[run]=[]#if no LS is selected for a run
00200             continue
00201         trgdataid=dataDML.guessTrgDataIdByRunInBranch(schema,run)
00202         if trgdataid is None:
00203             result[run]=None
00204             continue #run non exist
00205         trgdata=dataDML.trgLSById(schema,trgdataid,trgbitname=trgbitname,trgbitnamepattern=trgbitnamepattern,withL1Count=withL1Count,withPrescale=withPrescale)
00206         #(runnum,{cmslsnum:[deadtimecount(0),bitzerocount(1),bitzeroprescale(2),deadfrac(3),[(bitname,trgcount,prescale)](4)]})
00207         result[run]=[]
00208         if trgdata and trgdata[1]:
00209             lsdict={}
00210             for cmslsnum in sorted(trgdata[1]):
00211                 if lslist is not None and cmslsnum not in lslist:
00212                     continue
00213                 lsdata=[]
00214                 deadtimecount=trgdata[1][cmslsnum][0]
00215                 bitzerocount=trgdata[1][cmslsnum][1]
00216                 bitzeroprescale=trgdata[1][cmslsnum][2]
00217                 #if float(bitzerocount)*float(bitzeroprescale)==0.0:
00218                 #    deadfrac=1.0
00219                 #else:
00220                 #    deadfrac=float(deadtimecount)/(float(bitzerocount)*float(bitzeroprescale))
00221                 deadfrac=trgdata[1][cmslsnum][3]
00222                 if deadfrac<0 or deadfrac>1.0:
00223                     deadfrac=1.0
00224                 allbitsinfo=trgdata[1][cmslsnum][4]
00225                 lsdata.append(cmslsnum)
00226                 lsdata.append(deadfrac)
00227                 lsdata.append(deadtimecount)
00228                 lsdata.append(bitzerocount)
00229                 lsdata.append(bitzeroprescale)
00230                 lsdata.append(allbitsinfo)
00231                 result[run].append(lsdata)
00232     return result

def lumiCalcAPI::validation (   schema,
  run = None,
  cmsls = None 
)
retrieve validation data per run or all
input: run. if not run, retrive all; if cmslsnum selection list pesent, filter out unselected result
output: {run:[[cmslsnum,status,comment]]}

Definition at line 903 of file lumiCalcAPI.py.

00904                                           :
00905     '''retrieve validation data per run or all
00906     input: run. if not run, retrive all; if cmslsnum selection list pesent, filter out unselected result
00907     output: {run:[[cmslsnum,status,comment]]}
00908     '''
00909     result={}
00910     qHandle=schema.newQuery()
00911     queryHandle.addToTableList(nameDealer.lumivalidationTableName())
00912     queryHandle.addToOutputList('RUNNUM','runnum')
00913     queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
00914     queryHandle.addToOutputList('FLAG','flag')
00915     queryHandle.addToOutputList('COMMENT','comment')
00916     if run:
00917         queryCondition='RUNNUM=:runnum'
00918         queryBind=coral.AttributeList()
00919         queryBind.extend('runnum','unsigned int')
00920         queryBind['runnum'].setData(run)
00921         queryHandle.setCondition(queryCondition,queryBind)
00922     queryResult=coral.AttributeList()
00923     queryResult.extend('runnum','unsigned int')
00924     queryResult.extend('cmslsnum','unsigned int')
00925     queryResult.extend('flag','string')
00926     queryResult.extend('comment','string')
00927     queryHandle.defineOutput(queryResult)
00928     cursor=queryHandle.execute()
00929     while cursor.next():
00930         runnum=cursor.currentRow()['runnum'].data()
00931         if not result.has_key(runnum):
00932             result[runnum]=[]
00933         cmslsnum=cursor.currentRow()['cmslsnum'].data()
00934         flag=cursor.currentRow()['flag'].data()
00935         comment=cursor.currentRow()['comment'].data()
00936         result[runnum].append([cmslsnum,flag,comment])
00937     if run and cmsls and len(cmsls)!=0:
00938         selectedresult={}
00939         for runnum,perrundata in result.items():
00940             for lsdata in perrundata:
00941                 if lsdata[0] not in cmsls:
00942                     continue
00943                 if not selectedresult.has_key(runnum):
00944                     selectedresult[runnum]=[]
00945                 selectedresult[runnum].append(lsdata)
00946         return selectedresult
00947     else:
        return result