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 415 of file bin/beamspotnt.py.

Constructor & Destructor Documentation

◆ __init__() [1/2]

def beamspotnt.Plots.__init__ (   self,
  nt 
)

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

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

◆ __init__() [2/2]

def beamspotnt.Plots.__init__ (   self,
  nt 
)

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

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

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 467 of file www/beamspotnt.py.

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

◆ 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 474 of file bin/beamspotnt.py.

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

◆ 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 508 of file www/beamspotnt.py.

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

◆ 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 515 of file bin/beamspotnt.py.

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

◆ perbcid() [1/2]

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

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

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

◆ perbcid() [2/2]

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

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

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

◆ 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 588 of file www/beamspotnt.py.

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

◆ plot() [3/3]

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

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

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

◆ 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 898 of file www/beamspotnt.py.

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

◆ 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 901 of file bin/beamspotnt.py.

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

◆ 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 549 of file www/beamspotnt.py.

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

◆ 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 556 of file bin/beamspotnt.py.

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

◆ vsBunchPos() [1/2]

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

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

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

◆ vsBunchPos() [2/2]

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

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

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

◆ 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 415 of file www/beamspotnt.py.

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

◆ 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 422 of file bin/beamspotnt.py.

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

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 419 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 420 of file bin/beamspotnt.py.


The documentation for this class was generated from the following file:
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.
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
drawFromPickle.average
def average(lst)
Definition: drawFromPickle.py:38
plotBeamSpotCompare.varDef
dictionary varDef
Definition: plotBeamSpotCompare.py:24
ROOTUtils.drawAxisFrame
def drawAxisFrame(xmin, xmax, ymin, ymax, title='', xTitleOffset=None, yTitleOffset=None, doPlot=True, protectFrame=True)
Definition: roofit/ROOTUtils.py:213
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
plotmaker.hist
hist
Definition: plotmaker.py:148
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
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:305
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
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
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
plot
bool plot
Definition: listroot.cxx:44
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
ROOTUtils.StyleFactory
Definition: roofit/ROOTUtils.py:171
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65