def shape_variation(var, plot_range, varname, recreate, out_name): tot_hists = OrderedDict() tdrstyle() for wn, w in [ ("unw", Weight("1.0")), ("nominal", Weights.wjets_madgraph_shape_weight("nominal")), ("shape_up", Weights.wjets_madgraph_shape_weight("wjets_up")), ("shape_down", Weights.wjets_madgraph_shape_weight("wjets_down")) ]: p = data_mc( var, "2J0T_%s" % (wn), cut, Weights.total("mu", "nominal")*w, samples, ".", recreate, lumi_iso["mu"], plot_range=plot_range, ) for hn, h in p.hists.items(): logger.debug("%s %.2f" % (hn, h.Integral())) #sumw = [(sample.name, numpy.mean(root_numpy.root2array(sample.tfile.GetPath()[:-2], "trees/WJets_weights", branches=[str(w)])[str(w)])) for sample in samples] s = sum(p.hists.values()).Clone() tot_hists[wn] = s hc = HistCollection(tot_hists, name=out_name) for hn, h in hc.hists.items(): print hn, h.Integral() 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
tree = args.tree #The enabled systematic up/down variation sample prefixes to put on the ratio plot if args.do_systs: systs = { "JES": ("EnUp", "EnDown"), "JER": ["ResUp", "ResDown"], "MET": ["UnclusteredEnUp", "UnclusteredEnDown"], } else: systs = {} for lepton_channel in args.channels: logger.info("Plotting lepton channel %s" % lepton_channel) weight = Weights.total(lepton_channel)*Weights.wjets_madgraph_shape_weight()*Weights.wjets_madgraph_flat_weight() physics_processes = PhysicsProcess.get_proc_dict(lepton_channel=lepton_channel)#Contains the information about merging samples and proper pretty names for samples merge_cmds = PhysicsProcess.get_merge_dict(physics_processes) #The actual merge dictionary lumi = lumis[lepton_channel] isoreg='iso' use_antiiso = False if args.use_antiiso: isoreg='antiiso' use_antiiso = True #Get the file lists flist = get_file_list( merge_cmds,
flist = [] for i in ['sig','bg']: for j in ['train','eval']: flist += mvaFileList[i][j] logger.debug('Used file list: %s',str(flist)) # Read in the samples samples = {} for f in flist: samples[f] = Sample.fromFile(args.indir+'/%s/%s.root' % (proc,f), tree_name='Events_MVA') # Set the weight expression weightString = str(Weights.total(proc) * Weights.wjets_madgraph_shape_weight() * Weights.wjets_madgraph_flat_weight()) # Which file do we use to write our TMVA trainings ext='' if len(rVar): ext='_sans' for v in rVar: ext+='_'+v if len(cVar): ext='_with' for v in cVar: ext+='_'+v out = TFile('TMVA%s%s.root' % (proc,ext),'RECREATE')