~maddevelopers/mg5amcnlo/2.9.4

« back to all changes in this revision

Viewing changes to Template/NLO/SubProcesses/add_write_info.f

pass to v2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
      subroutine add_write_info(p_born,pp,ybst_til_tolab,iconfig,Hevents
 
2
     &     ,putonshell,ndim,ipole,x,jpart,npart,pb,shower_scale)
 
3
c Computes all the info needed to write out the events including the
 
4
c intermediate resonances. It also boosts the events to the lab frame
 
5
      implicit none
 
6
      include "genps.inc"
 
7
      include "nexternal.inc"
 
8
      include "born_nhel.inc"
 
9
      include "coloramps.inc"
 
10
      include "reweight0.inc"
 
11
      include "nFKSconfigs.inc"
 
12
      include "leshouche_info.inc"
 
13
      include "run.inc"
 
14
 
 
15
c Arguments
 
16
      double precision p_born(0:3,nexternal-1),pp(0:3,nexternal)
 
17
      double precision ybst_til_tolab,shower_scale
 
18
      integer iconfig
 
19
      logical Hevents,putonshell
 
20
      integer ndim,ipole,jpart(7,-nexternal+3:2*nexternal-3),npart
 
21
      double precision pb(0:4,-nexternal+3:2*nexternal-3)
 
22
 
 
23
c Local
 
24
      integer np,i,j,iBornGraph,ida(2),size,nexpart,idum,ires,nres,ns
 
25
      integer icolalt(2,-nexternal+3:2*nexternal-3),ip,iflow
 
26
      integer ito(-nexternal+3:nexternal)
 
27
      double precision xtarget,sumborn,jampsum
 
28
      double complex wgt1(2)
 
29
      logical firsttime,firsttime2
 
30
      data firsttime/.true./
 
31
      data firsttime2/.true./
 
32
 
 
33
c The process chosen to write
 
34
      integer i_process
 
35
      common/c_addwrite/i_process
 
36
      
 
37
c Random numbers
 
38
      double precision ran2
 
39
      external ran2
 
40
 
 
41
c Jamp amplitudes of the Born (to be filled with a call the sborn())
 
42
      double Precision amp2(maxamps), jamp2(0:maxamps)
 
43
      common/to_amps/  amp2,       jamp2
 
44
 
 
45
C iforest and other configuration info. Read once and saved.
 
46
      integer itree_S_t(2,-max_branch:-1),sprop_tree_S_t(-max_branch:-1)
 
47
     $     ,itree_H_t(2,-max_branch:-1),sprop_tree_H_t(-max_branch:-1)
 
48
      integer itree_S(2,-max_branch:-1,fks_configs),sprop_tree_S(
 
49
     $     -max_branch:-1,fks_configs),itree_H(2,-max_branch:-1
 
50
     $     ,fks_configs),sprop_tree_H(-max_branch:-1,fks_configs)
 
51
      save itree_S,sprop_tree_S,itree_H,sprop_tree_H
 
52
 
 
53
c Masses and widths of the (internal) propagators. Read once and saved.
 
54
      double precision pmass_tree_S_t(-nexternal:0) ,pwidth_tree_S_t(
 
55
     $     -nexternal:0),pmass_tree_H_t(-nexternal:0),pwidth_tree_H_t(
 
56
     $     -nexternal:0)
 
57
      double precision pmass_tree_S(-nexternal:0,fks_configs)
 
58
     $     ,pwidth_tree_S(-nexternal:0,fks_configs),pmass_tree_H(
 
59
     $     -nexternal:0,fks_configs),pwidth_tree_H(-nexternal:0
 
60
     $     ,fks_configs)
 
61
      save pmass_tree_S,pwidth_tree_S,pmass_tree_H,pwidth_tree_H
 
62
 
 
63
c tree, s-channel props, masses and widths, copied from the save values
 
64
c above
 
65
      integer itree(2,-max_branch:-1),sprop_tree(-max_branch:-1)
 
66
      double precision pmass_tree(-nexternal:0)
 
67
      double precision pwidth_tree(-nexternal:0)
 
68
 
 
69
c On Breit-Wigner
 
70
      logical OnBW(-nexternal:0)
 
71
 
 
72
c LesHouches info
 
73
      integer maxflow
 
74
      parameter (maxflow=999)
 
75
      integer idup(nexternal,maxproc),mothup(2,nexternal,maxproc),
 
76
     &     icolup(2,nexternal,maxflow)
 
77
c      include "leshouche.inc"
 
78
      common /c_leshouche_inc/idup,mothup,icolup
 
79
 
 
80
c Common block to check if we are doing MC over helicities.
 
81
      integer           isum_hel
 
82
      logical                   multi_channel
 
83
      common/to_matrix/isum_hel, multi_channel
 
84
 
 
85
c Masses of external (n+1)-body particles
 
86
      real*8         emass(nexternal)
 
87
      common/to_mass/emass
 
88
 
 
89
c The FKS partons
 
90
      integer i_fks,j_fks
 
91
      common/fks_indices/i_fks,j_fks
 
92
 
 
93
c For the boost to the lab frame
 
94
      double precision chy,shy,chymo,p1(0:3,nexternal),xdir(3)
 
95
      data (xdir(i),i=1,3) /0,0,1/
 
96
 
 
97
c For (n+1)-body this is the configuration mapping
 
98
      integer            mapconfig(0:lmaxconfigs), this_config
 
99
      common/to_mconfigs/mapconfig, this_config
 
100
 
 
101
c For shifting QCD partons from zero to their mass-shell
 
102
      double precision x(99),p(0:3,99)
 
103
      integer mfail
 
104
      double precision xmi,xmj,xm1,xm2,emsum,tmpecm,dot,wgt
 
105
      double precision p1_cnt(0:3,nexternal,-2:2)
 
106
      double precision wgt_cnt(-2:2)
 
107
      double precision pswgt_cnt(-2:2)
 
108
      double precision jac_cnt(-2:2)
 
109
      common/counterevnts/p1_cnt,wgt_cnt,pswgt_cnt,jac_cnt
 
110
      double precision xmcmass(nexternal)
 
111
      common/cxmcmass/xmcmass
 
112
      integer mohdr,izero
 
113
      parameter (mohdr=-100)
 
114
      parameter (izero=0)
 
115
c cFKSprocess
 
116
      INTEGER NFKSPROCESS
 
117
      COMMON/C_NFKSPROCESS/NFKSPROCESS
 
118
      integer save_nFKSprocess
 
119
      double precision SCALUP(fks_configs*2)
 
120
      common /cshowerscale/SCALUP
 
121
      integer iSorH_lhe,ifks_lhe(fks_configs) ,jfks_lhe(fks_configs)
 
122
     &     ,fksfather_lhe(fks_configs) ,ipartner_lhe(fks_configs)
 
123
      common/cto_LHE1/iSorH_lhe,ifks_lhe,jfks_lhe,
 
124
     #                fksfather_lhe,ipartner_lhe
 
125
c
 
126
c Set the leshouche info and fks info
 
127
c
 
128
      call fks_inc_chooser()
 
129
      call leshouche_inc_chooser()
 
130
 
 
131
c
 
132
c Set the number of external particles and overwrite the iSorH_lhe value
 
133
c
 
134
      if (Hevents) then
 
135
         nexpart=nexternal
 
136
         iSorH_lhe=2
 
137
      else
 
138
         nexpart=nexternal-1
 
139
         iSorH_lhe=1
 
140
      endif
 
141
c
 
142
c Determine which Born graph was used for multi-channeling
 
143
c
 
144
      iBornGraph=iconfig
 
145
 
 
146
c
 
147
c Fill the itree, sprop, pmass and pwidth of this configuration. Needed
 
148
c to determine possible intermediate s-channel resonances. Note that the
 
149
c set_itree subroutine does not properly set the t-channel info.
 
150
c
 
151
      if (firsttime) then
 
152
         save_nFKSprocess=nFKSprocess
 
153
         do nFKSprocess=1,FKS_configs
 
154
            call fks_inc_chooser()
 
155
c For the S-events
 
156
            call set_itree(iconfig,.false.,itree_S_t,sprop_tree_S_t
 
157
     $           ,pmass_tree_S_t,pwidth_tree_S_t)
 
158
c For the H-events
 
159
            call set_itree(iconfig,.true.,itree_H_t,sprop_tree_H_t
 
160
     $           ,pmass_tree_H_t,pwidth_tree_H_t)
 
161
            do j=-max_branch,-1
 
162
               itree_H(1,j,nFKSprocess)=itree_H_t(1,j)
 
163
               itree_H(2,j,nFKSprocess)=itree_H_t(2,j)
 
164
               sprop_tree_H(j,nFKSprocess)=sprop_tree_H_t(j)
 
165
               pmass_tree_H(j,nFKSprocess)=pmass_tree_H_t(j)
 
166
               pwidth_tree_H(j,nFKSprocess)=pwidth_tree_H_t(j)
 
167
               itree_S(1,j,nFKSprocess)=itree_S_T(1,j)
 
168
               itree_S(2,j,nFKSprocess)=itree_S_t(2,j)
 
169
               sprop_tree_S(j,nFKSprocess)=sprop_tree_S_t(j)
 
170
               pmass_tree_S(j,nFKSprocess)=pmass_tree_S_t(j)
 
171
               pwidth_tree_S(j,nFKSprocess)=pwidth_tree_S_t(j)
 
172
            enddo
 
173
         enddo
 
174
         firsttime=.false.
 
175
         nFKSprocess=save_nFKSprocess
 
176
         call fks_inc_chooser()
 
177
      endif
 
178
c Copy the saved information to the arrays actually used
 
179
      if (Hevents) then
 
180
         do j=-(nexternal-3),-1
 
181
            do i=1,2
 
182
               itree(i,j)=itree_H(i,j,nFKSprocess)
 
183
            enddo
 
184
            sprop_tree(j)=sprop_tree_H(j,nFKSprocess)
 
185
            pmass_tree(j)=pmass_tree_H(j,nFKSprocess)
 
186
            pwidth_tree(j)=pwidth_tree_H(j,nFKSprocess)
 
187
         enddo
 
188
      else
 
189
         do j=-(nexternal-4),-1
 
190
            do i=1,2
 
191
               itree(i,j)=itree_S(i,j,nFKSprocess)
 
192
            enddo
 
193
            sprop_tree(j)=sprop_tree_S(j,nFKSprocess)
 
194
            pmass_tree(j)=pmass_tree_S(j,nFKSprocess)
 
195
            pwidth_tree(j)=pwidth_tree_S(j,nFKSprocess)
 
196
         enddo
 
197
      endif
 
198
c Set the shower scale
 
199
      if (Hevents) then
 
200
         shower_scale=SCALUP(nFKSprocess*2)
 
201
      else
 
202
         shower_scale=SCALUP(nFKSprocess*2-1)
 
203
      endif
 
204
 
 
205
c This is an (n+1)-body process (see update_unwgt_table in
 
206
c driver_mintMC.f). For S events it corresponds to the underlying Born
 
207
c process chosen
 
208
      ip=i_process
 
209
      if (ip.lt.1 .or. ip.gt.maxproc_used) then
 
210
         write (*,*)'ERROR #12 in add_write_info,'/
 
211
     &        /' not a well-defined process',ip,Hevents
 
212
         stop
 
213
      endif
 
214
 
 
215
c
 
216
c Fill jpart particle info for the final state particles of
 
217
c the (n+1)-body events. Color is done below.
 
218
c
 
219
      do i=1,nexternal
 
220
         jpart(1,i) = idup(i,ip)
 
221
         jpart(2,i) = mothup(1,i,ip)
 
222
         jpart(3,i) = mothup(2,i,ip)
 
223
         if (i.le.nincoming) then
 
224
            jpart(6,i) = -1
 
225
         else
 
226
            jpart(6,i) = 1
 
227
         endif
 
228
      enddo
 
229
c Assume helicity summed
 
230
      do i=1,nexternal
 
231
         jpart(7,i)=0
 
232
      enddo
 
233
      if (firsttime2 .and. isum_hel.ne.0) then
 
234
         write (*,*) 'WARNING: for writing the events, no helicity '//
 
235
     &        'info is used even though some info could be available.'
 
236
         firsttime2=.false.
 
237
      endif
 
238
c Can be filled when doing MC over helicities...
 
239
c$$$   read(hel_buf,'(15i5)') (jpart(7,i),i=1,nexternal)
 
240
 
 
241
c
 
242
c Get color flow that is consistent with iconfig from Born 
 
243
c
 
244
      call sborn(p_born,wgt1)
 
245
      sumborn=0.d0
 
246
      do i=1,max_bcol
 
247
         if (icolamp(i,iBornGraph,1)) then
 
248
            sumborn=sumborn+jamp2(i)
 
249
         endif
 
250
      enddo
 
251
      if (sumborn.eq.0d0) then
 
252
         write (*,*) 'Error #1 in add_write_info:'
 
253
         write (*,*) 'in MadFKS, sumborn should always be larger'//
 
254
     &        ' than zero, because always QCD partons around',sumborn,max_bcol
 
255
         do i=1,max_bcol
 
256
            write (*,*) i,iBornGraph,icolamp(i,iBornGraph,1),jamp2(i)
 
257
         enddo
 
258
         stop
 
259
      endif
 
260
      xtarget=ran2()*sumborn
 
261
 
 
262
      iflow=1
 
263
      if (icolamp(1,iBornGraph,1)) then
 
264
         jampsum=jamp2(1)
 
265
      else
 
266
         jampsum=0d0
 
267
      endif
 
268
      do while (jampsum .lt. xtarget)
 
269
         iflow=iflow+1
 
270
         if (icolamp(iflow,iBornGraph,1)) then
 
271
            jampsum=jampsum+jamp2(iflow)
 
272
         endif
 
273
      enddo
 
274
      if (iflow.gt.max_bcol) then
 
275
         write (*,*) 'ERROR #2 in add_write_info',iflow,max_bcol
 
276
         stop
 
277
      endif
 
278
 
 
279
c
 
280
c Shift particle momenta to put them on the mass shell as given in the
 
281
c subroutine fill_MC_mshell().
 
282
c
 
283
      if(putonshell)then
 
284
         mfail=-1
 
285
c fills the common block with the MC masses (special treatment of i_fks
 
286
c and j_fks, because phase-space generation won't work in all cases).
 
287
         call put_on_MC_mshell(Hevents,jpart,xmi,xmj,xm1,xm2,emsum)
 
288
c Prevents the code from crashing in the extremely rare case in which
 
289
c the cm energy is smaller than sum of masses - keep massless partons
 
290
         tmpecm=min(dot(pp(0,1),pp(0,2)),
 
291
     #              dot(p_born(0,1),p_born(0,2)))
 
292
         tmpecm=sqrt(2d0*tmpecm)
 
293
         if(tmpecm.lt.0.99*emsum)then
 
294
           write (*,*) 'Momenta generation for put_on_MC_mshell failed'
 
295
           mfail=1
 
296
           goto 888
 
297
         endif
 
298
         wgt=1d0
 
299
c generate a phase-space point with the MC masses
 
300
         call generate_momenta(ndim,iconfig,wgt,x,p)
 
301
         if(Hevents)then
 
302
            call set_cms_stuff(mohdr)
 
303
c special treament here for i_fks and j_fks masses
 
304
            call put_on_MC_mshell_Hev(p,xmi,xmj,xm1,xm2,mfail)
 
305
c include initial state masses
 
306
            if(j_fks.gt.nincoming.and.mfail.eq.0)
 
307
     &           call put_on_MC_mshell_in(p,xm1,xm2,mfail)
 
308
         else
 
309
c include initial state masses
 
310
            call set_cms_stuff(izero)
 
311
            call put_on_MC_mshell_in(p1_cnt(0,1,0),xm1,xm2,mfail)
 
312
         endif
 
313
 888     continue
 
314
c restore the common block for the masses to the original MG masses
 
315
         call put_on_MG_mshell()
 
316
         if (mfail.eq.0) then 
 
317
c all went fine and we can copy the new momenta onto the old ones.
 
318
            do i=1,nexternal
 
319
               do j=0,3
 
320
                  if(Hevents) then
 
321
                     pp(j,i)=p(j,i)
 
322
                  elseif(.not.Hevents .and. i.lt.max(i_fks,j_fks)) then
 
323
                     p_born(j,i)=p1_cnt(j,i,0)
 
324
                  elseif(.not.Hevents .and. i.gt.max(i_fks,j_fks)) then
 
325
                     p_born(j,i-1)=p1_cnt(j,i,0)
 
326
                  endif
 
327
               enddo
 
328
            enddo
 
329
         elseif(mfail.eq.1)then
 
330
c Probably not needed, but just to make sure: fill the momenta common
 
331
c blocks again by call generate momenta again.
 
332
            wgt=1d0
 
333
            call generate_momenta(ndim,iconfig,wgt,x,p)
 
334
            if(Hevents)then
 
335
              call set_cms_stuff(mohdr)
 
336
            else
 
337
              call set_cms_stuff(izero)
 
338
            endif
 
339
c Also, set the masses that need to written in the event file to the MG
 
340
c masses
 
341
            call write_masses_lhe_MG()
 
342
         elseif(mfail.eq.-1)then
 
343
            write(*,*)'Error in driver: mfail not set',mfail
 
344
            stop
 
345
         endif
 
346
      else
 
347
c Use the MadGraph masses in the event file
 
348
         call write_masses_lhe_MG()
 
349
      endif
 
350
 
 
351
c
 
352
c Derive the n-body from the (n+1)-body if we are doing S-events
 
353
c
 
354
      if (.not.Hevents) then
 
355
         do i=1,nexternal-1
 
356
            if(i.lt.min(i_fks,j_fks)) then
 
357
               jpart(1,i) = jpart(1,i)
 
358
               jpart(2,i) = jpart(2,i)
 
359
               jpart(3,i) = jpart(3,i)
 
360
            elseif(i.eq.min(i_fks,j_fks)) then
 
361
               if(jpart(1,i_fks).eq.-jpart(1,j_fks)
 
362
     &              .and.j_fks.gt.nincoming) then
 
363
                  jpart(1,i) = 21
 
364
               elseif(jpart(1,i_fks).eq.jpart(1,j_fks)
 
365
     &                 .and.j_fks.le.nincoming) then
 
366
                  jpart(1,i)=21
 
367
               elseif(jpart(1,i_fks).eq.21) then
 
368
                  jpart(1,i)=jpart(1,j_fks)
 
369
               elseif(jpart(1,j_fks).eq.21.and.j_fks.le.nincoming) then
 
370
                  jpart(1,i)=-jpart(1,i_fks)
 
371
               else
 
372
                  write (*,*) 'ERROR #5 in add_write_info()',
 
373
     &                 i_fks,j_fks,jpart(1,i_fks),jpart(1,j_fks)
 
374
                  stop
 
375
               endif
 
376
               jpart(2,i) = jpart(2,i)
 
377
               jpart(3,i) = jpart(3,i)
 
378
            elseif(i.lt.max(i_fks,j_fks)) then
 
379
               jpart(1,i) = jpart(1,i)
 
380
               jpart(2,i) = jpart(2,i)
 
381
               jpart(3,i) = jpart(3,i)
 
382
            else
 
383
               jpart(1,i) = jpart(1,i+1)
 
384
               jpart(2,i) = jpart(2,i+1)
 
385
               jpart(3,i) = jpart(3,i+1)
 
386
            endif
 
387
         enddo
 
388
      endif
 
389
 
 
390
c
 
391
c Fill color of external particles
 
392
c
 
393
      if (Hevents) then
 
394
         call fill_icolor_H(iflow,jpart)
 
395
      else
 
396
         call fill_icolor_S(iflow,jpart,idum)
 
397
      endif
 
398
      do i=1,nexpart
 
399
         icolalt(1,i)=jpart(4,i)
 
400
         icolalt(2,i)=jpart(5,i)
 
401
      enddo
 
402
 
 
403
c
 
404
c Set-up the external momenta that should be written in event file
 
405
c Also boost them to the lab frame.
 
406
c
 
407
      if (abs(ybst_til_tolab).le.1d-7) then
 
408
         do i=1,nexpart
 
409
            do j=0,3
 
410
               if (Hevents) then
 
411
                  pb(j,i)=pp(j,i)
 
412
               else
 
413
                  pb(j,i)=p_born(j,i)
 
414
               endif
 
415
            enddo
 
416
            if (Hevents .or. i.lt.i_fks) then
 
417
               pb(4,i)=xmcmass(i)
 
418
            else
 
419
               pb(4,i)=xmcmass(i+1)
 
420
            endif
 
421
         enddo
 
422
      else
 
423
         chy=cosh(ybst_til_tolab)
 
424
         shy=sinh(ybst_til_tolab)
 
425
         chymo=chy-1d0
 
426
         do i=1,nexpart
 
427
            if (Hevents) then
 
428
               call boostwdir2(chy,shy,chymo,xdir,
 
429
     &              pp(0,i),p1(0,i))
 
430
            else
 
431
               call boostwdir2(chy,shy,chymo,xdir,
 
432
     &              p_born(0,i),p1(0,i))
 
433
            endif
 
434
            do j=0,3
 
435
               pb(j,i)=p1(j,i)
 
436
            enddo
 
437
            if (Hevents .or. i.lt.i_fks) then
 
438
               pb(4,i)=xmcmass(i)
 
439
            else
 
440
               pb(4,i)=xmcmass(i+1)
 
441
            endif
 
442
         enddo
 
443
c In some rare cases (due to numerical inaccuracies in the boost) the
 
444
c energy of the incoming partons can be larger than the beam energy This
 
445
c is, of course, non-physical, so we use the non-boosted events
 
446
         if (pb(0,1).gt.ebeam(1).or.pb(0,2).gt.ebeam(2)) then
 
447
            write (*,*) 'WARNING: boost from center-of-momentum to '/
 
448
     &           /'laboratory frame too extreme. Use the center-of-mo'/
 
449
     &           /'mentum momenta instead.',pb(0,1),pb(0,2),ebeam(1)
 
450
     &           ,ebeam(2)
 
451
            do i=1,nexpart
 
452
               do j=0,3
 
453
                  if (Hevents) then
 
454
                     pb(j,i)=pp(j,i)
 
455
                  else
 
456
                     pb(j,i)=p_born(j,i)
 
457
                  endif
 
458
               enddo
 
459
            enddo
 
460
         endif
 
461
      endif
 
462
 
 
463
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
 
464
C ALL EXTERNAL PARTICLE INFO SET-UP. CHECK WHICH RESONANCES SHOULD BE WRITTEN C
 
465
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
 
466
c
 
467
c Fill the OnBW array to determine which resonances should be written
 
468
c
 
469
      call OnBreitWigner(pp,p_born,Hevents,itree,sprop_tree,pmass_tree,
 
470
     &     pwidth_tree,OnBW)
 
471
 
 
472
c     First check number of resonant s-channel propagators
 
473
      ns=0
 
474
      nres=0
 
475
 
 
476
c     Loop over propagators to find mother-daughter information
 
477
      do i=-1,-nexpart+3,-1
 
478
c     Daughters
 
479
         ida(1)=itree(1,i)
 
480
         ida(2)=itree(2,i)
 
481
c Skip the t-channels
 
482
         if ( itree(1,i) .eq. 1 .or. itree(2,i) .eq. 1 .or.
 
483
     &        itree(1,i) .eq. 2 .or. itree(2,i) .eq. 2 ) exit
 
484
         jpart(1,i)=sprop_tree(i)
 
485
         ns=ns+1
 
486
c     Set status codes for propagator
 
487
         if(OnBW(i)) then 
 
488
c     Resonance whose mass should be preserved
 
489
            jpart(6,i)=2
 
490
            nres=nres+1
 
491
         else
 
492
c     Tag the s-channel internal propagators that we'll remove later
 
493
            jpart(6,i)=3
 
494
         endif
 
495
c     Calculate momentum (p1+p2 for s-channel)
 
496
         do j=0,3
 
497
            pb(j,i)=pb(j,ida(1))+pb(j,ida(2))
 
498
         enddo
 
499
         pb(4,i)=
 
500
     &        sqrt(max(0d0,pb(0,i)**2-pb(1,i)**2-pb(2,i)**2-pb(3,i)**2))
 
501
 
 
502
c     Set color info for all s-channels
 
503
c     Fist set "safe" color info
 
504
         if(icolalt(1,ida(1))+icolalt(1,ida(2))-
 
505
     $        icolalt(2,ida(1))-icolalt(2,ida(2)).eq.0) then ! color singlet
 
506
            icolalt(1,i) = 0
 
507
            icolalt(2,i) = 0            
 
508
         elseif(icolalt(1,ida(1))-icolalt(2,ida(2)).eq.0) then
 
509
            icolalt(1,i) = icolalt(1,ida(2))
 
510
            icolalt(2,i) = icolalt(2,ida(1))
 
511
         else if(icolalt(1,ida(2))-icolalt(2,ida(1)).eq.0) then
 
512
            icolalt(1,i) = icolalt(1,ida(1))
 
513
            icolalt(2,i) = icolalt(2,ida(2))
 
514
         else if(jpart(6,i).ge.3) then ! Don't need to match
 
515
            icolalt(1,i) = icolalt(1,ida(1))+icolalt(1,ida(2))
 
516
            icolalt(2,i) = icolalt(2,ida(1))+icolalt(2,ida(2))
 
517
         else
 
518
c     Erraneous color assignment for propagator
 
519
            write(*,*) 'ERROR: Safe color assignment wrong!'/
 
520
     &           /' This should never happen !',i,icolalt(1,ida(1))
 
521
     &           ,icolalt(1,ida(2)),icolalt(2,ida(1)),icolalt(2,ida(2))
 
522
     &           ,ida(1),ida(2)
 
523
            stop
 
524
         endif
 
525
c     Set initial state as tentative mothers
 
526
         jpart(2,i) = 1
 
527
         jpart(3,i) = 2
 
528
c     Set mother info for daughters
 
529
         do j=1,2
 
530
            jpart(2,ida(j)) = i
 
531
            jpart(3,ida(j)) = i
 
532
         enddo
 
533
c     Just zero helicity info for intermediate states
 
534
         jpart(7,i) = 0
 
535
      enddo                     ! do i (loop over internal propagators)
 
536
      
 
537
c     Remove non-resonant mothers, set position of particles
 
538
      ires=0
 
539
      do i=-ns,nexpart
 
540
         jpart(4,i)=icolalt(1,i)
 
541
         jpart(5,i)=icolalt(2,i)
 
542
         if(i.eq.1.or.i.eq.2) then 
 
543
            ito(i)=i            ! initial state particle
 
544
         elseif(i.ge.3) then 
 
545
            ito(i)=i+nres       ! final state particle
 
546
         elseif(i.le.-1.and.jpart(6,i).eq.2) then
 
547
            ires=ires+1
 
548
            ito(i)=2+ires       ! s-channel resonances
 
549
         else 
 
550
            ito(i)=0
 
551
            if(i.eq.0) cycle
 
552
         endif
 
553
         if(jpart(2,i).lt.0.and.jpart(6,jpart(2,i)).ne.2) then
 
554
            jpart(2,i)=jpart(2,jpart(2,i))
 
555
            jpart(3,i)=jpart(3,jpart(3,i))
 
556
         endif
 
557
      enddo
 
558
        
 
559
c
 
560
c Shift particles to right place
 
561
c     
 
562
      do i=nexpart,-ns,-1
 
563
         if(ito(i).le.0) cycle
 
564
         do j=1,7
 
565
            jpart(j,ito(i))=jpart(j,i)
 
566
         enddo
 
567
         if(jpart(2,ito(i)).lt.0) then
 
568
            jpart(2,ito(i))=ito(jpart(2,ito(i)))
 
569
            jpart(3,ito(i))=ito(jpart(3,ito(i)))
 
570
         endif
 
571
         do j=0,4
 
572
            pb(j,ito(i))=pb(j,i)
 
573
         enddo
 
574
      enddo
 
575
c
 
576
c     Set the number of particles that needs to be written in event file
 
577
c
 
578
      npart = nexpart+nres
 
579
         
 
580
      return
 
581
      end
 
582
 
 
583
 
 
584
      subroutine set_itree(iconfig,Hevents,itree,sprop_tree,pmass_tree
 
585
     &     ,pwidth_tree)
 
586
      implicit none
 
587
      integer iconfig
 
588
      logical Hevents
 
589
      include "genps.inc"
 
590
      include 'nexternal.inc'
 
591
      include "coupl.inc"
 
592
      double precision ZERO
 
593
      parameter (ZERO=0d0)
 
594
      integer itree(2,-max_branch:-1)
 
595
      integer sprop_tree(-max_branch:-1)
 
596
      integer iforest(2,-max_branch:-1,lmaxconfigs)
 
597
      integer sprop(-max_branch:-1,lmaxconfigs),mapconfig(0:lmaxconfigs)
 
598
      integer tprid(-max_branch:-1,lmaxconfigs)
 
599
      include "born_conf.inc"
 
600
      integer i,j,jj
 
601
      double precision pmass(-nexternal:0,lmaxconfigs)
 
602
      double precision pwidth(-nexternal:0,lmaxconfigs)
 
603
      integer pow(-nexternal:0,lmaxconfigs)
 
604
      double precision pmass_tree(-nexternal:0)
 
605
      double precision pwidth_tree(-nexternal:0)
 
606
      integer i_fks,j_fks
 
607
      common/fks_indices/i_fks,j_fks
 
608
      include "born_props.inc"
 
609
c
 
610
c Do not really care about t-channels: loop should just go to
 
611
c nexternal-4, even though there is one more when there are t-channels
 
612
c around
 
613
      do j=-(nexternal-4),-1
 
614
         do i=1,2
 
615
            itree(i,j)=iforest(i,j,iconfig)
 
616
         enddo
 
617
         sprop_tree(j)=sprop(j,iconfig)
 
618
         pmass_tree(j)=pmass(j,iconfig)
 
619
         pwidth_tree(j)=pwidth(j,iconfig)
 
620
      enddo
 
621
c
 
622
c When we are doing H-events, we need to add --when j_fks is final
 
623
c state-- the s-channel branching fks_mother -> j_fks + i_fks.  When
 
624
c j_fks is initial state, we need to add a 'bogus' t-channel splitting
 
625
c to make sure that all the loops stop properly
 
626
c
 
627
      if (Hevents) then
 
628
c must re-label the external particles to get the correct daughters
 
629
         if (i_fks.le.j_fks) then
 
630
            write (*,*) 'ERROR: i_fks should be greater than j_fks'
 
631
            stop
 
632
         endif
 
633
         do j=-(nexternal-4),-1
 
634
            do i=1,2
 
635
               if ( itree(i,j).ge.i_fks ) then
 
636
                  itree(i,j)=itree(i,j)+1
 
637
               endif
 
638
            enddo
 
639
         enddo
 
640
c
 
641
         if (j_fks.gt.nincoming) then
 
642
c we must add an extra s-channel. Easiest is to add it all the way at
 
643
c the beginning. Therefore, relabel everything else first. Use the
 
644
c original ones to make sure we are doing it correctly (and not
 
645
c accidentally overwriting something).
 
646
            do j=-(nexternal-4),-1
 
647
               sprop_tree(j-1)=sprop(j,iconfig)
 
648
               pmass_tree(j-1)=pmass(j,iconfig)
 
649
               pwidth_tree(j-1)=pwidth(j,iconfig)
 
650
               do i=1,2
 
651
                  itree(i,j-1)=iforest(i,j,iconfig)
 
652
c Also update the internal references
 
653
                  if ( itree(i,j-1).lt. 0 ) then
 
654
                     itree(i,j-1)=itree(i,j-1)-1
 
655
                  endif
 
656
               enddo
 
657
            enddo
 
658
c
 
659
c Add the new s-channel
 
660
c
 
661
            itree(1,-1)=i_fks
 
662
            itree(2,-1)=j_fks
 
663
c This will never be an on-shell s-channel. Hence, give it some bogus values:
 
664
            sprop_tree(-1)=0
 
665
            pmass_tree(-1)=0d0
 
666
            pwidth_tree(-1)=0d0
 
667
c
 
668
c We have to make sure that the fks_mother (which is equal to the j_fks
 
669
c label of the Born) is replaced by the new s-channel
 
670
c
 
671
            do j=-(nexternal-3),-2 ! do not include the new s-channel
 
672
               do i=1,2
 
673
                  if ( itree(i,j).eq. j_fks ) then
 
674
                     itree(i,j)=-1 ! reference to the new s-channel
 
675
                  endif
 
676
               enddo
 
677
            enddo
 
678
 
 
679
         else
 
680
c j_fks is initial state
 
681
            jj=-(nexternal-3)     ! Just add it at the end
 
682
c setting itree to 1 (or 2) makes sure that the loops over s-channel
 
683
c propagators will exit
 
684
            itree(1,jj)=1
 
685
            itree(2,jj)=1
 
686
            sprop_tree(jj)=0
 
687
            pmass_tree(jj)=0d0
 
688
            pwidth_tree(jj)=0d0
 
689
         endif
 
690
      endif
 
691
 
 
692
      return
 
693
      end
 
694
 
 
695
 
 
696
 
 
697
 
 
698
      subroutine OnBreitWigner(p,p_born,Hevents,itree,sprop_tree,
 
699
     &     pmass,pwidth,OnBW)
 
700
c*****************************************************************************
 
701
c Decides if internal s-channel propagator is on-shell
 
702
c*****************************************************************************
 
703
      implicit none
 
704
c
 
705
c     Constants
 
706
c     
 
707
      include 'genps.inc'
 
708
      include 'nexternal.inc'
 
709
      include 'run.inc'
 
710
c
 
711
c     Arguments
 
712
c
 
713
      double precision p(0:3,nexternal),p_born(0:3,nexternal-1)
 
714
      logical OnBW(-nexternal:0),Hevents
 
715
      integer itree(2,-max_branch:-1),sprop_tree(-max_branch:-1)
 
716
      double precision pmass(-nexternal:0)
 
717
      double precision pwidth(-nexternal:0)
 
718
c
 
719
c     Local
 
720
c
 
721
      double precision xp(0:3,-nexternal:nexternal)
 
722
      integer i,j,iloop
 
723
      logical onshell
 
724
      double precision xmass
 
725
      integer ida(2),idenpart
 
726
      integer IDUP(nexternal)
 
727
c
 
728
c     External
 
729
c
 
730
      double precision dot
 
731
c-----
 
732
c  Begin Code
 
733
c-----      
 
734
      if (Hevents) then
 
735
         call get_ID_H(IDUP)
 
736
         iloop=nexternal-3
 
737
      else
 
738
         call get_ID_S(IDUP)
 
739
         iloop=nexternal-4
 
740
      endif
 
741
      do i=1,nexternal
 
742
         do j=0,3
 
743
            if (Hevents) then
 
744
               xp(j,i)=p(j,i)
 
745
            else
 
746
               if (i.ne.nexternal) then
 
747
                  xp(j,i)=p_born(j,i)
 
748
               elseif (i.eq.nexternal) then
 
749
                  xp(j,i)=0d0
 
750
               endif
 
751
            endif
 
752
         enddo
 
753
      enddo
 
754
c
 
755
      do i=-1,-iloop,-1                      !Loop over propagators
 
756
         onbw(i) = .false.
 
757
c Skip the t-channels
 
758
         if ( itree(1,i) .eq. 1 .or. itree(2,i) .eq. 1 .or.
 
759
     &        itree(1,i) .eq. 2 .or. itree(2,i) .eq. 2 ) exit
 
760
         do j=0,3
 
761
            xp(j,i) = xp(j,itree(1,i))+xp(j,itree(2,i))
 
762
         enddo
 
763
         if (pwidth(i) .gt. 0d0) then !This is B.W.
 
764
c
 
765
c     If the invariant mass is close to pole mass, set OnBW to true
 
766
c
 
767
            xmass = sqrt(dot(xp(0,i),xp(0,i)))
 
768
            onshell = ( abs(xmass-pmass(i)) .lt. bwcutoff*pwidth(i) )
 
769
            if(onshell)then
 
770
               OnBW(i) = .true.
 
771
c     If mother and daughter have the same ID, remove one of them
 
772
               idenpart=0
 
773
               do j=1,2
 
774
                  ida(j)=itree(j,i)
 
775
                  if(ida(j).lt.0) then
 
776
                     if (sprop_tree(i).eq.sprop_tree(ida(j))) then
 
777
                        idenpart=ida(j) ! mother and daugher have same ID
 
778
                     endif
 
779
                  elseif (ida(j).gt.0) then
 
780
                     if (sprop_tree(i).eq.IDUP(ida(j))) then
 
781
                        idenpart=ida(j) ! mother and daugher have same ID
 
782
                     endif
 
783
                  endif
 
784
               enddo
 
785
c     Always remove if daughter final-state (and identical)
 
786
               if(idenpart.gt.0) then
 
787
                  OnBW(i)=.false.
 
788
c     Else remove either this resonance or daughter,
 
789
c                  whichever is closer to mass shell
 
790
               elseif(idenpart.lt.0.and.abs(xmass-pmass(i)).gt.
 
791
     $                 abs(sqrt(dot(xp(0,idenpart),xp(0,idenpart)))-
 
792
     $                 pmass(i))) then
 
793
                  OnBW(i)=.false.         ! mother off-shell
 
794
               elseif(idenpart.lt.0) then
 
795
                  OnBW(idenpart)=.false.  ! daughter off-shell
 
796
               endif
 
797
            endif
 
798
         endif
 
799
      enddo
 
800
      end
 
801
 
 
802
      subroutine get_ID_H(IDUP_tmp)
 
803
      implicit none
 
804
      include "genps.inc"
 
805
      include 'nexternal.inc'
 
806
      integer maxflow
 
807
      parameter (maxflow=999)
 
808
      integer idup(nexternal,maxproc),mothup(2,nexternal,maxproc),
 
809
     &     icolup(2,nexternal,maxflow)
 
810
c      include 'leshouche.inc'
 
811
      common /c_leshouche_inc/idup,mothup,icolup
 
812
      integer IDUP_tmp(nexternal),i
 
813
c
 
814
      do i=1,nexternal
 
815
         IDUP_tmp(i)=IDUP(i,1)
 
816
      enddo
 
817
c
 
818
      return
 
819
      end
 
820
 
 
821
      subroutine get_ID_S(IDUP_tmp)
 
822
      implicit none
 
823
      include "genps.inc"
 
824
      include 'nexternal.inc'
 
825
      integer    maxflow
 
826
      parameter (maxflow=999)
 
827
      integer idup(nexternal,maxproc)
 
828
      integer mothup(2,nexternal,maxproc)
 
829
      integer icolup(2,nexternal,maxflow)
 
830
      include 'born_leshouche.inc'
 
831
      integer IDUP_tmp(nexternal),i
 
832
c
 
833
      do i=1,nexternal-1
 
834
         IDUP_tmp(i)=IDUP(i,1)
 
835
      enddo
 
836
      IDUP_tmp(nexternal)=0
 
837
c
 
838
      return
 
839
      end
 
840
 
 
841
 
 
842
      subroutine fill_icolor_H(iflow,jpart)
 
843
      implicit none
 
844
      include "nexternal.inc"
 
845
c      include 'fks.inc'
 
846
      integer fks_j_from_i(nexternal,0:nexternal)
 
847
     &     ,particle_type(nexternal),pdg_type(nexternal)
 
848
      common /c_fks_inc/fks_j_from_i,particle_type,pdg_type
 
849
      integer i
 
850
      integer i_fks,j_fks
 
851
      common/fks_indices/i_fks,j_fks
 
852
      double precision xtarget,ran2
 
853
      external ran2
 
854
      integer jpart(7,-nexternal+3:2*nexternal-3),iflow
 
855
      integer i_part,j_part,imother,lc
 
856
c
 
857
      call fill_icolor_S(iflow,jpart,lc)
 
858
c
 
859
      j_part = particle_type(j_fks)
 
860
      i_part = particle_type(i_fks)
 
861
c
 
862
      do i=nexternal,1,-1
 
863
         if (i.gt.max(i_fks,j_fks)) then
 
864
            jpart(4,i)=jpart(4,i-1)
 
865
            jpart(5,i)=jpart(5,i-1)
 
866
         endif
 
867
      enddo
 
868
c
 
869
      imother=min(i_fks,j_fks)
 
870
c The following works only if i_fks is always greater than j_fks.      
 
871
      if (j_fks.gt.nincoming) then
 
872
         if (j_part.eq.3.and.i_part.eq.-3) then
 
873
            if(jpart(4,imother).eq.0 .or. jpart(5,imother).eq.0)then
 
874
               write (*,*) 'Error #3 in fill_icolor_H',
 
875
     &              jpart(4,imother),jpart(5,imother)
 
876
               stop
 
877
            endif
 
878
            jpart(4,i_fks)=0
 
879
            jpart(5,i_fks)=jpart(5,imother)
 
880
            jpart(4,j_fks)=jpart(4,imother)
 
881
            jpart(5,j_fks)=0
 
882
         elseif (j_part.eq.-3.and.i_part.eq.3) then
 
883
            if(jpart(4,imother).eq.0 .or. jpart(5,imother).eq.0)then
 
884
               write (*,*) 'Error #4 in fill_icolor_H',
 
885
     &              jpart(4,imother),jpart(5,imother)
 
886
               stop
 
887
            endif
 
888
            jpart(4,i_fks)=jpart(4,imother)
 
889
            jpart(5,i_fks)=0
 
890
            jpart(4,j_fks)=0
 
891
            jpart(5,j_fks)=jpart(5,imother) 
 
892
         elseif (j_part.eq.3.and.i_part.eq.8) then
 
893
            if(jpart(4,imother).eq.0 .or. jpart(5,imother).ne.0)then
 
894
               write (*,*) 'Error #5 in fill_icolor_H',
 
895
     &              jpart(4,imother),jpart(5,imother)
 
896
               stop
 
897
            endif
 
898
            jpart(4,i_fks)=jpart(4,imother)
 
899
            jpart(5,i_fks)=lc+1
 
900
            jpart(4,j_fks)=lc+1
 
901
            jpart(5,j_fks)=0
 
902
         elseif (j_part.eq.-3.and.i_part.eq.8) then
 
903
            if(jpart(4,imother).ne.0 .or. jpart(5,imother).eq.0)then
 
904
               write (*,*) 'Error #6 in fill_icolor_H',
 
905
     &              jpart(4,imother),jpart(5,imother)
 
906
               stop
 
907
            endif
 
908
            jpart(4,i_fks)=lc+1
 
909
            jpart(5,i_fks)=jpart(5,imother)
 
910
            jpart(4,j_fks)=0
 
911
            jpart(5,j_fks)=lc+1
 
912
         elseif (j_part.eq.8.and.i_part.eq.8) then
 
913
            if(jpart(4,imother).eq.0 .or. jpart(5,imother).eq.0)then
 
914
               write (*,*) 'Error #7 in fill_icolor_H',
 
915
     &              jpart(4,imother),jpart(5,imother)
 
916
               stop
 
917
            endif
 
918
            if (ran2().gt.0.5d0) then 
 
919
               jpart(4,i_fks)=lc+1
 
920
               jpart(5,i_fks)=jpart(5,imother)
 
921
               jpart(4,j_fks)=jpart(4,imother)
 
922
               jpart(5,j_fks)=lc+1
 
923
            else
 
924
               jpart(4,i_fks)=jpart(4,imother)
 
925
               jpart(5,i_fks)=lc+1
 
926
               jpart(4,j_fks)=lc+1
 
927
               jpart(5,j_fks)=jpart(5,imother)
 
928
            endif
 
929
         else
 
930
            write (*,*) 'Error #1 in fill_icolor_H',i_part,j_part
 
931
            stop
 
932
         endif
 
933
      else
 
934
         if (j_part.eq.-3.and.i_part.eq.-3) then
 
935
            if(jpart(4,imother).eq.0 .or. jpart(5,imother).eq.0)then
 
936
               write (*,*) 'Error #8 in fill_icolor_H',
 
937
     &              jpart(4,imother),jpart(5,imother)
 
938
               stop
 
939
            endif
 
940
            jpart(4,i_fks)=0
 
941
            jpart(5,i_fks)=jpart(4,imother)
 
942
            jpart(4,j_fks)=0
 
943
            jpart(5,j_fks)=jpart(5,imother)
 
944
         elseif (j_part.eq.3.and.i_part.eq.3) then
 
945
            if(jpart(4,imother).eq.0 .or. jpart(5,imother).eq.0)then
 
946
               write (*,*) 'Error #9 in fill_icolor_H',
 
947
     &              jpart(4,imother),jpart(5,imother),'HERE'
 
948
               stop
 
949
            endif
 
950
            jpart(4,i_fks)=jpart(5,imother)
 
951
            jpart(5,i_fks)=0
 
952
            jpart(4,j_fks)=jpart(4,imother)
 
953
            jpart(5,j_fks)=0
 
954
         elseif (j_part.eq.3.and.i_part.eq.8) then
 
955
            if(jpart(4,imother).eq.0 .or. jpart(5,imother).ne.0)then
 
956
               write (*,*) 'Error #10 in fill_icolor_H',
 
957
     &              jpart(4,imother),jpart(5,imother)
 
958
               stop
 
959
            endif
 
960
            jpart(4,i_fks)=lc+1
 
961
            jpart(5,i_fks)=jpart(4,imother)
 
962
            jpart(4,j_fks)=lc+1
 
963
            jpart(5,j_fks)=0
 
964
         elseif (j_part.eq.-3.and.i_part.eq.8) then
 
965
            if(jpart(4,imother).ne.0 .or. jpart(5,imother).eq.0)then
 
966
               write (*,*) 'Error #11 in fill_icolor_H',
 
967
     &              jpart(4,imother),jpart(5,imother)
 
968
               stop
 
969
            endif
 
970
            jpart(4,i_fks)=jpart(5,imother)
 
971
            jpart(5,i_fks)=lc+1
 
972
            jpart(4,j_fks)=0
 
973
            jpart(5,j_fks)=lc+1
 
974
         elseif (j_part.eq.8.and.i_part.eq.3) then
 
975
            if(jpart(4,imother).ne.0 .or. jpart(5,imother).eq.0)then
 
976
               write (*,*) 'Error #12 in fill_icolor_H',
 
977
     &              jpart(4,imother),jpart(5,imother)
 
978
               stop
 
979
            endif
 
980
            jpart(4,i_fks)=lc+1
 
981
            jpart(5,i_fks)=0
 
982
            jpart(4,j_fks)=lc+1
 
983
            jpart(5,j_fks)=jpart(5,imother)
 
984
         elseif (j_part.eq.8.and.i_part.eq.-3) then
 
985
            if(jpart(4,imother).eq.0 .or. jpart(5,imother).ne.0)then
 
986
               write (*,*) 'Error #13 in fill_icolor_H',
 
987
     &              jpart(4,imother),jpart(5,imother)
 
988
               stop
 
989
            endif
 
990
            jpart(4,i_fks)=0
 
991
            jpart(5,i_fks)=lc+1
 
992
            jpart(4,j_fks)=jpart(4,imother)
 
993
            jpart(5,j_fks)=lc+1
 
994
         elseif (j_part.eq.8.and.i_part.eq.8) then
 
995
            if(jpart(4,imother).eq.0 .or. jpart(5,imother).eq.0)then
 
996
               write (*,*) 'Error #14 in fill_icolor_H',
 
997
     &              jpart(4,imother),jpart(5,imother)
 
998
               stop
 
999
            endif
 
1000
            if (ran2().gt.0.5d0) then 
 
1001
               jpart(4,i_fks)=lc+1
 
1002
               jpart(5,i_fks)=jpart(4,imother)
 
1003
               jpart(4,j_fks)=lc+1
 
1004
               jpart(5,j_fks)=jpart(5,imother)
 
1005
            else
 
1006
               jpart(4,i_fks)=jpart(5,imother)
 
1007
               jpart(5,i_fks)=lc+1
 
1008
               jpart(4,j_fks)=jpart(4,imother)
 
1009
               jpart(5,j_fks)=lc+1
 
1010
            endif
 
1011
         else
 
1012
            write (*,*) 'Error #2 in fill_icolor_H',i_part,j_part
 
1013
            stop
 
1014
         endif
 
1015
      endif
 
1016
c
 
1017
      return
 
1018
      end
 
1019
 
 
1020
 
 
1021
      subroutine fill_icolor_S(iflow,jpart,lc)
 
1022
      implicit none
 
1023
      include 'genps.inc'
 
1024
      include 'nexternal.inc'
 
1025
      integer    maxflow
 
1026
      parameter (maxflow=999)
 
1027
      integer i
 
1028
      integer idup(nexternal,maxproc)
 
1029
      integer mothup(2,nexternal,maxproc)
 
1030
      integer icolup(2,nexternal,maxflow)
 
1031
      include "born_leshouche.inc"
 
1032
      integer jpart(7,-nexternal+3:2*nexternal-3),lc,iflow
 
1033
c
 
1034
      lc=0
 
1035
      do i=1,nexternal-1
 
1036
         jpart(4,i)=ICOLUP(1,i,iflow)
 
1037
         lc=max(lc,jpart(4,i))
 
1038
         jpart(5,i)=ICOLUP(2,i,iflow)
 
1039
         lc=max(lc,jpart(5,i))
 
1040
      enddo
 
1041
c
 
1042
      return
 
1043
      end
 
1044
 
 
1045
 
 
1046
 
 
1047
      subroutine put_on_MC_mshell(Hevents,jpart,xmi,xmj,xm1,xm2,emsum)
 
1048
c Sets the common block /to_mass/emass, to be passed to one_tree
 
1049
c to generate a massive kinematics with efficiency 1.
 
1050
c
 
1051
c ip is the number of the partonic process chosen at random in the case
 
1052
c of multiple possibilities.
 
1053
c This routines assumes that the mother of (i_fks,j_fks) has
 
1054
c label min(i_fks,j_fks)
 
1055
      implicit none
 
1056
      integer ip
 
1057
      double precision xmi,xmj,xm1,xm2,emsum
 
1058
      logical Hevents
 
1059
 
 
1060
      integer i,j,idpart,idparti,idpartj
 
1061
      double precision zero,tmpmass
 
1062
      parameter (zero=0.d0)
 
1063
c jpart contains ID of particles
 
1064
      include 'nexternal.inc'
 
1065
      integer jpart(7,-nexternal+3:2*nexternal-3)
 
1066
 
 
1067
c Masses to be given to genps_fks.f
 
1068
      double precision emass(nexternal)
 
1069
      common/to_mass/  emass
 
1070
 
 
1071
c Monte Carlo masses: use PDG conventions
 
1072
      double precision mcmass(-5:21)
 
1073
      common/cmcmass/mcmass
 
1074
 
 
1075
c Masses used by write_events_lhe
 
1076
      double precision xmcmass(nexternal)
 
1077
      common/cxmcmass/xmcmass
 
1078
 
 
1079
c cuts.inc contains maxjetflavor
 
1080
      include 'cuts.inc'
 
1081
 
 
1082
      integer i_fks,j_fks
 
1083
      common/fks_indices/i_fks,j_fks
 
1084
 
 
1085
c Masses of the real process, as set by MadGraph
 
1086
      include 'coupl.inc'
 
1087
      double precision pmass(nexternal)
 
1088
      include 'pmass.inc'
 
1089
c
 
1090
      if(j_fks.ne.min(i_fks,j_fks))then
 
1091
        write(*,*)'j_fks#min(i_fks,j_fks) in put_on_MC_mshell'
 
1092
        stop
 
1093
      endif
 
1094
c
 
1095
      xmi=-1.d0
 
1096
      xmj=-1.d0
 
1097
      xm1=-1.d0
 
1098
      xm2=-1.d0
 
1099
      do i=1,nexternal
 
1100
        if(i.eq.i_fks)then
 
1101
          if(pmass(i).ne.0.d0)then
 
1102
            write(*,*)'Fatal error in put_on_MC_mshell',i_fks,i,pmass(i)
 
1103
            stop
 
1104
          endif
 
1105
          emass(i)=0.d0
 
1106
        elseif(i.eq.j_fks)then
 
1107
          idpartj=jpart(1,j_fks)
 
1108
          idparti=jpart(1,i_fks)
 
1109
          if(.not.Hevents)then
 
1110
c S events
 
1111
            xmi=0.d0
 
1112
            if(idparti.eq.-idpartj.and.j_fks.gt.nincoming) then
 
1113
               idpart=21
 
1114
            elseif(idparti.eq.idpartj.and.j_fks.le.nincoming) then
 
1115
               idpart=21
 
1116
            elseif(idparti.eq.21) then
 
1117
               idpart=idpartj
 
1118
            elseif(idpartj.eq.21.and.j_fks.le.nincoming) then
 
1119
               idpart=-idparti
 
1120
            else
 
1121
               write(*,*)'Error #2 in put_on_MC_mshell',
 
1122
     &              i_fks,j_fks,idparti,idpartj
 
1123
               stop
 
1124
            endif
 
1125
            if( (abs(idpart).ge.1.and.abs(idpart).le.3) .or.
 
1126
     #          idpart.eq.21 .or.
 
1127
     #          ( (abs(idpart).eq.4.or.abs(idpart).eq.5) .and.
 
1128
     #            pmass(j_fks).eq.0.d0 ) )then
 
1129
              xmj=mcmass(idpart)
 
1130
            else
 
1131
c j_fks is an heavy particle
 
1132
              if(idparti.ne.21)then
 
1133
                write(*,*)'Error #3 in put_on_MC_mshell',
 
1134
     &            i_fks,j_fks,i,pmass(j_fks)
 
1135
                stop
 
1136
              endif
 
1137
c If MadFKS has a non-zero mass for a c or b quark, one probably wants
 
1138
c to use that in the shower phase as well (ie bottom or charm production)
 
1139
              xmj=pmass(j_fks)
 
1140
            endif
 
1141
            if(j_fks.gt.nincoming)then
 
1142
              emass(j_fks)=xmj
 
1143
            else
 
1144
c one_tree assumes massless incoming QCD particles
 
1145
              emass(j_fks)=0.d0
 
1146
              if(j_fks.eq.1)then
 
1147
                xm1=xmj
 
1148
              else
 
1149
                xm2=xmj
 
1150
              endif
 
1151
            endif
 
1152
            xmcmass(i)=xmj
 
1153
          else
 
1154
c H events
 
1155
            xmi=mcmass(idparti)
 
1156
            if( (abs(idpartj).ge.1.and.abs(idpartj).le.3) .or.
 
1157
     #          idpartj.eq.21 .or.
 
1158
     #          ( (abs(idpartj).eq.4.or.abs(idpartj).eq.5) .and.
 
1159
     #            pmass(j_fks).eq.0.d0 ) )then
 
1160
              xmj=mcmass(idpartj)
 
1161
            else
 
1162
c j_fks is an heavy particle
 
1163
              if(idparti.ne.21)then
 
1164
                write(*,*)'Error #3 in put_on_MC_mshell',
 
1165
     &            i_fks,j_fks,i,pmass(j_fks),(jpart(1,j),j=1,nexternal)
 
1166
                stop
 
1167
              endif
 
1168
c If MadFKS has a non-zero mass for a c or b quark, one probably wants
 
1169
c to use that in the shower phase as well (ie bottom or charm production)
 
1170
              xmj=pmass(j_fks)
 
1171
            endif
 
1172
            if(j_fks.gt.nincoming)then
 
1173
              emass(j_fks)=xmi+xmj
 
1174
            else
 
1175
c one_tree assumes massless incoming QCD particles
 
1176
              emass(j_fks)=0.d0
 
1177
              if(j_fks.eq.1)then
 
1178
                xm1=xmj
 
1179
              else
 
1180
                xm2=xmj
 
1181
              endif
 
1182
            endif
 
1183
            xmcmass(i_fks)=xmi
 
1184
            xmcmass(j_fks)=xmj
 
1185
          endif
 
1186
        else
 
1187
          idpart=jpart(1,i)
 
1188
          if( idpart.eq.21 .or.
 
1189
     #        (abs(idpart).ge.1.and.abs(idpart).le.5) )then
 
1190
            if(pmass(i).eq.0.d0)then
 
1191
              tmpmass=mcmass(idpart)
 
1192
            else
 
1193
c If MadFKS has a non-zero mass for a "light" quark, one probably wants
 
1194
c to use that in the shower phase as well (ie bottom or charm production).
 
1195
c One may use equivalently a condition on maxjetflavor
 
1196
              tmpmass=pmass(i)
 
1197
            endif
 
1198
          else
 
1199
            tmpmass=pmass(i)
 
1200
          endif
 
1201
          if(i.gt.nincoming)then
 
1202
            emass(i)=tmpmass
 
1203
          elseif(i.eq.1)then
 
1204
            emass(i)=0.d0
 
1205
            xm1=tmpmass
 
1206
          elseif(i.eq.2)then
 
1207
            emass(i)=0.d0
 
1208
            xm2=tmpmass
 
1209
          endif
 
1210
          xmcmass(i)=tmpmass
 
1211
        endif
 
1212
      enddo
 
1213
c
 
1214
      emsum=0.d0
 
1215
      do i=nincoming+1,nexternal
 
1216
        emsum=emsum+emass(i)
 
1217
      enddo
 
1218
c
 
1219
      if( xmi.eq.-1.d0.or.xmj.eq.-1.d0 .or.
 
1220
     #    xm1.eq.-1.d0.or.xm2.eq.-1.d0 )then
 
1221
        write(*,*)'Error #4 in put_on_MC_mshell',i_fks,j_fks
 
1222
        write(*,*)xmi,xmj,xm1,xm2
 
1223
        stop
 
1224
      endif
 
1225
c
 
1226
      return
 
1227
      end
 
1228
 
 
1229
 
 
1230
      subroutine put_on_MC_mshell_Hev(p,xmi,xmj,xm1,xm2,mfail)
 
1231
      implicit none
 
1232
      include 'nexternal.inc'
 
1233
      double precision p(0:3,99),xmi,xmj,xm1,xm2
 
1234
      integer mfail
 
1235
      integer i_fks,j_fks
 
1236
      common/fks_indices/i_fks,j_fks
 
1237
c
 
1238
      if (p(0,1).lt.0d0) then
 
1239
         mfail=1
 
1240
         write (*,*) 'Momenta generation for put_on_MC_mshell failed'
 
1241
         return
 
1242
      endif
 
1243
 
 
1244
      if(j_fks.le.nincoming)then
 
1245
        call put_on_MC_mshell_Hevin(p,xmi,xm1,xm2,mfail)
 
1246
      else
 
1247
        call put_on_MC_mshell_Hevout(p,xmi,xmj,mfail)
 
1248
      endif
 
1249
c
 
1250
      return
 
1251
      end
 
1252
 
 
1253
 
 
1254
      subroutine put_on_MC_mshell_in(p,xm1,xm2,mfail)
 
1255
      implicit none
 
1256
      include 'nexternal.inc'
 
1257
      double precision p(0:3,nexternal),xm1,xm2
 
1258
      integer mfail
 
1259
      double precision xm1_r,xm2_r
 
1260
 
 
1261
      double precision ybst_til_tolab,ybst_til_tocm,sqrtshat,shat
 
1262
      common/parton_cms_stuff/ybst_til_tolab,ybst_til_tocm,
 
1263
     #                        sqrtshat,shat
 
1264
      double precision xmcmass(nexternal)
 
1265
      common/cxmcmass/xmcmass
 
1266
c
 
1267
      if (p(0,1).lt.0d0) then
 
1268
         mfail=1
 
1269
         write (*,*) 'Momenta generation for put_on_MC_mshell failed'
 
1270
         return
 
1271
      endif
 
1272
 
 
1273
      if(abs(p(3,1)+p(3,2)).gt.1.d-10)then
 
1274
        write(*,*)'Error #1 in put_on_MC_mshell_in',p(3,1),p(3,2)
 
1275
        stop
 
1276
      endif
 
1277
      if(shat.le.(xm1+xm2)**2)then
 
1278
        mfail=1
 
1279
        return
 
1280
      endif
 
1281
      xm1_r=xm1
 
1282
      xm2_r=xm2
 
1283
c$$$CHECK AGAIN USE OF ybst_til_tolab IN getxmss.
 
1284
c$$$MUST BE THE SAME BOOST AS WHEN WRITING EVENTS
 
1285
      call getxmss_madfks(shat,ybst_til_tolab,
 
1286
     #                    p(3,1),xm1_r,p(3,2),xm2_r,
 
1287
     #                    p(3,1),p(3,2),mfail)
 
1288
      if(mfail.eq.0)then
 
1289
        p(0,1)=sqrt(xm1_r**2+p(3,1)**2)
 
1290
        p(0,2)=sqrt(xm2_r**2+p(3,2)**2)
 
1291
        xmcmass(1)=xm1_r
 
1292
        xmcmass(2)=xm2_r
 
1293
      endif
 
1294
c
 
1295
      return
 
1296
      end
 
1297
 
 
1298
 
 
1299
      subroutine getxmss_madfks(shat,ycm,p13cm,xm1,p23cm,xm2,
 
1300
     #                          p13,p23,mfail)
 
1301
c This routine is taken from the MC@NLO package. It is identical
 
1302
c to the routine getxmss() there, except for the fact that here,
 
1303
c by setting donotforce=.true., the partons are left massless if
 
1304
c putting them on the MC mass shell implies that they travel in
 
1305
c the same direction.
 
1306
c NOTE: the convention on the sign of the boost is opposite to that
 
1307
c  used in MC@NLO, hence the different definition of ytmp here
 
1308
c
 
1309
c Original comment in getxmss():
 
1310
c After putting the momenta on shell, the two incoming partons may
 
1311
c travel in the same direction. This routine prevents this to happen,
 
1312
c redefining Monte Carlo masses if necessary
 
1313
      implicit none
 
1314
      real*8 shat,ycm,p13cm,xm1,p23cm,xm2,p13,p23
 
1315
      integer mfail
 
1316
      real*8 tiny,fact,sqs,xm1s,xm2s,xkp2prime_norm2,xkp2prime_norm,
 
1317
     #  ytmp,e1,e2,p13p,p23p,s1p,s2p,xif,sol
 
1318
      integer iflag,idone,ileg
 
1319
      parameter (fact=0.98d0)
 
1320
      parameter (tiny=1.d-6)
 
1321
      logical donotforce
 
1322
      parameter (donotforce=.false.)
 
1323
c
 
1324
      sqs=sqrt(shat)
 
1325
      xm1s=xm1
 
1326
      xm2s=xm2
 
1327
c NOTE: was ytmp=-ycm in MC@NLO owing to different conventions
 
1328
      ytmp=ycm
 
1329
      idone=0
 
1330
 100  continue
 
1331
      xkp2prime_norm2=( shat-2*(xm1**2+xm2**2)+
 
1332
     #                  (xm1**2-xm2**2)**2/shat )/4.d0
 
1333
      xkp2prime_norm=sqrt(xkp2prime_norm2)
 
1334
      if(sign(1.d0,p13cm).ne.1.d0.or.sign(1.d0,p23cm).ne.-1.d0)then
 
1335
        write(*,*)'Error # 0 in getxmss_madfks'
 
1336
        stop
 
1337
      endif
 
1338
      p13=xkp2prime_norm
 
1339
      p23=-xkp2prime_norm
 
1340
      e1=sqrt(p13**2+xm1**2)
 
1341
      e2=sqrt(p23**2+xm2**2)
 
1342
      p13p=p13*cosh(ytmp)-e1*sinh(ytmp)
 
1343
      p23p=p23*cosh(ytmp)-e2*sinh(ytmp)
 
1344
      s1p=sign(1.d0,p13p)
 
1345
      s2p=sign(1.d0,p23p)
 
1346
      iflag=0
 
1347
      if(s1p.eq.1.d0 .and. s2p.eq.-1.d0)then
 
1348
        iflag=1
 
1349
      elseif(s1p.eq.-1.d0 .and. s2p.eq.-1.d0)then
 
1350
        if(ytmp.lt.0.d0)then
 
1351
          write(*,*)'getxmss_madfks: wrong y sign, # 1'
 
1352
          stop
 
1353
        endif
 
1354
        ileg=1
 
1355
        xif=xm2**2/shat
 
1356
      elseif(s1p.eq.1.d0 .and. s2p.eq.1.d0)then
 
1357
        if(ytmp.gt.0.d0)then
 
1358
          write(*,*)'getxmss_madfks: wrong y sign, # 2'
 
1359
          stop
 
1360
        endif
 
1361
        ileg=2
 
1362
        xif=xm1**2/shat
 
1363
      else
 
1364
        write(*,*)'Error # 1 in getxmss_madfks',s1p,s2p
 
1365
        write(*,*)shat,xm1,xm2
 
1366
        write(*,*)p13,e1,p23,e2,ytmp
 
1367
        stop
 
1368
      endif
 
1369
      if(iflag.eq.0.and.(.not.donotforce))then
 
1370
        sol=xif+cosh(2*ytmp)-
 
1371
     #      sqrt(2.d0)*cosh(ytmp)*sqrt(cosh(2*ytmp)-1+2*xif)
 
1372
        if(sol.le.0.d0.or.idone.eq.1)then
 
1373
c The procedure failed; pass the massless event to the Monte Carlo, 
 
1374
c and let the Monte Carlo deal with it
 
1375
          xm1=0.d0
 
1376
          xm2=0.d0
 
1377
          p13=sqs/2.d0
 
1378
          p23=-sqs/2.d0
 
1379
          mfail=1
 
1380
          return
 
1381
        endif
 
1382
        if(ileg.eq.1)then
 
1383
          xm1=fact*sqrt(sol*shat)
 
1384
          if(xm1.gt.xm1s)then
 
1385
            write(*,*)'Mass # 1 too large in getxmss_madfks'
 
1386
            stop
 
1387
          endif
 
1388
        elseif(ileg.eq.2)then
 
1389
          xm2=fact*sqrt(sol*shat)
 
1390
          if(xm2.gt.xm2s)then
 
1391
            write(*,*)'Mass # 2 too large in getxmss_madfks'
 
1392
            stop
 
1393
          endif
 
1394
        else
 
1395
          write(*,*)'Error # 2 in getxmss_madfks'
 
1396
          stop
 
1397
        endif
 
1398
        idone=1
 
1399
        goto 100
 
1400
      endif
 
1401
      mfail=1-iflag
 
1402
      return
 
1403
      end
 
1404
 
 
1405
 
 
1406
      subroutine put_on_MC_mshell_Hevout(p,xmi,xmj,mfail)
 
1407
      implicit none
 
1408
      double precision p(0:3,99),xmi,xmj
 
1409
      integer mfail
 
1410
 
 
1411
      double precision dirbst(1:3),dirpj(1:3)
 
1412
      double precision pipj(0:3),pibst(0:3),pjbst(0:3)
 
1413
 
 
1414
      double precision p1(0:3),p1R(0:3),pipjR(0:3)
 
1415
 
 
1416
      double precision E1o(-1:1),p1o(-1:1),E2o(-1:1),p2o(-1:1)
 
1417
      integer ifail(-1:1)
 
1418
 
 
1419
      integer i,i1vec,i2vec,isol
 
1420
      double precision dot,rho,threedot,Q,Q2,Q0,Qv,xm1,xm2,
 
1421
     # cosphi_pipj,cosphi_p1R,costh_pipj,costh_p1R,projj,proji,
 
1422
     # phi_p1R,phi_pipj,sinth_p1R,sinphi_pipj,sinphi_p1R,sinth_pipj,
 
1423
     # th_p1R,th_pipj
 
1424
      external dot,rho,threedot
 
1425
      include 'nexternal.inc'
 
1426
      integer i_fks,j_fks
 
1427
      common/fks_indices/i_fks,j_fks
 
1428
c
 
1429
      if(j_fks.le.nincoming)then
 
1430
        write(*,*)'put_on_MC_mshell_Hevout must not be called for ISR'
 
1431
        stop
 
1432
      endif
 
1433
c
 
1434
      do i=0,3
 
1435
        pipj(i)=p(i,i_fks)+p(i,j_fks)
 
1436
      enddo
 
1437
      Q2=dot(pipj,pipj)
 
1438
      Q=sqrt(Q2)
 
1439
      if(Q2.lt.(xmi+xmj)**2)then
 
1440
        write(*,*)'Error in put_on_MC_mshell_Hevout',pipj(0),xmi,xmj
 
1441
        stop
 
1442
      endif
 
1443
      Q0=pipj(0)
 
1444
      Qv=rho(pipj)
 
1445
      proji=threedot(pipj,p(0,i_fks))
 
1446
      projj=threedot(pipj,p(0,j_fks))
 
1447
      if(proji.gt.projj)then
 
1448
        i1vec=i_fks
 
1449
        i2vec=j_fks
 
1450
        xm1=xmi
 
1451
        xm2=xmj
 
1452
      else
 
1453
        i1vec=j_fks
 
1454
        i2vec=i_fks
 
1455
        xm1=xmj
 
1456
        xm2=xmi
 
1457
      endif
 
1458
      do i=0,3
 
1459
        p1(i)=p(i,i1vec)
 
1460
      enddo
 
1461
      call getangles(pipj,th_pipj,costh_pipj,sinth_pipj,
 
1462
     #                    phi_pipj,cosphi_pipj,sinphi_pipj)
 
1463
      call trp_rotate_invar(pipj,pipjR,
 
1464
     #                      costh_pipj,sinth_pipj,
 
1465
     #                      cosphi_pipj,sinphi_pipj)
 
1466
      if( abs(pipjR(0)-Q0).gt.max(Q0,1.d0)*1.d-8 .or.
 
1467
     #    abs(pipjR(3)-Qv).gt.max(Qv,1.d0)*1.d-8 )then
 
1468
        write(*,*)'Error #1 in put_on_MC_mshell_Hevout',pipj,Q0,Qv
 
1469
        stop
 
1470
      endif
 
1471
      call trp_rotate_invar(p1,p1R,
 
1472
     #                      costh_pipj,sinth_pipj,
 
1473
     #                      cosphi_pipj,sinphi_pipj)
 
1474
      call getangles(p1R,th_p1R,costh_p1R,sinth_p1R,
 
1475
     #                   phi_p1R,cosphi_p1R,sinphi_p1R)
 
1476
      call xkin_2body(Q0,Qv,xm1,xm2,costh_p1R,E1o,p1o,E2o,p2o,ifail)
 
1477
      if(ifail(1).eq.1.and.ifail(-1).eq.1)then
 
1478
        mfail=1
 
1479
        return
 
1480
      elseif(ifail(1).eq.1.and.ifail(-1).eq.0)then
 
1481
        isol=-1
 
1482
      elseif(ifail(1).eq.0.and.ifail(-1).eq.1)then
 
1483
        isol=1
 
1484
      else
 
1485
        if(abs(p1R(0)-E1o(1)).lt.abs(p1R(0)-E1o(-1)))then
 
1486
          isol=1
 
1487
        else
 
1488
          isol=-1
 
1489
        endif
 
1490
      endif
 
1491
      p1R(0)=E1o(isol)
 
1492
      p1R(1)=0.d0
 
1493
      p1R(2)=0.d0
 
1494
      p1R(3)=p1o(isol)
 
1495
c
 
1496
      call rotate_invar(p1R,p1,
 
1497
     #                  costh_p1R,sinth_p1R,
 
1498
     #                  cosphi_p1R,sinphi_p1R)
 
1499
      call rotate_invar(p1,p1,
 
1500
     #                  costh_pipj,sinth_pipj,
 
1501
     #                  cosphi_pipj,sinphi_pipj)
 
1502
      do i=0,3
 
1503
        p(i,i1vec)=p1(i)
 
1504
        p(i,i2vec)=pipj(i)-p1(i)
 
1505
      enddo
 
1506
      mfail=0
 
1507
c
 
1508
      return
 
1509
      end
 
1510
 
 
1511
 
 
1512
      subroutine xkin_2body(Q0,Qv,xm1,xm2,cth1,E1,p1,E2,p2,ifail)
 
1513
c Returns energies and moduli of 3-momenta of the two final-state particles
 
1514
c in a two-body phase space, in a frame where the incoming momentum has
 
1515
c energy equal to Q0 and modulus of 3-momentum equal to Qv.
 
1516
c cth1 is the cosine of the angle between \vec{Q} and \vec{p1}
 
1517
c
 
1518
c There are two possible solutions, returned in arrays E*(#) and p*(#)
 
1519
c with #=-1,1. If a given solution is acceptable, ifail(#)=0, 
 
1520
c and ifail(#)=1 otherwise
 
1521
      implicit none
 
1522
      double precision Q0,Qv,xm1,xm2,cth1
 
1523
      double precision E1(-1:1),p1(-1:1),E2(-1:1),p2(-1:1)
 
1524
      integer ifail(-1:1)
 
1525
      double precision Q02,Qv2,delta,den,arg,xA,xB
 
1526
      integer i
 
1527
c
 
1528
      ifail( 1)=0
 
1529
      ifail(-1)=0
 
1530
      Q02=Q0**2
 
1531
      Qv2=Qv**2
 
1532
      delta=(Q02-Qv2)+xm1**2-xm2**2
 
1533
      den=Q02-Qv2*cth1**2
 
1534
      arg=delta**2-4*xm1**2*den
 
1535
      if(arg.lt.0.d0)then
 
1536
        ifail( 1)=1
 
1537
        ifail(-1)=1
 
1538
        return
 
1539
      endif
 
1540
      xA=Q0*delta/(2*den)
 
1541
      xB=Qv*abs(cth1)*sqrt(arg)/(2*den)
 
1542
      E1( 1)=xA+xB
 
1543
      E1(-1)=xA-xB
 
1544
      if(cth1.gt.0.d0)then
 
1545
        if( (delta-2*Q0*E1( 1)).gt.0.d0 )ifail( 1)=1
 
1546
        if( (delta-2*Q0*E1(-1)).gt.0.d0 )ifail(-1)=1
 
1547
      elseif(cth1.gt.0.d0)then
 
1548
        if( (delta-2*Q0*E1( 1)).lt.0.d0 )ifail( 1)=1
 
1549
        if( (delta-2*Q0*E1(-1)).lt.0.d0 )ifail(-1)=1
 
1550
      endif
 
1551
      if(ifail(1).eq.1.and.ifail(-1).eq.1)return
 
1552
c
 
1553
      do i=-1,1
 
1554
        if(i.eq.0)goto 111
 
1555
        if(E1(i).lt.xm1)then
 
1556
          ifail(i)=1
 
1557
          goto 111
 
1558
        endif
 
1559
        p1(i)=E1(i)**2-xm1**2
 
1560
        if(p1(i).lt.0.d0)then
 
1561
          ifail(i)=1
 
1562
          goto 111
 
1563
        endif
 
1564
        p1(i)=sqrt(p1(i))
 
1565
c
 
1566
        E2(i)=Q0-E1(i)
 
1567
        if(E2(i).lt.xm2)then
 
1568
          ifail(i)=1
 
1569
          goto 111
 
1570
        endif
 
1571
        p2(i)=E2(i)**2-xm2**2
 
1572
        if(p2(i).lt.0.d0)then
 
1573
          ifail(i)=1
 
1574
          goto 111
 
1575
        endif
 
1576
        p2(i)=sqrt(p2(i))
 
1577
 111    continue
 
1578
      enddo
 
1579
c
 
1580
      return
 
1581
      end
 
1582
 
 
1583
 
 
1584
      subroutine put_on_MC_mshell_Hevin(p,xmi,xm1,xm2,mfail)
 
1585
      implicit none
 
1586
      double precision p(0:3,99),xmi,xm1,xm2
 
1587
      integer mfail
 
1588
      include 'run.inc'
 
1589
      include 'nexternal.inc'
 
1590
      double precision chy,shy,chymo,shatp,q0,stot,xm1_r,xm2_r,
 
1591
     # ybst_cm_tolab
 
1592
      double precision p1(0:3),p2(0:3),xk(0:3)
 
1593
      integer i 
 
1594
 
 
1595
      integer i_fks,j_fks
 
1596
      common/fks_indices/i_fks,j_fks
 
1597
 
 
1598
      double precision ybst_til_tolab,ybst_til_tocm,sqrtshat,shat
 
1599
      common/parton_cms_stuff/ybst_til_tolab,ybst_til_tocm,
 
1600
     #                        sqrtshat,shat
 
1601
 
 
1602
      double precision xmcmass(nexternal)
 
1603
      common/cxmcmass/xmcmass
 
1604
 
 
1605
      double precision zaxis(1:3)
 
1606
      data zaxis/0,0,1/
 
1607
 
 
1608
      double precision rho
 
1609
      external rho
 
1610
c
 
1611
      if(j_fks.gt.nincoming)then
 
1612
        write(*,*)'put_on_MC_mshell_Hevin must not be called for FSR'
 
1613
        stop
 
1614
      endif
 
1615
c
 
1616
      stot=4d0*ebeam(1)*ebeam(2)
 
1617
      chy=cosh(ybst_til_tocm)
 
1618
      shy=sinh(ybst_til_tocm)
 
1619
      chymo=chy-1.d0
 
1620
      do i=0,3
 
1621
        p1(i)=p(i,1)
 
1622
        p2(i)=p(i,2)
 
1623
        xk(i)=p(i,i_fks)
 
1624
      enddo
 
1625
c        write(*,*) 'p1:',(p1(i),i=0,3)
 
1626
c        write(*,*) 'p2:',(p2(i),i=0,3)
 
1627
c        write(*,*) 'xk:',(xk(i),i=0,3)
 
1628
      call boostwdir2(chy,shy,chymo,zaxis,p1,p1)
 
1629
      call boostwdir2(chy,shy,chymo,zaxis,p2,p2)
 
1630
      call boostwdir2(chy,shy,chymo,zaxis,xk,xk)
 
1631
      if(abs(p1(3)+p2(3)).gt.1.d-6)then
 
1632
        write(*,*)'Error #1 in put_on_MC_mshell_Hevin',p1(3),p2(3)
 
1633
        write(*,*) 'p1:',(p1(i),i=0,3)
 
1634
        write(*,*) 'p2:',(p2(i),i=0,3)
 
1635
        write(*,*) 'xk:',(xk(i),i=0,3)
 
1636
        stop
 
1637
      endif
 
1638
      q0=p1(0)+p2(0)-xk(0)
 
1639
      xk(0)=sqrt(xmi**2+rho(xk)**2)
 
1640
      shatp=(q0+xk(0))**2
 
1641
      if(shatp.lt.shat*0.9999d0)then
 
1642
        write(*,*)'Error #2 in put_on_MC_mshell_Hevin',shat,shatp
 
1643
        stop
 
1644
      elseif(shatp.le.shat)then
 
1645
        shatp=shat
 
1646
      endif
 
1647
      if(shatp.ge.stot)then
 
1648
        mfail=1
 
1649
        return
 
1650
      endif
 
1651
      ybst_cm_tolab=ybst_til_tolab-ybst_til_tocm
 
1652
      xm1_r=xm1
 
1653
      xm2_r=xm2
 
1654
      call getxmss_madfks(shatp,ybst_cm_tolab,
 
1655
     #                    p1(3),xm1_r,p2(3),xm2_r,
 
1656
     #                    p1(3),p2(3),mfail)
 
1657
      if(mfail.eq.1)return
 
1658
      p1(0)=sqrt(xm1_r**2+p1(3)**2)
 
1659
      p2(0)=sqrt(xm2_r**2+p2(3)**2)
 
1660
      xmcmass(1)=xm1_r
 
1661
      xmcmass(2)=xm2_r
 
1662
      call boostwdir2(chy,-shy,chymo,zaxis,p1,p1)
 
1663
      call boostwdir2(chy,-shy,chymo,zaxis,p2,p2)
 
1664
      call boostwdir2(chy,-shy,chymo,zaxis,xk,xk)
 
1665
      do i=0,3
 
1666
        p(i,1)=p1(i)
 
1667
        p(i,2)=p2(i)
 
1668
        p(i,i_fks)=xk(i)
 
1669
      enddo
 
1670
c
 
1671
      return
 
1672
      end
 
1673
 
 
1674
 
 
1675
      subroutine put_on_MG_mshell()
 
1676
c Puts particles back on the MadGraph mass shell
 
1677
      implicit none
 
1678
      include 'nexternal.inc'
 
1679
      integer i
 
1680
      double precision zero
 
1681
      parameter (zero=0.d0)
 
1682
c Masses to be given to genps_fks.f
 
1683
      double precision emass(nexternal)
 
1684
      common/to_mass/  emass
 
1685
c Masses of the real process, as set by MadGraph
 
1686
      include 'coupl.inc'
 
1687
      double precision pmass(nexternal)
 
1688
      include 'pmass.inc'
 
1689
c
 
1690
      do i=1,nexternal
 
1691
        emass(i)=pmass(i)
 
1692
      enddo
 
1693
c
 
1694
      return
 
1695
      end
 
1696
 
 
1697
 
 
1698
      subroutine write_masses_lhe_MG()
 
1699
c Set masses used by MC equal to MG ones
 
1700
      implicit none
 
1701
      include 'nexternal.inc'
 
1702
      double precision xmcmass(nexternal)
 
1703
      common/cxmcmass/xmcmass
 
1704
      integer i
 
1705
 
 
1706
      double precision zero
 
1707
      parameter       (ZERO = 0d0)
 
1708
      include 'coupl.inc'
 
1709
      double precision pmass(nexternal)
 
1710
      include 'pmass.inc'
 
1711
c
 
1712
      do i=1,nexternal
 
1713
        xmcmass(i)=pmass(i)
 
1714
      enddo
 
1715
c
 
1716
      return
 
1717
      end
 
1718
 
 
1719
 
 
1720
      subroutine get3space(pin,xlength,xdir)
 
1721
      implicit none
 
1722
      real*8 pin(0:3),xlength,xdir(1:3)
 
1723
      integer i
 
1724
c
 
1725
      xlength=pin(1)**2+pin(2)**2+pin(3)**2
 
1726
      if(xlength.eq.0)then
 
1727
        xdir(1)=0.d0
 
1728
        xdir(2)=0.d0
 
1729
        xdir(3)=1.d0
 
1730
      else
 
1731
        xlength=sqrt(xlength)
 
1732
        do i=1,3
 
1733
          xdir(i)=pin(i)/xlength
 
1734
        enddo
 
1735
      endif
 
1736
      return
 
1737
      end
 
1738
 
 
1739
 
 
1740
      subroutine put_on_MC_mshell_Hevout_old(p,xmi,xmj)
 
1741
      implicit none
 
1742
      double precision p(0:3,99),xmi,xmj
 
1743
      double precision dirbst(1:3),dirpj(1:3)
 
1744
      double precision pipj(0:3),pibst(0:3),pjbst(0:3)
 
1745
 
 
1746
      integer i
 
1747
      double precision dot,Q2,Q,expy,chybst,shybst,chybstmo,tmp,
 
1748
     # Emo,xpmo,pij,xmi2,xmj2
 
1749
      external dot
 
1750
 
 
1751
      include 'nexternal.inc'
 
1752
 
 
1753
      integer i_fks,j_fks
 
1754
      common/fks_indices/i_fks,j_fks
 
1755
c
 
1756
      do i=0,3
 
1757
        pipj(i)=p(i,i_fks)+p(i,j_fks)
 
1758
      enddo
 
1759
      Q2=dot(pipj,pipj)
 
1760
      Q=sqrt(Q2)
 
1761
      if(Q2.lt.(xmi+xmj)**2)then
 
1762
        write(*,*)'Error in put_on_MC_mshell_Hevout',Emo,xmi,xmj
 
1763
        stop
 
1764
      endif
 
1765
      Emo=pipj(0)
 
1766
      call get3space(pipj,xpmo,dirbst)
 
1767
      expy=sqrt((Emo+xpmo)/(Emo-xpmo))
 
1768
      chybst=0.5d0*(expy+1.d0/expy)
 
1769
      shybst=0.5d0*(expy-1.d0/expy)
 
1770
      chybstmo=chybst-1.d0
 
1771
      call boostwdir2(chybst,shybst,chybstmo,dirbst,p(0,j_fks),pjbst)
 
1772
      call boostwdir2(chybst,shybst,chybstmo,dirbst,p(0,i_fks),pibst)
 
1773
      call get3space(pjbst,tmp,dirpj)
 
1774
      if(tmp.eq.0.d0)then
 
1775
        write(*,*)'Parton j soft in put_on_MC_mshell_Hevout'
 
1776
        stop
 
1777
      endif
 
1778
c
 
1779
      xmj2=xmj**2
 
1780
      xmi2=xmi**2
 
1781
      pjbst(0)=Q/2.d0*(1+(xmj2-xmi2)/Q2)            
 
1782
      pibst(0)=Q/2.d0*(1-(xmj2-xmi2)/Q2)            
 
1783
      pij=Q2**2-2*Q2*(xmi2+xmj2)+(xmi2-xmj2)**2
 
1784
      pij=1/2.d0*sqrt( pij/Q2 )
 
1785
      do i=1,3
 
1786
        pjbst(i)= dirpj(i) * pij
 
1787
        pibst(i)=-dirpj(i) * pij
 
1788
      enddo
 
1789
c
 
1790
      call boostwdir2(chybst,-shybst,chybstmo,dirbst,pibst,p(0,i_fks))
 
1791
      call boostwdir2(chybst,-shybst,chybstmo,dirbst,pjbst,p(0,j_fks))
 
1792
c
 
1793
      if(j_fks.le.nincoming)then
 
1794
        write(*,*)'ISR not yet implemented in put_on_MC_mshell_Hevout'
 
1795
        stop
 
1796
      endif
 
1797
c
 
1798
      return
 
1799
      end