示例#1
0
def plotCutFlow(in_file_paths, out_file_path, in_file_path_names, ignore_weights=False, output_name = None):
    in_file_paths = makeList(in_file_paths)
    in_file_path_names = makeList(in_file_path_names)
    if len(in_file_paths) != len(in_file_path_names):
        print 'inconsistent file paths and names'
        exit(0)

    list_of_cut_hist = []
    tex_names = []
    x_name = []
    #If one input file, plot keys on x
    if len(in_file_paths) == 1:
        in_file = TFile(in_file_paths[0], 'read')
        key_names = [k[0] for k in rootFileContent(in_file, starting_dir = 'cutflow')]
        in_file.Close()
        list_of_cut_hist.append(ROOT.TH1D('cutflow', 'cutflow', len(key_names), 0, len(key_names)))
        for i, k in enumerate(key_names):
            if ignore_weights:
                list_of_cut_hist[0].SetBinContent(i+1, getObjFromFile(in_file_paths[0], k).GetEntries())
            else:
                list_of_cut_hist[0].SetBinContent(i+1, getObjFromFile(in_file_paths[0], k).GetSumOfWeights())
        tex_names = in_file_path_names
        x_name = [k.split('/')[-1] for k in key_names]
    #Plot samples on x
    else:
        in_file = TFile(in_file_paths[0])
        key_names = [k[0] for k in rootFileContent(in_file, starting_dir='cutflow')]
        in_file.Close()
        for j, k in enumerate(key_names):
            list_of_cut_hist.append(ROOT.TH1D('cutflow_'+k, 'cutflow_'+k, len(in_file_paths), 0, len(in_file_paths)))
            for i, ifp in enumerate(in_file_paths):
                if ignore_weights:
                    print ifp, k
                    list_of_cut_hist[j].SetBinContent(i+1, getObjFromFile(ifp, k).GetEntries())
                else:
                    list_of_cut_hist[j].SetBinContent(i+1, getObjFromFile(ifp, k).GetSumOfWeights())
        tex_names = [k.split('/')[-1] for k in key_names]
        x_name = in_file_path_names

    p = Plot(list_of_cut_hist, tex_names, name = 'cutflow' if output_name is None else output_name, x_name = x_name, y_log = True)
    p.drawBarChart(out_file_path, index_colors=True, parallel_bins=True)
示例#2
0
                        len(SUPER_CATEGORIES[supercat]))
                    for i, c in enumerate(SUPER_CATEGORIES[supercat]):
                        # hist_to_plot[sample_name].SetBinContent(i+1, list_of_values['bkgr'][sample_name][c]['total'].getHist().GetSumOfWeights())
                        hist_to_plot[sample_name].SetBinContent(
                            i + 1,
                            list_of_values['bkgr'][sample_name][c]['total'])
                x_names = [
                    CATEGORY_TEX_NAMES[n] for n in SUPER_CATEGORIES[supercat]
                ]
                p = Plot(hist_to_plot.values(),
                         hist_to_plot.keys(),
                         name='Events-bar-bkgr-' + supercat,
                         x_name=x_names,
                         y_name='Events',
                         y_log='SingleTau' in supercat)
                p.drawBarChart(output_dir=destination + '/BarCharts',
                               message=args.message)

                #
                # Signal
                #
                hist_to_plot = []
                hist_names = []
                for sn, sample_name in enumerate(
                        sorted(list_of_values['signal'].keys(),
                               key=lambda k: int(k.split('-m')[-1]))):
                    # hist_to_plot.append(ROOT.TH1D(sample_name, sample_name, len(list_of_values['signal'][sample_name]), 0, len(list_of_values['signal'][sample_name])))
                    hist_to_plot.append(
                        ROOT.TH1D(sample_name, sample_name,
                                  len(SUPER_CATEGORIES[supercat]), 0,
                                  len(SUPER_CATEGORIES[supercat])))
                    hist_names.append(sample_name)