This is fairy, a software tool for flexible analsysis of ionizing radaition yields in 1D or 2D spectra of experimental nuclear physics or other data. It is meant to be used with the Elder data analysis framework.
Fairy is free software, you can redistribute it and/or modify it under the terms of the GNU General Public License.
The GNU General Public License does not permit this software to be redistributed in proprietary programs.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
The Design goals of fairy were:
- quick response in interactive use
- fast update rates
- intuitive interface
- few dependencies (e.g. fairy does not use Root)
Features are:
- 1D/2D histograms
- 1D/2D window gates and 2D polygon gates
- 1D functions and interactive fitting to histogram data
- interactive projections of 2D histograms
The program is written in the D programming language. The GUI is currently based on GTK3 and Cairo.
fairy manages multiple data windows. Each window is separated into
- a tree-view of all available items,
- a canvas where items are visualized,
- and below the canvas is a control panel.
When a check box in the tree-view is clicked, the current status of the item will be shown. If the check box is a directory with multiple items, all items will be shown. If the item is a histogram which is changing because data is analyzed, the canvas will show the state of the histogram when the check box was clicked. Pressing the "refr." button in the control panel will update the drawing of the histogram once. In "auto refr." mode, the drawing of all items will be updated repeatedly as fast as possible.
Each window can display data (1D/2D histograms, 1D/2D gates, 1D functions) in tree modes
- overlay mode: all data is drawn on top of each other
- row-major mode: dat
Interactive items (1D-windows, 2D-windows, polygon gates) can be manipulated with the left mouse button. Elements of interactive items are
- left/right border of a 1D-Window
- points of a polygon gate
Hovering the mouse over an element of an interactive item will highligh that element in green. A single left click on an element of an interactive item will select only that element and deselect all previously selected elements. A single left click into the void will deselect all selected elelments. Holding Ctrl while left clicking an unselected/selected element will add/remove that element to/from the set of selected elements. Left click and hold will open a selection box. When releasing the left mouse button, all elements inside the box will be added/removed to/from the set of selected elelments if the Shift key is inactive/pressed. Click and hold any highlighted or selected element will allow to move all highlighted and selected elements together with the mouse unless a selected element is in a different tile in grid mode then where the mouse click happened. If elments of different items should be moved together, this must be done in overlay mode.
Polygon gates have a richer set of actions than 1D/2D-windows.
- Line segments can be split by left click on the line while the Shift key is pressed.
- A point can be deleted by left click on the point while the Shift key is pressed.
- The entire polygon can be scaled/rotated around its center by a left click an hold into the polygon area while the Shift/Ctrl key is pressed.
A function item is a 1D formula (e.g. a peak shape on top of a background) with parameters that can be fit to the data of a 1D histogram over some region, and that can additionally expose some of its parameters as draggable "handles" on the canvas, so that the start parameters of the fit can be adjusted interactively with the mouse instead of by editing numbers.
Right-click on a 1D-histogram in the item tree-view and choose "chi^2 fit" (or "log-L fit" for a log-likelihood/Poisson fit instead of a chi-square fit), then pick one of the predefined peak shapes ("gauss linear-bg", "cauchy linear-bg", "two gaussians linear-bg", "gauss quadratic-bg", "gaussian-folded exponential linear-bg", "gauss with exponential tail linear-bg"). This automatically creates and shows
- a 1D-window gate that marks the region used for the fit (its left/right border can be dragged like any other 1D-window, see above), and
- a function item with handles already placed at reasonable start values, derived from the currently visible part of the canvas.
From there, just drag the handles onto the peak you want to fit (see below), then let go of the mouse to fit. Holding Ctrl while dragging will continuously run a quick (20-step) fit so you can see a live preview of the fit result as you adjust the handles; releasing the mouse button always triggers a full fit over the gate's region.
The same thing can be done by typing a command (in the command line interface, or into a session file). The relevant commands are:
gate1d <gatename> <left> <right>
funct <name> <definition> <parameters> <handles> <hist1dname> <gate1dname> <results> <dragupdate> <loglikelihood>
show <gatename> <windowname>
show <name> <windowname>
<definition>is the function formula as a string, usingxfor the independent variable and any other identifier as a fit parameter. Built-in helper functions includegauss(x,s),cauchy(x,s)(a Lorentz/Cauchy peak),gex(x,s,t)(a Gaussian folded with an exponential tail of decay constantt),erf,erfc,step,window,triangleandatan2. Dividing by e.g.gauss(s,s)normalizes the peak so that the parameter in front of it (Abelow) is directly the peak area, not its height.<parameters>is a list of"name=startvalue"strings for every parameter in<definition>exceptx, e.g.["A=100","s=5","x0=50","a=2"].<handles>is the handle-tree string described below.<hist1dname>/<gate1dname>name the histogram to fit and the 1D-window gate that defines the fit region.<results>is a list of"name=expression"strings, derived quantities (and their errors, propagated from the fit's covariance matrix) that are displayed next to the function after fitting, e.g.["area=A/gauss(s,s)","FWHM=s*2.35482"]. The special namebinwidthcan be used inside a result expression to get the histogram's bin width (handy for turning a peak area into a count rate).<dragupdate>and<loglikelihood>aretrue/false;loglikelihoodselects a Poisson-deviance fit (good for low-statistics histograms) instead of the default chi-square fit.
A handle string is a sequence of nodes [paramX,paramY], where paramX/paramY are two parameter names from <definition>. Each node becomes one draggable point on the canvas. A node can be followed by (...) containing child nodes, which nests their handles as children of it; several [...] nodes next to each other (not nested) are independent siblings.
The position of a root node's handle is simply the value of its two parameters, in canvas (world) coordinates - e.g. [x0,a] sits at the point (x0, a), so x0 and a are naturally "global" quantities such as a peak position and a baseline height. A child node's handle, however, is drawn and dragged relative to its parent: its canvas position is the parent's position plus its own two parameter values. So a child node [s,A] nested under [x0,a] is drawn at (x0+s, a+A) - which conveniently places the handle for a peak's width/amplitude right on the slope of the peak, next to the peak position/baseline handle it is anchored to.
This has two practical consequences:
- Dragging a parent handle drags the whole subtree with it (the peak position moves, and its width/amplitude handle moves along, keeping their offsets, i.e. the peak keeps its shape while you reposition it).
- Dragging a child handle on its own only changes that child's own parameters (e.g. only the width/amplitude), leaving the parent (e.g. the peak position) untouched.
- Siblings (nodes not nested inside one another) move completely independently of each other.
You can fit without using the mouse at all with the fit (chi-square) or fitLL (log-likelihood) commands, giving the function name, histogram name, and a left/right fit region directly.
A straight line a + b*(x-x0) has no peak at all, but it is still useful to illustrate the simplest handle tree: a single node with no children, [x0,a]. Dragging it left/right changes x0 (just a reference point on the x-axis), dragging it up/down changes a (the line's height at x0); b (the slope) has no handle here and would be found purely by the fit, or set with a separate funct command for a line with no draggable handles at all.
gate1d peak/gate 40 60
funct peak/function "A*gauss(x-x0,s)/gauss(s,s)+a+b*(x-x0)" ["A=100","s=5","x0=50","a=2","b=0"] "[x0,a]([s,A])" peak peak/gate ["counts=A/gauss(s,s)/binwidth","area=A/gauss(s,s)","sigma=s","FWHM=s*2.35482","pos=x0"] true false
show peak/gate win1
show peak/function win1
The root handle [x0,a] sits on the peak's position/baseline and can be dragged to reposition the whole peak; its child [s,A] sits at (x0+s, a+A), right on the peak's shoulder, and controls the peak's width and amplitude without moving its position. This is exactly the handle tree used by the "gauss linear-bg" menu entry; "cauchy linear-bg" and "gauss quadratic-bg" use the same [x0,a]([s,A]) tree (the quadratic background's curvature parameter c simply has no handle and is left for the fit to determine), and "gauss with exponential tail linear-bg" / "gaussian-folded exponential linear-bg" use the same idea with an extra sibling child, e.g. [x0,a]([s,A][t,B]).
gate1d peak/gate 30 90
funct peak/function "A*gauss(x-x0,s0)/gauss(s0,s0)+B*gauss(x-x1-x0,s1)/gauss(s1,s1)+a+(x-x0)*b/x1" ["A=100","s0=5","x0=40","B=80","s1=5","x1=25","a=2","b=0"] "[x0,a]([s0,A][x1,b]([s1,B]))" peak peak/gate ["counts0=A/gauss(s0,s0)/binwidth","counts1=B/gauss(s1,s1)/binwidth","sigma0=s0","sigma1=s1","pos0=x0","pos1=x0+x1"] true false
show peak/gate win1
show peak/function win1
Here x1 is deliberately the distance between the two peaks, not an absolute position, and its handle [x1,b] is nested under the first peak's [x0,a], with the second peak's own width/amplitude [s1,B] nested one level deeper still. Dragging the first peak's root handle moves both peaks together (handy once you've roughly placed the doublet); dragging the second peak's [x1,b] handle only changes the gap between the two peaks; dragging the deepest [s1,B] handle only changes the second peak's shape. This is the handle tree used by the "two gaussians linear-bg" menu entry.
If two peaks should not be tied together, use two sibling root nodes instead of nesting one under the other:
funct doublet/function "A*gauss(x-x0,s0)/gauss(s0,s0)+a + B*gauss(x-x1,s1)/gauss(s1,s1)+b" ["A=100","s0=5","x0=40","a=2","B=80","s1=5","x1=65","b=2"] "[x0,a]([s0,A])[x1,b]([s1,B])" doublet doublet/gate [] true false
Now [x0,a] and [x1,b] are two separate root handles, each with its own child for width/amplitude, and each with its own independent baseline (a and b). Dragging either peak's handles never moves the other peak - useful when the two peaks don't belong to the same physical doublet and may need to be repositioned independently.
| key | action |
|---|---|
| Ctrl-n | open new window |
| Ctrl-w | close window |
| Ctrl-q | quit program |
| u | update content |
| p | toggle poll mode (aka auto update) |
| f | fit viewport to content |
| x | toggle auto fit mode on x axis |
| y | toggle auto fit mode on y axis |
| z | toggle auto fit mode on z axis |
| l | toggle logscale mode (affects y or z axis) |
| g | toggle grid |
| i | toggle fill mode for 1D histograms |
| t | toggle statistics display for 1D histograms |
| m | toggle zoom mode (only filled bins are considered when fitting the viewport) |
| o | overlay mode (no tiling, all histograms are drawn on top of each other) |
| r | row-major mode |
| c | column-major mode |
| 1...9 | set number of rows/columns in row-/column-major mode |
| b | toggle color bar |
| a,s,d,w | navigate the viewport |
| e,q | zoom in/out |



