Interactive parameterisation explorer with optional ref data display
TODO:
* Need to allow no-ref visualisation
* Optionally display the envelope of input MC runs
"""
import optparse, os, sys
op = optparse.OptionParser(usage=__doc__)
op.add_option("-v", "--debug", dest="DEBUG", action="store_true", default=False, help="Turn on some debug messages")
op.add_option("-q", "--quiet", dest="QUIET", action="store_true", default=False, help="Turn off messages")
op.add_option("--wfile", dest="WFILE", default=None, help="Path to a weight file, used to restrict plotting to a subset of histograms (default: %default)")
# TODO: Add weight file parsing to decide which histos (and bin subsets) to interpolate
opts, args = op.parse_args()
## Get arguments
IFILE = "ipol.dat"
if len(args) >= 1:
IFILE = args[0]
REFDIR = None
if len(args) >= 2:
REFDIR = args[1]
## Load the Professor machinery
import professor2 as prof
from professor2 import misc
if not opts.QUIET:
print prof.logo
## Read in ipol histos
METADATA, IHISTOS = prof.read_ipolhistos(IFILE)
## Weight file parsing
if opts.WFILE:
matchers = prof.read_pointmatchers(opts.WFILE)
for hn in IHISTOS.keys():
if not any(m.match_path(hn) for m in matchers.keys()):
del IHISTOS[hn]
if len(IHISTOS.keys())==0:
print "Nothing left after weight file parsing, exiting"
sys.exit(0)
## List of rivet analysis paths in IHISTOS
# TODO: Urgh, avoid this sort of noise-code!
ananames = list(set([filter(lambda x:len(x)>1, i.split("/"))[0] for i in IHISTOS.keys()]))
## Read reference data histos
import glob
HISTOS = {}
# TODO: consistent directory convention and protect against invalid structures
if REFDIR is not None:
reffiles = glob.glob(os.path.join(REFDIR, "*"))
for rf in reffiles:
HISTOS.update(prof.read_histos(rf))
## Find things available in both
available = []
for i in IHISTOS.keys():
for r in HISTOS.keys():
if i in r:
available.append([i,r])
ibins = []
databins = []
for a in available:
ibins.extend( IHISTOS[a[0]].bins)
databins.extend(HISTOS[a[1]].bins)
else:
ibins = []
available = [(i,i) for i in IHISTOS.keys()]
for a in available:
ibins.extend( IHISTOS[a[0]].bins)
## Sanity checks
if not ibins:
print "No bins ..., exiting"
import sys
sys.exit(1)
## Import and set up matplotlib (AFTER parsing arguments)
try:
import matplotlib
matplotlib.use('WXAgg')
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar
import wx, functools
params = {
'backend': 'pdf',
'axes.labelsize' : 16,
'text.size' : 16,
'legend.fontsize' : 16,
'axes.titlesize' : 16,
'xtick.labelsize' : 16,
'ytick.labelsize' : 16,
'text.usetex' : False,
'figure.dpi' : 50,
'lines.markersize' : 10,
'lines.linewidth' : 2,
'lines.elinewidth' : 3,
'lines.antialiased' : False,
#'patches.antialiased' : False,
'figure.subplot.left' : 0.05,
'figure.subplot.right' : 0.995,
'figure.subplot.bottom' : 0.1,
'figure.subplot.top' : 0.95,
'figure.subplot.wspace' : 0.15
}
for k, v in params.iteritems():
try:
matplotlib.rcParams[k] = v
except:
pass
except Exception, e:
print "Problem with getting & configuring matplotlib/WX interface method: %s" % e
print "Exiting!"
sys.exit(1)
observables=sorted([a[0] for a in available]) # When interested in comparison with data
#observables=sorted(IHISTOS.keys()) # all ipols, not neccessary data available
# TODO: add error bar plotting option (with errs from ipol)