2 from __future__
import print_function
3 from builtins
import range
5 from ROOT
import gDirectory,TFile
7 from online_beamspot_reader
import BeamspotMeasurement
8 from online_beamspot_reader
import paragraphs, \
9 start_of_new_beamspot_measurement
12 OUTDIR=
"./perbunchfiles/"
18 def __init__(self, x=None,y=None,z=None,ex=None,ey=None,ez=None,
19 wx=
None,wy=
None,wz=
None,ewx=
None,ewy=
None,ewz=
None,
20 dxdz=
None,dydz=
None,edxdz=
None,edydz=
None):
43 if run
not in runlstime.keys():
44 print(
"Reading lumi time from lumireg localcopy files")
45 filename=
"localcopy/BeamFitResults_Run"+run+
".txt"
46 if not os.path.exists(filename):
47 print(
"WARNING: file ",filename,
" does not exist. Returning null.")
52 in_file = open(filename)
53 pieces = paragraphs(in_file,start_of_new_beamspot_measurement,
True)
58 tmp = BeamspotMeasurement(piece)
59 except Exception
as err:
60 print(
" ERROR Found corrupt " \
61 "beamspot measurement entry!", file=sys.stderr)
62 print(
" !!! %s !!!" %
str(err), file=sys.stderr)
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
75 lslist=sorted(lstime.keys())
78 lstimesorted.append((ls,lstime[ls]))
79 runlstime[run]=lstimesorted
91 lstimesorted=runlstime[run]
93 for pair
in lstimesorted:
95 if abs(lumisection-lumi)<dcloselumi:
96 dcloselumi=
abs(lumisection-lumi)
100 finaltime=closetime+(lumisection-closelumi)*23
112 DIRES=[
'X0',
'Y0',
'Z0',
'width_X0',
'Width_Y0',
'Sigma_Z0',
'dxdz',
'dydz']
114 rootfile=
"BxAnalysis_Fill_"+FILL+
".root"
115 filein=TFile(rootfile)
119 histolist=gDirectory.GetListOfKeys()
120 iter = histolist.MakeIterator()
123 if key.GetClassName() ==
'TH1F':
125 histoname = td.GetName()
126 if "bx" in histoname:
128 bx=histoname.split(
'_')[-1]
138 histo=gDirectory.Get(histoname)
139 nbin=histo.GetNbinsX()
143 for bin
in range(1,nbin+1):
144 label=histo.GetXaxis().GetBinLabel(bin)
150 cont=histo.GetBinContent(bin)
154 err=histo.GetBinError(bin)
162 print(
"New range:",label,
" found in ",histoname)
165 if label
in thisbx.keys():
166 thismeas=thisbx[label]
169 thismeas=thisbx[label]
217 if __name__ ==
'__main__':
219 print(
"Usage: :",sys.argv[0],
" <fillnr>")
226 for bx
in allmeas.keys():
227 print(
"writing bx=",bx)
230 for meas
in bxmeas.keys():
232 runno=meas.split(
':')[0]
234 lumirange=meas.split(
':')[1]
235 lumimin=lumirange.split(
'-')[0]
236 lumimin=lumimin.strip()
237 lumimax=lumirange.split(
'-')[1]
238 lumimax=lumimax.strip()
239 lumimid=int((int(lumimin)+int(lumimax))/2.)
243 thismeas=bxmeas[meas]
249 line+=
"%11.7f %11.7f %11.7f %11.7f %11.7f %11.7f " % (-thismeas.x*10,thismeas.ex*10,
250 thismeas.y*10,thismeas.ey*10,
251 -thismeas.z*10,thismeas.ez*10)
252 line+=
"%11.7f %11.7f %11.7f %11.7f %11.7f %11.7f " % (thismeas.wx*10,thismeas.ewx*10,
253 thismeas.wy*10,thismeas.ewy*10,
254 thismeas.wz*10,thismeas.ewz*10)
255 line+=
"%11.7f %11.7f %11.7f %11.7f" % (thismeas.dxdz,thismeas.edxdz,-thismeas.dydz,thismeas.edydz)
259 if (thismeas.x != 0.0
and thismeas.y != 0.0
and thismeas.z != 0.0
and
260 thismeas.wx != 0.0
and thismeas.wy != 0.0
and thismeas.wz != 0.0
and
261 thismeas.dxdz != 0.0
and thismeas.dydz != 0.0 ):
267 os.system(
"mkdir -p "+WORKDIR)
268 rfbucket=(int(bx)-1)*10+1
269 filename=WORKDIR+
"/"+FILL+
"_lumireg_"+
str(rfbucket)+
"_CMS.txt"
270 file=open(filename,
'w')
271 sortedtimes=sorted(lines.keys())
272 for meastime
in sortedtimes:
273 file.write(lines[meastime])
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Abs< T >::type abs(const T &t)