Esempio n. 1
0
def get_hf_frac(name, cut):
    logging.info("Getting fractions for %s" % name)
    basepath = get_paths(dataset="latest")
    samp = Sample.fromFile("/".join([basepath["mc"]["mu"]["nominal"]["iso"], name]))

    hi = samp.drawHistogram("wjets_flavour_classification0", str(cut), plot_range=[8, 0, 8], dtype="I")
    out = dict()
    for sc, fr in zip(flavour_scenarios[0], list(hi.y())):
        out[sc] = fr
    return out
Esempio n. 2
0
    def test_plot(self):

        tdrstyle()
        paths = get_paths()
        dataset = 'Jul15'
        lepton = 'mu'
        systematic = 'nominal'
        iso = 'iso'

        #Define the different plots to make
        items = [
            ('tchan1', paths[dataset]['mc'][lepton][systematic][iso], 'T_t_ToLeptons.root', Cuts.n_jets(2), '1.0'),
            ('tbarchan1', '-.-', 'Tbar_t_ToLeptons.root', Cuts.n_jets(2), '1.0'),

            ('tchan2', '-.-', 'T_t_ToLeptons.root', Cuts.n_jets(2)*Cuts.n_tags(1), '1.0'),
            ('tbarchan2', '-.-', 'Tbar_t_ToLeptons.root', Cuts.n_jets(2)*Cuts.n_tags(1), '1.0'),
        ]
        items = fill_list(items)

        #Dewfine a callbakc for normalization
        def normalize(hn, h):
            norm(h)
            return h

        #The final plot definition to draw
        plot_def = {
            'var': 'mt_mu',
            'range': [20, 0, 300],
            'items': items,
            'merge_cmds': {'signal 2J1T':['tchan2', 'tbarchan2'], 'signal 2J':['tchan1', 'tbarchan1']},
            'xlab': 'M_t(W)'
            #'hist_callback': normalize
        }

        #Now do the draw comparison
        canv, hists = compare_plot(plot_def)

        #Do some post-checking that everything went fine
        for hn, h in hists.items():
            if hn=='signal 2J':
                self.assertAlmostEqual(h.Integral(), 39472.452918)
            elif hn=='signal 2J1T':
                self.assertAlmostEqual(h.Integral(), 16414.4804941)

        print "Saving the plot to test_plot.png"
        canv.SaveAs('test_plot.png')
Esempio n. 3
0
from plots.common.cuts import Cuts
from plots.common.cross_sections import lumi_iso
from plots.common.utils import merge_hists
from plots.common.histogram import HistCollection, norm
from plots.common.hist_plots import plot_hists_dict
import numpy, copy
from plots.common.odict import OrderedDict
from plots.common.tdrstyle import tdrstyle

import logging
if __name__=="__main__":

	tdrstyle()

	logging.basicConfig(level=logging.INFO)
	basepath = get_paths(samples_dir="data/83a02e9_Jul22_sftotal/", dataset="latest")
	sampnames = [
		"TTJets_FullLept", "TTJets_SemiLept",
		"T_t_ToLeptons", "Tbar_t_ToLeptons",
		"W1Jets_exclusive", "W2Jets_exclusive", "W3Jets_exclusive", "W4Jets_exclusive"

	]
	path = basepath["mc"]["mu"]["nominal"]["iso"]

	cut = Cuts.final(2,1)*Cuts.mu
	var = "cos_theta"
	plot_range=[20, -1, 1]
	lumi = lumi_iso["mu"]
	plot_args = {"x_label": "cos #theta"}

Esempio n. 4
0
	canv = plot_hists_dict(hc.hists, do_chi2=False, do_ks=True, x_label=varname, legend_pos="top-left")
	hc.hists.values()[0].SetTitle("shape variation")
	canv.SaveAs(out_name + ".png")
	hc.save(out_name)
	return hc, canv

if __name__=="__main__":
	ROOT.TH1F.AddDirectory(False)
	import logging
	#rootpy.log.basic_config_colorized()
	logging.basicConfig(level=logging.WARNING)
	logger = rootpy.log["/systematics"]

	data_repro = "Jul15"
	path = get_paths()[data_repro]["mc"]["mu"]["nominal"]["iso"]
	logger.info("Input path %s" % path)
	samples = [
		Sample.fromFile(f) for f in
			filter(lambda x: re.match(".*/W[1-4]Jets.*", x), glob.glob(path + "/*.root"))
	]
	logger.info("samples %s" % samples)


	cut = Cuts.final(2,1)
	recreate = True


	r1 = shape_variation("cos_theta", [10, -1, 1], "cos #theta", recreate, "variations_cos_theta")
	r2 = shape_variation("abs(eta_lj)", [10, 2.5, 4.5], "|#eta|_{j'}", recreate, "variations_abs_eta_lj")
	
Esempio n. 5
0
import subprocess
from plots.common.utils import *
from plots.common.sample import get_paths
import glob
from subprocess import check_call
from SingleTopPolarization.Analysis.sample_types import *
from rootpy.extern.progressbar import *


widgets = [Percentage(), ' ', Bar(marker=RotatingMarker()), ' ', ETA()]


if __name__=="__main__":
	import logging
	logging.basicConfig(level=logging.INFO)
	path = get_paths()
	print path.keys()
	data_repro = "Jul15"
	fnames = dict()
	fnames["mu/mc/iso/"] = glob.glob(path[data_repro]["mc"]["mu"]["nominal"]["iso"] + "/*.root")
	fnames["mu/data/iso/"] = glob.glob(path[data_repro]["data"]["mu"]["NONE"]["iso"] + "/*.root")
	fnames["mu/data/antiiso/"] = glob.glob(path[data_repro]["data"]["mu"]["NONE"]["antiiso"] + "/*.root")
	pbar = ProgressBar(
		widgets=["Projecting histograms"] + widgets,
		maxval=sum([len(fnames[k]) for k in fnames.keys()])
	).start()

	ofdir = "hists/"

	cuts = [
		("SR", "n_muons==1 && n_eles==0 && n_veto_mu==0 && n_jets>0 && n_veto_ele==0 && rms_lj<0.025 && abs(eta_lj)>2.5 && top_mass<220 && top_mass>130 && mt_mu>50"),