CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
specificLumi Namespace Reference

Functions

def calculateSpecificLumi
 
def filltofiles
 output methods#### More...
 
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 More...
 
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.

Referenced by getSpecificLumi().

16 
17 def calculateSpecificLumi(lumi,lumierr,beam1intensity,beam1intensityerr,beam2intensity,beam2intensityerr):
18  '''
19  '''
20  specificlumi=0.0
21  specificlumierr=0.0
22  if lumi!=0.0 and beam1intensity!=0.0 and beam2intensity!=0.0:
23  specificlumi=float(lumi)/(float(beam1intensity)*float(beam2intensity))
24  specificlumierr=specificlumi*math.sqrt(lumierr**2/lumi**2+beam1intensityerr**2/beam1intensity**2+beam2intensityerr**2/beam2intensity**2)
25  return (specificlumi,specificlumierr)
def calculateSpecificLumi
Definition: specificLumi.py:16
def specificLumi.filltofiles (   allfills,
  runsperfill,
  runtimes,
  dirname 
)

output methods####

Definition at line 125 of file specificLumi.py.

126 def filltofiles(allfills,runsperfill,runtimes,dirname):
127  f=open(os.path.join(dirname,allfillname),'w')
128  for fill in allfills:
129  print >>f,'%d'%(fill)
130  f.close()
131  for fill,runs in runsperfill.items():
132  filename='fill_'+str(fill)+'.txt'
133  if len(runs)!=0:
134  f=open(os.path.join(dirname,filename),'w')
135  for run in runs:
136  print >>f,'%d,%s'%(run,runtimes[run])
137  f.close()
def filltofiles
output methods####
def specificLumi.getFillFromDB (   dbsession,
  parameters,
  fillnum 
)

Definition at line 26 of file specificLumi.py.

References lumiQueryAPI.runsByfillrange(), and lumiQueryAPI.runsummaryByrun().

Referenced by getSpecificLumi().

26 
27 def getFillFromDB(dbsession,parameters,fillnum):
28  runtimesInFill={}
29  q=dbsession.nominalSchema().newQuery()
30  fillrundict=lumiQueryAPI.runsByfillrange(q,fillnum,fillnum)
31  del q
32  if len(fillrundict)>0:
33  for fill,runs in fillrundict.items():
34  for run in runs:
35  q=dbsession.nominalSchema().newQuery()
36  rresult=lumiQueryAPI.runsummaryByrun(q,run)
37  del q
38  if len(rresult)==0: continue
39  runtimesInFill[run]=rresult[3]
40  return runtimesInFill
def specificLumi.getFillFromFile (   fillnum,
  inputdir 
)

Definition at line 41 of file specificLumi.py.

Referenced by getSpecificLumi().

41 
42 def getFillFromFile(fillnum,inputdir):
43  runtimesInFill={}
44  #look for files 'fill_num.txt' in inputdir
45  for filename in os.listdir(inputdir):
46  filename=filename.strip()
47  if filename.find('.')==-1: continue
48  basename,extension=filename.split('.')
49  if not extension or extension!='txt':
50  continue
51  if basename.find('_')==-1: continue
52  prefix,number=basename.split('_')
53  if not number : continue
54  if fillnum!=int(number):continue
55  f=open(os.path.join(inputdir,'fill_'+number+'.txt'),'r')
56  for line in f:
57  l=line.strip()
58  fields=l.split(',')
59  if len(fields)<2 : continue
60  runtimesInFill[int(fields[0])]=fields[1]
61  f.close()
62  return runtimesInFill
def getFillFromFile
Definition: specificLumi.py:41
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.

References python.multivaluedict.append(), lumiQueryAPI.beamIntensityForRun(), calculateSpecificLumi(), lumiQueryAPI.calibratedDetailForRunLimitresult(), getFillFromDB(), getFillFromFile(), and lumiQueryAPI.lumisummaryByrun().

63 
64 def getSpecificLumi(dbsession,parameters,fillnum,inputdir):
65  '''
66  specific lumi in 1e-30 (ub-1s-1) unit
67  lumidetail occlumi in 1e-27
68  1309_lumireg_401_CMS.txt
69  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)
70  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
71  result [(time,lumi,lumierror,speclumi,speclumierror)]
72  '''
73  #result=[]
74  runtimesInFill=getFillFromFile(fillnum,inputdir)#{runnum:starttimestr}
76  fillbypos={}#{bxidx:(lstime,lumi,lumierror,specificlumi,specificlumierror)}
77  #'referencetime=time.mktime(datetime.datetime(2009,12,31,23,0,0).timetuple())
78  #referencetime=time.mktime(datetime.datetime(2010,1,1,0,0,0).timetuple())
79  referencetime=1262300400-7232
80  #for i in range(3564):
81  # fillbypos[i]=[]
82 
83  if fillnum and len(runtimesInFill)==0:
84  runtimesInFill=getFillFromDB(dbsession,parameters,fillnum)#{runnum:starttimestr}
85  #precheck
86  totalstablebeamLS=0
87  for runnum in runtimesInFill.keys():
88  q=dbsession.nominalSchema().newQuery()
89  runinfo=lumiQueryAPI.lumisummaryByrun(q,runnum,'0001',beamstatus='STABLE BEAMS')
90  del q
91  totalstablebeamLS+=len(runinfo)
92  if totalstablebeamLS<10:#less than 10 LS in a fill has 'stable beam', it's no a good fill
93  print 'fill ',fillnum,' , having less than 10 stable beam lS, is not good, skip'
94  return fillbypos
95 
96  for runnum,starttime in runtimesInFill.items():
97  if not runtimesInFill.has_key(runnum):
98  print 'run '+str(runnum)+' does not exist'
99  continue
100  q=dbsession.nominalSchema().newQuery()
101  occlumidata=lumiQueryAPI.calibratedDetailForRunLimitresult(q,parameters,runnum)#{(startorbit,cmslsnum):[(bxidx,lumivalue,lumierr)]} #values after cut
102  del q
103  #print occlumidata
104  q=dbsession.nominalSchema().newQuery()
105  beamintensitydata=lumiQueryAPI.beamIntensityForRun(q,parameters,runnum)#{startorbit:[(bxidx,beam1intensity,beam2intensity)]}
106  del q
107  for (startorbit,cmslsnum),lumilist in occlumidata.items():
108  if len(lumilist)==0: continue
109  lstimestamp=t.OrbitToTimestamp(starttime,startorbit)
110  if beamintensitydata.has_key(startorbit) and len(beamintensitydata[startorbit])>0:
111  for lumidata in lumilist:
112  bxidx=lumidata[0]
113  lumi=lumidata[1]
114  lumierror=lumidata[2]
115  for beamintensitybx in beamintensitydata[startorbit]:
116  if beamintensitybx[0]==bxidx:
117  if not fillbypos.has_key(bxidx):
118  fillbypos[bxidx]=[]
119  beam1intensity=beamintensitybx[1]
120  beam2intensity=beamintensitybx[2]
121  speclumi=calculateSpecificLumi(lumi,lumierror,beam1intensity,0.0,beam2intensity,0.0)
122  fillbypos[bxidx].append([lstimestamp-referencetime,lumi,lumierror,beam1intensity,beam2intensity,speclumi[0],speclumi[1]])
123  return fillbypos
def getSpecificLumi
Definition: specificLumi.py:63
def calculateSpecificLumi
Definition: specificLumi.py:16
def getFillFromFile
Definition: specificLumi.py:41
def calibratedDetailForRunLimitresult
def beamIntensityForRun
def specificLumi.specificlumiTofile (   fillnum,
  filldata,
  outdir 
)

Definition at line 138 of file specificLumi.py.

References python.multivaluedict.append(), Association.map, and CommonUtil.transposed().

139 def specificlumiTofile(fillnum,filldata,outdir):
140  timedict={}#{lstime:[[lumi,lumierr,speclumi,speclumierr]]}
141  ipnumber=5
142  for cmsbxidx,perbxdata in filldata.items():
143  lhcbucket=0
144  if cmsbxidx!=0:
145  lhcbucket=(cmsbxidx-1)*10+1
146  a=sorted(perbxdata,key=lambda x:x[0])
147  lscounter=0
148  filename=str(fillnum)+'_lumi_'+str(lhcbucket)+'_CMS.txt'
149  for perlsdata in a:
150  if perlsdata[-2]>0 and perlsdata[-1]>0 and perlsdata[1]>0:
151  if lscounter==0:
152  f=open(os.path.join(outdir,filename),'w')
153  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])
154  if not timedict.has_key(int(perlsdata[0])):
155  timedict[int(perlsdata[0])]=[]
156  timedict[int(perlsdata[0])].append([perlsdata[1],perlsdata[2],perlsdata[-2],perlsdata[-1]])
157  lscounter+=1
158  f.close()
159  summaryfilename=str(fillnum)+'_lumi_CMS.txt'
160  f=open(os.path.join(outdir,summaryfilename),'w')
161  lstimes=timedict.keys()
162  lstimes.sort()
163  for lstime in lstimes:
164  allvalues=timedict[lstime]
165  transposedvalues=CommonUtil.transposed(allvalues,0.0)
166  lumivals=transposedvalues[0]
167  lumitot=sum(lumivals)
168  lumierrs=transposedvalues[1]
169  lumierrortot=math.sqrt(sum(map(lambda x:x**2,lumierrs)))
170  specificvals=transposedvalues[2]
171  specificavg=sum(specificvals)/float(len(specificvals))#avg spec lumi
172  specificerrs=transposedvalues[3]
173  specifictoterr=math.sqrt(sum(map(lambda x:x**2,specificerrs)))
174  specificerravg=specifictoterr/float(len(specificvals))
175  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()
dictionary map
Definition: Association.py:160
def transposed
Definition: CommonUtil.py:52
def specificlumiTofile

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.

tuple specificLumi.allfillsFromDB = lumiQueryAPI.allfills(q)

Definition at line 209 of file specificLumi.py.

list specificLumi.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

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.

specificLumi.fillstoprocess = []

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.

tuple specificLumi.parameters = lumiQueryAPI.ParametersObject()

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.

tuple specificLumi.runsperfillFromDB = {}

Definition at line 238 of file specificLumi.py.

dictionary specificLumi.runtimes = {}

Definition at line 243 of file specificLumi.py.