2 import sys,commands,os,calendar
3 from ROOT
import gDirectory,TFile
5 from online_beamspot_reader
import BeamspotMeasurement
6 from online_beamspot_reader
import paragraphs, \
7 start_of_new_beamspot_measurement
10 OUTDIR=
"./perbunchfiles/"
16 def __init__(self, x=None,y=None,z=None,ex=None,ey=None,ez=None,
17 wx=
None,wy=
None,wz=
None,ewx=
None,ewy=
None,ewz=
None,
18 dxdz=
None,dydz=
None,edxdz=
None,edydz=
None):
41 if run
not in runlstime.keys():
42 print "Reading lumi time from lumireg localcopy files"
43 filename=
"localcopy/BeamFitResults_Run"+run+
".txt"
44 if not os.path.exists(filename):
45 print "WARNING: file ",filename,
" does not exist. Returning null."
50 in_file = open(filename)
51 pieces = paragraphs(in_file,start_of_new_beamspot_measurement,
True)
56 tmp = BeamspotMeasurement(piece)
57 except Exception, err:
58 print >> sys.stderr, \
59 " ERROR Found corrupt " \
60 "beamspot measurement entry!"
61 print >> sys.stderr, \
62 " !!! %s !!!" % str(err)
65 runfromfile=tmp.run_number
66 (lumimin,lumimax)=tmp.lumi_range
67 time_begin=tmp.time_begin
69 time_begin=calendar.timegm(time_begin.timetuple())
70 time_end=calendar.timegm(time_end.timetuple())-23
71 lstime[lumimin]=time_begin
72 lstime[lumimax]=time_end
79 lstimesorted.append((ls,lstime[ls]))
80 runlstime[run]=lstimesorted
92 lstimesorted=runlstime[run]
94 for pair
in lstimesorted:
96 if abs(lumisection-lumi)<dcloselumi:
97 dcloselumi=
abs(lumisection-lumi)
101 finaltime=closetime+(lumisection-closelumi)*23
113 DIRES=[
'X0',
'Y0',
'Z0',
'width_X0',
'Width_Y0',
'Sigma_Z0',
'dxdz',
'dydz']
115 rootfile=
"BxAnalysis_Fill_"+FILL+
".root"
116 filein=TFile(rootfile)
120 histolist=gDirectory.GetListOfKeys()
121 iter = histolist.MakeIterator()
124 if key.GetClassName() ==
'TH1F':
126 histoname = td.GetName()
127 if "bx" in histoname:
129 bx=histoname.split(
'_')[-1]
139 histo=gDirectory.Get(histoname)
140 nbin=histo.GetNbinsX()
144 for bin
in range(1,nbin+1):
145 label=histo.GetXaxis().GetBinLabel(bin)
151 cont=histo.GetBinContent(bin)
155 err=histo.GetBinError(bin)
163 print "New range:",label,
" found in ",histoname
166 if label
in thisbx.keys():
167 thismeas=thisbx[label]
170 thismeas=thisbx[label]
218 if __name__ ==
'__main__':
220 print "Usage: :",sys.argv[0],
" <fillnr>"
227 for bx
in allmeas.keys():
228 print "writing bx=",bx
231 for meas
in bxmeas.keys():
233 runno=meas.split(
':')[0]
235 lumirange=meas.split(
':')[1]
236 lumimin=lumirange.split(
'-')[0]
237 lumimin=lumimin.strip()
238 lumimax=lumirange.split(
'-')[1]
239 lumimax=lumimax.strip()
240 lumimid=int((int(lumimin)+int(lumimax))/2.)
242 print runno,str(lumimid),meastime
244 thismeas=bxmeas[meas]
248 line=str(meastime)+
" "
250 line+=
"%11.7f %11.7f %11.7f %11.7f %11.7f %11.7f " % (-thismeas.x*10,thismeas.ex*10,
251 thismeas.y*10,thismeas.ey*10,
252 -thismeas.z*10,thismeas.ez*10)
253 line+=
"%11.7f %11.7f %11.7f %11.7f %11.7f %11.7f " % (thismeas.wx*10,thismeas.ewx*10,
254 thismeas.wy*10,thismeas.ewy*10,
255 thismeas.wz*10,thismeas.ewz*10)
256 line+=
"%11.7f %11.7f %11.7f %11.7f" % (thismeas.dxdz,thismeas.edxdz,-thismeas.dydz,thismeas.edydz)
260 if (thismeas.x != 0.0
and thismeas.y != 0.0
and thismeas.z != 0.0
and
261 thismeas.wx != 0.0
and thismeas.wy != 0.0
and thismeas.wz != 0.0
and
262 thismeas.dxdz != 0.0
and thismeas.dydz != 0.0 ):
268 os.system(
"mkdir -p "+WORKDIR)
269 rfbucket=(int(bx)-1)*10+1
270 filename=WORKDIR+
"/"+FILL+
"_lumireg_"+str(rfbucket)+
"_CMS.txt"
271 file=open(filename,
'w')
272 sortedtimes=lines.keys()
274 for meastime
in sortedtimes:
275 file.write(lines[meastime])