if nb == maxB:
                nbMax = -1
            regionName = "GJetsInv"+name+"ClosureTest"+str(nb)+"B"
            regionsOrder.append(regionName)
            regions[regionName] = Analysis("GJetsInv",tag=tag,
                    njetsMin=jets[0], njetsMax=jets[1], nbMin=nb,
                    nbMax=nbMax, boostCuts=boostCuts)

    sfHists = macro.loadScaleFactorHists(
            sfFilename="data/ScaleFactors/RazorMADD2015/RazorScaleFactors_%s_Uncorr.root"%(tag), 
            processNames=regions.itervalues().next().samples, debugLevel=debugLevel)
    sfVars = ("MR_NoPho","Rsq_NoPho")
    sfNJetsFile = rt.TFile.Open(
            "data/ScaleFactors/RazorMADD2015/RazorNJetsScaleFactors_%s.root"%(tag))
    sfHists['NJetsInv'] = sfNJetsFile.Get("GJetsInvScaleFactors")
    razorWeights.loadPhotonPurityHists(sfHists, tag, debugLevel)
    for region in regionsOrder:
        analysis = regions[region]
        print "\nRegion:",region,"\n"
        #make output directory
        outdir = 'Plots/'+tag+'/'+region
        os.system('mkdir -p '+outdir)
        #set up analysis
        (xbins,cols) = analysis.unrollBins
        auxSFs = razorWeights.getNJetsSFs(analysis, jetName=analysis.jetVar)
        razorWeights.getPhotonPuritySFs(auxSFs)
        #perform analysis
        hists = makeControlSampleHistsForAnalysis( analysis, plotOpts=plotOpts, sfHists=sfHists,
                sfVars=sfVars, printdir=outdir, auxSFs=auxSFs, btags=analysis.nbMin,
                dataDrivenQCD=True, debugLevel=debugLevel, noFill=args.noFill )
        #compute scale factors
                                           nbMin=nb,
                                           nbMax=nbMax,
                                           boostCuts=boostCuts)

    sfHists = macro.loadScaleFactorHists(
        sfFilename=
        "data/ScaleFactors/RazorMADD2015/RazorScaleFactors_%s_Uncorr.root" %
        (tag),
        processNames=regions.itervalues().next().samples,
        debugLevel=debugLevel)
    sfVars = ("MR_NoPho", "Rsq_NoPho")
    sfNJetsFile = rt.TFile.Open(
        "data/ScaleFactors/RazorMADD2015/RazorNJetsScaleFactors_%s.root" %
        (tag))
    sfHists['NJetsInv'] = sfNJetsFile.Get("GJetsInvScaleFactors")
    razorWeights.loadPhotonPurityHists(sfHists, tag, debugLevel)
    for region in regionsOrder:
        analysis = regions[region]
        print "\nRegion:", region, "\n"
        #make output directory
        outdir = 'Plots/' + tag + '/' + region
        os.system('mkdir -p ' + outdir)
        #set up analysis
        (xbins, cols) = analysis.unrollBins
        auxSFs = razorWeights.getNJetsSFs(analysis, jetName=analysis.jetVar)
        razorWeights.getPhotonPuritySFs(auxSFs)
        #perform analysis
        hists = makeControlSampleHistsForAnalysis(analysis,
                                                  plotOpts=plotOpts,
                                                  sfHists=sfHists,
                                                  sfVars=sfVars,