3 """ plotting_utils.py : utility functions for plotting """
5 __author__ =
"Marco Milesi"
6 __email__ =
"marco.milesi@unimelb.edu.au"
7 __maintainer__ =
"Marco Milesi"
14 def get_ndf(data, fitres):
16 Return the number of degrees of freedom from RooDataHist and RooFitResult
18 nbins = data.numEntries()
19 params = fitres.floatParsFinal().getSize()
23 def draw_plots(**kwargs):
25 hypodir =
"pdg{0}{1}".format(abs(kwargs[
"hypo"]), kwargs[
"append"])
27 baseplotdir =
"{0}/FitPlots/{1}".format(kwargs[
"outputplots"], hypodir)
28 for plottype
in [
"LINY",
"LOGY"]:
29 plotdir =
"{0}/{1}".format(baseplotdir, plottype)
30 if not os.path.exists(plotdir):
33 pdfplot = ROOT.TCanvas(
"pdfplot",
"pdfplot", 1200, 1000)
35 pad1 = ROOT.TPad(
"pad1",
"", 0, 0.25, 1, 1)
36 pad2 = ROOT.TPad(
"pad2",
"", 0, 0, 1, 0.25)
37 pad1.SetBottomMargin(0.02)
38 pad2.SetBottomMargin(0.4)
42 frame1 = kwargs[
"frame1"]
45 frame1.GetYaxis().SetTitleSize(0.05)
46 frame1.GetYaxis().SetTitleOffset(0.8)
47 frame1.GetXaxis().SetLabelSize(0)
48 frame1.GetXaxis().SetLabelOffset(999)
49 frame1.getAttText(
'pdf_paramBox').SetLineWidth(0)
50 frame1.getAttText(
'pdf_paramBox').SetFillStyle(0)
53 chi2 = frame1.chiSquare()
57 t.SetTextColor(ROOT.kBlack)
60 t.DrawLatex(0.15, 0.8,
"#frac{{#chi^{{2}}}}{{ndf}} = #frac{{{0:.1f}}}{{{1}}}".format(chi2 * kwargs[
"ndf"], kwargs[
"ndf"]))
62 frame2 = kwargs[
"frame2"]
65 frame2.GetYaxis().SetTitle(frame2.GetTitle())
67 frame2.GetYaxis().SetTitleSize(0.14)
68 frame2.GetYaxis().SetTitleOffset(0.3)
69 frame2.GetYaxis().SetLabelSize(0.1)
70 frame2.GetXaxis().SetTitleSize(0.15)
71 frame2.GetXaxis().SetLabelSize(0.15)
72 frame2.GetXaxis().SetNdivisions(kwargs[
"ndiv"])
75 badfit =
"__BADFIT" if (chi2 > 500
or math.isnan(chi2))
else ""
77 outname =
"{0}/LINY/{1}_{2}_{3}{4}".format(baseplotdir,
82 pdfplot.Print(
"{0}.pdf".format(outname))
87 outname = outname.replace(
"LINY",
"LOGY")
88 pdfplot.Print(
"{0}_LOGY.pdf".format(outname))