示例#1
0
def hltpathsForRange(schema, runlist, hltpathname=None, hltpathpattern=None):
    '''
    input: runlist [run],     (required)      
           datatag: data version (optional)
    output : {runnumber,[(hltpath,l1seedexpr,l1bitname)...]}
    '''
    result = {}
    for run in runlist:
        hlttrgmap = dataDML.hlttrgMappingByrun(schema,
                                               run,
                                               hltpathname=hltpathname,
                                               hltpathpattern=hltpathpattern)
        result[run] = []
        for hltpath in sorted(hlttrgmap):
            l1seedexpr = hlttrgmap[hltpath]
            (exptype,
             l1bits) = hltTrgSeedMapper.findUniqueSeed(hltpath, l1seedexpr)
            l1bitname = 'n/a'
            if l1bits:
                if exptype:
                    l1bitname = l1seedexpr
                else:
                    l1bitname = l1bits[0]
            result[run].append((hltpath, l1seedexpr, l1bitname))
    return result
def hltpathsForRange(schema,runlist,hltpathname=None,hltpathpattern=None):
    '''
    input: runlist [run],     (required)      
           datatag: data version (optional)
    output : {runnumber,[(hltpath,l1seedexpr,l1bitname)...]}
    '''
    result={}
    for run in runlist:
        hlttrgmap=dataDML.hlttrgMappingByrun(schema,run,hltpathname=hltpathname,hltpathpattern=hltpathpattern)
        result[run]=[]
        for hltpath in sorted(hlttrgmap):
            l1seedexpr=hlttrgmap[hltpath]
            l1bitname=hltTrgSeedMapper.findUniqueSeed(hltpath,l1seedexpr)
            result[run].append((hltpath,l1seedexpr,l1bitname))
    return result
示例#3
0
def effectiveLumiForIds(schema,irunlsdict,dataidmap,runsummaryMap=None,beamstatusfilter=None,timeFilter=None,normmap=None,hltpathname=None,hltpathpattern=None,withBXInfo=False,bxAlgo=None,xingMinLum=None,withBeamIntensity=False,lumitype='HF',minbiasXsec=None):
    '''
    delivered/recorded/eff lumi in selected hlt path  (including calibration,time integral)
    input:
           irunlsdict: {run:[lsnum]}, where [lsnum]==None means all ; [lsnum]==[] means selected ls
           dataidmap : {run:(lumiid,trgid,hltid)}
           runsummaryMap: {run:[l1key(0),amodetag(1),egev(2),hltkey(3),fillnum(4),fillscheme(5),starttime(6),stoptime(7)]}
           beamstatusfilter: LS filter on beamstatus
           normmap: {since:[corrector(0),{paramname:paramvalue}(1),amodetag(2),egev(3),comment(4)]} if normmap empty, means without-correction , if notnormmap means without-correction
           hltpathname: selected hltpathname
           hltpathpattern: regex select hltpaths           
           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)
           lumitype: luminosity source
    output:
           result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),{hltpath:[l1name,l1prescale,hltprescale,efflumi]}(8),bxdata(9),beamdata(10),fillnum(11),ncollidingbunches(12)]}
           {run:None}  None means no run in lumiDB, 
           {run:[]} [] means no lumi for this run in lumiDB
           {run:[....deliveredlumi(5),recorded(6)==None,]} means no trigger in lumiDB
           {run:[....deliveredlumi(5),recorded(6),calibratedlumierror(7)==None]} means no hlt in lumiDB
           
           lumi unit: 1/ub
    '''
    deliveredresult=deliveredLumiForIds(schema,irunlsdict,dataidmap,runsummaryMap,beamstatusfilter=beamstatusfilter,timeFilter=timeFilter,normmap=normmap,withBXInfo=withBXInfo,bxAlgo=bxAlgo,xingMinLum=xingMinLum,withBeamIntensity=withBeamIntensity,lumitype=lumitype,minbiasXsec=minbiasXsec)
    trgresult=trgForIds(schema,irunlsdict,dataidmap,withPrescale=True) #{run:[cmslsnum,deadfrac,deadtimecount,bitzero_count,bitzero_prescale,[(bitname,prescale,counts,mask)]]}
    hltresult=hltForIds(schema,irunlsdict,dataidmap,hltpathname=hltpathname,hltpathpattern=hltpathpattern,withL1Pass=False,withHLTAccept=False) #{runnumber:[(cmslsnum,[(hltpath,hltprescale,l1pass,hltaccept),...]),(cmslsnum,[])})}
    for run in deliveredresult.keys(): #loop over delivered
        perrundata=deliveredresult[run]
        if perrundata is None or len(perrundata)==0:#pass through 
            continue
        alltrgls=[]
        if run in trgresult and trgresult[run]:
            alltrgls=[x[0] for x in trgresult[run]]
        allhltls=[]
        if run in hltresult and hltresult[run]:
            allhltls=[x[0] for x in hltresult[run]]            
        l1bitinfo=[]
        hltpathinfo=[]
        hlttrgmap=dataDML.hlttrgMappingByrun(schema,run,hltpathname=hltpathname,hltpathpattern=hltpathpattern)
        
        for perlsdata in perrundata: #loop over ls
            if not perlsdata: continue #no lumi for this ls
            perlsdata.insert(6,None)
            perlsdata.insert(8,None)
            if not alltrgls: continue  #no trg for this run
            cmslsnum=perlsdata[1]
            recordedlumi=0.0
            if cmslsnum==0:#if not a cmsls or not selected by cms list, set recordedlumi,efflumi to 0
                continue
            else:
                try:
                    trglsidx=alltrgls.index(cmslsnum)
                    deadfrac=trgresult[run][trglsidx][1]
                    l1bitinfo=trgresult[run][trglsidx][5]
                    if deadfrac<0 or deadfrac>1.0:deadfrac=1.0
                    deliveredlumi=perlsdata[5]
                    recordedlumi=(1.0-deadfrac)*deliveredlumi
                except ValueError:
                    #print '[WARNING] no trigger for LS=',cmslsnum
                    continue #do not go further
            perlsdata[6]=recordedlumi
            if not allhltls: continue #no hlt for this run
            try:
                hltlsidx=allhltls.index(cmslsnum)
            except ValueError:
                #print '[WARNING] no hlt for LS=',cmslsnum
                continue #do not go further
            trgprescalemap={} #{bitname:l1prescale} for this lumi section
            if l1bitinfo:
                for thisbitinfo in l1bitinfo:
                    thisbitname=thisbitinfo[0]
                    thisbitprescale=thisbitinfo[2]
                    trgprescalemap['"'+thisbitname+'"']=thisbitprescale
            else:
                continue
            hltpathdata=hltresult[run][hltlsidx][1]
            efflumidict={}#{pathname:[[l1bitname,l1prescale,hltprescale,efflumi]]}       
            for pathidx,thispathinfo in enumerate(hltpathdata):
                thispathname=thispathinfo[0]
                thisprescale=thispathinfo[1]
                thisl1seed=None
                l1bitname=None
                l1prescale=None
                try:
                    thisl1seed=hlttrgmap[thispathname]
                except KeyError:
                    thisl1seed=None
                if thisl1seed:
                    try:
                        (exptype,l1bits)=hltTrgSeedMapper.findUniqueSeed(thispathname,thisl1seed)
                        if l1bits:
                            if not exptype:
                                l1bitname=l1bits[0]
                                l1prescale=trgprescalemap[l1bits[0]]#need to match double quoted string!                                
                            else:
                                pmin=99999999
                                pmax=0                                
                                for bit in l1bits:
                                    l1p=trgprescalemap[bit]
                                    if exptype=='OR':
                                        if l1p!=0 and l1p<pmin:
                                            pmin=l1p
                                            l1prescale=l1p
                                            l1bitname=bit
                                    if exptype=='AND':
                                        if l1p!=0 and l1p>pmax:
                                            pmax=l1p
                                            l1prescale=l1p
                                            l1bitname=bit
                        else:
                            l1prescale=None
                    except KeyError:
                        l1prescale=None
            
                efflumi=0.0
                if l1prescale and thisprescale:#normal both prescaled
                    efflumi=recordedlumi/(float(l1prescale)*float(thisprescale))
                    efflumidict[thispathname]=[l1bitname,l1prescale,thisprescale,efflumi]
                elif l1prescale and thisprescale==0: #hltpath in menu but masked
                    efflumidict[thispathname]=[l1bitname,l1prescale,thisprescale,efflumi]
                else:
                    efflumidict[thispathname]=[None,0,thisprescale,efflumi]
            perlsdata[8]=efflumidict
    return deliveredresult
def 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
    '''
    if lumitype not in ['HF','PIXEL']:
        raise ValueError('unknown lumitype '+lumitype)
    if branchName is None:
        branchName='DATA'
    lumitableName=''
    lumilstableName=''
    if lumitype=='HF':
        lumitableName=nameDealer.lumidataTableName()
        lumilstableName=nameDealer.lumisummaryv2TableName()
    else:
        lumitableName=nameDealer.pixellumidataTableName()
        lumilstableName=nameDealer.pixellumisummaryv2TableName()
    numbx=3564
    result = {}
    normval=None
    perbunchnormval=None
    if norm:
        normval=_getnorm(schema,norm)
        perbunchnormval=float(normval)/float(1000)
    elif amodetag and egev:
        normval=_decidenormFromContext(schema,amodetag,egev)
        perbunchnormval=float(normval)/float(1000)
    c=lumiTime.lumiTime()
    lumip=lumiParameters.ParametersObject()
    for run in inputRange.keys():
        lslist=inputRange[run]
        if lslist is not None and len(lslist)==0:#no selected ls, do nothing for this run
            result[run]=[]
            continue
        cmsrunsummary=dataDML.runsummary(schema,run)
        if len(cmsrunsummary)==0:#non existing run
            result[run]=None
            continue
        startTimeStr=cmsrunsummary[6]
        fillnum=cmsrunsummary[4]
        lumidataid=None
        trgdataid=None
        hltdataid=None
        lumidataid=dataDML.guessLumiDataIdByRun(schema,run,lumitableName)
        trgdataid=dataDML.guessTrgDataIdByRun(schema,run)
        hltdataid=dataDML.guessHltDataIdByRun(schema,run)
        if lumidataid is None or trgdataid is None or hltdataid is None:
            result[run]=None
            continue
        (lumirunnum,lumidata)=dataDML.lumiLSById(schema,lumidataid,beamstatus,tableName=lumilstableName)
        (trgrunnum,trgdata)=dataDML.trgLSById(schema,trgdataid,withPrescale=True)
        (hltrunnum,hltdata)=dataDML.hltLSById(schema,hltdataid,hltpathname=hltpathname,hltpathpattern=hltpathpattern)
        hlttrgmap=dataDML.hlttrgMappingByrun(schema,run)
        if not normval:#if norm cannot be decided , look for it according to context per run
            normval=_decidenormForRun(schema,run)
            perbunchnormval=float(normval)/float(1000)
        if not normval:#still not found? resort to global default (should never come here)
            normval=6370
            perbunchnormval=6.37
            print '[Warning] using default normalization '+str(normval)

        perrunresult=[]
        for lumilsnum,perlsdata in lumidata.items():
            cmslsnum=perlsdata[0]            
            triggeredls=perlsdata[0] 
            if lslist is not None and cmslsnum not in lslist:
                #cmslsnum=0
                triggeredls=0
                recordedlumi=0.0
            instlumi=perlsdata[1]
            instlumierror=perlsdata[2]
            avglumi=instlumi*normval
            calibratedlumi=avglumi 
            if lumitype=='HF' and finecorrections and finecorrections[run]:
                if usecorrectionv2:
                    if driftcorrections and driftcorrections[run]:
                        calibratedlumi=lumiCorrections.applyfinecorrectionV2(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
                    else:
                        calibratedlumi=lumiCorrections.applyfinecorrectionV2(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
                else:
                    calibratedlumi=lumiCorrections.applyfinecorrection(avglumi,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
            if lumitype=='PIXEL' and finecorrections is not None:
                calibratedlumi=finecorrections[run]*avglumi
            calibratedlumierror=instlumierror*normval
            bstatus=perlsdata[4]
            begev=perlsdata[5]
            numorbit=perlsdata[6]
            startorbit=perlsdata[7]
            timestamp=c.OrbitToTime(startTimeStr,startorbit,0)
            lslen=lumip.lslengthsec()
            deliveredlumi=calibratedlumi*lslen
            recordedlumi=0.0
            trgprescalemap={}#trgprescalemap for this ls
            efflumidict={}
            if triggeredls!=0:
                if not trgdata.has_key(cmslsnum):
                    #triggeredls=0 #if no trigger, set back to non-cms-active ls
                    recordedlumi=0.0 # no trigger->nobeam recordedlumi=None
                else:
                    deadcount=trgdata[cmslsnum][0] ##subject to change !!
                    bitzerocount=trgdata[cmslsnum][1]
                    bitzeroprescale=trgdata[cmslsnum][2]
                    deadfrac=trgdata[cmslsnum][3]
                    if deadfrac<0 or deadfrac>1.0:
                        deadfrac=1.0
                    #if float(bitzerocount)*float(bitzeroprescale)==0.0:
                    #    deadfrac=1.0
                    #else:
                    #    deadfrac=float(deadcount)/(float(bitzerocount)*float(bitzeroprescale))
                    #if deadfrac>1.0:
                    #    deadfrac=1.0  #artificial correction in case of deadfrac>1
                    recordedlumi=deliveredlumi*(1.0-deadfrac)
                    l1bitinfo=trgdata[cmslsnum][4]
                    if l1bitinfo:
                        for thisbitinfo in l1bitinfo:
                            thisbitname=thisbitinfo[0]
                            thisbitprescale=thisbitinfo[2]
                            #trgprescalemap['"'+thisbitname+'"']=thisbitprescale#note:need to double quote bit name!
                            trgprescalemap['"'+thisbitname+'"']=thisbitprescale

                    del trgdata[cmslsnum][:]
                if hltdata.has_key(cmslsnum):                
                    hltpathdata=hltdata[cmslsnum]
                    #print 'hltpathdata ',hltpathdata
                    for pathidx,thispathinfo in enumerate(hltpathdata):
                        efflumi=0.0                    
                        thispathname=thispathinfo[0]
                        thisprescale=thispathinfo[1]
                        thisl1seed=None
                        l1bitname=None
                        l1prescale=None
                        try:
                            thisl1seed=hlttrgmap[thispathname]
                        except KeyError:
                            thisl1seed=None
                            # print 'hltpath, l1seed, hltprescale ',thispathname,thisl1seed,thisprescale
                        if thisl1seed:                            
                            try:
                                l1bitname=hltTrgSeedMapper.findUniqueSeed(thispathname,thisl1seed)
                                if l1bitname :
                                    l1prescale=trgprescalemap[l1bitname]#need to match double quoted string!
                                else:
                                    l1prescale=None
                            except KeyError:
                                l1prescale=None                           
                        if l1prescale and thisprescale :#normal both prescaled
                            efflumi=recordedlumi/(float(l1prescale)*float(thisprescale))
                            efflumidict[thispathname]=[l1bitname,l1prescale,thisprescale,efflumi]
                        elif l1prescale and thisprescale==0: #hltpath in menu but masked
                            efflumi=0.0
                            efflumidict[thispathname]=[l1bitname,l1prescale,thisprescale,efflumi]
                        else:
                            efflumi=0.0
                            efflumidict[thispathname]=[None,0,thisprescale,efflumi]
                
            bxvaluelist=[]
            bxerrorlist=[]
            bxdata=None
            beamdata=None
            if withBXInfo:
                bxinfo=lumidata[8]
                bxvalueArray=None
                bxerrArray=None
                if bxinfo:
                    bxvalueArray=bxinfo[0]
                    bxerrArray=bxinfo[1]
                    for idx,bxval in enumerate(bxvalueArray):
                        if finecorrections and finecorrections[run]:
                            if usecorrectionv2:
                                if driftcorrections and driftcorrections[run]:
                                    mybxval=lumiCorrections.applyfinecorrectionBXV2(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],driftcorrections[run])
                                else:
                                    mybxval=lumiCorrections.applyfinecorrectionBXV2(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2],finecorrections[run][3],finecorrections[run][4],1.0)
                            else:
                                mybxval=lumiCorrections.applyfinecorrectionBX(bxval,avglumi,perbunchnormval,finecorrections[run][0],finecorrections[run][1],finecorrections[run][2])
                        else:
                            mybxval=bxval*perbunchnormval
                        if mybxval>xingMinLum:
                            bxidxlist.append(idx)
                            bxvaluelist.append(bxval)
                            bxerrorlist.append(bxerrArray[idx])
                    del bxvalueArray[:]
                    del bxerrArray[:]
                bxdata=(bxidxlist,bxvaluelist,bxerrorlist)    
            if withBeamIntensity:
                beaminfo=perlsdata[9]
                bxindexlist=[]
                b1intensitylist=[]
                b2intensitylist=[]
                if beaminfo:
                    bxindexarray=beaminfo[0]
                    beam1intensityarray=beaminfo[1]
                    beam2intensityarray=beaminfo[2]                    
                    bxindexlist=bxindexarray.tolist()
                    b1intensitylist=beam1intensityarray.tolist()
                    b2intensitylist=beam2intensityarray.tolist()
                    del bxindexarray[:]
                    del beam1intensityarray[:]
                    del beam2intensityarray[:]
                beamdata=(bxindexlist,b1intensitylist,b2intensitylist)
#            print cmslsnum,deliveredlumi,recordedlumi,efflumidict
            perrunresult.append([lumilsnum,triggeredls,timestamp,bstatus,begev,deliveredlumi,recordedlumi,calibratedlumierror,efflumidict,bxdata,beamdata,fillnum])
            del perlsdata[:]
        result[run]=perrunresult
    #print result
    return result