ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
beamspotnt.Plots Class Reference
Inheritance diagram for beamspotnt.Plots:
Collaboration diagram for beamspotnt.Plots:

Public Member Functions

def __init__ (self, nt)
 
def writeText (self, var, legendList=[], showRuns=True, showFills=True, showTime=True, otherTitle=None, otherComment=None, legendX=0.6)
 
def hist (self, what)
 
def histvspileup (self, what)
 
def pull (self, what)
 
def plot (self, what)
 
def perbcid (self, what)
 
def vsBunchPos (self, what)
 
def plotscan (self, what)
 
def __init__ (self, nt)
 
def writeText (self, var, legendList=[], showRuns=True, showFills=True, showTime=True, otherTitle=None, otherComment=None, legendX=0.6)
 
def hist (self, what)
 
def histvspileup (self, what)
 
def pull (self, what)
 
def plot (self, what)
 
def perbcid (self, what)
 
def vsBunchPos (self, what)
 
def plotscan (self, what)
 
def protect (self, obj)
 
def plot (self, plotName='', *args)
 
def genPlot (self, what='ALL', code='plot', labels=[], *args)
 

Public Attributes

 nt
 
 whatList
 
 name
 
 otherMethods
 
 rootObjects
 
 singleCanvasSize
 
 allCanvasSize
 
 allCanvasDivs
 
 saveAsList
 
 gPadSaveAsList
 

Detailed Description

Definition at line 416 of file bin/beamspotnt.py.

Constructor & Destructor Documentation

◆ __init__() [1/2]

def beamspotnt.Plots.__init__ (   self,
  nt 
)

Definition at line 418 of file bin/beamspotnt.py.

418  def __init__(self,nt):
419  ROOTUtils.PlotLibrary.__init__(self,options.name)
420  self.nt = nt
421  self.whatList = ['posX','posY','posZ','sigmaX','sigmaY','sigmaZ','tiltX','tiltY','rhoXY','k','nValid']
422 

◆ __init__() [2/2]

def beamspotnt.Plots.__init__ (   self,
  nt 
)

Definition at line 411 of file www/beamspotnt.py.

411  def __init__(self,nt):
412  ROOTUtils.PlotLibrary.__init__(self,options.name)
413  self.nt = nt
414  self.whatList = ['posX','posY','posZ','sigmaX','sigmaY','sigmaZ','tiltX','tiltY','rhoXY','k']
415 

Member Function Documentation

◆ genPlot()

def ROOTUtils.PlotLibrary.genPlot (   self,
  what = 'ALL',
  code = 'plot',
  labels = [],
args 
)
inherited
Make plots using a general code. genPlot makes either a single plot defined
   by argument what, or all plots (if what=''). The plots made in the latter
   case are specified by whatList. A canvas that is subdivided if necessary
   is created before the plotting code is called.

Definition at line 116 of file roofit/ROOTUtils.py.

116  def genPlot(self,what='ALL',code='plot',labels=[],*args):
117  """Make plots using a general code. genPlot makes either a single plot defined
118  by argument what, or all plots (if what=''). The plots made in the latter
119  case are specified by whatList. A canvas that is subdivided if necessary
120  is created before the plotting code is called."""
121  if what=='' or what.upper()=='ALL':
122  c = self.protect( MyCanvas('%s-%s-%s' % (self.name,what,code),
123  self.allCanvasSize,self.allCanvasDivs[0],self.allCanvasDivs[1]) )
124  iCanvas = 0
125  for w in self.whatList:
126  iCanvas += 1
127  c.cd(iCanvas)
128  try:
129  self.__class__.__dict__[code](self,w,*args)
130  except:
131  self.__class__.__bases__[0].__dict__[code](self,w,*args)
132  ROOT.gPad.Update()
133  # For some strange reason, this works only for .eps, but not e.g. for gif files...???
134  for o in self.gPadSaveAsList:
135  if o[0]=='.':
136  ROOT.gPad.SaveAs('%s-%s-%s%s' % (self.name,code,w,o))
137  else:
138  ROOT.gPad.SaveAs(o)
139 
140  # If we want to put some labels on an empty pad, add them now.
141  if labels!=[] and self.allCanvasDivs[0]*self.allCanvasDivs[1] > len(self.whatList):
142  iCanvas+=1
143  c.cd(iCanvas)
144  xtext=0.0
145  ytext=0.8
146  for label in labels:
147  drawText(xtext,ytext,0.06,label)
148  ytext=ytext-0.1
149  elif labels!=[]:
150  print "ERROR: can't add labels unless we have an empty pad to use. Ignoring labels."
151 
152  for o in self.saveAsList:
153  if o[0]=='.':
154  c.SaveAs('%s-%s-%s%s' % (self.name,code,what,o))
155  else:
156  c.SaveAs(o)
157 
158  else:
159  c = self.protect( MyCanvas(what,self.singleCanvasSize) )
160  try:
161  self.__class__.__dict__[code](self,what,*args)
162  except:
163  self.__class__.__bases__[0].__dict__[code](self,what,*args)
164  ROOT.gPad.Update()
165  for o in self.saveAsList:
166  if o[0]=='.':
167  c.SaveAs('%s-%s-%s%s' % (self.name,code,what,o))
168  else:
169  c.SaveAs(o)
170 

◆ hist() [1/2]

def beamspotnt.Plots.hist (   self,
  what 
)
Histogram of variable what.

If what is of the form NAME:VALUE, VALUE will be subtracted
from each entry in order to produce plots of measured minus
true value.

Definition at line 468 of file www/beamspotnt.py.

468  def hist(self,what):
469  """Histogram of variable what.
470 
471  If what is of the form NAME:VALUE, VALUE will be subtracted
472  from each entry in order to produce plots of measured minus
473  true value."""
474  shift = 0.
475  try:
476  (what,shift) = what.split(':')
477  shift = float(shift)
478  except:
479  pass
480  ROOT.gStyle.SetOptStat(options.optstat) # emruo to add underflow, overflow
481  title = varDef(what,'title',what)+';'+varDef(what,'atit',what)
482  nBins = options.nbins if options.nbins else varDef(what,'nBins',100)
483  xmin = float(options.xmin) if options.xmin!=None else varDef(what,'min',-100)
484  xmax = float(options.xmax) if options.xmax!=None else varDef(what,'max',+100)
485  h = self.protect( ROOT.TH1F(what,title,nBins,xmin,xmax) )
486  if options.fit:
487  h.Sumw2()
488  h.GetYaxis().SetTitle('Number of fit results')
489  arescale = varDef(what,'arescale',1.0)
490  try:
491  for b in nt:
492  h.Fill(arescale*(getattr(b,what)-shift))
493  except Exception as e:
494  print ('ERROR filling histogram:',str(e))
495  h.Draw()
496  if options.fit:
497  ROOT.gStyle.SetOptFit(1111)
498  h.Fit(options.fit,options.optfit)
499  if options.logy:
500  ROOT.gPad.SetLogy(options.logy)
501  ndivs = varDef(what,'ndivs',override=options.ndivs)
502  if ndivs:
503  h.GetXaxis().SetNdivisions(ndivs,0)
504  if options.mc:
505  self.writeText(what,[],False,False,False)
506  else:
507  self.writeText(what,[],not options.public,options.public)
508 

◆ hist() [2/2]

def beamspotnt.Plots.hist (   self,
  what 
)
Histogram of variable what.

If what is of the form NAME:VALUE, VALUE will be subtracted
from each entry in order to produce plots of measured minus
true value.

Definition at line 475 of file bin/beamspotnt.py.

475  def hist(self,what):
476  """Histogram of variable what.
477 
478  If what is of the form NAME:VALUE, VALUE will be subtracted
479  from each entry in order to produce plots of measured minus
480  true value."""
481  shift = 0.
482  try:
483  (what,shift) = what.split(':')
484  shift = float(shift)
485  except:
486  pass
487  ROOT.gStyle.SetOptStat(options.optstat) # emruo to add underflow, overflow
488  title = varDef(what,'title',what)+';'+varDef(what,'atit',what)
489  nBins = options.nbins if options.nbins else varDef(what,'nBins',100)
490  xmin = float(options.xmin) if options.xmin!=None else varDef(what,'min',-100)
491  xmax = float(options.xmax) if options.xmax!=None else varDef(what,'max',+100)
492  h = self.protect( ROOT.TH1F(what,title,nBins,xmin,xmax) )
493  if options.fit:
494  h.Sumw2()
495  h.GetYaxis().SetTitle('Number of fit results')
496  arescale = varDef(what,'arescale',1.0)
497  try:
498  for b in nt:
499  h.Fill(arescale*(getattr(b,what)-shift))
500  except Exception as e:
501  print ('ERROR filling histogram:',str(e))
502  h.Draw()
503  if options.fit:
504  ROOT.gStyle.SetOptFit(1111)
505  h.Fit(options.fit,options.optfit)
506  if options.logy:
507  ROOT.gPad.SetLogy(options.logy)
508  ndivs = varDef(what,'ndivs',override=options.ndivs)
509  if ndivs:
510  h.GetXaxis().SetNdivisions(ndivs,0)
511  if options.mc:
512  self.writeText(what,[],False,False,False)
513  else:
514  self.writeText(what,[],not options.public,options.public)
515 

◆ histvspileup() [1/2]

def beamspotnt.Plots.histvspileup (   self,
  what 
)
Profile histogram of variable what vs pileup.

If what is of the form NAME:VALUE, VALUE will be subtracted
from each entry in order to produce plots of measured minus
true value.

Definition at line 509 of file www/beamspotnt.py.

509  def histvspileup(self,what):
510  """Profile histogram of variable what vs pileup.
511 
512  If what is of the form NAME:VALUE, VALUE will be subtracted
513  from each entry in order to produce plots of measured minus
514  true value."""
515  shift = 0.
516  try:
517  (what,shift) = what.split(':')
518  shift = float(shift)
519  except:
520  pass
521  ROOT.gStyle.SetOptStat(options.optstat) # emruo to add underflow, overflow
522  title = varDef(what,'title',what)+';Number of pileup vertices;'+varDef(what,'atit',what)
523  nBins = options.nbins if options.nbins else varDef(what,'nBins',100)
524  xmin = float(options.xmin) if options.xmin!=None else varDef(what,'min',-100)
525  xmax = float(options.xmax) if options.xmax!=None else varDef(what,'max',+100)
526  h = self.protect( ROOT.TProfile(what,title,nBins,0,nBins) )
527  if options.fit:
528  h.Sumw2()
529  h.GetYaxis().SetRangeUser(xmin,xmax)
530  arescale = varDef(what,'arescale',1.0)
531  try:
532  for b in nt:
533  h.Fill(getattr(b,'pileup'),arescale*(getattr(b,what)-shift))
534  except Exception as e:
535  print ('ERROR filling histogram:',str(e))
536  h.Draw()
537  if options.fit:
538  ROOT.gStyle.SetOptFit(1111)
539  h.Fit(options.fit,options.optfit)
540  if options.logy:
541  ROOT.gPad.SetLogy(options.logy)
542  ndivs = varDef(what,'ndivs',override=options.ndivs)
543  if ndivs:
544  h.GetYaxis().SetNdivisions(ndivs,0)
545  if options.mc:
546  self.writeText(what,[],False,False,False)
547  else:
548  self.writeText(what,[],not options.public,options.public)
549 

◆ histvspileup() [2/2]

def beamspotnt.Plots.histvspileup (   self,
  what 
)
Profile histogram of variable what vs pileup.

If what is of the form NAME:VALUE, VALUE will be subtracted
from each entry in order to produce plots of measured minus
true value.

Definition at line 516 of file bin/beamspotnt.py.

516  def histvspileup(self,what):
517  """Profile histogram of variable what vs pileup.
518 
519  If what is of the form NAME:VALUE, VALUE will be subtracted
520  from each entry in order to produce plots of measured minus
521  true value."""
522  shift = 0.
523  try:
524  (what,shift) = what.split(':')
525  shift = float(shift)
526  except:
527  pass
528  ROOT.gStyle.SetOptStat(options.optstat) # emruo to add underflow, overflow
529  title = varDef(what,'title',what)+';Number of pileup vertices;'+varDef(what,'atit',what)
530  nBins = options.nbins if options.nbins else varDef(what,'nBins',100)
531  xmin = float(options.xmin) if options.xmin!=None else varDef(what,'min',-100)
532  xmax = float(options.xmax) if options.xmax!=None else varDef(what,'max',+100)
533  h = self.protect( ROOT.TProfile(what,title,nBins,0,nBins) )
534  if options.fit:
535  h.Sumw2()
536  h.GetYaxis().SetRangeUser(xmin,xmax)
537  arescale = varDef(what,'arescale',1.0)
538  try:
539  for b in nt:
540  h.Fill(getattr(b,'pileup'),arescale*(getattr(b,what)-shift))
541  except Exception as e:
542  print ('ERROR filling histogram:',str(e))
543  h.Draw()
544  if options.fit:
545  ROOT.gStyle.SetOptFit(1111)
546  h.Fit(options.fit,options.optfit)
547  if options.logy:
548  ROOT.gPad.SetLogy(options.logy)
549  ndivs = varDef(what,'ndivs',override=options.ndivs)
550  if ndivs:
551  h.GetYaxis().SetNdivisions(ndivs,0)
552  if options.mc:
553  self.writeText(what,[],False,False,False)
554  else:
555  self.writeText(what,[],not options.public,options.public)
556 

◆ perbcid() [1/2]

def beamspotnt.Plots.perbcid (   self,
  what 
)
Variable what vs BCID.

Definition at line 756 of file www/beamspotnt.py.

756  def perbcid(self,what):
757  """Variable what vs BCID."""
758  ROOT.gStyle.SetOptStat(0)
759  if options.ave:
760  calc = BeamSpotAverage([what],weightedAverage=not options.simpleaverage)
761  gr = BeamSpotGraph(bcidAxis=True)
762  for b in nt:
763  gr.add(b,what)
764  if options.ave:
765  calc.add(b)
766  atit = ';%s;%s' % ('BCID',varDef(what,'atit',what))
767 
768  # Axis range and labels
769  xmin = max(-100,gr.xmin-100)
770  xmax = min(3600,gr.xmax+100) # 3564 is the max number of BCIDS + a little space
771  ymin = gr.ymin
772  ymax = gr.ymax
773 
774  # Prevent xmin>xmax or ymin>ymax if no succesful fits (but still allow user to override)
775  if xmin>xmax:
776  xmin,xmax=0,1
777  if ymin>ymax:
778  ymin,ymax=0,1
779 
780  h = (ymax-ymin)/2*options.yscale
781  ymax += 1.3*h
782  ymin -= 0.5*h
783  if options.ydef:
784  ymin = varDef(what,'min',-100)
785  ymax = varDef(what,'max',+100)
786  if options.ymin!=None:
787  ymin = options.ymin
788  if options.ymax!=None:
789  ymax = options.ymax
790  frame = ROOTUtils.drawAxisFrame(xmin,xmax,ymin,ymax,atit)
791  if options.logy:
792  ROOT.gPad.SetLogy(options.logy)
793 
794  legendList = []
795 
796  # Show average
797  if options.ave:
798  calc.average()
799  dx = (xmax-xmin)/30
800  mean = calc.ave[0]
801  if options.rms:
802  error = calc.rms[0]
803  else:
804  error = calc.err[0]
805  b = ROOTUtils.drawHorizontalBand(xmin+dx,xmax-dx,mean,error,centralLine=True)
806  legendList.append([b,options.alegend,'FL'])
807  legendList.append([None,'%s %s #pm %s %s' % (fmtVal(what,mean,True),varDef(what,'units'),
808  fmtVal(what,error,True),varDef(what,'units')),''])
809 
810  # Save and draw graph
811  name = '%s-perBCID' % what
812  tgraph = self.protect( gr.getTGraph(name) )
813  if not tgraph:
814  return
815  if options.tgraphfile:
816  print ('Saving TGraphErrors',tgraph.GetName(),'to file',options.tgraphfile)
817  tgraphfile = ROOT.TFile(options.tgraphfile,'UPDATE')
818  tgraph.Write()
819  tgraphfile.Close()
820  tgraph.SetMarkerSize(options.msize if options.msize else 0.8)
821  if options.plegend:
822  legendList.append([tgraph,options.plegend,'PLE'])
823  tgraph.Draw('P')
824 
825  # Draw title and legend
826  self.writeText(what,legendList,not options.public)
827 

◆ perbcid() [2/2]

def beamspotnt.Plots.perbcid (   self,
  what 
)
Variable what vs BCID.

Definition at line 759 of file bin/beamspotnt.py.

759  def perbcid(self,what):
760  """Variable what vs BCID."""
761  ROOT.gStyle.SetOptStat(0)
762  if options.ave:
763  calc = BeamSpotAverage([what],weightedAverage=not options.simpleaverage)
764  gr = BeamSpotGraph(bcidAxis=True)
765  for b in nt:
766  gr.add(b,what)
767  if options.ave:
768  calc.add(b)
769  atit = ';%s;%s' % ('BCID',varDef(what,'atit',what))
770 
771  # Axis range and labels
772  xmin = max(-100,gr.xmin-100)
773  xmax = min(3600,gr.xmax+100) # 3564 is the max number of BCIDS + a little space
774  ymin = gr.ymin
775  ymax = gr.ymax
776 
777  # Prevent xmin>xmax or ymin>ymax if no succesful fits (but still allow user to override)
778  if xmin>xmax:
779  xmin,xmax=0,1
780  if ymin>ymax:
781  ymin,ymax=0,1
782 
783  h = (ymax-ymin)/2*options.yscale
784  ymax += 1.3*h
785  ymin -= 0.5*h
786  if options.ydef:
787  ymin = varDef(what,'min',-100)
788  ymax = varDef(what,'max',+100)
789  if options.ymin!=None:
790  ymin = options.ymin
791  if options.ymax!=None:
792  ymax = options.ymax
793  frame = ROOTUtils.drawAxisFrame(xmin,xmax,ymin,ymax,atit)
794  if options.logy:
795  ROOT.gPad.SetLogy(options.logy)
796 
797  legendList = []
798 
799  # Show average
800  if options.ave:
801  calc.average()
802  dx = (xmax-xmin)/30
803  mean = calc.ave[0]
804  if options.rms:
805  error = calc.rms[0]
806  else:
807  error = calc.err[0]
808  b = ROOTUtils.drawHorizontalBand(xmin+dx,xmax-dx,mean,error,centralLine=True)
809  legendList.append([b,options.alegend,'FL'])
810  legendList.append([None,'%s %s #pm %s %s' % (fmtVal(what,mean,True),varDef(what,'units'),
811  fmtVal(what,error,True),varDef(what,'units')),''])
812 
813  # Save and draw graph
814  name = '%s-perBCID' % what
815  tgraph = self.protect( gr.getTGraph(name) )
816  if not tgraph:
817  return
818  if options.tgraphfile:
819  print ('Saving TGraphErrors',tgraph.GetName(),'to file',options.tgraphfile)
820  tgraphfile = ROOT.TFile(options.tgraphfile,'UPDATE')
821  tgraph.Write()
822  tgraphfile.Close()
823  tgraph.SetMarkerSize(options.msize if options.msize else 0.8)
824  if options.plegend:
825  legendList.append([tgraph,options.plegend,'PLE'])
826  tgraph.Draw('P')
827 
828  # Draw title and legend
829  self.writeText(what,legendList,not options.public)
830 

◆ plot() [1/3]

def ROOTUtils.PlotLibrary.plot (   self,
  plotName = '',
args 
)
inherited
Make one or all (if plotName=='') plots.

Definition at line 106 of file roofit/ROOTUtils.py.

106  def plot(self, plotName='',*args):
107  """Make one or all (if plotName=='') plots."""
108  if plotName:
109  self.__class__.__dict__[plotName](self,*args)
110  else:
111  for i in self.__class__.__dict__:
112  if i[0]=='_': continue # skip private methods
113  if i in self.otherMethods: continue
114  self.__class__.__dict__[i](self,*args)
115 

◆ plot() [2/3]

def beamspotnt.Plots.plot (   self,
  what 
)
History of variable what vs LB or time.

Definition at line 589 of file www/beamspotnt.py.

589  def plot(self,what):
590  """History of variable what vs LB or time."""
591  ROOT.gStyle.SetOptStat(0)
592  if options.ave:
593  calc = BeamSpotAverage([what],weightedAverage=not options.simpleaverage)
594  grDict = {}
595 
596  arescale = varDef(what,'arescale',1.0)
597  for b in nt:
598  if b.sigmaX < 0.01 or b.sigmaY < 0.01:
599  print ("OUTLIER ", b.run, b.lbStart, b.lbEnd, b.sigmaX, b.sigmaY)
600  if not b.bcid in grDict:
601  grDict[b.bcid] = BeamSpotGraph(timeAxis=options.timeaxis, separationAxis=options.separation)
602  # What was this for? Why ignore if no time info available?
603  #if b.timeStart>0 and b.timeEnd>0:
604  grDict[b.bcid].add(b,what,arescale)
605  if options.ave:
606  calc.add(b)
607 
608  print ('Plotting data from %i BCID ...\n' % len(grDict))
609 
610  # Determine axis range
611  xmin = 1E10
612  xmax = -1E10
613  ymin = 1E10
614  ymax = -1E10
615  for gr in [grDict.get(bcid) for bcid in grDict]:
616  xmin = min(xmin,gr.xmin)
617  xmax = max(xmax,gr.xmax)
618  ymin = min(ymin,gr.ymin)
619  ymax = max(ymax,gr.ymax)
620 
621  # Prevent xmin>xmax or ymin>ymax if no succesful fits (but still allow user to override)
622  if xmin>xmax:
623  xmin,xmax=0,1
624  if ymin>ymax:
625  ymin,ymax=0,1
626 
627  h = (xmax-xmin)
628  xmax += .05*h if len(grDict)==1 else 0.3*h
629  xmin -= .05*h
630  h = (ymax-ymin)/2*options.yscale
631  ymax += 1.3*h
632  ymin -= 0.5*h
633  if options.xmin!=None:
634  xmin = time.mktime(time.strptime(options.xmin,'%b %d %H:%M:%S %Y')) if options.timeaxis else float(options.xmin)
635  if options.xmax!=None:
636  xmax = time.mktime(time.strptime(options.xmax,'%b %d %H:%M:%S %Y')) if options.timeaxis else float(options.xmax)
637  if options.ydef:
638  ymin = varDef(what,'min',-100)
639  ymax = varDef(what,'max',+100)
640  if options.ymin!=None:
641  ymin = options.ymin
642  if options.ymax!=None:
643  ymax = options.ymax
644 
645  # Axis settings
646  if options.timeaxis:
647  atit = ';%s;%s' % (timeLabel,varDef(what,'atit',what))
648  elif options.separation:
649  atit = ';%s;%s' % ('Nominal Separation [mm]',varDef(what,'atit',what))
650  else:
651  atit = ';%s;%s' % ('Luminosity block number',varDef(what,'atit',what))
652  frame = ROOTUtils.drawAxisFrame(xmin,xmax,ymin,ymax,atit)
653  if options.logy:
654  ROOT.gPad.SetLogy(options.logy)
655  if options.timeaxis:
656  xAxis = frame.GetXaxis()
657  yAxis = frame.GetYaxis()
658  xAxis.SetTimeDisplay(1)
659 
660  # this may or may not be needed depending on the ROOT version... not sure whether to specify it or not.
661  # Setting this option in 5.34 seems to work, in 5.30 it offsets things by an hour, but then not setting it
662  # appears to result in bogus x-axis values.
663  xAxis.SetTimeOffset(0) # FIXME: this ignores options.timezone!
664 
665  if (xmax-xmin)/86400 < 1:
666  xAxis.SetTimeFormat('%H:%M')
667  else:
668  #d0 = ceil(xmin/86400) # day w/first tick mark
669  #d1 = floor(xmax/86400) # day w/last tick mark
670  #nTicks = d1-d0+1
671  #nDays = floor((xmax-xmin)/86400)
672  if options.public:
673  xAxis.SetTimeFormat('%b %d')
674  else:
675  xAxis.SetTimeFormat('#splitline{%b %d}{%H:%M}')
676  xAxis.SetLabelOffset(0.02)
677  xAxis.SetTitleOffset(1.6)
678  if options.lsize:
679  xAxis.SetLabelSize(options.lsize)
680  xAxis.SetTitleSize(options.lsize)
681  yAxis.SetLabelSize(options.lsize)
682  yAxis.SetTitleSize(options.lsize)
683  else:
684  xAxis.SetLabelSize(0.044)
685  if options.adatefmt:
686  xAxis.SetTimeFormat(options.adatefmt)
687  if options.ndivs:
688  xAxis.SetNdivisions(options.ndivs,0)
689  frame.LabelsOption('d','X') # Doesn't seem to work
690 
691  if options.xtitoffset:
692  xAxis.SetTitleOffset(options.xtitoffset)
693  if options.ytitoffset:
694  yAxis.SetTitleOffset(options.ytitoffset)
695 
696  legendList = []
697 
698  # Show average
699  if options.ave:
700  calc.average()
701  dx = (xmax-xmin)/30
702  mean = calc.ave[0]
703  if options.rms:
704  error = calc.rms[0]
705  else:
706  error = calc.err[0]
707  b = ROOTUtils.drawHorizontalBand(xmin+dx,xmax-dx,mean,error,centralLine=True)
708  legendList.append([b,options.alegend,'FL'])
709  legendList.append([None,'%s %s #pm %s %s' % (fmtVal(what,mean,True),varDef(what,'units'),
710  fmtVal(what,error,True),varDef(what,'units')),''])
711 
712  # Loop over graphs for all BCIDs
713  styleFactory = ROOTUtils.StyleFactory()
714  for bcid in sorted(grDict.keys()):
715  gr = grDict[bcid]
716 
717  # Get and save TGraphErrors, if desired
718  name = what if bcid==0 else '%s-bcid%04i' % (what,bcid)
719  tgraph = self.protect( gr.getTGraph(name) )
720  if not tgraph:
721  continue
722  if options.tgraphfile:
723  print ('Saving TGraphErrors',tgraph.GetName(),'to file',options.tgraphfile)
724  tgraphfile = ROOT.TFile(options.tgraphfile,'UPDATE')
725  tgraph.Write()
726  tgraphfile.Close()
727 
728  # Draw data points
729  if len(grDict)==1:
730  tgraph.SetMarkerSize(options.msize if options.msize else 0.8)
731  if options.plegend:
732  legendList.append([tgraph,options.plegend,'PLE'])
733  else:
734  tgraph.SetMarkerColor(styleFactory.nextColorStyle())
735  tgraph.SetMarkerStyle(styleFactory.nextMarkerStyle())
736  tgraph.SetMarkerSize(options.msize if options.msize else 1.2)
737  if len(legendList)<options.maxlegends:
738  text = 'All' if bcid==0 else 'BCID %i' % bcid
739  legendList.append([tgraph,text,'PLE'])
740  tgraph.Draw('P')
741 
742  # Indicate if legend incomplete
743  if len(grDict)>options.maxlegends:
744  legendList.append([None,'...',''])
745 
746  # Fit data, if desired
747  if options.fit and len(grDict)==1:
748  ROOT.gStyle.SetOptFit(1111)
749  legendList = [] # No legend to avoid crowding plot
750  tgraph.Fit(options.fit,'','SAME', gr.xmin,gr.xmax) #-0.05, 0.05) #ZEBRA
751 
752  # Draw title and legend
753  legendX = 0.6 if len(grDict)==1 else 0.8
754  self.writeText(what,legendList if not options.public else [],not options.public,legendX=legendX)
755 

◆ plot() [3/3]

def beamspotnt.Plots.plot (   self,
  what 
)
History of variable what vs LB or time.

Definition at line 596 of file bin/beamspotnt.py.

596  def plot(self,what):
597  """History of variable what vs LB or time."""
598  ROOT.gStyle.SetOptStat(0)
599  if options.ave:
600  calc = BeamSpotAverage([what],weightedAverage=not options.simpleaverage)
601  grDict = {}
602 
603  arescale = varDef(what,'arescale',1.0)
604  for b in nt:
605  if b.sigmaX < 0.005 or b.sigmaY < 0.005:
606  print ("OUTLIER ", b.run, b.lbStart, b.lbEnd, b.sigmaX, b.sigmaY)
607  if not b.bcid in grDict:
608  grDict[b.bcid] = BeamSpotGraph(timeAxis=options.timeaxis, separationAxis=options.separation)
609  # What was this for? Why ignore if no time info available?
610  #if b.timeStart>0 and b.timeEnd>0:
611  grDict[b.bcid].add(b,what,arescale)
612  if options.ave:
613  calc.add(b)
614 
615  print ('Plotting data from %i BCID ...\n' % len(grDict))
616 
617  # Determine axis range
618  xmin = 1E10
619  xmax = -1E10
620  ymin = 1E10
621  ymax = -1E10
622  for gr in [grDict.get(bcid) for bcid in grDict]:
623  xmin = min(xmin,gr.xmin)
624  xmax = max(xmax,gr.xmax)
625  ymin = min(ymin,gr.ymin)
626  ymax = max(ymax,gr.ymax)
627 
628  # Prevent xmin>xmax or ymin>ymax if no succesful fits (but still allow user to override)
629  if xmin>xmax:
630  xmin,xmax=0,1
631  if ymin>ymax:
632  ymin,ymax=0,1
633 
634  h = (xmax-xmin)
635  xmax += .05*h if len(grDict)==1 else 0.3*h
636  xmin -= .05*h
637  h = (ymax-ymin)/2*options.yscale
638  ymax += 1.3*h
639  ymin -= 0.5*h
640  if options.xmin!=None:
641  xmin = time.mktime(time.strptime(options.xmin,'%b %d %H:%M:%S %Y')) if options.timeaxis else float(options.xmin)
642  if options.xmax!=None:
643  xmax = time.mktime(time.strptime(options.xmax,'%b %d %H:%M:%S %Y')) if options.timeaxis else float(options.xmax)
644  if options.ydef:
645  ymin = varDef(what,'min',-100)
646  ymax = varDef(what,'max',+100)
647  if options.ymin!=None:
648  ymin = options.ymin
649  if options.ymax!=None:
650  ymax = options.ymax
651 
652  # Axis settings
653  if options.timeaxis:
654  atit = ';%s;%s' % (timeLabel,varDef(what,'atit',what))
655  elif options.separation:
656  atit = ';%s;%s' % ('Nominal Separation [mm]',varDef(what,'atit',what))
657  else:
658  atit = ';%s;%s' % ('Luminosity block number',varDef(what,'atit',what))
659  frame = ROOTUtils.drawAxisFrame(xmin,xmax,ymin,ymax,atit)
660  if options.logy:
661  ROOT.gPad.SetLogy(options.logy)
662  if options.timeaxis:
663  xAxis = frame.GetXaxis()
664  yAxis = frame.GetYaxis()
665  xAxis.SetTimeDisplay(1)
666 
667  # this may or may not be needed depending on the ROOT version... not sure whether to specify it or not.
668  # Setting this option in 5.34 seems to work, in 5.30 it offsets things by an hour, but then not setting it
669  # appears to result in bogus x-axis values.
670  xAxis.SetTimeOffset(0) # FIXME: this ignores options.timezone!
671 
672  if (xmax-xmin)/86400 < 1:
673  xAxis.SetTimeFormat('%H:%M')
674  else:
675  #d0 = ceil(xmin/86400) # day w/first tick mark
676  #d1 = floor(xmax/86400) # day w/last tick mark
677  #nTicks = d1-d0+1
678  #nDays = floor((xmax-xmin)/86400)
679  if options.public:
680  xAxis.SetTimeFormat('%b %d')
681  else:
682  xAxis.SetTimeFormat('#splitline{%b %d}{%H:%M}')
683  xAxis.SetLabelOffset(0.02)
684  xAxis.SetTitleOffset(1.6)
685  if options.lsize:
686  xAxis.SetLabelSize(options.lsize)
687  xAxis.SetTitleSize(options.lsize)
688  yAxis.SetLabelSize(options.lsize)
689  yAxis.SetTitleSize(options.lsize)
690  else:
691  xAxis.SetLabelSize(0.044)
692  if options.adatefmt:
693  xAxis.SetTimeFormat(options.adatefmt)
694  if options.ndivs:
695  xAxis.SetNdivisions(options.ndivs,0)
696  frame.LabelsOption('d','X') # Doesn't seem to work
697 
698  if options.xtitoffset:
699  xAxis.SetTitleOffset(options.xtitoffset)
700  if options.ytitoffset:
701  yAxis.SetTitleOffset(options.ytitoffset)
702 
703  legendList = []
704 
705  # Show average
706  if options.ave:
707  calc.average()
708  dx = (xmax-xmin)/30
709  mean = calc.ave[0]
710  if options.rms:
711  error = calc.rms[0]
712  else:
713  error = calc.err[0]
714  b = ROOTUtils.drawHorizontalBand(xmin+dx,xmax-dx,mean,error,centralLine=True)
715  legendList.append([b,options.alegend,'FL'])
716  legendList.append([None,'%s %s #pm %s %s' % (fmtVal(what,mean,True),varDef(what,'units'),
717  fmtVal(what,error,True),varDef(what,'units')),''])
718 
719  # Loop over graphs for all BCIDs
720  styleFactory = ROOTUtils.StyleFactory()
721  for bcid in sorted(grDict.keys()):
722  gr = grDict[bcid]
723 
724  # Get and save TGraphErrors, if desired
725  name = what if bcid==0 else '%s-bcid%04i' % (what,bcid)
726  tgraph = self.protect( gr.getTGraph(name) )
727  if not tgraph:
728  continue
729  if options.tgraphfile:
730  print ('Saving TGraphErrors',tgraph.GetName(),'to file',options.tgraphfile)
731  tgraphfile = ROOT.TFile(options.tgraphfile,'UPDATE')
732  tgraph.Write()
733  tgraphfile.Close()
734 
735  # Draw data points
736  if len(grDict)==1:
737  tgraph.SetMarkerSize(options.msize if options.msize else 0.8)
738  if options.plegend:
739  legendList.append([tgraph,options.plegend,'PLE'])
740  else:
741  tgraph.SetMarkerColor(styleFactory.nextColorStyle())
742  tgraph.SetMarkerStyle(styleFactory.nextMarkerStyle())
743  tgraph.SetMarkerSize(options.msize if options.msize else 1.2)
744  if len(legendList)<options.maxlegends:
745  text = 'All' if bcid==0 else 'BCID %i' % bcid
746  legendList.append([tgraph,text,'PLE'])
747  tgraph.Draw('P')
748 
749  # Fit data, if desired
750  if options.fit and len(grDict)==1:
751  ROOT.gStyle.SetOptFit(1111)
752  legendList = [] # No legend to avoid crowding plot
753  tgraph.Fit(options.fit,'','SAME', gr.xmin,gr.xmax) #-0.05, 0.05) #ZEBRA
754 
755  # Draw title and legend
756  legendX = 0.6 if len(grDict)==1 else 0.8
757  self.writeText(what,legendList if not options.public else [],not options.public,legendX=legendX)
758 

◆ plotscan() [1/2]

def beamspotnt.Plots.plotscan (   self,
  what 
)
History of variable what vs LB, time or separation.  Additionally overlap the results of more than one scan        


Definition at line 899 of file www/beamspotnt.py.

899  def plotscan(self,what):
900  """History of variable what vs LB, time or separation. Additionally overlap the results of more than one scan
901  """
902 
903  ROOT.gStyle.SetOptStat(0)
904  if options.ave:
905  calc = BeamSpotAverage([what],weightedAverage=not options.simpleaverage)
906  grDict = {}
907 
908  scans = [(int(s.split('-')[0]), int(s.split('-')[1])) for s in options.scans.split(',')]
909 
910  for b in nt:
911 
912  if options.separation and options.overlayScans:
913  try:
914  scanGroup = [s for s in scans if s[0] <= b.lbStart <= s[1]][0]
915  except IndexError:
916  # plB outside of scan ranges
917  continue
918  else:
919  scanGroup = 0
920 
921  if not scanGroup in grDict:
922  grDict[scanGroup] = BeamSpotGraph(timeAxis=options.timeaxis, separationAxis=options.separation)
923  grDict[scanGroup].add(b,what)
924  if options.ave:
925  calc.add(b)
926 
927  print ('Plotting data from %i scans ...\n' % len(grDict))
928 
929  # Determine axis range
930  xmin = 1E10
931  xmax = -1E10
932  ymin = 1E10
933  ymax = -1E10
934  for gr in [grDict.get(scan) for scan in grDict]:
935  xmin = min(xmin,gr.xmin)
936  xmax = max(xmax,gr.xmax)
937  ymin = min(ymin,gr.ymin)
938  ymax = max(ymax,gr.ymax)
939 
940  # Prevent xmin>xmax or ymin>ymax if no succesful fits (but still allow user to override)
941  if xmin>xmax:
942  xmin,xmax=0,1
943  if ymin>ymax:
944  ymin,ymax=0,1
945 
946  h = (xmax-xmin)
947  xmax += .05*h if len(grDict)==1 else 0.3*h
948  xmin -= .05*h
949  h = (ymax-ymin)/2*options.yscale
950  ymax += 1.3*h
951  ymin -= 0.5*h
952  if options.xmin!=None:
953  xmin = time.mktime(time.strptime(options.xmin,'%b %d %H:%M:%S %Y')) if options.timeaxis else float(options.xmin)
954  if options.xmax!=None:
955  xmax = time.mktime(time.strptime(options.xmax,'%b %d %H:%M:%S %Y')) if options.timeaxis else float(options.xmax)
956  if options.ydef:
957  ymin = varDef(what,'min',-100)
958  ymax = varDef(what,'max',+100)
959  if options.ymin!=None:
960  ymin = options.ymin
961  if options.ymax!=None:
962  ymax = options.ymax
963 
964  # Axis settings
965  if options.timeaxis:
966  atit = ';%s;%s' % (timeLabel,varDef(what,'atit',what))
967  elif options.separation:
968  atit = ';%s;%s' % ('Nominal Separation [mm]',varDef(what,'atit',what))
969  else:
970  atit = ';%s;%s' % ('Luminosity block number',varDef(what,'atit',what))
971  frame = ROOTUtils.drawAxisFrame(xmin,xmax,ymin,ymax,atit)
972  if options.logy:
973  ROOT.gPad.SetLogy(options.logy)
974  if options.timeaxis:
975  xAxis = frame.GetXaxis()
976  xAxis.SetTimeDisplay(1)
977  if (xmax-xmin)/86400 < 1:
978  xAxis.SetTimeFormat('%H:%M')
979  else:
980  #d0 = ceil(xmin/86400) # day w/first tick mark
981  #d1 = floor(xmax/86400) # day w/last tick mark
982  #nTicks = d1-d0+1
983  #nDays = floor((xmax-xmin)/86400)
984  xAxis.SetTimeFormat('#splitline{%b %d}{%H:%M}')
985  xAxis.SetLabelOffset(0.025)
986  xAxis.SetTitleOffset(1.6)
987  if options.adatefmt:
988  xAxis.SetTimeFormat(options.adatefmt)
989  if options.ndivs:
990  xAxis.SetNdivisions(options.ndivs,0)
991  frame.LabelsOption('d','X') # Doesn't seem to work
992 
993  legendList = []
994 
995  # Show average
996  if options.ave:
997  calc.average()
998  dx = (xmax-xmin)/30
999  mean = calc.ave[0]
1000  if options.rms:
1001  error = calc.rms[0]
1002  else:
1003  error = calc.err[0]
1004  b = ROOTUtils.drawHorizontalBand(xmin+dx,xmax-dx,mean,error,centralLine=True)
1005  legendList.append([b,options.alegend,'FL'])
1006  legendList.append([None,'%s %s #pm %s %s' % (fmtVal(what,mean,True),varDef(what,'units'),
1007  fmtVal(what,error,True),varDef(what,'units')),''])
1008 
1009  # Loop over graphs for all scans
1010  styleFactory = ROOTUtils.StyleFactory()
1011  for scan in sorted(grDict.keys()):
1012  gr = grDict[scan]
1013 
1014  # Get and save TGraphErrors, if desired
1015  name = what if scan==0 else '%s-scanoverlay' % (what)
1016  tgraph = self.protect( gr.getTGraph(name) )
1017  if not tgraph:
1018  continue
1019  if options.tgraphfile:
1020  print ('Saving TGraphErrors',tgraph.GetName(),'to file',options.tgraphfile)
1021  tgraphfile = ROOT.TFile(options.tgraphfile,'UPDATE')
1022  tgraph.Write()
1023  tgraphfile.Close()
1024 
1025  # Draw data points
1026  if len(grDict)==1:
1027  tgraph.SetMarkerSize(options.msize if options.msize else 0.8)
1028  if options.plegend:
1029  legendList.append([tgraph,options.plegend,'PLE'])
1030  else:
1031  tgraph.SetMarkerColor(styleFactory.nextColorStyle())
1032  tgraph.SetMarkerStyle(styleFactory.nextMarkerStyle())
1033  tgraph.SetMarkerSize(options.msize if options.msize else 1.2)
1034  if len(legendList)<options.maxlegends:
1035  text = 'All' if scan==0 else 'scan %i - %i' % scan
1036  legendList.append([tgraph,text,'PLE'])
1037  tgraph.Draw('P')
1038 
1039  # Indicate if legend incomplete
1040  if len(grDict)>options.maxlegends:
1041  legendList.append([None,'...',''])
1042 
1043  # Fit data, if desired
1044  if options.fit and len(grDict)==1:
1045  ROOT.gStyle.SetOptFit(1111)
1046  legendList = [] # No legend to avoid crowding plot
1047  tgraph.Fit(options.fit,'','SAME',gr.xmin,gr.xmax)
1048 
1049  # Draw title and legend
1050  legendX = 0.6 if len(grDict)==1 else 0.8
1051  self.writeText(what,legendList,not options.public,legendX=legendX)
1052 
1053 
1054 
1055 #
1056 # Dump beam spot ntuple
1057 #

◆ plotscan() [2/2]

def beamspotnt.Plots.plotscan (   self,
  what 
)
History of variable what vs LB, time or separation.  Additionally overlap the results of more than one scan        


Definition at line 902 of file bin/beamspotnt.py.

902  def plotscan(self,what):
903  """History of variable what vs LB, time or separation. Additionally overlap the results of more than one scan
904  """
905 
906  ROOT.gStyle.SetOptStat(0)
907  if options.ave:
908  calc = BeamSpotAverage([what],weightedAverage=not options.simpleaverage)
909  grDict = {}
910 
911  scans = [(int(s.split('-')[0]), int(s.split('-')[1])) for s in options.scans.split(',')]
912 
913  for b in nt:
914 
915  if options.separation and options.overlayScans:
916  try:
917  scanGroup = [s for s in scans if s[0] <= b.lbStart <= s[1]][0]
918  except IndexError:
919  # plB outside of scan ranges
920  continue
921  else:
922  scanGroup = 0
923 
924  if not scanGroup in grDict:
925  grDict[scanGroup] = BeamSpotGraph(timeAxis=options.timeaxis, separationAxis=options.separation)
926  grDict[scanGroup].add(b,what)
927  if options.ave:
928  calc.add(b)
929 
930  print ('Plotting data from %i scans ...\n' % len(grDict))
931 
932  # Determine axis range
933  xmin = 1E10
934  xmax = -1E10
935  ymin = 1E10
936  ymax = -1E10
937  for gr in [grDict.get(scan) for scan in grDict]:
938  xmin = min(xmin,gr.xmin)
939  xmax = max(xmax,gr.xmax)
940  ymin = min(ymin,gr.ymin)
941  ymax = max(ymax,gr.ymax)
942 
943  # Prevent xmin>xmax or ymin>ymax if no succesful fits (but still allow user to override)
944  if xmin>xmax:
945  xmin,xmax=0,1
946  if ymin>ymax:
947  ymin,ymax=0,1
948 
949  h = (xmax-xmin)
950  xmax += .05*h if len(grDict)==1 else 0.3*h
951  xmin -= .05*h
952  h = (ymax-ymin)/2*options.yscale
953  ymax += 1.3*h
954  ymin -= 0.5*h
955  if options.xmin!=None:
956  xmin = time.mktime(time.strptime(options.xmin,'%b %d %H:%M:%S %Y')) if options.timeaxis else float(options.xmin)
957  if options.xmax!=None:
958  xmax = time.mktime(time.strptime(options.xmax,'%b %d %H:%M:%S %Y')) if options.timeaxis else float(options.xmax)
959  if options.ydef:
960  ymin = varDef(what,'min',-100)
961  ymax = varDef(what,'max',+100)
962  if options.ymin!=None:
963  ymin = options.ymin
964  if options.ymax!=None:
965  ymax = options.ymax
966 
967  # Axis settings
968  if options.timeaxis:
969  atit = ';%s;%s' % (timeLabel,varDef(what,'atit',what))
970  elif options.separation:
971  atit = ';%s;%s' % ('Nominal Separation [mm]',varDef(what,'atit',what))
972  else:
973  atit = ';%s;%s' % ('Luminosity block number',varDef(what,'atit',what))
974  frame = ROOTUtils.drawAxisFrame(xmin,xmax,ymin,ymax,atit)
975  if options.logy:
976  ROOT.gPad.SetLogy(options.logy)
977  if options.timeaxis:
978  xAxis = frame.GetXaxis()
979  xAxis.SetTimeDisplay(1)
980  if (xmax-xmin)/86400 < 1:
981  xAxis.SetTimeFormat('%H:%M')
982  else:
983  #d0 = ceil(xmin/86400) # day w/first tick mark
984  #d1 = floor(xmax/86400) # day w/last tick mark
985  #nTicks = d1-d0+1
986  #nDays = floor((xmax-xmin)/86400)
987  xAxis.SetTimeFormat('#splitline{%b %d}{%H:%M}')
988  xAxis.SetLabelOffset(0.025)
989  xAxis.SetTitleOffset(1.6)
990  if options.adatefmt:
991  xAxis.SetTimeFormat(options.adatefmt)
992  if options.ndivs:
993  xAxis.SetNdivisions(options.ndivs,0)
994  frame.LabelsOption('d','X') # Doesn't seem to work
995 
996  legendList = []
997 
998  # Show average
999  if options.ave:
1000  calc.average()
1001  dx = (xmax-xmin)/30
1002  mean = calc.ave[0]
1003  if options.rms:
1004  error = calc.rms[0]
1005  else:
1006  error = calc.err[0]
1007  b = ROOTUtils.drawHorizontalBand(xmin+dx,xmax-dx,mean,error,centralLine=True)
1008  legendList.append([b,options.alegend,'FL'])
1009  legendList.append([None,'%s %s #pm %s %s' % (fmtVal(what,mean,True),varDef(what,'units'),
1010  fmtVal(what,error,True),varDef(what,'units')),''])
1011 
1012  # Loop over graphs for all scans
1013  styleFactory = ROOTUtils.StyleFactory()
1014  for scan in sorted(grDict.keys()):
1015  gr = grDict[scan]
1016 
1017  # Get and save TGraphErrors, if desired
1018  name = what if scan==0 else '%s-scanoverlay' % (what)
1019  tgraph = self.protect( gr.getTGraph(name) )
1020  if not tgraph:
1021  continue
1022  if options.tgraphfile:
1023  print ('Saving TGraphErrors',tgraph.GetName(),'to file',options.tgraphfile)
1024  tgraphfile = ROOT.TFile(options.tgraphfile,'UPDATE')
1025  tgraph.Write()
1026  tgraphfile.Close()
1027 
1028  # Draw data points
1029  if len(grDict)==1:
1030  tgraph.SetMarkerSize(options.msize if options.msize else 0.8)
1031  if options.plegend:
1032  legendList.append([tgraph,options.plegend,'PLE'])
1033  else:
1034  tgraph.SetMarkerColor(styleFactory.nextColorStyle())
1035  tgraph.SetMarkerStyle(styleFactory.nextMarkerStyle())
1036  tgraph.SetMarkerSize(options.msize if options.msize else 1.2)
1037  if len(legendList)<options.maxlegends:
1038  text = 'All' if scan==0 else 'scan %i - %i' % scan
1039  legendList.append([tgraph,text,'PLE'])
1040  tgraph.Draw('P')
1041 
1042  # Indicate if legend incomplete
1043  if len(grDict)>options.maxlegends:
1044  legendList.append([None,'...',''])
1045 
1046  # Fit data, if desired
1047  if options.fit and len(grDict)==1:
1048  ROOT.gStyle.SetOptFit(1111)
1049  legendList = [] # No legend to avoid crowding plot
1050  tgraph.Fit(options.fit,'','SAME',gr.xmin,gr.xmax)
1051 
1052  # Draw title and legend
1053  legendX = 0.6 if len(grDict)==1 else 0.8
1054  self.writeText(what,legendList,not options.public,legendX=legendX)
1055 
1056 
1057 
1058 #
1059 # Dump beam spot ntuple
1060 #

◆ protect()

def ROOTUtils.PlotLibrary.protect (   self,
  obj 
)
inherited
Protect ROOT object from garbage collection.

Definition at line 101 of file roofit/ROOTUtils.py.

101  def protect(self,obj):
102  """Protect ROOT object from garbage collection."""
103  self.rootObjects.append(obj)
104  return obj
105 

◆ pull() [1/2]

def beamspotnt.Plots.pull (   self,
  what 
)
Pull histogram of variable what.

what must be of the form name:value, where value is the
correct value of variable name.

Definition at line 550 of file www/beamspotnt.py.

550  def pull(self,what):
551  """Pull histogram of variable what.
552 
553  what must be of the form name:value, where value is the
554  correct value of variable name."""
555  try:
556  (what,value) = what.split(':')
557  value = float(value)
558  except:
559  print(('ERROR: Illegal input %s for pull variable - must be of the form NAME:VALUE' % what))
560  return
561  ROOT.gStyle.SetOptStat(options.optstat)
562  title = ';Pull'
563  nBins = options.nbins if options.nbins else varDef(what,'nBins',100)
564  xmin = float(options.xmin) if options.xmin!=None else -4.
565  xmax = float(options.xmax) if options.xmax!=None else +4.
566  h = self.protect( ROOT.TH1F(what,title,nBins,xmin,xmax) )
567  if options.fit:
568  h.Sumw2()
569  h.GetYaxis().SetTitle('Number of fit results')
570  whatErr = what+'Err'
571  try:
572  for b in nt:
573  h.Fill((getattr(b,what)-value)/getattr(b,whatErr))
574  except Exception as e:
575  print ('ERROR filling histogram:',str(e))
576  h.Draw()
577  if options.fit:
578  ROOT.gStyle.SetOptFit(1111)
579  h.Fit(options.fit,options.optfit)
580  if options.logy:
581  ROOT.gPad.SetLogy(options.logy)
582  if options.ndivs:
583  h.GetXaxis().SetNdivisions(options.ndivs,0)
584  if options.mc:
585  self.writeText(what,[],False,False,False)
586  else:
587  self.writeText(what,[],not options.public,options.public)
588 

◆ pull() [2/2]

def beamspotnt.Plots.pull (   self,
  what 
)
Pull histogram of variable what.

what must be of the form name:value, where value is the
correct value of variable name.

Definition at line 557 of file bin/beamspotnt.py.

557  def pull(self,what):
558  """Pull histogram of variable what.
559 
560  what must be of the form name:value, where value is the
561  correct value of variable name."""
562  try:
563  (what,value) = what.split(':')
564  value = float(value)
565  except:
566  print(('ERROR: Illegal input %s for pull variable - must be of the form NAME:VALUE' % what))
567  return
568  ROOT.gStyle.SetOptStat(options.optstat)
569  title = ';Pull'
570  nBins = options.nbins if options.nbins else varDef(what,'nBins',100)
571  xmin = float(options.xmin) if options.xmin!=None else -4.
572  xmax = float(options.xmax) if options.xmax!=None else +4.
573  h = self.protect( ROOT.TH1F(what,title,nBins,xmin,xmax) )
574  if options.fit:
575  h.Sumw2()
576  h.GetYaxis().SetTitle('Number of fit results')
577  whatErr = what+'Err'
578  try:
579  for b in nt:
580  h.Fill((getattr(b,what)-value)/getattr(b,whatErr))
581  except Exception as e:
582  print ('ERROR filling histogram:',str(e))
583  h.Draw()
584  if options.fit:
585  ROOT.gStyle.SetOptFit(1111)
586  h.Fit(options.fit,options.optfit)
587  if options.logy:
588  ROOT.gPad.SetLogy(options.logy)
589  if options.ndivs:
590  h.GetXaxis().SetNdivisions(options.ndivs,0)
591  if options.mc:
592  self.writeText(what,[],False,False,False)
593  else:
594  self.writeText(what,[],not options.public,options.public)
595 

◆ vsBunchPos() [1/2]

def beamspotnt.Plots.vsBunchPos (   self,
  what 
)
Variable what vs bunch position in train.

Definition at line 828 of file www/beamspotnt.py.

828  def vsBunchPos(self,what):
829  """Variable what vs bunch position in train."""
830  ROOT.gStyle.SetOptStat(0)
831 
832  lastb = -999
833  startb = -999
834  calcmap = {}
835  bunchnrs = []
836  trainGap = 36
837 
838  for b in nt:
839  if b.bcid - lastb > trainGap:
840  startb = b.bcid
841 
842  lastb = b.bcid
843  bunchnumber = b.bcid - startb
844 
845  if bunchnumber in calcmap:
846  calcmap[bunchnumber].add(b)
847  else:
848  calcmap[bunchnumber] = BeamSpotAverage([what], weightedAverage = not options.simpleaverage)
849  bunchnrs.append(bunchnumber)
850 
851  gr = self.protect( ROOT.TGraphErrors(len(bunchnrs)))
852  counter = 0
853  xmin = -10
854  xmax = 1
855  ymin = 1e9
856  ymax = -1e9
857 
858  for bunchnr in bunchnrs:
859  calcmap[bunchnr].average()
860  gr.SetPoint(counter, bunchnr, calcmap[bunchnr].ave[0])
861  gr.SetPointError(counter, 0.5, calcmap[bunchnr].err[0])
862  xmax = max(xmax, bunchnr)
863  ymin = min(ymin, calcmap[bunchnr].ave[0])
864  ymax = max(ymax, calcmap[bunchnr].ave[0])
865  counter += 1
866 
867  if xmin>xmax:
868  xmin,xmax=0,1
869  if ymin>ymax:
870  ymin,ymax=0,1
871 
872  xmax = xmax + 10
873  h = (ymax - ymin)/2*options.yscale
874  ymax += 2.0*h
875  ymin -= 1.0*h
876 
877  if options.xmin != None:
878  xmin = options.xmin
879  if options.xmax != None:
880  xmax = options.xmax
881  if options.ymin != None:
882  ymin = options.ymin
883  if options.ymax != None:
884  ymax = options.ymax
885 
886  gr.SetMarkerSize(options.msize if options.msize else 0.8)
887 
888  atit = ';%s;%s' % ('Bunch position in train',varDef(what,'atit',what))
889  frame = ROOTUtils.drawAxisFrame(xmin,xmax,ymin,ymax,atit)
890  if gr.GetN() == 0:
891  return
892 
893  legendList = []
894  if options.plegend:
895  legendList.append([gr,options.plegend,'PLE'])
896  gr.Draw('P')
897  self.writeText(what,legendList,not options.public)
898 

◆ vsBunchPos() [2/2]

def beamspotnt.Plots.vsBunchPos (   self,
  what 
)
Variable what vs bunch position in train.

Definition at line 831 of file bin/beamspotnt.py.

831  def vsBunchPos(self,what):
832  """Variable what vs bunch position in train."""
833  ROOT.gStyle.SetOptStat(0)
834 
835  lastb = -999
836  startb = -999
837  calcmap = {}
838  bunchnrs = []
839  trainGap = 36
840 
841  for b in nt:
842  if b.bcid - lastb > trainGap:
843  startb = b.bcid
844 
845  lastb = b.bcid
846  bunchnumber = b.bcid - startb
847 
848  if bunchnumber in calcmap:
849  calcmap[bunchnumber].add(b)
850  else:
851  calcmap[bunchnumber] = BeamSpotAverage([what], weightedAverage = not options.simpleaverage)
852  bunchnrs.append(bunchnumber)
853 
854  gr = self.protect( ROOT.TGraphErrors(len(bunchnrs)))
855  counter = 0
856  xmin = -10
857  xmax = 1
858  ymin = 1e9
859  ymax = -1e9
860 
861  for bunchnr in bunchnrs:
862  calcmap[bunchnr].average()
863  gr.SetPoint(counter, bunchnr, calcmap[bunchnr].ave[0])
864  gr.SetPointError(counter, 0.5, calcmap[bunchnr].err[0])
865  xmax = max(xmax, bunchnr)
866  ymin = min(ymin, calcmap[bunchnr].ave[0])
867  ymax = max(ymax, calcmap[bunchnr].ave[0])
868  counter += 1
869 
870  if xmin>xmax:
871  xmin,xmax=0,1
872  if ymin>ymax:
873  ymin,ymax=0,1
874 
875  xmax = xmax + 10
876  h = (ymax - ymin)/2*options.yscale
877  ymax += 2.0*h
878  ymin -= 1.0*h
879 
880  if options.xmin != None:
881  xmin = options.xmin
882  if options.xmax != None:
883  xmax = options.xmax
884  if options.ymin != None:
885  ymin = options.ymin
886  if options.ymax != None:
887  ymax = options.ymax
888 
889  gr.SetMarkerSize(options.msize if options.msize else 0.8)
890 
891  atit = ';%s;%s' % ('Bunch position in train',varDef(what,'atit',what))
892  frame = ROOTUtils.drawAxisFrame(xmin,xmax,ymin,ymax,atit)
893  if gr.GetN() == 0:
894  return
895 
896  legendList = []
897  if options.plegend:
898  legendList.append([gr,options.plegend,'PLE'])
899  gr.Draw('P')
900  self.writeText(what,legendList,not options.public)
901 

◆ writeText() [1/2]

def beamspotnt.Plots.writeText (   self,
  var,
  legendList = [],
  showRuns = True,
  showFills = True,
  showTime = True,
  otherTitle = None,
  otherComment = None,
  legendX = 0.6 
)

Definition at line 416 of file www/beamspotnt.py.

416  def writeText(self, var, legendList=[],
417  showRuns=True, showFills=True, showTime=True, otherTitle=None, otherComment=None,
418  legendX=0.6):
419  # Title and comment lines with optional run, fill and time/date info
420  if otherTitle!=None:
421  self.protect( ROOTUtils.drawText(0.2,0.86,0.06,otherTitle) )
422  else:
423  title = options.title or varDef(var,'title',var)
424  self.protect( ROOTUtils.drawText(0.2,0.86,0.06,title) )
425  comments = []
426  if otherComment:
427  comments.append(otherComment)
428  if options.comment:
429  comments.append(options.comment)
430  if showRuns and not options.omitrun:
431  if self.nt.selRunMin==self.nt.selRunMax:
432  comments.append('Run %i' % self.nt.selRunMin)
433  else:
434  comments.append('Runs %i - %i' % (self.nt.selRunMin,self.nt.selRunMax))
435  if showFills and not options.omitfill:
436  if self.nt.selFillMin==self.nt.selFillMax:
437  comments.append('Fill %i' % self.nt.selFillMin)
438  else:
439  comments.append('Fills %i - %i' % (self.nt.selFillMin,self.nt.selFillMax))
440  if showTime and not options.omittime:
441  if options.public:
442  t1 = time.strftime(options.datefmt,time.localtime(self.nt.selTimeMin))
443  t2 = time.strftime(options.datefmt,time.localtime(self.nt.selTimeMax))
444  else:
445  t1 = time.strftime(options.datefmt,time.localtime(self.nt.selTimeMin))
446  t2 = time.strftime(options.datefmt,time.localtime(self.nt.selTimeMax))
447  if t1==t2:
448  comments.append(t1)
449  else:
450  comments.append('%s - %s' % (t1,t2))
451 
452  self.protect( ROOTUtils.drawText(0.2,0.79,0.06,';'.join(comments),font=42) )
453  # ATLAS (preliminary) label
454  logoSize = options.lsize if options.lsize else 0.5
455  if options.prelim:
456  ROOTUtils.atlasLabel(options.atlasx,options.atlasy,True,offset=options.atlasdx,energy=options.energy,size=logoSize)
457  if options.approval:
458  ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,isForApproval=True,energy=options.energy,size=logoSize)
459  if options.published:
460  ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,energy=options.energy,size=logoSize)
461  if options.customlabel!="":
462  ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,isForApproval=False,customstring=options.customlabel,energy=options.energy,size=logoSize)
463  # Legend
464  if legendList:
465  legendMinY = max(0.91-0.07*len(legendList),0.2)
466  self.protect( ROOTUtils.drawLegend(legendX,legendMinY,0.92,0.91,legendList) )
467 

◆ writeText() [2/2]

def beamspotnt.Plots.writeText (   self,
  var,
  legendList = [],
  showRuns = True,
  showFills = True,
  showTime = True,
  otherTitle = None,
  otherComment = None,
  legendX = 0.6 
)

Definition at line 423 of file bin/beamspotnt.py.

423  def writeText(self, var, legendList=[],
424  showRuns=True, showFills=True, showTime=True, otherTitle=None, otherComment=None,
425  legendX=0.6):
426  # Title and comment lines with optional run, fill and time/date info
427  if otherTitle!=None:
428  self.protect( ROOTUtils.drawText(0.2,0.86,0.06,otherTitle) )
429  else:
430  title = options.title or varDef(var,'title',var)
431  self.protect( ROOTUtils.drawText(0.2,0.86,0.06,title) )
432  comments = []
433  if otherComment:
434  comments.append(otherComment)
435  if options.comment:
436  comments.append(options.comment)
437  if showRuns and not options.omitrun:
438  if self.nt.selRunMin==self.nt.selRunMax:
439  comments.append('Run %i' % self.nt.selRunMin)
440  else:
441  comments.append('Runs %i - %i' % (self.nt.selRunMin,self.nt.selRunMax))
442  if showFills and not options.omitfill:
443  if self.nt.selFillMin==self.nt.selFillMax:
444  comments.append('Fill %i' % self.nt.selFillMin)
445  else:
446  comments.append('Fills %i - %i' % (self.nt.selFillMin,self.nt.selFillMax))
447  if showTime and not options.omittime:
448  if options.public:
449  t1 = time.strftime(options.datefmt,time.localtime(self.nt.selTimeMin))
450  t2 = time.strftime(options.datefmt,time.localtime(self.nt.selTimeMax))
451  else:
452  t1 = time.strftime(options.datefmt,time.localtime(self.nt.selTimeMin))
453  t2 = time.strftime(options.datefmt,time.localtime(self.nt.selTimeMax))
454  if t1==t2:
455  comments.append(t1)
456  else:
457  comments.append('%s - %s' % (t1,t2))
458 
459  self.protect( ROOTUtils.drawText(0.2,0.79,0.06,';'.join(comments),font=42) )
460  # ATLAS (preliminary) label
461  logoSize = options.lsize if options.lsize else 0.5
462  if options.prelim:
463  ROOTUtils.atlasLabel(options.atlasx,options.atlasy,True,offset=options.atlasdx,energy=options.energy,size=logoSize)
464  if options.approval:
465  ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,isForApproval=True,energy=options.energy,size=logoSize)
466  if options.published:
467  ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,energy=options.energy,size=logoSize)
468  if options.customlabel!="":
469  ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,isForApproval=False,customstring=options.customlabel,energy=options.energy,size=logoSize)
470  # Legend
471  if legendList:
472  legendMinY = max(0.91-0.07*len(legendList),0.2)
473  self.protect( ROOTUtils.drawLegend(legendX,legendMinY,0.92,0.91,legendList) )
474 

Member Data Documentation

◆ allCanvasDivs

ROOTUtils.PlotLibrary.allCanvasDivs
inherited

Definition at line 97 of file roofit/ROOTUtils.py.

◆ allCanvasSize

ROOTUtils.PlotLibrary.allCanvasSize
inherited

Definition at line 96 of file roofit/ROOTUtils.py.

◆ gPadSaveAsList

ROOTUtils.PlotLibrary.gPadSaveAsList
inherited

Definition at line 99 of file roofit/ROOTUtils.py.

◆ name

ROOTUtils.PlotLibrary.name
inherited

Definition at line 88 of file roofit/ROOTUtils.py.

◆ nt

beamspotnt.Plots.nt

Definition at line 420 of file bin/beamspotnt.py.

◆ otherMethods

ROOTUtils.PlotLibrary.otherMethods
inherited

Definition at line 89 of file roofit/ROOTUtils.py.

◆ rootObjects

ROOTUtils.PlotLibrary.rootObjects
inherited

Definition at line 91 of file roofit/ROOTUtils.py.

◆ saveAsList

ROOTUtils.PlotLibrary.saveAsList
inherited

Definition at line 98 of file roofit/ROOTUtils.py.

◆ singleCanvasSize

ROOTUtils.PlotLibrary.singleCanvasSize
inherited

Definition at line 95 of file roofit/ROOTUtils.py.

◆ whatList

beamspotnt.Plots.whatList

Definition at line 421 of file bin/beamspotnt.py.


The documentation for this class was generated from the following file:
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
max
#define max(a, b)
Definition: cfImp.cxx:41
drawFromPickle.average
def average(lst)
Definition: drawFromPickle.py:38
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
plotBeamSpotCompare.varDef
dictionary varDef
Definition: plotBeamSpotCompare.py:25
ROOTUtils.drawAxisFrame
def drawAxisFrame(xmin, xmax, ymin, ymax, title='', xTitleOffset=None, yTitleOffset=None, doPlot=True, protectFrame=True)
Definition: roofit/ROOTUtils.py:213
plotmaker.hist
hist
Definition: plotmaker.py:148
ROOTUtils.protect
def protect(obj)
Definition: roofit/ROOTUtils.py:17
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
python.BeamSpotData.fmtVal
def fmtVal(var, value, strip=False, useAlternate=False)
Definition: BeamSpotData.py:248
ROOTUtils.drawHorizontalBand
def drawHorizontalBand(xmin, xmax, y, ywidth, color=33, protectBand=True, centralLine=False)
Definition: roofit/ROOTUtils.py:227
python.StandardJetMods.pull
pull
Definition: StandardJetMods.py:282
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
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
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
ROOTUtils.PlotLibrary.__init__
def __init__(self, name='MyPlots', otherMethods=[])
Definition: roofit/ROOTUtils.py:85
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
plot
bool plot
Definition: listroot.cxx:44
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
ROOTUtils.drawLegend
def drawLegend(x1, y1, x2, y2, legendList=[], fillColor=0, lineColor=0, textSize=None, protectLegend=True)
Definition: roofit/ROOTUtils.py:259
readCCLHist.float
float
Definition: readCCLHist.py:83
ROOTUtils.StyleFactory
Definition: roofit/ROOTUtils.py:171