2 from __future__
import print_function
3 import sys,commands,os,calendar
4 from ROOT
import gDirectory,TFile
6 from online_beamspot_reader
import BeamspotMeasurement
7 from online_beamspot_reader
import paragraphs, \
8 start_of_new_beamspot_measurement
11 OUTDIR=
"./perbunchfiles/" 17 def __init__(self, x=None,y=None,z=None,ex=None,ey=None,ez=None,
18 wx=
None,wy=
None,wz=
None,ewx=
None,ewy=
None,ewz=
None,
19 dxdz=
None,dydz=
None,edxdz=
None,edydz=
None):
42 if run
not in runlstime.keys():
43 print(
"Reading lumi time from lumireg localcopy files")
44 filename=
"localcopy/BeamFitResults_Run"+run+
".txt" 45 if not os.path.exists(filename):
46 print(
"WARNING: file ",filename,
" does not exist. Returning null.")
51 in_file = open(filename)
52 pieces = paragraphs(in_file,start_of_new_beamspot_measurement,
True)
57 tmp = BeamspotMeasurement(piece)
58 except Exception
as err:
59 print(
" ERROR Found corrupt " \
60 "beamspot measurement entry!", file=sys.stderr)
61 print(
" !!! %s !!!" %
str(err), file=sys.stderr)
64 runfromfile=tmp.run_number
65 (lumimin,lumimax)=tmp.lumi_range
66 time_begin=tmp.time_begin
68 time_begin=calendar.timegm(time_begin.timetuple())
69 time_end=calendar.timegm(time_end.timetuple())-23
70 lstime[lumimin]=time_begin
71 lstime[lumimax]=time_end
74 lslist=sorted(lstime.keys())
77 lstimesorted.append((ls,lstime[ls]))
78 runlstime[run]=lstimesorted
90 lstimesorted=runlstime[run]
92 for pair
in lstimesorted:
94 if abs(lumisection-lumi)<dcloselumi:
95 dcloselumi=
abs(lumisection-lumi)
99 finaltime=closetime+(lumisection-closelumi)*23
111 DIRES=[
'X0',
'Y0',
'Z0',
'width_X0',
'Width_Y0',
'Sigma_Z0',
'dxdz',
'dydz']
113 rootfile=
"BxAnalysis_Fill_"+FILL+
".root" 114 filein=TFile(rootfile)
118 histolist=gDirectory.GetListOfKeys()
119 iter = histolist.MakeIterator()
122 if key.GetClassName() ==
'TH1F':
124 histoname = td.GetName()
125 if "bx" in histoname:
127 bx=histoname.split(
'_')[-1]
137 histo=gDirectory.Get(histoname)
138 nbin=histo.GetNbinsX()
142 for bin
in range(1,nbin+1):
143 label=histo.GetXaxis().GetBinLabel(bin)
149 cont=histo.GetBinContent(bin)
153 err=histo.GetBinError(bin)
161 print(
"New range:",label,
" found in ",histoname)
164 if label
in thisbx.keys():
165 thismeas=thisbx[label]
168 thismeas=thisbx[label]
216 if __name__ ==
'__main__':
218 print(
"Usage: :",sys.argv[0],
" <fillnr>")
225 for bx
in allmeas.keys():
226 print(
"writing bx=",bx)
229 for meas
in bxmeas.keys():
231 runno=meas.split(
':')[0]
233 lumirange=meas.split(
':')[1]
234 lumimin=lumirange.split(
'-')[0]
235 lumimin=lumimin.strip()
236 lumimax=lumirange.split(
'-')[1]
237 lumimax=lumimax.strip()
242 thismeas=bxmeas[meas]
248 line+=
"%11.7f %11.7f %11.7f %11.7f %11.7f %11.7f " % (-thismeas.x*10,thismeas.ex*10,
249 thismeas.y*10,thismeas.ey*10,
250 -thismeas.z*10,thismeas.ez*10)
251 line+=
"%11.7f %11.7f %11.7f %11.7f %11.7f %11.7f " % (thismeas.wx*10,thismeas.ewx*10,
252 thismeas.wy*10,thismeas.ewy*10,
253 thismeas.wz*10,thismeas.ewz*10)
254 line+=
"%11.7f %11.7f %11.7f %11.7f" % (thismeas.dxdz,thismeas.edxdz,-thismeas.dydz,thismeas.edydz)
258 if (thismeas.x != 0.0
and thismeas.y != 0.0
and thismeas.z != 0.0
and 259 thismeas.wx != 0.0
and thismeas.wy != 0.0
and thismeas.wz != 0.0
and 260 thismeas.dxdz != 0.0
and thismeas.dydz != 0.0 ):
266 os.system(
"mkdir -p "+WORKDIR)
268 filename=WORKDIR+
"/"+FILL+
"_lumireg_"+
str(rfbucket)+
"_CMS.txt" 269 file=open(filename,
'w')
270 sortedtimes=sorted(lines.keys())
271 for meastime
in sortedtimes:
272 file.write(lines[meastime])
def __init__(self, x=None, y=None, z=None, ex=None, ey=None, ez=None, wx=None, wy=None, wz=None, ewx=None, ewy=None, ewz=None, dxdz=None, dydz=None, edxdz=None, edydz=None)
S & print(S &os, JobReport::InputFile const &f)
Abs< T >::type abs(const T &t)
def timeof(run, lumisection)