384 lines
22 KiB
C
384 lines
22 KiB
C
#ifndef ALG_GLOBAL_H
|
|
#define ALG_GLOBAL_H
|
|
|
|
#include <QString>
|
|
#include <QDebug>
|
|
#include <armadillo>
|
|
#include "GammaAnalyAlgLib.h"
|
|
|
|
#define MAX_INDEX_PEAK 47
|
|
#define MAX_INDEX_SPEC 24
|
|
#define pi_ 3.1415926535897932384L
|
|
|
|
struct PiecePoly // piecewise polynomial -- pp
|
|
{
|
|
QString form;
|
|
arma::rowvec b; // breaks
|
|
arma::mat c; // coefs
|
|
arma::rowvec d; // dim
|
|
int l; // pieces
|
|
int k; // order
|
|
};
|
|
|
|
// PAT cell data
|
|
struct PatCellData
|
|
{
|
|
// Variable lengths strings (cell vector)
|
|
QString NuclideSoft; // Soft identification from PAT
|
|
QString NuclideHard; // Hard identification from PAT
|
|
QString NuclideInternal; // normalized name of nuclide
|
|
QString Nuclide; // NuclideHard, probably followed by NuclideSoft
|
|
QString HalfLifeStr; // Nuclide half life as string, with time unit
|
|
QString EffectiveHalflifeStr; // Effective nuclide half life as string, including unit
|
|
};
|
|
|
|
// Nuclide Reference Peak index
|
|
struct NuclidePIdx
|
|
{
|
|
|
|
};
|
|
|
|
// Nuclide Analysis Table (NAT)
|
|
struct NuclideATab
|
|
{
|
|
|
|
};
|
|
|
|
struct PAT
|
|
{
|
|
//QString PatName; // 1
|
|
arma::mat Peaks; // 2
|
|
QString PatFlags; // 3
|
|
/* 1: Source 'E' External
|
|
* 'A' Artificial Peaks
|
|
* 'B' Background Peaks
|
|
* 'M' Mariscotti Peak Search
|
|
* 'R' Residual Peak Search
|
|
* 'I' Manually inserted
|
|
* 'L' Library inserted
|
|
* 'N' inserted by natural RN model
|
|
* 'S' inserted by summation peak model
|
|
* 'G' neutron-induced lumps in germanium
|
|
* 2-5: ?
|
|
* 6-7: 'ct'
|
|
* 8: Centroid- 'Q' Quickfit
|
|
* -Method 'F' Full Fit
|
|
* 'U' User Defined
|
|
* 'E' External
|
|
* 'T' Tied Multiplet fitting (relative energy)
|
|
* 'M' Mariscotti Centroid
|
|
* 'L' Library Energy (converted to centroid)
|
|
* 'G' Special Library Energy (Neutron Lumps)
|
|
* 9: Free '0' ct wasn't free in last fitting of this peak
|
|
* '1' ct was free in last fitting of this peak
|
|
* 10-11: 'na'
|
|
* 12: NetArea Method 'Q' Quickfit
|
|
* 'F' Full Fit
|
|
* 'U' User Defined
|
|
* 'E' External
|
|
* 'T' Tied Multiplet fitting
|
|
* 'C' Calculated from reference lines
|
|
* 'S' Summation above reliable baseline
|
|
* 's' summation above quick-and-dirty baseline
|
|
* 'G' fitting of neutron lump area
|
|
* 13: NetArea Free '0' na wasn't free in last fitting of this peak
|
|
* '1' na was free in last fitting of this peak
|
|
* 14-15: 'fw'
|
|
* 16: FWHM Method 'Q' Quickfit
|
|
* 'F' Full Fit
|
|
* 'U' User Defined
|
|
* 'E' External
|
|
* 'C' Calibration value (converted to fwhm_ch)
|
|
* 'G' Calibration value with add-on (lumps)
|
|
* 17: FWHM Free (0|1)
|
|
* 18-25: ?
|
|
* 26: Spurious (S|.) marked spurious
|
|
* 27: Reviewed (R|.) marked reviewed
|
|
* 28: TailChanged (T|.) tail changed since last fitting
|
|
* 29: ResChanged (R|.) resolution changed since last fitting
|
|
* 30: ?
|
|
*/
|
|
//PatCellData PatCell; // 4
|
|
QStringList CalibName; // 5
|
|
//NuclidePIdx PeakIdx; // 6 The param now is empty--@cao
|
|
//NuclideATab Nat; // 7
|
|
QVector<bool> NatUpdateFlag;
|
|
//QStringList AdminInfo; // 8
|
|
|
|
PAT()
|
|
{
|
|
Peaks.set_size(0, MAX_INDEX_PEAK);
|
|
CalibName << "" << "" << "" << "" << "" << "" << "" << "" << "";
|
|
PatFlags.fill(0, 30);
|
|
}
|
|
};
|
|
|
|
/*struct SpecBaseInfo
|
|
{
|
|
arma::rowvec Spectrum; // channel contents
|
|
// arma::rowvec SpectrumLong; // channel contents, padded with NaNs to length of longest spectrum
|
|
arma::rowvec BaseLine; // fitted baseline
|
|
arma::rowvec AnalysisRange; // Analysis Range (first and last valid channel)
|
|
arma::rowvec AnalysisRangeSave; // Save Analysis range, i.e. if empty will be [1,NCh]
|
|
arma::rowvec XControl; // baseline control points x-data
|
|
arma::rowvec YControl; // baseline control points y-data
|
|
arma::rowvec YSlope; // slope at breakpoints, NaN at normal control points
|
|
arma::rowvec Residual; // residual (Spectrum-BaseLine-Peaks)
|
|
arma::rowvec Stripped; // stripped spectrum (gaussian peaks substracted)
|
|
arma::rowvec Steps; // non-spline baseline components
|
|
arma::rowvec ROISmooth; // stripped spectrum minus Steps, with smoothened ROIs
|
|
arma::rowvec SmoothStripped; // smoothened stripped spectrum
|
|
arma::rowvec Approximation; // spectrum approximation (baseline + peaks)
|
|
arma::rowvec ChiSquare; // mean weighted residual and number of channels with zero counts ( [ChiSquare, nzero] )
|
|
arma::rowvec ArtXControl; // artificial baseline control points x-data
|
|
arma::rowvec ArtYControl; // artificial baseline control points y-data
|
|
arma::rowvec ArtYSlope; // slope of artificial baseline control points
|
|
arma::rowvec ArtificialBase; // Artificial baseline (if not empty)
|
|
arma::rowvec BaseFittingWeights; // Weight function used in baseline fitting
|
|
arma::rowvec PSS; // value of peak search sensitivity in each channel
|
|
};*/
|
|
|
|
#endif // ALG_GLOBAL_H
|
|
|
|
/*enum PatType
|
|
{
|
|
Pat_Current,
|
|
Pat_Temporary,
|
|
Pat_TrueCurrent,
|
|
Pat_Auxiliary,
|
|
Pat_External,
|
|
Pat_Other
|
|
};
|
|
|
|
struct __PeakInfo
|
|
{
|
|
double Centroid; // 1 directly read from data
|
|
double CentroidErr; // 2 directly read from data, currently always NaN for internal PATs
|
|
double Energy; // 3 EnergyPAT for peaks where EnergyPAT is NaN; for other peaks
|
|
// the value of energy calibration at Centroid is evaluated.
|
|
double EnergyErr; // 4 directly read from data, currently always NaN for internal PATs
|
|
|
|
double FWHM_Ch; // 5 FWHM_ChPAT, where this is not NaN; where it is NaN, using FWHM / dE
|
|
double FWHM; // 6 FWHMPAT, where not NaN; where Nan, use dE*FWHM_Ch
|
|
double FWHMErr; // 7 FWHM error estimate, read directly from PAT; currently always NaN for internal PATs
|
|
|
|
double StepRatioErr; // 8 Step Ratio error read from PAT, currently always NaN
|
|
double StepRatio; // 9 StepRatioPAT, where not NaN, else using calibration
|
|
|
|
double Tail; // 10 ManualTail, where not NaN; where NaN, tail calibration value of energy;
|
|
double TailErr; // 11 Tail uncertainty read from PAT, currently always NaN for internal PATs
|
|
|
|
double NetArea; // 12 Net area value read from PAT
|
|
double AreaErrorPAT; // 13 net area error read from PAT, currently always NaN for internal PATs
|
|
|
|
double MeanBackCount; // 14 mean background count read from PAT; for internal PATs updated whenever baseline changes
|
|
double Sensitivity; // 15 Peak Search sensitivity at finding, read from PAT; may be NaN
|
|
double Significance; // 16 Significance value read from PAT; for internal PATs updated whenever baseline changes
|
|
double SignificanceErr; // 17 significance uncertainty read from PAT, currently NaN for internal PATs
|
|
|
|
double MultipletPAT; // 18 multiplet flag (0|1) read from PAT, must be NaN for internal PATs
|
|
|
|
double Efficiency; // 19 EfficiencyPAT, where not NaN; where NaN, calculated from efficiency calibration of Energy
|
|
double EfficiencyErr; // 20 efficiency uncertainty read from PAT; currently always NaN for internal PATs
|
|
|
|
double BWWidth; // 21 BWWidthPAT, but 0 where NaN
|
|
|
|
double BWWidthErr; // 22 Breit-Wigner gamma uncertainty
|
|
|
|
double EmissionRate; // 23 currently EmissionRatePAT
|
|
double EmissionRateErr; // 24 emission rate error, read from PAT
|
|
|
|
double CCF; // 25 CCFPAT, if that is not NaN, 1 otherwise
|
|
double CCFErr; // 26 Error of CCF in % of CCF, if NaN in PAT, then 10*abs(1-CCF)
|
|
|
|
double LineEnergy; // 27 library line energy of the nuclide with which the peak was assoziated.
|
|
double LineEnergyErr; // 28 Line energy error read from PAT
|
|
|
|
double Yield; // 29 Library Line Yield (1 for 100%)
|
|
double YieldErr; // 30 Library Line Yield Uncertainty
|
|
|
|
double ReferenceID; // 31 Unique ID numbers for reference peaks, NaN otherwise (in PAT)
|
|
double RefPointer; // 32 Pointer to reference peak ID of nuclide assoziated with the
|
|
// peak, calculated from NuclideIntenal and nuclide Structure
|
|
|
|
double BranchingRatio; // 33 Branching Ratio between peak and its reference (equilibrium)
|
|
|
|
double LC; // 34 Currie's minimum NetArea for accepting peak
|
|
double LD; // 35 Currie's NetArea that should lead to reliable detection
|
|
|
|
double SignedResidual; // 36 Mean signed residual (patBaseVar)
|
|
double UnsignedResidual; // 37 Mean unsigned residual (patBaseVar)
|
|
|
|
double ResidualUpToDate; // 38 Flag whether variables 36 and 37 are up to date
|
|
|
|
double SumPeakArea; // 39 calculated area of summation peak (counts)
|
|
double SumPeakAreaErr; // 40 error of summation peak area (counts)
|
|
|
|
double BackgroundArea; // 41 Total Baseline Area (1+f)*BC
|
|
|
|
double RefEfficiencyErr; // 42 uncertainty of the efficiency ratio between the peak
|
|
// and it's reference peak. If the value in PAT is NaN, the
|
|
// uncertainties of the efficiencies will be propagated.
|
|
|
|
double TailAlpha; // 43 Calibration Alpha value for lower tail
|
|
double UpperTail; // 44 Calibration Tail Parameter for upper tails
|
|
double UpperTailAlpha; // 45 Calibration Tail Alpha for upper tails
|
|
|
|
double RecoilBeta;
|
|
double RecoilDeltaE;
|
|
};
|
|
|
|
struct SpectrumInfo
|
|
{
|
|
QString Station; // string Station Code
|
|
QString Detector; // string Detector Code
|
|
QString Geometry; // string Detector Geometry
|
|
char DataType; // char first letter of message data type
|
|
QString DataTypeLong; // string message data type
|
|
QString SampleType; // string sample type
|
|
char SystemType; // char P/G/B
|
|
QString SRID; // string sample reference id
|
|
QString Qualifier; // string sample qualifier ('FULL'|'PREL')
|
|
QString CollectionStart; // datenum Collection Start Date
|
|
QString CollectionStop; // datenum Collection Stop Date
|
|
double SampleVolume; // double Sampled Air Volume (m^3)
|
|
QString Comment; // string comment (including newlines)
|
|
double Channels; // double number of channels in spectrum
|
|
double ChannelZero; // double flag whether channel zero was truncated
|
|
QString AcquisitionStart; // datenum Acquisition Start date and time
|
|
QString AcquisitionStop; // datenum Acquisition Stop date and time
|
|
double AcquisitionReal; // double Acquisition Real Time (s)
|
|
double AcquisitionLive; // double Acquisition Live Time (s)
|
|
double SampleID; // double sample id
|
|
double Category; // double spectrum category
|
|
QString CalibrationDate; // datenum Date of calibration
|
|
QString MessageFile; // string message filename
|
|
QString ReportFile; // string report filename
|
|
QString AatFile; // string spectrum binary file name
|
|
QStringList AatamiComment; // cellstr aatami comments
|
|
char LoadSource; // char flag for input method
|
|
QString SetupClass; // string setup class for the spectrum
|
|
QString CertificateAssay; // datenum assay date of certificate
|
|
QStringList CertificateNuclides; // cellstr cell string of nuclides
|
|
double CertificateHalflifes; // double corresponding half lifes(days)
|
|
double CertificateActivities; // double corresponding assay act (Bq)
|
|
double CertificateActUncertainties; // double corresponding assay uncert (Bq)
|
|
double CertificateGEnergies; // double corresponding gamma energies (keV)
|
|
double CertificateGIntensities; // double corresponding gamma intensities (%)
|
|
QStringList CertificateDecayModes; // cellstr corresponding decay modes
|
|
double CertificateBEnergies; // double corresponding beta energies (keV)
|
|
double CertificateBIntensities; // double corresponding beta intensities (%)
|
|
};
|
|
|
|
struct PAT
|
|
{
|
|
// NUMERIC:
|
|
double Centroid; // directly read from data
|
|
double CentroidErr; // directly read from data, currently always NaN for internal PATs
|
|
double EnergyPAT; // energy value given in PAT, must be NaN for internal PATs
|
|
double Energy; // EnergyPAT for peaks where EnergyPAT is NaN; for other peaks
|
|
// the value of energy calibration at Centroid is evaluated.
|
|
double EnergyErr; // directly read from data, currently always NaN for internal PATs
|
|
double LineEnergy; // library line energy of the nuclide with which the peak was assoziated.
|
|
double LineEnergyErr; // Line energy error read from PAT
|
|
double FWHM_ChPAT; // PAT value of FWHM value in channels, must not be NaN for internal PATs
|
|
double FWHM_Ch; // FWHM_ChPAT, where this is not NaN; where it is NaN, using FWHM / dE
|
|
double FWHMPAT; // FWHM in energy range read directly from PAT. Always NaN for internal
|
|
double FWHM; // FWHMPAT, where not NaN; where Nan, use dE*FWHM_Ch
|
|
double FWHMErr; // FWHM error estimate, read directly from PAT; currently always NaN for internal PATs
|
|
double FWHMFitted; // FWHM, where FWHMIsFitted, NaN else
|
|
double BWWidthPAT; // Breit-Wigner width for x-rays, in keV, NaN for normal peaks
|
|
double BWWidth; // BWWidthPAT, but 0 where NaN
|
|
double BWWidthChan; // BWWidth in channel units
|
|
double StepRatioPAT; // Step Ratio (Step/NetArea) in PAT, may be NaN
|
|
double StepRatioErr; // Step Ratio error read from PAT, currently always NaN
|
|
double StepRatio; // StepRatioPAT, where not NaN, else using calibration
|
|
double Step; // NetArea * StepRatio
|
|
double StepErr; // NetArea * StepRatioErr
|
|
double ManualTail; // Tailing parameter read from PAT, may be NaN
|
|
double Tail; // ManualTail, where not NaN; where NaN, tail calibration value of energy;
|
|
double TailErr; // Tail uncertainty read from PAT, currently always NaN for internal PATs
|
|
double TailAlpha; // Calibration Alpha value for lower tail
|
|
double UpperTail; // Calibration Tail Parameter for upper tails
|
|
double UpperTailAlpha; // Calibration Tail Alpha for upper tails
|
|
double NetArea; // Net area value read from PAT
|
|
double NetAreaFree; // flag if net area should be free (has not been calculated)
|
|
double AreaErrorPAT; // net area error read from PAT, currently always NaN for internal PATs
|
|
double AreaError; // AreaErrorPAT, where not NaN; where NaN, calculated from NetArea and Baseline area
|
|
double AreaErrorP; // 100*AreaError/NetArea
|
|
double NetAreaCalculated; // net area calculated from reference peaks (counts)
|
|
double NetAreaCalcError; // error of calculated net area (%)
|
|
double NACalcMin; // Calculated Net area, but reference net area substituted by
|
|
// LC for too small peaks (or 1 if LC < 1)
|
|
double NetAreaCalcUTest; // u-test for calculated versus current net area (only
|
|
// reasonable for peaks fitted independently of reference peak).
|
|
double SumPeakArea; // calculated area of summation peak (counts)
|
|
double SumPeakAreaErr; // error of summation peak area (counts)
|
|
double PeakShare; // (SumPeakArea or NetAreaCal) / NetArea
|
|
double Activity; // Nuclide activity, decay corrected to acquisition start (assuming no feeding in
|
|
double EmissionRatePAT; // emission rate, read from PATcurrently always NaN
|
|
double EmissionRate; // currently EmissionRatePAT
|
|
double EmissionRateErr; // emission rate error, read from PAT
|
|
double CCFPAT; // coincidence correction factor read from PAT, currently always NaN
|
|
double CCF; // CCFPAT, if that is not NaN, 1 otherwise
|
|
double CCFErr; // Error of CCF in % of CCF, if NaN in PAT, then 10*abs(1-CCF)
|
|
double MeanBackCount; // mean background count read from PAT; for internal PATs updated whenever baseline changes
|
|
double Sensitivity; // Peak Search sensitivity at finding, read from PAT; may be NaN
|
|
double Significance; // Significance value read from PAT; for internal PATs updated whenever baseline changes
|
|
double SignificanceErr; // significance uncertainty read from PAT, currently NaN for internal PATs
|
|
double LC; // Currie's minimum NetArea for accepting peak
|
|
double LD; // Currie's NetArea that should lead to reliable detection
|
|
double SignedResidual; // Mean signed residual (patBaseVar)
|
|
double UnsignedResidual; // Mean unsigned residual (patBaseVar)
|
|
double MultipletPAT; // multiplet flag (0|1) read from PAT, must be NaN for internal PATs
|
|
double Multiplet; // MultipletPAT, where not NaN; where NaN, calculated from Centroid, NetArea and FWHM_Ch
|
|
double dE; // Energy Slope calculated from Centroid using Energy Calibration;
|
|
// if no energy calibration for that PAT, use current calibration;
|
|
// if no current calibration, return NaN
|
|
double EfficiencyPAT; // efficiency value read from PAT; always NaN for internal PATs
|
|
double Efficiency; // EfficiencyPAT, where not NaN; where NaN, calculated from efficiency calibration of Energy
|
|
double EfficiencyErr; // efficiency uncertainty read from PAT; currently always NaN for internal PATs
|
|
double RefEfficiencyErr; // uncertainty of the efficiency ratio between the peak
|
|
// and it's reference peak. If the value in PAT is NaN, the
|
|
// uncertainties of the efficiencies will be propagated.
|
|
double LineDeviation; // LineEnergy - Energy
|
|
double Res; // Resolution calibration value at Energy
|
|
double Res_Ch; // Res/dE
|
|
double FWHMIsFitted; // boolean whether FWHM comes from aatami fitting, calculated from FitFlags
|
|
double Index; // peak numbers
|
|
double CountsPerSecond; // NetArea/LiveTime
|
|
double appERate; // apparent Emmision Rate CountsPerSecond/Efficiency
|
|
double Yield; // Library Line Yield (1 for 100%)
|
|
double YieldErr; // Library Line Yield Uncertainty
|
|
double HalfLife; // Nuclide half life (days)
|
|
double EffectiveHalflife; // effective nuclide half life (days). For nuclides that are
|
|
// in an equilibrium-decay-chain, this is the halflife of the
|
|
// mother feeding the chain
|
|
double ReferenceID; // Unique ID numbers for reference peaks, NaN otherwise (in PAT)
|
|
double RefPointer; // Pointer to reference peak ID of nuclide assoziated with the
|
|
// peak, calculated from NuclideIntenal and nuclide Structure
|
|
double ReferencePN; // Peak Number of reference peak, if peak has reference peak, NaN otherwise
|
|
double PeakIdentified; // currently flag whether peak bears valid hard identification
|
|
double BranchingRatio; // Branching Ratio between peak and its reference (equilibrium)
|
|
|
|
// Fixed length strings; character array NPeak * l
|
|
char Source; // 1 source flag read from PAT
|
|
QString FitFlags; // 12 fitting flags in format 'ct**na**wt**' read from PAT
|
|
char Spurious; // 1 Spurious flag read from PAT
|
|
char Reviewed; // 1 Reviewed flag read from PAT
|
|
char TailChanged; // 1 Tail changed flag, read from PAT
|
|
char ResChanged; // 1 Resolution calibration changed flag, read from PAT
|
|
char TailFlag; // 1 Flag if ManualTail is NaN or finite
|
|
char MultipletStr; // 1 Flag if Multiplet is 0 or 1 ('.' or 'M')
|
|
char SignificanceFlag; // 1 flag according to Significance
|
|
char NetAreaFlag; // 1 where net area comes from
|
|
|
|
// Variable lengths strings (cell vector)
|
|
QString NuclideSoft; // Soft identification from PAT
|
|
QString NuclideHard; // Hard identification from PAT
|
|
QString NuclideInternal; // normalized name of nuclide
|
|
QString Nuclide; // NuclideHard, probably followed by NuclideSoft
|
|
QString HalfLifeStr; // Nuclide half life as string, with time unit
|
|
QString EffectiveHalflifeStr; // Effective nuclide half life as string, including unit
|
|
};*/
|