Ejemplo n.º 1
0
def hist_node(graph, cut, weights, variables):
    """
    Creates a simple CutNode -> WeightNode(s) ->
    HistNode(s) structure from the specified cut, weights and variables.

    Args:
        graph: a NX graph which is the parent of these nodes
        cut: a (cutname, Cut) tuple with the cut to apply
        weights: a list of (weightname, Weight) tuples to apply
        variables: a list of (varname, variable, binning) tuples to project out.

    Returns:
        The top CutNode that was created.
    """
    cut_name, cut = cut
    #weight_name, weight = _weight
    cutnode = CutNode(cut, graph, cut_name, [], [])

    if not isinstance(weights, list):
        weights = [weights]

    from weights import reweight

    for var_name, var, binning in variables:
        hist_desc = {
            "var": var,
            "binning": binning
        }
        histnode = HistNode(hist_desc, graph, var_name, [cutnode], [])
        reweight(histnode, [
            WeightNode(w[1], graph, w[0], [], []) for w in weights]
        )
    return cutnode
Ejemplo n.º 2
0
def create_plots(graph, plot_nodes, filter_funcs=[]):
    from weights import reweight, syst_weights
    from tree import HistNode
    #Add all the nodes for the final plots with all the possible reweighting combinations
    final_plots = dict()
    for t, descs in hdescs.items():
        for name, func, binning in descs:
            skip = False
            for f in filter_funcs:
                if f(name):
                    logger.info("Not creating a plot for %s" % name)
                    skip=True
                    break
            if skip:
                continue
            hd = hdesc(name, func, binning)

            #Make only the required plots per channel
            lambdas = []
            if t in final_plot_lambdas.keys():
                lambdas.append(final_plot_lambdas[t])

            final_plots[name] = HistNode(
                hd,
                graph, name, plot_nodes, [], filter_funcs=lambdas
            )
            final_plots[name] = reweight(
                final_plots[name],
                syst_weights(graph)
            )
    return final_plots