def plot(pad, w, pdfname, dsetname, resid=False, cat=None, popts=None, dopts=None): if cat: if cat.startswith('b0_'): cat = cat.replace('b0_', '') if cat.startswith('bs_'): cat = cat.replace('bs_', '') xtitle = { 'b0g': '#it{m}(' + rt.Dzb + rt.g + rt.Kp + rt.pim + ') [MeV/c^{2}]', 'b0pi0': '#it{m}(' + rt.Dzb + rt.piz + rt.Kp + rt.pim + ') [MeV/c^{2}]', 'bsg': '#it{m}(' + rt.Dzb + rt.g + rt.Km + rt.pip + ') [MeV/c^{2}]', 'bspi0': '#it{m}(' + rt.Dzb + rt.piz + rt.Km + rt.pip + ') [MeV/c^{2}]' } leg = { 'b0g': '#it{B}^{0} #rightarrow #bar{#it{D}}^{0}#it{#gamma}#it{K}^{+}#it{#pi}^{-}', 'b0pi0': '#it{B}^{0} #rightarrow #bar{#it{D}}^{0}#it{#pi}^{0}#it{K}^{+}#it{#pi}^{-}', 'bsg': '#it{B_{s}}^{#kern[-0.2]{0}} #rightarrow #bar{#it{D}}^{0}#it{#gamma}#it{K}^{-}#it{#pi}^{+}', 'bspi0': '#it{B_{s}}^{#kern[-0.2]{0}} #rightarrow #bar{#it{D}}^{0}#it{#pi}^{0}#it{K}^{-}#it{#pi}^{+}' } if not popts: popts = RooLinkedList() if not dopts: dopts = RooLinkedList() pl = w.var('B_DTFDict_D0_B_M').frame() if cat: pl.GetXaxis().SetTitle(xtitle[cat]) if w.data(dsetname): w.data(dsetname).plotOn(pl, dopts) if w.pdf(pdfname): w.pdf(pdfname).plotOn(pl, popts) if resid and w.data(dsetname) and w.pdf(pdfname): pu = TPad(pad.GetName() + '_pu', '', 0., 0.33, 1., 1.) pd = TPad(pad.GetName() + '_pd', '', 0., 0., 1., 0.33) pu.SetBottomMargin(0.03) pd.SetTopMargin(0.03) pd.SetBottomMargin(0.35) pad.cd() pu.Draw() pd.Draw() pu.cd() pl.GetYaxis().SetTitleOffset(1.1) pl.GetXaxis().SetLabelSize(0.) pl.Draw() pd.cd() pull = pl.pullHist() # roofit does something funny with pull hist range so need a dummy hist for it pull.Draw() ymax = max(abs(pull.GetYaxis().GetXmin()), pull.GetYaxis().GetXmax()) pulld = TH1F(pull.GetName() + '_pd', '', pl.GetNbinsX(), pl.GetXaxis().GetXmin(), pl.GetXaxis().GetXmax()) pulld.GetYaxis().SetRangeUser(-ymax, ymax) pulld.GetXaxis().SetTitle(pl.GetXaxis().GetTitle()) pulld.GetYaxis().SetTitle("Pull") pl.GetXaxis().SetTitle("") pulld.GetXaxis().SetTitleSize(0.13) pulld.GetYaxis().SetTitleSize(0.13) pulld.GetXaxis().SetLabelSize(0.13) pulld.GetYaxis().SetLabelSize(0.13) pulld.GetXaxis().SetTitleOffset(1.1) pulld.GetYaxis().SetTitleOffset(0.6) pulld.GetYaxis().SetNdivisions(505) pulld.GetXaxis().SetTickLength(0.06) ll = TLine() ll.SetLineWidth(4) ll.SetLineColor(4) pd.cd() pd.Clear() pulld.Draw("HIST") pull.Draw("EPsame") ll.DrawLine(pulld.GetXaxis().GetXmin(), 0., pulld.GetXaxis().GetXmax(), 0.) pulld.Draw("AXISsame") gROOT.Append(pulld) else: pad.cd() pl.Draw() pad.cd() if cat: lat = TLatex() lat.SetTextSize(0.05) lat.SetNDC() lat.DrawLatex(0.6, 0.8, leg[cat]) gROOT.Append(lat) pad.Update() pad.Modified()
y.SetTitle("Data/MC") y.SetNdivisions(505) y.SetTitleSize(0.11) y.SetRangeUser(0.6, 1.4) y.SetTitleOffset(0.35) y.SetLabelSize(0.1) x = r_bdt_data.GetXaxis() x.SetTitleSize(0.11) x.SetTitleOffset(1.0) x.SetLabelSize(0.1) r_bdt_data.Draw("EP") c1.Print('histo_' + tmva_version + '_' + ch + '_bdt.pdf') ################################################ if keras: pad1.Clear() pad2.Clear() pad1.cd() keras_data.SetTitle("") keras_data.SetMarkerStyle(20) keras_data.SetMarkerSize(0.5) keras_data.SetStats(0) keras_data.SetMaximum(keras_data.GetMaximum() * 1.3) keras_data.GetYaxis().SetTitle("Events") keras_data.GetYaxis().SetTitleOffset(1.2) keras_data.GetYaxis().SetTitleSize(0.045) keras_data.GetXaxis().SetLabelSize(0) # keras_data.GetXaxis().SetTitleOffset(5.0) keras_data.Draw('P') hs_keras_bkg.Draw('HIST SAME E') keras_data.Draw('P SAME')
def plotData(pad, w, pdfname, dsetname, resid=False, cat=None, log=False): if cat.startswith('b0_'): cat = cat.replace('b0_', '') if cat.startswith('bs_'): cat = cat.replace('bs_', '') xtitle = { 'b0g': '#it{m}(' + rt.Dzb + rt.g + rt.Kp + rt.pim + ') [MeV/c^{2}]', 'b0pi0': '#it{m}(' + rt.Dzb + rt.piz + rt.Kp + rt.pim + ') [MeV/c^{2}]', 'bsg': '#it{m}(' + rt.Dzb + rt.g + rt.Km + rt.pip + ') [MeV/c^{2}]', 'bspi0': '#it{m}(' + rt.Dzb + rt.piz + rt.Km + rt.pip + ') [MeV/c^{2}]', 'cg': '#it{m}(' + rt.Dzb + rt.g + rt.pip + rt.pip + ') [MeV/c^{2}]', 'cpi0': '#it{m}(' + rt.Dzb + rt.piz + rt.pim + rt.pip + ') [MeV/c^{2}]' } leg = { 'b0g': { 'sig': rt.Decay('Bd', 'Dzb', 'g', 'Kp', 'pim'), 'misrec': rt.Decay('Bd', 'Dzb', 'piz', 'Kp', 'pim'), 'bdstpp': rt.Decay('Bd', 'Dzb', 'g', 'pip', 'pim'), 'bdstkk': rt.Decay('Bd', 'Dzb', 'g', 'Kp', 'Km'), 'bsdstkk': rt.Decay('Bs', 'Dzb', 'g', 'Kp', 'Km'), 'bdkp': rt.Decay('Bd', 'Dzb', 'Kp', 'pim'), 'bdsth': rt.Decay('Bm', 'Dzb', 'g', 'pim'), 'partrec': 'Part Reco', 'lbdph': rt.Decay('Lb', 'Dzb', 'p', 'pim'), 'lbdstph': rt.Decay('Lb', 'Dzb', 'g', 'p', 'pim'), 'comb': 'Combinatorial' }, 'b0pi0': { 'sig': rt.Decay('Bd', 'Dzb', 'piz', 'Kp', 'pim'), 'misrec': rt.Decay('Bd', 'Dzb', 'g', 'Kp', 'pim'), 'bdstpp': rt.Decay('Bd', 'Dzb', 'piz', 'pip', 'pim'), 'bdstkk': rt.Decay('Bd', 'Dzb', 'piz', 'Kp', 'Km'), 'bsdstkk': rt.Decay('Bs', 'Dzb', 'piz', 'Kp', 'Km'), 'bdkp': rt.Decay('Bd', 'Dzb', 'Kp', 'pim'), 'bdsth': rt.Decay('Bm', 'Dzb', 'piz', 'pim'), 'partrec': 'Part Reco', 'lbdph': rt.Decay('Lb', 'Dzb', 'p', 'pim'), 'lbdstph': rt.Decay('Lb', 'Dzb', 'piz', 'p', 'pim'), 'comb': 'Combinatorial' }, 'bsg': { 'sig': rt.Decay('Bs', 'Dzb', 'g', 'Km', 'pip'), 'misrec': rt.Decay('Bs', 'Dzb', 'piz', 'Km', 'pip'), 'bdstpp': rt.Decay('Bs', 'Dzb', 'g', 'pim', 'pip'), 'bdstkk': rt.Decay('Bs', 'Dzb', 'g', 'Km', 'Kp'), 'bsdstkk': rt.Decay('Bs', 'Dzb', 'g', 'Km', 'Kp'), 'bdkp': rt.Decay('Bs', 'Dzb', 'Km', 'pip'), 'bdsth': rt.Decay('Bp', 'Dzb', 'g', 'pip'), 'partrec': 'Part Reco', 'lbdph': rt.Decay('Lb', 'Dzb', 'p', 'Km'), 'lbdstph': rt.Decay('Lb', 'Dzb', 'g', 'p', 'Km'), 'comb': 'Combinatorial' }, 'bspi0': { 'sig': rt.Decay('Bs', 'Dzb', 'piz', 'Km', 'pip'), 'misrec': rt.Decay('Bs', 'Dzb', 'g', 'Km', 'pip'), 'bdstpp': rt.Decay('Bs', 'Dzb', 'piz', 'pim', 'pip'), 'bdstkk': rt.Decay('Bs', 'Dzb', 'piz', 'Km', 'Kp'), 'bsdstkk': rt.Decay('Bs', 'Dzb', 'piz', 'Km', 'Kp'), 'bdkp': rt.Decay('Bs', 'Dzb', 'Km', 'pip'), 'bdsth': rt.Decay('Bp', 'Dzb', 'piz', 'pip'), 'partrec': 'Part Reco', 'lbdph': rt.Decay('Lb', 'Dzb', 'p', 'Km'), 'lbdstph': rt.Decay('Lb', 'Dzb', 'piz', 'p', 'Km'), 'comb': 'Combinatorial' }, 'cg': { 'sig': rt.Decay('Bd', 'Dzb', 'g', 'pip', 'pim'), 'misrec': rt.Decay('Bd', 'Dzb', 'piz', 'pip', 'pim'), 'bdstkp': rt.Decay('Bs', 'Dzb', 'g', 'Km', 'pip'), 'bdkp': rt.Decay('Bd', 'Dzb', 'Kp', 'pim'), 'bdsth': rt.Decay('Bm', 'Dzb', 'g', 'pim'), 'comb': 'Combinatorial' }, 'cpi0': { 'sig': rt.Decay('Bd', 'Dzb', 'piz', 'pip', 'pim'), 'misrec': rt.Decay('Bd', 'Dzb', 'g', 'pip', 'pim'), 'bdstkp': rt.Decay('Bs', 'Dzb', 'piz', 'Km', 'pip'), 'bdkp': rt.Decay('Bd', 'Dzb', 'Kp', 'pim'), 'bdsth': rt.Decay('Bm', 'Dzb', 'piz', 'pim'), 'comb': 'Combinatorial' }, } pl = w.var('B_DTFDict_D0_B_M').frame() if cat: pl.GetXaxis().SetTitle(xtitle[cat]) tleg = TLegend(0.6, 0.5, 0.9, 0.95) tleg.SetFillColorAlpha(0, 0.) tleg.SetLineColor(0) if w.data(dsetname): w.data(dsetname).plotOn(pl) if w.pdf(pdfname): w.pdf(pdfname).plotOn(pl) w.pdf(pdfname).plotOn(pl, rf.Components('comb_mc_pdf_%s' % cat), rf.LineStyle(2), rf.LineColor(kBlack)) tleg.AddEntry(pl.getObject(int(pl.numItems()) - 1), leg[cat]['comb'], "L") if cat != 'cg' and cat != 'cpi0': w.pdf(pdfname).plotOn(pl, rf.Components('partrec_mc_pdf_%s' % cat), rf.LineStyle(2), rf.LineColor(kRed + 3)) tleg.AddEntry(pl.getObject(int(pl.numItems()) - 1), leg[cat]['partrec'], "L") w.pdf(pdfname).plotOn(pl, rf.Components('lbdph_mc_pdf_%s' % cat), rf.LineStyle(2), rf.LineColor(kMagenta)) tleg.AddEntry(pl.getObject(int(pl.numItems()) - 1), leg[cat]['lbdph'], "L") w.pdf(pdfname).plotOn(pl, rf.Components('lbdstph_mc_pdf_%s' % cat), rf.LineStyle(2), rf.LineColor(kMagenta + 3)) tleg.AddEntry(pl.getObject(int(pl.numItems()) - 1), leg[cat]['lbdstph'], "L") w.pdf(pdfname).plotOn(pl, rf.Components('bdsth_mc_pdf_%s' % cat), rf.LineStyle(2), rf.LineColor(kRed - 3)) tleg.AddEntry(pl.getObject(int(pl.numItems()) - 1), leg[cat]['bdsth'], "L") if cat != 'cg' and cat != 'cpi0': w.pdf(pdfname).plotOn(pl, rf.Components('bdkp_mc_pdf_%s' % cat), rf.LineStyle(2), rf.LineColor(kOrange - 3)) tleg.AddEntry(pl.getObject(int(pl.numItems()) - 1), leg[cat]['bdkp'], "L") w.pdf(pdfname).plotOn(pl, rf.Components('bsdstkk_mc_pdf_%s' % cat), rf.LineStyle(2), rf.LineColor(kGreen + 1)) tleg.AddEntry(pl.getObject(int(pl.numItems()) - 1), leg[cat]['bsdstkk'], "L") w.pdf(pdfname).plotOn(pl, rf.Components('bdstkk_mc_pdf_%s' % cat), rf.LineStyle(2), rf.LineColor(kGreen + 3)) tleg.AddEntry(pl.getObject(int(pl.numItems()) - 1), leg[cat]['bdstkk'], "L") w.pdf(pdfname).plotOn(pl, rf.Components('bdstpp_mc_pdf_%s' % cat), rf.LineStyle(2), rf.LineColor(kRed)) tleg.AddEntry(pl.getObject(int(pl.numItems()) - 1), leg[cat]['bdstpp'], "L") else: w.pdf(pdfname).plotOn(pl, rf.Components('bdstkp_mc_pdf_%s' % cat), rf.LineStyle(2), rf.LineColor(kOrange - 3)) tleg.AddEntry(pl.getObject(int(pl.numItems()) - 1), leg[cat]['bdstkp'], "L") w.pdf(pdfname).plotOn(pl, rf.Components('misrec_mc_pdf_%s' % cat), rf.LineStyle(2), rf.LineColor(kCyan)) tleg.AddEntry(pl.getObject(int(pl.numItems()) - 1), leg[cat]['misrec'], "L") w.pdf(pdfname).plotOn(pl, rf.Components('sig_mc_pdf_%s' % cat), rf.LineStyle(2), rf.LineColor(kBlue + 3)) tleg.AddEntry(pl.getObject(int(pl.numItems()) - 1), leg[cat]['sig'], "L") w.pdf(pdfname).plotOn(pl) if resid and w.data(dsetname) and w.pdf(pdfname): pu = TPad(pad.GetName() + '_pu', '', 0., 0.33, 1., 1.) pd = TPad(pad.GetName() + '_pd', '', 0., 0., 1., 0.33) pu.SetBottomMargin(0.03) pd.SetTopMargin(0.03) pd.SetBottomMargin(0.35) pad.cd() pu.Draw() pd.Draw() pu.cd() pl.GetYaxis().SetTitleOffset(1.1) pl.GetXaxis().SetLabelSize(0.) pl.Draw() if log: pl.GetYaxis().SetRangeUser(0.1, 2. * pl.GetMaximum()) pl.Draw() pu.SetLogy() pd.cd() pull = pl.pullHist() # roofit does something funny with pull hist range so need a dummy hist for it pull.Draw() ymax = max(abs(pull.GetYaxis().GetXmin()), pull.GetYaxis().GetXmax()) pulld = TH1F(pull.GetName() + '_pd', '', pl.GetNbinsX(), pl.GetXaxis().GetXmin(), pl.GetXaxis().GetXmax()) pulld.GetYaxis().SetRangeUser(-ymax, ymax) pulld.GetXaxis().SetTitle(pl.GetXaxis().GetTitle()) pulld.GetYaxis().SetTitle("Pull") pl.GetXaxis().SetTitle("") pulld.GetXaxis().SetTitleSize(0.13) pulld.GetYaxis().SetTitleSize(0.13) pulld.GetXaxis().SetLabelSize(0.13) pulld.GetYaxis().SetLabelSize(0.13) pulld.GetXaxis().SetTitleOffset(1.1) pulld.GetYaxis().SetTitleOffset(0.6) pulld.GetYaxis().SetNdivisions(505) pulld.GetXaxis().SetTickLength(0.06) ll = TLine() ll.SetLineWidth(4) ll.SetLineColor(4) pd.cd() pd.Clear() pulld.Draw("HIST") pull.Draw("EPsame") ll.DrawLine(pulld.GetXaxis().GetXmin(), 0., pulld.GetXaxis().GetXmax(), 0.) pulld.Draw("AXISsame") gROOT.Append(pulld) else: pad.cd() pl.Draw() if log: pl.GetYaxis().SetRangeUser(0.1, 2 * pl.GetMaximum()) pl.Draw() pad.SetLogy() gROOT.Append(tleg) pad.cd() if not log: tleg.Draw("same") pad.Update() pad.Modified()
leg.SetLineColor(0) leg.SetFillColor(0) leg.SetBorderSize(0) leg.AddEntry(hist_allCutsQCD, "QCD Pythia", "f") leg.AddEntry(hist_allCutsQCD_Madgraph, "QCD Madgraph", "l") can_allCuts.cd() #----- pad 1 ----------- pad1 = TPad("pad1", "pad1", 0.01, 0.13, 0.75, 1.) pad1.SetRightMargin(0.1) pad1.SetLogy() pad1.Draw() pad1.cd() pad1.Clear() if logy: pad1.SetLogy() #hist_allCutsQCD.Reset() hist_allCutsQCD.GetXaxis().SetRangeUser(xmin, xmax) hist_allCutsQCD.GetXaxis().SetTitle(xtitle) hist_allCutsQCD.GetXaxis().SetTitleFont(42) hist_allCutsQCD.GetXaxis().SetTitleSize(0.05) #hist_allCutsQCD.GetXaxis().SetLabelOffset(999) hist_allCutsQCD.GetXaxis().SetLabelSize(0) size = hist_allCutsQCD.GetBinWidth(1) title_y = "events / " + str(size) + " GeV" hist_allCutsQCD.GetYaxis().SetTitleFont(42) hist_allCutsQCD.GetYaxis().SetTitleSize(0.04)
def resComp(inFPath): """! Plot two distributions on the same plot and also plot the ratio of the two. The input file must have trees. """ gROOT.SetBatch(True) gROOT.ForceStyle() setStyle() inF = TFile.Open(inFPath) tree = inF.Get('Ntuple') print tree.GetEntries() c = TCanvas('c', '', 800, 600) c.cd() pad = TPad("plotPad", "", 0, 0, 1, 1) pad.SetPad(0., 0.37, 1., 1.) pad.SetBottomMargin(0.02) pad.Draw() c.cd() ratioPad = TPad("ratioPad", "", 0., 0., 1., 1.) ratioPad.SetPad(0., 0.05, 1., 0.35) ratioPad.SetTopMargin(0.04) ratioPad.SetBottomMargin(0.3) ratioPad.Draw() refHists = {} compHists = {} ratioHists = {} for varName in compDict: pad.Clear() pad.SetLogy(False) ratioPad.Clear() refHistName = 'hist_' + varName.replace('[', '_').replace( ']', '_').replace('-', '_').replace('/', '_').replace( '(', '_').replace(')', '_') refHists[varName] = TH1F(refHistName, '', binning[varName][0], binning[varName][1], binning[varName][2]) tree.Draw(varName + '>>' + refHistName) compHists[varName] = [] ratioHists[varName] = [] print varName, refHistName print refHists[varName].Integral() refHists[varName].Scale(1. / refHists[varName].Integral()) maxY = refHists[varName].GetMaximum() for compVarI in range(len(compDict[varName])): compHistName = 'hist_' + compDict[varName][compVarI].replace( '[', '_').replace(']', '_').replace('-', '_').replace( '/', '_').replace('(', '_').replace(')', '_') compHist = TH1F(compHistName, '', binning[varName][0], binning[varName][1], binning[varName][2]) tree.Draw(compDict[varName][compVarI] + '>>' + compHistName) compHists[varName].append(compHist) compHists[varName][compVarI].Scale( 1. / compHists[varName][compVarI].Integral()) if maxY < compHists[varName][compVarI].GetMaximum(): maxY = compHists[varName][compVarI].GetMaximum() pad.Clear() refHists[varName].SetTitle('') refHists[varName].SetMaximum(1.2 * maxY) refHists[varName].Draw() unitsStr = '' if varNamesUnits[varName][1] != '': unitsStr = ' [' + varNamesUnits[varName][1] + ']' refHists[varName].GetXaxis().SetTitle(varNamesUnits[varName][0] + unitsStr) binSize = refHists[varName].GetBinLowEdge( 2) - refHists[varName].GetBinLowEdge(1) roundTo = -int(math.floor(math.log10(abs(binSize)))) roundedBinSize = round(binSize, roundTo) if roundTo < 0: binSizeStr = "%d" % roundedBinSize else: binSizeStr = "{0:.{1}f}".format(roundedBinSize, roundTo) yLabel = "1/N dN/(%s) [%s %s]^{-1}" % ( varNamesUnits[varName][0], binSizeStr, varNamesUnits[varName][1]) refHists[varName].GetYaxis().SetTitle(yLabel) ratioPad.Clear() for compVarI in range(len(compDict[varName])): pad.cd() compHists[varName][compVarI].SetLineColor(compVarI + 2) compHists[varName][compVarI].SetMarkerColor(compVarI + 2) compHists[varName][compVarI].Draw('same') ratioPad.cd() ratioHists[varName].append(refHists[varName].Clone()) ratioHists[varName][compVarI].GetYaxis().SetTitleOffset(0.4) ratioHists[varName][compVarI].GetYaxis().SetDecimals(True) ratioHists[varName][compVarI].GetYaxis().CenterTitle(True) ratioHists[varName][compVarI].Divide(compHists[varName][compVarI]) ratioHists[varName][compVarI].SetMaximum(2) ratioHists[varName][compVarI].SetMinimum(0.) ratioHists[varName][compVarI].GetYaxis().SetTitleSize( compHists[varName][compVarI].GetXaxis().GetTitleSize() * 2.1) ratioHists[varName][compVarI].GetXaxis().SetTitleSize( compHists[varName][compVarI].GetYaxis().GetTitleSize() * 2.1) ratioHists[varName][compVarI].GetYaxis().SetLabelSize( compHists[varName][compVarI].GetXaxis().GetLabelSize() * 2.1) ratioHists[varName][compVarI].GetXaxis().SetLabelSize( compHists[varName][compVarI].GetYaxis().GetLabelSize() * 2.1) ratioHists[varName][compVarI].GetYaxis().SetTitle('Reco/NN') ratioHists[varName][compVarI].SetLineColor(compVarI + 2) ratioHists[varName][compVarI].SetMarkerColor(compVarI + 2) if compVarI == 0: ratioHists[varName][compVarI].Draw() else: ratioHists[varName][compVarI].Draw('same') line = TLine() line.DrawLine(refHists[varName].GetXaxis().GetXmin(), 1, refHists[varName].GetXaxis().GetXmax(), 1) line.SetLineWidth(1) line.SetLineStyle(2) line.SetLineColor(1) c.cd() leg = CompLegend((0.2, 0.8, 0.4, 0.9), [refHists[varName]] + compHists[varName], [compDictNames[varName]] + [ compDictNames[compVarName] for compVarName in compDict[varName] ]) leg.Draw('same') c.Print( varName.replace('/', '_').replace('[', '_').replace(']', '_'). replace('(', '').replace(')', '').rstrip('_').lstrip('_') + '.pdf') pad.SetLogy() refHists[varName].SetMaximum(10 * maxY) c.Print( varName.replace('/', '_').replace('[', '_').replace(']', '_'). replace('(', '').replace(')', '').rstrip('_').lstrip('_') + '_log.pdf')
model += '+gaus(%d)'%((i+1)*3) print model par = array( 'd', 3*ncomp*[0.] ) for i in range(ncomp): par[3*(i)] = heigth[i] par[3*(i)+1] = phase[i] /360. * nbin par[3*(i)+2] = width[i] print par total = TF1( 'total', model, lowbin, hibin ) total.SetParameters( par ) # fit and display pad3.Clear() h3.Fit(total, 'ER') par1 = total.GetParameters() # residual plot pad2.Clear() for i in range(h3.GetNbinsX()): h2.SetBinContent( i+1, h3.GetBinContent(i) - total.Eval(h3.GetBinCenter(i)) ) pad2.cd() h2.Draw() icomp = ncomp #if 1: else:
class pdf_class: def __init__(self, filename): self._canvas = TCanvas("canvas", "canvas", 800, 450) self._canvas.cd() self._pad = TPad("pad", "", 0, 0, 1, 0.95) self._pdf = TPDF("%s.pdf" % filename) self._subCanvas = 0 self._nCanvasPerPage = 0 self._nx = 1 self._ny = 1 def newPage(self, headerText="", nx=1, ny=1, sameHeader=False): if self._subCanvas != 0: self._pad.Draw() self._canvas.cd() self._canvas.Update() self._pdf.NewPage() self._pad.Clear() self._canvas.cd() if not sameHeader: self._nx = nx self._ny = ny self._header = TPaveText(0, 0.95, 1, 1) self._header.SetFillColor(0) self._header.SetTextColor(1) self._header.SetTextFont(22) self._header.AddText(headerText) self._header.AddLine(0.0, 0.95, 1.0, 0.95) self._header.Draw() self._pad.cd() self._pad.Divide(self._nx, self._ny) self._pad.SetGrid(0, 0) self._nCanvasPerPage = self._nx * self._ny self._subCanvas = 0 def newLegend(self, header="", lx=0.8, ly=0.8, ux=0.9, uy=0.88): self._legend = TLegend(lx, ly, ux, uy) self._legend.SetFillColor(0) self._legend.SetBorderSize(0) self._legend.SetTextFont(132) self._legend.SetTextSize(0.035) if header != "": self._legend.SetHeader(header) def draw(self, hists, legend=False, drawOpt="", logx=False, logy=False, logz=False): if self._subCanvas + 1 > self._nCanvasPerPage: self.newPage(sameHeader=True) self._subCanvas += 1 self._pad.cd(self._subCanvas) first = 1 for h in hists: if first == 1: first = 0 h.Draw(drawOpt) else: h.Draw("same%s" % drawOpt) if legend: self._legend.AddEntry(h, h.GetTitle(), "LP") if legend: self._legend.Draw() if logx: self._pad.cd(self._subCanvas).SetLogx() if logy: self._pad.cd(self._subCanvas).SetLogy() if logz: self._pad.cd(self._subCanvas).SetLogz() self._canvas.cd() self._canvas.Update() self._pad.Draw() def close(self): self._pad.Draw() self._canvas.cd() self._canvas.Update() self._pdf.Close()