static internal OperationResult GetWarningFromString(this OperationResult result, string msg)
		{
			result.AddWarningMessage(msg);
			result.Status = StatusResult.Warning;
			Logger.Instance.WriteLog.Warn(msg);
			return result;
		}
		static internal OperationResult –°ombineResult(this OperationResult result, OperationResult newResult)
		{
			if (newResult == null)
			{
				return result;
			}
			if (newResult.Status == StatusResult.Warning)
			{
				result.AddWarningMessage(newResult.WarningMessages);
				result.Status = newResult.Status;
			}
			if (newResult.Status == StatusResult.Fail)
			{
				result.ErrorMessage = newResult.ErrorMessage;
				result.Status = newResult.Status;
			}
			return result;
		}
Example #3
0
        static void CalculateVerificationResults(this Measurement meas, Multiplicity mkey, MultiplicityCountingRes results)
        {
            Tuple normal_mass = new Tuple(-1, 0), backup_mass = new Tuple(-1, 0);
            try
            {
                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.CalibrationCurve))
                {
                    // get the current results_cal_curve_rec and cal_curve params

                    //dev note: the rates as computed by the first and second phases are not yet on ccres, because they exist soley on the counting results MultiplicityCountingRes instance

                    INCCMethodResults.results_cal_curve_rec ccres = (INCCMethodResults.results_cal_curve_rec)
                        meas.INCCAnalysisResults.LookupMethodResults(mkey, meas.INCCAnalysisState.Methods.selector, AnalysisMethod.CalibrationCurve, true);
                    INCCAnalysisParams.cal_curve_rec cal_curve = (INCCAnalysisParams.cal_curve_rec)meas.INCCAnalysisState.Methods.GetMethodParameters(AnalysisMethod.CalibrationCurve);
                    INCCAnalysisParams.CalCurveResult status = INCCAnalysisParams.CalCurveResult.Unknown;
                    if (cal_curve == null)
                    {
                        meas.Logger.TraceEvent(NCCReporter.LogLevels.Warning, 10199, "No " + AnalysisMethod.KnownA.FullName() + " method parameters found");
                        return;
                    }
                    if (cal_curve.CalCurveType != INCCAnalysisParams.CalCurveType.HM)
                    {
                        Tuple pu240e = new Tuple();
                        Tuple doubles;
                        if (cal_curve.cev.useSingles)  // the 2009 MTS hack
                            doubles = new Tuple(results.rates.GetDTCRates(RatesAdjustments.DeadtimeCorrected).Singles);
                        else
                            doubles = new Tuple(results.rates.GetDTCRates(RatesAdjustments.DeadtimeCorrected).Doubles);
                        status = INCCAnalysis.CalculateCalibrationCurveOnly(cal_curve.cev, out pu240e, results.rates, doubles, RatesAdjustments.DeadtimeCorrected); // rates (triples) not used
                        ccres.pu240e_mass = pu240e;
                    }
                    else
                    {
                        // get the item id from the acquire record or the ItemId on the measurement itself
                        // if there is no item id use the empty default item id
                        // dev note: at some point the acquire record item id becomes a full ItemId record on the measurmeent
                        //if not NC.App.DB.ItemIdSet.Contains AcquireState.item_id then
                        //    get the default empty one
                        //end

                        // from HEAVY_M.cpp
                        INCCAnalysis.calc_heavy_metal(
                                cal_curve.heavy_metal_corr_factor,
                                cal_curve.heavy_metal_reference,
                                results.rates.DTCRates.Singles,
                                results.rates.DTCRates.Doubles,
                                ref ccres.heavy_metal_content,
                                ref ccres.heavy_metal_correction,
                                ref ccres.heavy_metal_corr_singles,
                                ref ccres.heavy_metal_corr_doubles, meas);

                        status = INCCAnalysis.CalculateCalibrationCurveOnly(cal_curve.cev,
                                        out ccres.pu240e_mass,
                                        results.rates, ccres.heavy_metal_corr_doubles,
                                        RatesAdjustments.DeadtimeCorrected);

                        ccres.pu240e_mass.v *= meas.MeasurementId.Item.length;
                        ccres.pu240e_mass.err *= meas.MeasurementId.Item.length;
                    }

                    if (status == INCCAnalysisParams.CalCurveResult.FailedOnMassLimit)
                    {
                        string msg = String.Format("Passive calibration curve failed mass limits of {0} and {1}", cal_curve.cev.lower_mass_limit, cal_curve.cev.upper_mass_limit);
                        meas.AddErrorMessage(msg, 10196, mkey);
                    }
                    else if (status != INCCAnalysisParams.CalCurveResult.Success)
                    {
                        meas.AddErrorMessage("Passive calibration curve analysis error", 10197, mkey);
                    }
                    if (status == INCCAnalysisParams.CalCurveResult.Success || status == INCCAnalysisParams.CalCurveResult.FailedOnMassLimit)
                    {
                        ccres.dcl_pu_mass = meas.AcquireState.mass; // another requirement for the acquire state
                        meas.Logger.TraceEvent(NCCReporter.LogLevels.Verbose, 10133, "calc_mass/calc_u235_mass are called next");
                        if (cal_curve.CalCurveType != INCCAnalysisParams.CalCurveType.U)
                        {
                            INCCAnalysis.calc_mass(ccres.pu240e_mass,
                                ref ccres.pu_mass, ref ccres.dcl_pu_mass, ref ccres.dcl_pu240e_mass, ref ccres.dcl_minus_asy_pu_mass, ref ccres.dcl_minus_asy_pu_mass_pct, ref ccres.pass,
                                meas);
                        }
                        else
                        {
                            INCCAnalysis.calc_u235_mass(cal_curve.percent_u235, ccres.pu240e_mass,
                               ref ccres.pu_mass, ref ccres.dcl_pu_mass, ref ccres.dcl_minus_asy_pu_mass, ref ccres.dcl_minus_asy_pu_mass_pct, ref ccres.pass,
                                meas);
                        }

                        if (!ccres.pass)
                        {
                            meas.AddWarningMessage("Passive calibration curve: failed stratum rejection limits", 10198, mkey);
                        }
                        else
                        {
                            meas.AddWarningMessage("Passive calibration curve: passed stratum rejection limits", 10200, mkey);
                        }

                        if (ccres.pu240e_mass.v > ccres.methodParams.cev.upper_mass_limit)
                        {
                            meas.AddWarningMessage("Passive calibration curve: upper Pu240e mass limit exceeded.", 10210, mkey);
                        }
                        if (ccres.pu240e_mass.v < ccres.methodParams.cev.lower_mass_limit)
                        {
                            meas.AddWarningMessage("Passive calibration curve: lower Pu240e mass limit exceeded.", 10211, mkey);
                        }
                    }
                    // normal and backup retention
                    if (meas.INCCAnalysisState.Methods.Normal == AnalysisMethod.CalibrationCurve)
                    {
                        normal_mass.CopyFrom(ccres.pu240e_mass);
                    }
                    if (meas.INCCAnalysisState.Methods.Backup == AnalysisMethod.CalibrationCurve)
                    {
                        backup_mass.CopyFrom(ccres.pu240e_mass);
                    }

                }
                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.KnownA))
                {
                    INCCMethodResults.results_known_alpha_rec kares = (INCCMethodResults.results_known_alpha_rec)
                    meas.INCCAnalysisResults.LookupMethodResults(mkey, meas.INCCAnalysisState.Methods.selector, AnalysisMethod.KnownA, true);
                    INCCAnalysisParams.known_alpha_rec ka_params = (INCCAnalysisParams.known_alpha_rec)meas.INCCAnalysisState.Methods.GetMethodParameters(AnalysisMethod.KnownA);
                    if (ka_params == null)
                    {
                        meas.Logger.TraceEvent(NCCReporter.LogLevels.Warning, 10199, "No Known alpha method parameters found");
                        return;
                    }
                    bool success = false;
                    kares.dcl_pu_mass = meas.AcquireState.mass;  // dev note: another use of acq, a requirement, here
                    // copy the input calibration params to the copy on the results rec, to be saved with the KA results
                    kares.methodParams = new INCCAnalysisParams.known_alpha_rec(ka_params);

                    if (ka_params.known_alpha_type == INCCAnalysisParams.KnownAlphaVariant.Conventional)
                    {
                        INCCMethodResults.results_known_alpha_rec karesdup = INCCAnalysis.CalculateKnownAlpha(mkey, results.rates, meas, RatesAdjustments.DeadtimeCorrected); // rates (triples) not used
                        if (karesdup != null) // we have the new mass results, and they are preserved in the results map
                        {
                            success = true;
                            meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 240, "Known alpha results for pu240E {0} +- {1}", karesdup.pu240e_mass.v, karesdup.pu240e_mass.err);
                        }
                    }
                    else if (ka_params.known_alpha_type == INCCAnalysisParams.KnownAlphaVariant.HeavyMetalCorrection)
                    {
                        INCCAnalysis.calc_heavy_metal(
                                ka_params.heavy_metal_corr_factor,
                                ka_params.heavy_metal_reference,
                                results.rates.DTCRates.Singles,
                                results.rates.DTCRates.Doubles,
                                ref kares.heavy_metal_content,
                                ref kares.heavy_metal_correction,
                                ref kares.corr_singles,
                                ref kares.corr_doubles, meas);

                        Rates HMSDRates = new Rates();
                        HMSDRates.DeadtimeCorrectedRates.Singles.CopyFrom(kares.corr_singles);
                        HMSDRates.DeadtimeCorrectedRates.Doubles.CopyFrom(kares.corr_doubles);

                        INCCMethodResults.results_known_alpha_rec karesdup = INCCAnalysis.CalculateKnownAlpha(mkey, HMSDRates, meas, RatesAdjustments.DeadtimeCorrected);
                        if (karesdup != null) // we have the new mass results, and they are preserved in the results map
                        {
                            success = true;
                            meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 240, "Known alpha HM results for pu240E {0} +- {1}", karesdup.pu240e_mass.v, karesdup.pu240e_mass.err);
                        }
                        kares.pu240e_mass.v *= meas.MeasurementId.Item.length;
                        kares.pu240e_mass.err *= meas.MeasurementId.Item.length;
                    }
                    else if (ka_params.known_alpha_type == INCCAnalysisParams.KnownAlphaVariant.MoistureCorrAppliedToDryAlpha)
                    {
                        success =
                         INCCAnalysis.calc_known_alpha_moisture_corr(
                                    results.rates.DTCRates.Singles,
                                    results.rates.DTCRates.Doubles,
                                    results.Scaler1, results.Scaler2,
                                    ref kares.corr_singles, /* ring ratio */
                                    ref kares.corr_factor,
                                    ref kares.dry_alpha_or_mult_dbls, /* dry alpha */
                                    ref kares.mult_corr_doubles,
                                    ref kares.mult,
                                    ref kares.alphaK,
                                    ref kares.pu240e_mass, ka_params, meas, mkey);
                        if (success)
                            meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 240, "Known alpha MoistureCorrAppliedToDryAlpha results for pu240E {0} +- {1}", kares.pu240e_mass.v, kares.pu240e_mass.err);

                    }
                    else if (ka_params.known_alpha_type == INCCAnalysisParams.KnownAlphaVariant.MoistureCorrAppliedToMultCorrDoubles)
                    {
                        success =
                            INCCAnalysis.calc_known_alpha_moisture_corr_mult_doubles(
                                    results.rates.DTCRates.Singles,
                                    results.rates.DTCRates.Doubles,
                                    results.Scaler1, results.Scaler2,
                                    ref kares.corr_singles, /* ring ratio */
                                    ref kares.corr_factor,
                                    ref kares.dry_alpha_or_mult_dbls, /* moist mult_corr_doubles */
                                    ref kares.mult_corr_doubles,
                                    ref kares.mult,
                                    ref kares.alphaK,
                                    ref kares.pu240e_mass, ka_params, meas, mkey);
                        if (success)
                            meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 240, "Known alpha MoistureCorrAppliedToMultCorrDoubles results for pu240E {0} +- {1}", kares.pu240e_mass.v, kares.pu240e_mass.err);

                    }

                    if (success)
                    {
                        INCCAnalysis.calc_mass(kares.pu240e_mass,
                            ref kares.pu_mass, ref kares.dcl_pu_mass, ref kares.dcl_pu240e_mass, ref kares.dcl_minus_asy_pu_mass, ref kares.dcl_minus_asy_pu_mass_pct, ref kares.pass,
                            meas);
                    }
                    else
                    {
                        meas.AddErrorMessage("Known alpha analysis error", 10199, mkey);
                    }
                    if (!kares.pass)
                    {
                        meas.AddWarningMessage("Known alpha: failed stratum rejection limits", 10198, mkey);
                    }
                    else
                    {
                        meas.AddWarningMessage("Known alpha: passed stratum rejection limits", 10200, mkey);
                    }
                    if (kares.pu240e_mass.v > kares.methodParams.cev.upper_mass_limit)
                    {
                        meas.AddWarningMessage("Known alpha: upper Pu240e mass limit exceeded.", 10210, mkey);
                    }
                    if (kares.pu240e_mass.v < kares.methodParams.cev.lower_mass_limit)
                    {
                        meas.AddWarningMessage("Known alpha: lower Pu240e mass limit exceeded.", 10211, mkey);
                    }
                    // normal and backup retention
                    if (meas.INCCAnalysisState.Methods.Normal == AnalysisMethod.KnownA)
                    {
                        normal_mass.CopyFrom(kares.pu240e_mass);
                    }
                    if (meas.INCCAnalysisState.Methods.Backup == AnalysisMethod.KnownA)
                    {
                        backup_mass.CopyFrom(kares.pu240e_mass);
                    }
                }

                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.Multiplicity))
                {
                    double error = 0.0;
                    INCCAnalysisParams.multiplicity_rec mul_param = (INCCAnalysisParams.multiplicity_rec)meas.INCCAnalysisState.Methods.GetMethodParameters(AnalysisMethod.Multiplicity);
                    if (mul_param == null)
                    {
                        meas.Logger.TraceEvent(NCCReporter.LogLevels.Warning, 10198, "No Multiplicity method parameters found");
                        return;
                    }
                    INCCMethodResults.results_multiplicity_rec mmres = (INCCMethodResults.results_multiplicity_rec)meas.INCCAnalysisResults.LookupMethodResults(
                                                              mkey, meas.INCCAnalysisState.Methods.selector, AnalysisMethod.Multiplicity, true);
                    // weird rates (triples) used, but they are wrong (see note line 568 avg_sums.cs)
                    INCCMethodResults.results_multiplicity_rec mmresdup = INCCAnalysis.CalculateMultiplicity(mkey, results.covariance_matrix, results.rates.GetDTCRates(RatesAdjustments.DeadtimeCorrected), meas, RatesAdjustments.DeadtimeCorrected);
                    if (mmresdup != null) // we have the new mass results, and they are preserved in the results map
                    {
                        meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 240, "Multiplicity results for pu240E {0} +- {1}", mmres.pu240e_mass.v, mmres.pu240e_mass.err);
                        if (meas.AcquireState.acquire_type == AcquireConvergence.Pu240EffPrecision)
                        {
                            if (mmres.pu240e_mass.v != 0.0)
                            {
                                error = mmres.pu240e_mass.err /
                                    mmres.pu240e_mass.v * 100.0;
                                if (error > meas.AcquireState.meas_precision)
                                {
                                    meas.AddWarningMessage(String.Format("Multiplicity: Pu240e error = {0}%", error), 10198, mkey);
                                }
                            }
                        }
                        mmres.dcl_pu_mass = meas.AcquireState.mass;  // another use of acq, a requirement, here

                        INCCAnalysis.calc_mass(mmres.pu240e_mass,
                            ref mmres.pu_mass, ref mmres.dcl_pu_mass, ref mmres.dcl_pu240e_mass, ref mmres.dcl_minus_asy_pu_mass, ref mmres.dcl_minus_asy_pu_mass_pct, ref mmres.pass,
                            meas);

                        if (!mmres.pass)
                        {
                            meas.AddWarningMessage("Multiplicity: failed stratum rejection limits", 10198, mkey);
                        }
                        else
                        {
                            meas.AddWarningMessage("Multiplicity: passed stratum rejection limits", 10200, mkey);
                        }

                        if (mul_param.solve_efficiency == INCCAnalysisParams.MultChoice.CONVENTIONAL_MULT_WEIGHTED) // todo: implement Weighted
                        {
                            meas.Logger.TraceEvent(NCCReporter.LogLevels.Warning, 36010, "CONVENTIONAL_MULT_WEIGHTED Multiplicity measurement results");
                        }
                        else if (mul_param.solve_efficiency == INCCAnalysisParams.MultChoice.MULT_DUAL_ENERGY_MODEL) // todo: implement DE
                        {
                            meas.Logger.TraceEvent(NCCReporter.LogLevels.Warning, 36010, "MULT_DUAL_ENERGY_MODEL Multiplicity measurement results");
                        }
                        // normal and backup retention
                        if (meas.INCCAnalysisState.Methods.Normal == AnalysisMethod.Multiplicity)
                        {
                            normal_mass.CopyFrom(mmres.pu240e_mass);
                        }
                        if (meas.INCCAnalysisState.Methods.Backup == AnalysisMethod.Multiplicity)
                        {
                            backup_mass.CopyFrom(mmres.pu240e_mass);
                        }
                    }
                    else
                    {
                        meas.AddErrorMessage("Multiplicity analysis error", 10198, mkey);
                    }

                    // copy the input calib to the results rec
                    mmres.methodParams = new INCCAnalysisParams.multiplicity_rec(mul_param);

                }
                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.KnownM))
                {
                    INCCMethodResults.results_known_m_rec kmres = INCCAnalysis.CalculateKnownM(mkey, results, meas, RatesAdjustments.DeadtimeCorrected);

                    // calc mass
                    if (kmres != null) // you have calculated well my child
                    {
                        INCCAnalysis.calc_mass(kmres.pu240e_mass,
                                            ref kmres.pu_mass, ref kmres.dcl_pu_mass, ref kmres.dcl_pu240e_mass,
                                            ref kmres.dcl_minus_asy_pu_mass, ref kmres.dcl_minus_asy_pu_mass_pct, ref kmres.pass, meas);

                        if (!kmres.pass)
                        {
                            meas.AddWarningMessage("Known M: failed stratum rejection limits", 10198, mkey);
                        }
                        else
                        {
                            meas.AddWarningMessage("Known M: passed stratum rejection limits", 10200, mkey);
                        }

                        if (kmres.pu240e_mass.v > kmres.methodParams.upper_mass_limit)
                        {
                            meas.AddWarningMessage("Known M: upper Pu240e mass limit exceeded.", 10210, mkey);
                        }
                        if (kmres.pu240e_mass.v < kmres.methodParams.lower_mass_limit)
                        {
                            meas.AddWarningMessage("Known M: lower Pu240e mass limit exceeded.", 10211, mkey);
                        }
                        // normal and backup retention
                        if (meas.INCCAnalysisState.Methods.Normal == AnalysisMethod.KnownM)
                        {
                            normal_mass.CopyFrom(kmres.pu240e_mass);
                        }
                        if (meas.INCCAnalysisState.Methods.Backup == AnalysisMethod.KnownM)
                        {
                            backup_mass.CopyFrom(kmres.pu240e_mass);
                        }
                    }
                    else
                    {
                        meas.AddErrorMessage("Known M: analysis error", 10198, mkey);
                    }

                }
                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.Active))
                {
                    INCCAnalysisParams.active_rec act_param = (INCCAnalysisParams.active_rec)meas.INCCAnalysisState.Methods.GetMethodParameters(AnalysisMethod.Active);
                    if (act_param == null)
                    {
                        meas.Logger.TraceEvent(NCCReporter.LogLevels.Warning, 10198, "No Active method parameters found");
                        return;
                    }
                    INCCMethodResults.results_active_rec actres = (INCCMethodResults.results_active_rec)meas.INCCAnalysisResults.LookupMethodResults(
                                                              mkey, meas.INCCAnalysisState.Methods.selector, AnalysisMethod.Active, true);
                    /* calculate active doubles rate corrected for source yield factor */
                    //line 331 if calc_asy.cpp
                    Measurement.SourceYieldFactoredRates syfr = new Measurement.SourceYieldFactoredRates(results, meas);
                    // line 1267 of calc_asy.cpp
                    //Martyn says we need stuff here to deal with Cf active measurements HN 7.23.2015
                    actres.k0.v = syfr.source_yield_factor;
                    actres.k = new Tuple(syfr.total_corr_fact);
                    actres.k1 = new Tuple(meas.Norm.currNormalizationConstant);
                    // This stays the same for Cf. HN 7.23.2015
                    INCCAnalysisParams.CalCurveResult status = INCCAnalysis.CalculateCalibrationCurveOnly(act_param.cev,
                                    out actres.u235_mass, results.rates, syfr.corrected_doubles,
                                    RatesAdjustments.DeadtimeCorrected);

                    if (status == INCCAnalysisParams.CalCurveResult.FailedOnMassLimit)
                    {
                        string msg = String.Format("Active calibration curve failed mass limits of {0} and {1}", act_param.cev.lower_mass_limit, act_param.cev.upper_mass_limit);
                        meas.AddErrorMessage(msg, 10196, mkey);
                    }
                    else if (status != INCCAnalysisParams.CalCurveResult.Success)
                    {
                        meas.AddErrorMessage("Active calibration curve analysis error", 10197, mkey);
                    }
                    meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 240, "Active results for U235 {0} +- {1}", actres.u235_mass.v, actres.u235_mass.err);
                    if (status == INCCAnalysisParams.CalCurveResult.Success || status == INCCAnalysisParams.CalCurveResult.FailedOnMassLimit)
                    {
                        actres.dcl_u235_mass = meas.AcquireState.mass;
                        INCCAnalysis.calc_decl_minus_assay_u235(actres.u235_mass, actres.dcl_u235_mass, ref actres.dcl_minus_asy_u235_mass, ref actres.dcl_minus_asy_u235_mass_pct, ref actres.pass, meas);
                        if (!actres.pass)
                        {
                            meas.AddWarningMessage("Active calibration curve: failed stratum rejection limits", 10198, mkey);
                        }
                        else if (!meas.Stratum.Unset)
                        {
                            meas.AddWarningMessage("Active calibration curve: passed stratum rejection limits", 10200, mkey);
                        }

                        if (actres.u235_mass.v > actres.methodParams.cev.upper_mass_limit)
                        {
                            meas.AddWarningMessage("Active calibration curve: upper U235 mass limit exceeded.", 10210, mkey);
                        }
                        if (actres.u235_mass.v < actres.methodParams.cev.lower_mass_limit)
                        {
                            meas.AddWarningMessage("Active calibration curve: lower U235 mass limit exceeded.", 10211, mkey);
                        }
                    }
                    // normal and backup retention not performed for active

                }
                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.ActiveMultiplicity))
                {
                    // sets results class' mult v,err values at end of calculation
                    INCCMethodResults.results_active_mult_rec res = INCCAnalysis.CalculateActiveMultiplicity(mkey, results, meas, RatesAdjustments.DeadtimeCorrected);
                    if (res == null)
                    {
                        meas.AddErrorMessage("Active multiplicity analysis error", 10152, mkey);
                    }
                }
                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.TruncatedMultiplicity))
                {
                    INCCMethodResults.results_truncated_mult_rec res = INCCAnalysis.CalculateTruncatedMult(mkey, results, meas, RatesAdjustments.DeadtimeCorrected);
                    // normal and backup retention
                    if (meas.INCCAnalysisState.Methods.Normal == AnalysisMethod.TruncatedMultiplicity)
                    {
                        if (res.methodParams.known_eff)
                            normal_mass.CopyFrom(res.k.pu240e_mass);
                        else
                            normal_mass.CopyFrom(res.s.pu240e_mass);
                    }
                    if (meas.INCCAnalysisState.Methods.Backup == AnalysisMethod.TruncatedMultiplicity)
                    {
                        if (res.methodParams.known_eff)
                            backup_mass.CopyFrom(res.k.pu240e_mass);
                        else
                            backup_mass.CopyFrom(res.s.pu240e_mass);
                    }
                }

                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.Collar))
                {
                    meas.AddWarningMessage("Collar mass results", 10153, mkey); // NEXT: Collar is incomplete, new design from IAEA is pending, this is a big task
                    INCCAnalysis.CalculateCollar(mkey, results, meas, RatesAdjustments.DeadtimeCorrected);
                }

                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.ActivePassive))
                {
                    INCCAnalysisParams.active_passive_rec act_param = (INCCAnalysisParams.active_passive_rec)meas.INCCAnalysisState.Methods.GetMethodParameters(AnalysisMethod.ActivePassive);
                    if (act_param == null)
                    {
                        meas.Logger.TraceEvent(NCCReporter.LogLevels.Warning, 10198, "No active/passive method parameters found");
                        return;
                    }
                    INCCMethodResults.results_active_passive_rec actres = (INCCMethodResults.results_active_passive_rec)meas.INCCAnalysisResults.LookupMethodResults(
                                                              mkey, meas.INCCAnalysisState.Methods.selector, AnalysisMethod.ActivePassive, true);

                    INCCAnalysis.CalculateActivePassive(mkey, results, meas, RatesAdjustments.DeadtimeCorrected);

                    //line 1134 if calc_asy.cpp
                    // calculate delta doubles and error from passive and active doubles
                    Measurement.SourceYieldFactoredRates syfr = new Measurement.SourceYieldFactoredRates(results, meas);
                    actres.k0.v = syfr.source_yield_factor;
                    actres.k = new Tuple(syfr.total_corr_fact);
                    actres.k1 = new Tuple(meas.Norm.currNormalizationConstant);

                    actres.delta_doubles.v = syfr.corrected_doubles.v - results.DeadtimeCorrectedDoublesRate.v;
                    actres.delta_doubles.err = Math.Sqrt((syfr.corrected_doubles.v * results.DeadtimeCorrectedDoublesRate.err) + (syfr.corrected_doubles.v * results.DeadtimeCorrectedDoublesRate.err));

                    INCCAnalysisParams.CalCurveResult status = INCCAnalysis.CalculateCalibrationCurveOnly(act_param.cev,
                                                 out actres.u235_mass, results.rates, actres.delta_doubles,
                                                 RatesAdjustments.DeadtimeCorrected);

                    if (status == INCCAnalysisParams.CalCurveResult.FailedOnMassLimit)
                    {
                        string msg = String.Format("Active/passive calibration curve failed mass limits of {0} and {1}", act_param.cev.lower_mass_limit, act_param.cev.upper_mass_limit);
                        meas.AddErrorMessage(msg, 10196, mkey);
                    }
                    else if (status != INCCAnalysisParams.CalCurveResult.Success)
                    {
                        meas.AddErrorMessage("Active/passive calibration curve analysis error", 10197, mkey);
                    }
                    if (status == INCCAnalysisParams.CalCurveResult.Success || status == INCCAnalysisParams.CalCurveResult.FailedOnMassLimit)
                    {
                        actres.dcl_u235_mass = meas.AcquireState.mass;
                        INCCAnalysis.calc_decl_minus_assay_u235(actres.u235_mass, actres.dcl_u235_mass, ref actres.dcl_minus_asy_u235_mass, ref actres.dcl_minus_asy_u235_mass_pct, ref actres.pass, meas);
                        if (!actres.pass)
                        {
                            meas.AddWarningMessage("Active/passive: failed stratum rejection limits", 10198, mkey);
                        }
                        else if (!meas.Stratum.Unset)
                        {
                            meas.AddWarningMessage("Active/passive: passed stratum rejection limits", 10200, mkey);
                        }

                        if (actres.u235_mass.v > actres.methodParams.cev.upper_mass_limit)
                        {
                            meas.AddWarningMessage("Active/passive: upper U235 mass limit exceeded.", 10210, mkey);
                        }
                        if (actres.u235_mass.v < actres.methodParams.cev.lower_mass_limit)
                        {
                            meas.AddWarningMessage("Active/passive: lower U235 mass limit exceeded.", 10211, mkey);
                        }
                    }
                }

                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.AddASource))
                {
                    INCCAnalysisParams.CalCurveResult status;
                    INCCMethodResults.results_add_a_source_rec res = null;
                    // gotta do a sanity check for the AAS cycles, they may not be there due to unfinished processing in the overall code
                    if (meas.CFCycles != null)
                    {
                        res = INCCAnalysis.CalculateAddASource(mkey, results, meas, RatesAdjustments.DeadtimeCorrected, out status);
                    }
                    else
                    {
                        meas.AddErrorMessage("Add-a-source calibration curve cycles not present error", 10197, mkey);
                        status = INCCAnalysisParams.CalCurveResult.EpicFailLOL;
                    }
                    if (status == INCCAnalysisParams.CalCurveResult.FailedOnMassLimit)
                    {
                        string msg = String.Format("Add-a-source calibration curve failed mass limits of {0} and {1}", res.methodParams.cev.lower_mass_limit, res.methodParams.cev.upper_mass_limit);
                        meas.AddErrorMessage(msg, 10196, mkey);
                    }
                    else if (status != INCCAnalysisParams.CalCurveResult.Success)
                    {
                        meas.AddErrorMessage("Add-a-source calibration curve analysis error", 10197, mkey);
                    }
                    if (status == INCCAnalysisParams.CalCurveResult.Success || status == INCCAnalysisParams.CalCurveResult.FailedOnMassLimit)
                    {
                        res.dcl_pu_mass = meas.AcquireState.mass;
                        INCCAnalysis.calc_mass(res.pu240e_mass,
                                ref res.pu_mass, ref res.dcl_pu_mass, ref res.dcl_pu240e_mass,
                                ref res.dcl_minus_asy_pu_mass, ref res.dcl_minus_asy_pu_mass_pct, ref res.pass, meas);
                        if (!res.pass)
                        {
                            meas.AddWarningMessage("Add-a-source calibration curve: failed stratum rejection limits", 10198, mkey);
                        }
                        else
                        {
                            meas.AddWarningMessage("Add-a-source calibration curve: passed stratum rejection limits", 10200, mkey);
                        }

                        if (res.pu240e_mass.v > res.methodParams.cev.upper_mass_limit)
                        {
                            meas.AddWarningMessage("Add-a-source calibration curve: upper Pu240e mass limit exceeded.", 10210, mkey);
                        }
                        if (res.pu240e_mass.v < res.methodParams.cev.lower_mass_limit)
                        {
                            meas.AddWarningMessage("Add-a-source calibration curve: lower Pu240e mass limit exceeded.", 10211, mkey);
                        }
                        // normal and backup retention
                        if (meas.INCCAnalysisState.Methods.Normal == AnalysisMethod.AddASource)
                        {
                            normal_mass.CopyFrom(res.pu240e_mass);
                        }
                        if (meas.INCCAnalysisState.Methods.Backup == AnalysisMethod.AddASource)
                        {
                            backup_mass.CopyFrom(res.pu240e_mass);
                        }
                    }
                }
                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.CuriumRatio))
                {
                    INCCAnalysisParams.CalCurveResult status;
                    INCCMethodResults.results_curium_ratio_rec res = INCCAnalysis.CalculateCuriumRatio(mkey, results, meas, RatesAdjustments.DeadtimeCorrected, out status);
                    if (status == INCCAnalysisParams.CalCurveResult.FailedOnMassLimit)
                    {
                        string msg = String.Format("Curium ratio calibration curve failed mass limits of {0} and {1}", res.methodParams.cev.lower_mass_limit, res.methodParams.cev.upper_mass_limit);
                        meas.AddErrorMessage(msg, 10196, mkey);
                    }
                    else if (status != INCCAnalysisParams.CalCurveResult.Success)
                    {
                        meas.AddErrorMessage("Curium ratio calibration curve analysis error", 10197, mkey);
                    }

                    if (status == INCCAnalysisParams.CalCurveResult.Success || status == INCCAnalysisParams.CalCurveResult.FailedOnMassLimit)
                    {
                        INCCAnalysisParams.cm_pu_ratio_rec cm_pu_ratio = NC.App.DB.Cm_Pu_RatioParameters.Get(); // load from DB, just like test params,
                        // dev note: better not to ref DB here, because this is a one-off state retrieval and no other DB access occurs during mass calc processing, but that is how it works this morning

                        //calc  curium mass
                        INCCAnalysis.calc_curium_mass(res, cm_pu_ratio, meas);
                        res.u.dcl_mass = cm_pu_ratio.cm_dcl_u_mass;
                        res.u235.dcl_mass = cm_pu_ratio.cm_dcl_u235_mass;
                        if (!res.pu.pass)
                        {
                            meas.AddWarningMessage("Curium ratio: Pu failed stratum rejection limits", 10198, mkey);
                        }
                        else
                        {
                            meas.AddWarningMessage("Curium ratio: Pu passed stratum rejection limits", 10200, mkey);
                        }
                        if (!res.u.pass)
                        {
                            meas.AddWarningMessage("Curium ratio: U failed stratum rejection limits", 10198, mkey);
                        }
                        else
                        {
                            meas.AddWarningMessage("Curium ratio: U passed stratum rejection limits", 10200, mkey);
                        }
                        // normal and backup retention
                        if (meas.INCCAnalysisState.Methods.Normal == AnalysisMethod.CuriumRatio)
                        {
                            normal_mass.CopyFrom(res.pu.pu240e_mass);
                        }
                        if (meas.INCCAnalysisState.Methods.Backup == AnalysisMethod.CuriumRatio)
                        {
                            backup_mass.CopyFrom(res.pu.pu240e_mass);
                        }
                    }

                }

                // annotate the final results method marker on the INCC results instance.
                INCCMethodResults imr = null;
                if (normal_mass.v != -1.0)
                {
                    bool got = meas.INCCAnalysisResults.TryGetINCCResults(mkey, out imr);
                    if (got)
                        imr.primaryMethod = meas.INCCAnalysisState.Methods.Normal;
                    meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10100, "Verification primary method {0} with mass {1} is from the normal method", imr.primaryMethod.ToString(), normal_mass.v);
                }
                else if (backup_mass.v != -1.0)
                {
                    bool got = meas.INCCAnalysisResults.TryGetINCCResults(mkey, out imr);
                    if (got)
                        imr.primaryMethod = meas.INCCAnalysisState.Methods.Backup;
                    meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10101, "Verification primary method {0} with mass {1} is from the backup method", imr.primaryMethod.ToString(), backup_mass.v);
                }
                if ((normal_mass.v != -1.0) && (backup_mass.v != -1.0))
                {
                    if (meas.INCCAnalysisState.Methods.Backup.IsNone())
                    {
                        double delta = Math.Abs(normal_mass.v - backup_mass.v);
                        double delta_error = Math.Sqrt(normal_mass.err * normal_mass.err +
                             backup_mass.err * backup_mass.err);

                        bool got = meas.INCCAnalysisResults.TryGetINCCResults(mkey, out imr);

                        if (delta <= (delta_error * meas.Tests.normalBackupAssayTestLimit))
                        {
                            if (got) imr.primaryMethod = meas.INCCAnalysisState.Methods.Normal;
                            meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10102, "Verification primary method {0} with masses {1} and {2} is from the normal method", imr.primaryMethod.ToString(), normal_mass.v, backup_mass.v);
                        }
                        else
                        {
                            if (got) imr.primaryMethod = meas.INCCAnalysisState.Methods.Backup;
                            meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10103, "Verification primary method {0} with masses {1} and {2} is from the backup method", imr.primaryMethod.ToString(), normal_mass.v, backup_mass.v);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                meas.Logger.TraceException(e);
            }
        }
Example #4
0
        /// <summary>
        /// after each cycle, run this cycle limit test and exit code
        /// </summary>
        /// <param name="seq"></param>
        /// <param name="mkey"></param>
        public static void CycleStatusTerminationCheck(this Measurement meas, Cycle cc)
        {
            bool stopAndComputeResults = meas.AcquireState.lm.SaveOnTerminate;
            IEnumerator iter = cc.CountingAnalysisResults.GetMultiplicityEnumerator();
            while (iter.MoveNext())
            {
                Multiplicity mkey = (Multiplicity)((KeyValuePair<SpecificCountingAnalyzerParams, object>)(iter.Current)).Key;
                MultiplicityCountingRes mcr = (MultiplicityCountingRes)((KeyValuePair<SpecificCountingAnalyzerParams, object>)(iter.Current)).Value;

                if (meas.MeasCycleStatus.num_checksum_failures > meas.Tests.maxNumFailures)
                {
                    meas.Logger.TraceEvent(NCCReporter.LogLevels.Warning, 7071, "Maximum checksum failure count met, cycle {0} {1}", cc.seq, mkey);
                    if (stopAndComputeResults)
                    {
                        // URGENT: set state to end of measurement so that state moves out of cycles and skips forward to CalculateMeasurementResults
                    }
                    else
                    {
                        // exit processing completely, do not compute or save results
                        NC.App.Opstate.Abort();
                    }
                }
                if (meas.MeasCycleStatus.num_acc_sngl_failures > meas.Tests.maxNumFailures)
                {
                    meas.Logger.TraceEvent(NCCReporter.LogLevels.Warning, 7072, "Maximum A/S failure count met, cycle {0} {1}", cc.seq, mkey);
                    // ditto above comment block
                }
                if (meas.MeasCycleStatus.num_high_voltage_failures > meas.Tests.maxNumFailures)
                {
                    meas.Logger.TraceEvent(NCCReporter.LogLevels.Warning, 7073, "Maximum checksum failure count met, cycle {0} {1}", cc.seq, mkey);
                    // ditto above comment block
                }
                if ((meas.MeasCycleStatus.num_acc_sngl_failures >= NUM_ACC_SNGL_WARNING) &&
                     (!meas.MeasCycleStatus.acc_sngl_warning_sent))
                {
                    meas.AddWarningMessage("At least " + meas.MeasCycleStatus.num_acc_sngl_failures + " A/S test failures", 7074, mkey);
                    meas.MeasCycleStatus.acc_sngl_warning_sent = true;
                }
                if ((meas.MeasCycleStatus.num_checksum_failures >= NUM_CHECKSUM_WARNING) &&
                    (!meas.MeasCycleStatus.checksum_warning_sent))
                {
                    meas.AddWarningMessage("At least " + meas.MeasCycleStatus.num_checksum_failures + " checksum failures", 7075, mkey);
                    meas.MeasCycleStatus.checksum_warning_sent = true;
                }
                if ((meas.MeasCycleStatus.num_high_voltage_failures >= NUM_HIGH_VOLTAGE_WARNING) &&
                    (!meas.MeasCycleStatus.high_voltage_warning_sent))
                {
                    meas.AddWarningMessage("At least " + meas.MeasCycleStatus.num_high_voltage_failures + " high voltage failures", 7076, mkey);
                    meas.MeasCycleStatus.high_voltage_warning_sent = true;
                }
                if (meas.AcquireState.acquire_type == AcquireConvergence.CycleCount)
                {
                    meas.MeasCycleStatus.acquire_num_runs = meas.MeasCycleStatus.initial_num_runs +
                        meas.MeasCycleStatus.num_outlier_failures + meas.MeasCycleStatus.num_acc_sngl_failures +
                        meas.MeasCycleStatus.num_checksum_failures;
                }
                else if (meas.Cycles.GetValidCycleCountForThisKey(mkey) < 100) // an arbitrary limit, make it a config item
                {
                    // URGENT: set state to end of measurement so that state moves out of cycles and skips forward to CalculateMeasurementResults
                    // todo: see take_data.cpp line 733 for mass check processing steps
                    if (meas.Cycles.GetValidCycleCountForThisKey(mkey) > 1)
                    {
                        INCCResult results;
                        MeasOptionSelector ar = new MeasOptionSelector(meas.MeasOption, mkey);
                        bool found = meas.INCCAnalysisResults.TryGetValue(ar, out results);
                        double error = 0;
                        if (meas.AcquireState.acquire_type == AcquireConvergence.DoublesPrecision)
                        {
                            if (results.rates.DTCRates.Doubles.v != 0.0)
                            {
                                error = results.rates.DTCRates.Doubles.err / results.rates.DTCRates.Doubles.v * 100.0;
                            }
                        }
                        else if (meas.AcquireState.acquire_type == AcquireConvergence.TriplesPrecision)
                        {
                            if (results.rates.DTCRates.Triples.v != 0.0)
                            {
                                error = results.rates.DTCRates.Triples.err / results.rates.DTCRates.Triples.v * 100.0;
                            }
                        }
                        else if (meas.AcquireState.acquire_type == AcquireConvergence.Pu240EffPrecision)
                        {
                            RatesAdjustments dtchoice = RatesAdjustments.Raw; // NEXT: design out this choice everywhere, it shoud be a flag on the current computational state somewhere
                            INCCMethodResults.results_multiplicity_rec res = INCCAnalysis.CalculateMultiplicity(mkey, results.covariance_matrix, results.rates.GetDTCRates(dtchoice), meas, dtchoice);
                            if (res != null)
                            {
                                // the results obtained within the method are already stored on the result and they do not need to be copied here (VERIFY THIS)
                                if (res.pu240e_mass.v != 0.0)
                                {
                                    error = res.pu240e_mass.err /
                                        res.pu240e_mass.v * 100.0;
                                }
                                else
                                    error = 0.0;
                            }
                        }

                        meas.MeasCycleStatus.acquire_num_runs = (uint)((double)cc.seq * (error / meas.AcquireState.meas_precision) * (error / meas.AcquireState.meas_precision)) + 1;
                        meas.MeasCycleStatus.acquire_num_runs += meas.MeasCycleStatus.num_outlier_failures +
                            meas.MeasCycleStatus.num_acc_sngl_failures + meas.MeasCycleStatus.num_checksum_failures;
                    }
                    else
                        meas.MeasCycleStatus.acquire_num_runs = meas.AcquireState.max_num_runs;
                    if (meas.MeasCycleStatus.acquire_num_runs > meas.AcquireState.max_num_runs)
                        meas.MeasCycleStatus.acquire_num_runs = meas.AcquireState.max_num_runs;
                    if (meas.MeasCycleStatus.acquire_num_runs < meas.AcquireState.min_num_runs)
                        meas.MeasCycleStatus.acquire_num_runs = meas.AcquireState.min_num_runs;
                }
            }
        }
Example #5
0
        /// <summary>
        /// Do the third phase  . . .
        /// From calc_res.cpp,
        /// </summary>
        public static void CalculateResults(this Measurement meas)
        {
            IEnumerator iter = meas.CountingAnalysisResults.GetMultiplicityEnumerator();
            while (iter.MoveNext())
            {
                Multiplicity mkey = (Multiplicity)((KeyValuePair<SpecificCountingAnalyzerParams, object>)(iter.Current)).Key;
                if (NC.App.Opstate.IsAbortRequested)
                    return;

                INCCResult results;
                MeasOptionSelector ar = new MeasOptionSelector(meas.MeasOption, mkey);
                bool found = meas.INCCAnalysisResults.TryGetValue(ar, out results);
                if (!found)
                {
                    meas.AddErrorMessage("No results available", 10151, mkey);
                    return;
                }
                /* if using measure to precision, and max # runs reached, then add warning message indicating actual precision reached. */
                if (meas.AcquireState.acquire_type == AcquireConvergence.DoublesPrecision)
                {
                    if (results.rates.DTCRates.DoublesRate != 0.0)
                    {
                        double error = results.rates.DTCRates.Doubles.err / results.rates.DTCRates.DoublesRate * 100.0;
                        if (error > meas.AcquireState.meas_precision)
                        {
                            meas.AddWarningMessage("Measurement doubles error = " + error.ToString("F2"), 10126, mkey);
                        }
                    }
                }
                else if (meas.AcquireState.acquire_type == AcquireConvergence.TriplesPrecision)
                {
                    if (results.rates.DTCRates.TriplesRate != 0.0)
                    {
                        double error = results.rates.DTCRates.Triples.err / results.rates.DTCRates.TriplesRate * 100.0;
                        if (error > meas.AcquireState.meas_precision)
                        {
                            meas.AddWarningMessage("Measurement triples error = " + error.ToString("F2"), 10127, mkey);
                        }
                    }
                }

                if (meas.MeasOption == AssaySelector.MeasurementOption.rates)   // Doug  Requirement #2
                {
                    // for a rates only measurement, all done!
                    meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10180, "Rates Only measurement complete");
                    continue;
                }

                try
                {
                    switch (meas.MeasOption)
                    {
                        case AssaySelector.MeasurementOption.background: // Doug  Requirement #3
                            // a bkg is an average over a bunch of cycles with only the deadtime correction applied,
                            // but note the variant for Truncated Mult background, where an additional calculation is made

                            if (results.rates.DTCRates.DoublesRate > meas.Tests.bkgDoublesRateLimit)
                                meas.AddWarningMessage("Background doubles rate " + results.rates.DTCRates.DoublesRate + " greater than " + meas.Tests.bkgDoublesRateLimit, 10141, mkey);
                            if (results.rates.DTCRates.TriplesRate > meas.Tests.bkgTriplesRateLimit)
                                meas.AddWarningMessage("Background triples rate " + results.rates.DTCRates.TriplesRate + " greater than " + meas.Tests.bkgTriplesRateLimit, 10142, mkey);

                            // dev note: this is a background measurement per se, so we copy the results to the Background class and store the entire thing that way
                            // NEXT: Need to account for Active bkg beginning here.

                            if (Integ.GetCurrentAcquireParams().well_config == WellConfiguration.Active)// Is an active acquisition.
                            {
                                meas.Background.INCCActive.CopyFrom(results.rates.DeadtimeCorrectedRates);
                            }
                            else
                                meas.Background.CopyFrom(results.rates);
                            //  maybe if (INCCAnalysisState.Methods.Has(AnalysisMethod.TruncatedMultiplicity))
                            if (meas.Background.TMBkgParams.ComputeTMBkg)
                                // Trunc Mult Bkg step, calc_tm_rates, sets TM bkg rates on Measurement.Background
                                INCCAnalysis.calc_tm_rates(mkey, results, meas, meas.Background.TMBkgParams, meas.Detector.Id.SRType);

                            meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10181, "Background measurement complete");
                            break;
                        case AssaySelector.MeasurementOption.initial:

                            INCCResults.results_init_src_rec results_init_src = (INCCResults.results_init_src_rec)results;

                            meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10182, "Calculating Initial source measurement results");
                            bool funhappy = INCCAnalysis.initial_source_meas(meas, mkey, RatesAdjustments.DeadtimeCorrected);
                            if (!funhappy || !results_init_src.pass)
                            {
                                meas.AddWarningMessage("Initial source measurement failed", 10123, mkey);
                            }
                            // on fail, only the relevant results_init_src_rec is saved
                            // on pass, the normalization parameters are modified with the results_init_src_rec results, and so both are udpated.
                            break;
                        case AssaySelector.MeasurementOption.normalization:

                            meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10183, "Calculating Normalization measurement results");
                            bool happyfun = INCCAnalysis.bias_test(meas, mkey, RatesAdjustments.DeadtimeCorrected);
                            if (!happyfun)
                            {
                                meas.AddWarningMessage("Normalization test -- data quality is inadequate", 10124, mkey);
                            }
                            break;
                        case AssaySelector.MeasurementOption.precision:

                            meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10184, "Calculating Precision measurement results");
                            bool charmyfun = INCCAnalysis.precision_test(meas, mkey, RatesAdjustments.DeadtimeCorrected);
                            if (!charmyfun)
                            {
                                meas.AddWarningMessage("Precision test failed", 10125, mkey);
                            }
                            break;
                        case AssaySelector.MeasurementOption.calibration: // from calc_res.cpp
                            if (meas.INCCAnalysisState.Methods.CalibrationAnalysisSelected())
                            {
                                meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10185, "Calculating Calibration measurement results");
                                // dev note: since the analysis routines have similar signatures, design a class OK?
                                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.CalibrationCurve))
                                {
                                    meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10191, "Calculating " + AnalysisMethod.CalibrationCurve.FullName() + " measurement results");
                                    // get the current results_cal_curve_rec
                                    INCCMethodResults.results_cal_curve_rec ccres = (INCCMethodResults.results_cal_curve_rec)
                                        meas.INCCAnalysisResults.LookupMethodResults(mkey, meas.INCCAnalysisState.Methods.selector, AnalysisMethod.CalibrationCurve, true);

                                    INCCAnalysisParams.cal_curve_rec cal_curve = (INCCAnalysisParams.cal_curve_rec)meas.INCCAnalysisState.Methods.GetMethodParameters(AnalysisMethod.CalibrationCurve);
                                    ccres.methodParams = new INCCAnalysisParams.cal_curve_rec(cal_curve);

                                    double pu_mass = ccres.pu_mass.v;
                                    meas.Isotopics.UpdateDeclaredPuMass(meas.MeasDate, ref pu_mass, INCCAnalysis.INCCParity);
                                    ccres.pu_mass.v = pu_mass;
                                    ccres.pu_mass.err = 0.0;
                                    ccres.pu240e_mass.err = 0.0;

                                    double pu240e_mass = ccres.pu240e_mass.v;
                                    meas.Isotopics.calc_pu240e(pu_mass, out pu240e_mass, meas);
                                    ccres.pu240e_mass.v = pu240e_mass;

                                }
                                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.KnownA))
                                {
                                    meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10192, "Calculating " + AnalysisMethod.KnownA.FullName() + " calibration results");
                                    INCCMethodResults.results_known_alpha_rec kares = INCCAnalysis.CalculateKnownAlpha(mkey, results.rates, meas, RatesAdjustments.DeadtimeCorrected);
                                    if (kares == null)
                                    {
                                        meas.AddErrorMessage("Known alpha analysis error", 10153, mkey);
                                    }
                                    else
                                    {
                                        kares.pu_mass.v = meas.AcquireState.mass;
                                        double pu_mass = kares.pu_mass.v;
                                        meas.Isotopics.UpdateDeclaredPuMass(meas.MeasDate, ref pu_mass, INCCAnalysis.INCCParity);
                                        kares.pu_mass.v = pu_mass;
                                        kares.pu_mass.err = 0.0;
                                        kares.pu240e_mass.err = 0.0;

                                        double pu240e_mass = kares.pu240e_mass.v;
                                        meas.Isotopics.calc_pu240e(pu_mass, out pu240e_mass, meas);
                                        kares.pu240e_mass.v = pu240e_mass;
                                    }
                                }
                                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.Active))
                                {
                                    meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10192, "Arranging " + AnalysisMethod.Active.FullName() + " calibration results");

                                    INCCSelector sel = new INCCSelector(meas.INCCAnalysisState.Methods.selector);
                                    INCCAnalysisParams.active_rec act;
                                    INCCAnalysisParams.INCCMethodDescriptor surr = meas.INCCAnalysisState.Methods.GetMethodParameters(AnalysisMethod.Active);
                                    if (surr == null)
                                    {
                                        act = new INCCAnalysisParams.active_rec();
                                        meas.INCCAnalysisState.Methods.AddMethod(AnalysisMethod.Active, act);
                                    }
                                    else
                                    {
                                        act = (INCCAnalysisParams.active_rec)surr;
                                    }
                                    INCCMethodResults.results_active_rec res;
                                    res = (INCCMethodResults.results_active_rec)meas.INCCAnalysisResults.LookupMethodResults(mkey, sel, AnalysisMethod.Active, true);

                                    // all this does is copy the declared mass over to the results, WTF
                                    res.u235_mass.v = meas.AcquireState.mass;

                                }
                                if (meas.INCCAnalysisState.Methods.Has(AnalysisMethod.AddASource))
                                {
                                    meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10152, "Calculating " + AnalysisMethod.AddASource.FullName() + " calibration results");
                                    INCCSelector sel = new INCCSelector(meas.INCCAnalysisState.Methods.selector);
                                    INCCAnalysisParams.add_a_source_rec aas;
                                    INCCMethodResults.results_add_a_source_rec acres;
                                    INCCAnalysisParams.INCCMethodDescriptor surr = meas.INCCAnalysisState.Methods.GetMethodParameters(AnalysisMethod.AddASource);
                                    if (surr == null)
                                    {
                                        aas = new INCCAnalysisParams.add_a_source_rec();
                                        meas.INCCAnalysisState.Methods.AddMethod(AnalysisMethod.AddASource, aas);
                                    }
                                    else
                                    {
                                        aas = (INCCAnalysisParams.add_a_source_rec)surr;
                                    }
                                    acres = (INCCMethodResults.results_add_a_source_rec)meas.INCCAnalysisResults.LookupMethodResults(mkey, sel, AnalysisMethod.AddASource, true);

                                    acres.pu_mass.v = meas.AcquireState.mass;
                                    // update_declared_pu_mass
                                    double pu_mass = acres.pu_mass.v;
                                    meas.Isotopics.UpdateDeclaredPuMass(meas.MeasDate, ref pu_mass, INCCAnalysis.INCCParity);
                                    acres.pu_mass.v = pu_mass;
                                    acres.pu_mass.err = 0.0;
                                    acres.pu240e_mass.err = 0.0;

                                    double pu240e_mass = acres.pu240e_mass.v;
                                    meas.Isotopics.calc_pu240e(pu_mass, out pu240e_mass, meas);
                                    acres.pu240e_mass.v = pu240e_mass;

                                }
                            }
                            else
                            {
                                meas.AddErrorMessage("No Calibration analysis methods selected", 10153, mkey);
                            }
                            break;
                        case AssaySelector.MeasurementOption.verification:
                            // see INCC calc_asy.cpp
                            // dev note: check for item in the item table, make sure to place this item id on the MeasurementId.item property
                            if (!string.IsNullOrEmpty(meas.AcquireState.item_id))
                            {
                                meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10194, "Using item id '{0}'", meas.AcquireState.item_id);
                            }
                            else
                                meas.Logger.TraceEvent(NCCReporter.LogLevels.Verbose, 10194, "No item id");

                            if (meas.INCCAnalysisState.Methods.VerificationAnalysisSelected())
                            {
                                meas.Logger.TraceEvent(NCCReporter.LogLevels.Info, 10186, "Calculating {0} measurement results", meas.MeasOption.PrintName());

                                meas.CalculateVerificationResults(mkey, results);
                            }
                            else
                            {
                                meas.AddErrorMessage("No analysis methods selected", 10156, mkey);
                            }
                            break;
                        case AssaySelector.MeasurementOption.holdup:   // NEXT: Hold-up held up, implement it #35
                            meas.Logger.TraceEvent(NCCReporter.LogLevels.Error, 10187, "Holdup analysis unsupported");
                            break;
                    }
                }
                catch (Exception e)
                {
                    meas.Logger.TraceException(e);
                }
            }
        }