instancename = '{}_{}_{}'.format(flavour, year, var)
    inputfile = os.path.abspath('fakeRateMeasurement_data_' + instancename +
                                '_histograms.root')

    # check if input file exists
    if not os.path.exists(inputfile):
        raise Exception(
            'ERROR: required input file {} does not exist.'.format(inputfile))
    # make a working directory to store intermediate results
    workingdir = 'fakeRateTemplateFits_{}'.format(instancename)
    if not os.path.exists(workingdir):
        os.makedirs(workingdir)

    # read pt and eta bins and ranges
    basehistname = 'data_numerator_' + var + '_' + year + '_' + flavour
    (ptbins, etabins) = frt.readptetabins(inputfile, basehistname)
    ptrange = copy(ptbins)
    ptrange.append(100)
    etarange = copy(etabins)
    etarange.append(2.5)
    if (flavour == 'muon'): etarange[-1] = 2.4

    # make 2D maps to hold number of nonprompt leptons in num and denom
    nummap = ROOT.TH2D("fake-rate", "fake-rate; p_{T} (GeV); |#eta|",
                       len(ptrange) - 1, array('f', ptrange),
                       len(etarange) - 1, array('f', etarange))
    nummap.SetDirectory(0)
    nummap.Sumw2()
    denommap = ROOT.TH2D("", "",
                         len(ptrange) - 1, array('f', ptrange),
                         len(etarange) - 1, array('f', etarange))
Beispiel #2
0
 #	- process is a process tag (e.g. "DY" or "VV" or "data")
 #	- ptype is either "prompt" or "nonprompt" (absent for data!)
 #	- ftype is either "numerator" or "denominator"
 #	- var is usually "mT"
 if (doprefitplots):
     print('making input plots...')
     outputdir_sub = 'fakeRateMeasurementPlots_{}_{}_subtraction'.format(
         year, flavour)
     outputdir_fit = 'fakeRateMeasurementPlots_{}_{}_prefit'.format(
         year, flavour)
     if not os.path.exists(outputdir_sub): os.makedirs(outputdir_sub)
     if not os.path.exists(outputdir_fit): os.makedirs(outputdir_fit)
     # initializations
     var = 'mT' if use_mT else 'met'
     histbasename = 'data_numerator_{}_{}_{}'.format(var, year, flavour)
     (ptbins, etabins) = frt.readptetabins(inputfile, histbasename)
     # loop over bins
     for ptbin in ptbins:
         for etabin in etabins:
             print('   bin pt {}, eta {}'.format(ptbin, etabin))
             for ftype in ['denominator', 'numerator']:
                 # get histograms
                 ptbinstr = str(ptbin).replace('.', 'p')
                 etabinstr = str(etabin).replace('.', 'p')
                 thisbin = '{}_{}_{}_{}_{}_{}'.format(
                     ftype, var, year, flavour, ptbinstr, etabinstr)
                 histograms = frt.loadselectedhistograms(
                     inputfile, ftype, var, year, flavour, ptbin,
                     etabin)
                 datahist = histograms['datahist']
                 prompthists = histograms['prompthists']