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
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
if MET.Pt() < 30.: retval = 0. if jet[0].Pt() < 30. or jet[1].Pt() < 30.: retval = 0. if ROOT.TMath.Abs(jet[0].Eta()) > 4.7 or ROOT.TMath.Abs(jet[1].Eta()) > 4.7: retval = 0. return retval if __name__ == "__main__": # This here has to match the generation info in run_card.dat lhapdf.initPDFSetByName("cteq6ll.LHpdf") lhapdf.initPDF(0) mjj_min = 150. detajj_min = 1.5 # Be careful, this thing will stash all the weights in memory. # It shouldn't be much, but don't go crazy with extremely large LHE files print 'Reading WmWm EWK + QCD' WmWmEWKQCD = readFiles(['../WmWm_VBS_QED4_QCD99_SM/Events/run_01/unweighted_events.lhe', '../WmWm_VBS_QED4_QCD99_SM/Events/run_02/unweighted_events.lhe', '../WmWm_VBS_QED4_QCD99_SM/Events/run_03/unweighted_events.lhe', '../WmWm_VBS_QED4_QCD99_SM/Events/run_04/unweighted_events.lhe', '../WmWm_VBS_QED4_QCD99_SM/Events/run_05/unweighted_events.lhe', '../WmWm_VBS_QED4_QCD99_SM/Events/run_06/unweighted_events.lhe']) print 'Reading WmWm EWK'
import math, numpy import lhapdf import matplotlib.pyplot as plt 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
#comment out the following if not using matplotlib and numpy import matplotlib # import mpmath as mp import numpy as np # import pylab as pl # from scipy import interpolate, signal import matplotlib.font_manager as fm from matplotlib.ticker import MultipleLocator import matplotlib.pyplot as plt import matplotlib.patches as patches import matplotlib.path as path ## import LHAPDF and initialize PDFs import lhapdf ## initializes PDF member object (for protons) lhapdf.initPDFSetByName("cteq6ll.LHpdf") lhapdf.initPDF(0) ## what follows depends on matplotlib/numpy ## (taken from http://matplotlib.org/examples/api/histogram_path_demo.html) def generate_histo(array, name): fig, ax = plt.subplots() n, bins = np.histogram(array, 30) # get the corners of the rectangles for the histogram left = np.array(bins[:-1]) right = np.array(bins[1:]) bottom = np.zeros(len(left)) top = bottom + n
import lhapdf import matplotlib.pyplot as plt 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)$")
import numpy as np import matplotlib.mlab as mlab import matplotlib.pyplot as plt #scale factor path = '/home/daniel/workspace/LHAPDF/install_dir/' import sys sys.path.append('%s/python2.6/site-packages/' % path) sys.path.append('%s/lib/' % path) import lhapdf lhapdf.initPDFSetByName("cteq6mE.LHgrid") lhapdf.initPDF(0) print "alpha_s(Mz) = ", lhapdf.alphasPDF(91.2) sf = 1 / lhapdf.alphasPDF(90.1) x = range(100, 1500) y = [sf * lhapdf.alphasPDF(xx) for xx in x] y2 = [yy * yy for yy in y] y3 = [yy * yy * yy for yy in y] y4 = [yy * yy * yy * yy for yy in y] y5 = [yy * yy * yy * yy * yy for yy in y] from matplotlib import rc import matplotlib as mpl rc('text', usetex=True) mpl.rcParams['font.size'] = 20.0