예제 #1
0
def MakeTH1s(arg, branchname, isMC, binning, category, selection=""):
    hs = []
    for a in arg:
        parse = a.split(',')
        filename, label = parse[:2]
        if len(parse) > 2: branchname = parse[2]
        elif not branchname:
            raise Exception("branch not defined for " + filename + ' ' + label)
        if len(parse) > 3:
            energybranchname = parse[3]
        else:
            energybranchname = None

        print "selection=", selection
        chain = ROOT.TFile.Open(filename).Get("selected")
        hs.append(
            plot.GetTH1(chain,
                        branchname,
                        isMC,
                        binning,
                        category,
                        selection,
                        label=label,
                        energyBranchName=energybranchname,
                        usePU=not args.noPU,
                        useEleIDSF=not args.noEleIDSF,
                        scale=not args.noScales,
                        smear=not args.noSmearings))
    return hs
예제 #2
0
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)
예제 #3
0
def MakeTH1s(arg, branchname, isMC, binning, category):
	hs = []
	for a in arg:
		parse = a.split(',')
		filename, label = parse[:2]
		if len(parse) >2: branchname = parse[2]
		elif not branchname:
			raise Exception("branch not defined for " + filename + ' ' + label)
		if len(parse) >3:
			energybranchname = parse[3]
		else:
			energybranchname = None


		chain = ROOT.TFile.Open(filename).Get("selected")
		hs.append( plot.GetTH1(chain, branchname, isMC, binning, category, label=label , energyBranchName = energybranchname))
	return hs
예제 #4
0
    hi = 500
    nbins = (hi - low) / binwidth
    binning = "({n},{l},{h},{n},{l},{h})".format(n=nbins, l=low, h=hi)

    branch1 = "energy_ECAL_ele[0]/cosh(etaSCEle[0])"
    branch2 = branch1.replace("[0]", "[1]")
    branchname = "max({0},{1}):min({0},{1})".format(branch1, branch2)

    f = ROOT.TFile.Open("tmp/EtBins.root", "RECREATE")

    for region in regions:
        if region == "ALL": region = ""
        print region
        isMC = False
        print "Data"
        data = plot.GetTH1(data_c, branchname, isMC, binning,
                           region + '-' + common_cut)
        isMC = True
        print "Inc"
        inc = plot.GetTH1(inc_c,
                          branchname,
                          isMC,
                          binning,
                          region + '-' + common_cut,
                          noWeights=True)
        print "LT"
        lt = plot.GetTH1(lt_c,
                         branchname,
                         isMC,
                         binning,
                         region + '-' + common_cut,
                         noWeights=True)
예제 #5
0
h = None
if args.fromFile:
	f = ROOT.TFile.Open("tmp/" + args.name + ".root")
	if f:
		h = f.Get("hist0")
if not args.fromFile or not h:
	nbins, low, hi = eval(args.binning)
	binning = "({n},{l},{h},{n},{l},{h})".format(n=nbins, l=low, h=hi)

	chain = ROOT.TFile.Open(args.file).Get("selected")
	if not args.noSym:
		branchpair = args.branch + "," + args.branch.replace("[0]", "[1]") 
		branchname = "max({0}):min({0})".format(branchpair)
	else:
		branchname = "{0}:{1}".format(args.branch, args.branch.replace("[0]", "[1]") )

	h = plot.GetTH1(chain, branchname, args.isMC, binning, category)

	f = ROOT.TFile.Open("tmp/" + args.name + ".root", "RECREATE")
	h.Write()
	f.Close()

if args.makeDiagBins:
	values, integrals = plot.makeDiagBins(h, args.nevents)
	with open("data/regions/" +args.name + ".dat","w") as datfile:
		for low,hi,integral in zip(values[:-1], values[1:], integrals):
			datfile.write(args.category + "-ET_%.2f_%.2f # nevents %d\n" % (low, hi, integral))
else:
	values = None
plot.Draw2D(h, args.label, args.name, diagBins = values, logy=True, logx=True)
예제 #6
0
import sys, os
import argparse

sys.path.insert(0, os.getcwd() + '/python')
import plot
import ROOT

chain = ROOT.TFile.Open("tmp/Moriond17_oldRegr/s1_chain.root").Get("selected")
f = ROOT.TFile.Open("LT_inc.root", "RECREATE")
h = plot.GetTH1(
    chain,
    "energy_ECAL_ele[0]/cosh(etaSCEle[0])+energy_ECAL_ele[1]/cosh(etaSCEle[1])",
    True,
    binning="(4000,0,2000)",
    category="eleID_loose25nsRun22016Moriond",
    label="LT",
    usePU=False)

h.Write()
f.Close()
예제 #7
0
parser.add_argument("binning", help="(nbins,low,hi)")
parser.add_argument("file", help="specify data file")
parser.add_argument("name", help="outfile base name")
parser.add_argument("-c",
                    "--category",
                    help="category string",
                    default=category)

args = parser.parse_args()

sys.path.insert(0, os.getcwd() + '/python')
import plot
import ROOT

#plot.ndraw_entries = 100000
ROOT.gROOT.SetBatch(True)
ROOT.gStyle.SetOptStat(0)
ROOT.gStyle.SetOptTitle(0)

binning = args.binning

chain = ROOT.TFile.Open(args.file).Get("selected")
branchname = "energy_ECAL_ele[0]/cosh(etaSCEle[0]):energy_ECAL_ele[1]/cosh(etaSCEle[1])"
isMC = False

et_h = plot.GetTH1(chain, branchname, isMC, binning, args.category)

f = ROOT.TFile.Open("tmp/" + args.name + ".root", "RECREATE")
et_h.Write()
f.Close()
예제 #8
0
	33.375,  34.125,   34.75,    35.375,  36.0,
	36.625,  37.25,    37.875,   38.5,    39.125,
	39.625,  40.125,   40.625,   41.125,  41.625,
	42.125,  42.625,   43.125,   43.625,  44.125,
	44.625,  45.125,   45.625,   46.125,  46.75,
	47.5,    48.5,     49.875,   51.625,  53.875,
	56.75,   60.5,     65.25,    71.5,    79.875,
	91.875,  110.625,  147.625,  2000.0
	]

bins = np.array(bins)
ROOT.gStyle.SetOptTitle(1)

branchname = "energy_ECAL_ele[0]/cosh(etaSCEle[0]):energy_ECAL_ele[1]/cosh(etaSCEle)[1]"
inc_et= ROOT.TH2F("inc_et", "", len(bins) - 1, bins, len(bins) - 1, bins)
plot.GetTH1(inc_chain, branchname, isMC, histname="inc_et", category=category, label="Inclusive Madgraph", usePU = False, useEleIDSF = False)
plot.FoldTH2(inc_et)

data_et= ROOT.TH2F("data_et", "", len(bins) - 1, bins, len(bins) - 1, bins)
plot.GetTH1(data_chain, branchname, False, histname="data_et", category=category, label="Data", usePU = False, useEleIDSF = False)
plot.FoldTH2(data_et)

ltbinned_et= ROOT.TH2F("ltbinned_et", "", len(bins) - 1, bins, len(bins) - 1, bins)
plot.GetTH1(lt_binned_all, branchname, isMC, histname="ltbinned_et", category=category, label="LT Binned Madgraph", usePU = False, useLT=True, useEleIDSF = False)
plot.FoldTH2(ltbinned_et)

ltbinned_et_entries = ROOT.TH2F("ltbinned_et_entries", "", len(bins) - 1, bins, len(bins) - 1, bins)
plot.GetTH1(lt_binned_all, branchname, isMC, histname="ltbinned_et_entries", category=category, label="LT Binned Madgraph Unweighted", usePU = False, useLT=False, useEleIDSF = False)
plot.FoldTH2(ltbinned_et_entries)

for h in [inc_et, data_et, ltbinned_et, ltbinned_et_entries]:
예제 #9
0
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)