~maddevelopers/mg5amcnlo/WWW5_caching

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
      subroutine set_invarients(nfinal,ninvar)
c***************************************************************************
c     Calculates all of the invarients for a 2->n process
c***************************************************************************
      implicit none
c     
c     Constants
c
      include 'genps.inc'
c
c     Arguments
c
      integer nfinal,ninvar
c
c     Local
c     
      integer ip1,ip2,ipstart,ipstop,np,i
      integer ncycle
      character*10 buff
c
c     Global
c
      integer              imom(maxinvar),ninvarients
      common/to_invarients/imom          ,ninvarients
c-----
c  Begin Code
c-----

      do i=1,nfinal
         imom(i)=i
      enddo
      ipstart=1
      ipstop =nfinal
      np     =nfinal
c
c     First do all the s-channel
c
      do ncycle=2,nfinal-1
         do ip1 = ipstart,ipstop-1
            do ip2=int((real(imom(ip1))/10.-imom(ip1)/10)*10+.1)+1,
     $           nfinal
               np=np+1
               if (np .gt. maxinvar) then
                  print*,'Sorry too many invarients',np,ip1,ip2,ncycle
                  stop
               endif
               imom(np)=imom(ip1)*10+imom(ip2)
               if (imom(np) .lt. 10) then
                  write(buff,'(a2,i1)') 'S?',imom(np)
               elseif (imom(np) .lt. 100) then
                  write(buff,'(a2,i2)') 'S?',imom(np)
               elseif (imom(np) .lt. 1000) then
                  write(buff,'(a2,i3)') 'S?',imom(np)
               elseif (imom(np) .lt. 10000) then
                  write(buff,'(a2,i4)') 'S?',imom(np)
               elseif (imom(np) .lt. 100000) then
                  write(buff,'(a2,i5)') 'S?',imom(np)
               else
                  write(buff,'(a2,i6)') 'S?',imom(ip1)
               endif
c               call hbook1(100+np-nfinal,buff,100,0.,1.,0.)
c               write(*,'(i4,i6)') np-nfinal,imom(np)
               write(*,'(i4,a1,a6)') np-nfinal,'=',buff
               if ((np-nfinal)/7 .eq. real(np-nfinal)/7.) write(*,*)' '
            enddo
         enddo
         ipstart=ipstop+1
         ipstop = np
      enddo
c
c     Now do the t-channel
c
      ipstop = np
      do ip1 = 1,ipstop
c         write(*,'(i4,a2,i6)') np-nfinal+ip1,'a-',imom(ip1)
         if (imom(ip1) .lt. 10) then
            write(buff,'(a2,i1)') 'T?',imom(ip1)
         elseif (imom(ip1) .lt. 100) then
            write(buff,'(a2,i2)') 'T?',imom(ip1)
         elseif (imom(ip1) .lt. 1000) then
            write(buff,'(a2,i3)') 'T?',imom(ip1)
         elseif (imom(ip1) .lt. 10000) then
            write(buff,'(a2,i4)') 'T?',imom(ip1)
         elseif (imom(ip1) .lt. 100000) then
            write(buff,'(a2,i5)') 'T?',imom(ip1)
         else
            write(buff,'(a2,i6)') 'T?',imom(ip1)
         endif
c         call hbook1(100+np-nfinal+ip1,buff,100,0.,1.,0.)
c         write(*,*) np-nfinal+ip1,buff
         write(*,'(i4,a1,a6)') np-nfinal+ip1,'=',buff
         if ((np-nfinal+ip1)/7 .eq. real(np-nfinal+ip1)/7.) write(*,*)
      enddo
      write(*,*)
      print*,'Particles, Invarients',nfinal,np-nfinal+np
      ninvarients=np-nfinal+np
      ninvar=ninvarients
      if (ninvarients .gt. maxinvar) then
         print*,'Error too many invarients to map'
c         stop
      endif
      end


      subroutine fill_invarients(nfinal,p1,s,xx)
c***************************************************************************
c     Calculates all of the invarients for a 2->n process
c***************************************************************************
      implicit none
c     
c     Constants
c     
      include 'genps.inc'
c
c     Arguments
c
      integer nfinal
      double precision p1(0:3,nfinal+2),s,xx(55)
c
c     Local
c     
      integer ip1,ip2,ipstart,ipstop,np,i,j
      integer imom(maxinvar)
      integer ncycle
      character*10 buff
      double precision p(0:3,maxinvar),ptemp(0:3)
c
c     External
c
      double precision dot
      external         dot
c-----
c  Begin Code
c-----

      do i=1,nfinal
         imom(i) = i
         do j=0,3
            p(j,i)=p1(j,i+2)
         enddo
c         write(*,'(i3,4f17.8)') i,(p(j,i),j=0,3)
      enddo
      ipstart=1
      ipstop =nfinal
      np     =nfinal
c
c     First do all the s-channel
c
      do ncycle=2,nfinal-1
         do ip1 = ipstart,ipstop-1
            do ip2=int((real(imom(ip1))/10.-imom(ip1)/10)*10+.1)+1
     $           ,nfinal
               np=np+1
               if (np .gt. maxinvar) then
                  print*,'Sorry too many invarients',np,ip1,ip2,ncycle
                  stop
               endif
               imom(np)=imom(ip1)*10+imom(ip2)
               do j=0,3
                  p(j,np) = p(j,ip1)+p(j,ip2)
               enddo
               xx(np-nfinal) = dot(p(0,np),p(0,np))/s
c               call hfill(100+np-nfinal,
c     &              real(dot(p(0,np),p(0,np))/s),0.,wgt)
c               write(*,'(i4,3f20.8)') np-nfinal,
c     &              real(dot(p(0,np),p(0,np))/s)
            enddo
         enddo
         ipstart=ipstop+1
         ipstop = np
      enddo
c
c     Now do the t-channel
c
      ipstop = np
      do ip1 = 1,ipstop
         do j = 0,3
            ptemp(j)=p1(j,1)-p(j,ip1)
         enddo
         xx(np-nfinal+ip1)= .5d0*(dot(ptemp,ptemp)/s+1d0)
c         call hfill(100+np-nfinal+ip1,real(-dot(ptemp,ptemp)/s),0.,wgt)
c         write(*,'(i4,3f20.8)') np-nfinal+ip1,
c     &         real(-dot(ptemp,ptemp)/s)
      enddo
      end


      subroutine map_invarients(Minvar,nconfigs,ninvar,mincfig,maxcfig,nexternal,nincoming)
c****************************************************************************
c     Determines mappings for each structure of invarients onto integration
c     variables.  Input: Ninvar, iforest.  Output: Minvar, ninvar
c****************************************************************************
      implicit none
c
c     Constants
c
      include 'genps.inc'
      include 'maxconfigs.inc'
c
c     Arguments
c
      integer Minvar(maxdim,lmaxconfigs),nconfigs,ninvar,nexternal,nincoming
      integer mincfig,maxcfig
c
c     Local
c
      integer iconfig, jgrid,j, nbranch
      logical found,tchannel
c
c     Global
c
      integer              imom(maxinvar),ninvarients
      common/to_invarients/imom          ,ninvarients
      integer iforest(2,-max_branch:-1,lmaxconfigs)
      common/to_forest/ iforest

c-----
c  Begin Code
c----

      nbranch = nexternal-2
      jgrid=0
c
c     
c     Try simple mapping if nconfigs = 1
c

      if (nconfigs .eq. 1) then
c         do j=1,3*nbranch-4+2
         do j=1,maxdim
            minvar(j,mincfig)=j
         enddo
         jgrid=j-1
      else
c      if (ep) jgrid=1
c      if (pp) jgrid=2
      do iconfig=mincfig,maxcfig
         tchannel = .false.         
         do j=1,nbranch-1
            if (iforest(1,-j,iconfig) .eq. 1) then
               tchannel=.true.
            endif
            jgrid=jgrid+1
            minvar(j,iconfig) = jgrid
            if (tchannel .and. j .lt. nbranch-1) then
               jgrid=jgrid+1            
               minvar(nbranch-1+2*j,iconfig)=jgrid
            endif
         enddo             !Each Branch
         if (.not. tchannel .and. nincoming.eq.2) then          !Don't need last s-channel
            jgrid=jgrid-1
            minvar(nbranch-1,iconfig)=0
         endif
c         if (pp) then
c            jgrid=jgrid+1
c            minvar(3*nbranch-3,iconfig)=jgrid
c            jgrid=jgrid+1
c            minvar(3*nbranch-2,iconfig)=jgrid
c         elseif (ep) then
c            jgrid=jgrid+1
c            minvar(3*nbranch-3,iconfig)=jgrid
c         endif
      enddo  !Each configurations
      endif
      ninvar = jgrid
      end

      subroutine sortint(n,ra)
      integer ra(n)
      l=n/2+1
      ir=n
10    continue
        if(l.gt.1)then
          l=l-1
          rra=ra(l)
        else
          rra=ra(ir)
          ra(ir)=ra(1)
          ir=ir-1
          if(ir.eq.1)then
            ra(1)=rra
            return
          endif
        endif
        i=l
        j=l+l
20      if(j.le.ir)then
          if(j.lt.ir)then
            if(ra(j).lt.ra(j+1))j=j+1
          endif
          if(rra.lt.ra(j))then
            ra(i)=ra(j)
            i=j
            j=j+j
          else
            j=ir+1
          endif
        go to 20
        endif
        ra(i)=rra
      go to 10
      end