示例#1
0
def guess_available_selections_from_histofiles(inputDir, plot_group, verbose):
    grp = plot_group.name
    sys = plot_group.syst  # default one, usually 'NOM' which is just fine
    available_root_files = [
        f for f in os.listdir(inputDir) if sys in f and grp in f
    ]
    pre = commonPrefix(available_root_files)
    suf = commonSuffix(available_root_files)

    def abbreviate_suffix(s):
        if s[1] in ['.', '_']:
            return s[1:]

    suf = abbreviate_suffix(suf)
    if verbose:
        print "guess_available_selections_from_histofiles: pre '{0}', suf '{1}'".format(
            pre, suf)
    available_selections = [
        r.replace(pre, '').replace(suf, '') for r in available_root_files
    ]
    selections = regions_to_plot(regions=available_selections)
    if not selections:
        raise UserWarning("guess_available_selections_from_histofiles:"
                          " failed to guess anything from '{0}'"
                          "\nTry using --region".format(inputDir))
    return selections
示例#2
0
 def guess_out_name(input_names=[]):
     pref = commonPrefix(hnames)
     suff = commonSuffix(hnames)
     out_name = (pref+label+suff) if (pref or suff) else (input_names[0]+'_'+label)
     out_name = out_name.replace('__','_') if remove_extra_underscore else out_name
     out_name = out_name[:-1] if remove_extra_underscore and out_name.endswith('_') else out_name
     return out_name
示例#3
0
    def build_average_sys_yield(cls,
                                component_nominal_yields=[],
                                component_syst_yields_up=[],
                                component_syst_yields_do=[]):
        "build the average sys yield of up/down variations"
        cny = component_nominal_yields
        csyu = component_syst_yields_up
        csyd = component_syst_yields_do
        cls.check_attribute_with_same_value('region', cny + csyu + csyd)
        cls.check_attribute_with_same_value('variation', csyu)
        cls.check_attribute_with_same_value('variation', csyd)

        nom_yield = cls.build_merged_yield(cny, cny)
        up_yield = cls.build_merged_yield(cny, csyu)
        do_yield = cls.build_merged_yield(cny, csyd)
        vup = csyu[0].variation
        vdo = csyd[0].variation
        variation = commonPrefix([vup, vdo]).strip('_') + commonSuffix(
            [vup, vdo]).strip('_')
        nom = nom_yield.get_yield()
        up = up_yield.get_yield()
        do = do_yield.get_yield()
        avg_delta = 0.5 * (abs(nom - up) + abs(nom - do))
        tot_yield = SignalYield(nom_yield, variation, nom + avg_delta)
        return tot_yield
示例#4
0
 def guess_out_name(input_names=[]):
     pref = commonPrefix(hnames)
     suff = commonSuffix(hnames)
     out_name = (pref+label+suff) if (pref or suff) else (input_names[0]+'_'+label)
     out_name = out_name.replace('__','_') if remove_extra_underscore else out_name
     out_name = out_name[:-1] if remove_extra_underscore and out_name.endswith('_') else out_name
     return out_name
def fastSamplesFromFilenames(filenames=[], verbose=False):
    """Assume a list of filenames with some common prefix (basepath)
    and suffix (tag): strip away the prefix&suffix, and return a list
    of Dataset objects obtained by matching the name to the dataset
    """
    prefix = utils.commonPrefix(filenames)
    suffix = utils.commonSuffix(filenames)
    if verbose : print "fastSamplesFromFilenames: prefix '%s' suffix '%s'"%(prefix, suffix)
    if not prefix or not suffix : print "fastSamplesFromFilenames: warning prefix '%s' suffix '%s'"%(prefix, suffix)
    filenames = [f.replace(prefix, '').replace(suffix, '') for f in filenames]
    dsets = dict([(d.name, d) for d in datasets])
    return [dsets[f] for f in filenames if f in dsets]
示例#6
0
def fastSamplesFromFilenames(filenames=[], verbose=False):
    """Assume a list of filenames with some common prefix (basepath)
    and suffix (tag): strip away the prefix&suffix, and return a list
    of Dataset objects obtained by matching the name to the dataset
    """
    prefix = utils.commonPrefix(filenames)
    suffix = utils.commonSuffix(filenames)
    if verbose:
        print "fastSamplesFromFilenames: prefix '%s' suffix '%s'" % (prefix,
                                                                     suffix)
    if not prefix or not suffix:
        print "fastSamplesFromFilenames: warning prefix '%s' suffix '%s'" % (
            prefix, suffix)
    filenames = [f.replace(prefix, '').replace(suffix, '') for f in filenames]
    dsets = dict([(d.name, d) for d in datasets])
    return [dsets[f] for f in filenames if f in dsets]
示例#7
0
def guess_available_selections_from_histofiles(inputDir, plot_group, verbose):
    grp = plot_group.name
    sys = plot_group.syst # default one, usually 'NOM' which is just fine
    available_root_files = [f for f in os.listdir(inputDir) if sys in f and grp in f]
    pre = commonPrefix(available_root_files)
    suf = commonSuffix(available_root_files)
    def abbreviate_suffix(s):
        if s[1] in ['.','_']:
            return s[1:]
    suf = abbreviate_suffix(suf)
    if verbose:
        print "guess_available_selections_from_histofiles: pre '{0}', suf '{1}'".format(pre, suf)
    available_selections = [r.replace(pre, '').replace(suf, '') for r in available_root_files]
    selections = regions_to_plot(regions=available_selections)
    if not selections:
        raise UserWarning("guess_available_selections_from_histofiles:"
                          " failed to guess anything from '{0}'"
                          "\nTry using --region".format(inputDir))
    return selections
def buildRatioHistos(histosNum={}, histosDen={}) :
    "assume that the histos are organized in two dict[vt][sample] provided by buildHistos"
    histosPerVtypePerSample = {}
    def sameLists(l1=[], l2=[]) : return len(l1)==len(l2) and sorted(l1)==sorted(l2)
    assert sameLists(histosNum.keys(), histosDen.keys()),"num and den w/ different vtype keys"
    result = {}
    for vt in histosDen.keys() :
        resultPerSample = {}
        hvn, hvd = histosNum[vt], histosDen[vt]
        assert sameLists(hvn.keys(), hvd.keys()),"num and den w/ different sample keys"
        for s in hvd.keys() :
            hnum, hden = hvn[s], hvd[s]
            hNames = [h.GetName() for h in hnum, hden]
            pre, suf = commonPrefix(hNames), commonSuffix(hNames)
            hName = pre+'_ratio_'+suf if len(pre) and len(suf) else '_over_'.join(hNames)
            h = buildRatioHistogram(hnum, hden, hName)
            resetErrors(h)
            resultPerSample[s] = h
        result[vt] = resultPerSample
    return result
def buildRatioHistos(histosNum={}, histosDen={}) :
    "assume that the histos are organized in two dict[vt][sample] provided by buildHistos"
    histosPerVtypePerSample = {}
    def sameLists(l1=[], l2=[]) : return len(l1)==len(l2) and sorted(l1)==sorted(l2)
    assert sameLists(histosNum.keys(), histosDen.keys()),"num and den w/ different vtype keys"
    result = {}
    for vt in histosDen.keys() :
        resultPerSample = {}
        hvn, hvd = histosNum[vt], histosDen[vt]
        assert sameLists(hvn.keys(), hvd.keys()),"num and den w/ different sample keys"
        for s in hvd.keys() :
            hnum, hden = hvn[s], hvd[s]
            hNames = [h.GetName() for h in hnum, hden]
            pre, suf = commonPrefix(hNames), commonSuffix(hNames)
            hName = pre+'_ratio_'+suf if len(pre) and len(suf) else '_over_'.join(hNames)
            h = buildRatioHistogram(hnum, hden, hName)
            resetErrors(h)
            resultPerSample[s] = h
        result[vt] = resultPerSample
    return result
示例#10
0
 def merged_sample_name(cls, names=[]):
     return commonPrefix(names) + commonSuffix(names).replace('__', '_')
def guessBaseHistoname(histonames=[]) :
    basename = commonSuffix(histonames)
    basename = commonPrefix(histonames) if not len(basename) else basename
    basename = histonames[0] if not len(basename) else basename
    return basename.strip(' _')