Esempio n. 1
0
def data_mc(var, cut_name, cut, weight, samples, out_dir, recreate, lumi, **kwargs):
    plot_name = "%s__%s" % (var, cut_name)
    plot_name = escape(plot_name)
    systematic = kwargs.get("systematic", "nominal")
    if recreate:
        hists = {}
        metadata = {}
        pbar = ProgressBar(
            widgets=["Plotting %s:" % plot_name] + widgets, maxval=sum([s.getEventCount() for s in samples])
        ).start()
        nSamp = 1
        for sample in samples:
            hname = sample.name
            if sample.isMC:
                hname_ = sample.name
                hist = sample.drawHistogram(var, str(cut), weight=str(weight), **kwargs)
                hist.Scale(sample.lumiScaleFactor(lumi))
                hists[hname_] = hist
                metadata[hname_] = HistMetaData(sample_name=sample.name, process_name=sample.process_name)
            else:
                hist = sample.drawHistogram(var, str(cut), **kwargs)
                hists[hname] = hist
                metadata[hname] = HistMetaData(sample_name=sample.name, process_name=sample.process_name)
            pbar.update(nSamp)
            nSamp += sample.getEventCount()

        hist_coll = HistCollection(hists, metadata, plot_name)
        hist_coll.save(out_dir)
        logger.debug("saved hist collection %s" % (out_dir))
        pbar.finish()

    hist_coll = HistCollection.load(out_dir + "/%s.root" % plot_name)
    logger.debug("loaded hist collection %s" % (out_dir + "/%s.root" % plot_name))
    return hist_coll
Esempio n. 2
0
			for wn, w in weights:
				hi = sample.drawHistogram(var, str(cut), weight=w, plot_range=plot_range)
				hi.Scale(sample.lumiScaleFactor(lumi))
				hists[wn][sample.name] = hi

		
		merged = dict()
		for wn, w in weights:
			merged[wn] = merge_hists(hists[wn], merge_cmds)
			hc = HistCollection(merged[wn], name="bweight_%s" % wn)
			hc.save(".")

	colls = dict()
	for wn, w in weights:
		hc = HistCollection.load("./bweight_%s.root" % wn)
		colls[wn] = hc


	for proc in merge_cmds.keys():
		hists = OrderedDict([(wn, colls[wn].hists[proc]) for wn, w in weights])
		for hn, h in hists.items():
			h.SetTitle(pretty_names_weights[hn])
		hists_normed = copy.deepcopy(hists)

		for hn, h in hists_normed.items():
			norm(h, setName=False)
			if hn!="unw":
				h.Divide(hists_normed["unw"])

		hists_normed["unw"].Divide(hists_normed["unw"])