Extreme Graphics with Extrema
Highenergy physics experiments tend to generate huge amounts of data. While this data is passed through analysis software, very often the first thing you may want to do is to graph it and see what it actually looks like. To this end, a powerful graphing and plotting program is an absolute must. One available package is called Extrema (http://exsitewebware.com/extrema/index.html). Extrema evolved from an earlier software package named Physica. Physica was developed at the TRIUMF highenergy centre in British Columbia, Canada. It has both a complete graphical interface for interactive use in data analysis and a command language that allows you to process larger data sets or repetitive tasks in a batch fashion.
Installing Extrema typically is simply a matter of using your distribution's package manager. If you want the source, it is available at the SourceForge site (http://sourceforge.net/projects/extrema). At SourceForge, there also is a Windows version, in case you are stuck using such an operating system.
Once it is installed
on your Linux box, launching it is as simple as typing in
extrema
and
pressing Enter. At start up, you should see two windows: a visualization
window and an analysis window (Figure 1). One of the most important buttons
is the help button. In the analysis window, you can bring it up by clicking
on the question mark (Figure 2). In the help window, you can get more
detailed information on all the functions and operators available
in Extrema.
Figure 1. On startup, you are presented with a blank visualization window and an analysis window.
Figure 2. The help window gives you information on all of the available functions, operators and commands.
Extrema provides 3D contour and density plots. For 2D graphing, you can control almost all the features, like axes, plot points, colors, fonts and legends. You also can do some data analysis from within Extrema. You can do various types of interpolation, such as linear, Lagrange or FritschCarlson. You can fit an equation to your data with up to 25 parameters. Extrema contains a full scripting language that includes nested loops, branches and conditional statements. You either can write out scripts in a text editor or use the automatic scriptwriting mode that translates your pointandclick actions to the equivalent script commands.
The first thing you will need to do is get your data into Extrema. Data is stored in variables and is referenced by the variable's name. The first character of a variable name must be alphabetic and cannot be any longer than 32 characters. Other than these restrictions, variable names can contain any alphabetic or numeric characters, underscores or dollar signs. Unlike most things in Linux, variable names are caseinsensitive. And remember, function names are reserved, so you can't use them as variable names.
String variables can contain either
a single string of text or an array of text strings. Numeric variables
can contain a single number, a vector (1D array), a matrix (2D array)
or a tensor (3D array). All numbers are stored as doubleprecision
real values. Unlike most other programming languages, these arrays
are indexed starting at 1, rather than 0. There are no limits to the
size of these arrays, other than the amount of memory available on your
machine. Indexing arrays in Extrema can be interesting. If you want the
eighth element of array x, you simply can reference it with
x[8]
. You can
grab elements 8, 9 and 10 with x[8:10]
. These indices can be replaced
with expressions, so you could get the eighth element with
x[2^3]
.
There
also are special characters that you can use in indexing arrays. The
statement x[*]
refers to all the values in the vector. If you want
the last element, you can use x[#]
. The secondtolast element can be
referenced with x[#1]
.
You likely have all of your data stored in files. The simplest file format is a commaseparated list of values. Extrema can read in these types of files and store the data directly into a set of variables. If you have a file with two columns of data, you can load them into two variables with the statement:
READ file1.dat x y
You also can read in all of the data and store it into a single matrix with:
READ\matrix file1.dat m nrows
In order to do this, you need to provide the number of rows that are being read in. You also can generate data to be used in your analysis. If you simply need a series of numbers, you can use:
x = [startval:stopval:stepsize]
This will give you an array of numbers starting at
startval
, incrementing by
stepsize
until you reach
stopval
. You can use the
GENERATE
command
to do this as well. The GENERATE command also will generate an array of random
numbers with:
GENERATE\RANDOM x min max num_points
Extrema has all of the standard functions available, like the various types of trigonometric functions. The standard arithmetic operators are:

+ — addition

 — subtraction

* — multiplication

/ — division

^ — exponentiation

() — grouping of terms
There also are special operators for matrix and vector operations:

>< — outer product

<> — inner product

< — matrix transpose

> — matrix reflect

/ — vector union

/& — vector intersection
There also is a full complement of logical Boolean operators that give true (1) or false (0) results.
Now that you have your data and have seen some of the basic functions and operators available, let's take a look at graphing this data and doing some analysis on it. The most basic type of graph is plotting a onedimensional array. When you do this, Extrema treats the data as the y value and the array index as the x value. To see this in action, you can use:
x = [1:10:1]
GRAPH x
This plots a fairly uninteresting straight line (Figure 3).
Figure 3. Plotting a Vector of Values
To plot twodimensional data, you can use:
GRAPH x y
where x and y are two vectors of equal length. The default is to draw the data joined by a solid line. If you want your data as a series of disconnected points, you can set the point type to a negative number, for example:
SET PLOTSYMBOL 1
Then you can go ahead and graph your data.
Parametric plots also are possible. Let's say you have an independent variable called t that runs from 0 to 2*Pi. You then can plot t*sin(t) and t*cos(t) with:
t = [0:2*pi:0.1]
x = t * sin(t)
y = t * cos(t)
graph x y
This will give you the plot shown in Figure 4.
Figure 4. Graphing a Parametric Plot
In scientific experiments, you usually have some value for error in your measurements. You can include this in your graphs as an extra parameter to the graph command, assuming these error values are stored in an extra variable. So, you could use:
graph x y yerr
to get a nice plot. Many options are available for the graph command (Figure 5).
Figure 5. The graph command has many available options.
More complicated data can be graphed in three dimensions. There are several types of 3D graphs, including contour plots and surface plots. The simplest data structure would be a matrix, where the indices represent the x and y values, and the actual numbers in the matrix are the z values. If this doesn't work, you can represent the separate x, y and z values with three different vectors, all of the same length. The most basic contour graph can be made with the command:
CONTOUR m
where m is the matrix of values to be graphed. In this case, Extrema will make a selection of nice contour lines that create a reasonable graph.
You can draw a density plot of the same data with the density command, where the values in your matrix are assigned a color from a color map, and that is what gets graphed. Unless you say differently, Extrema will try to select a color map that fits your data the best. A surface plot tries to draw a surface in the proper perspective to show what surface is defined by the z values in your data.
Let's finish by looking at one of the more important analysis steps, fitting an equation to your data. The point of much of science is to develop equations that describe the data being observed, in the hope that you then will be able to predict what you would see under different conditions. Also, you may learn some important underlying physics by looking at the structure of the equation that fits your data. Let's look at a simple fitting of a straight line. Let's assume that the data is stored in two vectors called x and y. You'll also need two other variables to store the slope and intercept. Let's call them b and a. Then you can fit your data with the command:
SCALAR\FIT a b
FIT y=a+b*x
Then, if you want to graph your straight line fit and your data, you can do something like:
SET PLOTSYMBOL 1
SET PLOTSYMBOLCOLOR RED
GRAPH x y
SET PLOTSYMBOL 0
SET CURVECOLOR BLUE
GRAPH x a+b*x
Now that you have seen the basics of what Extrema can do, hopefully you will be inspired to explore it further. It should be able to meet most of your dataanalysis needs, and you can have fun using the same tool that is being used by leading particle physicists.