LHAPDF veraion 5.9.1
[u/mrichter/AliRoot.git] / LHAPDF / lhapdf-5.9.1 / src / wrapXNN.f
1 !***********************************************************************
2 !     Initial parameterization: NN (simplified wrt our code)            
3 !***********************************************************************
4                                                                         
5       subroutine LH_PDFIN(X,PDFTMP) 
6       implicit none 
7 !                                                                       
8       INCLUDE 'parmsetup.inc' 
9       CHARACTER*16 name(nmxset) 
10       INTEGER nmem(nmxset),ndef(nmxset),mmem 
11       COMMON/NAME/name,nmem,ndef,mmem 
12 !                                                                       
13       INTEGER KREP 
14       integer MXREP 
15       parameter(MXREP=1e3) 
16       integer MXPDF 
17       parameter(MXPDF=13) 
18                                 !# pdfs parametrized with NN            
19       integer NTOTPDF 
20       parameter(NTOTPDF=5) 
21       integer MXPAR 
22       parameter(MXPAR=2e2) 
23 !                                                                       
24       integer JPDF 
25       REAL*8 X 
26       REAL*8 PDFTMP(MXPDF),PDFFLV(NTOTPDF) 
27 !                                                                       
28 !     Warnings                                                          
29                                                                         
30       KREP = MMEM 
31       if(X.gt.1d0) then 
32          write(6,*) "X = ",X 
33          write(6,*) 'X greater than 1 in pdfin routine !' 
34          call exit(-10) 
35       elseif(X.le.0d0) then 
36          write(6,*) "X = ",X 
37          write(6,*) 'X less or equal 0 in pdfin routine !' 
38          call exit(-10) 
39       endif 
40 !                                                                       
41 !     Neural network parton distributions                               
42       do JPDF=1,NTOTPDF 
43          call LH_NNPDF(X,JPDF,KREP,PDFFLV(JPDF)) 
44       enddo 
45       call LH_PDFINPAR2EVLN(PDFFLV,PDFTMP) 
46 !                                                                       
47       return 
48       END                                           
49                                                                         
50 !***********************************************************************
51 !     those commons might be changed depending on those put in inputPDF.
52 !***********************************************************************
53                                                                         
54       subroutine LH_NNPDF(X,JPDF,KREP,PDFNET) 
55       implicit none 
56 !                                                                       
57       integer KREP 
58       integer MXREP 
59       parameter(MXREP=1e3) 
60       integer MXPDF 
61       parameter(MXPDF=13) 
62                                 !# pdfs parametrized with NN            
63       integer NTOTPDF 
64       parameter(NTOTPDF=5) 
65       integer MXPAR 
66       parameter(MXPAR=2e2) 
67 !                                                                       
68                                 !NN basic parameters                    
69       integer MXL,MXN 
70       parameter(MXL=5,MXN=10) 
71 !                                                                       
72                                             ! NN architecture           
73       integer TNL(NTOTPDF),NEU(MXL,NTOTPDF) 
74       REAL*8 XNOR(2,NTOTPDF),PDFNOR(2,NTOTPDF) 
75       REAL*8 PDFEXP(2,NTOTPDF) 
76       REAL*8 PDFDELTA(NTOTPDF) 
77       REAL*8 XDELTALIN(NTOTPDF),XDELTALOG(NTOTPDF) 
78       common/nnpdf10CNNARC/PDFEXP,PDFNOR,PDFDELTA,XDELTALIN             &
79      &     ,XDELTALOG,XNOR,NEU,TNL                                      
80 !                                                                       
81       real*8 PARTR(MXPAR,0:MXREP,MXPDF) 
82       real*8 ANORMTR(MXPDF,0:MXREP) 
83       common/nnpdf10CPARTR/PARTR,ANORMTR 
84 !                                                                       
85       INTEGER ipdf,JPDF,NTMP(MXL),L 
86       REAL*8 PDFOUT,X 
87       REAL*8 XNNIN(MXN),XNNOUT,XNN(MXN,MXL) 
88       REAL*8 PDFNET 
89 !                                                                       
90 !     Temporary array of neuron number                                  
91       do L=1,TNL(JPDF) 
92          NTMP(L)=NEU(L,JPDF) 
93       enddo 
94 !                                                                       
95       do IPDF=1,NTOTPDF 
96 !     Evaluate fixed coefficients used in the normalizaion of NN        
97          XDELTALIN(IPDF)=1.d0/(XNOR(2,IPDF)-XNOR(1,IPDF))*0.8d0 
98          XDELTALOG(IPDF)=1.d0/dlog(XNOR(2,IPDF)/XNOR(1,IPDF))*0.8d0 
99          PDFDELTA(IPDF)=(PDFNOR(2,IPDF)-PDFNOR(1,IPDF))/0.8d0 
100       enddo 
101 !                                                                       
102       XNNIN(1)=(X-XNOR(1,JPDF))*XDELTALIN(JPDF)+0.1d0 
103       XNNIN(2)=dlog(X/XNOR(1,JPDF))*XDELTALOG(JPDF)+0.1d0 
104 !                                                                       
105 !     Call neural network routine                                       
106 !                                                                       
107       call LH_NNOUT(XNNIN,TNL(JPDF),NTMP,PARTR(1,KREP,JPDF),XNN,XNNOUT) 
108 !                                                                       
109 !     Output normalization: the delta is defined in pdfcreate.f         
110 !                                                                       
111       PDFOUT=PDFNOR(1,JPDF)+(XNNOUT - 0.1d0)*PDFDELTA(JPDF) 
112 !                                                                       
113 !     Preprocessing exponents                                           
114 !                                                                       
115       PDFNET=((1.-x)**PDFEXP(1,JPDF))*PDFOUT*x**(-PDFEXP(2,JPDF)) 
116 !                                                                       
117 !     PDF normalization factor (fixed in some cases by sum rules)       
118 !                                                                       
119       PDFNET= ANORMTR(JPDF,KREP) * PDFNET 
120 !                                                                       
121       return 
122       END                                           
123 !                                                                       
124 !     file: NNSUB.f --> It evaluates NN output                          
125 !                                                                       
126       subroutine LH_NNOUT(xnnin,tnl,n,PAR,xnn,xnnout) 
127       implicit none 
128 !                                                                       
129       integer MXL,MXN 
130       parameter(MXL=5,MXN=10) 
131       integer MXPAR 
132       parameter(MXPAR=2e2) 
133 !                                                                       
134       integer tnl,n,l,i,ii,j 
135       REAL*8 xnnin,xnnout,xnn,LH_G,h 
136       dimension n(mxl) 
137       dimension xnnin(mxn) 
138       dimension xnn(mxn,mxl) 
139 !                                                                       
140       REAL*8 PAR(mxpar) 
141       integer IPAR 
142 !                                                                       
143       IPAR=0 
144       do ii=1,n(1) 
145          xnn(ii,1)=xnnin(ii) 
146       enddo 
147       do l=1,tnl-1 
148          xnn(n(l)+1,l)=1d0 
149       enddo 
150                                                                         
151       do   l=2,tnl-1 
152          do  i=1,n(l) 
153             h=0. 
154             do j=1,n(l-1)+1 
155                IPAR=IPAR+1 
156                h=h+PAR(IPAR)*xnn(j,l-1) 
157             enddo 
158             xnn(i,l)=LH_G(h) 
159          enddo 
160       enddo 
161       do i=1,n(tnl) 
162          h=0. 
163          do j=1,n(l-1)+1 
164             IPAR=IPAR+1 
165             h=h+PAR(IPAR)*xnn(j,l-1) 
166          enddo 
167          xnn(i,tnl)=h 
168       enddo 
169                                                                         
170       xnnout=xnn(1,tnl) 
171                                                                         
172       return 
173       END                                           
174 !                                                                       
175 !     Neural network activation function                                
176 !                                                                       
177       function LH_g(x) 
178       implicit none 
179       REAL*8 LH_g,x 
180 !                                                                       
181       LH_g=1./(1.+DExp(-x)) 
182 !                                                                       
183       return 
184       END