Exemplo n.º 1
0
                         if args.lepton == 'Muon':
                             x_lims = (0., 0.15) if lepcat == 'Tight' else (0.15, 1.)
                         if args.lepton == 'Electron':
                             x_lims = (0., 0.1) if lepcat == 'Tight' else (0., 0.5)
 
                     mc_opts = {
                         #'mcorder' : ['QCD', 'EWK', 'singlet', 'ttJets'] if not ttJets_cats else ['QCD', 'EWK', 'singlet', 'ttJets_other', 'ttJets_unmatchable', 'ttJets_matchable', 'ttJets_right']
                         #'maskData' : not withData
                     }
 
                     Plotter.plot_stack1d(ax, rax, hslice, xlabel=xtitle, xlimits=x_lims, **mc_opts)
 
                     #set_trace() 
                     if hname == 'Jets_njets':
                         print(jmult)
                         yields_txt, yields_json = Plotter.get_samples_yield_and_frac(hslice, data_lumi_year['%ss' % args.lepton]/1000., promptmc=True)
                         frac_name = '%s_yields_and_fracs' % '_'.join([jmult, args.lepton, lepcat, btagregion])
                         plt_tools.print_table(yields_txt, filename='%s/%s.txt' % (pltdir, frac_name), print_output=True)
                         print('%s/%s.txt written' % (pltdir, frac_name))
                         with open('%s/%s.json' % (pltdir, frac_name), 'w') as out:
                             out.write(prettyjson.dumps(yields_json))
 
                         # add lepton/jet multiplicity label
                     #set_trace()
                     ax.text(
                         0.02, 0.88, "%s, %s\n%s" % (lep_cats[lepcat], jet_mults[jmult], btag_cats[btagregion]),
                         fontsize=rcParams['font.size']*0.75, horizontalalignment='left', verticalalignment='bottom', transform=ax.transAxes
                     )
                     hep.cms.label(ax=ax, data=withData, paper=False, year=args.year, lumi=round(data_lumi_year['%ss' % args.lepton]/1000., 1))
 
                     #set_trace()
Exemplo n.º 2
0
                    pltdir = os.path.join(outdir, args.lepton, jmult, lepcat,
                                          btagregion)
                    if not os.path.isdir(pltdir):
                        os.makedirs(pltdir)

                    hslice = histo[:, jmult, btagregion, lepcat].integrate(
                        'jmult').integrate('lepcat').integrate('btag')

                    # split hslice into signal samples/SM MC+data
                    sig_hslice = hslice[Plotter.signal_samples]
                    SM_hslice = hslice[Plotter.nonsignal_samples]

                    if hname == 'Jets_njets':
                        print(jmult)
                        yields_txt, yields_json = Plotter.get_samples_yield_and_frac(
                            hslice,
                            data_lumi_year['%ss' % args.lepton] / 1000.)
                        yields_fname = os.path.join(
                            pltdir,
                            '%s_%s_yields_and_fracs' % (jmult, args.lepton))
                        plt_tools.print_table(yields_txt,
                                              filename='%s.txt' % yields_fname,
                                              print_output=True)
                        with open('%s.json' % yields_fname, 'w') as out:
                            out.write(prettyjson.dumps(yields_json))

                        # plot signal
                    if sig_hslice.values():
                        for signal in sig_hslice.values().keys():
                            fig, ax = plt.subplots()
                            fig.subplots_adjust(hspace=.07)
Exemplo n.º 3
0
                if not os.path.isdir(pltdir):
                    os.makedirs(pltdir)

                opts = {
                    "legend_title" : sys,
                    "maskData" : maskData,
                }

                sys_histo = hdict[(args.lepton, jmult, sys, hname)]
                sys_histo = sys_histo.group(process_cat, process, process_groups)

                fig, (ax, rax) = plt.subplots(2, 1, gridspec_kw={"height_ratios": (3, 1)}, sharex=True)
                fig.subplots_adjust(hspace=.07)

                if hname == "Jets_njets":
                    yields_txt, yields_json = Plotter.get_samples_yield_and_frac(sys_histo, data_lumi_year["%ss" % args.lepton]/1000., sys=sys)
                    frac_name = "%s_%s_yields_and_fracs_QCD_Est" % (sys, "_".join([jmult, args.lepton]))
                    plt_tools.print_table(yields_txt, filename="%s/%s.txt" % (pltdir, frac_name), print_output=True)
                    print("%s/%s.txt written" % (pltdir, frac_name))
                    with open("%s/%s.json" % (pltdir, frac_name), "w") as out:
                        out.write(prettyjson.dumps(yields_json))
                
                ax, rax = Plotter.plot_stack1d(ax, rax, sys_histo, xlabel=xtitle, xlimits=x_lims, **opts)
                
                    # add lepton/jet multiplicity label
                ax.text(
                    0.02, 0.92, "%s, %s" % (leptypes[args.lepton], jet_mults[jmult]),
                    fontsize=rcParams["font.size"]*0.9, horizontalalignment="left", verticalalignment="bottom", transform=ax.transAxes
                )
                        ## draw vertical lines for distinguishing different ctstar bins
                if vlines is not None: