aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_all_gf.py
diff options
context:
space:
mode:
authorshivesh <s.p.mandalia@qmul.ac.uk>2018-05-06 21:22:47 -0500
committershivesh <s.p.mandalia@qmul.ac.uk>2018-05-06 21:22:47 -0500
commit932a8691e16eb904e3eec61daae08d72c2039f10 (patch)
treef82f6fab18bbffbcd8b12f071f597e5cec2302b4 /test/test_all_gf.py
parenta1ab1014c7b2d6be8beffa99b47a57b74b90b876 (diff)
downloadGolemFlavor-932a8691e16eb904e3eec61daae08d72c2039f10.tar.gz
GolemFlavor-932a8691e16eb904e3eec61daae08d72c2039f10.zip
Sun May 6 21:22:46 CDT 2018
Diffstat (limited to 'test/test_all_gf.py')
-rw-r--r--test/test_all_gf.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/test/test_all_gf.py b/test/test_all_gf.py
new file mode 100644
index 0000000..04b0980
--- /dev/null
+++ b/test/test_all_gf.py
@@ -0,0 +1,79 @@
+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()