Пример #1
0
        /// <summary>
        /// Create parameter list for the results on a cycle
        /// </summary>
        /// <param name="mkey">The multiplicity parameters used to select the specific results. There can be more than one such results set per cycle.</param>
        public void GenParamList(Multiplicity mkey)
        {
            GenParamList(); // ^ does the basic INCC5 and new LM cycle stuff

            // now add the mkey stuff
            Table = "cycles";
            MultiplicityCountingRes pmcr = null;
            QCTestStatus status = QCTestStatus.None;
            if (CountingAnalysisResults.HasMultiplicity)
                try
                {
                    pmcr = (MultiplicityCountingRes)CountingAnalysisResults[mkey];
                    status = qcstatus[mkey].status;
                }
                catch (Exception) // mkey not found happens when a param is changed on a VSR that is not reflected back to the default [0] SR
                {
                    logger.TraceEvent(LogLevels.Warning, 7832, "Cycle status not set in DB, mkey mismatch: " + mkey.ToString());
                }
            if (pmcr == null)
                pmcr = new MultiplicityCountingRes();  // null results
            ps.Add(new DBParamEntry("scaler1", pmcr.Scaler1.v));
            ps.Add(new DBParamEntry("scaler2", pmcr.Scaler2.v));
            ps.Add(new DBParamEntry("reals_plus_acc", pmcr.RASum));
            ps.Add(new DBParamEntry("acc", pmcr.ASum));
            ps.Add(new DBParamEntry("mult_reals_plus_acc", pmcr.RAMult));
            ps.Add(new DBParamEntry("mult_acc", pmcr.NormedAMult));
            ps.Add(new DBParamEntry("scaler1_rate", pmcr.Scaler1Rate.v));
            ps.Add(new DBParamEntry("scaler2_rate", pmcr.Scaler2Rate.v));
            ps.Add(new DBParamEntry("doubles_rate", pmcr.RawDoublesRate.v));
            ps.Add(new DBParamEntry("triples_rate", pmcr.RawTriplesRate.v));
            ps.Add(new DBParamEntry("multiplicity_mult", pmcr.multiplication));
            ps.Add(new DBParamEntry("multiplicity_alpha", pmcr.multiAlpha));
            ps.Add(new DBParamEntry("multiplicity_efficiency", pmcr.efficiency));
            ps.Add(new DBParamEntry("mass", pmcr.mass));
            ps.Add(new DBParamEntry("status", (int)status));
            {	// la super hack-a-whack
                DB.DB db = new DB.DB(true);
                if (db.TableHasColumn(Table,"mult_acc_un"))
                    ps.Add(new DBParamEntry("mult_acc_un", pmcr.UnAMult));
            }
        }
Пример #2
0
 public bool Transfer(Multiplicity mup, MultiplicityResult mr, int idx)
 {
     if (mr == null)
         return true;
     bool res = true;
     try
     {
         SetQCStatus(mup, QCTestStatus.Pass);  // marked Pass at the outset
         MultiplicityCountingRes lmcs = new MultiplicityCountingRes(mup.FA, idx);
         countresults.Add(mup, lmcs);
         lmcs.Totals = Totals;
         lmcs.TransferRawResult(mr);
         lmcs.TS = new TimeSpan(TS.Ticks);
     }
     catch (OutOfMemoryException e)
     {
         mup.reason = "Multiplicity transfer " + e.Message;
         res = false;
         logger.TraceEvent(LogLevels.Error, 87406,  mup.reason);
     }
     return res;
 }
Пример #3
0
        void AddTestDataCycle(int run, uint run_seconds, double run_count_time, Measurement meas, TestDataFile td, string pivot = "", int cfindex = -1)
        {
            Cycle cycle = new Cycle(datalog);
            try
            {
                cycle.UpdateDataSourceId(ConstructedSource.CycleFile, meas.Detectors[0].Id.SRType,
                        td.DTO.AddSeconds(run_seconds), td.Filename);
                cycle.seq = run;
                cycle.TS = TimeSpan.FromSeconds(run_count_time);  // dev note: check if this is always only in seconds, or fractions of a second
                                                                  // hn -- 9/4/14 -- not integer for count time.  Convert from double seconds here.
                                                                  // Joe still has force to int.  bleck!

                /* init run tests */
                cycle.SetQCStatus(meas.Detectors[0].MultiplicityParams, QCTestStatus.None); // multmult creates entry if not found
                meas.Add(cycle, cfindex);
                /* singles, reals + accidentals, accidentals */
                string l = td.reader.ReadLine();
                string[] zorks = l.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
                double[] v = new double[5];
                for (int z = 0; z < 5; z++)
                {
                    double d;
                    bool b = Double.TryParse(zorks[z], out d);
                    if (b)
                        v[z] = d;
                }
                cycle.Totals = (ulong)v[0];
                MultiplicityCountingRes mcr = new MultiplicityCountingRes(meas.Detectors[0].MultiplicityParams.FA, cycle.seq); // multmult
                cycle.CountingAnalysisResults.Add(meas.Detectors[0].MultiplicityParams, mcr);  // multmult
                mcr.AB.TransferIntermediates(meas.Detectors[0].AB);  // copy alpha beta onto the cycle's results 
                mcr.Totals = cycle.Totals;
                mcr.TS = cycle.TS;
                mcr.ASum = v[4];
                mcr.RASum = v[3];
                mcr.Scaler1.v = v[1];
                mcr.Scaler2.v = v[2];
                cycle.SinglesRate = v[0] / run_count_time;

                // assign the hits to a single channel (0)
                cycle.HitsPerChannel[0] = cycle.Totals;

                mcr.RawSinglesRate.v = cycle.SinglesRate;

                /* number of multiplicity values */
                string mv = td.reader.ReadLine();
                UInt16 k = 0;
                UInt16.TryParse(mv, out k);
                if (k == 0)  // test data files require an entry with 1 bin set 0s for the absence of multiplicity, go figure
                {
                    ctrllog.TraceEvent(LogLevels.Error, 440, "This" + pivot + " cycle " + run.ToString() + " has no good multiplicity data.");
                    return;
                }
                mcr.MinBins = mcr.MaxBins = k;
                mcr.RAMult = new ulong[k];
                mcr.NormedAMult = new ulong[k];
                mcr.UnAMult = new ulong[k]; // todo: compute this
                /* multiplicity values */
                for (UInt16 j = 0; j < k; j++)
                {
                    string ra = td.reader.ReadLine();
                    string[] blorks = ra.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
                    double[] ve = new double[2];
                    for (int z = 0; z < 2; z++)
                    {
                        double d;
                        bool b = Double.TryParse(blorks[z], out d);
                        if (b)
                            ve[z] = d;
                    }
                    mcr.RAMult[j] = (ulong)ve[0];
                    mcr.NormedAMult[j] = (ulong)ve[1];
                }
                ctrllog.TraceEvent(LogLevels.Verbose, 5439, "Cycle " + cycle.seq.ToString() + pivot + ((mcr.RAMult[0] + mcr.NormedAMult[0]) > 0 ? " max:" + mcr.MaxBins.ToString() : " *"));

            }
            catch (Exception e)
            {
                ctrllog.TraceEvent(LogLevels.Warning, 33085, pivot + "cycle processing error {0} {1} {2}", run, e.Message, pivot);
            }
        }
Пример #4
0
        unsafe void AddReviewFileCycle(int i, run_rec_ext run, INCCReviewFile.run_rec_ext_plus rrep, Measurement meas, string fn)
        {
            Cycle cycle = new Cycle(datalog);
            try
            {
                cycle.UpdateDataSourceId(ConstructedSource.ReviewFile, meas.Detectors[0].Id.SRType,
                        rrep.dt, fn);
                cycle.seq = (run.run_number > 0 ? run.run_number : i); // INCC run record sequence numbers start at 1
                cycle.TS = TimeSpan.FromSeconds(run.run_count_time);

                /* init run tests */
                cycle.SetQCStatus(meas.Detectors[0].MultiplicityParams, QCTestStatus.Pass, run.run_high_voltage); // multmult creates entry if not found
                meas.Add(cycle);
                /* singles, reals + accidentals, accidentals */
                cycle.Totals = (ulong)run.run_singles;
                MultiplicityCountingRes mcr = new MultiplicityCountingRes(meas.Detectors[0].MultiplicityParams.FA, cycle.seq); // multmult
                cycle.CountingAnalysisResults.Add(meas.Detectors[0].MultiplicityParams, mcr); // multmult
                mcr.AB.TransferIntermediates(meas.Detectors[0].AB);  // copy alpha beta onto the cycle's results 
                mcr.Totals = cycle.Totals;
                mcr.TS = cycle.TS;
                mcr.ASum = run.run_acc;
                mcr.RASum = run.run_reals_plus_acc;
                mcr.Scaler1.v = run.run_scaler1;
                mcr.Scaler2.v = run.run_scaler2;
                cycle.SinglesRate = run.run_singles / run.run_count_time;

                // assign the hits to a single channel (0)
                cycle.HitsPerChannel[0] = cycle.Totals;

                mcr.RawSinglesRate.v = cycle.SinglesRate;

                // now back-compute the actual limits of the bins
                for (int n = rrep.n_mult - 1; n >= 0; n--)
                {
                    if ((run.run_mult_reals_plus_acc[n] > 0.0) || (run.run_mult_acc[n] > 0.0))
                    {
                        mcr.MinBins = mcr.MaxBins = (ulong)(n + 1);
                        break;
                    }
                }
                mcr.RAMult = new ulong[mcr.MaxBins];
                mcr.NormedAMult = new ulong[mcr.MaxBins];
                mcr.UnAMult = new ulong[mcr.MaxBins]; // todo: compute this

                // copy the bin values, if any
                for (UInt16 j = 0; j < mcr.MaxBins; j++)
                {
                    mcr.RAMult[j] = (ulong)run.run_mult_reals_plus_acc[j];
                    mcr.NormedAMult[j] = (ulong)run.run_mult_acc[j];
                }
                ctrllog.TraceEvent(LogLevels.Verbose, 5439, "Cycle " + cycle.seq.ToString() + (rrep.n_mult > 0 ? " n_:" + rrep.n_mult.ToString() + " max:" + mcr.MaxBins.ToString() : " *"));
            }
            catch (Exception e)
            {
                ctrllog.TraceEvent(LogLevels.Warning, 33085, "Cycle processing error {0} {1}", run, e.Message);
            }
        }
Пример #5
0
        /// <summary>
        ///  Create the cycle counting results, add it to the measurement and copy the data from the run to the equivalent fields on the cycle
        /// </summary>
        /// <param name="run"></param>
        /// <param name="cycle"></param>
        public static unsafe MultiplicityCountingRes RunToCycle(run_rec run, Cycle cycle, Multiplicity key)
        {
            cycle.seq = run.run_number;
            cycle.TS = new TimeSpan(0, 0, (int)run.run_count_time);  // dev note: check if this is always only in seconds, or fractions of a second

            cycle.Totals = (ulong)run.run_singles;
            cycle.SinglesRate = run.run_singles / run.run_count_time; // use this value in the conditioning steps, it is not yet the DT corrected rate

            string s = TransferUtils.str(run.run_tests, INCC.MAX_RUN_TESTS_LENGTH);
            QCTestStatus qcts = QCTestStatusExtensions.FromString(s);

            cycle.SetQCStatus(key, qcts); // creates entry if not found

            MultiplicityCountingRes mcr = new MultiplicityCountingRes(key.FA, cycle.seq);
            cycle.CountingAnalysisResults.Add(key, mcr);
            mcr.Totals = cycle.Totals;
            mcr.TS = cycle.TS;

            mcr.DeadtimeCorrectedSinglesRate.v = run.run_singles_rate; // overridden later, not used
            mcr.DeadtimeCorrectedDoublesRate.v = run.run_doubles_rate;
            mcr.DeadtimeCorrectedTriplesRate.v = run.run_triples_rate;

            mcr.RASum = (ulong)run.run_reals_plus_acc;
            mcr.ASum = (ulong)run.run_acc;

            mcr.efficiency = run.run_multiplicity_efficiency;
            mcr.mass = run.run_mass;
            mcr.multiAlpha = run.run_multiplicity_alpha;
            mcr.multiplication = run.run_multiplicity_mult;
            cycle.HighVoltage = run.run_high_voltage;

            // assign the hits to a single channel (0)
            cycle.HitsPerChannel[0] = run.run_singles;
            mcr.RawSinglesRate.v = run.run_singles_rate;
            mcr.RawDoublesRate.v = run.run_doubles_rate;
            mcr.RawTriplesRate.v = run.run_triples_rate;

            mcr.Scaler1.v = run.run_scaler1;
            mcr.Scaler2.v = run.run_scaler2;
            mcr.Scaler1Rate.v = run.run_scaler1_rate;
            mcr.Scaler2Rate.v = run.run_scaler2_rate;

            mcr.RAMult = TransferUtils.multarrayxfer(run.run_mult_reals_plus_acc, INCC.MULTI_ARRAY_SIZE);
            mcr.NormedAMult = TransferUtils.multarrayxfer(run.run_mult_acc, INCC.MULTI_ARRAY_SIZE);
            mcr.MaxBins = (ulong)Math.Max(mcr.RAMult.Length, mcr.NormedAMult.Length);
            mcr.MinBins = (ulong)Math.Min(mcr.RAMult.Length, mcr.NormedAMult.Length);
            mcr.UnAMult = new ulong[mcr.MaxBins]; // todo: compute this
            return mcr;
        }
Пример #6
0
        public unsafe void BuildDetector(INCCInitialDataDetectorFile iddf, int num)
        {
            INCCDB DB = NC.App.DB;

            detector_rec d = iddf.Detector[0];
            sr_parms_rec sr = iddf.SRParms[0];
            bkg_parms_rec bkh = iddf.BKGParms[0];
            norm_parms_rec norm = iddf.NormParms[0];
            tm_bkg_parms_rec tmbkg = iddf.TMBKGParms[0];
            add_a_source_setup_rec aass = iddf.AASParms[0];

            InstrType srtype = (InstrType)sr.sr_type;

            bool overwrite = NC.App.AppContext.OverwriteImportedDefs;

            mlogger.TraceEvent(LogLevels.Verbose, 34100, "Building '{0}' detector '{1}' from {2} {3}",
                                srtype.ToString(),
                                TransferUtils.str(d.detector_id, INCC.MAX_DETECTOR_ID_LENGTH),
                                num, iddf.Path);

            // if the detector is not known internally, then
            //        add the detector to the list of detectors in memory, and
            //        associate a new set of SR, Bkg and Norm and AB params with the new detector
            // todo: What are the HV Params from INCC5, and once that is known, can they be transferred to the INCC6 HV Param and results tables
            Detector det = new Detector();
            if (srtype.IsListMode())
                det.Id.FullConnInfo = new LMConnectionInfo();

            try
            {
                // this transfer should be a method in this class, it will be used elsewhere too
                det.Id.DetectorId = TransferUtils.str(d.detector_id, INCC.MAX_DETECTOR_ID_LENGTH);
                det.Id.SRType = srtype;
                det.Id.Type = TransferUtils.str(d.detector_type, INCC.DETECTOR_TYPE_LENGTH);
                det.Id.ElectronicsId = TransferUtils.str(d.electronics_id, INCC.ELECTRONICS_ID_LENGTH);
                det.Id.ConnInfo = sr.sr_port_number.ToString();
                det.Id.source = ConstructedSource.INCCTransferCopy;
                det.MultiplicityParams.FA = srtype.DefaultFAFor();
                det.MultiplicityParams.gateWidthTics = (ulong)(sr.gate_length * 10.0);  // shift down to tics from microseconds
                det.SRParams.deadTimeCoefficientAinMicroSecs = sr.coeff_a_deadtime;
                det.SRParams.deadTimeCoefficientBinPicoSecs = sr.coeff_b_deadtime;
                det.SRParams.deadTimeCoefficientCinNanoSecs = sr.coeff_c_deadtime;
                det.SRParams.deadTimeCoefficientMultiplicityinNanoSecs = sr.multiplicity_deadtime;
                det.SRParams.dieAwayTime = sr.die_away_time * 10.0;  // shift down to tics from microseconds
                det.SRParams.doublesGateFraction = sr.doubles_gate_fraction;
                det.SRParams.efficiency = sr.efficiency;
                det.SRParams.gateLength = (ulong)(sr.gate_length * 10.0);  // shift down to tics from microseconds
                //det.SRParams.gateLength2 = sr.gate_length2;
                det.SRParams.highVoltage = sr.high_voltage;
                det.SRParams.predelay = (ulong)(sr.predelay * 10.0);  // shift down to tics from microseconds
                det.SRParams.triplesGateFraction = sr.triples_gate_fraction;
                //    = sr.sr_type , sr.sr_port_number, sr.sr_detector_id  these are in the Id now, not the SRparams, but they travel together.

                if (NC.App.AppContext.OverwriteImportedDefs)
                    DB.Detectors.Replace(det);
                else
                    DB.Detectors.AddOnlyIfNotThere(det);
                DetectorIndex = DB.Detectors.Count - 1;

                BackgroundParameters bkg = new BackgroundParameters();
                bkg.DeadtimeCorrectedRates.Singles.v = bkh.curr_passive_bkg_singles_rate;
                bkg.DeadtimeCorrectedRates.Doubles.v = bkh.curr_passive_bkg_doubles_rate;
                bkg.DeadtimeCorrectedRates.Triples.v = bkh.curr_passive_bkg_triples_rate;
                bkg.DeadtimeCorrectedRates.Singles.err = bkh.curr_passive_bkg_singles_err;
                bkg.DeadtimeCorrectedRates.Doubles.err = bkh.curr_passive_bkg_doubles_err;
                bkg.DeadtimeCorrectedRates.Triples.err = bkh.curr_passive_bkg_triples_err;
                bkg.Scaler1.v = bkh.curr_passive_bkg_scaler1_rate;
                bkg.Scaler2.v = bkh.curr_passive_bkg_scaler2_rate;
                bkg.INCCActive.Singles.v = bkh.curr_active_bkg_singles_rate;
                bkg.INCCActive.Singles.err = bkh.curr_active_bkg_singles_err;
                bkg.INCCActive.Scaler1Rate = bkh.curr_active_bkg_scaler1_rate;
                bkg.INCCActive.Scaler2Rate = bkh.curr_active_bkg_scaler2_rate;
                bkg.TMBkgParams.Singles.v = tmbkg.tm_singles_bkg;
                bkg.TMBkgParams.Ones.v = tmbkg.tm_ones_bkg;
                bkg.TMBkgParams.Twos.v = tmbkg.tm_twos_bkg;
                bkg.TMBkgParams.Zeros.v = tmbkg.tm_zeros_bkg;
                bkg.TMBkgParams.Singles.err = tmbkg.tm_singles_bkg_err;
                bkg.TMBkgParams.Ones.err = tmbkg.tm_ones_bkg_err;
                bkg.TMBkgParams.Twos.err = tmbkg.tm_twos_bkg_err;
                bkg.TMBkgParams.Zeros.err = tmbkg.tm_zeros_bkg_err;
                bkg.TMBkgParams.ComputeTMBkg = (tmbkg.tm_bkg == 0 ? false : true);

                if (DB.BackgroundParameters.Get(det.Id.DetectorName) == null)
                {
                    DB.BackgroundParameters.GetMap().Add(det, bkg); // saved to DB at below
                }
                else if (overwrite)
                {
                    bkg.modified = true;
                    NC.App.DB.BackgroundParameters.GetMap().Remove(det);
                    NC.App.DB.BackgroundParameters.GetMap().Add(det, bkg);
                    NC.App.DB.BackgroundParameters.Set(det, bkg);
                }

                // save the params listed here using the detector as the key
                NormParameters normp = new NormParameters();
                normp.acceptanceLimitPercent = norm.acceptance_limit_percent;
                normp.acceptanceLimitStdDev = norm.acceptance_limit_std_dev;
                normp.amliRefSinglesRate = norm.amli_ref_singles_rate;
                normp.biasMode = OldToNewBiasTestId(norm.bias_mode);
                normp.biasPrecisionLimit = norm.bias_precision_limit;
                normp.biasTestAddasrcPosition = norm.bias_test_addasrc_position;
                normp.biasTestUseAddasrc = (norm.bias_test_use_addasrc == 0 ? false : true);
                normp.cf252RefDoublesRate.v = norm.cf252_ref_doubles_rate;
                normp.currNormalizationConstant.v = norm.curr_normalization_constant;
                normp.currNormalizationConstant.err = norm.curr_normalization_constant_err;
                normp.initSrcPrecisionLimit = norm.init_src_precision_limit;
                normp.measRate.v = norm.meas_rate;
                normp.measRate.err = norm.meas_rate_err;
                normp.refDate = INCC.DateFrom(TransferUtils.str(norm.ref_date, INCC.DATE_TIME_LENGTH));
                normp.sourceId = TransferUtils.str(norm.source_id, INCC.SOURCE_ID_LENGTH);
                normp.yieldRelativeToMrc95 = norm.yield_relative_to_mrc_95;

                if (DB.NormParameters.Get(det.Id.DetectorName) == null)
                {
                    DB.NormParameters.GetMap().Add(det, normp); // saved to DB at end
                }
                else if (overwrite)
                {
                    normp.modified = true;
                    DB.NormParameters.GetMap().Remove(det);
                    DB.NormParameters.GetMap().Add(det, normp); // the in-memory map
                    DB.NormParameters.Set(det, normp);  // the DB table
                }
                AddASourceSetup aassp = new AddASourceSetup();
                aassp.type = OldToNewAASId(aass.ad_type);
                aassp.port_number = aass.ad_port_number;
                aassp.forward_over_travel = aass.ad_forward_over_travel;
                aassp.reverse_over_travel = aass.ad_reverse_over_travel;
                aassp.number_positions = aass.ad_number_positions;
                aassp.dist_to_move = TransferUtils.Copy(aass.ad_dist_to_move, INCC.MAX_ADDASRC_POSITIONS);
                aassp.cm_steps_per_inch = aass.cm_steps_per_inch;
                aassp.cm_forward_mask = aass.cm_forward_mask;
                aassp.cm_reverse_mask = aass.cm_reverse_mask;
                aassp.cm_axis_number = aass.cm_axis_number;
                aassp.cm_over_travel_state = aass.cm_over_travel_state;
                aassp.cm_step_ratio = aass.cm_step_ratio;
                aassp.cm_slow_inches = aass.cm_slow_inches;
                aassp.plc_steps_per_inch = aass.plc_steps_per_inch;
                aassp.scale_conversion_factor = aass.scale_conversion_factor;
                aassp.cm_rotation = (aass.cm_rotation == 0 ? false : true);

                if (!DB.AASSParameters.GetMap().ContainsKey(det))
                {
                    DB.AASSParameters.GetMap().Add(det, aassp);
                }
                else if (overwrite)
                {
                    aassp.modified = true;
                    DB.AASSParameters.GetMap().Remove(det);
                    DB.AASSParameters.GetMap().Add(det, aassp); // todo: in-memory and db
                }
                if (!DB.UnattendedParameters.GetMap().ContainsKey(det))
                {
                    DB.UnattendedParameters.GetMap().Add(det, new UnattendedParameters());
                }
                else if (overwrite)
                {
                    DB.UnattendedParameters.GetMap().Remove(det);
                    DB.UnattendedParameters.GetMap().Add(det, new UnattendedParameters());
                }

                // the alpha beta arrays must be sized here, for first use by the calc_alpha_beta code in the cycle conditioning code
                Multiplicity mkey = new Multiplicity(srtype.DefaultFAFor());
                mkey.SR = new ShiftRegisterParameters(det.SRParams);
                MultiplicityCountingRes mcr = new MultiplicityCountingRes(srtype.DefaultFAFor(), 0);
                ABKey abkey = new ABKey(mkey, 512); // NEXT: maxbins is arbitrary
                LMRawAnalysis.SDTMultiplicityCalculator.SetAlphaBeta(abkey, det.AB);
                mcr.AB.TransferIntermediates(det.AB);
            }
            catch (Exception e)
            {
                mlogger.TraceEvent(LogLevels.Warning, 34064, "Detector transfer processing error {0} {1} ({2})", det.Id.DetectorName, e.Message, System.IO.Path.GetFileName(iddf.Path));
            }
        }
Пример #7
0
 void Bloat(ulong _MaxBins, MultiplicityCountingRes amcr)
 {
     ulong[] RA = new ulong[_MaxBins];
     ulong[] NA = new ulong[_MaxBins];
     ulong[] UNA = new ulong[_MaxBins];
     amcr.MaxBins = _MaxBins;
     Array.Copy(amcr.RAMult, RA, amcr.RAMult.Length); // adds trailing 0s by leaving them untouched
     Array.Copy(amcr.NormedAMult, NA, amcr.NormedAMult.Length); // adds trailing 0s
     Array.Copy(amcr.UnAMult, UNA, amcr.UnAMult.Length); // adds trailing 0s
     amcr.RAMult = RA;
     amcr.NormedAMult = NA;
     amcr.UnAMult = UNA;
 }
Пример #8
0
            internal static unsafe results_rec MoveResultsRec(Measurement m)
            {
                results_rec rec = new results_rec();
                byte[] b = StringSquish(m.MeasDate.ToString("yy.MM.dd"), INCC.DATE_TIME_LENGTH);
                TransferUtils.Copy(b, rec.meas_date);
                TransferUtils.Copy(b, rec.original_meas_date);  // this value is now properly tracked in INCC6
                b = StringSquish(m.MeasDate.ToString("HH:mm:ss"), INCC.DATE_TIME_LENGTH);
                TransferUtils.Copy(b, rec.meas_time);

                b = StringSquish(System.IO.Path.GetFileName(m.MeasurementId.FileName), INCC.FILE_NAME_LENGTH);
                TransferUtils.Copy(b, rec.filename);

                b = StringSquish(m.AcquireState.facility.Name, INCC.FACILITY_LENGTH);
                TransferUtils.Copy(b, rec.results_facility);
                b = StringSquish(m.AcquireState.mba.Name, INCC.MBA_LENGTH);
                TransferUtils.Copy(b, rec.results_mba);
                b = StringSquish(m.AcquireState.stratum_id.Name, INCC.MAX_STRATUM_ID_LENGTH);
                TransferUtils.Copy(b, rec.stratum_id);
                b = StringSquish(m.AcquireState.facility.Desc, INCC.DESCRIPTION_LENGTH);
                TransferUtils.Copy(b, rec.results_facility_description);
                b = StringSquish(m.AcquireState.mba.Desc, INCC.DESCRIPTION_LENGTH);
                TransferUtils.Copy(b, rec.results_mba_description);
                b = StringSquish(m.AcquireState.stratum_id.Desc, INCC.DESCRIPTION_LENGTH);
                TransferUtils.Copy(b, rec.stratum_id_description);

                b = StringSquish(m.AcquireState.item_id, INCC.MAX_ITEM_ID_LENGTH);
                TransferUtils.Copy(b, rec.item_id);

                b = StringSquish(m.AcquireState.campaign_id, INCC.MAX_CAMPAIGN_ID_LENGTH);
                TransferUtils.Copy(b, rec.results_campaign_id);
                TransferUtils.Copy(b, rec.results_inspection_number);

                b = StringSquish(m.AcquireState.item_type, INCC.MAX_ITEM_TYPE_LENGTH);
                TransferUtils.Copy(b, rec.results_item_type);

                rec.results_collar_mode = (byte)(m.AcquireState.collar_mode ? 1 : 0);

                b = StringSquish(m.Detector.Id.DetectorId, INCC.MAX_DETECTOR_ID_LENGTH);
                TransferUtils.Copy(b, rec.results_detector_id);
                b = StringSquish(m.Detector.Id.Type, INCC.DETECTOR_TYPE_LENGTH);
                TransferUtils.Copy(b, rec.results_detector_type);
                b = StringSquish(m.Detector.Id.ElectronicsId, INCC.ELECTRONICS_ID_LENGTH);
                TransferUtils.Copy(b, rec.results_electronics_id);

                b = StringSquish(m.AcquireState.glovebox_id, INCC.MAX_GLOVEBOX_ID_LENGTH);
                TransferUtils.Copy(b, rec.results_glovebox_id);
                rec.results_num_rows = m.INCCAnalysisResults.TradResultsRec.hc.num_rows;
                rec.results_num_columns = m.INCCAnalysisResults.TradResultsRec.hc.num_columns;
                rec.results_distance = m.INCCAnalysisResults.TradResultsRec.hc.distance;

                // devnote: full hc results record on a measurement is lost in the persist -> restore loop because upon 'read from DB' or restore we normally do not build out the TradResultsRec.
                rec.bias_uncertainty = m.Stratum.bias_uncertainty;
                rec.random_uncertainty = m.Stratum.random_uncertainty;
                rec.systematic_uncertainty = m.Stratum.systematic_uncertainty;
                rec.relative_std_dev = m.Stratum.relative_std_dev;

                b = StringSquish(m.AcquireState.inventory_change_code, INCC.INVENTORY_CHG_LENGTH);
                TransferUtils.Copy(b, rec.inventory_change_code);
                b = StringSquish(m.AcquireState.io_code, INCC.IO_CODE_LENGTH);
                TransferUtils.Copy(b, rec.io_code);

                rec.meas_option = (byte)m.MeasOption;

                rec.well_config = (byte)m.AcquireState.well_config;
                rec.data_source = (byte)m.AcquireState.data_src;
                rec.results_qc_tests = (byte)(m.AcquireState.qc_tests ? 1 : 0);
                rec.results_print = (byte)(m.AcquireState.print ? 1 : 0);
                rec.error_calc_method = (ushort) (m.AcquireState.error_calc_method == ErrorCalculationTechnique.Sample ? INCC.IDC_SAMPLE_STD_DEV : INCC.IDC_THEORETICAL_STD_DEV);

                b = StringSquish(m.AcquireState.user_id, INCC.CHAR_FIELD_LENGTH);
                TransferUtils.Copy(b, rec.user_id);
                b = StringSquish(m.AcquireState.comment, INCC.MAX_COMMENT_LENGTH);
                TransferUtils.Copy(b, rec.comment);
                b = StringSquish(m.AcquireState.ending_comment_str, INCC.MAX_COMMENT_LENGTH);
                TransferUtils.Copy(b, rec.ending_comment);

                rec.item_pu238 = m.Isotopics.pu238;
                rec.item_pu238_err = m.Isotopics.pu238_err;
                rec.item_pu239 = m.Isotopics.pu239;
                rec.item_pu239_err = m.Isotopics.pu239_err;
                rec.item_pu240 = m.Isotopics.pu240;
                rec.item_pu240_err = m.Isotopics.pu240_err;
                rec.item_pu241 = m.Isotopics.pu241;
                rec.item_pu241_err = m.Isotopics.pu241_err;
                rec.item_pu242 = m.Isotopics.pu242;
                rec.item_pu242_err = m.Isotopics.pu242_err;
                rec.item_am241 = m.Isotopics.am241;
                rec.item_am241 = m.Isotopics.am241_err;
                b = StringSquish(m.Isotopics.id, INCC.MAX_ISOTOPICS_ID_LENGTH);
                TransferUtils.Copy(b, rec.item_isotopics_id);
                b = StringSquish(m.Isotopics.source_code.ToString(), INCC.ISO_SOURCE_CODE_LENGTH);
                TransferUtils.Copy(b, rec.item_isotopics_source_code);

                rec.normalization_constant = m.Norm.currNormalizationConstant.v;
                rec.normalization_constant_err = m.Norm.currNormalizationConstant.err;

                rec.results_predelay = m.Detector.SRParams.predelayMS;
                rec.results_gate_length = m.Detector.SRParams.gateLengthMS;
                rec.results_gate_length2 = m.Detector.SRParams.gateLengthMS; // not used
                rec.results_high_voltage = m.Detector.SRParams.highVoltage;
                rec.results_die_away_time = m.Detector.SRParams.dieAwayTimeMS;
                rec.results_efficiency = m.Detector.SRParams.efficiency;
                rec.results_multiplicity_deadtime = m.Detector.SRParams.deadTimeCoefficientMultiplicityinNanoSecs;
                rec.results_coeff_a_deadtime = m.Detector.SRParams.deadTimeCoefficientAinMicroSecs;
                rec.results_coeff_b_deadtime = m.Detector.SRParams.deadTimeCoefficientBinPicoSecs;
                rec.results_coeff_c_deadtime = m.Detector.SRParams.deadTimeCoefficientCinNanoSecs;
                rec.results_doubles_gate_fraction = m.Detector.SRParams.triplesGateFraction;
                rec.results_triples_gate_fraction = m.Detector.SRParams.doublesGateFraction;

                // get the first results from the results map
                MultiplicityCountingRes mcr = null;
                if (m.CountingAnalysisResults.Count > 0 && m.CountingAnalysisResults.HasMultiplicity)
                    try
                    {
                        mcr = (MultiplicityCountingRes)m.CountingAnalysisResults[m.Detector.MultiplicityParams];
                    }
                    catch (Exception)
                    {
                        if (mcr == null)
                            mcr = m.CountingAnalysisResults.GetFirstMultiplicity;
                    }
                if (mcr == null)
                    mcr = new MultiplicityCountingRes();  // inadequate attempt tries to account for LM-only condition, where no mcr, or no matching mcr, exists

                rec.r_acc_sngl_test_rate_limit = m.Tests.accSnglTestRateLimit;
                rec.r_acc_sngl_test_precision_limit = m.Tests.accSnglTestPrecisionLimit;
                rec.r_acc_sngl_test_outlier_limit = m.Tests.accSnglTestOutlierLimit;
                rec.r_outlier_test_limit = m.Tests.outlierTestLimit;
                rec.r_bkg_doubles_rate_limit = m.Tests.bkgDoublesRateLimit;
                rec.r_bkg_triples_rate_limit = m.Tests.bkgTriplesRateLimit;
                rec.r_chisq_limit = m.Tests.chiSquaredLimit;
                rec.r_max_num_failures = m.Tests.maxNumFailures;
                rec.r_high_voltage_test_limit = m.Tests.highVoltageTestLimit;

                rec.r_normal_backup_assay_test_lim = m.Tests.normalBackupAssayTestLimit;
                rec.r_max_runs_for_outlier_test = m.Tests.maxCyclesForOutlierTest;
                rec.r_checksum_test = (byte)(m.Tests.checksum ? 1 : 0);
                rec.results_accidentals_method = (m.Tests.accidentalsMethod == AccidentalsMethod.Measure ? INCC.IDC_MEASURE_ACCIDENTALS : INCC.IDC_CALCULATE_ACCIDENTALS);

                rec.passive_bkg_singles_rate = m.Background.DeadtimeCorrectedRates.Singles.v;
                rec.passive_bkg_singles_rate_err = m.Background.DeadtimeCorrectedRates.Singles.err;
                rec.passive_bkg_doubles_rate = m.Background.DeadtimeCorrectedRates.Doubles.v;
                rec.passive_bkg_doubles_rate_err = m.Background.DeadtimeCorrectedRates.Doubles.err;
                rec.passive_bkg_triples_rate = m.Background.DeadtimeCorrectedRates.Triples.v;
                rec.passive_bkg_triples_rate_err = m.Background.DeadtimeCorrectedRates.Triples.err;
                rec.active_bkg_singles_rate = m.Background.INCCActive.Singles.v;
                rec.active_bkg_singles_rate_err = m.Background.INCCActive.Singles.err;
                rec.passive_bkg_scaler1_rate = m.Background.Scaler1.v;
                rec.passive_bkg_scaler2_rate = m.Background.Scaler2.v;
                rec.active_bkg_scaler1_rate = m.Background.INCCActive.Scaler1Rate;
                rec.active_bkg_scaler2_rate = m.Background.INCCActive.Scaler2Rate;

                List<MeasurementMsg> msgs = m.GetMessageList(m.Detector.MultiplicityParams);
                byte[] bb = new byte[INCC.NUM_ERROR_MSG_CODES * INCC.ERR_MSG_LENGTH];
                int indx = 0, recidx = 0;
                for (int i = 0; i < msgs.Count && recidx < INCC.NUM_ERROR_MSG_CODES; i++)
                {
                    if (msgs.Count > i && string.IsNullOrEmpty(msgs[i].text) && msgs[i].IsError)
                    {
                        char[] aa = msgs[i].text.ToCharArray(0, Math.Min(msgs[i].text.Length, INCC.ERR_MSG_LENGTH));
                        Encoding.ASCII.GetBytes(aa, 0, aa.Length, bb, indx);
                        recidx++;
                    }
                    indx += INCC.ERR_MSG_LENGTH;
                }
                TransferUtils.Copy(bb, 0, rec.error_msg_codes, 0, INCC.NUM_ERROR_MSG_CODES * INCC.ERR_MSG_LENGTH);
                bb = new byte[INCC.NUM_ERROR_MSG_CODES * INCC.ERR_MSG_LENGTH];
                indx = 0; recidx = 0;
                for (int i = 0; i < msgs.Count && recidx < INCC.NUM_ERROR_MSG_CODES; i++)
                {
                    if (msgs.Count > i && string.IsNullOrEmpty(msgs[i].text) && msgs[i].IsWarning)
                    {
                        char[] aa = msgs[i].text.ToCharArray(0, Math.Min(msgs[i].text.Length, INCC.ERR_MSG_LENGTH));
                        Encoding.ASCII.GetBytes(aa, 0, aa.Length, bb, indx);
                        recidx++;
                    }
                    indx += INCC.ERR_MSG_LENGTH;
                }
                TransferUtils.Copy(bb, 0, rec.warning_msg_codes, 0, INCC.NUM_ERROR_MSG_CODES * INCC.ERR_MSG_LENGTH);

                // these ride on, or can be computed from, m.Cycles, but they sum across multiple analyzers and so are not considered complete yet for LM measurements
                rec.total_number_runs = (ushort)m.Cycles.GetValidCycleCount(); // any and all cycles
                rec.number_good_runs = (ushort)m.Cycles.GetUseableCycleCount();  // those that are marked OK
                rec.total_good_count_time = (ushort)m.Cycles.GetUseableCycleCount() * m.AcquireState.run_count_time;  // check against time on first cycle, to assert

                rec.singles_sum = mcr.Totals;
                rec.scaler1_sum = mcr.S1Sum;
                rec.scaler2_sum = mcr.S2Sum;
                rec.reals_plus_acc_sum = mcr.RASum;
                rec.acc_sum = mcr.ASum;
                rec.singles = mcr.DeadtimeCorrectedSinglesRate.v;
                rec.singles_err = mcr.DeadtimeCorrectedSinglesRate.err;
                rec.doubles = mcr.DeadtimeCorrectedDoublesRate.v;
                rec.doubles_err = mcr.DeadtimeCorrectedDoublesRate.err;
                rec.triples = mcr.DeadtimeCorrectedTriplesRate.v;
                rec.triples_err = mcr.DeadtimeCorrectedTriplesRate.err;
                rec.scaler1 = mcr.Scaler1.v;
                rec.scaler1_err = mcr.Scaler1.err;
                rec.scaler2 = mcr.Scaler2.v;
                rec.scaler2_err = mcr.Scaler2.err;
                rec.uncorrected_doubles = mcr.RawDoublesRate.v;
                rec.uncorrected_doubles_err = mcr.RawDoublesRate.err;
                rec.singles_multi = mcr.singles_multi;
                rec.doubles_multi = mcr.doubles_multi;
                rec.triples_multi = mcr.triples_multi;
                rec.declared_mass= mcr.mass;
                TransferUtils.CopyULongsToDbls(mcr.RAMult, rec.mult_reals_plus_acc_sum);
                TransferUtils.CopyULongsToDbls(mcr.NormedAMult, rec.mult_acc_sum);
                for (int ix = 0; ix < 9; ix++)
                    rec.covariance_matrix[ix] = mcr.covariance_matrix[ix];

                INCCMethodResults imr;
                bool got = m.INCCAnalysisResults.TryGetINCCResults(m.Detector.MultiplicityParams, out imr);
                if (got)
                    rec.primary_analysis_method = (byte)NewTypeToOldMethodId(imr.primaryMethod);

                // rec.net_drum_weight =  // NEXT: no entry in INCC6 results for this result value, add it
                // NEXT: duo of passive and active measurent results identifier not yet properly handled in INCC6
                b = StringSquish(m.MeasDate.ToString("yy.MM.dd"), INCC.DATE_TIME_LENGTH);
                TransferUtils.Copy(b, rec.passive_meas_date);
                TransferUtils.Copy(b, rec.active_meas_date);
                b = StringSquish(m.MeasDate.ToString("HH:mm:ss"), INCC.DATE_TIME_LENGTH);
                TransferUtils.Copy(b, rec.passive_meas_time);
                TransferUtils.Copy(b, rec.active_meas_time);

                b = StringSquish(System.IO.Path.GetFileName(m.MeasurementId.FileName), INCC.FILE_NAME_LENGTH);
                TransferUtils.Copy(b, rec.passive_filename);
                TransferUtils.Copy(b, rec.active_filename);
                b = StringSquish(System.IO.Path.GetFileName(m.MeasurementId.FileName), INCC.FILE_NAME_LENGTH);
                TransferUtils.Copy(b, rec.passive_results_detector_id);
                TransferUtils.Copy(b, rec.active_results_detector_id);
                b = StringSquish(m.Detector.Id.DetectorId, INCC.MAX_DETECTOR_ID_LENGTH);
                TransferUtils.Copy(b, rec.passive_results_detector_id);
                TransferUtils.Copy(b, rec.active_results_detector_id);
                ItemId itid = NC.App.DB.ItemIds.Get(m.AcquireState.item_id);
                if (itid != null)
                {
                    rec.declared_u_mass = itid.declaredUMass;
                    rec.length = itid.length;
                }
                rec.db_version = 5.0;
                return rec;
            }
Пример #9
0
 Row GenDytlewskiResultsRow(MultiplicityCountingRes mcr)
 {
     Row row = new Row();
     row.Add((int)RepResults.Singles, mcr.DytlewskiCorrectedSinglesRate.v.ToString());
     row.Add((int)RepResults.SinglesSigma, mcr.DytlewskiCorrectedSinglesRate.err.ToString());
     row.Add((int)RepResults.Doubles, mcr.DytlewskiCorrectedDoublesRate.v.ToString());
     row.Add((int)RepResults.DoublesSigma, mcr.DytlewskiCorrectedDoublesRate.err.ToString());
     row.Add((int)RepResults.Triples, mcr.DytlewskiCorrectedTriplesRate.v.ToString());
     row.Add((int)RepResults.TripleSigmas, mcr.DytlewskiCorrectedTriplesRate.err.ToString());
     //row.Add((int)RepResults.Quads, "");
     //row.Add((int)RepResults.QuadsSigma, "");
     return row;
 }
Пример #10
0
 Row GenResultsRow(MultiplicityCountingRes mcr)
 {
     Row row = new Row();
     row.Add((int)RepResults.Singles, mcr.DeadtimeCorrectedSinglesRate.v.ToString()); // todo: move to results list entry processing scope
     row.Add((int)RepResults.SinglesSigma, mcr.DeadtimeCorrectedSinglesRate.err.ToString());
     row.Add((int)RepResults.Doubles, mcr.DeadtimeCorrectedDoublesRate.v.ToString());
     row.Add((int)RepResults.DoublesSigma, mcr.DeadtimeCorrectedDoublesRate.err.ToString());
     if (!meas.AcquireState.data_src.ToString().Equals ("Shift Register"))
     {
         row.Add((int)RepResults.Triples, mcr.DeadtimeCorrectedTriplesRate.v.ToString());
         row.Add((int)RepResults.TripleSigmas, mcr.DeadtimeCorrectedTriplesRate.err.ToString());
     }
     //row.Add((int)RepResults.Quads, "");
     //row.Add((int)RepResults.QuadsSigma, "");
     return row;
 }
Пример #11
0
 protected Section ConstructReportSection(ReportSections section, Multiplicity mu, MultiplicityCountingRes mcr)
 {
     Section sec = null;
     if (!(bool)selectedReportSections.GetValue((int)section))
         return sec;
     try
     {
         switch (section)
         {
             case ReportSections.RepResults:
                 sec = new Section(typeof(RepResults), 1, 1, 1);
                 sec[1].Add(0, "Corrected rates for SR " + mu.ShortName());
                 sec.Add(GenResultsRow(mcr));
                 break;
             case ReportSections.RepDytlewskiResults:
                 sec = new Section(typeof(RepResults), 1, 1, 1);
                 sec[1].Add(0, "Dytlewski rates for SR " + mu.ShortName());
                 sec.Add(GenDytlewskiResultsRow(mcr));
                 break;
         }
     }
     catch (Exception e)
     {
         ctrllog.TraceException(e);
     }
     return sec;
 }
Пример #12
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);
            }
        }
Пример #13
0
        unsafe static void RunValuesToResults(run_rec_ext run, Cycle cycle, Multiplicity key, MultiplicityCountingRes mcr)
        {
            cycle.seq = run.run_number;
            cycle.TS = TimeSpan.FromSeconds(run.run_count_time);  // is not always whole seconds hn 10-1.

            cycle.Totals = (ulong)run.run_singles;
            cycle.SinglesRate = run.run_singles / run.run_count_time;

            // table lookup on the strings, so test status is correct
            string s = TransferUtils.str(run.run_tests, INCC.MAX_RUN_TESTS_LENGTH);
            QCTestStatus qcts = QCTestStatusExtensions.FromString(s);

            cycle.SetQCStatus(key, qcts); // creates entry if not found


            mcr.Totals = cycle.Totals;
            mcr.TS = cycle.TS;

            mcr.DeadtimeCorrectedSinglesRate.v = run.run_singles_rate;
            mcr.DeadtimeCorrectedDoublesRate.v = run.run_doubles_rate;
            mcr.DeadtimeCorrectedTriplesRate.v = run.run_triples_rate;

            mcr.RASum = (ulong)run.run_reals_plus_acc;
            mcr.ASum = (ulong)run.run_acc;

            mcr.efficiency = run.run_multiplicity_efficiency;
            mcr.mass = run.run_mass;
            mcr.multiAlpha = run.run_multiplicity_alpha;
            mcr.multiplication = run.run_multiplicity_mult;
            cycle.HighVoltage = run.run_high_voltage;

            // assign the hits to a single channel (0)
            cycle.HitsPerChannel[0] = run.run_singles;
            mcr.RawSinglesRate.v = run.run_singles_rate;
            mcr.RawDoublesRate.v = run.run_doubles_rate;
            mcr.RawTriplesRate.v = run.run_triples_rate;

            mcr.Scaler1.v = run.run_scaler1;
            mcr.Scaler2.v = run.run_scaler2;
            mcr.Scaler1Rate.v = run.run_scaler1_rate;
            mcr.Scaler2Rate.v = run.run_scaler2_rate;

            long index = 0;
            for (ulong i = 0; i < INCC.SR_EX_MAX_MULT; i++)
            {
                if (run.run_mult_acc[i] > 0 || run.run_mult_reals_plus_acc[i] > 0)
                {
                    index = (long)i;
                }
            }

            mcr.MaxBins = (ulong)index + 1;
            mcr.MinBins = (ulong)index + 1;

            mcr.NormedAMult = new ulong[mcr.MaxBins];
            mcr.RAMult = new ulong[mcr.MaxBins];
            mcr.UnAMult = new ulong[mcr.MaxBins];

            // was not setting these to the right values hn 10-2
            for (ulong i = 0; i < (ulong)mcr.MaxBins; i++)
            {
                mcr.RAMult[i] = (ulong)run.run_mult_reals_plus_acc[i]; 
                mcr.NormedAMult[i] = (ulong)run.run_mult_acc[i];
            }
            mcr.RASum = run.run_reals_plus_acc; // JFL the cycle summary processing accumulates these sums later in the pipline
            mcr.ASum = run.run_acc;
            mcr.AB.Resize((int)mcr.MaxBins); // JFL also happens during transferintermediates
        }
Пример #14
0
        private void OKBtn_Click(object sender, EventArgs e)
        {
            ClipboardMonitor.OnClipboardChange -= new ClipboardMonitor.OnClipboardChangeEventHandler(ClipboardMonitor_OnClipboardChange);
            ClipboardMonitor.Stop(); // do not forget to stop

            ClearMeasCycles();
            CycleList newCycles = new CycleList();
            // NEXT: manual entry needs more work to get it completed, but you have a good start here
            Multiplicity key = new Multiplicity(ah.det.MultiplicityParams);  // APluralityOfMultiplicityAnalyzers: expand in some logical manner, e.g. enable user to select the analyzer and related results for manual entry and assignment
            for (int i = 0; i < MAX_MANUAL_ENTRIES; i++) // hard-coded limits are ... lame
            {
                DataGridViewRow r = cyclesGridView.Rows[i];
                if (r.Cells == null || (r.Cells[1].Value == null) || r.Cells[1].Value.ToString() == string.Empty)
                    break;

                Cycle cycle = new Cycle(m_log);

                ulong tots = 0, r_acc = 0, acc = 0;
                ulong.TryParse(r.Cells[1].Value.ToString(), out tots);
                ulong.TryParse((string)r.Cells[2].FormattedValue, out r_acc); // FormattedValue gives "" instead of the null checked for in the conditional above
                ulong.TryParse((string)r.Cells[3].FormattedValue, out acc);

                newCycles.Add(cycle);
                cycle.Totals = tots;
                cycle.TS = new TimeSpan(0, 0, 0, 0, (int)(1000 * m_counttime)); // milliseconds permitted for LM and future
                cycle.SinglesRate = tots / m_counttime;
                cycle.SetQCStatus(key, QCTestStatus.Pass);
                cycle.seq = i+1;

                MultiplicityCountingRes mcr = new MultiplicityCountingRes(key.FA, cycle.seq);
                cycle.CountingAnalysisResults.Add(key, mcr);
                mcr.Totals = cycle.Totals;
                mcr.TS = cycle.TS;
                mcr.ASum = acc;
                mcr.RASum = r_acc;

                // assign the hits to a single channel (0)
                cycle.HitsPerChannel[0] = tots;
                mcr.RawSinglesRate.v = cycle.SinglesRate;

                // no alpha-beta, mult bins, HV, doubles, triples, raw nor corrected

            }

            int seq = 0;
            foreach (Cycle cycle in newCycles)  // add the necessary meta-data to the cycle identifier instance
            {
                seq++;
                cycle.UpdateDataSourceId(ConstructedSource.Manual, ah.det.Id.SRType,
                    new DateTimeOffset(m_refDate.AddTicks(cycle.TS.Ticks * cycle.seq)), string.Empty);
            }
            NC.App.Opstate.Measurement.Add(newCycles);
            if (newCycles.Count > 0)
                DialogResult = DialogResult.OK;
            Close();
        }
Пример #15
0
 public static void SetAlphaBeta(Multiplicity mkey, MultiplicityCountingRes mcr)
 {
     ABKey abkey = new ABKey(mkey, mcr);
     SetAlphaBeta(abkey, mcr.AB);
 }