ATLAS Offline Software
Functions | Variables
bsPlotVsRun Namespace Reference

Functions

def main ()
 

Variables

string __author__ = 'Anthony Morley'
 
string __version__ = ''
 
string __usage__
 
 varDefs
 
string lumiTag_default = 'OflPrefLumi-RUN3-UPD4-02'
 
string indetbsTag_default = 'IndetBeampos-RUN3-ES1-UPD2-02'
 
 parser = OptionParser(usage=__usage__, version=__version__)
 
 dest
 
 default
 
 help
 
 type
 
 None
 
 action
 
 False
 
 True
 
 options
 
 args
 
int db1 = 1 else 'COOLOFL_INDET/CONDBR2'
 
int db2 = 2 else 'COOLOFL_TRIGGER/CONDBR2'
 
list varColl = []
 
list varPlot = []
 

Function Documentation

◆ main()

def bsPlotVsRun.main ( )

Definition at line 68 of file bsPlotVsRun.py.

68 def main():
69  f1 = "%s::%s" % (db1, options.folderBS)
70  f2 = "%s::%s" % (db2, options.folderLumi)
71 
72  print( "="*100 )
73  print( "Comparing: " )
74  print( " * ", f1, options.tagBS )
75  print( " * ", f2, options.tagLumi )
76  print( "="*100 )
77 
78  requiredForNtuple = ['posX','posY','posZ','sigmaX','sigmaY','sigmaZ']
79  checkNtupleProd = all(item in varColl for item in requiredForNtuple)
80  if not checkNtupleProd:
81  print( 'Ntuple will not be filled missing vars' )
82 
83 
84  #Open up required databases
85  from PyCool import cool
86  from CoolConvUtilities import AtlCoolLib
87  cooldbBS = AtlCoolLib.indirectOpen(db1, True, False)
88  cooldbLumi = AtlCoolLib.indirectOpen(db2, True, False)
89 
90  folderBS = cooldbBS.getFolder(options.folderBS)
91  folderLumi = cooldbLumi.getFolder(options.folderLumi)
92 
93  from InDetBeamSpotExample.COOLUtils import COOLQuery
94  coolQuery = COOLQuery()
95 
96  if options.runMin is not None:
97  iov1 = options.runMin << 32
98  if options.runMax is not None:
99  iov2 = (options.runMax +1) << 32
100  else :
101  iov2 = (options.runMin +1) << 32
102  print( 'Plotting iovs %i to %i ' % (iov1,iov2) )
103  else :
104  print( 'No run selected -- ERROR' )
105  return
106 
107  if (iov2>cool.ValidityKeyMax):
108  iov2=cool.ValidityKeyMax
109 
110  print( "Reading data from database" )
111  itrBS = folderBS.browseObjects(iov1, iov2, cool.ChannelSelection.all(), options.tagBS)
112  print( "...finished getting BS data" )
113 
114  lbDict = dict()
115 
116  startRLB =0x7FFFFFFFFFFFFFFF
117  endRLB =0
118 
119  outfile = ROOT.TFile("BeamspotLumi_%i.root" % (options.runMin),"recreate")
120  ntuple = ROOT.TNtupleD( 'BeamspotLumi', 'BeamSpotLumi', "x:y:z:sigma_x:sigma_y:sigma_z:run:mu:lumi:year:month:day:hour:minute:epoch" )
121 
122 
123  #runs = set()
124  runs = list()
125  while itrBS.goToNext():
126 
127  obj = itrBS.currentRef()
128 
129  since = obj.since()
130 
131  runBegin = since >> 32
132  lumiBegin = since & 0xFFFFFFFF
133 
134  until = obj.until()
135  runUntil = until >> 32
136  lumiUntil = until & 0xFFFFFFFF
137 
138  status = int(obj.payloadValue('status'))
139  if status != 59:
140  continue
141 
142  if runs.count(runBegin) < 1:
143  runs.append(runBegin)
144 
145  if since < startRLB:
146  startRLB = since
147  if until > endRLB:
148  endRLB = until
149 
150 
151  values={}
152  for var in varColl:
153  values[var] = float(obj.payloadValue(var))
154  values[var+'Err'] = float(obj.payloadValue(var+'Err'))
155  values['until'] = until
156  lbDict[since] = values
157 
158  runs.sort()
159  print( 'Runs: ',runs )
160 
161  lumi = array('d')
162  xd = array('d')
163  exd = array('d')
164  bstar = array('d')
165  runsLB = array('d')
166  fillsLB = array('d')
167  ydDict = {}
168  eydDict = {}
169  ydDict2 = {}
170 
171 
172  sqtrt2pi = math.sqrt(2*math.pi)
173 
174  lblb = CoolDataReader('COOLONL_TRIGGER/CONDBR2', '/TRIGGER/LUMI/LBLB')
175  from DQUtils.sugar import RANGEIOV_VAL, RunLumi
176  from DQUtils import IOVSet
177 
178  for run in runs:
179  iov1 = run << 32
180  iov2 = (run + 1) << 32
181 
182  itrLumi = folderLumi.browseObjects(iov1, iov2, cool.ChannelSelection(0), options.tagLumi)
183  print( "...finished getting Lumi data for run %i" % run )
184 
185  lblb.setIOVRangeFromRun(run)
186  lblb.readData()
187  if len(lblb.data) < 1:
188  print( 'No LBLB data found!' )
189  continue
190  # Make time map
191  lblbMap = dict()
192  for obj in lblb.data:
193  lblbMap[obj.since()] = (obj.payload()['StartTime'], obj.payload()['EndTime'])
194 
195 
196  while itrLumi.goToNext():
197  obj = itrLumi.currentRef()
198 
199  since = obj.since()
200  runBegin = since >> 32
201  lumiBegin = since & 0xFFFFFFFF
202 
203  until = obj.until()
204  runUntil = until >> 32
205  lumiUntil = until & 0xFFFFFFFF
206 
207  inGRL = False
208  mu = float(obj.payloadValue('LBAvEvtsPerBX'))
209  instlumi = float(obj.payloadValue('LBAvInstLumi'))
210 
211  if since in lbDict:
212  if lbDict[ since ]['sigmaX'] > 0.1 :
213  continue
214  startTime = lblbMap.get(obj.since(), (0., 0.))[0]
215  endTime = lblbMap.get(lbDict[ since ]['until'], (0., 0.))[0] #[1] end of lumiblock
216  mylumi = (endTime - startTime)/1e9 * instlumi/1e9
217  thisTime = time.gmtime( startTime /1.e9 )
218  year = thisTime[0]
219  month = thisTime[1]
220  day = thisTime[2]
221  hour = thisTime[3]
222  mins = thisTime[4]
223  sec = thisTime[5]
224  lumi.append( mylumi ); # in fb^-1
225  xd.append(mu)
226  exd.append(0)
227 
228  if options.plotSomething:
229  for var in varColl:
230  if not var in ydDict:
231  ydDict[var] = array('d')
232  ydDict2[var] = array('d')
233  eydDict[var] = array('d')
234 
235  ydDict2[var].append( mu/(lbDict[ since ][var] * sqtrt2pi ))
236  ydDict[var].append( lbDict[ since ][var] )
237  eydDict[var].append( lbDict[ since ][var+'Err'] )
238 
239  timeSt = coolQuery.lbTime( int(since >> 32), int(since & 0xFFFFFFFF) )[0]
240  betaStar = coolQuery.getLHCInfo(timeSt).get('BetaStar',0)
241  fillSt = coolQuery.getLHCInfo(timeSt).get('FillNumber',0)
242  bstar.append(betaStar)
243  runsLB.append(run)
244  fillsLB.append(fillSt)
245  #print('Add LB: ',run,' ',lumiBegin,' ',mu,' ',betaStar,' ',fillSt,' ', lbDict[since]['sigmaZ'])
246  if checkNtupleProd and lbDict[ since ]['sigmaZErr'] < 5 :
247  ntuple.Fill( lbDict[ since ][ 'posX'], lbDict[ since ][ 'posY'], lbDict[ since ][ 'posZ'], lbDict[ since ][ 'sigmaX'], lbDict[ since ][ 'sigmaY'], lbDict[ since ][ 'sigmaZ'],runBegin, mu, mylumi, year, month, day,hour, mins, startTime /1.e9 )
248 
249  runStart = startRLB >> 32
250  runEnd = endRLB >> 32
251  fillStart = fillEnd = 0
252  timeStart = timeEnd = 0
253  beamEnergy = 10.0
254  try:
255  timeStart = coolQuery.lbTime( int(startRLB >> 32), int(startRLB & 0xFFFFFFFF) )[0]
256  except:
257  pass
258  try:
259  timeEnd = coolQuery.lbTime( int(endRLB >> 32), int(endRLB & 0xFFFFFFFF)-1 )[1]
260  except:
261  pass
262  try:
263  fillStart = coolQuery.getLHCInfo(timeStart).get('FillNumber',0)
264  except:
265  pass
266  try:
267  fillEnd = coolQuery.getLHCInfo(timeEnd).get('FillNumber',0)
268  except:
269  pass
270  try:
271  beamEnergy = coolQuery.getLHCInfo(timeStart).get('BeamEnergyGeV',0)
272  beamEnergy *= 2e-3
273  except:
274  pass
275 
276  ntuple.Write()
277 
278  if not options.plotSomething:
279  return
280 
281  from InDetBeamSpotExample import ROOTUtils
283  canvas = ROOT.TCanvas('BeamSpotComparison', 'BeamSpotComparison', 1600, 1200)
284 
285  canvas.cd()
286  ROOT.gPad.SetTopMargin(0.05)
287  ROOT.gPad.SetLeftMargin(0.15)
288  ROOT.gPad.SetRightMargin(0.05)
289 
290  if not options.plotGraph:
291  ROOT.gPad.SetRightMargin(0.15)
292 
293 
294  #Profile histogram for beam size v.s. run
295 
296  #Find non-empty fills with beta* = 30
297  fillsFilled = list()
298  for runLB, betaStar in zip(fillsLB,bstar):
299  if betaStar < 31. :
300  try:
301  pos = fillsFilled.index(runLB)
302  except:
303  fillsFilled.append(int(runLB))
304  fillsFilled.sort()
305  print("Fills with beta* = 30 cm",fillsFilled)
306  length = len(fillsFilled)
307  print('Number of fills with beta* = 30 cm: ',length)
308 
309  #Find non-empty fills with beta* = 120
310  fillsFilled120 = list()
311  for runLB, betaStar in zip(fillsLB,bstar):
312  if betaStar > 119. and betaStar < 121 :
313  try:
314  pos = fillsFilled120.index(runLB)
315  except:
316  fillsFilled120.append(int(runLB))
317  fillsFilled120.sort()
318  print("Fills with beta* = 120 cm",fillsFilled120)
319  length120 = len(fillsFilled120)
320  print('Number of fills with beta* = 120 cm: ',length120)
321 
322  #Plot each variable
323  for var in varPlot:
324  if var not in ydDict:
325  print( 'Missing yd: ',var )
326  if var not in eydDict:
327  print( 'Missing eyd: ',var )
328  continue
329 
330  gr = ROOT.TGraphErrors(len(xd), xd, ydDict[var], exd, eydDict[var])
331  xmin = min(xd)
332  xmax = max(xd)
333  ymin = min(ydDict[var])
334  ymax = max(ydDict[var])
335 
336  h = (ymax-ymin)
337  ymin -= 0.25*h
338  ymaxSmall = ymax + 0.25*h
339  ymax += 0.75*h
340 
341  ymin2 = min(ydDict2[var])
342  ymax2 = max(ydDict2[var])
343 
344  h = (ymax2-ymin2)
345  ymin2 -= 0.25*h
346  ymax2 += 0.75*h
347 
348  h = (xmax-xmin)
349  xmin -= 0.05*h
350  xmax += 0.05*h
351 
352  #This histogram is made just to make it easier to manipulate the margins
353  histo = ROOT.TH2D('hd'+var, 'hd'+var, 100, xmin, xmax, 100, ymin, ymax)
354  histo.GetYaxis().SetTitle(varDef(var,'atit',var))
355  histo.GetXaxis().SetTitle('Average interactions per bunch crossing')
356  histo.GetZaxis().SetTitle('Entries')
357 
358  histo2 = ROOT.TH2D('hd2'+var, 'hd2'+var, 100, xmin, xmax, 100, ymin2, ymax2)
359  histo2.GetYaxis().SetTitle( "<Interaction density> @ z=0 [interactions/mm]")
360  histo2.GetXaxis().SetTitle('Average interactions per bunch crossing')
361  histo2.GetZaxis().SetTitle('Entries')
362 
363  histo2W = ROOT.TH2D('hd3'+var, 'hd3'+var, 100, xmin, xmax, 100, ymin2, ymax2)
364  histo2W.GetYaxis().SetTitle( "<Interaction density> @ z=0 [interactions/mm]")
365  histo2W.GetXaxis().SetTitle('Average interactions per bunch crossing')
366  histo2W.GetZaxis().SetTitle('Integrated Luminosity (fb^{-1}/bin)')
367 
368  histoW = ROOT.TH2D('hdW'+var, 'hdW'+var, 100, xmin, xmax, 100, ymin, ymax)
369  histoW.GetYaxis().SetTitle(varDef(var,'atit',var))
370  histoW.GetXaxis().SetTitle('Average interactions per bunch crossing')
371  histoW.GetZaxis().SetTitle('Integrated Luminosity (fb^{-1}/bin)')
372 
373  histoW1D = ROOT.TH1D('hd1D'+var, 'hd1D'+var, 100, ymin, ymaxSmall)
374  histoW1D.GetXaxis().SetTitle(varDef(var,'atit',var))
375  histoW1D.GetYaxis().SetTitle('Integrated Luminosity (fb^{-1}/bin)')
376 
377  yminP = ymin
378  ymaxP = ymax
379  yminB = ymin
380  ymaxB = ymax
381  if var == 'sigmaZ':
382  yminP = 25.
383  ymaxP = 50.
384  yminB = 25.
385  ymaxB = 50.
386  elif var == 'sigmaX':
387  yminP = 0.000
388  ymaxP = 0.020
389  yminB = 0.000
390  ymaxB = 0.020
391  elif var == 'sigmaY':
392  yminP = 0.000
393  ymaxP = 0.020
394  yminB = 0.000
395  ymaxB = 0.020
396  elif var == 'posZ':
397  yminP = -20.00
398  ymaxP = 30.00
399  elif var == 'posX':
400  yminP = -0.80
401  ymaxP = -0.20
402  elif var == 'posY':
403  yminP = -0.60
404  ymaxP = 0.00
405 
406  #histoP = ROOT.TProfile('hdP'+var, 'hdP'+var, length,runsDouble)
407  histoP = ROOT.TProfile('hdP'+var, 'hdP'+var, length,0.,length)
408  histoP.GetYaxis().SetTitle(varDef(var,'atit',var))
409  histoP.GetXaxis().SetTitle('Fill Number')
410  histoP.SetMinimum(yminP)
411  histoP.SetMaximum(ymaxP)
412 
413  histoB = ROOT.TH2D('hdB'+var, 'hdB'+var, 100, 20., 150., 100, yminB, ymaxB)
414  histoB.GetYaxis().SetTitle(varDef(var,'atit',var))
415  histoB.GetXaxis().SetTitle('#beta*')
416  histoB.GetZaxis().SetTitle('Entries')
417 
418  #set names of the bins as run numbers
419  i = 0
420  irate = int(length/10)+1
421  for run in fillsFilled:
422  i += 1
423  if int((i-1)/irate)*irate == i-1:
424  histoP.GetXaxis().SetBinLabel(i,str(run))
425  else:
426  histoP.GetXaxis().SetBinLabel(i,'')
427 
428  i = 0
429  irate = int(length120/10)+1
430  histo.Draw();
431  if options.plotGraph:
432  gr.Draw("p");
433  else:
434  for mu, x, l in zip(xd, ydDict[var], lumi):
435  histo.Fill( mu, x )
436  histoW.Fill( mu, x , l)
437  histoW1D.Fill( x, l)
438  for mu, x, l in zip(xd, ydDict2[var], lumi):
439  histo2.Fill( mu, x )
440  histo2W.Fill( mu,x, l)
441  for runLB, betaStar, x in zip(fillsLB,bstar,ydDict[var]):
442  #exclude runs from Period G
443  if runLB < 435229 or runLB > 435777 :
444  histoB.Fill( betaStar, x )
445  if betaStar < 31. :
446  pos = fillsFilled.index(runLB)
447  histoP.Fill(pos+0.5,x)
448  if betaStar > 119. and betaStar < 121 :
449  pos = fillsFilled120.index(runLB)
450 # histoP120.Fill(pos+0.5,x)
451 
452  histo.Draw("colz")
453 
454  histo.Write()
455  histoW.Write()
456  histo2.Write()
457  histo2W.Write()
458  histoW1D.Write()
459  histoP.Write()
460 # histoP120.Write()
461  histoB.Write()
462 
463  # Add some information to the graph
464  ROOTUtils.atlasLabel( 0.53,0.87,False,offset=0.12,isForApproval=False,customstring="Internal",energy='%2.1f' % beamEnergy,size=0.055)
465  ROOTUtils.drawText(0.18,0.87,0.055, varDef(var,'title',var) )
466 
467  comments = []
468 
469  if runStart==runEnd:
470  comments.append('Run %i' % runStart)
471  else:
472  comments.append('Runs %i - %i' % (runStart,runEnd))
473 
474  if fillStart==fillEnd:
475  comments.append('Fill %i' % fillStart)
476  else:
477  comments.append('Fills %i - %i' % (fillStart,fillEnd))
478 
479  t1 = time.strftime('%d %b %Y',time.localtime(timeStart))
480  t2 = time.strftime('%d %b %Y',time.localtime(timeEnd))
481  if t1==t2:
482  comments.append(t1)
483  else:
484  comments.append('%s - %s' % (t1,t2))
485 
486  ROOTUtils.drawText(0.18,0.81,0.05,';'.join(comments),font=42)
487 
488  canvas.Print( "Run_%d_%sVsMu.png" % ( options.runMin,var ) )
489  #canvas.Print( "Run_%d_%sVsMu.pdf" % ( options.runMin,var ) )
490  if not options.plotGraph:
491  canvas.SetLogz(False)
492 
493  canvas.SetLogy(False)
494 
495  histoP.Draw("colz");
496  ROOTUtils.atlasLabel( 0.53,0.87,False,offset=0.12,isForApproval=False,customstring="Internal",energy='%2.1f' % beamEnergy,size=0.055)
497  ROOTUtils.drawText(0.18,0.87,0.055, varDef(var,'title',var) )
498  ROOTUtils.drawText(0.18,0.81,0.055, "#beta* = 30 cm" )
499  ROOTUtils.drawText(0.18,0.75,0.05,';'.join(comments),font=42)
500  canvas.Print( "Run_%d_%sVsFill.png" % ( options.runMin,var ) )
501  canvas.SetLogy(False)
502 
503  histoB.Draw("colz");
504  ROOTUtils.atlasLabel( 0.53,0.87,False,offset=0.12,isForApproval=False,customstring="Internal",energy='%2.1f' % beamEnergy,size=0.055)
505  ROOTUtils.drawText(0.18,0.87,0.055, varDef(var,'title',var) )
506  ROOTUtils.drawText(0.18,0.81,0.05,';'.join(comments),font=42)
507  canvas.Print( "Run_%d_%sVsBetaStar.png" % ( options.runMin,var ) )
508  canvas.SetLogy(False)
509 

Variable Documentation

◆ __author__

string bsPlotVsRun.__author__ = 'Anthony Morley'
private

Definition at line 10 of file bsPlotVsRun.py.

◆ __usage__

string bsPlotVsRun.__usage__
private
Initial value:
1 = '''%prog [options] [database1] [database2]
2 
3 Database can be either connection string or db file:
4 
5  e.g COOLOFL_INDET/CONDBR2 (default)
6  beamspot.db/BEAMSPOT
7 
8 Example:
9 
10  PlotVsMu --rl 341123 --ru 341123
11 
12 '''

Definition at line 12 of file bsPlotVsRun.py.

◆ __version__

string bsPlotVsRun.__version__ = ''
private

Definition at line 11 of file bsPlotVsRun.py.

◆ action

bsPlotVsRun.action

Definition at line 50 of file bsPlotVsRun.py.

◆ args

bsPlotVsRun.args

Definition at line 52 of file bsPlotVsRun.py.

◆ db1

int bsPlotVsRun.db1 = 1 else 'COOLOFL_INDET/CONDBR2'

Definition at line 54 of file bsPlotVsRun.py.

◆ db2

int bsPlotVsRun.db2 = 2 else 'COOLOFL_TRIGGER/CONDBR2'

Definition at line 55 of file bsPlotVsRun.py.

◆ default

bsPlotVsRun.default

Definition at line 43 of file bsPlotVsRun.py.

◆ dest

bsPlotVsRun.dest

Definition at line 43 of file bsPlotVsRun.py.

◆ False

bsPlotVsRun.False

Definition at line 50 of file bsPlotVsRun.py.

◆ help

bsPlotVsRun.help

Definition at line 43 of file bsPlotVsRun.py.

◆ indetbsTag_default

bsPlotVsRun.indetbsTag_default = 'IndetBeampos-RUN3-ES1-UPD2-02'

Definition at line 39 of file bsPlotVsRun.py.

◆ lumiTag_default

bsPlotVsRun.lumiTag_default = 'OflPrefLumi-RUN3-UPD4-02'

Definition at line 38 of file bsPlotVsRun.py.

◆ None

bsPlotVsRun.None

Definition at line 47 of file bsPlotVsRun.py.

◆ options

bsPlotVsRun.options

Definition at line 52 of file bsPlotVsRun.py.

◆ parser

bsPlotVsRun.parser = OptionParser(usage=__usage__, version=__version__)

Definition at line 42 of file bsPlotVsRun.py.

◆ True

bsPlotVsRun.True

Definition at line 51 of file bsPlotVsRun.py.

◆ type

bsPlotVsRun.type

Definition at line 47 of file bsPlotVsRun.py.

◆ varColl

list bsPlotVsRun.varColl = []

Definition at line 58 of file bsPlotVsRun.py.

◆ varDefs

bsPlotVsRun.varDefs

Definition at line 31 of file bsPlotVsRun.py.

◆ varPlot

list bsPlotVsRun.varPlot = []

Definition at line 59 of file bsPlotVsRun.py.

ROOTUtils.drawText
def drawText(x=0.74, y=0.87, dy=0.06, text='', font=62, color=1, align=11, linesep=';')
Definition: roofit/ROOTUtils.py:243
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
plotBeamSpotCompare.varDef
dictionary varDef
Definition: plotBeamSpotCompare.py:25
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
ROOTUtils.setStyle
def setStyle(style=None)
Definition: roofit/ROOTUtils.py:413
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
ROOTUtils.atlasLabel
def atlasLabel(x, y, isPreliminary=False, color=1, offset=0.115, isForApproval=False, energy=8, customstring="", size=0.05)
Definition: roofit/ROOTUtils.py:303
bsPlotVsRun.main
def main()
Definition: bsPlotVsRun.py:68
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
array
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:67
COOLUtils
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
str
Definition: BTagTrackIpAccessor.cxx:11
readCCLHist.float
float
Definition: readCCLHist.py:83