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