xboa
Classes | Functions | Variables
xboa.common._common Namespace Reference

Classes

class  rg
 root globals line_color_int=1, line_style_int=1, line_width_int=2, fill_color_int=None, stats_bool=False, hist_title_string='' More...
 

Functions

def substitute
 Read in file_name_in and write to file_name_out, replacing key with value in switch_dict. More...
 
def __y_function_wrapper
 
def nd_newton_raphson1
 Root finding in an arbitrary dimensional system. More...
 
def nd_newton_raphson2
 Alternative version of nd_newton_raphson1. More...
 
def has_multiprocessing
 Raise an exception if multiprocessing libraries have not been imported properly. More...
 
def has_maus
 Raise an exception if MAUS tracking library has not been imported properly. More...
 
def has_root
 Raise an exception if ROOT graphics libraries have not been imported properly. More...
 
def has_numpy
 Raise an exception if NumPy numerical algebra libraries have not been imported properly. More...
 
def has_scipy
 Raise an exception if SciPy math/analysis libraries have not been imported properly. More...
 
def has_matplot
 Raise an exception if NumPy numerical algebra libraries have not been imported properly. More...
 
def has_json
 Raise an exception if json data libraries have not been imported properly. More...
 
def min_max
 Return minimum and maximum of a list (i) discarding values with ~0 weight and (ii) adding a margin. More...
 
def multisort
 Sort a list of lists by the first list. More...
 
def n_bins
 Dynamically decide a number of bins depending on the number of points in the histogram. More...
 
def histogram
 Get a 1d or 2d list of bin weights from a set of data, weights and bin edges. More...
 
def get_bin_edges
 Get a sorted list of equally spaced bin edges from a list of floats. More...
 
def make_root_canvas
 Make a root canvas with name canvas_name_string-<index> where <index> is a unique integer starting from 0. More...
 
def make_root_histogram
 Make a root histogram with data taken from float lists and axes named after the axis strings. More...
 
def make_root_legend
 Build a legend for the canvas. More...
 
def make_matplot_histogram
 Make a matplot graph with data taken from float lists and axes naemd after the axis strings. More...
 
def make_root_graph
 Make a root graph with data taken from float lists and axes named after the axis strings. More...
 
def make_matplot_graph
 Make a matplot graph with data taken from float lists and axes naemd after the axis strings. More...
 
def make_root_multigraph
 Print several different graphs on the same canvas. More...
 
def make_matplot_multigraph
 Print several different graphs on the same axes. More...
 
def make_matplot_scatter
 Make a matplot scatter graph with data taken from float lists and axes naemd after the axis strings. More...
 
def wait_for_root
 Force python to halt processing until ROOT windows are closed. More...
 
def clear_root
 Close root plots (and free memory) More...
 
def wait_for_matplot
 Show any plots made using matplotlib on the screen. More...
 
def matplot_show_and_continue
 Show matplotlib plots and return to the script. More...
 
def subprocess
 Make a function call in a subprocess; return the subprocess pid. More...
 
def kill_all_subprocesses
 Kill all subprocesses generated by common.subprocess call; automatically called at exit unless kill_subprocesses_at_exit is set to False Note that this makes a call to the os, which may take a bit of time to respond. More...
 
def kolmogorov_smirnov_test
 Convenience wrapper for ROOT kolmogorov-smirnov test. More...
 
def __atexit
 Calls some functions automatically at exit. More...
 
def make_grid
 Make a rectangular n_dimensional grid of points evenly spaced between [-1,1] in each dimension. More...
 
def make_shell
 Make a shell of points that sit on a hyper-ellipsoid defined by ellipse matrix. More...
 
def normalise_vector
 Normalise vector so that vector.T() * matrix.inverse * vector = 1. More...
 
def __function_with_queue
 Wrapper function to put multiprocessing output into a queue. More...
 
def process_list
 Run multiprocessing on a list of arguments. More...
 
def _sum_weight
 
def _get_fit_ellipse_covariance_matrix
 
def _update_fit_ellipse_cut
 
def fit_ellipse
 Fit an ellipse of arbitrary dimension n to a set of points. More...
 
def make_root_ellipse_function
 Make a ROOT TFunction for a given beam ellipse. More...
 
def common_overview_doc
 Creates some summary documentation for the common module. More...
 

Variables

string xboa_version = '0.16.2'
 
int float_tolerance = 1
 
 kill_subprocesses_at_exit = True
 
 __has_maus = False
 
 __has_root = True
 
 __has_scipy = True
 
 __has_numpy = True
 
 __has_matplot = True
 
 __has_multiprocessing = True
 
 __has_json = True
 
dictionary pdg_pid_to_muon1 = {-13:'mu+'}
 
dictionary muon1_pid_to_pdg = {}
 
dictionary icool_pid_to_pdg = {0:0, 1:-11, 2:-13, 3:211, 4:321, 5:2212, -1:11, -2:13, -3:-211, -4:-321, -5:-2212}
 
dictionary pdg_pid_to_icool = {}
 
dictionary mars_pid_to_pdg = {1:2212, 2:2112, 3:211, 4:-211, 5:321, 6:-321, 7:-13, 8:13, 9:22, 10:11, 11:-11, 12:-2212, 13:111, 14:1000010020, 15:1000010030, 16:1000020030, 17:1000020040, 18:14, 19:-14, 20:12, 21:-12, 22:130, 23:310, 24:311, 25:-311,26:3122,27:-3122,28:0,29:0,30:0,31:-2112,32:0,33:0,34:0,35:0,36:0,38:0,39:0,40:0}
 
dictionary pdg_pid_to_mars = {}
 
dictionary pdg_pid_to_mass = {0:0, 11:0.510998910, 12:0., 13:105.6583668, 14:0., 22:0., 111:134.9766, 211:139.57018, 321:493.667, 2112:939.56536, 2212:938.271996, 1000010020:1876.1239, 1000010030:2809.432, 1000020030:2809.41346, 1000020040: 3728.4001, 130:497.614, 310:497.614, 311:497.614, 3122:1115.683}
 
dictionary pdg_pid_to_name
 
dictionary pdg_pid_to_charge = {0:0, 11:-1, 12:0, 13:-1, 14:0, 22:0, 111:0, 211:+1, 321:+1, 2112:0, 2212:+1, 1000010020:0, 1000010030:0, 1000020030:0, 1000020040:0, 130:0, 310:0, 311:0, 3122:0, -11:+1, -12:0, -13:+1, -14:0, -211:-1, -321:-1, -2112:0, -2212:-1, -3122:0}
 
dictionary constants = {'c_light':299.792458, 'pi':3.14159265,'echarge':1}
 
dictionary units
 
list _canvas_persistent = []
 privates More...
 
list _hist_persistent = []
 
list _graph_persistent = []
 
list _legend_persistent = []
 
list _function_persistent = []
 
int _figure_index = 1
 pyplot globals More...
 
 wrapped_y_function = None
 
list __mp_subprocesses = []
 
list __fk_subprocesses = []
 
tuple __doc__ = common_overview_doc()
 

Function Documentation

def xboa.common._common.substitute (   file_name_in,
  file_name_out,
  switch_dict 
)

Read in file_name_in and write to file_name_out, replacing key with value in switch_dict.

Must be a built in function somewhere to do same...

  • file_name_in = string name of the input file
  • file_name_out = string name of the output file
  • switch_dict = dict of values to be swapped to the values they will be swapped for

e.g. common.substitute('file.in', 'file.out', {'energy':'momentum'})

Definition at line 187 of file _common.py.

def xboa.common._common.__y_function_wrapper (   x_list_of_lists)
private

Definition at line 198 of file _common.py.

References xboa.common._common.wrapped_y_function.

def xboa.common._common.nd_newton_raphson1 (   y_function,
  y_tolerances_list,
  x_start_values_list,
  x_deltas_list,
  max_iteration = 10,
  x_upper_limits = None,
  x_lower_limits = None,
  verbose = True 
)

Root finding in an arbitrary dimensional system.

Returns x-value for y(x) = 0; caveat is dimension of y must equal dimension of x. If you use this, you might find more and better root finding functions in SciPy module

  • y_function is a reference to the function to be minimised i.e. y(x); it takes a list of x-values; and returns a list of y-values
  • y_tolerances_list is a list of tolerances; the iteration will stop when abs(value) < value_tolerance _ x_start_values_list is a list of the values I will try to start with
  • x_deltas_list is a list of the initial estimates of the error on x
  • max_iteration is the maximum number of iterations allowed
  • x_upper_limits is for future development
  • x_lower_limits is for future development

e.g. nd_newton_raphson(some_function, [0.1, 0.1], [0,0], [1,1]) will find root to y(x) < (0.1,0.1); starting at x=(0,0); initial error estimated to be [1,1]. some_function would be called like some_function([x_0, x_1]) and should return a list like [y_0,y_1]

Definition at line 220 of file _common.py.

References xboa.common._common.nd_newton_raphson2().

def xboa.common._common.nd_newton_raphson2 (   y_function,
  y_tolerances_list,
  x_start_values_list,
  x_deltas_list,
  max_iteration = 10,
  x_upper_limits = None,
  x_lower_limits = None,
  verbose = True 
)

Alternative version of nd_newton_raphson1.

Here y_function takes a list of lists of x_values, of length dimension+1 and returns a list of lists of y_values Optimisation for when y_function can be made faster by running several jobs at once...

  • y_function is a reference to the function to be minimised i.e. y(x); it takes a list of lists of x-values; and returns a list of lists y-values
  • y_tolerances_list is a list of tolerances; the iteration will stop when abs(value) < value_tolerance
  • x_start_values_list is a list of the values I will try to start with
  • x_deltas_list is a list of the initial estimates of the error on x
  • max_iteration is the maximum number of iterations allowed
  • x_upper_limits is for future development
  • x_lower_limits is for future development

e.g. nd_newton_raphson(some_function, [0.1, 0.1], [0,0], [1,1]) will find root to y(x) < (0.1,0.1); starting at x=(0,0); initial error estimated to be [1,1]. some_function would be called like some_function([[x_00, x_01] ,[x_10, x_11], [x_20, x_21]) and should return a list like [[y_00,y_01],[y_10,y_11],[y_20,y_21]]

Definition at line 241 of file _common.py.

References xboa.common._common.has_numpy().

Referenced by xboa.common._common.nd_newton_raphson1().

def xboa.common._common.has_multiprocessing ( )

Raise an exception if multiprocessing libraries have not been imported properly.

Definition at line 293 of file _common.py.

Referenced by xboa.common._common.subprocess().

def xboa.common._common.has_maus ( )

Raise an exception if MAUS tracking library has not been imported properly.

Definition at line 300 of file _common.py.

def xboa.common._common.has_root ( )
def xboa.common._common.has_numpy ( )
def xboa.common._common.has_scipy ( )

Raise an exception if SciPy math/analysis libraries have not been imported properly.

Definition at line 321 of file _common.py.

def xboa.common._common.has_matplot ( )
def xboa.common._common.has_json ( )

Raise an exception if json data libraries have not been imported properly.

Definition at line 336 of file _common.py.

def xboa.common._common.min_max (   x_float_list,
  weight_list = [],
  margin = 0.1,
  xmin = None,
  xmax = None 
)

Return minimum and maximum of a list (i) discarding values with ~0 weight and (ii) adding a margin.

For making histograms.

  • x_float_list = return minimum and maximum of this list of floats
  • weight_list = ignore items in x_float_list if weight is 0. Ignored if weight_list is not same length as x_float_list
  • margin = add a margin given by (x_max-x_min)*margin
  • xmin = if set, will override the xmin value
  • xmax = if set, will override the xmax value

e.g. common.min_max([0.1,0.2,0.3,0.4], [0,1,1,1], 0.2) will return [0.16,0.44]

Definition at line 354 of file _common.py.

Referenced by xboa.common._common.get_bin_edges(), xboa.common._common.make_matplot_graph(), xboa.common._common.make_matplot_multigraph(), xboa.common._common.make_root_graph(), xboa.common._common.make_root_histogram(), and xboa.common._common.make_root_multigraph().

def xboa.common._common.multisort (   list_of_lists)

Sort a list of lists by the first list.

Definition at line 375 of file _common.py.

Referenced by xboa.common._common.make_matplot_graph(), xboa.common._common.make_matplot_multigraph(), and xboa.common._common.make_root_graph().

def xboa.common._common.n_bins (   n_points,
  nx_bins = None,
  ny_bins = None,
  nz_bins = None,
  n_dimensions = 1 
)

Dynamically decide a number of bins depending on the number of points in the histogram.

  • n_points = number of data points in the histogram
  • nx_bins = set to an integer to override the automatic selection for number of x bins
  • ny_bins = set to an integer to override the automatic selection for number of y bins
  • n_dimensions = set to number of dimensions in the histogram

Return value is a tuple (nx_bins, ny_bins, nz_bins), setting 0 to values that are out of the dimension range

Definition at line 402 of file _common.py.

def xboa.common._common.histogram (   x_values,
  x_bins,
  y_values = None,
  y_bins = None,
  weights = None 
)

Get a 1d or 2d list of bin weights from a set of data, weights and bin edges.

  • x_values = list of x values to be binned
  • x_bins = list of x bin edges
  • y_values = list of y values to be binned. Set to None to make a 1d binning
  • y_bins = list of y bin edges of same length as x_values
  • weights = list of statistical weights of same length as x_values. Set to None to make all weights default to 1.

Return value is a tuple of (bin_weights, x_bins, y_bins)

Definition at line 427 of file _common.py.

References xboa.common._common.has_numpy().

def xboa.common._common.get_bin_edges (   list_of_variables,
  number_of_bins,
  xmin = None,
  xmax = None 
)

Get a sorted list of equally spaced bin edges from a list of floats.

  • list_of_variables = list of floats to be binned
  • number_of_bins = number of bins to make; note that there will be number_of_bins+1 edges
  • xmin = lower edge of all the bins (set to None to auto-detect)
  • xmax = upper edge of all the bins (set to None to auto-detect)

Definition at line 455 of file _common.py.

References xboa.common._common.make_root_canvas(), and xboa.common._common.min_max().

def xboa.common._common.make_root_canvas (   name_string,
  title_string = None,
  bg_color = rg.canvas_fill_color,
  highlight_color = rg.canvas_highlight_color,
  border_mode = rg.canvas_border_mode,
  frame_fill_color = rg.hist_fill_color 
)

Make a root canvas with name canvas_name_string-<index> where <index> is a unique integer starting from 0.

  • name_string = Name of the canvas. Due to a ROOT bug, xboa adds a unique identifier to the name_string to ensure the canvas is drawn.
  • title_string = Title of the canvas (as displayed in canvas window title bar); if set to None will use the name_string.
  • bg_color = Fill color of the canvas.
  • highlight_color = When a canvas is selected, ROOT draws a border with a particular color to indicate that the canvas is selected.
  • border_mode = When a canvas is selected, ROOT draws a border if border mode is not set to 0.
  • frame_fill_color = Fill color of frames drawn on the canvas (e.g. histograms).

Definition at line 477 of file _common.py.

References xboa.common._common.has_root(), and xboa.common._common.make_root_histogram().

Referenced by xboa.common._common.get_bin_edges().

def xboa.common._common.make_root_histogram (   name_string,
  x_float_list,
  x_axis_string,
  n_x_bins,
  y_float_list = [],
  y_axis_string = '',
  n_y_bins = 0,
  weight_list = [],
  xmin = None,
  xmax = None,
  ymin = None,
  ymax = None,
  line_color = rg.line_color,
  line_style = rg.line_style,
  line_width = rg.line_width,
  fill_color = rg.fill_color,
  stats = rg.stats,
  hist_title_string = '' 
)

Make a root histogram with data taken from float lists and axes named after the axis strings.

  • name_string = name given to the histogram
  • x_float_list = list of x-data
  • x_axis_string = string used to label the x-axis
  • n_x_bins = number of bins in x direction
  • y_float_list = list of y-data. If number of items in y list not equal to number in x list, will build 1d histogram
  • y_axis_string = string used to label the y-axis
  • n_y_bins = number of y bins
  • weight_list = if present, each item will be filled with weight taken from this list
  • xmin = float that overrides auto-detection of minimum x-axis value
  • xmax = float that overrides auto-detection of maximum x-axis value
  • ymin = float that overrides auto-detection of minimum y-axis value
  • ymax = float that overrides auto-detection of maximum y-axis value
  • line_color = int that sets the line colour of the histogram
  • line_style = int that sets the line style of the histogram
  • line_width = int that sets the line width of the histogram
  • fill_color = int that sets the fill color of the histogram
  • stats = set to True to plot a stats box on the histogram
  • hist_title_string = specify the string that will appear as a title on the canvas

Return value is the histogram

Definition at line 515 of file _common.py.

References xboa.common._common.has_root(), and xboa.common._common.min_max().

Referenced by xboa.common._common.make_root_canvas(), and xboa.common._common.make_root_graph().

def xboa.common._common.make_root_legend (   canvas,
  root_item_list 
)

Build a legend for the canvas.

Definition at line 548 of file _common.py.

References xboa.common._common.has_root().

def xboa.common._common.make_matplot_histogram (   x_float_list,
  x_axis_string,
  n_x_bins,
  y_float_list = [],
  y_axis_string = '',
  n_y_bins = 0,
  weight_list = [] 
)

Make a matplot graph with data taken from float lists and axes naemd after the axis strings.

Return value is a tuple of (hist, graph) matplot can format using tex expressions - use '$some math expression$' to include math text in your labels

  • x_float_list = list of x-data
  • x_axis_string = string used to label the x-axis
  • y_float_list = list of y-data
  • y_axis_string = string used to label the y-axis

After building the graph, use matplotlib.pyplot.show() to show something on the screen

Definition at line 632 of file _common.py.

References xboa.common._common.has_matplot(), xboa.common._common.has_numpy(), and xboa.common._common.make_root_graph().

def xboa.common._common.make_root_graph (   name_string,
  x_float_list,
  x_axis_string,
  y_float_list,
  y_axis_string,
  sort = True,
  xmin = None,
  xmax = None,
  ymin = None,
  ymax = None,
  line_color = rg.line_color,
  line_style = rg.line_style,
  line_width = rg.line_width,
  fill_color = rg.graph_fill_color,
  hist_title_string = '' 
)

Make a root graph with data taken from float lists and axes named after the axis strings.

Return value is a tuple of (hist, graph)

  • name_string = name given to the histogram
  • x_float_list = list of x-data
  • x_axis_string = string used to label the x-axis
  • y_float_list = list of y-data
  • y_axis_string = string used to label the y-axis
  • sort = boolean - set to true to automatically sort input data
  • xmin = float that overrides auto-detection of minimum x-axis value
  • xmax = float that overrides auto-detection of maximum x-axis value
  • ymin = float that overrides auto-detection of minimum y-axis value
  • ymax = float that overrides auto-detection of maximum y-axis value
  • line_color = int that sets the line colour of the graph
  • line_style = int that sets the line style of the graph
  • line_width = int that sets the line width of the graph
  • fill_color = graphs dont usually get a fill, but sometimes the fill colour turns up in e.g. legend drawing
  • hist_title_string = specify the string that will appear as a title

Return value is a tuple of (histogram, graph)

Definition at line 687 of file _common.py.

References xboa.common._common.has_root(), xboa.common._common.make_root_histogram(), xboa.common._common.min_max(), and xboa.common._common.multisort().

Referenced by xboa.common._common.make_matplot_histogram().

def xboa.common._common.make_matplot_graph (   x_float_list,
  x_axis_string,
  y_float_list,
  y_axis_string,
  sort = True 
)

Make a matplot graph with data taken from float lists and axes naemd after the axis strings.

Return value is a tuple of (hist, graph) matplot can format using tex expressions - use '$some math expression$' to include math text in your labels

  • x_float_list = list of x-data
  • x_axis_string = string used to label the x-axis
  • y_float_list = list of y-data
  • y_axis_string = string used to label the y-axis
  • sort = boolean - set to true to automatically sort input data

After building the graph, use matplotlib.pyplot.show() to show something on the screen

Definition at line 725 of file _common.py.

References xboa.common._common.has_matplot(), xboa.common._common.min_max(), and xboa.common._common.multisort().

def xboa.common._common.make_root_multigraph (   name_string,
  x_float_list_of_lists,
  x_axis_string,
  y_float_list_of_lists,
  y_axis_string 
)

Print several different graphs on the same canvas.

Some default colour scheme is applied, but it may not be the best...

  • name_string = name that will be given to the axes (histogram)
  • x_float_list_of_lists = list of lists. Each list will be used as the x-axis for a graph
  • x_axis_string = string that will be used to label the x_axis
  • y_float_list_of_lists = list of lists. Each list will be used as the y-axis for a graph
  • y_axis_string = string that will be used to label the y_axis

E.g. common.make_root_multigraph('example', [[1.,2.,3.,4.], [1.,4.,9.,16.]], 'x', [[1.,2.,3.,4.],[1.,2.,3.,4.]], 'f(x)') will make a graph of f = x and f = x^0.5

Definition at line 755 of file _common.py.

References xboa.common._common.has_root(), and xboa.common._common.min_max().

def xboa.common._common.make_matplot_multigraph (   x_float_list_of_lists,
  x_axis_string,
  y_float_list_of_lists,
  y_axis_string 
)

Print several different graphs on the same axes.

Some default colour scheme is applied, but it may not be the best...

  • x_float_list_of_lists = list of lists. Each list will be used as the x-axis for a graph
  • x_axis_string = string that will be used to label the x_axis
  • y_float_list_of_lists = list of lists. Each list will be used as the y-axis for a graph
  • y_axis_string = string that will be used to label the y_axis

E.g. common.make_matplot_multigraph('example', [[1.,2.,3.,4.], [1.,4.,9.,16.]], 'x', [[1.,2.,3.,4.],[1.,2.,3.,4.]], 'f(x)') will make a graph of f = x and f = x^0.5

Definition at line 788 of file _common.py.

References xboa.common._common.has_matplot(), xboa.common._common.min_max(), and xboa.common._common.multisort().

def xboa.common._common.make_matplot_scatter (   x_float_list,
  x_axis_string,
  y_float_list,
  y_axis_string 
)

Make a matplot scatter graph with data taken from float lists and axes naemd after the axis strings.

matplot can format using tex expressions - use '$some math expression$' to include math text in your labels

  • x_float_list = list of x-data
  • x_axis_string = string used to label the x-axis
  • y_float_list = list of y-data
  • y_axis_string = string used to label the y-axis

After building the graph, use matplotlib.pyplot.show() to show something on the screen

Definition at line 821 of file _common.py.

References xboa.common._common.has_matplot().

def xboa.common._common.wait_for_root ( )

Force python to halt processing until ROOT windows are closed.

Definition at line 837 of file _common.py.

def xboa.common._common.clear_root ( )

Close root plots (and free memory)

Definition at line 852 of file _common.py.

def xboa.common._common.wait_for_matplot ( )

Show any plots made using matplotlib on the screen.

Definition at line 863 of file _common.py.

References xboa.common._common.has_matplot().

def xboa.common._common.matplot_show_and_continue ( )

Show matplotlib plots and return to the script.

Definition at line 869 of file _common.py.

References xboa.common._common.has_matplot(), and xboa.common._common.subprocess().

def xboa.common._common.subprocess (   function,
  args 
)

Make a function call in a subprocess; return the subprocess pid.

  • This uses the multiprocessing libary in the first instance - if multiprocessing is not available the function tries to use os.fork(); however, os.fork is not compatible with ROOT. If
  • multiprocessing is not available and ROOT is installed, this routine will throw an ImportError

Definition at line 885 of file _common.py.

References xboa.common._common.has_multiprocessing(), and xboa.common._common.has_root().

Referenced by xboa.common._common.matplot_show_and_continue().

def xboa.common._common.kill_all_subprocesses ( )

Kill all subprocesses generated by common.subprocess call; automatically called at exit unless kill_subprocesses_at_exit is set to False Note that this makes a call to the os, which may take a bit of time to respond.

Definition at line 910 of file _common.py.

Referenced by xboa.common._common.__atexit().

def xboa.common._common.kolmogorov_smirnov_test (   list_1,
  list_2 
)

Convenience wrapper for ROOT kolmogorov-smirnov test.

  • list_1 = list of floats that are sampled from some parent probability distribution
  • list_2 = list of floats that are sampled from other some parent distribution Returns double between 0. and 1. giving probability that list_1 and list_2 have the same parent distribution.

Definition at line 924 of file _common.py.

def xboa.common._common.__atexit ( )
private

Calls some functions automatically at exit.

Definition at line 938 of file _common.py.

References xboa.common._common.kill_all_subprocesses().

def xboa.common._common.make_grid (   n_dimensions,
  n_per_dimension 
)

Make a rectangular n_dimensional grid of points evenly spaced between [-1,1] in each dimension.

  • n_dimensions = number of dimensions
  • n_per_dimension = number of points in each dimension; total number of points will be n_per_dimension^n_dimensions

Return value is a list of numpy.matrices with shape (n_dimensions, 1)

Definition at line 955 of file _common.py.

References xboa.common._common.has_numpy().

Referenced by xboa.common._common.make_shell().

def xboa.common._common.make_shell (   n_per_dimension,
  ellipse 
)

Make a shell of points that sit on a hyper-ellipsoid defined by ellipse matrix.

  • n_per_dimension = number of points in each dimension; total number of points will be n_per_dimension^n_dimensions if n_per_dimension is even or n_per_dimension^n_dimensions-1 if n_per_dimension is odd
  • ellipse = matrix that defines the ellipse on which vector sits; should be a numpy.matrix with shape (vec_length, vec_length)

Points are defined on a (hyper-)cuboidal grid and then compressed so that lengths are all 1. Doesn't necessarily mean points are evenly spaced. Return value is a list of numpy.matrices with shape (n_dimensions, 1)

Definition at line 982 of file _common.py.

References xboa.common._common.has_numpy(), xboa.common._common.make_grid(), and xboa.common._common.normalise_vector().

def xboa.common._common.normalise_vector (   vector,
  matrix_inverse 
)

Normalise vector so that vector.T() * matrix.inverse * vector = 1.

  • vector = the vector to normalise; should be a numpy.matrix with shape (vec_length,1)
  • matrix_inverse = inverse of matrix that defines the ellipse on which vector sits; should be a numpy.matrix with shape (vec_length, vec_length)

Return value is a list of numpy.matrices with shape (vec_length,1)

Definition at line 1003 of file _common.py.

References xboa.common._common.has_numpy().

Referenced by xboa.common._common.make_shell().

def xboa.common._common.__function_with_queue (   args)
private

Wrapper function to put multiprocessing output into a queue.

  • args tuple of (function_call, queue, function_arg) where
    • function_call is a reference to the function that we want to wrap
    • queue is the queue that will hold return values from the function
    • function_arg is the argument to function_call
    • index is an index indicating function_arg's position in the inputs

tuple of (index, Output) is placed into queue; if function_call throws an exception, the exception is placed on the queue instead

Definition at line 1023 of file _common.py.

def xboa.common._common.process_list (   function_call,
  list_of_args,
  max_n_processes 
)

Run multiprocessing on a list of arguments.

  • function_call multiprocess this function call
  • list_of_args list of tuples of arguments for function_call
  • max_n_processes maximum number of concurrent processes to use

Returns list of return values, one for each function call. List is always sorted into same order as input.

e.g. process_list(time.sleep, [(3, ), (6, ), (2, )], 2) will multiprocess the time.sleep function with inputs 3, 6 and 2 across 2 cores and return list like [None, None, None].

Definition at line 1045 of file _common.py.

def xboa.common._common._sum_weight (   weights,
  in_cut 
)
private
def xboa.common._common._get_fit_ellipse_covariance_matrix (   points,
  weights,
  in_cut 
)
private

Definition at line 1071 of file _common.py.

References xboa.common._common._sum_weight().

Referenced by xboa.common._common.fit_ellipse().

def xboa.common._common._update_fit_ellipse_cut (   points,
  cov_inv,
  mean,
  eps_cut 
)
private

Definition at line 1089 of file _common.py.

Referenced by xboa.common._common.fit_ellipse().

def xboa.common._common.fit_ellipse (   points,
  eps_cut,
  weights = None,
  max_number_of_iterations = 10,
  verbose = True 
)

Fit an ellipse of arbitrary dimension n to a set of points.

  • points iterable of points; each point should be an iterable of floats of length n
  • eps_cut float cut value; only particles with eps = x^T*V^{-1}*x*|V|**{1/n} < eps_{cut} are considered. The cut value is a normalised chi-squared. It should be positive.
  • weights list of floats, one for each point; use statistically weighted particles for the fit. Set to None to ignore weights.
  • max_number_of_iterations integer number of iterations; the ellipse fitting procedure is repeated several times to attempt to improve the fit of the ellipse. This sets a maximum number of repetitions.
  • verbose set to True to provide some verbose output during fitting

Returns ellipse centre vector <x> and defining matrix V. The ensemble of points on the ellipse is given by (x-<x>)^T*V^{-1}*(x-<x>) where x is a particle vector and V is the defining matrix.

Definition at line 1122 of file _common.py.

References xboa.common._common._get_fit_ellipse_covariance_matrix(), xboa.common._common._sum_weight(), and xboa.common._common._update_fit_ellipse_cut().

def xboa.common._common.make_root_ellipse_function (   mean,
  cov,
  contours = None,
  xmin = -1e3,
  xmax = 1e3,
  ymin = -1e3,
  ymax = 1e3 
)

Make a ROOT TFunction for a given beam ellipse.

  • mean sequence type of length>=2 (must allow reference by integer [index])
  • cov ellipse >= 2x2 symmetric numpy.array (must allow referencing by integer indices like [a, b])
  • contours iterable; draw contours at values of x^T V^{-1} x given by elements. Uses ROOT default if equal to None.

Returns a ROOT TFunction. Note ROOT TFunction does not like drawing small ellipses if the ellipse matrix is highly correlated (i.e. determinant near zero). A workaround is to make a TGraph with appropriate points (using e.g. formula given by this function). May be possible to fix by increasing the number of points in plot (func.SetNpy).

Definition at line 1169 of file _common.py.

References xboa.common._common.has_root().

def xboa.common._common.common_overview_doc (   verbose = False)

Creates some summary documentation for the common module.

If verbose is True then will also print any functions or data not included in summary

Definition at line 1198 of file _common.py.

Variable Documentation

string xboa_version = '0.16.2'

Definition at line 42 of file _common.py.

int float_tolerance = 1

Definition at line 43 of file _common.py.

kill_subprocesses_at_exit = True

Definition at line 44 of file _common.py.

__has_maus = False

Definition at line 46 of file _common.py.

__has_root = True

Definition at line 53 of file _common.py.

__has_scipy = True

Definition at line 61 of file _common.py.

__has_numpy = True

Definition at line 69 of file _common.py.

__has_matplot = True

Definition at line 78 of file _common.py.

__has_multiprocessing = True

Definition at line 87 of file _common.py.

__has_json = True

Definition at line 94 of file _common.py.

dictionary pdg_pid_to_muon1 = {-13:'mu+'}

Definition at line 101 of file _common.py.

dictionary muon1_pid_to_pdg = {}

Definition at line 102 of file _common.py.

dictionary icool_pid_to_pdg = {0:0, 1:-11, 2:-13, 3:211, 4:321, 5:2212, -1:11, -2:13, -3:-211, -4:-321, -5:-2212}

Definition at line 106 of file _common.py.

dictionary pdg_pid_to_icool = {}

Definition at line 107 of file _common.py.

dictionary mars_pid_to_pdg = {1:2212, 2:2112, 3:211, 4:-211, 5:321, 6:-321, 7:-13, 8:13, 9:22, 10:11, 11:-11, 12:-2212, 13:111, 14:1000010020, 15:1000010030, 16:1000020030, 17:1000020040, 18:14, 19:-14, 20:12, 21:-12, 22:130, 23:310, 24:311, 25:-311,26:3122,27:-3122,28:0,29:0,30:0,31:-2112,32:0,33:0,34:0,35:0,36:0,38:0,39:0,40:0}

Definition at line 117 of file _common.py.

dictionary pdg_pid_to_mars = {}

Definition at line 118 of file _common.py.

dictionary pdg_pid_to_mass = {0:0, 11:0.510998910, 12:0., 13:105.6583668, 14:0., 22:0., 111:134.9766, 211:139.57018, 321:493.667, 2112:939.56536, 2212:938.271996, 1000010020:1876.1239, 1000010030:2809.432, 1000020030:2809.41346, 1000020040: 3728.4001, 130:497.614, 310:497.614, 311:497.614, 3122:1115.683}

Definition at line 122 of file _common.py.

dictionary pdg_pid_to_name
Initial value:
1 = {0:'none', 11:'e-', 12:'electron neutrino', 13:'mu-', 14:'muon neutrino', 22:'photon', 111:'pi0', 211:'pi+', 321:'K+', 2112:'neutron', 2212:'proton', 1000010020:'deuterium', 1000010030:'tritium', 1000020030:'3He', 1000020040:'4He', 130:'K0L', 310:'K0S', 311:'K0', 3122:'lambda',
2 -11:'e+', -12:'electron antineutrino', -13:'mu+', -14:'muon antineutrino', -211:'pi-', -321:'K-', -2112:'antineutron', -2212:'antiproton', -3122:'antilambda'}

Definition at line 123 of file _common.py.

dictionary pdg_pid_to_charge = {0:0, 11:-1, 12:0, 13:-1, 14:0, 22:0, 111:0, 211:+1, 321:+1, 2112:0, 2212:+1, 1000010020:0, 1000010030:0, 1000020030:0, 1000020040:0, 130:0, 310:0, 311:0, 3122:0, -11:+1, -12:0, -13:+1, -14:0, -211:-1, -321:-1, -2112:0, -2212:-1, -3122:0}

Definition at line 126 of file _common.py.

dictionary constants = {'c_light':299.792458, 'pi':3.14159265,'echarge':1}

Definition at line 129 of file _common.py.

dictionary units
Initial value:
1 = {'':1.,
2  'mum':1.e-3, 'mm':1., 'cm':10., 'm':1.e3, 'km':1.e6,
3  'ns':1., 'mus':1.e3, 'ms':1e6, 's':1.e9,
4  'eV':1e-6, 'keV':1e-3, 'MeV':1., 'GeV':1.e3, 'TeV':1e6,
5  'eV/c':1e-6, 'keV/c':1e-3, 'MeV/c':1., 'GeV/c':1.e3, 'TeV/c':1e6,
6  'eV/c2':1e-6, 'keV/c2':1e-3, 'MeV/c2':1., 'GeV/c2':1.e3, 'TeV/c2':1e6,
7  'Gauss':1.e-7, 'mT':1.e-6, 'T':1.e-3, 'kT':1.,
8  'V':1.e-6, 'kV':1.e-3, 'MV':1., 'GV':1.e3,
9  'kHz':1.e-6, 'MHz':1.e-3, 'GHz':1.,
10  'GV/m':1.,'GV/mm':1.e3,
11  'kW':6.24150974e6, 'MW':6.24150974e9, 'GW':6.24150974e12,
12  'degrees':2.*constants['pi']/360., 'radians':1., 'deg':2.*constants['pi']/360., 'rad':1., 'degree':2.*constants['pi']/360., 'radian':1.,
13  'echarge':1., 'Coulomb':6.24150974*10.**18.
14 }

Definition at line 130 of file _common.py.

list _canvas_persistent = []

privates

Definition at line 168 of file _common.py.

list _hist_persistent = []

Definition at line 169 of file _common.py.

list _graph_persistent = []

Definition at line 170 of file _common.py.

list _legend_persistent = []

Definition at line 171 of file _common.py.

list _function_persistent = []

Definition at line 172 of file _common.py.

int _figure_index = 1

pyplot globals

Definition at line 175 of file _common.py.

wrapped_y_function = None

Definition at line 197 of file _common.py.

Referenced by xboa.common._common.__y_function_wrapper().

list __mp_subprocesses = []

Definition at line 876 of file _common.py.

list __fk_subprocesses = []

Definition at line 877 of file _common.py.

tuple __doc__ = common_overview_doc()

Definition at line 1244 of file _common.py.