Beispiel #1
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
                    // JFL copy the input calib to the results rec
                    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,
                                    new Tuple(), new Tuple(), // todo: use scalers
                                    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,
                                    new Tuple(), new Tuple(), // todo: use scalers 
                                    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.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.CalculateActivePassive(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);
            }

        }