コード例 #1
0
def closure( filenames, plot, treename="photonJetTree" ):
	commonCut = "[email protected]() && [email protected]()"
	#commonCut = "1"
	leptonPtCut = 15 # only larger than 15 make sense here, since this is the reprocessing cut
	commonCut = "([email protected]() || Max$(electrons.pt)<{0}) && ([email protected]() || Max$(muons.pt)<{0})".format(leptonPtCut)

	totalHist = getHists( filenames, plot, cut=commonCut, treeName=treename )
	gGenHist = getHists( filenames, plot, cut="photons[0].isGen(0) && "+commonCut, treeName=treename )
	eGenHist = getHists( filenames, plot, cut="photons[0].isGen(1) && "+commonCut, treeName=treename )
	gGenHist.SetLineColor(2)
	eGenHist.SetLineColor(3)

	gDatasetAbbrs = [getDatasetAbbr(f) for f in filenames ]
	gDatasetAbbrs = mergeDatasetAbbr( gDatasetAbbrs )

	multihisto = Multihisto()
	multihisto.leg.SetHeader( "/".join([ datasetToLatex(x) for x in gDatasetAbbrs]) )
	multihisto.addHisto( totalHist, "Simulation", draw="e0 hist" )
	multihisto.addHisto( gGenHist, "gen #gamma", toStack=True, draw="e0 hist" )
	multihisto.addHisto( eGenHist, "gen e", toStack=True, draw="e0 hist" )

	infoText = ROOT.TLatex(0.03,.96, "CMS Private Work - 8TeV #geq1#gamma,#geq2jets" )
	infoText.SetNDC()

	can = ROOT.TCanvas()
	can.cd()
	multihisto.Draw()
	infoText.Draw()
	r = Ratio( "Sim./Pred.", totalHist, multihisto.stack.GetStack().Last() )
	r.draw(0,2)
	SaveAs( can, "genMatches_%s_%s"%(getSaveNameFromDatasets(filenames), plot))

	ROOT.SetOwnership( can, False )
	del can
コード例 #2
0
ファイル: compareFiles.py プロジェクト: kkiesel/singlePhoton
def compareFiles( plot, filenames, treename, diff ):
	tree1 = readTree( filenames[0], treename )
	tree2 = readTree( filenames[1], treename )

	if diff:
		cut1, cut2 = getEventNumberDiff( tree1, tree2 )
		tree1 = getTreeFriendsWithBooleanVariable( tree1, cut1)
		tree2 = getTreeFriendsWithBooleanVariable( tree2, cut2)
		h1 = createHistoFromTree( tree1, plot, "x" )
		h2 = createHistoFromTree( tree2, plot, "x" )

	else:

		h1 = getHisto( tree1, plot, weight="1" )
		h2 = getHisto( tree2, plot, weight="1" )
		mini = min(h1.GetBinLowEdge(1), h2.GetBinLowEdge(1))
		maxi = max(h2.GetBinLowEdge(h2.GetNbinsX()+2), h1.GetBinLowEdge(h1.GetNbinsX()+2))
		h1 = getHisto( tree1, plot, weight="1", firstBin=mini, lastBin=maxi  )
		h2 = getHisto( tree2, plot, weight="1", firstBin=mini, lastBin=maxi )


	h2.SetLineColor(2)
	mh = Multihisto()
	name1 = getVersion(filenames[0])
	name2 = getVersion(filenames[1])
	mh.addHisto( h1, name1, draw="hist e" )
	mh.addHisto( h2, name2, draw="hist e" )
	mh.Draw()
	from myRatio import Ratio
	r = Ratio( "%s/%s"%(name1,name2), h1, h2 )
	r.draw()

	plot ="test"
	ROOT.gPad.GetCanvas().SaveAs( "compareFiles_%s.pdf"%plot )
コード例 #3
0
def closure(filenames, plot):
    commonCut = "[email protected]() && [email protected]()"
    #if plot != "met": commonCut += " && met>=100"

    gHist = getHists(filenames,
                     plot,
                     cut="(photons[0].isStatus(1)) && " + commonCut)
    eHist = multiDimFakeRate(filenames, plot, commonCut, isData=False)
    gHist.SetName("gHist")
    eHist.SetName("eHist")

    eHistSys = eHist.Clone("eHistSys")
    eHistSys = setRelativeUncertainty(eHistSys, 0.11)
    eHistSys.SetFillColor(eHistSys.GetLineColor())
    eHistSys.SetFillStyle(3354)
    eHistSys.SetMarkerSize(0)
    eHistSys.SetName("eHistSys")

    gDatasetAbbrs = [getDatasetAbbr(f) for f in filenames]
    gDatasetAbbrs = mergeDatasetAbbr(gDatasetAbbrs)

    multihisto = Multihisto()
    multihisto.leg = myLegend(.63, .75, .96, .94)
    multihisto.leg.SetTextSize(0.035)
    multihisto.leg.SetTextFont(42)

    multihisto.leg.SetHeader(",".join(
        [datasetToLatex(x) for x in gDatasetAbbrs]))
    multihisto.addHisto(gHist, "Direct Simulation", draw="p e x0")
    multihisto.addHisto(eHist, "", draw="hist")
    multihisto.addHisto(eHistSys, "Prediction", draw="e2")

    infoText = ROOT.TLatex()
    infoText.SetNDC()
    infoText.SetTextFont(gHist.GetLabelFont())
    infoText.SetTextSize(gHist.GetLabelSize())
    infoText.SetText(
        .02, .96,
        "CMS Simulation                         19.7fb^{-1} (8 TeV)          #geq1#gamma,#geq2jets"
    )

    can = ROOT.TCanvas("c1", "", 600, 600)
    can.cd()
    multihisto.Draw()
    infoText.Draw()
    r = Ratio("Direct/Pred.", gHist, eHist, eHistSys)
    r.draw(0, 2)
    SaveAs(can,
           "ewkClosure_%s_%s" % (getSaveNameFromDatasets(filenames), plot))
    ROOT.gPad.SaveAs("plots/ewkClosure_%s_%s.C" %
                     (getSaveNameFromDatasets(filenames), plot))

    ewkOut = ROOT.TFile("ewkOout.root", "recreate")
    ewkOut.cd()
    for h in gHist, eHist, eHistSys:
        h.Write()
    ewkOut.Close()

    ROOT.SetOwnership(can, False)
    del can
コード例 #4
0
ファイル: compareFiles.py プロジェクト: kkiesel/singlePhoton
def compareFiles(plot, filenames, treename, diff):
    tree1 = readTree(filenames[0], treename)
    tree2 = readTree(filenames[1], treename)

    if diff:
        cut1, cut2 = getEventNumberDiff(tree1, tree2)
        tree1 = getTreeFriendsWithBooleanVariable(tree1, cut1)
        tree2 = getTreeFriendsWithBooleanVariable(tree2, cut2)
        h1 = createHistoFromTree(tree1, plot, "x")
        h2 = createHistoFromTree(tree2, plot, "x")

    else:

        h1 = getHisto(tree1, plot, weight="1")
        h2 = getHisto(tree2, plot, weight="1")
        mini = min(h1.GetBinLowEdge(1), h2.GetBinLowEdge(1))
        maxi = max(h2.GetBinLowEdge(h2.GetNbinsX() + 2),
                   h1.GetBinLowEdge(h1.GetNbinsX() + 2))
        h1 = getHisto(tree1, plot, weight="1", firstBin=mini, lastBin=maxi)
        h2 = getHisto(tree2, plot, weight="1", firstBin=mini, lastBin=maxi)

    h2.SetLineColor(2)
    mh = Multihisto()
    name1 = getVersion(filenames[0])
    name2 = getVersion(filenames[1])
    mh.addHisto(h1, name1, draw="hist e")
    mh.addHisto(h2, name2, draw="hist e")
    mh.Draw()
    from myRatio import Ratio
    r = Ratio("%s/%s" % (name1, name2), h1, h2)
    r.draw()

    plot = "test"
    ROOT.gPad.GetCanvas().SaveAs("compareFiles_%s.pdf" % plot)
コード例 #5
0
ファイル: ewkClosure.py プロジェクト: kkiesel/singlePhoton
def closure(filenames, plot):
    commonCut = "[email protected]() && [email protected]()"
    # if plot != "met": commonCut += " && met>=100"

    gHist = getHists(filenames, plot, cut="(photons[0].isStatus(1)) && " + commonCut)
    eHist = multiDimFakeRate(filenames, plot, commonCut, isData=False)
    gHist.SetName("gHist")
    eHist.SetName("eHist")

    eHistSys = eHist.Clone("eHistSys")
    eHistSys = setRelativeUncertainty(eHistSys, 0.11)
    eHistSys.SetFillColor(eHistSys.GetLineColor())
    eHistSys.SetFillStyle(3354)
    eHistSys.SetMarkerSize(0)
    eHistSys.SetName("eHistSys")

    gDatasetAbbrs = [getDatasetAbbr(f) for f in filenames]
    gDatasetAbbrs = mergeDatasetAbbr(gDatasetAbbrs)

    multihisto = Multihisto()
    multihisto.leg = myLegend(0.63, 0.75, 0.96, 0.94)
    multihisto.leg.SetTextSize(0.035)
    multihisto.leg.SetTextFont(42)

    multihisto.leg.SetHeader(",".join([datasetToLatex(x) for x in gDatasetAbbrs]))
    multihisto.addHisto(gHist, "Direct Simulation", draw="p e x0")
    multihisto.addHisto(eHist, "", draw="hist")
    multihisto.addHisto(eHistSys, "Prediction", draw="e2")

    infoText = ROOT.TLatex()
    infoText.SetNDC()
    infoText.SetTextFont(gHist.GetLabelFont())
    infoText.SetTextSize(gHist.GetLabelSize())
    infoText.SetText(
        0.02, 0.96, "CMS Simulation                         19.7fb^{-1} (8 TeV)          #geq1#gamma,#geq2jets"
    )

    can = ROOT.TCanvas("c1", "", 600, 600)
    can.cd()
    multihisto.Draw()
    infoText.Draw()
    r = Ratio("Direct/Pred.", gHist, eHist, eHistSys)
    r.draw(0, 2)
    SaveAs(can, "ewkClosure_%s_%s" % (getSaveNameFromDatasets(filenames), plot))
    ROOT.gPad.SaveAs("plots/ewkClosure_%s_%s.C" % (getSaveNameFromDatasets(filenames), plot))

    ewkOut = ROOT.TFile("ewkOout.root", "recreate")
    ewkOut.cd()
    for h in gHist, eHist, eHistSys:
        h.Write()
    ewkOut.Close()

    ROOT.SetOwnership(can, False)
    del can
コード例 #6
0
ファイル: qcdClosure.py プロジェクト: kkiesel/singlePhoton
def drawClosure(filenames,
                predFilenames,
                plot,
                commonCut,
                infoText,
                additionalLabel="",
                modifyEmptyBins=True):
    infoText = ROOT.TLatex(
        0, .96,
        "CMS Private Work 19.7fb^{-1} #sqrt{s}=8TeV #geq1#gamma,#geq2jets")
    infoText.SetNDC()
    infoText.SetTextSize(0.045)

    gHist = getHists(filenames, plot, commonCut)
    fHist, sysHist = predictionHistos(predFilenames, plot, commonCut,
                                      modifyEmptyBins)
    fHist.SetMarkerSize(0)
    sysHist.SetFillStyle(3254)
    sysHist.SetFillColor(sysHist.GetLineColor())
    sysHist.SetLineColor(0)

    signalAbbrs = mergeDatasetAbbr([getDatasetAbbr(x) for x in filenames])

    muhisto = Multihisto()
    muhisto.leg.SetHeader(",".join([datasetToLatex(x) for x in signalAbbrs]))
    muhisto.addHisto(gHist, "Simulation", draw="")
    muhisto.addHisto(fHist, "Prediction", draw="hist e")
    muhisto.addHisto(sysHist, "syst. uncert", draw="e2")
    muhisto.addHisto(gHist, "", draw="e0")  ## add a second time to draw on top

    can = ROOT.TCanvas("", "", 1000, 1200)
    can.cd()

    muhisto.Draw()

    from myRatio import Ratio
    r = Ratio("Sim./Pred.", gHist, fHist, sysHist)
    r.draw(0., 2)
    infoText.Draw()
    muhisto.leg.AddEntry(r.totalUncert, "total uncert", "f")
    muhisto.leg.Draw()
    SaveAs(can,
           "qcdClosure_%s_%s" % ("".join(signalAbbrs) + additionalLabel, plot))

    # Since root is too stupid to clear the canvas before python is ending, clean
    # the canvas yourself
    ROOT.SetOwnership(can, False)
    del can
コード例 #7
0
ファイル: ewkPrediction.py プロジェクト: kkiesel/singlePhoton
def closure( filenames, plot ):
	leptonPtCut = 15 # only larger than 15 make sense here, since this is the reprocessing cut
	commonCut = "([email protected]() || Max$(electrons.pt)<{0}) && ([email protected]() || Max$(muons.pt)<{0})".format(leptonPtCut)
	#commonCut = "1"


	totalHist = getHists( filenames, plot, cut=commonCut )
	gGenHist = getHists( filenames, plot, cut="photons[0].isGen(0) && "+commonCut )
	eHist = multiDimFakeRate( filenames, plot, commonCut, False )
	fakeHist = predictionHistos( filenames, plot, cut=commonCut )[0]
	fakeHist.SetLineColor(4)
	eHist.SetLineColor(3)
	gGenHist.SetLineColor(2)

	eHistSys = eHist.Clone( randomName() )
	eHistSys = setRelativeUncertainty( eHistSys, 0.11 )
	eHistSys.SetFillColor( eHistSys.GetLineColor() )
	eHistSys.SetFillStyle(3354)
	eHistSys.SetMarkerSize(0)

	gDatasetAbbrs = [getDatasetAbbr(f) for f in filenames ]
	gDatasetAbbrs = mergeDatasetAbbr( gDatasetAbbrs )

	multihisto = Multihisto()
	multihisto.setMinimum(0.01)
	multihisto.setMaximum(20)
	multihisto.leg.SetHeader( "/".join([ datasetToLatex(x) for x in gDatasetAbbrs]) )
	multihisto.addHisto( totalHist, "Simulation", draw="e0 hist" )
	multihisto.addHisto( fakeHist, "QCD", toStack=True, draw="hist" )
	multihisto.addHisto( gGenHist, "gen#gamma", toStack=True, draw="e0 hist" )
	multihisto.addHisto( eHist, "e#rightarrow#gamma", toStack=True, draw="hist" )

	infoText = ROOT.TLatex(0.03,.96, "CMS Private Work - 8TeV #geq1#gamma,#geq2jets" )
	infoText.SetNDC()

	can = ROOT.TCanvas()
	can.cd()
	multihisto.Draw()
	infoText.Draw()
	r = Ratio( "Sim./Pred.", totalHist, multihisto.stack.GetStack().Last() )
	r.draw(0,2)
	SaveAs( can, "ewkPrediction_%s_%s"%(getSaveNameFromDatasets(filenames), plot))

	ROOT.SetOwnership( can, False )
	del can
コード例 #8
0
def drawClosure( plot, gTree, foTree, cut, can, info, datasetAbbr, additionalInfo="" ):

		# The first attempt to get the histogram is only to get the minimal
		# and maximal value on the x-axis, for not predefined binning
		h_gamma = getHisto( gTree, plot,cut=cut )
		h_fo = getHisto( foTree, plot, cut=cut )
		xMin, xMax = getXMinXMax( [ h_gamma, h_fo ] )

		h_gamma = getHisto( gTree, plot, cut=cut, color=1, firstBin=xMin,lastBin=xMax )
		h_fo = getHisto( foTree, plot, cut=cut, weight="weight*w_qcd", color=46, firstBin=xMin,lastBin=xMax )
		h_fo_error = getQCDErrorHisto( foTree, plot, cut=cut, firstBin=xMin, lastBin=xMax )
		h_fo_error.SetFillColor( h_fo.GetLineColor() )
		h_fo_error.SetLineColor( h_fo_error.GetLineColor() )
		h_fo_error.SetFillStyle(3254)
		h_fo_error.SetMarkerSize(0)

		muhisto = Multihisto()
		muhisto.leg.SetHeader( datasetToLatex( datasetAbbr ) )
		muhisto.addHisto( h_gamma, "#gamma", draw="hist e0" )
		muhisto.addHisto( h_fo, "#gamma_{jet}#upointw", draw="hist e0")
		muhisto.addHisto( h_fo_error, "#sigma_{w}", draw="e2")

		hPad = ROOT.TPad("hPad", "Histogram", 0, 0.2, 1, 1)
		hPad.cd()
		muhisto.Draw()

		ratioPad = ROOT.TPad("ratioPad", "Ratio", 0, 0, 1, 0.2)
		ratioPad.cd()
		ratioPad.SetLogy( False )
		from myRatio import Ratio
		r = Ratio( "#gamma/#gamma_{pred}", h_gamma, h_fo )
		ratio, sys, one = r.draw(0,2)
		ratio.Draw("e1")
		sys.Draw("same e2")
		one.Draw()

		can.cd()
		hPad.Draw()
		ratioPad.Draw()
		info.Draw()
		SaveAs(can, "qcd_afterWeighting_%s_%s_%s"%(datasetAbbr+additionalInfo, plot,reweightVar) )
		ROOT.SetOwnership( hPad, False )
		ROOT.SetOwnership( ratioPad, False )
コード例 #9
0
def compareTrees( plot="photons.pt", filename="slimQCD_V02.28_tree.root" ):
	label, unit, binning = readAxisConf( "photons[0].ptJet()" )
	#binning = range(0,70,10) + binning
	#binning = range(0,1000, 30 )
	import array
	gH = ROOT.TH1F( randomName(), ";jet_{x};", len(binning)-1, array.array('d', binning) )
	fH = gH.Clone( randomName() )
	fH.SetLineColor(2)
	fH.SetMarkerColor(2)
	#cut = "!photons[0].isGen(0)"
	#cut = "1"

	gTree = readTree( filename, "photonTree" )
	fTree = readTree( filename, "photonJetTree" )

	#gH = getHisto( gTree, plot, color=1, cut=cut,firstBin=0,lastBin=1400 )
	#fH = getHisto( fTree, plot, color=2, cut=cut,firstBin=0,lastBin=1400 )

	for h, tree in [(gH, gTree), (fH, fTree)]:
		h.Sumw2()
		for event in tree:
			h.Fill( getFromEvent( event ), event.weight )


	for h in [gH, fH]:
		h.Scale( 1, "width" )

	mh = Multihisto()
	mh.addHisto( gH, "#gamma", draw="hist e" )
	mh.addHisto( fH, "#gamma_{jet}", draw="hist e" )

	can = ROOT.TCanvas()
	can.cd()
	mh.Draw()


	from myRatio import Ratio
	r = Ratio( "#gamma/#gamma_{jet}", gH, fH )
	r.draw(None,2)


	SaveAs( can, "compare_test" )
コード例 #10
0
ファイル: optimizeFoId.py プロジェクト: kkiesel/singlePhoton
def compareHists( filenames, tight, fcut, draw=False ):
	loose = getHistoFromFiles( "met", "photonJetTree", filenames, fcut )
	loose.SetLineColor(2)
	if loose.Integral(0,loose.FindBin(99)):
		loose.Scale( tight.Integral(0,loose.FindBin(99)) / loose.Integral(0,loose.FindBin(99)) )
	option = "uu norm" if filenames[0].startswith("PhotonHad") else "ww"
	if draw:

		c = ROOT.TCanvas()
		c.cd()
		mh = Multihisto()
		mh.addHisto( tight.Clone( randomName() ), "#gamma_{tight}", draw="hist e")
		mh.addHisto( loose, "#gamma_{loose}", draw="hist e")
		mh.Draw()
		from myRatio import Ratio
		r = Ratio( "#gamma_{tight}/#gamma_{loose}", tight, loose )
		r.draw(0,2)
		c.SaveAs("plots/findFoId_%s_twoDistributions_%s.pdf"%(getSaveNameFromDatasets(filenames),''.join([s for s in fcut if s.isdigit()])) )

	return tight.Chi2Test( loose, option )
コード例 #11
0
def compareTrees(plot="photons.pt", filename="slimQCD_V02.28_tree.root"):
    label, unit, binning = readAxisConf("photons[0].ptJet()")
    #binning = range(0,70,10) + binning
    #binning = range(0,1000, 30 )
    import array
    gH = ROOT.TH1F(randomName(), ";jet_{x};",
                   len(binning) - 1, array.array('d', binning))
    fH = gH.Clone(randomName())
    fH.SetLineColor(2)
    fH.SetMarkerColor(2)
    #cut = "!photons[0].isGen(0)"
    #cut = "1"

    gTree = readTree(filename, "photonTree")
    fTree = readTree(filename, "photonJetTree")

    #gH = getHisto( gTree, plot, color=1, cut=cut,firstBin=0,lastBin=1400 )
    #fH = getHisto( fTree, plot, color=2, cut=cut,firstBin=0,lastBin=1400 )

    for h, tree in [(gH, gTree), (fH, fTree)]:
        h.Sumw2()
        for event in tree:
            h.Fill(getFromEvent(event), event.weight)

    for h in [gH, fH]:
        h.Scale(1, "width")

    mh = Multihisto()
    mh.addHisto(gH, "#gamma", draw="hist e")
    mh.addHisto(fH, "#gamma_{jet}", draw="hist e")

    can = ROOT.TCanvas()
    can.cd()
    mh.Draw()

    from myRatio import Ratio
    r = Ratio("#gamma/#gamma_{jet}", gH, fH)
    r.draw(None, 2)

    SaveAs(can, "compare_test")
コード例 #12
0
ファイル: qcdClosure.py プロジェクト: kkiesel/singlePhoton
def drawTwoHists( gHist, fHist, sHist, saveName, minmax ):
	for bin in range( sHist.GetNbinsX()+2 ):
		sHist.SetBinError( bin, sHist.GetBinContent(bin) )
		sHist.SetBinContent( bin, fHist.GetBinContent(bin) )

	sHist.SetFillColor( sHist.GetLineColor() )
	sHist.SetLineColor( sHist.GetLineColor() )
	sHist.SetFillStyle(3254)
	sHist.SetMarkerSize(0)
	fHist.SetLineColor(2)
	sHist.SetLineColor(2)


	for h in gHist, fHist, sHist:
		from inheritRoot import H1F
		h.__class__ = H1F
		h.MergeOverflow()
		h.Scale(1., "width")

	muhisto = Multihisto()
	muhisto.addHisto( gHist, "Simulation", draw="hist e" )
	muhisto.addHisto( fHist, "Prediction", draw="hist")
	muhisto.addHisto( sHist, "#sigma_{w}", draw="e2")

	can = ROOT.TCanvas(randomName(), "", 1000, 1200)
	can.cd()
	muhisto.Draw()
	text = ROOT.TLatex(.1,.965, "%i #leq p_{T^{*}} < %i, %i #leq H_{T} < %i"%minmax)
	text.SetNDC()
	text.Draw()

	from myRatio import Ratio
	r = Ratio( "Sim./Pred.", gHist, fHist )
	r.draw(0,2)

	can.SaveAs(saveName+".pdf")

	ROOT.SetOwnership( can, False )
	del can
コード例 #13
0
ファイル: qcdClosure.py プロジェクト: kkiesel/singlePhoton
def drawClosure( filenames, predFilenames, plot, commonCut, infoText, additionalLabel="", modifyEmptyBins=True ):
	infoText = ROOT.TLatex(0,.96, "CMS Private Work 19.7fb^{-1} #sqrt{s}=8TeV #geq1#gamma,#geq2jets" )
	infoText.SetNDC()
	infoText.SetTextSize(0.045)

	gHist = getHists( filenames, plot, commonCut )
	fHist, sysHist = predictionHistos( predFilenames, plot, commonCut, modifyEmptyBins )
	fHist.SetMarkerSize(0)
	sysHist.SetFillStyle(3254)
	sysHist.SetFillColor( sysHist.GetLineColor() )
	sysHist.SetLineColor(0)


	signalAbbrs = mergeDatasetAbbr( [ getDatasetAbbr(x) for x in filenames ] )

	muhisto = Multihisto()
	muhisto.leg.SetHeader( ",".join( [ datasetToLatex(x) for x in signalAbbrs ] ) )
	muhisto.addHisto( gHist, "Simulation", draw="" )
	muhisto.addHisto( fHist, "Prediction", draw="hist e")
	muhisto.addHisto( sysHist, "syst. uncert", draw="e2")
	muhisto.addHisto( gHist, "", draw="e0" ) ## add a second time to draw on top

	can = ROOT.TCanvas("", "", 1000, 1200)
	can.cd()

	muhisto.Draw()

	from myRatio import Ratio
	r = Ratio( "Sim./Pred.", gHist, fHist, sysHist )
	r.draw(0.,2)
	infoText.Draw()
	muhisto.leg.AddEntry( r.totalUncert, "total uncert", "f" )
	muhisto.leg.Draw()
	SaveAs(can, "qcdClosure_%s_%s"%("".join(signalAbbrs)+additionalLabel, plot) )

	# Since root is too stupid to clear the canvas before python is ending, clean
	# the canvas yourself
	ROOT.SetOwnership( can, False )
	del can
コード例 #14
0
ファイル: qcdClosure.py プロジェクト: kkiesel/singlePhoton
def drawTwoHists(gHist, fHist, sHist, saveName, minmax):
    for bin in range(sHist.GetNbinsX() + 2):
        sHist.SetBinError(bin, sHist.GetBinContent(bin))
        sHist.SetBinContent(bin, fHist.GetBinContent(bin))

    sHist.SetFillColor(sHist.GetLineColor())
    sHist.SetLineColor(sHist.GetLineColor())
    sHist.SetFillStyle(3254)
    sHist.SetMarkerSize(0)
    fHist.SetLineColor(2)
    sHist.SetLineColor(2)

    for h in gHist, fHist, sHist:
        from inheritRoot import H1F
        h.__class__ = H1F
        h.MergeOverflow()
        h.Scale(1., "width")

    muhisto = Multihisto()
    muhisto.addHisto(gHist, "Simulation", draw="hist e")
    muhisto.addHisto(fHist, "Prediction", draw="hist")
    muhisto.addHisto(sHist, "#sigma_{w}", draw="e2")

    can = ROOT.TCanvas(randomName(), "", 1000, 1200)
    can.cd()
    muhisto.Draw()
    text = ROOT.TLatex(.1, .965,
                       "%i #leq p_{T^{*}} < %i, %i #leq H_{T} < %i" % minmax)
    text.SetNDC()
    text.Draw()

    from myRatio import Ratio
    r = Ratio("Sim./Pred.", gHist, fHist)
    r.draw(0, 2)

    can.SaveAs(saveName + ".pdf")

    ROOT.SetOwnership(can, False)
    del can
コード例 #15
0
ファイル: justRatio.py プロジェクト: kkiesel/singlePhoton
def compareTrees( plot="met", filenames=["slimAllQCD_V02.28_tree.root"], drawRatio=False ):
	cut = "1"
	fcut = cut
	fcut += "&& photons[0].chargedIso/10<2.6 && photons[0].neutralIso/10<3.5+0.04*photons[0].pt && photonIso/10<1.3+0.005*photons[0].pt"
	fcut += "&& photons[0].chargedIso*10>2.6 && photons[0].neutralIso*10>3.5+0.04*photons[0].pt && photonIso*10>1.3+0.005*photons[0].pt"


	gH = getHistoFromFiles( plot, "photonTree", filenames, cut )
	fH = getHistoFromFiles( plot, "photonJetTree", filenames, fcut, color=1 )
	#fH = getHistoFromFiles( plot, "photonTree", filenames, cut+"&& fabs(photons[0].eta)>=%s"%etaCut )



	ratio = gH.Clone( randomName() )
	ratio.Divide( fH )
	ratio.SetYTitle( "#gamma_{tight}/#gamma_{loose}" )


	can = ROOT.TCanvas()
	can.SetLogy(0)
	can.cd()
	ratio.Draw(" e")

	pc1 = ROOT.TLatex(0,.96, "CMS Private Work")
	pc2 = ROOT.TLatex( .42,.96, "\SI{19.8}{fb^{-1}} #sqrt{s}=\SI{8}{TeV}#, #geq1#ggamma(#geq1#fgamma),#geq2#text{jets}")
	for pc in [pc1, pc2]:
		pc.SetNDC()
		pc.SetTextSize(0.06311227345609463)
		pc.Draw()


	if drawRatio:
		from myRatio import Ratio
		r = Ratio( "#gamma/#gamma_{jet}", gH, fH )
		r.draw()

	#can.SetFillColor(ROOT.kGreen)
	SavePad( "ratioCompare2_%s_%s"%(plot,shortName( filenames )) )
コード例 #16
0
def compareTrees( plot="photons.pt", filename="slimAllQCD_V02.28_tree.root" ):
	label, unit, binning = readAxisConf( "ht" )
	import array
	fH = ROOT.TH1F( randomName(), ";%s;"%label, len(binning)-1, array.array('d', binning) )
	fH.SetLineColor(2)
	fH.SetMarkerColor(2)
	fH.Sumw2()
	#cut = "!photons[0].isGen(0)"
	cut = "1"

	gTree = readTree( filename, "photonTree" )
	fTree = readTree( filename, "photonJetTree" )

	gH = getHisto( gTree, "ht", color=1, cut=cut,firstBin=0,lastBin=1400 )
	#fH = getHisto( fTree, plot, color=2, cut=cut,firstBin=0,lastBin=1400 )

	for event in fTree:
		fH.Fill( getFromEvent( event ) )


	for h in [gH, fH]:
		h.Scale( 1./h.Integral() )

	mh = Multihisto()
	mh.addHisto( gH, "new", draw="hist e" )
	mh.addHisto( fH, "old (recalculated)", draw="hist e" )

	can = ROOT.TCanvas()
	can.cd()
	mh.Draw()


	from myRatio import Ratio
	r = Ratio( "#gamma/#gamma_{jet}", gH, fH )
	r.draw(0,2)


	SaveAs( can, "compare_%s_norm"%plot )
コード例 #17
0
ファイル: justRatio.py プロジェクト: kkiesel/singlePhoton
def compareTrees(plot="met",
                 filenames=["slimAllQCD_V02.28_tree.root"],
                 drawRatio=False):
    cut = "1"
    fcut = cut
    fcut += "&& photons[0].chargedIso/10<2.6 && photons[0].neutralIso/10<3.5+0.04*photons[0].pt && photonIso/10<1.3+0.005*photons[0].pt"
    fcut += "&& photons[0].chargedIso*10>2.6 && photons[0].neutralIso*10>3.5+0.04*photons[0].pt && photonIso*10>1.3+0.005*photons[0].pt"

    gH = getHistoFromFiles(plot, "photonTree", filenames, cut)
    fH = getHistoFromFiles(plot, "photonJetTree", filenames, fcut, color=1)
    #fH = getHistoFromFiles( plot, "photonTree", filenames, cut+"&& fabs(photons[0].eta)>=%s"%etaCut )

    ratio = gH.Clone(randomName())
    ratio.Divide(fH)
    ratio.SetYTitle("#gamma_{tight}/#gamma_{loose}")

    can = ROOT.TCanvas()
    can.SetLogy(0)
    can.cd()
    ratio.Draw(" e")

    pc1 = ROOT.TLatex(0, .96, "CMS Private Work")
    pc2 = ROOT.TLatex(
        .42, .96,
        "\SI{19.8}{fb^{-1}} #sqrt{s}=\SI{8}{TeV}#, #geq1#ggamma(#geq1#fgamma),#geq2#text{jets}"
    )
    for pc in [pc1, pc2]:
        pc.SetNDC()
        pc.SetTextSize(0.06311227345609463)
        pc.Draw()

    if drawRatio:
        from myRatio import Ratio
        r = Ratio("#gamma/#gamma_{jet}", gH, fH)
        r.draw()

    #can.SetFillColor(ROOT.kGreen)
    SavePad("ratioCompare2_%s_%s" % (plot, shortName(filenames)))
コード例 #18
0
def drawComparison( histName, mc, data ):
	hdata = getIsolationHist( data, histName )
	hdata.SetLineColor(1)


	hmc = getIsolationHist( mc, histName )
	hmc.SetLineColor(2)
	for h in hmc, hdata:
		h.SetLineWidth(2)

	hmc.Scale( hdata.Integral() / hmc.Integral() )

	mh = Multihisto()
	mh.addHisto( hdata, "Data", draw="e0" )
	mh.addHisto( hmc, "MC", draw="hist", toStack=True )
	c = ROOT.TCanvas()
	mh.Draw()

	from myRatio import Ratio
	r = Ratio( "Data/Bkg", hdata, hmc )
	r.draw(0,2)

	SavePad("isolationComparison_%s"%histName )
コード例 #19
0
def compareTrees(plot="photons.pt", filename="slimAllQCD_V02.28_tree.root"):
    label, unit, binning = readAxisConf("ht")
    import array
    fH = ROOT.TH1F(randomName(), ";%s;" % label,
                   len(binning) - 1, array.array('d', binning))
    fH.SetLineColor(2)
    fH.SetMarkerColor(2)
    fH.Sumw2()
    #cut = "!photons[0].isGen(0)"
    cut = "1"

    gTree = readTree(filename, "photonTree")
    fTree = readTree(filename, "photonJetTree")

    gH = getHisto(gTree, "ht", color=1, cut=cut, firstBin=0, lastBin=1400)
    #fH = getHisto( fTree, plot, color=2, cut=cut,firstBin=0,lastBin=1400 )

    for event in fTree:
        fH.Fill(getFromEvent(event))

    for h in [gH, fH]:
        h.Scale(1. / h.Integral())

    mh = Multihisto()
    mh.addHisto(gH, "new", draw="hist e")
    mh.addHisto(fH, "old (recalculated)", draw="hist e")

    can = ROOT.TCanvas()
    can.cd()
    mh.Draw()

    from myRatio import Ratio
    r = Ratio("#gamma/#gamma_{jet}", gH, fH)
    r.draw(0, 2)

    SaveAs(can, "compare_%s_norm" % plot)
コード例 #20
0
ファイル: optimizeFoId.py プロジェクト: kkiesel/singlePhoton
def compareHists(filenames, tight, fcut, draw=False):
    loose = getHistoFromFiles("met", "photonJetTree", filenames, fcut)
    loose.SetLineColor(2)
    if loose.Integral(0, loose.FindBin(99)):
        loose.Scale(
            tight.Integral(0, loose.FindBin(99)) /
            loose.Integral(0, loose.FindBin(99)))
    option = "uu norm" if filenames[0].startswith("PhotonHad") else "ww"
    if draw:

        c = ROOT.TCanvas()
        c.cd()
        mh = Multihisto()
        mh.addHisto(tight.Clone(randomName()), "#gamma_{tight}", draw="hist e")
        mh.addHisto(loose, "#gamma_{loose}", draw="hist e")
        mh.Draw()
        from myRatio import Ratio
        r = Ratio("#gamma_{tight}/#gamma_{loose}", tight, loose)
        r.draw(0, 2)
        c.SaveAs("plots/findFoId_%s_twoDistributions_%s.pdf" %
                 (getSaveNameFromDatasets(filenames), ''.join(
                     [s for s in fcut if s.isdigit()])))

    return tight.Chi2Test(loose, option)
コード例 #21
0
ファイル: simpleDraw.py プロジェクト: kkiesel/singlePhoton
def compareTrees(plot="met",
                 filenames=["slimAllQCD_V02.28_tree.root"],
                 drawRatio=False):
    #cut = "@electrons.size()==0 && @muons.size()==0"
    #cut = plot+">110"
    #cut = "!photons[0].isGen(0)"
    #cut = "ht < 600"
    cut = "1"

    gH = getHistoFromFiles(plot, "photonTree", filenames, "1")
    fH = getHistoFromFiles(plot, "photonJetTree", filenames, "1", color=2)

    for h in [gH, fH]:
        #h.Scale( 1./h.Integral() )
        h.SetMarkerSize(0)
        h.GetXaxis().SetTitleOffset(1.03)
        h.GetYaxis().SetTitleOffset(1.5)
        h.GetXaxis().SetLabelSize(0.0633790992496425)
        h.GetXaxis().SetTitleSize(0.0633790992496425)
        h.GetYaxis().SetLabelSize(0.0633790992496425)
        h.GetYaxis().SetTitleSize(0.0633790992496425)
        h.GetYaxis().SetLabelOffset(0)

        if plot == "photons[0].pt":
            h.GetXaxis().SetTitle("$p_{T}$ [GeV]")
        if plot == "photons[0].ptJet()":
            h.GetXaxis().SetTitle("$p_{T^*}$ [GeV]")

    ratio = gH.Clone(randomName())
    ratio.Divide(fH)

    mh = Multihisto()
    #mh.leg.SetX1(0.608)
    #mh.leg.SetX2(0.95)
    mh.addHisto(gH, "#gamma_{#text{tight}}", draw="hist e")
    mh.addHisto(fH, "#gamma_{#text{loose}}", draw="hist e")

    can = ROOT.TCanvas()
    #can.SetBottomMargin(0)
    #can.SetTopMargin(0)
    #can.SetRightMargin(0)
    #can.SetLeftMargin(0.19)
    can.cd()
    mh.Draw()

    pc1 = ROOT.TLatex(0, .96, "CMS Private Work")
    pc2 = ROOT.TLatex(.51, .96, "\SI{19.8}{fb^{-1}} #sqrt{s}=\SI{8}{TeV}")
    for pc in [pc1, pc2]:
        pc.SetNDC()
        pc.SetTextSize(0.06311227345609463)
        pc.Draw()

    if drawRatio:
        from myRatio import Ratio
        r = Ratio("#gamma/#gamma_{jet}", gH, fH)
        r.draw()

    #can.SetFillColor(ROOT.kGreen)
    SavePad("compare2_%s_%s" % ("test", shortName(filenames)))
    #ROOT.gPad.SaveAs("~/master/documents/thesis/plots/compare_%s_%s.tex"%(manipulateSaveName(plot),shortName( filenames )) )
    ROOT.SetOwnership(can, False)
コード例 #22
0
def finalDistributionData( plot ):

	# Sample names
	treeVersion = "31"
	wg = [ "slimWGamma_50_130_V03.%s_tree.root"%treeVersion, \
			"slimWGamma_130_inf_V03.%s_tree.root"%treeVersion ]
	tg = [ "slimTTGamma_V03.%s_tree.root"%treeVersion ]
	zgn = [ "slimZGammaNuNu_V03.%s_tree.root"%treeVersion ]
	zgll = [ "slimZGammaLL_V02.19b_tree.root" ]
	data = [ "PhotonHad%s_V03.%s_tree.root"%(x,treeVersion) for x in ["A","B","C","D" ] ]

	# additional ISR uncertainty
	ewkUncertainty = 0.11
	isrUncertaintyZ = 0.5
	isrUncertaintyW = 0.5
	isrUncertaintyT = 0.5
	isrUncertainty = 0.5


	leptonPtCut = 25 # only larger than 15 make sense here, since this is the reprocessing cut
	#commonCut = "([email protected]() || Max$(electrons.pt)<{0}) && ([email protected]() || Max$(muons.pt)<{0})".format(leptonPtCut)
	commonCut = "[email protected]() && [email protected]() && thisPt>0 && recoilChr > 0"

	# Compute the weights:
	weight2D = getMixedWeigthHisto( data, data, commonCut )
	attachWeightsToFiles( data, weight2D, "foWeights" )
	drawWeightHisto( weight2D, "Data", writeWeightFile=True )

	# Get Histograms
	dataHist = getHists( data, plot, commonCut )
	fgammaHist, fgammaWeightError = predictionHistos( data, plot, commonCut, modifyEmptyBins=False )

	egammaHist = multiDimFakeRate( data, plot, commonCut )
	egammaHistsys = setRelativeUncertainty( egammaHist.Clone(randomName()), ewkUncertainty )

	fsrZ = getHists( zgn, plot, commonCut+"&&genPhotons[0].pt>130" )
	fsrZll = getHists( zgll, plot, commonCut )
	if plot=="met":
		fsrZ2 = getHists( zgll, plot+"LL", commonCut+"&&genPhotons[0].pt<130" )
	else:
		fsrZ2 = getHists( zgll, plot, commonCut+"&&0" )
	fsrZ2.Scale( 20./(2.*3.363) )
	fsrW = getHists( wg, plot, commonCut )
	fsrT = getHists( tg, plot, commonCut )

	# apply common scale factor
	for h in fsrW, fsrT, fsrZ, fsrZ2, fsrZll:
		h.Scale(1.5)

	fsr = addHistos( [fsrT, fsrW, fsrZ, fsrZ2,fsrZll ] )
	fsr.SetLineColor(ROOT.kRed)
	fsrSys = setRelativeUncertainty( fsr, isrUncertainty )

	#signal1 = getMetHisto( "W", 900, 1720 )
	#signal2 = getMetHisto( "B", 1700, 1120 )
	signal1 = getHists( ["slimW_1700_720_375_V03.06_tree.root"], plot, commonCut )
	signal2 = getHists( ["slimW_900_1720_375_V03.06_tree.root"], plot, commonCut )
	signal3 = getHists( ["slimB_1300_1720_375_V03.06_tree.root"], plot, commonCut )
	signal4 = getHists( ["slimB_1700_1120_375_V03.06_tree.root"], plot, commonCut )
	for i, signal in enumerate([signal1, signal2, signal3, signal4]):
		signal.SetLineColor( ROOT.kGreen + i )
		signal.SetLineColor( ROOT.kBlue + i )
		#signal.SetLineStyle(5+i)


	# prettify histograms
	fgammaHist.SetLineColor(7)
	egammaHist.SetLineColor( 3 )
	fsrZ.SetLineColor( ROOT.kRed-7 )
	fsrW.SetLineColor( ROOT.kRed-9 )
	fsrT.SetLineColor( ROOT.kRed )

	mh = Multihisto()
	mh.setMinimum(0.2)
	mh.orderByIntegral = False
	mh.addHisto( fsr, "ISR", True )
	mh.addHisto( egammaHist, "e#rightarrow#gamma", True )
	mh.addHisto( fgammaHist, "Multijet", True )
	dataLegName = "Data"
	mh.addHisto( dataHist, dataLegName, draw="pe x0" )
	mh.addHisto( signal2, "Bino-like #chi_{1}^{0}", draw="hist" )
	mh.addHisto( signal1, "Wino-like #chi_{1}^{0}", draw="hist" )


	# get all SYSTEMATICAL uncertainties:
	systematicUncertHistStack = ROOT.THStack()
	systematicUncertHistStack.Add( fgammaWeightError )
	systematicUncertHistStack.Add( egammaHistsys )
	systematicUncertHistStack.Add( fsrSys )


	if plot == "met":
		writeDataCard( treeVersion, dataHist, fgammaHist, fgammaWeightError,
			egammaHist, egammaHistsys,
			fsr, fsrSys )

	# draw stuff
	luminosity = 19.7
	infoText = ROOT.TLatex(0,.96, "CMS Private Work - %sfb^{-1} #sqrt{s}=8TeV #geq1#gamma_{tight},#geq2jets"%luminosity )
	infoText.SetNDC()
	infoText.SetTextSize(.04)

	can = ROOT.TCanvas()
	mh.Draw()
	statUncert = mh.stack.GetStack().Last().Clone( randomName() )
	systUncert = systematicUncertHistStack.GetStack().Last().Clone( randomName() )
	totalUncert = statUncert.Clone( randomName() )
	for bin in range( totalUncert.GetNbinsX()+2 ):
		totalUncert.SetBinError( bin, statUncert.GetBinError(bin) |qPlus| systUncert.GetBinError(bin) )
	for h in statUncert, systUncert, totalUncert:
		h.SetMarkerSize(0)

	totalUncert.SetFillStyle(3002)
	totalUncert.SetFillColor(1)
	totalUncert.Draw("same e2")
	systUncert.SetFillStyle(3254)
	systUncert.SetFillColor(2)
	systUncert.Draw("same e2")
	statUncert.SetLineWidth(3)
	statUncert.SetLineColor(2)
	statUncert.Draw("same e x0")
	dataHist.Draw("same pe x0")

	from myRatio import Ratio
	r = Ratio( "Data / Bkg", dataHist, mh.stack.GetStack().Last(), systematicUncertHistStack.GetStack().Last() )
	r.draw(.5,1.5)

	infoText.Draw()

	SaveAs( can, "finalDistributionData_%s"%plot )
コード例 #23
0
def finalDistributionMC(plot):

    # Sample names
    treeVersion = 12
    g1 = "slimGJets_200_400_V03.%s_tree.root" % treeVersion
    g2 = "slimGJets_400_inf_V03.%s_tree.root" % treeVersion
    q1 = "slimQCD_250_500_V03.%s_tree.root" % treeVersion
    q2 = "slimQCD_500_1000_V03.%s_tree.root" % treeVersion
    q3 = "slimQCD_1000_inf_V03.%s_tree.root" % treeVersion

    tt = "slimTTJets_V03.%s_tree.root" % treeVersion
    w1 = "slimWJets_250_300_V03.%s_tree.root" % treeVersion
    w2 = "slimWJets_300_400_V03.%s_tree.root" % treeVersion
    w3 = "slimWJets_400_inf_V03.%s_tree.root" % treeVersion

    wg1 = "slimWGamma_50_130_V03.%s_tree.root" % treeVersion
    wg2 = "slimWGamma_130_inf_V03.%s_tree.root" % treeVersion
    tg = "slimTTGamma_V03.%s_tree.root" % treeVersion
    zgn = "slimZGammaNuNu_V03.%s_tree.root" % treeVersion
    data = [g1, g2, q1, q2, q3, tt, w1, w2, w3, zgn, wg1, wg2, tg]

    # additional ISR uncertainty
    ewkUncertainty = 0.11
    isrUncertaintyZ = 0.5
    isrUncertaintyW = 0.5
    isrUncertaintyT = 0.5
    isrUncertainty = 0.5

    leptonPtCut = 25  # only larger than 15 make sense here, since this is the reprocessing cut
    commonCut = "([email protected]() || Max$(electrons.pt)<{0}) && ([email protected]() || Max$(muons.pt)<{0})".format(
        leptonPtCut)
    #commonCut = "[email protected]() && [email protected]()"

    # Compute the weights:
    #weight2D = getMixedWeigthHisto( data, data, commonCut )
    #attachWeightsToFiles( data, weight2D, "foWeights" )
    #from qcdClosure import drawWeightHisto
    #drawWeightHisto( weight2D, "MC" )

    # Get Histograms
    dataHist = getHists(data, plot, commonCut)
    fgammaHist, fgammaWeightError = predictionHistos(data,
                                                     plot,
                                                     commonCut,
                                                     modifyEmptyBins=False)

    egammaHist = multiDimFakeRate(data, plot, commonCut, isData=False)
    egammaHistsys = setRelativeUncertainty(egammaHist.Clone(randomName()),
                                           ewkUncertainty)

    fsrZ = getHists([zgn], plot, commonCut)
    fsrZsys = setRelativeUncertainty(fsrZ, isrUncertaintyZ)
    fsrW = getHists([wg1, wg2], plot, commonCut)
    fsrWsys = setRelativeUncertainty(fsrW, isrUncertaintyW)
    fsrT = getHists([tg], plot, commonCut)
    fsrTsys = setRelativeUncertainty(fsrT, isrUncertaintyT)
    fsr = addHistos([fsrT, fsrW, fsrZ])
    fsrSys = setRelativeUncertainty(fsr, isrUncertainty)

    #signal1 = getMetHisto( "W", 900, 1720 )
    #signal2 = getMetHisto( "B", 1700, 1120 )
    signal1 = getHists(["slimW_1700_720_375_V03.06_tree.root"], plot,
                       commonCut)
    signal2 = getHists(["slimW_900_1720_375_V03.06_tree.root"], plot,
                       commonCut)
    signal3 = getHists(["slimB_1300_1720_375_V03.06_tree.root"], plot,
                       commonCut)
    signal4 = getHists(["slimB_1700_1120_375_V03.06_tree.root"], plot,
                       commonCut)
    for i, signal in enumerate([signal1, signal2, signal3, signal4]):
        signal.SetLineColor(ROOT.kGreen + i)
        signal.SetLineColor(ROOT.kBlue + i)
        #signal.SetLineStyle(5+i)

    # prettify histograms
    fgammaHist.SetLineColor(7)
    egammaHist.SetLineColor(3)
    fsrZ.SetLineColor(ROOT.kRed - 7)
    fsrW.SetLineColor(ROOT.kRed - 9)
    fsrT.SetLineColor(ROOT.kRed)

    mh = Multihisto()
    mh.orderByIntegral = False
    mh.addHisto(fsrT, "#gamma t#bar{t}", True)
    mh.addHisto(fsrW, "#gamma W", True)
    mh.addHisto(fsrZ, "#gamma Z", True)
    mh.addHisto(egammaHist, "e#rightarrow#gamma", True)
    mh.addHisto(fgammaHist, "Multijet", True)
    dataLegName = "Data"
    mh.addHisto(dataHist, dataLegName, draw="pe")
    mh.addHisto(signal2, "Bino-like #chi_{1}^{0}", draw="hist")
    mh.addHisto(signal1, "Wino-like #chi_{1}^{0}", draw="hist")

    # get all SYSTEMATICAL uncertainties:
    systematicUncertHistStack = ROOT.THStack()
    systematicUncertHistStack.Add(fgammaWeightError)
    systematicUncertHistStack.Add(egammaHistsys)
    #systematicUncertHistStack.Add( fsrTsys )
    #systematicUncertHistStack.Add( fsrWsys )
    #systematicUncertHistStack.Add( fsrZsys )
    systematicUncertHistStack.Add(fsrSys)

    #if plot == "met":
    #	writeDataCard( treeVersion, dataHist, fgammaHist, fgammaWeightError,
    #		egammaHist, egammaHistsys,
    #		fsr, fsrSys )

    # draw stuff
    luminosity = 19.7
    infoText = ROOT.TLatex(
        0, .96,
        "CMS Private Work - %sfb^{-1} #sqrt{s}=8TeV #geq1#gamma_{tight},#geq2jets"
        % luminosity)
    infoText.SetNDC()
    infoText.SetTextSize(.04)

    can = ROOT.TCanvas()
    mh.Draw()
    errorBand = mh.stack.GetStack().Last().Clone(randomName())
    sysUncert = systematicUncertHistStack.GetStack().Last()
    for bin in range(errorBand.GetNbinsX() + 2):
        errorBand.SetBinError(
            bin,
            errorBand.GetBinError(bin) | qPlus | sysUncert.GetBinError(bin))
    errorBand.SetFillStyle(3002)
    errorBand.SetMarkerSize(0)
    errorBand.SetFillColor(1)
    errorBand.Draw("e2 same")

    from myRatio import Ratio
    r = Ratio("Data / Bkg", dataHist,
              mh.stack.GetStack().Last(),
              systematicUncertHistStack.GetStack().Last())
    r.draw(0.5, 1.5)

    infoText.Draw()

    SaveAs(can, "finalDistributionData_%s" % plot)
コード例 #24
0
def compareTrees(plot="photons.pt",
                 filenames=["slimAllQCD_V02.28_tree.root"],
                 drawRatio=False):
    cut = "1"
    #cut = plot+">110"
    #cut = "!photons[0].isGen(0)"
    #cut = "ht < 600"

    gH = getHistoFromFiles(plot, "photonTree", filenames, cut)
    fH = getHistoFromFiles(plot, "photonJetTree", filenames, cut, color=2)

    weight2D = getMixedWeigthHisto(filenames,
                                   filenames,
                                   cut,
                                   control=True,
                                   fillEmptyBins=False)
    for filename in filenames:
        fTree = readTree(filename, "photonJetTree")
        writeWeight2DToFile(filename, fTree, weight2D, "foWeightsCompare")
    fgammaHist, fgammaWeightError = qcdPredictionHistos(
        filenames, plot, cut, True)
    for bin in range(fgammaHist.GetNbinsX() + 2):
        fgammaHist.SetBinError(
            bin,
            sqrt(
                fgammaHist.GetBinError(bin)**2 +
                fgammaWeightError.GetBinContent(bin)**2))

    fH = fgammaHist

    for h in [gH, fH]:
        h.Scale(1. / h.Integral())
        h.SetMarkerSize(0)
        h.GetXaxis().SetTitleOffset(1.03)
        h.GetYaxis().SetTitleOffset(1.5)
        h.GetXaxis().SetLabelSize(0.0633790992496425)
        h.GetXaxis().SetTitleSize(0.0633790992496425)
        h.GetYaxis().SetLabelSize(0.0633790992496425)
        h.GetYaxis().SetTitleSize(0.0633790992496425)
        h.GetYaxis().SetLabelOffset(0)

        if plot == "photons[0].pt":
            h.GetXaxis().SetTitle("$p_{T}$ [GeV]")
        if plot == "photons[0].ptJet()":
            h.GetXaxis().SetTitle("$p_{T^*}$ [GeV]")

    mh = Multihisto()
    mh.leg.SetX1(0.608)
    mh.leg.SetX2(0.95)
    mh.addHisto(gH, "#gamma_{#text{tight}}", draw="hist e")
    mh.addHisto(fH, "#gamma_{#text{loose}}", draw="hist e")

    can = ROOT.TCanvas()
    #can.SetBottomMargin(0)
    #can.SetTopMargin(0)
    #can.SetRightMargin(0)
    can.SetLeftMargin(0.19)
    can.cd()
    mh.Draw()

    pc1 = ROOT.TLatex(0, .96, "CMS Private Work")
    pc2 = ROOT.TLatex(.51, .96, "\SI{19.8}{fb^{-1}} #sqrt{s}=\SI{8}{TeV}")
    for pc in [pc1, pc2]:
        pc.SetNDC()
        pc.SetTextSize(0.06311227345609463)
        pc.Draw()

    if drawRatio:
        from myRatio import Ratio
        r = Ratio("#gamma/#gamma_{jet}", gH, fH)
        r.draw()

    #can.SetFillColor(ROOT.kGreen)
    SavePad("compare2_%s_%s" % (plot, shortName(filenames)))
    ROOT.gPad.SaveAs("~/master/documents/thesis/plots/compare_%s_%s.tex" %
                     (manipulateSaveName(plot), shortName(filenames)))
    correctTiksPlot(
        "/home/knut/master/documents/thesis/plots/compare_%s_%s.tex" %
        (manipulateSaveName(plot), shortName(filenames)))
    ROOT.SetOwnership(can, False)
コード例 #25
0
def compareTrees( plot="photons.pt", filenames=["slimAllQCD_V02.28_tree.root"], drawRatio=False ):
	cut = "1"
	#cut = plot+">110"
	#cut = "!photons[0].isGen(0)"
	#cut = "ht < 600"

	gH = getHistoFromFiles( plot, "photonTree", filenames, cut )
	fH = getHistoFromFiles( plot, "photonJetTree", filenames, cut, color=2 )

	weight2D = getMixedWeigthHisto( filenames, filenames, cut, control=True, fillEmptyBins=False )
	for filename in filenames:
		fTree = readTree( filename, "photonJetTree" )
		writeWeight2DToFile( filename, fTree, weight2D, "foWeightsCompare" )
	fgammaHist, fgammaWeightError = qcdPredictionHistos( filenames, plot, cut, True )
	for bin in range( fgammaHist.GetNbinsX()+2 ):
		fgammaHist.SetBinError( bin, sqrt( fgammaHist.GetBinError(bin)**2 + fgammaWeightError.GetBinContent(bin)**2 ) )

	fH = fgammaHist


	for h in [gH, fH]:
		h.Scale( 1./h.Integral() )
		h.SetMarkerSize(0)
		h.GetXaxis().SetTitleOffset( 1.03 )
		h.GetYaxis().SetTitleOffset( 1.5 )
		h.GetXaxis().SetLabelSize( 0.0633790992496425 )
		h.GetXaxis().SetTitleSize( 0.0633790992496425 )
		h.GetYaxis().SetLabelSize( 0.0633790992496425 )
		h.GetYaxis().SetTitleSize( 0.0633790992496425 )
		h.GetYaxis().SetLabelOffset(0)

		if plot == "photons[0].pt":
			h.GetXaxis().SetTitle( "$p_{T}$ [GeV]" )
		if plot == "photons[0].ptJet()":
			h.GetXaxis().SetTitle( "$p_{T^*}$ [GeV]" )


	mh = Multihisto()
	mh.leg.SetX1(0.608)
	mh.leg.SetX2(0.95)
	mh.addHisto( gH, "#gamma_{#text{tight}}", draw="hist e" )
	mh.addHisto( fH, "#gamma_{#text{loose}}", draw="hist e" )

	can = ROOT.TCanvas()
	#can.SetBottomMargin(0)
	#can.SetTopMargin(0)
	#can.SetRightMargin(0)
	can.SetLeftMargin(0.19)
	can.cd()
	mh.Draw()

	pc1 = ROOT.TLatex(0,.96, "CMS Private Work")
	pc2 = ROOT.TLatex( .51,.96, "\SI{19.8}{fb^{-1}} #sqrt{s}=\SI{8}{TeV}")
	for pc in [pc1, pc2]:
		pc.SetNDC()
		pc.SetTextSize(0.06311227345609463)
		pc.Draw()


	if drawRatio:
		from myRatio import Ratio
		r = Ratio( "#gamma/#gamma_{jet}", gH, fH )
		r.draw()

	#can.SetFillColor(ROOT.kGreen)
	SavePad( "compare2_%s_%s"%(plot,shortName( filenames )) )
	ROOT.gPad.SaveAs("~/master/documents/thesis/plots/compare_%s_%s.tex"%(manipulateSaveName(plot),shortName( filenames )) )
	correctTiksPlot("/home/knut/master/documents/thesis/plots/compare_%s_%s.tex"%(manipulateSaveName(plot),shortName( filenames )) )
	ROOT.SetOwnership( can, False )
コード例 #26
0
def drawStackedBackground( plot, treeName, listOfFiles, sumBinned, order=False ):

	cut = "[email protected]() && [email protected]()"

	# if a data histogram is present, the mc integral will scaled to data
	mcHists = []
	dataHists = []
	for fileName in listOfFiles:
		datasetAbbr = getDatasetAbbr( fileName )
		try:
			color = colors[datasetAbbr]
		except:
			color = 1
		tree = readTree( fileName, treeName )
		histo = getHisto( tree, plot, color=color, cut=cut )
		if "PhotonHad" in fileName:
			dataHists.append( (datasetAbbr, histo ) )
		else:
			mcHists.append( ( datasetAbbr, histo ) )

	# merge datahists if there
	dataHist = addHistos( [histo for datasetAbbr, histo in dataHists] ) if dataHists else None

	scale = 1.*dataHist.Integral()/addHistos( [histo for datasetAbbr, histo in mcHists] ).Integral() if dataHists else 1
	scale = 1.

	# combine MC datasets
	if sumBinned:
		for combiAbbr, abbrList in combinedDatasets.iteritems():
			if set(abbrList).issubset( set( [ a for a, h in mcHists ] ) ):
				#print "a valid combination was found"
				histosToAdd = [ h for a,h in mcHists if a in abbrList ]
				thisSum = addHistos( histosToAdd )
				mcHists = [ (a,h) for a,h in mcHists if a not in abbrList]+[(combiAbbr,thisSum)]


	mh = Multihisto()
	mh.setMinimum(0.01)
	mh.leg.SetX1NDC(0.5)
	mh.leg.SetY1NDC(0.5)
	mh.orderByIntegral = order
	if dataHist:
		mh.addHisto( dataHist, "Data", draw="e0" )

	for abbr, hist in mcHists:
		hist.Scale( scale )
		mh.addHisto( hist, datasetToLatex(abbr), toStack=True, draw="hist" )

	# add signal histos
	#signalFiles = ["slimW_1000_1020_375_V02.44_tree.root", "slimW_1200_1120_375_V02.44_tree.root"]
	signalFiles = ["slimW_1200_1120_375_V02.44_tree.root"]
	signalFiles = []
	for iColor, sf in enumerate(signalFiles):
		tree = readTree( sf, treeName )
		histo = getHisto( tree, plot, color=ROOT.kMagenta+iColor, cut=cut )
		mh.addHisto( histo, datasetToLatex(getDatasetAbbr(sf)), draw="hist" )

	can = ROOT.TCanvas()
	can.cd()
	mh.Draw()
	info = PlotCaption(treeName=treeName)
	info.Draw()
	if dataHist:
		from myRatio import Ratio
		den = mh.stack.GetStack().Last().Clone( randomName() )
		den.SetLineColor(2)
		r = Ratio( "Data/Sim", dataHist, den )
		r.draw(0,2)

	allDatasetAbbr = getSaveNameFromDatasets( listOfFiles )
	SaveAs( can, "stackedHisto_%s_%s_%s"%(treeName, plot,allDatasetAbbr) )
コード例 #27
0
def drawClosure(plot,
                gTree,
                foTree,
                cut,
                can,
                info,
                datasetAbbr,
                additionalInfo=""):

    # The first attempt to get the histogram is only to get the minimal
    # and maximal value on the x-axis, for not predefined binning
    h_gamma = getHisto(gTree, plot, cut=cut)
    h_fo = getHisto(foTree, plot, cut=cut)
    xMin, xMax = getXMinXMax([h_gamma, h_fo])

    h_gamma = getHisto(gTree,
                       plot,
                       cut=cut,
                       color=1,
                       firstBin=xMin,
                       lastBin=xMax)
    h_fo = getHisto(foTree,
                    plot,
                    cut=cut,
                    weight="weight*w_qcd",
                    color=46,
                    firstBin=xMin,
                    lastBin=xMax)
    h_fo_error = getQCDErrorHisto(foTree,
                                  plot,
                                  cut=cut,
                                  firstBin=xMin,
                                  lastBin=xMax)
    h_fo_error.SetFillColor(h_fo.GetLineColor())
    h_fo_error.SetLineColor(h_fo_error.GetLineColor())
    h_fo_error.SetFillStyle(3254)
    h_fo_error.SetMarkerSize(0)

    muhisto = Multihisto()
    muhisto.leg.SetHeader(datasetToLatex(datasetAbbr))
    muhisto.addHisto(h_gamma, "#gamma", draw="hist e0")
    muhisto.addHisto(h_fo, "#gamma_{jet}#upointw", draw="hist e0")
    muhisto.addHisto(h_fo_error, "#sigma_{w}", draw="e2")

    hPad = ROOT.TPad("hPad", "Histogram", 0, 0.2, 1, 1)
    hPad.cd()
    muhisto.Draw()

    ratioPad = ROOT.TPad("ratioPad", "Ratio", 0, 0, 1, 0.2)
    ratioPad.cd()
    ratioPad.SetLogy(False)
    from myRatio import Ratio
    r = Ratio("#gamma/#gamma_{pred}", h_gamma, h_fo)
    ratio, sys, one = r.draw(0, 2)
    ratio.Draw("e1")
    sys.Draw("same e2")
    one.Draw()

    can.cd()
    hPad.Draw()
    ratioPad.Draw()
    info.Draw()
    SaveAs(
        can, "qcd_afterWeighting_%s_%s_%s" %
        (datasetAbbr + additionalInfo, plot, reweightVar))
    ROOT.SetOwnership(hPad, False)
    ROOT.SetOwnership(ratioPad, False)
コード例 #28
0
def finalDistributionData(plot):

    # Sample names
    treeVersion = "31"
    wg = [ "slimWGamma_50_130_V03.%s_tree.root"%treeVersion, \
      "slimWGamma_130_inf_V03.%s_tree.root"%treeVersion ]
    tg = ["slimTTGamma_V03.%s_tree.root" % treeVersion]
    zgn = ["slimZGammaNuNu_V03.%s_tree.root" % treeVersion]
    zgll = ["slimZGammaLL_V02.19b_tree.root"]
    data = [
        "PhotonHad%s_V03.%s_tree.root" % (x, treeVersion)
        for x in ["A", "B", "C", "D"]
    ]

    # additional ISR uncertainty
    ewkUncertainty = 0.11
    isrUncertaintyZ = 0.5
    isrUncertaintyW = 0.5
    isrUncertaintyT = 0.5
    isrUncertainty = 0.5

    leptonPtCut = 25  # only larger than 15 make sense here, since this is the reprocessing cut
    #commonCut = "([email protected]() || Max$(electrons.pt)<{0}) && ([email protected]() || Max$(muons.pt)<{0})".format(leptonPtCut)
    commonCut = "[email protected]() && [email protected]() && thisPt>0 && recoilChr > 0"

    # Compute the weights:
    weight2D = getMixedWeigthHisto(data, data, commonCut)
    attachWeightsToFiles(data, weight2D, "foWeights")
    drawWeightHisto(weight2D, "Data", writeWeightFile=True)

    # Get Histograms
    dataHist = getHists(data, plot, commonCut)
    fgammaHist, fgammaWeightError = predictionHistos(data,
                                                     plot,
                                                     commonCut,
                                                     modifyEmptyBins=False)

    egammaHist = multiDimFakeRate(data, plot, commonCut)
    egammaHistsys = setRelativeUncertainty(egammaHist.Clone(randomName()),
                                           ewkUncertainty)

    fsrZ = getHists(zgn, plot, commonCut + "&&genPhotons[0].pt>130")
    fsrZll = getHists(zgll, plot, commonCut)
    if plot == "met":
        fsrZ2 = getHists(zgll, plot + "LL",
                         commonCut + "&&genPhotons[0].pt<130")
    else:
        fsrZ2 = getHists(zgll, plot, commonCut + "&&0")
    fsrZ2.Scale(20. / (2. * 3.363))
    fsrW = getHists(wg, plot, commonCut)
    fsrT = getHists(tg, plot, commonCut)

    # apply common scale factor
    for h in fsrW, fsrT, fsrZ, fsrZ2, fsrZll:
        h.Scale(1.5)

    fsr = addHistos([fsrT, fsrW, fsrZ, fsrZ2, fsrZll])
    fsr.SetLineColor(ROOT.kRed)
    fsrSys = setRelativeUncertainty(fsr, isrUncertainty)

    #signal1 = getMetHisto( "W", 900, 1720 )
    #signal2 = getMetHisto( "B", 1700, 1120 )
    signal1 = getHists(["slimW_1700_720_375_V03.06_tree.root"], plot,
                       commonCut)
    signal2 = getHists(["slimW_900_1720_375_V03.06_tree.root"], plot,
                       commonCut)
    signal3 = getHists(["slimB_1300_1720_375_V03.06_tree.root"], plot,
                       commonCut)
    signal4 = getHists(["slimB_1700_1120_375_V03.06_tree.root"], plot,
                       commonCut)
    for i, signal in enumerate([signal1, signal2, signal3, signal4]):
        signal.SetLineColor(ROOT.kGreen + i)
        signal.SetLineColor(ROOT.kBlue + i)
        #signal.SetLineStyle(5+i)

    # prettify histograms
    fgammaHist.SetLineColor(7)
    egammaHist.SetLineColor(3)
    fsrZ.SetLineColor(ROOT.kRed - 7)
    fsrW.SetLineColor(ROOT.kRed - 9)
    fsrT.SetLineColor(ROOT.kRed)

    mh = Multihisto()
    mh.setMinimum(0.2)
    mh.orderByIntegral = False
    mh.addHisto(fsr, "ISR", True)
    mh.addHisto(egammaHist, "e#rightarrow#gamma", True)
    mh.addHisto(fgammaHist, "Multijet", True)
    dataLegName = "Data"
    mh.addHisto(dataHist, dataLegName, draw="pe x0")
    mh.addHisto(signal2, "Bino-like #chi_{1}^{0}", draw="hist")
    mh.addHisto(signal1, "Wino-like #chi_{1}^{0}", draw="hist")

    # get all SYSTEMATICAL uncertainties:
    systematicUncertHistStack = ROOT.THStack()
    systematicUncertHistStack.Add(fgammaWeightError)
    systematicUncertHistStack.Add(egammaHistsys)
    systematicUncertHistStack.Add(fsrSys)

    if plot == "met":
        writeDataCard(treeVersion, dataHist, fgammaHist, fgammaWeightError,
                      egammaHist, egammaHistsys, fsr, fsrSys)

    # draw stuff
    luminosity = 19.7
    infoText = ROOT.TLatex(
        0, .96,
        "CMS Private Work - %sfb^{-1} #sqrt{s}=8TeV #geq1#gamma_{tight},#geq2jets"
        % luminosity)
    infoText.SetNDC()
    infoText.SetTextSize(.04)

    can = ROOT.TCanvas()
    mh.Draw()
    statUncert = mh.stack.GetStack().Last().Clone(randomName())
    systUncert = systematicUncertHistStack.GetStack().Last().Clone(
        randomName())
    totalUncert = statUncert.Clone(randomName())
    for bin in range(totalUncert.GetNbinsX() + 2):
        totalUncert.SetBinError(
            bin,
            statUncert.GetBinError(bin) | qPlus | systUncert.GetBinError(bin))
    for h in statUncert, systUncert, totalUncert:
        h.SetMarkerSize(0)

    totalUncert.SetFillStyle(3002)
    totalUncert.SetFillColor(1)
    totalUncert.Draw("same e2")
    systUncert.SetFillStyle(3254)
    systUncert.SetFillColor(2)
    systUncert.Draw("same e2")
    statUncert.SetLineWidth(3)
    statUncert.SetLineColor(2)
    statUncert.Draw("same e x0")
    dataHist.Draw("same pe x0")

    from myRatio import Ratio
    r = Ratio("Data / Bkg", dataHist,
              mh.stack.GetStack().Last(),
              systematicUncertHistStack.GetStack().Last())
    r.draw(.5, 1.5)

    infoText.Draw()

    SaveAs(can, "finalDistributionData_%s" % plot)
コード例 #29
0
def finalDistributionMC( plot ):

	# Sample names
	treeVersion = 12
	g1 = "slimGJets_200_400_V03.%s_tree.root"%treeVersion
	g2 = "slimGJets_400_inf_V03.%s_tree.root"%treeVersion
	q1 = "slimQCD_250_500_V03.%s_tree.root"%treeVersion
	q2 = "slimQCD_500_1000_V03.%s_tree.root"%treeVersion
	q3 = "slimQCD_1000_inf_V03.%s_tree.root"%treeVersion

	tt = "slimTTJets_V03.%s_tree.root"%treeVersion
	w1 = "slimWJets_250_300_V03.%s_tree.root"%treeVersion
	w2 = "slimWJets_300_400_V03.%s_tree.root"%treeVersion
	w3 = "slimWJets_400_inf_V03.%s_tree.root"%treeVersion


	wg1 = "slimWGamma_50_130_V03.%s_tree.root"%treeVersion
	wg2 = "slimWGamma_130_inf_V03.%s_tree.root"%treeVersion
	tg = "slimTTGamma_V03.%s_tree.root"%treeVersion
	zgn = "slimZGammaNuNu_V03.%s_tree.root"%treeVersion
	data = [ g1, g2, q1, q2, q3, tt, w1, w2, w3, zgn, wg1,wg2,tg ]

	# additional ISR uncertainty
	ewkUncertainty = 0.11
	isrUncertaintyZ = 0.5
	isrUncertaintyW = 0.5
	isrUncertaintyT = 0.5
	isrUncertainty = 0.5


	leptonPtCut = 25 # only larger than 15 make sense here, since this is the reprocessing cut
	commonCut = "([email protected]() || Max$(electrons.pt)<{0}) && ([email protected]() || Max$(muons.pt)<{0})".format(leptonPtCut)
	#commonCut = "[email protected]() && [email protected]()"

	# Compute the weights:
	#weight2D = getMixedWeigthHisto( data, data, commonCut )
	#attachWeightsToFiles( data, weight2D, "foWeights" )
	#from qcdClosure import drawWeightHisto
	#drawWeightHisto( weight2D, "MC" )

	# Get Histograms
	dataHist = getHists( data, plot, commonCut )
	fgammaHist, fgammaWeightError = predictionHistos( data, plot, commonCut, modifyEmptyBins=False )

	egammaHist = multiDimFakeRate( data, plot, commonCut, isData=False )
	egammaHistsys = setRelativeUncertainty( egammaHist.Clone(randomName()), ewkUncertainty )

	fsrZ = getHists( [zgn], plot, commonCut )
	fsrZsys = setRelativeUncertainty( fsrZ, isrUncertaintyZ  )
	fsrW = getHists( [wg1,wg2], plot, commonCut )
	fsrWsys = setRelativeUncertainty( fsrW, isrUncertaintyW  )
	fsrT = getHists( [tg], plot, commonCut )
	fsrTsys = setRelativeUncertainty( fsrT, isrUncertaintyT  )
	fsr = addHistos( [fsrT, fsrW, fsrZ ] )
	fsrSys = setRelativeUncertainty( fsr, isrUncertainty )

	#signal1 = getMetHisto( "W", 900, 1720 )
	#signal2 = getMetHisto( "B", 1700, 1120 )
	signal1 = getHists( ["slimW_1700_720_375_V03.06_tree.root"], plot, commonCut )
	signal2 = getHists( ["slimW_900_1720_375_V03.06_tree.root"], plot, commonCut )
	signal3 = getHists( ["slimB_1300_1720_375_V03.06_tree.root"], plot, commonCut )
	signal4 = getHists( ["slimB_1700_1120_375_V03.06_tree.root"], plot, commonCut )
	for i, signal in enumerate([signal1, signal2, signal3, signal4]):
		signal.SetLineColor( ROOT.kGreen + i )
		signal.SetLineColor( ROOT.kBlue + i )
		#signal.SetLineStyle(5+i)

	# prettify histograms
	fgammaHist.SetLineColor(7)
	egammaHist.SetLineColor( 3 )
	fsrZ.SetLineColor( ROOT.kRed-7 )
	fsrW.SetLineColor( ROOT.kRed-9 )
	fsrT.SetLineColor( ROOT.kRed )

	mh = Multihisto()
	mh.orderByIntegral = False
	mh.addHisto( fsrT, "#gamma t#bar{t}", True )
	mh.addHisto( fsrW, "#gamma W", True )
	mh.addHisto( fsrZ, "#gamma Z", True )
	mh.addHisto( egammaHist, "e#rightarrow#gamma", True )
	mh.addHisto( fgammaHist, "Multijet", True )
	dataLegName = "Data"
	mh.addHisto( dataHist, dataLegName, draw="pe" )
	mh.addHisto( signal2, "Bino-like #chi_{1}^{0}", draw="hist" )
	mh.addHisto( signal1, "Wino-like #chi_{1}^{0}", draw="hist" )


	# get all SYSTEMATICAL uncertainties:
	systematicUncertHistStack = ROOT.THStack()
	systematicUncertHistStack.Add( fgammaWeightError )
	systematicUncertHistStack.Add( egammaHistsys )
	#systematicUncertHistStack.Add( fsrTsys )
	#systematicUncertHistStack.Add( fsrWsys )
	#systematicUncertHistStack.Add( fsrZsys )
	systematicUncertHistStack.Add( fsrSys )


	#if plot == "met":
	#	writeDataCard( treeVersion, dataHist, fgammaHist, fgammaWeightError,
	#		egammaHist, egammaHistsys,
	#		fsr, fsrSys )

	# draw stuff
	luminosity = 19.7
	infoText = ROOT.TLatex(0,.96, "CMS Private Work - %sfb^{-1} #sqrt{s}=8TeV #geq1#gamma_{tight},#geq2jets"%luminosity )
	infoText.SetNDC()
	infoText.SetTextSize(.04)

	can = ROOT.TCanvas()
	mh.Draw()
	errorBand = mh.stack.GetStack().Last().Clone( randomName() )
	sysUncert = systematicUncertHistStack.GetStack().Last()
	for bin in range(errorBand.GetNbinsX()+2):
		errorBand.SetBinError( bin, errorBand.GetBinError(bin) |qPlus| sysUncert.GetBinError(bin) )
	errorBand.SetFillStyle(3002)
	errorBand.SetMarkerSize(0)
	errorBand.SetFillColor(1)
	errorBand.Draw("e2 same")

	from myRatio import Ratio
	r = Ratio( "Data / Bkg", dataHist, mh.stack.GetStack().Last(), systematicUncertHistStack.GetStack().Last() )
	r.draw(0.5,1.5)

	infoText.Draw()

	SaveAs( can, "finalDistributionData_%s"%plot )
コード例 #30
0
ファイル: simpleDraw.py プロジェクト: kkiesel/singlePhoton
def compareTrees( plot="met", filenames=["slimAllQCD_V02.28_tree.root"], drawRatio=False ):
	#cut = "@electrons.size()==0 && @muons.size()==0"
	#cut = plot+">110"
	#cut = "!photons[0].isGen(0)"
	#cut = "ht < 600"
	cut = "1"

	gH = getHistoFromFiles( plot, "photonTree", filenames, "1" )
	fH = getHistoFromFiles( plot, "photonJetTree", filenames, "1", color=2 )

	for h in [gH, fH]:
		#h.Scale( 1./h.Integral() )
		h.SetMarkerSize(0)
		h.GetXaxis().SetTitleOffset( 1.03 )
		h.GetYaxis().SetTitleOffset( 1.5 )
		h.GetXaxis().SetLabelSize( 0.0633790992496425 )
		h.GetXaxis().SetTitleSize( 0.0633790992496425 )
		h.GetYaxis().SetLabelSize( 0.0633790992496425 )
		h.GetYaxis().SetTitleSize( 0.0633790992496425 )
		h.GetYaxis().SetLabelOffset(0)

		if plot == "photons[0].pt":
			h.GetXaxis().SetTitle( "$p_{T}$ [GeV]" )
		if plot == "photons[0].ptJet()":
			h.GetXaxis().SetTitle( "$p_{T^*}$ [GeV]" )

	ratio = gH.Clone( randomName() )
	ratio.Divide( fH )


	mh = Multihisto()
	#mh.leg.SetX1(0.608)
	#mh.leg.SetX2(0.95)
	mh.addHisto( gH, "#gamma_{#text{tight}}", draw="hist e" )
	mh.addHisto( fH, "#gamma_{#text{loose}}", draw="hist e" )

	can = ROOT.TCanvas()
	#can.SetBottomMargin(0)
	#can.SetTopMargin(0)
	#can.SetRightMargin(0)
	#can.SetLeftMargin(0.19)
	can.cd()
	mh.Draw()

	pc1 = ROOT.TLatex(0,.96, "CMS Private Work")
	pc2 = ROOT.TLatex( .51,.96, "\SI{19.8}{fb^{-1}} #sqrt{s}=\SI{8}{TeV}")
	for pc in [pc1, pc2]:
		pc.SetNDC()
		pc.SetTextSize(0.06311227345609463)
		pc.Draw()


	if drawRatio:
		from myRatio import Ratio
		r = Ratio( "#gamma/#gamma_{jet}", gH, fH )
		r.draw()

	#can.SetFillColor(ROOT.kGreen)
	SavePad( "compare2_%s_%s"%("test",shortName( filenames )) )
	#ROOT.gPad.SaveAs("~/master/documents/thesis/plots/compare_%s_%s.tex"%(manipulateSaveName(plot),shortName( filenames )) )
	ROOT.SetOwnership( can, False )