ATLAS Offline Software
plotBeamSpotCompare.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 
5 from __future__ import print_function
6 
7 """
8 Compare two sets of beam spots for the same run; can read results from
9 ntuples,CSV, or from COOL; use BeamSpotData class
10 """
11 __author__ = 'Martina Hurwitz'
12 __version__ = '$Id $'
13 __usage__ = '%prog [options] file1/tag1 file2/tag2'
14 
15 import sys, os
16 import re
17 import time
18 from math import *
19 from array import array
20 
22 from InDetBeamSpotExample.Utils import getRunFromName
23 
24 # Define plot properties for different ntuple variables
25 varDef = {
26  'nEvents': {'xtit': 'Luminosity Block Number', 'ytit': '#Delta(N_{vert})', 'ytit2': 'Number of vertices', 'title': 'Difference in number of vertices', 'bigchange': 300, 'cannr':2},
27  'k': {'xtit': 'Luminosity Block Number', 'ytit': '#Delta(k)', 'ytit2': 'Error scale factor k', 'title': 'Difference in error scale factor k', 'bigchange': 0.2, 'cannr':3},
28  'posX': {'xtit': 'Luminosity Block Number', 'ytit': '#Delta(x) [mm]', 'ytit2': 'X position [mm]', 'title': 'Difference in beamspot x', 'bigchange': 10, 'cannr':7},
29  'posY': {'xtit': 'Luminosity Block Number', 'ytit': '#Delta(y) [mm]', 'ytit2': 'Y position [mm]', 'title': 'Difference in beamspot y', 'bigchange': 10, 'cannr':8},
30  'posZ': {'xtit': 'Luminosity Block Number', 'ytit': '#Delta(z) [mm]', 'ytit2': 'Z position [mm]', 'title': 'Difference in beamspot z', 'bigchange': 3, 'cannr':9},
31  'sigmaX': {'xtit': 'Luminosity Block Number', 'ytit': '#Delta(#sigma_{x}) [mm]', 'ytit2': '#sigma_{x} [mm]', 'title': 'Difference in beamspot #sigma_{x}', 'bigchange': 3,'cannr':13},
32  'sigmaY': {'xtit': 'Luminosity Block Number', 'ytit': '#Delta(#sigma_{y}) [mm]', 'ytit2': '#sigma_{y} [mm]', 'title': 'Difference in beamspot #sigma_{y}', 'bigchange': 3,'cannr':14},
33  'sigmaZ': {'xtit': 'Luminosity Block Number', 'ytit': '#Delta(#sigma_{z}) [mm]', 'ytit2': '#sigma_{z} [mm]', 'title': 'Difference in beamspot #sigma_{z}', 'bigchange': 2, 'cannr':15},
34  'tiltX': {'xtit': 'Luminosity Block Number', 'ytit': '#Delta(Tilt_{x-z}) [rad]', 'ytit2': 'Tilt in x-z [rad]', 'title': 'Difference in beamspot tilt in x-z', 'bigchange': 0.15,'cannr':19},
35  'tiltY': {'xtit': 'Luminosity Block Number', 'ytit': '#Delta(Tilt_{y-z}) [rad]', 'ytit2': 'Tilt in y-z [rad]', 'title': 'Difference in beamspot tilt in y-z', 'bigchange': 0.15,'cannr':20},
36  'rhoXY': {'xtit': 'Luminosity Block Number', 'ytit': '#Delta(#rho_{xy})', 'ytit2': '#rho_{xy}', 'title': 'Difference in #rho', 'bigchange': 0.15,'cannr':21}
37  }
38 def getVarDef(what,property,default=''):
39  try:
40  return varDef[what][property]
41  except:
42  return default
43  global __usage__
44  __usage__ += '\n\nPossible variables to plot are:\n'
45  __usage__ += ' '.join(sorted(ntDef.keys()))
46 
47 # Argument parsing
48 from optparse import OptionParser
49 parser = OptionParser(usage=__usage__, version=__version__)
50 parser.add_option('-b', '--batch', dest='batch', action='store_true', default=False, help='run in batch mode')
51 parser.add_option('-o', '--output', dest='output', default='.gif', help='comma-separated list of output files or formats (default: .gif)')
52 parser.add_option('-r', '--runNumber', dest='runNumber', default=0, help='run number')
53 parser.add_option('', '--rl', dest='runMin', type='int', default=0, help='minimum run number (inclusive)')
54 parser.add_option('', '--ru', dest='runMax', type='int', default=0, help='maximum run number (inclusive)')
55 parser.add_option('-p', '--plot', dest='plot', default='', help='quantity to plot, only make one plot')
56 parser.add_option('', '--finder1', dest='finder1', action='store_true', default=False, help='First ntuple is BeamSpotFinder ntuple')
57 parser.add_option('', '--finder2', dest='finder2', action='store_true', default=False, help='Second ntuple is BeamSpotFinder ntuple')
58 parser.add_option('', '--online1', dest='online1', action='store_true', default=False, help='First COOL tag is for online folder')
59 parser.add_option('', '--online2', dest='online2', action='store_true', default=False, help='Second COOL tag is for online folder')
60 parser.add_option('', '--config', dest='config', default='', help='Use known configuration (OnlineOffline or Reproc)')
61 parser.add_option('', '--plotHistos', dest='plotHistos', action='store_true', default=False, help='Plot histograms instead of graphs')
62 parser.add_option('', '--label1', dest='label1', default='', help='Description of first argument')
63 parser.add_option('', '--label2', dest='label2', default='', help='Description of second argument')
64 parser.add_option('', '--lbmin', dest='lbmin', type='int', default=0, help='Miminum LB used in comparison')
65 parser.add_option('', '--lbmax', dest='lbmax', type='int', default=0, help='Maximum LB used in comparison')
66 parser.add_option('', '--smallChanges', dest='smallChanges', action='store_true', default=False, help='Print out changes larger than 0.1 percent')
67 parser.add_option('', '--RooFit', dest='RooFit',action='store_true',default=False,help='Compare Run 1 Fit Method with RooFit result in same file')
68 parser.add_option('', '--status', dest='status',action='store',default=59,help='default fit status to use for first file')
69 parser.add_option('', '--multicanv', dest='multicanv', action='store_true',default=False,help="create multiple canvases")
70 parser.add_option('', '--outtag', dest='outtag', action='store', default='', help="string to prepend to output file names.")
71 parser.add_option('', '--html', dest='html', action='store_true', default=False, help="create an HTML page to see plots more easily. Only really useful with multicanv.")
72 parser.add_option('', '--htmltag', dest='htmltag', action='store', default='', help="tag to distinguish different HTML pages")
73 (options,args) = parser.parse_args()
74 
75 tag1=''
76 tag2=''
77 
78 if options.RooFit:
79  if len(args) != 1:
80  parser.error('wrong number of command line arguments')
81  tag1=args[0]
82  tag2=args[0]
83 
84 else:
85  if len(args) < 2:
86  parser.error('wrong number of command line arguments')
87  tag1=args[0]
88  tag2=args[1]
89 
90 if options.runNumber :
91  runNumber = int(options.runNumber)
92  print ('Doing comparison for run %i' % runNumber)
93 elif options.config=='OnlineOffline':
94  runNumber = getRunFromName(tag1,'0',True)
95  print ('Doing comparison for run %i' % runNumber)
96 elif options.config=='Reproc':
97  runNumber = getRunFromName(tag2,'0',True)
98  print ('Doing comparison for run %i' % runNumber)
99 else :
100  runNumber = 0
101  #print ('Doing comparison for all runs in %s' % tag1)
102 
103 # Precision
104 ndp=5
105 ndptilt=8
106 
107 # Setup ROOT
108 if options.batch:
109  ROOT.gROOT.SetBatch(1)
110 import ROOT
111 from InDetBeamSpotExample import ROOTUtils
113 
114 # Flag for DB info
115 fromDB = False
116 fromCSV = False
117 
118 # Determine type of input
119 if tag1.find('.root') > -1:
120  # It's a root file
121  if options.finder1:
122  BSData1 = BeamSpotFinderNt(tag1)
123  else:
124  BSData1 = BeamSpotNt(tag1)
125 elif tag1.find('.csv') > -1:
126  # comma-separated format
127  BSData1 = BeamSpotCSV(tag1)
128  fromCSV = True
129 else :
130  # It's a COOL tag
131  if options.online1:
132  BSData1 = BeamSpotCOOL(tag1, 'COOLONL_INDET/CONDBR2', '/Indet/Onl/Beampos') #, "sqlite://;schema=beamspot.db;dbname=BEAMSPOT")
133  else:
134  BSData1 = BeamSpotCOOL(tag1)
135  fromDB = True
136 
137 if tag2.find('.root') > -1:
138  # root file
139  if options.finder2:
140  BSData2 = BeamSpotFinderNt(tag2)
141  else:
142  BSData2 = BeamSpotNt(tag2)
143 elif tag2.find('.csv') > -1:
144  # CSV file
145  BSData2 = BeamSpotCSV(tag2)
146  fromCSV = True
147 else :
148  # COOL
149  if options.online2:
150  BSData2 = BeamSpotCOOL(tag2, 'COOLONL_INDET/CONDBR2', '/Indet/Onl/Beampos')
151  else:
152  BSData2 = BeamSpotCOOL(tag2)
153  fromDB = True
154 
155 # What variables to look at
156 varColl = []
157 if options.plot:
158  doOnePlot = True
159  varColl.append(options.plot)
160 else:
161  doOnePlot = False
162  varColl = ['posX', 'posY', 'posZ', 'sigmaX', 'sigmaY', 'sigmaZ', 'tiltX', 'tiltY']
163  if not fromCSV:
164  varColl.append('rhoXY')
165  if not fromDB and not fromCSV:
166  varColl = ['nEvents', 'k', 'posX', 'posY', 'posZ', 'sigmaX', 'sigmaY', 'sigmaZ', 'tiltX', 'tiltY', 'rhoXY']
167 
168 # Now run over them; take diff and make TGraphs at same time
169 
170 if runNumber != 0 :
171  BSData1.runMin = runNumber
172  BSData1.runMax = runNumber
173  BSData2.runMin = runNumber
174  BSData2.runMax = runNumber
175 
176 if options.runMin != 0 :
177  BSData1.runMin = options.runMin
178  BSData2.runMin = options.runMin
179 
180 if options.runMax != 0 :
181  BSData1.runMax = options.runMax
182  BSData2.runMax = options.runMax
183 
184 if options.lbmin != 0:
185  BSData1.lbmin = options.lbmin
186  BSData2.lbmin = options.lbmin
187 
188 if options.lbmax != 0:
189  BSData1.lbmax = options.lbmax
190  BSData2.lbmax = options.lbmax
191 
192 
193 BS2_status = options.status
194 if options.RooFit:
195  if options.status==107:
196  BS2_status=59
197  else:
198  BS2_status=107
199 if not options.config=='OnlineOffline':
200  BSData2.statusList=[BS2_status]
201 BS2Dict = BSData2.getDataCache()
202 
203 if(len(BS2Dict)==0):
204  if options.config == 'OnlineOffline':
205  print ('No entries found in Online DB!')
206  elif options.config == 'Reproc':
207  print ('No entries in reprocessed sample!')
208  else:
209  print ('No entries found for second tag!')
210 
211  sys.exit(1)
212 
213 numNew = 0
214 numOld = 0
215 
216 x1 = array('d')
217 ex1 = array('d')
218 x2 = array('d')
219 ex2 = array('d')
220 xd = array('d')
221 exd = array('d')
222 
223 y1Dict = {}
224 ey1Dict = {}
225 y2Dict = {}
226 ey2Dict = {}
227 ydDict = {}
228 eydDict = {}
229 
230 for BS1 in BSData1:
231  pass1 = False
232  if BS1.status == options.status: pass1 = True
233 
234  run = BS1.run
235  lbmin = BS1.lbStart
236  lbmax = BS1.lbEnd
237  # This is taken into account correctly for COOL, not for ROOT
238  if ".csv" in tag1 or ".root" in tag1:
239  lbmax+=1
240 
241  if lbmax-lbmin > 100:
242  lbmax = lbmin+10
243 
244  if options.lbmin != 0 and lbmin < options.lbmin:
245  lbmin = options.lbmin
246  if options.lbmax != 0 and lbmax > options.lbmax:
247  lbmax = options.lbmax
248 
249  for lb in range(lbmin, lbmax) :
250 
251  if pass1:
252  x1.append(lb)
253  ex1.append(0.0)
254 
255  for var in varColl:
256  if not var in y1Dict:
257  y1Dict[var] = array('d')
258  ey1Dict[var] = array('d')
259  y1Dict[var].append(getattr(BS1, var))
260  try:
261  ey1Dict[var].append(getattr(BS1, var+'Err'))
262  except:
263  ey1Dict[var].append(0.0)
264 
265  if run in BS2Dict:
266  if lb in BS2Dict[run]:
267  BS2 = BS2Dict[run][lb]
268 
269  pass2 = False
270  if options.RooFit:
271  if options.status==59:
272  if BS2.status == 107: pass2 = True
273  elif options.status==107:
274  if BS2.status == 59: pass2 = True
275  elif options.config=='OnlineOffline':
276  if (BS2.status%8)==7: pass2=True
277  else:
278  if BS2.status == options.status: pass2 = True
279 
280  if pass1 and not pass2:
281  print ("Warning: run %s lumiBlock %s doesn't have good fit anymore" %(run,lb))
282  numOld += 1
283 
284  if pass2 and not pass1: numNew += 1
285  if not pass1 or not pass2: continue
286 
287  xd.append(lb)
288  exd.append(0.0)
289 
290  for var in varColl:
291  if not var in ydDict:
292  ydDict[var] = array('d')
293  eydDict[var] = array('d')
294  diff = getattr(BS1, var) - getattr(BS2, var)
295  try:
296  ediff = max(getattr(BS1, var+'Err'), getattr(BS2, var+'Err'))
297  except:
298  ediff = 0.0
299  ydDict[var].append(diff)
300  eydDict[var].append(ediff)
301 
302  try:
303  percdiff = diff / max(getattr(BS1, var), getattr(BS2, var))
304  except:
305  percdiff = 0
306 
307  try:
308  sigmaChange = diff/ediff
309  except:
310  sigmaChange = 0
311 
312  if sigmaChange > 3 and diff > getVarDef(var, 'bigchange') :
313  print ("WARNING: Big change in value of %s for lumiBlock %i" % (var, lb))
314  print (" change in value is %f microns, or %f sigma" % (diff, diff/ediff))
315 
316  if options.smallChanges and percdiff > 0.001 :
317  print ("WARNING: value of %s in run %s in lumiBlock %i changed by more than 0.1 percent" % (var, run, lb))
318 
319 
320  else:
321  if pass1:
322  print ("Warning: run %s lumiBlock %s doesn't have beamspot anymore" %(run, lb))
323  numOld += 1
324 
325 for run in BS2Dict:
326  for lb in BS2Dict[run]:
327  BS2 = BS2Dict[run][lb]
328 
329  if options.RooFit:
330  if options.status==59:
331  if BS2.status == 107: pass2 = True
332  elif options.status==107:
333  if BS2.status == 59: pass2 = True
334  elif options.config=="OnlineOffline":
335  if (BS2.status%8)==7: pass2=True
336  else:
337  if BS2.status == options.status: pass2 = True
338 
339  x2.append(lb)
340  ex2.append(0.0)
341 
342  for var in varColl:
343  if not var in y2Dict:
344  y2Dict[var] = array('d')
345  ey2Dict[var] = array('d')
346  y2Dict[var].append(getattr(BS2, var))
347  try:
348  ey2Dict[var].append(getattr(BS2, var+'Err'))
349  except:
350  ey2Dict[var].append(0.0)
351 
352 print ("Number of LBs where beam spot is good but was bad before: %i" % numNew)
353 print ("Number of LBs where beam spot is bad but was good before: %i" % numOld)
354 
355 if len(xd)==0:
356  print ("ERROR: No overlapping LB range found")
357  sys.exit(1)
358 
359 # Plotting
360 if doOnePlot:
361  canvas = ROOT.TCanvas('BeamSpotComparison', 'BeamSpotComparison', 600, 500)
362  if options.plotHistos:
363  ROOT.gStyle.SetOptStat(1110)
364  ROOT.gStyle.SetStatW(0.3)
365  ROOT.gStyle.SetStatH(0.2)
366  else:
367  canvas.Divide(1,2,0,0)
368 elif options.plotHistos:
369  canvas = ROOT.TCanvas('BeamSpotComparison', 'BeamSpotComparison', 750, 1000)
370  canvas.Divide(3, 4)
371 elif options.multicanv:
372  canvases = {}
373  ratiopad = {}
374  primarypad = {}
375  zeroline = {}
376 else:
377  canvas = ROOT.TCanvas('BeamSpotComparison', 'BeamSpotComparison', 750, 1400)
378  ROOT.gPad.SetLeftMargin(0.0)
379  ROOT.gPad.SetBottomMargin(0.0)
380  canvas.Divide(3, 8, 0.01, 0)
381 
382 
383 ivar = 0
384 graphColl = []
385 dummyColl = []
386 histColl = []
387 
388 for var in varColl:
389  #for var in ['posX'] :
390 
391  gr1 = ROOT.TGraphErrors(len(x1), x1, y1Dict[var], ex1, ey1Dict[var])
392  graphColl.append(gr1)
393  gr2 = ROOT.TGraphErrors(len(x2), x2, y2Dict[var], ex2, ey2Dict[var])
394  graphColl.append(gr2)
395  grdiff = ROOT.TGraphErrors(len(xd), xd, ydDict[var], exd, eydDict[var])
396  graphColl.append(grdiff)
397 
398  xmin = min(min(x1), min(x2))
399  xmax = max(max(x1), max(x2))
400  ymin = min(min(y1Dict[var]), min(y2Dict[var]))
401  ymax = max(max(y1Dict[var]), max(y2Dict[var]))
402 
403  h = (ymax-ymin)
404  ymin -= 0.25*h
405  ymax += 0.25*h
406  h = (xmax-xmin)
407  xmin -= 0.05*h
408 
409  diffmin = min(ydDict[var])
410  diffmax = max(ydDict[var])
411  h = diffmax - diffmin
412  diffmin -= 0.25*h
413  diffmax += 0.25*h
414 
415  histo = ROOT.TH1F(var, var, 40, diffmin, diffmax)
416  histo.GetXaxis().SetTitle(getVarDef(var,'ytit'))
417  histo.GetYaxis().SetTitle('LumiBlocks')
418 
419  for i in range(0, len(ydDict[var])):
420  histo.Fill(ydDict[var][i])
421 
422  histColl.append(histo)
423 
424  if options.plotHistos:
425  if doOnePlot:
426  histo.GetXaxis().SetTitleOffset(1.7)
427  histo.DrawCopy()
428  else:
429  canvas.cd(ivar+2)
430  histo.DrawCopy()
431  else:
432  hdummy = ROOT.TH2D('hd'+var, 'hd'+var, 10, xmin, xmax, 10, ymin, ymax)
433  hdummy.SetTitle("")
434  hdummy.GetYaxis().SetTitle(getVarDef(var, 'ytit2'))
435  hdummy.GetYaxis().SetTitleSize(0.07)
436  hdummy.GetXaxis().SetLabelSize(0)
437 
438  dummyColl.append(hdummy)
439 
440  gr1.SetMarkerSize(0.8)
441  gr1.SetMarkerStyle(22)
442  gr1.SetMarkerColor(4)
443  gr1.SetLineColor(4)
444  gr1.SetLineWidth(1)
445  gr2.SetMarkerSize(0.8)
446  gr2.SetMarkerStyle(21)
447  gr2.SetMarkerColor(2)
448  gr2.SetLineColor(2)
449  gr2.SetLineWidth(1)
450  grdiff.SetMarkerSize(0.8)
451  grdiff.SetLineWidth(1)
452 
453  if options.batch :
454  gr1.SetMarkerSize(0.3)
455  gr2.SetMarkerSize(0.3)
456  grdiff.SetMarkerSize(0.3)
457  gr1.GetYaxis().SetTitleOffset(1.7)
458  grdiff.GetXaxis().SetTitle(getVarDef(var, 'xtit'))
459  grdiff.GetYaxis().SetTitle(getVarDef(var, 'ytit'))
460  grdiff.GetXaxis().SetTitleSize(0.07)
461  grdiff.GetYaxis().SetTitleSize(0.07)
462  grdiff.GetXaxis().SetLimits(xmin, xmax)
463 
464  if doOnePlot:
465  canvas.cd(1)
466  ROOT.gPad.SetTopMargin(0.1)
467  ROOT.gPad.SetLeftMargin(0.2)
468  ROOT.gPad.SetRightMargin(0.1)
469  hdummy.Draw()
470  gr1.Draw("P")
471  gr2.Draw("P")
472 
473  canvas.cd(2)
474  ROOT.gPad.SetTopMargin(0.05)
475  ROOT.gPad.SetBottomMargin(0.2)
476  ROOT.gPad.SetLeftMargin(0.2)
477  ROOT.gPad.SetRightMargin(0.1)
478  grdiff.Draw("AP")
479 
480  elif options.multicanv:
481  ROOT.gStyle.SetGridColor(ROOT.kGray)
482  ROOT.gStyle.SetGridWidth(1)
483  canvases[var]=ROOT.TCanvas('BeamSpotComparison_%s'%var,
484  'BeamSpotComparison_%s'%var,
485  800,600)
486  canvases[var].cd()
487 
488  primarypad[var] = ROOT.TPad("primarypad","primarypad",0,0.35,1,1)
489  primarypad[var].SetBottomMargin(0.03)
490  primarypad[var].Draw()
491  primarytextscale=1./(primarypad[var].GetWh()*primarypad[var].GetAbsHNDC());
492 
493  ratiopad[var] = ROOT.TPad("ratiopad","ratiopad",0,0.03,1,0.35)
494  ratiopad[var].SetTopMargin(0.03)
495  ratiopad[var].SetBottomMargin(0.3)
496  ratiopad[var].SetGridy(1)
497  ratiopad[var].Draw()
498  ratiotextscale=1./(ratiopad[var].GetWh()*ratiopad[var].GetAbsHNDC())
499 
500  primarypad[var].cd()
501  hdummy.Draw()
502  gr1.Draw("P")
503  gr2.Draw("P")
504 
505  hdummy.GetYaxis().SetTitleSize(0.085)
506  hdummy.GetYaxis().SetTitleOffset(0.75)
507  hdummy.GetYaxis().SetLabelSize(0.06)
508  hdummy.GetXaxis().SetLabelSize(0)
509 
510  minyaxis=hdummy.GetYaxis().GetXmin()
511  maxyaxis=hdummy.GetYaxis().GetXmax()
512  rangeyaxis=abs(minyaxis-maxyaxis)
513  hdummy.GetYaxis().SetLimits(minyaxis,maxyaxis+0.50*rangeyaxis)
514  primarypad[var].Update()
515 
516  ratiopad[var].cd()
517  grdiff.Draw("AP")
518 
519  diffymax=grdiff.GetYaxis().GetXmax()
520  diffymin=grdiff.GetYaxis().GetXmin()
521  if diffymin>0.:
522  grdiff.GetYaxis().SetRangeUser(0.-0.1*abs(diffymax-diffymin),diffymax)
523  elif diffymax<0.:
524  grdiff.GetYaxis().SetRangeUser(diffymin,0.+0.1*abs(diffymax-diffymin))
525 
526  grdiff.GetYaxis().SetTitleSize(0.16)
527  grdiff.GetYaxis().SetTitleOffset(.39)
528  grdiff.GetXaxis().SetTitleOffset(0.9)
529  grdiff.GetXaxis().SetTitleSize(0.16)
530  grdiff.GetYaxis().SetLabelSize(0.12)
531  grdiff.GetYaxis().SetNdivisions(8)
532  grdiff.GetXaxis().SetLabelSize(0.12)
533 
534  zeroline[var]=ROOT.TLine(xmin, 0.0, xmax+1, 0.0)
535  zeroline[var].SetLineWidth(2)
536  zeroline[var].Draw()
537 
538  grdiff.Draw("P")
539 
540  ratiopad[var].Update()
541 
542  canvases[var].Update()
543  else:
544  canvas.cd(getVarDef(var, 'cannr'))
545  ROOT.gPad.SetTopMargin(0.1)
546  ROOT.gPad.SetLeftMargin(0.2)
547  ROOT.gPad.SetRightMargin(0.1)
548  ROOT.gPad.SetBottomMargin(0.02)
549  hdummy.Draw()
550  gr1.Draw("P")
551  gr2.Draw("P")
552 
553  canvas.cd(getVarDef(var, 'cannr')+3)
554  ROOT.gPad.SetTopMargin(0.05)
555  ROOT.gPad.SetBottomMargin(0.2)
556  ROOT.gPad.SetLeftMargin(0.2)
557  ROOT.gPad.SetRightMargin(0.1)
558  grdiff.Draw("AP")
559 
560  ivar += 1
561 
562 # summary frame
563 def drawSummary(var=''):
564  # description
565  descrText=''
566  if options.config == 'OnlineOffline':
567  descrText += 'Online - Offline comparison'
568  legText1 = 'Offine'
569  legText2 = 'Online'
570  elif options.config == 'Reproc':
571  if not options.multicanv:
572  descrText += 'Reprocessed - Tier0 comparison'
573  if options.label1 == '':
574  legText1 = 'Tier0'
575  if options.label2 == '':
576  legText2 = 'Reproc'
577  else:
578  legText1 = 'Beamspots 1'
579  legText2 = 'Beamspots 2'
580 
581  if options.label1 != '':
582  legText1 = options.label1
583 
584  if options.label2 != '':
585  legText2 = options.label2
586 
587 
588  if options.multicanv:
589  primarypad[var].cd()
590  if not options.multicanv:
591  ROOTUtils.drawText(0.14, 0.95, 0.1, descrText)
592  else:
593  ROOTUtils.drawText(0.14, 0.95, 0.1, descrText)
594 
595  # legend
596  legendList = []
597 
598  legendList.append([gr1, legText1, 'LP'])
599  legendList.append([gr2, legText2, 'LP'])
600  legendList.append([grdiff, 'Difference', 'LP'])
601  if options.multicanv:
602  ROOTUtils.drawLegend(0.25, 0.6, 0.60, 0.92, legendList)
603  elif not options.plotHistos:
604  ROOTUtils.drawLegend(0.14, 0.67, 0.9, 0.9, legendList)
605  if runNumber != 0:
606  if options.multicanv:
607  ROOTUtils.drawText(0.6, 0.7, 0.1, 'Run = %i' %runNumber)
608  else:
609  ROOTUtils.drawText(0.14, 0.55, 0.1, 'Run = %i' %runNumber)
610  if options.multicanv:
611  primarypad[var].Update()
612 
613 if not doOnePlot:
614  if options.plotHistos:
615  canvas.cd(1)
616  drawSummary()
617  elif options.multicanv:
618  for var,canv in canvases.items():
619  canv.cd()
620  drawSummary(var)
621  else:
622  canvas.cd(4)
623  drawSummary()
624 
625 
626  if not options.multicanv:
627  newText = 'New fits: %i' % numNew
628  oldText = 'Missing fits: %i' %numOld
629  ROOTUtils.drawText(0.14, 0.19, 0.1, newText)
630  ROOTUtils.drawText(0.14, 0.07, 0.1, oldText)
631 
632 if options.output:
633  basename=options.outtag
634  if options.config == "Reproc":
635  basename=tag2.replace(".BeamSpotNt-nt.root",".PlotBeamSpotCompareReproc").replace(".MergeNt-nt.root",".PlotBeamSpotCompareReproc")
636  basename=basename[basename.rfind('/')+1:]
637  if options.html and options.outtag.find('/'):
638  basename=options.outtag[:options.outtag.rfind('/')+1]+basename+options.htmltag+"."
639  elif options.runNumber>0:
640  basename+=str(options.runNumber)
641  basename+="_"
642  elif options.runMin>0:
643  basename+=str(options.runMin)
644  basename+="_"
645  basename+=str(options.runMax)
646  basename+="_"
647 
648  for o in options.output.split(','):
649  if options.multicanv:
650  if options.html:
651  htmlstart=0
652  if basename.find('/')>0:
653  htmlstart=basename.rfind('/')+1
654  htmlfilename=basename[htmlstart:-1]+".html"
655  html=open(htmlfilename,'w')
656  print ("writing html file %s" % htmlfilename)
657  for var,canv in canvases.items():
658  canv.Print(basename+var+o)
659  if o==".png" and options.html:
660  for var in ['posX', 'posY', 'posZ', 'sigmaX', 'sigmaY', 'sigmaZ', 'rhoXY', 'tiltX', 'tiltY', 'k', 'nEvents']:
661  if var in canvases:
662  if "pdf" in options.output:
663  html.write("<a href=\""+basename+var+".pdf\"><img src=\""+basename+var+o+"\" width=\"33%\"></a>")
664  else:
665  html.write("<img src=\""+basename+var+o+"\" width=\"33%\">")
666  if options.html:
667  html.close()
668  else:
669  canvas.SaveAs(o)
670 
671 
672 if not options.batch:
673  while(True):
674  time.sleep(1)
675 
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
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
BeamSpotData
max
#define max(a, b)
Definition: cfImp.cxx:41
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ROOTUtils.setStyle
def setStyle(style=None)
Definition: roofit/ROOTUtils.py:413
python.Utils.getRunFromName
def getRunFromName(name, default='', asInt=False)
Definition: InnerDetector/InDetExample/InDetBeamSpotExample/python/Utils.py:13
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
while
while((inf=(TStreamerInfo *) nextinfo()) !=0)
Definition: liststreamerinfos.cxx:13
plotBeamSpotCompare.drawSummary
def drawSummary(var='')
Definition: plotBeamSpotCompare.py:563
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
min
#define min(a, b)
Definition: cfImp.cxx:40
array
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
plotBeamSpotCompare.getVarDef
def getVarDef(what, property, default='')
Definition: plotBeamSpotCompare.py:38
Trk::open
@ open
Definition: BinningType.h:40
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:569
calibdata.cd
cd
Definition: calibdata.py:51
str
Definition: BTagTrackIpAccessor.cxx:11
ROOTUtils.drawLegend
def drawLegend(x1, y1, x2, y2, legendList=[], fillColor=0, lineColor=0, textSize=None, protectLegend=True)
Definition: roofit/ROOTUtils.py:259