Created
June 27, 2011 06:40
-
-
Save mgmarino/1048407 to your computer and use it in GitHub Desktop.
Rescaling frame from RooFit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rescale_frame(canvas, frame, scale, title): | |
""" | |
HACK | |
Takes a frame and rescales it to arbitrary coordinates. | |
This is helpful when dealing with RooPlot to get the axes | |
correct. Returns axis in case anything else needs to be done. | |
""" | |
import ROOT | |
yaxis = frame.GetYaxis() | |
yaxis.SetTickLength(0) | |
yaxis.SetNdivisions(0) | |
yaxis.SetLabelSize(0) | |
yaxis.SetTitle("") | |
yaxis.SetLabelColor(10) | |
yaxis.SetAxisColor(10) | |
frame.Draw() | |
canvas.Update() | |
amax = frame.GetMaximum() | |
amin = frame.GetMinimum() | |
new_max = amax*scale | |
new_min = amin*scale | |
x = canvas.PadtoX | |
y = canvas.PadtoY | |
axis = ROOT.TGaxis(x(canvas.GetUxmin()), y(canvas.GetUymin()), | |
x(canvas.GetUxmin()), y(canvas.GetUymax()), | |
new_min,new_max,510,"") | |
axis.SetTitle(title) | |
axis.Draw() | |
canvas.Update() | |
return axis | |
# example usage | |
final_pdf.plotOn(frame, ROOT.RooFit.LineStyle(ROOT.kDashed), | |
ROOT.RooFit.Components("energy_pdf_flat*")) | |
frame.Draw() | |
myaxis = rescale_frame(c1, frame, scale, "Counts/kg") | |
c1.Update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment