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, | |
string | default = 'frontier://LumiCalc/CMS_LUMI_PROD' |
driftcorrections = None | |
dictionary | filldata = {} |
list | fillstoprocess = [] |
finecorrections = None | |
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 | |
normfactor = options.normfactor | |
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 | |
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) |
required = 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) |
type = int, | |
withcorrection = notoptions.withoutFineCorrection | |
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 69 of file specificLumi.py.
00070 : 00071 ''' 00072 calculate specific lumi 00073 input: instlumi, instlumierror,beam1intensity,beam1intensityerror,beam2intensity,beam2intensityerror 00074 output (specific lumi value,specific lumi error) 00075 ''' 00076 specificlumi=0.0 00077 specificlumierr=0.0 00078 if beam1intensity<0: beam1intensity=0 00079 if beam2intensity<0: beam2intensity=0 00080 if beam1intensity!=0.0 and beam2intensity!=0.0: 00081 specificlumi=float(lumi)/(float(beam1intensity)*float(beam2intensity)) 00082 specificlumierr=specificlumi*math.sqrt(lumierr**2/lumi**2+beam1intensityerr**2/beam1intensity**2+beam2intensityerr**2/beam2intensity**2) 00083 return (specificlumi,specificlumierr)
def specificLumi::filltofiles | ( | allfills, | |
runsperfill, | |||
runtimes, | |||
dirname | |||
) |
output methods####
write runnumber:starttime map per fill to files
Definition at line 116 of file specificLumi.py.
00117 : 00118 ''' 00119 write runnumber:starttime map per fill to files 00120 ''' 00121 f=open(os.path.join(dirname,allfillname),'w') 00122 for fill in allfills: 00123 print >>f,'%d'%(fill) 00124 f.close() 00125 for fill,runs in runsperfill.items(): 00126 filename='fill_'+str(fill)+'.txt' 00127 if len(runs)!=0: 00128 f=open(os.path.join(dirname,filename),'w') 00129 for run in runs: 00130 print >>f,'%d,%s'%(run,runtimes[run]) 00131 f.close()
def specificLumi::getFillFromDB | ( | schema, | |
fillnum | |||
) |
output: {run:starttime}
Definition at line 17 of file specificLumi.py.
00018 : 00019 ''' 00020 output: {run:starttime} 00021 ''' 00022 runtimesInFill={} 00023 fillrundict=lumiCalcAPI.fillrunMap(schema,fillnum) 00024 if len(fillrundict)>0: 00025 runs=fillrundict.values()[0] 00026 runlsdict=dict(zip(runs,[None]*len(runs))) 00027 runresult=lumiCalcAPI.runsummary(schema,runlsdict) 00028 for perrundata in runresult: 00029 runtimesInFill[perrundata[0]]=perrundata[7] 00030 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 84 of file specificLumi.py.
00085 : 00086 ''' 00087 parse fill_xxx.txt files in the input directory for runs, starttime in the fill 00088 input: fillnumber, input dir 00089 output: {run:tarttime} 00090 ''' 00091 runtimesInFill={} 00092 #look for files 'fill_num.txt' in inputdir 00093 for filename in os.listdir(inputdir): 00094 mpat=r'^fill_[0-9]{4}.txt$' 00095 m=re.compile(mpat) 00096 if m.match(filename) is None: 00097 continue 00098 filename=filename.strip() 00099 if filename.find('.')==-1: continue 00100 basename,extension=filename.split('.') 00101 if not extension or extension!='txt': 00102 continue 00103 if basename.find('_')==-1: continue 00104 prefix,number=basename.split('_') 00105 if not number : continue 00106 if fillnum!=int(number):continue 00107 f=open(os.path.join(inputdir,'fill_'+number+'.txt'),'r') 00108 for line in f: 00109 l=line.strip() 00110 fields=l.split(',') 00111 if len(fields)<2 : continue 00112 runtimesInFill[int(fields[0])]=fields[1] 00113 f.close() 00114 return runtimesInFill
def specificLumi::getSpecificLumi | ( | schema, | |
fillnum, | |||
inputdir, | |||
xingMinLum = 0.0 , |
|||
norm = 'pp7TeV' , |
|||
withcorrection = True , |
|||
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 235 of file specificLumi.py.
00236 : 00237 ''' 00238 specific lumi in 1e-30 (ub-1s-1) unit 00239 lumidetail occlumi in 1e-27 00240 1309_lumi_401_CMS.txt 00241 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) 00242 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 00243 result [(time,beamstatusfrac,lumi,lumierror,speclumi,speclumierror)] 00244 ''' 00245 t=lumiTime.lumiTime() 00246 fillbypos={}#{bxidx:[[ts,beamstatusfrac,lumi,lumierror,spec1,specerror],[]]} 00247 runtimesInFill=getFillFromDB(schema,fillnum)#{runnum:starttimestr} 00248 runlist=runtimesInFill.keys() 00249 if not runlist: return fillbypos 00250 irunlsdict=dict(zip(runlist,[None]*len(runlist))) 00251 #print irunlsdict 00252 finecorrections=None 00253 driftcorrections=None 00254 if withcorrection : 00255 cterms=lumiCorrections.nonlinearV2() 00256 finecorrections=lumiCorrections.correctionsForRangeV2(schema,runlist,cterms)#constant+nonlinear corrections 00257 driftcorrections=lumiCorrections.driftcorrectionsForRange(schema,runlist,cterms) 00258 lumidetails=lumiCalcAPI.instCalibratedLumiForRange(schema,irunlsdict,beamstatus=None,amodetag=amodetag,withBXInfo=True,withBeamIntensity=True,bxAlgo=bxAlgo,xingMinLum=xingMinLum,norm=norm,finecorrections=finecorrections,driftcorrections=driftcorrections,usecorrectionv2=True) 00259 session.transaction().commit() 00260 # 00261 #output: {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),calibratedlumi(5),calibratedlumierr(6),startorbit(7),numorbit(8),(bxvalues,bxerrs)(9),(bxidx,b1intensities,b2intensities)(10)]}} 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 for run in orderedrunlist: 00276 perrundata=lumidetails[run] 00277 for perlsdata in perrundata: 00278 beamstatusfrac=0.0 00279 tsdatetime=perlsdata[2] 00280 ts=calendar.timegm(tsdatetime.utctimetuple()) 00281 beamstatus=perlsdata[3] 00282 if beamstatus=='STABLE BEAMS': 00283 beamstatusfrac=1.0 00284 (bxidxlist,bxvaluelist,bxerrolist)=perlsdata[9] 00285 maxlumi=0.0 00286 if len(bxvaluelist)!=0: 00287 maxlumi=max(bxvaluelist) 00288 avginstlumi=0.0 00289 if len(bxvaluelist)!=0: 00290 avginstlumi=sum(bxvaluelist) 00291 (intbxidxlist,b1intensities,b2intensities)=perlsdata[10]#contains only non-zero bx 00292 for bxidx in bxidxlist: 00293 idx=bxidxlist.index(bxidx) 00294 bxvalue=bxvaluelist[idx] 00295 bxerror=bxerrolist[idx] 00296 if bxvalue<max(xingMinLum,maxlumi*0.2): 00297 continue 00298 bintensityPos=-1 00299 try: 00300 bintensityPos=intbxidxlist.index(bxidx) 00301 except ValueError: 00302 pass 00303 if bintensityPos<=0: 00304 fillbypos.setdefault(bxidx,[]).append([ts,beamstatusfrac,bxvalue,bxerror,0.0,0.0]) 00305 continue 00306 b1intensity=b1intensities[bintensityPos] 00307 b2intensity=b2intensities[bintensityPos] 00308 speclumi=calculateSpecificLumi(bxvalue,bxerror,b1intensity,0.0,b2intensity,0.0) 00309 fillbypos.setdefault(bxidx,[]).append([ts,beamstatusfrac,bxvalue,bxerror,speclumi[0],speclumi[1]]) 00310 return fillbypos 00311
def specificLumi::lastcompleteFill | ( | infile | ) |
parse infile to find LASTCOMPLETEFILL input: input file name output: last completed fill number
Definition at line 52 of file specificLumi.py.
00053 : 00054 ''' 00055 parse infile to find LASTCOMPLETEFILL 00056 input: input file name 00057 output: last completed fill number 00058 ''' 00059 lastfill=None 00060 hlinepat=r'(LASTCOMPLETEFILL )([0-9]{4})' 00061 h=re.compile(hlinepat) 00062 dqmfile=open(infile,'r') 00063 for line in dqmfile: 00064 result=h.match(line) 00065 if result: 00066 lastfill=result.group(2) 00067 break 00068 return int(lastfill)
def specificLumi::listfilldir | ( | indir | ) |
list all fills contained in the given dir input: indir output: [fill]
Definition at line 31 of file specificLumi.py.
00032 : 00033 ''' 00034 list all fills contained in the given dir 00035 input: indir 00036 output: [fill] 00037 ''' 00038 fillnamepat=r'^[0-9]{4}$' 00039 p=re.compile(fillnamepat) 00040 processedfills=[] 00041 dirList=os.listdir(indir) 00042 for fname in dirList: 00043 if p.match(fname) and os.path.isdir(os.path.join(indir,fname)):#found fill dir 00044 allfs=os.listdir(os.path.join(indir,fname)) 00045 for myfile in allfs: 00046 sumfilenamepat=r'^[0-9]{4}_bxsum_CMS.txt$' 00047 s=re.compile(sumfilenamepat) 00048 if s.match(myfile): 00049 #only if fill_summary_CMS.txt file exists 00050 processedfills.append(int(fname)) 00051 return processedfills
def specificLumi::specificlumiTofile | ( | fillnum, | |
filldata, | |||
outdir | |||
) |
Definition at line 132 of file specificLumi.py.
00133 : 00134 # 00135 #input : fillnum 00136 # filldata: {bxidx:[[lstime,beamstatusfrac,lumivalue,lumierror,speclumi,speclumierr]],[]} 00137 #sorted by bxidx, sorted by lstime inside list 00138 #check outdir/fillnum subdir exists; if not, create it; else outdir=outdir/fillnum 00139 # 00140 if not filldata: 00141 print 'empty input data, do nothing for fill ',fillnum 00142 return 00143 timedict={}#{lstime:[[stablebeamfrac,lumi,lumierr,speclumi,speclumierr]]} 00144 filloutdir=os.path.join(outdir,str(fillnum)) 00145 if not os.path.exists(filloutdir): 00146 os.mkdir(filloutdir) 00147 for cmsbxidx,perbxdata in filldata.items(): 00148 lhcbucket=0 00149 if cmsbxidx!=0: 00150 lhcbucket=(cmsbxidx-1)*10+1 00151 a=sorted(perbxdata,key=lambda x:x[0]) 00152 filename=str(fillnum)+'_lumi_'+str(lhcbucket)+'_CMS.txt' 00153 linedata=[] 00154 for perlsdata in a: 00155 ts=int(perlsdata[0]) 00156 beamstatusfrac=perlsdata[1] 00157 lumi=perlsdata[2] 00158 lumierror=perlsdata[3] 00159 #beam1intensity=perlsdata[4] 00160 #beam2intensity=perlsdata[5] 00161 speclumi=perlsdata[4] 00162 speclumierror= perlsdata[5] 00163 if lumi>0: 00164 linedata.append([ts,beamstatusfrac,lumi,lumierror,speclumi,speclumierror]) 00165 if not timedict.has_key(ts): 00166 timedict[ts]=[] 00167 timedict[ts].append([beamstatusfrac,lumi,lumierror,speclumi,speclumierror]) 00168 if len(linedata)>10:#at least 10 good ls 00169 f=open(os.path.join(filloutdir,filename),'w') 00170 for line in linedata: 00171 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]) 00172 f.close() 00173 #print 'writing avg file' 00174 summaryfilename=str(fillnum)+'_lumi_CMS.txt' 00175 f=None 00176 lstimes=timedict.keys() 00177 lstimes.sort() 00178 fillseg=[] 00179 lscounter=0 00180 for lstime in lstimes: 00181 allvalues=timedict[lstime] 00182 transposedvalues=CommonUtil.transposed(allvalues,0.0) 00183 bstatfrac=transposedvalues[0][0]#beamstatus does not change with bx position 00184 lumivals=transposedvalues[1] 00185 lumitot=sum(lumivals) 00186 if bstatfrac==1.0 : 00187 fillseg.append([lstime,lumitot]) 00188 lumierrs=transposedvalues[2] 00189 lumierrortot=math.sqrt(sum(map(lambda x:x**2,lumierrs))) 00190 specificvals=transposedvalues[3] 00191 specificavg=sum(specificvals)/float(len(specificvals))#avg spec lumi 00192 specificerrs=transposedvalues[4] 00193 specifictoterr=math.sqrt(sum(map(lambda x:x**2,specificerrs))) 00194 specificerravg=specifictoterr/float(len(specificvals)) 00195 if lscounter==0: 00196 f=open(os.path.join(filloutdir,summaryfilename),'w') 00197 lscounter+=1 00198 print >>f,'%d\t%e\t%e\t%e\t%e\t%e'%(lstime,bstatfrac,lumitot,lumierrortot,specificavg,specificerravg) 00199 if f is not None: 00200 f.close() 00201 #print 'writing summary file' 00202 fillsummaryfilename=str(fillnum)+'_bxsum_CMS.txt' 00203 f=open(os.path.join(filloutdir,fillsummaryfilename),'w') 00204 if len(fillseg)==0: 00205 print >>f,'%s'%('#no stable beams') 00206 f.close() 00207 return 00208 previoustime=fillseg[0][0] 00209 boundarytime=fillseg[0][0] 00210 #print 'boundary time ',boundarytime 00211 summaryls={} 00212 summaryls[boundarytime]=[] 00213 for [lstime,lumitot] in fillseg:#fillseg is everything with stable beam flag 00214 if lstime-previoustime>50.0: 00215 boundarytime=lstime 00216 #print 'found new boundary ',boundarytime 00217 summaryls[boundarytime]=[] 00218 # print 'appending ',boundarytime,lstime,lumitot 00219 summaryls[boundarytime].append([lstime,lumitot]) 00220 previoustime=lstime 00221 #print summaryls 00222 00223 summarylstimes=summaryls.keys() 00224 summarylstimes.sort() 00225 lumip=lumiParameters.ParametersObject() 00226 for bts in summarylstimes: 00227 startts=bts 00228 tsdatainseg=summaryls[bts] 00229 #print 'tsdatainseg ',tsdatainseg 00230 stopts=tsdatainseg[-1][0] 00231 plu=max(CommonUtil.transposed(tsdatainseg,0.0)[1]) 00232 lui=sum(CommonUtil.transposed(tsdatainseg,0.0)[1])*lumip.lslengthsec() 00233 print >>f,'%d\t%d\t%e\t%e'%(startts,stopts,plu,lui) 00234 f.close()
string specificLumi::action = 'store' |
Definition at line 326 of file specificLumi.py.
string specificLumi::allfillname = 'allfills.txt' |
Definition at line 15 of file specificLumi.py.
tuple specificLumi::allfillsFromDB = lumiCalcAPI.fillInRange(schema,fillmin=minfillnum,fillmax=maxfillnum,amodetag=options.amodetag) |
Definition at line 412 of file specificLumi.py.
list specificLumi::amodetagChoices = [ "PROTPHYS","IONPHYS",'PAPHYS' ] |
Definition at line 322 of file specificLumi.py.
Definition at line 363 of file specificLumi.py.
string specificLumi::default = 'frontier://LumiCalc/CMS_LUMI_PROD' |
Definition at line 329 of file specificLumi.py.
Definition at line 432 of file specificLumi.py.
tuple specificLumi::filldata = {} |
Definition at line 436 of file specificLumi.py.
list specificLumi::fillstoprocess = [] |
Definition at line 404 of file specificLumi.py.
Definition at line 431 of file specificLumi.py.
string specificLumi::help = 'connect string to lumiDB,optional' |
Definition at line 328 of file specificLumi.py.
tuple specificLumi::lastcompletedFill = lastcompleteFill(os.path.join(options.inputdir,'runtofill_dqm.txt')) |
Definition at line 414 of file specificLumi.py.
int specificLumi::MAXFILL = 9999 |
Definition at line 14 of file specificLumi.py.
specificLumi::maxfillnum = options.maxfill |
Definition at line 405 of file specificLumi.py.
int specificLumi::MINFILL = 1800 |
Definition at line 13 of file specificLumi.py.
specificLumi::minfillnum = options.minfill |
Definition at line 406 of file specificLumi.py.
specificLumi::normfactor = options.normfactor |
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 400 of file specificLumi.py.
tuple specificLumi::options = parser.parse_args() |
Definition at line 391 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 321 of file specificLumi.py.
tuple specificLumi::processedfills = listfilldir(options.outputdir) |
Definition at line 413 of file specificLumi.py.
specificLumi::required = False, |
Definition at line 327 of file specificLumi.py.
tuple specificLumi::schema = session.nominalSchema() |
Definition at line 411 of file specificLumi.py.
tuple specificLumi::session = svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')]) |
Definition at line 402 of file specificLumi.py.
tuple specificLumi::svc = sessionManager.sessionManager(options.connect,authpath=options.authpath,debugON=options.debug) |
Definition at line 401 of file specificLumi.py.
specificLumi::type = int, |
Definition at line 349 of file specificLumi.py.
specificLumi::withcorrection = notoptions.withoutFineCorrection |
Definition at line 435 of file specificLumi.py.
list specificLumi::xingAlgoChoices = [ "OCC1","OCC2","ET"] |
Definition at line 323 of file specificLumi.py.