CMS 3D CMS Logo

Functions | Variables

specificLumi Namespace Reference

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 5 fills 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 = {}

Function Documentation

def specificLumi::calculateSpecificLumi (   lumi,
  lumierr,
  beam1intensity,
  beam1intensityerr,
  beam2intensity,
  beam2intensityerr 
)

Definition at line 16 of file specificLumi.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::filltofiles (   allfills,
  runsperfill,
  runtimes,
  dirname 
)

output methods####

Definition at line 125 of file specificLumi.py.

00126                                                       :
00127     f=open(os.path.join(dirname,allfillname),'w')
00128     for fill in allfills:
00129         print >>f,'%d'%(fill)
00130     f.close()
00131     for fill,runs in runsperfill.items():
00132         filename='fill_'+str(fill)+'.txt'
00133         if len(runs)!=0:
00134             f=open(os.path.join(dirname,filename),'w')
00135             for run in runs:
00136                 print >>f,'%d,%s'%(run,runtimes[run])
00137             f.close()
            
def specificLumi::getFillFromDB (   dbsession,
  parameters,
  fillnum 
)

Definition at line 26 of file specificLumi.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::getFillFromFile (   fillnum,
  inputdir 
)

Definition at line 41 of file specificLumi.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::getSpecificLumi (   dbsession,
  parameters,
  fillnum,
  inputdir 
)
specific lumi in 1e-30 (ub-1s-1) unit
lumidetail occlumi in 1e-27
1309_lumireg_401_CMS.txt
ip fillnum time 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)
5  1309 20800119.0 -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,lumi,lumierror,speclumi,speclumierror)]

Definition at line 63 of file specificLumi.py.

00064                                                           :
00065     '''
00066     specific lumi in 1e-30 (ub-1s-1) unit
00067     lumidetail occlumi in 1e-27
00068     1309_lumireg_401_CMS.txt
00069     ip fillnum time 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     5  1309 20800119.0 -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,lumi,lumierror,speclumi,speclumierror)]
00072     '''
00073     #result=[]
00074     runtimesInFill=getFillFromFile(fillnum,inputdir)#{runnum:starttimestr}
00075     t=lumiTime.lumiTime()
00076     fillbypos={}#{bxidx:(lstime,lumi,lumierror,specificlumi,specificlumierror)}
00077     #'referencetime=time.mktime(datetime.datetime(2009,12,31,23,0,0).timetuple())
00078     #referencetime=time.mktime(datetime.datetime(2010,1,1,0,0,0).timetuple())
00079     referencetime=1262300400-7232
00080     #for i in range(3564):
00081     #    fillbypos[i]=[]
00082 
00083     if fillnum and len(runtimesInFill)==0:
00084         runtimesInFill=getFillFromDB(dbsession,parameters,fillnum)#{runnum:starttimestr}
00085     #precheck
00086     totalstablebeamLS=0
00087     for runnum in runtimesInFill.keys():
00088         q=dbsession.nominalSchema().newQuery()
00089         runinfo=lumiQueryAPI.lumisummaryByrun(q,runnum,'0001',beamstatus='STABLE BEAMS')
00090         del q
00091         totalstablebeamLS+=len(runinfo)
00092     if totalstablebeamLS<10:#less than 10 LS in a fill has 'stable beam', it's no a good fill
00093         print 'fill ',fillnum,' , having less than 10 stable beam lS, is not good, skip'
00094         return fillbypos
00095     
00096     for runnum,starttime in runtimesInFill.items():
00097         if not runtimesInFill.has_key(runnum):
00098             print 'run '+str(runnum)+' does not exist'
00099             continue
00100         q=dbsession.nominalSchema().newQuery()
00101         occlumidata=lumiQueryAPI.calibratedDetailForRunLimitresult(q,parameters,runnum)#{(startorbit,cmslsnum):[(bxidx,lumivalue,lumierr)]} #values after cut
00102         del q
00103         #print occlumidata
00104         q=dbsession.nominalSchema().newQuery()
00105         beamintensitydata=lumiQueryAPI.beamIntensityForRun(q,parameters,runnum)#{startorbit:[(bxidx,beam1intensity,beam2intensity)]}
00106         del q
00107         for (startorbit,cmslsnum),lumilist in occlumidata.items():
00108             if len(lumilist)==0: continue
00109             lstimestamp=t.OrbitToTimestamp(starttime,startorbit)
00110             if beamintensitydata.has_key(startorbit) and len(beamintensitydata[startorbit])>0:
00111                 for lumidata in lumilist:
00112                     bxidx=lumidata[0]
00113                     lumi=lumidata[1]
00114                     lumierror=lumidata[2]
00115                     for beamintensitybx in beamintensitydata[startorbit]:
00116                         if beamintensitybx[0]==bxidx:
00117                             if not fillbypos.has_key(bxidx):
00118                                 fillbypos[bxidx]=[]
00119                             beam1intensity=beamintensitybx[1]
00120                             beam2intensity=beamintensitybx[2]
00121                             speclumi=calculateSpecificLumi(lumi,lumierror,beam1intensity,0.0,beam2intensity,0.0)
00122                             fillbypos[bxidx].append([lstimestamp-referencetime,lumi,lumierror,beam1intensity,beam2intensity,speclumi[0],speclumi[1]])
00123     return fillbypos

def specificLumi::specificlumiTofile (   fillnum,
  filldata,
  outdir 
)

Definition at line 138 of file specificLumi.py.

00139                                                :
00140     timedict={}#{lstime:[[lumi,lumierr,speclumi,speclumierr]]}
00141     ipnumber=5
00142     for cmsbxidx,perbxdata in filldata.items():
00143         lhcbucket=0
00144         if cmsbxidx!=0:
00145             lhcbucket=(cmsbxidx-1)*10+1
00146         a=sorted(perbxdata,key=lambda x:x[0])
00147         lscounter=0
00148         filename=str(fillnum)+'_lumi_'+str(lhcbucket)+'_CMS.txt'
00149         for perlsdata in a:
00150             if perlsdata[-2]>0 and perlsdata[-1]>0 and perlsdata[1]>0:
00151                 if lscounter==0:
00152                     f=open(os.path.join(outdir,filename),'w')
00153                 print >>f, '%d\t%d\t%d\t%e\t%e\t%e\t%e\n'%(int(ipnumber),int(fillnum),int(perlsdata[0]),perlsdata[1],perlsdata[2],perlsdata[-2],perlsdata[-1])
00154                 if not timedict.has_key(int(perlsdata[0])):
00155                     timedict[int(perlsdata[0])]=[]
00156                 timedict[int(perlsdata[0])].append([perlsdata[1],perlsdata[2],perlsdata[-2],perlsdata[-1]])
00157                 lscounter+=1
00158         f.close()
00159         summaryfilename=str(fillnum)+'_lumi_CMS.txt'
00160         f=open(os.path.join(outdir,summaryfilename),'w')
00161         lstimes=timedict.keys()
00162         lstimes.sort()
00163         for lstime in lstimes:
00164             allvalues=timedict[lstime]
00165             transposedvalues=CommonUtil.transposed(allvalues,0.0)
00166             lumivals=transposedvalues[0]
00167             lumitot=sum(lumivals)
00168             lumierrs=transposedvalues[1]
00169             lumierrortot=math.sqrt(sum(map(lambda x:x**2,lumierrs)))
00170             specificvals=transposedvalues[2]
00171             specificavg=sum(specificvals)/float(len(specificvals))#avg spec lumi
00172             specificerrs=transposedvalues[3]
00173             specifictoterr=math.sqrt(sum(map(lambda x:x**2,specificerrs)))
00174             specificerravg=specifictoterr/float(len(specificvals))
00175             print >>f,'%d\t%d\t%d\t%e\t%e\t%e\t%e\n'%(int(ipnumber),int(fillnum),lstime,lumitot,lumierrortot,specificavg,specificerravg)
        f.close()

Variable Documentation

tuple specificLumi::allfillF = open(os.path.join(options.inputdir,allfillname),'r')

Definition at line 212 of file specificLumi.py.

string specificLumi::allfillname = 'allfills.txt'

Definition at line 14 of file specificLumi.py.

Definition at line 209 of file specificLumi.py.

query DB for all fills and compare with allfills.txt if found newer fills, store in mem fill number reprocess anyway the last 5 fills in the dir redo specific lumi for all marked fills

Definition at line 202 of file specificLumi.py.

list specificLumi::allruns = [item for sublist in runs for item in sublist]

Definition at line 245 of file specificLumi.py.

tuple specificLumi::filldata = getSpecificLumi(session,parameters,fillnum,options.inputdir)

Definition at line 259 of file specificLumi.py.

Definition at line 203 of file specificLumi.py.

tuple specificLumi::l = line.strip()

Definition at line 214 of file specificLumi.py.

tuple specificLumi::options = parser.parse_args()

Definition at line 187 of file specificLumi.py.

Definition at line 190 of file specificLumi.py.

tuple specificLumi::parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description = "Dump Fill",formatter_class=argparse.ArgumentDefaultsHelpFormatter)

Definition at line 177 of file specificLumi.py.

tuple specificLumi::q = session.nominalSchema()

Definition at line 208 of file specificLumi.py.

tuple specificLumi::runs = runsperfillFromDB.values()

Definition at line 244 of file specificLumi.py.

Definition at line 238 of file specificLumi.py.

dictionary specificLumi::runtimes = {}

Definition at line 243 of file specificLumi.py.