コード例 #1
0
def multiplot(plotdict):
	"""This function makes similar plots with the same quantities and different cuts and selections"""
	pdgids = [211, 321, 11, 13]
	quantities = ["TauSpinnerWeight", "1genBoson1Daughter2GranddaughterPt", "1genBoson1Daughter2GranddaughterEta", "1genBoson1Daughter2GranddaughterPhi", "1genBoson1Daughter2GranddaughterMass"]
	for i in pdgids:
		for quantity in quantities:
			local_plotdict = utils.copyplotdict(plotdict)
			for key in xlimsdict.keys():
				if key in quantity:
					local_plotdict['xlims'] = xlimsdict[key]
					if local_plotdict['xlims'] == ["mass"]:
						local_plotdict['xlims'] = particledict.get(i)[1]

			local_plotdict["x"] = [quantity]
			if quantity == "TauSpinnerWeight":
				local_plotdict["log"] = True
			local_plotdict["weights"][0] = 'abs(1genBoson1Daughter2GranddaughterPdgId) == %0.0f && TauSpinnerWeight != -999 && TauSpinnerWeight != -777' % i
			#print local_plotdict["weights"][0]
			local_plotdict["filename"] = local_plotdict["x"][0] + 'ForPdgId%s' % i
			local_plotdict["title"] = local_plotdict["x"][0] + ' for ' + particledict.get(i)[0] + ' and ' + particledict.get(-i)[0]
			#local_local_plotdict["labels"] = local_plotdict["x"][0] + ' for ' + particledict.get(i) + ' and ' + particledict.get(-i)
			plot1d.get_root_histos(local_plotdict)

			plot1d.get_mpl_histos(local_plotdict)
			plot1d.plot1d_mpl(local_plotdict)

			labels.add_labels(local_plotdict)
			utils.setaxislimits(local_plotdict)
			utils.save(local_plotdict)
コード例 #2
0
def ratioplot(plotdict):
    """ This function sorts particles depending on the pdgids-list"""

    plotdict['xlims'] = [-20300.5, 20299.5]
    plotdict['nbins'] = 40600

    plot1d.get_root_histos(plotdict)
    plot1d.get_mpl_histos(plotdict)
    # remove empty bins
    # map  plotdict["mplhistos"]  x entries (=pdgIDs) to particle names
    # regroup

    pdgids = [
        -20213, 20213, -323, 323, -321, 321, -213, 213, -211, 211, -24, 24, 11,
        -11, 13, -13
    ]
    for i in range(len(plotdict["mplhistos"])):
        for xc, y in zip(plotdict["mplhistos"][i].xc,
                         plotdict["mplhistos"][i].y):
            if (y != 0) and not (xc in pdgids) and (xc != 0):
                print "PdgId %5.0f is not contained in the list 'pdgids'" % xc
                sys.exit(1)

    binlabelslist = [particledict.get(p) for p in pdgids]

    for i in range(len(plotdict["mplhistos"])):
        new_y = [0] * len(pdgids)
        new_yerr = [0] * len(pdgids)
        for j in range(len(pdgids)):
            for xc, y, yerr in zip(plotdict["mplhistos"][i].xc,
                                   plotdict["mplhistos"][i].y,
                                   plotdict["mplhistos"][i].yerr):
                if pdgids[j] == xc:
                    new_y[j] = y
                    new_yerr[j] = yerr
        numblist = range(len(pdgids))
        for k in numblist:
            numblist[k] -= 0.5
        plotdict["mplhistos"][i].x = numblist
        plotdict["mplhistos"][i].xc = range(len(pdgids))
        plotdict["mplhistos"][i].y = new_y
        plotdict["mplhistos"][i].yerr = new_yerr

    plot1d.plot1d_mpl(plotdict)  # plottet mplhistos

    # set x axis xticks, xticklabels
    plotdict['axes'].set_ylim(top=1.2 * max(d.ymax()
                                            for d in plotdict['mplhistos']),
                              bottom=0)
    labels.add_labels(plotdict)
    plotdict["axes"].set_xticks(range(len(pdgids)))
    plotdict["axes"].set_xticklabels(binlabelslist, rotation=90)
    utils.save(plotdict)
コード例 #3
0
ファイル: example_plots.py プロジェクト: ArturAkh/Artus
def example_plotscale(plotdict):
	""" This function does basically the same as plot1d, but scales the root
		histograms with a factor and then convertes them to MPL.
	"""
	#TODO: The conversion ROOT->MPL is actually done twice - avoid this

	plot1d.get_root_histos(plotdict)

	for n, (roothisto, rootfile) in enumerate(zip(plotdict['roothistos'], plotdict['rootfiles'])):
		# Scale (or whatever you want to do with the root histos):
		roothisto.Scale(plotdict['scalefactor'])
		plotdict["mplhistos"][n] = mplconvert.root2histo(roothisto, rootfile.GetName(), 1)

	plot1d.plot1d_mpl(plotdict)
	utils.setaxislimits(plotdict)
	labels.add_labels(plotdict)
	utils.save(plotdict)
コード例 #4
0
def ratioplot(plotdict):
	""" This function sorts particles depending on the pdgids-list"""

	plotdict['xlims'] = [-20300.5, 20299.5]
	plotdict['nbins'] = 40600

	plot1d.get_root_histos(plotdict)
	plot1d.get_mpl_histos(plotdict)
	# remove empty bins
	# map  plotdict["mplhistos"]  x entries (=pdgIDs) to particle names
	# regroup

	pdgids = [-20213, 20213, -323, 323, -321, 321, -213, 213, -211, 211, -24, 24, 11, -11, 13, -13]
	for i in range(len(plotdict["mplhistos"])):
		for xc, y in zip(plotdict["mplhistos"][i].xc, plotdict["mplhistos"][i].y):
			if (y != 0) and not (xc in pdgids) and (xc != 0):
				print "PdgId %5.0f is not contained in the list 'pdgids'" % xc
				sys.exit(1)

	binlabelslist = [particledict.get(p) for p in pdgids]

	for i in range(len(plotdict["mplhistos"])):
		new_y = [0] * len(pdgids)
		new_yerr = [0] * len(pdgids)
		for j in range(len(pdgids)):
			for xc, y, yerr in zip(plotdict["mplhistos"][i].xc, plotdict["mplhistos"][i].y, plotdict["mplhistos"][i].yerr):
				if pdgids[j] == xc:
					new_y[j] = y
					new_yerr[j] = yerr
		numblist = range(len(pdgids))
		for k in numblist:
			numblist[k] -= 0.5
		plotdict["mplhistos"][i].x = numblist
		plotdict["mplhistos"][i].xc = range(len(pdgids))
		plotdict["mplhistos"][i].y = new_y
		plotdict["mplhistos"][i].yerr = new_yerr

	plot1d.plot1d_mpl(plotdict)  # plottet mplhistos

	# set x axis xticks, xticklabels
	plotdict['axes'].set_ylim(top=1.2 * max(d.ymax() for d in plotdict['mplhistos']), bottom=0)
	labels.add_labels(plotdict)
	plotdict["axes"].set_xticks(range(len(pdgids)))
	plotdict["axes"].set_xticklabels(binlabelslist, rotation=90)
	utils.save(plotdict)
コード例 #5
0
def example_plotscale(plotdict):
    """ This function does basically the same as plot1d, but scales the root
		histograms with a factor and then convertes them to MPL.
	"""
    #TODO: The conversion ROOT->MPL is actually done twice - avoid this

    plot1d.get_root_histos(plotdict)

    for n, (roothisto, rootfile) in enumerate(
            zip(plotdict['roothistos'], plotdict['rootfiles'])):
        # Scale (or whatever you want to do with the root histos):
        roothisto.Scale(plotdict['scalefactor'])
        plotdict["mplhistos"][n] = mplconvert.root2histo(
            roothisto, rootfile.GetName(), 1)

    plot1d.plot1d_mpl(plotdict)
    utils.setaxislimits(plotdict)
    labels.add_labels(plotdict)
    utils.save(plotdict)
コード例 #6
0
def multiplot(plotdict):
    """This function makes similar plots with the same quantities and different cuts and selections"""
    pdgids = [211, 321, 11, 13]
    quantities = [
        "TauSpinnerWeight", "1genBoson1Daughter2GranddaughterPt",
        "1genBoson1Daughter2GranddaughterEta",
        "1genBoson1Daughter2GranddaughterPhi",
        "1genBoson1Daughter2GranddaughterMass"
    ]
    for i in pdgids:
        for quantity in quantities:
            local_plotdict = utils.copyplotdict(plotdict)
            for key in xlimsdict.keys():
                if key in quantity:
                    local_plotdict['xlims'] = xlimsdict[key]
                    if local_plotdict['xlims'] == ["mass"]:
                        local_plotdict['xlims'] = particledict.get(i)[1]

            local_plotdict["x"] = [quantity]
            if quantity == "TauSpinnerWeight":
                local_plotdict["log"] = True
            local_plotdict["weights"][
                0] = 'abs(1genBoson1Daughter2GranddaughterPdgId) == %0.0f && TauSpinnerWeight != -999 && TauSpinnerWeight != -777' % i
            #print local_plotdict["weights"][0]
            local_plotdict[
                "filename"] = local_plotdict["x"][0] + 'ForPdgId%s' % i
            local_plotdict[
                "title"] = local_plotdict["x"][0] + ' for ' + particledict.get(
                    i)[0] + ' and ' + particledict.get(-i)[0]
            #local_local_plotdict["labels"] = local_plotdict["x"][0] + ' for ' + particledict.get(i) + ' and ' + particledict.get(-i)
            plot1d.get_root_histos(local_plotdict)

            plot1d.get_mpl_histos(local_plotdict)
            plot1d.plot1d_mpl(local_plotdict)

            labels.add_labels(local_plotdict)
            utils.setaxislimits(local_plotdict)
            utils.save(local_plotdict)