(***********************************************************************
This file was generated automatically by the Mathematica front end.
It contains Initialization cells from a Notebook file, which typically
will have the same name as this file except ending in ".nb" instead of
".m".

This file is intended to be loaded into the Mathematica kernel using
the package loading commands Get or Needs.  Doing so is equivalent to
using the Evaluate Initialization Cells menu command in the front end.

DO NOT EDIT THIS FILE.  This entire file is regenerated automatically 
each time the parent Notebook file is saved in the Mathematica front end.
Any changes you make to this file will be overwritten.
***********************************************************************)



Print["Loading Package: PDF"];
Print["PDF's from CTEQ5"];
Print["Eur.Phys.J.C12:375-392,2000 "];
Print["*** Warning *** Unofficial release. "];
Print["*** Cross-check with official Fortran code."];
Print[" Version 1.0: Written by Tamara Trout & Fred Olness, October 1, 2000"];
Print[" "];
Print["In case of problems, contact:"];
Print["Fred Olness: olness@mail.physics.smu.edu"];




BeginPackage["cteq5pdf`"];

cteq5pdf::usage = "cteq5pdf[iset, iparton, x, q] The function call is: cteq5pdf[iset, iparton, x, q]";
name::usage= "name[iset] Gives the names of the pdf set ";
parton::usage= "parton[iflavor] Gives the names of the parton ";


Begin["`Private`"];

protected = Unprotect[cteq5pdf];

SetAttributes[cteq5pdf,ReadProtected]; 

name[1]  = "CTEQ5 Set  1: CTEQ5M. ";
name[2]  = "CTEQ5 Set  2: CTEQ5D. 	*** not yet implemented *** ";
name[3]  = "CTEQ5 Set  3: CTEQ5L. LO (evolution) version of CTEQ5M.";



parton[-6]= "t-bar quark";
parton[-5]= "b-bar quark";
parton[-4]= "c-bar quark";
parton[-3]= "s-bar quark";
parton[-2]= "d-bar quark";
parton[-1]= "u-bar quark";
parton[ 0]= "gluon";
parton[ 1]= "u quark";
parton[ 2]= "d quark";
parton[ 3]= "s quark";
parton[ 4]= "c quark";
parton[ 5]= "b quark";
parton[ 6]= "t quark";






listTmp ={{{4.289071080000001, -2.53687, -1.25994802}, {1.332497, -0.370371789, 0.128863797}, {119.198997, -0.854873896, -1.96303999}, 
 
   {24.2886295, 1.90703499, -0.4606457050000001}, {-0.621693492, 0.236996293, -0.00790994894}, 
 
   {-2.73445797, -0.724567294, -0.6351373790000001}, {-1.74387205, -1.12892103, -0.284196913}, {-6.800138, 2.49362707, -1.07572401}}, 
 
  {{0.983941019, 0.0416842587, -0.0501895212}, {0.754468679, 0.0325507484, -0.04706680030000001}, 
 
   {-94.4997177, 1.07477105, 2.05605507}, {2.00680995, -0.126591504, 0.007153556220000001}, 
 
   {1.24544001, -0.103151001, 0.004916523120000001}, {2.92717409, 0.482270896, -0.0108878696}, {3.3457551, 0.318776488, 0.137812406}, 
 
   {3.03655505, 0.332473308, 0.200829804}}, {{-16.5196095, 9.24626064, 5.996399880000001}, 
 
   {-0.763881385, 0.5008313060000001, -0.0923737437}, {3.70106411, -0.00116794696, 0.193357304}, 
 
   {-18.8454609, -2.3394711, 5.74067879}, {-7.06082392, -0.0387528315, 0.178498104}, {-17.7101707, -1.41663504, 8.4676218}, 
 
   {-20.3761501, 4.12168694, 0.223652005}, {-5.203878880000001, -8.49347591, -4.523208140000001}}, 
 
  {{-20.7793598, 9.78646946, 7.656465050000001}, {-0.368988901, -1.05509806, -0.4645065070000001}, 
 
   {117.134499, -1.06454003, -1.87531197}, {-25.2789192, -2.04412389, 12.8046999}, {-7.43059492, 0.196457207, -0.128499895}, 
 
   {-49.72782140000001, -3.34854698, 17.6706104}, {-47.0310402, 5.35308695, -1.45534694}, {-1.52423894, -3.41191196, -17.7186699}}, 
 
  {{30.5492592, 1.88953602, 1.38054097}, {39.9160995, 1.97988105, 1.77581406}, {-101.445297, -0.570742726, 0.04511241990000001}, 
 
   {-101.382401, -1.59419894, 0.221640095}, {-6.89780998, 2.620543, 0.00801255275}, {-7.10276985, -3.20533705, 0.410170406}, 
 
   {-10.6022997, -1.55112195, -1.07886302}, {-10.9944401, 1.32093, -2.35383105}}, 
 
  {{30.8469505, -12.1230297, -10.5355101}, {6.201079850000001, 2.04628801, 0.380457103}, {6.36516809, 1.27535403, -0.496408105}, 
 
   {80.7092972, 1.79207206, -21.6436405}, {15.0771303, 0.0234030709, 2.48253489}, {71.69698330000001, -2.20598507, -24.6393108}, 
 
   {50.8889198, -8.19730377, 8.08345127}, {16.9929905, -35.65802, 35.6687202}}, 
 
  {{-14.2677803, 6.23953676, 5.25481892}, {-0.802789986, -0.7011687760000001, -0.804961205}, 
 
   {-3.37069297, -1.12202001, 0.05947751180000001}, {-46.41049960000001, 0.197733805, 12.7301397}, 
 
   {-1.815341, -1.53869796, -2.01420808}, {-40.9034691, 2.10348606, 14.1650696}, {-28.1907005, 4.554086210000001, -5.89099503}, 
 
   {-14.6579304, 27.0336494, -21.7637196}}, {{-19.0981102, 3.695678, 5.49572897}, {-8.63130474, -3.98119998, 0.697015285}, 
 
   {-5.327270030000001, -0.929355621, 0.662994027}, {-39.1056786, 1.71963203, 10.8652496}, {-25.7193203, 0.290394098, -2.84820604}, 
 
   {-29.5263901, 5.37613583, 7.82558489}, {-10.9823799, 2.590096, -8.06287861}, {0., 0., 0.}}, 
 
  {{0.0188975092, 0.00502719311, 0.0006624896199999999}, {0.0237122998, 0.00537268305, 0.00111870095}, 
 
   {0.0243751295, 0.00160093897, 0.0006855336249999999}, {-1.18549597, -0.190584704, -0.00087441178}, {0., 0., 0.}, {0., 0., 0.}, 
 
   {0., 0., 0.}, {0., 0., 0.}}}; 
   


   
{mexvecM, mlfvecM, ut1vecM, ut2vecM, alfvecM, qmavecM} = {{8, 8, 8, 8, 7, 7, 7, 6}, {2, 2, 2, 2, 2, 2, 2, 2}, 
    {5.141718, 4.138426, -1.026789, 5.243571, 4.78221, 4.518239, 2.78323, 16.19654}, 
    {-1.346944, -3.221374, -9.051707, -2.870513, -19.76856, -2.69059, -1.746328, -3.367346}, 
    {0.5260555, 0.49609620000000004, 0.9462977, 0.6701448, 0.7558374, 0.6124079, 1.115653, 0.005109891}, 
    {0, 0, 0, 0, 0, 0, 1.3, 4.5}}; 



Clear[faux5MI,tmp,x,q]

faux5MI[ifl_?IntegerQ,x_,q_]:=
Module[{tmp1,tmp2,tempam,tmp,sb,sb1,af,y,u
     ,part1,part2,part3,part4},

sb1 = Log[Log[q / alfvecM[[-ifl + 3]]]] - 1.2;

af = Table[     listTmp[[i+1, -ifl+3,0+1]] 
    + sb1     * listTmp[[i+1, -ifl+3,1+1]] 
    + (sb1^2) * listTmp[[i+1, -ifl+3,2+1]], {i, 0, 8}];

y = -Log[x];
u = Log[x/0.00001];

part1 = af[[ 2 ]]*y^(1 + 0.01*af[[ 5 ]])*(1 + af[[ 9 ]]*u);

part2 = af[[ 1 ]]*(1 - x) + af[[ 4 ]]*x;

part3 = x*(1 - x)*(af[[ 6 ]] + af[[ 7 ]]*(1 - x) + af[[ 8 ]]*x*(1 - x));

part4 = ut1vecM[[-ifl + 3]] * Log[1 - x] + af[[ 3 ]] * Log[1 + E^ut2vecM[[-ifl + 3]] - x];

tmp1 = Exp[Log[x] + part1 + part2 + part3 +part4]; (* faux5MI[-ifl + 3] *)

tmp2= tmp1 * (1-qmavecM[[-ifl + 3]]/q );  

Return[tmp2]
] /; ((ifl>=-5)&&(ifl<=2))

Clear[ctq5MI,temp,sum,ratio,x,q]

ctq5MI[ifl_?IntegerQ,x_,q_]:=
Module[{temp,sum,ratio},
     
	If[ ((ifl>=-5)&&(ifl<=5)),
		
		 sum = faux5MI[-1,x,q];
         ratio = faux5MI[-2,x,q];
         
		 If[ ifl == -2,   
		  
			temp = sum * ratio / (1 + ratio),
			
			If[ ifl == -1,
				temp = sum / (1 + ratio),
				
				If[ ifl == 3 || ifl ==4 || ifl == 5,
					temp = faux5MI[-ifl,x,q],
					temp = faux5MI[ifl,x,q]
					]
				]
			],	
			
		temp = 0
		];	
			
	Return[temp]
] ; 





listLtemp =
{{{5.292615890000001, -2.75190997, -2.48899007}, {0.990530014, -0.4502235050000001, 0.1624441}, {119.357201, -3.88684511, -1.13396502}, 
 
   {26.4744091, 10.5927696, -0.917665422}, {-0.6556774970000001, 0.249018997, 0.0396648496}, {1.58093095, -2.27382588, -1.822245}, 
 
   {-0.829366088, -3.98237491, -0.06494282930000001}, {-6.03123713, 1.99272704, -1.07633102}}, 
 
  {{0.971442401, 0.0101182703, -0.0102366004}, {0.88675338, 0.0163082909, -0.04049085080000001}, {-94.2144928, 3.9958849, 1.60736299}, 
 
   {1.99063599, 0.0855891779, 0.04248667140000001}, {1.30510199, -0.118892498, -0.004600869960000001}, 
 
   {2.70264411, 0.676324308, 0.00723158615}, {2.75461793, 0.833863616, -0.06885159759999999}, 
 
   {2.93391204, 0.5839673880000001, 0.0750943497}}, {{-16.5100594, 7.959721090000001, 8.81056309}, 
 
   {0.854797423, 0.333630115, 0.137138799}, {4.206383230000001, 0.248595402, 0.249746799}, {-14.7609501, -32.7625504, 1.55811}, 
 
   {-2.37143612, 0.356681406, -0.283468306}, {-18.5792408, 3.90750003, 5.8501091}, {-16.5798702, 14.3914299, -0.688723981}, 
 
   {-8.28491879, 1.48859298, -0.825167775}}, {{-16.4339409, 5.892854210000001, 9.34887409}, {0.294111311, -1.52790499, 0.233187899}, 
 
   {121.055702, -3.01576495, -1.42365098}, {-2.9668889, -36.4903717, 1.19591403}, {-6.152825830000001, 0.833987713, -0.723322988}, 
 
   {-30.4479294, 2.63933206, 5.56664419}, {-28.0070305, 15.3596601, -0.7377693060000001}, {-19.2598591, 2.80575299, -3.01544595}}, 
 
  {{30.6742191, 4.23579597, -0.5112136010000001}, {33.84235, 3.7153151, 0.827692986}, {-101.389702, -0.7113478180000001, 0.262186497}, 
 
   {-100.051903, -2.4646349, 0.196484894}, {-8.34655762, 2.89216805, 0.213709906}, {-4.25801086, -5.429244040000001, 0.441894591}, 
 
   {-6.46021605, -4.78301907, 0.4913297}, {-9.48048306, -0.976783693, -1.16554403}}, 
 
  {{23.5252609, -5.30516815, -11.69174}, {6.23011494, 3.13463902, -1.72909904}, {-1.31240404, -0.929769099, -0.156253099}, 
 
   {37.1833115, 47.00389100000001, -2.77214193}, {12.7952995, 0.102111399, 0.578743875}, {34.6525917, -5.53260422, -4.90415287}, 
 
   {31.4183006, -31.7803097, 7.13601303}, {21.9319496, -17.8851795, 9.46090794}}, 
 
  {{-10.9545097, 3.00657701, 5.63813591}, {-1.18692803, -0.328245997, 0.105201997}, {1.62713695, 0.4954110980000001, -0.638700902}, 
 
   {-18.7272205, -22.91189, 1.08905196}, {0.5858815910000001, -1.94037497, -0.402926892}, {-16.5885792, 2.92327499, 2.2662859}, 
 
   {-18.0250893, 18.6216297, -4.632843020000001}, {-13.2737703, 12.01754, -6.277843950000001}}, 
 
  {{-11.7225103, -2.18362403, 4.95579386}, {-8.54570198, -6.247947220000001, 3.69256091}, {0.153769806, -0.248787805, 0.830594718}, 
 
   {-16.2814598, -18.2399292, 2.53736901}, {-27.9572506, -0.5263391730000001, 1.29022896}, {-11.49263, 2.87747502, -0.799910486}, 
 
   {-12.4041204, 25.6538601, -10.6657}, {0., 0., 0.}}, 
 
  {{0.0166253299, 0.00762287015, -0.00048958871}, {0.01724598, 0.007120464929999999, 0.00004003645880000001}, 
 
   {0.0249644797, 0.00245782291, 0.000823427574}, {-1.15629995, -0.128049493, 0.05153245110000001}, {0., 0., 0.}, {0., 0., 0.}, 
 
   {0., 0., 0.}, {0., 0., 0.}}};

{mexvecL, mlfvecL, ut1vecL, ut2vecL, alfvecL, qmavecL} = {{8, 8, 8, 8, 7, 7, 7, 6}, {2, 2, 2, 2, 2, 2, 2, 2}, 
 	{4.971265, 2.612618, -0.4656819, 3.862583, 0.1895615, 3.753257, 4.400772, 5.562568},
 	{-1.105128, -125830.4, -274.2389999999999, -1.265969, -3.069097, -1.113085, -1.356116, -1.801317}, 
    {0.2987216, 0.3407552, 0.4491863000000001, 0.2457668, 0.5293999000000001, 0.3713141, 0.03712017, 0.00495201}, 
    {0., 0., 0., 0., 0., 0., 1.3, 4.5}}; 




Clear[faux5L,tmp,x,q]

faux5L[ifl_?IntegerQ,x_,q_]:=
Module[{tmp1,tmp2,tempam,tmp,sb,sb1,af,y,u
     ,part1,part2,part3,part4},

sb1 = Log[Log[q / alfvecL[[-ifl + 3]]]] - 1.2;

af = Table[     listLtemp[[i+1, -ifl+3,0+1]] 
    + sb1     * listLtemp[[i+1, -ifl+3,1+1]] 
    + (sb1^2) * listLtemp[[i+1, -ifl+3,2+1]], {i, 0, 8}];

y = -Log[x];
u = Log[x/0.00001];

part1 = af[[ 2 ]]*y^(1 + 0.01*af[[ 5 ]])*(1 + af[[ 9 ]]*u);

part2 = af[[ 1 ]]*(1 - x) + af[[ 4 ]]*x;

part3 = x*(1 - x)*(af[[ 6 ]] + af[[ 7 ]]*(1 - x) + af[[ 8 ]]*x*(1 - x));

part4 = ut1vecL[[-ifl + 3]] * Log[1 - x] + af[[ 3 ]] * Log[1 + E^ut2vecL[[-ifl + 3]] - x];

tmp1 = Exp[Log[x] + part1 + part2 + part3 +part4]; (* faux5L[-ifl + 3] *)

tmp2= tmp1 * (1-qmavecL[[-ifl + 3]]/q );  

Return[tmp2]
] /; ((ifl>=-5)&&(ifl<=2))

Clear[ctq5L,temp,sum,ratio,x,q]

ctq5L[ifl_?IntegerQ,x_,q_]:=
Module[{temp,sum,ratio},
     
	If[ ((ifl>=-5)&&(ifl<=5)),
		
		 sum = faux5L[-1,x,q];
         ratio = faux5L[-2,x,q];
         
		 If[ ifl == -2,   
		  
			temp = sum * ratio / (1 + ratio),
			
			If[ ifl == -1,
				temp = sum / (1 + ratio),
				
				If[ ifl == 3 || ifl ==4 || ifl == 5,
					temp = faux5L[-ifl,x,q],
					temp = faux5L[ifl,x,q]
					]
				]
			],	
			
		temp = 0
		];	
			
	Return[temp]
	]



(* Iset is the set number: 1 for CTEQ5M1 or 3 for CTEQ5L *)
Clear[pdftemp];
cteq5pdf[iset_, iparton_, x_, q_]:=
Module[{},

	pdftemp =Switch[ iset
		,1,ctq5MI[iparton, x, q]
		,2,0
		,3,ctq5L[iparton, x, q]
		];
	If[pdftemp<0.0,pdftemp=0.0];  (* Protect *)
	
	Return[pdftemp]
] /; ((iset == 1) || (iset == 3))



Protect[Evaluate[protected]];

End[];

Protect[cteq5pdf, name,parton];

EndPackage[];