def get_pdf(pdfset, parton, q, xs):
	"""get the PDF (xfx) for a certain set, parton, x and Q"""

	lhapdf.initPDFSetByName(pdfset)
	npdfs = lhapdf.numberPDF()
	pdf = np.zeros((npdfs, len(xs)))

	for member in range(1, npdfs + 1):
		lhapdf.initPDF(member)
		for (i, xi) in enumerate(xs):
			if parton < 7:
				pdf[member - 1][i] = lhapdf.xfx(xi, q, parton)
			elif parton == 7:
				#DVAL 1-(-1)
				pdf[member - 1][i] = lhapdf.xfx(xi, q, 1) - \
								 lhapdf.xfx(xi, q, -1)
			elif parton == 8:
				#UVAL 2-(-2)
				pdf[member - 1][i] = lhapdf.xfx(xi, q, 2) - \
								 lhapdf.xfx(xi, q, -2)
			elif parton == 9:
				#Light sea: xS=2(xubar + xdbar + xsbar)
				pdf[member - 1][i] = 2*(lhapdf.xfx(xi, q, -1) + \
								 lhapdf.xfx(xi, q, -2) + \
								 lhapdf.xfx(xi, q, -3))
			else:
				raise ValueError('Parton id not in range 0...9')
	return pdf
Exemple #2
0
    def _get_lhapdf_flavor(self, flavor, lhgrid_filename):

        lhapdf.initPDFSetByName(lhgrid_filename)
        npdfs = lhapdf.numberPDF()
        pdf = numpy.zeros((npdfs + 1, self._xrange.size))
        for member in range(0, npdfs + 1):
            lhapdf.initPDF(member)
            for (i, xi) in enumerate(self._xrange):
                if flavor < 7:
                    pdf[member][i] = lhapdf.xfx(xi, self._q, flavor)
                elif flavor == 7:
                    #DVAL 1-(-1)
                    pdf[member][i] = lhapdf.xfx(xi, self._q, 1) - \
                                     lhapdf.xfx(xi, self._q, -1)
                elif flavor == 8:
                    #UVAL 2-(-2)
                    pdf[member][i] = lhapdf.xfx(xi, self._q, 2) - \
                                     lhapdf.xfx(xi, self._q, -2)
                elif flavor == 9:
                    #Light sea: xS=2(xubar + xdbar + xsbar)
                    pdf[member][i] = 2*(lhapdf.xfx(xi, self._q, -1) + \
                                     lhapdf.xfx(xi, self._q, -2) + \
                                     lhapdf.xfx(xi, self._q, -3))
                else:
                    raise Exception('Flavor not defined')
        return pdf
def recalculateFactorization(x1, id1, factorizationScale1, x2, id2, factorizationScale2, multiplier):

    ''' Recalculate the PDF using the new factorization scale '''

    lhapdfID1 = id1
    if lhapdfID1 == 21:
        lhapdfID1 = 0
        
    lhapdfID2 = id1
    if lhapdfID2 == 21:
        lhapdfID2 = 0

    # LHAPDF only returns x * f(x, Q) ... that's why I divide by x.
    # Not strictly necessary, since we are interest in ratios, but anyway...

    oldWeight1 = lhapdf.xfx(x1, factorizationScale1, lhapdfID1)/x1
    newWeight1 = lhapdf.xfx(x1, factorizationScale1*multiplier, lhapdfID1)/x1

    oldWeight2 = lhapdf.xfx(x2, factorizationScale2, lhapdfID2)/x2
    newWeight2 = lhapdf.xfx(x2, factorizationScale2*multiplier, lhapdfID2)/x2

    return (newWeight1*newWeight2)/(oldWeight1*oldWeight2)
q = math.sqrt(6400.0)
pdfsets = ["cteq6ll.LHpdf", "MSTW2008lo68cl.LHgrid", "MRST2001lo.LHgrid", "MRST2007lomod.LHgrid", "MRSTMCal.LHgrid"]
#pdfsets = ["cteq6ll.LHpdf", "MRST2001lo.LHgrid", "MRST2007lomod.LHgrid", "MRSTMCal.LHgrid"]
partons = { 0 : "gluon", 2 : "up" }
NPOINTS = 1000

xs = numpy.logspace(-4, -0.001, NPOINTS)
plt.figure(figsize=(13,7))
for n, parton in enumerate(sorted(partons.keys())):
    plt.subplot(1, len(partons), n+1)

    lhapdf.initPDFSetByName(pdfsets[0])
    lhapdf.initPDF(0)
    refxfxs = numpy.zeros([NPOINTS])
    for i, x in enumerate(xs):
        xfx = lhapdf.xfx(x, q, parton)
        refxfxs[i] = xfx

    lines = []
    for pdfset in pdfsets:
        lhapdf.initPDFSetByName(pdfset)
        lhapdf.initPDF(0)
        xfxs = numpy.zeros([NPOINTS])
        for i, x in enumerate(xs):
            xfx = lhapdf.xfx(x, q, parton)
            xfxs[i] = xfx
        xfxratios = xfxs/refxfxs
        l = plt.plot(xs, xfxratios)
        lines.append(l)

    plt.xscale("log")
Exemple #5
0
def weight(hats, mu, x1, x2, costh_ii):
    # 1 for down-quarks, 2 for up, 3 for strange, 4 for charm and negative values for the corresponding anti-quarks. gluon is given by 21
    qtype = 0  # up-type quarks
    w_ii = dsigma(costh_ii, hats,
                  qtype) * (lhapdf.xfx(x1, mu, 2) * lhapdf.xfx(-x2, mu, 2) +
                            lhapdf.xfx(x1, mu, 4) * lhapdf.xfx(-x2, mu, 4))
    w_ii = w_ii + dsigma(-costh_ii, hats, qtype) * (
        lhapdf.xfx(-x1, mu, 2) * lhapdf.xfx(x2, mu, 2) +
        lhapdf.xfx(-x1, mu, 4) * lhapdf.xfx(x2, mu, 4))
    qtype = 1  # down-type quarks
    w_ii = w_ii + dsigma(costh_ii, hats, qtype) * (
        lhapdf.xfx(x1, mu, 1) * lhapdf.xfx(-x2, mu, 1) +
        lhapdf.xfx(x1, mu, 3) * lhapdf.xfx(-x2, mu, 3))
    w_ii = w_ii + dsigma(-costh_ii, hats, qtype) * (
        lhapdf.xfx(-x1, mu, 1) * lhapdf.xfx(x2, mu, 1) +
        lhapdf.xfx(-x1, mu, 3) * lhapdf.xfx(x2, mu, 3))
    # multiply by ranges and Jacobian, divide by the x1 and x2 since xfxaQ gives x * f(x)
    return w_ii
Exemple #6
0
q = math.sqrt(6400.0)
pdfsets = ["cteq6ll.LHpdf", "MSTW2008lo68cl.LHgrid", "MRST2001lo.LHgrid", "MRST2007lomod.LHgrid", "MRSTMCal.LHgrid"]
#pdfsets = ["cteq6ll.LHpdf", "MRST2001lo.LHgrid", "MRST2007lomod.LHgrid", "MRSTMCal.LHgrid"]
partons = { 0 : "gluon", 2 : "up" }
NPOINTS = 1000

xs = numpy.logspace(-4, -0.001, NPOINTS)
plt.figure(figsize=(13,7))
for n, parton in enumerate(sorted(partons.keys())):
    plt.subplot(1, len(partons), n+1)
    lines = []
    for pdfset in pdfsets:
        lhapdf.initPDFSetByName(pdfset)
        lhapdf.initPDF(0)
        xfxs = numpy.zeros([NPOINTS])
        for i, x in enumerate(xs):
            xfx = lhapdf.xfx(x, q, parton)
            xfxs[i] = xfx
        l = plt.plot(xs, xfxs)
        lines.append(l)

    plt.xscale("log")
    #plt.ylim(0.5, 3)
    plt.legend(lines, pdfsets)
    plt.title(partons[parton])
    plt.xlabel("$x$")
    if n == 0:
        plt.ylabel("$x f(x, Q^2)$")

plt.show()
Exemple #7
0
    def weight(self, hats, mu, x1, x2, costh_i):
        '''
		1 for down-quarks, 2 for up, 3 for strange,
		4 for charm and negative values for the corresponding anti-quarks. gluon is given by 21
		'''
        # up-type quarks
        qtype = 0
        w_i = self.dsig.dsigma(costh_i, hats, qtype) * (
            lhapdf.xfx(x1, mu, 2) * lhapdf.xfx(-x2, mu, 2) +
            lhapdf.xfx(x1, mu, 4) * lhapdf.xfx(-x2, mu, 4))
        w_i = w_i + self.dsig.dsigma(-costh_i, hats, qtype) * (
            lhapdf.xfx(-x1, mu, 2) * lhapdf.xfx(x2, mu, 2) +
            lhapdf.xfx(-x1, mu, 4) * lhapdf.xfx(x2, mu, 4))
        # down-type quarks
        qtype = 1
        w_i = w_i + self.dsig.dsigma(costh_i, hats, qtype) * (
            lhapdf.xfx(x1, mu, 1) * lhapdf.xfx(-x2, mu, 1) +
            lhapdf.xfx(x1, mu, 3) * lhapdf.xfx(-x2, mu, 3))
        w_i = w_i + self.dsig.dsigma(-costh_i, hats, qtype) * (
            lhapdf.xfx(-x1, mu, 1) * lhapdf.xfx(x2, mu, 1) +
            lhapdf.xfx(-x1, mu, 3) * lhapdf.xfx(x2, mu, 3))
        return w_i
Exemple #8
0
 def xpdf(self, mem, x1, x2, id1, id2, Q):
     lhapdf.usePDFMember(*mem)
     return lhapdf.xfx(mem[0], x1, Q, id1) * lhapdf.xfx(mem[0], x2, Q, id2)
Exemple #9
0
 def xpdf(self, mem, x1, x2, id1, id2, Q) :
     lhapdf.usePDFMember(*mem)
     return lhapdf.xfx(mem[0], x1,Q,id1) * lhapdf.xfx(mem[0], x2,Q,id2)