-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaao_rad.F
1909 lines (1533 loc) · 52.8 KB
/
aao_rad.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
program aaorad_gen
c This program makes an n-tuple that can be used with Paw to
c make distributions of energies, angles, resonance
c mass resulting from internal bremmstrahlung associated with pion
c production on a proton. The exact integration formula of Mo and Tsai
c is used.
c The n-tuple contains the photon energy(EG), the true hadronic invariant
c mass (W), the components of the proton momentum (PPX, PPY, PPZ),
c the proton energy (EP), the pion momentum (PPIX, PPIY, PPIZ) and
c pion energy (EPI), the angles for the hadronic
c decay in the hadronic frame (CSTCM, PHICM), the missing mass (MM),
c and the photon angles relative to the q vector, (CSTHK, PHIK).
c
c This program forces the monte carlo to concentrate on the regions
c of photon emission along the directions of the incident and
c scattered electrons.
c
c The electrons are radiated as they pass through the target. Resolution
c of detectors is not folded into the results. If this is desired it
c should be done with a second program that can operate on the n-tuple
c and make a new version.
implicit none
#include "bcs.inc"
#include "mc.inc"
#include "names.inc"
COMMON/ALPHA/ ALPHA,PI,MP,MPI,MEL,WG,EPIREA,TH_OPT,RES_OPT
common /radcal/T0,es,ep,ps,pp,rs,rp,u0,pu,uu,cst0,snt0,csths,csthp
* ,snths,snthp,pdotk,sdotk
common /random/idum
real lundmass(4)
integer timevals(8)
integer sseed(64)
integer ssize
real*8 ek,Tk,delta
real*8 alpha,pi,mp,mpi,mel,wg,T0
real*8 es,ep,ps,pp,rs,rp,u0,pu,uu,pdotk,sdotk
real*8 cst0,snt0,csths,csthp,snths,snthp
real csran,csrng,csrnge,csrngb,delphi
real csthcm
real csthcm_max
real cstk
real cstk1,cstk2
real cstmp
real csdotk,cpdotk,cqdotk
real delinf
real deltar
real ek_max
real ekmax
real ekx,eky,ekz
real epeps
real epi
real epmax
real eprng
real eprot
real epw
real ep_min,ep_max,ep_test
real ep_sav
real events
real f
real fkt
real fmcall
real g
real jacob
real kexp
real kfac
real mcfac
real mm2
real mm_exp,mm_cut
real mpfac
real mpi0
real mpip
real meta
real mpi_s
real myran
real nu
real phik
real ppx,ppy,ppz
real ppix,ppiy,ppiz
real phicm
real phicm_max
real phir
real px,py
real q0
real q2
real q2_min,q2_max,q2max
real qsq
real qvecx
real qvecz
real ran
real reg1,reg2,reg3,reg4
real rn1,rn2
real rotc,rots
real rtest
real s
real s1
real s2
real sigi
real sigl
real sigma
real sigma0
real signr
real sigr,sig_ratio
real sigr_max
real sigr1
real*8 sig_tot,sig_sum
real sigt
real sigu
real sigip, asym_p
real sntk
real sp
real spence
real stest
real t_elapse
real th0
real theta
real tk_max
real tp
real tries
real itime1, itime2
real ts
real uek
real uq2, uq2_min,uq2_max,uq2rng
real w2
real wreal, w_min_input
real x1
real x2
real targs,targp,xs,eloss,gxs,xtest,ebeam,t_targ,bfac,r_targ,temp
real sig_int, hydrogen_rad, vertex_x, vertex_y, vertex_z, vz
integer dismc(6,100)
integer intreg
integer epirea, th_opt, res_opt
integer i
integer ir1
c integer iext
integer j
integer jj
integer mcall
integer mcall_max
integer nprint,ntell,ntold
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
integer get_spin
integer flag_ehel
integer ehel
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
integer*4 idum
integer*4 ntries
real cfac,asig
c Parameters for the n-tuple, which is named func1 and contains
c 15 elements per event.
common /pawc/h(5000000)
integer h,n,nevent,nmax,lrecl,istat,icycle
parameter (n=32)
real*4 ntp(n)
c tag is the an array of names for the variables in the n-tuple.
c character*1 ich1
character*3 month
character*2 day
character*2 year
character*5 tag(n)
character*13 filerz
character*13 file_out
character*13 lund_out
character*13 file_sum
character*13 file_bos
character*8 recname
character*28 ctime
data tag /' ES ',' EP ','THETE',' W ','WREAL',
* ' PPX ',' PPY ',' PPZ ','EPROT','PPIX ',
* 'PPIY ','PPIZ ',' EPI ','CSTCM','PHICM',' MM ',' EG ',
* 'CSTHK','PHIK ', ' QX ',' QZ ',' Q0 ','CSTHE',' EGX ',
* ' EGY ',' EGZ ', ' VX ', ' VY ', ' VZ ', ' Q2 ',
* ' HEL ','ASYM '/
DATA PI /3.1415926/
DATA MPIP /.1395/
DATA MPI0 /.1349/
DATA META /.547853/
DATA MP /.938/
DATA MEL /.511E-3/
data filerz /'aao_rad.hbook'/
data file_out /'aao_rad.out'/
data lund_out /'aao_rad.lund'/
data file_sum /'aao_rad.sum'/
data file_bos /'aao_rad.bos'/
data ctime /' '/
do j=1,6
do i=1,100
dismc(j,i)=0
enddo
enddo
c set up parameters for breaking the monte-carlo integration region
c over csthk into 5 parts:
csrng=.04
c Region sizes suggested for 4 GeV: reg1=.23, reg2=.14, reg3=.11, reg4=.10
14 print *, 'Enter theory_opt,resonance_opt: (1=AO,4=MAID98,5=MAID2000)'
read(5,*) th_opt
c
print *, th_opt
print *, 'Enter 1 for polarized electron, 0 for unpolarized electron'
read(5,*) flag_ehel
c
print *, flag_ehel
res_opt = 0
print *, 'Input the sizes of the integration regions'
read(5,*)reg1,reg2,reg3,reg4
reg2 = reg1 + reg2
reg3 = reg2 + reg3
reg4 = reg3 + reg4
if (reg4 .gt. .95) then
write(6,*)' The sum of the region sizes must be less than .95'
go to 14
endif
alpha = 1/137.
c set up parameters for bos bank input to GSIM
print *, ' Input 2 for two charged particles in the bos bank'
print *, ' Input 4 to get the neutral hadron and photon as well'
read(5,*)npart
print *, ' Input=',npart
if (npart .ne. 4) npart=2
q(1) = -1
id(1) = 3 !Geant ID, e-
pdgid(1) = 11 !PDG ID, e-
if (npart .eq. 4)then
q(4) = 0
id(4) = 1 !Geant ID, photon
pdgid(4) = 22 !PDG ID, photon
endif
c
c Choose whether a neutral or charged pion is made in the reaction
5 print *, ' Input epirea (1 for pi0, 3 for pi+, 5 for eta)'
read(5,*)epirea
print *, 'epiarea=', epirea
print *, ' Input a limit on the error in (mm)**2'
read(5,*)mm_cut
print *, 'mm_cut=', mm_cut
IF(epirea.eq.1)then
MPI = MPI0
mm_exp = MPI0**2
id(2) = 14 !Geant ID, proton
q(2) = 1
pdgid(2) = 2212 !PDG ID, proton
if (npart .eq. 4)then
id(3) = 7 !Geant ID, pi-zero
pdgid(3) = 111 !PDG ID, pi-zero
q(3) = 0
endif
elseif(epirea.eq.3)then
MPI = MPIP
mm_exp = mp**2
id(2) = 8 !Geant ID, pi-plus
pdgid(2) = 211 !PDG ID, pi-plus
q(2) = 1
if (npart .eq. 4)then
id(3) = 13 !Geant ID, neutron
pdgid(3) = 2112 !PDG ID, neutron
q(3) = 0
endif
elseif(epirea.eq.5)then
MPI = META
mm_exp = META**2
id(2) = 14 !Geant ID, proton
q(2) = 1
pdgid(2) = 2212 !PDG ID, proton
if (npart .eq. 4)then
id(3) = 17 !Geant ID, eta-zero
pdgid(3) = 221 !PDG ID, pi-zero
q(3) = 0
endif
else
go to 5
endif
if (epirea .eq. 3)filerz(13:13)='p'
c Set single precision version of pion mass
mpi_s=mpi
c Calculate the minimum hadronic mass for pion production:
wg = mp + mpi + .0005
write(6,*)' Input the target thickness (cm)'
read(5,*)t_targ
print *, 't_target=', t_targ
write(6,*)' Input the target radius, (cm)'
read(5,*)r_targ
print *, 'r_target=', r_targ
write(6,*)' Input the x-coordinate of the beam position, (cm)'
read(5,*)vertex_x
write(6,*)' Input the y-coordinate of the beam position, (cm)'
read(5,*)vertex_y
write(6,*)' Input the z-coordinate of the beam position, (cm)'
read(5,*)vz
print *, 'VX,VY,VZ=', vertex_x,vertex_y,vertex_z
bfac = 4./3.
hydrogen_rad = 865 ! hydrogen radiation length (cm)
t_targ = bfac * t_targ / hydrogen_rad
write(6,*)' Input the incident electron energy (GeV)'
read(5,*)ebeam
print *, 'E beam=', ebeam
c calculate the incident momentum
es = ebeam
ps = sqrt(es**2-mel**2)
rs = ps/es
c cut off q2 at the value for 90 degree elastic scattering
s = 0.5
q2max = 4.*ebeam**2*s/(1.+2.*ebeam*s/mp)
c Choose two limits for Q**2
write(6,*)'Input lower and upper limit for Q**2'
read(5,*)q2_min,q2_max
print *, ' Q2 min max=', q2_min,q2_max
if (q2_max .gt. q2max) q2_max = q2max
uq2_min = 1/q2_max
uq2_max = 1/q2_min
uq2rng = uq2_max-uq2_min
c Set the limits on the range of scattered electron energies
write(6,*)'Input lower and upper limit for scat e- energy(GeV).'
read(5,*)ep_min,ep_max
print *, 'Eelectron min max', ep_min,ep_max
epmax = es - (wg**2 + q2_min - mp**2)/2./mp
if (ep_max .lt. epmax)epmax=ep_max
eprng = epmax - ep_min
c Choose a maximum value for the range of photon energies
write(6,*)' Input minimum photon energy for integration'
read(5,*)delta
print *, ' Min photon energy=', delta
c Select the number of events desired in the rz file
write(6,*)' Input the desired number of events in the ntuple'
read(5,*)nmax
print *, 'Number of events in the ntuple=', nmax
nprint = nmax/25
write(6,*)' Input a multiplication factor for sigr_max'
read(5,*)fmcall
print *, ' Factor=', fmcall
if (fmcall .eq. 0.)then
write(6,*)' Input sigr_max'
read(5,*)sigr_max
print *, 'sigr_max=', sigr_max
endif
c
if (th_opt .gt. 10) then
write(6,*)'W mininum input'
read(5,*) w_min_input
print *, 'W min=', w_min_input
endif
c
1 mcall_max = 0
ntold = 0
events = 0
c Use the internal clock to initialize the random number generator
call timex(itime1)
call getunixtime(idum)
call getasciitime(idum,ctime)
idum = -idum
month = ctime(5:7)
day = ctime(9:10)
year = ctime(23:24)
if (day(1:1).eq. ' ')then
ir1=48
day(1:1)=char(ir1)
endif
call date_and_time(values=timevals)
call random_seed(size=ssize)
write(6,*)'seed:',ssize
sseed(:) = timevals(8)
call random_seed(put=sseed)
c call random_number(rnd)
c write(6,*)'seed:',rnd
c call random_number(rnd)
c write(6,*)'seed:',rnd
c call random_number(rnd)
c write(6,*)'seed:',rnd
c write(6,*)'seed:',idum,' from start time ',ctime
nevent = 0
t_elapse = 0.
itime2 = itime1
ntries = 0
sig_int = 0.
sig_tot = 0.
c Name the output rz file according to meson type and beam energy.
c filerz=aaoradgen-pi0-1.6-0811.rz.0, for example.
open(unit=12,file=file_out)
open(unit=13,file=lund_out)
c Initialize BOS
bosout = file_bos
recname = 'MCEVENT'
Cvpk call bos_ini(recname)
c set up the ntuple file
print *,' set up the ntuple file'
lrecl = 1024
call hlimit(5000000)
call hropen(1,'aaoradgen',filerz,'n',lrecl,istat)
call hbookn(10,'func1',n,'aaoradgen',1000,tag)
open(unit=12,file=file_out)
write(12,*)' AO Calculation of Single Pion Production'
write(12,*)' Starting time:', ctime
write(12,*)' Epirea (1 for pi0, 3 for pi+, 5 for eta) =',epirea
write(12,*)' Target thickness =',t_targ*3./4.,' (r.l.)'
write(12,*)' Incident electron energy =',ebeam,' GeV'
write(12,*)' Electron Q**2 limits:',q2_min,q2_max
write(12,*)' Lower and upper limit for scattered electron',
* ' energy(GeV):',ep_min,epmax
write(12,*)' Minimum photon energy for integration (delta):',delta
c Use a new variable in place of ek. Let uek=exp(-kek*ek)
c ek=-(1/kexp)alog(uek). The factor of 5. was chosen empirically for kexp
c by looking at the ek spectrum for E0=1.6 GeV.
c Let uek range from 0 to 1. Then ek will range from 0 and infinity.
c This requires a jacobian. Jacobian=1./(kexp*uek)=(1./kexp)exp(kexp*ek)
kexp = 5.
if (fmcall .eq. 0.)then
write(6,*)' sigr_max from input data =',sigr_max
write(12,*)' sigr_max from input data =',sigr_max
go to 20
endif
c Do a preliminary calculation to estimate the maximum value
c of the integrand
c calculate the energy and momentum of the scattered electron,
c and calculate Q**2 at the delta mass, 1.232 GeV
10 q2 = q2_min
q0 = (1.232**2 - mp**2 + q2)/2./mp
if (th_opt.gt.10) then
q0 = (w_min_input**2 - mp**2 + q2)/2./mp
endif
ep = es-q0
pp = sqrt(ep**2 - mel**2)
rp = pp/ep
s = q2/4/es/ep
th0 = 2.*asin(sqrt(s))
theta = th0*180./pi
T0 = th0
snt0 = sin(th0)
cst0 = cos(th0)
c calculate kinematic quantities needed for the Mo and Tsai calculation
u0 = es - ep + mp
pu = sqrt(ps**2 + pp**2 - 2*ps*pp*cst0)
uu = u0**2 - pu**2
csths = (ps - pp*cst0)/pu
csthp = (ps*cst0 - pp)/pu
snths = sqrt(1. - csths**2)
snthp = sqrt(1. - csthp**2)
ts = acos(csths)
tp = acos(csthp)
qsq = q2
sp = es*ep - ps*pp*cst0
sigr_max = 0.
cstk1 = (es - ep*cst0)/(sqrt(es**2 + ep**2 - 2*es*ep*cst0))
cstk2 = (es*cst0 - ep)/(sqrt(es**2 + ep**2 - 2*es*ep*cst0))
csrnge = csrng
if ((1.-cstk1) .lt. csrnge) csrnge = 1.-cstk1
if ((cstk1-cstk2) .lt. 2.*csrnge) csrnge = 0.5*(cstk1-cstk2)
csrngb = csrng/40.
if (csrngb .gt. csrnge/5.) csrngb = csrnge/5.
delphi = pi/9.
phik = (myran()-0.5)*delphi
mpfac = delphi/2./pi
ek = delta
jacob = exp(kexp*ek)/kexp*(q2**2/(2*es*ep))
c
ehel = 0
if(flag_ehel.eq.1) ehel = 1
c
do i=1,10000
csthcm = 2.*(myran()-0.5)
phicm = 360.*myran()
csran = myran()
if (csran .gt. .3) then
cstk = 2.*csrngb*(myran()-0.5) + cstk1
else
cstk = 2.*csrngb*(myran()-0.5) + cstk2
endif
mcfac = csrngb /reg1
phik = (myran()-0.5)*delphi
mpfac = delphi/2./pi
Tk = acos(cstk)
sntk = sin(Tk)
sdotk = es*ek - ps*ek*cstk*csths - ps*ek*sntk*snths*cos(phik)
pdotk = ep*ek - pp*ek*cstk*csthp - pp*ek*sntk*snthp*cos(phik)
sigr = sigma(ek,Tk,csthcm,phicm,ehel)
sigr = sigr*mcfac*mpfac
sigr = sigr*jacob
if (sigr .gt. sigr_max) then
sigr_max = sigr
ek_max = ek
tk_max = Tk
csthcm_max = csthcm
phicm_max = phicm
endif
enddo
write(6,*)'sigr_max,ek_max,tk_max,csthcm_max,phicm_max',
* sigr_max,ek_max,tk_max,csthcm_max,phicm_max
write(12,*)'sigr_max,ek_max,tk_max,csthcm_max,phicm_max',
* sigr_max,ek_max,tk_max,csthcm_max,phicm_max
sigr_max = sigr_max*fmcall
25 write(6,*) ' sigr_max changed to ',sigr_max
write(12,*)' sigr_max changed to ',sigr_max
c %%%%%%%%%%%%%%%%%%% Main Calculation %%%%%%%%%%%%%%%%%%%%%%%
c Use a Monte-Carlo to calculate a distribution of nmax events
c distributed according to the Mo-Tsai integrand.
ehel = 0
20 continue
ntries = ntries+1
if(flag_ehel.eq.1) ehel = get_spin(idum)
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
hel = ehel
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c calculate the energy of the electron at the scattering point
c after making its way through the target. First, randomly
c choose the interaction point.
c Change from units of r.l. to cm
t_targ = hydrogen_rad * t_targ / bfac
targs = t_targ*myran()
c Change into proper coordinate system
vertex_z = vz + targs - t_targ / 2.0
c calculates the distance that the electron stays in the target
targp = r_targ/sin(T0)
temp = (t_targ - targs)/cos(T0)
if (temp .lt. targp) targp = temp
c Back to units of r.l.
t_targ = bfac * t_targ / hydrogen_rad
targs = bfac * targs / hydrogen_rad
targp = bfac * targp / hydrogen_rad
c Now calculate the radiation loss
22 xs = myran()
eloss = xs**(1./targs)
gxs = 1.-eloss
xtest = myran()
if (xtest.gt.gxs) go to 22
es = ebeam*(1.-eloss)
c Cut off the incident energy at e_s=ebeam/4.
if (es .lt. ebeam/4.) go to 20
ps = sqrt(es**2-mel**2)
rs = ps/es
uq2 = uq2_min+uq2rng*myran()
q2 = 1./uq2
c calculate the energy and momentum of the scattered electron,
c and calculate Q**2
ep = epmax-eprng*myran()
c check to see if the scattered electron energy is below the
c detector threshold
if (ep .lt. ep_min)go to 20
q0 = es-ep
s = q2/4/es/ep
c cut off scattering at 90 degree
if (s .gt. .5)go to 20
th0 = 2.*asin(sqrt(s))
theta = th0*180./pi
T0 = th0
snt0 = sin(th0)
cst0 = cos(th0)
c check to see if the scattered electron energy is above
c the pion threshold for this angle.
ep_test = (mp**2 + 2*mp*es - wg**2)/2./(mp + 2.*es*s)
if (ep .gt. ep_test)go to 20
pp = sqrt(ep**2-mel**2)
rp = pp/ep
qsq = q2
if (qsq .le. 0.)then
write(6,*)' Main-1:, qsq =',qsq
go to 20
endif
qvecx = -pp*sin(th0)
qvecz = ps - pp*cos(th0)
w2 = mp**2 + 2*mp*q0 - q2
if (w2 .lt. mp**2)go to 20
epw = sqrt(w2)
if (th_opt.gt.10) then
if (epw .lt. W_min_input) go to 20
else
if (epw .lt. wg+0.002)go to 20
endif
c calculate kinematic quantities needed for the Mo and Tsai calculation
u0 = es - ep + mp
pu = ps**2 + pp**2 - 2*ps*pp*cst0
if (pu .le. 0.)then
write(6,*)' Main-2, pu**2 =',pu
go to 20
endif
pu = sqrt(pu)
uu = u0**2 - pu**2
csths = (ps - pp*cst0)/pu
csthp = (ps*cst0 - pp)/pu
snths = 1.-csths**2
if (snths**2 .le. 0.)then
write(6,*)' Main-3: snths =',snths
go to 20
endif
snths = sqrt(snths)
snthp = 1.-csthp**2
if (snthp .le. 0.)then
write(6,*)' Main-4: snthp**2 =',snthp
go to 20
endif
snthp = sqrt(snthp)
ts = acos(csths)
tp = acos(csthp)
sp = es*ep - ps*pp*cst0
cstk1 = csths
cstk2 = csthp
csrnge = csrng
if (cstk1 .lt. cstk2)then
cstmp=cstk1
cstk1=cstk2
cstk2=cstmp
endif
if ((1.-cstk1) .lt. csrnge) csrnge=1.-cstk1
if ((cstk1-cstk2) .lt. 2.*csrnge) csrnge=0.5*(cstk1-cstk2)
csrngb = csrng/40.
if (csrngb .gt. csrnge/5.) csrngb=csrnge/5.
csran = myran()
rn1 = myran()
if (rn1 .gt. 0.5)then
rn1=1.
else
rn1=-1.
endif
rn2 = myran()
delphi = ps*cstk1*csrngb/pp/sqrt(1.-cst0**2)/sqrt(1.-cstk1**2)
if (delphi .lt. pi/9.) delphi=pi/9.
if (delphi .gt. 2.*pi) delphi=2.*pi
if (cstk1 .gt. .995) delphi=2.*pi
delphi = pi/9.
if (csran .lt. reg1)then
intreg = 1
cstk = cstk1+(2.*rn2-1.)*csrngb
mcfac = csrngb /reg1
phik = (myran()-0.5)*delphi
mpfac = delphi/2./pi
elseif(csran .lt. reg2)then
intreg = 2
cstk = cstk2+(2.*rn2-1.)*csrngb
mcfac = csrngb /(reg2-reg1)
phik = (myran()-0.5)*delphi
mpfac = delphi/2./pi
elseif(csran .lt. reg3)then
intreg = 3
cstk = cstk1+rn1*(csrngb+rn2*(csrnge-csrngb))
mcfac = (csrnge-csrngb) /(reg3-reg2)
phik = (myran()-0.5)*delphi
mpfac = delphi/2./pi
elseif(csran .lt. reg4)then
intreg = 4
cstk = cstk2+rn1*(csrngb+rn2*(csrnge-csrngb))
mcfac = (csrnge-csrngb) /(reg4-reg3)
phik = (myran()-0.5)*delphi
mpfac = delphi/2./pi
else
intreg = 5
45 cstk = 2.*rn2-1.
phik = 2.*pi*(myran()-0.5)
if (abs(cstk-cstk1) .lt. csrnge .or.
& abs(cstk-cstk2) .lt. csrnge) then
if(abs(phik).lt. delphi/2.) go to 45
endif
c combine mcfac and mpfac into one factor and set mpfac=1
mcfac=(1.-csrnge*delphi/pi)/(1.-reg4)
mpfac=1.
endif
Tk = acos(cstk)
sntk = sin(Tk)
c change the following on Jan. 19, 1999
c phran=myran()
c if (phran .lt. .2)then
c else
c 48 phik=2*pi*(myran()-0.5)
c if(abs(phik).lt. pi/180.)go to 48
c mpfac=1.25
c endif
c end of jan 19, 1999 correction
ekmax = 0.5*(uu - wg**2)/(u0 - pu*cstk)
if (ekmax .gt. ebeam)then
write(6,*)' Main-5: ekmax =',ekmax
ekmax=ebeam
endif
c choose ek by making a change of variables
78 uek = myran()
if (uek .lt. 0.1E-20)then
write(6,*)' Main-6: uek =',uek
go to 20
endif
ek = -alog(uek)/kexp
if (ek .gt. ekmax)go to 20
csthcm = -1.+2.*myran()
phicm = 360.*myran()
c********************************** Ek < Delta ****************************************
if (ek .lt. delta)then
intreg=6
c print *, th0,qsq,epw,csthcm,phicm
c calculate the non-radiative cross section
call dsigma(th0,qsq,epw,csthcm,phicm,th_opt,epirea,res_opt,sigma0
* ,sigu,sigt,sigl,sigi,sigip,asym_p,ehel)
if (sigma0.le.0.) go to 20
c PRINT *,'DSIGMA=',
c * th0,qsq,epw,csthcm,phicm,th_opt,epirea,res_opt,sigma0
c * ,sigu,sigt,sigl,sigi,sigip,asym_p,ehel
c print *, 'AAO_RAD s0,u,t,l,i:',sigma0,sigu,sigt,sigl,sigi
c if (abs(epw-1.232).lt.0.010.and.abs(qsq-0.35).lt.0.1) then
c print *, qsq,epw,csthcm,phicm
c print *, 'AO:',sigma0,sigu,sigl,sigt,sigi
c call dsigma(th0,qsq,epw,csthcm,phicm,4,epirea,res_opt,sigma0
c * ,sigu,sigt,sigl,sigi,sigip,asym_p,ehel)
c print *, 'MAID:',sigma0,sigu,sigl,sigt,sigi
c print *, ''
c endif
c %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c The AO program calculates sigu,sigl,sigt and sigi with
c the kinematic factors included. To convert them to the
c form needed for the above problem we must use
epeps = 1. + 2.*(1 + q0**2/qsq)*s/(1-s)
if (epeps .le. 1.)then
write(6,*)' Main-6: epeps-inv =',epeps
go to 20
endif
epeps = 1./epeps
kfac = (w2 - mp**2)/2./mp
c cfac=1/Gamma_T
c cfac=2*pi**2*qsq*(es/ep)*(1-epeps)/kfac/alpha
c sigu=sigu*cfac
c sigl=sigl*cfac
c sigt=sigt*cfac
c sigi=sigi*cfac
c %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c Mo and Tsai give a formula for the cross section in terms
c of amplitudes, f and g. Here we try to extract f and g
c from the AO cross section. I may not have this part right.
c sig0=4.*pi**2*alpha/mp**2
c The following would work if there were no polarization terms
c f=2.*kfac/(mp**3)*qsq/(qsq+q0**2)*(sigu+sigl)/sig0
c g=(2.*kfac/mp)*(sigu)/sig0
c I don\'t know what to do with the polarization terms: these give
c the dependence on the center of mass phi decay angle. I try
c the following:
nu = (w2 + qsq - mp**2)/2/mp
f = (1./(2*pi**2*alpha*mp))*(kfac/(1.+nu**2/qsq))*(sigu+sigl)
g = mp/(2*pi**2*alpha) * kfac * sigu
fkt = (w2-mp**2+mpi**2)/2./epw
fkt = sqrt(fkt**2-mpi**2)*2.*epw/(w2-mp**2)
f = f*fkt
g = g*fkt
c Calculate the non-radiative cross section
signr = 2*(alpha*ep/qsq)**2
& * (f*mp*cos(th0/2)**2+2*g*sin(th0/2)**2/mp)
c asig = fkt*(sigu+epeps*sigl)/cfac
c print *, 'Compare x-sections',signr,asig
c Modulate the cross section with the polarization and interference terms
signr = signr * (1.+(epeps*sigt*cos(phicm*pi/90.)
& + sqrt(epeps*(1.+epeps)/2)*sigi*cos(phicm*pi/180.)
& + ehel*sqrt(epeps*(1.-epeps)/2)*sigip*sin(phicm*pi/180.))
& /(sigu+epeps*sigl))
if (signr .le. 0.)then
write(6,*)'signr,sigu,sigl,sigt,sigi,epeps',
& signr,sigu,sigl,sigt,sigi,epeps
write(6,*)'qsq,epw,th0,csthcm,phicm,epirea',
& qsq,epw,th0,csthcm,phicm,epirea
endif
c Calculate the radiative correction factor deltar for the cross
c section. This includes vertex corrections and the integration
c up to photon energies of delta.
x1 = (ep-es)/ep
x2 = (es-ep)/es
s1 = spence(x1)
s2 = spence(x2)
deltar = -(alpha/pi)*(28./9. -(13./6.)*dlog(2.*sp/mel**2)
& -s1-s2)
delinf = -(alpha/pi)*dlog(es*ep/delta**2)*(dlog(2.*sp/mel**2)-1.)
sigr1 = signr*(1.+deltar)*exp(delinf)
c calculate average differential cross section in the region
c from ek=0 to delta, and from cos(thetak)=-1 to 1.
sigr = sigr1/delta/4./pi
if (sigr .gt. 0.) then
go to 28
else
go to 20
endif
c end of section for calculation with ek < delta.
c Normally, go to statement 28
endif
sdotk = es*ek - ps*ek*cstk*csths - ps*ek*sntk*snths*cos(phik)
pdotk = ep*ek - pp*ek*cstk*csthp - pp*ek*sntk*snthp*cos(phik)
sigr = sigma(ek,Tk,csthcm,phicm,ehel)
if (sigr .le. 0.) go to 20
28 jacob = exp(kexp*ek)/kexp/(2*es*ep)*q2**2
sigr = sigr*jacob
call missm(epirea,ebeam,es,ep,th0,ek,cstk,phik,mpi_s,
* ppx,ppy,ppz,eprot,ppix,ppiy,ppiz,epi,ekx,eky,ekz,
* csthcm,phicm,wreal,mm2)
if (abs(mm2-mm_exp) .gt. mm_cut)go to 20
c Compare sigr to the sigr_max to determine whether to generate
c an event.
sigr = mcfac*mpfac*sigr
sig_ratio = sigr/sigr_max
sig_tot = sig_tot + sigr
c Choose the number of times, mcall, to call the routine used
c to calculate kinematic quantities for the n-tuple.