diff --git a/GammaAnalyALG.cpp b/GammaAnalyALG.cpp index 6bdbf38..28a46c5 100644 --- a/GammaAnalyALG.cpp +++ b/GammaAnalyALG.cpp @@ -1990,18 +1990,17 @@ bool GammaAnalyALG::Process(bool bUpdate, QChar dataType, vec certEne) qDebug() << "The counts of spectrum are all zero!"; return false; } - callGammaProcess(0); stdvec vy; vy = getBaseInfo(s_YControl); - /* **********************************刻度更新*********************************************** */ if(bUpdate) { calUpdate(dataType, certEne, true, true, true); callGammaProcess(1); } + vy = getBaseInfo(s_YControl); /* **********************************寻峰*********************************************** */ PeakSearch(); @@ -2022,7 +2021,6 @@ bool GammaAnalyALG::Process(bool bUpdate, QChar dataType, vec certEne) fitPeakFull(idx, ep, ep, ep); vy = getBaseInfo(s_YControl); callGammaProcess(4); - baseInfo(s_Energy) = calValues(Cal_Energy, RangeVec2(1, m_nChans)); baseInfo(s_FwhmcAll) = GetFwhmcAll(); baseInfo(s_Lc) = calculateLC(baseInfo(s_BaseLine), baseInfo(s_FwhmcAll), specSetup.RiskLevelK); @@ -2034,7 +2032,6 @@ bool GammaAnalyALG::Process(bool bUpdate, QChar dataType, vec certEne) ////("____na_cy.txt", baseInfo(s_YControl)); ////("____na_cdy.txt", baseInfo(s_YSlope)); ////("____na_steps.txt", baseInfo(s_Steps));*/ - return true; } @@ -2077,6 +2074,7 @@ bool GammaAnalyALG::AnalyseSpectrum(PHDFile *phd, QMap ma QStringList names; names << phd->newEner << phd->newReso; bool bUpdate = false; + if(phd->bAnalyed) { SetCalPara(names, phd->mapEnerPara[ names[0] ], phd->mapResoPara[ names[1] ], phd->mapEffiPara[phd->newEffi], phd->mapTotEPara[phd->newTotE]); @@ -2458,10 +2456,8 @@ void GammaAnalyALG::SetCalData(QStringList names, G_EnergyBlock EnerKD, G_Resolu qDebug() << "The parameter names must has at least 2 element in GammaAnalyALG::SetCalData."; return; } - m_curEner = names[0]; m_curReso = names[1]; - if(EnerKD.record_count > 0) { mat calDatas(EnerKD.record_count, 3); @@ -2509,7 +2505,6 @@ void GammaAnalyALG::SetCalData(QStringList names, G_EnergyBlock EnerKD, G_Resolu Acal_tot_efficiency_para = FitCalPara(Cal_Tot_efficiency, Cal_Tot_Effi_Data); //Acal_tot_efficiency_para.print("Acal_tot_efficiency_para = "); } - /*QString name; setCalibrationData(name, Cal_Energy, "PHD", tmpEner); setCalibrationData(name, Cal_Resolution, "PHD", QVec2ToMat(ResoKD)); @@ -3352,7 +3347,6 @@ void GammaAnalyALG::patBaseVar(colvec &sqi, colvec &uqi, uvec idx, int updr) double k = specSetup.k_back; double k_alpha = specSetup.k_alpha; double k_beta = specSetup.k_beta; - // get baseline and peak parameters field t_f1; if(updr) @@ -3367,6 +3361,7 @@ void GammaAnalyALG::patBaseVar(colvec &sqi, colvec &uqi, uvec idx, int updr) } else { t_f1 = dmspec(QStringList("BaseLine")); //BL = dmspec(sn, 'BaseLine'); + /* -------------------------------打印输出 ---------------------------------- */ //("patBaseVar_BaseLine.txt", t_f1(0)); } @@ -3375,7 +3370,6 @@ void GammaAnalyALG::patBaseVar(colvec &sqi, colvec &uqi, uvec idx, int updr) QStringList dmpsItems; dmpsItems << "Centroid" << "FWHM_Ch" << "NetArea" << "SigmaCh"; field t_f2 = dmps(dmpsItems); - /* // modify all peaks, if idx is string if isstr(idx) idx = [1 : length(Ct)]; @@ -3385,7 +3379,6 @@ void GammaAnalyALG::patBaseVar(colvec &sqi, colvec &uqi, uvec idx, int updr) { idx = vectorise( RangeVec(0, t_f2(0).size()-1) ); } - vec MBC, LC, LD, BC; if(t_f1(0).is_empty()) //if isempty(BL) { @@ -3404,17 +3397,14 @@ void GammaAnalyALG::patBaseVar(colvec &sqi, colvec &uqi, uvec idx, int updr) t_f2(1) = t_f2(1)(idx); //Fc = Fc(idx); t_f2(2) = t_f2(2)(idx); //NA = NA(idx); t_f2(3) = t_f2(3)(idx); //Sc = Sc(idx); - vec W = 2 * k * t_f2(1); //W = 2 * k * Fc; /* -------------------------------打印输出 ---------------------------------- */ // total background counts from Ct +- k*Fc - rowvec tmp1 = max(0, t_f1(0)); BC = Independ::abkcnt( tmp1, t_f2(0), t_f2(1), k); //BC = abkcnt(max(BL, 0), Ct, Fc, k); /* -------------------------------打印输出 ---------------------------------- */ - // Mean Back Counts MBC = BC / W; /* -------------------------------打印输出 ---------------------------------- */ @@ -3433,7 +3423,6 @@ void GammaAnalyALG::patBaseVar(colvec &sqi, colvec &uqi, uvec idx, int updr) vec DA = c*f*sqrt(t_f2(3) % MBC); //DA = c*f*sqrt(Sc .* MBC); /* -------------------------------打印输出 ---------------------------------- */ //("patBaseVar_DA.txt", DA); - // Currie's LC LC = k_alpha * DA; @@ -3444,7 +3433,6 @@ void GammaAnalyALG::patBaseVar(colvec &sqi, colvec &uqi, uvec idx, int updr) LD = LC + (kb2/2) * ( 1 + sqrt(1 + (4/kb2)*( LC+pow(DA,2) ) ) ); /* -------------------------------打印输出 ---------------------------------- */ //("patBaseVar_LD.txt", LD); - if(updr) { // total counts @@ -5596,7 +5584,6 @@ void GammaAnalyALG::calUpdate(QChar dataType, vec certEne, bool E1, bool R, bool // if true, peaks found in peak search will be kept //write_peaks_to_pat = getSpecSetup(sn, 'KeepCalPeakSearchPeaks'); bool write_peaks_to_pat = specSetup.KeepCalPeakSearchPeaks; - // for calibration spectra, use energies from certificate instead of setup file //[dataType, certEne] = dminfo(sn, 'DataType', 'CertificateGEnergies'); vec ELibEne, ELibRes; @@ -5648,7 +5635,6 @@ void GammaAnalyALG::calUpdate(QChar dataType, vec certEne, bool E1, bool R, bool return; } } - ////("calUpdate_ELibEne.txt", ELibEne); ////("calUpdate_ELibRes.txt", ELibRes); @@ -5659,7 +5645,6 @@ void GammaAnalyALG::calUpdate(QChar dataType, vec certEne, bool E1, bool R, bool uvec ene1PIdx = calPeakSearch(ELibEne1, ELibEne); calEnergyUpdate1(ene1PIdx, ELibEne1); } - if(R) { // update resolution calibration @@ -5667,7 +5652,6 @@ void GammaAnalyALG::calUpdate(QChar dataType, vec certEne, bool E1, bool R, bool uvec resPIdx = calPeakSearch(ELibRes1, ELibRes); calResUpdate(resPIdx); } - if(E2) { // second energy calibration update @@ -5675,7 +5659,6 @@ void GammaAnalyALG::calUpdate(QChar dataType, vec certEne, bool E1, bool R, bool uvec ene2PIdx = calPeakSearch(ELibEne2, ELibEne); calEnergyUpdate2(ene2PIdx, ELibEne2); } - // keep changes (quickfit) in PAT, if requested if(write_peaks_to_pat) { @@ -5696,7 +5679,6 @@ void GammaAnalyALG::calUpdate(QChar dataType, vec certEne, bool E1, bool R, bool baseInfo(s_YSlope).clear(); baseInfo(s_AnalysisRange).clear(); } - } uvec GammaAnalyALG::calPeakSearch(vec &EF, vec ELib) @@ -5920,7 +5902,6 @@ void GammaAnalyALG::calEnergyUpdate2(uvec idx, vec ELib) { uword NPeaks = idx.size(); vec C = zeros(NPeaks); - // fit peaks vec ret1, ret2, ret3; uvec tmp; @@ -5936,7 +5917,6 @@ void GammaAnalyALG::calEnergyUpdate2(uvec idx, vec ELib) C(i) = as_scalar(ret2); } //C.print("C = "); - // fit new centroids to library energies vec p, perr; s = Independ::calFitPara(p, perr, Cal_Energy, C, ELib); @@ -5952,15 +5932,12 @@ void GammaAnalyALG::calEnergyUpdate2(uvec idx, vec ELib) { vec F02 = Independ::calFcnEval(C, Acal_energy_para[m_curEner](0)); double sum02 = sum(pow(F02 - ELib, 2)) / C.size(); - vec F2 = Independ::calFcnEval(C, p); double sum2 = sum(pow(F2 - ELib, 2)) / C.size(); - if(sum2 < sum02) { m_curEner = CalUpdate2; Cal_Ener_Data[m_curEner] = data; - field f_p(2); f_p(0) = p; f_p(1) = perr; Acal_energy_para[m_curEner] = f_p; @@ -6131,7 +6108,6 @@ bool GammaAnalyALG::fitPeakQuick(vec &Ao, vec &Co, vec &Fo, double &X2, uvec Af, end */ bool s = true; QStringList addArg(""); - // get index of leftmost and rightmost peak //allidx = [Af; Cf; Ff]; uvec allidx = join_vert(Af, Cf); @@ -6145,7 +6121,6 @@ bool GammaAnalyALG::fitPeakQuick(vec &Ao, vec &Co, vec &Fo, double &X2, uvec Af, X2 = gNaN; return s; } - uword LIdx = min(allidx); uword RIdx = max(allidx); @@ -6153,7 +6128,6 @@ bool GammaAnalyALG::fitPeakQuick(vec &Ao, vec &Co, vec &Fo, double &X2, uvec Af, uvec Bool = zeros(RIdx + 1u); Bool(allidx) = ones(allidx.n_elem); allidx = find(Bool); - // get peak parameters //[C, FC, NA] = dmps(sn, 'Centroid', 'FWHM_Ch', 'NetArea'); QStringList Opts; Opts << "Centroid" << "FWHM_Ch" << "NetArea"; @@ -6161,7 +6135,6 @@ bool GammaAnalyALG::fitPeakQuick(vec &Ao, vec &Co, vec &Fo, double &X2, uvec Af, vec C = t_f(0); vec FC = t_f(1); vec NA = t_f(2); - // interval for fitting: left centroid - width left FWHM to right centroid + ... int CL = floor(C(LIdx) - FitWidth * FC(LIdx)); int CR = ceil(C(RIdx) + FitWidth * FC(RIdx)); @@ -6170,7 +6143,6 @@ bool GammaAnalyALG::fitPeakQuick(vec &Ao, vec &Co, vec &Fo, double &X2, uvec Af, rowvec S = baseInfo(s_Spectrum); //S = dmspec(sn, 'Spectrum'); rowvec x = RangeVec2(CL, CR); rowvec y = S.cols(CL-1, CR-1); - // initial baseline y = k*x + d through extremal points (spectrum data) double k = (S(CR) - S(CL)) / (CR -CL); double d = S(CL) - k * CL; @@ -6182,7 +6154,6 @@ bool GammaAnalyALG::fitPeakQuick(vec &Ao, vec &Co, vec &Fo, double &X2, uvec Af, uvec zeroIdx = find(NA(Af) < minNA); MatAssign(NA, Af(zeroIdx), minNA); } - // fit parameters //[s, BL, Ao, Co, Fo, X2] = fitFunction(x, y, 'peakBaseLin', [k d], [1 2], NA, Af, C, Cf, FC, Ff, addArg{:}); field para; @@ -6197,7 +6168,6 @@ bool GammaAnalyALG::fitPeakQuick(vec &Ao, vec &Co, vec &Fo, double &X2, uvec Af, Co = para(2); Fo = para(3); } - // write results to temporary PAT /*patSetPeaks(allidx, 'FittingMethod', 'Q', 'NetArea', Ao(allidx), ... 'Centroid', Co(allidx), 'FWHM_Ch', Fo(allidx), 'NetAreaFree', Af, ... @@ -6213,7 +6183,6 @@ bool GammaAnalyALG::fitPeakQuick(vec &Ao, vec &Co, vec &Fo, double &X2, uvec Af, patSetPeaks(allidx, items, vals); vec sqi, uqi; patBaseVar(sqi, uqi, allidx); - // return only fitted parameters Ao = Ao(Af); Co = Co(Cf); diff --git a/GammaAnalyALG.pro.user b/GammaAnalyALG.pro.user index 0d6223c..181abd5 100644 --- a/GammaAnalyALG.pro.user +++ b/GammaAnalyALG.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/IndependentAlg.cpp b/IndependentAlg.cpp index edf48c6..19ad1e6 100644 --- a/IndependentAlg.cpp +++ b/IndependentAlg.cpp @@ -1424,7 +1424,6 @@ mat vecsum(rowvec y, vec l, vec h) // sizes of input vectors int n = y.size(); int m = l.size(); - if(h.size() != m) { qDebug() << "summation indizes must be of same size"; @@ -1444,7 +1443,6 @@ mat vecsum(rowvec y, vec l, vec h) // integer and fractional part vec rl = round(l); - // 0.5 added, since e.g. for integer l, only y(l)/2 accounts to the sum vec dl = l - rl + 0.5; @@ -1456,7 +1454,6 @@ mat vecsum(rowvec y, vec l, vec h) vec rh = round(h); vec dh = rh - h + 0.5; - //uvec bh = AndUMat( AndUMat( rh > 0, rh <= n), dh != 0 ); //bh.print("bh = "); @@ -1466,15 +1463,16 @@ mat vecsum(rowvec y, vec l, vec h) { // sum from low to high //s(i) = sum( y([max(1, rl(i)) : min(n, rh(i))]) ); - if(min(n,rh(i)) < 0) throw std::string(" Row::cols(): indices out of bounds or incorrectly used"); - s(i) = sum( y.cols( max(1, rl(i))-1, min(n, rh(i))-1 ) ); + if(min(n,rh(i)) < 0) throw std::string(" Row::cols(): indices out of bounds or incorrectly used"); + if(max(1, rl(i))-1 >= y.n_cols || min(n, rh(i))-1 >= y.n_cols || max(1, rl(i))-1 < 0 || min(n, rh(i))-1 < 0) + throw std::string(" Row::cols(): indices out of bounds or incorrectly used"); + s(i) = sum( y.cols( max(1, rl(i))-1, min(n, rh(i))-1 ) ); // fractional part at low border if( rl(i) > 0 && rl(i) <= n && dl(i) != 0 ) // if( bl(i) ) { s(i) = s(i) - dl(i) * y(rl(i)-1); } - // fractional part at high border if( rh(i) > 0 && rh(i) <= n && dh(i) != 0 ) // if( bh(i) ) { @@ -1482,7 +1480,6 @@ mat vecsum(rowvec y, vec l, vec h) } } } - // size of l s.reshape( size(l) ); //s = reshape(s, sz); return s; diff --git a/org_jeecg_modules_native_jni_CalValuesHandler.cpp b/org_jeecg_modules_native_jni_CalValuesHandler.cpp index 3311078..bd851d6 100644 --- a/org_jeecg_modules_native_jni_CalValuesHandler.cpp +++ b/org_jeecg_modules_native_jni_CalValuesHandler.cpp @@ -1465,13 +1465,13 @@ JNIEXPORT jstring JNICALL Java_org_jeecg_modules_native_1jni_CalValuesHandler_an } // **************** printf("maplines get\n"); - GammaAnalyALG alg; try { alg.setFilePath(xmlFilePath); alg.setJniBl(env, sendObj, userId); alg.AnalyseSpectrum(phd, mapLines); - } catch (std::string error) { + } + catch (std::string error) { QJsonObject errObj; errObj["analyFlag"] = false; errObj["analyMessage"] = error.c_str(); @@ -1480,8 +1480,16 @@ JNIEXPORT jstring JNICALL Java_org_jeecg_modules_native_1jni_CalValuesHandler_an QString jsonStr = doc.toJson(); jstring jresult = env->NewStringUTF(jsonStr.toStdString().c_str()); return jresult; + } catch (...) { + QJsonObject errObj; + errObj["analyFlag"] = false; + errObj["analyMessage"] = "update calibration error"; + QJsonDocument doc; + doc.setObject(errObj); + QString jsonStr = doc.toJson(); + jstring jresult = env->NewStringUTF(jsonStr.toStdString().c_str()); + return jresult; } - // **************** printf("AnalyseSpectrum calc\n"); QJsonObject resultjson;