1
subroutine Zoom_Event(wgt,p)
2
C**************************************************************************
3
C Determines if region needs to be investigated in case of large
5
C**************************************************************************
11
parameter (max_zoom=2000)
13
include 'nexternal.inc'
18
double precision wgt, p(0:3,nexternal)
22
double precision xstore(2),gstore,qstore(2)
23
double precision trunc_wgt, xsum, wstore,pstore(0:3,nexternal)
29
double precision twgt, maxwgt,swgt(maxevents)
30
integer lun, nw, itmin
31
common/to_unwgt/twgt, maxwgt, swgt, lun, nw, itmin
33
double precision tx(1:3,maxinvar)
34
common/to_xpoints/tx, nzoom
35
double precision xzoomfact
36
common/to_zoom/ xzoomfact
45
save ix, pstore, wstore, xstore, gstore, qstore
49
if (trunc_Wgt .lt. 0d0 .and. twgt .gt. 0d0) then
50
write(*,*) 'Selecting zoom level', twgt*500, wgt
52
if (twgt .lt. 0d0) then
53
write(*,*) 'Resetting zoom iteration', twgt
55
trunc_wgt = twgt * 500d0
58
trunc_wgt = twgt * 500d0
60
trunc_wgt=max(trunc_wgt, twgt*500d0)
61
if (nzoom .eq. 0 .and. trunc_wgt .gt. 0d0 ) then
62
if (wgt .gt. trunc_wgt) then
63
write(*,*) 'Zooming on large event ',wgt / trunc_wgt
80
elseif (trunc_wgt .gt. 0 .and. wgt .gt. 0d0) then
82
if (nzoom .gt. 1) wgt = 0d0
85
if (xsum .ne. 0d0 .and. nzoom .le. 1) then
86
if (wgt .gt. 0d0) then
87
c xzoomfact = xsum/real(max_zoom) / wgt !Store avg wgt
88
xzoomfact = wstore / wgt !Store large wgt
90
xzoomfact = -xsum/real(max_zoom)
92
wgt = max(xsum/real(max_zoom),trunc_wgt) !Don't make smaller then truncated wgt
103
write(*,'(a,2e15.3,2f15.3, i8)') 'Stored wgt ',
104
$ wgt/trunc_wgt, wstore, wstore/wgt, real(ix)/max_zoom, ix
105
trunc_wgt = max(trunc_wgt, wgt)
111
subroutine clear_events
112
c-------------------------------------------------------------------
113
c delete all events thus far, start from scratch
114
c------------------------------------------------------------------
120
include 'nexternal.inc'
124
integer iseed, nover, nstore
128
double precision twgt, maxwgt,swgt(maxevents)
129
integer lun, nw, itmin
130
common/to_unwgt/twgt, maxwgt, swgt, lun, nw, itmin
135
c write(*,*) 'storing Events'
142
SUBROUTINE unwgt(px,wgt,numproc)
143
C**************************************************************************
144
C Determines if event should be written based on its weight
145
C**************************************************************************
151
include 'nexternal.inc'
155
double precision px(0:3,nexternal),wgt
161
double precision uwgt,yran,fudge, p(0:3,nexternal), xwgt
165
double precision twgt, maxwgt,swgt(maxevents)
166
integer lun, nw, itmin
167
common/to_unwgt/twgt, maxwgt, swgt, lun, nw, itmin
169
double precision matrix
170
common/to_maxmatrix/matrix
173
common /to_zoomchoice/zooming
189
if (twgt .ge. 0d0) then
196
if (zooming) call zoom_event(xwgt,P)
197
if (xwgt .eq. 0d0) return
199
if (xwgt .gt. twgt*fudge*yran) then
200
uwgt = max(xwgt,twgt*fudge)
201
c Set sign of uwgt to sign of wgt
202
uwgt = dsign(uwgt,wgt)
203
if (twgt .gt. 0) uwgt=uwgt/twgt/fudge
204
c call write_event(p,uwgt)
205
c write(29,'(2e15.5)') matrix,wgt
206
c $B$ S-COMMENT_C $B$
207
call write_leshouche(p,uwgt,numproc)
208
elseif (xwgt .gt. 0d0 .and. nw .lt. 5) then
209
call write_leshouche(p,wgt/twgt*1d-6,numproc)
210
c $E$ S-COMMENT_C $E$
212
maxwgt=max(maxwgt,xwgt)
216
subroutine store_events()
217
C**************************************************************************
218
C Takes events from scratch file (lun) and writes them to a permanent
220
C**************************************************************************
226
include 'nexternal.inc'
227
double precision trunc_max
228
parameter (trunc_max = 0.01) !Maximum % cross section to truncate
235
integer i, lunw, ic(7,2*nexternal-3), n, j
237
double precision wgt,p(0:4,2*nexternal-3)
238
double precision xsec,xsecabs,xerr,xscale,xtot
239
double precision xsum, xover
240
double precision target_wgt,orig_Wgt(maxevents)
241
logical store_event(maxevents)
242
integer iseed, nover, nstore
243
double precision scale,aqcd,aqed
249
double precision twgt, maxwgt,swgt(maxevents)
250
integer lun, nw, itmin
251
common/to_unwgt/twgt, maxwgt, swgt, lun, nw, itmin
253
integer neventswritten
254
common /to_eventswritten/ neventswritten
255
c save neventswritten
258
common/to_group/ngroup
266
data neventswritten/0/
271
c First scale all of the events to the total cross section
273
if (nw .le. 0) return
274
call sample_result(xsecabs,xsec,xerr,itmin)
275
if (xsecabs .le. 0) return !Fix by TS 12/3/2010
279
xtot=xtot+dabs(swgt(i))
282
c Determine minimum target weight given truncation parameter
286
do while (xsum-dabs(swgt(i))*(nw-i) .lt. xtot*trunc_max .and. i .gt. 2)
287
xsum = xsum + dabs(swgt(i))
291
target_wgt = dabs(swgt(i))
293
c Select events which will be written
301
call read_event(lun,P,wgt,n,ic,ievent,scale,aqcd,aqed,buff,done)
305
if (dabs(wgt) .gt. target_wgt*xran1(iseed)) then
306
xsum=xsum+max(dabs(wgt),target_Wgt)
307
store_event(i)=.true.
310
store_event(i) = .false.
313
xscale = xsecabs/xsum
314
target_wgt = target_wgt*xscale
316
c JA 8/17/2011 Don't check for previously stored events
317
c if (nstore .le. neventswritten) then
318
c write(*,*) 'No improvement in events',nstore, neventswritten
322
open(unit = lunw, file='events.lhe', status='unknown')
330
call read_event(lun,P,wgt,n,ic,ievent,scale,aqcd,aqed,buff,done)
332
write(*,*) 'Error done early',j,nw
334
if (store_event(j) .and. .not. done) then
336
wgt = dsign(max(dabs(wgt), target_wgt),wgt)
337
if (dabs(wgt) .gt. target_wgt) then
338
xover = xover + dabs(wgt) - target_wgt
341
xtot = xtot + dabs(wgt)
343
call write_Event(lunw,p,wgt,n,ic,ngroup,scale,aqcd,aqed,buff)
346
write(*,*) 'Found ',nw,' events.'
347
write(*,*) 'Wrote ',i ,' events.'
348
write(*,*) 'Actual xsec ',xsec
349
write(*,*) 'Correct abs xsec ',xsecabs
350
write(*,*) 'Event xsec ', xtot
351
write(*,*) 'Events wgts > 1: ', nover
352
write(*,*) '% Cross section > 1: ',xover, xover/xtot*100.
358
SUBROUTINE write_leshouche(p,wgt,numproc)
359
C**************************************************************************
360
C Writes out information for event
361
C**************************************************************************
366
double precision zero
367
parameter (ZERO = 0d0)
369
include 'nexternal.inc'
370
include 'maxamps.inc'
371
include 'message.inc'
372
include 'cluster.inc'
377
double precision p(0:3,nexternal),wgt
383
double precision xtarget,targetamp(maxflow)
384
integer ic, nc, jpart(7,-nexternal+3:2*nexternal-3)
385
integer ida(2),ito(-nexternal+3:nexternal),ns,nres,ires,icloop
387
double precision pboost(0:3),pb(0:4,-nexternal+3:2*nexternal-3),eta
388
double precision ptcltmp(nexternal), pdum(0:3)
390
integer idup(nexternal,maxproc,maxsproc)
391
integer mothup(2,nexternal)
392
integer icolup(2,nexternal,maxflow,maxsproc)
394
integer isym(nexternal,99), nsym, jsym
396
double precision sscale,aaqcd,aaqed
408
double precision twgt, maxwgt,swgt(maxevents)
409
integer lun, nw, itmin
410
common/to_unwgt/twgt, maxwgt, swgt, lun, nw, itmin
413
COMMON /SubProc/ IPSEL
415
Double Precision amp2(maxamps), jamp2(0:maxflow)
416
common/to_amps/ amp2, jamp2
418
character*101 hel_buf
419
common/to_helicity/hel_buf
421
integer mincfig, maxcfig
422
common/to_configs/mincfig, maxcfig
425
common/to_group/ngroup
427
double precision stot,m1,m2
428
common/to_stot/stot,m1,m2
432
include 'leshouche.inc'
435
double precision pmass(nexternal)
436
common/to_mass/ pmass
438
c integer ncols,ncolflow(maxamps),ncolalt(maxamps)
439
c common/to_colstats/ncols,ncolflow,ncolalt,ic
440
c data ncolflow/maxamps*0/
441
c data ncolalt/maxamps*0/
443
include 'symswap.inc'
449
if (nw .ge. maxevents) return
451
c Store weight for event
455
c In case of identical particles symmetry, choose assignment
457
xtarget = ran1(iseed)*nsym
459
do while (xtarget .gt. jsym .and. jsym .lt. nsym)
463
c Fill jpart color and particle info
466
jpart(1,isym(i,jsym)) = idup(i,ipsel,numproc)
467
jpart(2,isym(i,jsym)) = mothup(1,i)
468
jpart(3,isym(i,jsym)) = mothup(2,i)
469
c Color info is filled in mothup
470
jpart(4,isym(i,jsym)) = 0
471
jpart(5,isym(i,jsym)) = 0
472
jpart(6,isym(i,jsym)) = 1
475
jpart(6,isym(i,jsym))=-1
479
c write(*,*) 'Getting helicity',hel_buf(1:50)
480
read(hel_buf,'(20i5)') (jpart(7,isym(i, jsym)),i=1,nexternal)
481
c write(*,*) 'ihel',jpart(7,1),jpart(7,2)
483
c Fix ordering of ptclus
485
ptcltmp(isym(i,jsym)) = ptclus(i)
488
ptclus(i) = ptcltmp(i)
491
c Check if we have flipped particle 1 and 2, and flip back
493
if (p(3,1).lt.0) then
503
c Boost momentum to lab frame
509
if (nincoming.eq.2) then
510
if (xbk(1) .gt. 0d0 .and. xbk(1) .lt. 1d0 .and.
511
$ xbk(2) .gt. 0d0 .and. xbk(2) .lt. 1d0) then
512
eta = sqrt(xbk(1)*ebeam(1)/
514
pboost(0)=p(0,1)*(eta + 1d0/eta)
515
pboost(3)=p(0,1)*(eta - 1d0/eta)
516
else if (xbk(1) .gt. 0d0 .and. xbk(1) .lt. 1d0 .and.
517
$ xbk(2) .eq. 1d0) then
518
pboost(0)=xbk(1)*ebeam(1)+ebeam(2)
519
pboost(3)=xbk(1)*ebeam(1)-
520
$ sqrt(ebeam(2)**2-m2**2)
521
else if (xbk(1) .eq. 1d0 .and.
522
$ xbk(2) .gt. 0d0 .and. xbk(2) .lt. 1d0) then
523
pboost(0)=ebeam(1)+xbk(2)*ebeam(2)
524
pboost(3)=sqrt(ebeam(1)**2-m1**2)-
526
else if (xbk(1) .eq. 1d0 .and. xbk(2) .eq. 1d0) then
527
pboost(0)=ebeam(1)+ebeam(2)
528
pboost(3)=sqrt(ebeam(1)**2-m1**2)-
529
$ sqrt(ebeam(2)**2-m2**2)
531
write(*,*) 'Warning bad x1 or x2 in write_leshouche',
536
call boostx(p(0,j),pboost,pb(0,isym(j,jsym)))
537
c Add mass information in pb(4)
538
pb(4,isym(j,jsym))=pmass(j)
542
c Add info on resonant mothers
544
call addmothers(ipsel,jpart,pb,isym,jsym,sscale,aaqcd,aaqed,buff,
547
c Need to flip after addmothers, since color might get overwritten
551
jpart(i,1)=jpart(i,2)
560
c Write events to lun
562
c write(*,*) 'Writing event'
563
if(q2fact(1).gt.0.and.q2fact(2).gt.0)then
564
sscale = sqrt(max(q2fact(1),q2fact(2)))
565
else if(q2fact(1).gt.0)then
566
sscale = sqrt(q2fact(1))
567
else if(q2fact(2).gt.0)then
568
sscale = sqrt(q2fact(2))
572
aaqcd = g*g/4d0/3.1415926d0
573
aaqed = gal(1)*gal(1)/4d0/3.1415926d0
575
if (btest(mlevel,3)) then
576
write(*,*)' write_leshouche: SCALUP to: ',sscale
580
call write_event(lun,pb(0,1),wgt,npart,jpart(1,1),ngroup,
581
& sscale,aaqcd,aaqed,buff)
583
& call write_event(6,pb(0,1),wgt,npart,jpart(1,1),ngroup,
584
& sscale,aaqcd,aaqed,buff)
588
integer function n_unwgted()
589
c************************************************************************
590
c Determines the number of unweighted events which have been written
591
c************************************************************************
597
include 'nexternal.inc'
602
double precision xtot, sum
606
double precision twgt, maxwgt,swgt(maxevents)
607
integer lun, nw, itmin
608
common/to_unwgt/twgt, maxwgt, swgt, lun, nw, itmin
613
c write(*,*) 'Sorting ',nw
614
if (nw .gt. 1) call dsort(nw,swgt)
621
do while (xtot .lt. sum/100d0 .and. i .gt. 2) !Allow for 1% accuracy
622
xtot = xtot + swgt(i)
625
if (i .lt. nw) i = i+1
626
c write(*,*) 'Found ',nw,' events'
627
c write(*,*) 'Integrated weight',sum
628
c write(*,*) 'Maximum wgt',swgt(nw), swgt(i)
629
c write(*,*) 'Average wgt', sum/nw
630
c write(*,*) 'Unweight Efficiency', (sum/nw)/swgt(i)
631
n_unwgted = sum/swgt(i)
632
c write(*,*) 'Number unweighted ',sum/swgt(i), nw
633
if (nw .ge. maxevents) n_unwgted = -sum/swgt(i)
637
subroutine dsort(n,ra)
639
double precision ra(n),rra
660
if(dabs(ra(j)).lt.dabs(ra(j+1))) j=j+1
662
if(dabs(rra).lt.dabs(ra(j)))then