class TriggerRateComparisonPlot(object): """ Class that puts a TriggerRate object and TriggerRateRatio object on the same page. """ instantiationCount = 0 # Need this to get around root's stupid requirement for globally unique names def __init__(self): self.instantiationCount = TriggerRateComparisonPlot.instantiationCount TriggerRateComparisonPlot.instantiationCount += 1 splitPoint = 0.33 self.padRatio = (1 - splitPoint) / splitPoint self.canvas = TCanvas() # Use the instantiation count to give every instance unique names for the pads self.ratePad = TPad( "TriggerRateComparisonPlot(" + str(self.instantiationCount) + ").ratePad", "L1 rate", 0, splitPoint, 1, 1) self.ratioPad = TPad( "TriggerRateComparisonPlot(" + str(self.instantiationCount) + ").ratioPad", "L1 ratio", 0, 0, 1, splitPoint) self.ratePad.Draw() self.ratioPad.Draw() self.ratioPad.SetTopMargin(0) self.ratioPad.SetBottomMargin( self.ratePad.GetBottomMargin() * self.padRatio * 1.1) # A little 10% extra because some is cut off self.ratePad.SetBottomMargin( 0.15) # was zero before I wanted to see the axis self.ratePlot = TriggerRate(self.ratePad) self.ratioPlot = TriggerRateRatio(self.ratioPad) def add(self, histogram, legendName=None): self.ratePlot.add(histogram, legendName) if len(self.ratePlot.histograms) > 1: self.ratioPlot.add(self.ratePlot.histograms[0], histogram) def addByTriggerName(self, file, triggerName, legendName=None): # Try the old format with the name used in L1Menu2015.C macro histogram = file.Get("h_" + triggerName + "_byThreshold") if histogram != None: return self.add(histogram, legendName) # Try the name given when there is more than one threshold and they're all scaled histogram = file.Get("L1_" + triggerName + "_v_allThresholdsScaled") if histogram != None: return self.add(histogram, legendName) # Try the name when there is only one threshold histogram = file.Get("L1_" + triggerName + "_v_threshold1") if histogram != None: return self.add(histogram, legendName) def addVerticalLine(self, xPosition, colour=1, thickness=3): self.ratePlot.addVerticalLine(xPosition, colour, thickness) self.ratioPlot.addVerticalLine(xPosition, colour, thickness) def draw(self): self.ratePlot.axisTitleSize = 0.053 self.ratioPlot.axisLabelSize = self.ratePlot.axisLabelSize * self.padRatio self.ratioPlot.axisTitleSize = self.ratePlot.axisTitleSize * self.padRatio self.ratioPlot.axisTitleOffset = self.ratePlot.axisTitleOffset / self.padRatio self.ratePlot.draw() self.ratioPlot.draw() self.canvas.Update()