-
Notifications
You must be signed in to change notification settings - Fork 0
/
glaubermc.f90
1178 lines (1023 loc) · 46.9 KB
/
glaubermc.f90
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
! *****************************************************************************
! * *
! * ECHO-QGP *
! * *
! * Version: 1.5.0-alpha *
! * *
! * Copyright (C) 2015,2016 The ECHO-QGP team *
! * *
! * File: glaubermc.f90 *
! * *
! * License: GPL version 2.0 (Please, read the file LICENSE.TXT) *
! * *
! * This program is free software; you can redistribute it and/or *
! * modify it under the terms of the GNU General Public License *
! * as published by the Free Software Foundation; either version 2 *
! * of the License, or (at your option) any later version. *
! * *
! * This program is distributed in the hope that it will be useful, *
! * but WITHOUT ANY WARRANTY; without even the implied warranty of *
! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
! * GNU General Public License for more details. *
! * *
! * You should have received a copy of the GNU General Public License *
! * along with this program; if not, write to the Free Software *
! * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
! * Boston, MA 02110-1301, USA. *
! * *
! * Authors: Andrea Beraudo ([email protected]) *
! * *
! * Contributors: Gabriele Inghirami ([email protected]) *
! * *
! * Acknowledgments: *
! * *
! *****************************************************************************
module glaubermc
use parallel
use common
implicit none
integer, parameter :: ntrials=10000000
real(8), parameter :: rmax=12.6d0 ! max radius of nucleons in fm
real(8), parameter :: rmaxd=16.d0 ! max radius of nucleons in deuteron in fm
real(8), parameter :: bmaxAA=20.d0 ! max b impact parameter in fm for AA collisions
real(8), parameter :: bmaxdA=20.d0 ! max b impact parameter in fm for dA collisions
real(8), parameter :: bmaxpA=13.d0 ! max b impact parameter in fm for pA collisions
integer :: nevent,ncoll,npart,npartA,npartB
real(8) ybeam
real(8) xpartA(300),ypartA(300) !they will be not more than nA, but why to avoid a bit larger sizes?
real(8) xspecA(300),yspecA(300)
integer part_typeA(300), part_typeB(300), spec_typeA(300), spec_typeB(300)
!for pA and dA 1 or 2 would be fine, but since they are not large arrays, let's avoid specific sizes for these cases
real(8) xpartB(300),ypartB(300)
real(8) xspecB(300),yspecB(300)
real(8) xcoll(90000),ycoll(90000) !they will be not more than nA^2, but usually they will be at maximum a few thousands
integer :: recl_partcoll_bin, recl_spectators_bin, recl_collisions_bin
type event_data
real(8) :: b
integer :: ncoll
integer :: npart
integer :: npartA
integer :: npartB
integer :: nspecA
integer :: nspecB
integer :: index_partcoll_bin
integer :: index_spectators_bin
integer :: index_collisions_bin
end type event_data
type(event_data),dimension(:),allocatable :: events_data
contains
! **************************************************************************
subroutine generate_events
! subroutines to generate events for Glauber-MC initial conditions
! IMPORTANT: please, note that this subroutine usually is executed only by process 0 (so, if you use mpi, you have to broadcast)
integer iseed
integer previous_seed
integer filerror, allocate_result,read_status
!change it from -1 to the random seed of a previous run to reproduce its initial conditions
integer i,j,iA,iB,ii,iimp,iconf !just counters DDD check if all of them are used
real(8), allocatable, dimension(:,:) :: xA, yA, zA, xB, yB, zB
real(8), allocatable, dimension(:,:) :: xcollAB, ycollAB, dsquare
real(8), allocatable, dimension(:) :: xAcoll, xBcoll, dndnpart ! coordinates displaced of +/- b/2
integer, allocatable, dimension(:) :: ipartA ,ipartB ! flag to label participants
integer, allocatable, dimension(:,:) :: icollAB ! flag to label collisions
integer nA,nA1,nA2
real(8) fmax
real(8) b,r,rd,r1,r2,xcos,rcos,theta,phi,rphi,xcmA,xcmB,ycmA,ycmB,sumxA,sumyA,sumxB,sumyB,bmax,phin,pxB,pyB
!for B field investigations
integer nspecA, nspecB !nucleon spectators in nuclei A and B
integer, allocatable, dimension(:) :: ispecA, ispecB !spectator nucleons
integer :: record_length_real, record_length_integer
integer :: idx_part, idx_spec, idx_coll, idp, ids, idc
inquire (iolength=record_length_real) fmax
inquire (iolength=record_length_integer) nA
!
recl_partcoll_bin=2*record_length_real+record_length_integer
recl_spectators_bin=2*record_length_real+record_length_integer
recl_collisions_bin=2*record_length_real
open(unit=14,status='replace',file='summary.dat',iostat=filerror)
if(filerror .ne. 0) then
print*, 'Impossible to create file summary.dat, leaving...'
end if
open(unit=16,status='replace',file='partcoll.dat',iostat=filerror)
if(filerror .ne. 0) then
print*, 'Impossible to create file partcoll.dat, leaving...'
end if
open(unit=17,status='replace',file='partcoll.bin',form='unformatted',access='direct',&
&recl=recl_partcoll_bin,iostat=filerror)
if(filerror .ne. 0) then
print*, 'Impossible to create file partcoll.bin, leaving...'
end if
open(unit=18,status='OLD',file='random_seed.dat',iostat=filerror)
if (filerror .ne. 0) then
call system_clock(iseed)
call srand(iseed)
open(unit=19,status='NEW',file='random_seed.dat',iostat=filerror)
if(filerror .ne. 0) then
print*, "ATTENTION, IT HAS NOT BEEN POSSIBLE TO STORE THE VALUE OF THE RANDOM SEED INTO THE FILE random_seed.dat"
else
print*,'New seed of the random number generator is:', iseed
write(19,*) iseed
close(19)
end if
else
read(18,*) iseed
close(18)
print*,'Old seed of the random number generator was:', iseed
call srand(iseed)
end if
! added for B field study
open(unit=20,status='replace',file='spectators.dat',iostat=filerror)
if(filerror .ne. 0) then
print*, 'Impossible to create file spectators.dat, leaving...'
end if
open(unit=21,status='replace',file='spectators.bin',form='unformatted',access='direct',&
&recl=recl_spectators_bin,iostat=filerror)
if(filerror .ne. 0) then
print*, 'Impossible to create file spectators.bin, leaving...'
end if
open(unit=22,status='replace',file='collisions.bin',form='unformatted',access='direct',&
&recl=recl_collisions_bin,iostat=filerror)
if(filerror .ne. 0) then
print*, 'Impossible to create file collisions.bin, leaving...'
end if
! formats to read parameter file (to update if necessary...)
007 format(10x,f10.5)
008 format(10x,i1)
012 format(10x,i2)
014 format(17x,f8.4,9x,f7.5,13x,f8.6,28x,f8.6,46x,i3)
017 format(10x,a5)
018 format(10x,i5)
019 format(13x,a15)
009 format(a40,f10.3)
010 format(a40,3f12.3)
011 format(a40,e10.2)
112 format(a40,i10)
113 format(a40,a20)
if(ienentr .ne. 0) then
write(*,*) 'Careful!!! This initialization assumes that ienentr&
&=0!! Please, stop the program, correct the parameters (usually, param.dat) file and&
&relaunch the simulation again...'
end if
nA=int(projmass)
nA1=nA
select case (kind_of_collision)
case(1)
nA2=nA
bmax=bmaxAA
case(2)
nA2=2
bmax=bmaxdA
case(3)
nA2=1
bmax=bmaxpA
case default
write(*,*) "Sorry, I was not able to understand which kind of collisions you wish to simulate..."
write(*,*) "Please, check the parameter COLLISION into the parameters (usually, param.dat) file."
call exit(1)
end select
if(kind_of_collision .eq. 3) then
allocate(xA(1:nconf,1:nA1),yA(1:nconf,1:nA1),zA(1:nconf,1:nA1),dsquare(1:nA1,1:nA2),ipartA(1:nA1),dndnpart(1:nA1),&
& stat=allocate_result)
if(allocate_result /=0) then
write(*,*) "Proc.0 - Error, I can't allocate one or more of the arrays for Glauber-MonteCarlo initialization..."
write(*,*) "(source file glaubermc.f08)"
call exit(1)
end if
xA=0.
yA=0.
zA=0.
dndnpart=0
else
allocate(xA(1:nconf,1:nA1),yA(1:nconf,1:nA1),zA(1:nconf,1:nA1),xB(1:nconf,1:nA2),yB(1:nconf,1:nA2),zB(1:nconf,1:nA2),&
& xcollAB(1:nA1,1:nA2), ycollAB(1:nA1,1:nA2),dsquare(1:nA1,1:nA2),ipartA(1:nA1),ipartB(1:nA2),icollAB(1:nA1,1:nA2),&
& xAcoll(1:nA1),xBcoll(1:nA2), ispecA(1:nA1),ispecB(1:nA2),stat=allocate_result)
if(allocate_result /=0) then
write(*,*) "Proc.0 - Error, I can't allocate one or more of the arrays for Glauber-MonteCarlo initialization..."
write(*,*) "(source file glaubermc.f08)"
call exit(1)
end if
xA=0.
yA=0.
zA=0.
xB=0.
yB=0.
zB=0.
end if
fmax=radius*radius*roze*2. ! to accept/reject
nevent=0
allocate(events_data(1:nconf),stat=allocate_result)
if(allocate_result /=0) then
write(*,*) "Proc.0 - Error, I can't allocate the array of events_data structures..."
write(*,*) "(source file glaubermc.f08 for Glauber-MonteCarlo initialization)"
call exit(1)
end if
! we consider the first n=zelectrons as protons, the rest as neutrons
do i=1,nconf !AAADDD the loop could include more lines of code instead of being repeated, left in this way for make easier
!direct comparison with previous versions of these subroutines
iA=0
! extract radial position of nucleons from WS
do j=1,ntrials
r1=rand()
r2=rand()
r=r1*rmax ! r1 within 0 and 1...
if (woods(r,radius,delta,roze).le.(fmax*r2)) then
continue
else
iA=iA+1
! evaluate x,y,z extracting angles
rcos=rand()
rphi=rand()
xcos=2.d0*rcos-1.d0
theta=acos(xcos)
phi=2.d0*pi*rphi
xA(i,iA)=r*sin(theta)*cos(phi)
yA(i,iA)=r*sin(theta)*sin(phi)
zA(i,iA)=r*cos(theta)
endif
if (iA.eq.nA) exit !exits frm the j cycle and re-enters the i cycle with another nuclear configuration
enddo !close j=1,ntrials cycle
end do !close i=1,conf cycle
select case(kind_of_collision)
case(1) !AA collisions
do i=1,nconf
! I extract then positions of nucleons in B
iB=0
! extract radial position of nucleons from WS
do j=1,ntrials
r1=rand()
r2=rand()
r=r1*rmax ! r1 within 0 and 1...
if (woods(r,radius,delta,roze).le.(fmax*r2)) then
continue
else
iB=iB+1
! evaluate x,y,z extracting angles
rcos=rand()
rphi=rand()
xcos=2.d0*rcos-1.d0
theta=acos(xcos)
phi=2.d0*pi*rphi
xB(i,iB)=r*sin(theta)*cos(phi)
yB(i,iB)=r*sin(theta)*sin(phi)
zB(i,iB)=r*cos(theta)
endif
if (iB.eq.nA) exit
enddo !close j=1,ntrials cycle
end do !close i=1,conf cycle
case(2) !dA collisions
do i=1,nconf
! I extract then positions of nucleons in B
iB=1 !we place the proton at the origin
xB(i,iB)=0.
yB(i,iB)=0.
zB(i,iB)=0.
! extract radial position of nucleons from WS
do j=1,ntrials
r1=rand()
r2=rand()
rd=r1*rmaxd ! r1 within 0 and 1...
if (hulten(rd).le.(0.3*r2)) then
continue
else
iB=iB+1
! evaluate x,y,z extracting angles
rcos=rand()
rphi=rand()
xcos=2.d0*rcos-1.d0
theta=acos(xcos)
phi=2.d0*pi*rphi
xB(i,iB)=rd*sin(theta)*cos(phi)
yB(i,iB)=rd*sin(theta)*sin(phi)
zB(i,iB)=rd*cos(theta)
endif
if (iB.eq.nA2) exit
enddo !close j=1,ntrials cycle
end do !close i=1,conf cycle
end select
do i=1,nconf
xcmA=0.
ycmA=0.
xcmB=0.
ycmB=0.
do j=1,nA1
xcmA=xcmA+xA(i,j)
ycmA=ycmA+yA(i,j)
end do
xcmA=xcmA/real(nA1,8) ! center-of-mass coordinates
ycmA=ycmA/real(nA1,8)
if(kind_of_collision .ne. 3) then
do j=1,nA2
xcmB=xcmB+xB(i,j)
ycmB=ycmB+yB(i,j)
enddo
xcmB=xcmB/real(nA2,8)
ycmB=ycmB/real(nA2,8)
end if
do j=1,nA1
! rewriting the coordinates in the cm frame
xA(i,j)=xA(i,j)-xcmA
yA(i,j)=yA(i,j)-ycmA
end do
if(kind_of_collision .ne. 3) then
do j=1,nA2
xB(i,j)=xB(i,j)-xcmB
yB(i,j)=yB(i,j)-ycmB
!write(12,*) xA(i,j),yA(i,j),xB(i,j),yB(i,j)
enddo
end if
end do !close i=1,conf cycle
nevent=0
iconf=1 !iconf and nevent have the same value, they are just set at different times, but they are equivalent
if(kind_of_collision .ne. 3) then
do while(iconf .le. nconf)
do iimp=1,nbcoll !start cycle nbcoll
! extract impact parameter
r1=rand()
r2=rand()
b=r1*bmax ! r1 within 0 and 1...
if ((.not. fixed_b) .and. (b.le.(bmax*r2*1.001))) then ! linear function
continue
else
if(fixed_b) b=bimpact
! shift the A and B positions along the x-axis
do i=1,nA1
xAcoll(i)=xA(iconf,i)+b/2.
end do
do i=1,nA2
xBcoll(i)=xB(iconf,i)-b/2.
enddo
npartA=0 ! at each AA coll initialize npartA and npartB to 0
npartB=0
ncoll=0 ! at each AA coll initialize ncoll to 0
! at each AA, dA or pA collision initialize flags to 0
ipartA=0 ! flag for participants
ipartB=0
icollAB=0 ! flag for collisions
!protons spectators
ispecA=0
ispecB=0
do iA=1,nA1
do iB=1,nA2
dsquare(iA,iB)=(xA(iconf,iA)-xB(iconf,iB)+b)**2+(yA(iconf,iA)-yB(iconf,iB))**2
if (dsquare(iA,iB).le.(sigma_in/pi)) then
ncoll=ncoll+1
ipartA(iA)=1
ipartB(iB)=1
icollAB(iA,iB)=1
xcollAB(iA,iB)=(xA(iconf,iA)+xB(iconf,iB))/2.
ycollAB(iA,iB)=(yA(iconf,iA)+yB(iconf,iB))/2.
endif
enddo
enddo
nspecA=0
do ii=1,nA1
npartA=npartA+ipartA(ii)
if(ipartA(ii) .eq. 0) then
nspecA=nspecA+1
ispecA(ii)=1
end if
end do
nspecB=0
do ii=1,nA2
npartB=npartB+ipartB(ii)
if(ipartB(ii) .eq. 0) then
nspecB=nspecB+1
ispecB(ii)=1
end if
enddo
npart=npartA+npartB
if ((ncoll.ge.1) .and. (npart .ge. min_participants)) then
nevent=nevent+1
write(14,*) 'ev=',nevent,' b=',b,' nc=',ncoll,' np=',npart, ' npA=',npartA, ' npB=',npartB, ' nspecA=',nspecA,&
&' nspecB=',nspecB
events_data(nevent)%b=b
events_data(nevent)%ncoll=ncoll
events_data(nevent)%npart=npart
events_data(nevent)%npartA=npartA
events_data(nevent)%npartB=npartB
events_data(nevent)%nspecA=nspecA
events_data(nevent)%nspecB=nspecB
if(nevent .eq. 1) then
events_data(nevent)%index_partcoll_bin=0
events_data(nevent)%index_spectators_bin=0
events_data(nevent)%index_collisions_bin=0
else
events_data(nevent)%index_partcoll_bin=events_data(nevent-1)%index_partcoll_bin+events_data(nevent)%npart
events_data(nevent)%index_spectators_bin=events_data(nevent-1)%index_spectators_bin+events_data(nevent)%nspecA&
&+events_data(nevent-1)%nspecB
events_data(nevent)%index_collisions_bin=events_data(nevent-1)%index_collisions_bin+events_data(nevent)%ncoll
end if
idx_part=events_data(nevent)%index_partcoll_bin
idx_spec=events_data(nevent)%index_spectators_bin
idx_coll=events_data(nevent)%index_collisions_bin
write(16,*) 'ev=',nevent,' b=',b,' nc=',ncoll,' np=',npart, ' npA=',npartA, ' npB=',npartB
if((nspecA .gt. 0) .or. (nspecB .gt. 0)) then
write(20,*) 'ev=',nevent,' b=', b, ' Aspectators=', nspecA,' Bspectators=', nspecB
end if
idp=0
ids=0
do iA=1,nA1
if (ipartA(iA).eq.1) then ! write participants of A
idp=idp+1
if(iA .le. zelectrons) then
write(16,*)'A',xAcoll(iA),yA(iconf,iA),'p'
write(17,rec=idx_part+idp) xAcoll(iA),yA(iconf,iA),0
else
write(16,*)'A',xAcoll(iA),yA(iconf,iA),'n'
write(17,rec=idx_part+idp) xAcoll(iA),yA(iconf,iA),1
end if
else if(ispecA(iA) .eq. 1) then
ids=ids+1
if(iA .le. zelectrons) then
write(20,*)'A',xAcoll(iA),yA(iconf,iA),'p'
write(21, rec=idx_spec+ids) xAcoll(iA),yA(iconf,iA),0
else
write(20,*)'A',xAcoll(iA),yA(iconf,iA),'n'
write(21, rec=idx_spec+ids) xAcoll(iA),yA(iconf,iA),1
end if
else
write(*,*) "Error found: a particle must be either a participant or a spectator..."
close(14)
close(16)
close(17)
close(20)
close(21)
close(22)
call exit(5)
end if
enddo
do iB=1,nA2
if (ipartB(iB).eq.1) then ! write participants of B
idp=idp+1
if(iB .le. zelectrons) then
write(16,*)'B',xBcoll(iB),yB(iconf,iB),'p'
write(17,rec=idx_part+idp) xBcoll(iB),yB(iconf,iB),0
else
write(16,*)'B',xBcoll(iB),yB(iconf,iB),'n'
write(17,rec=idx_part+idp) xBcoll(iB),yB(iconf,iB),1
end if
else if(ispecB(iB) .eq. 1) then
ids=ids+1
if(iB .le. zelectrons) then
write(20,*)'B',xBcoll(iB),yB(iconf,iB),'p'
write(21,rec=idx_spec+ids) xBcoll(iB),yB(iconf,iB),0
else
write(20,*)'B',xBcoll(iB),yB(iconf,iB),'n'
write(21,rec=idx_spec+ids) xBcoll(iB),yB(iconf,iB),1
end if
else
write(*,*) "Error found: a particle must be either a participant or a spectator..."
call exit(5)
close(14)
close(16)
close(17)
close(20)
close(21)
close(22)
endif
enddo
idc=0
do iA=1,nA1
do iB=1,nA2
if (icollAB(iA,iB).eq.1) then ! write collisions
idc=idc+1
write(16,*)'AB',xcollAB(iA,iB),ycollAB(iA,iB)
write(22,rec=idx_coll+idc) xcollAB(iA,iB),ycollAB(iA,iB)
endif
enddo
enddo
else
continue
endif
endif
enddo ! end of the iimp=1,nbcoll cycle
iconf=iconf+1
enddo ! end of the iconf=1,nconf cycle
else !begin case for pA collisions
do iconf=1,nconf
do iimp=1,nbcoll !start cycle nbcoll
! extract impact parameter
r1=rand()
r2=rand()
b=r1*bmax ! r1 within 0 and 1...
if ((.not. fixed_b) .and. (b.le.(bmax*r2*1.02))) then ! linear function
continue
else
if(fixed_b) b=bimpact
phin=rand()
phin=2.*pi*phin
pxB=b*cos(phin)
pyB=b*sin(phin)
npartA=0 ! at each AA coll initialize npartA to 0
ipartA=0 ! flag for participants
do iA=1,nA1
do iB=1,nA2
dsquare(iA,iB)=(xA(iconf,iA)-pxB)**2+(yA(iconf,iA)-pyB)**2
if (dsquare(iA,iB).le.(sigma_in/pi)) then
ipartA(iA)=1
endif
enddo
enddo
do ii=1,nA1
npartA=npartA+ipartA(ii)
end do
npart=npartA+1
if (npart .ge. 2) then
nevent=nevent+1
write(14,*) 'ev=',nevent,' b=',b,' np=',npart
dndnpart(npart)=dndnpart(npart)+1
write(16,*) 'ev=',nevent,' b=',b,' np=',npart
idp=0
do iA=1,nA1
if (ipartA(iA).eq.1) then ! write participants of A
idp=idp+1
if(iA .lt. zelectrons) then
write(16,*)'A',xA(iconf,iA),yA(iconf,iA),"p"
write(17,rec=idx_part+idp) xA(iconf,iA),yA(iconf,iA),0
else
write(16,*)'A',xA(iconf,iA),yA(iconf,iA),"n"
write(17,rec=idx_part+idp) xA(iconf,iA),yA(iconf,iA),1
end if
endif
enddo
write(16,*)'p',pxB,pyB
write(22,rec=idx_coll+idc) pxB,pyB
else
continue
endif
endif
enddo ! end of the iimp=1,nbcoll cycle
enddo ! end of the iconf=1,nconf cycle
end if !end case for pA collisions
close(14)
close(16)
close(20)
close(17)
close(21)
close(22)
! to uncomment if we want just to get the position of protons to compute an initial magnetic field
! write(*,*) 'Events generated. Run finished.'
! call exit(0)
end subroutine generate_events
! **************************************************************************
! Woods-Saxon distribution (no hard core!)
real(8) function woods(r,radius,delta,roze)
implicit none
real(8) r,roze,radius,delta
woods=r*r*roze/(exp((r-radius)/delta)+1.)
return
end
! **************************************************************************
! Hulten distribution (for deuteron)
real(8) function hulten(r)
implicit none
real(8) r
real(8), parameter :: a=0.228 !fm^-1
real(8), parameter :: b=1.118 !fm^-1
hulten=(exp(-a*r)-exp(-b*r))**2.
return
end
! **************************************************************************
real(8) function feta(etas)
implicit none
real(8) etas
real(8) half_deta
half_deta=deta/2.
if (abs(etas) .ge. ybeam) then
feta=0.
!the following is just an attemp to improve stability by avoiding jumps
!however, please notice that without cutting the energy density at ybeam,
!the profile designed in generate_energy has some issue
!DDD feta=exp(-((abs(etas)-half_deta)**2.)/(2.*(sigeta**2.)))*(4.**(ybeam-abs(etas)))
else
if (abs(etas) .le. half_deta) then
feta=1.
else
feta=exp(-((abs(etas)-half_deta)**2.)/(2.*(sigeta**2.)))
end if
end if
return
end
! **************************************************************************
subroutine generate_energy_density_profile(edens_array)
! program to plot the energy density
use system_eqgp
implicit none
! In the following:
! A: is the nucleus (usually Au), taken as right-moving
! B: is the second nucleus or the deuteron, taken as left-moving
! if one prefers the opposite kinematics, one has simply to invert the dependence on the rapidity
!convention for type of particles (part_type and spec_type): 0=proton, 1=neutron
real(8), allocatable, dimension(:,:,:) :: edens_array
character(3) event,impact,npart,AorB,numcoll,npartA,npartB
real(8) b,epart,ecoll,edenscoll,edenspart,epartcoll,edenspartA,edenspartB
real(8) xprot,yprot, ZZ_pA, AA_pA, ynucl, ycm, ecm, enucleus, eproton !variables used for the pA collisions case
integer i,ievrecord,numpart,ix,iy,iz,iev,ncoll,numpartA,numpartB
integer error_flag, allocate_result, opening_error
real(8) cmx, cmy, cmx_p, cmx_c, cmy_p, cmy_c
integer :: nucltype_bitbucket, index_partcoll_bin, index_collisions_bin, index_spectators_bin
iev=id_of_the_run
if(pe0) then !oly the first processor knows the data of the events
b=events_data(iev)%b
bimpact=b !it can change if the impact parameter is not fixed. We report and print this value in config_summary.dat
ncoll=events_data(iev)%ncoll
numpart=events_data(iev)%npart
numpartA=events_data(iev)%npartA
numpartB=events_data(iev)%npartB
index_partcoll_bin=events_data(iev)%index_partcoll_bin
index_collisions_bin=events_data(iev)%index_collisions_bin
end if
if(prl) then
call MPI_Bcast(b,1,mpi_realtype,0,icomm,ierr)
call MPI_Bcast(bimpact,1,mpi_realtype,0,icomm,ierr)
call MPI_Bcast(ncoll,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(numpart,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(numpartA,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(numpartB,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(index_partcoll_bin,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(index_collisions_bin,1,mpi_integer,0,icomm,ierr)
call MPI_Barrier(MPI_COMM_WORLD,ierr)
end if
error_flag=0
ybeam=log(rads/am)
cmx=0.
cmy=0.
cmx_p=0.
cmy_p=0.
cmx_c=0.
cmy_c=0.
if(kind_of_collision .eq. 3) then
yprot=log(2*eprot/am)
AA_pA=real(projmass,8)
ZZ_pA=real(zelectrons,8)
ynucl=yprot+log(ZZ_pA/AA_pA)
ycm=log(AA_pA/ZZ_pA)/2.d0
ecm=2*eprot*sqrt(ZZ_pA/AA_pA)
end if
if(pe0) then !only the first processor manages the files
open(unit=2,file='partcoll.bin',status='old',iostat=opening_error,access='direct',recl=recl_partcoll_bin)
if(opening_error .ne. 0) then
write(*,*) "Sorry, it was not possible to open the file partcoll.bin. Leaving..."
call exit(1)
end if
open(unit=3,file='collisions.bin',status='old',iostat=opening_error,access='direct',recl=recl_collisions_bin)
if(opening_error .ne. 0) then
write(*,*) "Sorry, it was not possible to open the file partcoll.bin. Leaving..."
call exit(1)
end if
write(*,*) "Reading event:", id_of_the_run
if(kind_of_collision .le. 2) then
do ievrecord=1,numpartA
read(2,rec=index_partcoll_bin+ievrecord) xpartA(ievrecord),ypartA(ievrecord), nucltype_bitbucket
enddo
do ievrecord=1,numpartB
read(2,rec=index_partcoll_bin+numpartA+ievrecord) xpartB(ievrecord),ypartB(ievrecord), nucltype_bitbucket
enddo
do ievrecord=1,ncoll
read(3, rec=index_collisions_bin+ievrecord) xcoll(ievrecord),ycoll(ievrecord)
end do
else
!read data for the pA case
do ievrecord=1,numpart
read(2,rec=index_partcoll_bin+ievrecord) xpartA(ievrecord),ypartA(ievrecord),nucltype_bitbucket
enddo
end if
end if !end if pe0
!processor 0 informs the other processors
if(prl) then
call MPI_Bcast(xpartA, numpartA, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(ypartA, numpartA, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(xpartB, numpartB, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(ypartB, numpartB, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(xcoll, ncoll, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(ycoll, ncoll, mpi_realtype, 0, icomm, ierr)
!call MPI_Barrier(MPI_COMM_WORLD,ierr)
end if
if(kind_of_collision .ne. 3) then
do i=1,numpartA
cmx_p=cmx_p+xpartA(i)
cmy_p=cmy_p+ypartA(i)
end do
do i=1,numpartB
cmx_p=cmx_p+xpartB(i)
cmy_p=cmy_p+ypartB(i)
end do
do i=1,ncoll
cmx_c=cmx_c+xcoll(i)
cmy_c=cmy_c+ycoll(i)
end do
cmx=((1-ah)*cmx_p+ah*cmx_c)/((1-ah)*(numpartA+numpartB)+ah*ncoll)
cmy=((1-ah)*cmy_p+ah*cmy_c)/((1-ah)*(numpartA+numpartB)+ah*ncoll)
do iz=iz1,iz2
do iy=iy1,iy2
do ix=ix1,ix2
edenspartA=0.
edenspartB=0.
do i=1,numpartA
edenspartA=edenspartA+exp(-((x(ix)-xpartA(i)+cmx)**2+(y(iy)-ypartA(i)+cmy)**2)/2./sig_mc**2)
enddo
do i=1,numpartB
edenspartB=edenspartB+exp(-((x(ix)-xpartB(i)+cmx)**2+(y(iy)-ypartB(i)+cmy)**2)/2./sig_mc**2)
enddo
edenspart=edenspartA*(ybeam+z(iz))/ybeam+edenspartB*(ybeam-z(iz))/ybeam
edenscoll=0.
do i=1,ncoll
edenscoll=edenscoll+exp(-((x(ix)-xcoll(i)+cmx)**2+(y(iy)-ycoll(i)+cmy)**2)/2./sig_mc**2)
enddo
edens_array(ix,iy,iz)=kappa/(2.d0*pi*sig_mc**2)*(ah*edenscoll+(1-ah)*edenspart)*feta(z(iz))
enddo
enddo
end do
else !case of pA collisions
do i=1,numpartA
cmx_p=cmx_p+xpartA(i)+xprot
cmy_p=cmy_p+ypartA(i)+yprot
end do
cmx=cmx_p/(numpartA+1)
cmy=cmy_p/(numpartA+1)
do iz=iz1,iz2
do iy=iy1,iy2
do ix=ix1,ix2
enucleus=0.
do i=1,numpart-1
enucleus=enucleus+exp(-((x(ix)-xpartA(i)+cmx)**2+(y(iy)-ypartA(i)+cmy)**2)/2./sig_mc**2)
enddo
eproton=exp(-((x(ix)-xprot+cmx)**2+(y(iy)-yprot+cmy)**2)/2./sig_mc**2)
edenspart=eproton*(ybeam+z(iz))/ybeam+enucleus*(ybeam-z(iz))/ybeam
edens_array(ix,iy,iz)=edenspart*kappa/2./pi/sig_mc**2*feta(z(iz))
enddo
enddo
end do
!end of case of pA collisions
end if
if(pe0) then
close(2)
close(3)
end if
end subroutine generate_energy_density_profile
! **************************************************************************
subroutine generate_B_field_profile()
! program to plot the energy density
use system_eqgp
implicit none
! In the following:
! A: is the nucleus (usually Au), taken as right-moving
! B: is the second nucleus or the deuteron, taken as left-moving
! if one prefers the opposite kinematics, one has simply to invert the dependence on the rapidity
!convention for type of particles (part_type and spec_type): 0=proton, 1=neutron
real(8), allocatable, dimension(:,:,:) :: edens_array
character(3) event,impact,npart,AorB,numcoll,npartA,npartB,nspecA,nspecB
real(8) b, tt, xcoord,ycoord,zcoord,zpos,vel, xt2, xt, D, sqrD, A, Bphi, Br, Bz, toMilne, toMilne_z, phi
real(8) xprot,yprot, ZZ_pA, AA_pA, ynucl, ycm, ecm, enucleus, eproton !variables used for the pA collisions case
integer i,ievrecord,numpart,ix,iy,iz,iev,ncoll,numpartA,numpartB,numspecA,numspecB
integer error_flag, allocate_result, opening_error
integer :: index_partcoll_bin, index_collisions_bin, index_spectators_bin
iev=id_of_the_run
if(pe0) then !oly the first processor knows the data of the events
b=events_data(iev)%b
ncoll=events_data(iev)%ncoll
numpart=events_data(iev)%npart
numpartA=events_data(iev)%npartA
numpartB=events_data(iev)%npartB
numspecA=events_data(iev)%nspecA
numspecB=events_data(iev)%nspecB
index_partcoll_bin=events_data(iev)%index_partcoll_bin
index_spectators_bin=events_data(iev)%index_spectators_bin
index_collisions_bin=events_data(iev)%index_collisions_bin
end if
if(prl) then
call MPI_Bcast(b,1,mpi_realtype,0,icomm,ierr)
call MPI_Bcast(ncoll,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(numpart,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(numpartA,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(numpartB,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(numspecA,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(numspecB,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(index_partcoll_bin,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(index_spectators_bin,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(index_collisions_bin,1,mpi_integer,0,icomm,ierr)
call MPI_Barrier(MPI_COMM_WORLD,ierr)
end if
error_flag=0
ybeam=log(rads/am)
if(pe0) then !only the first processor manages the files
open(unit=2,file='partcoll.bin',status='old',iostat=opening_error,access='direct',recl=recl_partcoll_bin)
if(opening_error .ne. 0) then
write(*,*) "Sorry, it was not possible to open the file partcoll.bin. Leaving..."
call exit(1)
end if
open(unit=3,file='collisions.bin',status='old',iostat=opening_error,access='direct',recl=recl_collisions_bin)
if(opening_error .ne. 0) then
write(*,*) "Sorry, it was not possible to open the file partcoll.bin. Leaving..."
call exit(1)
end if
open(unit=4,file='spectators.bin',status='old',iostat=opening_error,access='direct',recl=recl_spectators_bin)
if(opening_error .ne. 0) then
write(*,*) "Sorry, it was not possible to open the file spectators.bin. Leaving..."
call exit(1)
end if
write(*,*) "Reading event:", id_of_the_run
if(kind_of_collision .le. 2) then
do ievrecord=1,numpartA
read(2,rec=index_partcoll_bin+ievrecord) xpartA(ievrecord),ypartA(ievrecord), part_typeA(ievrecord)
enddo
do ievrecord=1,numpartB
read(2,rec=index_partcoll_bin+numpartA+ievrecord) xpartB(ievrecord),ypartB(ievrecord), part_typeB(ievrecord)
enddo
do ievrecord=1,ncoll
read(3,rec= index_collisions_bin+ievrecord) xcoll(ievrecord),ycoll(ievrecord)
end do
do ievrecord=1,numspecA
read(4,rec=index_spectators_bin+ievrecord) xspecA(ievrecord),yspecA(ievrecord), spec_typeA(ievrecord)
enddo
do ievrecord=1,numspecB
read(4,rec=index_spectators_bin+numspecA+ievrecord) xspecB(ievrecord),yspecB(ievrecord), spec_typeB(ievrecord)
enddo
else
!actually, this message should never be printed, because there is another check in init.f90 just before calling
!this subroutine
write(*,*) "Sorry, but the creation of B fields at runtime is not possible with pA collisions. I quit."
call exit(1)
end if
end if !end pe0
!processor 0 informs the other processors
if(prl) then
call MPI_Bcast(numpartA,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(numpartB,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(numspecA,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(numspecB,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(ncoll,1,mpi_integer,0,icomm,ierr)
call MPI_Bcast(xpartA, numpartA, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(ypartA, numpartA, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(xspecA, numspecA, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(yspecA, numspecA, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(xpartB, numpartB, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(ypartB, numpartB, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(xspecB, numspecB, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(yspecB, numspecB, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(xcoll, ncoll, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(ycoll, ncoll, mpi_realtype, 0, icomm, ierr)
call MPI_Bcast(spec_typeA, numspecA, mpi_integer, 0, icomm, ierr)