Usort Help
Usort Help
Usort Help
c 1/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* */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
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}};
ncge = add.ncge;
/***********************************************
* get the gainmatching coeffs appropriate to
usort_help.c 3/4
~/ssort/jan09/ 11/10/2010
/***********************************************
* 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
*******************************************************/
/***********************************************
* 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
/***********************************************
* 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);
}
}
}