~maddevelopers/mg5amcnlo/3.0.2-alpha0

« back to all changes in this revision

Viewing changes to Template/SubProcesses/reweight.f

Added Template and HELAS into bzr

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
      double precision function gamma(q0)
 
2
c**************************************************
 
3
c   calculates the branching probability
 
4
c**************************************************
 
5
      implicit none
 
6
      include 'nexternal.inc'
 
7
      include 'message.inc'
 
8
      include 'cluster.inc'
 
9
      include 'sudakov.inc'
 
10
      include 'run.inc'
 
11
      integer i
 
12
      double precision q0, val, add, add2
 
13
      double precision qr,lf
 
14
      double precision alphas
 
15
      external alphas
 
16
      double precision pi
 
17
      parameter (pi=3.141592654d0)
 
18
 
 
19
      gamma=0.0d0
 
20
 
 
21
      if (Q1<m_qmass(iipdg)) return
 
22
      m_lastas=Alphas(alpsfact*q0)
 
23
      val=2d0*m_colfac(iipdg)*m_lastas/PI/q0
 
24
c   if (m_mode & bpm::power_corrs) then
 
25
      qr=q0/Q1
 
26
      if(m_pca(iipdg,iimode).eq.0)then
 
27
        lf=log(1d0/qr-1d0)
 
28
      else 
 
29
        lf=log(1d0/qr)
 
30
      endif
 
31
      val=val*(m_dlog(iipdg)*(1d0+m_kfac*m_lastas/(2d0*PI))*lf+m_slog(iipdg)
 
32
     $   +qr*(m_power(iipdg,1,iimode)+qr*(m_power(iipdg,2,iimode)
 
33
     $   +qr*m_power(iipdg,3,iimode))))
 
34
c   else
 
35
c   val=val*m_dlog*(1d0+m_kfac*m_lastas/(2d0*PI))*log(Q1/q0)+m_slog;
 
36
c   endif
 
37
      if(m_qmass(iipdg).gt.0d0)then
 
38
        val=val+m_colfac(iipdg)*m_lastas/PI/q0*(0.5-q0/m_qmass(iipdg)*
 
39
     $     atan(m_qmass(iipdg)/q0)-
 
40
     $     (1.0-0.5*(q0/m_qmass(iipdg))**2)*log(1.0+(m_qmass(iipdg)/q0)**2))
 
41
      endif
 
42
      val=max(val,0d0)
 
43
      if (iipdg.eq.21) then
 
44
        add=0d0
 
45
        do i=-6,-1
 
46
          if(m_qmass(abs(i)).gt.0d0)then
 
47
            add2=m_colfac(i)*m_lastas/PI/q0/
 
48
     $         (1.0+(m_qmass(abs(i))/q0)**2)*
 
49
     $         (1.0-1.0/3.0/(1.0+(m_qmass(abs(i))/q0)**2))
 
50
          else
 
51
            add2=2d0*m_colfac(i)*m_lastas/PI/q0*(m_slog(i)
 
52
     $         +qr*(m_power(i,1,iimode)+qr*(m_power(i,2,iimode)
 
53
     $         +qr*m_power(i,3,iimode))))
 
54
          endif
 
55
          add=add+max(add2,0d0)
 
56
        enddo
 
57
        val=val+add
 
58
      endif
 
59
      
 
60
      gamma = max(val,0d0)
 
61
 
 
62
      if (btest(mlevel,6)) then
 
63
        write(*,*)'       \\Delta^I_{',iipdg,'}(',
 
64
     &     q0,',',q1,') -> ',gamma
 
65
        write(*,*) val,m_lastas,m_dlog(iipdg),m_slog(iipdg)
 
66
        write(*,*) m_power(iipdg,1,iimode),m_power(iipdg,2,iimode),m_power(iipdg,3,iimode)
 
67
      endif
 
68
 
 
69
      return
 
70
      end
 
71
 
 
72
      double precision function sud(q0,Q11,ipdg,imode)
 
73
c**************************************************
 
74
c   actually calculates is sudakov weight
 
75
c**************************************************
 
76
      implicit none
 
77
      include 'message.inc'
 
78
      include 'nexternal.inc'
 
79
      include 'cluster.inc'      
 
80
      integer ipdg,imode
 
81
      double precision q0, Q11
 
82
      double precision gamma,DGAUSS
 
83
      external gamma,DGAUSS
 
84
      double precision eps
 
85
      parameter (eps=1d-5)
 
86
      
 
87
      sud=0.0d0
 
88
 
 
89
      Q1=Q11
 
90
      iipdg=iabs(ipdg)
 
91
      iimode=imode
 
92
 
 
93
      sud=exp(-DGAUSS(gamma,q0,Q1,eps))
 
94
 
 
95
      if (btest(mlevel,6)) then
 
96
        write(*,*)'       \\Delta^',imode,'_{',ipdg,'}(',
 
97
     &     2*log10(q0/q1),') -> ',sud
 
98
      endif
 
99
 
 
100
      return
 
101
      end
 
102
 
 
103
      double precision function sudwgt(q0,q1,q2,ipdg,imode)
 
104
c**************************************************
 
105
c   calculates is sudakov weight
 
106
c**************************************************
 
107
      implicit none
 
108
      include 'message.inc'
 
109
      integer ipdg,imode
 
110
      double precision q0, q1, q2
 
111
      double precision sud
 
112
      external sud
 
113
      
 
114
      sudwgt=1.0d0
 
115
 
 
116
      if(q2.le.q1)then
 
117
         if(q2.lt.q1.and.btest(mlevel,4))
 
118
     $        write(*,*)'Warning! q2 < q1 in sudwgt. Return 1.'
 
119
         return
 
120
      endif
 
121
 
 
122
      sudwgt=sud(q0,q2,ipdg,imode)/sud(q0,q1,ipdg,imode)
 
123
 
 
124
      if (btest(mlevel,5)) then
 
125
        write(*,*)'       \\Delta^',imode,'_{',ipdg,'}(',
 
126
     &     q0,',',q1,',',q2,') -> ',sudwgt
 
127
      endif
 
128
 
 
129
      return
 
130
      end
 
131
 
 
132
      logical function isqcd(ipdg)
 
133
c**************************************************
 
134
c   determines whether particle is qcd particle
 
135
c**************************************************
 
136
      implicit none
 
137
      integer ipdg, irfl
 
138
 
 
139
      isqcd=.true.
 
140
 
 
141
      irfl=iand(abs(ipdg),63)
 
142
      if (irfl.gt.8.and.irfl.ne.21) isqcd=.false.
 
143
c      write(*,*)'iqcd? pdg = ',ipdg,' -> ',irfl,' -> ',isqcd
 
144
 
 
145
      return
 
146
      end
 
147
 
 
148
      logical function isjet(ipdg)
 
149
c**************************************************
 
150
c   determines whether particle is qcd jet particle
 
151
c**************************************************
 
152
      implicit none
 
153
 
 
154
      include 'cuts.inc'
 
155
 
 
156
      integer ipdg, irfl
 
157
 
 
158
      isjet=.true.
 
159
 
 
160
      irfl=abs(ipdg)
 
161
      if (irfl.gt.maxjetflavor.and.irfl.ne.21) isjet=.false.
 
162
c      write(*,*)'isjet? pdg = ',ipdg,' -> ',irfl,' -> ',isjet
 
163
 
 
164
      return
 
165
      end
 
166
 
 
167
      logical function isparton(ipdg)
 
168
c**************************************************
 
169
c   determines whether particle is qcd jet particle
 
170
c**************************************************
 
171
      implicit none
 
172
 
 
173
      include 'cuts.inc'
 
174
 
 
175
      integer ipdg, irfl
 
176
 
 
177
      isparton=.true.
 
178
 
 
179
      irfl=abs(ipdg)
 
180
      if (irfl.gt.5.and.irfl.ne.21) isparton=.false.
 
181
c      write(*,*)'isparton? pdg = ',ipdg,' -> ',irfl,' -> ',isparton
 
182
 
 
183
      return
 
184
      end
 
185
 
 
186
 
 
187
      subroutine ipartupdate(p,imo,ida1,ida2,ipdg,ipart)
 
188
c**************************************************
 
189
c   Traces particle lines according to CKKW rules
 
190
c**************************************************
 
191
      implicit none
 
192
 
 
193
      include 'ncombs.inc'
 
194
      include 'nexternal.inc'
 
195
      include 'message.inc'
 
196
 
 
197
      double precision p(0:3,nexternal)
 
198
      integer imo,ida1,ida2,i,idmo,idda1,idda2
 
199
      integer ipdg(n_max_cl),ipart(2,n_max_cl)
 
200
 
 
201
      do i=1,2
 
202
        ipart(i,imo)=0
 
203
      enddo
 
204
 
 
205
      idmo=ipdg(imo)
 
206
      idda1=ipdg(ida1)
 
207
      idda2=ipdg(ida2)
 
208
 
 
209
      if (btest(mlevel,1)) then
 
210
        write(*,*) ' updating ipart for: ',ida1,ida2,imo
 
211
      endif
 
212
 
 
213
        if (btest(mlevel,1)) then
 
214
          write(*,*) ' daughters: ',(ipart(i,ida1),i=1,2),(ipart(i,ida2),i=1,2)
 
215
        endif
 
216
 
 
217
c     IS clustering - just transmit info on incoming line
 
218
      if((ipart(1,ida1).ge.1.and.ipart(1,ida1).le.2).or.
 
219
     $   (ipart(1,ida2).ge.1.and.ipart(1,ida2).le.2))then
 
220
        if(ipart(1,ida2).ge.1.and.ipart(1,ida2).le.2)
 
221
     $     ipart(1,imo)=ipart(1,ida2)        
 
222
        if(ipart(1,ida1).ge.1.and.ipart(1,ida1).le.2)
 
223
     $     ipart(1,imo)=ipart(1,ida1)
 
224
        if (btest(mlevel,1)) then
 
225
          write(*,*) ' -> ',(ipart(i,imo),i=1,2)
 
226
c     Set intermediate particle identity
 
227
          if(iabs(idmo).lt.6)then
 
228
            if(iabs(idda1).lt.6) ipdg(imo)=-idda1
 
229
            if(iabs(idda2).lt.6) ipdg(imo)=-idda2
 
230
            idmo=ipdg(imo)
 
231
            if (btest(mlevel,1)) then
 
232
              write(*,*) ' particle identities: ',idda1,idda2,idmo
 
233
            endif
 
234
          endif
 
235
        endif
 
236
        return
 
237
      endif        
 
238
 
 
239
c     FS clustering
 
240
      if(idmo.eq.21.and.idda1.eq.21.and.idda2.eq.21)then
 
241
c     gluon -> 2 gluon splitting: Choose hardest gluon
 
242
        if(p(1,ipart(1,ida1))**2+p(2,ipart(1,ida1))**2.gt.
 
243
     $     p(1,ipart(1,ida2))**2+p(2,ipart(1,ida2))**2) then
 
244
          ipart(1,imo)=ipart(1,ida1)
 
245
          ipart(2,imo)=ipart(2,ida1)
 
246
        else
 
247
          ipart(1,imo)=ipart(1,ida2)
 
248
          ipart(2,imo)=ipart(2,ida2)
 
249
        endif
 
250
      else if(idmo.eq.21.and.idda1.eq.-idda2)then
 
251
c     gluon -> quark anti-quark: use both, but take hardest as 1
 
252
        if(p(1,ipart(1,ida1))**2+p(2,ipart(1,ida1))**2.gt.
 
253
     $     p(1,ipart(1,ida2))**2+p(2,ipart(1,ida2))**2) then
 
254
          ipart(1,imo)=ipart(1,ida1)
 
255
          ipart(2,imo)=ipart(1,ida2)
 
256
        else
 
257
          ipart(1,imo)=ipart(1,ida2)
 
258
          ipart(2,imo)=ipart(1,ida1)
 
259
        endif
 
260
      else if(idmo.eq.idda1.or.idmo.eq.idda1+sign(1,idda2))then
 
261
c     quark -> quark-gluon or quark-Z or quark-h or quark-W
 
262
        ipart(1,imo)=ipart(1,ida1)
 
263
      else if(idmo.eq.idda2.or.idmo.eq.idda2+sign(1,idda1))then
 
264
c     quark -> gluon-quark or Z-quark or h-quark or W-quark
 
265
        ipart(1,imo)=ipart(1,ida2)
 
266
      endif
 
267
      
 
268
      if (btest(mlevel,1)) then
 
269
        write(*,*) ' -> ',(ipart(i,imo),i=1,2)
 
270
      endif
 
271
 
 
272
c     Set intermediate particle identity
 
273
      if(iabs(idmo).lt.6)then
 
274
        if(iabs(idda1).lt.6) ipdg(imo)=idda1
 
275
        if(iabs(idda2).lt.6) ipdg(imo)=idda2
 
276
        idmo=ipdg(imo)
 
277
        if (btest(mlevel,1)) then
 
278
          write(*,*) ' particle identities: ',idda1,idda2,idmo
 
279
        endif
 
280
      endif
 
281
 
 
282
      return
 
283
      end
 
284
      
 
285
      logical function isjetvx(imo,ida1,ida2,ipdg,ipart)
 
286
c***************************************************
 
287
c   Checks if a qcd vertex generates a jet
 
288
c***************************************************
 
289
      implicit none
 
290
 
 
291
      include 'ncombs.inc'
 
292
      include 'nexternal.inc'
 
293
 
 
294
      integer imo,ida1,ida2,idmo,idda1,idda2,i
 
295
      integer ipdg(n_max_cl),ipart(2,n_max_cl)
 
296
      logical isqcd,isjet
 
297
      external isqcd,isjet
 
298
 
 
299
      idmo=ipdg(imo)
 
300
      idda1=ipdg(ida1)
 
301
      idda2=ipdg(ida2)
 
302
 
 
303
c     Check QCD vertex
 
304
      if(.not.isqcd(idmo).or..not.isqcd(idda1).or.
 
305
     &     .not.isqcd(idda2)) then
 
306
         isjetvx = .false.
 
307
         return
 
308
      endif
 
309
 
 
310
c     IS clustering
 
311
      if((ipart(1,ida1).ge.1.and.ipart(1,ida1).le.2).or.
 
312
     $   (ipart(1,ida2).ge.1.and.ipart(1,ida2).le.2))then
 
313
c     Check if ida1 is outgoing parton or ida2 is outgoing parton
 
314
        if(ipart(1,ida2).ge.1.and.ipart(1,ida2).le.2.and.isjet(idda1).or.
 
315
     $        ipart(1,ida1).ge.1.and.ipart(1,ida1).le.2.and.isjet(idda2))then
 
316
           isjetvx=.true.
 
317
        else
 
318
           isjetvx=.false.
 
319
        endif
 
320
        return
 
321
      endif        
 
322
 
 
323
c     FS clustering
 
324
      if(isjet(idda1).or.isjet(idda2))then
 
325
         isjetvx=.true.
 
326
      else
 
327
         isjetvx=.false.
 
328
      endif
 
329
      
 
330
      return
 
331
      end
 
332
 
 
333
      logical function setclscales(p)
 
334
c**************************************************
 
335
c   reweight the hard me according to ckkw
 
336
c   employing the information in common/cl_val/
 
337
c**************************************************
 
338
      implicit none
 
339
 
 
340
      include 'message.inc'
 
341
      include 'genps.inc'
 
342
      include 'nexternal.inc'
 
343
      include 'cluster.inc'
 
344
      include 'run.inc'
 
345
      include 'coupl.inc'
 
346
C   
 
347
C   ARGUMENTS 
 
348
C   
 
349
      DOUBLE PRECISION P(0:3,NEXTERNAL)
 
350
 
 
351
C   local variables
 
352
      integer i, j, idi, idj
 
353
      real*8 PI
 
354
      parameter( PI = 3.14159265358979323846d0 )
 
355
 
 
356
      integer mapconfig(0:lmaxconfigs), this_config
 
357
      integer iforest(2,-max_branch:-1,lmaxconfigs)
 
358
      integer sprop(-max_branch:-1,lmaxconfigs)
 
359
      integer tprid(-max_branch:-1,lmaxconfigs)
 
360
      include 'configs.inc'
 
361
      real*8 xptj,xptb,xpta,xptl,xmtc
 
362
      real*8 xetamin,xqcut,deltaeta
 
363
      common /to_specxpt/xptj,xptb,xpta,xptl,xmtc,xetamin,xqcut,deltaeta
 
364
      real*8 q2bck(2)
 
365
      save q2bck
 
366
      include 'maxamps.inc'
 
367
      integer idup(nexternal,maxproc)
 
368
      integer mothup(2,nexternal,maxproc)
 
369
      integer icolup(2,nexternal,maxflow)
 
370
      include 'leshouche.inc'
 
371
      double precision asref, pt2prev(n_max_cl),pt2min
 
372
      integer n, icmp, ibeam(2), iqcd(0:2)!, ilast(0:nexternal)
 
373
      integer idfl, ipdg(n_max_cl), idmap(-nexternal:nexternal)
 
374
      integer ipart(2,n_max_cl)
 
375
      double precision xnow(2)
 
376
      integer jlast(2),jfirst(2)
 
377
      logical qcdline(2),qcdrad(2)
 
378
      logical failed,first
 
379
      data first/.true./
 
380
 
 
381
      logical isqcd,isjet,isparton,isjetvx,cluster
 
382
      double precision alphas
 
383
      external isqcd, isjet, isparton, isjetvx, cluster, alphas
 
384
 
 
385
      setclscales=.true.
 
386
 
 
387
      if(ickkw.le.0.and.xqcut.le.0d0.and.q2fact(1).gt.0.and.scale.gt.0) return
 
388
 
 
389
c   
 
390
c   Cluster the configuration
 
391
c   
 
392
      
 
393
      if (.not.cluster(p(0,1))) then
 
394
c        if (xqcut.gt.0d0) then
 
395
c          failed=.false.          
 
396
cc          if(pt2ijcl(1).lt.xqcut**2) failed=.true.
 
397
c          if(failed) then
 
398
c            if (btest(mlevel,3)) then
 
399
c              write(*,*)'q_min = ',pt2ijcl(1),' < ',xqcut**2
 
400
c            endif
 
401
c            setclscales=.false.
 
402
c            return
 
403
c          endif
 
404
c        endif
 
405
c      else
 
406
        write(*,*)'setclscales: Error. Clustering failed.'
 
407
        setclscales=.false.
 
408
        return
 
409
      endif
 
410
 
 
411
c   Preparing graph particle information
 
412
      do i=1,nexternal
 
413
        ipart(1,ishft(1,i))=i
 
414
        ipart(2,ishft(1,i))=0
 
415
      enddo
 
416
      ibeam(1)=ishft(1,1)
 
417
      ibeam(2)=ishft(1,2)
 
418
      if (btest(mlevel,1)) then
 
419
        write(*,*)'setclscales: identified tree {'
 
420
        do i=1,nexternal-2
 
421
          write(*,*)'  ',i,': ',idacl(i,1),'&',idacl(i,2),
 
422
     &       ' -> ',imocl(i),', ptij = ',dsqrt(pt2ijcl(i)) 
 
423
        enddo
 
424
        write(*,*)'  graphs (',igscl(0),'):',(igscl(i),i=1,igscl(0))
 
425
        write(*,*)'}'
 
426
      endif
 
427
c   fill particle information
 
428
      icmp=ishft(1,nexternal+1)-2
 
429
      do i=1,nexternal
 
430
        idmap(i)=ishft(1,i)
 
431
        ipdg(idmap(i))=idup(i,1)
 
432
        if(btest(mlevel,3))
 
433
     $     write(*,*) i,' got id ',idmap(i),' -> ',ipdg(idmap(i))
 
434
      enddo
 
435
      do i=1,nexternal-2
 
436
        idi=iforest(1,-i,igscl(1))
 
437
        idj=iforest(2,-i,igscl(1))
 
438
        idmap(-i)=idmap(idi)+idmap(idj)
 
439
        idfl=sprop(-i,igscl(1))
 
440
        if (idfl.ne.0) then
 
441
          ipdg(idmap(-i))=idfl
 
442
          ipdg(icmp-idmap(-i))=idfl
 
443
        endif
 
444
        idfl=tprid(-i,igscl(1))
 
445
        if (idfl.ne.0) then
 
446
          ipdg(idmap(-i))=idfl
 
447
          ipdg(icmp-idmap(-i))=idfl
 
448
        endif
 
449
c     write(*,*) -i,' (',idi,',',idj,') got id ',idmap(-i),
 
450
c     &        ' -> ',ipdg(idmap(-i))
 
451
      enddo
 
452
 
 
453
cc
 
454
cc   Set factorization scale as for the MLM case
 
455
cc
 
456
c      if(xqcut.gt.0) then
 
457
cc     Using last clustering value
 
458
c        if(pt2ijcl(nexternal-2).lt.max(4d0,xqcut**2))then
 
459
c           setclscales=.false.
 
460
c           return
 
461
c        endif
 
462
 
 
463
c     If last clustering is s-channel QCD (e.g. ttbar) use mt2last instead
 
464
c     (i.e. geom. average of transverse mass of t and t~)
 
465
        if(mt2last.gt.4d0 .and. nexternal.gt.3 .and. isqcd(ipdg(idacl(nexternal-3,1)))
 
466
     $      .and. isqcd(ipdg(idacl(nexternal-3,2)))
 
467
     $      .and. isqcd(ipdg(imocl(nexternal-3))))then
 
468
           mt2ij(nexternal-2)=mt2last
 
469
           mt2ij(nexternal-3)=mt2last
 
470
           if (btest(mlevel,3)) then
 
471
              write(*,*)' setclscales: set last vertices to mtlast: ',sqrt(mt2last)
 
472
           endif
 
473
        endif
 
474
 
 
475
C   If we have fixed factorization scale, for ickkw>0 means central
 
476
C   scale, i.e. last two scales (ren. scale for these vertices are
 
477
C   anyway already set by "scale" above
 
478
      if(ickkw.gt.0) then
 
479
         if(fixed_fac_scale.and.first)then
 
480
            q2bck(1)=q2fact(1)
 
481
            q2bck(2)=q2fact(2)
 
482
            first=.false.
 
483
         else if(fixed_fac_scale) then
 
484
            q2fact(1)=q2bck(1)
 
485
            q2fact(2)=q2bck(2)
 
486
         endif
 
487
      endif
 
488
      jfirst(1)=0
 
489
      jfirst(2)=0
 
490
 
 
491
      jlast(1)=0
 
492
      jlast(2)=0
 
493
      qcdline(1)=.false.
 
494
      qcdline(2)=.false.
 
495
      qcdrad(1)=.true.
 
496
      qcdrad(2)=.true.
 
497
 
 
498
c   Go through clusterings and set factorization scales for use in dsig
 
499
      do n=1,nexternal-2
 
500
c   Update particle tree map
 
501
        call ipartupdate(p,imocl(n),idacl(n,1),idacl(n,2),
 
502
     $     ipdg,ipart)
 
503
 
 
504
        do i=1,2
 
505
          if (isqcd(ipdg(idacl(n,i)))) then
 
506
            do j=1,2
 
507
              if ((isparton(ipdg(idacl(n,i))).and.idacl(n,i).eq.ibeam(j).or.
 
508
     $           isparton(ipdg(imocl(n))).and.imocl(n).eq.ibeam(j))
 
509
     $           .and.qcdrad(j)) then
 
510
c             is emission - this is what we want
 
511
c             Total pdf weight is f1(x1,pt2E)*fj(x1*z,Q)/fj(x1*z,pt2E)
 
512
c             f1(x1,pt2E) is given by DSIG, just need to set scale.
 
513
                ibeam(j)=imocl(n)
 
514
                if(ickkw.eq.0.or.jfirst(j).eq.0) jfirst(j)=n
 
515
                jlast(j)=n
 
516
                qcdline(j)=isqcd(ipdg(imocl(n)))
 
517
                if(n.lt.nexternal-2)then
 
518
                   qcdrad(j)=isqcd(ipdg(idacl(n,3-i)))
 
519
                endif
 
520
              endif
 
521
            enddo
 
522
          endif
 
523
        enddo
 
524
      enddo
 
525
 
 
526
      if (btest(mlevel,3))
 
527
     $     write(*,*) 'jfirst is ',jfirst(1),jfirst(2),
 
528
     $     ' and jlast is ',jlast(1),jlast(2)
 
529
 
 
530
c     Set central scale to mT2 and multiply with scalefact
 
531
      if(jlast(1).gt.0.and.mt2ij(jlast(1)).gt.0d0)
 
532
     $     pt2ijcl(jlast(1))=mt2ij(jlast(1))
 
533
      if(jlast(2).gt.0.and.mt2ij(jlast(2)).gt.0d0)
 
534
     $     pt2ijcl(jlast(2))=mt2ij(jlast(2))
 
535
      if(qcdline(1).and.qcdline(2).and.jlast(1).ne.jlast(2)) then
 
536
c     If not WBF or similar, set uniform scale to be geom. average
 
537
         pt2ijcl(jlast(1))=sqrt(pt2ijcl(jlast(1))*pt2ijcl(jlast(2)))
 
538
         pt2ijcl(jlast(2))=pt2ijcl(jlast(1))
 
539
      endif
 
540
      if(jlast(1).gt.0) pt2ijcl(jlast(1))=scalefact**2*pt2ijcl(jlast(1))
 
541
      if(jlast(2).gt.0) pt2ijcl(jlast(2))=scalefact**2*pt2ijcl(jlast(2))
 
542
      if(lpp(1).eq.0.and.lpp(2).eq.0)then
 
543
         pt2ijcl(nexternal-2)=scalefact**2*pt2ijcl(nexternal-2)
 
544
         pt2ijcl(nexternal-3)=pt2ijcl(nexternal-2)
 
545
      endif
 
546
 
 
547
c     Check xqcut for vertices with jet daughters only
 
548
      if(xqcut.gt.0) then
 
549
         do n=1,nexternal-2
 
550
            if (n.lt.nexternal-2.and.n.ne.jlast(1).and.n.ne.jlast(2).and.
 
551
     $           (isjet(ipdg(idacl(n,1))).or.isjet(ipdg(idacl(n,2)))).and.
 
552
     $           sqrt(pt2ijcl(n)).lt.xqcut)then
 
553
               setclscales=.false.
 
554
               return
 
555
            endif
 
556
         enddo
 
557
      endif
 
558
 
 
559
c     JA: Check xmtc cut for central process
 
560
      if(pt2ijcl(jlast(1)).lt.xmtc**2.or.pt2ijcl(jlast(2)).lt.xmtc**2)then
 
561
         setclscales=.false.
 
562
         if(btest(mlevel,3)) write(*,*)'Failed xmtc cut ',
 
563
     $        sqrt(pt2ijcl(jlast(1))),sqrt(pt2ijcl(jlast(1))),' < ',xmtc
 
564
         return
 
565
      endif
 
566
      
 
567
      if(ickkw.eq.0.and.(fixed_fac_scale.or.q2fact(1).gt.0).and.
 
568
     $     (fixed_ren_scale.or.scale.gt.0)) return
 
569
 
 
570
c     Set renormalization scale to largest factorization scale
 
571
      if(scale.eq.0d0) then
 
572
         if(jlast(1).gt.0.and.jlast(2).gt.0) then
 
573
            scale=(pt2ijcl(jlast(1))*pt2ijcl(jlast(2)))**0.25d0
 
574
         elseif(jlast(1).gt.0) then
 
575
            scale=sqrt(pt2ijcl(jlast(1)))
 
576
         elseif(jlast(2).gt.0) then
 
577
            scale=sqrt(pt2ijcl(jlast(2)))
 
578
         elseif(lpp(1).eq.0.and.lpp(2).eq.0) then
 
579
            scale=sqrt(pt2ijcl(nexternal-2))
 
580
         endif
 
581
         if(scale.gt.0)
 
582
     $        G = SQRT(4d0*PI*ALPHAS(scale))
 
583
      endif
 
584
      if (btest(mlevel,3))
 
585
     $     write(*,*) 'Set ren scale to ',scale
 
586
 
 
587
      if(ickkw.gt.0.and.q2fact(1).gt.0) then
 
588
c     Use the fixed or previously set scale for central scale
 
589
         if(jlast(1).gt.0) pt2ijcl(jlast(1))=q2fact(1)
 
590
         if(jlast(2).gt.0) pt2ijcl(jlast(2))=q2fact(2)
 
591
      endif
 
592
      
 
593
      if(lpp(1).eq.0.and.lpp(2).eq.0)then
 
594
         if(q2fact(1).gt.0)then
 
595
            pt2ijcl(nexternal-2)=q2fact(1)
 
596
            pt2ijcl(nexternal-3)=q2fact(1)
 
597
         else
 
598
            q2fact(1)=pt2ijcl(nexternal-2)
 
599
            q2fact(2)=q2fact(1)
 
600
         endif
 
601
      elseif(ickkw.eq.2.or.pdfwgt)then
 
602
c     Use the minimum scale found for fact scale in ME
 
603
         if(jlast(1).gt.0) q2fact(1)=min(pt2ijcl(jfirst(1)),pt2ijcl(jlast(1)))
 
604
         if(jlast(2).gt.0) q2fact(2)=min(pt2ijcl(jfirst(2)),pt2ijcl(jlast(2)))
 
605
      else if(q2fact(1).eq.0d0) then
 
606
         if(jlast(1).gt.0) q2fact(1)=pt2ijcl(jlast(1))
 
607
         if(jlast(2).gt.0) q2fact(2)=pt2ijcl(jlast(2))
 
608
      endif
 
609
 
 
610
      if(nexternal.eq.3.and.nincoming.eq.2) then
 
611
         if(q2fact(1).eq.0)
 
612
     $        q2fact(1)=pt2ijcl(nexternal-2)
 
613
         if(q2fact(2).eq.0)
 
614
     $        q2fact(2)=pt2ijcl(nexternal-2)
 
615
      endif
 
616
 
 
617
      if (btest(mlevel,3))
 
618
     $     write(*,*) 'Set fact scales to ',sqrt(q2fact(1)),sqrt(q2fact(2))
 
619
      return
 
620
      end
 
621
      
 
622
      double precision function rewgt(p)
 
623
c**************************************************
 
624
c   reweight the hard me according to ckkw
 
625
c   employing the information in common/cl_val/
 
626
c**************************************************
 
627
      implicit none
 
628
 
 
629
      include 'message.inc'
 
630
      include 'genps.inc'
 
631
      include 'nexternal.inc'
 
632
      include 'cluster.inc'
 
633
      include 'run.inc'
 
634
      include 'coupl.inc'
 
635
C   
 
636
C   ARGUMENTS 
 
637
C   
 
638
      DOUBLE PRECISION P(0:3,NEXTERNAL)
 
639
 
 
640
C   global variables
 
641
      integer              IPROC 
 
642
      DOUBLE PRECISION PD(0:MAXPROC)
 
643
      COMMON /SubProc/ PD, IPROC
 
644
 
 
645
C   local variables
 
646
      integer i, j, idi, idj
 
647
      real*8 PI
 
648
      parameter( PI = 3.14159265358979323846d0 )
 
649
 
 
650
      integer mapconfig(0:lmaxconfigs), this_config
 
651
      integer iforest(2,-max_branch:-1,lmaxconfigs)
 
652
      integer sprop(-max_branch:-1,lmaxconfigs)
 
653
      integer tprid(-max_branch:-1,lmaxconfigs)
 
654
      include 'configs.inc'
 
655
      real*8 xptj,xptb,xpta,xptl,xmtc
 
656
      real*8 xetamin,xqcut,deltaeta
 
657
      common /to_specxpt/xptj,xptb,xpta,xptl,xmtc,xetamin,xqcut,deltaeta
 
658
      include 'maxamps.inc'
 
659
      integer idup(nexternal,maxproc)
 
660
      integer mothup(2,nexternal,maxproc)
 
661
      integer icolup(2,nexternal,maxflow)
 
662
      include 'leshouche.inc'
 
663
      double precision asref, pt2prev(n_max_cl),pt2pdf(n_max_cl),pt2min
 
664
      integer n, icmp, ibeam(2), iqcd(0:2)!, ilast(0:nexternal)
 
665
      integer idfl, ipdg(n_max_cl), idmap(-nexternal:nexternal)
 
666
      integer ipart(2,n_max_cl)
 
667
      double precision xnow(2)
 
668
      double precision xtarget, tmp
 
669
      integer iseed,np
 
670
      data iseed/0/
 
671
      logical isvx
 
672
 
 
673
      logical isqcd,isjet,isparton,isjetvx
 
674
      double precision alphas,getissud,pdg2pdf, sudwgt
 
675
      real xran1
 
676
      external isqcd,isjet,isparton
 
677
      external alphas, isjetvx, getissud, pdg2pdf, xran1,  sudwgt
 
678
 
 
679
      rewgt=1.0d0
 
680
 
 
681
      if(ickkw.le.0) return
 
682
 
 
683
      if(.not.clustered)then
 
684
        write(*,*)'Error: No clustering done when calling rewgt!'
 
685
        stop
 
686
      endif
 
687
      clustered=.false.
 
688
 
 
689
c   Set mimimum kt scale, depending on highest mult or not
 
690
      if(hmult.or.ickkw.eq.1)then
 
691
        pt2min=0
 
692
      else
 
693
        pt2min=xqcut**2
 
694
      endif
 
695
      if (btest(mlevel,3))
 
696
     $     write(*,*) 'pt2min set to ',pt2min
 
697
 
 
698
c   Since we use pdf reweighting, need to know particle identities
 
699
      iprocset=1
 
700
      np = iproc
 
701
      xtarget=xran1(iseed)*pd(np)
 
702
      iprocset = 1
 
703
      do while (pd(iprocset) .lt. xtarget .and. iprocset .lt. np)
 
704
         iprocset=iprocset+1
 
705
      enddo
 
706
      if (btest(mlevel,1)) then
 
707
         write(*,*) 'Set process number ',iprocset
 
708
      endif
 
709
 
 
710
c   Preparing graph particle information
 
711
      do i=1,nexternal
 
712
c        ilast(i)=ishft(1,i)
 
713
         if(pt2min.gt.0)then
 
714
            pt2prev(ishft(1,i))=max(pt2min,p(0,i)**2-p(1,i)**2-p(2,i)**2-p(3,i)**2)
 
715
         else
 
716
            pt2prev(ishft(1,i))=0d0
 
717
         endif
 
718
         pt2pdf(ishft(1,i))=pt2prev(ishft(1,i))
 
719
         ptclus(i)=sqrt(pt2prev(ishft(1,i)))
 
720
         ipart(1,ishft(1,i))=i
 
721
         ipart(2,ishft(1,i))=0
 
722
      enddo
 
723
c      ilast(0)=nexternal
 
724
      ibeam(1)=ishft(1,1)
 
725
      ibeam(2)=ishft(1,2)
 
726
      if (btest(mlevel,1)) then
 
727
        write(*,*)'rewgt: identified tree {'
 
728
        do i=1,nexternal-2
 
729
          write(*,*)'  ',i,': ',idacl(i,1),'&',idacl(i,2),
 
730
     &       ' -> ',imocl(i),', ptij = ',dsqrt(pt2ijcl(i)) 
 
731
        enddo
 
732
        write(*,*)'  graphs (',igscl(0),'):',(igscl(i),i=1,igscl(0))
 
733
        write(*,*)'}'
 
734
      endif
 
735
c   fill particle information
 
736
      icmp=ishft(1,nexternal+1)-2
 
737
      do i=1,nexternal
 
738
        idmap(i)=ishft(1,i)
 
739
        ipdg(idmap(i))=idup(i,iprocset)
 
740
        if(btest(mlevel,3))
 
741
     $     write(*,*) i,' got id ',idmap(i),' -> ',ipdg(idmap(i))
 
742
      enddo
 
743
      do i=1,nexternal-2
 
744
        idi=iforest(1,-i,igscl(1))
 
745
        idj=iforest(2,-i,igscl(1))
 
746
        idmap(-i)=idmap(idi)+idmap(idj)
 
747
        idfl=sprop(-i,igscl(1))
 
748
        if (idfl.ne.0) then
 
749
          ipdg(idmap(-i))=idfl
 
750
          ipdg(icmp-idmap(-i))=idfl
 
751
        endif
 
752
        idfl=tprid(-i,igscl(1))
 
753
        if (idfl.ne.0) then
 
754
          ipdg(idmap(-i))=idfl
 
755
          ipdg(icmp-idmap(-i))=idfl
 
756
        endif
 
757
c     write(*,*) -i,' (',idi,',',idj,') got id ',idmap(-i),
 
758
c     &        ' -> ',ipdg(idmap(-i))
 
759
      enddo
 
760
c     Set x values for the two sides, for IS Sudakovs
 
761
      do i=1,2
 
762
        xnow(i)=xbk(i)
 
763
      enddo
 
764
      if(btest(mlevel,3))then
 
765
        write(*,*) 'Set x values to ',xnow(1),xnow(2)
 
766
      endif
 
767
 
 
768
c     Prepare for resetting q2fact based on PDF reweighting
 
769
      if(ickkw.eq.2.or.pdfwgt)then
 
770
         q2fact(1)=0d0
 
771
         q2fact(2)=0d0
 
772
      endif
 
773
c   
 
774
c   Set strong coupling used
 
775
c   
 
776
      asref=G**2/(4d0*PI)
 
777
 
 
778
c   Perform alpha_s reweighting based on type of vertex
 
779
      do n=1,nexternal-2
 
780
        if (btest(mlevel,3)) then
 
781
          write(*,*)'  ',n,': ',idacl(n,1),'(',ipdg(idacl(n,1)),
 
782
     &       ')&',idacl(n,2),'(',ipdg(idacl(n,2)),') -> ',
 
783
     &       imocl(n),'(',ipdg(imocl(n)),'), ptij = ',
 
784
     &       dsqrt(pt2ijcl(n)) 
 
785
        endif
 
786
c     perform alpha_s reweighting only for vertices where a jet is produced
 
787
c     and not for the last clustering (use non-fixed ren. scale for these)
 
788
        if (n.lt.nexternal-2.and.
 
789
     $     isjetvx(imocl(n),idacl(n,1),idacl(n,2),ipdg,ipart)) then
 
790
c       alpha_s weight
 
791
          rewgt=rewgt*alphas(alpsfact*sqrt(pt2ijcl(n)))/asref
 
792
          if (btest(mlevel,3)) then
 
793
             write(*,*)' reweight vertex: ',ipdg(imocl(n)),ipdg(idacl(n,1)),ipdg(idacl(n,2))
 
794
            write(*,*)'       as: ',alphas(alpsfact*dsqrt(pt2ijcl(n))),
 
795
     &         '/',asref,' -> ',alphas(alpsfact*dsqrt(pt2ijcl(n)))/asref
 
796
            write(*,*)' and G=',SQRT(4d0*PI*ALPHAS(scale))
 
797
          endif
 
798
        endif
 
799
c   Update starting values for FS parton showering
 
800
        do i=1,2
 
801
          do j=1,2
 
802
            if(ipart(j,idacl(n,i)).gt.0)then
 
803
              ptclus(ipart(j,idacl(n,i)))=dsqrt(pt2ijcl(n))
 
804
            endif
 
805
          enddo
 
806
        enddo
 
807
c   Update particle tree map
 
808
        call ipartupdate(p,imocl(n),idacl(n,1),idacl(n,2),ipdg,ipart)
 
809
        if(ickkw.eq.2.or.pdfwgt) then
 
810
c       Perform PDF and, if ickkw=2, Sudakov reweighting
 
811
          isvx=.false.
 
812
          do i=1,2
 
813
c         write(*,*)'weight ',idacl(n,i),', ptij=',pt2prev(idacl(n,i))
 
814
            if (isqcd(ipdg(idacl(n,i)))) then
 
815
               if(pt2min.eq.0d0) then
 
816
                  pt2min=pt2ijcl(n)
 
817
                  if (btest(mlevel,3))
 
818
     $                 write(*,*) 'pt2min set to ',pt2min
 
819
               endif
 
820
               if(pt2prev(idacl(n,i)).eq.0d0) pt2prev(idacl(n,i))=
 
821
     $              max(pt2min,p(0,i)**2-p(1,i)**2-p(2,i)**2-p(3,i)**2)
 
822
               do j=1,2
 
823
                  if (isparton(ipdg(idacl(n,i))).and.idacl(n,i).eq.ibeam(j)) then
 
824
c               is sudakov weight - calculate only once for each parton
 
825
c               line where parton line ends with change of parton id or
 
826
c               non-radiation vertex
 
827
                     isvx=.true.
 
828
                     ibeam(j)=imocl(n)
 
829
                     if(pt2pdf(idacl(n,i)).eq.0d0) pt2pdf(idacl(n,i))=pt2prev(idacl(n,i))
 
830
                     if(ickkw.eq.2.and.(ipdg(idacl(n,i)).ne.ipdg(imocl(n)).or.
 
831
     $                    .not.isjetvx(imocl(n),idacl(n,1),idacl(n,2),ipdg,ipart)).and.
 
832
     $                    pt2prev(idacl(n,i)).lt.pt2ijcl(n).and.zcl(n).gt.1d-20)then
 
833
                        tmp=min(1d0,max(getissud(ibeam(j),ipdg(idacl(n,i)),xnow(j),xnow(3-j),pt2ijcl(n)),1d-20)/
 
834
     $                       max(getissud(ibeam(j),ipdg(idacl(n,i)),xnow(j),xnow(3-j),pt2prev(idacl(n,i))),1d-20))
 
835
                        rewgt=rewgt*tmp
 
836
                        pt2prev(imocl(n))=pt2ijcl(n)
 
837
                        if (btest(mlevel,3)) then
 
838
                           write(*,*)' reweight line: ',ipdg(idacl(n,i)), idacl(n,i)
 
839
                           write(*,*)'     pt2prev, pt2new, x1, x2: ',pt2prev(idacl(n,i)),pt2ijcl(n),xnow(j),xnow(3-j)
 
840
                           write(*,*)'           Sud: ',tmp
 
841
                           write(*,*)'        -> rewgt: ',rewgt
 
842
                        endif
 
843
                     else
 
844
                        pt2prev(imocl(n))=pt2prev(idacl(n,i))
 
845
                     endif
 
846
c               Total pdf weight is f1(x1,pt2E)*fj(x1*z,Q)/fj(x1*z,pt2E)
 
847
c               f1(x1,pt2E) is given by DSIG, already set scale for that
 
848
                     xnow(j)=xnow(j)*zcl(n)
 
849
                     if(q2fact(j).eq.0d0.and.ickkw.eq.2)then
 
850
                        q2fact(j)=pt2min ! Starting scale for PS
 
851
                        if (btest(mlevel,3)) then
 
852
                           write(*,*)' reweight: set fact scale ',j,' for PS scale to: ',q2fact(j)
 
853
                        endif
 
854
                     else if(q2fact(j).eq.0d0)then
 
855
                        q2fact(j)=pt2ijcl(n)
 
856
                     else if(pt2pdf(idacl(n,i)).lt.pt2ijcl(n).and.zcl(n).gt.1d-20) then
 
857
                        if(ickkw.eq.1) q2fact(j)=pt2ijcl(n)
 
858
                        rewgt=rewgt*max(pdg2pdf(abs(ibeam(j)),ipdg(idacl(n,i))*sign(1,ibeam(j)),xnow(j),sqrt(pt2ijcl(n))),1d-20)/
 
859
     $                       max(pdg2pdf(abs(ibeam(j)),ipdg(idacl(n,i))*sign(1,ibeam(j)),xnow(j),sqrt(pt2pdf(idacl(n,i)))),1d-20)
 
860
                        if (btest(mlevel,3)) then
 
861
                           write(*,*)' reweight ',ipdg(idacl(n,i)),' by pdfs: '
 
862
                           write(*,*)'     x, pt2prev, ptnew: ',xnow(j),pt2pdf(idacl(n,i)),pt2ijcl(n)
 
863
                           write(*,*)'           PDF: ',
 
864
     $                          pdg2pdf(abs(ibeam(j)),ipdg(idacl(n,i))*sign(1,ibeam(j)),xnow(j),sqrt(pt2ijcl(n))),' / ',
 
865
     $                          pdg2pdf(abs(ibeam(j)),ipdg(idacl(n,i))*sign(1,ibeam(j)),xnow(j),sqrt(pt2pdf(idacl(n,i))))
 
866
                           write(*,*)'        -> rewgt: ',rewgt
 
867
c                           write(*,*)'  (compare for glue: ',
 
868
c     $                          pdg2pdf(ibeam(j),21,xbk(j),sqrt(pt2pdf(idacl(n,i)))),' / ',
 
869
c     $                          pdg2pdf(ibeam(j),21,xbk(j),sqrt(pt2ijcl(n)))
 
870
c                           write(*,*)'       = ',pdg2pdf(ibeam(j),21,xbk(j),sqrt(pt2pdf(idacl(n,i))))/
 
871
c     $                          pdg2pdf(ibeam(j),21,xbk(j),sqrt(pt2ijcl(n)))
 
872
c                           write(*,*)'       -> ',pdg2pdf(ibeam(j),21,xbk(j),sqrt(pt2pdf(idacl(n,i))))/
 
873
c     $                          pdg2pdf(ibeam(j),21,xbk(j),sqrt(pt2ijcl(n)))*rewgt,' )'
 
874
                        endif
 
875
                     endif
 
876
c               End both Sudakov and pdf reweighting when we reach a
 
877
c               non-radiation vertex
 
878
                     if(isjetvx(imocl(n),idacl(n,1),idacl(n,2),ipdg,ipart)) then
 
879
                        pt2pdf(imocl(n))=pt2ijcl(n)
 
880
                     else
 
881
                        pt2pdf(imocl(n))=1d30
 
882
                        pt2prev(imocl(n))=1d30
 
883
                        if (btest(mlevel,3)) then
 
884
                           write(*,*)' rewgt: for vertex ',idacl(n,1),idacl(n,2),imocl(n),
 
885
     $                          ' with ids ',ipdg(idacl(n,1)),ipdg(idacl(n,2)),ipdg(imocl(n))
 
886
                           write(*,*)'    set pt2prev, pt2pdf: ',pt2prev(imocl(n)),pt2pdf(imocl(n))
 
887
                        endif
 
888
                     endif
 
889
                     goto 10
 
890
                  endif
 
891
               enddo
 
892
c           fs sudakov weight
 
893
               if(ickkw.eq.2.and.pt2prev(idacl(n,i)).lt.pt2ijcl(n).and.
 
894
     $              (isvx.or.ipdg(idacl(n,i)).ne.ipdg(imocl(n)).or.
 
895
     $              (ipdg(idacl(n,i)).ne.ipdg(idacl(n,3-i)).and.
 
896
     $              pt2prev(idacl(n,i)).gt.pt2prev(idacl(n,3-i))))) then
 
897
                  tmp=sudwgt(sqrt(pt2min),sqrt(pt2prev(idacl(n,i))),
 
898
     &                 dsqrt(pt2ijcl(n)),ipdg(idacl(n,i)),1)
 
899
                  rewgt=rewgt*tmp
 
900
                  if (btest(mlevel,3)) then
 
901
                     write(*,*)' reweight fs line: ',ipdg(idacl(n,i)), idacl(n,i)
 
902
                     write(*,*)'     pt2prev, pt2new: ',pt2prev(idacl(n,i)),pt2ijcl(n)
 
903
                     write(*,*)'           Sud: ',tmp
 
904
                     write(*,*)'        -> rewgt: ',rewgt
 
905
                  endif
 
906
                  pt2prev(imocl(n))=pt2ijcl(n)
 
907
               else
 
908
                  pt2prev(imocl(n))=pt2prev(idacl(n,i))
 
909
               endif 
 
910
            endif
 
911
 10         continue
 
912
          enddo
 
913
          if (ickkw.eq.2.and.n.eq.nexternal-2.and.isqcd(ipdg(imocl(n))).and.
 
914
     $         pt2prev(imocl(n)).lt.pt2ijcl(n)) then
 
915
             tmp=sudwgt(sqrt(pt2min),sqrt(pt2prev(imocl(n))),
 
916
     &            dsqrt(pt2ijcl(n)),ipdg(imocl(n)),1)
 
917
             rewgt=rewgt*tmp
 
918
             if (btest(mlevel,3)) then
 
919
                write(*,*)' reweight last fs line: ',ipdg(imocl(n)), imocl(n)
 
920
                write(*,*)'     pt2prev, pt2new: ',pt2prev(imocl(n)),pt2ijcl(n)
 
921
                write(*,*)'           Sud: ',tmp
 
922
                write(*,*)'        -> rewgt: ',rewgt
 
923
             endif
 
924
          endif
 
925
        endif
 
926
      enddo
 
927
 
 
928
      if((ickkw.eq.2.or.pdfwgt).and.lpp(1).eq.0.and.lpp(2).eq.0)then
 
929
         q2fact(1)=pt2min
 
930
         q2fact(2)=q2fact(1)
 
931
      endif
 
932
 
 
933
      if (btest(mlevel,3)) then
 
934
        write(*,*)'} ->  w = ',rewgt
 
935
      endif
 
936
      return
 
937
      end
 
938