17 A very simple script to plot the beam spot data stored in condDB 19 usage: %prog -t <tag name> 20 -a, --auth = AUTH: DB authorization path. online(/nfshome0/popcondev/conddb). 21 -b, --batch : Run ROOT in batch mode. 22 -c, --create = CREATE: name for beam spot data file. 23 -d, --data = DATA: input beam spot data file. 24 -D, --destDB = DESTDB: destination DB string. online(oracle://cms_orcon_prod/CMS_COND_31X_BEAMSPOT). 25 -i, --initial = INITIAL: First IOV. Options: run number, or run:lumi, eg. \"133200:21\" 26 -f, --final = FINAL: Last IOV. Options: run number, or run:lumi 27 -o, --output = OUTPUT: filename of ROOT file with plots. 28 -x, --xcrossing = XCROSSING : Bunch crossing number. 30 Francisco Yumiceva (yumiceva@fnal.gov) 36 import os, string, re, sys, math
38 from BeamSpotObj
import BeamSpot
39 from IOVObj
import IOV
40 from CommonMethods
import *
45 print "\nCannot load PYROOT, make sure you have setup ROOT in the path" 46 print "and pyroot library is also defined in the variable PYTHONPATH, try:\n" 47 if (os.getenv(
"PYTHONPATH")):
48 print " setenv PYTHONPATH ${PYTHONPATH}:$ROOTSYS/lib\n" 50 print " setenv PYTHONPATH $ROOTSYS/lib\n" 54 from array
import array
64 run0 =
int(json[i][0])
65 run1 =
int(json[i][1])
66 if run>= run0
and run<=run1:
71 if __name__ ==
'__main__':
77 runsfile = open(
"FillandRuns.txt")
79 if line.find(
'fill:') != -1:
84 FillList[
int(afill)] = [
int(run0),
int(run1)]
94 Float_t widthError[3];\ 96 Float_t slopeError[2];\ 104 fntuple = TFile(
'bntuple.root',
'RECREATE' )
105 tbylumi = TTree(
'bylumi',
'beam spot data lumi by lumi' )
106 tbylumi.Branch(
'fill', AddressOf( bntuple,
'fill'),
'fill/I' )
107 tbylumi.Branch(
'run', AddressOf( bntuple,
'run'),
'run/I' )
108 tbylumi.Branch(
'lumi', AddressOf( bntuple,
'lumi'),
'lumi[2]/I' )
109 tbylumi.Branch(
'position', AddressOf( bntuple,
'position'),
'position[3]/F')
110 tbylumi.Branch(
'posErr', AddressOf( bntuple,
'posError'),
'posError[3]/F')
111 tbylumi.Branch(
'width', AddressOf( bntuple,
'width'),
'width[3]/F')
112 tbylumi.Branch(
'widthErr', AddressOf( bntuple,
'widthError'),
'widthError[3]/F')
113 tbylumi.Branch(
'slope', AddressOf( bntuple,
'slope'),
'slope[2]/F')
114 tbylumi.Branch(
'slopeErr', AddressOf( bntuple,
'slopeError'),
'slopeError[2]/F')
115 tbylumi.Branch(
'time', AddressOf( bntuple,
'time'),
'time[2]/F')
117 tbyIOV = TTree(
'byIOV',
'beam spot data by IOV' )
118 tbyIOV.Branch(
'fill', AddressOf( bntuple,
'fill'),
'fill/I' )
119 tbyIOV.Branch(
'run', AddressOf( bntuple,
'run'),
'run/I' )
120 tbyIOV.Branch(
'lumi', AddressOf( bntuple,
'lumi'),
'lumi[2]/I' )
121 tbyIOV.Branch(
'position', AddressOf( bntuple,
'position'),
'position[3]/F')
122 tbyIOV.Branch(
'posErr', AddressOf( bntuple,
'posError'),
'posError[3]/F')
123 tbyIOV.Branch(
'width', AddressOf( bntuple,
'width'),
'width[3]/F')
124 tbyIOV.Branch(
'widthErr', AddressOf( bntuple,
'widthError'),
'widthError[3]/F')
125 tbyIOV.Branch(
'slope', AddressOf( bntuple,
'slope'),
'slope[2]/F')
126 tbyIOV.Branch(
'slopeErr', AddressOf( bntuple,
'slopeError'),
'slopeError[2]/F')
127 tbyIOV.Branch(
'time', AddressOf( bntuple,
'time'),
'time[2]/F')
129 tbyrun = TTree(
'byrun',
'beam spot data by run' )
130 tbyrun.Branch(
'fill', AddressOf( bntuple,
'fill'),
'fill/I' )
131 tbyrun.Branch(
'run', AddressOf( bntuple,
'run'),
'run/I' )
132 tbyrun.Branch(
'lumi', AddressOf( bntuple,
'lumi'),
'lumi[2]/I' )
133 tbyrun.Branch(
'position', AddressOf( bntuple,
'position'),
'position[3]/F')
134 tbyrun.Branch(
'posErr', AddressOf( bntuple,
'posError'),
'posError[3]/F')
135 tbyrun.Branch(
'width', AddressOf( bntuple,
'width'),
'width[3]/F')
136 tbyrun.Branch(
'widthErr', AddressOf( bntuple,
'widthError'),
'widthError[3]/F')
137 tbyrun.Branch(
'slope', AddressOf( bntuple,
'slope'),
'slope[2]/F')
138 tbyrun.Branch(
'slopeErr', AddressOf( bntuple,
'slopeError'),
'slopeError[2]/F')
139 tbyrun.Branch(
'time', AddressOf( bntuple,
'time'),
'time[2]/F')
145 if not args
and not option:
exit()
148 print " need to provide beam spot data file" 152 ROOT.gROOT.SetBatch()
154 datafilename =
"tmp_beamspot.dat" 156 datafilename = option.create
164 lastRun =
"4999999999:4999999999" 167 firstRun = option.initial
169 lastRun = option.final
176 print " read DB to get list of IOVs for the given tag" 177 acommand =
'cmscond_list_iov -c frontier://PromptProd/CMS_COND_31X_BEAMSPOT -P /afs/cern.ch/cms/DB/conddb -t '+ tag
178 tmpstatus = commands.getstatusoutput( acommand )
179 tmplistiov = tmpstatus[1].
split(
'\n')
185 totlines = len(tmplistiov)
186 for line
in tmplistiov:
188 if line.find(
'since') != -1:
191 if passline
and iline > jline
and iline < totlines-1:
192 linedata = line.split()
195 aIOV.since =
int(linedata[0])
196 aIOV.till =
int(linedata[1])
197 iovlist.append( aIOV )
200 print " total number of IOVs = " +
str(len(iovlist))
208 otherArgs =
" -d " + option.destDB
210 otherArgs = otherArgs +
" -a "+ option.auth
212 print " get beam spot data from DB for IOVs. This can take a few minutes ..." 214 tmpfile = open(datafilename,
'w')
218 tmprunfirst = firstRun
221 tmplumilast = 9999999
222 if IOVbase==
"lumibase":
227 tmprunfirst =
pack(
int(firstRun.split(
":")[0]) ,
int(firstRun.split(
":")[1]) )
228 tmprunlast =
pack(
int(lastRun.split(
":")[0]) ,
int(lasstRun.split(
":")[1]) )
230 if iIOV.since >=
int(tmprunfirst)
and int(tmprunlast) < 0
and iIOV.since <=
int(tmprunfirst):
231 print " IOV: " +
str(iIOV.since)
233 if iIOV.since >=
int(tmprunfirst)
and int(tmprunlast) > 0
and iIOV.till <=
int(tmprunlast):
234 print " IOV: " +
str(iIOV.since) +
" to " +
str(iIOV.till)
236 if iIOV.since >=
int(tmprunlast)
and iIOV.till >= 4294967295:
237 print " IOV: " +
str(iIOV.since) +
" to " +
str(iIOV.till)
240 acommand =
'getBeamSpotDB.py -t '+ tag +
" -r " +
str(iIOV.since) +otherArgs
241 if IOVbase==
"lumibase":
244 acommand =
'getBeamSpotDB.py -t '+ tag +
" -r " +
str(tmprun) +
" -l "+tmplumi +otherArgs
245 status = commands.getstatusoutput( acommand )
246 tmpfile.write(status[1])
248 print " beam spot data collected and stored in file " + datafilename
258 if os.path.isdir(option.data):
259 tmp = commands.getstatusoutput(
"ls "+option.data)
261 datafilename =
"combined_all.txt" 262 output = open(datafilename,
"w")
265 if os.path.isdir(option.data+
"/"+f)
is False:
266 input = open(option.data +
"/"+f)
267 output.writelines(input.readlines())
269 print " data files have been collected in "+datafilename
271 elif os.path.exists(option.data):
272 datafilename = option.data
274 print " input beam spot data DOES NOT exist, file " + option.data
282 print "List of bunch crossings in the file:" 284 listbeam = listmap[option.Xrossing]
293 for ii
in range(0,len(listbeam)):
301 bntuple.run =
int(ibeam.Run)
303 bntuple.lumi =
array(
'i', [
int(ibeam.IOVfirst),
int(ibeam.IOVlast)])
304 line = ibeam.IOVBeginTime
305 begintime = time.mktime( time.strptime(line.split()[0] +
" " + line.split()[1] +
" " + line.split()[2],
"%Y.%m.%d %H:%M:%S %Z") )
306 line = ibeam.IOVEndTime
307 endtime = time.mktime( time.strptime(line.split()[0] +
" " + line.split()[1] +
" " + line.split()[2],
"%Y.%m.%d %H:%M:%S %Z") )
308 bntuple.time =
array(
'f', [begintime, endtime])
315 for ii
in range(0,len(iovlist)):
321 bntuple.width =
array(
'f', [
float(ibeam.beamWidthX),
float(ibeam.beamWidthY),
float(ibeam.sigmaZ)])
322 bntuple.widthError =
array(
'f',[
float(ibeam.beamWidthXerr),
float(ibeam.beamWidthYerr),
float(ibeam.sigmaZerr)])
323 bntuple.run =
int(ibeam.Run)
325 bntuple.lumi =
array(
'i', [
int(ibeam.IOVfirst),
int(ibeam.IOVlast)])
326 line = ibeam.IOVBeginTime
327 begintime = time.mktime( time.strptime(line.split()[0] +
" " + line.split()[1] +
" " + line.split()[2],
"%Y.%m.%d %H:%M:%S %Z") )
328 line = ibeam.IOVEndTime
329 endtime = time.mktime( time.strptime(line.split()[0] +
" " + line.split()[1] +
" " + line.split()[2],
"%Y.%m.%d %H:%M:%S %Z") )
330 bntuple.time =
array(
'f', [begintime, endtime])
334 weightedlist = listbeam
337 for ii
in range(0,len(weightedlist)):
339 ibeam = weightedlist[ii]
343 bntuple.width =
array(
'f', [
float(ibeam.beamWidthX),
float(ibeam.beamWidthY),
float(ibeam.sigmaZ)])
344 bntuple.widthError =
array(
'f',[
float(ibeam.beamWidthXerr),
float(ibeam.beamWidthYerr),
float(ibeam.sigmaZerr)])
345 bntuple.run =
int(ibeam.Run)
347 bntuple.lumi =
array(
'i', [
int(ibeam.IOVfirst),
int(ibeam.IOVlast)])
348 line = ibeam.IOVBeginTime
349 begintime = time.mktime( time.strptime(line.split()[0] +
" " + line.split()[1] +
" " + line.split()[2],
"%Y.%m.%d %H:%M:%S %Z") )
350 line = ibeam.IOVEndTime
351 endtime = time.mktime( time.strptime(line.split()[0] +
" " + line.split()[1] +
" " + line.split()[2],
"%Y.%m.%d %H:%M:%S %Z") )
352 bntuple.time =
array(
'f', [begintime, endtime])
357 os.system(
'rm tmp.txt')
def readBeamSpotFile(fileName, listbeam=[], IOVbase="runbase", firstRun='1', lastRun='4999999999')
def createWeightedPayloads(fileName, listbeam=[], weighted=True)
CREATE FILE FOR PAYLOADS.
def sortAndCleanBeamList(listbeam=[], IOVbase="lumibase")
Sort and clean list of data for consecutive duplicates and bad fits.