12.07.2015 Views

cg Version

cg Version

cg Version

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

KEK Internal 2011-5December 2011R/DLecture Notes ofResponse calculation of NaI detector(<strong>cg</strong> <strong>Version</strong>)H. Hirayama and Y. NamitoHigh Energy Accelerator Reserach Organization


cHigh Energy Accelerator Research Organization (KEK), 2011KEK Reports are available fromHigh Energy Accelerator Research Organization (KEK)1-1 Oho, Tsukuba-shIbaraki-ken, 305-0801JAPANPhone: +81-29-864-5137Fax: +81-29-864-4604E-mail: irdpub@mail.kek.jpInternet: http://www.kek.jp


Lecture Notes ofResponse calculation of NaI detector(<strong>cg</strong> <strong>Version</strong>)H. Hirayama and Y. NamitoHigh Energy Accelerator Reserach Organization


ContentsJapanese Parts 11 Combinatrial Geometry (CG) 22 Combinatrial Geometry (CG) 22.1 Body . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 ucnai<strong>cg</strong>v.f 53.1 CG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 64.1 : Step 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64.2 : Step 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74.3 : Step 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84.4 : Step 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94.5 : Step 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104.6 : Step 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104.7 : Step 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104.8 : Step 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.8.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124.9 : Step 9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134.10 Subroutine ausgab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144.11 Subroutine howfar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 ucnai.f ucnai<strong>cg</strong>v.f 156 166.1 NaI . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166.2 Ge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 177.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21English Parts 261 Combinatorial Geometry (CG) 271.1 Body Denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271.2 Region Denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271.3 Example of Region Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 Outlines of sample user code uc<strong>cg</strong> phantom.f 302.1 CG input data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30i


3 Details of user code 313.1 Main program: Step 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313.1.1 Include lines and specication statements . . . . . . . . . . . . . . . . . . . 313.1.2 open statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323.2 Step 2: Pegs5-call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323.3 Step 3: Pre-hatch-call-initialization . . . . . . . . . . . . . . . . . . . . . . . . . . 333.4 Step 4: Determination-of-incident-particle-parameters . . . . . . . . . . . . . . . 343.5 Step 5: hatch-call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353.6 Step 6: Initialization-for-howfar . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353.7 Step 7: Initialization-for-ausgab . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353.8 Step 8: Shower-call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353.8.1 Statistical uncertainty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373.8.2 Output of results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373.9 Subroutine ausgab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383.10 Subroutine howfar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394 Comparison of speed between ucnai.f and ucnai<strong>cg</strong>v.f 405 Exercise problems 405.1 Problem 1 : Calculation for NaI detector . . . . . . . . . . . . . . . . . . . . . . 405.2 Problem 2 : Ge detector calculation . . . . . . . . . . . . . . . . . . . . . . . . . 405.3 Problem 3 : Air ionization chamber calculation . . . . . . . . . . . . . . . . . . . 406 Answer for exercises 416.1 Problem 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416.2 Problem 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446.3 Problem 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45Appendix: Full listings of ucnai<strong>cg</strong>v.f 50ii


EGS5 (ucnai<strong>cg</strong>v.f)NaI (<strong>cg</strong> <strong>Version</strong>)(Japanese Parts)1


1 Combinatrial Geometry (CG)2 Combinatrial Geometry (CG)2.1 Body EGS CG [1] Body1. (RPP)x-, y- z-2. (SPH) V 3. (RCC) V H 4. (TRC) V H R1 R2 5. (TOR) V R1 R2 (n: x/y/z =1/2/3) 1 2 1=0, 2=2 Table 1: RPP # Xmin Xmax Ymin Ymax Zmin ZmaxSPH # Vx Vy Vz RRCC # Vx Vy Vz Hx Hy HzRTRC # Vx Vy Vz Hx Hy HzR1 R2TOR # Vx Vy Vz R1 R21 2 n2.2 body +, ; OR + body body ; body body body + ; body AND +1 +2 body 1 body 2 body 1 body 2 +1 ;2 body 1 body 2 body 1 body 2 Body OR OR OR OR 2


OR OR OR body + ; 2.3 (a)(b)(c)2I3(d)(e)J2K3Figure 1: Combinatorial Geometry 1 (body 2) (body 3) I( 1c) I I = +2OR + 3 I body 2 body 3 (K) ( J) J( 1d) J=+2; 3body 2 body 3 K( 2e) K=+33


ody 3 2 body + ; OR B23A1Figure 2: Use of OR operator.OR A B (body 1 3) (body 2) A=+1+2B=+3; 1OR+3; 2OR OR body 4


3 ucnai<strong>cg</strong>v.f ucnai<strong>cg</strong>v.f CG CG 43.1 CG 3 ROuter vacuum (region 6)Air region (region 5)Al Cover (region 3)Gap (region 2)NaI (region 1)1.253MeVPhoton-5.6 -0.6 -0.5 0.0 7.62 8.1213.12Quarz window(region 4)ZFigure 3: ucnai<strong>cg</strong>v.f RCC 1 0.00 0.0 0.0 0.00 0.07.62 3.81RCC 2 0.00 0.0 -0.5 0.00 0.08.12 4.31RCC 3 0.00 0.0 -0.6 0.00 0.08.72 4.41RCC 4 0.00 0.0 7.62 0.00 0.00.5 4.31RCC 5 0.00 0.0 -5.6 0.00 0.018.72 9.41RCC 6 0.0 0.0 -10.0 0.0 0.030.0 12.0ENDZ1 +1Z2 +2 -1Z3 +3 -2 -45


Z4 +4Z5 +5 -3Z6 +6 -5END1 0 2 3 4 01. 1.253MeV Z- (0.0, 0.0, -5.0) 2. CGview (egs5job.pic) (egs5job.out){ { { { { NaI 4 4.1 : Step 1egs5 Fortran egs5 parameter include common include egs5 include include/egs pegscommons/pegs auxcommons/egs5 1Mortran EGS4 egs5 include/egs5 h.fauxcommons/aux h.f parameter egs include implicit none! ------------! EGS5 COMMONs! ------------include 'include/egs5_h.f'! Main EGS "header" fileinclude 'include/egs5_bounds.f'include 'include/egs5_edge.f'include 'include/egs5_media.f'include 'include/egs5_misc.f'include 'include/egs5_switches.f'include 'include/egs5_uphiot.f'include 'include/egs5_useful.f'include 'include/randomm.f'1 egs5run egs5run.bat 6


include 'include/egs5 h.f' common include 2 include ! ----------------------! Auxiliary-code COMMONs! ----------------------include 'auxcommons/aux_h.f'include 'auxcommons/edata.f'include 'auxcommons/etaly1.f'include 'auxcommons/instuf.f'include 'auxcommons/lines.f'include 'auxcommons/watch.f'! Auxiliary-code "header" file! ------------------! <strong>cg</strong> related COMMONs! ------------------include 'auxcommons/geom_common.f' ! geom-common fileinteger irinn include CG CG common common/totals/* depe,deltae,spec(3,50),maxpictreal*8 depe,deltae,specinteger maxpict! Variables to scoreimplicit none open egs5 pegs5 pegs 7-26 close openpegs open 7-26 ! ----------! Open files! ----------open(6,FILE='egs5job.out',STATUS='unknown')open(4,FILE='egs5job.inp',STATUS='old')open(39,FILE='egs5job.pic',STATUS='unknown') 39 counters out(0) call 4.2 : Step 2 nmed Characteristic Dimensionpegs5 call medarr 24 24 24 Chracteristic Dimension (1 cm 1cm 1cm 1cm) nmed=4if(nmed.gt.MXMED) thenwrite(6,'(A,I4,A,I4,A/A)')* ' nmed (',nmed,') larger than MXMED (',MXMED,')',* ' MXMED in iclude/egs5_h.f must be increased.'stop2 EGS4 COMIN 7


end if! ==============call block_set! ==============! ---------------------------------! define media before calling PEGS5! ---------------------------------medarr(1)='NAImedarr(2)='ALmedarr(3)='QUARTZmedarr(4)='AIR-AT-NTPdo j=1,nmeddo i=1,24media(i,j)=medarr(j)(i:i)end doend do! Initialize some general variableschard(1) = 3.81d0 ! automatic step-size controlchard(2) = 0.1d0chard(3) = 0.5d0chard(4) = 5.0d0write(6,fmt="('chard =',5e12.5)") (chard(j),j=1,nmed)! -----------------------------------! Run KEK PEGS5 before calling HATCH! -----------------------------------write(6,100)100 FORMAT('PEGS5-call comes next'/)! ==========call pegs5! ==========4.3 : Step 3 npreci 3 CG CG data CG <strong>cg</strong> (6) geomgt call CG End of CG data ifto 39 PICT (CSTA-FREE CSTA) subroutine geomgt CG CG CEND <strong>cg</strong> nreg CG write(6,*) 'Read <strong>cg</strong>-related data'!-----------------------------------------------! initilize <strong>cg</strong> related parameter!-----------------------------------------------npreci=3 ! PICT data mode for CGView in free formatifti = 4ifto = 39''''! Input unit number for <strong>cg</strong>-data! Output unit number for PICTwrite(6,fmt="(' CG data')")call geomgt(ifti,6) ! Read in CG datawrite(6,fmt="(' End of CG data',/)")if(npreci.eq.3) write(ifto,fmt="('CSTA-FREE-TIME')")if(npreci.eq.2) write(ifto,fmt="('CSTA-TIME')")8


ewind ifticall geomgt(ifti,ifto)! Dummy call to write geom info for iftowrite(ifto,110)110 FORMAT('CEND')!--------------------------------! Get nreg from <strong>cg</strong> input data!--------------------------------nreg=izoninCG egs X anlux inseed ! Read material for each refion from egs5job.dataread(4,*) (med(i),i=1,nreg)! Set option except vacuum regiondo i=2,nreg-2if(med(i).ne.0) theniphter(i) = 1 ! Switches for PE-angle samplingiedgfl(i) = 1 ! K & L-edge fluorescenceiauger(i) = 0 ! K & L-Augeriraylr(i) = 0 ! Rayleigh scatteringlpolar(i) = 0 ! Linearly-polarized photon scatteringincohr(i) = 0 ! S/Z rejectioniprofr(i) = 0 ! Doppler broadeningimpacr(i) = 0 ! Electron impact ionizationend ifend do! --------------------------------------------------------! Random number seeds. Must be defined before call hatch! or defaults will be used. inseed (1- 2^31)! --------------------------------------------------------luxlev = 1inseed=1write(6,120) inseed120 FORMAT(/,' inseed=',I12,5X,* ' (seed for generating unique sequences of Ranlux)')! =============call rluxinit! =============4.4 : Step 4! Initialize the Ranlux random-number generator (1.253MeV) CG irin=0 irin irin=0 irin CG ! Define initial variables for incident particle normally incident! on the slabiqin=0! Incident particle charge - photonsekein=1.253 ! Incident particle kinetic energyxin=0.0! Source positionyin=0.0zin=-5.0uin=0.0! Moving along z axisvin=0.0win=1.0irin=0! Starting region (0: Automatic search in CG)wtin=1.0! Weight = 1 since no variance reduction used9


! pdf data for many sourcedeltae=0.05 ! Energy bin of response!-----------------------------------------! Get source region from <strong>cg</strong> input data!-----------------------------------------!if(irin.le.0.or.irin.gt.nreg) thencall srzone(xin,yin,zin,iqin+2,0,irin)if(irin.le.0.or.irin.ge.nreg) thenwrite(6,fmt="(' Stopped in MAIN. irin = ',i5)")irinstopend ifcall rstnxt(iqin+2,0,irin)end if4.5 : Step 5pegs emaxe hatch emaxe 0 subroutine hatch emaxe hatch emaxe = 0.D0 ! dummy value to extract min(UE,UP+RM).write(6,130)130 format(/' Call hatch to get cross-section data')! ------------------------------! Open files (before HATCH call)! ------------------------------open(UNIT=KMPI,FILE='pgs5job.pegs5dat',STATUS='old')open(UNIT=KMPO,FILE='egs5job.dummy',STATUS='unknown')write(6,140)140 FORMAT(/,' HATCH-call comes next',/)! ==========call hatch! ==========4.6 : Step 6 <strong>cg</strong> 4.7 : Step 7ausgab (50) Ncases maxpict ! Energy bin widthdeltae=ekein / 50! Zero the variablesdepe=0.D0pefs=0.D0pef2s=0.D0tefs=0.D0tef2S=0.D0do j=1,50phs(j)=0.D0ph2s(j)=0.D0do ntype=1,3spec(ntype,j)=0.D010


specs(ntype,j)=0.D0spec2s(ntype,j)=0.D0end doend do! Set historiesncases=10000! Set maximum number for pictmaxpict=504.8 : Step 8ncases subroutine shower call emaxe NaI wtin 99.9% wtin wtin ! Write batch numberwrite(39,fmt="('01')")! ========================if(iwatch.gt.0) call swatch(-99,iwatch)! ========================do i=1,ncases! ----------------------! Select incident energy! ----------------------wtin = 1.0wtsum = wtsum + wtinetot = ekein + iabs(iqin)*RMif(iqin.eq.1) thenavailke = ekein + 2.0*RMelseavailke = ekeinend iftotke = totke + availke! ----------------------! Select incident angle! ----------------------! -------------------------! Start of shower call-loop! -------------------------! Keep running sum of weights! Incident total energy (MeV)! Available K.E. (MeV) in system! for positron! Available K.E. (MeV) in system! for photon and electron! Keep running sum of KE! ---------------------------------------------------! Print first NWRITE or NLINES, whichever comes first! ---------------------------------------------------if (ncount .le. nwrite .and. ilines .le. nlines) thenilines = ilines + 1write(6,280) etot,xin,yin,zin,uin,vin,win,iqin,irin,idin280 FORMAT(7G15.7,3I5)end if! -----------------------------------------------------------! Compare maximum energy of material data and incident energy! -----------------------------------------------------------if(etot+(1-iabs(iqin))*RM.gt.emaxe) thenwrite(6,fmt="(' Stopped in MAIN.',1 ' (Incident kinetic energy + RM) > min(UE,UP+RM).')")stopend if11


! ----------------------------------------------------! Verify the normalization of source direction cosines! ----------------------------------------------------if(abs(uin*uin+vin*vin+win*win-1.0).gt.1.e-6) thenwrite(6,fmt="(' Following source direction cosines are not',1 ' normalized.',3e12.5)")uin,vin,winstopend if! ==========================================================call shower (iqin,etot,xin,yin,zin,uin,vin,win,irin,wtin)! ==========================================================! If some energy is deposited inside detector add pulse-height! and efficiency.if (depe .gt. 0.D0) thenie=depe/deltae + 1if (ie .gt. 50) ie = 50phs(ie)=phs(ie)+wtinph2s(ie)=ph2s(ie)+wtin*wtintefs=tefs + wtintef2s=tef2s + wtin*wtinif(depe .ge. ekein*0.999) thenpefs=pefs +wtinpef2s=pef2s +wtin*wtinend ifdepe = 0.D0end ifdo ntype=1,3do ie=1,50specs(ntype,ie)=specs(ntype,ie)+spec(ntype,ie)spec2s(ntype,ie)=spec2s(ntype,ie)+* spec(ntype,ie)*spec(ntype,ie)spec(ntype,ie)=0.D0end doend doncount = ncount + 1! ========================if(iwatch.gt.0) call swatch(-1,iwatch)! ========================end do! ========================if(iwatch.gt.0) call swatch(-88,iwatch)! ========================! Count total number of actual cases! -----------------------! End of CALL SHOWER loop! -----------------------call plotxyz(99,0,0,0.D0,0.D0,0.D0,0.D0,0,0.D0,0.D0)write(39,fmt="('9')")4.8.1 ! Set end of batch for CG Viewx ucnai<strong>cg</strong>v.f MCNP N xi i 12


x :x = 1 NNXxi (1)i=1 xi :s 2 = 1N ; 1NX(xi ; x) 2 ' x 2 ; x 2 (x 2 = 1 Ni=1NXi=1x 2 i ): (2) x s 2 x = 1 N s2 ' 1 N [x2 ; x 2 ] (3) sx ' [ 1 N (x2 ; x 2 )] 1=2 (4)4.9 : Step 9! -----------------------------------! Calculate average and its deviation! -----------------------------------! ---------------! Peak efficiency! ---------------avpe = pefs/ncountpef2s=pef2s/ncountsigpe=dsqrt((pef2s-avpe*avpe)/ncount)avpe = avpe*100.0sigpe = sigpe*100.0write(6,350) avpe,sigpe350 FORMAT(' Peak efficiency =',G11.4,'+-',G9.2,' %')! ----------------! Total efficiency! ----------------avte = tefs/ncounttef2s = tef2s/ncountsigte = dsqrt((tef2s-avte*avte)/ncount)avte = avte*100.0sigte = sigte*100.0write(6,360) avte,sigte360 FORMAT(' Total efficiency =',G11.4,'+-',G9.2,' %')! --------------------------! Pulse height distribution! --------------------------write(6,370)370 FORMAT(/' Pulse height distribution ')do ie=1,50elow=deltae*(ie-1)eup=deltae*ieavph = phs(ie)/ncountph2s(ie)=ph2s(ie)/ncount13


sigph=dsqrt((ph2s(ie)-avph*avph)/ncount)avph = avph/deltaesigph= sigph/deltaewrite(6,380) eup,avph,sigph380 FORMAT(' E (upper-edge --',G10.4,' MeV )=',G15.5,'+-',G15.5,* ' counts/MeV/incident')end do NaI 4.10 Subroutine ausgabAUSGAB include iarg < 5 1(NaI) wt maxpict plotxyz call ! ------------------------! Set some local variables! ------------------------irl = ir(np)iql = iq(np)edepwt = edep*wt(np)! -----------------------------------------------------------! Keep track of energy deposition (for conservation purposes)! -----------------------------------------------------------if (iarg .lt. 5) thenesum(iql+2,irl,iarg+1) = esum(iql+2,irl,iarg+1) + edepwtnsum(iql+2,irl,iarg+1) = nsum(iql+2,irl,iarg+1) + 1end if! -----------------------------------------------------------------! Print out particle transport information (if switch is turned on)! -----------------------------------------------------------------! ========================if (iwatch .gt. 0) call swatch(iarg,iwatch)! ========================if(iarg. .ge. 5) return! ----------------------------------------------! Score energy deposition inside NaI detector! ----------------------------------------------if (med(irl) .eq. 1) thendepe = depe + edepwt! ----------------------------------------------------! Score particle information if it enters from outside! ----------------------------------------------------if (irl .ne. irold .and. iarg .eq. 0) thenif (iql .eq. 0) then! photonntype=1ie = e(np)/deltae +1if(ie .gt. 50) ie = 50elseif (iql .eq. -1) then ! electronntype=2ie = (e(np) - RM)/deltae +1if(ie .gt. 50) ie = 50elsentype=3ie = (e(np) - RM)/deltae +1! positron14


if(ie .gt. 50) ie = 50end ifspec(ntype,ie) = spec(ntype,ie) + wt(np)end ifend if! ----------------------------------------------------------------! Print out stack information (for limited number cases and lines)! ----------------------------------------------------------------if (ncount .le. nwrite .and. ilines .le. nlines) thenilines = ilines + 1write(6,100) e(np),x(np),y(np),z(np),u(np),v(np),w(np),* iql,irl,iarg100 FORMAT(7G15.7,3I5)end if! ------------------------------------! Output particle information for plot! ------------------------------------if (ncount.le.maxpict) thencall plotxyz(iarg,np,iq(np),x(np),y(np),z(np),e(np),ir(np),* wt(np),time(np))end ifreturnend4.11 Subroutine howfarCG howfar howfar howfar howfar (idisc=1) 5 ucnai.f ucnai<strong>cg</strong>v.f <strong>cg</strong> howfar ucnai.f ucnai<strong>cg</strong>v.f ucnai.f 1.6 [2]15


6 6.1 NaI 1. Cs-137 (0.662MeV) 2. Co-60 1.173MeV 1.333MeV 3. 1.253MeV (Z-) 4. 1.253MeV 2 6.2 Ge Ge NaI 1.253MeV 6.3 20 1 1.253MeV 3 3 5mm AlAl 5cm W (33.97eV/pair) 1 (Coulomb/source)1:602 10 ;19 C/e 16


7 ucnai<strong>cg</strong>v.f 10000 (egs5job.out) ( nai.out) 7.1 1. Cs-137 cp ucnai<strong>cg</strong>v.f ucnai<strong>cg</strong>v1.fUNIX Cygwin DOS copy ucnai<strong>cg</strong>v.f ucnai<strong>cg</strong>v1.fWindows cp ucnai<strong>cg</strong>v.data ucnai<strong>cg</strong>v1.data cp ucnai<strong>cg</strong>v.inp ucnai<strong>cg</strong>v1.inp ucnai<strong>cg</strong>v1.f { ucnai<strong>cg</strong>v1.f ekein=1.253ekein=0.662 ucnai<strong>cg</strong>v1.f egs5run ! Incident particle kinetic energy! Incident particle kinetic energy{ Linux Cygwin ucnai<strong>cg</strong>v1 , 4 25 "Does this user code read from the terminal?" 1 { DOS egs5run ucnai<strong>cg</strong>v1{ ucnai<strong>cg</strong>v1 egs5run.bat DOS / Y= egs5job.out 1.253MeV (P e ) (T e )ucnai<strong>cg</strong>v 37.6 0.5 % 76.2 0.4 %ucnai<strong>cg</strong>v1 60.3 0.5 % 87.5 0.3 %2. Co-60 source cp ucnai<strong>cg</strong>v.f ucnai<strong>cg</strong>v2.f cp ucnai<strong>cg</strong>v.data ucnai<strong>cg</strong>v2.data cp ucnai<strong>cg</strong>v.inp ucnai<strong>cg</strong>v2.inp ucnai<strong>cg</strong>v2.f { 17


ekein=1.253ekein=1.333{ ! ----------------------! Select incident energy! ----------------------call randomset(rnnow)if(rnnow.le.0.5) thenekein=1.173elseekein=1.333end if{ ! Incident particle kinetic energy! Incident particle kinetic energywrite(6,340) ekein340 FORMAT(' Results for ',G15.5,'MeV photon'/)write(6,340)340 FORMAT(' Results for Co-60 gamma-ray (1.173 and 1.333 MeV)'/) ucnai<strong>cg</strong>v2.f egs5run { Linux Cygwin ucnai<strong>cg</strong>v2 , 4 25 "Does this user code read from the terminal?" 1 { DOS egs5run ucnai<strong>cg</strong>v2 egs5job.out 1.253MeV 2 3. cp ucnai<strong>cg</strong>v.f ucnai<strong>cg</strong>v3.f cp ucnai<strong>cg</strong>v.data ucnai<strong>cg</strong>v3.data cp ucnai<strong>cg</strong>v.inp ucnai<strong>cg</strong>v3.inp ucnai<strong>cg</strong>v3.f { 2 ! ----------------------! Select incident angle! ----------------------! ----------------------! Select incident angle! ----------------------275 call randomset(rnnow)zi0=rnnowcall randomset(rnnow)xi0=2.0*rnnow-1.0call randomset(rnnow)yi0=2.0*rnnow-1.0rr0=dsqrt(xi0*xi0+yi0*yi0+zi0*zi0)18


if(rr0.gt.1.0) go to 275win = zi0/rr0uin = xi0/rr0vin = yi0/rr0 ucnai<strong>cg</strong>v3.f egs5run { Linux Cygwin ucnai<strong>cg</strong>v3 , 4 25 "Does this user code read from the terminal?" 1 { DOS egs5run ucnai<strong>cg</strong>v3 CGview ""egs5job.pic egs5job.out : P e =3.6 0.2 %, T e =9.3 0.3 %4. 2 NaI cp ucnai<strong>cg</strong>v.f ucnai<strong>cg</strong>v4.f cp ucnai<strong>cg</strong>v.data ucnai<strong>cg</strong>v4.data cp ucnai<strong>cg</strong>v.inp ucnai<strong>cg</strong>v4.inp ucnai<strong>cg</strong>v4.f { tdet=7.62tdet=7.62*2.0{ CG CG ucnai<strong>cg</strong>v4.data ucnai<strong>cg</strong>v4.data RCC 1 0.00 0.0 0.0 0.00 0.015.24 3.81RCC 2 0.00 0.0 -0.5 0.00 0.015.74 4.31RCC 3 0.00 0.0 -0.6 0.00 0.016.34 4.41RCC 4 0.00 0.0 15.24 0.00 0.00.5 4.31RCC 5 0.00 0.0 -5.6 0.00 0.026.34 9.41RCC 6 0.0 0.0 -10.0 0.0 0.036.74 12.0ENDZ1 +1Z2 +2 -1Z3 +3 -2 -4Z4 +4Z5 +5 -3Z6 +6 -5END1 0 2 3 4 0 ucnai<strong>cg</strong>v4.data 19


ROuter vacuum (region 6)Air region (region 5)Al Cover (region 3)Gap (region 2)NaI (region 1)1.253MeVPhoton-5.6 -0.6 -0.5 0.0 15.24Quarz window(region 4)15.7420.74ZFigure 4: Geometry of ucnai<strong>cg</strong>v4.f90{ CGview ""{ "" ucnai<strong>cg</strong>v4.data { { """" ucnai<strong>cg</strong>v4.f egs5run { Linux Cygwin ucnai<strong>cg</strong>v4 , 4 25 "Does this user code read from the terminal?" 1 { DOS egs5run ucnai<strong>cg</strong>v4 CGview ""egs5job.pic 2 egs5job.out : P e =55.1 0.5%, T e =94.3 0.2 %7.2 1. cp ucnai<strong>cg</strong>v.f ucnai<strong>cg</strong>v5.f2. cp ucnai<strong>cg</strong>v.data ucnai<strong>cg</strong>v5.data3. cp ucnai<strong>cg</strong>v.inp ucnai<strong>cg</strong>v5.inp4. ucnai<strong>cg</strong>v5.f 20


medarr(1)='NAI'medarr(1)='GE' medarr 24 5. ucnai<strong>cg</strong>v5.inp COMP&INP NE=2,RHO=3.67, PZ=1,1,IRAYL=1 /ENDNAINAINA IELEM&INP IRAYL=1 /ENDGEGEGE(1 2 GE 31 )6. ucnai<strong>cg</strong>v5.f egs5run Linux Cygwin ucnai<strong>cg</strong>v5 , 4 25 "Does this user code read from the terminal?" 1 DOS egs5run ucnai<strong>cg</strong>v57. egs5job.out NaI : P e =41.1 0.5 %, T e =88.1 0.3 %7.3 1. cp ucnai<strong>cg</strong>v.f ucion<strong>cg</strong>v.f2. cp ucnai<strong>cg</strong>v.data ucion<strong>cg</strong>v.data3. cp ucnai<strong>cg</strong>v.inp ucion<strong>cg</strong>v.inp4. ucion<strong>cg</strong>v.f * xi0,yi0,zi0* xi0,yi0,zi0,avab,depes,depe2s,sigab nmed=421


nmed=2 medarr(1)='NAImedarr(2)='ALmedarr(3)='QUARTZmedarr(4)='AIR-AT-NTP''''medarr(1)='AIR-AT-NTPmedarr(2)='AL chard chard(3) = 0.5d0chard(4) = 5.0d0 ! Zero the variablesdepe=0.D0! Zero the variablesdepe=0.D0depes=0.D0depe2s=0.D0 100,000 ! Set historiesncases=10000 o! Set historiesncases=100000 if (depe .gt. 0.D0) thenie=depe/deltae + 1if (depe .gt. 0.D0) thendepes=depes+depedepe2s=depe2s+depe*depeie=depe/deltae + 1 ''22


tdet=7.62rdet=3.81tcov=0.1rtcov=0.1tgap=0.5rtgap=0.5write(6,330) tdet,rdet,tcov,rtcov,tgap,rtgap330 FORMAT(/' Detector length=',G15.5,' cm'/* ' Detector radius=',G15.5,' cm'/* ' Al cover thickness=',G10.2,' cm'/* ' Al cover side thickness=',G10.2,' cm'/* ' Front gap =',G10.2,' cm'/' Side gap =',G10.2,' cm'/)tdet=7.62rdet=3.81tcov=0.5rtcov=0.5write(6,330) tdet,rdet,tcov,rtcov330 FORMAT(/' Detector length=',G15.5,' cm'/* ' Detector radius=',G15.5,' cm'/* ' Al cover thickness=',G10.2,' cm'/* ' Al cover side thickness=',G10.2,' cm'/) ! --------------------------! Pulse height distribution! --------------------------write(6,370)! ----------------------! Absorbed energy in air! ----------------------avab = depes/ncountdepe2s = depe2s/ncountsigab = sqrt((depe2s - avab*avab)/ncount)write(6,362) avab,sigab362 FORMAT(' Absorbed energy in air =',G10.3,'+-',G9.2,' MeV/photon')avab = avab /33.97D-6 *1.602D-19sigab= sigab /33.97D-6 *1.602D-19write(6,364) avab,sigab364 FORMAT(' Output current =',G10.3,'+-',G9.2,' C/photon')! --------------------------! Pulse height distribution! --------------------------write(6,370) ausgab if (med(irl) .eq. 1) thendepe = depe + edepwtif (irl .eq. 1) thendepe = depe + edepwt23


ROuter vacuum (region 4)Air region (region 3)Al Cover (region 2)Air (region 1)1.253MeVPhoton13.12Z-0.5 0.0 8.127.62-5.5Figure 5: Geometry of ucion<strong>cg</strong>v.f5. ucion<strong>cg</strong>v.data RCC 1 0.00 0.0 0.0 0.00 0.07.62 3.81RCC 2 0.00 0.0 -0.5 0.00 0.08.62 4.31RCC 3 0.00 0.0 -5.5 0.00 0.018.62 9.31RCC 4 0.00 0.0 -6.0 0.00 0.020.62 10.31ENDZ1 +1Z2 +2 -1Z3 +3 -2Z4 +4 -3END1 2 1 06. ucion<strong>cg</strong>v.inp MIXT&INP NE=3,RHO= 1.2929E-03,RHOZ= 0.755,0.232,0.013,GASP=0.93174, IRAYL=1 /ENDAIR-AT-NTPAIR-GASN O ARENER&INP AE=0.521,AP=0.010,UE=2.511,UP=2.0 /ENDPWLF&INP /ENDDECK&INP /ENDELEM24


&INP IRAYL=1 /ENDALALALENER&INP AE=0.521,AP=0.010,UE=2.511,UP=2.0 /ENDPWLF&INP /ENDDECK&INP /END7. ucion<strong>cg</strong>v.f egs5run Linux Cygwin ucion<strong>cg</strong>v , 4 25 "Does this user code read from the terminal?" 1 DOS egs5run ucion<strong>cg</strong>v8. CGview egs5job.pic NaI 9. egs5job.out References P e (%) 0.0 T e (%) 0.73 0.3e-1 (MeV/) 0.15e-3 0.7e-5 (C/)0.69e-18 0.3e-19[1] T. Torii and T. Sugita, \Development of PRESTA-CG Incorprating Combinatorial Geometryin EGS4/PRESTA", JNC TN1410 2002-201, Japan Nuclear Cycle DevelopmentInstitute (2002).[2] T. Sugita, T. Torii, A. Takamura, \Incorporating Combinatorial Geometry to the EGS5Code and Its Speed-Up", Twelfth EGS User's Meeting in Japan, KEK Proc. 2005-10, 7-21,(KEK, Tsukuba, 9 - 11 Aug. 2005).25


EGS5 sample user code (ucnai<strong>cg</strong>v.f)Response calculation of NaI detector(<strong>cg</strong> <strong>Version</strong>)(English Parts)26


1 Combinatorial Geometry (CG)1.1 Body DenitionFollowing bodies are supported in CG for EGS [1] .1. Rectangular Parallelepiped (RPP)Specify the maximum and minimum values of x-, y-, and z-coordinates that bound arectangular parallelepiped whose six sides are perpendicular to the coordinate axis.2. Sphere (SPH)Specify the components of the radius vector V to the center of sphere and the radius R ofthe sphere.3. Right Circular Cylinder (RCC)Specify the components of a radius vector V to the center of one base, the components ofavector H from the center of that base to the other base, and the radius of the cylinder.4. Truncated Right Angle Cone (TRC)Specify the components of a radius vector V to the center of one base, the components ofa vector H from the center of that base to the center of the other base, and the radii R1and R2 of the lower and upper bases, respectively.5. Torus (TOR)Specify the components of a radius vector V to the center of the torus, and the torus iscongured parallel to one of the axis. R1 is the length between the center of torus andthe center of tube, and R2 is the radius of the tube. Also, input the direction number oftorus (n: x/y/z = 1/2/3). Furthermore, input starting angle 1 and ending angle 2 ofthe sector for the calculation of a part of torus. For the calculation of \complete" torus,set 1=0, and 2=2, respectively.Table 1: Data required to described each body type.Body Type Number Real Data Dening Particular BodyRPP # Xmin Xmax Ymin Ymax Zmin ZmaxSPH # Vx Vy Vz RRCC # Vx Vy Vz Hx Hy HzRTRC # Vx Vy Vz Hx Hy HzR1 R2TOR # Vx Vy Vz R1 R21 2 n1.2 Region DenitionThe basic technique for description of the geometry consists of dening the location and shapeof the various zones in term of the intersections and unions of the geometric bodies. Here, regionand zone are used as the same meaning. A special operator notations involving the symbols(+), (;), and (OR) is used to describe the intersections and unions. These symbols are used bythe program to construct information relating material descriptions to the body denitions.If a body appears in a region description with a (+) operator, it means that the region beingdescribed is wholly contained in the body. If a body appears in a region description with a (;)27


operator, it means that the region being described is wholly outside the body. If body appearswith an (OR) operator, it means that the region being described includes all points in the body.OR may be considered as a union operator. In some instances, a region may be described interms of subregion lumped together by (OR) statements. Subregions are formed as intersectsand then the region is formed by union of these subregions. When (OR) operators are usedthere are always two ormoreof them, and they refer to all body numbers following them, either(+) or (;). That is, all body numbers between \OR's" or until the end of the region cards forthat region are intersected together before OR's are performed.(a)(b)(c)2I3(d)(e)J2K3Figure 1: Examples of Combinatorial Geometry Method.1.3 Example of Region DescriptionConsider an object composed of a sphere and a cylinder as shown in Fig. 1. To describe theobject, one takes a spherical body (2) penetrated by a cylindrical body (3) (see Fig. 1). If thematerials in the sphere and cylinder are the same, then they can be considered as one region,say region I (Fig. 1c). The description of region I would beI = +2OR + 3:This means that a point is in region I if it is either body 2 or inside body 3.28


If dierent material are used in the sphere and cylinder, then the sphere with a cylindricalhole in it would be given a dierent region number (say J) from one cylinder (K).The description of region J would be (Fig. 1d):J=+2; 3:This means that points in region J are all those points inside body 2 which are not inside body3.The description if region K is simply (Fig. 2e):K=+3:That is, all points in region K lie inside body 3.Combination of more than two bodies and similar region descriptions could contain a longstring of (+), (;), and (OR) operators. It is importanthowever to remember that every spatialpoint in the geometry must be located in one and only one region.As a more complicated example of the use of the (OR) operator, consider the system shownin Fig. 2 consisting of the shaded region A and the unshaded region B. These regions can bedescribed by the two BOX's, bodies 1 and 3, and the RCC, body 2. The region descriptionwould beA=+1+2andB=+3; 1OR + 3 ; 2:Notice that OR operator refers to all following body numbers until the next OR operator isreached.B23A1Figure 2: Use of OR operator.29


2 Outlines of sample user code uc<strong>cg</strong> phantom.fucnai<strong>cg</strong>v.f is the egs5 user code to calculate the NaI detector response using CG. Input dataof CG are written on the input data read from unit 4.2.1 CG input dataGeometry are dened by the combination of several cylinders as shown in Fig. 3.The input data for this geometry can be written as follows.RCC 1 0.00 0.0 0.0 0.00 0.07.62 3.81RCC 2 0.00 0.0 -0.5 0.00 0.08.12 4.31RCC 3 0.00 0.0 -0.6 0.00 0.08.72 4.41RCC 4 0.00 0.0 7.62 0.00 0.00.5 4.31RCC 5 0.00 0.0 -5.6 0.00 0.018.72 9.41RCC 6 0.0 0.0 -10.0 0.0 0.030.0 12.0ENDZ1 +1Z2 +2 -1Z3 +3 -2 -4Z4 +4Z5 +5 -3Z6 +6 -5END1 0 2 3 4 0ROuter vacuum (region 6)Air region (region 5)Al Cover (region 3)Gap (region 2)NaI (region 1)1.253MeVPhoton-5.6 -0.6 -0.5 0.0 7.62 8.1213.12Quarz window(region 4)ZFigure 3: Geometry of ucnai<strong>cg</strong>v.f30


1. Source conditions Source photon energy is 1.253 MeV. Pencil beam normally along Z-axis to a point of (0.0, 0.0, -5.0).2. Results obtained(a) Particle trajectory data (egs5job.pic)(b) Calculated result (egs5job.out) Material data used in the calculation. Information set to each region. Peak and total eciency of the detector and their uncertainties. Detector response. Particle spectra entering to NaI detector region.3 Details of user code3.1 Main program: Step 13.1.1 Include lines and specication statementsegs5 is written in Fortran 77. The size of arguments is dened in other les and included byusing 'include line'. Various commons used inside egs5 are also included by the same way.Include les related with egs5 are put on the include directory and those related with pegs5are put on the pegscommons directory. Those for each user code including geometry related areput on the auxcommons directory. These les are linked by running egs5run script.This is the most dierent feature with EGS4 at which the size of arguments can be modiedinside an user code with Mortran macro. If it is necessary to modify the size of argumentsused in egs5, you must modify the related parameter in 'egs5/include/egs5 h.f'. The parametersrelated to each user code are dened in 'egs5/auxcommons/aux h.f'.First parts is include lines related egs5.implicit none! ------------! EGS5 COMMONs! ------------include 'include/egs5_h.f'include 'include/egs5_bounds.f'include 'include/egs5_edge.f'include 'include/egs5_media.f'include 'include/egs5_misc.f'include 'include/egs5_switches.f'include 'include/egs5_uphiot.f'include 'include/egs5_useful.f'include 'include/randomm.f'! Main EGS "header" fileinclude 'include/egs5 h.f' is always necessary. Other parts are only necessary whenvariables included in each common are used inside the main program. 1Next is include lines not directly related to egs5 like geometry related.! ----------------------! Auxiliary-code COMMONs! ----------------------include 'auxcommons/aux_h.f'! Auxiliary-code "header" file1 This is corresponding to COMIN macros in EGS4.31


include 'auxcommons/edata.f'include 'auxcommons/etaly1.f'include 'auxcommons/instuf.f'include 'auxcommons/lines.f'include 'auxcommons/watch.f'! ------------------! <strong>cg</strong> related COMMONs! ------------------include 'auxcommons/geom_common.f' ! geom-common fileinteger irinnThe last include statement is related to CG.common used inside the user code is dened next.common/totals/* depe,deltae,spec(3,50),maxpictreal*8 depe,deltae,specinteger maxpict! Variables to scoreBy implicit none at the top, it is required to declare all data by atype declaration statement.3.1.2 open statementAt the top of executable statement, it is necessary to open les used in the user code. Dueto the new feature that pegs is called inside each user code, user must be careful to the unitnumber used. The unit number from 7 to 26 are used inside 'pegs' and close at the end of 'pegs'.These units, therefore, must be re-open after calling pegs. It is better not to use these unit inthe user code. The unit used in the subroutine 'plotxyz' and 'geomout' used to keep and outputtrajectory information is changed from '9' to '39' for this reason.! ----------! Open files! ----------open(6,FILE='egs5job.out',STATUS='unknown')open(4,FILE='egs5job.inp',STATUS='old')open(39,FILE='egs5job.pic',STATUS='unknown')counters out is the subroutine to set various counters to 0.3.2 Step 2: Pegs5-callDene the number of materials used in the user code as nmed.Material names used in egs are dened after initialize some general variables by callingsubroutine block set. The material name dened here must be included in the materialproduced by pegs5 using input data read from unit 25. Data of 24 characters should be suppliedfor each lineofmedarr.Characteristic dimension which is related to the minimum region size like diameter, lengthor thickness for each material is set as chard.Subroutine pegs5 is called after above setting.nmed=4if(nmed.gt.MXMED) thenwrite(6,'(A,I4,A,I4,A/A)')* ' nmed (',nmed,') larger than MXMED (',MXMED,')',* ' MXMED in iclude/egs5_h.f must be increased.'stopend if! ==============32


call block_set! ==============! ---------------------------------! define media before calling PEGS5! ---------------------------------medarr(1)='NAImedarr(2)='ALmedarr(3)='QUARTZmedarr(4)='AIR-AT-NTPdo j=1,nmeddo i=1,24media(i,j)=medarr(j)(i:i)end doend do! Initialize some general variableschard(1) = 7.62d0 ! automatic step-size controlchard(2) = 0.1d0chard(3) = 0.5d0chard(4) = 5.0d0write(6,fmt="('chard =',5e12.5)") (chard(j),j=1,nmed)! -----------------------------------! Run KEK PEGS5 before calling HATCH! -----------------------------------write(6,100)100 FORMAT(' PEGS5-call comes next'/)! ==========call pegs5! ==========3.3 Step 3: Pre-hatch-call-initializationThe npreci is used to specify format for particle trajectories data and it is set to 2 in this usercode for CGview. After initializing CG related parameters, subroutine geomgt is called toread CG input data and output CG information for CGview. CSTA and CEND are written beforeand after CG related data, respectively. The ifto which denes output unit of <strong>cg</strong>-data is set to39 as the unit of trajectory data le for CGview. The number of region, NREG, issetby izonin.write(6,*) 'Read <strong>cg</strong>-related data'!-----------------------------------------------! initilize <strong>cg</strong> related parameter!-----------------------------------------------npreci=3 ! PICT data mode for CGView in free formatifti = 4ifto = 39''''! Input unit number for <strong>cg</strong>-data! Output unit number for PICTwrite(6,fmt="(' CG data')")call geomgt(ifti,6) ! Read in CG datawrite(6,fmt="(' End of CG data',/)")if(npreci.eq.3) write(ifto,fmt="('CSTA-FREE-TIME')")if(npreci.eq.2) write(ifto,fmt="('CSTA-TIME')")rewind ifticall geomgt(ifti,ifto)! Dummy call to write geom info for iftowrite(ifto,110)110 FORMAT('CEND')!--------------------------------! Get nreg from <strong>cg</strong> input data!--------------------------------nreg=izonin33


The material assignment is read in from input le (egs5job.data). Egs cut-o energy andvarious option ags are set to each region except vacuum regions. In this user code, K & L-edgeuorescence option is turn-on.After setting the seed, initialize the Ranlux random number generator.! Read material for each region from egs5job.dataread(4,*) (med(i),i=1,nreg)! Set option except vacuum regiondo i=1,nreg-1if(med(i).ne.0) theniphter(i) = 1 ! Switches for PE-angle samplingiedgfl(i) = 1 ! K & L-edge fluorescenceiauger(i) = 0 ! K & L-Augeriraylr(i) = 0 ! Rayleigh scatteringlpolar(i) = 0 ! Linearly-polarized photon scatteringincohr(i) = 0 ! S/Z rejectioniprofr(i) = 0 ! Doppler broadeningend ifend doimpacr(i) = 0! Electron impact ionization! --------------------------------------------------------! Random number seeds. Must be defined before call hatch! or defaults will be used. inseed (1- 2^31)! --------------------------------------------------------luxlev = 1inseed=1write(6,120) inseed120 FORMAT(/,' inseed=',I12,5X,* ' (seed for generating unique sequences of Ranlux)')! =============call rluxinit! =============! Initialize the Ranlux random-number generator3.4 Step 4: Determination-of-incident-particle-parametersVarious source parameters like energy, position and direction are set. In this user code, 1.253MeV photons normally incident along Z-axis to a point of (0.0, 0.0, -5.0). In CG geometry, itispossible to set irin automatically by setting irin=0 .! Define initial variables for incident particle normally incident! on the slabiqin=0! Incident particle charge - photonsekein=1.253 ! Incident particle kinetic energyxin=0.0! Source positionyin=0.0zin=-5.0uin=0.0! Moving along z axisvin=0.0win=1.0irin=0! Starting region (0: Automatic search in CG)wtin=1.0! Weight = 1 since no variance reduction used! pdf data for many sourcedeltae=0.05 ! Energy bin of response!-----------------------------------------! Get source region from <strong>cg</strong> input data!-----------------------------------------!if(irin.le.0.or.irin.gt.nreg) thencall srzone(xin,yin,zin,iqin+2,0,irin)if(irin.le.0.or.irin.ge.nreg) thenwrite(6,fmt="(' Stopped in MAIN. irin = ',i5)")irinstop34


end ifcall rstnxt(iqin+2,0,irin)end if3.5 Step 5: hatch-callSet emaxe=0.D0 to get minimum upper energy of electrons in the material used, and thensubroutine hatch is called.Output the material data and parameters of each region to the result le (unit 1). Outputthe number of regions and the material number of each region to the trajectory le (unit 39).emaxe = 0.D0 ! dummy value to extract min(UE,UP+RM).! ==========call hatch! ==========3.6 Step 6: Initialization-for-howfarDene various parameters used for the geometry denition in this step. This part is not necessaryin the case of using CG.3.7 Step 7: Initialization-for-ausgabThe energy bin width is calculated from the source energy and the number of energy bin (50).ncases is a history number and maxpict is a number of histories to store trajectory data.! Energy bin widthdeltae=ekein / 50! Zero the variablesdepe=0.D0pefs=0.D0pef2s=0.D0tefs=0.D0tef2S=0.D0do j=1,50phs(j)=0.D0ph2s(j)=0.D0do ntype=1,3spec(ntype,j)=0.D0specs(ntype,j)=0.D0spec2s(ntype,j)=0.D0end doend do! Set historiesncases=10000! Set maximum number for pictmaxpict=503.8 Step 8: Shower-callSubroutine shower is called ncases times. Before shower call-loop, a batch number iswritten on the trajectory display le.If some energy is deposited at NaI, particle weight is added as total eciency. If its energy islarger than 99.9% of source kinetic energy, the particle is treat as the contribution to the totalabsorption peak and its weight is added to peak eciency. Bin number corresponding absorbedenergy is calculated and its weight is added for corresponding channel of the pulse height.Summation of weight squared of above variables together with spectrum information are alsostored for statistical analysis.35


! Write batch numberwrite(39,fmt="('01')")! ========================if(iwatch.gt.0) call swatch(-99,iwatch)! ========================do i=1,ncases! ----------------------! Select incident energy! ----------------------wtin = 1.0wtsum = wtsum + wtinetot = ekein + iabs(iqin)*RMavailke = etot + iqin*RMtotke = totke + availke! ----------------------! Select incident angle! ----------------------! -------------------------! Start of shower call-loop! -------------------------! Keep running sum of weights! Incident total energy (MeV)! Available K.E. (MeV) in system! Keep running sum of KE! ---------------------------------------------------! Print first NWRITE or NLINES, whichever comes first! ---------------------------------------------------if (ncount .le. nwrite .and. ilines .le. nlines) thenilines = ilines + 1write(6,280) etot,xin,yin,zin,uin,vin,win,iqin,irinn,idin280 FORMAT(7G15.7,3I5)end if! -----------------------------------------------------------! Compare maximum energy of material data and incident energy! -----------------------------------------------------------if(etot+(1-iabs(iqin))*RM.gt.emaxe) thenwrite(6,fmt="(' Stopped in MAIN.',1 ' (Incident kinetic energy + RM) > min(UE,UP+RM).')")stopend if! ----------------------------------------------------! Verify the normalization of source direction cosines! ----------------------------------------------------if(abs(uin*uin+vin*vin+win*win-1.0).gt.1.e-6) thenwrite(6,fmt="(' Following source direction cosines are not',1 ' normalized.',3e12.5)")uin,vin,winstopend if! ==========================================================call shower (iqin,etot,xin,yin,zin,uin,vin,win,irinn,wtin)! ==========================================================! If some energy is deposited inside detector add pulse-height! and efficiency.if (depe .gt. 0.D0) thenie=depe/deltae + 1if (ie .gt. 50) ie = 50phs(ie)=phs(ie)+wtinph2s(ie)=ph2s(ie)+wtin*wtintefs=tefs + wtintef2s=tef2s + wtin*wtinif(depe .ge. ekein*0.999) thenpefs=pefs +wtinpef2s=pef2s +wtin*wtinend if36


depe = 0.D0end ifdo ntype=1,3do ie=1,50specs(ntype,ie)=specs(ntype,ie)+spec(ntype,ie)spec2s(ntype,ie)=spec2s(ntype,ie)+* spec(ntype,ie)*spec(ntype,ie)spec(ntype,ie)=0.D0end doend doncount = ncount + 1! ========================if(iwatch.gt.0) call swatch(-1,iwatch)! ========================end do! ========================if(iwatch.gt.0) call swatch(-88,iwatch)! ========================! Count total number of actual cases! -----------------------! End of CALL SHOWER loop! -----------------------call plotxyz(99,0,0,0.D0,0.D0,0.D0,0.D0,0,0.D0,0.D0)write(39,fmt="('9')")3.8.1 Statistical uncertainty! Set end of batch for CG ViewThe uncertainty of obtained, x, is estimated using the method used in MCNP in this user code. Assume that the calculation calls for N \incident" particle histories. Assume that x i is the result at the i-th history. Calculate the mean value of x :x = 1 NNXi=1x i (1) Estimate the variance associated with the distribution of x i :s 2 = 1N ; 1NXi=1(x i ; x) 2 ' x 2 ; (x) 2 (x 2 = 1 NNXi=1x 2 i ): (2) Estimate the variance associated with the distribution of x:s 2 x = 1 N s2 ' 1 N [x2 ; (x) 2 ] (3) Report the statistical error as:s x ' [ 1 N (x2 ; x 2 )] 1=2 (4)3.8.2 Output of resultsAfter nishing all histories, obtained results are analyzed and written on output le. Averagevalues and their statistical uncertainty are calculated form the sum of weight and the sum ofweight squared.37


! -----------------------------------! Calculate average and its deviation! -----------------------------------! ---------------! Peak efficiency! ---------------avpe = pefs/ncountpef2s=pef2s/ncountsigpe=dsqrt((pef2s-avpe*avpe)/ncount)avpe = avpe*100.0sigpe = sigpe*100.0write(6,350) avpe,sigpe350 FORMAT(' Peak efficiency =',G11.4,'+-',G9.2,' %')! ----------------! Total efficiency! ----------------avte = tefs/ncounttef2s = tef2s/ncountsigte = dsqrt((tef2s-avte*avte)/ncount)avte = avte*100.0sigte = sigte*100.0write(6,360) avte,sigte360 FORMAT(' Total efficiency =',G11.4,'+-',G9.2,' %')! --------------------------! Pulse height distribution! --------------------------write(6,370)370 FORMAT(/' Pulse height distribution ')do ie=1,50elow=deltae*(ie-1)eup=deltae*ieavph = phs(ie)/ncountph2s(ie)=ph2s(ie)/ncountsigph=dsqrt((ph2s(ie)-avph*avph)/ncount)avph = avph/deltaesigph= sigph/deltaewrite(6,380) eup,avph,sigph380 FORMAT(' E (upper-edge --',G10.4,' MeV )=',G15.5,'+-',G15.5,* ' counts/MeV/incident')end doSpectra of particles incident on NaI detector are also analyzed and output.3.9 Subroutine ausgabSubroutine ausgab is a subroutine to score variables that user want to calculate.Include lines and specication statements are written at rst by the same way used at themain program.When iarg < 5, absorbed energy at the region nreg (outside the system) and other regionsare summed separately to check energy balance at each history.If the material number 1, NaI region, absorbed energy per step is added as the energydeposition at the detector.If a particle enters to NaI region from outside, energy information corresponding to eachparticle type is scored.! ------------------------! Set some local variables! ------------------------irl = ir(np)iql = iq(np)edepwt = edep*wt(np)38


! -----------------------------------------------------------! Keep track of energy deposition (for conservation purposes)! -----------------------------------------------------------if (iarg .lt. 5) thenesum(iql+2,irl,iarg+1) = esum(iql+2,irl,iarg+1) + edepwtnsum(iql+2,irl,iarg+1) = nsum(iql+2,irl,iarg+1) + 1end if! -----------------------------------------------------------------! Print out particle transport information (if switch is turned on)! -----------------------------------------------------------------! ========================if (iwatch .gt. 0) call swatch(iarg,iwatch)! ========================if(iarg .ge. 5) return! ----------------------------------------------! Score energy deposition inside NaI detector! ----------------------------------------------if (med(irl) .eq. 1) thendepe = depe + edepwt! ----------------------------------------------------! Score particle information if it enters from outside! ----------------------------------------------------if (irl .ne. irold .and. iarg .eq. 0) thenif (iql .eq. 0) then! photonntype=1ie = e(np)/deltae +1if(ie .gt. 50) ie = 50elseif (iql .eq. -1) then ! electronntype=2ie = (e(np) - RM)/deltae +1if(ie .gt. 50) ie = 50else! positronntype=3ie = (e(np) - RM)/deltae +1if(ie .gt. 50) ie = 50end ifspec(ntype,ie) = spec(ntype,ie) + wt(np)end ifend if! ----------------------------------------------------------------! Print out stack information (for limited number cases and lines)! ----------------------------------------------------------------if (ncount .le. nwrite .and. ilines .le. nlines) thenilines = ilines + 1write(6,100) e(np),x(np),y(np),z(np),u(np),v(np),w(np),* iql,irl,iarg100 FORMAT(4G15.7/3G15.7,3I5)end if! ------------------------------------! Output particle information for plot! ------------------------------------if (ncount.le.maxpict) thencall plotxyz(iarg,np,iq(np),x(np),y(np),z(np),e(np),ir(np),* wt(np),time(np))end ifreturnend3.10 Subroutine howfarAs far as CG is used, it is not necessary for user to change subroutine howfar atall.For user's convenience, outline of subroutine howfar is described. At subroutine howfar,39


a distance to the boundary of region is checked. If the distance to the boundary is shorter thanthe distance to the next point, the distance to the next point is replaced with the distance tothe boundary and new region irnew is set to the region number to which particle will enter.If idisc is set to 1 by user, the treatment to stop following will be done in this subroutine.Calculation to a distance to the boundary is done by using the various subroutines related<strong>cg</strong> in ucnai<strong>cg</strong>v.f.4 Comparison of speed between ucnai.f and ucnai<strong>cg</strong>v.fCG geometry is suitable to treat a complex geometry than the cylinder-plane geometry etc. Onthe other hand, <strong>cg</strong> needs more cpu time. For example, ucnai<strong>cg</strong>v.f needs 1.6 times longer cputime than ucnai.f for the same problem. [2]5 Exercise problems5.1 Problem 1 : Calculation for NaI detectorStudy variation of the results for the following cases.1. Change to isotropic source of 1.253 MeV.2. Change the source to 0.662 MeV photons from Cs-137.3. Change source energy to 1.173 and 1.332 MeV photons of Co-60.4. Increase detector thickness twice for 1.253 MeV photons.5.2 Problem 2 : Ge detector calculationChange detector to Ge from NaI and compare its peak and total eciencies with NaI detectorof same size for 1.253 MeV photons.5.3 Problem 3 : Air ionization chamber calculationChange detector to air at 20 C and 1 atm and calculate absorbed energy for 1.253 MeV pencilbeam photon. Air region have 7.62 cm diameter and 7.62 cm length and is surrounded by 0.5cm aluminum wall. Air layer of 5 cm thickness exist outside aluminum wall.Calculate output of this chamber (Coulomb/source) using W-value of air (33.97 eV/pair)and the electron charge magnitude (1:602 10 ;19 C/e) .40


6 Answer for exercisesIt is recommended to save egs5job.out which is the result of ucnai<strong>cg</strong>v.f for 10,000 historieswith a dierent le name like nai.out for comparisons with the results of following problems.6.1 Problem 11. 137 Cs source cp ucnai<strong>cg</strong>v.f ucnai<strong>cg</strong>v1.fYou must use copy ucnai<strong>cg</strong>v.f ucnai<strong>cg</strong>v1.f or copy function of Windows in thecase of DOS. cp ucnai<strong>cg</strong>v.data ucnai<strong>cg</strong>v1.data cp ucnai<strong>cg</strong>v.inp ucnai<strong>cg</strong>v1.inp Modify ucnai<strong>cg</strong>v1.f as follows:{ Modify source photon energy.Changetoekein=1.253ekein=0.662 Run ucnai<strong>cg</strong>v1.f by egs5run.! Incident particle kinetic energy! Incident particle kinetic energy{ In the case of Linux or CygwinEnter ucnai<strong>cg</strong>v1 as the user code.Simply enter "return" as the le name for unit 4 and 25.Enter 1 for "Does this user code read from the terminal?".{ In the case of DOSegs5run ucnai<strong>cg</strong>v1 Compare the calculated results with nai.out. Peak eciency and total eciencyrepresent the results. These values are shown in the table below.2. 60 Co sourceEciencies before and after the modicationPeak eciency (P e ) Total eciency (T e )ucnai<strong>cg</strong>vucnai<strong>cg</strong>v137.6 0.5 %60.3 0.5 %76.2 0.4 %87.5 0.3 %Here user should be careful on the point that eciency value can have uctuation onthe order of statistical error depending on computer and compiler. cp ucnai<strong>cg</strong>v.f ucnai<strong>cg</strong>v2.f cp ucnai<strong>cg</strong>v.data ucnai<strong>cg</strong>v2.data cp ucnai<strong>cg</strong>v.inp ucnai<strong>cg</strong>v2.inp Modify ucnai<strong>cg</strong>v2.f as follows:{ Modify the maximum electron kinetic energy used.Changetoekein=1.253ekein=1.333! Incident particle kinetic energy! Incident particle kinetic energy41


{ Add sampling routines for source photon energy sampling.Just after! ----------------------! Select incident energy! ----------------------add followings.call randomset(rnnow)if(rnnow.le.0.5) thenekein=1.173elseekein=1.333end if{ Modify output statement concerning the source energy.Changewrite(6,340) ekin340 FORMAT(' Results for ',G15.5,'MeV photon'/)towrite(6,340)340 FORMAT(' Results for Co-60 gamma-ray (1.173 and 1.333 MeV)'/) Run ucnai<strong>cg</strong>v2.f by egs5run.{ In the case of Linux or CygwinEnter ucnai<strong>cg</strong>v2 as the user code.Simply enter "return" as the le name for unit 4 and 25.Enter 1 for "Does this user code read from the terminal?".{ In the case of DOSegs5run ucnai<strong>cg</strong>v2 Compare the calculated results with nai.out. Conrm that there are 2peaks in the response corresponding to the source energies.3. Isotropic source cp ucnai<strong>cg</strong>v.f ucnai<strong>cg</strong>v3.f cp ucnai<strong>cg</strong>v.data ucnai<strong>cg</strong>v3.data cp ucnai<strong>cg</strong>v.inp ucnai<strong>cg</strong>v3.inp Modify ucnai<strong>cg</strong>v3.f as follows:{ Add a source direction sampling routine.Change! ----------------------! Select incident angle! ----------------------to! ----------------------! Select incident angle! ----------------------275 call randomset(rnnow)zi0=rnnowcall randomset(rnnow)xi0=2.0*rnnow-1.0call randomset(rnnow)yi0=2.0*rnnow-1.0rr0=dsqrt(xi0*xi0+yi0*yi0+zi0*zi0)if(rr0.gt.1.0) go to 275win = zi0/rr0uin = xi0/rr0vin = yi0/rr042


Run ucnai<strong>cg</strong>v3.f by egs5run.{ In the case of Linux or CygwinEnter ucnai<strong>cg</strong>v3 as the user code.Simply enter "return" as the le name for unit 4 and 25.Enter 1 for "Does this user code read from the terminal?".{ In the case of DOSegs5run ucnai<strong>cg</strong>v3 Check the trajectories by CGview using egs5job.pic. Conrm that sourcephotons were emitted isotropically. Compare the calculated results with nai.out.Example of result: P e =3.6 0.2 %, T e =9.3 0.3 %4. Increase NaI detector thickness twice cp ucnai<strong>cg</strong>v.f ucnai<strong>cg</strong>v4.f cp ucnai<strong>cg</strong>v.data ucnai<strong>cg</strong>v4.data cp ucnai<strong>cg</strong>v.inp ucnai<strong>cg</strong>v4.inp Modify ucnai<strong>cg</strong>v4.f as follows:{ Increase the detector length.Changetotdet=7.62tdet=7.62*2.0{ This modication is not directly related to the calculation in the case of using<strong>cg</strong>. This is used to output the detector size on the result le. The real change ofthe geometry is done by the next change of <strong>cg</strong> data. Modify ucnai<strong>cg</strong>v4.data as follows:RCC 1 0.00 0.0 0.0 0.00 0.015.24 3.81RCC 2 0.00 0.0 -0.5 0.00 0.015.74 4.31RCC 3 0.00 0.0 -0.6 0.00 0.016.34 4.41RCC 4 0.00 0.0 15.24 0.00 0.00.5 4.31RCC 5 0.00 0.0 -5.6 0.00 0.026.34 9.41RCC 6 0.0 0.0 -10.0 0.0 0.036.74 12.0ENDZ1 +1Z2 +2 -1Z3 +3 -2 -4Z4 +4Z5 +5 -3Z6 +6 -5END1 0 2 3 4 0 Check ucnai<strong>cg</strong>v4.data.43


ROuter vacuum (region 6)Air region (region 5)Al Cover (region 3)Gap (region 2)NaI (region 1)1.253MeVPhoton-5.6 -0.6 -0.5 0.0 15.24Quarz window(region 4)15.7420.74ZFigure 4: Geometry of ucnai<strong>cg</strong>v4.f{ Check ucnai<strong>cg</strong>v4.data by using CGView as followsSelect "Making geometry data" of File option.Select Open File and assign ucnai<strong>cg</strong>v4.data by changing le type to "all les".Geometry is displayed when you select OK.Select "Geometry Check" of Environment option.Select "Check Start". Run ucnai<strong>cg</strong>v4.f by egs5run.{ In the case of Linux or CygwinEnter ucnai<strong>cg</strong>v4 as the user code.Simply enter "return" as the le name for unit 4 and 25.Enter 1 for "Does this user code read from the terminal?".{ In the case of DOSegs5run ucnai<strong>cg</strong>v4 Compare the calculated results with nai.out.Example of the result: P e =53.1 0.5%, T e =94.3 0.2 %6.2 Problem 21. cp ucnai<strong>cg</strong>v.f ucnai<strong>cg</strong>v5.f2. cp ucnai<strong>cg</strong>v.data ucnai<strong>cg</strong>v5.data3. cp ucnai<strong>cg</strong>v.inp ucnai<strong>cg</strong>v5.inp4. Modify ucnai<strong>cg</strong>v5.f as follows: Modify the material data used.Change44


tomedarr(1)='NAImedarr(1)='GEHere, data of 24 characters must be specified as medarr(1).User should be careful on the point that data of 24 characters are necessary for medarr .5. Modify ucnai<strong>cg</strong>v5.inp as follows:ModifyCOMP&INP NE=2,RHO=3.67, PZ=1,1,IRAYL=1 /ENDNAINAINA Ito''ELEM&INP IRAYL=1 /ENDGEGEGEUser should be careful on the point that the second "GE" must start from 31-th column.6. Run ucnai<strong>cg</strong>v5.f by egs5run. In the case of Linux or CygwinEnter ucnai<strong>cg</strong>v5 as the user code.Simply enter "return" as the le name for unit 4 and 25.Enter 1 for "Does this user code read from the terminal?". In the case of DOSegs5run ucnai<strong>cg</strong>v57. Compare the calculated results with nai.out. Example of the result: P e =41.1 0.5 %,T e =88.1 0.3 %6.3 Problem 31. cp ucnai<strong>cg</strong>v.f ucion<strong>cg</strong>v.f2. cp ucnai<strong>cg</strong>v.data ucion<strong>cg</strong>v.data3. cp ucnai<strong>cg</strong>v.inp ucion<strong>cg</strong>v.inp4. Modify ucion<strong>cg</strong>v.f as follows: Add variables used.ChangetoChange* xi0,yi0,zi0* xi0,yi0,zi0,avab,depes,depe2s,sigab* xi0,yi0,zi045


to* xi0,yi0,zi0,avab,depes,depe2s,sigab Modify the number of materials used.Changenmed=4nmed=2 Modify the name of materials.Changetomedarr(1)='NAImedarr(2)='ALmedarr(3)='QUARTZmedarr(4)='AIR-AT-NTPmedarr(1)='AIR-AT-NTPmedarr(2)='AL Delete unnecessary chard for non existing material number. Delete following lineschard(3) = 0.5d0chard(4) = 5.0d0 Modify variables to be initialized.Change! Zero the variablesdepe=0.D0to! Zero the variablesdepe=0.D0depes=0.D0depe2s=0.D0 Increase history number to 100,000. Change! Set historiesncases=10000to! Set historiesncases=100000 Add routines to sum absorbed energy in air.Changetoif (depe .gt. 0.D0) thenie=depe/deltae + 1if (depe .gt. 0.D0) thendepes=depes+depedepe2s=depe2s+depe*depeie=depe/deltae + 1''''''46


Modify statements related geometry output.Changetdet=7.62rdet=3.81tcov=0.1rtcov=0.1tgap=0.5rtgap=0.5write(6,330) tdet,rdet,tcov,rtcov,tgap,rtgap330 FORMAT(/' Detector length=',G15.5,' cm'/* ' Detector radius=',G15.5,' cm'/* ' Al cover thickness=',G10.2,' cm'/* ' Al cover side thickness=',G10.2,' cm'/* ' Front gap =',G10.2,' cm'/' Side gap =',G10.2,' cm'/)totdet=7.62rdet=3.81tcov=0.5rtcov=0.5write(6,330) tdet,rdet,tcov,rtcov330 FORMAT(/' Detector length=',G15.5,' cm'/* ' Detector radius=',G15.5,' cm'/* ' Al cover thickness=',G10.2,' cm'/* ' Al cover side thickness=',G10.2,' cm'/) Add routines to calculated average absorbed energy of air and its statistical error.Change! --------------------------! Pulse height distribution! --------------------------write(6,370)to! ----------------------! Absorbed energy in air! ----------------------avab = depes/ncountdepe2s = depe2s/ncountsigab = sqrt((depe2s - avab*avab)/ncount)write(6,362) avab,sigab362 FORMAT(' Absorbed energy in air =',G15.5,'+-',G15.5,' MeV/photon')avab = avab /33.97D-6 *1.602D-19sigab= sigab /33.97D-6 *1.602D-19write(6,364) avab,sigab364 FORMAT(' Output current =',G15.5,'+-',G15.5,' C/photon')! --------------------------! Pulse height distribution! --------------------------write(6,370) Modify score condition at the detector region in ausgab to distinguish from air outsidedetector.toif (med(irl) .eq. 1) thendepe = depe + edepwtif (irl .eq. 1) thendepe = depe + edepwt5. Modify ucion<strong>cg</strong>v.data as follows:47


ROuter vacuum (region 4)Air region (region 3)Al Cover (region 2)Air (region 1)1.253MeVPhoton13.12Z-0.5 0.0 8.127.62-5.5Figure 5: Geometry of ucion<strong>cg</strong>v.fRCC 1 0.00 0.0 0.0 0.00 0.07.62 3.81RCC 2 0.00 0.0 -0.5 0.00 0.08.62 4.31RCC 3 0.00 0.0 -5.5 0.00 0.018.62 9.31RCC 4 0.00 0.0 -6.0 0.00 0.020.62 10.31ENDZ1 +1Z2 +2 -1Z3 +3 -2Z4 +4 -3END1 2 1 06. Check ucion<strong>cg</strong>v.data. cp ucion<strong>cg</strong>v.data ucion<strong>cg</strong>v.geo. Check ucion<strong>cg</strong>v.geo by using CGView as followsSelect "Making geometry data" of File option.Select Open File and assign ucion<strong>cg</strong>v.geo".Geometry is displayed when you select OK.Select "Geomtry Check" of Environment option.Select "Check Start".7. Modify ucion<strong>cg</strong>v.inp as follows.MIXT48


&INP NE=3,RHO= 1.2929E-03,RHOZ= 0.755,0.232,0.013,GASP=0.93174, IRAYL=1 /ENDAIR-AT-NTPAIR-GASN O ARENER&INP AE=0.521,AP=0.010,UE=2.511,UP=2.0 /ENDPWLF&INP /ENDDECK&INP /ENDELEM&INP IRAYL=1 /ENDALALALENER&INP AE=0.521,AP=0.010,UE=2.511,UP=2.0 /ENDPWLF&INP /ENDDECK&INP /END8. Run ucion<strong>cg</strong>v.f by egs5run. In the case of Linux or CygwinEnter ucion<strong>cg</strong>v as the user code.Simply enter "return" as the le name for unit 4 and 25.Enter 1 for "Does this user code read from the terminal?". In the case of DOSegs5run ucion<strong>cg</strong>v9. Check the trajectories by CGview using egs5job.pic.10. Check the calculated results.Example of result are shown in the table below.ReferencesResult of ionization chamber calculationPeak eciency P e (%) 0.0Total eciency T e (%) 0.73 0.3e-1Absorbed energy (MeV/) 0.15e-3 0.7e-5Output (C/)0.69e-18 0.3e-19[1] T. Torii and T. Sugita, \Development of PRESTA-CG Incorprating Combinatorial Geometryin EGS4/PRESTA", JNC TN1410 2002-201, Japan Nuclear Cycle DevelopmentInstitute (2002).[2] T. Sugita, T. Torii, A. Takamura, \Incorporating Combinatorial Geometry to the EGS5Code and Its Speed-Up", Twelfth EGS User's Meeting in Japan, KEK Proc. 2005-10, 7-21,(KEK, Tsukuba, 9 - 11 Aug. 2005).49


Appendix: Full listings of ucnai<strong>cg</strong>v.f!***********************************************************************!***************************** KEK, High Energy Accelerator Research *!***************************** Organization *!*** u c n a i c g v ********* *!***************************** EGS5.0 USER CODE - 28 Jul 2012/1430 *!***********************************************************************!* This is a general User Code based on the <strong>cg</strong> geometry scheme. *!***********************************************************************! *! PROGRAMMERS: H. Hirayama *! Applied Research Laboratory *! KEK, High Energy Accelerator Research Organization *! 1-1, Oho, Tsukuba, Ibaraki, 305-0801 *! Japan *! *! E-mail: hideo.hirayama@kek.jp *! Telephone: +81-29-864-5451 *! Fax: +81-29-864-4051 *! *! Y. Namito *! Radiation Science Center *! Applied Research Laboratory *! KEK, High Energy Accelerator Research Organization *! 1-1, Oho, Tsukuba, Ibaraki, 305-0801 *! Japan *! *! E-mail: yoshihito.namito@kek.jp *! Telephone: +81-29-864-5489 *! Fax: +81-29-864-1993 *! *!***********************************************************************!***********************************************************************! The ucnai<strong>cg</strong>v.f User Code requires a <strong>cg</strong>-input file only *! (e.g., ucnai<strong>cg</strong>v.data). *! The following shows the geometry for ucnai<strong>cg</strong>.data. *! Input data for CG geometry must be written at the top of data-input *! file together with material assignment to each region. Cg-data can *! be checked by CGview. *! This user code corresponds to ucnai3<strong>cg</strong>p.mor for egs4. *! Use Ranlux random number generator. *!***********************************************************************! *! ----------------------- *! <strong>cg</strong> Geometry (ucnai<strong>cg</strong>v) *! ----------------------- *! *! *! R *! ^ *! | *! +----+----+----+--------+------+--- *! | *! | Outer vacuum region *! + +----+----+--------+------+-----+ R=9.41 *! | | Air | *! | | +--------------------+ + R=4.41 *! | | | Al cover | | *! | + + +-----------+---+ + R=4.31 *! | | | | Gap | | | *! + + + + +-------+ + + R=3.81 *! | | | | | |Quartz | *! | | | | | NaI | | | *! 1.253 MeV | | | | | | | | *! ============>--+----+---+-------+---+-----+--------> Z *! photons -5.6 -0.6 -0.5 0.0 7.62 8.12 13.12 *! -5.0 *! *! *! *!***********************************************************************!23456789|123456789|123456789|123456789|123456789|123456789|123456789|12!-----------------------------------------------------------------------!------------------------------- main code -----------------------------!-----------------------------------------------------------------------!-----------------------------------------------------------------------! Step 1: Initialization50


!-----------------------------------------------------------------------implicit none! ------------! EGS5 COMMONs! ------------include 'include/egs5_h.f'include 'include/egs5_bounds.f'include 'include/egs5_brempr.f'include 'include/egs5_edge.f'include 'include/egs5_media.f'include 'include/egs5_misc.f'include 'include/egs5_thresh.f'include 'include/egs5_uphiot.f'include 'include/egs5_useful.f'include 'include/egs5_usersc.f'include 'include/egs5_userxt.f'include 'include/randomm.f'! ----------------------! Auxiliary-code COMMONs! ----------------------include 'auxcommons/aux_h.f'include 'auxcommons/edata.f'include 'auxcommons/etaly1.f'include 'auxcommons/instuf.f'include 'auxcommons/lines.f'include 'auxcommons/nfac.f'include 'auxcommons/watch.f'! Main EGS "header" file! Auxiliary-code "header" file! ------------------! <strong>cg</strong> related COMMONs! ------------------include 'auxcommons/geom_common.f' ! geom-common fileinteger irinncommon/totals/* depe,deltae,spec(3,50),maxpictreal*8 depe,deltae,specinteger maxpict! Variables to score!**** real*8 ! Argumentsreal*8 totkereal*8 rnnow,etotreal*8 esumtreal*8! Local variables* availke,avpe,avph,avspe,avspg,avspp,avte,desci2,pefs,pef2s,* rr0,sigpe,sigte,sigph,sigspg,sigspe,sigspp,tefs,tef2s,wtin,wtsum,* xi0,yi0,zi0real*8* phs(50),ph2s(50),specs(3,50),spec2s(3,50)real* elow,eup,rdet,rtcov,rtgap,tcov,tdet,tgapreal* tarray(2),tt,tt0,tt1,cputime,etimeinteger* i,icases,idin,ie,ifti,ifto,ii,iiz,imed,ireg,isam,* izn,nlist,j,k,n,ner,ntypecharacter*24 medarr(MXMED)! Local variables! ----------! Open files! ----------!----------------------------------------------------------------! Units 7-26 are used in pegs and closed. It is better not! to use as output file. If they are used, they must be opened! after get<strong>cg</strong> etc. Unit for pict must be 39.!----------------------------------------------------------------open(6,FILE='egs5job.out',STATUS='unknown')open(4,FILE='egs5job.inp',STATUS='old')51


open(39,FILE='egs5job.pic',STATUS='unknown')! ====================call counters_out(0)! ====================!-----------------------------------------------------------------------! Step 2: pegs5-call!-----------------------------------------------------------------------! ---------------------------------! Define media before calling PEGS5! ---------------------------------nmed=4if(nmed.gt.MXMED) thenwrite(6,'(A,I4,A,I4,A/A)')* ' nmed (',nmed,') larger than MXMED (',MXMED,')',* ' MXMED in iclude/egs5_h.f must be increased.'stopend if! ==============call block_set! ==============medarr(1)='NAImedarr(2)='ALmedarr(3)='QUARTZmedarr(4)='AIR-AT-NTPdo j=1,nmeddo i=1,24media(i,j)=medarr(j)(i:i)end doend do! Initialize some general variableschard(1) = 7.62d0 ! automatic step-size controlchard(2) = 0.1d0chard(3) = 0.5d0chard(4) = 5.0d0write(6,fmt="('chard =',5e12.5)") (chard(j),j=1,nmed)! -----------------------------------! Run KEK PEGS5 before calling HATCH! -----------------------------------write(6,100)100 FORMAT('PEGS5-call comes next'/)! ==========call pegs5! ==========!-----------------------------------------------------------------------! Step 3: Pre-hatch-call-initialization!-----------------------------------------------------------------------write(6,*) 'Read <strong>cg</strong>-related data'!-----------------------------------------------! Initialize CG related parameters!-----------------------------------------------npreci=3 ! PICT data mode for CGView in free formatifti = 4ifto = 39''''! Input unit number for <strong>cg</strong>-data! Output unit number for PICTwrite(6,fmt="(' CG data')")call geomgt(ifti,6) ! Read in CG datawrite(6,fmt="(' End of CG data',/)")if(npreci.eq.3) write(ifto,fmt="('CSTA-FREE-TIME')")if(npreci.eq.2) write(ifto,fmt="('CSTA-TIME')")rewind ifticall geomgt(ifti,ifto)! Dummy call to write geom info for iftowrite(ifto,110)110 FORMAT('CEND')!--------------------------------! Get nreg from <strong>cg</strong> input data!--------------------------------52


nreg=izonin! Read material for each region from egs5job.dataread(4,*) (med(i),i=1,nreg)! Set option except vacuum regiondo i=1,nreg-1if(med(i).ne.0) theniphter(i) = 1 ! Switches for PE-angle samplingiedgfl(i) = 1 ! K & L-edge fluorescenceiauger(i) = 0 ! K & L-Augeriraylr(i) = 0 ! Rayleigh scatteringlpolar(i) = 0 ! Linearly-polarized photon scatteringincohr(i) = 0 ! S/Z rejectioniprofr(i) = 0 ! Doppler broadeningend ifend doimpacr(i) = 0! Electron impact ionization! --------------------------------------------------------! Random number seeds. Must be defined before call hatch! or defaults will be used. inseed (1- 2^31)! --------------------------------------------------------luxlev = 1inseed=1write(6,120) inseed120 FORMAT(/,' inseed=',I12,5X,* ' (seed for generating unique sequences of Ranlux)')! =============call rluxinit! =============! Initialize the Ranlux random-number generator!-----------------------------------------------------------------------! Step 4: Determination-of-incident-particle-parameters!-----------------------------------------------------------------------! Define initial variables for incident particle normally incident! on the slabiqin=0! Incident particle charge - photonsekein=1.253 ! Incident particle kinetic energyxin=0.0! Source positionyin=0.0zin=-5.0uin=0.0! Moving along z axisvin=0.0win=1.0irin=0! Starting region (0: Automatic search in CG)wtin=1.0! Weight = 1 since no variance reduction used! pdf data for many sourcedeltae=0.05 ! Energy bin of response!-----------------------------------------! Get source region from <strong>cg</strong> input data!-----------------------------------------!if(irin.le.0.or.irin.gt.nreg) thencall srzone(xin,yin,zin,iqin+2,0,irin)if(irin.le.0.or.irin.ge.nreg) thenwrite(6,fmt="(' Stopped in MAIN. irin = ',i5)")irinstopend ifcall rstnxt(iqin+2,0,irin)end if!-----------------------------------------------------------------------! Step 5: hatch-call!-----------------------------------------------------------------------!-----------------------------------------------------------------------emaxe = 0.D0 ! dummy value to extract min(UE,UP+RM).write(6,130)130 format(/' Call hatch to get cross-section data')! ------------------------------! Open files (before HATCH call)! ------------------------------open(UNIT=KMPI,FILE='pgs5job.pegs5dat',STATUS='old')open(UNIT=KMPO,FILE='egs5job.dummy',STATUS='unknown')53


write(6,140)140 FORMAT(/,' HATCH-call comes next',/)! ==========call hatch! ==========! ------------------------------! Close files (after HATCH call)! ------------------------------close(UNIT=KMPI)close(UNIT=KMPO)! ----------------------------------------------------------! Print various data associated with each media (not region)! ----------------------------------------------------------write(6,150)150 FORMAT(/,' Quantities associated with each MEDIA:')do j=1,nmedwrite(6,160) (media(i,j),i=1,24)160 FORMAT(/,1X,24A1)write(6,170) rhom(j),rlcm(j)170 FORMAT(5X,' rho=',G15.7,' g/cu.cm rlc=',G15.7,' cm')write(6,180) ae(j),ue(j)180 FORMAT(5X,' ae=',G15.7,' MeVwrite(6,190) ap(j),up(j)ue=',G15.7,' MeV')190 FORMAT(5X,' ap=',G15.7,' MeVend doup=',G15.7,' MeV',/)! -------------------------------------------------------! Print media and cutoff energies assigned to each region! -------------------------------------------------------do i=1,nregif (med(i) .eq. 0) thenwrite(6,200) i200 FORMAT(' medium(',I3,')=vacuum')elsewrite(6,210) i,(media(ii,med(i)),ii=1,24),ecut(i),pcut(i)210 FORMAT(' medium(',I3,')=',24A1,* 'ecut=',G10.5,' MeV, pcut=',G10.5,' MeV')! -----------------------------------------------! Print out energy information of K- and L-X-rays! -----------------------------------------------if (iedgfl(i) .ne. 0) then! Output X-ray energyner = nne(med(i))do iiz=1,nerizn = zelem(med(i),iiz) ! Atomic number of this elementwrite(6,220) izn220 FORMAT(' X-ray information for Z=',I3)write(6,230) (ekx(ii,izn),ii=1,10)230 FORMAT(' K-X-ray energy in keV',/,* 4G15.5,/,4G15.5,/,2G15.5)write(6,240) (elx1(ii,izn),ii=1,8)240 FORMAT(' L-1 X-ray in keV',/,4G15.5,/,4G15.5)write(6,250) (elx2(ii,izn),ii=1,5)250 FORMAT(' L-2 X-ray in keV',/,5G15.5)write(6,260) (elx3(ii,izn),ii=1,7)260 FORMAT(' L-3 X-ray in keV',/,4G15.5,/,3G15.5)end doend ifend ifend dowrite(39,fmt="('MSTA')")write(39,fmt="(i4)") nregwrite(39,fmt="(15i4)") (med(i),i=1,nreg)write(39,fmt="('MEND')")!-----------------------------------------------------------------------! Step 6: Initialization-for-howfar!-----------------------------------------------------------------------!-----------------------------------------------------------------------! Step 7: Initialization-for-ausgab!-----------------------------------------------------------------------ncount = 0ilines = 0nwrite = 1054


nlines = 10idin = -1totke = 0.wtsum = 0.iwatch=0! =========================call ecnsv1(0,nreg,totke)call ntally(0,nreg)! =========================write(6,270)270 FORMAT(//,' Energy/Coordinates/Direction cosines/etc.',/,* 6X,'e',14X,'x',14X,'y',14X,'z',* 14X,'u',14X,'v',14X,'w',11X,'iq',3X,'ir',1X,'iarg',/)! Energy bin widthdeltae=ekein / 50! Zero the variablesdepe=0.D0pefs=0.D0pef2s=0.D0tefs=0.D0tef2S=0.D0do j=1,50phs(j)=0.D0ph2s(j)=0.D0do ntype=1,3spec(ntype,j)=0.D0specs(ntype,j)=0.D0spec2s(ntype,j)=0.D0end doend do! Set historiesncases=10000! Set maximum number for pictmaxpict=50tt=etime(tarray)tt0=tarray(1)!-----------------------------------------------------------------------! Step 8: Shower-call!-----------------------------------------------------------------------! Write batch numberwrite(39,fmt="('0 1')")! ========================if(iwatch.gt.0) call swatch(-99,iwatch)! ========================do i=1,ncases! ----------------------! Select incident energy! ----------------------wtin = 1.0wtsum = wtsum + wtinetot = ekein + iabs(iqin)*RMif(iqin.eq.1) thenavailke = ekein + 2.0*RMelseavailke = ekeinend iftotke = totke + availke! ----------------------! Select incident angle! ----------------------! -------------------------! Start of shower call-loop! -------------------------! Keep running sum of weights! Incident total energy (MeV)! Available K.E. (MeV) in system! for positron! Available K.E. (MeV) in system! for photon and electron! Keep running sum of KE! ---------------------------------------------------! Print first NWRITE or NLINES, whichever comes first! ---------------------------------------------------if (ncount .le. nwrite .and. ilines .le. nlines) then55


ilines = ilines + 1write(6,280) etot,xin,yin,zin,uin,vin,win,iqin,irin,idin280 FORMAT(7G15.7,3I5)end if! -----------------------------------------------------------! Compare maximum energy of material data and incident energy! -----------------------------------------------------------if(etot+(1-iabs(iqin))*RM.gt.emaxe) thenwrite(6,fmt="(' Stopped in MAIN.',1 ' (Incident kinetic energy + RM) > min(UE,UP+RM).')")stopend if! ----------------------------------------------------! Verify the normalization of source direction cosines! ----------------------------------------------------if(abs(uin*uin+vin*vin+win*win-1.0).gt.1.e-6) thenwrite(6,fmt="(' Following source direction cosines are not',1 ' normalized.',3e12.5)")uin,vin,winstopend if! ==========================================================call shower (iqin,etot,xin,yin,zin,uin,vin,win,irin,wtin)! ==========================================================! If some energy is deposited inside detector add pulse-height! and efficiency.if (depe .gt. 0.D0) thenie=depe/deltae + 1if (ie .gt. 50) ie = 50phs(ie)=phs(ie)+wtinph2s(ie)=ph2s(ie)+wtin*wtintefs=tefs + wtintef2s=tef2s + wtin*wtinif(depe .ge. ekein*0.999) thenpefs=pefs +wtinpef2s=pef2s +wtin*wtinend ifdepe = 0.D0end ifdo ntype=1,3do ie=1,50specs(ntype,ie)=specs(ntype,ie)+spec(ntype,ie)spec2s(ntype,ie)=spec2s(ntype,ie)+* spec(ntype,ie)*spec(ntype,ie)spec(ntype,ie)=0.D0end doend doncount = ncount + 1! ========================if(iwatch.gt.0) call swatch(-1,iwatch)! ========================end do! ========================if(iwatch.gt.0) call swatch(-88,iwatch)! ========================! Count total number of actual cases! -----------------------! End of CALL SHOWER loop! -----------------------call plotxyz(99,0,0,0.D0,0.D0,0.D0,0.D0,0,0.D0,0.D0)write(39,fmt="('9')")tt=etime(tarray)tt1=tarray(1)cputime=tt1-tt0write(6,300) cputime300 format(' Elapsed Time (sec)=',G15.5)! Set end of batch for CG View!-----------------------------------------------------------------------! Step 9: Output-of-results!-----------------------------------------------------------------------write(6,310) ncount,ncases,totke56


310 FORMAT(/,' Ncount=',I10,' (actual cases run)',/,* ' Ncases=',I10,' (number of cases requested)',/,* ' TotKE =',G15.5,' (total KE (MeV) in run)')if (totke .le. 0.D0) thenwrite(6,320) totke,availke,ncount320 FORMAT(//,' Stopped in MAIN with TotKE=',G15.5,/,* ' AvailKE=',G15.5, /,' Ncount=',I10)stopend iftdet=7.62rdet=3.81tcov=0.1rtcov=0.1tgap=0.5rtgap=0.5write(6,330) tdet,rdet,tcov,rtcov,tgap,rtgap330 FORMAT(/' Detector length=',G15.5,' cm'/* ' Detector radius=',G15.5,' cm'/* ' Al cover thickness=',G10.2,' cm'/* ' Al cover side thickness=',G10.2,' cm'/* ' Front gap =',G10.2,' cm'/' Side gap =',G10.2,' cm'/)write(6,340) ekein340 FORMAT(' Results for ',G15.5,'MeV photon'/)! -----------------------------------! Calculate average and its deviation! -----------------------------------! ---------------! Peak efficiency! ---------------avpe = pefs/ncountpef2s=pef2s/ncountsigpe=dsqrt((pef2s-avpe*avpe)/ncount)avpe = avpe*100.0sigpe = sigpe*100.0write(6,350) avpe,sigpe350 FORMAT(' Peak efficiency =',G11.4,'+-',G9.2,' %')! ----------------! Total efficiency! ----------------avte = tefs/ncounttef2s = tef2s/ncountsigte = dsqrt((tef2s-avte*avte)/ncount)avte = avte*100.0sigte = sigte*100.0write(6,360) avte,sigte360 FORMAT(' Total efficiency =',G11.4,'+-',G9.2,' %')! --------------------------! Pulse height distribution! --------------------------write(6,370)370 FORMAT(/' Pulse height distribution ')do ie=1,50elow=deltae*(ie-1)eup=deltae*ieavph = phs(ie)/ncountph2s(ie)=ph2s(ie)/ncountsigph=dsqrt((ph2s(ie)-avph*avph)/ncount)avph = avph/deltaesigph= sigph/deltaewrite(6,380) eup,avph,sigph380 FORMAT(' E (upper-edge --',G10.4,' MeV )=',G15.5,'+-',G15.5,* ' counts/MeV/incident')end do! ----------------------------------------------------------! Particle spectrum. Incident particle spectrum to detector.! ----------------------------------------------------------write(6,400)400 FORMAT(/' Particle spectrum crossing the detector plane'/* 30X,'particles/MeV/source photon'/* ' Upper energy',11X,' Gamma',18X,' Electron',57


* 14X,' Positron')do ie=1,50elow=deltae*(ie-1)eup=deltae*ie! ----------------------------------! Gamma spectrum per MeV per source! ----------------------------------avspg = specs(1,ie)/ncountspec2s(1,ie)=spec2s(1,ie)/ncountsigspg=dsqrt((spec2s(1,ie)-avspg*avspg)/ncount)avspg=avspg/deltaesigspg= sigspg/deltae! -------------------------------------! Electron spectrum per MeV per source! -------------------------------------avspe = specs(2,ie)/ncountspec2s(2,ie)=spec2s(2,ie)/ncountsigspe=dsqrt((spec2s(2,ie)-avspe*avspe)/ncount)avspe= avspe/deltaesigspe= sigspe/deltae! ------------------------------------! Positron spectrum per MeV per source! ------------------------------------avspp = specs(3,ie)/ncountspec2s(3,ie)=spec2s(3,ie)/ncountsigspp=dsqrt((spec2s(3,ie)-avspp*avspp)/ncount)avspp= avspp/deltaesigspp= sigspp/deltaewrite(6,410) eup,avspg,sigspg,avspe,sigspe,avspp,sigspp410 FORMAT(G10.5,' MeV--',3(G12.5,'+-',G12.5))end donlist=1! =============================call ecnsv1(nlist,nreg,totke)call ntally(nlist,nreg)! =============================! ====================call counters_out(1)! ====================stopend!-------------------------last line of main code------------------------!-------------------------------ausgab.f--------------------------------! <strong>Version</strong>: 080708-1600! Reference: SLAC-265 (p.19-20, Appendix 2)!-----------------------------------------------------------------------!23456789|123456789|123456789|123456789|123456789|123456789|123456789|12! ----------------------------------------------------------------------! Required subroutine for use with the EGS5 Code System! ----------------------------------------------------------------------! A AUSGAB to:!! 1) Score energy deposition! 2) Score particle information enter to detector from outside! 3) Print out particle transport information! 4) call plotxyz if imode=0! ----------------------------------------------------------------------subroutine ausgab(iarg)implicit none58


include 'include/egs5_h.f'include 'include/egs5_epcont.f'include 'include/egs5_misc.f'include 'include/egs5_stack.f'include 'include/egs5_useful.f'include 'auxcommons/aux_h.f'include 'auxcommons/etaly1.f'include 'auxcommons/lines.f'include 'auxcommons/ntaly1.f'include 'auxcommons/watch.f'common/totals/* depe,deltae,spec(3,50),maxpictreal*8 depe,deltae,specinteger maxpictinteger* iargreal*8* edepwtinteger* ie,iql,irl,ntype! ------------------------! Set some local variables! ------------------------irl = ir(np)iql = iq(np)edepwt = edep*wt(np)! Main EGS "header" file! COMMONs required by EGS5 code! Auxiliary-code "header" file! Auxiliary-code COMMONs! Variables to score! Arguments! Local variables! -----------------------------------------------------------! Keep track of energy deposition (for conservation purposes)! -----------------------------------------------------------if (iarg .lt. 5) thenesum(iql+2,irl,iarg+1) = esum(iql+2,irl,iarg+1) + edepwtnsum(iql+2,irl,iarg+1) = nsum(iql+2,irl,iarg+1) + 1end if! -----------------------------------------------------------------! Print out particle transport information (if switch is turned on)! -----------------------------------------------------------------! ========================if (iwatch .gt. 0) call swatch(iarg,iwatch)! ========================if(iarg .ge. 5) return! ----------------------------------------------! Score energy deposition inside NaI detector! ----------------------------------------------if (med(irl) .eq. 1) thendepe = depe + edepwt! ----------------------------------------------------! Score particle information if it enters from outside! ----------------------------------------------------if (irl .ne. irold .and. iarg .eq. 0) thenif (iql .eq. 0) then! photonntype=1ie = e(np)/deltae +1if(ie .gt. 50) ie = 50elseif (iql .eq. -1) then ! electronntype=2ie = (e(np) - RM)/deltae +1if(ie .gt. 50) ie = 50else! positronntype=3ie = (e(np) - RM)/deltae +1if(ie .gt. 50) ie = 50end ifspec(ntype,ie) = spec(ntype,ie) + wt(np)end ifend if59


! ----------------------------------------------------------------! Print out stack information (for limited number cases and lines)! ----------------------------------------------------------------if (ncount .le. nwrite .and. ilines .le. nlines) thenilines = ilines + 1write(6,100) e(np),x(np),y(np),z(np),u(np),v(np),w(np),* iql,irl,iarg100 FORMAT(7G15.7,3I5)end if! ------------------------------------! Output particle information for plot! ------------------------------------if (ncount.le.maxpict) thencall plotxyz(iarg,np,iq(np),x(np),y(np),z(np),e(np),ir(np),* wt(np),time(np))end ifreturnend!--------------------------last line of ausgab.f------------------------!-------------------------------howfar.f--------------------------------! <strong>Version</strong>: 070627-1600! Reference: T. Torii and T. Sugita, "Development of PRESTA-CG! Incorporating Combinatorial Geometry in EGS4/PRESTA", JNC TN1410 2002-201,! Japan Nuclear Cycle Development Institute (2002).! Improved version is provided by T. Sugita. 7/27/2004!-----------------------------------------------------------------------!23456789|123456789|123456789|123456789|123456789|123456789|123456789|12! ----------------------------------------------------------------------! Required (geometry) subroutine for use with the EGS5 Code System! ----------------------------------------------------------------------! This is a CG-HOWFAR.! ----------------------------------------------------------------------ccccccccccsubroutine howfarimplicit noneinclude 'include/egs5_h.f' ! Main EGS "header" fileinclude 'include/egs5_epcont.f' ! COMMONs required by EGS5 codeinclude 'include/egs5_stack.f'include 'auxcommons/geom_common.f' ! geom-common fileinteger i,j,jjj,ir_np,nozone,jty,knointeger irnear,irnext,irlold,irlfg,itvlfg,ihit<strong>cg</strong>double precision xidd,yidd,zidd,x_np,y_np,z_np,u_np,v_np,w_npdouble precision tval,tval0,tval00,tval10,tvalmn,delhowdouble precision atvaltmpinteger iq_npir_np = ir(np)iq_np = iq(np) + 2if(ir_np.le.0) thenwrite(6,*) 'Stopped in howfar with ir(np) izonin'stopend ifif(ir_np.EQ.izonin) thenidisc=1returnend iftval=1.d+30itvalm=0body checku_np=u(np)v_np=v(np)w_np=w(np)60


cccccccccccccccx_np=x(np)y_np=y(np)z_np=z(np)do i=1,nbbody(ir_np)nozone=ABS(nbzone(i,ir_np))jty=itblty(nozone)kno=itblno(nozone)rpp checkif(jty.eq.ityknd(1)) thenif(kno.le.0.or.kno.gt.irppin) go to 190call rpp<strong>cg</strong>1(kno,x_np,y_np,z_np,u_np,v_np,w_np)sph checkelseif(jty.eq.ityknd(2)) thenif(kno.le.0.or.kno.gt.isphin) go to 190call sph<strong>cg</strong>1(kno,x_np,y_np,z_np,u_np,v_np,w_np)rcc checkelseif(jty.eq.ityknd(3)) thenif(kno.le.0.or.kno.gt.irccin) go to 190call rcc<strong>cg</strong>1(kno,x_np,y_np,z_np,u_np,v_np,w_np)trc checkelseif(jty.eq.ityknd(4)) thenif(kno.le.0.or.kno.gt.itrcin) go to 190call trc<strong>cg</strong>1(kno,x_np,y_np,z_np,u_np,v_np,w_np)tor checkelseif(jty.eq.ityknd(5)) thenif(kno.le.0.or.kno.gt.itorin) go to 190call tor<strong>cg</strong>1(kno,x_np,y_np,z_np,u_np,v_np,w_np)rec checkelseif(jty.eq.ityknd(6)) thenif(kno.le.0.or.kno.gt.irecin) go to 190call rec<strong>cg</strong>1(kno,x_np,y_np,z_np,u_np,v_np,w_np)ell checkelseif(jty.eq.ityknd(7)) thenif(kno.le.0.or.kno.gt.iellin) go to 190call ell<strong>cg</strong>1(kno,x_np,y_np,z_np,u_np,v_np,w_np)wed checkelseif(jty.eq.ityknd(8)) thenif(kno.le.0.or.kno.gt.iwedin) go to 190call wed<strong>cg</strong>1(kno,x_np,y_np,z_np,u_np,v_np,w_np)box checkelseif(jty.eq.ityknd(9)) thenif(kno.le.0.or.kno.gt.iboxin) go to 190call box<strong>cg</strong>1(kno,x_np,y_np,z_np,u_np,v_np,w_np)arb checkelseif(jty.eq.ityknd(10)) thenif(kno.le.0.or.kno.gt.iarbin) go to 190call arb<strong>cg</strong>1(kno,x_np,y_np,z_np,u_np,v_np,w_np)hex checkelseif(jty.eq.ityknd(11)) thenif(kno.le.0.or.kno.gt.ihexin) go to 190call hex<strong>cg</strong>1(kno,x_np,y_np,z_np,u_np,v_np,w_np)haf checkelseif(jty.eq.ityknd(12)) thenif(kno.le.0.or.kno.gt.ihafin) go to 190call haf<strong>cg</strong>1(kno,x_np,y_np,z_np,u_np,v_np,w_np)tec checkelseif(jty.eq.ityknd(13)) thenif(kno.le.0.or.kno.gt.itecin) go to 190call tec<strong>cg</strong>1(kno,x_np,y_np,z_np,u_np,v_np,w_np)gel checkelseif(jty.eq.ityknd(14)) thenif(kno.le.0.or.kno.gt.igelin) go to 190call gel<strong>cg</strong>1(kno,x_np,y_np,z_np,u_np,v_np,w_np)cc**** add new geometry in herecend if190 continueend docirnear=ir_npif(itvalm.eq.0) thentval0=<strong>cg</strong>eps1xidd=x_np+tval0*u_np61


ccyidd=y_np+tval0*v_npzidd=z_np+tval0*w_np310 continueif(x_np.ne.xidd.or.y_np.ne.yidd.or.z_np.ne.zidd) goto 320tval0=tval0*10.d0xidd=x_np+tval0*u_npyidd=y_np+tval0*v_npzidd=z_np+tval0*w_npgo to 310320 continuewrite(*,*) 'srzone:1'call srzone(xidd,yidd,zidd,iq_np,ir_np,irnext)if(irnext.ne.ir_np) thentval=0.0d0irnear=irnextelsetval00=0.0d0tval10=10.0d0*tval0irlold=ir_npirlfg=0330 continueif(irlfg.eq.1) go to 340tval00=tval00+tval10if(tval00.gt.1.0d+06) thenwrite(6,9000) iq(np),ir(np),x(np),y(np),z(np),&u(np),v(np),w(np),tval009000 format(' TVAL00 ERROR : iq,ir,x,y,z,u,v,w,tval=',& 2I3,1P7E12.5)stopend ifxidd=x_np+tval00*u_npyidd=y_np+tval00*v_npzidd=z_np+tval00*w_npcall srzold(xidd,yidd,zidd,irlold,irlfg)go to 330340 continuecctval=tval00do j=1,10xidd=x_np+tval00*u_npyidd=y_np+tval00*v_npzidd=z_np+tval00*w_npwrite(*,*) 'srzone:2'call srzone(xidd,yidd,zidd,iq_np,irlold,irnext)if(irnext.ne.irlold) thentval=tval00irnear=irnextend iftval00=tval00-tval0end doif(ir_np.eq.irnear) thenwrite(0,*) 'ir(np),tval=',ir_np,tvalend ifend ifelsedo j=1,itvalm-1do i=j+1,itvalmif(atval(i).lt.atval(j)) thenatvaltmp=atval(i)atval(i)=atval(j)atval(j)=atvaltmpendifenddoenddoitvlfg=0tvalmn=tvaldo jjj=1,itvalmif(tvalmn.gt.atval(jjj)) thentvalmn=atval(jjj)end ifdelhow=<strong>cg</strong>eps2tval0=atval(jjj)+delhowxidd=x_np+tval0*u_npyidd=y_np+tval0*v_npzidd=z_np+tval0*w_np410 continueif(x_np.ne.xidd.or.y_np.ne.yidd.or.z_np.ne.zidd) go to 420delhow=delhow*10.d0tval0=atval(jjj)+delhow62


cxidd=x_np+tval0*u_npyidd=y_np+tval0*v_npzidd=z_np+tval0*w_npgo to 410420 continue&write(*,*) 'srzone:3'call srzone(xidd,yidd,zidd,iq_np,ir_np,irnext)if((irnext.ne.ir_np.or.atval(jjj).ge.1.).and.tval.gt.atval(jjj)) THENtval=atval(jjj)irnear=irnextitvlfg=1goto 425end ifend do425 continueif(itvlfg.eq.0) thentval0=<strong>cg</strong>mnstxidd=x_np+tval0*u_npyidd=y_np+tval0*v_npzidd=z_np+tval0*w_np430 continueif(x_np.ne.xidd.or.y_np.ne.yidd.or.z_np.ne.zidd) go to 440tval0=tval0*10.d0xidd=x_np+tval0*u_npyidd=y_np+tval0*v_npzidd=z_np+tval0*w_npgo to 430440 continueif(tvalmn.gt.tval0) thentval=tvalmnelsetval=tval0end ifend ifend ifihit<strong>cg</strong>=0if(tval.le.ustep) thenustep=tvalihit<strong>cg</strong>=1end ifif(ihit<strong>cg</strong>.eq.1) THENif(irnear.eq.0) THENwrite(6,9200) iq(np),ir(np),x(np),y(np),z(np),&u(np),v(np),w(np),tval9200 format(' TVAL ERROR : iq,ir,x,y,z,u,v,w,tval=',2I3,1P7E12.5)idisc=1itverr=itverr+1if(itverr.ge.100) thenstopend ifreturnend ifirnew=irnearif(irnew.ne.ir_np) thencall rstnxt(iq_np,ir_np,irnew)endifend ifreturnend!--------------------last line of subroutine howfar---------------------63

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!