inputFileNames = [f  for i in inputs for f in glob.glob(i if i.endswith(ext) else i+'/*'+ext)]
assert channel in validChannels,"Invalid channel %s (should be one of %s)" % (channel, str(validChannels))
inputFiles = [r.TFile.Open(f) for f in inputFileNames]

if verbose :
    print "Options:\n" \
          + '\n'.join(["%s : %s" % (o, eval(o))
                       for o in ['channel', 'printData', 'printTotBkg',
                                 'rawcnt', 'referenceHisto', 'referenceSyst','selRegexp',
                                 'pickleFile']])
    print 'Input files:\n'+'\n'.join(inputFileNames)

# navigate the files and collect the histos
referenceType = HistoType(pr='', ch=channel, var=referenceHisto, syst=referenceSyst)
histosByType = collections.defaultdict(list)
classifier = HistoNameClassifier()

histoNames = []
for fname, infile in zip(inputFileNames, inputFiles) :
    sample = guessGroupFromFilename(fname)
    setType, setSample = setHistoType, setHistoSample
    def getType(histoName) : return classifier.histoType(histoName)
    def isRightType(histo) : return referenceType.matchAllAvailabeAttrs(histo.type)
    histonamesCached = len(histoNames)>0
    if not histonamesCached : histoNames = getAllHistoNames(infile, onlyTH1=True, nameStem=histoname)
    histos = filter(isRightType, map(lambda hn :
                                     setSample(setType(infile.Get(hn), getType(hn)), sample),
                                     histoNames))
    if not histonamesCached : histoNames = [h.GetName() for h in histos] # after filtering
    organizeHistosByType(histosByType, histos)
refHistos = histosByType # already filtered histonames, all histosByType are refHistos
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
inputDir        = options.inputdir
signalFname     = options.sig
prodTag         = options.tag
referenceHisto  = options.histo
plotRegions     = options.regions.split(',')
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]))
예제 #4
0
                  help="print more details about what is going on")
(options, args) = parser.parse_args()
inputDir        = options.inputdir
prodTag         = options.tag
signalFname     = options.sigFname
signalScale     = options.sigScale
justTest        = options.test
verbose         = options.verbose

inputFileNames = glob.glob(inputDir+'/'+'*'+prodTag+'*.root') + glob.glob(signalFname)
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