Functions | |
def | calculateSpecificLumi |
def | filltofiles |
output methods#### | |
def | getFillFromDB |
def | getFillFromFile |
def | getSpecificLumi |
def | specificlumiTofile |
Variables | |
tuple | allfillF = open(os.path.join(options.inputdir,allfillname),'r') |
string | allfillname = 'allfills.txt' |
tuple | allfillsFromDB = lumiQueryAPI.allfills(q) |
list | allfillsFromFile = [] |
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 | |
list | allruns = [item for sublist in runs for item in sublist] |
tuple | filldata = getSpecificLumi(session,parameters,fillnum,options.inputdir) |
list | fillstoprocess = [] |
tuple | l = line.strip() |
tuple | options = parser.parse_args() |
tuple | parameters = lumiQueryAPI.ParametersObject() |
tuple | parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description = "Dump Fill",formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
tuple | q = session.nominalSchema() |
tuple | runs = runsperfillFromDB.values() |
dictionary | runsperfillFromDB = {} |
dictionary | runtimes = {} |
def specificLumi-2011::calculateSpecificLumi | ( | lumi, | |
lumierr, | |||
beam1intensity, | |||
beam1intensityerr, | |||
beam2intensity, | |||
beam2intensityerr | |||
) |
Definition at line 16 of file specificLumi-2011.py.
00017 : 00018 ''' 00019 ''' 00020 specificlumi=0.0 00021 specificlumierr=0.0 00022 if lumi!=0.0 and beam1intensity!=0.0 and beam2intensity!=0.0: 00023 specificlumi=float(lumi)/(float(beam1intensity)*float(beam2intensity)) 00024 specificlumierr=specificlumi*math.sqrt(lumierr**2/lumi**2+beam1intensityerr**2/beam1intensity**2+beam2intensityerr**2/beam2intensity**2) 00025 return (specificlumi,specificlumierr)
def specificLumi-2011::filltofiles | ( | allfills, | |
runsperfill, | |||
runtimes, | |||
dirname | |||
) |
output methods####
Definition at line 136 of file specificLumi-2011.py.
00137 : 00138 f=open(os.path.join(dirname,allfillname),'w') 00139 for fill in allfills: 00140 print >>f,'%d'%(fill) 00141 f.close() 00142 for fill,runs in runsperfill.items(): 00143 filename='fill_'+str(fill)+'.txt' 00144 if len(runs)!=0: 00145 f=open(os.path.join(dirname,filename),'w') 00146 for run in runs: 00147 print >>f,'%d,%s'%(run,runtimes[run]) 00148 f.close()
def specificLumi-2011::getFillFromDB | ( | dbsession, | |
parameters, | |||
fillnum | |||
) |
Definition at line 26 of file specificLumi-2011.py.
00027 : 00028 runtimesInFill={} 00029 q=dbsession.nominalSchema().newQuery() 00030 fillrundict=lumiQueryAPI.runsByfillrange(q,fillnum,fillnum) 00031 del q 00032 if len(fillrundict)>0: 00033 for fill,runs in fillrundict.items(): 00034 for run in runs: 00035 q=dbsession.nominalSchema().newQuery() 00036 rresult=lumiQueryAPI.runsummaryByrun(q,run) 00037 del q 00038 if len(rresult)==0: continue 00039 runtimesInFill[run]=rresult[3] 00040 return runtimesInFill
def specificLumi-2011::getFillFromFile | ( | fillnum, | |
inputdir | |||
) |
Definition at line 41 of file specificLumi-2011.py.
00042 : 00043 runtimesInFill={} 00044 #look for files 'fill_num.txt' in inputdir 00045 for filename in os.listdir(inputdir): 00046 filename=filename.strip() 00047 if filename.find('.')==-1: continue 00048 basename,extension=filename.split('.') 00049 if not extension or extension!='txt': 00050 continue 00051 if basename.find('_')==-1: continue 00052 prefix,number=basename.split('_') 00053 if not number : continue 00054 if fillnum!=int(number):continue 00055 f=open(os.path.join(inputdir,'fill_'+number+'.txt'),'r') 00056 for line in f: 00057 l=line.strip() 00058 fields=l.split(',') 00059 if len(fields)<2 : continue 00060 runtimesInFill[int(fields[0])]=fields[1] 00061 f.close() 00062 return runtimesInFill
def specificLumi-2011::getSpecificLumi | ( | dbsession, | |
parameters, | |||
fillnum, | |||
inputdir | |||
) |
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 63 of file specificLumi-2011.py.
00064 : 00065 ''' 00066 specific lumi in 1e-30 (ub-1s-1) unit 00067 lumidetail occlumi in 1e-27 00068 1309_lumi_401_CMS.txt 00069 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) 00070 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 00071 result [(time,beamstatusfrac,lumi,lumierror,speclumi,speclumierror)] 00072 ''' 00073 #result=[] 00074 runtimesInFill=getFillFromFile(fillnum,inputdir)#{runnum:starttimestr} 00075 beamstatusDict={}#{runnum:{(startorbit,cmslsnum):beamstatus}} 00076 t=lumiTime.lumiTime() 00077 fillbypos={}#{bxidx:(lstime,beamstatusfrac,lumi,lumierror,specificlumi,specificlumierror)} 00078 #referencetime=time.mktime(datetime.datetime(2010,1,1,0,0,0).timetuple()) 00079 referencetime=0 00080 if fillnum and len(runtimesInFill)==0: 00081 runtimesInFill=getFillFromDB(dbsession,parameters,fillnum)#{runnum:starttimestr} 00082 #precheck 00083 totalstablebeamLS=0 00084 for runnum in runtimesInFill.keys(): 00085 q=dbsession.nominalSchema().newQuery() 00086 runinfo=lumiQueryAPI.lumisummaryByrun(q,runnum,'0001',beamstatus=None) 00087 del q 00088 lsbeamstatusdict={} 00089 for perlsdata in runinfo: 00090 cmslsnum=perlsdata[0] 00091 startorbit=perlsdata[3] 00092 beamstatus=perlsdata[4] 00093 lsbeamstatusdict[(startorbit,cmslsnum)]=beamstatus 00094 #print (startorbit,cmslsnum),beamstatus 00095 if beamstatus=='STABLE BEAMS': 00096 totalstablebeamLS+=1 00097 beamstatusDict[runnum]=lsbeamstatusdict 00098 if totalstablebeamLS<10:#less than 10 LS in a fill has 'stable beam', it's no a good fill 00099 print 'fill ',fillnum,' , having less than 10 stable beam lS, is not good, skip' 00100 return fillbypos 00101 for runnum,starttime in runtimesInFill.items(): 00102 if not runtimesInFill.has_key(runnum): 00103 print 'run '+str(runnum)+' does not exist' 00104 continue 00105 q=dbsession.nominalSchema().newQuery() 00106 occlumidata=lumiQueryAPI.calibratedDetailForRunLimitresult(q,parameters,runnum)#{(startorbit,cmslsnum):[(bxidx,lumivalue,lumierr)]} #values after cut 00107 del q 00108 #print occlumidata 00109 q=dbsession.nominalSchema().newQuery() 00110 beamintensitydata=lumiQueryAPI.beamIntensityForRun(q,parameters,runnum)#{startorbit:[(bxidx,beam1intensity,beam2intensity)]} 00111 #print 'beamintensity for run ',runnum,beamintensitydata 00112 del q 00113 for (startorbit,cmslsnum),lumilist in occlumidata.items(): 00114 if len(lumilist)==0: continue 00115 beamstatusflag=beamstatusDict[runnum][(startorbit,cmslsnum)] 00116 beamstatusfrac=0.0 00117 if beamstatusflag=='STABLE BEAMS': 00118 beamstatusfrac=1.0 00119 lstimestamp=t.OrbitToUTCTimestamp(starttime,startorbit) 00120 if beamintensitydata.has_key(startorbit) and len(beamintensitydata[startorbit])>0: 00121 for lumidata in lumilist: 00122 bxidx=lumidata[0] 00123 lumi=lumidata[1] 00124 lumierror=lumidata[2] 00125 for beamintensitybx in beamintensitydata[startorbit]: 00126 if beamintensitybx[0]==bxidx: 00127 if not fillbypos.has_key(bxidx): 00128 fillbypos[bxidx]=[] 00129 beam1intensity=beamintensitybx[1] 00130 beam2intensity=beamintensitybx[2] 00131 speclumi=calculateSpecificLumi(lumi,lumierror,beam1intensity,0.0,beam2intensity,0.0) 00132 fillbypos[bxidx].append([lstimestamp-referencetime,beamstatusfrac,lumi,lumierror,beam1intensity,beam2intensity,speclumi[0],speclumi[1]]) 00133 #print fillbypos 00134 return fillbypos
def specificLumi-2011::specificlumiTofile | ( | fillnum, | |
filldata, | |||
outdir | |||
) |
Definition at line 149 of file specificLumi-2011.py.
00150 : 00151 timedict={}#{lstime:[[stablebeamfrac,lumi,lumierr,speclumi,speclumierr]]} 00152 # 00153 #check outdir/fillnum subdir exists; if not, create it; else outdir=outdir/fillnum 00154 # 00155 filloutdir=os.path.join(outdir,str(fillnum)) 00156 print 'filloutdir ',filloutdir 00157 if not os.path.exists(filloutdir): 00158 os.mkdir(filloutdir) 00159 for cmsbxidx,perbxdata in filldata.items(): 00160 lhcbucket=0 00161 if cmsbxidx!=0: 00162 lhcbucket=(cmsbxidx-1)*10+1 00163 a=sorted(perbxdata,key=lambda x:x[0]) 00164 filename=str(fillnum)+'_lumi_'+str(lhcbucket)+'_CMS.txt' 00165 linedata=[] 00166 for perlsdata in a: 00167 ts=int(perlsdata[0]) 00168 beamstatusfrac=perlsdata[1] 00169 lumi=perlsdata[2] 00170 lumierror=perlsdata[3] 00171 beam1intensity=perlsdata[4] 00172 beam2intensity=perlsdata[5] 00173 speclumi=perlsdata[6] 00174 speclumierror= perlsdata[7] 00175 if lumi>0 and lumierror>0 and speclumi>0: 00176 linedata.append([ts,beamstatusfrac,lumi,lumierror,speclumi,speclumierror]) 00177 if not timedict.has_key(ts): 00178 timedict[ts]=[] 00179 timedict[ts].append([beamstatusfrac,lumi,lumierror,speclumi,speclumierror]) 00180 if len(linedata)>10:#at least 10 good ls 00181 f=open(os.path.join(filloutdir,filename),'w') 00182 for line in linedata: 00183 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]) 00184 f.close() 00185 #print 'writing avg file' 00186 summaryfilename=str(fillnum)+'_lumi_CMS.txt' 00187 f=None 00188 lstimes=timedict.keys() 00189 lstimes.sort() 00190 fillseg=[] 00191 lscounter=0 00192 for lstime in lstimes: 00193 allvalues=timedict[lstime] 00194 transposedvalues=CommonUtil.transposed(allvalues,0.0) 00195 bstatfrac=transposedvalues[0][0]#beamstatus does not change with bx position 00196 lumivals=transposedvalues[1] 00197 lumitot=sum(lumivals) 00198 if bstatfrac==1.0 : 00199 fillseg.append([lstime,lumitot]) 00200 lumierrs=transposedvalues[2] 00201 lumierrortot=math.sqrt(sum(map(lambda x:x**2,lumierrs))) 00202 specificvals=transposedvalues[3] 00203 specificavg=sum(specificvals)/float(len(specificvals))#avg spec lumi 00204 specificerrs=transposedvalues[4] 00205 specifictoterr=math.sqrt(sum(map(lambda x:x**2,specificerrs))) 00206 specificerravg=specifictoterr/float(len(specificvals)) 00207 if lscounter==0: 00208 f=open(os.path.join(filloutdir,summaryfilename),'w') 00209 lscounter+=1 00210 print >>f,'%d\t%e\t%e\t%e\t%e\t%e'%(lstime,bstatfrac,lumitot,lumierrortot,specificavg,specificerravg) 00211 if f is not None: 00212 f.close() 00213 #print 'writing summary file' 00214 fillsummaryfilename=str(fillnum)+'_summary_CMS.txt' 00215 f=open(os.path.join(filloutdir,fillsummaryfilename),'w') 00216 if len(fillseg)==0: 00217 print >>f,'%s'%('#no stable beams') 00218 f.close() 00219 return 00220 previoustime=fillseg[0][0] 00221 boundarytime=fillseg[0][0] 00222 #print 'boundary time ',boundarytime 00223 summaryls={} 00224 summaryls[boundarytime]=[] 00225 for [lstime,lumitot] in fillseg:#fillseg is everything with stable beam flag 00226 if lstime-previoustime>50.0: 00227 boundarytime=lstime 00228 #print 'found new boundary ',boundarytime 00229 summaryls[boundarytime]=[] 00230 # print 'appending ',boundarytime,lstime,lumitot 00231 summaryls[boundarytime].append([lstime,lumitot]) 00232 previoustime=lstime 00233 #print summaryls 00234 00235 summarylstimes=summaryls.keys() 00236 summarylstimes.sort() 00237 for bts in summarylstimes: 00238 startts=bts 00239 tsdatainseg=summaryls[bts] 00240 #print 'tsdatainseg ',tsdatainseg 00241 stopts=tsdatainseg[-1][0] 00242 plu=max(CommonUtil.transposed(tsdatainseg,0.0)[1]) 00243 lui=sum(CommonUtil.transposed(tsdatainseg,0.0)[1])*23.357 00244 print >>f,'%d\t%d\t%e\t%e'%(startts,stopts,plu,lui) 00245 f.close()
tuple specificLumi-2011::allfillF = open(os.path.join(options.inputdir,allfillname),'r') |
Definition at line 285 of file specificLumi-2011.py.
string specificLumi-2011::allfillname = 'allfills.txt' |
Definition at line 14 of file specificLumi-2011.py.
tuple specificLumi-2011::allfillsFromDB = lumiQueryAPI.allfills(q) |
Definition at line 282 of file specificLumi-2011.py.
list specificLumi-2011::allfillsFromFile = [] |
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 275 of file specificLumi-2011.py.
Definition at line 318 of file specificLumi-2011.py.
tuple specificLumi-2011::filldata = getSpecificLumi(session,parameters,fillnum,options.inputdir) |
Definition at line 332 of file specificLumi-2011.py.
specificLumi-2011::fillstoprocess = [] |
Definition at line 276 of file specificLumi-2011.py.
tuple specificLumi-2011::l = line.strip() |
Definition at line 287 of file specificLumi-2011.py.
tuple specificLumi-2011::options = parser.parse_args() |
Definition at line 258 of file specificLumi-2011.py.
tuple specificLumi-2011::parameters = lumiQueryAPI.ParametersObject() |
Definition at line 261 of file specificLumi-2011.py.
tuple specificLumi-2011::parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description = "Dump Fill",formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
Definition at line 247 of file specificLumi-2011.py.
tuple specificLumi-2011::q = session.nominalSchema() |
Definition at line 281 of file specificLumi-2011.py.
tuple specificLumi-2011::runs = runsperfillFromDB.values() |
Definition at line 317 of file specificLumi-2011.py.
tuple specificLumi-2011::runsperfillFromDB = {} |
Definition at line 311 of file specificLumi-2011.py.
dictionary specificLumi-2011::runtimes = {} |
Definition at line 316 of file specificLumi-2011.py.