lhapdf is hosted by Hepforge, IPPP Durham
LHAPDF  6.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
/examples/pythonexample.py
1 #! /usr/bin/env python
2 
3 ## Python LHAPDF6 usage example
4 
5 import lhapdf
6 
7 ## Getting a PDF member object
8 p = lhapdf.mkPDF("CT10nlo", 0)
9 p = lhapdf.mkPDF("CT10nlo/0")
10 
11 ## Gluon PDF querying at x=0.001, Q2=10000
12 print(p.xfxQ2(21, 1e-3, 1e4))
13 
14 ## Basic all-flavour PDF querying at x=0.01, Q=M_Z
15 for pid in p.flavors():
16  print(p.xfxQ(pid, 0.01, 91.2))
17 
18 # TODO: demonstrate looping over PDF set members
19 pset = lhapdf.getPDFSet("CT10nlo")
20 print(pset.description)
21 pcentral = pset.mkPDF(0)
22 pdfs1 = pset.mkPDFs()
23 pdfs2 = lhapdf.mkPDFs("CT10nlo") # a direct way to get all the set's PDFs
24 
25 ## Filling a numpy 2D array with xf(x,Q) samples
26 import numpy as np
27 xs = [x for x in np.logspace(-7, 0, 5)]
28 qs = [q for q in np.logspace(1, 4, 4)]
29 gluon_xfs = np.empty([len(xs), len(qs)])
30 for ix, x in enumerate(xs):
31  for iq, q in enumerate(qs):
32  gluon_xfs[ix,iq] = p.xfxQ(21, x, q)
33 print(gluon_xfs)
34 
35 ## Version info, search paths, and metadata
36 print(lhapdf.version())
37 print(lhapdf.__version__)
38 lhapdf.pathsPrepend("/path/to/extra/pdfsets")
39 print(lhapdf.paths())
40 # ...