AnalysisSystemForRadionucli.../GammaAnalyAlgLib.h

575 lines
15 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef GAMMAANALYALGLIB_H
#define GAMMAANALYALGLIB_H
#include <QtCore/qglobal.h>
#include <QString>
#include "RadionuclideMessage.h"
#include <QDateTime>
#if defined(GAMMAANALYALG_LIBRARY)
#define GAMMAANALYALGSHARED_EXPORT Q_DECL_EXPORT
#else
#define GAMMAANALYALGSHARED_EXPORT Q_DECL_IMPORT
#endif
//#ifdef Q_OS_WIN
// #define gNaN (_nan())
//#else
#define gNaN (qQNaN())
//#endif
#ifdef Q_OS_WIN
#define LINE_END QLatin1String("\r\n")
#else
#define LINE_END QLatin1String("\n")
#endif
// QC 检查项的名称,与配置文件 SystemManager.xml 对应
#define QC_COL_TIME QLatin1String("col_time")
#define QC_ACQ_TIME QLatin1String("acq_time")
#define QC_DECAY_TIME QLatin1String("decay_time")
#define QC_SAMP_VOL QLatin1String("samp_vol")
#define QC_AIR_FLOW QLatin1String("airFlow")
#define QC_Be7_FWHM QLatin1String("Be7-FWHM")
#define QC_Ba140_MDC QLatin1String("Ba140-MDC")
#define QC_Xe133_MDC QLatin1String("Xe133-MDC")
#define NUCL_IDENT_VALUE1 0.8 // 核素识别中核素被认证标准值1 sum_found/sum_total>0.8 直接被认证
#define NUCL_IDENT_VALUE2 0.5 // 核素识别中核素被认证标准值2 0.5<sum_found/sum_total<=0.8 需进一步认证
#define DETECTOR_EFFICIENCY_ERROR_RATIO 0.01 // 探测器效率误差相对值
// 刻度数据名称
#define CalPHD QLatin1String("PHD")
#define CalUpdate1 QLatin1String("CalUpdate1")
#define CalUpdate2 QLatin1String("CalUpdate2")
#define CalResUpdate QLatin1String("CalResUpdate")
#define CalInput QLatin1String("Input")
#define WRITE_LC QLatin1String("Lc")
#define WRITE_SCAC QLatin1String("Scac")
using namespace RadionuclideData;
typedef std::vector<double> stdvec;
typedef std::vector< std::vector<double> > stdvec2;
enum AnalyseState
{
AS_Null,
AS_CalibFitted,
AS_PeakSearched,
AS_BaseImproved,
AS_NetAreaFitted
};
enum PeakInsertMethod
{
Ins_Manual,
Ins_H0Test,
Ins_MultFit,
Ins_SumPeakModel
};
enum PeakIndex {
i_Centroid = 0,
i_CentroidErr,//无效
i_Energy,
i_EnergyErr,//无效
i_FWHM_Ch,
i_FWHM, // = 5
i_FWHMErr,//无效
i_StepRatioErr,//无效
i_StepRatio,
i_Tail,
i_TailErr, // = 10 无效
i_NetArea,
i_AreaError,
i_MeanBackCount,
i_Sensitivity,
i_Significance, // = 15
i_SignificanceErr,//无效
i_Multiplet,
i_Efficiency,
i_EfficiencyErr,
i_BWWidth, // = 20
i_BWWidthErr,//无效
i_EmissionRate,
i_EmissionRateErr,//无效
i_CCF,
i_CCFErr, // = 25
i_LineEnergy,
i_LineEnergyErr,//无效
i_Yield,
i_YieldErr,
i_ReferenceID, // = 30
i_RefPointer,
i_BranchingRatio,
i_LC,
i_LD,
i_SignedResidual, // = 35
i_UnsignedResidual,
i_ResidualUpToDate,
i_SumPeakArea,
i_SumPeakAreaErr,//无效
i_BackgroundArea, // = 40
i_RefEfficiencyErr,
i_TailAlpha,
i_UpperTail,
i_UpperTailAlpha,
i_RecoilBeta, // = 45
i_RecoilDeltaE // = 46
};
enum SpecBaseIdx
{
s_Spectrum = 0, // 0: channel contents
s_BaseLine, // 1: fitted baseline
s_AnalysisRange, // 2: Analysis Range (first and last valid channel)
s_AnalysisRangeSave, // 3: Save Analysis range, i.e. if empty will be [1,NCh]
s_XControl, // 4: baseline control points x-data
s_YControl, // 5: baseline control points y-data
s_YSlope, // 6: slope at breakpoints, NaN at normal control points
s_Residual, // 7: residual (Spectrum-BaseLine-Peaks)
s_Stripped, // 8: stripped spectrum (gaussian peaks substracted)
s_Steps, // 9: non-spline baseline components
s_ROISmooth, // 10: stripped spectrum minus Steps, with smoothened ROIs
s_SmoothStripped, // 11: smoothened stripped spectrum
s_Approximation, // 12: spectrum approximation (baseline + peaks)
s_ChiSquare, // 13: mean weighted residual and number of channels with zero counts ( [ChiSquare, nzero] )
s_ArtXControl, // 14: artificial baseline control points x-data
s_ArtYControl, // 15: artificial baseline control points y-data
s_ArtYSlope, // 16: slope of artificial baseline control points
s_ArtificialBase, // 17: Artificial baseline (if not empty)
s_BaseFittingWeights, // 18: Weight function used in baseline fitting
s_PSS, // 19: value of peak search sensitivity in each channel
s_FwhmcAll,
s_Energy,
s_Lc,
s_Scac
};
enum PeakSearchType
{
search_full,
search_residual
};
enum CalibrationType
{
Cal_Energy = 0,
Cal_Resolution,
Cal_Efficiency,
Cal_Tot_efficiency,
Cal_Tail = 4,
Cal_Tail_alpha = 5,
Cal_Tail_right = 6,
Cal_Tail_right_alpha = 7,
Cal_Step_ratio = 8,
Cal_HalflifeAnalysis = 9,
Cal_Default
};
struct NuclideLines
{
QStringList fullNames; // 核素全名
stdvec vEnergy; // 核素的所有γ射线能量
stdvec vUncertE;
stdvec vYield; // 核素γ射线分支比
stdvec vUncertY;
double halflife;// 单位:秒
int key_flag; // 记录主射线下标
int maxYeildIdx;
NuclideLines()
{
maxYeildIdx = -1;
key_flag = -1;
halflife = 0;
}
~NuclideLines()
{
fullNames.clear();
vEnergy.clear();
vUncertE.clear();
vYield.clear();
vUncertY.clear();
}
};
struct QcCheckItem
{
QString standard;
double value;
bool bPass;
QcCheckItem()
{
bPass = false;
value = 0;
}
};
struct NuclideActMda
{
bool bCalculateMDA;
int calculateIdx;
int key_flag; // 第 key_flag 条射线是主射线,从 0 开始编号, key_flag < 0 表示无主射线
double halflife;
double activity;
double act_err;
double mda;
double mdc;
double efficiency;
double effi_err;
double concentration;
QStringList fullNames;
stdvec vEnergy; // 匹配的γ射线能量
stdvec vUncertE;
stdvec vYield; // 匹配的γ射线分支比
stdvec vUncertY;
QVector<int> vPeakIdx; // 匹配的峰序号, 从 1 开始
NuclideActMda()
{
bCalculateMDA = false;
calculateIdx = -1;
key_flag = -1;
halflife = 0;
activity = 0;
act_err = 0;
mda = 0;
mdc = 0;
efficiency = 0;
effi_err = 0;
concentration = 0;
}
~NuclideActMda()
{
fullNames.clear();
vEnergy.clear();
vUncertE.clear();
vYield.clear();
vUncertY.clear();
vPeakIdx.clear();
}
};
struct BaseCtrlStack
{
stdvec cx;
stdvec cy;
stdvec cdy;
~BaseCtrlStack()
{
cx.clear();
cy.clear();
cdy.clear();
}
};
struct BaseControls
{
bool ReplotUsed;
bool ReplotNeeded;
int rg_low; //分析范围的最小值
int rg_high; //分析范围的最大值
stdvec XCtrl;
stdvec YCtrl;
stdvec YSlope;
stdvec Baseline;
stdvec StepCounts;
QVector<BaseCtrlStack> BaseStack;
//stdvec SlopeHandle;
BaseControls()
{
rg_low = 1;
rg_high = qInf();
ReplotUsed = false;
ReplotNeeded = false;
}
~BaseControls()
{
XCtrl.clear();
YCtrl.clear();
YSlope.clear();
Baseline.clear();
StepCounts.clear();
BaseStack.clear();
}
};
struct SpecSetup
{
/*int SChan; // Begin Channel
int EChan; // End Channel
int Sensity; // Peak Searching Sensitivity
int Level; // Uncertainty Confidence Level
int EDS; // EDS pretreatment
int PDA; // Peak Detection Algorithm
int Method; // peak area compute method
int Iter; // Iterations
float Width; // Energy Window Width
QString MDAType; // MDA Type
QString date; // Activity Reference Time
QString time; // Activity Reference Time*/
//QString CalibrationLinesFile;
double ECutAnalysis_Low;
double ECutAnalysis_High;
double EnergyTolerance;
double CalibrationPSS_high;
double CalibrationPSS_low;
double BaseImprovePSS;
double PSS_low;
double k_back;
double k_alpha;
double k_beta;
double RiskLevelK;
bool bUpdateCal;
bool KeepCalPeakSearchPeaks;
QDateTime refTime_act; //活度参考时间默认是AcqStartTime
QDateTime refTime_conc; //默认是CollectStartTime
SpecSetup()
{
//ECutAnalysis_Low = 35;//SystemType = "P"
ECutAnalysis_Low = 12.0; //SystemType = "G"
ECutAnalysis_High = qInf();
EnergyTolerance = 0.5;
CalibrationPSS_high = 10.0;
CalibrationPSS_low = 5.0;
BaseImprovePSS = 10.0;
PSS_low = 2.7;
k_back = 1.25;
k_alpha = 2.576;
k_beta = 1.645;
RiskLevelK = 4.264890;
bUpdateCal = false; //SystemType = "G"
//bUpdateCal = true;//SystemType = "P"
KeepCalPeakSearchPeaks = false;
//CalibrationLinesFile = "/setup/ene_cal_update.txt";
}
};
struct PeakInfo
{
int index; //峰序号
int multiIndex; //重峰序号
int left; //峰的左边界
int right; //峰的右边界
double peakCentroid; //峰拟合后加权峰中心道
double energy;
double fwhmc; //半高宽
double fwhm; //以keV为单位的半高宽
double area; //净面积
double areaErr; //
double efficiency;
double lc;
double ld;
double meanBackCount;
double backgroundArea;
double significance;
double sensitivity;
double stepRatio;
double tail;
double tailAlpha;
double upperTail;
double upperTailAlpha;
double BWWidthChan;
double recoilBetaChan;
double recoilDeltaChan;
QString comments;
QStringList nuclides;
/*int num_peaks; //重峰个数
int no_peaks; //重峰中的序号
double Peaklocation;//加权峰中心道matlab算法得到
double fwhmc_temp;//峰的半高宽估计值
double p[5];
double v[8];//v[6] i0; v[3] l; v[4] h; v[7] w; v[5] H0
double baseline_left;//峰的左端基线值(计数)
double baseline_right;//峰的右端基线值(计数)
double area_base;//基底面积
double detectability;//峰可探测度
double PeakAreaErr;
double unCern;
int isFit; //拟合标识
int PeakLeft;//峰左边界matlab算法得到
int PeakRight;//峰右边界matlab算法得到
int peakChannel;//峰的道数
PeakCoeff coeff;*/
};
struct ParameterInfo
{
stdvec p;
stdvec perr;
~ParameterInfo()
{
p.clear();
perr.clear();
}
};
class PHDFile
{
public:
PHDFile()
{
bAnalyed = false;
isValid = true;
filename = "";
filepath = "";
totalCmt = "";
id_sample = "";
id_analysis = "";
status = "";
category = "";
process.sample_volume_of_Xe = -1;
sampleBlock.dimension_1 = 0;
sampleBlock.dimension_2 = 0;
newEner = CalPHD;
newReso = CalPHD;
newEffi = CalPHD;
newTotE = CalPHD;
stdvec t_vec(4, 0.0);
t_vec[0] = 99;
para_tail.p = t_vec;
stdvec t_vec2(2, 98.0);
t_vec2[1] = 1;
para_tailAlpha.p = t_vec2;
para_tailRightAlpha.p = t_vec2;
t_vec2[1] = 0.35;
para_tailRight.p = t_vec2;
t_vec2[1] = 0;
para_stepRatio.p = t_vec2;
}
~PHDFile()
{
vPeak.clear();
vEnergy.clear();
vBase.clear();
vLc.clear();
vScac.clear();
mapEnerKD.clear();
mapResoKD.clear();
mapEffiKD.clear();
mapTotEKD.clear();
mapEnerPara.clear();
mapResoPara.clear();
mapEffiPara.clear();
mapTotEPara.clear();
QcItems.clear();
mapNucActMda.clear();
}
bool isValid; // 是否有效谱
bool bAnalyed; // 记录是否被分析
QString analy_start_time;
QString filename; // 谱文件名称
QString filepath; // 谱文件路径
QString log_path;
QString report_path;
QString baseline_path;
QString lc_path;
QString scac_path;
QString totalCmt; // 谱文件总注释
QString oriTotalCmt;// 原始谱总注释
SpecSetup usedSetting; // 当前使用的分析设置
SpecSetup setting; // 新修改的分析设置
// 分析结果
std::vector<PeakInfo> vPeak;
stdvec vEnergy;
stdvec vBase;
stdvec vLc;
stdvec vScac;
//stdvec vFwhm;
//stdvec vFwhmc;
BaseControls baseCtrls;
// 当前修改的刻度名称
QString newEner;
QString newReso;
QString newEffi;
QString newTotE;
// 当前寻峰结果所用的刻度名称
QString usedEner;
QString usedReso;
QString usedEffi;
QString usedTotE;
// 当前寻峰结果所用的刻度数据
G_EnergyBlock usedEnerKD;
G_ResolutionBlock usedResoKD;
G_EfficiencyBlock usedEffiKD;
TotaleffBlock usedTotEKD;
// 存储所有的刻度数据
QMap<QString, G_EnergyBlock> mapEnerKD; // 能量刻度
QMap<QString, G_ResolutionBlock> mapResoKD; // 分辨率刻度
QMap<QString, G_EfficiencyBlock> mapEffiKD; // 效率刻度
QMap<QString, n_G_EfficiencyBlock> nMapEffiKD; // 效率刻度
QMap<QString, TotaleffBlock> mapTotEKD; // 总效率刻度
//bate刻度数据
QMap<QString, BG_EfficiencyBlock> mapbgEffiKD; // 效率刻度
QMap<QString, NBG_EfficiencyBlock> nMapbgEffiKD; // 效率刻度
// 当前寻峰结果所用的刻度参数
ParameterInfo usedEnerPara;
ParameterInfo usedResoPara;
ParameterInfo usedEffiPara;
ParameterInfo usedTotEPara;
// 存储所有的刻度参数
QMap<QString, ParameterInfo> mapEnerPara;
QMap<QString, ParameterInfo> mapResoPara;
QMap<QString, ParameterInfo> mapEffiPara;
QMap<QString, ParameterInfo> mapTotEPara;
// 其他参数,目前存储的是默认值
ParameterInfo para_stepRatio;
ParameterInfo para_tail;
ParameterInfo para_tailAlpha;
ParameterInfo para_tailRight;
ParameterInfo para_tailRightAlpha;
//自衰减
BSelfAttenuationBlock bSelfAttenuation;
// 谱基本信息
QString id_sample;
QString id_analysis;
QString status;
QString category;
HeaderBlock header;
MessageInfo msgInfo;
G_SpectrumBlock Spec;
AcquisitionBlock acq;
CollectionBlock collect;
ProcessingBlock process;
CalibrationBlock calibration;
SampleBlock sampleBlock;
CertificateBlock certificate;
// QC Check
QMap<QString, QcCheckItem> QcItems;
// 核素活度浓度
QMap<QString, NuclideActMda> mapNucActMda;
};
#endif // GAMMAANALYALGLIB_H