inputFiles = [r.TFile.Open(f) for f in inputFileNames]
assert len(inputFileNames) == len(
    inputFiles), "Cannot open some of the input files"

refHistoType = HistoType(pr='',
                         ch=channel,
                         var=referenceHisto,
                         syst=referenceSyst)
histosByType = collections.defaultdict(list)
classifier = HistoNameClassifier()

for fname, infile in zip(inputFileNames, inputFiles):
    samplename = guessSampleFromFilename(fname)
    histoNames = [
        n for n in getAllHistoNames(infile, onlyTH1=True)
        if refHistoType.matchAllAvailabeAttrs(classifier.histoType(n))
    ]
    histos = [infile.Get(hn) for hn in histoNames]
    for h in histos:
        setHistoType(h, classifier.histoType(h.GetName()))
        setHistoSample(h, samplename)
    histos = [h for h in histos if h.type.pr in plotRegions]
    organizeHistosByType(histosByType, histos)
refHistos = histosByType  # already filtered histonames, all histosByType are refHistos


def isSignal(sampleName):
    return 'WH_' in sampleName


allSamples = list(
referenceSyst   = options.syst
verbose         = options.verbose
assert channel in validChannels,"Invalid channel %s (should be one of %s)" % (channel, str(validChannels))
inputFileNames = glob.glob(inputDir+'/'+'*'+prodTag+'*.root') + glob.glob(signalFname)
inputFiles = [r.TFile.Open(f) for f in inputFileNames]
assert len(inputFileNames)==len(inputFiles),"Cannot open some of the input files"


refHistoType = HistoType(pr='', ch=channel, var=referenceHisto, syst=referenceSyst)
histosByType = collections.defaultdict(list)
classifier = HistoNameClassifier()

for fname, infile in zip(inputFileNames, inputFiles) :
    samplename = guessSampleFromFilename(fname)
    histoNames = [n for n in getAllHistoNames(infile, onlyTH1=True)
                  if refHistoType.matchAllAvailabeAttrs( classifier.histoType( n ) )]
    histos = [infile.Get(hn) for hn in histoNames]
    for h in histos :
        setHistoType(h, classifier.histoType(h.GetName()))
        setHistoSample(h, samplename)
    histos = [h for h in histos if h.type.pr in plotRegions]
    organizeHistosByType(histosByType, histos)
refHistos = histosByType # already filtered histonames, all histosByType are refHistos

def isSignal(sampleName) : return 'WH_' in sampleName
allSamples = list(set([h.sample for histos in refHistos.values() for h in histos]))
allBkgNames  = [s for s in allSamples if not isSignal(s)]
sigName = next(s for s in allSamples if isSignal(s))
if verbose : print '\n'.join("%s : %s" % (s,l) for s,l in zip(['bkg','sig'], [str(allBkgNames), sigName]))

bkgHistosByType, sigHistosByType = dict(), dict()
예제 #3
0
print 'input files:\n'+'\n'.join(inputFileNames)
inputFiles = [r.TFile.Open(f) for f in inputFileNames]


histosByType = collections.defaultdict(list)
classifier = HistoNameClassifier()

for fname, infile in zip(inputFileNames, inputFiles) :
    print '-'*3 + fname + '-'*3
    samplename = guessSampleFromFilename(fname)
    histoNames = getAllHistoNames(inputFiles[0], onlyTH1=True)
    histoNames = [h for h in histoNames if any([h.startswith(p) for p in ['sr6', 'sr7', 'sr8', 'sr9']])]
    if justTest : histoNames = histoNames[:10] # just get 10 histos to run quick tests
    histos = [infile.Get(hn) for hn in histoNames]
    for h in histos :
        setHistoType(h, classifier.histoType(h.GetName()))
        setHistoSample(h, samplename)
    organizeHistosByType(histosByType, histos)

def isSignal(sampleName) : return 'WH_' in sampleName

def cumsum(l, leftToRight=True) :
    #return numpy.cumsum(l) # not available ?
    return [sum(l[:i]) for i in range(1,len(l)+1)] if leftToRight \
           else [sum(l[-i:]) for i in range(1,len(l)+1)][::-1]
def mergeOuter(bc, nOuter=2) : # add over/underflow in the first/last bin
    return [sum(bc[:nOuter])] + bc[nOuter:-nOuter] + [sum(bc[-nOuter:])]

def cumSumHisto(histo, leftToRight=True) :
    hCs = histo.Clone(histo.GetName()+'_cs')
    nBinsX = 1+hCs.GetNbinsX() # TH1 starts from 1 (0 underflow, N+1 overflow)