PDFLIB.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2017, GENIE Neutrino MC Generator Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5  or see $GENIE/LICENSE
6 
7  Author: Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
8  University of Liverpool & STFC Rutherford Appleton Lab
9 
10  Disabled PDFLIB - Only LHAPDFv5 support left / to clean-up before next
11  release. Experimenting in LHAPDFv6
12 
13 */
14 //____________________________________________________________________________
15 
16 #include <cstdlib>
17 
18 #include <TSystem.h>
19 #include <TMath.h>
20 
21 #include "Conventions/GBuild.h"
22 #include "PDF/PDFLIB.h"
23 #include "Messenger/Messenger.h"
24 
25 #ifdef __GENIE_LHAPDF_ENABLED__
26 //
27 // include the LHAPDF C++ wrapper
28 //
29 #include "LHAPDF/LHAPDF.h"
30 //#else
31 //
32 // the actual PDFLIB fortran calls
33 //
34 //extern "C" {
35 // void pdfset_ (const char param[20][20], double val[20]);
36 // void structm_ (double *, double *, double *, double *, double *,
37 // double *, double *, double *, double *, double *, double *);
38 //}
39 #endif
40 
41 using namespace genie;
42 
43 //____________________________________________________________________________
45 PDFModelI("genie::PDFLIB")
46 {
47  this->Initialize();
48 }
49 //____________________________________________________________________________
51 PDFModelI("genie::PDFLIB", config)
52 {
53  LOG("PDF", pDEBUG) << "PDFLIB configuration:\n " << *fConfig;
54 
55  this->Initialize();
56 }
57 //____________________________________________________________________________
59 {
60 
61 }
62 //____________________________________________________________________________
63 void PDFLIB::Initialize(void) const
64 {
65 #ifdef __GENIE_LHAPDF_ENABLED__
66  //
67  // LHAPDF
68  //
69  bool lhapath_ok = true;
70  const char * lhapath = gSystem->Getenv("LHAPATH");
71  if(!lhapath) lhapath_ok = false;
72  else {
73  void *dirp = gSystem->OpenDirectory(lhapath);
74  if (dirp) gSystem->FreeDirectory(dirp);
75  else lhapath_ok = false;
76  }
77  if(!lhapath_ok) {
78  LOG("PDF", pFATAL)
79  << "\n"
80  << "** LHAPDF won't be able to read-in the PDF data. \n"
81  << "** The LHAPATH env. variable is not properly (or at all) defined. \n"
82  << "** Please, set LHAPATH to <lhapdf_top_dir>/PDFsets/ \n"
83  << "** See http://projects.hepforge.org/lhapdf/ for more details. \n\n";
84  gAbortingInErr = true;
85  exit(1);
86  }
87 
88 /*
89 #else
90  //
91  // PDFLIB
92  //
93  char param[20][20];
94  double val[20];
95  strcpy(param[0], "Init0");
96  pdfset_(param, val); // call pdfset from the fortran PDFLIB library
97 */
98 #endif
99 }
100 //____________________________________________________________________________
102 {
103 // Get PDF spec (particle type, pdf group/set) from configuration registry.
104 // For definitions, have a look at PDFLIB and LHAPDF manuals
105 
106 #ifdef __GENIE_LHAPDF_ENABLED__
107  //
108  // LHAPDF
109  //
110  string name = "";
111  int type = 0;
112  int memset = 0;
113 
114  fConfig->Get("name_lhapdf", name);
115  fConfig->Get("type_lhapdf", type);
116  fConfig->Get("memset_lhapdf", memset);
117 
118  LHAPDF::SetType stype = (type==0) ? LHAPDF::LHPDF : LHAPDF::LHGRID;
119 
120  LHAPDF::initPDFByName(name, stype, memset);
121  LHAPDF::extrapolate(false);
122 
123 /*
124 #else
125  //
126  // PDFLIB
127  //
128  int nptype = -1; // particle type
129  int ngroup = -1; // PDF author group
130  int nset = -1; // PDF set --within PDF author group--
131 
132  fConfig->Get("nptype_pdflib", nptype);
133  fConfig->Get("ngroup_pdflib", ngroup);
134  fConfig->Get("nset_pdflib", nset );
135 
136  char param[20][20];
137  double val[20];
138 
139  strcpy(param[0],"Nptype");
140  val[0] = nptype;
141  strcpy(param[1],"Ngroup");
142  val[1] = ngroup;
143  strcpy(param[2],"Nset");
144  val[2] = nset;
145 
146  pdfset_(param, val);
147 */
148 
149 #endif
150 }
151 //____________________________________________________________________________
152 double PDFLIB::UpValence(double x, double Q2) const
153 {
154  return AllPDFs(x,Q2).uval;
155 }
156 //____________________________________________________________________________
157 double PDFLIB::DownValence(double x, double Q2) const
158 {
159  return AllPDFs(x,Q2).dval;
160 }
161 //____________________________________________________________________________
162 double PDFLIB::UpSea(double x, double Q2) const
163 {
164  return AllPDFs(x,Q2).usea;
165 }
166 //____________________________________________________________________________
167 double PDFLIB::DownSea(double x, double Q2) const
168 {
169  return AllPDFs(x,Q2).dsea;
170 }
171 //____________________________________________________________________________
172 double PDFLIB::Strange(double x, double Q2) const
173 {
174  return AllPDFs(x,Q2).str;
175 }
176 //____________________________________________________________________________
177 double PDFLIB::Charm(double x, double Q2) const
178 {
179  return AllPDFs(x,Q2).chm;
180 }
181 //____________________________________________________________________________
182 double PDFLIB::Bottom(double x, double Q2) const
183 {
184  return AllPDFs(x,Q2).bot;
185 }
186 //____________________________________________________________________________
187 double PDFLIB::Top(double x, double Q2) const
188 {
189  return AllPDFs(x,Q2).top;
190 }
191 //____________________________________________________________________________
192 double PDFLIB::Gluon(double x, double Q2) const
193 {
194  return AllPDFs(x,Q2).gl;
195 }
196 //____________________________________________________________________________
197 PDF_t PDFLIB::AllPDFs(double x, double Q2) const
198 {
199  PDF_t pdf;
200 
201 #ifdef __GENIE_LHAPDF_ENABLED__
202  //
203  // LHAPDF
204  //
205 
206  // QCD scale
207  double Q = TMath::Sqrt( TMath::Abs(Q2) );
208 
209  vector<double> pdfs = LHAPDF::xfx(x, Q);
210  pdf.uval = pdfs[8] - pdfs[4];
211  pdf.dval = pdfs[7] - pdfs[5];
212  pdf.usea = pdfs[4];
213  pdf.dsea = pdfs[5];
214  pdf.str = pdfs[9];
215  pdf.chm = pdfs[10];
216  pdf.bot = pdfs[11];
217  pdf.top = pdfs[12];
218  pdf.gl = pdfs[6];;
219 
220 /*
221 #else
222  //
223  // PDFLIB
224  //
225 
226  double uval, dval, usea, dsea, str, chm, bot, top, gl;
227 
228  // call structm from the fortran PDFLIB library
229  structm_(&x, &q, &uval, &dval, &usea, &dsea, &str, &chm, &bot, &top, &gl);
230 
231  pdf.uval = uval;
232  pdf.dval = dval;
233  pdf.usea = usea;
234  pdf.dsea = dsea;
235  pdf.str = str;
236  pdf.chm = chm;
237  pdf.bot = bot;
238  pdf.top = top;
239  pdf.gl = gl;
240 */
241 
242 #endif
243 
244  return pdf;
245 }
246 //____________________________________________________________________________
248 {
249  Algorithm::Configure(config);
250 
251  this->Initialize();
252  this->SetPDFSetFromConfig();
253 
254  fAllowReconfig=false;
255 }
256 //____________________________________________________________________________
258 {
259  Algorithm::Configure(config);
260 
261  this->Initialize();
262  this->SetPDFSetFromConfig();
263 
264  fAllowReconfig=false;
265 }
266 //____________________________________________________________________________
267 
PDF_t AllPDFs(double x, double Q2) const
Definition: PDFLIB.cxx:197
#include "Numerical/GSFunc.h"
Definition: AlgCmp.h:26
void SetPDFSetFromConfig(void) const
Definition: PDFLIB.cxx:101
double Q2(const Interaction *const i)
Definition: KineUtils.cxx:642
double Bottom(double x, double Q2) const
Definition: PDFLIB.cxx:182
virtual ~PDFLIB()
Definition: PDFLIB.cxx:58
#define pFATAL
Definition: Messenger.h:47
double Charm(double x, double Q2) const
Definition: PDFLIB.cxx:177
Pure abstract base class. Defines the PDFModelI interface to be implemented by any algorithmic class ...
Definition: PDFModelI.h:33
void Configure(const Registry &config)
Configure the algorithm.
Definition: PDFLIB.cxx:247
double Strange(double x, double Q2) const
Definition: PDFLIB.cxx:172
void Get(RgKey key, const RegistryItemI *&item) const
Definition: Registry.cxx:339
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:87
double DownValence(double x, double Q2) const
Definition: PDFLIB.cxx:157
virtual void Configure(const Registry &config)
Configure the algorithm.
Definition: Algorithm.cxx:70
A struct to hold PDF set data.
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:66
double UpSea(double x, double Q2) const
Definition: PDFLIB.cxx:162
double Top(double x, double Q2) const
Definition: PDFLIB.cxx:187
double Gluon(double x, double Q2) const
Definition: PDFLIB.cxx:192
Registry * fConfig
config. (either owned or pointing to config pool)
Definition: Algorithm.h:122
double UpValence(double x, double Q2) const
Definition: PDFLIB.cxx:152
bool gAbortingInErr
Definition: Messenger.cxx:56
double DownSea(double x, double Q2) const
Definition: PDFLIB.cxx:167
void Initialize(void) const
Definition: PDFLIB.cxx:63
#define pDEBUG
Definition: Messenger.h:54