Advertisement
idioticbaka1824

bethebloch-phy5601hw2q4

Oct 3rd, 2022
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.64 KB | Science | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. #everything in SI
  4.  
  5. n=8.49*10**28 #electron density of copper
  6. e=1.60217663*10**-19
  7. c=299792458
  8. me=9.1093837*10**-31
  9. epsilon=8.85418782*10**-12
  10. K1=(n*e**4)/(me*c**2*4*np.pi*epsilon**2)
  11.  
  12. I=322*e #https://physics.nist.gov/PhysRefData/XrayMassCoef/tab1.html #the 'e' is to convert to SI
  13. K2=2*me*c**2/I
  14.  
  15. def dEdx(E, z, m): #Sigmund, Peter. Particle Penetration and Radiation Effects.
  16.     gamma=E/(m*c**2)
  17.     beta=np.sqrt(1-gamma**-2)
  18.     return K1*z**2*beta**-2*(np.log(K2*beta**2*gamma**2)-beta**2)
  19.  
  20. m_mu=1.883531627*10**-28
  21. z_mu=1
  22. m_p=1.67262192*10**-27
  23. z_p=1
  24. m_a=6.6446573357*10**-27
  25. z_a=2
  26.  
  27. betagamma=3
  28. E_mu=m_mu*c**2*np.sqrt(1+betagamma**2)
  29. E_p=m_p*c**2*np.sqrt(1+betagamma**2)
  30. E_a=m_a*c**2*np.sqrt(1+betagamma**2)
  31.  
  32. L=0.1 #10cm in m
  33. ndx=1000
  34. #super basic numerical integration haha
  35. def energy_left(E, z, m, L, ndx): #L=length of copper block, ndx=number of steps
  36.     energy_lost=0
  37.     dx=L/ndx
  38.     for i in range(ndx):
  39.         dE=dx*dEdx(E-energy_lost,z,m)
  40.         energy_lost+=dE
  41.     return E-energy_lost
  42.  
  43. energy_left_mu=energy_left(E_mu, z_mu, m_mu, L, ndx)
  44. energy_left_p=energy_left(E_p, z_p, m_p, L, ndx)
  45. energy_left_a=energy_left(E_a, z_a, m_a, L, ndx)
  46. print('Muon started with ', round(10**-6*E_mu/e, 2), ' MeV. Muon energy left = ', round(10**-6*energy_left_mu/e, 2), ' MeV')
  47. print('Proton started with ', round(10**-6*E_p/e, 2), ' MeV. Proton energy left = ', round(10**-6*energy_left_p/e, 2), ' MeV')
  48. print('Alpha started with ', round(10**-6*E_a/e, 2), ' MeV. Alpha energy left = ', round(10**-6*energy_left_a/e, 2), ' MeV')
  49. print('')
  50.  
  51. L=1
  52. ndx=9000
  53. def rangelength(E, z, m, L, ndx):
  54.     stoppower=[]
  55.     i=0
  56.     energy_lost=0
  57.     dx=L/ndx
  58.     threshold=m*c**2 #'at rest' condition
  59.     while E-energy_lost>=threshold:
  60.         dE=dx*dEdx(E-energy_lost,z,m)
  61.         stoppower.append(dE/dx)
  62.         energy_lost+=dE
  63.         i+=1
  64.     return i*dx, 10**-8*np.array(stoppower)/e
  65.  
  66. range_mu, sp_mu=rangelength(E_mu, z_mu, m_mu, L, ndx)
  67. print('Muon range = ', round(100*range_mu, 2), ' cm.')
  68. range_p, sp_p=rangelength(E_p, z_p, m_p, L, ndx)
  69. print('Proton range = ', round(100*range_p, 2), ' cm.')
  70. range_a, sp_a=rangelength(E_a, z_a, m_a, L, ndx)
  71. print('Alpha range = ', round(100*range_a, 2), ' cm.')
  72.  
  73. #trying to plot bragg peaks but they look weird so never mind :(
  74. '''plt.plot(100*np.array(range(len(sp_mu)))/ndx, sp_mu, label='mu bragg')
  75. plt.plot(100*np.array(range(len(sp_p)))/ndx, sp_p, label='p bragg')
  76. plt.plot(100*np.array(range(len(sp_a)))/ndx, sp_a, label='a bragg')
  77. plt.xlabel('path length (cm)')
  78. plt.ylabel('stopping power (MeV/cm)')
  79. plt.legend()
  80. plt.show()'''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement