Example #1
0
def printCounters(counters):
    countTotalBkg(counters)
    blindGroups   = [g for g in counters.keys() if g!='data']
    unblindGroups = [g for g in counters.keys()]
    tableSr  = CutflowTable(samples=blindGroups,   selections=signalRegions(), countsSampleSel=counters)
    tablePre = CutflowTable(samples=blindGroups,   selections=controlRegions(), countsSampleSel=counters)
    tableBld = CutflowTable(samples=unblindGroups, selections=blindRegions(), countsSampleSel=counters)
    for table in [tableSr, tablePre, tableBld] : table.nDecimal = 6
    print 4*'-',' sig regions ',4*'-'
    print tableSr.csv()
    print 4*'-',' pre regions ',4*'-'
    print tablePre.csv()
    print 4*'-',' blind regions ',4*'-'
    print tableBld.csv()
def printSummary(counts, outfilename='') :
    samples = counts.keys()
    signal = [s for s in samples if isSigSample(s)][0]
    counts = renameDictKey(counts, signal, 'signal')
    samples = counts.keys()
    selections = sorted(first(counts).keys())
    def isSignal(s) : return isSigSample(s) or s=='signal'
    if 'totbkg' not in counts :
        counts['totbkg'] = dict([(sel, sum(countsSample[sel]
                                           for sam, countsSample in counts.iteritems() if not isSignal(sam)))
                                 for sel in first(counts).keys()])
    bkgUnc = 0.30
    zn = r.RooStats.NumberCountingUtils.BinomialExpZ
    counts['Zn'] = dict([(sel, zn(counts['signal'][sel], counts['totbkg'][sel], bkgUnc)) for sel in selections])
    firstThreeColumns = ['Zn', 'signal', 'totbkg']
    otherSamples = sorted([s for s in samples if s not in firstThreeColumns])
    table = CutflowTable(firstThreeColumns + otherSamples, selections, counts)
    table.nDecimal = 2
    if outfilename :
        with open(outfilename, 'w') as f :
            f.write('\n'+table.latex()+'\n')
    else :
        print
        print table.latex()
Example #3
0
def printCounters(counters):
    countTotalBkg(counters)
    blindGroups = [g for g in counters.keys() if g != 'data']
    unblindGroups = [g for g in counters.keys()]
    tableSr = CutflowTable(samples=blindGroups,
                           selections=signalRegions(),
                           countsSampleSel=counters)
    tablePre = CutflowTable(samples=blindGroups,
                            selections=controlRegions(),
                            countsSampleSel=counters)
    tableBld = CutflowTable(samples=unblindGroups,
                            selections=blindRegions(),
                            countsSampleSel=counters)
    for table in [tableSr, tablePre, tableBld]:
        table.nDecimal = 6
    print 4 * '-', ' sig regions ', 4 * '-'
    print tableSr.csv()
    print 4 * '-', ' pre regions ', 4 * '-'
    print tablePre.csv()
    print 4 * '-', ' blind regions ', 4 * '-'
    print tableBld.csv()
allSamples += ['totbkg'] if printTotBkg else []
allSelects = sorted(list(set([k.pr for k in histosByType.keys()])))
if verbose : print 'allSamples : ',allSamples
if verbose : print 'allSelects : ',allSelects

# get the counts (adding up what needs to be merged by samplename)
sampleCountsPerSel = dict() # counts[sample][sel]
countsSampleSel = dict([(s, collections.defaultdict(float)) for s in allSamples])
for t, histos in refHistos.iteritems() :
    if t.ch != channel : continue
    for h in histos :
        sample, sel = h.sample, h.type.pr
        cnt = h.GetEntries() if rawcnt else h.Integral()
        skipIt = not printData and sample=='data'
        countIt = not skipIt
        countsSampleSel[sample][sel] += cnt if countIt else 0.0
        if printTotBkg and isBkgSample(sample) :
            countsSampleSel['totbkg'][sel] += cnt

ct = CutflowTable(allSamples, allSelects, countsSampleSel,
                  isRawCount=rawcnt, selectionRegexp=selRegexp)
csv = ct.csv()
print csv
if csvFile :
    with open(csvFile, 'w') as f : f.write(csv)
if texFile :
    with open(texFile, 'w') as f : f.write(ct.latex())
if pklFile :
    dumpToPickle(pklFile, countsSampleSel)