def directories(args) :
    ## prepare structure of parent directories
    dirs = []
    for dir in args :
        if is_number(get_mass(dir)) or get_mass(dir) == "common" :
            dir = dir[:dir.rstrip('/').rfind('/')]
        if not dir in dirs :
            dirs.append(dir)
    ## prepare mapping of masses per parent directory
    masses = {}
    for dir in dirs :
        buffer = []
        for path in args :
            if dir+'/' in path :
                if is_number(get_mass(path)) :
                    mass = get_mass(path)
                    if not contained(mass, buffer) :
                        buffer.append(mass)
        masses[dir] = list(buffer)
    return (dirs, masses)
Beispiel #2
0
def directories(args) :
    ## prepare structure of parent directories
    dirs = []
    for dir in args :
        if is_number(get_mass(dir)) or get_mass(dir) == "common" :
            dir = dir[:dir.rstrip('/').rfind('/')]
        if not dir in dirs :
            dirs.append(dir)
    ## prepare mapping of masses per parent directory
    masses = {}
    for dir in dirs :
        buffer = []
        for path in args :
            if dir+'/' in path :
                if is_number(get_mass(path)) :
                    mass = get_mass(path)
                    if not contained(mass, buffer) :
                        buffer.append(mass)
        masses[dir] = list(buffer)
    return (dirs, masses)
Beispiel #3
0
    if file == "tmp.txt":
        # Ignore generated combined file - can't be parsed..
        continue
    an = matcher.match(file).group("ANALYSIS")
    matcher = re.compile(exprV)
    if an != "vhtt":
        matcher = re.compile(expr)
    cat = matcher.match(file).group("CATEGORY")
    chn = matcher.match(file).group("CHANNEL")
    per = matcher.match(file).group("PERIOD")
    # print "an:",an,"chn:",chn,"cat:",cat,"per:",per
    if an == "vhtt" and (cat == "0" or cat == "2"):
        chn = "wh"
    if an == "vhtt" and cat == "1":
        chn = "zh"
    if not contained(cat, categories):
        categories.append(cat)
    if not contained(chn, channels):
        channels.append(chn)
    if not contained(per, periods):
        periods.append(per)

print "Picking up channels, categories and periods from datacards in input directory:", options.input
print "------------------------------------------------------------------------------"
print "Expecting datacards of type htt_chn_cat_per.txt, with the following valid "
print "variables: "
print " - chn : em, et, mt, mm, tt"
print " - cat : 0, 1, 2, 3, 5, 6, 7, 8, 9"
print " - per : 7TeV, 8TeV, 14TeV"
print "------------------------------------------------------------------------------"
print "Picked up categories are:", categories
Beispiel #4
0
def merge_efficiencies(channel, categories, periods) :
    """
    Merge the contents of the *.tmp files used to temporarily safe the information for the calculation
    of the signal efficiencies.The argument categories should contain a compact dictionary of event
    sub-categories to be contracted into main event-categories, the argument contains the list of all
    run periods to be considered. First the information per run period is added. Then the infomration
    of the event sub-categories is contracted into the main event categories. The results are safed in
    a *.tmp file labeld by the channel but no run period label. The information integrated over the
    run periods but not yet contracted into the main event categories is safed in a file which carries
    the extra label *_split.tmp. Only the signal channels ggH, qqH and VH are taken into account. VH
    it the sum of WH, ZH and ttH. 
    """
    ## list of subsets (used for contraction of sub-categories)
    subsets = []
    ## lines used to add periods
    lines = dict([(per, []) for per in periods])
    ## combine run periods
    for per in periods:
        file = open('eff_'+channel+'_'+per+'.tmp')
        for line in file :
            values = line.split()
            if len(values) == 1 :
                if not contained(values[0], subsets) :
                    subsets.append(values[0])
            lines[per].append(values)
        file.close()

    file = open('eff_'+channel+'_split.tmp', 'w')
    for i in range(len(lines[periods[0]])) :
        line = lines[periods[0]][i]
        if len(line) == 1 :
            file.write(line[0]+'\n')
        else :
            line_summed = []
            for per in periods :
                for j in range(len(lines[per][i])) :
                    if len(line_summed) == j :
                        line_summed.append(float(lines[per][i][j]) if j>0 else str(lines[per][i][j]))
                    elif j>0 :
                        line_summed[j]+=float(lines[per][i][j])
            file.write("%s \t %f \t %f \n" % (line_summed[0], line_summed[1], line_summed[2]))
    file.close()

    ## lines used to add sub-categories
    lines = dict([(sub, []) for sub in subsets])
    ## combine sub-categories
    file = open('eff_'+channel+'_split.tmp')
    file_empty = True
    for line in file :
        file_empty = False
        values = line.split()
        if len(values) == 1 :
            subset = values[0]
        else :
            for value in values :
                lines[subset].append(value)
    file.close()
    if not file_empty :
        file = open('eff_'+channel+'.tmp', 'w')
        for cat, subsets in categories.iteritems() :
            file.write(channel+'_'+cat+'\n')
            if len(subsets) == 0 :
                if options.analysis == "mssm" : 
                    file.write("%s \t %s \t %s \n" % (lines[channel+'_'+cat][0], lines[channel+'_'+cat][1], lines[channel+'_'+cat][2]))
                    file.write("%s \t %s \t %s \n" % (lines[channel+'_'+cat][3], lines[channel+'_'+cat][4], lines[channel+'_'+cat][5]))
                else :
                    file.write("%s \t %s \t %s \n" % (lines[channel+'_'+cat][0], lines[channel+'_'+cat][1], lines[channel+'_'+cat][2]))
                    file.write("%s \t %s \t %s \n" % (lines[channel+'_'+cat][3], lines[channel+'_'+cat][4], lines[channel+'_'+cat][5]))
                    file.write("%s \t %s \t %s \n" % (lines[channel+'_'+cat][6], lines[channel+'_'+cat][7], lines[channel+'_'+cat][8]))
            else :
                lines_summed = {}
                if options.analysis == "mssm" :
                    lines_summed = {
                        'ggH' : 0.,
                        'bbH' : 0.,
                        }
                else:
                    lines_summed = {
                        'ggH' : 0.,
                        'qqH' : 0.,
                        'VH'  : 0.,
                        }
                for sub in subsets :
                    if options.analysis == "mssm" :
                        lines_summed['ggH']+=float(lines[channel+'_'+cat+'_'+sub][1])
                        lines_summed['bbH']+=float(lines[channel+'_'+cat+'_'+sub][4])
                    else :
                        if len(lines[channel+'_'+cat+'_'+sub])>0 :
                            lines_summed['ggH']+=float(lines[channel+'_'+cat+'_'+sub][1])
                            lines_summed['qqH']+=float(lines[channel+'_'+cat+'_'+sub][4])
                            lines_summed['VH' ]+=float(lines[channel+'_'+cat+'_'+sub][7])
                if options.analysis == "mssm" :
                    file.write("%s \t %f \t %s \n" % (lines[channel+'_'+cat+'_'+sub][0], lines_summed['ggH'], lines[channel+'_'+cat+'_'+sub][2]))
                    file.write("%s \t %f \t %s \n" % (lines[channel+'_'+cat+'_'+sub][3], lines_summed['bbH'], lines[channel+'_'+cat+'_'+sub][5]))
                else :
                    if len(lines[channel+'_'+cat+'_'+sub])>0 :
                        file.write("%s \t %f \t %s \n" % (lines[channel+'_'+cat+'_'+sub][0], lines_summed['ggH'], lines[channel+'_'+cat+'_'+sub][2]))
                        file.write("%s \t %f \t %s \n" % (lines[channel+'_'+cat+'_'+sub][3], lines_summed['qqH'], lines[channel+'_'+cat+'_'+sub][5]))
                        file.write("%s \t %f \t %s \n" % (lines[channel+'_'+cat+'_'+sub][6], lines_summed['VH' ], lines[channel+'_'+cat+'_'+sub][8]))
        file.close()
Beispiel #5
0
    output.write("\\end{center} \n")
    output.write("\\end{table*} \n")
    return
    

## channels to be considered
channels = options.channels.split()
for idx in range(len(channels)) : channels[idx] = channels[idx].rstrip(',')## channels
## categories to be considered
categories = options.categories.split()
for idx in range(len(categories)) : categories[idx] = categories[idx].rstrip(',')
## periods to be considered
periods = options.period.split()
for idx in range(len(periods)) : periods[idx] = periods[idx].rstrip(',')
## extended dictionary of subsets to be contracted (used for merging of table yields)
if len(periods) == 1 and contained('7TeV', periods) :
    subsets_extended = {
        "0jet"  : ["low_7TeV", "high_7TeV"],
        "boost" : ["low_7TeV", "high_7TeV"],
        "vbf"   : ["7TeV"],
       #"btag"  : ["7TeV"],
       #"nobtag": ["7TeV"],
        }
if len(periods) == 1 and contained('8TeV', periods) :
    subsets_extended = {
        "0jet"     : ["low_8TeV", "high_8TeV"],
        "boost"    : ["low_8TeV", "high_8TeV"],
       #"boost" : ["8TeV"], ##for tt
        "vbf"   : ["8TeV"],
       #"btag"  : ["8TeV"],
       #"nobtag": ["8TeV"],
def merge_efficiencies(channel, categories, periods):
    """
    Merge the contents of the *.tmp files used to temporarily safe the information for the calculation
    of the signal efficiencies.The argument categories should contain a compact dictionary of event
    sub-categories to be contracted into main event-categories, the argument contains the list of all
    run periods to be considered. First the information per run period is added. Then the infomration
    of the event sub-categories is contracted into the main event categories. The results are safed in
    a *.tmp file labeld by the channel but no run period label. The information integrated over the
    run periods but not yet contracted into the main event categories is safed in a file which carries
    the extra label *_split.tmp. Only the signal channels ggH, qqH and VH are taken into account. VH
    it the sum of WH, ZH and ttH. 
    """
    ## list of subsets (used for contraction of sub-categories)
    subsets = []
    ## lines used to add periods
    lines = dict([(per, []) for per in periods])
    ## combine run periods
    for per in periods:
        file = open('eff_' + channel + '_' + per + '.tmp')
        for line in file:
            values = line.split()
            if len(values) == 1:
                if not contained(values[0], subsets):
                    subsets.append(values[0])
            lines[per].append(values)
        file.close()

    file = open('eff_' + channel + '_split.tmp', 'w')
    for i in range(len(lines[periods[0]])):
        line = lines[periods[0]][i]
        if len(line) == 1:
            file.write(line[0] + '\n')
        else:
            line_summed = []
            for per in periods:
                for j in range(len(lines[per][i])):
                    if len(line_summed) == j:
                        line_summed.append(
                            float(lines[per][i][j]
                                  ) if j > 0 else str(lines[per][i][j]))
                    elif j > 0:
                        line_summed[j] += float(lines[per][i][j])
            file.write("%s \t %f \t %f \n" %
                       (line_summed[0], line_summed[1], line_summed[2]))
    file.close()

    ## lines used to add sub-categories
    lines = dict([(sub, []) for sub in subsets])
    ## combine sub-categories
    file = open('eff_' + channel + '_split.tmp')
    file_empty = True
    for line in file:
        file_empty = False
        values = line.split()
        if len(values) == 1:
            subset = values[0]
        else:
            for value in values:
                lines[subset].append(value)
    file.close()
    if not file_empty:
        file = open('eff_' + channel + '.tmp', 'w')
        for cat, subsets in categories.iteritems():
            file.write(channel + '_' + cat + '\n')
            if len(subsets) == 0:
                if options.analysis == "mssm":
                    file.write("%s \t %s \t %s \n" %
                               (lines[channel + '_' + cat][0],
                                lines[channel + '_' + cat][1],
                                lines[channel + '_' + cat][2]))
                    file.write("%s \t %s \t %s \n" %
                               (lines[channel + '_' + cat][3],
                                lines[channel + '_' + cat][4],
                                lines[channel + '_' + cat][5]))
                else:
                    file.write("%s \t %s \t %s \n" %
                               (lines[channel + '_' + cat][0],
                                lines[channel + '_' + cat][1],
                                lines[channel + '_' + cat][2]))
                    file.write("%s \t %s \t %s \n" %
                               (lines[channel + '_' + cat][3],
                                lines[channel + '_' + cat][4],
                                lines[channel + '_' + cat][5]))
                    file.write("%s \t %s \t %s \n" %
                               (lines[channel + '_' + cat][6],
                                lines[channel + '_' + cat][7],
                                lines[channel + '_' + cat][8]))
            else:
                lines_summed = {}
                if options.analysis == "mssm":
                    lines_summed = {
                        'ggH': 0.,
                        'bbH': 0.,
                    }
                else:
                    lines_summed = {
                        'ggH': 0.,
                        'qqH': 0.,
                        'VH': 0.,
                    }
                for sub in subsets:
                    if options.analysis == "mssm":
                        lines_summed['ggH'] += float(lines[channel + '_' +
                                                           cat + '_' + sub][1])
                        lines_summed['bbH'] += float(lines[channel + '_' +
                                                           cat + '_' + sub][4])
                    else:
                        if len(lines[channel + '_' + cat + '_' + sub]) > 0:
                            lines_summed['ggH'] += float(
                                lines[channel + '_' + cat + '_' + sub][1])
                            lines_summed['qqH'] += float(
                                lines[channel + '_' + cat + '_' + sub][4])
                            lines_summed['VH'] += float(
                                lines[channel + '_' + cat + '_' + sub][7])
                if options.analysis == "mssm":
                    file.write("%s \t %f \t %s \n" %
                               (lines[channel + '_' + cat + '_' + sub][0],
                                lines_summed['ggH'],
                                lines[channel + '_' + cat + '_' + sub][2]))
                    file.write("%s \t %f \t %s \n" %
                               (lines[channel + '_' + cat + '_' + sub][3],
                                lines_summed['bbH'],
                                lines[channel + '_' + cat + '_' + sub][5]))
                else:
                    if len(lines[channel + '_' + cat + '_' + sub]) > 0:
                        file.write("%s \t %f \t %s \n" %
                                   (lines[channel + '_' + cat + '_' + sub][0],
                                    lines_summed['ggH'],
                                    lines[channel + '_' + cat + '_' + sub][2]))
                        file.write("%s \t %f \t %s \n" %
                                   (lines[channel + '_' + cat + '_' + sub][3],
                                    lines_summed['qqH'],
                                    lines[channel + '_' + cat + '_' + sub][5]))
                        file.write("%s \t %f \t %s \n" %
                                   (lines[channel + '_' + cat + '_' + sub][6],
                                    lines_summed['VH'],
                                    lines[channel + '_' + cat + '_' + sub][8]))
        file.close()

## channels to be considered
channels = options.channels.split()
for idx in range(len(channels)):
    channels[idx] = channels[idx].rstrip(',')  ## channels
## categories to be considered
categories = options.categories.split()
for idx in range(len(categories)):
    categories[idx] = categories[idx].rstrip(',')
## periods to be considered
periods = options.period.split()
for idx in range(len(periods)):
    periods[idx] = periods[idx].rstrip(',')
## extended dictionary of subsets to be contracted (used for merging of table yields)
if len(periods) == 1 and contained('7TeV', periods):
    subsets_extended = {
        "0jet": ["low_7TeV", "high_7TeV"],
        "boost": ["low_7TeV", "high_7TeV"],
        "vbf": ["7TeV"],
        #"btag"  : ["7TeV"],
        #"nobtag": ["7TeV"],
    }
if len(periods) == 1 and contained('8TeV', periods):
    subsets_extended = {
        "0jet": ["low_8TeV", "high_8TeV"],
        "boost": ["low_8TeV", "high_8TeV"],
        #"boost" : ["8TeV"], ##for tt
        "vbf": ["8TeV"],
        #"btag"  : ["8TeV"],
        #"nobtag": ["8TeV"],
Beispiel #8
0
    if file == 'tmp.txt':
        # Ignore generated combined file - can't be parsed..
        continue
    an  = matcher.match(file).group('ANALYSIS')
    matcher = re.compile(exprV)
    if an != 'vhtt' :
        matcher = re.compile(expr)
    cat = matcher.match(file).group('CATEGORY')
    chn = matcher.match(file).group('CHANNEL')
    per = matcher.match(file).group('PERIOD')
    #print "an:",an,"chn:",chn,"cat:",cat,"per:",per
    if an == 'vhtt' and (cat == '0' or cat == '2'):
        chn = 'wh'
    if an == 'vhtt' and cat == '1' :
        chn = 'zh'
    if not contained(cat, categories) :
        categories.append(cat)
    if not contained(chn, channels) :
        channels.append(chn)
    if not contained(per, periods) :
        periods.append(per)

print "Picking up channels, categories and periods from datacards in input directory:", options.input
print "------------------------------------------------------------------------------"
print "Expecting datacards of type htt_chn_cat_per.txt, with the following valid "
print "variables: "
print " - chn : em, et, mt, mm, tt"
print " - cat : 0, 1, 2, 3, 5, 6, 7, 8, 9"
print " - per : 7TeV, 8TeV, 14TeV"
print "------------------------------------------------------------------------------"
print "Picked up categories are:", categories
Beispiel #9
0
    else :
        ## directories and mases per directory
        struct = directories(args)
        lxb_submit(struct[0], struct[1], cmd, "{MODEL} {OPTS} {USER}".format(MODEL=model, OPTS=opts, USER=options.opt))
##
## INJECTED (asymptotic limits with signal injected, implementation for SM only)
##
if options.optInject :
    ## the input for lxb-injected.py should be a path, that is passed on as an
    ## option and the masses in question. Prepare here the corresponding paths
    ## and directories.
    paths = []
    dirs = {}
    for dir in args :
        head = dir[:dir.rstrip('/').rfind('/')]
        if not contained(head, paths) :
            paths.append(head)
            dirs[head] = []
    for dir in args :
        for path in paths :
            if path in dir :
                tail = dir[dir.rstrip('/').rfind('/')+1:]
                if is_number(tail) :
                    dirs[path].append(tail)
    if not options.calculate_injected :
        ## prepare options
        opts = options.opt
        opts+=" --observedOnly"
        if not options.nuisances == "" :
            opts+=" --no-prefit --external-pulls \"{PATH}\" --signal-plus-background {SPLUSB}".format(PATH=options.nuisances, SPLUSB=options.signal_plus_BG)
        method = options.injected_method#"--asymptotic"

## channels to be considered
channels = options.channels.split()
for idx in range(len(channels)):
    channels[idx] = channels[idx].rstrip(",")  ## channels
## categories to be considered
categories = options.categories.split()
for idx in range(len(categories)):
    categories[idx] = categories[idx].rstrip(",")
## periods to be considered
periods = options.period.split()
for idx in range(len(periods)):
    periods[idx] = periods[idx].rstrip(",")
## extended dictionary of subsets to be contracted (used for merging of table yields)
if len(periods) == 1 and contained("7TeV", periods):
    if options.analysis == "mssm":
        subsets_extended = {"btag": ["7TeV"], "nobtag": ["7TeV"]}
    else:
        if len(channels) == 1 and contained("em", channels):
            subsets_extended = {
                "0jet": ["low_7TeV", "high_7TeV"],
                "1jet": ["low_7TeV", "high_7TeV"],
                "vbf": ["loose_7TeV"],
            }
        elif len(channels) == 1 and contained("et", channels):
            subsets_extended = {
                "0jet": ["medium_7TeV", "high_7TeV"],
                "1jet": ["medium_7TeV", "high_mediumhiggs_7TeV"],
                "vbf": ["loose_7TeV"],
            }
for idx in range(len(channels)) : channels[idx] = channels[idx].rstrip(',')## channels
## categories
categories = options.categories.split()
for idx in range(len(categories)) : categories[idx] = categories[idx].rstrip(',')
## periods
periods = options.period.split()
for idx in range(len(periods)) : periods[idx] = periods[idx].rstrip(',')


os.system("rm -f *.tmp")
for chn in channels :
    for per in periods :
        for cat in categories :
            filename = options.input+"/htt_"+chn+"_"+cat+"_"+per+"-"+options.mass+".txt"
            extractor(filename, per)

        if contained("0", categories) and contained("1", categories):
            mergingCategories(chn,'0Jet',per)
        if contained("1", categories) and contained("2", categories):
            mergingCategories(chn,'Boosted',per)
        if contained("6", categories) and contained("7", categories):
            mergingCategories(chn,'Btag',per)
    if contained("7TeV", periods) and contained("8TeV", periods) :
        for cat in categories :
            mergingPeriods(chn, cat)
        makingTables(chn, "7+8TeV", True)
    else :
        for per in periods :
            makingTables(chn, per, True)
os.system("rm *.tmp")
Beispiel #12
0

## channels to be considered
channels = options.channels.split()
for idx in range(len(channels)):
    channels[idx] = channels[idx].rstrip(',')  ## channels
## categories to be considered
categories = options.categories.split()
for idx in range(len(categories)):
    categories[idx] = categories[idx].rstrip(',')
## periods to be considered
periods = options.period.split()
for idx in range(len(periods)):
    periods[idx] = periods[idx].rstrip(',')
## extended dictionary of subsets to be contracted (used for merging of table yields)
if len(periods) == 1 and contained('7TeV', periods):
    if options.analysis == "mssm":
        subsets_extended = {
            "btag": ["7TeV"],
            "nobtag": ["7TeV"],
        }
    else:
        if len(channels) == 1 and contained('em', channels):
            subsets_extended = {
                "0jet": ["low_7TeV", "high_7TeV"],
                "1jet": ["low_7TeV", "high_7TeV"],
                "vbf": ["loose_7TeV"],
            }
        elif len(channels) == 1 and contained('et', channels):
            subsets_extended = {
                "0jet": ["medium_7TeV", "high_7TeV"],