Beispiel #1
0
 names=["histo1", "histo2"]
 
 # set drawing options
 legends=["Test Histo 1", "Test Histo 2"]
 options=["LPE", "HIST"]
 opt_legends=["LPE", "L"]
 marker_types=[22, 0]
 marker_sizes=line_sizes=[2, 2]
 marker_colors=line_colors=[2,4]
 binning=[0,10,20,30,40,50,60,70,80,90,100]
 
 # set fig name
 figname="examplev1"
 
 # draw the histograms
 theone = oneplot()
 theone.initialize(file=file,names=names,legends=legends, opt_legends=opt_legends,
                 ratio=0.2,xtitle="Arbitrary",ytitle="Arbitrary",
                 figname=figname, binning=binning,
                 ratiotitle="Histo2/Histo1",
                 marker_types=marker_types, marker_sizes=marker_sizes, marker_colors=marker_colors,
                 line_sizes=line_sizes, line_colors=line_colors)
 theone.plot1DHistogram()
 theone.finish()    
 
 # end
 
 
 
 
 
Beispiel #2
0
def plot_histograms(process, variable_name, normalization_option):
    # read histograms from the signal files
    if process == 'signal':
        root_file_1 = TFile(FILE_PATH + "/BDT/BDT_Signal_histogram_3.root")
        root_file_2 = TFile(FILE_PATH +
                            "/210_eeee_fid_preselected_histograms.root")
        signals = root_file_1.Get(variable_name)
        backgrounds = root_file_2.Get(variable_name)

        # specify the output png file name in different cases
        # no normalization
        if normalization_option == 0:
            figname = "signal_" + FIGURE_NAME[variable_name]
        # normalize the histograms to 40fb-1 with their respective cross-section
        elif normalization_option == 1:
            signals.Scale(0.18 * 40 * EFF_SIGNAL_PRE_SELECTION /
                          signals.Integral(0, -1))
            backgrounds.Scale(1.85 * 40 * EFF_BACKGROUND_PRE_SELECTION /
                              backgrounds.Integral(0, -1))
            figname = "signal_" + FIGURE_NAME[
                variable_name] + "_normalized_to_40fb-1"
        # normalize the histograms to unity area
        elif normalization_option == 2:
            signals.Scale(1. / signals.Integral(0, -1))
            backgrounds.Scale(1. / backgrounds.Integral(0, -1))
            figname = "signal_" + FIGURE_NAME[
                variable_name] + "_normalized_to_unity_area"

    elif process == 'background':
        root_file_1 = TFile(FILE_PATH + "/BDT/BDT_Background_histogram_3.root")
        root_file_2 = TFile(FILE_PATH +
                            "/3210_eeee_fid_preselected_histograms.root")
        signals = root_file_1.Get(variable_name)
        backgrounds = root_file_2.Get(variable_name)

        print "signal events:", signals.Integral(0, -1)
        print "background events", backgrounds.Integral(0, -1)

        # if there is no signal or backround event, do not normalize the histograms
        if (signals.Integral(0, -1) == 0 or backgrounds.Integral(0, -1) == 0):
            normalization_option = 0

        # specify the output png file name in different cases
        # no normalization
        if normalization_option == 0:
            figname = "background_" + FIGURE_NAME[variable_name]
        # normalize the histograms to 40fb-1 with their respective cross-section
        elif normalization_option == 1:
            signals.Scale(0.18 * 40 * EFF_SIGNAL_PRE_SELECTION /
                          signals.Integral(0, -1))
            backgrounds.Scale(1.85 * 40 * EFF_BACKGROUND_PRE_SELECTION /
                              backgrounds.Integral(0, -1))
            figname = "background_" + FIGURE_NAME[
                variable_name] + "_normalized_to_40fb-1"
        # normalize the histograms to unity area
        elif normalization_option == 2:
            signals.Scale(1. / signals.Integral(0, -1))
            backgrounds.Scale(1. / backgrounds.Integral(0, -1))
            figname = "background_" + FIGURE_NAME[
                variable_name] + "_normalized_to_unity_area"

    histograms = []
    histograms.append(signals)
    histograms.append(backgrounds)

    names = []
    names.append("final selection")
    names.append("pre-selection")

    xtitle = AXES_TITLES[variable_name][0]
    ytitle = AXES_TITLES[variable_name][1]
    legends = LEGENDS[variable_name]

    options = ["HIST", "HIST"]
    opt_legends = ["L", "L"]
    marker_types = [26, 32]
    marker_sizes = [1, 3]
    line_sizes = [2, 2]
    marker_colors = line_colors = fill_colors = [30, 38]
    fill_types = [0, 0]

    # call oneplot.py for plotting in ATLAS style
    theone = oneplot()
    theone._figtype = ["png"]
    theone.initialize(
        list_histo=histograms,
        names=names,
        legends=legends,
        opt_legends=opt_legends,
        xtitle=xtitle,
        ytitle=ytitle,
        figname=figname,
        #   binning= [i*0.25 for i in range(40)],
        binning=BINNING[variable_name],
        options=options,
        marker_types=marker_types,
        marker_colors=marker_colors,
        marker_sizes=marker_sizes,
        line_colors=line_colors,
        line_sizes=line_sizes,
        fill_colors=fill_colors,
        fill_types=fill_types)
    theone.plot1DHistogram()
    theone.finish()

    # close the read files
    root_file_1.Close()
    root_file_2.Close()
Beispiel #3
0
                    # Draw histograms
                    xtitle = TITLES[var_name][0]
                    ytitle = TITLES[var_name][1]
                    legends = ["leading_{l}", "subleading_{l}", "leading_{v}", "subleading_{v}"]
                    options = ["HIST", "HIST", "HIST", "HIST"]            
                    opt_legends = ["L", "L", "L", "L"]                    
                    marker_types = [26, 26, 32, 32]                       
                    marker_sizes = [1, 1, 1, 1]                           
                    line_sizes = [2, 2, 2, 2]                             
                    marker_colors=line_colors=fill_colors=[4, 6, 2, 12] 
                    fill_types = [0, 0, 0, 0]                             
                    figname = cut + "_" + var_name
            
                    # call one plot
                    theone = oneplot()
                    theone._figtype=["png"]
                    theone.initialize(list_histo=histos,names=names,legends=legends, opt_legends=opt_legends,
                                    xtitle=xtitle,ytitle=ytitle,
                                    figname=figname, 
                                    options=options, marker_types=marker_types, marker_colors=marker_colors, marker_sizes=marker_sizes,
                                    line_colors=line_colors, line_sizes=line_sizes,
                                    fill_colors=fill_colors, fill_types=fill_types)
                    theone.plot1DHistogram()
                    theone.finish()

        for entry in VAR_2:
            for par in entry[0]:
                for var in entry[1]:

                    # load histograms
Beispiel #4
0
def plot_two_histograms(normalization_option, file_name_portion):
    histograms = []

    # no noramlization
    if normalization_option == 0:
        pass
    # normalize the histograms to 40fb-1 with their respective cross-section
    if normalization_option == 1:
        # print "'signals' has type: ", type(signals)
        signals.Scale(0.18 * 40 * EFF_SIGNAL_PRE_SELECTION /
                      signals.Integral(0, -1))
        backgrounds.Scale(1.85 * 40 * EFF_BACKGROUND_PRE_SELECTION /
                          backgrounds.Integral(0, -1))

    # normalize the histograms to unity area
    if normalization_option == 2:
        signals.Scale(1. / signals.Integral(0, -1))
        backgrounds.Scale(1. / backgrounds.Integral(0, -1))

    histograms.append(signals)
    histograms.append(backgrounds)

    names = []
    names.append("VBS signal")
    names.append("QCD background")

    xtitle = "BDT Score"
    ytitle = "events scaled"
    legends = ["VBS signal", "QCD background"]

    options = ["HIST", "HIST"]
    opt_legends = ["L", "L"]
    marker_types = [26, 32]
    marker_sizes = [1, 3]
    line_sizes = [2, 2]
    marker_colors = line_colors = fill_colors = [30, 38]
    fill_types = [0, 0]

    if normalization_option == 0:
        figname = "BDT_classification_cut_" + file_name_portion + "_rebinned"
    elif normalization_option == 1:
        figname = "BDT_classification_cut_" + file_name_portion + "_normalized_to_40fb-1_rebinned"
    elif normalization_option == 2:
        figname = "BDT_classification_cut_" + file_name_portion + "_normalized_to_unity_area_rebinned"

    # call oneplot.py for plotting in ATLAS style
    theone = oneplot()
    theone._figtype = ["png"]
    theone.initialize(
        list_histo=histograms,
        names=names,
        legends=legends,
        opt_legends=opt_legends,
        xtitle=xtitle,
        ytitle=ytitle,
        figname=figname,
        #   binning=np.arange(-1, 1.03, 0.03).tolist(),
        options=options,
        marker_types=marker_types,
        marker_colors=marker_colors,
        marker_sizes=marker_sizes,
        line_colors=line_colors,
        line_sizes=line_sizes,
        fill_colors=fill_colors,
        fill_types=fill_types)
    theone.plot1DHistogram()
    theone.finish()
Beispiel #5
0
def plot_histograms(normalization_option, file_name):

    # read the root file in list
    root_file_1 = TFile(file_name)
    root_file_2 = TFile(
        file_name.split("_")[0] + "_Background_histogram_" +
        file_name.split(".")[0].split("_")[-1] + ".root")

    # read signal and background histograms from the file
    signals = root_file_1.Get("h1")
    backgrounds = root_file_2.Get("h1")

    # calculate figure of merits
    calculate_figure_of_merit(signals, backgrounds)

    # read suffix of the file
    suffix = file_name.split(".")[0].split("_")[-1]

    # no normalization
    if normalization_option == 0:
        # specify the output png file name
        figname = "BDT_signal_background_distribution_" + suffix

    # normalize the histograms to 40fb-1 with their respective cross-sections
    if normalization_option == 1:
        signals.Scale(0.18 * 40 * EFF_SIGNAL_PRE_SELECTION /
                      signals.Integral(0, -1))
        backgrounds.Scale(1.85 * 40 * EFF_BACKGROUND_PRE_SELECTION /
                          backgrounds.Integral(0, -1))
        # specify the output png file name
        figname = "BDT_signal_background_distribution_normalized_to_unity_area_" + suffix

    # normalize the histograms to unity area
    elif normalization_option == 2:
        print "total numebr of signal events", signals.Integral(0, -1)
        print "total numebr of background events", backgrounds.Integral(0, -1)
        signals.Scale(1. / signals.Integral(0, -1))
        backgrounds.Scale(1. / backgrounds.Integral(0, -1))
        # specify the output png file name
        figname = "BDT_signal_background_distribution_normalized_to_40fb-1_" + suffix

    histograms = []
    histograms.append(signals)
    histograms.append(backgrounds)

    names = []
    names.append("signal")
    names.append("background")

    xtitle = "BDT Score"
    if normalization_option == 0:
        ytitle = "events"
    elif normalization_option == 1:
        ytitle = "events normalized to 40 fb-1"
    elif normalization_option == 2:
        ytitle = "events normalized to unity area"
    legends = ["VBS Singal", "QCD Background"]

    options = ["HIST", "HIST"]
    opt_legends = ["L", "L"]
    marker_types = [26, 32]
    marker_sizes = [1, 3]
    line_sizes = [2, 2]
    marker_colors = line_colors = fill_colors = [30, 38]
    fill_types = [0, 0]

    # call oneplot.py for plotting in ATLAS style
    theone = oneplot()
    theone._figtype = ["png"]
    theone.initialize(list_histo=histograms,
                      names=names,
                      legends=legends,
                      opt_legends=opt_legends,
                      xtitle=xtitle,
                      ytitle=ytitle,
                      figname=figname,
                      options=options,
                      marker_types=marker_types,
                      marker_colors=marker_colors,
                      marker_sizes=marker_sizes,
                      line_colors=line_colors,
                      line_sizes=line_sizes,
                      fill_colors=fill_colors,
                      fill_types=fill_types)
    theone.plot1DHistogram()
    theone.finish()

    # close the read files
    root_file_1.Close()
    root_file_2.Close()