Beispiel #1
0
    def __finalizeAction__(self):
        self.plotUp.logX = self.logX
        self.plotUp.logY = self.logY
        self.plotUp.logZ = self.logZ
        self.plotDown.__finalizeAction__()
        self.plotUp.__finalizeAction__()
        if self.firstTimeDrawn:
            if self.plotUp.firstDrawnObject:
                xAxis = self.plotUp.firstDrawnObject.GetXaxis()
                xAxis.SetTickLength(xAxis.GetTickLength() / self.upperFraction)
                xAxis.SetLabelOffset(xAxis.GetLabelOffset() * 10.)
                xAxis.Draw()
                yAxis = self.plotUp.firstDrawnObject.GetYaxis()
                yAxis.SetTickLength(yAxis.GetTickLength() / self.upperFraction)
                yAxis.SetLabelSize(yAxis.GetLabelSize() / self.upperFraction)
                yAxis.SetLabelOffset(yAxis.GetLabelOffset() /
                                     self.upperFraction)
                yAxis.SetTitleSize(yAxis.GetTitleSize() / self.upperFraction)
                yAxis.SetTitleOffset(yAxis.GetTitleOffset() *
                                     self.upperFraction)
                yAxis.Draw()
        if self.plotDown.firstDrawnObject:
            xAxis = self.plotDown.firstDrawnObject.GetXaxis()
            xAxis.SetTickLength(xAxis.GetTickLength() / self.lowerFraction)
            xAxis.SetTitleSize(xAxis.GetTitleSize() / self.lowerFraction)
            xAxis.SetLabelSize(xAxis.GetLabelSize() / self.lowerFraction)
            xAxis.SetLabelOffset(xAxis.GetLabelOffset() / self.lowerFraction)
            xAxis.Draw()
            yAxis = self.plotDown.firstDrawnObject.GetYaxis()
            self.plotDown.firstDrawnObject.SetMinimum(0.9)
            self.plotDown.firstDrawnObject.SetMaximum(1.1)
            yAxis.SetNdivisions(5)
            yAxis.CenterTitle(True)
            yAxis.SetTickLength(yAxis.GetTickLength() / self.lowerFraction *
                                0.5)
            yAxis.SetLabelSize(yAxis.GetLabelSize() / self.lowerFraction * 0.5)
            yAxis.SetLabelOffset(yAxis.GetLabelOffset() / self.lowerFraction *
                                 0.5)
            yAxis.SetTitleSize(yAxis.GetTitleSize() / self.lowerFraction * 0.7)
            yAxis.SetTitleOffset(yAxis.GetTitleOffset() * self.lowerFraction *
                                 0.8)
            yAxis.Draw()

        #self.stretchAxis( self.plotUp.firstDrawnObject, 1./self.upperFraction, 1.0 )
        #self.stretchAxis( self.plotDown.firstDrawnObject, 1./self.lowerFraction, 0.7 )
        self.plotUp.canvas.Update()
        self.plotDown.canvas.Update()
        self.canvas.Update()
        BasicPlot.__finalizeAction__(self)
Beispiel #2
0
 def __init__(self,
              title='',
              xVariable=None,
              yVariable=None,
              zVariable=None,
              tree=None):
     ## Default constructor
     #  @param title           title of the canvas
     #  @param xVariable       Variable object to define the xAxis and the draw command
     #  @param yVariable       Variable object to define the yAxis
     from AtlasStyle import linesColor
     BasicPlot.__init__(self, title, xVariable, yVariable, zVariable)
     self.cutDefinitions = []
     self.defaultTree = tree
     self.cutStyle = linesColor
Beispiel #3
0
 def __finalizeAction__(self):
     self.plotUp.logX = self.logX
     self.plotUp.logY = self.logY
     self.plotUp.logZ = self.logZ
     self.plotDown.__finalizeAction__()
     self.plotUp.__finalizeAction__()
     if self.plotUp.firstDrawnObject and self.plotUp.firstDrawnObject != self.plotUp.previousFirstDrawnObject:
         xAxis = self.plotUp.firstDrawnObject.GetXaxis()
         xAxis.SetTickLength(xAxis.GetTickLength() / self.upperFraction)
         # supress labels by drawing in white
         xAxis.SetLabelColor(0)
         xAxis.SetTitleColor(0)
         xAxis.Draw()
         yAxis = self.plotUp.firstDrawnObject.GetYaxis()
         #yAxis.SetTickLength( yAxis.GetTickLength() / self.upperFraction )
         yAxis.SetLabelSize(yAxis.GetLabelSize() / self.upperFraction)
         yAxis.SetLabelOffset(yAxis.GetLabelOffset() / self.upperFraction)
         yAxis.SetTitleSize(yAxis.GetTitleSize() / self.upperFraction)
         yAxis.SetTitleOffset(yAxis.GetTitleOffset() * self.upperFraction *
                              1.1)
         yAxis.Draw()
     if self.plotDown.firstDrawnObject and self.plotDown.firstDrawnObject != self.plotDown.previousFirstDrawnObject:
         xAxis = self.plotDown.firstDrawnObject.GetXaxis()
         xAxis.SetTickLength(xAxis.GetTickLength() / self.lowerFraction)
         xAxis.SetTitleSize(xAxis.GetTitleSize() / self.lowerFraction)
         xAxis.SetLabelSize(xAxis.GetLabelSize() / self.lowerFraction)
         xAxis.SetLabelOffset(xAxis.GetLabelOffset() / self.lowerFraction)
         xAxis.Draw()
         yAxis = self.plotDown.firstDrawnObject.GetYaxis()
         #yAxis.SetNdivisions( 5 )
         yAxis.CenterTitle(False)
         yAxis.SetTickLength(yAxis.GetTickLength() / self.lowerFraction *
                             self.upperFraction)
         yAxis.SetLabelSize(yAxis.GetLabelSize() / self.lowerFraction *
                            0.7)  #adapted for envelope plots
         yAxis.SetLabelOffset(yAxis.GetLabelOffset() /
                              self.lowerFraction)  #* 0.5 )
         yAxis.SetTitleSize(yAxis.GetTitleSize() /
                            self.lowerFraction)  # * 0.7 )
         yAxis.SetTitleOffset(yAxis.GetTitleOffset() * self.lowerFraction *
                              1.1)
         yAxis.Draw()
     self.plotUp.canvas.Update()
     self.plotDown.canvas.Update()
     self.canvas.Update()
     BasicPlot.__finalizeAction__(self)
Beispiel #4
0
    def __initAction__(self):
        from ROOT import TCanvas
        ## Method that does all the magic
        if not self.canvas:
            self.canvas = TCanvas(alphanumericString(self.title), self.title,
                                  self.xSize, self.ySize)
        BasicPlot.__initAction__(self)
        self.plotDown.__initAction__()
        self.plotUp.__initAction__()

        self.canvas.Divide(1, 2)
        self.plotUp.canvas = self.canvas.cd(1)
        self.plotDown.canvas = self.canvas.cd(2)
        self.plotUp.drawLegend = self.drawLegend
        self.plotUp.drawTitle = self.drawTitle
        self.plotUp.normalizeByBinWidth = self.normalizeByBinWidth

        # initialize layout
        self.plotUp.canvas.SetPad(0., 1. - self.upperFraction, 1., 1.)
        self.plotUp.canvas.SetBottomMargin(0.01)
        self.plotUp.canvas.SetTopMargin(self.plotDown.canvas.GetTopMargin() /
                                        self.upperFraction)
        self.plotUp.canvas.Update()
        self.plotDown.canvas.SetPad(0., 0., 1., self.lowerFraction)
        self.plotDown.canvas.SetTopMargin(0.01)
        self.plotDown.canvas.SetBottomMargin(
            self.plotDown.canvas.GetBottomMargin() / (self.lowerFraction))
        self.plotDown.canvas.SetGridy(True)
        self.plotDown.canvas.Update()
        self.canvas.Update()

        if self.firstTimeDrawn:
            self.plotUp.topMargin = self.topMargin / self.upperFraction
            self.plotUp.bottomMargin = self.bottomMargin / self.bottomMargin
            self.plotUp.legendDecorator.defaultUpperY = 1. - (
                1 - self.legendDecorator.defaultUpperY) / self.upperFraction
            self.plotUp.legendDecorator.defaultLowerY = self.legendDecorator.defaultLowerY / self.upperFraction
            self.plotUp.legendDecorator.labelTextSize = self.legendDecorator.labelTextSize / self.upperFraction
            self.plotUp.legendDecorator.textSize = self.legendDecorator.textSize / self.upperFraction
            self.plotUp.legendDecorator.lineGap = self.legendDecorator.lineGap / self.upperFraction
            self.plotUp.titleDecorator.defaultUpperY = 1. - (
                1 - self.titleDecorator.defaultUpperY) / self.upperFraction
            self.plotUp.titleDecorator.defaultLowerY = self.titleDecorator.defaultLowerY / self.upperFraction
            self.plotUp.titleDecorator.textSize = self.titleDecorator.textSize / self.upperFraction
            self.plotUp.titleDecorator.labelTextSize = self.titleDecorator.labelTextSize / self.upperFraction
Beispiel #5
0
 def __init__(self,
              title='DoublePlot',
              xVariable=None,
              yVariableUp=var_Entries,
              yVariableDown=None,
              upperFraction=0.7,
              lowerFraction=0.3):
     BasicPlot.__init__(self, title, xVariable, yVariableUp)
     self.plotUp = BasicPlot(title + '_up', xVariable, yVariableUp)
     self.plotDown = BasicPlot(title + '_down', xVariable, yVariableDown)
     self.plotDown.drawLegend = False
     self.plotDown.showBinWidthY = False
     self.upperFraction = upperFraction
     self.lowerFraction = lowerFraction
     self.legendElements = self.plotUp.legendElements
     self.titles = self.plotUp.titles
     self.plotDown.drawLegend = False
     self.plotDown.drawTitle = False
Beispiel #6
0
class DoublePlot(BasicPlot):
    def __init__(self,
                 title='DoublePlot',
                 xVariable=None,
                 yVariableUp=var_Entries,
                 yVariableDown=None,
                 upperFraction=0.7,
                 lowerFraction=0.3):
        BasicPlot.__init__(self, title, xVariable, yVariableUp)
        self.plotUp = BasicPlot(title + '_up', xVariable, yVariableUp)
        self.plotDown = BasicPlot(title + '_down', xVariable, yVariableDown)
        self.plotDown.drawLegend = False
        self.plotDown.showBinWidthY = False
        self.upperFraction = upperFraction
        self.lowerFraction = lowerFraction
        self.legendElements = self.plotUp.legendElements
        self.titles = self.plotUp.titles
        self.plotDown.drawLegend = False
        self.plotDown.drawTitle = False
        self.plotDown.topMargin = 0.
        self.plotDown.bottomMargin = 0.
        self.decorators = []
        self.plotDown.decorators = []

    def __initAction__(self):
        from ROOT import TCanvas
        ## Method that does all the magic
        if not self.canvas:
            self.canvas = TCanvas(alphanumericString(self.title), self.title,
                                  self.xSize, self.ySize)
        BasicPlot.__initAction__(self)
        self.plotDown.__initAction__()
        self.plotUp.__initAction__()

        self.canvas.Divide(1, 2)
        self.plotUp.canvas = self.canvas.cd(1)
        self.plotDown.canvas = self.canvas.cd(2)
        self.plotUp.drawLegend = self.drawLegend
        self.plotUp.drawTitle = self.drawTitle
        self.plotUp.normalizeByBinWidth = self.normalizeByBinWidth

        # initialize layout
        self.plotUp.canvas.SetPad(0., 1. - self.upperFraction, 1., 1.)
        self.plotUp.canvas.SetBottomMargin(0.01)
        self.plotUp.canvas.SetTopMargin(self.plotDown.canvas.GetTopMargin() /
                                        self.upperFraction)
        self.plotUp.canvas.Update()
        self.plotDown.canvas.SetPad(0., 0., 1., self.lowerFraction)
        self.plotDown.canvas.SetTopMargin(0.01)
        self.plotDown.canvas.SetBottomMargin(
            self.plotDown.canvas.GetBottomMargin() / (self.lowerFraction))
        self.plotDown.canvas.SetGridy(True)
        self.plotDown.canvas.Update()
        self.canvas.Update()

        if self.firstTimeDrawn:
            self.plotUp.topMargin = self.topMargin / self.upperFraction
            self.plotUp.bottomMargin = self.bottomMargin / self.bottomMargin
            self.plotUp.legendDecorator.defaultUpperY = 1. - (
                1 - self.legendDecorator.defaultUpperY) / self.upperFraction
            self.plotUp.legendDecorator.defaultLowerY = self.legendDecorator.defaultLowerY / self.upperFraction
            self.plotUp.legendDecorator.labelTextSize = self.legendDecorator.labelTextSize / self.upperFraction
            self.plotUp.legendDecorator.textSize = self.legendDecorator.textSize / self.upperFraction
            self.plotUp.legendDecorator.lineGap = self.legendDecorator.lineGap / self.upperFraction
            self.plotUp.titleDecorator.defaultUpperY = 1. - (
                1 - self.titleDecorator.defaultUpperY) / self.upperFraction
            self.plotUp.titleDecorator.defaultLowerY = self.titleDecorator.defaultLowerY / self.upperFraction
            self.plotUp.titleDecorator.textSize = self.titleDecorator.textSize / self.upperFraction
            self.plotUp.titleDecorator.labelTextSize = self.titleDecorator.labelTextSize / self.upperFraction

    def __mainAction__(self):
        BasicPlot.__mainAction__(self)
        self.plotDown.__mainAction__()
        self.plotUp.__mainAction__()

    def __normalizeObjects__(self):
        self.plotUp.__normalizeObjects__()
        self.plotDown.__normalizeObjects__()

    def __normalizeByBinWidth__(self):
        self.plotUp.__normalizeByBinWidth__()
        #Commented out since normbybinwidth not necessary for ratioplot down
        #self.plotDown.__normalizeByBinWidth__()

    def __fitObjects__(self):
        self.plotUp.__fitObjects__()
        self.plotDown.__fitObjects__()

    def __drawObjects__(self):
        BasicPlot.__drawObjects__(self)
        self.plotDown.__drawObjects__()
        self.plotUp.__drawObjects__()

    def __drawDecorations__(self):
        BasicPlot.__drawDecorations__(self)
        self.plotDown.__drawDecorations__()
        self.plotUp.__drawDecorations__()

    def __finalizeAction__(self):
        self.plotUp.logX = self.logX
        self.plotUp.logY = self.logY
        self.plotUp.logZ = self.logZ
        self.plotDown.__finalizeAction__()
        self.plotUp.__finalizeAction__()
        if self.plotUp.firstDrawnObject and self.plotUp.firstDrawnObject != self.plotUp.previousFirstDrawnObject:
            xAxis = self.plotUp.firstDrawnObject.GetXaxis()
            xAxis.SetTickLength(xAxis.GetTickLength() / self.upperFraction)
            # supress labels by drawing in white
            xAxis.SetLabelColor(0)
            xAxis.SetTitleColor(0)
            xAxis.Draw()
            yAxis = self.plotUp.firstDrawnObject.GetYaxis()
            #yAxis.SetTickLength( yAxis.GetTickLength() / self.upperFraction )
            yAxis.SetLabelSize(yAxis.GetLabelSize() / self.upperFraction)
            yAxis.SetLabelOffset(yAxis.GetLabelOffset() / self.upperFraction)
            yAxis.SetTitleSize(yAxis.GetTitleSize() / self.upperFraction)
            yAxis.SetTitleOffset(yAxis.GetTitleOffset() * self.upperFraction *
                                 1.1)
            yAxis.Draw()
        if self.plotDown.firstDrawnObject and self.plotDown.firstDrawnObject != self.plotDown.previousFirstDrawnObject:
            xAxis = self.plotDown.firstDrawnObject.GetXaxis()
            xAxis.SetTickLength(xAxis.GetTickLength() / self.lowerFraction)
            xAxis.SetTitleSize(xAxis.GetTitleSize() / self.lowerFraction)
            xAxis.SetLabelSize(xAxis.GetLabelSize() / self.lowerFraction)
            xAxis.SetLabelOffset(xAxis.GetLabelOffset() / self.lowerFraction)
            xAxis.Draw()
            yAxis = self.plotDown.firstDrawnObject.GetYaxis()
            #yAxis.SetNdivisions( 5 )
            yAxis.CenterTitle(False)
            yAxis.SetTickLength(yAxis.GetTickLength() / self.lowerFraction *
                                self.upperFraction)
            yAxis.SetLabelSize(yAxis.GetLabelSize() / self.lowerFraction *
                               0.7)  #adapted for envelope plots
            yAxis.SetLabelOffset(yAxis.GetLabelOffset() /
                                 self.lowerFraction)  #* 0.5 )
            yAxis.SetTitleSize(yAxis.GetTitleSize() /
                               self.lowerFraction)  # * 0.7 )
            yAxis.SetTitleOffset(yAxis.GetTitleOffset() * self.lowerFraction *
                                 1.1)
            yAxis.Draw()
        self.plotUp.canvas.Update()
        self.plotDown.canvas.Update()
        self.canvas.Update()
        BasicPlot.__finalizeAction__(self)

    def stretchAxis(self, drawnObject, factor, yFactor=1.0):
        # get the axis
        xAxis = drawnObject.GetXaxis()
        yAxis = drawnObject.GetYaxis()

        for axis in [xAxis, yAxis]:
            axis.SetTickLength(axis.GetTickLength() * factor)
            axis.SetLabelSize(0.05 * factor)
            axis.SetLabelOffset(axis.GetLabelOffset() * factor)
            if axis == xAxis:
                axis.SetTitleSize(axis.GetTitleSize() * factor)
                # axis.SetLabelOffset( axis.GetLabelOffset() * factor )
                # axis.SetTitleOffset( axis.GetTitleOffset() / factor )
            if axis == yAxis:
                axis.SetTitleSize(axis.GetTitleSize() * factor * yFactor)
                axis.SetTitleOffset(axis.GetTitleOffset() / (factor * yFactor))
Beispiel #7
0
         # subtract other backgrounds from data
         h_tmp = process.getHistogram(
             var,
             process.title,
             luminosity=lumi,
             cut=selection,
             weightExpression=weight_expression)
         sys.stdout.write('.')
         sys.stdout.flush()
         h_data.Add(h_tmp, -1)
 print "read all histograms for {0}".format(var.name)
 # calculating scale factor data/MC for the given Variable
 h_sf = var.createHistogram('SF')
 h_sf.Divide(h_data, h_mc, 1, 1, 'B')
 # plotting the scale factor
 bp_sf = BasicPlot('SF_' + var.name, var, Variable('Scale Factor'))
 bp_sf.titles.append(
     '#sqrt{{s}} = 13 TeV, #scale[0.5]{{#int}}Ldt = {0:.2f} fb^{{-1}}, '
     .format(lumi / 1000.))
 bp_sf.addHistogram(h_sf, 'E', copy=True)
 bp_sf.draw()
 bp_sf.saveAsAll(os.path.join(outFolder, bp_sf.title))
 # storing histogram in root file
 from ROOT import TFile, TObject
 filename = outFolder + '/SF_' + var.name + '.root'
 rootfile = TFile.Open(filename, 'update')
 if rootfile.IsOpen():
     print "writing in file {}".format(filename)
     rootfile.cd()
     histogram = h_sf.Clone(var.name)
     histogram.SetTitle(var.name)
Beispiel #8
0
class DoublePlot(BasicPlot):
    def __init__(self,
                 title='DoublePlot',
                 xVariable=None,
                 yVariableUp=var_Entries,
                 yVariableDown=None,
                 upperFraction=0.7,
                 lowerFraction=0.3):
        BasicPlot.__init__(self, title, xVariable, yVariableUp)
        self.plotUp = BasicPlot(title + '_up', xVariable, yVariableUp)
        self.plotDown = BasicPlot(title + '_down', xVariable, yVariableDown)
        self.plotDown.drawLegend = False
        self.plotDown.showBinWidthY = False
        self.upperFraction = upperFraction
        self.lowerFraction = lowerFraction
        self.legendElements = self.plotUp.legendElements
        self.titles = self.plotUp.titles
        self.plotDown.drawLegend = False
        self.plotDown.drawTitle = False

    def __initAction__(self):
        from ROOT import TCanvas
        ## Method that does all the magic
        if not self.canvas:
            self.canvas = TCanvas(alphanumericString(self.title), self.title,
                                  self.xSize, self.ySize)
        BasicPlot.__initAction__(self)
        self.plotDown.__initAction__()
        self.plotUp.__initAction__()

        self.canvas.Divide(1, 2)
        self.plotUp.canvas = self.canvas.cd(1)
        self.plotDown.canvas = self.canvas.cd(2)
        self.plotUp.drawLegend = self.drawLegend
        self.plotUp.drawTitle = self.drawTitle

        # initialize layout
        self.plotUp.canvas.SetPad(0., 1. - self.upperFraction, 1., 1.)
        self.plotUp.canvas.SetBottomMargin(0.03)
        self.plotUp.canvas.SetTopMargin(self.plotDown.canvas.GetTopMargin() /
                                        self.upperFraction)
        self.plotUp.canvas.Update()
        self.plotDown.canvas.SetPad(0., 0., 1., self.lowerFraction)
        self.plotDown.canvas.SetTopMargin(0.)
        self.plotDown.canvas.SetBottomMargin(
            self.plotDown.canvas.GetBottomMargin() / (self.lowerFraction))
        self.plotDown.canvas.SetGridy(True)
        self.plotDown.canvas.Update()
        self.canvas.Update()

        if self.firstTimeDrawn:
            self.plotUp.topMargin = self.topMargin / self.upperFraction
            self.plotUp.bottomMargin = self.bottomMargin / self.bottomMargin
            self.plotUp.legendDecorator.defaultUpperY = 1. - (
                1 - self.legendDecorator.defaultUpperY) / self.upperFraction
            self.plotUp.legendDecorator.defaultLowerY = self.legendDecorator.defaultLowerY / self.upperFraction
            self.plotUp.legendDecorator.labelTextSize = self.legendDecorator.labelTextSize / self.upperFraction
            self.plotUp.legendDecorator.textSize = self.legendDecorator.textSize / self.upperFraction
            self.plotUp.legendDecorator.lineGap = self.legendDecorator.lineGap / self.upperFraction
            self.plotUp.titleDecorator.defaultUpperY = 1. - (
                1 - self.titleDecorator.defaultUpperY) / self.upperFraction
            self.plotUp.titleDecorator.defaultLowerY = self.titleDecorator.defaultLowerY / self.upperFraction
            self.plotUp.titleDecorator.textSize = self.titleDecorator.textSize / self.upperFraction
            self.plotUp.titleDecorator.labelTextSize = self.titleDecorator.labelTextSize / self.upperFraction

    def __mainAction__(self):
        BasicPlot.__mainAction__(self)
        self.plotDown.__mainAction__()
        self.plotUp.__mainAction__()

    def __drawHistograms__(self):
        BasicPlot.__drawHistograms__(self)
        self.plotDown.__drawHistograms__()
        self.plotUp.__drawHistograms__()

    def __drawFunctions__(self):
        BasicPlot.__drawFunctions__(self)
        self.plotDown.__drawFunctions__()
        self.plotUp.__drawFunctions__()

    def __drawDecorations__(self):
        # No top level decorations
        #BasicPlot.__drawDecorations__(self)
        self.plotDown.__drawDecorations__()
        self.plotUp.__drawDecorations__()

    def __drawObjects__(self):
        BasicPlot.__drawObjects__(self)
        self.plotDown.__drawObjects__()
        self.plotUp.__drawObjects__()

    def __finalizeAction__(self):
        self.plotUp.logX = self.logX
        self.plotUp.logY = self.logY
        self.plotUp.logZ = self.logZ
        self.plotDown.__finalizeAction__()
        self.plotUp.__finalizeAction__()
        if self.firstTimeDrawn:
            if self.plotUp.firstDrawnObject:
                xAxis = self.plotUp.firstDrawnObject.GetXaxis()
                xAxis.SetTickLength(xAxis.GetTickLength() / self.upperFraction)
                xAxis.SetLabelOffset(xAxis.GetLabelOffset() * 10.)
                xAxis.Draw()
                yAxis = self.plotUp.firstDrawnObject.GetYaxis()
                yAxis.SetTickLength(yAxis.GetTickLength() / self.upperFraction)
                yAxis.SetLabelSize(yAxis.GetLabelSize() / self.upperFraction)
                yAxis.SetLabelOffset(yAxis.GetLabelOffset() /
                                     self.upperFraction)
                yAxis.SetTitleSize(yAxis.GetTitleSize() / self.upperFraction)
                yAxis.SetTitleOffset(yAxis.GetTitleOffset() *
                                     self.upperFraction)
                yAxis.Draw()
        if self.plotDown.firstDrawnObject:
            xAxis = self.plotDown.firstDrawnObject.GetXaxis()
            xAxis.SetTickLength(xAxis.GetTickLength() / self.lowerFraction)
            xAxis.SetTitleSize(xAxis.GetTitleSize() / self.lowerFraction)
            xAxis.SetLabelSize(xAxis.GetLabelSize() / self.lowerFraction)
            xAxis.SetLabelOffset(xAxis.GetLabelOffset() / self.lowerFraction)
            xAxis.Draw()
            yAxis = self.plotDown.firstDrawnObject.GetYaxis()
            self.plotDown.firstDrawnObject.SetMinimum(0.9)
            self.plotDown.firstDrawnObject.SetMaximum(1.1)
            yAxis.SetNdivisions(5)
            yAxis.CenterTitle(True)
            yAxis.SetTickLength(yAxis.GetTickLength() / self.lowerFraction *
                                0.5)
            yAxis.SetLabelSize(yAxis.GetLabelSize() / self.lowerFraction * 0.5)
            yAxis.SetLabelOffset(yAxis.GetLabelOffset() / self.lowerFraction *
                                 0.5)
            yAxis.SetTitleSize(yAxis.GetTitleSize() / self.lowerFraction * 0.7)
            yAxis.SetTitleOffset(yAxis.GetTitleOffset() * self.lowerFraction *
                                 0.8)
            yAxis.Draw()

        #self.stretchAxis( self.plotUp.firstDrawnObject, 1./self.upperFraction, 1.0 )
        #self.stretchAxis( self.plotDown.firstDrawnObject, 1./self.lowerFraction, 0.7 )
        self.plotUp.canvas.Update()
        self.plotDown.canvas.Update()
        self.canvas.Update()
        BasicPlot.__finalizeAction__(self)

    def stretchAxis(self, drawnObject, factor, yFactor=1.0):
        # get the axis
        xAxis = drawnObject.GetXaxis()
        yAxis = drawnObject.GetYaxis()

        for axis in [xAxis, yAxis]:
            axis.SetTickLength(axis.GetTickLength() * factor)
            axis.SetLabelSize(0.05 * factor)
            axis.SetLabelOffset(axis.GetLabelOffset() * factor)
            if axis == xAxis:
                axis.SetTitleSize(axis.GetTitleSize() * factor)
                # axis.SetLabelOffset( axis.GetLabelOffset() * factor )
                # axis.SetTitleOffset( axis.GetTitleOffset() / factor )
            if axis == yAxis:
                axis.SetTitleSize(axis.GetTitleSize() * factor * yFactor)
                axis.SetTitleOffset(axis.GetTitleOffset() / (factor * yFactor))
Beispiel #9
0
    binning = Binning(50, 0, 100)
    var_tau_0_pt = Variable('tau_0_pt',
                            title='p_{T}(#tau_{0})',
                            unit='GeV',
                            binning=binning)
    var_tau_1_pt = Variable('tau_1_pt',
                            title='p_{T}(#tau_{1})',
                            unit='GeV',
                            binning=binning)
    var_tau_pt = CombinedVariable('tau_0_pt',
                                  'p_{T}(#tau)',
                                  'GeV',
                                  binning,
                                  variables=[var_tau_0_pt, var_tau_1_pt])

    p = BasicPlot('Test Plot', var_tau_pt)
    p.addHistogram(
        var_tau_pt.createHistogramFromTree(t, 'Any Tau', style=blackLine),
        'E0')
    p.addHistogram(
        var_tau_0_pt.createHistogramFromTree(t, 'Leading Tau', style=redLine),
        'E0')
    p.addHistogram(
        var_tau_1_pt.createHistogramFromTree(t,
                                             'Sub-Leading Tau',
                                             style=blueLine), 'E0')
    p.draw()

    raw_input('Continue?')
Beispiel #10
0
		    h_tmp.Divide( h_data_fr[i], h_mc_fr[i]) # Do NOT use binomial errors for scale factors!
		    h_sf.append( h_tmp )
	    if not only_mc_fakes:
		histo_set = [	h_data,		h_mc,		h_data_fr,	h_mc_fr,	h_sf	]
	    else:
		histo_set = [	h_mc,		h_mc_fr		]
	    # Plotting Fake Rates and Scale Factors
	    # -------------------------------------
	    for i_type in range(len(name_type)): # Selection, FR or SF plot?
		if name_type[i_type] == '_SF':
		    n_sets = 1
		else:
		    n_sets = len(name_set)
		for i_set in range(n_sets): # data or mc plot ?
		    if i_type == 2: # SF plots have a different naming convention
			bp = BasicPlot( 'FakeRate_'+var.name+name_type[i_type]+sel_p_suffix[p], var )
		    else:
			bp = BasicPlot( 'FakeRate_'+var.name+name_type[i_type]+sel_p_suffix[p]+name_set[i_set], var )
		    bp.showBinWidthY = False
		    if name_type[i_type] == '_SF': # Draw a line at 1 for SF plots
			h_tmp = var.createHistogram( '' )
			for i_bin in range( h_tmp.GetNbinsX() + 2 ):
			    h_tmp.SetBinContent( i_bin, 1 )
			    h_tmp.SetBinError( i_bin, 0 )
			h_tmp.SetLineColor( kGray )
			bp.addHistogram( h_tmp, 'E' )
		    for i in range(id_range[i_type]): # Loop over different IDs
			histo_set[len(name_set)*i_type+i_set][i].SetLineColor( sel_colors[i] )
			histo_set[len(name_set)*i_type+i_set][i].SetMarkerColor( sel_colors[i] )
			histo_set[len(name_set)*i_type+i_set][i].SetMarkerStyle( sel_marker[i] )
			bp.addHistogram( histo_set[len(name_set)*i_type+i_set][i], 'E', copy=True )
Beispiel #11
0
    from plotting.BasicPlot import BasicPlot
    var = Variable(
        'ditau_tau0_decay_mode', 'ditau_tau0_decay_mode',
        'Decay Mode (#tau_{0})', '',
        Binning(6, 0, 6, ['1p0n', '1p1n', '1pXn', '3p0n', '3pXn', 'Other']))

    h = var.createHistogram('h_test')
    h.Fill(2)
    h.Fill(3)
    h.Fill(2)
    h.Fill(0)
    h.Fill(2)

    g = histToGraph(h, 'g_test')
    g.SetLineColor(2)

    #g = addGraphs( g, g, True )

    p = BasicPlot('test', var)
    p.addHistogram(h)
    p.addGraph(g, '0')
    p.draw()

    interrupt()

    import time

    for i in xrange(35):
        progressBarInt(i + 1, 35, 'index: %d' % i)
        time.sleep(0.01)
Beispiel #12
0
    energyVar = Variable('energy',
                         title='Hit Energy',
                         unit='MeV',
                         binning=Binning(50, 0, 100))

    # create a plot using the TreePlot class
    treePlotTest = TreePlot('TreePlot Test',
                            sizeVar,
                            Variable('Entries'),
                            tree=t)
    treePlotTest.addCut('No Cut')
    treePlotTest.addCut('Energy > 15 MeV', 'energy > 15')
    treePlotTest.draw()

    # create a plot using the BasicPlot class
    testBasicPlot = BasicPlot('BasicPlot test', energyVar, Variable('Entries'))
    testBasicPlot.addHistogram(
        createHistogramFromTree(t,
                                energyVar,
                                'Size > 1',
                                Cut('size > 1'),
                                style=redLine), 'E0')
    testBasicPlot.addHistogram(
        createHistogramFromTree(t,
                                energyVar,
                                'Size > 3',
                                Cut('size > 3'),
                                style=blueLine), 'E0')
    testBasicPlot.addHistogram(
        createHistogramFromTree(t,
                                energyVar,
Beispiel #13
0
 def __drawFunctions__(self):
     BasicPlot.__drawFunctions__(self)
     self.plotDown.__drawFunctions__()
     self.plotUp.__drawFunctions__()
Beispiel #14
0
def PullPlot(filename,
             h_data,
             h_quarks,
             h_gluons,
             w_quarks=None,
             w_gluons=None,
             pull_widths=[1, 1]):
    # Creating a pull-plot
    # --------------------
    ratio_q = []
    error_q = []
    ratio_g = []
    error_g = []
    n_runs = 10000
    # getting fit results for toy experiments
    for i in range(1, n_runs + 1):
        if i == 1: print "    starting loop"
        h_tmp = var.createHistogram(str(i))
        h_tmp.FillRandom(h_data)
        filename_tmp = filename + '_' + str(i)
        out_file.write(str(i) + ":\n")

        fit = TemplateFit(filename,
                          h_tmp,
                          h_quarks,
                          h_gluons,
                          w_quarks,
                          w_gluons,
                          pull_widths,
                          doPlots=False)

        val_q = ROOT.Double()
        err_q = ROOT.Double()
        val_g = ROOT.Double()
        err_g = ROOT.Double()
        fit.GetResult(0, val_q, err_q)
        fit.GetResult(1, val_g, err_g)
        del fit
        err_q = err_q * pull_widths[
            0]  # correcting the error for the width of the pull plot
        err_g = err_g * pull_widths[
            1]  # correcting the error for the width of the pull plot

        ratio_q.append(val_q)
        error_q.append(err_q)
        ratio_g.append(val_g)
        error_g.append(err_g)

        if i % (n_runs / 10) == 0 or i == 1 or i == n_runs:
            print "    {}\tQ: {} +- {}\tG: {} +- {}".format(
                i, val_q, err_q, val_g, err_g)

    # creating pull histogram for quarks
    h_pull = var_pull.createHistogram()
    ratio_q_mean = sum(ratio_q) / len(ratio_q)
    for i in range(n_runs):
        tmp = (ratio_q[i] - ratio_q_mean) / error_q[i]
        h_pull.Fill(tmp)

    fit_result = h_pull.Fit('gaus', 'QS')
    f_gaus = h_pull.GetFunction('gaus')
    v_q_mu = fit_result.Parameter(1)
    v_q_mu_err = fit_result.ParError(1)
    v_q_sigma = fit_result.Parameter(2)
    v_q_sigma_err = fit_result.ParError(2)
    chi = fit_result.Chi2()
    ndf = fit_result.Ndf()
    #red_chi = chi / ndf

    filename_tmp = filename + '_PullPlot_q'
    bp = BasicPlot(filename_tmp, var_pull)
    bp.titles.append(
        'Fit Results: #mu = {:05.3f}#pm{:05.3f}, #sigma = {:05.3f}#pm{:05.3f}'.
        format(v_q_mu, v_q_mu_err, v_q_sigma, v_q_sigma_err))
    bp.titles.append('#chi^{{2}}/ndf: {:.3}/{}'.format(chi, ndf))
    bp.addHistogram(h_pull, 'E', copy=True)
    bp.yVariable = Variable("Events")
    bp.normalizeByBinWidth = False
    bp.showBinWidthY = False
    bp.normalized = False
    bp.logY = False
    bp.yVariable.binning.low = 0  # start y-axis at 0
    bp.draw()
    bp.saveAsAll(os.path.join(outFolder, bp.title))

    del h_pull
    del bp

    # creating pull histogram for gluons
    h_pull = var_pull.createHistogram()
    ratio_g_mean = sum(ratio_g) / len(ratio_g)
    for i in range(n_runs):
        tmp = (ratio_g[i] - ratio_g_mean) / error_g[i]
        h_pull.Fill(tmp)

    fit_result = h_pull.Fit('gaus', 'QS')
    f_gaus = h_pull.GetFunction('gaus')
    v_g_mu = fit_result.Parameter(1)
    v_g_mu_err = fit_result.ParError(1)
    v_g_sigma = fit_result.Parameter(2)
    v_g_sigma_err = fit_result.ParError(2)
    chi = fit_result.Chi2()
    ndf = fit_result.Ndf()
    #red_chi = chi / ndf

    filename_tmp = filename + '_PullPlot_g'
    bp = BasicPlot(filename_tmp, var_pull)
    bp.titles.append(
        'Fit Results: #mu = {:05.3f}#pm{:05.3f}, #sigma = {:05.3f}#pm{:05.3f}'.
        format(v_g_mu, v_g_mu_err, v_g_sigma, v_g_sigma_err))
    bp.titles.append('#chi^{{2}}/ndf: {:.3}/{}'.format(chi, ndf))
    bp.addHistogram(h_pull, 'E', copy=True)
    bp.yVariable = Variable("Events")
    bp.normalizeByBinWidth = False
    bp.showBinWidthY = False
    bp.normalized = False
    bp.logY = False
    bp.yVariable.binning.low = 0  # start y-axis at 0
    bp.draw()
    bp.saveAsAll(os.path.join(outFolder, bp.title))

    return [v_q_sigma, v_g_sigma]
Beispiel #15
0
 def __mainAction__(self):
     BasicPlot.__mainAction__(self)
     self.plotDown.__mainAction__()
     self.plotUp.__mainAction__()
Beispiel #16
0
def storeHistogram(var, lumi, cut, histo, filename):
    # Plotting Data
    # ------------------
    bp = BasicPlot(filename, var)
    bp.addHistogram(histo, 'E', copy=True)
    bp.titles.append(
        "#sqrt{{s}} = 13 TeV, #scale[0.5]{{#int}}Ldt = {0:.2f} fb^{{-1}}".
        format(lumi / 1000.))
    bp.yVariable = Variable("Events")
    bp.normalizeByBinWidth = False
    bp.showBinWidthY = False
    bp.normalized = False
    bp.logY = False
    bp.yVariable.binning.low = 0  # start y-axis at 0
    bp.draw()
    bp.saveAsAll(os.path.join(outFolder, bp.title))
    # storing histogram in root file
    # ------------------------------
    from ROOT import TFile, TObject
    rootfile = TFile.Open(outFolder + '/' + filename + '.root', 'update')
    if rootfile.IsOpen():
        print "writing in file {}".format(outFolder + '/' + filename + '.root')
        rootfile.cd()
        histogram = histo.Clone('h_' + var.name)
        histogram.SetTitle('h_' + var.name)
        histogram.Write('h_' + var.name, TObject.kOverwrite)
        rootfile.Close()
    else:
        print "Problem opening file {}".format(outFolder + '/' + filename +
                                               '.root')
Beispiel #17
0
                                                 weight=tmp_weight)
                    sys.stdout.write('.')
                    sys.stdout.flush()
            sys.stdout.write(' ')
            sys.stdout.flush()
            # Styling
            # --------
            h_jet.SetLineColor(sel_colors[0])
            h_jet.SetMarkerColor(sel_colors[0])
            h_jet.SetMarkerStyle(sel_marker[0])
            h_tau.SetLineColor(sel_colors[1])
            h_tau.SetMarkerColor(sel_colors[1])
            h_tau.SetMarkerStyle(sel_marker[1])
            # Plotting
            # --------
            bp = BasicPlot('TauID-studies_' + var.name + sel_p_suffix[i_p],
                           var)
            bp.showBinWidthY = False
            bp.addHistogram(h_jet, 'E', copy=True)
            bp.addHistogram(h_tau, 'E', copy=True)
            bp.titles.append(
                '#sqrt{{s}} = 13 TeV, #scale[0.5]{{#int}}Ldt = {0:.2f} fb^{{-1}}'
                .format(lumi / 1000.))
            bp.yVariable = Variable('normalized')
            if var.name == 'SumPtTrkFracCorrected':
                bp.logY = True
            bp.normalized = True
            bp.draw()
            bp.saveAsAll(os.path.join("plots/", bp.title))
        print " done with {0}".format(var.name)
    print 'everything is done!'
Beispiel #18
0
 sys.stdout.flush()
 h_var_r2 = process.getHistogram(var,
                                 "Region 2",
                                 cut=selections[0] +
                                 sel_p[i_p] +
                                 cut_option_region2,
                                 luminosity=lumi,
                                 weight=tmp_weight)
 sys.stdout.write('.')
 sys.stdout.flush()
 h_var_r1.SetLineColor(kRed)
 h_var_r1.SetMarkerColor(kRed)
 h_var_r2.SetLineColor(kBlue)
 h_var_r2.SetMarkerColor(kBlue)
 bp = BasicPlot(
     'Q-G-Separation' + sel_p_suffix[i_p] + '_' +
     var.name + cut_option_suffix, var)
 bp.yVariable = Variable("Events with quark match")
 bp.yVariable.binning.low = 0
 bp.yVariable.binning.up = None
 bp.showBinWidthY = False
 bp.addHistogram(h_var_r1, 'E', copy=True)
 bp.addHistogram(h_var_r2, 'E', copy=True)
 bp.titles.append(
     '#sqrt{{s}} = 13 TeV, #scale[0.5]{{#int}}Ldt = {0:.2f} fb^{{-1}}, '
     .format(lumi / 1000.))
 bp.draw()
 bp.saveAsAll(os.path.join("plots/", bp.title))
 # print quark rate
 h_var_tot_r1 = process.getHistogram(var,
                                     "Region 1",
Beispiel #19
0
def TemplateFit(filename,
                data,
                mc_q,
                mc_g,
                w_q=None,
                w_g=None,
                pull_widths=[1, 1],
                doPlots=True):
    n_mc = 2

    # Define MC samples
    mc = TObjArray(n_mc)
    mc.Add(mc_q)
    mc.Add(mc_g)

    # Names
    mc_type = []
    mc_type.append('Quarks')
    mc_type.append('Gluons')

    # Perform Fit
    fit = TFractionFitter(data, mc, "q")
    if w_q and w_g:
        fit.SetWeight(0, w_q)
        fit.SetWeight(1, w_g)
    fit.Constrain(0, 0.0, 1.0)  #quarks
    fit.Constrain(1, 0.0, 1.0)  #gluons
    fit.Fit()

    # Printing results
    val_q = ROOT.Double()
    err_q = ROOT.Double()
    val_g = ROOT.Double()
    err_g = ROOT.Double()
    fit.GetResult(0, val_q, err_q)
    fit.GetResult(1, val_g, err_g)
    err_q = err_q * pull_widths[
        0]  # correcting the error for the width of the pull plot
    err_g = err_g * pull_widths[
        1]  # correcting the error for the width of the pull plot
    for i in range(n_mc):
        val = ROOT.Double()
        err = ROOT.Double()
        fit.GetResult(i, val, err)
        out_file.write("fit result {}: {}, {}\n".format(mc_type[i], val, err))
    out_file.write("X2 = {}\n".format(fit.GetChisquare()))
    out_file.write("NDF = {}\n".format(fit.GetNDF()))
    red_chi = fit.GetChisquare() / fit.GetNDF()
    out_file.write("red. X2 = {}\n".format(red_chi))
    out_file.write("\n")

    if doPlots:
        print "storing plot as {}".format(filename)
        # Preparing Histograms
        h_fit = fit.GetPlot()
        h_q = fit.GetMCPrediction(0)
        h_g = fit.GetMCPrediction(1)
        h_fit.SetTitle("Fit")
        h_q.SetTitle("Quarks")
        h_g.SetTitle("Gluons")
        h_fit.SetLineColor(kGreen)
        h_q.SetLineColor(kRed)
        h_g.SetLineColor(kBlue)
        h_q.SetMarkerColor(kRed)
        h_g.SetMarkerColor(kBlue)

        # Scaling to the fit result
        int_fit = h_fit.Integral()
        int_q = h_q.Integral()
        int_g = h_g.Integral()
        h_q.Sumw2()
        h_g.Sumw2()
        h_q.Scale(val_q * int_fit / int_q)
        h_g.Scale(val_g * int_fit / int_g)

        # Checking fit vs. templates
        h_check = h_fit.Clone('Fit - Templates Check')
        h_check.Add(h_q, -1)
        h_check.Add(h_g, -1)
        check_maxBin = h_check.GetMaximumBin()
        out_file.write(
            "Maximal bin of fit minus templates divided by content of that bin in fit: {} / {}\n\n"
            .format(h_fit.GetBinContent(check_maxBin),
                    h_check.GetBinContent(check_maxBin)))

        # Plotting results
        bp = BasicPlot(filename, var_tau0_width)
        bp.addHistogram(h_q, 'E', copy=True)
        bp.addHistogram(h_g, 'E', copy=True)
        bp.addHistogram(h_fit, 'HIST', copy=True)
        bp.addHistogram(data, 'E', copy=True)
        bp.titles.append(
            'Quarks: {:.3} #pm {:.2}, Gluons: {:.3} #pm {:.2}'.format(
                val_q, err_q, val_g, err_g))
        bp.titles.append(
            '#sqrt{{s}} = 13 TeV, #scale[0.5]{{#int}}Ldt = {0:.2f} fb^{{-1}}'.
            format(lumi / 1000.))
        bp.titles.append('#chi^{{2}}/ndf: {:.3}'.format(red_chi))
        bp.yVariable = Variable("Events")
        bp.legendDecorator.textSize = 0.045
        bp.normalizeByBinWidth = False
        bp.showBinWidthY = False
        bp.normalized = False
        bp.logY = False
        bp.yVariable.binning.low = 0  # start y-axis at 0
        bp.draw()
        bp.saveAsAll(os.path.join(outFolder, bp.title))

    return fit
Beispiel #20
0
 def __drawHistograms__(self):
     BasicPlot.__drawHistograms__(self)
     self.plotDown.__drawHistograms__()
     self.plotUp.__drawHistograms__()
Beispiel #21
0
 def __drawDecorations__(self):
     BasicPlot.__drawDecorations__(self)
     self.plotDown.__drawDecorations__()
     self.plotUp.__drawDecorations__()
Beispiel #22
0
 def __drawObjects__(self):
     BasicPlot.__drawObjects__(self)
     self.plotDown.__drawObjects__()
     self.plotUp.__drawObjects__()
Beispiel #23
0
             tmp_weight = weight_expression + '*SF_dilepton_pt_vect'
             h_id = process.getHistogram(var,
                                         sel_names[i],
                                         cut=selections[i] +
                                         sel_p[p],
                                         luminosity=lumi,
                                         weight=tmp_weight)
             h_mc.append(h_id)
             sys.stdout.write('.')
             sys.stdout.flush()
 print "\tgot all{0} histograms for {1}".format(
     sel_p_names[p], var.name)
 # Plotting
 # --------
 if do_plots:
     bp = BasicPlot(var.name + sel_p_suffix[p], var)
     bp.legendDecorator.textSize = 0.045
     bp.showBinWidthY = False
     for i in range(
             len(selections)):  # Loop over different selections
         h_mc[i].SetLineColor(sel_colors[i])
         h_mc[i].SetMarkerColor(sel_colors[i])
         h_mc[i].SetMarkerStyle(sel_marker[i])
         bp.addHistogram(h_mc[i], 'E', copy=True)
     bp.titles.append(
         'Simulation, #sqrt{{s}} = 13 TeV, #scale[0.5]{{#int}}Ldt = {0:.2f} fb^{{-1}}'
         .format(lumi / 1000.))
     bp.normalizeByBinWidth = False
     bp.normalized = True
     bp.yVariable = Variable('Normalized')
     #bp.yVariable = Variable( 'Events' )
Beispiel #24
0
if __name__ == '__main__':
    from ROOT import TTree, TRandom3
    from array import array
    from plotting.Variable import Variable, Binning
    from AtlasStyle import redLine, blueLine, greenLine
    
    # create some dummy tree
    rndm = TRandom3()
    size = array( 'f', [0] )
    energy = array( 'f', [0] )
    t = TTree( 'tree', 'My Tree' )
    t.Branch( 'size', size, 'size/F' )
    t.Branch( 'energy', energy, 'energy/F' )
    for entry in xrange( 10000 ):
        size[0] = rndm.Poisson( 3 )
        energy[0] = rndm.Landau( size[0]*2.5, size[0] )
        t.Fill()
    
    # define a variable object for each branch
    sizeVar = Variable( 'size', title='Cluster Size', binning=Binning(10, 1, 11, range(1,11)) )
    energyVar = Variable( 'energy', title='Hit Energy', unit='MeV', binning=Binning(50, 0, 100) )

    p = BasicPlot( 'test', sizeVar, Variable( 'RMS(E)', unit = 'MeV' ) )
    measure = HalfWidth()
    measure.selection = Truncate( 0.68 )
    g = p.addGraph( resolutionGraph( t, sizeVar, energyVar, '', measure ) )
    p.draw()

    g.Draw()
    
    raw_input( 'Continue?' )
Beispiel #25
0
def PlotAndStore(var,
                 filename,
                 lumi,
                 h_1,
                 h_2=None,
                 h_3=None,
                 drawOneLine=False,
                 simulation=False,
                 yLabel="Fake Rate",
                 yLow=0,
                 yHigh=None):
    bp = BasicPlot(filename, var)
    # Add histos
    SetHistStyle(h_1, 0)
    bp.addHistogram(h_1, 'E', copy=True)
    if h_2:
        SetHistStyle(h_2, 1)
        bp.addHistogram(h_2, 'E', copy=True)
    if h_3:
        SetHistStyle(h_3, 2)
        bp.addHistogram(h_3, 'E', copy=True)
    # Draw a line at 1 e.g. for SF plots
    if drawOneLine:
        h_tmp = var.createHistogram('')
        for i_bin in range(h_tmp.GetNbinsX() + 2):
            h_tmp.SetBinContent(i_bin, 1)
            h_tmp.SetBinError(i_bin, 0)
        h_tmp.SetLineColor(kGray)
        bp.addHistogram(h_tmp, 'E')
    # Some further settings
    bp.titles.append(
        '#sqrt{{s}} = 13 TeV, #scale[0.5]{{#int}}Ldt = {0:.2f} fb^{{-1}}'.
        format(lumi / 1000.))
    bp.legendDecorator.textSize = 0.045
    if simulation:
        bp.titles.append('Simulation')
    bp.showBinWidthY = False
    bp.logY = False
    bp.normalized = False
    bp.normalizeByBinWidth = False
    bp.yVariable = Variable(yLabel)
    bp.yVariable.binning.low = yLow
    bp.yVariable.binning.up = yHigh
    # Plot and store
    bp.draw()
    bp.saveAsAll(os.path.join(outFolder, bp.title))