Data analysis

From Polymer Physics
Jump to: navigation, search

Data analysis

This page contains information about and links to the Pro Fit plugins for neutron reflectivity analysis developed by Simon Martin.


In general the fitting of neutron data proceeds in the following way: First the data is loaded (imported), this involves setting up various things such as the length of any header included, the column delimiter and the line terminator. Next the data needs to be put into a usable format (ISIS data files are in histogram format and ILL files need to be re-binned). Finally the fitting process can begin. This involves choosing the model with which to model the data, setting up initial values and then setting the fitter going. Once the data is fitted, then it is usual to produce a summary of the fitting and to save the parameters obtained if they are considered reasonable.

The routines described here are designed to make this process as painless as possible. Data can be imported and modified easily and the routines to model the data are written in C in order to get a reasonably high performance from your computer.

I have invested quite a lot of effort in these routines and due credit should be given for this when the results are disseminated. This does not mean that I will demand to be an author on every paper that uses results obtained using the routines.


Macintosh computer running OS X 10.2 or newer pro Fit 6.0 or higher.

The following files add the required functionality to pro Fit.

  • ISIS import
  • dehistogram2
  • Params_To_DataWindow
  • Params_From_DataWindow
  • bundle.func
  • reflec.fitplugin
  • brush tanh.fitplugin
  • polymer-polymer-baytron-plugin.plugin

To get these files, download and unpack the archive


The latest version of pro Fit can be downloaded from the Quantumsoft web site (

The additional files are installed in one of two ways, depending on their type.

  • .func files

These are functions or programs written in pro Fit’s internal language (a variant of Pascal). To load one of these files into pro Fit: open the file using either the “open” option in the file menu or by double clicking on it. At the top of the window that opens there is a button marked "To Menu" press this to activate the pro Fit compiler. Alternatively this can done by selecting the Compile and Add to Menu option in the Customize menu. Once compiled the function or program will then be available to use from either the Function or Program menu.

  • .plugin

These are functions/programs that have been written in C and compiled with a dedicated compiler. They run much quicker than the equivalent routines written in pro Fit’s language. These are installed by selecting the Load plugin... option from the Customize menu.

Installing at start up

To avoid reloading the routines each time you start pro Fit you can arrange to have them loaded and installed each time the program is started by converting it into a “plug-in” that pro Fit can load automatically. First load and install the function/program as above. Then select the name of this routine in the “Save as plugin” sub-menu in the customize menu. When prompted choose to save the plug-in version of the routine in the “pro Fit plug- ins” folder which is in the same folder as the pro Fit application. Next time you start pro Fit you will find that the function/program is ready and waiting for you in the relevant menu.

Using the routines

Importing data

ISIS data

Select ISIS import from the program menu. You will be presented with the standard open file dialog. You may need to click on the pop-up menu next to the word enable at the top of the dialog box and select “All files” before you can select your data file. Once the file is selected press the return key or click on the “Open” button. The file will be opened and a new data window will appear. You will then be prompted to input a “value for scale factor” in another window. This is to allow you to easily normalize the data which needs to be done because in general ISIS files are not normalized (to the critical edge). Enter your chosen number and press the return key.

Once finished you will have a data window with 8 columns. The first 3 are the data as read in from the file (i.e. in histogram format). The remaining columns contain the data in x-y format - both R and RQˆ4 are provided along with their respective errors. Note that columns 4 to 6 are marked x,y and ∆y this means that these are the default columns for display in the preview window and are the data used in the fitting procedure.

De-histogramming data

You may not be satisfied with the normalization factor that you selected when using ISIS import. Using the program dehistogram2 allows you to select a new scaling factor for the data without going through the file selection procedure again. Note this routine overwrites the data in columns 4 to 8.

ILL (D17) data

Notes to follow...

Modeling data

This section briefly describes the various functions that have been written to model reflectivity data.

Slab model

The plugin reflec.plugin provides the function reflec. This allows the data to be modeled as up to 6 layers of constant scattering length density with a capping medium (usually air) and a backing medium (e.g. silicon).

Each layer in the model is characterized by three parameters. These are: its scattering length density (sldx); its roughness (roughx) in ̊Angstroms; its thickness (TK x) in Ångstroms, where x is the number of the layer - layer six is adjacent to the substrate. The other parameters are: TopSLD, the scattering length density of the capping medium; sld sub, the SLD of the substrate; r sub, the roughness of the substrate; scalef , a normalization parameter; Qmax, this is not used and will disappear when I get time; reso, the resolution to be used; backgr, the background value for the reflectivity.

Surface segregation

As its name implies the function polymer-polymer-baytron, which is provided by the plugin polymer-polymer-baytron-plugin.fitplugin, is designed to model a poly(fluorene)/dBaytron/Si system. It can however be used to study surface segregation effects in general by setting the SLD of the layer on top of the dBaytron layer to that of the capping layer. The Baytron layer is represented as a two component system, the volume fractions of the components through the film are modeled using a normalized complementary error function. The function works by dividing the layer into a series of slabs the thickness of which is chosen so that the change in scattering length density across each layer is the same.


Many of the parameters are similar to those in reflec. TopSLD is the capping medium. The layer on top of the Baytron is represented by sld1, rough1 and TK 1. The substrate is repesented by SLD and r subs. There is the possibility of having an oxide layer on top of the substrate, this is represented by SLDoxi, rougho and Toxide. The functional layer is represented by 8 parameters: sld a, is the SLD of the segregating component; sld b is the SLD of the second component of the the layer; TK 2 is the total thickness of the layer; rough2 is the roughness of the layer at the interface with layer 1; surfVF is the volume fraction of component a at the interface with layer 1; erfwidth is the width of the error function; erf is on offset in the centre of the error function about the interface between the two layers; bulkfa is the volume fraction of component a. The parameter min slab defines the minimum size of a slab that can be used to model the volume fraction profile.

Brush - tanh profile

The function brush tanh provides a crude method for modeling the swelling of a brush in a solvent system. This model allows for an initator layer between the substrate and the brush, this is represented by a scattering length density (sldinit) a roughness (rinit) and a thickness (TKinit). The scattering length density of the solvent is Solven. The substrate needs a scattering length density (SLD) and roughness (r subs). Six parameters are used to represent the brush: sld bru, rBrush and TK bru are the scattering length density, roughness and thickness of the brush; Zstar is the integrated coverage of the brush (essentially the thickness of the brush in air); VfracBr is the volume fraction of the brush; tanhwi is the width of the tanh profile.

Fitting the data


Profit provides a number of different methods for fitting data. For neutron reflectivity data the useful ones are Levenberg-Marquardt, Monte-Carlo and Robust. These are described below. It is possible to right custom fitting routines for Pro Fit. An example of this is the Simplex fitter that is provided by simplex.fitplugin. The simplex fitter works much more quickly than the built in methods, at the expense of graphical updates, and appears to be much better at finding (at least close to) global minima.

Built in fitting routines


In my experience the Robust method is the method of choice of the built in fitters. It works as follows: Starting from its present value, each active parameter is varied by a small step to find if this will decrease the value of Chi-squared. If yes, the new parameter set replaces the present set. This process is repeated iteratively until Chi-squared does not decrease further. This method is slow but sure. It will converge to a minimum - not necessarily the global one.

Monte Carlo

The ”Monte Carlo” fitting algorithm: each active parameter is varied at random within its variation range. With a new set of parameters obtained in this way, the value of Chi-square is calculated. If Chi-square has become smaller, the new parameter set replaces the present set. This process is repeated iteratively until you interrupt the operation.


In theory the Levenberg-Marquardt fitter should converge to the minimum much quicker than the robust method. It uses the derivatives of the function with respect to the active parameters in order to estimate a set of parameters that is closer to the minimum than the present set. However with highly nonlin- ear functions this process tends to be numerically unstable and the fitter often fails if the start parameters are too far from a minimum. Improved stability can be obtained by first running the robust method for say 100 iterations and then using the parameters obtained as the starting point for the LM fitter.

External fitting routines


This fitter uses the Nelder-Mead Simplex method (wikipedia entry). It is remarkably good at fitting neutron data and it is much faster than the built in fitters.

The fitter is provided by the plugin Simplex.fitplugin, it is loaded in the same way as the other plugins for Pro Fit.

To use the fitter set up your function to model the data with as usual. The Simplex fitter is started from the "Prog" menu. The preview window is not updated as the fit procedes, but text updates are given in the results windows instead.

Source Code

The source code for these routines can be obtained by contacting Simon Martin. The code is available as Xcode projects. It is poorly documented, but reasonably well commented.