8 #ifndef Pythia8_LHAPDF6_H
9 #define Pythia8_LHAPDF6_H
11 #include "Pythia8/PartonDistributions.h"
12 #include "LHAPDF/LHAPDF.h"
22 namespace LHAPDF6Interface {
34 PdfSets(
string setName) : info(::LHAPDF::PDFSet(setName)),
35 pdfs(vector< ::LHAPDF::PDF* >(info.size(), 0)) {;}
38 ::LHAPDF::PDF *operator[](
unsigned int member) {
39 if (!pdfs[member]) pdfs[member] = info.mkPDF(member);
44 int size() {
return pdfs.size();}
47 ::LHAPDF::PDFSet info;
48 vector< ::LHAPDF::PDF* > pdfs;
62 for (map<int, PdfSets>::iterator pdf = pdfs.begin();
63 pdf != pdfs.end(); ++pdf)
64 for (
int iMem = 0; iMem < (int)pdf->second.size(); ++iMem)
65 if (pdf->second.pdfs[iMem])
delete pdf->second.pdfs[iMem];
70 int id = ::LHAPDF::lookupLHAPDFID(setName, 0);
72 else if (pdfs.find(
id) == pdfs.end()) pdfs[
id] =
PdfSets(setName);
79 map<int, PdfSets> pdfs;
100 LHAPDF6(
int idBeamIn,
string setName,
int member,
int,
Info* infoPtr)
101 :
PDF(idBeamIn), pdf(0), extrapol(
false)
102 { init(setName, member, infoPtr); }
105 void setExtrapolate(
bool extrapolIn) {extrapol = extrapolIn;}
112 ::LHAPDF::Extrapolator *ext;
116 void init(
string setName,
int member,
Info* infoPtr);
119 void xfUpdate(
int id,
double x,
double Q2);
122 bool insideBounds(
double x,
double Q2) {
123 return (x > pdf->xMin() && x < pdf->xMax()
124 && Q2 > pdf->q2Min() && Q2 < pdf->q2Max());}
127 double alphaS(
double Q2) {
return pdf->alphasQ2(Q2); }
130 double muPDFSave, mdPDFSave, mcPDFSave, msPDFSave, mbPDFSave;
131 double mQuarkPDF(
int id) {
132 if (abs(
id) == 1)
return mdPDFSave;
133 if (abs(
id) == 2)
return muPDFSave;
134 if (abs(
id) == 3)
return msPDFSave;
135 if (abs(
id) == 4)
return mcPDFSave;
136 if (abs(
id) == 5)
return mbPDFSave;
141 void calcPDFEnvelope(
int,
double,
double,
int);
142 void calcPDFEnvelope(pair<int,int>, pair<double,double>,
double,
int);
145 static const double PDFMINVALUE;
148 int nMembers() {
return nMembersSave; }
156 const double LHAPDF6::PDFMINVALUE = 1e-10;
162 void LHAPDF6::init(
string setName,
int member,
Info *info) {
166 pdfs = LHAPDF6Interface::pdfTracker.find(setName);
168 info->errorMsg(
"Error in LHAPDF6::init: unknown PDF " + setName);
170 }
else if ((*pdfs).size() == 0) {
171 info->errorMsg(
"Error in LHAPDF6::init: could not initialize PDF "
174 }
else if (member >= (*pdfs).size()) {
175 info->errorMsg(
"Error in LHAPDF6::init: " + setName
176 +
" does not contain requested member");
179 pdf = (*pdfs)[member];
183 muPDFSave = pdf->info().get_entry_as<
double>(
"MUp");
184 mdPDFSave = pdf->info().get_entry_as<
double>(
"MDown");
185 mcPDFSave = pdf->info().get_entry_as<
double>(
"MCharm");
186 msPDFSave = pdf->info().get_entry_as<
double>(
"MStrange");
187 mbPDFSave = pdf->info().get_entry_as<
double>(
"MBottom");
189 nMembersSave = pdf->info().get_entry_as<
int>(
"NumMembers");
197 void LHAPDF6::xfUpdate(
int,
double x,
double Q2) {
200 if (x < pdf->xMin() && !extrapol) x = pdf->xMin();
201 if (x > pdf->xMax() ) x = pdf->xMax();
202 if (Q2 < pdf->q2Min() ) Q2 = pdf->q2Min();
203 if (Q2 > pdf->q2Max() ) Q2 = pdf->q2Max();
206 xg = pdf->xfxQ2(21, x, Q2);
207 xu = pdf->xfxQ2(2, x, Q2);
208 xd = pdf->xfxQ2(1, x, Q2);
209 xs = pdf->xfxQ2(3, x, Q2);
210 xubar = pdf->xfxQ2(-2, x, Q2);
211 xdbar = pdf->xfxQ2(-1, x, Q2);
212 xsbar = pdf->xfxQ2(-3, x, Q2);
213 xc = pdf->xfxQ2(4, x, Q2);
214 xb = pdf->xfxQ2(5, x, Q2);
215 xgamma = pdf->xfxQ2(22, x, Q2);
232 void LHAPDF6::calcPDFEnvelope(
int idNow,
double xNow,
double Q2NowIn,
236 double x1 = (xNow < pdf->xMin() && !extrapol)
237 ? pdf->xMin() : xNow;
238 if (x1 > pdf->xMax() ) x1 = pdf->xMax();
239 double Q2Now = (Q2NowIn < pdf->q2Min() )
240 ? pdf->q2Min() : Q2NowIn;
241 if (Q2Now > pdf->q2Max() ) Q2Now = pdf->q2Max();
244 vector<double> xfCalc((*pdfs).size());
245 for(
int iMem = 0; iMem < (*pdfs).size(); ++iMem) {
246 if (valSea==0 || (idNow != 1 && idNow != 2)) {
247 xfCalc[iMem] = (*pdfs)[iMem]->xfxQ2(idNow, x1, Q2Now);
248 }
else if (valSea==1 && (idNow == 1 || idNow == 2 )) {
249 xfCalc[iMem] = (*pdfs)[iMem]->xfxQ2(idNow, x1, Q2Now) -
250 (*pdfs)[iMem]->xfxQ2(-idNow, x1, Q2Now);
251 }
else if (valSea==2 && (idNow == 1 || idNow == 2 )) {
252 xfCalc[iMem] = (*pdfs)[iMem]->xfxQ2(-idNow, x1, Q2Now);
257 ::LHAPDF::PDFUncertainty xfErr = (*pdfs).info.uncertainty(xfCalc);
258 pdfEnvelope.centralPDF = xfErr.central;
259 pdfEnvelope.errplusPDF = xfErr.errplus;
260 pdfEnvelope.errminusPDF = xfErr.errminus;
261 pdfEnvelope.errsymmPDF = xfErr.errsymm;
262 pdfEnvelope.scalePDF = xfErr.scale;
269 void LHAPDF6::calcPDFEnvelope(pair<int,int> idNows, pair<double,double> xNows,
270 double Q2NowIn,
int valSea) {
273 double x1 = (xNows.first < pdf->xMin() && !extrapol)
274 ? pdf->xMin() : xNows.first;
275 if (x1 > pdf->xMax() ) x1 = pdf->xMax();
276 double x2 = (xNows.second < pdf->xMin() && !extrapol)
277 ? pdf->xMin() : xNows.second;
278 if (x2 > pdf->xMax() ) x2 = pdf->xMax();
279 double Q2Now = (Q2NowIn < pdf->q2Min() )
280 ? pdf->q2Min() : Q2NowIn;
281 if (Q2Now > pdf->q2Max() ) Q2Now = pdf->q2Max();
284 vector<double> xfCalc((*pdfs).size());
285 pdfEnvelope.pdfMemberVars.resize((*pdfs).size());
286 for(
int iMem = 0; iMem < (*pdfs).size(); ++iMem) {
287 if (valSea == 0 || (idNows.first != 1 && idNows.first != 2 ) ) {
288 xfCalc[iMem] = (*pdfs)[iMem]->xfxQ2(idNows.first, x1, Q2Now);
289 }
else if (valSea == 1 && (idNows.first == 1 || idNows.first == 2)) {
290 xfCalc[iMem] = (*pdfs)[iMem]->xfxQ2(idNows.first, x1, Q2Now)
291 - (*pdfs)[iMem]->xfxQ2(-idNows.first, x1, Q2Now);
292 }
else if (valSea == 2 && (idNows.first == 1 || idNows.first == 2 )) {
293 xfCalc[iMem] = (*pdfs)[iMem]->xfxQ2(-idNows.first, x1, Q2Now);
295 xfCalc[iMem] = max(0.0, xfCalc[iMem]);
296 if (valSea == 0 || (idNows.second != 1 && idNows.second != 2)) {
298 (PDFMINVALUE, (*pdfs)[iMem]->xfxQ2(idNows.second, x2, Q2Now));
299 }
else if (valSea == 1 && (idNows.second == 1 || idNows.second == 2 )) {
301 ((*pdfs)[iMem]->xfxQ2(idNows.second, x2, Q2Now) - (*pdfs)[iMem]->xfxQ2
302 (-idNows.second, x2, Q2Now), PDFMINVALUE);
303 }
else if (valSea == 2 && (idNows.second == 1 || idNows.second == 2 )) {
305 ((*pdfs)[iMem]->xfxQ2(-idNows.second, x2, Q2Now), PDFMINVALUE);
307 pdfEnvelope.pdfMemberVars[iMem] = xfCalc[iMem];
311 ::LHAPDF::PDFUncertainty xfErr = (*pdfs).info.uncertainty(xfCalc);
312 pdfEnvelope.centralPDF = xfErr.central;
313 pdfEnvelope.errplusPDF = xfErr.errplus;
314 pdfEnvelope.errminusPDF = xfErr.errminus;
315 pdfEnvelope.errsymmPDF = xfErr.errsymm;
316 pdfEnvelope.scalePDF = xfErr.scale;
324 extern "C" LHAPDF6* newLHAPDF(
int idBeamIn,
string setName,
int member,
326 return new LHAPDF6(idBeamIn, setName, member, 1, infoPtr);
330 extern "C" void deleteLHAPDF(LHAPDF6* pdf) {
339 #endif // end Pythia8_LHAPDF6_H