aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rwxr-xr-xutils/plot-atmospheric-fluxes53
-rwxr-xr-xutils/plot-atmospheric-oscillations48
-rwxr-xr-xutils/plot-energy76
-rwxr-xr-xutils/plot-fit-results54
-rwxr-xr-xutils/plot-root-results46
-rw-r--r--utils/sddm/__init__.py39
-rwxr-xr-xutils/sddm/plot.py9
7 files changed, 95 insertions, 230 deletions
diff --git a/utils/plot-atmospheric-fluxes b/utils/plot-atmospheric-fluxes
index 7dafbbb..042981c 100755
--- a/utils/plot-atmospheric-fluxes
+++ b/utils/plot-atmospheric-fluxes
@@ -30,59 +30,18 @@ if __name__ == '__main__':
import argparse
import matplotlib
import glob
+ from sddm import setup_matplotlib
parser = argparse.ArgumentParser("plot solar fluxes")
parser.add_argument("filenames", nargs='+', help="filenames of flux files")
parser.add_argument("--save", action="store_true", default=False, help="save plots")
args = parser.parse_args()
- if args.save:
- # default \textwidth for a fullpage article in Latex is 16.50764 cm.
- # You can figure this out by compiling the following TeX document:
- #
- # \documentclass{article}
- # \usepackage{fullpage}
- # \usepackage{layouts}
- # \begin{document}
- # textwidth in cm: \printinunitsof{cm}\prntlen{\textwidth}
- # \end{document}
-
- width = 16.50764
- width /= 2.54 # cm -> inches
- # According to this page:
- # http://www-personal.umich.edu/~jpboyd/eng403_chap2_tuftegospel.pdf,
- # Tufte suggests an aspect ratio of 1.5 - 1.6.
- height = width/1.5
- FIGSIZE = (width,height)
-
- import matplotlib.pyplot as plt
-
- font = {'family':'serif', 'serif': ['computer modern roman']}
- plt.rc('font',**font)
-
- plt.rc('text', usetex=True)
- else:
- # on retina screens, the default plots are way too small
- # by using Qt5 and setting QT_AUTO_SCREEN_SCALE_FACTOR=1
- # Qt5 will scale everything using the dpi in ~/.Xresources
- import matplotlib
- matplotlib.use("Qt5Agg")
-
- import matplotlib.pyplot as plt
-
- # Default figure size. Currently set to my monitor width and height so that
- # things are properly formatted
- FIGSIZE = (13.78,7.48)
-
- font = {'family':'serif', 'serif': ['computer modern roman']}
- plt.rc('font',**font)
-
- # Make the defalt font bigger
- plt.rc('font', size=22)
-
- plt.rc('text', usetex=True)
-
- fig = plt.figure(figsize=FIGSIZE)
+ setup_matplotlib(args.save)
+
+ import matplotlib.pyplot as plt
+
+ fig = plt.figure()
colors = plt.rcParams["axes.prop_cycle"].by_key()["color"]
linestyles = ['-','--']
diff --git a/utils/plot-atmospheric-oscillations b/utils/plot-atmospheric-oscillations
index c24a776..2d2a0bf 100755
--- a/utils/plot-atmospheric-oscillations
+++ b/utils/plot-atmospheric-oscillations
@@ -11,52 +11,16 @@ import numpy as np
if __name__ == '__main__':
import argparse
from os.path import split, splitext
+ from sddm import setup_matplotlib
parser = argparse.ArgumentParser("script to plot atmospheric oscillations")
parser.add_argument("filenames", nargs='+', help="oscillation probability filenames")
parser.add_argument("--save", action="store_true", default=False, help="save plots")
args = parser.parse_args()
- if args.save:
- # default \textwidth for a fullpage article in Latex is 16.50764 cm.
- # You can figure this out by compiling the following TeX document:
- #
- # \documentclass{article}
- # \usepackage{fullpage}
- # \usepackage{layouts}
- # \begin{document}
- # textwidth in cm: \printinunitsof{cm}\prntlen{\textwidth}
- # \end{document}
+ setup_matplotlib(args.save)
- width = 16.50764
- width /= 2.54 # cm -> inches
- # According to this page:
- # http://www-personal.umich.edu/~jpboyd/eng403_chap2_tuftegospel.pdf,
- # Tufte suggests an aspect ratio of 1.5 - 1.6.
- height = width/1.5
- FIGSIZE = (width,height)
-
- import matplotlib.pyplot as plt
-
- font = {'family':'serif', 'serif': ['computer modern roman']}
- plt.rc('font',**font)
-
- plt.rc('text', usetex=True)
- else:
- # on retina screens, the default plots are way too small
- # by using Qt5 and setting QT_AUTO_SCREEN_SCALE_FACTOR=1
- # Qt5 will scale everything using the dpi in ~/.Xresources
- import matplotlib
- matplotlib.use("Qt5Agg")
-
- import matplotlib.pyplot as plt
-
- # Default figure size. Currently set to my monitor width and height so that
- # things are properly formatted
- FIGSIZE = (13.78,7.48)
-
- # Make the defalt font bigger
- plt.rc('font', size=22)
+ import matplotlib.pyplot as plt
for filename in args.filenames:
head, tail = split(filename)
@@ -74,7 +38,7 @@ if __name__ == '__main__':
levels = np.linspace(0,1,101)
- plt.figure(figsize=FIGSIZE)
+ plt.figure()
plt.contourf(ee,zz,pnue,levels=levels)
plt.gca().set_xscale('log')
plt.xlabel("Energy (GeV)")
@@ -86,7 +50,7 @@ if __name__ == '__main__':
plt.savefig("%s_nue.eps" % root)
else:
plt.title(r"Probability to oscillate to $\nu_e$")
- plt.figure(figsize=FIGSIZE)
+ plt.figure()
plt.contourf(ee,zz,pnum,levels=levels)
plt.gca().set_xscale('log')
plt.xlabel("Energy (GeV)")
@@ -98,7 +62,7 @@ if __name__ == '__main__':
plt.savefig("%s_num.eps" % root)
else:
plt.title(r"Probability to oscillate to $\nu_\mu$")
- plt.figure(figsize=FIGSIZE)
+ plt.figure()
plt.contourf(ee,zz,pnut,levels=levels)
plt.gca().set_xscale('log')
plt.xlabel("Energy (GeV)")
diff --git a/utils/plot-energy b/utils/plot-energy
index 5c33969..f082b8c 100755
--- a/utils/plot-energy
+++ b/utils/plot-energy
@@ -56,7 +56,9 @@ def plot_hist2(df, muons=False):
plt.hist(np.log10(df_id.ke.values/1000), bins=np.linspace(0,4.5,100), histtype='step')
plt.xlabel("log10(Energy (GeV))")
else:
- plt.hist(df_id.ke.values, bins=np.linspace(20,10e3,100), histtype='step')
+ bins = np.logspace(np.log10(20),np.log10(10e3),21)
+ plt.hist(df_id.ke.values, bins=bins, histtype='step')
+ plt.gca().set_xscale("log")
plt.xlabel("Energy (MeV)")
plt.title('$' + ''.join([particle_id[int(''.join(x))] for x in grouper(str(id),2)]) + '$')
@@ -103,6 +105,7 @@ if __name__ == '__main__':
import h5py
from sddm.plot_energy import *
from sddm.plot import despine
+ from sddm import setup_matplotlib
parser = argparse.ArgumentParser("plot fit results")
parser.add_argument("filenames", nargs='+', help="input files")
@@ -110,46 +113,9 @@ if __name__ == '__main__':
parser.add_argument("--save", action='store_true', default=False, help="save corner plots for backgrounds")
args = parser.parse_args()
- if args.save:
- # default \textwidth for a fullpage article in Latex is 16.50764 cm.
- # You can figure this out by compiling the following TeX document:
- #
- # \documentclass{article}
- # \usepackage{fullpage}
- # \usepackage{layouts}
- # \begin{document}
- # textwidth in cm: \printinunitsof{cm}\printlen{\textwidth}
- # \end{document}
-
- width = 16.50764
- width /= 2.54 # cm -> inches
- # According to this page:
- # http://www-personal.umich.edu/~jpboyd/eng403_chap2_tuftegospel.pdf,
- # Tufte suggests an aspect ratio of 1.5 - 1.6.
- height = width/1.5
- FIGSIZE = (width,height)
-
- import matplotlib.pyplot as plt
-
- font = {'family':'serif', 'serif': ['computer modern roman']}
- plt.rc('font',**font)
-
- plt.rc('text', usetex=True)
- else:
- # on retina screens, the default plots are way too small
- # by using Qt5 and setting QT_AUTO_SCREEN_SCALE_FACTOR=1
- # Qt5 will scale everything using the dpi in ~/.Xresources
- import matplotlib
- matplotlib.use("Qt5Agg")
-
- import matplotlib.pyplot as plt
-
- # Default figure size. Currently set to my monitor width and height so that
- # things are properly formatted
- FIGSIZE = (13.78,7.48)
+ setup_matplotlib(args.save)
- # Make the defalt font bigger
- plt.rc('font', size=22)
+ import matplotlib.pyplot as plt
ev = pd.concat([pd.read_hdf(filename, "ev") for filename in args.filenames],ignore_index=True)
fits = pd.concat([pd.read_hdf(filename, "fits") for filename in args.filenames],ignore_index=True)
@@ -339,11 +305,11 @@ if __name__ == '__main__':
plot_corner_plot(noise,"Noise")
plot_corner_plot(signal,"Signal")
- fig = plt.figure(figsize=FIGSIZE)
+ fig = plt.figure()
plot_hist2(flashers)
despine(fig,trim=True)
plt.suptitle("Flashers")
- fig = plt.figure(figsize=FIGSIZE)
+ fig = plt.figure()
plot_hist2(muon,muons=True)
despine(fig,trim=True)
plt.suptitle("Muons")
@@ -460,15 +426,19 @@ if __name__ == '__main__':
muon_best_fit = muons.sort_values('fmin').groupby(['run','gtid']).nth(0)
muons = muons[muons.id == 22].sort_values('fmin').groupby(['run','gtid'],as_index=False).nth(0).reset_index(level=0,drop=True)
- # require r < 6 meters
+ # require (r/r_psup)^3 < 0.9
prompt = prompt[prompt.r_psup < 0.9]
atm = atm[atm.r_psup < 0.9]
print("number of events after radius cut = %i" % len(prompt))
- # Note: Need to design and apply a psi based cut here
+ # require psi < 6
+ prompt = prompt[prompt.psi < 6]
+ atm = atm[atm.psi < 6]
+
+ print("number of events after psi cut = %i" % len(prompt))
- fig = plt.figure(figsize=FIGSIZE)
+ fig = plt.figure()
plot_hist2(prompt)
despine(fig,trim=True)
if args.save:
@@ -476,7 +446,7 @@ if __name__ == '__main__':
plt.savefig("prompt.eps")
else:
plt.suptitle("Without Neutron Follower")
- fig = plt.figure(figsize=FIGSIZE)
+ fig = plt.figure()
plot_hist2(atm)
despine(fig,trim=True)
if args.save:
@@ -484,7 +454,7 @@ if __name__ == '__main__':
plt.savefig("atm.eps")
else:
plt.suptitle("With Neutron Follower")
- fig = plt.figure(figsize=FIGSIZE)
+ fig = plt.figure()
plot_hist2(michel_best_fit)
despine(fig,trim=True)
if args.save:
@@ -492,7 +462,7 @@ if __name__ == '__main__':
plt.savefig("michel_electrons.eps")
else:
plt.suptitle("Michel Electrons")
- fig = plt.figure(figsize=FIGSIZE)
+ fig = plt.figure()
plot_hist2(muon_best_fit,muons=True)
despine(fig,trim=True)
if len(muon_best_fit):
@@ -504,7 +474,7 @@ if __name__ == '__main__':
plt.suptitle("External Muons")
# Plot the energy and angular distribution for external muons
- fig = plt.figure(figsize=FIGSIZE)
+ fig = plt.figure()
plt.subplot(2,1,1)
plt.hist(muons.ke.values, bins=np.logspace(3,7,100), histtype='step')
plt.xlabel("Energy (MeV)")
@@ -533,7 +503,7 @@ if __name__ == '__main__':
stopping_muons['T_dx'] = dx_to_energy(stopping_muons.dx)
stopping_muons['dT'] = stopping_muons['energy1'] - stopping_muons['T_dx']
- fig = plt.figure(figsize=FIGSIZE)
+ fig = plt.figure()
plt.hist((stopping_muons['energy1']-stopping_muons['T_dx'])*100/stopping_muons['T_dx'], bins=np.linspace(-100,100,200), histtype='step')
despine(fig,trim=True)
plt.xlabel("Fractional energy difference (\%)")
@@ -554,7 +524,7 @@ if __name__ == '__main__':
dT = stopping_muons.groupby(pd_bins)['dT'].agg(['mean','sem','std',std_err,median,median_err,iqr_std,iqr_std_err])
- fig = plt.figure(figsize=FIGSIZE)
+ fig = plt.figure()
plt.errorbar(T,dT['median']*100/T,yerr=dT['median_err']*100/T)
despine(fig,trim=True)
plt.xlabel("Kinetic Energy (MeV)")
@@ -566,7 +536,7 @@ if __name__ == '__main__':
else:
plt.title("Stopping Muon Energy Bias")
- fig = plt.figure(figsize=FIGSIZE)
+ fig = plt.figure()
plt.errorbar(T,dT['iqr_std']*100/T,yerr=dT['iqr_std_err']*100/T)
despine(fig,trim=True)
plt.xlabel("Kinetic Energy (MeV)")
@@ -578,7 +548,7 @@ if __name__ == '__main__':
else:
plt.title("Stopping Muon Energy Resolution")
- fig = plt.figure(figsize=FIGSIZE)
+ fig = plt.figure()
bins=np.linspace(0,100,100)
plt.hist(michel.ke.values, bins=bins, histtype='step', label="Dark Matter Fitter")
if michel.size:
diff --git a/utils/plot-fit-results b/utils/plot-fit-results
index e154b21..c90c13a 100755
--- a/utils/plot-fit-results
+++ b/utils/plot-fit-results
@@ -24,52 +24,16 @@ if __name__ == '__main__':
import itertools
from sddm import IDP_E_MINUS, IDP_MU_MINUS, SNOMAN_MASS
from sddm.plot import plot_hist, plot_legend, get_stats, despine, iqr_std_err, iqr_std, quantile_error, q90_err, q90, median, median_err, std_err
+ from sddm import setup_matplotlib
parser = argparse.ArgumentParser("plot fit results")
parser.add_argument("filenames", nargs='+', help="input files")
parser.add_argument("--save", action="store_true", default=False, help="save plots")
args = parser.parse_args()
- if args.save:
- # default \textwidth for a fullpage article in Latex is 16.50764 cm.
- # You can figure this out by compiling the following TeX document:
- #
- # \documentclass{article}
- # \usepackage{fullpage}
- # \usepackage{layouts}
- # \begin{document}
- # textwidth in cm: \printinunitsof{cm}\prntlen{\textwidth}
- # \end{document}
-
- width = 16.50764
- width /= 2.54 # cm -> inches
- # According to this page:
- # http://www-personal.umich.edu/~jpboyd/eng403_chap2_tuftegospel.pdf,
- # Tufte suggests an aspect ratio of 1.5 - 1.6.
- height = width/1.5
- FIGSIZE = (width,height)
-
- import matplotlib.pyplot as plt
-
- font = {'family':'serif', 'serif': ['computer modern roman']}
- plt.rc('font',**font)
-
- plt.rc('text', usetex=True)
- else:
- # on retina screens, the default plots are way too small
- # by using Qt5 and setting QT_AUTO_SCREEN_SCALE_FACTOR=1
- # Qt5 will scale everything using the dpi in ~/.Xresources
- import matplotlib
- matplotlib.use("Qt5Agg")
-
- import matplotlib.pyplot as plt
-
- # Default figure size. Currently set to my monitor width and height so that
- # things are properly formatted
- FIGSIZE = (13.78,7.48)
+ setup_matplotlib(args.save)
- # Make the defalt font bigger
- plt.rc('font', size=22)
+ import matplotlib.pyplot as plt
# Read in all the data.
#
@@ -148,8 +112,8 @@ if __name__ == '__main__':
markers = itertools.cycle(('o', 'v'))
- fig3, ax3 = plt.subplots(3,1,figsize=FIGSIZE,num=3,sharex=True)
- fig4, ax4 = plt.subplots(3,1,figsize=FIGSIZE,num=4,sharex=True)
+ fig3, ax3 = plt.subplots(3,1,num=3,sharex=True)
+ fig4, ax4 = plt.subplots(3,1,num=4,sharex=True)
for id in [IDP_E_MINUS, IDP_MU_MINUS]:
events = data_true[data_true['mcgn_id'] == id]
@@ -168,10 +132,10 @@ if __name__ == '__main__':
marker = markers.next()
- plt.figure(1,figsize=FIGSIZE)
+ plt.figure(1)
plt.errorbar(T,dT['median']*100/T,yerr=dT['median_err']*100/T,fmt=marker,label=label)
- plt.figure(2,figsize=FIGSIZE)
+ plt.figure(2)
plt.errorbar(T,dT['iqr_std']*100/T,yerr=dT['iqr_std_err']*100/T,fmt=marker,label=label)
ax3[0].errorbar(T,dx['median'],yerr=dx['median_err'],fmt=marker,label=label)
@@ -182,10 +146,10 @@ if __name__ == '__main__':
ax4[1].errorbar(T,dy['iqr_std'],yerr=dy['iqr_std_err'],fmt=marker,label=label)
ax4[2].errorbar(T,dz['iqr_std'],yerr=dz['iqr_std_err'],fmt=marker,label=label)
- plt.figure(5,figsize=FIGSIZE)
+ plt.figure(5)
plt.errorbar(T,theta['std'],yerr=theta['std_err'],fmt=marker,label=label)
- plt.figure(6,figsize=FIGSIZE)
+ plt.figure(6)
plt.scatter(events['Te'],events['ratio'],marker=marker,label=label)
fig = plt.figure(1)
diff --git a/utils/plot-root-results b/utils/plot-root-results
index 7f115f1..51df7cc 100755
--- a/utils/plot-root-results
+++ b/utils/plot-root-results
@@ -22,52 +22,16 @@ if __name__ == '__main__':
import argparse
from os.path import split
from sddm.plot import despine
+ from sddm import setup_matplotlib
parser = argparse.ArgumentParser("plot ROOT fit results")
parser.add_argument("filename", help="input file")
parser.add_argument("--save", action="store_true", default=False, help="save plots")
args = parser.parse_args()
- if args.save:
- # default \textwidth for a fullpage article in Latex is 16.50764 cm.
- # You can figure this out by compiling the following TeX document:
- #
- # \documentclass{article}
- # \usepackage{fullpage}
- # \usepackage{layouts}
- # \begin{document}
- # textwidth in cm: \printinunitsof{cm}\prntlen{\textwidth}
- # \end{document}
-
- width = 16.50764
- width /= 2.54 # cm -> inches
- # According to this page:
- # http://www-personal.umich.edu/~jpboyd/eng403_chap2_tuftegospel.pdf,
- # Tufte suggests an aspect ratio of 1.5 - 1.6.
- height = width/1.5
- FIGSIZE = (width,height)
-
- import matplotlib.pyplot as plt
-
- font = {'family':'serif', 'serif': ['computer modern roman']}
- plt.rc('font',**font)
-
- plt.rc('text', usetex=True)
- else:
- # on retina screens, the default plots are way too small
- # by using Qt5 and setting QT_AUTO_SCREEN_SCALE_FACTOR=1
- # Qt5 will scale everything using the dpi in ~/.Xresources
- import matplotlib
- matplotlib.use("Qt5Agg")
-
- import matplotlib.pyplot as plt
-
- # Default figure size. Currently set to my monitor width and height so that
- # things are properly formatted
- FIGSIZE = (13.78,7.48)
+ setup_matplotlib(args.save)
- # Make the defalt font bigger
- plt.rc('font', size=22)
+ import matplotlib.pyplot as plt
root_file = ROOT.TFile(args.filename)
@@ -99,7 +63,7 @@ if __name__ == '__main__':
hist /= norm
- fig = plt.figure(figsize=FIGSIZE)
+ fig = plt.figure()
plt.hist(bincenters,weights=hist,bins=bins,histtype='step')
x = np.linspace(bins[0],bins[-1],10000)
if tf1_number:
@@ -154,7 +118,7 @@ if __name__ == '__main__':
y = np.array(y)
yerr = np.array(yerr)
- fig = plt.figure(figsize=FIGSIZE)
+ fig = plt.figure()
plt.errorbar(x,y,yerr=yerr,fmt='o')
x = np.linspace(x[0],x[-1],10000)
if tf1_number:
diff --git a/utils/sddm/__init__.py b/utils/sddm/__init__.py
index 902039d..1f926df 100644
--- a/utils/sddm/__init__.py
+++ b/utils/sddm/__init__.py
@@ -133,3 +133,42 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
if _access_check(name, mode):
return name
return None
+
+def setup_matplotlib(save=False):
+ import matplotlib
+
+ if save:
+ # default \textwidth for a fullpage article in Latex is 16.50764 cm.
+ # You can figure this out by compiling the following TeX document:
+ #
+ # \documentclass{article}
+ # \usepackage{fullpage}
+ # \usepackage{layouts}
+ # \begin{document}
+ # textwidth in cm: \printinunitsof{cm}\printlen{\textwidth}
+ # \end{document}
+
+ width = 16.50764
+ width /= 2.54 # cm -> inches
+ # According to this page:
+ # http://www-personal.umich.edu/~jpboyd/eng403_chap2_tuftegospel.pdf,
+ # Tufte suggests an aspect ratio of 1.5 - 1.6.
+ height = width/1.5
+ matplotlib.rcParams['figure.figsize'] = (width,height)
+
+ matplotlib.rcParams['font.family'] = 'serif'
+ matplotlib.rcParams['font.serif'] = 'computer modern roman'
+
+ matplotlib.rcParams['text.usetex'] = True
+ else:
+ # on retina screens, the default plots are way too small
+ # by using Qt5 and setting QT_AUTO_SCREEN_SCALE_FACTOR=1
+ # Qt5 will scale everything using the dpi in ~/.Xresources
+ matplotlib.use("Qt5Agg")
+
+ # Default figure size. Currently set to my monitor width and height so that
+ # things are properly formatted
+ matplotlib.rcParams['figure.figsize'] = (13.78,7.48)
+
+ # Make the defalt font bigger
+ matplotlib.rcParams['font.size'] = 12
diff --git a/utils/sddm/plot.py b/utils/sddm/plot.py
index b00adbd..935b26a 100755
--- a/utils/sddm/plot.py
+++ b/utils/sddm/plot.py
@@ -132,8 +132,13 @@ def despine(fig=None, ax=None, top=True, right=True, left=False,
# clip off the parts of the spines that extend past major ticks
xticks = ax_i.get_xticks()
if xticks.size:
- firsttick = np.compress(xticks >= min(ax_i.get_xlim()),
- xticks)[0]
+ if ax_i.get_xscale() == 'log':
+ xticks = np.sort(np.concatenate((ax_i.get_xticks(),ax_i.get_xticks(minor=True))))
+ firsttick = np.compress(xticks >= min(ax_i.get_xlim()),
+ xticks)[0]
+ else:
+ firsttick = np.compress(xticks >= min(ax_i.get_xlim()),
+ xticks)[0]
lasttick = np.compress(xticks <= max(ax_i.get_xlim()),
xticks)[-1]
ax_i.spines['bottom'].set_bounds(firsttick, lasttick)