aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_LV.py96
-rw-r--r--test/test_NSI.py106
-rw-r--r--test/test_all_gf.py79
-rw-r--r--test/test_gf.py89
-rw-r--r--test/test_gf_freq.py80
-rw-r--r--test/test_gf_simple.py66
6 files changed, 0 insertions, 516 deletions
diff --git a/test/test_LV.py b/test/test_LV.py
deleted file mode 100644
index 72d0a9c..0000000
--- a/test/test_LV.py
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/usr/bin/env python
-
-from __future__ import absolute_import, division
-
-import numpy as np
-import matplotlib
-matplotlib.use('Agg')
-import matplotlib.pyplot as plt
-from matplotlib import rc
-
-import GolemFitPy as gf
-
-rc('text', usetex=True)
-rc('font', **{'family':'serif', 'serif':['Computer Modern'], 'size':18})
-
-dp = gf.DataPaths()
-steer = gf.SteeringParams()
-
-fig = plt.figure(figsize=[12, 8])
-ax = fig.add_subplot(111)
-ax.set_xscale('log')
-ax.set_yscale('log')
-
-npp = gf.NewPhysicsParams()
-npp.type = gf.NewPhysicsType.None
-# npp.n_lv = 1
-# npp.lambda_1 = 1.e100
-# npp.lambda_2 = 1.e100
-
-golem = gf.GolemFit(dp, steer, npp)
-
-binning = golem.GetEnergyBinsMC()
-ax.set_xlim(binning[0], binning[-1])
-# ax.set_ylim(binning[0], binning[-1])
-
-fit_params = gf.FitParameters(gf.sampleTag.HESE)
-golem.SetupAsimov(fit_params)
-
-exp = np.sum(golem.GetExpectation(fit_params), axis=(0, 1, 2, 3))
-ax.step(binning, np.concatenate([[exp[0]], exp]), alpha=1,
- drawstyle='steps-pre', label='NULL', linestyle='--')
-
-print 'NULL min_llh', golem.MinLLH().likelihood
-print 'NULL expectation', exp
-print
-
-npp = gf.NewPhysicsParams()
-npp.type = gf.NewPhysicsType.LorentzViolation
-npp.n_lv = 1
-npp.lambda_1 = 1.e20
-npp.lambda_2 = 1.e20
-
-golem.SetNewPhysicsParams(npp)
-
-exp = np.sum(golem.GetExpectation(fit_params), axis=(0, 1, 2, 3))
-ax.step(binning, np.concatenate([[exp[0]], exp]), alpha=1,
- drawstyle='steps-pre', label='1e-20 LV', linestyle='--')
-
-print '1e20 LV min_llh', golem.MinLLH().likelihood
-print '1e20 LV expectation', exp
-
-npp = gf.NewPhysicsParams()
-npp.type = gf.NewPhysicsType.LorentzViolation
-npp.n_lv = 1
-npp.lambda_1 = 1.e10
-npp.lambda_2 = 1.e10
-
-golem.SetNewPhysicsParams(npp)
-
-exp = np.sum(golem.GetExpectation(fit_params), axis=(0, 1, 2, 3))
-ax.step(binning, np.concatenate([[exp[0]], exp]), alpha=1,
- drawstyle='steps-pre', label='1e-10 LV', linestyle='--')
-
-print '1e10 LV min_llh', golem.MinLLH().likelihood
-print '1e10 LV expectation', exp
-
-npp = gf.NewPhysicsParams()
-npp.type = gf.NewPhysicsType.LorentzViolation
-npp.n_lv = 1
-npp.lambda_1 = 1.e-20
-npp.lambda_2 = 1.e-20
-
-golem.SetNewPhysicsParams(npp)
-
-ax.tick_params(axis='x', labelsize=12)
-ax.tick_params(axis='y', labelsize=12)
-ax.set_xlabel(r'Deposited energy / GeV')
-ax.set_ylabel(r'Events')
-for xmaj in ax.xaxis.get_majorticklocs():
- ax.axvline(x=xmaj, ls=':', color='gray', alpha=0.7, linewidth=1)
-for ymaj in ax.yaxis.get_majorticklocs():
- ax.axhline(y=ymaj, ls=':', color='gray', alpha=0.7, linewidth=1)
-
-legend = ax.legend(prop=dict(size=12))
-fig.savefig('test.png', bbox_inches='tight', dpi=250)
-
diff --git a/test/test_NSI.py b/test/test_NSI.py
deleted file mode 100644
index d144420..0000000
--- a/test/test_NSI.py
+++ /dev/null
@@ -1,106 +0,0 @@
-#!/usr/bin/env python
-
-from __future__ import absolute_import, division
-
-import numpy as np
-import matplotlib
-matplotlib.use('Agg')
-import matplotlib.pyplot as plt
-from matplotlib import rc
-
-import GolemFitPy as gf
-
-rc('text', usetex=True)
-rc('font', **{'family':'serif', 'serif':['Computer Modern'], 'size':18})
-
-dp = gf.DataPaths()
-steer = gf.SteeringParams()
-npp = gf.NewPhysicsParams()
-
-steer.quiet = False
-steer.fastmode = True
-
-golem = gf.GolemFit(dp, steer, npp)
-
-fit_params = gf.FitParameters(gf.sampleTag.HESE)
-golem.SetupAsimov(fit_params)
-
-fig = plt.figure(figsize=[6, 5])
-ax = fig.add_subplot(111)
-ax.set_xscale('log')
-ax.set_yscale('log')
-
-binning = golem.GetEnergyBinsMC()
-ax.set_xlim(binning[0], binning[-1])
-# ax.set_ylim(binning[0], binning[-1])
-
-print 'NULL min_llh', golem.MinLLH().likelihood
-
-# exp = np.sum(golem.GetExpectation(fit_params), axis=(0, 1, 2, 3))
-# ax.step(binning, np.concatenate([[exp[0]], exp]), alpha=1,
-# drawstyle='steps-pre', label='NULL', linestyle='--')
-
-# print 'NULL expectation', exp
-print
-
-npp.type = gf.NewPhysicsType.NonStandardInteraction
-npp.epsilon_mutau = 0.1
-golem.SetNewPhysicsParams(npp)
-
-print '0.1 mutau min_llh', golem.MinLLH().likelihood
-
-# exp = np.sum(golem.GetExpectation(fit_params), axis=(0, 1, 2, 3))
-# ax.step(binning, np.concatenate([[exp[0]], exp]), alpha=1,
-# drawstyle='steps-pre', label='0.1 mutau', linestyle='--')
-
-# print '0.1 mutau expectation', exp
-print
-
-np.epsilon_mutau = 0.2
-golem.SetNewPhysicsParams(npp)
-
-print '0.2 mutau min_llh', golem.MinLLH().likelihood
-
-# exp = np.sum(golem.GetExpectation(fit_params), axis=(0, 1, 2, 3))
-# ax.step(binning, np.concatenate([[exp[0]], exp]), alpha=1,
-# drawstyle='steps-pre', label='0.2 mutau', linestyle='--')
-
-# print '0.2 mutau expectation', exp
-print
-
-np.epsilon_mutau = 0.3
-golem.SetNewPhysicsParams(npp)
-
-print '0.3 mutau min_llh', golem.MinLLH().likelihood
-
-# exp = np.sum(golem.GetExpectation(fit_params), axis=(0, 1, 2, 3))
-# ax.step(binning, np.concatenate([[exp[0]], exp]), alpha=1,
-# drawstyle='steps-pre', label='0.3 mutau', linestyle='--')
-
-# print '0.3 mutau expectation', exp
-print
-
-np.epsilon_mutau = 0.4
-golem.SetNewPhysicsParams(npp)
-
-print '0.4 mutau min_llh', golem.MinLLH().likelihood
-
-# exp = np.sum(golem.GetExpectation(fit_params), axis=(0, 1, 2, 3))
-# ax.step(binning, np.concatenate([[exp[0]], exp]), alpha=1,
-# drawstyle='steps-pre', label='0.4 mutau', linestyle='--')
-
-# print '0.4 mutau expectation', exp
-print
-
-ax.tick_params(axis='x', labelsize=12)
-ax.tick_params(axis='y', labelsize=12)
-ax.set_xlabel(r'Deposited energy / GeV')
-ax.set_ylabel(r'Events')
-for xmaj in ax.xaxis.get_majorticklocs():
- ax.axvline(x=xmaj, ls=':', color='gray', alpha=0.7, linewidth=1)
-for ymaj in ax.yaxis.get_majorticklocs():
- ax.axhline(y=ymaj, ls=':', color='gray', alpha=0.7, linewidth=1)
-
-legend = ax.legend(prop=dict(size=12))
-fig.savefig('test_NSI.png', bbox_inches='tight', dpi=250)
-
diff --git a/test/test_all_gf.py b/test/test_all_gf.py
deleted file mode 100644
index 04b0980..0000000
--- a/test/test_all_gf.py
+++ /dev/null
@@ -1,79 +0,0 @@
-import numpy as np
-import matplotlib as mpl
-mpl.use('Agg')
-import matplotlib.pyplot as plt
-
-import GolemFitPy as gf
-
-FASTMODE = True
-PARAMETERS = [
- # 'astroFlavorAngle1', 'astroFlavorAngle2',
- 'convNorm',
- # 'promptNorm', 'muonNorm', 'astroNorm'
-]
-DEFAULTS = [
- # 4/9., 0., 1., 0., 1., 6.9
- 1.
-]
-RANGES = [
- # (0, 1), (-1, 1), (0.01, 10), (0., 30), (0.01, 10), (0.01, 30)
- (0.01, 10)
-]
-BINS = 50
-
-def steering_params():
- steering_categ = 'p2_0'
- params = gf.SteeringParams(gf.sampleTag.HESE)
- if FASTMODE:
- params.fastmode = True
- params.quiet = False
- params.simToLoad= steering_categ.lower()
- return params
-
-def set_up_as(fitter, params):
- print 'Injecting the model', params
- asimov_params = gf.FitParameters(gf.sampleTag.HESE)
- for x in params.iterkeys():
- asimov_params.__setattr__(x, float(params[x]))
- fitter.SetupAsimov(asimov_params)
- priors = gf.Priors()
- priors.convNormWidth = 9e9
- fitter.SetFitPriors(priors)
-
-def setup_fitter(asimov_paramset):
- datapaths = gf.DataPaths()
- sparams = steering_params()
- npp = gf.NewPhysicsParams()
- fitter = gf.GolemFit(datapaths, sparams, npp)
- set_up_as(fitter, asimov_paramset)
- return fitter
-
-def get_llh(fitter, params):
- fitparams = gf.FitParameters(gf.sampleTag.HESE)
- for x in params.iterkeys():
- fitparams.__setattr__(x, float(params[x]))
- llh = -fitter.EvalLLH(fitparams)
- return llh
-
-for ip, param in enumerate(PARAMETERS):
- asimov_paramset = {param: DEFAULTS[ip]}
- print 'injecting', asimov_paramset
- fitter = setup_fitter(asimov_paramset)
- binning = np.linspace(RANGES[ip][0], RANGES[ip][1], BINS)
- llhs = []
- for b in binning:
- test_paramset = {param: b}
- print 'testing', test_paramset
- llh = get_llh(fitter, test_paramset)
- print 'llh', llh
- llhs.append(llh)
- plt.plot(binning, llhs)
- plt.axvline(x=DEFAULTS[ip])
- plt.xlabel(param)
- plt.ylabel('LLH')
- outfile = 'llh_profile_noprior_'
- if FASTMODE:
- plt.savefig(outfile + 'fastmode_{0}.png'.format(param))
- else:
- plt.savefig(outfile + '{0}.png'.format(param))
- plt.clf()
diff --git a/test/test_gf.py b/test/test_gf.py
deleted file mode 100644
index 4b77924..0000000
--- a/test/test_gf.py
+++ /dev/null
@@ -1,89 +0,0 @@
-import numpy.ma as ma
-
-import GolemFitPy as gf
-
-FASTMODE = True
-
-def steering_params():
- steering_categ = 'p2_0'
- params = gf.SteeringParams(gf.sampleTag.HESE)
- if FASTMODE:
- params.fastmode = True
- params.quiet = False
- params.simToLoad= steering_categ.lower()
- return params
-
-def set_up_as(fitter, params):
- print 'Injecting the model', params
- asimov_params = gf.FitParameters(gf.sampleTag.HESE)
- for x in params.iterkeys():
- asimov_params.__setattr__(x, float(params[x]))
- fitter.SetupAsimov(asimov_params)
-
-def setup_fitter(asimov_paramset):
- datapaths = gf.DataPaths()
- sparams = steering_params()
- npp = gf.NewPhysicsParams()
- fitter = gf.GolemFit(datapaths, sparams, npp)
- set_up_as(fitter, asimov_paramset)
- return fitter
-
-def get_llh(fitter, params):
- fitparams = gf.FitParameters(gf.sampleTag.HESE)
- for x in params.iterkeys():
- fitparams.__setattr__(x, float(params[x]))
- llh = -fitter.EvalLLH(fitparams)
- return llh
-
-asimov_paramset = {'astroFlavorAngle1': 4/9., 'astroFlavorAngle2': 0.}
-print 'injecting', asimov_paramset
-fitter = setup_fitter(asimov_paramset)
-
-test_paramset = {'astroFlavorAngle1': 0.36, 'astroFlavorAngle2': -0.57}
-print 'testing', test_paramset
-print 'llh', get_llh(fitter, test_paramset)
-
-test_paramset = {'astroFlavorAngle1': 0.385224559219, 'astroFlavorAngle2': -0.157617854374}
-print 'testing', test_paramset
-print 'llh', get_llh(fitter, test_paramset)
-
-test_paramset = {'astroFlavorAngle1': 0.415578500878, 'astroFlavorAngle2': -0.0196186993217}
-print 'testing', test_paramset
-print 'llh', get_llh(fitter, test_paramset)
-
-test_paramset = {'astroFlavorAngle1': 4/9., 'astroFlavorAngle2': 0}
-print 'testing', test_paramset
-print 'llh', get_llh(fitter, test_paramset)
-
-test_paramset = {'astroFlavorAngle1': 4/9., 'astroFlavorAngle2': 0}
-print 'testing', test_paramset
-print 'llh', get_llh(fitter, test_paramset)
-
-
-import numpy as np
-import matplotlib as mpl
-mpl.use('Agg')
-import matplotlib.pyplot as plt
-
-shape = (10, 100)
-angle1_binning = np.linspace(0, 1, shape[0])
-angle2_binning = np.linspace(-1, 1, shape[1])
-
-for an1 in angle1_binning:
- llhs = []
- for an2 in angle2_binning:
- test_paramset = {'astroFlavorAngle1': an1, 'astroFlavorAngle2': an2}
- llh = get_llh(fitter, test_paramset)
- if abs(llh) > 9e9:
- llhs.append(np.nan)
- else:
- llhs.append(llh)
- llhs = ma.masked_invalid(llhs)
- plt.plot(angle2_binning, llhs, label='astroFlavorAngle1 = {0}'.format(an1))
-plt.xlabel('astroFlavorAngle2')
-plt.ylabel('LLH')
-plt.legend()
-if FASTMODE:
- plt.savefig('llh_profile_fastmode.png'.format(an1))
-else:
- plt.savefig('llh_profile.png'.format(an1))
diff --git a/test/test_gf_freq.py b/test/test_gf_freq.py
deleted file mode 100644
index e6ca5f4..0000000
--- a/test/test_gf_freq.py
+++ /dev/null
@@ -1,80 +0,0 @@
-import GolemFitPy as gf
-
-FASTMODE = False
-
-def steering_params():
- steering_categ = 'p2_0'
- params = gf.SteeringParams(gf.sampleTag.MagicTau)
- params.quiet = False
- if FASTMODE:
- params.fastmode = True
- else:
- params.fastmode = False
- params.simToLoad= steering_categ.lower()
- params.evalThreads = 4
- params.minFitEnergy = 6E4 # GeV
- params.maxFitEnergy = 1E7 # GeV
- params.load_data_from_text_file = False
- params.do_HESE_reshuffle=False
- params.use_legacy_selfveto_calculation = False
- return params
-
-def setup_fitter():
- datapaths = gf.DataPaths()
- sparams = steering_params()
- npp = gf.NewPhysicsParams()
- fitter = gf.GolemFit(datapaths, sparams, npp)
- return fitter
-
-def fit_flags(fitter):
- default_flags = {
- # False means it's not fixed in minimization
- 'astroFlavorAngle1' : False,
- 'astroFlavorAngle2' : False,
- 'astroNorm' : True,
- }
- flags = gf.FitParametersFlag()
- gf_nuisance = []
- for param in default_flags.keys():
- if default_flags[param]:
- flags.__setattr__(param, True)
- else:
- print 'Setting param {0:<15} to float in the ' \
- 'minimisation'.format(param)
- flags.__setattr__(param, False)
- fitter.SetFitParametersFlag(flags)
-
-def setup_asimov(fitter, params):
- print 'Injecting the model', params
- asimov_params = gf.FitParameters(gf.sampleTag.MagicTau)
- for x in params.keys():
- asimov_params.__setattr__(x, float(params[x]))
- fitter.SetupAsimov(asimov_params)
-
-def get_bf_freq(fitter):
- bf = fitter.MinLLH()
- return bf
-
-# Setup fitter
-fitter = setup_fitter()
-fit_flags(fitter)
-
-params = {'astroFlavorAngle1': 4/9., 'astroFlavorAngle2': 0.}
-print
-setup_asimov(fitter, params)
-print 'fitting...'
-bf = get_bf_freq(fitter)
-print 'bestfit params = astroFlavorAngle1:', bf.params.astroFlavorAngle1, \
- ', astroFlavorAngle2:', bf.params.astroFlavorAngle2
-print 'bestfit llh =', -bf.likelihood
-print
-
-params = {'astroFlavorAngle1': 2/6., 'astroFlavorAngle2': 1/2.}
-print
-setup_asimov(fitter, params)
-print 'fitting...'
-bf = get_bf_freq(fitter)
-print 'bestfit params = astroFlavorAngle1:', bf.params.astroFlavorAngle1, \
- ', astroFlavorAngle2:', bf.params.astroFlavorAngle2
-print 'bestfit llh =', -bf.likelihood
-print
diff --git a/test/test_gf_simple.py b/test/test_gf_simple.py
deleted file mode 100644
index daa14a4..0000000
--- a/test/test_gf_simple.py
+++ /dev/null
@@ -1,66 +0,0 @@
-import numpy as np
-import matplotlib as mpl
-mpl.use('Agg')
-import matplotlib.pyplot as plt
-
-import GolemFitPy as gf
-
-FASTMODE = False
-
-dp = gf.DataPaths()
-npp = gf.NewPhysicsParams()
-sp = gf.SteeringParams(gf.sampleTag.MagicTau)
-
-sp.quiet = False
-if FASTMODE:
- sp.fastmode = True
-# sp.frequentist = True
-sp.load_data_from_text_file = False
-
-golem = gf.GolemFit(dp, sp, npp)
-
-fp = gf.FitParameters(gf.sampleTag.MagicTau)
-fp.astroFlavorAngle1 = 4./9.
-fp.astroFlavorAngle2 = 0.
-
-# golem.SetupAsimov(fp)
-seed = 0
-golem.Swallow(golem.SpitRealization(fp, seed))
-
-fp_sh = gf.FitParameters(gf.sampleTag.MagicTau)
-# fp_sh.astroFlavorAngle1 = 0.36
-# fp_sh.astroFlavorAngle2 = -0.57
-fp_sh.astroFlavorAngle1 = 0.
-fp_sh.astroFlavorAngle2 = 1.
-
-print 'Eval fp = {0}'.format(golem.EvalLLH(fp))
-
-# energy_centers = golem.GetEnergyBinsMC()[:-1]+ np.diff(golem.GetEnergyBinsMC())/2.
-
-# plt.hist(energy_centers,bins=golem.GetEnergyBinsMC(),
-# weights=np.sum(golem.GetExpectation(fp),axis=(0,1,2,3)),
-# histtype="step", lw = 2, label='injected')
-
-# data_energy_dist = np.sum(golem.GetDataDistribution(),axis=(0,1,2,3))
-# energy_centers=golem.GetEnergyBinsData()[:-1]+ np.diff(golem.GetEnergyBinsData())/2.
-# plt.errorbar(energy_centers,data_energy_dist,yerr = np.sqrt(data_energy_dist),fmt='o')
-
-print 'Eval fp_sh = {0}'.format(golem.EvalLLH(fp_sh))
-
-# plt.hist(energy_centers,bins=golem.GetEnergyBinsMC(),
-# weights=np.sum(golem.GetExpectation(fp_sh),axis=(0,1,2,3)),
-# histtype="step", lw = 2, label='test')
-
-# data_energy_dist = np.sum(golem.GetDataDistribution(),axis=(0,1,2,3))
-# energy_centers=golem.GetEnergyBinsData()[:-1]+ np.diff(golem.GetEnergyBinsData())/2.
-# plt.errorbar(energy_centers,data_energy_dist,yerr = np.sqrt(data_energy_dist),fmt='o')
-
-# plt.loglog(nonposy="clip")
-# plt.xlabel(r"Deposited energy/GeV")
-# plt.ylabel(r"Events")
-
-# outname = 'Expectation'
-# if FASTMODE:
-# plt.savefig(outname + 'fastmode.png')
-# else:
-# plt.savefig(outname + '.png')