def getInputFilenames(inputdir, tag, options) : sig, bkg = dict(), dict() for f in glob.glob(inputdir+'/*'+tag+'.root') : sample = os.path.splitext(os.path.basename(f))[0].replace(tag, '').strip('_') coll = sig if isSigSample(sample) else bkg assert sample not in coll,"%s already found\n%s\n%s"%(sample, f, coll[sample]) coll[sample] = f if options.verbose : print 'input files:\n',sig,'\n',bkg assert sig and bkg, "missing signals or backgrounds" return sig, bkg
def fillInScriptTemplate(sample, input, output, outlog, otherOptions, outScript, scriptTemplate, tag) : options = otherOptions options += ' --WH-sample' if isSigSample(sample) else '' jobname = sample out_logfile = logdir+'/'+sample+'_'+tag+'.log' outFile = open(outScript, 'w') for line in open(scriptTemplate).readlines() : line = line.replace('%(inp)s', input) line = line.replace('%(jobname)s', jobname) line = line.replace('%(logfile)s', out_logfile) line = line.replace('%(out)s', output) line = line.replace('%(opt)s', options) line = line.replace('%(sample)s', sample) outFile.write(line) outFile.close()
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()
def isSignal(s) : return isSigSample(s) or s=='signal' if 'totbkg' not in counts :