Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. import random
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4.  
  5. # Random numerical factors
  6. C_F = 12./5.
  7. alpha_s = .12
  8.  
  9. def sample_stSpace(num):
  10. """Samples points in the triangle 0 < s < 1, 0 < t < 1-s"""
  11. st = []
  12. numTotal = 0
  13. numInside = 0
  14.  
  15. while(len(st) < num):
  16. s,t = random.random(),random.random()
  17. srange = 0 < s and s < 1
  18. trange = 0 < t and t < 1 - s
  19. if(srange and trange):
  20. st.append([s,t])
  21. numInside+=1.
  22. numTotal+=1.
  23. st = np.array(st)
  24. # colors = eventWeight(st[:,0],st[:,1]); plt.scatter(st[:,0],st[:,1],c=colors,s = min(10,1000/num)); plt.show()
  25.  
  26. return st
  27.  
  28. def eventWeight(s,t):
  29. """returns dsigma/(dsdt) in terms of s and t -- the `pdf' (not normalizable) in s and t space"""
  30. return (C_F * alpha_s/(2.*np.pi) ) * ( (s**2. - 2.*s + t**2. - 2.*t + 2)/(s * t) )
  31.  
  32.  
  33. def getThrusts(numbins, numSamplePoints):
  34. """Generates events in st space and returns an np histogram of the variable that we're interested in: looking for the pdf of the function of s and t given by min(s,t,1-s-t)
  35. """
  36. st = sample_stSpace(numSamplePoints)
  37.  
  38. s = st[:,0]; t = st[:,1]
  39. thrusts = np.min(np.array([s,t,1-s-t]), axis=0)
  40. weights = np.array( eventWeight(s,t) * (3.* numbins/2.) / numSamplePoints )
  41. # total weight of a bin = dsigma/dT = <dsigma/(ds dt)>_bin / bin_width --> sum_bins dsigma/dT * bin_width = sigma_total
  42. # THIS IS WHERE I INSERT A FACTOR OF 2 BY HAND: the random variable goes from 0 to 1/3, so the bin width is total_width/numbins = (3 * numbins). I need a factor of 2 to make things right :'(
  43.  
  44. squared_weights = np.array( eventWeight(s,t)**2. * (3.* numbins/2.)**2. / numSamplePoints )
  45.  
  46. return thrusts, weights, squared_weights
  47.  
  48.  
  49. def MC_thrust_Distribution_Plot(numbins, numSamplePoints):
  50. """Plots the analytic and MC `pdf' of the variable min(s,t,1-s-t)"""
  51. thrusts, weights, squared_weights = getThrusts(numbins, numSamplePoints)
  52.  
  53. # Data for Differential Cross Section:
  54. diff_xsec, bins = np.histogram(thrusts, bins=numbins, range=(0,1./3.),weights=weights)
  55. squared_counts, _ = np.histogram(thrusts, bins=numbins, range=(0,1./3.),weights=squared_weights)
  56. num_in_bin, _ = np.histogram(thrusts, bins=numbins, range=(0,1./3.))
  57.  
  58. diff_xsec_error = np.sqrt( squared_counts - np.square(diff_xsec) ) / np.sqrt(num_in_bin)
  59.  
  60. # Analytic Expressions:
  61. diff_xsec_τ_Analytic = lambda τ: C_F*alpha_s*( 3*(1+τ)*(3*τ-1)/τ + (4 + 6*τ*(τ-1))*np.log((1-2*τ)/(τ)) / ((1 - τ)*τ) ) / (2. * np.pi)
  62. analytic_diff_xsec = np.array( diff_xsec_τ_Analytic(np.linspace(.0001,1./3.,numbins)) )
  63.  
  64. #MC Plot
  65. plt.errorbar(x=(bins[:-1]+bins[1:])/2., y=diff_xsec,
  66. xerr=(bins[:-1]-bins[1:])/2., yerr=diff_xsec_error, color='orange', label='MC EMD diff_xsec')
  67. #Analytic plot
  68. plt.plot(np.linspace(.0001,1./3.,numbins), analytic_diff_xsec, 'b--', label='Analytic Result')
  69.  
  70. plt.show()
  71.  
  72.  
  73. if __name__ == "__main__":
  74. MC_thrust_Distribution_Plot(100, 100000)
  75. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement