fd_test2.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/python
  2. import numpy.random
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. from math import sqrt, pi
  6. from Tools.Decomp import DataSet
  7. from Tools.OrthExp import ExpDecompFactory
  8. ###
  9. end = 12.0 # Maximum value to evaluate
  10. Npt = 3000 # Number of points to use
  11. Nbasis = 128 # Number of basis elements to evaluate
  12. Ntrial = 1 # Number of PEs to perform
  13. Bsamp = 1e7 # Number of bkg points per PE
  14. Bmu = 1.0 # bkg gaussian mean
  15. Bsig = 2.0 # bkg gaussian sigma
  16. Lambda = 2.8 # 2.18 #1.5
  17. Alpha = 1.9 # 1.02
  18. x = np.linspace(0, end, Npt)
  19. dx = float(end)/Npt
  20. ###
  21. def gaus(x, mu, sigma):
  22. x = np.array(x)
  23. return np.exp(-( (x-mu)/sigma)**2/2)/(sigma*sqrt(2*pi))
  24. np.set_printoptions(precision=3, linewidth=160)
  25. #np.show_config()
  26. Factory = ExpDecompFactory(Nthread=4, Nbasis=Nbasis, Lambda=Lambda, x0=0.0, Alpha=Alpha, a=0)
  27. for n in range(Ntrial):
  28. # Generate pseudodata
  29. t = numpy.random.normal(loc=Bmu, scale=Bsig, size=int(Bsamp))
  30. D = DataSet( t, Factory)
  31. print "PE: %d/%d; Nevt: %.1f" % (n+1, Ntrial, D.DatNint)
  32. '''
  33. Lbest = np.inf
  34. Pbest = ((0, 0))
  35. for a in np.linspace(1, 2, 11):
  36. for l in np.linspace(1, 3, 21):
  37. L = D.ObjFunc((a, l))
  38. if L < Lbest:
  39. Lbest = L
  40. Pbest = ((a, l))
  41. D.ObjFunc(Pbest)
  42. '''
  43. #D.Decompose()
  44. D.FitW()
  45. #D.ScanN(Nsearch=30)
  46. print "wgt: ", Factory["a"]
  47. print "Nb: ", D.Test.Nmax
  48. print "Mom: ", D.Test.Mom
  49. plt.plot(x, D.Test( x ), color='red', alpha=0.1)
  50. Tf = (Bsamp/D.DatNint) * np.exp(-( (x-Bmu)/Bsig )**2/2)/(Bsig*sqrt(2*pi))
  51. plt.plot(x, Tf, lw=2.5, ls='--', color='black')
  52. plt.yscale('log')
  53. plt.show()
  54. exit()