From 9926a742261d0e64b66d3227b5d346030eabce47 Mon Sep 17 00:00:00 2001 From: Shivesh Mandalia Date: Tue, 5 Nov 2019 12:09:28 -0600 Subject: add gf freq test --- .gitignore | 2 +- test/test_gf_freq.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ utils/plot.py | 3 ++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 test/test_gf_freq.py diff --git a/.gitignore b/.gitignore index 6fbed04..0603bba 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ mnrun_* mnrun/ plot_llh/frs plot_llh/chains -test/ +test/bayesian *.tar.gz *.tar *.gz diff --git a/test/test_gf_freq.py b/test/test_gf_freq.py new file mode 100644 index 0000000..3abfd87 --- /dev/null +++ b/test/test_gf_freq.py @@ -0,0 +1,80 @@ +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 set_up_as(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.SetFitParametersSeed(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 +set_up_as(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 +set_up_as(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/utils/plot.py b/utils/plot.py index 1f4b5a6..a4fc5ce 100644 --- a/utils/plot.py +++ b/utils/plot.py @@ -822,6 +822,9 @@ def plot_x(data, outfile, outformat, args, normalise=False): if dim != 4 or dim != 3: yticks = range(ylims[0], ylims[1], 2) + [ylims[1]] ax.set_yticks(yticks, minor=False) + if dim == 3 or dim == 4: + yticks = range(ylims[0], ylims[1], 1) + [ylims[1]] + ax.set_yticks(yticks, minor=False) # for ymaj in ax.yaxis.get_majorticklocs(): # ax.axhline(y=ymaj, ls=':', color='gray', alpha=0.2, linewidth=1) for xmaj in xticks: -- cgit v1.2.3