tag = args.tag noCorr = args.noCorr boostCuts = not args.noBoostCuts #initialize plotOpts = { "comment":False, 'SUS15004CR':True } regions = {} regionsOrder = [] #define all tests jetsOrder = ["Inclusive","OneJet","DiJet","MultiJet"] jetsLimit = [(-1,-1),(1,1),(2,3),(4,-1)] for name,jets in zip(jetsOrder, jetsLimit): regionName = "OneLepton"+name+"ClosureTest" if noCorr: regionName += "_NoCorr" regions[regionName] = Analysis("SingleLepton",tag=tag, njetsMin=jets[0], njetsMax=jets[1], boostCuts=boostCuts) regionsOrder.append(regionName) for nb in range(3): regions[regionName+str(nb)+"B"] = Analysis("SingleLepton",tag=tag, njetsMin=jets[0], njetsMax=jets[1], nbMin=nb, nbMax=nb, boostCuts=boostCuts) regionsOrder.append(regionName+str(nb)+"B") #add 3B test for MultiJet regionName = "OneLeptonMultiJetClosureTest" if noCorr: regionName += "_NoCorr" regions[regionName+"3B"] = Analysis("SingleLepton",tag=tag, njetsMin=4, nbMin=3, nbMax=3, boostCuts=boostCuts) regionsOrder.append(regionName+"3B") sfHists = macro.loadScaleFactorHists(
action="store_true") parser.add_argument("-d", "--debug", help="display excruciatingly detailed output messages", action="store_true") parser.add_argument("--tag", help="Analysis tag, e.g. Razor2015", default="Razor2016") args = parser.parse_args() debugLevel = args.verbose + 2 * args.debug tag = args.tag #initialize plotOpts = {'comment': False, "SUS15004CR": True} regions = { "OneLeptonForNJets": Analysis("SingleLepton", tag=tag), "OneLeptonInvForNJets": Analysis("SingleLeptonInv", tag=tag), "GJetsInvForNJets": Analysis("GJetsInv", tag=tag), } sfVars = { "OneLeptonForNJets": ("MR", "Rsq"), "OneLeptonInvForNJets": { "WJetsInv": ("MR_NoW", "Rsq_NoW"), "TTJets": ("MR", "Rsq") }, "GJetsInvForNJets": ("MR_NoPho", "Rsq_NoPho") } sfHists = { region: macro.loadScaleFactorHists( sfFilename= "data/ScaleFactors/RazorMADD2015/RazorScaleFactors_%s.root" %
parser = make_parser() args = parser.parse_args() debugLevel = args.verbose + 2 * args.debug tag = args.tag boostCuts = not args.noBoostCuts #initialize plotOpts = {'comment': False, "SUS15004CR": True} regions = {} regionsOrder = [] #define all tests for name, jets in {"DiJet": (2, 3), "MultiJet": (4, -1)}.iteritems(): regionName = "GJetsInv" + name + "ClosureTest" regions[regionName] = Analysis("GJetsInv", tag=tag, njetsMin=jets[0], njetsMax=jets[1], boostCuts=boostCuts) regionsOrder.append(regionName) maxB = 3 if name == 'DiJet': maxB = 2 for nb in range(maxB + 1): nbMax = nb if nb == maxB: nbMax = -1 regionName = "GJetsInv" + name + "ClosureTest" + str(nb) + "B" regionsOrder.append(regionName) regions[regionName] = Analysis("GJetsInv", tag=tag, njetsMin=jets[0],
if __name__ == "__main__": rt.gROOT.SetBatch() parser = make_parser() args = parser.parse_args() debugLevel = args.verbose + 2 * args.debug tag = args.tag boostCuts = not args.noBoostCuts #initialize plotOpts = {"comment": False, 'SUS15004CR': True} regionsOrder = ["DYJetsDileptonInvBCheck"] regions = { "DYJetsDileptonInvBCheck": Analysis("DYJetsDileptonInv", tag=tag, boostCuts=boostCuts) } sfFilename = "data/ScaleFactors/RazorMADD2015/RazorScaleFactors_%s.root" % ( tag) sfHists = macro.loadScaleFactorHists( sfFilename=sfFilename, processNames=regions["DYJetsDileptonInvBCheck"].samples, scaleFactorNames={"DYJetsInv": "GJetsInv"}, debugLevel=debugLevel) sfNJetsFile = rt.TFile.Open( "data/ScaleFactors/RazorMADD2015/RazorNJetsScaleFactors_%s.root" % (tag)) for d in [sfHists]: d['NJetsTTJets'] = sfNJetsFile.Get("TTJetsScaleFactors") d['NJetsWJets'] = sfNJetsFile.Get("WJetsScaleFactors") d['NJetsInv'] = sfNJetsFile.Get("GJetsInvScaleFactors")
dphiHists["VetoTauEta"] = dphiTauFile.Get("VetoTauDPhiCutEfficiencyVsEta") #initialize plotOpts = {"comment": False, 'SUS15004CR': True} regionsOrder = [] regions = {} regionsCorrespondence = { } #get the control region corresponding to each signal region regionMtHists = {} regionDphiHists = {} for ltype in ["VetoLepton", "VetoTau"]: for jtype, jets in {"DiJet": (2, 3), "MultiJet": (4, -1)}.iteritems(): #veto lepton/tau control region regionsOrder.append(ltype + jtype) regions[ltype + jtype] = Analysis(ltype + "ControlRegion", tag=tag, njetsMin=jets[0], njetsMax=jets[1]) #corresponding signal region sigR = jtype + "For" + ltype regionsOrder.append(sigR) regions[jtype + "For" + ltype] = Analysis(sigR + "ControlRegion", tag=tag, njetsMin=jets[0], njetsMax=jets[1]) regionsCorrespondence[sigR] = ltype + jtype regionMtHists[sigR] = mtHists[ltype + "Pt"] regionDphiHists[sigR] = dphiHists[ltype + "Pt"] #veto lepton/tau control region regionsOrder.append(ltype + jtype + "PtCorr") regions[ltype + jtype + "PtCorr"] = Analysis(ltype + "ControlRegion",
dest='njets80Cut') args = parser.parse_args() debugLevel = args.verbose + 2 * args.debug tag = args.tag #initialize sfHists = {} plotOpts = {'comment': False, "SUS15004CR": True} regionsOrder = [ "TTJetsSingleLepton", "WJetsSingleLepton", "WJetsSingleLeptonInv" ] if tag != "Razor2015": regionsOrder.insert(0, "GJetsInv") regions = { "TTJetsSingleLepton": Analysis("TTJetsSingleLepton", tag=tag, nbMin=1), "WJetsSingleLepton": Analysis("WJetsSingleLepton", tag=tag, nbMax=0), "WJetsSingleLeptonInv": Analysis("WJetsSingleLeptonInv", tag=tag, nbMax=0), "GJetsInv": Analysis("GJetsInv", tag=tag) } for region in regionsOrder: analysis = regions[region] process = region.replace('SingleLepton', '') (xbins, cols) = analysis.unrollBins #make output directory outdir = 'Plots/' + tag + '/' + region if args.noSave: outdir += '_Test'
parser = make_parser() args = parser.parse_args() debugLevel = args.verbose + 2*args.debug tag = args.tag boostCuts = not args.noBoostCuts #initialize plotOpts = { "comment":False, 'SUS15004CR':True } regionsOrder = [ "TTJetsDileptonSevenJet", "TTJetsDileptonMultiJet", "TTJetsDileptonDiJet"] regions = { "TTJetsDileptonDiJet":Analysis( "TTJetsDilepton",tag=tag,njetsMin=2,njetsMax=3, boostCuts=boostCuts), "TTJetsDileptonMultiJet":Analysis( "TTJetsDileptonMultiJet",tag=tag,njetsMin=4,njetsMax=6, boostCuts=boostCuts), "TTJetsDileptonSevenJet":Analysis( "TTJetsDileptonMultiJet",tag=tag,njetsMin=7, boostCuts=boostCuts), } sfFilename="data/ScaleFactors/RazorMADD2015/RazorScaleFactors_%s.root"%(tag) sfHists = macro.loadScaleFactorHists( sfFilename=sfFilename, processNames=regions["TTJetsDileptonSevenJet"].samples, debugLevel=debugLevel ) sfNJetsFile = rt.TFile.Open( "data/ScaleFactors/RazorMADD2015/RazorNJetsScaleFactors_%s.root"%(tag)) sfHists['NJetsTTJets'] = sfNJetsFile.Get("TTJetsScaleFactors") sfHists['NJetsWJets'] = sfNJetsFile.Get("WJetsScaleFactors")
print "Please choose an analysis box with --box" exit() box = args.box boxList = box.split('_') # list of boxes to combine, separated by _ # make output directory os.system('mkdir -p '+outDir) for curBox in boxList: btagsMax = getMaxBtags(curBox) # retrieve binning and other info analyses = [] unrollBins = [] for nb in range(btagsMax + 1): analyses.append(Analysis(curBox, args.tag, nbMin=nb)) unrollBins.append(analyses[-1].unrollBins) lumi = analyses[0].lumi sfNames = { "TTJets1L":"TTJets", "TTJets2L":"TTJets", "ZInv":"GJetsInv" } sfHists = macro.loadScaleFactorHists( "data/ScaleFactors/RazorMADD2015/RazorScaleFactors_%s.root"%(args.tag), processNames=["TTJets1L","TTJets2L","WJets","ZInv"], scaleFactorNames=sfNames, debugLevel=debugLevel) sfFileNameBClosure = 'data/ScaleFactors/RazorMADD2015/RazorBTagScaleFactors_%s.root'%(args.tag) sfFileBClosure = rt.TFile.Open(sfFileNameBClosure) sfHistsForUncorrSFs1D = {} sfHistsForUncorrSFs1DMR = {} jets = 'MultiJet' if curBox in ['DiJet', 'LeptonJet']: jets = 'DiJet'
#and the second pass will be a rerun with the corrected normalization if closure: regionsOrder = [ "DYJetsDileptonInv", "DYJetsDileptonInvDiJet", "DYJetsDileptonInvMultiJet" ] else: regionsOrder = [ "DYJetsDileptonInvUncorr", "DYJetsDileptonInv", "DYJetsDileptonInvDiJet", "DYJetsDileptonInvMultiJet", "DYJetsDileptonInvDiJetWJetsCorr", "DYJetsDileptonInvMultiJetWJetsCorr", "DYJetsDileptonInvNoSFs" ] regions = { "DYJetsDileptonInvUncorr": Analysis("DYJetsDileptonInv", tag=tag), "DYJetsDileptonInv": Analysis("DYJetsDileptonInv", tag=tag), "DYJetsDileptonInvDiJet": Analysis("DYJetsDileptonInv", tag=tag, njetsMin=2, njetsMax=3), "DYJetsDileptonInvMultiJet": Analysis("DYJetsDileptonInvMultiJet", tag=tag, njetsMin=4), "DYJetsDileptonInvDiJetWJetsCorr": Analysis("DYJetsDileptonInv", tag=tag, njetsMin=2, njetsMax=3), "DYJetsDileptonInvMultiJetWJetsCorr": Analysis("DYJetsDileptonInvMultiJet", tag=tag, njetsMin=4), "DYJetsDileptonInvNoSFs": Analysis("DYJetsDileptonInv", tag=tag), } sfFilename = "data/ScaleFactors/RazorMADD2015/RazorScaleFactors_%s.root" % ( tag)
debugLevel = args.verbose + 2 * args.debug tag = args.tag boostCuts = not args.noBoostCuts plotOpts = {"comment": False, 'SUS15004CR': True} wjetsRegionNames = [ "WJetsSingleLeptonInvNLO", "WJetsSingleLeptonInvNLOForNJets" ] dyjetsRegionNames = [ "DYJetsDileptonInvNLO", "DYJetsDileptonInvNLODiJet", "DYJetsDileptonInvNLOMultiJet" ] regionsOrder = wjetsRegionNames + dyjetsRegionNames regions = { "WJetsSingleLeptonInvNLO": Analysis("WJetsSingleLeptonInv", nbMax=0, tag=tag, boostCuts=boostCuts), "WJetsSingleLeptonInvNLOForNJets": Analysis("WJetsSingleLeptonInv", nbMax=0, tag=tag, boostCuts=boostCuts), "DYJetsDileptonInvNLO": Analysis("DYJetsDileptonInv", tag=tag, boostCuts=boostCuts), "DYJetsDileptonInvNLODiJet": Analysis("DYJetsDileptonInv", tag=tag, njetsMin=2, njetsMax=3, boostCuts=boostCuts), "DYJetsDileptonInvNLOMultiJet": Analysis("DYJetsDileptonInvMultiJet", tag=tag, njetsMin=4,
dest="tag", default="Razor2016", help="Analysis tag, e.g. Razor2015") args = parser.parse_args() debugLevel = args.verbose + 2 * args.debug tag = args.tag #initialize plotOpts = {'comment': False, "SUS15004CR": True} regions = {} regionsOrder = [] #define all tests for name, jets in {"DiJet": (2, 3), "MultiJet": (4, -1)}.iteritems(): regionName = "GJetsInv" + name + "ClosureTest" regions[regionName] = Analysis("GJetsInv", tag=tag, njetsMin=jets[0], njetsMax=jets[1]) regionsOrder.append(regionName) maxB = 3 if name == 'DiJet': maxB = 2 for nb in range(maxB + 1): nbMax = nb 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],
dest='njets80Cut') args = parser.parse_args() debugLevel = args.verbose + 2 * args.debug tag = args.tag boostCuts = not args.noBoostCuts #initialize sfHists = {} regionsOrder = [ "TTJetsSingleLepton", "WJetsSingleLepton", "WJetsSingleLeptonInv" ] if tag != "Razor2015": regionsOrder.insert(0, "GJetsInv") regions = { "TTJetsSingleLepton": Analysis("TTJetsSingleLepton", tag=tag, nbMin=1, boostCuts=boostCuts), "WJetsSingleLepton": Analysis("WJetsSingleLepton", tag=tag, nbMax=0, boostCuts=boostCuts), "WJetsSingleLeptonInv": Analysis("WJetsSingleLeptonInv", tag=tag, nbMax=0, boostCuts=boostCuts), "GJetsInv": Analysis("GJetsInv", tag=tag, boostCuts=boostCuts) } for region in regionsOrder: analysis = regions[region] process = region.replace('SingleLepton', '') (xbins, cols) = analysis.unrollBins plotOpts = { 'comment': False,
elif btags >= 2: nbMax = -1 #no upper limit else: nbMax = btags #exclusive else: if btags >= 3: nbMax = -1 #no upper limit else: nbMax = btags #exclusive if args.bInclusive: nbMin = 0 nbMax = -1 #define analysis region extBox = '%s%dB%s' % (box, btags, dirSuffix) regionsOrder.append(extBox) regions[extBox] = Analysis(box, tag=tag, nbMin=btags, nbMax=nbMax) ####LOAD ALL SCALE FACTOR HISTOGRAMS #scale factor file names sfdir = "data/ScaleFactors/RazorMADD2015/" sfFile = sfdir + '/RazorScaleFactors_%s.root' % (tag) sfFile_nJets = sfdir + '/RazorNJetsScaleFactors_%s.root' % (tag) vetolepFile = sfdir + '/RazorVetoLeptonClosureTests_%s.root' % (tag) ttFile = sfdir + '/RazorTTJetsDileptonCrossCheck_%s.root' % (tag) dyFile = sfdir + '/RazorDYJetsDileptonInvCrossCheck_%s.root' % (tag) btagFile = sfdir + '/RazorBTagClosureTests_%s.root' % (tag) gjetsbtagFile = sfdir + '/RazorGJetsBTagClosureTests_%s.root' % (tag) #get MR-Rsq scale factor histograms sfNames = {
def checkSignalContamination(config, outDir, lumi, box, model, mLSP, mGluino=-1, mStop=-1, mergeBins=False, debugLevel=0, treeName="RazorInclusive", tag='Razor2016_MoriondRereco'): cfg = Config.Config(config) x = array('d', cfg.getBinning(box)[0]) # MR binning y = array('d', cfg.getBinning(box)[1]) # Rsq binning z = array('d', cfg.getBinning(box)[2]) # nBtag binning dirToUse = razorSignalDirs[tag] unrollBins = [] analyses = [] if mergeBins: btagBins = cfg.getBinning(box)[2][:-1] for btags in btagBins: analyses.append(Analysis(box, tag, nbMin=btags)) unrollBins.append(analyses[-1].unrollBins) xBR = yBR = -1 if 'T1x' in model: xBR, yBR = getBranchingFracsFromModelName(model) fileName = dirToUse + '/SMS-T1ttbb_%i_%i.root' % (mGluino, mLSP) elif 'T2' in model: modelName = getModelName(model, mStop, mLSP) fileName = dirToUse + '/%s.root' % (modelName) else: modelName = getModelName(model, mGluino, mLSP) fileName = dirToUse + '/%s.root' % (modelName) smsOpts = SMSOpts(xBR=xBR, yBR=yBR, doNPVExtrap=False, doGenMetVsPFMet=False) sigTH1 = makeSMSTemplates(box, fileName, opts=smsOpts, debugLevel=debugLevel, tag=tag)['Signal'] bkgdHistDict = importHists('%s/controlHistograms%s.root' % (BACKGROUND_DIR, box)) tempTH2 = bkgdHistDict['Data'][('MR', 'Rsq')] #unroll into TH1F if unrollBins is None: nBins = (len(x) - 1) * (len(y) - 1) maxBins = nBins myTH1 = rt.TH1F(treeName, treeName, maxBins, 0, maxBins) myTH1.SetDirectory(0) #prevent it from going out of scope myTH1.Sumw2() i = 0 for ix in range(1, len(x)): for iy in range(1, len(y)): i += 1 myTH1.SetBinContent(i, tempTH2.GetBinContent(ix, iy)) myTH1.SetBinError(i, tempTH2.GetBinError(ix, iy)) else: print "Merging bins according to custom (MR-dependent) binning" layers = [] #turn it into a TH2Poly with the reduced binning unrollRows = unrollBins[0][0] unrollCols = unrollBins[0][1] poly = makeTH2PolyFromColumns(tempTH2.GetName() + "poly", 'poly', unrollRows, unrollCols) fillTH2PolyFromTH2(tempTH2, poly) numbins = poly.GetNumberOfBins() unrolledSlice = rt.TH1D(tempTH2.GetName() + "Unroll", "slice", numbins, 0, numbins) for bn in range(1, numbins + 1): unrolledSlice.SetBinContent(bn, poly.GetBinContent(bn)) unrolledSlice.SetBinError(bn, poly.GetBinError(bn)) layers.append(unrolledSlice) poly.Delete() myTH1 = stitch(layers) myTH1.SetName(treeName) myTH1.SetTitle(treeName) sigTH1.Sumw2() myTH1.Sumw2() sigTH1.Divide(myTH1) return sigTH1
def makeSMSTemplates(box, inFile, uncertainties=[], debugLevel=0, tag="Razor2016_MoriondRereco", opts=None, boostCuts=True, doUncorrelate=True): """Returns a dictionary of histograms representing predicted yields for the indicated signal sample. 'opts' should be an SMSOpts instance containing desired values for configurable parameters.""" print '\nInput file is %s' % inFile uncerts = copy.copy(uncertainties) # process configuration options if opts is None: opts = SMSOpts() xBR = opts.xBR yBR = opts.yBR doMCStat = True if opts.doNPVExtrap: uncerts.append('npvextrap') doMCStat = False if opts.doGenMetVsPFMet: uncerts.append('genmetvspfmet') # get mass point information model, m1, m2 = getModelInfoFromFilename(inFile, xBR, yBR) isGluinos = ("T1" in model or "T5" in model) if isGluinos: thyXsec, _ = getTheoryCrossSectionAndError( mGluino=m1) else: thyXsec, _ = getTheoryCrossSectionAndError( mStop=m1) print "\n--- %s %s %s ---\n"%(model, m1, m2) print "Theory cross section: %.3f pb"%thyXsec minBtags = 0 maxBtags = getMaxBtags(box) # special case: 1L control regions if box == "TTJetsSingleLeptonForSignal": minBtags = maxBtags = 1 elif box == "WJetsSingleLeptonForSignal": minBtags = maxBtags = 0 hists = [] unrollBins = [] for nb in range(minBtags, maxBtags+1): # get analysis info nbMax = nb if nb == maxBtags: nbMax = -1 # special case: 1L control regions if box == "WJetsSingleLeptonForSignal": nbMax = 0 analysis = Analysis(box, tag, nbMin=nb, nbMax=nbMax, boostCuts=boostCuts) unrollBins.append(analysis.unrollBins) # modify for signal sample analysis.filenames = { 'Signal':inFile } analysis.samples = ['Signal'] analysis.samplesReduced = analysis.samples # scale according to cross section f = rt.TFile.Open(inFile) nEvents = f.Get('NEvents').Integral() globalScaleFactor = thyXsec/nEvents nisrFactor = getGlobalNISRScaleFactor(f) globalScaleFactor *= nisrFactor print "Number of events: %d"%nEvents print "Integrated luminosity: %d /pb"%analysis.lumi print "Overall NISR scale factor: {}".format(nisrFactor) print "Overall scale factor: %.3f"%( analysis.lumi * globalScaleFactor) # fill the histograms hists.append(makeControlSampleHistsForAnalysis(analysis, treeName="RazorInclusive", shapeErrors=uncerts, boxName=box, btags=nb, makePlots=False, exportShapeErrs=True, propagateScaleFactorErrs=False, lumiMC=1./globalScaleFactor, debugLevel=debugLevel)) makeRazor2DTable(pred=None, boxName='{}-{}-{}-{}-'.format(box, model, m1, m2), mcNames=['{} {} {}'.format(model, m1, m2)], mcHists=[hists[-1]['Signal'][('MR','Rsq')]], btags=nb, unrollBins=unrollBins[-1], listAllMC=True) signalHists = unrollAndStitch(hists, box, samples=analysis.samples, debugLevel=debugLevel, unrollBins=unrollBins, addStatUnc=doMCStat) # apply pileup weight extrapolation procedure if 'Signal_npvextrapUp' in signalHists: npvLowHighHist = getNPVLowHighHist(analysis) npvHist = getNPVHist(tag) doNPVExtrapolation(signalHists, npvHist, npvLowHighHist, scale=analysis.lumi*globalScaleFactor) # need this extrapolation to be uncorrelated across bins & boxes for sysName in ['Signal_npvextrapUp', 'Signal_npvextrapDown']: signalHists[sysName.replace( 'npvextrap','npvextrap'+box)] = signalHists[sysName] del signalHists[sysName] if doUncorrelate: uncorrelate(signalHists, 'npvextrap'+box, suppressLevel=0.1) # apply gen-MET vs PF MET systematic if 'Signal_genmetvspfmetUp' in signalHists: doGenMetVsPFMetSystematic(signalHists) return signalHists
#parse args parser = sig.makeSignalRegionParser() parser.add_argument("--dir", help="Specify input/output directory") args = parser.parse_args() debugLevel = args.verbose + 2 * args.debug tag = args.tag box = args.box btags = args.btags dirName = 'Plots/%s/%s%dB' % (tag, box, btags) + sig.getDirSuffix(args) if 'Blinded' in dirName: # allow making blinded plots even when histograms # were filled with unblind option dirName = dirName.replace('Blinded', '') analysis = Analysis(box, tag=tag, nbMin=btags, nbMax=btags) sig.applyAnalysisOptions(analysis, args, box) plotOpts = sig.getPlotOpts(args, analysis) blindBins = [(x, y) for x in range(1, len(analysis.binning["MR"]) + 1) for y in range(1, len(analysis.binning["Rsq"]) + 1)] if args.unblind: blindBins = None shapesToUse = copy.copy(sig.shapes[box]) shapesToUse = adjustShapes(analysis, shapesToUse) if args.noSFs: print "Ignoring all uncertainties from scale factor cross checks." sig.removeSFShapes(shapesToUse)
parser.add_argument("--tag", dest="tag", default="Razor2016", help="Analysis tag, e.g. Razor2015") args = parser.parse_args() debugLevel = args.verbose + 2 * args.debug tag = args.tag #initialize plotOpts = {"comment": False, 'SUS15004CR': True} regionsOrder = [ "TTJetsDilepton", "TTJetsDileptonMultiJet", "TTJetsDileptonDiJet" ] regions = { "TTJetsDilepton": Analysis("TTJetsDilepton", tag=tag), "TTJetsDileptonDiJet": Analysis("TTJetsDilepton", tag=tag, njetsMin=2, njetsMax=3), "TTJetsDileptonMultiJet": Analysis("TTJetsDileptonMultiJet", tag=tag, njetsMin=4), } sfFilename = "data/ScaleFactors/RazorMADD2015/RazorScaleFactors_%s.root" % ( tag) sfHists = macro.loadScaleFactorHists( sfFilename=sfFilename, processNames=regions["TTJetsDilepton"].samples, debugLevel=debugLevel) sfNJetsFile = rt.TFile.Open( "data/ScaleFactors/RazorMADD2015/RazorNJetsScaleFactors_%s.root" % (tag)) sfHists['NJetsTTJets'] = sfNJetsFile.Get("TTJetsScaleFactors")
def convertTree2Dataset(tree, cfg, box, workspace, useWeight, globalScaleFactor, treeName='RMRTree', isData=False, tag="Razor2016_MoriondRereco"): """This defines the format of the RooDataSet""" z = array('d', cfg.getBinning(box)[2]) # nBtag binning args = workspace.set("variables") data = rt.RooDataSet(treeName, 'Selected R and MR', args) btagCutoff = 3 if box in ["MuEle", "MuMu", "EleEle"]: btagCutoff = 1 elif box in [ "DiJet", "LeptonJet", "EleJet", "MuJet", "DiJet_2b", "LeptonJet_2b" ]: btagCutoff = 2 # Use the Analysis object to store cuts # to keep synchronized with the MADD analysis analysis = Analysis(box, tag=tag) if isData: cuts = analysis.cutsData else: cuts = analysis.cutsMC print "Cuts:", cuts tree.Draw('>>elist', cuts, 'entrylist') elist = rt.gDirectory.Get('elist') entry = -1 while True: entry = elist.Next() if entry == -1: break tree.GetEntry(entry) #set the RooArgSet and save a = rt.RooArgSet(args) a.setRealValue('MR', tree.MR) a.setRealValue('Rsq', tree.Rsq) a.setRealValue('nBtag', min(tree.nBTaggedJets, btagCutoff)) if useWeight: a.setRealValue('W', tree.weight * globalScaleFactor) else: a.setRealValue('W', 1.0) data.add(a) numEntries = data.numEntries() wdata = rt.RooDataSet(data.GetName(), data.GetTitle(), data, data.get(), "MR>=0.", "W") numEntriesByBtag = [] sumEntriesByBtag = [] for i in z[:-1]: numEntriesByBtag.append(wdata.reduce('nBtag==%i' % i).numEntries()) sumEntriesByBtag.append(wdata.reduce('nBtag==%i' % i).sumEntries()) print "Number of Entries [ %s ] =" % (box), numEntriesByBtag print "Sum of Weights [ %s ] =" % (box), sumEntriesByBtag return wdata