AnalysisSystemForRadionucli.../ROI.cpp

282 lines
9.2 KiB
C++
Raw Normal View History

2024-06-04 15:27:02 +08:00
#include "ROI.h"
#include "ProcessAlgorithmGlobalVar.h"
#include <QtMath>
bool CROI::CalcNetCounts(NetCountsI& _net_counts,QVector<double>& _output)
{
//计算同位素系数
bool bRet=false;
double F135;
double F133;
double F131m;
double F133m;
bRet = CalcF(_net_counts.time,global::cst_d_decay_135xeg_lam,F135);
if(!bRet)
{
return false;
}
bRet = CalcF(_net_counts.time,global::cst_d_decay_133xeg_lam,F133);
if(!bRet)
{
return false;
}
bRet = CalcF(_net_counts.time,global::cst_d_decay_131xem_lam,F131m);
if(!bRet)
{
return false;
}
bRet = CalcF(_net_counts.time,global::cst_d_decay_133xem_lam,F133m);
if(!bRet)
{
return false;
}
QVector<double> factor;
factor.append(F135);
factor.append(F133);
factor.append(F133);
factor.append(F131m);
factor.append(F133m);
factor.append(F133);
//通过系数计算净计数总数
bRet = CalcNetCountsByFactor(_net_counts,factor,_output);
if(!bRet)
{
return false;
}
return true;
}
bool CROI::CalcF(SGTime& _time,double _Xe,double& _output)
{
double drData = 1-qExp(-_Xe*_time.g_acquisition_real_time);
if(!_time.g_acquisition_live_time || !_time.s_acquisition_real_time || !drData)
{
return false;
}
else
{
drData = (_time.g_acquisition_real_time/_time.g_acquisition_live_time)*(_time.s_acquisition_live_time/_time.s_acquisition_real_time)*qExp(-_Xe*_time.gtos_acqStartDiff)* \
(1-qExp(-_Xe*_time.s_acquisition_real_time))/drData;
}
_output = drData;
return true;
}
bool CROI::CalcNetCountsByFactor(NetCountsI& _net_counts,QVector<double>& _factor,QVector<double>& _output)
{
QVector<double>::size_type size = _net_counts.g_netXe.size();
//参数传入判断
if(size!=_net_counts.s_netXe.size())
{
return false;
}
QVector<double> rData(size,0);
bool bPara1 = true;//默认为一行一个参数
QVector<double>::size_type bParaPos = 6; //系数起始位 此处理函数没有用到前六个系数
if(size>_factor.size()) //系数个数判断
{
bPara1 = false;
bParaPos = 0;
}
//提取数据
double factor = 1.0;
const int detuct_grpnm = 3;
const int pos_cts = 0; //扣除 计数偏移
const int pos_vari = 1; //偏差偏移
const int pos_level = 2; //关键水平偏移
const int pos_net_counts=0;//输出净计数 偏移值
const int pos_net_counts_vari=1; //净计数偏差 偏移值
const int pos_net_counts_0_vari=2; //净计数 0 信号偏移值
for(QVector<double>::size_type pos=2*detuct_grpnm;pos+pos_level<size;pos+=detuct_grpnm)
{
if(bParaPos<_factor.size())
{
factor = _factor.at(bParaPos);
if(bPara1)
{
bParaPos+=3;
}
else
{
bParaPos+=1;
}
}//获取系数
else
{
//系数等于上次系数
}
rData[pos+pos_net_counts] = _net_counts.s_netXe[pos+pos_cts] - factor*_net_counts.g_netXe[pos+pos_cts];
rData[pos+pos_net_counts_vari] = _net_counts.s_netXe[pos+pos_vari] + factor*factor*_net_counts.g_netXe[pos+pos_vari];
rData[pos+pos_net_counts_0_vari] = rData[pos+pos_vari] - qAbs(rData[pos+pos_cts]);
}
_output = rData;
return true;
}
bool CROI::CalcNetXects(NetXectsI& _input,QVector<double>& _output)
{
const int group_num = 3; //每组个数为3
const int pos_cts = 0; //净计数位置
const int pos_variance = 1; //误差位置
const int pos_level =2; //关键水平位置
const int pos_one_ratios =-1; //比率第一组相对下标值
const int pos_two_ratios =6; //比率第二组相对下标值
QVector<double> rData(group_num,0);
QVector<double>::size_type size = _input.roi_cts.size();
//大小判断
if(size-1+pos_two_ratios>=_input.roi_ratios.size()||size>_input.roi_detbg_cts.size())
{
return false;
}
// QVector<double>::size_type pos = 0;
double dKTemp;
double dVTemp;
double dLTemp;
double dKtempFactor=0.0;
double dVTempFactor=0.0;
for(QVector<double>::size_type pos=0;pos<size;pos++)
{
dKtempFactor=0.0;
dVTempFactor=0.0;
if(0 == pos) //第零组不做处理
{
//
}
else
{
if(rData.at(1*group_num+pos_cts)>rData.at(1*group_num+pos_level))
{
if(pos>=3)//第三组以后
{
double qvctRatiosData1 = _input.roi_ratios.at(pos+pos_one_ratios);
double qvctRatiosData2 = _input.roi_ratios.at(pos+pos_two_ratios);
if(rData.at(3*group_num+pos_cts)>rData.at(3*group_num+pos_level))//第三组k 大于第三组lk
{
dKtempFactor = -(qvctRatiosData1*rData.at(1*group_num+pos_cts) + qvctRatiosData2*rData.at(3*group_num+pos_cts));
dVTempFactor = qvctRatiosData1*qvctRatiosData1*rData.at(1*group_num+pos_variance)+qvctRatiosData2*qvctRatiosData2*rData.at(3*group_num+pos_variance);
}
else
{
dKtempFactor = -(qvctRatiosData1*rData.at(1*group_num+pos_cts));
dVTempFactor = qvctRatiosData1*qvctRatiosData1*rData.at(1*group_num+pos_variance);
}
}
else // 1 2 组处理
{
double qvctRatiosData = _input.roi_ratios.at(pos+pos_one_ratios);
dKtempFactor = -(qvctRatiosData*rData.at(1*group_num+pos_cts));
dVTempFactor = qvctRatiosData*qvctRatiosData*rData.at(1*group_num+pos_variance);
}
}
else
{
if(pos>=3)//第三组以后
{
double qvctRatiosData2 = _input.roi_ratios.at(pos+pos_two_ratios);
if(rData.at(3*group_num+pos_cts)>rData.at(3*group_num+pos_level))//第三组k 大于第三组lk
{
dKtempFactor = -(qvctRatiosData2*rData.at(3*group_num+pos_cts));
dVTempFactor = qvctRatiosData2*qvctRatiosData2*rData.at(3*group_num+pos_variance);
}
else
{
//没有系数
}
}
else// 1 2 组处理
{
//没有系数
}
}
}
//净计数
dKTemp = _input.roi_cts.at(pos)-_input.ratio*_input.roi_detbg_cts.at(pos)+dKtempFactor;
//不确定度
dVTemp = _input.roi_cts.at(pos)+_input.ratio*_input.ratio*_input.roi_detbg_cts.at(pos)+dVTempFactor;
//关键水平
if((dVTemp-dKTemp)<0)
{
return false;
}
dLTemp = global::cst_k*qSqrt(dVTemp-dKTemp);
rData.append(dKTemp);
rData.append(dVTemp);
rData.append(dLTemp);
}
_output = rData;
return true;
}
bool CROI::ExtractROIcts(ROIctsI& _input,ROIctsO& _output)
{
bool bRet = false;
//获取总计数
bRet = CalcROIctsByBoundary(_input.roi_boundary,_input.histogram,_output.roi_cts);
if(!bRet)
{
return false;
}
return true;
}
bool CROI::CalcROIctsByBoundary(ROIBoundary& _boundary,Histogram& _histogram,QVector<double>& _output)
{
//10个通道数据
QVector<double> qdDataTemp(10,0);
QString qsDataTemp;
//参数判断
if(_boundary.ROI_B_start_x.size()<10||\
_boundary.ROI_B_stop_x.size()<10||\
_boundary.ROI_G_start_y.size()<10||\
_boundary.ROI_G_stop_y.size()<10)
{
return false;
}
for(int roi=0;roi<10;roi++) //提取
{
qdDataTemp[roi] = 0;
QVector<int>::size_type base = 0;
// int row = 0;
int y=0;
for(;y<_boundary.ROI_G_start_y[roi];y++)
{
//row
}
base = y;
// QVector<int>::size_type y=_boundary.ROI_G_start_y[roi]-1;
// base = y+1;
for(y=0;y<(_boundary.ROI_G_stop_y[roi]-_boundary.ROI_G_start_y[roi]+1);y++)
{
for(QVector<int>::size_type x=_boundary.ROI_B_start_x[roi];x<=_boundary.ROI_B_stop_x[roi];x++)
{
if((base+y)*_histogram.b_channels+x<_histogram.counts.size()&&((base+y)*_histogram.b_channels+x)>=0)
{
qdDataTemp[roi] += _histogram.counts.at((base+y)*_histogram.b_channels+x);
}
else
{
return false;
}
}
}
}
_output = qdDataTemp;
return true;
}
bool CROI::CalcLimitToBoundary(QVector<double>& _ROI_limit,QVector<double>& _cal_coeffs,QVector<int>& _output)
{
_output.clear();
if(_cal_coeffs.size()<3||_ROI_limit.size()<0) //刻度系数大小错误 或 限制数据不存在
{
return false;
}
int dataTemp = 0;
for(QVector<double>::size_type pos=0;pos<_ROI_limit.size();pos++)
{
dataTemp = int(_cal_coeffs[0]+_cal_coeffs[1]*_ROI_limit[pos]+_cal_coeffs[2]*_ROI_limit[pos]*_ROI_limit[pos]+0.5);
_output.append(dataTemp);
}
return true;
}