Commit ffa29eec3fe1c3f02db25661df3a2fbfd64a2251

Authored by Jürgen Knödlseder
1 parent 1a935627

Make show_significance_distribution.py script Python 2.3 compatible

examples/show_significance_distribution.py
@@ -96,7 +96,13 @@ class gaussian(gammalib.GPythonOptimizerFunction): @@ -96,7 +96,13 @@ class gaussian(gammalib.GPythonOptimizerFunction):
96 y = [norm * math.exp(-0.5*(x-mean)**2/(sigma**2)) for x in self._x_vals] 96 y = [norm * math.exp(-0.5*(x-mean)**2/(sigma**2)) for x in self._x_vals]
97 97
98 # Compute weights (1/sqrt(y)) 98 # Compute weights (1/sqrt(y))
99 - weight = [1.0/val if val > 0.0 else 0.0 for val in self._y_vals] 99 + weight = []
  100 + for val in self._y_vals:
  101 + if val > 0.0:
  102 + weight.append(1.0/val)
  103 + else:
  104 + weight.append(0.0)
  105 + #weight = [1.0/val if val > 0.0 else 0.0 for val in self._y_vals]
100 106
101 # Compute Chi Square 107 # Compute Chi Square
102 value = 0.0 108 value = 0.0
@@ -346,16 +352,17 @@ def plot_significance_distribution(mappath, nbins, sigma_min, sigma_max, @@ -346,16 +352,17 @@ def plot_significance_distribution(mappath, nbins, sigma_min, sigma_max,
346 label='significance without exclusions') 352 label='significance without exclusions')
347 353
348 # Set initial Gaussian parameters 354 # Set initial Gaussian parameters
349 - par1 = gammalib.GOptimizerPar('Norm', y.max())  
350 - par2 = gammalib.GOptimizerPar('Mean', 0.0)  
351 - par3 = gammalib.GOptimizerPar('Sigma', 1.0)  
352 - pars = gammalib.GOptimizerPars() 355 + y_max = float(y.max())
  356 + par1 = gammalib.GOptimizerPar('Norm', y_max)
  357 + par2 = gammalib.GOptimizerPar('Mean', 0.0)
  358 + par3 = gammalib.GOptimizerPar('Sigma', 1.0)
  359 + pars = gammalib.GOptimizerPars()
353 pars.append(par1) 360 pars.append(par1)
354 pars.append(par2) 361 pars.append(par2)
355 pars.append(par3) 362 pars.append(par3)
356 363
357 # Set fit function 364 # Set fit function
358 - x = [0.5*(bin_edges[i]+bin_edges[i+1]) for i in range(nbins)] 365 + x = [0.5*(bin_edges[i]+bin_edges[i+1]) for i in range(nbins)]
359 fct = gaussian(x, y) 366 fct = gaussian(x, y)
360 367
361 # Optimize function and compute errors 368 # Optimize function and compute errors