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 __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 #3
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 #4
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))