def plotPulls(optunf="Bayes", ntest=10, leff=True, loufl=False, optfun="exp", opttfun="", gmean=-1.0, nrebin=4): if opttfun == "": opttfun = optfun if optfun == "blobel": gmean = 0.0 funttxt, funtxt = funtxts(opttfun, optfun, leff, loufl) global histos, canv, canv2 histos = [] canv = TCanvas("canv", "thruth vs reco pulls", 600, 800) canv.Divide(1, 3) canv2 = TCanvas("canv2", "P(chi^2)", 600, 800) canv2.Divide(2, 3) if optunf == "BasisSplines": bininfo = BinInfo(nrebin) unfoldtester = UnfoldTester(optunf, nrebin) else: bininfo = BinInfo() unfoldtester = UnfoldTester(optunf) trainer = Trainer(bininfo, opttfun, optfun) tester = Tester(bininfo, optfun) hbininfo = bininfo.create(optfun) dx = hbininfo["mhi"] for sigma, ipad in [[0.01 * dx, 1], [0.03 * dx, 2], [0.1 * dx, 3]]: txt = optunf + ", smear mu, s.d.= " + str(gmean) + ", " + str( sigma) + ", train: " + funttxt + ", test: " + funtxt + ", " + str( ntest) + " tests" hPulls = TProfile("pulls", txt, hbininfo["tbins"], hbininfo["tlo"], hbininfo["thi"]) hPulls.SetErrorOption("s") hPulls.SetYTitle("Thruth reco pull") histos.append(hPulls) hChisq = TH1D("chisq", "P(chi^2) rec " + txt, 10, 0.0, 1.0) hChisqm = TH1D("chisqm", "P(chi^2) mea " + txt, 10, 0.0, 1.0) histos.append(hChisq) histos.append(hChisqm) measurement = createMeasurement(gmean, sigma, leff, optfun) response = trainer.train(measurement, loufl=loufl) for itest in range(ntest): print "Test", itest unfold, hTrue, hMeas = unfoldtester.rununfoldtest( tester, measurement, response) unfold.PrintTable(cout, hTrue, 2) hReco = unfold.Hreco(2) nbin = hReco.GetNbinsX() if hbininfo["nrebin"] > 1: hTrue = hTrue.Rebin(nrebin) for ibin in range(nbin + 1): truevalue = hTrue.GetBinContent(ibin) recvalue = hReco.GetBinContent(ibin) error = hReco.GetBinError(ibin) if error > 0.0: pull = (recvalue - truevalue) / error hPulls.Fill(hReco.GetBinCenter(ibin), pull) chisq = unfold.Chi2(hTrue, 2) hChisq.Fill(TMath.Prob(chisq, hTrue.GetNbinsX())) chisqm = unfold.Chi2measured() pchisqm = TMath.Prob(chisqm, hMeas.GetNbinsX() - hReco.GetNbinsX()) print "Chisq measured=", chisqm, "P(chi^2)=", pchisqm hChisqm.Fill(pchisqm) canv.cd(ipad) gStyle.SetErrorX(0) hPulls.SetMinimum(-3.0) hPulls.SetMaximum(3.0) hPulls.SetMarkerSize(1.0) hPulls.SetMarkerStyle(20) hPulls.SetStats(False) hPulls.Draw() canv2.cd(ipad * 2 - 1) hChisq.Draw() canv2.cd(ipad * 2) hChisqm.Draw() fname = "RooUnfoldTestPulls_" + optunf + "_" + opttfun + "_" + optfun if loufl: fname += "_oufl" canv.Print(fname + ".pdf") fname = "RooUnfoldTestChisq_" + optunf + "_" + opttfun + "_" + optfun if loufl: fname += "_oufl" canv2.Print(fname + ".pdf") return
Ymax = 0.4 nameX = "eta" nameY = "pT-pT(true)/pT(true)" h = gPad.DrawFrame(Xmin, Ymin, Xmax, Ymax) ax = h.GetXaxis() ax.SetTitleOffset(0.8) ax.SetTitle(nameX) ay = h.GetYaxis() ay.SetTitleOffset(0.8) ay.SetTitle(nameY) ax.SetTitleOffset(1.1) ay.SetTitleOffset(1.4) ax.Draw("same") ay.Draw("same") prof_eta.SetMarkerSize(1.1) prof_eta.SetMarkerColor(1) prof_eta.Draw("pe same") prof_eta_nn.SetMarkerSize(1) prof_eta_nn.SetMarkerColor(2) prof_eta_nn.Draw("pe same") out = "histo_" + outfile hfile = TFile(out, "RECREATE", "DijetsMC") c1.Write() prof_eta.Write() prof_pt.Write() prof_eta_nn.Write() prof_pt_nn.Write() hfile.ls()