Commit e41ea9535e1204d0542e3be713af8d7d7ba06447

Authored by Jürgen Knödlseder
Committed by Luigi Tibaldo
1 parent cfa725ca

Make show_significance_distribution.py script Python 2.3 compatible

examples/show_significance_distribution.py
... ... @@ -96,7 +96,13 @@ class gaussian(gammalib.GPythonOptimizerFunction):
96 96 y = [norm * math.exp(-0.5*(x-mean)**2/(sigma**2)) for x in self._x_vals]
97 97  
98 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 107 # Compute Chi Square
102 108 value = 0.0
... ... @@ -346,16 +352,17 @@ def plot_significance_distribution(mappath, nbins, sigma_min, sigma_max,
346 352 label='significance without exclusions')
347 353  
348 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 360 pars.append(par1)
354 361 pars.append(par2)
355 362 pars.append(par3)
356 363  
357 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 366 fct = gaussian(x, y)
360 367  
361 368 # Optimize function and compute errors
... ...