Usort Help

Download as ps, pdf, or txt
Download as ps, pdf, or txt
You are on page 1of 4

usort_help.

c 1/4
~/ssort/jan09/ 11/10/2010

// * Example usort file with annotations *


// * *
// * Preamble section: *
// * *
// * Here the spectra, data format and runfiles are specified *
// * The section must start with /* *PREAMBLE* *
// * and end with *END* */ *
// * *
// * *
// * *
//
//
/* *PREAMBLE*
// comments within the preamble must be C++ style, ie preceeded by a //
//
*SPECTRA*
// section to define the spectra to be sorted, must begin with
// the keyword *SPECTRA*, and end with *ENDSPECTRA*
// The number of spectra is only limited by the amount of memory that
// your computer has.
//
// Information about a spectrum must be all in the same line.
//
// *************************1 dimensional spectra***************************
// eg RadWare format:
// total projection spectrum and a spectrum after a 2D gate
NAME=totalspec, DIM=1, XLEN=8192, TYPE=SPE
NAME=gatedspec, DIM=1, XLEN=8192, TYPE=SPE
// can have multiple spectra using the NSPE keyword (see later for increment commands)
NAME=multiples, DIM=1, NSPE=110, XLEN=8192, TYPE=SPE
//
//
//
// *************************2 dimensional spectra***************************
// can be MAT format (2 bytes per channel)
// or M4B format (4 bytes per channel) for use with escl8r, slice, etc.
NAME=matrix, DIM=2, XLEN=4096, YLEN=4096, TYPE=MAT
NAME=matrixm4b, DIM=2, LEN=4096, TYPE=M4B
// the optional keyword LEN allows both axes to be specified at once
//
//
//
// *************************3 dimensional spectra***************************
// can be RadWare (levit8r) format
// or ana format
//
// RadWare format must have a .tab file, which in the case below
// should be radcube.tab (run lufwhm to make this .tab file)
NAME=radcube, TYPE=RADCUBE, DIM=3, SCRATCHSIZE=500
// ana format for use with the Ana program has options:
// ANATYPE describes the degree of symmetrisation.
// ANATYPE=FULL_CUBE is non−symmetrised
// =HALF_CUBE is axes x and y are symmetrised
// =SIXTH_CUBE is axes x,y,z are symmetrised
// ANAPREC specifies either 2 or 4 bytes per channel
NAME=anacube, TYPE=ANA, DIM=3, XLEN=2048, YLEN=2048, ZLEN=2048, ANATYPE=SIXTH_CUBE, ANAPREC=2
//
*ENDSPECTRA*
//
//
// Next define the data format.
// This section must start with *FORMAT* and end with *ENDFORMAT*
*FORMAT*
//
// There are format files already provided with ssort, for use with data
// from various labs. This example is for Gammasphere data at Argonne.
// The example format files all put the data into structures, which are
// accessible by the user sort routines, by the #include "sortheader.h"
// preprocessor statement (see below)
//
FORMAT=gstapeanl
*ENDFORMAT*
usort_help.c 2/4
~/ssort/jan09/ 11/10/2010

//
//
// Now specify the input source for the data. This can be from a tape device
// attached to the computer, or files stored on the filesystem.
//
// Useful keywords here are SWAPBYTES=1 which will byte−swap the data
// as it is read in. (SWAPBYTES=0 will switch this off)
// BLOCKSIZE specifies the blocksize of the data buffer to be sorted. For
// tape drives this must be equal to the blocksize of the data on the tape.
// For disc files, this can be set to any number, but a sensible value is
// 16384, which will sort 16 kilobyte blocks.
// example for a tape drive
TAPE1=/dev/rmt/0mbn, SWAPBYTES=0, BLOCKSIZE=16384
// example for a disc file
FILE1=/home/user/file1.dat, SWAPBYTES=0, BLOCKSIZE=16384, GAINFILE=file1gains.dat
FILE2=/home/user/file2.dat, SWAPBYTES=0, BLOCKSIZE=16384
//
// The program will sort each of the input sources in succession.
// The data can be gainmatched on a per−file basis, in order to correct for
// gain drifts. This is specified by using the GAINFILE keyword. The format
// of the gainfile should be in the format given in the example gainfile
// provided, examplegains.dat. For more information on how to do the
// per−file gainmatching see the sections below.
// *** for the moment, per−file gainmatching only works for ***
// *** disc files, not for tape devices ***
*ENDRUNFILES*
*END* */

// Now starts the sort file itself, coded in normal c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>

// The ssort−specific header files must be included as below:


#include "ssort.h"
#include "autogain.h"
#include "sortheader.h"

// Declare a struct to hold the per−file gainmatching coefficients


struct gegaincoeffs
{
double ecoeffs[4];
double tcoeffs[4];
};

int usub(struct matrix **head, struct gainstruct **gainhead, struct sortinfo *sinfo)
{

int ncge,i;

/**********************************************************
* 2D gates can be made, by declaring the gate coordinates
* as below, and using the gate function (see later).
* Coordinates must be in clockwise order. The
* following gate defines a 50x200 rectangle centred on the
* point 225,105 in the x−y plane
* The gate is declared as a 2D array, gate2d[i][2] where
* i is the number of vertices
**********************************************************/
int gate2d[4][2] = {{200, 10}, {200, 210}, {250, 210}, {250, 10}};

// **important** declare the gain coeffs struct to be static


static struct gegaincoeffs coeffs[110];

ncge = add.ncge;

/***********************************************
* get the gainmatching coeffs appropriate to
usort_help.c 3/4
~/ssort/jan09/ 11/10/2010

* this run, and store them in the coeffs struct


***********************************************/
if (sinfo−>autogain == 1)
{
for (i=0; i<nge; i++)
{
findgains(germanium[i].energy,i,&coeffs[i].ecoeffs);
findgains(germanium[i].time,i,&coeffs[i].tcoeffs);
}
sinfo−>autogain = 2;
}

/***********************************************
* now we have found the gain coefficients
* do the gainmatching itself
*
* Have to be very careful here. The coefficents
* are indexed by detector id in the input file
* ie
* germanium[4].energy 0 0.399713 0.179
* where 4 is the detector id number.
* BUT gammasphere data (and some other data types)
* are written out in unspecified order, so if you
* loop over i from 0 to ncge (number of clean ge), you
* have to index the coeffs by [germanium[i].id]
* and not [i], ie coeffs[germanium[i].id].ecoeffs[0]
*
* the gainmatching routine is called as:
* data = gainmatch(data,a,b,c,factor)
* and will return (a*data^2 + b*data + c)*factor
* if factor is zero it will be ignored
***********************************************/

if (sinfo−>autogain == 2)
{
for (i=0; i<ncge; i++)
{
germanium[i].energy = gainmatch(germanium[i].energy,coeffs[germanium[i].id].ecoeffs[0],
coeffs[germanium[i].id].ecoeffs[1],coeffs[germanium[i].id].ecoeffs[2],coeffs[germanium[i].id].eco
effs[3]);
germanium[i].time = gainmatch(germanium[i].time,coeffs[germanium[i].id].tcoeffs[0],coef
fs[germanium[i].id].tcoeffs[1],coeffs[germanium[i].id].tcoeffs[2],coeffs[germanium[i].id].tcoeffs
[3]);
}
}

/*******************************************************
* from here onwards we have gainmatched data
*******************************************************/

for (i=0; i<ncge; i++)


{

/***********************************************
* increment a total projection spectrum
* using the syntax:
* inc_spectrumname(data)
* with respect to the spectra declared in
* the preamble
***********************************************/
inc_totalspec(germanium[i].energy);
/***********************************************
* increment multiple spectra using the syntax:
* inc_spectrumname(id,data)
*
* where id will be appended to the spectrum name
* when written to disk, ie spectrumname.id.spe
***********************************************/
inc_multiples(germanium[i].id,germanium[i].energy);
for (j=i+1; j<ncge; j++)
{
/***********************************************
usort_help.c 4/4
~/ssort/jan09/ 11/10/2010

* increment the two matrices


* first one is symmetric (ie increment the
* same data to both axes, needs 2 inc commands)
***********************************************/
inc_matrix(germanium[i].energy,germanium[j].energy);
inc_matrix(germanium[j].energy,germanium[i].energy);

/***********************************************
* second matrix is not symmetric (ie energy−time
* matrix)
***********************************************/
inc_matrixm4b(germanium[i].energy,germanium[j].time);
}
}

/***********************************************
* now for the cubes
***********************************************/
if (ncge >= 3)
{
for (i=0; i<ncge; i++)
{
for (j=i+1; j<ncge; j++)
{
for (k=j+1; k<ncge; k++)
{
inc_anacube(myge[i].energy,myge[j].energy,myge[k].energy);
inc_radcube(myge[i].energy,myge[j].energy,myge[k].energy);
}
}
}
}

/**********************************************
* A demonstration of the gate function
* using the gate defined above
* The function is called as:
* gate(TWOD,x,y,gatename,npoints)
**********************************************/
for (i=0; i<ncge; i++)
{
if (gate(TWOD,germanium[i].energy,germanium[i].time,gate2d,4))
{
/* The gate is passed, therefore the points
(germanium[i].energy,germanium[i].time) are
within the rectangular gate defined by
the gate2d polygram
*/
inc_gatedspec(germanium[i].energy);
}
}
}

You might also like