def getHistogram(path,plot,runRange,background): treesEE = readTrees(path,"EE") treesMM = readTrees(path,"MuMu") if "NLL" in path: plot.cuts = plot.cuts.replace(" && metFilterSummary > 0", "") eeSF = getTriggerScaleFactor("EE", "Inclusive", runRange)[0] mmSF = getTriggerScaleFactor("EE", "Inclusive", runRange)[0] eventCounts = totalNumberOfGeneratedEvents(path) proc = Process(getattr(Backgrounds[runRange.era],background),eventCounts) histSF = proc.createCombinedHistogram(runRange.lumi,plot,treesEE,treesMM, 1.0, eeSF, mmSF) return histSF
def getHistograms(path, plot, runRange, isMC, backgrounds, EM=False): treesEE = readTrees(path, "EE") treesEM = readTrees(path, "EMu") treesMM = readTrees(path, "MuMu") if isMC: eventCounts = totalNumberOfGeneratedEvents(path) processes = [] for background in backgrounds: processes.append( Process(getattr(Backgrounds, background), eventCounts)) histoEE = TheStack(processes, runRange.lumi, plot, treesEE, "None", 1.0, 1.0, 1.0).theHistogram histoMM = TheStack(processes, runRange.lumi, plot, treesMM, "None", 1.0, 1.0, 1.0).theHistogram if EM: histoEM = TheStack(processes, runRange.lumi, plot, treesEM, "None", 1.0, 1.0, 1.0).theHistogram else: histoEE = getDataHist(plot, treesEE) histoMM = getDataHist(plot, treesMM) if EM: histoEM = getDataHist(plot, treesEM) if EM: return histoEE, histoMM, histoEM else: return histoEE, histoMM
def getHistogram(plot,runRange,backgrounds,region): path = locations[runRange.era].dataSetPath treesEE = readTrees(path,"EE") treesEM = readTrees(path,"EMu") treesMM = readTrees(path,"MuMu") eventCounts = totalNumberOfGeneratedEvents(path) processes = [] for background in backgrounds: processes.append(Process(getattr(Backgrounds[runRange.era],background),eventCounts)) triggerSF_EE,_ = getTriggerScaleFactor("EE", region, runRange) triggerSF_MM,_ = getTriggerScaleFactor("MuMu", region, runRange) triggerSF_EM,_ = getTriggerScaleFactor("EMu", region, runRange) histoEE = TheStack(processes,runRange.lumi,plot,treesEE,"None",1.0,triggerSF_EE,1.0,useTriggerEmulation=True).theHistogram histoMM = TheStack(processes,runRange.lumi,plot,treesMM,"None",1.0,triggerSF_MM,1.0,useTriggerEmulation=True).theHistogram histoEM = TheStack(processes,runRange.lumi,plot,treesEM,"None",1.0,triggerSF_EM,1.0,useTriggerEmulation=True).theHistogram histSF = histoEE.Clone() histSF.Add(histoMM.Clone(), 1) histSF.Add(histoEM.Clone(), -1) return histSF
def getHistogram(path, plot, plot2, runRange, background): treesEE = readTrees(path, "EE") treesEM = readTrees(path, "EMu") treesMM = readTrees(path, "MuMu") eventCounts = totalNumberOfGeneratedEvents(path) proc = Process(getattr(Backgrounds[runRange.era], background), eventCounts) histSF = proc.createCombined2DHistogram(runRange.lumi, plot, plot2, treesEE, treesMM) # histoEE = TheStack(processes,runRange.lumi,plot,treesEE,"None",1.0,1.0,1.0, useTriggerEmulation=True).theHistogram # histoMM = TheStack(processes,runRange.lumi,plot,treesMM,"None",1.0,1.0,1.0, useTriggerEmulation=True).theHistogram return histSF
def getHistograms(path, plot, runRange, isMC, backgrounds, region=""): treesEE = readTrees(path, "EE") treesEM = readTrees(path, "EMu") treesMM = readTrees(path, "MuMu") if isMC: eventCounts = totalNumberOfGeneratedEvents(path) processes = [] for background in backgrounds: processes.append( Process(getattr(Backgrounds, background), eventCounts)) histoEE = TheStack(processes, runRange.lumi, plot, treesEE, "None", 1.0, 1.0, 1.0).theHistogram histoMM = TheStack(processes, runRange.lumi, plot, treesMM, "None", 1.0, 1.0, 1.0).theHistogram histoEM = TheStack(processes, runRange.lumi, plot, treesEM, "None", 1.0, 1.0, 1.0).theHistogram histoEE.Scale(getattr(triggerEffs, region).effEE.val) histoEE.Scale(getattr(triggerEffs, region).effMM.val) histoEM.Scale(getattr(triggerEffs, region).effEM.val) else: histoEE = getDataHist(plot, treesEE) histoMM = getDataHist(plot, treesMM) histoEM = getDataHist(plot, treesEM) return histoEE, histoMM, histoEM
def getHistograms(path,source,modifier,plot,runRange,isMC,backgrounds,region=""): treesEE = readTrees(path,"EE",source = source,modifier= modifier) treesEM = readTrees(path,"EMu",source = source,modifier= modifier) treesMM = readTrees(path,"MuMu",source = source,modifier= modifier) histosEE = [] histosMM = [] histosEM = [] #~ print path, source, modifier eventCounts = totalNumberOfGeneratedEvents(path,source,modifier) processes = [] for background in backgrounds: processes = [] processes.append(Process(getattr(Backgrounds,background),eventCounts)) histosEE.append(TheStack(processes,runRange.lumi,plot,treesEE,"None",1.0,1.0,1.0).theHistogram) histosMM.append(TheStack(processes,runRange.lumi,plot,treesMM,"None",1.0,1.0,1.0).theHistogram) histosEM.append(TheStack(processes,runRange.lumi,plot,treesEM,"None",1.0,1.0,1.0).theHistogram) return histosEE , histosMM, histosEM
def getHistograms(path, source, modifier, plot, runRange, isMC, nonNormalized, backgrounds, region=""): treesEE = readTrees(path, "EE", source=source, modifier=modifier) treesEM = readTrees(path, "EMu", source=source, modifier=modifier) treesMM = readTrees(path, "MuMu", source=source, modifier=modifier) if isMC: #~ print path, source, modifier eventCounts = totalNumberOfGeneratedEvents(path, source, modifier) processes = [] for background in backgrounds: if nonNormalized: processes.append( Process(getattr(Backgrounds, background), eventCounts, normalized=False)) else: processes.append( Process(getattr(Backgrounds, background), eventCounts)) histoEE = TheStack(processes, runRange.lumi, plot, treesEE, "None", 1.0, 1.0, 1.0).theHistogram histoMM = TheStack(processes, runRange.lumi, plot, treesMM, "None", 1.0, 1.0, 1.0).theHistogram histoEM = TheStack(processes, runRange.lumi, plot, treesEM, "None", 1.0, 1.0, 1.0).theHistogram histoEE.Scale(getattr(triggerEffs, region).effEE.val) histoEE.Scale(getattr(triggerEffs, region).effMM.val) histoEM.Scale(getattr(triggerEffs, region).effEM.val) else: histoEE = getDataHist(plot, treesEE) histoMM = getDataHist(plot, treesMM) histoEM = getDataHist(plot, treesEM) return histoEE, histoMM, histoEM
def getCounts(trees, cut, isMC, backgrounds,plot,runRange,baseTreePath): if isMC: tmpCut = plot.cuts plot.cuts = cut source = "" modifier = "" eventCounts = totalNumberOfGeneratedEvents(baseTreePath,source,modifier) processes = [] for background in backgrounds: processes.append(Process(getattr(Backgrounds,background),eventCounts)) histEE = TheStack(processes,runRange.lumi,plot,trees["EE"],"None",1.0,1.0,1.0).theHistogram histMM = TheStack(processes,runRange.lumi,plot,trees["MM"],"None",1.0,1.0,1.0).theHistogram histEM = TheStack(processes,runRange.lumi,plot,trees["EM"],"None",1.0,1.0,1.0).theHistogram #~ histoEE.Scale(getattr(triggerEffs,region).effEE.val) #~ histoEE.Scale(getattr(triggerEffs,region).effMM.val) #~ histoEM.Scale(getattr(triggerEffs,region).effEM.val) eeErr = ROOT.Double() ee = histEE.IntegralAndError(1,histEE.GetNbinsX(),eeErr) mmErr = ROOT.Double() mm = histMM.IntegralAndError(1,histMM.GetNbinsX(),mmErr) emErr = ROOT.Double() em = histEM.IntegralAndError(1,histEM.GetNbinsX(),emErr) n= { "MM": ee, "EE": mm, "EM": em, } n["MMStatErr"] = float(eeErr) n["EEStatErr"] = float(mmErr) n["EMStatErr"] = float(emErr) plot.cuts = tmpCut else: n= { "MM": trees["MM"].GetEntries(cut), "EE": trees["EE"].GetEntries(cut), "EM": trees["EM"].GetEntries(cut), } n["MMStatErr"] = n["MM"]**0.5 n["EEStatErr"] = n["EE"]**0.5 n["EMStatErr"] = n["EM"]**0.5 #~ print cut, n n["cut"] = cut return n
def getHistograms(path,plot,runRange,backgrounds): treesEE = readTrees(path,"EE") treesEM = readTrees(path,"EMu") treesMM = readTrees(path,"MuMu") eventCounts = totalNumberOfGeneratedEvents(path) processes = [] for background in backgrounds: processes.append(Process(getattr(Backgrounds[runRange.era],background),eventCounts)) histoEE = TheStack(processes,runRange.lumi,plot,treesEE,"None",1.0,1.0,1.0).theHistogram histoMM = TheStack(processes,runRange.lumi,plot,treesMM,"None",1.0,1.0,1.0).theHistogram return histoEE , histoMM
def getHistograms(path,plot,runRange,backgrounds): treesEE = readTrees(path,"EE") treesEM = readTrees(path,"EMu") treesMM = readTrees(path,"MuMu") eventCounts = totalNumberOfGeneratedEvents(path) processes = [] for background in backgrounds: processes.append(Process(getattr(Backgrounds[runRange.era],background),eventCounts)) tmpC = plot.cuts plot.cuts = plot.cuts.replace("pt > 25 &&", "pt > 25 && miniIsoEffArea1 < 0.1 && miniIsoEffArea2 < 0.1 &&") histoEE = TheStack(processes,runRange.lumi,plot,treesEE,"None",1.0,1.0,1.0).theHistogram plot.cuts = tmpC plot.cuts = plot.cuts.replace("pt > 25 &&", "pt > 25 && miniIsoEffArea1 < 0.2 && miniIsoEffArea2 < 0.2 &&") histoMM = TheStack(processes,runRange.lumi,plot,treesMM,"None",1.0,1.0,1.0).theHistogram return histoEE , histoMM
def getHistograms(path, plot, runRange, isMC, backgrounds): treesEE = readTrees(path, "EE") treesEM = readTrees(path, "EMu") treesMM = readTrees(path, "MuMu") if "NLL" in path: isNLL = True plot.cuts = plot.cuts.replace(" && metFilterSummary > 0", "") if isMC: eventCounts = totalNumberOfGeneratedEvents(path) processes = [] for background in backgrounds: processes.append( Process(getattr(Backgrounds[runRange.era], background), eventCounts)) histoEE = TheStack(processes, runRange.lumi, plot, treesEE, "None", 1.0, 1.0, 1.0, useTriggerEmulation=(not isNLL)).theHistogram histoMM = TheStack(processes, runRange.lumi, plot, treesMM, "None", 1.0, 1.0, 1.0, useTriggerEmulation=(not isNLL)).theHistogram else: histoEE = getDataHist(plot, treesEE) histoMM = getDataHist(plot, treesMM) return histoEE, histoMM
def getCounts(trees, cut, isMC, backgrounds, plot, runRange, path, blind=False): rMuEPars = corrections[runRange.era].rMuELeptonPt.inclusive corrMap = {} corrMapUp = {} corrMapDn = {} if isMC: corrMap["offset"] = rMuEPars.ptOffsetMC corrMap["falling"] = rMuEPars.ptFallingMC corrMap["etaParabolaBase"] = rMuEPars.etaParabolaBaseMC corrMap["etaParabolaMinus"] = rMuEPars.etaParabolaMinusMC corrMap["etaParabolaPlus"] = rMuEPars.etaParabolaPlusMC corrMap["norm"] = rMuEPars.normMC else: corrMap["offset"] = rMuEPars.ptOffset corrMap["falling"] = rMuEPars.ptFalling corrMap["etaParabolaBase"] = rMuEPars.etaParabolaBase corrMap["etaParabolaMinus"] = rMuEPars.etaParabolaMinus corrMap["etaParabolaPlus"] = rMuEPars.etaParabolaPlus corrMap["norm"] = rMuEPars.norm rMuEDummy = "({norm:.3f}*( ({offset:.3f} + {falling:.3f}/{pt})*({etaParabolaBase} + ({eta}<-1.6)*{etaParabolaMinus:.3f}*pow({eta}+1.6, 2)+({eta}>1.6)*{etaParabolaPlus:.3f}*pow({eta}-1.6,2) )))" rMuE_El = rMuEDummy.format(pt="pt1", eta="eta1", **corrMap) rMuE_Mu = rMuEDummy.format(pt="pt2", eta="eta2", **corrMap) rMuEWeight = "(0.5*(%s + pow(%s, -1)))" % (rMuE_El, rMuE_Mu) rMuEWeight_EE = "(0.5*pow(%s, -1))" % (rMuE_Mu) rMuEWeight_MM = "(0.5*(%s))" % (rMuE_El) variationUpFlat = "(1 + 0.05)" # variationDnFlat = "(1 - 0.05)" # variationUpPt = "(1 + 0.05*max(110.0 - {pt},0)/90.0)" # variationDnPt = "(1 - 0.05*max(110.0 - {pt},0)/90.0)" # variationUpEta = "(1 + 0.05*abs(max({eta}-1.2,0))/1.2 )" # variationDnEta = "(1 - 0.05*abs(max({eta}-1.2,0))/1.2 )" # # Flat uncertainty rMuE_ElUpFlat = "(%s*%s)" % (rMuE_El, variationUpFlat) rMuE_MuUpFlat = "(%s*%s)" % (rMuE_Mu, variationUpFlat) rMuEWeightUpFlat = "(0.5*(%s + pow(%s, -1)))" % (rMuE_ElUpFlat, rMuE_MuUpFlat) rMuEWeightUpFlat_MM = "(0.5*(%s))" % (rMuE_ElUpFlat) rMuEWeightUpFlat_EE = "(0.5*pow(%s, -1))" % (rMuE_MuUpFlat) rMuE_ElDnFlat = "(%s*%s)" % (rMuE_El, variationDnFlat) rMuE_MuDnFlat = "(%s*%s)" % (rMuE_Mu, variationDnFlat) rMuEWeightDnFlat = "(0.5*(%s + pow(%s, -1)))" % (rMuE_ElDnFlat, rMuE_MuDnFlat) rMuEWeightDnFlat_MM = "(0.5*(%s))" % (rMuE_ElDnFlat) rMuEWeightDnFlat_EE = "(0.5*pow(%s, -1))" % (rMuE_MuDnFlat) # Pt uncertainty rMuE_ElUpPt = "(%s*%s)" % (rMuE_El, variationUpPt.format(pt="pt1")) rMuE_MuUpPt = "(%s*%s)" % (rMuE_Mu, variationUpPt.format(pt="pt2")) rMuEWeightUpPt = "(0.5*(%s + pow(%s, -1)))" % (rMuE_ElUpPt, rMuE_MuUpPt) rMuEWeightUpPt_MM = "(0.5*(%s))" % (rMuE_ElUpPt) rMuEWeightUpPt_EE = "(0.5*pow(%s, -1))" % (rMuE_MuUpPt) rMuE_ElDnPt = "(%s*%s)" % (rMuE_El, variationDnPt.format(pt="pt1")) rMuE_MuDnPt = "(%s*%s)" % (rMuE_Mu, variationDnPt.format(pt="pt2")) rMuEWeightDnPt = "(0.5*(%s + pow(%s, -1)))" % (rMuE_ElDnPt, rMuE_MuDnPt) rMuEWeightDnPt_MM = "(0.5*(%s))" % (rMuE_ElDnPt) rMuEWeightDnPt_EE = "(0.5*pow(%s, -1))" % (rMuE_MuDnPt) # Pt uncertainty rMuE_ElUpEta = "(%s*%s)" % (rMuE_El, variationUpEta.format(eta="eta1")) rMuE_MuUpEta = "(%s*%s)" % (rMuE_Mu, variationUpEta.format(eta="eta2")) rMuEWeightUpEta = "(0.5*(%s + pow(%s, -1)))" % (rMuE_ElUpEta, rMuE_MuUpEta) rMuEWeightUpEta_MM = "(0.5*(%s))" % (rMuE_ElUpEta) rMuEWeightUpEta_EE = "(0.5*pow(%s, -1))" % (rMuE_MuUpEta) rMuE_ElDnEta = "(%s*%s)" % (rMuE_El, variationDnEta.format(eta="eta1")) rMuE_MuDnEta = "(%s*%s)" % (rMuE_Mu, variationDnEta.format(eta="eta2")) rMuEWeightDnEta = "(0.5*(%s + pow(%s, -1)))" % (rMuE_ElDnEta, rMuE_MuDnEta) rMuEWeightDnEta_MM = "(0.5*(%s))" % (rMuE_ElDnEta) rMuEWeightDnEta_EE = "(0.5*pow(%s, -1))" % (rMuE_MuDnEta) plot.cuts = cut.replace( "prefireWeight*leptonFullSimScaleFactor1*leptonFullSimScaleFactor2*genWeight*weight*", "") cutRMuEScaled = "%s*%s" % (rMuEWeight, plot.cuts) cutRMuEScaledUpFlat = "%s*%s" % (rMuEWeightUpFlat, plot.cuts) cutRMuEScaledDnFlat = "%s*%s" % (rMuEWeightDnFlat, plot.cuts) cutRMuEScaledUpPt = "%s*%s" % (rMuEWeightUpPt, plot.cuts) cutRMuEScaledDnPt = "%s*%s" % (rMuEWeightDnPt, plot.cuts) cutRMuEScaledUpEta = "%s*%s" % (rMuEWeightUpEta, plot.cuts) cutRMuEScaledDnEta = "%s*%s" % (rMuEWeightDnEta, plot.cuts) cutRMuEScaled_EE = "%s*%s" % (rMuEWeight_EE, plot.cuts) cutRMuEScaledUpFlat_EE = "%s*%s" % (rMuEWeightUpFlat_EE, plot.cuts) cutRMuEScaledDnFlat_EE = "%s*%s" % (rMuEWeightDnFlat_EE, plot.cuts) cutRMuEScaledUpPt_EE = "%s*%s" % (rMuEWeightUpPt_EE, plot.cuts) cutRMuEScaledDnPt_EE = "%s*%s" % (rMuEWeightDnPt_EE, plot.cuts) cutRMuEScaledUpEta_EE = "%s*%s" % (rMuEWeightUpEta_EE, plot.cuts) cutRMuEScaledDnEta_EE = "%s*%s" % (rMuEWeightDnEta_EE, plot.cuts) cutRMuEScaled_MM = "%s*%s" % (rMuEWeight_MM, plot.cuts) cutRMuEScaledUpFlat_MM = "%s*%s" % (rMuEWeightUpFlat_MM, plot.cuts) cutRMuEScaledDnFlat_MM = "%s*%s" % (rMuEWeightDnFlat_MM, plot.cuts) cutRMuEScaledUpPt_MM = "%s*%s" % (rMuEWeightUpPt_MM, plot.cuts) cutRMuEScaledDnPt_MM = "%s*%s" % (rMuEWeightDnPt_MM, plot.cuts) cutRMuEScaledUpEta_MM = "%s*%s" % (rMuEWeightUpEta_MM, plot.cuts) cutRMuEScaledDnEta_MM = "%s*%s" % (rMuEWeightDnEta_MM, plot.cuts) if isMC: RT = corrections[runRange.era].rSFOFTrig.inclusive.valMC RTErr = corrections[runRange.era].rSFOFTrig.inclusive.errMC else: RT = corrections[runRange.era].rSFOFTrig.inclusive.val RTErr = corrections[runRange.era].rSFOFTrig.inclusive.err if isMC: source = "" modifier = "" eventCounts = totalNumberOfGeneratedEvents(path, source, modifier) processes = [] for background in backgrounds: processes.append( Process(getattr(Backgrounds[runRange.era], background), eventCounts)) n = {} for region in [ "inclusive", ]: histEE = TheStack(processes, runRange.lumi, plot, trees["EE"], "None", 1.0, getTriggerScaleFactor("EE", region, runRange), 1.0).theHistogram histMM = TheStack(processes, runRange.lumi, plot, trees["MM"], "None", 1.0, getTriggerScaleFactor("MM", region, runRange), 1.0).theHistogram histEM = TheStack(processes, runRange.lumi, plot, trees["EM"], "None", 1.0, getTriggerScaleFactor("EM", region, runRange), 1.0).theHistogram triggerEffs = corrections[runRange.era] histEE.Scale(getattr(triggerEffs, region).effEE.val) histMM.Scale(getattr(triggerEffs, region).effMM.val) histEM.Scale(getattr(triggerEffs, region).effEM.val) # central value plot.cuts = cutRMuEScaled histEMRMuEScaled = TheStack(processes, runRange.lumi, plot, trees["EM"], "None", 1.0, 1.0, 1.0).theHistogram histEMRMuEScaled.Scale(getattr(triggerEffs, region).effEM.val) # flat uncertainty plot.cuts = cutRMuEScaledUpFlat histEMRMuEScaledUpFlat = TheStack(processes, runRange.lumi, plot, trees["EM"], "None", 1.0, 1.0, 1.0).theHistogram histEMRMuEScaledUpFlat.Scale( getattr(triggerEffs, region).effEM.val) plot.cuts = cutRMuEScaledDnFlat histEMRMuEScaledDownFlat = TheStack(processes, runRange.lumi, plot, trees["EM"], "None", 1.0, 1.0, 1.0).theHistogram histEMRMuEScaledDownFlat.Scale( getattr(triggerEffs, region).effEM.val) # pt uncertainty plot.cuts = cutRMuEScaledUpPt histEMRMuEScaledUpPt = TheStack(processes, runRange.lumi, plot, trees["EM"], "None", 1.0, 1.0, 1.0).theHistogram histEMRMuEScaledUpPt.Scale(getattr(triggerEffs, region).effEM.val) plot.cuts = cutRMuEScaledDnPt histEMRMuEScaledDownPt = TheStack(processes, runRange.lumi, plot, trees["EM"], "None", 1.0, 1.0, 1.0).theHistogram histEMRMuEScaledDownPt.Scale( getattr(triggerEffs, region).effEM.val) # eta uncertainty plot.cuts = cutRMuEScaledUpEta histEMRMuEScaledUpEta = TheStack(processes, runRange.lumi, plot, trees["EM"], "None", 1.0, 1.0, 1.0).theHistogram histEMRMuEScaledUpEta.Scale(getattr(triggerEffs, region).effEM.val) plot.cuts = cutRMuEScaledDnEta histEMRMuEScaledDownEta = TheStack(processes, runRange.lumi, plot, trees["EM"], "None", 1.0, 1.0, 1.0).theHistogram histEMRMuEScaledDownEta.Scale( getattr(triggerEffs, region).effEM.val) eeErr = ROOT.Double() ee = histEE.IntegralAndError(0, -1, eeErr) mmErr = ROOT.Double() mm = histMM.IntegralAndError(0, -1, mmErr) emErr = ROOT.Double() em = histEM.IntegralAndError(0, -1, emErr) #central value emRMuEScaledErr = ROOT.Double() emRMuEScaled = histEMRMuEScaled.IntegralAndError( 0, -1, emRMuEScaledErr) # flat uncertainty emRMuEScaledUpFlatErr = ROOT.Double() emRMuEScaledUpFlat = histEMRMuEScaledUpFlat.IntegralAndError( 0, -1, emRMuEScaledUpFlatErr) emRMuEScaledDownFlatErr = ROOT.Double() emRMuEScaledDownFlat = histEMRMuEScaledDownFlat.IntegralAndError( 0, -1, emRMuEScaledDownFlatErr) # pt uncertainty emRMuEScaledUpPtErr = ROOT.Double() emRMuEScaledUpPt = histEMRMuEScaledUpPt.IntegralAndError( 0, -1, emRMuEScaledUpPtErr) emRMuEScaledDownPtErr = ROOT.Double() emRMuEScaledDownPt = histEMRMuEScaledDownPt.IntegralAndError( 0, -1, emRMuEScaledDownPtErr) # eta uncertainty emRMuEScaledUpEtaErr = ROOT.Double() emRMuEScaledUpEta = histEMRMuEScaledUpEta.IntegralAndError( 0, -1, emRMuEScaledUpEtaErr) emRMuEScaledDownEtaErr = ROOT.Double() emRMuEScaledDownEta = histEMRMuEScaledDownEta.IntegralAndError( 0, -1, emRMuEScaledDownEtaErr) n["EMRMuEScaled"] = emRMuEScaled * RT n["EMRMuEScaledUpFlat"] = emRMuEScaledUpFlat * RT n["EMRMuEScaledDownFlat"] = emRMuEScaledDownFlat * RT n["EMRMuEScaledUpPt"] = emRMuEScaledUpPt * RT n["EMRMuEScaledDownPt"] = emRMuEScaledDownPt * RT n["EMRMuEScaledUpEta"] = emRMuEScaledUpEta * RT n["EMRMuEScaledDownEta"] = emRMuEScaledDownEta * RT n["MM"] = mm n["EE"] = ee n["EM"] = em n["MMStatErr"] = float(mmErr) n["EEStatErr"] = float(eeErr) n["EMStatErr"] = float(emErr) else: n = {} for region in [ "inclusive", ]: if blind: n["MM"] = createHistoFromTree(trees["EM"], "mll", cutRMuEScaled_MM, 100, 0, 10000).Integral(0, -1) * RT n["EE"] = createHistoFromTree(trees["EM"], "mll", cutRMuEScaled_EE, 100, 0, 10000).Integral(0, -1) * RT else: n["MM"] = trees["MM"].GetEntries(plot.cuts) n["EE"] = trees["EE"].GetEntries(plot.cuts) n["EM"] = trees["EM"].GetEntries(plot.cuts) n["EMRMuEScaled"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaled, 100, 0, 10000).Integral( 0, -1) * RT n["EMRMuEScaled_EE"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaled_EE, 100, 0, 10000).Integral( 0, -1) * RT n["EMRMuEScaled_MM"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaled_MM, 100, 0, 10000).Integral( 0, -1) * RT n["EMRMuEScaledUpRT"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaled, 10, 0, 10000).Integral( 0, -1) * (RT + RTErr) n["EMRMuEScaledDownRT"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaled, 10, 0, 10000).Integral( 0, -1) * (RT - RTErr) n["EMRMuEScaledUpFlat"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledUpFlat, 10, 0, 10000).Integral(0, -1) * RT n["EMRMuEScaledDownFlat"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledDnFlat, 10, 0, 10000).Integral(0, -1) * RT n["EMRMuEScaledUpPt"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledUpPt, 10, 0, 10000).Integral( 0, -1) * RT n["EMRMuEScaledDownPt"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledDnPt, 10, 0, 10000).Integral( 0, -1) * RT n["EMRMuEScaledUpEta"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledUpEta, 10, 0, 10000).Integral( 0, -1) * RT n["EMRMuEScaledDownEta"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledDnEta, 10, 0, 10000).Integral( 0, -1) * RT n["EMRMuEScaledUpRT_EE"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaled_EE, 10, 0, 10000).Integral( 0, -1) * (RT + RTErr) n["EMRMuEScaledDownRT_EE"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaled_EE, 10, 0, 10000).Integral( 0, -1) * (RT - RTErr) n["EMRMuEScaledUpFlat_EE"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledUpFlat_EE, 10, 0, 10000).Integral(0, -1) * RT n["EMRMuEScaledDownFlat_EE"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledDnFlat_EE, 10, 0, 10000).Integral(0, -1) * RT n["EMRMuEScaledUpPt_EE"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledUpPt_EE, 10, 0, 10000).Integral(0, -1) * RT n["EMRMuEScaledDownPt_EE"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledDnPt_EE, 10, 0, 10000).Integral(0, -1) * RT n["EMRMuEScaledUpEta_EE"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledUpEta_EE, 10, 0, 10000).Integral(0, -1) * RT n["EMRMuEScaledDownEta_EE"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledDnEta_EE, 10, 0, 10000).Integral(0, -1) * RT n["EMRMuEScaledUpRT_MM"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaled_MM, 10, 0, 10000).Integral( 0, -1) * (RT + RTErr) n["EMRMuEScaledDownRT_MM"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaled_MM, 10, 0, 10000).Integral( 0, -1) * (RT - RTErr) n["EMRMuEScaledUpFlat_MM"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledUpFlat_MM, 10, 0, 10000).Integral(0, -1) * RT n["EMRMuEScaledDownFlat_MM"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledDnFlat_MM, 10, 0, 10000).Integral(0, -1) * RT n["EMRMuEScaledUpPt_MM"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledUpPt_MM, 10, 0, 10000).Integral(0, -1) * RT n["EMRMuEScaledDownPt_MM"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledDnPt_MM, 10, 0, 10000).Integral(0, -1) * RT n["EMRMuEScaledUpEta_MM"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledUpEta_MM, 10, 0, 10000).Integral(0, -1) * RT n["EMRMuEScaledDownEta_MM"] = createHistoFromTree( trees["EM"], "mll", cutRMuEScaledDnEta_MM, 10, 0, 10000).Integral(0, -1) * RT n["MMStatErr"] = n["MM"]**0.5 n["EEStatErr"] = n["EE"]**0.5 n["EMStatErr"] = n["EM"]**0.5 n["cut"] = cut return n
ptCutLabel = "20"#"20(10)" variable = "p4.M()" cuts = "weight*(chargeProduct < 0 && %s && abs(eta1) < 2.4 && abs(eta2) < 2.4 && p4.M() > 20 && ((abs(eta1) < 1.4 || abs(eta1) > 1.6) && (abs(eta2) < 1.4 || abs(eta2) > 1.6)))"%(ptCut) SampleName = "TT_Powheg" runRange = getRunRange("Run2015_25ns") plot = getPlot("mllPlot") selection = getRegion("SignalInclusive") plot.addRegion(selection) plot.cleanCuts() plot.cuts = plot.cuts % runRange.runCut eventCounts = totalNumberOfGeneratedEvents(path) processes = [Process(getattr(Backgrounds,"TT_Powheg"),eventCounts)] treesEE = readTrees(path,"EE") treesEM = readTrees(path,"EMu") treesMM = readTrees(path,"MuMu") histoEE = TheStack(processes,runRange.lumi,plot,treesEE,"None",1.0,1.0,1.0).theHistogram histoMM = TheStack(processes,runRange.lumi,plot,treesMM,"None",1.0,1.0,1.0).theHistogram histoEM = TheStack(processes,runRange.lumi,plot,treesEM,"None",1.0,1.0,1.0).theHistogram #~ histoEE.Scale(getattr(triggerEffs,"central").effEE.valMC) #~ histoMM.Scale(getattr(triggerEffs,"central").effMM.valMC) #~ histoEM.Scale(getattr(triggerEffs,"central").effEM.valMC)
def getYields(runRange): import ratios import pickle path = locations[runRange.era].dataSetPathNLL EE = readTrees(path, "EE") EM = readTrees(path, "EMu") MM = readTrees(path, "MuMu") ### Mass bins for Morion 2017 SRs, summed low and high mass regions + legacy regions massRegions = [ "mass20To60", "mass60To86", "mass86To96", "mass96To150", "mass150To200", "mass200To300", "mass300To400", "mass400" ] ### Two likelihood bins and MT2 cut nLLRegions = ["lowNLL", "highNLL"] MT2Regions = ["highMT2"] nBJetsRegions = ["zeroBJets", "oneOrMoreBJets"] signalBins = [] signalCuts = {} plot = getPlot("mllPlotROutIn") for massRegion in massRegions: for nLLRegion in nLLRegions: for MT2Region in MT2Regions: for nBJetsRegion in nBJetsRegions: signalBins.append( "%s_%s_%s_%s" % (massRegion, nLLRegion, MT2Region, nBJetsRegion)) signalCuts["%s_%s_%s_%s" % (massRegion, nLLRegion, MT2Region, nBJetsRegion)] = "%s && %s && %s && %s" % ( massCuts[massRegion], nLLCuts[nLLRegion], MT2Cuts[MT2Region], NBJetsCuts[nBJetsRegion]) selection = getRegion("SignalHighMT2DeltaPhiJetMet") backgrounds = [ "RareWZOnZ", "RareZZLowMassOnZ", "RareTTZOnZ", "RareRestOnZ" ] plot.addRegion(selection) plot.addRunRange(runRange) plot.cuts = plot.cuts.replace("p4.M()", "mll") plot.variable = plot.variable.replace("p4.M()", "mll") if runRange.era == "2018": plot.cuts = plot.cuts.replace("chargeProduct < 0 &&", "chargeProduct < 0 && vetoHEM == 1 &&") counts = {} eventCounts = totalNumberOfGeneratedEvents(path) defaultCut = plot.cuts ### loop over signal regions for signalBin in signalBins: ### Add signal cut and remove those that are renamed or already applied ### on NLL datasets plot.cuts = defaultCut.replace( "chargeProduct < 0", "chargeProduct < 0 && %s" % (signalCuts[signalBin])) plot.cuts = plot.cuts.replace("metFilterSummary > 0 &&", "") plot.cuts = plot.cuts.replace("&& metFilterSummary > 0", "") plot.cuts = plot.cuts.replace("triggerSummary > 0 &&", "") plot.cuts = plot.cuts.replace("p4.Pt()", "pt") plot.cuts = "bTagWeight*" + plot.cuts #print plot.cuts eventCountSF = 0 eventYieldSF = 0 eventYieldEE = 0 eventYieldMM = 0 eventYieldSFTotErr = 0 eventYieldSFStatErr = 0 eventYieldEEStatErr = 0 eventYieldMMStatErr = 0 eventYieldSFSystErr = 0 eventYieldSFUp = 0 eventYieldEEUp = 0 eventYieldMMUp = 0 eventYieldSFDown = 0 eventYieldEEDown = 0 eventYieldMMDown = 0 eventYieldOF = 0 eventYieldOFTotErr = 0 eventYieldOFStatErr = 0 eventYieldOFSystErr = 0 eventYieldOFUp = 0 eventYieldOFDown = 0 counts["%s_bySample" % signalBin] = {} processes = [] for background in backgrounds: proc = Process(getattr(Backgrounds[runRange.era], background), eventCounts) processes.append(proc) picklePath = "/home/home4/institut_1b/teroerde/Doktorand/SUSYFramework/frameWorkBase/shelves/scaleFactor_{runRange}_{background}.pkl" sf = 1.0 sferr = 0.0 if proc.label in ["WZ", "ZZ", "TTZ"]: if proc.label == "WZ": backgroundName = "WZTo3LNu" elif proc.label == "ZZ": backgroundName = "ZZTo4L" elif proc.label == "TTZ": backgroundName = "ttZToLL" import pickle with open( picklePath.format(runRange=runRange.label, background=backgroundName), "r") as fi: scaleFac = pickle.load(fi) sf = scaleFac["scaleFac"] sferr = scaleFac["scaleFacErr"] else: sferr = proc.uncertainty sfErrRel = sferr / sf saveCut = plot.cuts histoEE = proc.createCombinedHistogram( runRange.lumi, plot, EE, "None", 1.0, getTriggerScaleFactor("EE", "inclusive", runRange)[0] * sf, 1.0, TopWeightUp=False, TopWeightDown=False, signal=False, doTopReweighting=True, doPUWeights=False, normalizeToBinWidth=False, useTriggerEmulation=False) histoMM = proc.createCombinedHistogram( runRange.lumi, plot, MM, "None", 1.0, getTriggerScaleFactor("MM", "inclusive", runRange)[0] * sf, 1.0, TopWeightUp=False, TopWeightDown=False, signal=False, doTopReweighting=True, doPUWeights=False, normalizeToBinWidth=False, useTriggerEmulation=False) # RSFOF weighted EMu sample with rMuE parametrization rMuEPars = corrections[runRange.era].rMuELeptonPt.inclusive RT = corrections[runRange.era].rSFOFTrig.inclusive.val corrMap = {} corrMap["offset"] = rMuEPars.ptOffsetMC corrMap["falling"] = rMuEPars.ptFallingMC corrMap["etaParabolaBase"] = rMuEPars.etaParabolaBaseMC corrMap["etaParabolaMinus"] = rMuEPars.etaParabolaMinusMC corrMap["etaParabolaPlus"] = rMuEPars.etaParabolaPlusMC corrMap["norm"] = rMuEPars.normMC rMuEDummy = "({norm:.3f}*(({offset:.3f} + {falling:.3f}/{pt})*({etaParabolaBase} + ({eta}<-1.6)*{etaParabolaMinus:.3f}*pow({eta}+1.6, 2)+({eta}>1.6)*{etaParabolaPlus:.3f}*pow({eta}-1.6,2) )))" rMuE_El = rMuEDummy.format(pt="pt1", eta="eta1", **corrMap) rMuE_Mu = rMuEDummy.format(pt="pt2", eta="eta2", **corrMap) rMuEWeight = "(0.5*(%s + pow(%s, -1)))*%.3f" % (rMuE_Mu, rMuE_El, RT) #tmpCut = plot.cuts plot.cuts = "%s*%s" % (rMuEWeight, plot.cuts) histoEM = proc.createCombinedHistogram( runRange.lumi, plot, EM, "None", 1.0, getTriggerScaleFactor("EM", "inclusive", runRange)[0] * sf, 1.0, TopWeightUp=False, TopWeightDown=False, signal=False, doTopReweighting=True, doPUWeights=False, normalizeToBinWidth=False, useTriggerEmulation=False) #plot.cuts = tmpCut plot.cuts = saveCut statErrEE = ROOT.Double() statErrMM = ROOT.Double() statErrEM = ROOT.Double() eventCountSF += histoEE.GetEntries() + histoMM.GetEntries() procYield = histoEE.IntegralAndError( 0, -1, statErrEE) + histoMM.IntegralAndError(0, -1, statErrMM) procYield_EE = histoEE.IntegralAndError(0, -1, statErrEE) procYield_MM = histoMM.IntegralAndError(0, -1, statErrMM) #if "mass20To60" in signalBin and proc.label == "ZZ": #print signalBin, procYield eventYieldSF += procYield eventYieldSFUp += (procYield) * (1 + sfErrRel) eventYieldSFDown += (procYield) * (1 - sfErrRel) eventYieldEE += procYield_EE eventYieldEEUp += (procYield_EE) * (1 + sfErrRel) eventYieldEEDown += (procYield_EE) * (1 - sfErrRel) eventYieldMM += procYield_MM eventYieldMMUp += (procYield_MM) * (1 + sfErrRel) eventYieldMMDown += (procYield_MM) * (1 - sfErrRel) eventYieldSFStatErr = (eventYieldSFStatErr**2 + statErrEE**2 + statErrMM**2)**0.5 eventYieldEEStatErr = (eventYieldEEStatErr**2 + statErrEE**2)**0.5 eventYieldMMStatErr = (eventYieldMMStatErr**2 + statErrMM**2)**0.5 eventYieldSFSystErr = (eventYieldSFSystErr**2 + (eventYieldSF * sfErrRel)**2)**0.5 eventYieldOF += histoEM.IntegralAndError(0, -1, statErrEM) eventYieldOFUp += histoEM.Integral(0, -1) * (1 + proc.uncertainty) eventYieldOFDown += histoEM.Integral(0, -1) * (1 - proc.uncertainty) eventYieldOFStatErr = (eventYieldOFStatErr**2 + statErrEM**2)**0.5 eventYieldOFSystErr = (eventYieldOFSystErr**2 + (eventYieldOF * sfErrRel)**2)**0.5 counts["%s_bySample" % signalBin][proc.label] = procYield if proc.label in ["WZ", "ZZ", "TTZ", "Rare"]: # uncertainty from just this one sample. Used to treat uncertainties uncorrelated between WZ,ZZ,TTZ,Rare counts["%s_SingleErr%s" % (signalBin, proc.label)] = ( ((procYield) * sfErrRel)**2 + statErrEE**2 + statErrMM**2)**0.5 #if proc.label == "ZZ" and "highNLL" in signalBin: #print signalBin, gotten eventYieldSFTotErr = (eventYieldSFStatErr**2 + eventYieldSFSystErr**2)**0.5 eventYieldOFTotErr = (eventYieldOFStatErr**2 + eventYieldOFSystErr**2)**0.5 eventCountSF = histoEE.GetEntries() + histoMM.GetEntries() counts["%s_SF" % signalBin] = eventYieldSF counts["%s_EE" % signalBin] = eventYieldEE counts["%s_MM" % signalBin] = eventYieldMM counts["%s_SF_Stat" % signalBin] = eventYieldSFStatErr counts["%s_EE_Stat" % signalBin] = eventYieldEEStatErr counts["%s_MM_Stat" % signalBin] = eventYieldMMStatErr counts["%s_SF_Syst" % signalBin] = eventYieldSFSystErr counts["%s_SF_Up" % signalBin] = eventYieldSFUp counts["%s_EE_Up" % signalBin] = eventYieldEEUp counts["%s_MM_Up" % signalBin] = eventYieldMMUp counts["%s_SF_Down" % signalBin] = eventYieldSFDown counts["%s_EE_Down" % signalBin] = eventYieldEEDown counts["%s_MM_Down" % signalBin] = eventYieldMMDown counts["MCEvents_%s_SF" % signalBin] = eventCountSF counts["%s_OF" % signalBin] = eventYieldOF counts["%s_OF_Stat" % signalBin] = eventYieldOFStatErr counts["%s_OF_Syst" % signalBin] = eventYieldOFSystErr counts["%s_OF_Err" % signalBin] = eventYieldOFTotErr counts["%s_OF_Up" % signalBin] = eventYieldOFUp counts["%s_OF_Down" % signalBin] = eventYieldOFDown fileName = "RareOnZBG_%s" % (runRange.label) outFilePkl = open("shelves/%s.pkl" % fileName, "w") pickle.dump(counts, outFilePkl) outFilePkl.close()
def getHistograms(path, plot, runRange, isMC, backgrounds, source): if not isMC: treesEE = readTrees(path, "EE", modifier="TriggerPFHT") treesMuMu = readTrees(path, "MuMu", modifier="TriggerPFHT") treesEMu = readTrees(path, "EMu", modifier="TriggerPFHT") denominatorHistoEE = TH1F("", "", plot.nBins, plot.firstBin, plot.lastBin) for name, tree in treesEE.iteritems(): if name == "MergedData": denominatorHistoEE.Add( createHistoFromTree(tree, plot.variable, plot.cuts, plot.nBins, plot.firstBin, plot.lastBin, binning=plot.binning).Clone()) denominatorHistoMuMu = TH1F("", "", plot.nBins, plot.firstBin, plot.lastBin) for name, tree in treesMuMu.iteritems(): if name == "MergedData": denominatorHistoMuMu.Add( createHistoFromTree(tree, plot.variable, plot.cuts, plot.nBins, plot.firstBin, plot.lastBin, binning=plot.binning).Clone()) denominatorHistoMuEG = TH1F("", "", plot.nBins, plot.firstBin, plot.lastBin) for name, tree in treesEMu.iteritems(): if name == "MergedData": denominatorHistoMuEG.Add( createHistoFromTree(tree, plot.variable, plot.cuts, plot.nBins, plot.firstBin, plot.lastBin, binning=plot.binning).Clone()) cutsEE = plot.cuts.replace( "chargeProduct < 0", "chargeProduct < 0 && %s" % theCuts.triggerCuts.EE.cut) cutsOF = plot.cuts.replace( "chargeProduct < 0", "chargeProduct < 0 && %s" % theCuts.triggerCuts.EM.cut) cutsMuMu = plot.cuts.replace( "chargeProduct < 0", "chargeProduct < 0 && %s" % theCuts.triggerCuts.MM.cut) nominatorHistoEE = TH1F("", "", plot.nBins, plot.firstBin, plot.lastBin) for name, tree in treesEE.iteritems(): if name == "MergedData": nominatorHistoEE.Add( createHistoFromTree(tree, plot.variable, cutsEE, plot.nBins, plot.firstBin, plot.lastBin, binning=plot.binning).Clone()) nominatorHistoMuMu = TH1F("", "", plot.nBins, plot.firstBin, plot.lastBin) for name, tree in treesMuMu.iteritems(): if name == "MergedData": nominatorHistoMuMu.Add( createHistoFromTree(tree, plot.variable, cutsMuMu, plot.nBins, plot.firstBin, plot.lastBin, binning=plot.binning).Clone()) nominatorHistoMuEG = TH1F("", "", plot.nBins, plot.firstBin, plot.lastBin) for name, tree in treesEMu.iteritems(): if name == "MergedData": nominatorHistoMuEG.Add( createHistoFromTree(tree, plot.variable, cutsOF, plot.nBins, plot.firstBin, plot.lastBin, binning=plot.binning).Clone()) else: treesEE = readTrees(path, "EE") treesMuMu = readTrees(path, "MuMu") treesEMu = readTrees(path, "EMu") eventCounts = totalNumberOfGeneratedEvents(path) processes = [] for background in backgrounds: processes.append( Process(getattr(Backgrounds, background), eventCounts)) nominatorStackEE = TheStack(processes, runRange.lumi, plot, treesEE, "None", 1.0, 1.0, 1.0, useTriggerEmulation=True) nominatorStackMuMu = TheStack(processes, runRange.lumi, plot, treesMuMu, "None", 1.0, 1.0, 1.0, useTriggerEmulation=True) nominatorStackMuEG = TheStack(processes, runRange.lumi, plot, treesEMu, "None", 1.0, 1.0, 1.0, useTriggerEmulation=True) denominatorStackEE = TheStack(processes, runRange.lumi, plot, treesEE, "None", 1.0, 1.0, 1.0) denominatorStackMuMu = TheStack(processes, runRange.lumi, plot, treesMuMu, "None", 1.0, 1.0, 1.0) denominatorStackMuEG = TheStack(processes, runRange.lumi, plot, treesEMu, "None", 1.0, 1.0, 1.0) denominatorHistoEE = denominatorStackEE.theHistogram denominatorHistoMuMu = denominatorStackMuMu.theHistogram denominatorHistoMuEG = denominatorStackMuEG.theHistogram nominatorHistoEE = nominatorStackEE.theHistogram nominatorHistoMuMu = nominatorStackMuMu.theHistogram nominatorHistoMuEG = nominatorStackMuEG.theHistogram return { "EE": denominatorHistoEE, "MuMu": denominatorHistoMuMu, "MuEG": denominatorHistoMuEG }, { "EE": nominatorHistoEE, "MuMu": nominatorHistoMuMu, "MuEG": nominatorHistoMuEG }