示例#1
0
def mc_stack_n_data_sum(wrps, merge_mc_key_func=None, use_all_data_lumi=False):
    """
    Stacks MC histos and merges data, input needs to be sorted and grouped.

    The output are tuples of MC stacks and data histograms.
    ATTENTION: This crashes, if the proper histograms are not present!

    :param wrps:                Iterables of HistoWrapper (grouped)
    :param merge_mc_key_func:   key function for python sorted(...), default
                                tries to sort after stack position
    :yields:                    (StackWrapper, HistoWrapper)
    """
    if not merge_mc_key_func:
        merge_mc_key_func = lambda w: settings.get_stack_position(w.sample)

    for grp in wrps:

        # split stream
        data, mc = split_data_mc(grp)

        # sum up data
        data_sum = None
        try:
            data_sum = op.sum(data)
        except op.TooFewWrpsError:
            print "WARNING generators.mc_stack_n_data_sum(..): "\
                  "No data histos present! I will yield only mc."
        if use_all_data_lumi:
            data_lumi = settings.data_lumi_sum_wrp()
        else:
            data_lumi = op.lumi(data_sum)

        # merge mc samples (merge also normalizes to lumi = 1.)
        mc_sorted = sorted(mc, key=merge_mc_key_func)
        mc_groupd = group(mc_sorted, merge_mc_key_func)
        mc_merged = (op.merge(g) for g in mc_groupd)
        mc_colord = apply_histo_fillcolor(mc_merged)

        # stack mc
        mc_norm = gen_prod(
            itertools.izip(mc_colord, itertools.repeat(data_lumi)))
        mc_stck = None
        try:
            mc_stck = op.stack(mc_norm)
        except op.TooFewWrpsError:
            print "WARNING generators.mc_stack_n_data_sum(..): " \
                  "No mc histos present! I will yield only data"
        if mc_stck and data_sum:
            yield mc_stck, data_sum
        elif mc_stck:
            yield (mc_stck, )
        elif data_sum:
            yield (data_sum, )
        else:
            raise op.TooFewWrpsError("Neither data nor mc histos present!")
示例#2
0
def mc_stack_n_data_sum(wrps, merge_mc_key_func=None, use_all_data_lumi=False):
    """
    Stacks MC histos and merges data, input needs to be sorted and grouped.

    The output are tuples of MC stacks and data histograms.
    ATTENTION: This crashes, if the proper histograms are not present!

    :param wrps:                Iterables of HistoWrapper (grouped)
    :param merge_mc_key_func:   key function for python sorted(...), default
                                tries to sort after stack position
    :yields:                    (StackWrapper, HistoWrapper)
    """
    if not merge_mc_key_func:
        merge_mc_key_func = lambda w: settings.get_stack_position(w.sample)

    for grp in wrps:

        # split stream
        data, mc = split_data_mc(grp)

        # sum up data
        data_sum = None
        try:
            data_sum = op.sum(data)
        except op.TooFewWrpsError:
            print "WARNING generators.mc_stack_n_data_sum(..): "\
                  "No data histos present! I will yield only mc."
        if use_all_data_lumi:
            data_lumi = settings.data_lumi_sum_wrp()
        else:
            data_lumi = op.lumi(data_sum)

        # merge mc samples (merge also normalizes to lumi = 1.)
        mc_sorted = sorted(mc, key=merge_mc_key_func)
        mc_groupd = group(mc_sorted, merge_mc_key_func)
        mc_merged = (op.merge(g) for g in mc_groupd)
        mc_colord = apply_histo_fillcolor(mc_merged)

        # stack mc
        mc_norm = gen_prod(itertools.izip(mc_colord, itertools.repeat(data_lumi)))
        mc_stck = None
        try:
            mc_stck = op.stack(mc_norm)
        except op.TooFewWrpsError:
            print "WARNING generators.mc_stack_n_data_sum(..): " \
                  "No mc histos present! I will yield only data"
        if mc_stck and data_sum:
            yield mc_stck, data_sum
        elif mc_stck:
            yield (mc_stck, )
        elif data_sum:
            yield (data_sum, )
        else:
            raise op.TooFewWrpsError("Neither data nor mc histos present!")
示例#3
0
def mc_stack(wrps, merge_mc_key_func=None):
    """
    Delivers only MC stacks, feed only with MC.

    :param wrps:                Iterables of HistoWrapper (grouped)
    :param merge_mc_key_func:   key function for python sorted(...), default
                                tries to sort after stack position
    :yields:                    StackWrapper
    """
    if not merge_mc_key_func:
        merge_mc_key_func = lambda w: settings.get_stack_position(w.sample)
    for grp in wrps:

        # merge mc samples (merge also normalizes to lumi = 1.)
        mc_sorted = sorted(grp, key=merge_mc_key_func)
        mc_groupd = group(mc_sorted, merge_mc_key_func)
        mc_merged = (op.merge(g) for g in mc_groupd)
        mc_colord = apply_histo_fillcolor(mc_merged)

        # stack mc
        stack = op.stack(mc_colord)
        yield stack
示例#4
0
def mc_stack(wrps, merge_mc_key_func=None):
    """
    Delivers only MC stacks, feed only with MC.

    :param wrps:                Iterables of HistoWrapper (grouped)
    :param merge_mc_key_func:   key function for python sorted(...), default
                                tries to sort after stack position
    :yields:                    StackWrapper
    """
    if not merge_mc_key_func:
        merge_mc_key_func = lambda w: settings.get_stack_position(w.sample)
    for grp in wrps:

        # merge mc samples (merge also normalizes to lumi = 1.)
        mc_sorted = sorted(grp, key=merge_mc_key_func)
        mc_groupd = group(mc_sorted, merge_mc_key_func)
        mc_merged = (op.merge(g) for g in mc_groupd)
        mc_colord = apply_histo_fillcolor(mc_merged)

        # stack mc
        stack = op.stack(mc_colord)
        yield stack