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
for ievent in range(NEntries): if ievent % 100 == 0: print("Processed %d of %d events..." % (ievent, NEntries)) ntuple.GetEntry(ievent) n_weight = ntuple.__getattr__('weight') n_ptPruned = ntuple.__getattr__('ptPruned') if (170 < n_ptPruned < 1000): x.append(n_ptPruned) y.append(n_weight) print(n_weight) hprof2d.Fill(n_ptPruned, n_weight) # hprof2d.LabelsOption("h","pT") hprof2d.SetMinimum(-0.2) hprof2d.SetMaximum(0.3) hprof2d.Draw() c.SaveAs("old2dhist.png") # # H = verification # nbins = 100 # # xedges = 101 # # yedges =4 # H, xedges, yedges = np.histogram2d(x,y,bins=nbins) # # # print (xedges) # print (yedges) # # H= H.T # # print (H)