Functions | |
def | calculateSpecificLumi |
def | filltofiles |
output methods#### | |
def | getFillFromDB |
def | getFillFromFile |
def | getSpecificLumi |
def | lastcompleteFill |
def | listfilldir |
def | specificlumiTofile |
Variables | |
string | action = 'store' |
string | allfillname = 'allfills.txt' |
tuple | allfillsFromDB = lumiCalcAPI.fillInRange(schema,fillmin=minfillnum,fillmax=maxfillnum,amodetag=options.amodetag) |
list | amodetagChoices = [ "PROTPHYS","IONPHYS",'PAPHYS' ] |
choices = amodetagChoices, | |
tuple | dataidmap = revisionDML.dataIdsByTagId(session.nominalSchema(),datatagid,runlist=runlist,withcomment=False) |
datatagname = options.datatag | |
string | default = 'frontier://LumiCalc/CMS_LUMI_PROD' |
dictionary | filldata = {} |
list | fillstoprocess = [] |
string | help = 'connect string to lumiDB,optional' |
tuple | lastcompletedFill = lastcompleteFill(os.path.join(options.inputdir,'runtofill_dqm.txt')) |
int | MAXFILL = 9999 |
maxfillnum = options.maxfill | |
int | MINFILL = 1800 |
minfillnum = options.minfill | |
int | normid = 0 |
tuple | normmap = normDML.normIdByType(session.nominalSchema(),lumitype='HF',defaultonly=True) |
string | normname = 'NONE' |
dictionary | normvalueDict = {} |
tuple | options = parser.parse_args() |
tuple | parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description = "specific lumi",formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
######################## ## ## ################## ## ## ## ## Main Program ## ## ## ## ################## ## ## ######################## ## | |
tuple | processedfills = listfilldir(options.outputdir) |
tuple | reqfillmax = max(fillstoprocess) |
tuple | reqfillmin = min(fillstoprocess) |
required = False, | |
tuple | runlist = lumiCalcAPI.runList(session.nominalSchema(),options.fillnum,runmin=None,runmax=None,fillmin=reqfillmin,fillmax=reqfillmax,startT=None,stopT=None,l1keyPattern=None,hltkeyPattern=None,amodetag=options.amodetag,nominalEnergy=None,energyFlut=None,requiretrg=False,requirehlt=False) |
tuple | schema = session.nominalSchema() |
tuple | session = svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')]) |
tuple | svc = sessionManager.sessionManager(options.connect,authpath=options.authpath,debugON=options.debug) |
query DB for all fills and compare with allfills.txt if found newer fills, store in mem fill number reprocess anyway the last 1 fill in the dir redo specific lumi for all marked fills | |
type = int, | |
list | xingAlgoChoices = [ "OCC1","OCC2","ET"] |
def specificLumi::calculateSpecificLumi | ( | lumi, | |
lumierr, | |||
beam1intensity, | |||
beam1intensityerr, | |||
beam2intensity, | |||
beam2intensityerr | |||
) |
calculate specific lumi input: instlumi, instlumierror,beam1intensity,beam1intensityerror,beam2intensity,beam2intensityerror output (specific lumi value,specific lumi error)
Definition at line 74 of file specificLumi.py.
00075 : 00076 ''' 00077 calculate specific lumi 00078 input: instlumi, instlumierror,beam1intensity,beam1intensityerror,beam2intensity,beam2intensityerror 00079 output (specific lumi value,specific lumi error) 00080 ''' 00081 specificlumi=0.0 00082 specificlumierr=0.0 00083 if beam1intensity<0: beam1intensity=0 00084 if beam2intensity<0: beam2intensity=0 00085 if beam1intensity>0.0 and beam2intensity>0.0: 00086 specificlumi=float(lumi)/(float(beam1intensity)*float(beam2intensity)) 00087 specificlumierr=specificlumi*math.sqrt(lumierr**2/lumi**2+beam1intensityerr**2/beam1intensity**2+beam2intensityerr**2/beam2intensity**2) 00088 return (specificlumi,specificlumierr)
def specificLumi::filltofiles | ( | allfills, | |
runsperfill, | |||
runtimes, | |||
dirname | |||
) |
output methods####
write runnumber:starttime map per fill to files
Definition at line 121 of file specificLumi.py.
00122 : 00123 ''' 00124 write runnumber:starttime map per fill to files 00125 ''' 00126 f=open(os.path.join(dirname,allfillname),'w') 00127 for fill in allfills: 00128 print >>f,'%d'%(fill) 00129 f.close() 00130 for fill,runs in runsperfill.items(): 00131 filename='fill_'+str(fill)+'.txt' 00132 if len(runs)!=0: 00133 f=open(os.path.join(dirname,filename),'w') 00134 for run in runs: 00135 print >>f,'%d,%s'%(run,runtimes[run]) 00136 f.close()
def specificLumi::getFillFromDB | ( | schema, | |
fillnum | |||
) |
output: {run:starttime}
Definition at line 22 of file specificLumi.py.
00023 : 00024 ''' 00025 output: {run:starttime} 00026 ''' 00027 runtimesInFill={} 00028 fillrundict=lumiCalcAPI.fillrunMap(schema,fillnum) 00029 if len(fillrundict)>0: 00030 runs=fillrundict.values()[0] 00031 runlsdict=dict(zip(runs,[None]*len(runs))) 00032 runresult=lumiCalcAPI.runsummary(schema,runlsdict) 00033 for perrundata in runresult: 00034 runtimesInFill[perrundata[0]]=perrundata[7] 00035 return runtimesInFill
def specificLumi::getFillFromFile | ( | fillnum, | |
inputdir | |||
) |
parse fill_xxx.txt files in the input directory for runs, starttime in the fill input: fillnumber, input dir output: {run:tarttime}
Definition at line 89 of file specificLumi.py.
00090 : 00091 ''' 00092 parse fill_xxx.txt files in the input directory for runs, starttime in the fill 00093 input: fillnumber, input dir 00094 output: {run:tarttime} 00095 ''' 00096 runtimesInFill={} 00097 #look for files 'fill_num.txt' in inputdir 00098 for filename in os.listdir(inputdir): 00099 mpat=r'^fill_[0-9]{4}.txt$' 00100 m=re.compile(mpat) 00101 if m.match(filename) is None: 00102 continue 00103 filename=filename.strip() 00104 if filename.find('.')==-1: continue 00105 basename,extension=filename.split('.') 00106 if not extension or extension!='txt': 00107 continue 00108 if basename.find('_')==-1: continue 00109 prefix,number=basename.split('_') 00110 if not number : continue 00111 if fillnum!=int(number):continue 00112 f=open(os.path.join(inputdir,'fill_'+number+'.txt'),'r') 00113 for line in f: 00114 l=line.strip() 00115 fields=l.split(',') 00116 if len(fields)<2 : continue 00117 runtimesInFill[int(fields[0])]=fields[1] 00118 f.close() 00119 return runtimesInFill
def specificLumi::getSpecificLumi | ( | schema, | |
fillnum, | |||
inputdir, | |||
dataidmap, | |||
normmap, | |||
xingMinLum = 0.0 , |
|||
amodetag = 'PROTPHYS' , |
|||
bxAlgo = 'OCC1' |
|||
) |
specific lumi in 1e-30 (ub-1s-1) unit lumidetail occlumi in 1e-27 1309_lumi_401_CMS.txt time(in seconds since January 1,2011,00:00:00 UTC) stab(fraction of time spent in stable beams for this time bin) l(lumi in Hz/ub) dl(point-to-point error on lumi in Hz/ub) sl(specific lumi in Hz/ub) dsl(error on specific lumi) 20800119.0 1 -0.889948 0.00475996848729 0.249009 0.005583287562 -0.68359 6.24140208607 0.0 0.0 0.0 0.0 0.0 0.0 0.0383576 0.00430892097862 0.0479095 0.00430892097862 66.6447 4.41269758764 0.0 0.0 0.0 result [(time,beamstatusfrac,lumi,lumierror,speclumi,speclumierror)]
Definition at line 240 of file specificLumi.py.
00241 : 00242 ''' 00243 specific lumi in 1e-30 (ub-1s-1) unit 00244 lumidetail occlumi in 1e-27 00245 1309_lumi_401_CMS.txt 00246 time(in seconds since January 1,2011,00:00:00 UTC) stab(fraction of time spent in stable beams for this time bin) l(lumi in Hz/ub) dl(point-to-point error on lumi in Hz/ub) sl(specific lumi in Hz/ub) dsl(error on specific lumi) 00247 20800119.0 1 -0.889948 0.00475996848729 0.249009 0.005583287562 -0.68359 6.24140208607 0.0 0.0 0.0 0.0 0.0 0.0 0.0383576 0.00430892097862 0.0479095 0.00430892097862 66.6447 4.41269758764 0.0 0.0 0.0 00248 result [(time,beamstatusfrac,lumi,lumierror,speclumi,speclumierror)] 00249 ''' 00250 t=lumiTime.lumiTime() 00251 fillbypos={}#{bxidx:[[ts,beamstatusfrac,lumi,lumierror,spec1,specerror],[]]} 00252 runtimesInFill=getFillFromDB(schema,fillnum)#{runnum:starttimestr} 00253 runlist=runtimesInFill.keys() 00254 if not runlist: return fillbypos 00255 irunlsdict=dict(zip(runlist,[None]*len(runlist))) 00256 #print irunlsdict 00257 GrunsummaryData=lumiCalcAPI.runsummaryMap(session.nominalSchema(),irunlsdict) 00258 lumidetails=lumiCalcAPI.deliveredLumiForIds(schema,irunlsdict,dataidmap,GrunsummaryData,beamstatusfilter=None,normmap=normmap,withBXInfo=True,bxAlgo=bxAlgo,xingMinLum=xingMinLum,withBeamIntensity=True,lumitype='HF') 00259 00260 # 00261 #output: {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),calibratedlumierr(6),(bxvalues,bxerrs)(7),(bxidx,b1intensities,b2intensities)(8),fillnum(9)]} 00262 # 00263 totalstablebeamls=0 00264 orderedrunlist=sorted(lumidetails) 00265 for run in orderedrunlist: 00266 perrundata=lumidetails[run] 00267 for perlsdata in perrundata: 00268 beamstatus=perlsdata[3] 00269 if beamstatus=='STABLE BEAMS': 00270 totalstablebeamls+=1 00271 #print 'totalstablebeamls in fill ',totalstablebeamls 00272 if totalstablebeamls<10:#less than 10 LS in a fill has 'stable beam', it's no a good fill 00273 print 'fill ',fillnum,' , having less than 10 stable beam lS, is not good, skip' 00274 return fillbypos 00275 lumiparam=lumiParameters.ParametersObject() 00276 for run in orderedrunlist: 00277 perrundata=lumidetails[run] 00278 for perlsdata in perrundata: 00279 beamstatusfrac=0.0 00280 tsdatetime=perlsdata[2] 00281 ts=calendar.timegm(tsdatetime.utctimetuple()) 00282 beamstatus=perlsdata[3] 00283 if beamstatus=='STABLE BEAMS': 00284 beamstatusfrac=1.0 00285 (bxidxlist,bxvaluelist,bxerrolist)=perlsdata[7] 00286 #instbxvaluelist=[x/lumiparam.lslengthsec() for x in bxvaluelist if x] 00287 instbxvaluelist=[x for x in bxvaluelist if x] 00288 maxlumi=0.0 00289 if len(instbxvaluelist)!=0: 00290 maxlumi=max(instbxvaluelist) 00291 avginstlumi=0.0 00292 if len(instbxvaluelist)!=0: 00293 avginstlumi=sum(instbxvaluelist) 00294 (intbxidxlist,b1intensities,b2intensities)=perlsdata[8]#contains only non-zero bx 00295 for bxidx in bxidxlist: 00296 idx=bxidxlist.index(bxidx) 00297 instbxvalue=instbxvaluelist[idx] 00298 bxerror=bxerrolist[idx] 00299 if instbxvalue<max(xingMinLum,maxlumi*0.2): 00300 continue 00301 bintensityPos=-1 00302 try: 00303 bintensityPos=intbxidxlist.index(bxidx) 00304 except ValueError: 00305 pass 00306 if bintensityPos<=0: 00307 fillbypos.setdefault(bxidx,[]).append([ts,beamstatusfrac,instbxvalue,bxerror,0.0,0.0]) 00308 continue 00309 b1intensity=b1intensities[bintensityPos] 00310 b2intensity=b2intensities[bintensityPos] 00311 speclumi=calculateSpecificLumi(instbxvalue,bxerror,b1intensity,0.0,b2intensity,0.0) 00312 fillbypos.setdefault(bxidx,[]).append([ts,beamstatusfrac,instbxvalue,bxerror,speclumi[0],speclumi[1]]) 00313 return fillbypos 00314
def specificLumi::lastcompleteFill | ( | infile | ) |
parse infile to find LASTCOMPLETEFILL input: input file name output: last completed fill number
Definition at line 57 of file specificLumi.py.
00058 : 00059 ''' 00060 parse infile to find LASTCOMPLETEFILL 00061 input: input file name 00062 output: last completed fill number 00063 ''' 00064 lastfill=None 00065 hlinepat=r'(LASTCOMPLETEFILL )([0-9]{4})' 00066 h=re.compile(hlinepat) 00067 dqmfile=open(infile,'r') 00068 for line in dqmfile: 00069 result=h.match(line) 00070 if result: 00071 lastfill=result.group(2) 00072 break 00073 return int(lastfill)
def specificLumi::listfilldir | ( | indir | ) |
list all fills contained in the given dir input: indir output: [fill]
Definition at line 36 of file specificLumi.py.
00037 : 00038 ''' 00039 list all fills contained in the given dir 00040 input: indir 00041 output: [fill] 00042 ''' 00043 fillnamepat=r'^[0-9]{4}$' 00044 p=re.compile(fillnamepat) 00045 processedfills=[] 00046 dirList=os.listdir(indir) 00047 for fname in dirList: 00048 if p.match(fname) and os.path.isdir(os.path.join(indir,fname)):#found fill dir 00049 allfs=os.listdir(os.path.join(indir,fname)) 00050 for myfile in allfs: 00051 sumfilenamepat=r'^[0-9]{4}_bxsum_CMS.txt$' 00052 s=re.compile(sumfilenamepat) 00053 if s.match(myfile): 00054 #only if fill_summary_CMS.txt file exists 00055 processedfills.append(int(fname)) 00056 return processedfills
def specificLumi::specificlumiTofile | ( | fillnum, | |
filldata, | |||
outdir | |||
) |
Definition at line 137 of file specificLumi.py.
00138 : 00139 # 00140 #input : fillnum 00141 # filldata: {bxidx:[[lstime,beamstatusfrac,lumivalue,lumierror,speclumi,speclumierr]],[]} 00142 #sorted by bxidx, sorted by lstime inside list 00143 #check outdir/fillnum subdir exists; if not, create it; else outdir=outdir/fillnum 00144 # 00145 if not filldata: 00146 print 'empty input data, do nothing for fill ',fillnum 00147 return 00148 timedict={}#{lstime:[[stablebeamfrac,lumi,lumierr,speclumi,speclumierr]]} 00149 filloutdir=os.path.join(outdir,str(fillnum)) 00150 if not os.path.exists(filloutdir): 00151 os.mkdir(filloutdir) 00152 for cmsbxidx,perbxdata in filldata.items(): 00153 lhcbucket=0 00154 if cmsbxidx!=0: 00155 lhcbucket=(cmsbxidx-1)*10+1 00156 a=sorted(perbxdata,key=lambda x:x[0]) 00157 filename=str(fillnum)+'_lumi_'+str(lhcbucket)+'_CMS.txt' 00158 linedata=[] 00159 for perlsdata in a: 00160 ts=int(perlsdata[0]) 00161 beamstatusfrac=perlsdata[1] 00162 lumi=perlsdata[2] 00163 lumierror=perlsdata[3] 00164 #beam1intensity=perlsdata[4] 00165 #beam2intensity=perlsdata[5] 00166 speclumi=perlsdata[4] 00167 speclumierror= perlsdata[5] 00168 if lumi>0: 00169 linedata.append([ts,beamstatusfrac,lumi,lumierror,speclumi,speclumierror]) 00170 if not timedict.has_key(ts): 00171 timedict[ts]=[] 00172 timedict[ts].append([beamstatusfrac,lumi,lumierror,speclumi,speclumierror]) 00173 if len(linedata)>10:#at least 10 good ls 00174 f=open(os.path.join(filloutdir,filename),'w') 00175 for line in linedata: 00176 print >>f, '%d\t%e\t%e\t%e\t%e\t%e'%(line[0],line[1],line[2],line[3],line[4],line[5]) 00177 f.close() 00178 #print 'writing avg file' 00179 summaryfilename=str(fillnum)+'_lumi_CMS.txt' 00180 f=None 00181 lstimes=timedict.keys() 00182 lstimes.sort() 00183 fillseg=[] 00184 lscounter=0 00185 for lstime in lstimes: 00186 allvalues=timedict[lstime] 00187 transposedvalues=CommonUtil.transposed(allvalues,0.0) 00188 bstatfrac=transposedvalues[0][0]#beamstatus does not change with bx position 00189 lumivals=transposedvalues[1] 00190 lumitot=sum(lumivals) 00191 if bstatfrac==1.0 : 00192 fillseg.append([lstime,lumitot]) 00193 lumierrs=transposedvalues[2] 00194 lumierrortot=math.sqrt(sum(map(lambda x:x**2,lumierrs))) 00195 specificvals=transposedvalues[3] 00196 specificavg=sum(specificvals)/float(len(specificvals))#avg spec lumi 00197 specificerrs=transposedvalues[4] 00198 specifictoterr=math.sqrt(sum(map(lambda x:x**2,specificerrs))) 00199 specificerravg=specifictoterr/float(len(specificvals)) 00200 if lscounter==0: 00201 f=open(os.path.join(filloutdir,summaryfilename),'w') 00202 lscounter+=1 00203 print >>f,'%d\t%e\t%e\t%e\t%e\t%e'%(lstime,bstatfrac,lumitot,lumierrortot,specificavg,specificerravg) 00204 if f is not None: 00205 f.close() 00206 #print 'writing summary file' 00207 fillsummaryfilename=str(fillnum)+'_bxsum_CMS.txt' 00208 f=open(os.path.join(filloutdir,fillsummaryfilename),'w') 00209 if len(fillseg)==0: 00210 print >>f,'%s'%('#no stable beams') 00211 f.close() 00212 return 00213 previoustime=fillseg[0][0] 00214 boundarytime=fillseg[0][0] 00215 #print 'boundary time ',boundarytime 00216 summaryls={} 00217 summaryls[boundarytime]=[] 00218 for [lstime,lumitot] in fillseg:#fillseg is everything with stable beam flag 00219 if lstime-previoustime>50.0: 00220 boundarytime=lstime 00221 #print 'found new boundary ',boundarytime 00222 summaryls[boundarytime]=[] 00223 # print 'appending ',boundarytime,lstime,lumitot 00224 summaryls[boundarytime].append([lstime,lumitot]) 00225 previoustime=lstime 00226 #print summaryls 00227 00228 summarylstimes=summaryls.keys() 00229 summarylstimes.sort() 00230 lumip=lumiParameters.ParametersObject() 00231 for bts in summarylstimes: 00232 startts=bts 00233 tsdatainseg=summaryls[bts] 00234 #print 'tsdatainseg ',tsdatainseg 00235 stopts=tsdatainseg[-1][0] 00236 plu=max(CommonUtil.transposed(tsdatainseg,0.0)[1]) 00237 lui=sum(CommonUtil.transposed(tsdatainseg,0.0)[1])*lumip.lslengthsec() 00238 print >>f,'%d\t%d\t%e\t%e'%(startts,stopts,plu,lui) 00239 f.close()
string specificLumi::action = 'store' |
Definition at line 329 of file specificLumi.py.
string specificLumi::allfillname = 'allfills.txt' |
Definition at line 20 of file specificLumi.py.
tuple specificLumi::allfillsFromDB = lumiCalcAPI.fillInRange(schema,fillmin=minfillnum,fillmax=maxfillnum,amodetag=options.amodetag) |
Definition at line 418 of file specificLumi.py.
list specificLumi::amodetagChoices = [ "PROTPHYS","IONPHYS",'PAPHYS' ] |
Definition at line 325 of file specificLumi.py.
Definition at line 366 of file specificLumi.py.
tuple specificLumi::dataidmap = revisionDML.dataIdsByTagId(session.nominalSchema(),datatagid,runlist=runlist,withcomment=False) |
Definition at line 453 of file specificLumi.py.
specificLumi::datatagname = options.datatag |
Definition at line 450 of file specificLumi.py.
string specificLumi::default = 'frontier://LumiCalc/CMS_LUMI_PROD' |
Definition at line 332 of file specificLumi.py.
tuple specificLumi::filldata = {} |
Definition at line 441 of file specificLumi.py.
list specificLumi::fillstoprocess = [] |
Definition at line 410 of file specificLumi.py.
string specificLumi::help = 'connect string to lumiDB,optional' |
Definition at line 331 of file specificLumi.py.
tuple specificLumi::lastcompletedFill = lastcompleteFill(os.path.join(options.inputdir,'runtofill_dqm.txt')) |
Definition at line 420 of file specificLumi.py.
int specificLumi::MAXFILL = 9999 |
Definition at line 19 of file specificLumi.py.
specificLumi::maxfillnum = options.maxfill |
Definition at line 411 of file specificLumi.py.
int specificLumi::MINFILL = 1800 |
Definition at line 18 of file specificLumi.py.
specificLumi::minfillnum = options.minfill |
Definition at line 412 of file specificLumi.py.
tuple specificLumi::normid = 0 |
Definition at line 462 of file specificLumi.py.
tuple specificLumi::normmap = normDML.normIdByType(session.nominalSchema(),lumitype='HF',defaultonly=True) |
Definition at line 467 of file specificLumi.py.
tuple specificLumi::normname = 'NONE' |
Definition at line 461 of file specificLumi.py.
tuple specificLumi::normvalueDict = {} |
Definition at line 463 of file specificLumi.py.
tuple specificLumi::options = parser.parse_args() |
Definition at line 398 of file specificLumi.py.
tuple specificLumi::parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description = "specific lumi",formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
######################## ## ## ################## ## ## ## ## Main Program ## ## ## ## ################## ## ## ######################## ##
Definition at line 324 of file specificLumi.py.
tuple specificLumi::processedfills = listfilldir(options.outputdir) |
Definition at line 419 of file specificLumi.py.
tuple specificLumi::reqfillmax = max(fillstoprocess) |
Definition at line 446 of file specificLumi.py.
tuple specificLumi::reqfillmin = min(fillstoprocess) |
Definition at line 445 of file specificLumi.py.
specificLumi::required = False, |
Definition at line 330 of file specificLumi.py.
tuple specificLumi::runlist = lumiCalcAPI.runList(session.nominalSchema(),options.fillnum,runmin=None,runmax=None,fillmin=reqfillmin,fillmax=reqfillmax,startT=None,stopT=None,l1keyPattern=None,hltkeyPattern=None,amodetag=options.amodetag,nominalEnergy=None,energyFlut=None,requiretrg=False,requirehlt=False) |
Definition at line 448 of file specificLumi.py.
tuple specificLumi::schema = session.nominalSchema() |
Definition at line 417 of file specificLumi.py.
tuple specificLumi::session = svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')]) |
Definition at line 408 of file specificLumi.py.
tuple specificLumi::svc = sessionManager.sessionManager(options.connect,authpath=options.authpath,debugON=options.debug) |
query DB for all fills and compare with allfills.txt if found newer fills, store in mem fill number reprocess anyway the last 1 fill in the dir redo specific lumi for all marked fills
Definition at line 407 of file specificLumi.py.
specificLumi::type = int, |
Definition at line 352 of file specificLumi.py.
list specificLumi::xingAlgoChoices = [ "OCC1","OCC2","ET"] |
Definition at line 326 of file specificLumi.py.