def comp(branchname, filename, binning, xlabel, ratio, nele, logx=False, remake=False): global hist_index lt_hists = [] lt_sum = 0 if not remake: print "opening tmp/LT_%s.root" % filename f = ROOT.TFile.Open("tmp/LT_%s.root" % filename, "READ") inclusive = f.Get("hist%d" % hist_index) hist_index += 1 for i in xrange(1,11): lt_hists.append(f.Get("hist%d" % hist_index )) hist_index += 1 print lt_hists[-1].GetTitle() lt_sum += lt_hists[-1].Integral() else: inclusive = plot.GetTH1(inc_chain, branchname, isMC, binning, category, label="Inclusive Madgraph", usePU = False, useEleIDSF=nele) for name, chain in zip(lt_names,lt_binned_chains): print "Getting", name h = plot.GetTH1(chain, branchname, isMC, binning, category, label= "L_{T} " + name + " GeV", usePU = False, useEleIDSF=nele) lt_hists.append(h) lt_sum += h.Integral() if remake: f = ROOT.TFile.Open("tmp/LT_%s.root" % filename, "RECREATE") for h in lt_hists + [inclusive]: h.Write() f.Close() plot.ColorData(inclusive) plot.ColorMCs(lt_hists) #inclusive.Scale(1./inclusive.Integral()) rajdeep_new = [828.72, 129.496, 155.178, 217.287, 175.158, 50.51, 91.48, 3.69, 0.196, 0.0072] old_xs = [8.670e+02, 1.345e+02, 1.599e+02, 2.295e+02, 1.654e+02, 4.896e+01, 9.401e+01, 3.588e+00, 2.012e-01, 8.329e-03] fit_new = [ 9.93694e-01, 9.72633e-01, 9.90570e-01, 9.89391e-01, 9.92841e-01, 8.56845e-01, 8.91049e-01, 9.04437e-01, 6.09500e-01,1] filename = "before_" + filename #for i, h in enumerate(lt_hists): #print "### XS RATIO: ", h.GetTitle(), old_xs[i], old_xs[i] * fit_new[i] #h.Scale(fit_new[i]) #h.Scale(rajdeep_new[i]/old_xs[i]) # h.Scale(1./lt_sum) inclusive.Scale(1000*4.957e+03/49144274.0) lt_hists.reverse() plot.PlotDataMC(inclusive, lt_hists, "plots/validation/LTBinned/", "LT_comparison_" + filename, xlabel=xlabel + " [GeV]", ylabel="Fraction", ylabel_unit="GeV", stack_mc=True, ratio=ratio, logx=logx)
print "* selection = ", selection if not args.branch: args.branch = [""] for branchname in args.branch: if not args.name: args.name = branchname if not args.xlabel: args.xlabel = branchname if args.data: print "[STATUS] Data: " + branchname isMC = False data_hs = MakeTH1s(args.data, branchname, isMC, binning, category, selection) plot.ColorData(data_hs) else: data_hs = [] if args.mc: print "[STATUS] MC: " + branchname isMC = True mc_hs = MakeTH1s(args.mc, branchname, isMC, binning, category, selection) plot.ColorMCs(mc_hs) else: mc_hs = [] plot.Normalize(data_hs, mc_hs) plot.PlotDataMC(data_hs, mc_hs,
def comp(branchname, filename, binning, xlabel, ratio, nele, logx=False, remake=False): global hist_index branchname = "smearerCat[0]:" + branchname nbins, low, hi = eval(binning) binning = "({nbins},{low},{hi},{ncat},0,{ncat})".format(nbins=nbins, low=low, hi=hi, ncat=ncat * (ncat + 1) / 2) if not remake: f = ROOT.TFile.Open("tmp/smear_comp_%s.root" % filename, "READ") histos = [ f.Get("hist%d" % i) for i in range(hist_index, 5 + hist_index) ] data_step7_hist, data_step2_hist, mc_h, mc_step4_h, mc_step7_h = histos data_hists = [data_step7_hist, data_step2_hist] mc_hists = [mc_h, mc_step4_h, mc_step7_h] hist_index += 5 else: data_step7_hist = plot.GetTH1(data_step7_chain, branchname, not isMC, binning, category, label="Data HggRunEtaR9Et", usePU=False, useEleIDSF=nele, scale=True) data_step2_hist = plot.GetTH1(data_step2_chain, branchname, not isMC, binning, category, label="Data HggRunEtaR9", usePU=False, useEleIDSF=nele, scale=True) data_hists = [data_step7_hist, data_step2_hist] mc_h = plot.GetTH1(mc_chain, branchname, isMC, binning, category, label="no Correction", usePU=False, useEleIDSF=nele, smear=False) mc_step4_h = plot.GetTH1(mc_step4_chain, branchname, isMC, binning, category, label="Step4 Smear", usePU=False, useEleIDSF=nele, smear=True) mc_step7_h = plot.GetTH1(mc_step7_chain, branchname, isMC, binning, category, label="Step7 Smear", usePU=False, useEleIDSF=nele, smear=True) mc_hists = [mc_h, mc_step4_h, mc_step7_h] if remake: f = ROOT.TFile.Open("tmp/smear_comp_%s.root" % filename, "RECREATE") for h in data_hists + mc_hists: h.Write() f.Close() c = ROOT.TCanvas() names = [ "data_HggRunEtaR9Et", "data_HggRunEtaR9", "uncorrected", "step4", "step7" ] for name, h in zip(names, data_hists + mc_hists): h.Draw("colz") c.SaveAs("plots/scale_smear/%s.png" % name) data_step7_hs = ROOT.THStack(data_step7_hist, "x") data_step2_hs = ROOT.THStack(data_step2_hist, "x") mc_hs = ROOT.THStack(mc_h, "x") mc_step4_hs = ROOT.THStack(mc_step4_h, "x") mc_step7_hs = ROOT.THStack(mc_step7_h, "x") #print "CHI2 Category", " ".join(names[2:]) for i, dicat_name in enumerate(dicat_names): ds = [data_step7_hs.GetHists()[i], data_step2_hs.GetHists()[i]] plot.ColorData(ds) mcs = [ mc_hs.GetHists()[i], mc_step4_hs.GetHists()[i], mc_step7_hs.GetHists()[i] ] plot.ColorMCs(mcs) plot.Normalize(ds, mcs) ds[0].GetXaxis().SetRangeUser(80, 100) #print "CHI2", dicat_name, #for h in mcs: #ch2 = ds[0].Chi2Test(h, "UW CHI2/NDF") #print ch2, #for h in mcs: #print h.GetEntries(), #print plot.PlotDataMC(ds[0], mcs, "plots/smear_comp/", filename + "_" + dicat_name, x_range=(80, 100), xlabel=xlabel + " [GeV]", ylabel="Events", ylabel_unit="GeV", ratio=ratio, logx=logx) mcs[1].SetFillStyle(1001) mcs[1].SetFillColor(ROOT.kAzure + 6) mcs[1].SetLineColor(ROOT.kAzure + 6) plot.PlotDataMC(ds, mcs[1], "plots/scale_comp/", filename + "_" + dicat_name, x_range=(80, 100), xlabel=xlabel + " [GeV]", ylabel="Events", ylabel_unit="GeV", ratio=False, logx=logx)