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