AnalysisSystemForRadionucli.../MDC.cpp
2024-06-04 15:27:02 +08:00

372 lines
15 KiB
C++

#include "MDC.h"
#include <QtMath>
#include <QtGlobal>
double CMdc::CalcSqrt(QVector<double>& _data,QVector<double>::size_type _pos)
{
double rData=0.0;
if(_pos < _data.size())
{
rData = _data[_pos]*_data[_pos];
}
return rData;
}
double CMdc::CalcLD(QVector<double>& _data,QVector<double>::size_type _pos)
{
double rData=0.0;
if(_pos < _data.size())
{
rData = _data[_pos]+LD(_data[_pos]);
}
return rData;
}
bool CMdc::MDC(MDCI& _input,global::XeType& _input_Xetype,MDCO& _output)
{
bool bRet=false;
bRet = LC(_input,_input_Xetype,_output.lcPara);
if(!bRet)
{
return false;
}
bRet = MDCFromLC(_input,_input_Xetype,_output);
return bRet;
}
bool CMdc::MDCFromLC(MDCI& _input,global::XeType _input_Xetype,MDCO& _output)
{
const int cts_grpnum = 3; //净计数 3数1组
// const int pos_cts = 0; //净计数偏移
// const int pos_vari = 1; //误差偏移
const int pos_0_vari = 2; //0信号误差偏移
const int factor_grpnum = 1; //感兴趣区浓度计算系数
const int min_cts = 10*cts_grpnum+pos_0_vari;
const int min_factor = 10*factor_grpnum;
//净计数数组大小判断
if(min_cts>=_input.ROI_netcts.size())
{
return false;
}
//感兴趣区浓度计算系数
if(min_factor>=_input.ROI_con_counts_factor.size())
{
return false;
}
//除数为零判断
if(_input.ROI_con_counts_factor[2*factor_grpnum]==0.0 || \
_input.ROI_con_counts_factor[3*factor_grpnum]==0.0 || \
_input.ROI_con_counts_factor[5*factor_grpnum]==0.0 || \
_input.ROI_con_counts_factor[6*factor_grpnum]==0.0 || \
_input.ROI_netcts[3*cts_grpnum+pos_0_vari]==0.0 || \
_input.ROI_netcts[7*cts_grpnum+pos_0_vari]==0.0 || \
_input.ROI_netcts[8*cts_grpnum+pos_0_vari]==0.0 || \
_input.ROI_netcts[9*cts_grpnum+pos_0_vari]==0.0 || \
_input.ROI_netcts[10*cts_grpnum+pos_0_vari]==0.0)
{
return false;
}
//Use ROIs 2
_output.mdcPara.MDC_Xe135 = _output.lcPara.LC_Xe135+global::cst_k*qSqrt(\
CalcLD(_input.ROI_netcts,2*cts_grpnum+pos_0_vari)/CalcSqrt(_input.ROI_con_counts_factor,2*factor_grpnum)\
);
if(qIsNaN(_output.mdcPara.MDC_Xe135))
{
return false;
}
//Use ROIs 5
_output.mdcPara.MDC_Xe131m = _output.lcPara.LC_Xe131m+global::cst_k*qSqrt(\
CalcLD(_input.ROI_netcts,5*cts_grpnum+pos_0_vari)/CalcSqrt(_input.ROI_con_counts_factor,5*factor_grpnum)\
);
//Use ROIs 6
_output.mdcPara.MDC_Xe133m = _output.lcPara.LC_Xe133m+global::cst_k*qSqrt(\
CalcLD(_input.ROI_netcts,6*cts_grpnum+pos_0_vari)/CalcSqrt(_input.ROI_con_counts_factor,6*factor_grpnum)\
);
if(qIsNaN(_output.mdcPara.MDC_Xe133m))
{
return false;
}
switch ( _input_Xetype)
{
case global::none:
{
//Use ROIs 3 4
double temp = (CalcSqrt(_input.ROI_con_counts_factor,3*factor_grpnum)*CalcLD(_input.ROI_netcts,4*cts_grpnum+pos_0_vari)+\
CalcSqrt(_input.ROI_con_counts_factor,4*factor_grpnum)*CalcLD(_input.ROI_netcts,3*cts_grpnum+pos_0_vari));
if(temp == 0.0)
{
return false;
}
_output.mdcPara.MDC_Xe133 = _output.lcPara.LC_Xe133+ global::cst_k*qSqrt(\
(CalcLD(_input.ROI_netcts,3*cts_grpnum+pos_0_vari)* CalcLD(_input.ROI_netcts,4*cts_grpnum+pos_0_vari))/ \
temp\
);
if(qIsNaN(_output.mdcPara.MDC_Xe133))
{
return false;
}
}
break;
case global::_131m:
{
//Use ROIs 3 7 9
//Roi 3
double VD3 = CalcLD(_input.ROI_netcts,3*cts_grpnum+pos_0_vari)/CalcSqrt(_input.ROI_con_counts_factor,3*factor_grpnum);
//Roi 7 9
double temp = (CalcSqrt(_input.ROI_con_counts_factor,7*factor_grpnum)*CalcLD(_input.ROI_netcts,9*cts_grpnum+pos_0_vari)+\
CalcSqrt(_input.ROI_con_counts_factor,9*factor_grpnum)*CalcLD(_input.ROI_netcts,7*cts_grpnum+pos_0_vari));
if(temp == 0.0)
{
return false;
}
double VD79 = (\
(CalcLD(_input.ROI_netcts,7*cts_grpnum+pos_0_vari)* CalcLD(_input.ROI_netcts,9*cts_grpnum+pos_0_vari))/ \
temp\
);
//Roi 3 7 9
if(0.0==VD3||0.0==VD79||0==(1/VD3+1/VD79))
{
return false;
}
double VD379 = 1/(1/VD3+1/VD79);
_output.mdcPara.MDC_Xe133 = global::cst_k/qSqrt(\
CalcSqrt(_input.ROI_con_counts_factor,3*factor_grpnum)/_input.ROI_netcts[3*cts_grpnum+pos_0_vari]+\
CalcSqrt(_input.ROI_con_counts_factor,7*factor_grpnum)/_input.ROI_netcts[7*cts_grpnum+pos_0_vari]+\
CalcSqrt(_input.ROI_con_counts_factor,9*factor_grpnum)/_input.ROI_netcts[9*cts_grpnum+pos_0_vari])+\
global::cst_k*qSqrt(VD379);
if(qIsNaN(_output.mdcPara.MDC_Xe133))
{
return false;
}
}
break;
case global::_133m:
{
//Use ROIs 3 8 10
//Roi 3
double VD3 = CalcLD(_input.ROI_netcts,3*cts_grpnum+pos_0_vari)/CalcSqrt(_input.ROI_con_counts_factor,3*factor_grpnum);
//Roi 8 10
double temp = (CalcSqrt(_input.ROI_con_counts_factor,7*factor_grpnum)*CalcLD(_input.ROI_netcts,9*cts_grpnum+pos_0_vari)+\
CalcSqrt(_input.ROI_con_counts_factor,9*factor_grpnum)*CalcLD(_input.ROI_netcts,7*cts_grpnum+pos_0_vari));
if(temp == 0.0)
{
return false;
}
double VD810 =(\
(CalcLD(_input.ROI_netcts,8*cts_grpnum+pos_0_vari)* CalcLD(_input.ROI_netcts,10*cts_grpnum+pos_0_vari))/ \
temp\
);
//Roi 3 8 10
if(0.0==VD3||0.0==VD810||0==(1/VD3+1/VD810))
{
return false;
}
double VD3810 = 1/(1/VD3+1/VD810);
_output.mdcPara.MDC_Xe133 = global::cst_k/qSqrt(\
CalcSqrt(_input.ROI_con_counts_factor,3*factor_grpnum)/_input.ROI_netcts[3*cts_grpnum+pos_0_vari]+\
CalcSqrt(_input.ROI_con_counts_factor,8*factor_grpnum)/_input.ROI_netcts[8*cts_grpnum+pos_0_vari]+\
CalcSqrt(_input.ROI_con_counts_factor,10*factor_grpnum)/_input.ROI_netcts[10*cts_grpnum+pos_0_vari])+\
global::cst_k*qSqrt(VD3810);
if(qIsNaN(_output.mdcPara.MDC_Xe133))
{
return false;
}
}
break;
case global::both:
{
//Use ROIs 3 7 8
//Roi 3
double VD3 =CalcLD(_input.ROI_netcts,3*cts_grpnum+pos_0_vari)/CalcSqrt(_input.ROI_con_counts_factor,3*factor_grpnum);
//Roi 8 10
//Roi 7 8
double VD78 = (\
(CalcLD(_input.ROI_netcts,7*cts_grpnum+pos_0_vari)* CalcLD(_input.ROI_netcts,8*cts_grpnum+pos_0_vari))/ \
(CalcSqrt(_input.ROI_con_counts_factor,7*factor_grpnum)*CalcLD(_input.ROI_netcts,8*cts_grpnum+pos_0_vari)+\
CalcSqrt(_input.ROI_con_counts_factor,8*factor_grpnum)*CalcLD(_input.ROI_netcts,7*cts_grpnum+pos_0_vari))\
);
//Roi 3 7 8
if(0.0==VD3||0.0==VD78||0==(1/VD3+1/VD78))
{
return false;
}
double VD378 = 1/(1/VD3+1/VD78);
_output.mdcPara.MDC_Xe133 = global::cst_k/qSqrt(\
CalcSqrt(_input.ROI_con_counts_factor,3*factor_grpnum)/_input.ROI_netcts[3*cts_grpnum+pos_0_vari]+\
CalcSqrt(_input.ROI_con_counts_factor,7*factor_grpnum)/_input.ROI_netcts[7*cts_grpnum+pos_0_vari]+\
CalcSqrt(_input.ROI_con_counts_factor,8*factor_grpnum)/_input.ROI_netcts[8*cts_grpnum+pos_0_vari])+\
global::cst_k*qSqrt(VD378);
if(qIsNaN(_output.mdcPara.MDC_Xe133))
{
return false;
}
}
break;
default:
break;
}
//计算没有使用,客户需要存储数据库
for(int pos=2;pos<=10;pos++)
{
if((2+3*pos)<_input.ROI_netcts.size() && (pos)<_input.ROI_con_counts_factor.size())
{
if((_input.ROI_con_counts_factor[pos]!=0.0)
&& (_input.ROI_con_counts_factor[pos]*_input.ROI_con_counts_factor[pos] != 0.0))
{
double temp=global::cst_k*qSqrt(_input.ROI_netcts[2+3*pos])/_input.ROI_con_counts_factor[pos]+
global::cst_k*qSqrt((_input.ROI_netcts[2+3*pos]+LD(_input.ROI_netcts[2+3*pos]))/
(_input.ROI_con_counts_factor[pos]*_input.ROI_con_counts_factor[pos]));
if(qIsNaN(temp))
{
return false;
}
_output.mdcPara.MDC.append(temp);
// double temp= global::cst_k*qSqrt(_input.ROI_netcts[2+3*pos]);
// _output.mdcPara.MDC_CTS.append(temp);
}
}
}
return true;
}
double CMdc::LD(const double& _inputa)
{
return global::cst_k*global::cst_k+2*global::cst_k*qSqrt(_inputa);
}
bool CMdc::LC(MDCI& _input,global::XeType _input_Xetype,LCPara& _output)
{
const int cts_grpnum = 3; //净计数 3数1组
// const int pos_cts = 0; //净计数偏移
// const int pos_vari = 1; //误差偏移
const int pos_0_vari = 2; //0信号误差偏移
const int factor_grpnum = 1; //感兴趣区浓度计算系数
const int con_uncer_grpnum = 2; //感兴趣区浓度不平衡度 2数1组
const int pos_con = 0; //浓度偏移
// const int pos_uncer = 1; //不平衡度偏移
const int min_cts = 10*cts_grpnum+pos_0_vari;
const int min_factor = 10*factor_grpnum;
const int min_u = 3*con_uncer_grpnum+pos_con;
//净计数数组大小判断
if(min_cts>=_input.ROI_netcts.size())
{
return false;
}
//感兴趣区浓度计算系数
if(min_factor>=_input.ROI_con_counts_factor.size())
{
return false;
}
//感兴趣区浓度不平衡度
if(min_u>=_input.ROI_con_uncer.size())
{
return false;
}
//除数为零判断
if(_input.ROI_con_counts_factor[2*factor_grpnum]==0.0 ||\
_input.ROI_con_counts_factor[5*factor_grpnum]==0.0 ||\
_input.ROI_con_counts_factor[6*factor_grpnum]==0.0 ||\
_input.ROI_netcts[3*cts_grpnum+pos_0_vari]==0.0 ||\
_input.ROI_netcts[4*cts_grpnum+pos_0_vari]==0.0 ||\
_input.ROI_netcts[7*cts_grpnum+pos_0_vari]==0.0 ||\
_input.ROI_netcts[8*cts_grpnum+pos_0_vari]==0.0 ||\
_input.ROI_netcts[9*cts_grpnum+pos_0_vari]==0.0 ||\
_input.ROI_netcts[10*cts_grpnum+pos_0_vari]==0.0)
{
return false;
}
//Use ROIs 2
_output.LC_Xe135 = global::cst_k*qSqrt(_input.ROI_netcts[2*cts_grpnum+pos_0_vari])/_input.ROI_con_counts_factor[2*factor_grpnum];
if(qIsNaN( _output.LC_Xe135))
{
return false;
}
//Use ROIs 5
_output.LC_Xe131m = global::cst_k*qSqrt(_input.ROI_netcts[5*cts_grpnum+pos_0_vari])/_input.ROI_con_counts_factor[5*factor_grpnum];
if(qIsNaN( _output.LC_Xe131m))
{
return false;
}
//Use ROIs 6
_output.LC_Xe133m = global::cst_k*qSqrt(_input.ROI_netcts[6*cts_grpnum+pos_0_vari])/_input.ROI_con_counts_factor[6*factor_grpnum];
if(qIsNaN( _output.LC_Xe133m))
{
return false;
}
switch (_input_Xetype)
{
case global::none:
// Use ROIs 3 4
_output.LC_Xe133 =global::cst_k/qSqrt(\
(_input.ROI_con_counts_factor[3*factor_grpnum]*_input.ROI_con_counts_factor[3*factor_grpnum])/_input.ROI_netcts[3*cts_grpnum+pos_0_vari]+ \
( _input.ROI_con_counts_factor[4*factor_grpnum]*_input.ROI_con_counts_factor[4*factor_grpnum])/_input.ROI_netcts[4*cts_grpnum+pos_0_vari] \
);
if(qIsNaN( _output.LC_Xe133))
{
return false;
}
break;
case global::_131m:
// Use ROIs 3 7 9
_output.LC_Xe133 = global::cst_k/qSqrt(\
(_input.ROI_con_uncer[3*con_uncer_grpnum+pos_con]*_input.ROI_con_uncer[3*con_uncer_grpnum+pos_con])/_input.ROI_netcts[3*cts_grpnum+pos_0_vari]+ \
(_input.ROI_con_counts_factor[7*factor_grpnum]*_input.ROI_con_counts_factor[7*factor_grpnum])/_input.ROI_netcts[7*cts_grpnum+pos_0_vari]+ \
( _input.ROI_con_counts_factor[9*factor_grpnum]*_input.ROI_con_counts_factor[9*factor_grpnum])/_input.ROI_netcts[9*cts_grpnum+pos_0_vari] \
);
if(qIsNaN( _output.LC_Xe133))
{
return false;
}
break;
case global::_133m:
//# Use ROIs 3 8 10
_output.LC_Xe133 = global::cst_k/qSqrt(\
(_input.ROI_con_counts_factor[3*factor_grpnum]*_input.ROI_con_counts_factor[3*factor_grpnum])/_input.ROI_netcts[3*cts_grpnum+pos_0_vari]+ \
(_input.ROI_con_counts_factor[8*factor_grpnum]*_input.ROI_con_counts_factor[8*factor_grpnum])/_input.ROI_netcts[8*cts_grpnum+pos_0_vari]+ \
( _input.ROI_con_counts_factor[10*factor_grpnum]*_input.ROI_con_counts_factor[10*factor_grpnum])/_input.ROI_netcts[10*cts_grpnum+pos_0_vari] \
);
if(qIsNaN( _output.LC_Xe133))
{
return false;
}
break;
case global::both:
//# Use ROIs 3 7 8
_output.LC_Xe133 = global::cst_k/qSqrt(\
(_input.ROI_con_counts_factor[3*factor_grpnum]*_input.ROI_con_counts_factor[3*factor_grpnum])/_input.ROI_netcts[3*cts_grpnum+pos_0_vari]+ \
(_input.ROI_con_counts_factor[7*factor_grpnum]*_input.ROI_con_counts_factor[7*factor_grpnum])/_input.ROI_netcts[7*cts_grpnum+pos_0_vari]+ \
( _input.ROI_con_counts_factor[8*factor_grpnum]*_input.ROI_con_counts_factor[8*factor_grpnum])/_input.ROI_netcts[8*cts_grpnum+pos_0_vari] \
);
if(qIsNaN( _output.LC_Xe133))
{
return false;
}
break;
default:
break;
}
//计算没有使用,客户需要存储数据库
for(int pos=2;pos<=10;pos++)
{
if((2+3*pos)<_input.ROI_netcts.size() && (2*pos)<_input.ROI_con_uncer.size())
{
if(_input.ROI_con_uncer[2*pos]!=0.0)
{
double temp = global::cst_k*qSqrt(_input.ROI_netcts[2+3*pos])/(_input.ROI_netcts[3*pos]/_input.ROI_con_uncer[2*pos]);
_output.LC.append(temp);
temp= global::cst_k*qSqrt(_input.ROI_netcts[2+3*pos]);
if(qIsNaN(temp))
{
return false;
}
_output.LC_CTS.append(temp);
}
}
}
return true;
}