CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
plotting.Plot Class Reference

Public Member Functions

def __init__
 
def addToLegend
 
def create
 
def draw
 
def drawRatioUncertainty
 
def getName
 
def getNumberOfHistograms
 
def isEmpty
 
def isTGraph2D
 

Private Member Functions

def _calculateRatios
 
def _createOne
 
def _normalize
 
def _setStats
 

Private Attributes

 _binOffset
 
 _forLegend
 
 _frame
 
 _gr
 
 _histograms
 
 _name
 
 _ratio
 
 _ratios
 
 _th1
 
 _uncertainty
 
 _xerrshigh
 
 _xerrslow
 
 _xvalues
 
 _yerrshigh
 
 _yerrslow
 
 _yvalues
 

Detailed Description

Represents one plot, comparing one or more histograms.

Definition at line 782 of file plotting.py.

Constructor & Destructor Documentation

def plotting.Plot.__init__ (   self,
  name,
  kwargs 
)
Constructor.

Arguments:
name -- String for name of the plot, or Efficiency object

Keyword arguments:
title        -- String for a title of the plot (default None)
xtitle       -- String for x axis title (default None)
xtitlesize   -- Float for x axis title size (default None)
xtitleoffset -- Float for x axis title offset (default None)
xlabelsize   -- Float for x axis label size (default None)
ytitle       -- String for y axis title (default None)
ytitlesize   -- Float for y axis title size (default None)
ytitleoffset -- Float for y axis title offset (default None)
ztitle       -- String for z axis title (default None)
ztitleoffset -- Float for z axis title offset (default None)
xmin         -- Float for x axis minimum (default None, i.e. automatic)
xmax         -- Float for x axis maximum (default None, i.e. automatic)
ymin         -- Float for y axis minimum (default 0)
ymax         -- Float for y axis maximum (default None, i.e. automatic)
xlog         -- Bool for x axis log status (default False)
ylog         -- Bool for y axis log status (default False)
xgrid        -- Bool for x axis grid status (default True)
ygrid        -- Bool for y axis grid status (default True)
stat         -- Draw stat box? (default False)
fit          -- Do gaussian fit? (default False)
statx        -- Stat box x coordinate (default 0.65)
staty        -- Stat box y coordinate (default 0.8)
statyadjust  -- List of floats for stat box y coordinate adjustments (default None)
normalizeToUnitArea -- Normalize histograms to unit area? (default False)
profileX     -- Take histograms via ProfileX()? (default False)
fitSlicesY   -- Take histograms via FitSlicesY() (default False)
rebinX       -- rebin x axis (default None)
scale        -- Scale histograms by a number (default None)
xbinlabels   -- List of x axis bin labels (if given, default None)
xbinlabelsize -- Size of x axis bin labels (default None)
xbinlabeloption -- Option string for x axis bin labels (default None)
drawStyle    -- If "hist", draw as line instead of points (default None)
drawCommand  -- Deliver this to Draw() (default: None for same as drawStyle)
lineWidth    -- If drawStyle=="hist", the width of line (default 2)
legendDx     -- Float for moving TLegend in x direction for separate=True (default None)
legendDy     -- Float for moving TLegend in y direction for separate=True (default None)
legendDw     -- Float for changing TLegend width for separate=True (default None)
legendDh     -- Float for changing TLegend height for separate=True (default None)
adjustMarginRight  -- Float for adjusting right margin (default None)
ratioYmin    -- Float for y axis minimum in ratio pad (default 0.9)
ratioYmax    -- Float for y axis maximum in ratio pad (default 1.1)
ratioUncertainty -- Plot uncertainties on ratio? (default True)
histogramModifier -- Function to be called in create() to modify the histograms (default None)

Definition at line 784 of file plotting.py.

Referenced by plotting.Plot._calculateRatios().

785  def __init__(self, name, **kwargs):
786  """ Constructor.
787 
788  Arguments:
789  name -- String for name of the plot, or Efficiency object
790 
791  Keyword arguments:
792  title -- String for a title of the plot (default None)
793  xtitle -- String for x axis title (default None)
794  xtitlesize -- Float for x axis title size (default None)
795  xtitleoffset -- Float for x axis title offset (default None)
796  xlabelsize -- Float for x axis label size (default None)
797  ytitle -- String for y axis title (default None)
798  ytitlesize -- Float for y axis title size (default None)
799  ytitleoffset -- Float for y axis title offset (default None)
800  ztitle -- String for z axis title (default None)
801  ztitleoffset -- Float for z axis title offset (default None)
802  xmin -- Float for x axis minimum (default None, i.e. automatic)
803  xmax -- Float for x axis maximum (default None, i.e. automatic)
804  ymin -- Float for y axis minimum (default 0)
805  ymax -- Float for y axis maximum (default None, i.e. automatic)
806  xlog -- Bool for x axis log status (default False)
807  ylog -- Bool for y axis log status (default False)
808  xgrid -- Bool for x axis grid status (default True)
809  ygrid -- Bool for y axis grid status (default True)
810  stat -- Draw stat box? (default False)
811  fit -- Do gaussian fit? (default False)
812  statx -- Stat box x coordinate (default 0.65)
813  staty -- Stat box y coordinate (default 0.8)
814  statyadjust -- List of floats for stat box y coordinate adjustments (default None)
815  normalizeToUnitArea -- Normalize histograms to unit area? (default False)
816  profileX -- Take histograms via ProfileX()? (default False)
817  fitSlicesY -- Take histograms via FitSlicesY() (default False)
818  rebinX -- rebin x axis (default None)
819  scale -- Scale histograms by a number (default None)
820  xbinlabels -- List of x axis bin labels (if given, default None)
821  xbinlabelsize -- Size of x axis bin labels (default None)
822  xbinlabeloption -- Option string for x axis bin labels (default None)
823  drawStyle -- If "hist", draw as line instead of points (default None)
824  drawCommand -- Deliver this to Draw() (default: None for same as drawStyle)
825  lineWidth -- If drawStyle=="hist", the width of line (default 2)
826  legendDx -- Float for moving TLegend in x direction for separate=True (default None)
827  legendDy -- Float for moving TLegend in y direction for separate=True (default None)
828  legendDw -- Float for changing TLegend width for separate=True (default None)
829  legendDh -- Float for changing TLegend height for separate=True (default None)
830  adjustMarginRight -- Float for adjusting right margin (default None)
831  ratioYmin -- Float for y axis minimum in ratio pad (default 0.9)
832  ratioYmax -- Float for y axis maximum in ratio pad (default 1.1)
833  ratioUncertainty -- Plot uncertainties on ratio? (default True)
834  histogramModifier -- Function to be called in create() to modify the histograms (default None)
835  """
836  self._name = name
837 
838  def _set(attr, default):
839  setattr(self, "_"+attr, kwargs.get(attr, default))
840 
841  _set("title", None)
842  _set("xtitle", None)
843  _set("xtitlesize", None)
844  _set("xtitleoffset", None)
845  _set("xlabelsize", None)
846  _set("ytitle", None)
847  _set("ytitlesize", None)
848  _set("ytitleoffset", None)
849  _set("ztitle", None)
850  _set("ztitleoffset", None)
851 
852  _set("xmin", None)
853  _set("xmax", None)
854  _set("ymin", 0.)
855  _set("ymax", None)
856 
857  _set("xlog", False)
858  _set("ylog", False)
859  _set("xgrid", True)
860  _set("ygrid", True)
861 
862  _set("stat", False)
863  _set("fit", False)
864 
865  _set("statx", 0.65)
866  _set("staty", 0.8)
867  _set("statyadjust", None)
868 
869  _set("normalizeToUnitArea", False)
870  _set("profileX", False)
871  _set("fitSlicesY", False)
872  _set("rebinX", None)
873 
874  _set("scale", None)
875  _set("xbinlabels", None)
876  _set("xbinlabelsize", None)
877  _set("xbinlabeloption", None)
878 
879  _set("drawStyle", None)
880  _set("drawCommand", None)
881  _set("lineWidth", 2)
882 
883  _set("legendDx", None)
884  _set("legendDy", None)
885  _set("legendDw", None)
886  _set("legendDh", None)
887 
888  _set("adjustMarginRight", None)
889 
890  _set("ratioYmin", 0.9)
891  _set("ratioYmax", 1.1)
892  _set("ratioUncertainty", True)
893 
894  _set("histogramModifier", None)
896  self._histograms = []

Member Function Documentation

def plotting.Plot._calculateRatios (   self,
  histos 
)
private
Calculate the ratios for a list of histograms

Definition at line 1196 of file plotting.py.

References plotting.Plot.__init__().

1197  def _calculateRatios(self, histos):
1198  """Calculate the ratios for a list of histograms"""
1199 
1200  def _divideOrZero(numerator, denominator):
1201  if denominator == 0:
1202  return 0
1203  return numerator/denominator
1204 
1205  # Define wrappers for TH1/TGraph/TGraph2D to have uniform interface
1206  # TODO: having more global wrappers would make some things simpler also elsewhere in the code
1207  class WrapTH1:
1208  def __init__(self, th1, uncertainty):
1209  self._th1 = th1
1210  self._uncertainty = uncertainty
1211 
1212  xaxis = th1.GetXaxis()
1213  xaxis_arr = xaxis.GetXbins()
1214  if xaxis_arr.GetSize() > 0: # unequal binning
1215  lst = [xaxis_arr[i] for i in xrange(0, xaxis_arr.GetSize())]
1216  arr = array.array("d", lst)
1217  self._ratio = ROOT.TH1F("foo", "foo", xaxis.GetNbins(), arr)
1218  else:
1219  self._ratio = ROOT.TH1F("foo", "foo", xaxis.GetNbins(), xaxis.GetXmin(), xaxis.GetXmax())
1220  _copyStyle(th1, self._ratio)
1221  self._ratio.SetStats(0)
1222  self._ratio.SetLineColor(ROOT.kBlack)
1223  self._ratio.SetLineWidth(1)
1224  def draw(self, style=None):
1225  st = style
1226  if st is None:
1227  if self._uncertainty:
1228  st = "EP"
1229  else:
1230  st = "HIST P"
1231  self._ratio.Draw("same "+st)
1232  def begin(self):
1233  return 1
1234  def end(self):
1235  return self._th1.GetNbinsX()+1
1236  def xvalues(self, bin):
1237  xval = self._th1.GetBinCenter(bin)
1238  xlow = xval-self._th1.GetXaxis().GetBinLowEdge(bin)
1239  xhigh = self._th1.GetXaxis().GetBinUpEdge(bin)-xval
1240  return (xval, xlow, xhigh)
1241  def yvalues(self, bin):
1242  yval = self._th1.GetBinContent(bin)
1243  yerr = self._th1.GetBinError(bin)
1244  return (yval, yerr, yerr)
1245  def y(self, bin):
1246  return self._th1.GetBinContent(bin)
1247  def divide(self, bin, scale, xcenter):
1248  self._ratio.SetBinContent(bin, _divideOrZero(self._th1.GetBinContent(bin), scale))
1249  self._ratio.SetBinError(bin, _divideOrZero(self._th1.GetBinError(bin), scale))
1250  def makeRatio(self):
1251  pass
1252 
1253  class WrapTGraph:
1254  def __init__(self, gr, uncertainty):
1255  self._gr = gr
1256  self._uncertainty = uncertainty
1257  self._xvalues = []
1258  self._xerrslow = []
1259  self._xerrshigh = []
1260  self._yvalues = []
1261  self._yerrshigh = []
1262  self._yerrslow = []
1263  self._binOffset = 0
1264  def draw(self, style=None):
1265  if self._ratio is None:
1266  return
1267  st = style
1268  if st is None:
1269  if self._uncertainty:
1270  st = "PZ"
1271  else:
1272  st = "PX"
1273  self._ratio.Draw("same "+st)
1274  def begin(self):
1275  return 0
1276  def end(self):
1277  return self._gr.GetN()
1278  def xvalues(self, bin):
1279  return (self._gr.GetX()[bin], self._gr.GetErrorXlow(bin), self._gr.GetErrorXhigh(bin))
1280  def yvalues(self, bin):
1281  return (self._gr.GetY()[bin], self._gr.GetErrorYlow(bin), self._gr.GetErrorYhigh(bin))
1282  def y(self, bin):
1283  return self._gr.GetY()[bin]
1284  def divide(self, bin, scale, xcenter):
1285  # Ignore bin if denominator is zero
1286  if scale == 0:
1287  return
1288  # No more items in the numerator
1289  if bin >= self._gr.GetN():
1290  return
1291  # denominator is missing an item
1292  trueBin = bin + self._binOffset
1293  xvals = self.xvalues(trueBin)
1294  xval = xvals[0]
1295  epsilon = 1e-3 * xval # to allow floating-point difference between TGraph and TH1
1296  if xval+epsilon < xcenter:
1297  self._binOffset += 1
1298  return
1299  # numerator is missing an item
1300  elif xval-epsilon > xcenter:
1301  self._binOffset -= 1
1302  return
1303 
1304  self._xvalues.append(xval)
1305  self._xerrslow.append(xvals[1])
1306  self._xerrshigh.append(xvals[2])
1307  yvals = self.yvalues(trueBin)
1308  self._yvalues.append(yvals[0] / scale)
1309  if self._uncertainty:
1310  self._yerrslow.append(yvals[1] / scale)
1311  self._yerrshigh.append(yvals[2] / scale)
1312  else:
1313  self._yerrslow.append(0)
1314  self._yerrshigh.append(0)
1315  def makeRatio(self):
1316  if len(self._xvalues) == 0:
1317  self._ratio = None
1318  return
1319  self._ratio = ROOT.TGraphAsymmErrors(len(self._xvalues), array.array("d", self._xvalues), array.array("d", self._yvalues),
1320  array.array("d", self._xerrslow), array.array("d", self._xerrshigh),
1321  array.array("d", self._yerrslow), array.array("d", self._yerrshigh))
1322  _copyStyle(self._gr, self._ratio)
1323  class WrapTGraph2D(WrapTGraph):
1324  def __init__(self, gr, uncertainty):
1325  WrapTGraph.__init__(self, gr, uncertainty)
1326  def xvalues(self, bin):
1327  return (self._gr.GetX()[bin], self._gr.GetErrorX(bin), self._gr.GetErrorX(bin))
1328  def yvalues(self, bin):
1329  return (self._gr.GetY()[bin], self._gr.GetErrorY(bin), self._gr.GetErrorY(bin))
1330 
1331  def wrap(o):
1332  if isinstance(o, ROOT.TH1):
1333  return WrapTH1(o, self._ratioUncertainty)
1334  elif isinstance(o, ROOT.TGraph):
1335  return WrapTGraph(o, self._ratioUncertainty)
1336  elif isinstance(o, ROOT.TGraph2D):
1337  return WrapTGraph2D(o, self._ratioUncertainty)
1338 
1339  wrappers = [wrap(h) for h in histos]
1340  ref = wrappers[0]
1341 
1342  for bin in xrange(ref.begin(), ref.end()):
1343  (scale, ylow, yhigh) = ref.yvalues(bin)
1344  (xval, xlow, xhigh) = ref.xvalues(bin)
1345  for w in wrappers:
1346  w.divide(bin, scale, xval)
1347 
1348  for w in wrappers:
1349  w.makeRatio()
1350 
1351  return wrappers
#define end
Definition: vmac.h:37
def _copyStyle
Definition: plotting.py:770
#define begin
Definition: vmac.h:30
def _calculateRatios
Definition: plotting.py:1196
auto wrap(F iFunc) -> decltype(iFunc())
def plotting.Plot._createOne (   self,
  index,
  tdir 
)
private
Create one histogram from a TDirectory.

Definition at line 921 of file plotting.py.

References plotting._getOrCreateObject(), TrackerHitsObject._name, FP420HitsObject._name, PGeometricDet::Item._name, LikelihoodSpecies._name, LikelihoodPdfProduct._name, LikelihoodPdf._name, citk::IsolationConeDefinitionBase._name, DrellYanValidation._name, WValidation._name, HistoParams< T >._name, CutApplicatorBase._name, ElectronMVAEstimatorRun2Phys14NonTrig._name, PhotonMVAEstimatorRun2Spring15NonTrig._name, PhotonMVAEstimatorRun2Phys14NonTrig._name, GeometricDetExtra._name, ElectronMVAEstimatorRun2Spring15Trig._name, ElectronMVAEstimatorRun2Spring15NonTrig._name, HistoParams< TH2F >._name, plotting.Subtract._name, HistoParams< TProfile2D >._name, plotting.FakeDuplicate._name, plotting.AggregateBins._name, plotting.AggregateHistos._name, plotting.ROC._name, Vispa.Views.PropertyView.Property._name, SequenceTypes.SequencePlaceholder._name, and plotting.Plot._name.

Referenced by plotting.Plot.create().

922  def _createOne(self, index, tdir):
923  """Create one histogram from a TDirectory."""
924  if tdir == None:
925  return None
926 
927  # If name is a list, pick the name by the index
928  if isinstance(self._name, list):
929  name = self._name[index]
930  else:
931  name = self._name
932 
933  return _getOrCreateObject(tdir, name)
def _createOne
Definition: plotting.py:921
def _getOrCreateObject
Definition: plotting.py:16
def plotting.Plot._normalize (   self)
private
Normalise histograms to unit area

Definition at line 1015 of file plotting.py.

References RunHistogramManager._histograms, and plotting.Plot._histograms.

Referenced by plotting.Plot.draw().

1016  def _normalize(self):
1017  """Normalise histograms to unit area"""
1018 
1019  for h in self._histograms:
1020  if h is None:
1021  continue
1022  i = h.Integral()
1023  if i == 0:
1024  continue
1025  h.Sumw2()
1026  h.Scale(1.0/i)
def plotting.Plot._setStats (   self,
  startingX,
  startingY 
)
private
Set stats box.

Definition at line 974 of file plotting.py.

References RunHistogramManager._histograms, plotting.Plot._histograms, DTSC._stat, and DTTrigGeom._stat.

Referenced by plotting.Plot.draw().

975  def _setStats(self, startingX, startingY):
976  """Set stats box."""
977  if not self._stat:
978  for h in self._histograms:
979  if h is not None and hasattr(h, "SetStats"):
980  h.SetStats(0)
981  return
982 
983  def _doStats(h, col, dy):
984  if h is None:
985  return
986  h.SetStats(True)
987 
988  if self._fit:
989  h.Fit("gaus", "Q")
990  f = h.GetListOfFunctions().FindObject("gaus")
991  if f == None:
992  h.SetStats(0)
993  return
994  f.SetLineColor(col)
995  f.SetLineWidth(1)
996  h.Draw()
997  ROOT.gPad.Update()
998  st = h.GetListOfFunctions().FindObject("stats")
999  if self._fit:
1000  st.SetOptFit(0010)
1001  st.SetOptStat(1001)
1002  st.SetX1NDC(startingX)
1003  st.SetX2NDC(startingX+0.3)
1004  st.SetY1NDC(startingY+dy)
1005  st.SetY2NDC(startingY+dy+0.15)
1006  st.SetTextColor(col)
1007 
1008  dy = 0.0
1009  for i, h in enumerate(self._histograms):
1010  if self._statyadjust is not None and i < len(self._statyadjust):
1011  dy += self._statyadjust[i]
1012 
1013  _doStats(h, _plotStylesColor[i], dy)
1014  dy -= 0.19
def plotting.Plot.addToLegend (   self,
  legend,
  legendLabels,
  denomUncertainty 
)
Add histograms to a legend.

Arguments:
legend       -- TLegend
legendLabels -- List of strings for the legend labels

Definition at line 1175 of file plotting.py.

References RunHistogramManager._histograms, and plotting.Plot._histograms.

1176  def addToLegend(self, legend, legendLabels, denomUncertainty):
1177  """Add histograms to a legend.
1178 
1179  Arguments:
1180  legend -- TLegend
1181  legendLabels -- List of strings for the legend labels
1182  """
1183  first = denomUncertainty
1184  for h, label in zip(self._histograms, legendLabels):
1185  if h is None:
1186  first = False
1187  continue
1188  if first:
1189  self._forLegend = h.Clone()
1190  self._forLegend.SetFillStyle(1001)
1191  self._forLegend.SetFillColor(ROOT.kGray)
1192  entry = legend.AddEntry(self._forLegend, label, "lpf")
1193  first = False
1194  else:
1195  legend.AddEntry(h, label, "LP")
def plotting.Plot.create (   self,
  tdirs,
  requireAllHistograms = False 
)
Create histograms from list of TDirectories

Definition at line 934 of file plotting.py.

References plotting.Plot._createOne(), RunHistogramManager._histograms, plotting.Plot._histograms, plotting.AggregateBins._scale, Vispa.Gui.VispaWidget.VispaWidget._scale, HistoParams< T >._title, HistoParams< TH1F >._title, HistoParams< TProfile >._title, HistoParams< TH2F >._title, plotting.Subtract._title, HistoParams< TProfile2D >._title, plotting.FakeDuplicate._title, html.PageSet._title, html.HtmlReport._title, and python.multivaluedict.map().

935  def create(self, tdirs, requireAllHistograms=False):
936  """Create histograms from list of TDirectories"""
937  self._histograms = [self._createOne(i, tdir) for i, tdir in enumerate(tdirs)]
938 
939  if self._histogramModifier is not None:
940  self._histograms = self._histogramModifier(self._histograms)
941 
942  if len(self._histograms) > len(_plotStylesColor):
943  raise Exception("More histograms (%d) than there are plot styles (%d) defined. Please define more plot styles in this file" % (len(self._histograms), len(_plotStylesColor)))
944 
945  # Modify histograms here in case self._name returns numbers
946  # and self._histogramModifier creates the histograms from
947  # these numbers
948  def _modifyHisto(th1):
949  if th1 is None:
950  return None
951 
952  if self._profileX:
953  th1 = th1.ProfileX()
954 
955  if self._fitSlicesY:
956  ROOT.TH1.AddDirectory(True)
957  th1.FitSlicesY()
958  th1 = ROOT.gDirectory.Get(th1.GetName()+"_2")
959  th1.SetDirectory(None)
960  #th1.SetName(th1.GetName()+"_ref")
961  ROOT.TH1.AddDirectory(False)
962 
963  if self._title is not None:
964  th1.SetTitle(self._title)
965 
966  if self._scale is not None:
967  th1.Scale(self._scale)
968 
969  return th1
970 
971  self._histograms = map(_modifyHisto, self._histograms)
972  if requireAllHistograms and None in self._histograms:
973  self._histograms = [None]*len(self._histograms)
def _createOne
Definition: plotting.py:921
def plotting.Plot.draw (   self,
  pad,
  ratio,
  ratioFactor,
  nrows 
)
Draw the histograms using values for a given algorithm.

Definition at line 1027 of file plotting.py.

References plotting._findBounds(), RunHistogramManager._histograms, plotting.Plot._histograms, plotting.Plot._normalize(), plotting.Plot._setStats(), plotting.FrameTGraph2D._xlabelsize, MEGeom._xmax, HistoParams< TProfile >._xmax, HistoParams< TH1F >._xmax, HistoParams< T >._xmax, HistoParams< TH2F >._xmax, HistoParams< TProfile2D >._xmax, MEGeom._xmin, HistoParams< T >._xmin, HistoParams< TProfile >._xmin, HistoParams< TH1F >._xmin, HistoParams< TH2F >._xmin, HistoParams< TProfile2D >._xmin, plotting.FrameTGraph2D._xtitle, plotting.FrameTGraph2D._xtitleoffset, plotting.FrameTGraph2D._xtitlesize, MEGeom._ymax, HistoParams< T >._ymax, HistoParams< TProfile >._ymax, HistoParams< TH1F >._ymax, HistoParams< TH2F >._ymax, HistoParams< TProfile2D >._ymax, MEGeom._ymin, HistoParams< T >._ymin, HistoParams< TH1F >._ymin, HistoParams< TProfile >._ymin, HistoParams< TH2F >._ymin, HistoParams< TProfile2D >._ymin, plotting.FrameTGraph2D._ytitle, plotting.FrameTGraph2D._ytitleoffset, plotting.FrameTGraph2D._ytitlesize, HistoData.getName(), PhysicsTools::Source.getName(), LikelihoodSpecies.getName(), ecaldqm::DBReaderWorker.getName(), CocoaMaterialElementary.getName(), PCaloHit.getName(), EcalLogicID.getName(), pftools::SpaceManager.getName(), ecaldqm::DBWriterWorker.getName(), LikelihoodPdf.getName(), TkOfflineVariables.getName(), FieldHandlerBase< TOutput >.getName(), AnyMVAEstimatorRun2Base.getName(), FittedEntry.getName(), HPDNoiseDataCatalog.getName(), jsoncollector::JsonMonitorable.getName(), CSGAction.getName(), DTTPGLutFile.getName(), PhysicsTools::MVATrainer.getName(), L1TriggerLutFile.getName(), QCriterion.getName(), SeedMergerPixelLayer.getName(), pos::PixelPortcardMap.getName(), L1MuGMTReg.getName(), GenericMVAComputer::TaggingVariableIterator< Iter_t >::Value.getName(), GEMStation.getName(), PhysicsTools::Variable::Value.getName(), pftools::SpaceVoxel.getName(), ecaldqm::DQWorker.getName(), PhotonMVAEstimatorRun2Phys14NonTrig.getName(), PhotonMVAEstimatorRun2Spring15NonTrig.getName(), ElectronMVAEstimatorRun2Phys14NonTrig.getName(), edm::ELslProxy< ELgen >.getName(), L1MuGMTRegMMConfig.getName(), PhysicsTools::MVAModuleHelper< Record, Object, Filler >::Value.getName(), ElectronMVAEstimatorRun2Spring15Trig.getName(), ElectronMVAEstimatorRun2Spring15NonTrig.getName(), cscdqm::HistoDef.getName(), FourVectorHLT::PathInfo.getName(), jsoncollector::DataPoint.getName(), MonitorElement.getName(), edm::ELseverityLevel.getName(), PhysicsTools::Variable.getName(), PhysicsTools::TrainerMonitoring::Object.getName(), L1MuGMTRegSortRankOffset.getName(), L1MuGMTRegCDLConfig.getName(), cscdqm::CSCHistoDef.getName(), plotting.Plot.getName(), and plotting.Plot.isTGraph2D().

1028  def draw(self, pad, ratio, ratioFactor, nrows):
1029  """Draw the histograms using values for a given algorithm."""
1030 # if len(self._histograms) == 0:
1031 # print "No histograms for plot {name}".format(name=self._name)
1032 # return
1033 
1034  isTGraph2D = self.isTGraph2D()
1035  if isTGraph2D:
1036  # Ratios for the TGraph2Ds is not that interesting
1037  ratioOrig = ratio
1038  ratio = False
1039 
1040  if self._normalizeToUnitArea:
1041  self._normalize()
1042 
1043  if self._rebinX is not None:
1044  for h in self._histograms:
1045  h.Rebin(self._rebinX)
1046 
1047  def _styleMarker(h, msty, col):
1048  h.SetMarkerStyle(msty)
1049  h.SetMarkerColor(col)
1050  h.SetMarkerSize(0.7)
1051  h.SetLineColor(1)
1052  h.SetLineWidth(1)
1053 
1054  def _styleHist(h, msty, col):
1055  _styleMarker(h, msty, col)
1056  h.SetLineColor(col)
1057  h.SetLineWidth(self._lineWidth)
1058 
1059  # Use marker or hist style
1060  style = _styleMarker
1061  if self._drawStyle is not None:
1062  if "hist" in self._drawStyle.lower():
1063  style = _styleHist
1064  if len(self._histograms) > 0 and isinstance(self._histograms[0], ROOT.TGraph):
1065  if "l" in self._drawStyle.lower():
1066  style = _styleHist
1067 
1068  # Apply style to histograms, filter out Nones
1069  histos = []
1070  for i, h in enumerate(self._histograms):
1071  if h is None:
1072  continue
1073  style(h, _plotStylesMarker[i], _plotStylesColor[i])
1074  histos.append(h)
1075  if len(histos) == 0:
1076  print "No histograms for plot {name}".format(name=self.getName())
1077  return
1078 
1079  bounds = _findBounds(histos, self._ylog,
1080  xmin=self._xmin, xmax=self._xmax,
1081  ymin=self._ymin, ymax=self._ymax)
1082 
1083  # Create bounds before stats in order to have the
1084  # SetRangeUser() calls made before the fit
1085  #
1086  # stats is better to be called before frame, otherwise get
1087  # mess in the plot (that frame creation cleans up)
1088  if ratio:
1089  pad.cd(1)
1090  self._setStats(self._statx, self._staty)
1091 
1092  xbinlabels = self._xbinlabels
1093  if xbinlabels is None:
1094  if len(histos[0].GetXaxis().GetBinLabel(1)) > 0:
1095  xbinlabels = []
1096  for i in xrange(1, histos[0].GetNbinsX()+1):
1097  xbinlabels.append(histos[0].GetXaxis().GetBinLabel(i))
1098 
1099  # Create frame
1100  if isTGraph2D:
1101  frame = FrameTGraph2D(pad, bounds, histos, ratioOrig, ratioFactor)
1102  else:
1103  if ratio:
1104  ratioBounds = (bounds[0], self._ratioYmin, bounds[2], self._ratioYmax)
1105  frame = FrameRatio(pad, bounds, ratioBounds, ratioFactor, nrows, xbinlabels, self._xbinlabelsize, self._xbinlabeloption)
1106  else:
1107  frame = Frame(pad, bounds, nrows, xbinlabels, self._xbinlabelsize, self._xbinlabeloption)
1108 
1109  # Set log and grid
1110  frame.setLogx(self._xlog)
1111  frame.setLogy(self._ylog)
1112  frame.setGridx(self._xgrid)
1113  frame.setGridy(self._ygrid)
1114 
1115  # Construct draw option string
1116  opt = "sames" # s for statbox or something?
1117  ds = ""
1118  if self._drawStyle is not None:
1119  ds = self._drawStyle
1120  if self._drawCommand is not None:
1121  ds = self._drawCommand
1122  if len(ds) > 0:
1123  opt += " "+ds
1124 
1125  # Set properties of frame
1126  frame.setTitle(histos[0].GetTitle())
1127  if self._xtitle is not None:
1128  frame.setXTitle(self._xtitle)
1129  if self._xtitlesize is not None:
1130  frame.setXTitleSize(self._xtitlesize)
1131  if self._xtitleoffset is not None:
1132  frame.setXTitleOffset(self._xtitleoffset)
1133  if self._xlabelsize is not None:
1134  frame.setXLabelSize(self._xlabelsize)
1135  if self._ytitle is not None:
1136  frame.setYTitle(self._ytitle)
1137  if self._ytitlesize is not None:
1138  frame.setYTitleSize(self._ytitlesize)
1139  if self._ytitleoffset is not None:
1140  frame.setYTitleOffset(self._ytitleoffset)
1141  if self._ztitle is not None:
1142  frame.setZTitle(self._ztitle)
1143  if self._ztitleoffset is not None:
1144  frame.setZTitleOffset(self._ztitleoffset)
1145  if self._adjustMarginRight is not None:
1146  frame.adjustMarginRight(self._adjustMarginRight)
1147  elif "z" in opt:
1148  frame.adjustMarginLeft(0.03)
1149  frame.adjustMarginRight(0.08)
1150 
1151  # Draw histograms
1152  if ratio:
1153  frame._pad.cd()
1154 
1155  for h in histos:
1156  h.Draw(opt)
1157 
1158  # Draw ratios
1159  if ratio and len(histos) > 0:
1160  frame._padRatio.cd()
1161  self._ratios = self._calculateRatios(histos) # need to keep these in memory too ...
1162  if self._ratioUncertainty and self._ratios[0]._ratio is not None:
1163  self._ratios[0]._ratio.SetFillStyle(1001)
1164  self._ratios[0]._ratio.SetFillColor(ROOT.kGray)
1165  self._ratios[0]._ratio.SetLineColor(ROOT.kGray)
1166  self._ratios[0]._ratio.SetMarkerColor(ROOT.kGray)
1167  self._ratios[0]._ratio.SetMarkerSize(0)
1168  self._ratios[0].draw("E2")
1169  frame._padRatio.RedrawAxis("G") # redraw grid on top of the uncertainty of denominator
1170  for r in self._ratios[1:]:
1171  r.draw()
1172 
1173  frame.redrawAxis()
1174  self._frame = frame # keep the frame in memory for sure
def isTGraph2D
Definition: plotting.py:905
def _findBounds
Definition: plotting.py:71
def _calculateRatios
Definition: plotting.py:1196
def plotting.Plot.drawRatioUncertainty (   self)
Return true if the ratio uncertainty should be drawn

Definition at line 917 of file plotting.py.

918  def drawRatioUncertainty(self):
919  """Return true if the ratio uncertainty should be drawn"""
920  return self._ratioUncertainty
def drawRatioUncertainty
Definition: plotting.py:917
def plotting.Plot.getName (   self)

Definition at line 911 of file plotting.py.

References FP420HitsObject._name, TrackerHitsObject._name, PGeometricDet::Item._name, LikelihoodSpecies._name, LikelihoodPdfProduct._name, LikelihoodPdf._name, citk::IsolationConeDefinitionBase._name, DrellYanValidation._name, WValidation._name, HistoParams< T >._name, CutApplicatorBase._name, ElectronMVAEstimatorRun2Phys14NonTrig._name, PhotonMVAEstimatorRun2Spring15NonTrig._name, PhotonMVAEstimatorRun2Phys14NonTrig._name, GeometricDetExtra._name, ElectronMVAEstimatorRun2Spring15Trig._name, ElectronMVAEstimatorRun2Spring15NonTrig._name, HistoParams< TH2F >._name, plotting.Subtract._name, HistoParams< TProfile2D >._name, plotting.FakeDuplicate._name, plotting.AggregateBins._name, plotting.AggregateHistos._name, plotting.ROC._name, Vispa.Views.PropertyView.Property._name, SequenceTypes.SequencePlaceholder._name, and plotting.Plot._name.

Referenced by plotting.Plot.draw().

912  def getName(self):
913  if isinstance(self._name, list):
914  return str(self._name[0])
915  else:
916  return str(self._name)
def plotting.Plot.getNumberOfHistograms (   self)
Return number of existing histograms.

Definition at line 897 of file plotting.py.

References RunHistogramManager._histograms, plotting.Plot._histograms, and alcazmumu_cfi.filter.

Referenced by plotting.Plot.isEmpty().

898  def getNumberOfHistograms(self):
899  """Return number of existing histograms."""
900  return len(filter(lambda h: h is not None, self._histograms))
def getNumberOfHistograms
Definition: plotting.py:897
def plotting.Plot.isEmpty (   self)
Return true if there are no histograms created for the plot

Definition at line 901 of file plotting.py.

References plotting.Plot.getNumberOfHistograms().

902  def isEmpty(self):
903  """Return true if there are no histograms created for the plot"""
904  return self.getNumberOfHistograms() == 0
def getNumberOfHistograms
Definition: plotting.py:897
def plotting.Plot.isTGraph2D (   self)

Definition at line 905 of file plotting.py.

References RunHistogramManager._histograms, and plotting.Plot._histograms.

Referenced by plotting.Plot.draw().

906  def isTGraph2D(self):
907  for h in self._histograms:
908  if isinstance(h, ROOT.TGraph2D):
909  return True
910  return False
def isTGraph2D
Definition: plotting.py:905

Member Data Documentation

plotting.Plot._binOffset
private

Definition at line 1262 of file plotting.py.

plotting.Plot._forLegend
private

Definition at line 1188 of file plotting.py.

plotting.Plot._frame
private

Definition at line 1173 of file plotting.py.

plotting.Plot._gr
private

Definition at line 1254 of file plotting.py.

plotting.Plot._histograms
private

Definition at line 895 of file plotting.py.

Referenced by plotting.Plot._normalize(), plotting.Plot._setStats(), plotting.Plot.addToLegend(), plotting.Plot.create(), plotting.Plot.draw(), plotting.Plot.getNumberOfHistograms(), and plotting.Plot.isTGraph2D().

plotting.Plot._name
private

Definition at line 835 of file plotting.py.

Referenced by plotting.Plot._createOne(), plotting.PlotGroup._drawSeparate(), plotting.PlotGroup._save(), plotting.PlotGroup.draw(), plotting.Plot.getName(), plotting.PlotterFolder.getName(), plotting.PlotterFolder.getSelectionNameIterator(), validation.SimpleSample.name(), and plotting.PlotterItem.readDirs().

plotting.Plot._ratio
private

Definition at line 1216 of file plotting.py.

plotting.Plot._ratios
private

Definition at line 1160 of file plotting.py.

plotting.Plot._th1
private

Definition at line 1208 of file plotting.py.

plotting.Plot._uncertainty
private

Definition at line 1209 of file plotting.py.

plotting.Plot._xerrshigh
private

Definition at line 1258 of file plotting.py.

plotting.Plot._xerrslow
private

Definition at line 1257 of file plotting.py.

plotting.Plot._xvalues
private

Definition at line 1256 of file plotting.py.

plotting.Plot._yerrshigh
private

Definition at line 1260 of file plotting.py.

plotting.Plot._yerrslow
private

Definition at line 1261 of file plotting.py.

plotting.Plot._yvalues
private

Definition at line 1259 of file plotting.py.