1
subroutine sample_full(ndim,ncall,itmax,dsig,ninvar,nconfigs)
2
c**************************************************************************
3
c Driver for sample which does complete integration
4
c This is done in double precision, and should be told the
5
c number of possible phasespace choices.
7
c ndim Number of dimensions for integral(number or random #'s/point)
8
c ncall Number of times to evaluate the function/iteration
9
c itmax Number of iterations
10
c ninvar Number of invarients to keep grids on (s,t,u, s',t' etc)
11
c nconfigs Number of different pole configurations
12
c dsig Function to be integrated
13
c**************************************************************************
19
integer ndim,ncall,itmax,ninvar,nconfigs
25
double precision x(maxinvar),wgt,p(4*maxdim/3+14)
26
double precision tdem, chi2
27
integer ievent,kevent,nwrite,iter,nun
28
integer jmax,i,j,ipole
39
character*40 result_file,where_file
40
common /sample_status/result_file,where_file,nsteps
44
integer mincfig, maxcfig
45
common/to_configs/mincfig, maxcfig
47
double precision xmean(99),xsigma(99),xwmax(99),xeff(99)
48
common/to_iterations/xmean, xsigma, xwmax, xeff
50
double precision accur
51
common /to_accuracy/accur
53
double precision twgt, maxwgt,swgt(maxevents)
55
common/to_unwgt/twgt, maxwgt, swgt, lun, nw
58
double precision tx(1:3,maxinvar)
59
common/to_xpoints/tx, nzoom
61
double precision xzoomfact
62
common/to_zoom/ xzoomfact
64
double precision tmean, tsigma
65
integer dim, events, itm, kn, cur_it, invar, configs
66
common /sample_common/
67
. tmean, tsigma, dim, events, itm, kn, cur_it, invar, configs
70
common /to_weight/use_cut
73
common/to_correlated/icor
75
integer neventswritten
76
common /to_eventswritten/ neventswritten
85
data result_file,where_file,nsteps/'SAMPLE','WHERE.AMI',100/
89
data twgt/-1d0/ !Dont write out events
90
data lun/27/ !Unit number for events
92
data nw/0/ !Number of events written
102
if (nsteps .lt. 1) nsteps=1
103
nwrite = itmax*ncall/nsteps
104
c open(unit=66,file='.sample_warn',status='unknown')
105
c write(66,*) 'Warnings from sample run.',itmax,ncall
107
call sample_init(ndim,ncall,itmax,ninvar,nconfigs)
117
c Main Integration Loop
120
do while(iter .le. itmax)
122
c Get integration point
124
call sample_get_config(wgt,iter,ipole)
125
if (iter .le. itmax) then
127
call x_to_f_arg(ndim,ipole,mincfig,maxcfig,ninvar,wgt,x,p)
128
if (pass_point(p)) then
130
fx = dsig(p,wgt) !Evaluate function
131
if (xzoomfact .gt. 0d0) then
132
wgt = wgt*fx*xzoomfact
136
if (wgt .gt. 0d0) call graph_point(p,wgt) !Update graphs
141
if (nzoom .le. 0) then
142
call sample_put_point(wgt,x(1),iter,ipole) !Store result
148
if (wgt .gt. 0d0) kevent=kevent+1
150
c Write out progress/histograms
152
if (kevent .ge. nwrite) then
153
nwrite = nwrite+ncall*itmax/nsteps
154
nwrite = min(nwrite,ncall*itmax)
161
open(unit=66,file='results.dat',status='unknown')
163
do while(xmean(i) .ne. 0 .and. i .lt. cur_it)
172
do while (xmean(i) .ne. 0 .and. i .lt. cur_it)
173
tmean = tmean+xmean(i)*xmean(i)**2/xsigma(i)**2
174
tdem = tdem+xmean(i)**2/xsigma(i)**2
175
tsigma = tsigma + xmean(i)**2/ xsigma(i)**2
179
tsigma= tmean/sqrt(tsigma)
185
do i = cur_it-3,cur_it-1
186
chi2 = chi2+(xmean(i)-tmean)**2/xsigma(i)**2
188
chi2 = chi2/2d0 !Since using only last 3, n-1=2
189
write(*,'(a)') '-----------------------------------------------------'
190
write(*,'(a)') '---------------------------'
191
write(*,'(a,e12.4)') ' Results Last 3 iters: Integral = ',tmean
192
write(*,'(25x,a,e12.4)') 'Std dev = ',tsigma
193
write(*,'(17x,a,f12.4)') 'Chi**2 per DoF. =',chi2
194
write(*,'(a)') '-----------------------------------------------------'
195
write(*,'(a)') '---------------------------'
197
if (nun .lt. 0) nun=-nun !Case when wrote maximun number allowed
198
if (chi2 .gt. 1) tsigma=tsigma*sqrt(chi2)
199
if (icor .eq. 0) then
200
write(66,'(3e12.5,2i9,i5,i9,e10.3)')tmean,tsigma,0.0,kevent,nw,
201
& cur_it-1,nun, nun/max(tmean,1d-99)
203
write(66,'(3e12.5,2i9,i5,i9,e10.3)')tmean,0.0,tsigma,kevent,nw,
204
& cur_it-1,nun, nun/max(tmean,1d-99)
207
do i=cur_it-3,cur_it-1
208
write(66,'(i4,4e15.5)') i,xmean(i),xsigma(i),xeff(i),xwmax(i)
212
open(unit=66,file='results.dat',status='unknown')
213
write(66,'(3e12.5,2i9,i5,i9,e10.3)')0,0,0.0,kevent,nw,
215
write(66,'(i4,4e15.5)') 1,0,0,0,0
220
c Now let's check to see if we got all of the events we needed
221
c if not, will give it another try with 5 iterations to set
222
c the grid, and 4 more to try and get the appropriate number of
225
write(*,*) "Status",accur, cur_it, itmax
226
if (accur .ge. 0d0 .or. cur_it .gt. itmax+3) return
228
if (neventswritten .gt. -accur) then
229
write(*,*) "We found enough events",neventswritten, -accur*1000*tmean
234
c Need to start from scratch. This is clunky but I'll just
235
c remove the grid, so we are clean
237
write(*,*) "Trying w/ fresh grid"
238
open(unit=25,file='ftn25',status='unknown',err=102)
243
c First few iterations will allow the grid to adjust
253
ncall = ncall*4 ! / 2**(itmax-2)
254
write(*,*) "Starting w/ ncall = ", ncall
256
call sample_init(ndim,ncall,itmax,ninvar,nconfigs)
265
c Main Integration Loop
270
use_cut = 2 !Start adjusting grid
271
do while(iter .le. itmax)
272
if (iter .gt. itmax_adjust .and. use_cut .ne. 0) then
274
write(*,*) 'Fixing grid'
277
c Get integration point
279
call sample_get_config(wgt,iter,ipole)
280
if (iter .le. itmax) then
282
call x_to_f_arg(ndim,ipole,mincfig,maxcfig,ninvar,wgt,x,p)
283
if (pass_point(p)) then
285
fx = dsig(p,wgt) !Evaluate function
286
if (xzoomfact .gt. 0d0) then
287
wgt = wgt*fx*xzoomfact
291
if (wgt .gt. 0d0) call graph_point(p,wgt) !Update graphs
296
if (nzoom .le. 0) then
297
call sample_put_point(wgt,x(1),iter,ipole) !Store result
303
if (wgt .gt. 0d0) kevent=kevent+1
308
open(unit=66,file='results.dat',status='unknown')
310
do while(xmean(i) .ne. 0 .and. i .lt. cur_it)
319
do while (xmean(i) .ne. 0 .and. i .lt. cur_it)
320
tmean = tmean+xmean(i)*xmean(i)**2/xsigma(i)**2
321
tdem = tdem+xmean(i)**2/xsigma(i)**2
322
tsigma = tsigma + xmean(i)**2/ xsigma(i)**2
326
tsigma= tmean/sqrt(tsigma)
334
do i = cur_it-3,cur_it-1
335
chi2 = chi2+(xmean(i)-tmean)**2/xsigma(i)**2
337
chi2 = chi2/2d0 !Since using only last 3, n-1=2
338
write(*,'(a)') '-----------------------------------------------------'
339
write(*,'(a)') '---------------------------'
340
write(*,'(a,e12.4)') ' Results Last 3 iters: Integral = ',tmean
341
write(*,'(25x,a,e12.4)') 'Std dev = ',tsigma
342
write(*,'(17x,a,f12.4)') 'Chi**2 per DoF. =',chi2
343
write(*,'(a)') '-----------------------------------------------------'
344
write(*,'(a)') '---------------------------'
346
if (nun .lt. 0) nun=-nun !Case when wrote maximun number allowed
347
if (chi2 .gt. 1) tsigma=tsigma*sqrt(chi2)
348
if (icor .eq. 0) then
349
write(66,'(3e12.5,2i9,i5,i9,e10.3)')tmean,tsigma,0.0,kevent,nw,
350
& cur_it-1,nun, nun/max(tmean,1d-99)
352
write(66,'(3e12.5,2i9,i5,i9,e10.3)')tmean,0.0,tsigma,kevent,nw,
353
& cur_it-1,nun, nun/max(tmean,1d-99)
356
do i=cur_it-3,cur_it-1
357
write(66,'(i4,4e15.5)') i,xmean(i),xsigma(i),xeff(i),xwmax(i)
361
open(unit=66,file='results.dat',status='unknown')
362
write(66,'(3e12.5,2i9,i5,i9,e10.3)')0,0,0.0,kevent,nw,
364
write(66,'(i4,4e15.5)') 1,0,0,0,0
370
subroutine sample_fullx(ndim,ncall,itmax,dsig,ninvar,nconfigs)
371
c**************************************************************************
372
c Driver for sample which does complete integration
373
c This is done in double precision, and should be told the
374
c number of possible phasespace choices.
376
c ndim Number of dimensions for integral(number or random #'s/point)
377
c ncall Number of times to evaluate the function/iteration
378
c itmax Number of iterations
379
c ninvar Number of invarients to keep grids on (s,t,u, s',t' etc)
380
c nconfigs Number of different pole configurations
381
c dsig Function to be integrated
382
c**************************************************************************
388
integer ndim,ncall,itmax,ninvar,nconfigs
390
double precision dsig
394
double precision x(maxinvar),wgt,p(4*maxdim/3+14)
395
double precision tdem, chi2
396
integer ievent,kevent,nwrite,iter,nun
397
integer jmax,i,j,ipole
407
character*40 result_file,where_file
408
common /sample_status/result_file,where_file,nsteps
412
integer mincfig, maxcfig
413
common/to_configs/mincfig, maxcfig
415
double precision xmean(99),xsigma(99),xwmax(99),xeff(99)
416
common/to_iterations/xmean, xsigma, xwmax, xeff
418
double precision accur
419
common /to_accuracy/accur
421
double precision twgt, maxwgt,swgt(maxevents)
423
common/to_unwgt/twgt, maxwgt, swgt, lun, nw
426
double precision tx(1:3,maxinvar)
427
common/to_xpoints/tx, nzoom
429
double precision xzoomfact
430
common/to_zoom/ xzoomfact
432
double precision tmean, tsigma
433
integer dim, events, itm, kn, cur_it, invar, configs
434
common /sample_common/
435
. tmean, tsigma, dim, events, itm, kn, cur_it, invar, configs
438
common/to_correlated/icor
446
c data result_file,where_file,nsteps/'SAMPLE','WHERE.AMI',100/
450
c data twgt/-1d0/ !Dont write out events
451
c data lun/27/ !Unit number for events
453
c data nw/0/ !Number of events written
463
if (nsteps .lt. 1) nsteps=1
464
nwrite = itmax*ncall/nsteps
465
c open(unit=66,file='.sample_warn',status='unknown')
466
c write(66,*) 'Warnings from sample run.',itmax,ncall
468
call sample_init(ndim,ncall,itmax,ninvar,nconfigs)
478
c Main Integration Loop
481
do while(iter .le. itmax)
483
c Get integration point
485
call sample_get_config(wgt,iter,ipole)
486
if (iter .le. itmax) then
488
call x_to_f_arg(ndim,ipole,mincfig,maxcfig,ninvar,wgt,x,p)
489
if (pass_point(p)) then
491
fx = dsig(p,wgt) !Evaluate function
492
if (xzoomfact .gt. 0d0) then
493
wgt = wgt*fx*xzoomfact
497
if (wgt .gt. 0d0) call graph_point(p,wgt) !Update graphs
502
if (nzoom .le. 0) then
503
call sample_put_point(wgt,x(1),iter,ipole) !Store result
509
if (wgt .gt. 0d0) kevent=kevent+1
511
c Write out progress/histograms
513
if (kevent .ge. nwrite) then
514
nwrite = nwrite+ncall*itmax/nsteps
515
nwrite = min(nwrite,ncall*itmax)
516
c open(unit=22,file=where_file,status='old',
517
c & access='append',err=99)
518
c write(22,'(2i15)') ievent,kevent
526
c open(unit=66,file='.sample_warn',status='old',access='append')
527
c write(66,*) 'Finished sample',ievent,kevent,wgt
528
c if (wgt .ne. -1) then
530
c jmax = min(ndim,4*j)
531
c write(66,'(4e19.12)') (x(i),i=(j-1)*4+1,jmax)
536
open(unit=66,file='results.dat',status='unknown')
538
do while(xmean(i) .ne. 0 .and. i .lt. cur_it)
547
do while (xmean(i) .ne. 0 .and. i .lt. cur_it)
548
tmean = tmean+xmean(i)*xmean(i)**2/xsigma(i)**2
549
tdem = tdem+xmean(i)**2/xsigma(i)**2
550
tsigma = tsigma + xmean(i)**2/ xsigma(i)**2
553
c tmean = tmean/dble(i-1)
554
c tsigma= sqrt(tsigma)/dble(i-1)
556
c tsigma= sqrt(tsigma)/dble(3)
557
tsigma= tmean/sqrt(tsigma)
561
do i = cur_it-3,cur_it-1
562
chi2 = chi2+(xmean(i)-tmean)**2/xsigma(i)**2
564
chi2 = chi2/2d0 !Since using only last 3, n-1=2
565
c tsigma = tsigma*sqrt(chi2)
566
c write(*,*) "chi2 / dof=", chi2
567
write(*,'(a)') '-----------------------------------------------------'
568
write(*,'(a)') '---------------------------'
569
write(*,'(a,e12.4)') ' Results Last 3 iters: Integral = ',tmean
570
write(*,'(25x,a,e12.4)') 'Std dev = ',tsigma
571
write(*,'(17x,a,f12.4)') 'Chi**2 per DoF. =',chi2
572
write(*,'(a)') '-----------------------------------------------------'
573
write(*,'(a)') '---------------------------'
575
if (nun .lt. 0) nun=-nun !Case when wrote maximun number allowed
576
if (chi2 .gt. 1) tsigma=tsigma*sqrt(chi2)
577
if (icor .eq. 0) then
578
write(66,'(3e12.5,2i9,i5,i9,e10.3)')tmean,tsigma,0.0,kevent,nw,
579
& cur_it-1,nun, nun/max(tmean,1d-99)
581
write(66,'(3e12.5,2i9,i5,i9,e10.3)')tmean,0.0,tsigma,kevent,nw,
582
& cur_it-1,nun, nun/max(tmean,1d-99)
585
do i=cur_it-3,cur_it-1
586
write(66,'(i4,4e15.5)') i,xmean(i),xsigma(i),xeff(i),xwmax(i)
590
open(unit=66,file='results.dat',status='unknown')
591
write(66,'(3e12.5,2i9,i5,i9,e10.3)')0,0,0.0,kevent,nw,
593
write(66,'(i4,4e15.5)') 1,0,0,0,0
601
subroutine sample_writehtm()
602
c***********************************************************************
603
c Writes out results of run in html format
604
c***********************************************************************
609
character*(*) htmfile
610
parameter (htmfile='results.html')
617
double precision scale
622
double precision xmean(99),xsigma(99),xwmax(99),xeff(99)
623
common/to_iterations/xmean, xsigma, xwmax, xeff
630
c Here we determine the appropriate units. Assuming the results
631
c were written in picobarns
633
if (xmean(1) .ge. 1e4) then !Use nano barns
636
elseif (xmean(1) .ge. 1e1) then !Use pico barns
643
open(unit=lun,file=htmfile,status='unknown',err=999)
644
write(lun,50) '<head><title>Results_head</title></head>'
645
write(lun,50) '<body><h2>Results for Process</h2>'
646
write(lun,50) '<table border>'
647
write(lun,50) '<Caption> Caption Results'
648
write(lun,49) '<tr><th>Iteration</th>'
649
write(lun,48)'<th>Cross Sect',cpref,'</th><th>Error',cpref,'</th>'
650
write(lun,49) '<th>Events (K)</th><th>Eff</th>'
651
write(lun,50) '<th>Wrote</th><th>Unwgt</th></tr>'
653
c write(lun,60) '<tr><th>AVG</th><th>',xtot*scale
654
c $ ,'</th><th>',errtot*scale,'</th><th align=right>',
655
c $ ntot/1000,'</th><th align=right>',teff,'</th></tr>'
657
do while(xmean(i) .gt. 0d0)
658
write(lun,'(a)') '<tr>'
659
write(lun,45) '<td align=right>',i,'</tr>'
660
write(lun,46) '<td align=right>',xmean(i)*scale,'</td>'
661
write(lun,46) '<td align=right>',xsigma(i)*scale,'</td>'
662
write(lun,46) '<td align=right>',xeff(i)*scale,'</td>'
663
write(lun,'(a)') '</tr>'
666
write(lun,50) '</table></body>'
677
subroutine sample_init(p1, p2, p3, p4, p5)
678
c************************************************************************
679
c Initialize grid and random number generators
680
c************************************************************************
689
integer p1, p2, p3, p4, p5
699
character*40 result_file,where_file
700
common /sample_status/result_file,where_file,nsteps
702
double precision tmean, tsigma
703
integer dim, events, iter, kn, cur_it, invar, configs
704
common /sample_common/
705
. tmean, tsigma, dim, events, iter, kn, cur_it, invar, configs
707
double precision grid(2, ng, 0:maxinvar)
708
common /data_grid/ grid
709
integer Minvar(maxdim,lmaxconfigs)
710
common /to_invar/ Minvar
711
double precision psect(maxconfigs),alpha(maxconfigs)
712
common/to_mconfig2/psect ,alpha
714
common/to_first/first_time
716
common /to_weight/use_cut
718
common /to_random/ituple
721
common/to_readgrid/flat_grid !Tells if grid read from file
724
common/to_correlated/icor
727
common /to_zoomchoice/zooming
729
data use_cut/2/ !Grid: 0=fixed , 1=standard, 2=non-zero
730
data ituple/1/ !1=htuple, 2=sobel
731
data Minvar(1,1)/-1/ !No special variable mapping
737
If (use_cut .eq. 0) then
738
icor = 1 !Assume correlated unless grid read
739
print*,'Keeping grid fixed.'
740
elseif(use_cut .eq. 1) then
741
print*,'Using standard SAMPLE grid deformation.'
742
elseif(use_cut .eq. 2) then
743
print*,'Using non-zero grid deformation.'
744
elseif(use_cut .eq. 3) then
745
print*,'Using fluctuation for grid deformation.'
746
elseif(use_cut .eq. 4) then
747
print*,'Generating unweighted event shape.'
748
elseif(use_cut .eq. 5) then
749
print*,'Using constant plus linear grid deformation.'
750
elseif(use_cut .eq. 6) then
751
print*,'Using power law grid deformation.'
753
print*,'Using unknown grid deformation:',use_cut
755
c open(unit=22,file=result_file,status='unknown')
756
c write(22,*) 'Sample Status ',p2,p3,nsteps
758
c open(unit=22,file=where_file,status='unknown')
759
c write(22,*) 'Sample Progress ',p2,p3,nsteps
769
if (dim .gt. maxdim) then
770
write(*,*) 'Too many dimensions requested from Sample()'
773
c if (dim .gt. invar) then
774
c write(*,*) 'Too many dimensions dim > invar',dim,invar
777
if (p4 .gt. maxinvar) then
778
write(*,*) 'Too many invarients requested from Sample()',p4
781
if (p5 .gt. maxconfigs) then
782
write(*,*) 'Too many configs requested from Sample()',p5
786
write(*,'(i3,a,i7,a,i3,a,i3,a,i3,a)') dim, ' dimensions', events,
787
& ' events',p4,' invarients',iter, ' iterations',
788
& p5,' config(s), (0.99)'
790
if (ituple .eq. 1) then
791
print*,'Using h-tuple random number sequence.'
792
elseif (ituple .eq. 2) then
793
print*,'Using Sobel quasi-random number sequence.'
794
write(*,*) 'Sorry cant use sobel'
798
print*,'Unknown random number generator',ituple
801
c See if need mapping between dimensions in different configurations
802
c (ie using s,t,u type invarients)
804
if (Minvar(1,1) .eq. -1) then
805
print*,'No invarient mapping defined, using 1 to 1.'
808
Minvar(j,i) = j+(i-1)*dim
820
grid(2,j,0) = xgmin+(xgmax-xgmin)*j/dble(ng)
823
c Try to read grid from file
826
open(unit=25,file='ftn25',status='unknown',err=102)
827
read(25,fmt='(4f20.17)', err=101, end=101)
828
. ((grid(2,i,j),i=1,ng),j=1,maxinvar)
829
c write(*,*) 'Got the grid OK, now getting alpha'
830
c read(25,fmt='(4f20.17)',err=101,end=101)(alpha(i),i=1,maxconfigs)
831
write(*,*) 'Grid read from file'
835
c Determine weighting for each configuration
837
if (.not. flat_grid) icor = 0 !0 = not correlated
838
zooming = (.not. flat_grid .and. use_cut .eq. 0) !only zoom if grid already adjusted and not changing more
840
c tjs 5/22/07 turn off zooming
843
if (configs .eq. 1) then
848
write(*,*) 'Using uniform alpha',alpha(1)
854
if(i .le. configs) then
855
alpha(i)=1d0/dble(configs)
863
c write(*,*) 'Tried reading it',i,j
864
102 write(*,*) 'Error opening grid'
866
c Unable to read grid, using uniform grid and equal points in
869
write(*,*) 'Using Uniform Grid!'
872
grid(2, i, j) = xgmin+ (xgmax-xgmin)*(i / dble(ng))**1
876
if (j .le. configs) then
877
alpha(j)=1d0/dble(configs)
882
write(*,*) 'Using uniform alpha',alpha(1)
883
c write(*,*) 'Forwarding random number generator'
885
103 write(*,*) 'Grid defined OK'
888
subroutine setgrid(j,xo,a,itype)
889
c*************************************************************************
890
c Presets the grid for a 1/(x-a)^itype distribution down to xo
891
c*************************************************************************
900
integer j, itype !grid number
901
double precision xo !minimum value
902
double precision a !offset for peak
911
double precision grid(2, ng, 0:maxinvar)
912
common /data_grid/ grid
915
common/to_readgrid/flat_grid !Tells if grid read from file
921
write(*,'(a,i4,2e15.5,i4)') 'Setting grid',j,xo,a,itype
923
write(*,*) 'Can not integrate over singularity'
924
write(*,*) 'Set grid',j,xo,a
929
if (itype .eq. 1) then
931
c We'll use most for the peak, but save some for going down
938
c New form for setgrid
940
c grid(2,i+ngd,j)=((1d0-a)/(xo-a))**(1d0-dble(i)/dble(ngu))
941
c grid(2,i+ngd,j)=1d0/grid(2,i+ngd,j)+a
942
grid(2,i+ngd,j) = xo + ((dble(i)+xo-a)/(dble(ngu)+xo-a))**2
946
c Now lets go down the other side
950
c grid(2,i,j) = ((1d0-a)/(xo-a))**(1d0-dble(i)/dble(ngd))
951
grid(2,ngd-i,j) = xo-(grid(2,ngd+i,j)-xo)
952
if (grid(2,ngd-i,j) .lt. -1d0) then
953
write(*,*) 'Error grid set too low',grid(2,ngd-i,j)
955
write(*,*) k,grid(2,k,j)
962
c Make sure sample all the way down to zero
964
if (xo .gt. 0) grid(2,1,j) = 0d0
965
c write(*,*) "Adjusted bin 1 to zero"
967
elseif (itype .eq. 2) then
969
grid(2,i,j)=(1d0/(xo-a))*(1d0-dble(i)/dble(ng))+
970
$ (dble(i)/dble(ng))*(1d0/(1d0-a))
971
grid(2,i,j)=1d0/grid(2,i,j)+a
974
write(*,*) 'No modification in setgrid',itype
977
c write(*,*) j,i,grid(2,i,j)
979
call sample_write_g(j,'_0')
981
write(*,*) 'No modification is setgrid, grid read from file'
985
subroutine sample_get_config(wgt, iteration, iconfig)
986
c************************************************************************
990
c OUTPUTS: wgt == 1/nevents*niterations
991
c iteration == Current iteration
992
c iconfig == configuration to use
994
c************************************************************************
1003
double precision wgt
1004
integer iteration, iconfig
1010
double precision tot
1018
double precision tmean, tsigma
1019
integer dim, events, iter, kn, cur_it, invar, configs
1020
common /sample_common/
1021
. tmean, tsigma, dim, events, iter, kn, cur_it, invar, configs
1022
double precision psect(maxconfigs),alpha(maxconfigs)
1023
common/to_mconfig2/psect ,alpha
1026
integer mincfig, maxcfig
1027
common/to_configs/mincfig, maxcfig
1033
if (cur_it .gt. iter) then
1036
wgt = 1d0 / (dble(events) * dble(iter))
1038
c Choose configuration
1040
if (configs .gt. 1) then
1043
tot = alpha(iconfig)
1044
do while (tot .lt. xrnd .and. iconfig .lt. configs)
1046
tot = tot+alpha(iconfig)
1054
subroutine sample_get_x(wgt, x, j, ipole, xmin, xmax)
1055
c************************************************************************
1056
c Returns maxdim random numbers between 0 and 1, and the wgt
1057
c associated with this set of points, and the iteration number
1058
c This routine chooses the point within the range specified by
1059
c xmin and xmax for dimension j in configuration ipole
1060
c************************************************************************
1069
double precision wgt, x, xmin, xmax
1074
integer im, ip,ij,icount,it_warned
1075
double precision xbin_min,xbin_max,ddum(maxdim),xo,y
1079
double precision xbin
1084
double precision tmean, tsigma
1085
integer dim, events, iter, kn, cur_it, invar, configs
1086
common /sample_common/
1087
. tmean, tsigma, dim, events, iter, kn, cur_it, invar, configs
1089
double precision grid(2, ng, 0:maxinvar)
1090
common /data_grid/ grid
1091
integer Minvar(maxdim,lmaxconfigs)
1092
common /to_invar/ Minvar
1095
common /to_random/ituple
1097
double precision spole(maxinvar),swidth(maxinvar),bwjac
1098
common/to_brietwigner/spole ,swidth ,bwjac
1101
double precision tx(1:3,maxinvar)
1102
common/to_xpoints/tx, nzoom
1104
data ddum/maxdim*0d0/
1110
if (it_warned .ne. cur_it) then
1114
if (ituple .eq. 2) then !Sobel generator
1115
print*,'Sorry Sobel generator disabled'
1118
c write(*,'(7f11.5)')(ddum(j)*real(ng),j=1,dim)
1120
if (ituple .eq. 1) then
1121
c write(*,*) 'Getting variable',ipole,j,minvar(j,ipole)
1122
xbin_min = xbin(xmin,minvar(j,ipole))
1123
xbin_max = xbin(xmax,minvar(j,ipole))
1124
if (xbin_min .gt. xbin_max) then
1125
c write(*,'(a,4e15.4)') 'Bad limits',xbin_min,xbin_max,
1127
c xbin_max=xbin_min+1d-10
1128
xbin_min = xbin(xmin,minvar(j,ipole))
1129
xbin_max = xbin(xmax,minvar(j,ipole))
1132
c Line which allows us to keep choosing same x
1134
c if (swidth(j) .ge. 0) then
1135
if (nzoom .le. 0) then
1136
call ntuple(ddum(j), xbin_min,xbin_max, j, ipole)
1138
c write(*,*) 'Reusing num',j,nzoom,tx(2,j)
1140
call ntuple(ddum(j),max(xbin_min,dble(int(tx(2,j)))),
1141
$ min(xbin_max,dble(int(tx(2,j))+1)),j,ipole)
1143
if(max(xbin_min,dble(int(tx(2,j)))).gt.
1144
$ min(xbin_max,dble(int(tx(2,j))+1))) then
1145
c write(*,*) 'not good'
1148
c write(*,'(2i6,4e15.5)') nzoom,j,ddum(j),tx(2,j),
1149
c $ max(xbin_min,dble(int(tx(2,j)))),
1150
c $ min(xbin_max,dble(int(tx(2,j))+1))
1152
c ddum(j) = tx(2,j) !Use last value
1159
elseif (ituple .eq. 2) then
1160
if (ipole .gt. 1) then
1161
print*,'Sorry Sobel not configured for multi-pole.'
1164
ddum(j)=ddum(j)*dble(ng)
1166
print*,'Error unknown random number generator.',ituple
1172
ij = Minvar(j,ipole)
1174
c New method of choosing x from bins
1176
if (ip .eq. 1) then !This is in the first bin
1177
xo = grid(2, ip, ij)-xgmin
1178
x = grid(2, ip, ij) - xo * (dble(ip) - ddum(j))
1180
xo = grid(2, ip, ij)-grid(2,im,ij)
1181
x = grid(2, ip, ij) - xo * (dble(ip) - ddum(j))
1184
c Now we transform x if there is a B.W., S, or T pole
1187
if (swidth(ij) .gt. 0d0) then
1188
y = x !Takes uniform y and returns
1189
c write(*,*) 'Tranpole called',ij,swidth(ij)
1190
call transpole(spole(ij),swidth(ij),y,x,wgt) !x on BW pole
1194
c Simple checks to see if we got the right point note 1e-3 corresponds
1195
c to the fact that the grids are required to be separated by 1e-14. Since
1196
c double precision is about 18 digits, we expect things to agree to
1199
if (abs(ddum(j)-xbin(x,ij))/(ddum(j)+1d-22) .gt. 1e-3) then
1200
if (icount .lt. 5) then
1201
write(*,'(a,i4,2e14.6,1e12.4)')
1202
& 'Warning xbin not returning correct x', ij,
1203
& ddum(j),xbin(x,ij),xo
1204
elseif (icount .eq. 5) then
1205
write(*,'(a,a)')'Warning xbin still not working well. ',
1206
& 'Last message this iteration.'
1210
if (x .lt. xmin .or. x .gt. xmax) then
1211
c write(*,'(a,4i4,2f24.16,1e10.2)') 'Bad x',ij,int(xbin_min),ip,
1212
c & int(xbin_max),xmin,x,xmax-xmin
1215
wgt = wgt * xo * dble(xbin_max-xbin_min)
1216
c print*,'Returning x',ij,ipole,j,x
1219
subroutine sample_get_wgt(wgt, x, j, ipole, xmin, xmax)
1220
c************************************************************************
1221
c Returns the wgt for a point x in grid j of configuration
1222
c ipole between xmin and xmax
1223
c************************************************************************
1232
double precision wgt, x, xmin, xmax
1238
double precision xbin_min,xbin_max,xbin2
1243
double precision xbin
1248
double precision tmean, tsigma
1249
integer dim, events, iter, kn, cur_it, invar, configs
1250
common /sample_common/
1251
. tmean, tsigma, dim, events, iter, kn, cur_it, invar, configs
1253
double precision grid(2, ng, 0:maxinvar)
1254
common /data_grid/ grid
1255
integer Minvar(maxdim,lmaxconfigs)
1256
common /to_invar/ Minvar
1258
common /to_random/ituple
1259
double precision spole(maxinvar),swidth(maxinvar),bwjac
1260
common/to_brietwigner/spole ,swidth ,bwjac
1265
if (xmin .gt. x) then
1266
if (xmin-x .lt. 1d-13) then
1269
write(*,'(a,2i4,4e10.4)') 'Error x out of range in get_wgt',
1270
$ j,minvar(j,ipole),xmin,x,xmax,x-xmin
1274
if (xmax .lt. x) then
1275
if (x-xmax .lt. 1d-13) then
1278
write(*,'(a,2i4,4f8.4)') 'Error x out of range in get_wgt',
1279
$ j,minvar(j,ipole),xmin,x,xmax,x-xmin
1283
if (ituple .eq. 1) then
1284
xbin_min = xbin(xmin,minvar(j,ipole))
1285
xbin_max = xbin(xmax,minvar(j,ipole))
1286
xbin2 = xbin(x,minvar(j,ipole)) !This must be last one for bwjac
1287
if (xbin_min .gt. xbin_max) then
1288
write(*,'(a,2e15.3,i6,2e15.3)') 'Error xbinmin>xbinmax'
1290
& xbin_max,minvar(j,ipole),xmin,xmax
1293
print*,'Error unknown random number generator.',ituple
1298
ij = Minvar(j,ipole)
1300
c New method for finding bin
1303
xo=grid(2,ip,ij)-xgmin
1305
xo=grid(2,ip,ij)-grid(2,im,ij)
1307
wgt = wgt * xo * dble(xbin_max-xbin_min)*bwjac
1308
if (wgt .le. 0d0) then
1309
c write(*,'(a,3i4,2f6.1,3e15.3)') 'Error wgt<0',j,ij,ip,
1310
c & xbin_min,xbin_max,xo,xmin,xmax
1311
c write(*,'(2e25.15)') grid(2, ip, ij),grid(2, im, ij)
1312
c write(*,'(a,5e15.5)') 'Wgt',wgt,xo,
1313
c & dble(xbin_max-xbin_min),bwjac
1317
subroutine sample_result(mean, sigma)
1319
double precision mean, sigma
1321
double precision tsigma,tmean,tsig,tdem
1323
double precision xmean(99),xsigma(99),xwmax(99),xeff(99)
1324
common/to_iterations/xmean, xsigma, xwmax, xeff
1328
do while(xmean(i) .ne. 0 .and. i .lt. 99)
1337
do while (xmean(i) .ne. 0 .and. i .lt. cur_it)
1338
tmean = tmean+xmean(i)*xmean(i)**2/xsigma(i)**2
1339
tdem = tdem+xmean(i)**2/xsigma(i)**2
1340
tsigma = tsigma + xmean(i)**2/ xsigma(i)**2
1343
tmean = tmean/tsigma
1344
tsigma= tmean/sqrt(tsigma)
1353
subroutine sample_put_point(wgt, point, iteration,ipole)
1354
c**************************************************************************
1355
c Given point(maxinvar),wgt and iteration, updates the grid.
1356
c If at the end of an iteration, reforms the grid as necessary
1357
c and outputs current results
1358
c**************************************************************************
1365
parameter (max_events=500000) !Maximum # events before get non_zero
1369
integer iteration,ipole
1370
double precision wgt, point(maxinvar)
1374
integer i, j, k, knt, non_zero, nun
1375
double precision vol,xnmin,xnmax,tot
1376
double precision rc, dr, xo, xn, x(maxinvar), dum(ng)
1378
double precision chi2
1380
double precision wmax1,ddumb
1382
double precision twgt1,xchi2,xmean
1384
save twgt1,iavg,navg
1388
double precision binwidth,xbin
1391
external binwidth,xbin,rebin,n_unwgted
1395
double precision accur
1396
common /to_accuracy/accur
1398
double precision ymean(99),ysigma(99),ywmax(99),yeff(99)
1399
common/to_iterations/ymean, ysigma, ywmax, yeff
1401
double precision mean,sigma
1402
common/to_result/mean,sigma
1404
double precision grid2(0:ng,maxinvar)
1405
integer inon_zero(ng,maxinvar)
1406
common/to_grid2/grid2,inon_zero
1408
double precision tmean, tsigma
1409
integer dim, events, iter, kn, cur_it, invar, configs
1410
common /sample_common/
1411
. tmean, tsigma, dim, events, iter, kn, cur_it, invar, configs
1413
double precision grid(2, ng, 0:maxinvar)
1414
common /data_grid/ grid
1416
character*40 result_file,where_file
1417
common /sample_status/result_file,where_file,nsteps
1419
common/to_first/first_time
1421
common /to_weight/use_cut
1422
double precision xmin(maxinvar),xmax(maxinvar)
1423
common /to_extreme/xmin ,xmax
1424
double precision reliable(ng,maxdim)
1425
common /to_error/reliable
1427
double precision twgt, maxwgt,swgt(maxevents)
1429
common/to_unwgt/twgt, maxwgt, swgt, lun, nw
1432
real*8 wmax !This is redundant
1433
common/to_unweight/wmax
1437
double precision prb(maxconfigs,maxpoints,maxplace)
1438
double precision fprb(maxinvar,maxpoints,maxplace)
1440
common/to_mconfig1/prb ,fprb,jpnt,jplace
1441
double precision psect(maxconfigs),alpha(maxconfigs)
1442
common/to_mconfig2/psect ,alpha
1443
double precision spole(maxinvar),swidth(maxinvar),bwjac
1444
common/to_brietwigner/spole ,swidth ,bwjac
1446
integer neventswritten
1447
common /to_eventswritten/ neventswritten
1449
data prb/maxprb*1d0/
1450
data fprb/maxfprb*1d0/
1451
data jpnt,jplace /1,1/
1456
if (first_time) then
1457
first_time = .false.
1459
iavg = 0 !Vars for averging to increase err estimate
1467
vol = 1d0 / dble(events * iter)
1484
if (iteration .eq. cur_it) then
1486
if (.true.) then !Average points to increase error estimate
1487
twgt1=twgt1+wgt !This doesn't change anything should remove
1489
if (iavg .ge. navg) then
1490
sigma=sigma+twgt1**2
1495
sigma = sigma + wgt**2
1497
if (wgt .gt. 0.) then
1498
if (wgt*iter*events .gt. wmax) then
1499
wmax=wgt*iter*events
1501
non_zero = non_zero + 1
1504
c psect(ipole)=psect(ipole)+wgt*wgt/alpha(ipole) !Ohl
1505
c psect(ipole)=1d0 !Not doing multi_config
1509
tot=tot+prb(i,jpnt,jplace)*alpha(i)
1512
if (tot .gt. 0d0) then !Pittau hep-ph/9405257
1513
psect(i)=psect(i)+wgt*wgt*prb(i,jpnt,jplace)/tot
1515
psect(i)=psect(i)+wgt*wgt*alpha(i) !prb not set....
1519
c write(123,'(2i6,1e15.5)') 1,1,wgt
1520
c write(123,'(5e15.9)') (fprb(i,jpnt,jplace),i=1,invar)
1521
c write(123,'(5e15.9)') (prb(i,jpnt,jplace),i=1,configs)
1523
i = int(xbin(point(j),j))+1
1525
print*,'error i>ng',i,j,ng,point(j)
1528
grid(1, i, j) = grid(1, i, j) + abs(wgt)
1529
grid2(i, j) = grid2(i, j) + wgt**2
1531
c Lines below are for multiconfiguration
1533
c grid(1, i, j) = grid(1, i, j) +
1534
c & (abs(wgt)**2)*fprb(j,jpnt,jplace)
1535
c grid2(i, j) = grid2(i, j) + wgt**4*fprb(j,jpnt,jplace)
1536
if (abs(wgt) .gt. 0) inon_zero(i,j) = inon_zero(i,j)+1
1538
c Here we need to look out for point(j) which has been transformed
1539
c for Briet-Wigner pole
1542
if (swidth(j) .gt. 0d0) then
1544
call untranspole(spole(j),swidth(j),
1545
& point(j),point(j),ddumb)
1546
if (point(j) .lt. 0d0) then
1547
print*,'Warning point<0',j,point(j)
1551
if (abs(wgt) .gt. 0) xmin(j)=min(xmin(j),point(j))
1552
if (abs(wgt) .gt. 0) xmax(j)=max(xmax(j),point(j))
1553
if (xmin(j) .lt. xgmin) then
1554
print*,'Warning xmin<0',j,xmin(j),point(j)
1556
xmin(j)=max(xmin(j),xgmin)
1560
c Now if done with an iteration, print out stats, rebin, reset
1562
c if (kn .eq. events) then
1563
if (kn .ge. max_events .and. non_zero .lt. 5) then
1564
call none_pass(max_events)
1566
if (non_zero .eq. events .or. (kn .gt. 200*events .and.
1567
$ non_zero .gt. 5)) then
1568
mean=mean*dble(events)/dble(non_zero)
1569
twgt1=twgt1*dble(events)/dble(non_zero)
1570
sigma=sigma+twgt1**2 !This line for averaging over points
1571
if (non_zero .eq. 0) then
1572
write(*,*) 'Error no points passed the cuts.'
1573
write(*,*) 'Try running with more points or looser cuts.'
1576
c mean = mean * iter !Used if don't have non_zero
1578
mean = mean * iter *dble(non_zero)/dble(kn)
1582
c Need to fix this if averaging over navg events
1584
c write(*,*) (sigma/vol/vol-knt*mean*mean)/dble(knt-1)/dble(knt),
1585
c & (sigma/vol/vol-knt*mean*mean*navg)/dble(knt-1)/ dble(knt)
1588
c vol = 1d0/(knt*iter)
1589
sigma = (sigma/vol/vol-non_zero*mean*mean*navg) !knt replaced by non_zero
1590
. / dble(knt-1) / dble(knt)
1592
sigma = (sigma/vol/vol - knt*mean*mean)
1593
. / dble(knt-1) / dble(knt)
1596
tmean = tmean + mean * (mean**2 / sigma)
1597
tsigma = tsigma + mean**2 / sigma
1598
chi2 = chi2 + mean**2 * (mean**2 / sigma)
1599
sigma = sqrt(abs(sigma))
1601
if (cur_it .lt. 100) then
1602
ymean(cur_it) = mean
1603
ysigma(cur_it) = sigma
1604
ywmax(cur_it)= wmax*dble(non_zero)/dble(kn)
1605
yeff(cur_it)= sigma*sqrt(dble(non_zero))/mean
1606
c call sample_writehtm()
1608
write(*,222) 'Iteration',cur_it,'Mean: ',mean,
1609
& ' Fluctuation: ',sigma,
1610
& wmax*(dble(non_zero)/dble(kn)),
1611
& dble(non_zero)/dble(kn)*100.,'%'
1612
222 format(a10,I3,3x,a6,e10.4,a16,e10.3,e12.3,3x,f5.1,a1)
1614
write(*,223) cur_it, mean, ' +- ', sigma,
1615
& sigma*sqrt(dble(non_zero))/mean
1616
223 format( i3,3x,e10.4,a,e10.4,f10.2)
1622
& write(*,'(8f10.5)') (psect(i)/tot, i=1,configs)
1624
c Now set things up for generating unweighted events
1626
if (twgt .eq. -2d0) then
1627
twgt = mean *kn/ (dble(iter)*dble(events)*dble(events))
1629
c now scale twgt, in case have large fluctuations
1632
c twgt = twgt * max(1d0, yeff(cur_it))
1635
c For small number of events only write about 1% of events
1637
c if (events .le. 2500) then
1638
c twgt = mean *kn*100 /
1639
c $ (dble(iter)*dble(events)*dble(events))
1641
c twgt = max(twgt, maxwgt/10d0)
1642
write(*,*) 'Writing out events',twgt, yeff(cur_it)
1643
c write(*,*) mean, kn, iter, events
1646
c This tells it to write out a file for unweighted events
1648
c if(wmax*(dble(non_zero)/dble(kn)) .lt. wmax1) then
1649
if(sigma/(mean+1d-99) .lt. wmax1 .and. use_cut .ne. 0) then
1650
c wmax1 = wmax*(dble(non_zero)/dble(kn))
1651
wmax1 = sigma/(mean+1d-99)
1652
c open(26, file='ftn99',status='unknown')
1653
c write(26,fmt='(4f20.17)')
1654
c $ ((grid(2,i,j),i=1,ng),j=1,maxinvar)
1655
c write(26,fmt='(4f20.17)') (alpha(i),i=1,maxconfigs)
1659
if (use_cut .ne. 0) then
1660
c write(*,*) 'Keeping alpha fixed'
1661
if (configs .gt. 1) then
1663
alpha(i)=alpha(i)*sqrt(sqrt(psect(i))) !Pittau
1668
alpha(i)=alpha(i)/tot
1670
write(*,'(A)') 'Configs:'
1671
write(*,'(8f10.5)') (alpha(i),i=1,configs)
1674
c open(unit=22,file=result_file,status='old',access='append',
1676
c write(22,222) 'Iteration',cur_it,'Mean: ',mean,
1677
c & ' Fluctuation: ',sigma,
1678
c & wmax*(dble(non_zero)/dble(kn)),
1679
c & dble(non_zero)/dble(kn)*100.,'%'
1682
c Here we will double the number of events requested for the next run
1684
23 events = 2 * events
1685
vol = 1d0/dble(events*iter)
1687
twgt = mean / (dble(iter)*dble(events))
1688
c write(*,*) 'New number of events',events,twgt
1696
c do so adjusting of weights according to number of events in bin
1700
if (use_cut .ne. 2 .and.
1701
& use_cut .ne. 3 .and. use_cut .ne. 5)
1702
$ inon_zero(i,j) = 0
1703
if (use_cut .eq. 3) grid(1,i,j)=grid2(i,j)
1704
if (inon_zero(i,j) .ne. 0) then
1705
grid(1,i,j) = grid(1,i,j)
1706
& *dble(min((real(non_zero)/real(inon_zero(i,j))),
1708
grid2(i,j) = grid2(i,j)
1709
& *dble(min((real(non_zero)/real(inon_zero(i,j))),
1711
if (real(non_zero)/real(inon_zero(i,j))
1713
c if (j .eq. 1) then
1714
print*,'Exceeded boost',j,i,
1715
& real(non_zero)/real(inon_zero(i,j))
1721
& reliable(i,j)=dsqrt(grid2(i,j))/grid(1,i,j)
1724
if (use_cut .eq. 4) then
1730
c special routines to deal with xmin cutoff
1732
do while(grid(1,k,j) .le. 0d0 .and. k .lt. ng)
1736
c if (j .eq. 1) then
1737
c open(unit=22,file='x1.dat',status='unknown')
1739
c write(22,'(i6,2e20.8)') i,grid(1,i,j),
1740
c $ dsqrt(grid2(i,j))
1747
x(j)=x(j)+grid(1,i,j)
1750
call average_grid(j,k,grid,grid2,x)
1752
c if (j .eq. 1 .and. .true.) then
1753
c open(unit=22,file='x1avg.dat',status='unknown')
1755
c write(22,'(i6,2e20.8)') i,grid(1,i,1),
1756
c $ dsqrt(grid2(i,1))
1762
c Now take logs to help the rebinning converge quicker
1766
xo = (1.0d-14) + grid(1, i, j) / x(j)
1767
grid(1, i, j) = ((xo - 1d0) / log(xo))**1.5 !this is 1.5
1768
rc = rc + grid(1, i, j)
1777
c Special lines to deal with xmin .ne. 0 cutoffs
1780
c These assume one endpoints are xgmin and xgmax
1784
xnmin = xgmin !Endpoints for grid usually 0d0
1785
xnmax = xgmax !Endpoint for grid usually 1d0
1786
if (xmin(j)-xgmin .gt. (grid(2,2,j)-grid(2,1,j)))then
1787
xnmin = xmin(j)-(grid(2,2,j)-grid(2,1,j))/5d0
1791
rc = rc * dble(ng)/dble(ng-i)
1794
if (xgmax-xmax(j).gt.(grid(2,ng-1,j)-grid(2,ng-2,j)))then
1795
xnmax = xmax(j)+(grid(2,ng-1,j)-grid(2,ng-2,j))/5d0
1797
rc = rc * dble(ng-i)/dble(ng-i-1)
1798
c print*,'xmax',j,xmax(j),dum(ng-1)
1802
dr = dr + grid(1, k, j)
1804
xn = max(grid(2, k, j),xnmin)
1806
26 if (rc .gt. dr) goto 25
1810
dum(i) = xn - (xn - xo) * dr / grid(1, k, j)
1812
c Put in check for 0 width bin NEED TO FIX THIS
1814
if (dum(ng-1) .eq. -1) then
1815
if (i .lt. ng - 1 ) goto 26
1817
if (i .lt. ng - 2 ) goto 26
1820
c Here is another fix for 0 width bins
1823
if (dum(i+1)-dum(i) .le. 1d-14) then
1824
c write(*,'(a,2i4,2f24.17,1e10.3)') 'Bin too small',
1825
c & j,i,dum(i),dum(i+1),dum(i+1)-dum(i)
1826
dum(i+1)=dum(i)+1d-14
1827
if (dum(i+1) .gt. xgmax) then
1828
write(*,*) 'Error in rebin',i,dum(i),dum(i+1)
1833
c Now reset counters and set new grid as necessary
1838
if (use_cut .ne. 0 .and. j .gt. 0)
1839
$ grid(2, i, j) = dum(i)
1841
grid(1, ng, J) = 0d0
1842
grid(2, ng, J) = xgmax
1846
call sample_write_g(j,'_1')
1849
c write(*,*) (irebin(j),j=1,dim)
1850
c open(unit=26,file='grid.dat',status='unknown')
1853
c write(26,*) grid(2,i,j),j,i
1858
c Add test to see if we have achieved desired accuracy
1860
if (tsigma .gt. 0d0 .and. cur_it .gt. 5 .and. accur .gt. 0d0) then
1862
xmean = tmean/tsigma
1863
xchi2 = (chi2/xmean/xmean-tsigma)/dble(cur_it-2)
1864
write(*,'(a,4f8.3)') 'We got it',sqrt(xchi2/tsigma),
1865
& accur,1/sqrt(tsigma),xchi2
1866
c write(*,*) 'We got it',1d0/sqrt(tsigma), accur
1867
c if (1d0/sqrt(tsigma) .lt. accur) then
1868
if (sqrt(xchi2/tsigma) .lt. accur) then
1869
write(*,*) 'Finished due to accuracy',sqrt(xchi2/tsigma), accur
1870
tmean = tmean / tsigma
1871
if (cur_it .gt. 2) then
1872
chi2 = (chi2/tmean/tmean-tsigma)/dble(cur_it-2)
1876
tsigma = tmean / sqrt(tsigma)
1877
write(*, 80) real(tmean), real(tsigma), real(chi2)
1878
if (use_cut .ne. 0) then
1879
open(26, file='ftn26',status='unknown')
1880
write(26,fmt='(4f20.17)')
1881
$ ((grid(2,i,j),i=1,ng),j=1,maxinvar)
1882
write(26,fmt='(4f20.17)') (alpha(i),i=1,maxconfigs)
1885
call sample_writehtm()
1886
c open(unit=22,file=result_file,status='old',
1887
c $ access='append',err=122)
1888
c write(22, 80) real(tmean), real(tsigma), real(chi2)
1890
tsigma = tsigma*sqrt(chi2) !This gives the 68% confidence cross section
1897
c New check to see if we need to keep integrating this one or not.
1899
if (cur_it .gt. 3 .and. accur .lt. 0d0) then !Check # unweighted
1901
c Lets get the actual number instead
1905
c write(*,*) 'Estimated events',nun, accur
1907
nun = neventswritten
1908
write(*,*) "Checking number of events",accur,nun
1909
if (nun .gt. -accur)then
1910
tmean = tmean / tsigma
1911
if (cur_it .gt. 2) then
1912
chi2 = (chi2/tmean/tmean-tsigma)/dble(cur_it-2)
1916
tsigma = tmean / sqrt(tsigma)
1917
write(*, 80) real(tmean), real(tsigma), real(chi2)
1918
if (use_cut .ne. 0) then
1919
open(26, file='ftn26',status='unknown')
1920
write(26,fmt='(4f20.17)')
1921
$ ((grid(2,i,j),i=1,ng),j=1,maxinvar)
1922
write(26,fmt='(4f20.17)') (alpha(i),i=1,maxconfigs)
1925
call sample_writehtm()
1927
c open(unit=22,file=result_file,status='old',
1928
c $ access='append',err=129)
1929
c write(22, 80) real(tmean), real(tsigma), real(chi2)
1931
tsigma = tsigma*sqrt(chi2) !This gives the 68% confidence cross section
1938
if (cur_it .gt. iter) then
1940
tmean = tmean / tsigma
1941
chi2 = (chi2 / tmean / tmean - tsigma) / dble(iter - 1)
1942
tsigma = tmean / sqrt(tsigma)
1943
write(*, 80) real(tmean), real(tsigma), real(chi2)
1944
80 format(/1X,79(1H-)/1X,23HAccumulated results: ,
1945
. 10HIntegral =,e12.4/24X,10HStd dev =,e12.4/
1946
. 13X,21HChi**2 per DoF. =,f12.4/1X,79(1H-))
1947
if (use_cut .ne. 0) then
1948
open(26, file='ftn26',status='unknown')
1949
write(26,fmt='(4f20.17)')
1950
$ ((grid(2,i,j),i=1,ng),j=1,maxinvar)
1951
write(26,fmt='(4f20.17)') (alpha(i),i=1,maxconfigs)
1954
call sample_writehtm()
1955
c open(unit=22,file=result_file,status='old',
1956
c $ access='append',err=123)
1957
c write(22, 80) real(tmean), real(tsigma), real(chi2)
1959
tsigma = tsigma*sqrt(chi2) !This gives the 68% confidence cross section
1962
c Starting new iteration, should clean out stored events
1966
c write(*,*) 'Estimated unweighted events ', nun
1974
subroutine none_pass(max_events)
1975
c*************************************************************************
1976
c Special break to handle case where no events are passing cuts
1977
c We'll set the cross section to zero here.
1978
c*************************************************************************
1992
character*40 result_file,where_file
1993
common /sample_status/result_file,where_file,nsteps
1998
write(*,*) 'No points passed cuts!'
1999
write(*,*) 'Loosen cuts or increase max_events',max_events
2000
c open(unit=22,file=result_file,status='old',access='append',
2002
c write(22,222) 'Iteration',0,'Mean: ',0d0,
2003
c & ' Fluctuation: ',0d0,
2007
222 format(a10,I3,3x,a6,e10.4,a16,e10.3,e12.3,3x,f5.1,a1)
2009
open(unit=66,file='results.dat',status='unknown')
2010
write(66,*) 0,0,0,0,0,0,0,1
2011
write(66,'(i4,4e15.5)') 1,0d0,0d0,0d0,0d0
2014
c Remove file events.lhe (otherwise event combination gets screwed up)
2015
write(*,*) 'Deleting file events.lhe'
2016
open(unit=67,file='events.lhe',status='unknown')
2023
subroutine average_grid(j,k,grid,grid2,x)
2024
c**************************************************************************
2025
c Special routine to deal with averaging over the grid bins
2026
c This routine starts averaging at bin k rather than bin 1 so that
2027
c one can accommodate cutoffs. With k=1 this should give the
2028
c standard sample/vegas/bases averaging results.
2030
c Also stops averaging when reaches maximum value
2032
c**************************************************************************
2042
double precision grid(2,ng,0:maxinvar),grid2(0:ng,maxinvar)
2043
double precision x(maxinvar)
2048
double precision xo,xn
2054
if (grid(1,i,j) .gt. 0d0) kmax=i
2058
grid(1,k,j) = (xo+xn)/2d0
2060
c do i=k+1,ng-1 !Original without kmax stuff
2062
grid(1, i, j) = xo + xn
2064
xn = grid(1, i+1, j)
2065
grid(1, i, j) = (grid(1, i, j) + xn) / 3d0
2066
x(j) = x(j) + grid(1, i, j)
2068
c grid(1, ng, j) = (xn + xo) / 2d0 !Original without kmax stuff
2069
grid(1, kmax, j) = (xn + xo) / 2d0
2070
x(j) = x(j) + grid(1, ng, j)
2073
double precision function xbin(y,j)
2074
c**************************************************************************
2075
c Subroutine to determine which value y will map to give you the
2076
c value of x when put through grid j. That is what random number
2077
c do you need to be given to get the value x out of grid j and will be
2078
c between 0 < x < ng.
2079
c**************************************************************************
2085
double precision tol
2086
parameter (tol=1d-12)
2096
double precision x,xo
2100
double precision grid(2, ng, 0:maxinvar)
2101
common /data_grid/ grid
2102
double precision spole(maxinvar),swidth(maxinvar),bwjac
2103
common/to_brietwigner/spole ,swidth ,bwjac
2107
data spole,swidth/maxinvar*0d0,maxinvar*0d0/
2113
if (swidth(j) .gt. 0d0) then
2114
call untranspole(spole(j),swidth(j),x,y,bwjac)
2121
if (x .eq. xgmax) then
2124
elseif (x .eq. xgmin) then
2126
elseif(x .le. grid(2,1,j)) then
2128
xo = grid(2,i,j)-xgmin
2129
xbin = dble(i)+(x-grid(2,i,j))/xo
2133
do while (ju-jl .gt. 1) !Binary search
2135
if (grid(2,i,j) .le. x) then
2142
xo = grid(2,i,j)-grid(2,i-1,j)
2143
xbin = dble(i)+(x-grid(2,i,j))/xo
2147
c if (x+tol .gt. grid(2,i,j) .and. i .ne. ng) then
2148
c write(*,'(a,2e23.16,e9.2)') 'Warning in DSAMPLE:JBIN ',
2149
c & x,grid(2,i,j),tol
2150
c x=2d0*grid(2,i,j)-x
2156
subroutine sample_write_g(idim,cpost)
2157
c**************************************************************************
2158
c Writes out grid in function form for dimension i with extension cpost
2160
c**************************************************************************
2176
double precision xo,yo
2180
double precision grid(2, ng, 0:maxinvar)
2181
common /data_grid/ grid
2187
if (idim .lt. 1 .or. idim .gt.maxinvar) then
2188
write(*,*) 'Error invalid dimension in sample_write_f',idim
2191
if (idim .lt. 10) then
2192
write(fname,'(a,i1,a,a)') 'g_',idim,cpost,'.dat'
2193
elseif (idim .lt. 100) then
2194
write(fname,'(a,i2,a,a)') 'g_',idim,cpost,'.dat'
2196
open(unit=21,file=fname,status='unknown',err=99)
2198
xo = (grid(2,i,idim)+grid(2,i+1,idim))/2d0
2199
yo =1d0/(-grid(2,i,idim)+grid(2,i+1,idim))
2204
99 write(*,*) 'Error opening file ',fname
2209
parameter (m1=259200,ia1=7141,ic1=54773,rm1=3.8580247e-6)
2210
parameter (m2=134456,ia2=8121,ic2=28411,rm2=7.4373773e-6)
2211
parameter (m3=243000,ia3=4561,ic3=51349)
2213
save r, ix1, ix2, ix3
2214
if (idum.lt.0.or.iff.eq.0) then
2216
ix1=mod(ic1-idum,m1)
2217
ix1=mod(ia1*ix1+ic1,m1)
2219
ix1=mod(ia1*ix1+ic1,m1)
2222
ix1=mod(ia1*ix1+ic1,m1)
2223
ix2=mod(ia2*ix2+ic2,m2)
2224
r(j)=(float(ix1)+float(ix2)*rm2)*rm1
2228
ix1=mod(ia1*ix1+ic1,m1)
2229
ix2=mod(ia2*ix2+ic2,m2)
2230
ix3=mod(ia3*ix3+ic3,m3)
2232
if(j.gt.97.or.j.lt.1) stop
2234
r(j)=(float(ix1)+float(ix2)*rm2)*rm1