Beispiel #1
0
        public CountingAnalysisParameters CountingParameters(Detector det, bool applySRFromDetector)
        {
            CountingAnalysisParameters cap = CountingParameters(det.Id.DetectorName);

            if (applySRFromDetector)
            {
                Multiplicity m = det.MultiplicityParams;
                foreach (SpecificCountingAnalyzerParams s in cap)
                {
                    Type t = s.GetType();
                    if (t.Equals(typeof(Multiplicity)))
                    {
                        Multiplicity thisone = ((Multiplicity)s);
                        ulong        gw      = thisone.gateWidthTics;
                        //ulong predelay = thisone.SR.predelay;
                        thisone.SR = new ShiftRegisterParameters(m.SR); // use the current detector's SR params, then
                        thisone.SetGateWidthTics(gw);                   // override with the user's choice from the DB
                        //thisone.SR.predelay = predelay;
                    }
                    else if (t.Equals(typeof(Coincidence)))
                    {
                        Coincidence thisone = ((Coincidence)s);
                        ulong       gw      = thisone.gateWidthTics;
                        //ulong predelay = thisone.SR.predelay;
                        thisone.SR = new ShiftRegisterParameters(m.SR); // use the current detector's SR params, then
                        thisone.SetGateWidthTics(gw);                   // override with the user's choice from the DB
                        //thisone.SR.predelay = predelay;
                    }
                }
            }
            return(cap);
        }
Beispiel #2
0
        public static int FindBlockSizeWithCoincidence(string cipherText, int maximumBlockSize = Constants.MAX_BLOCK_SIZE)
        {
            // Try different block sizes starting from 2 to maximumBlockSize.
            int currentBlockSize = 2;
            // Store average error calculated between the found coincidence and English language's coincidence in a dictionary.
            Dictionary <int, double> errorsPerBlockSize = new Dictionary <int, double>();

            while (currentBlockSize <= maximumBlockSize)
            {
                double error = 0;
                // Divide cipher text according to the block size.
                IEnumerable <string> dividedCipherTexts = DivideCipherText(cipherText, currentBlockSize);

                // For each divided cipher text, calculate coincidence and obtain error.
                for (int i = 0; i < currentBlockSize; i++)
                {
                    double coincidence = Coincidence.CalculateIndex(dividedCipherTexts.ElementAt(i));
                    error += Math.Abs(coincidence - Constants.EnglishIndexOfCoincidence);

                    // Check after every 5 calculation of index of coincidence on a divided cipher text to see whether
                    // current block size is yielding good results. If error is too large, try next block size.
                    if (i % 5 == 0)
                    {
                        double currentError = error / currentBlockSize;
                        if (currentError > 0.01)
                        {
                            break;
                        }
                    }
                }

                // Take average of the calculated error sum.
                error /= currentBlockSize;

                // If error is less than %0.5 (if average coincidence is between 0.060 and 0.070), store as a candidate block size.
                if (error < 0.005)
                {
                    errorsPerBlockSize.Add(currentBlockSize, error);
                }

                // Increment the block size and try again.
                currentBlockSize++;
            }

            if (errorsPerBlockSize.Count == 0)
            {
                // If no suitable block size has been found, return -1 to signify the analysis has failed.
                return(-1);
            }
            else
            {
                // Get the block size that resulted in the lowest error and return it.
                errorsPerBlockSize = errorsPerBlockSize.OrderBy(k => k.Value).ToDictionary(k => k.Key, v => v.Value);
                return(errorsPerBlockSize.First().Key);
            }
        }
Beispiel #3
0
        // build up the requested analyses for this run from the list of analyzer params
        internal void PrepareAndStartCountingAnalyzers(CountingAnalysisParameters ap)
        {
            if (ap == null)
            {
                logger.TraceEvent(LogLevels.Error, 1519, "No counting analyzers specified");
                return;
            }

            bool good = false;

            foreach (SpecificCountingAnalyzerParams sap in ap)
            {
                if (!sap.Active) // skip disabled analyzers
                {
                    continue;
                }
                if (sap is BaseRate)
                {
                    BaseRate b = (BaseRate)sap;
                    good = State.Sup.AddRates(b.gateWidthTics);
                    if (!good)
                    {
                        // perhaps the gate is too large
                        // dev note : each analyzer should publish it's limits with constant attributes on the class
                        good = State.Sup.AddRates(b.gateWidthTics = (ulong)1e7);
                        logger.TraceEvent(LogLevels.Warning, 1512, "Rate analyzer gatewidth created with default {0} ticks", b.gateWidthTics);
                    }
                }
                else if (sap is Multiplicity)
                {
                    Multiplicity m = (Multiplicity)sap;
                    good = State.Sup.AddMultiplicity(m, m.FA);
                }
                else if (sap is Rossi)
                {
                    Rossi r = (Rossi)sap;
                    good = State.Sup.AddRossi(r.gateWidthTics);
                }
                else if (sap is Feynman)
                {
                    Feynman f = (Feynman)sap;
                    good = State.Sup.AddFeynman(f.gateWidthTics);
                }
                else if (sap is TimeInterval)
                {
                    TimeInterval ti = (TimeInterval)sap;
                    good = State.Sup.AddTimeInterval(ti.gateWidthTics);
                }
                else if (sap is Coincidence)
                {
                    Coincidence co = (Coincidence)sap;
                    good = State.Sup.AddCoincidenceMatrix(co);
                }
            }
        }
Beispiel #4
0
        public bool AddCoincidenceMatrix(Coincidence co)
        {
            bool good;

            good = handler.InstantiateCoincidenceAnalyzerSlowBackground(co.SR.gateLength, co.SR.predelay, co.AccidentalsGateDelayInTics);
            if (!good)
            {
                logger.TraceEvent(LogLevels.Warning, 1506, "CoincidenceMatrix analyzer trouble, que no? ", co.SR.ToString());
            }
            return(good);
        }
Beispiel #5
0
        /// <summary>
        /// Analiza una cara detectada en particular para validar si ya se encuentra actualmente en la lista de jugadores
        /// </summary>
        /// <param name="face"></param>
        /// <returns></returns>
        private async Task <Face> AnalyzePlayerFace(Face face)
        {
            try
            {
                Guid[]      playersId   = _players.Select(p => p.Id).ToArray();
                Coincidence coincidence = await FindSimilarFaceAsync(face.FaceId, playersId, FindSimilarMatchMode.matchFace);

                face.FaceId = (coincidence.MatchId != Guid.Empty) ? coincidence.MatchId : coincidence.NewId;

                return(face);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #6
0
 public bool Transfer(Coincidence cop, CoincidenceResult cor)
 {
     if (cor == null)
         return true;
     bool res = true;
     try
     {
         CoincidenceMatrixResult cr = new CoincidenceMatrixResult(cor.RACoincidenceRate.Length); // check for equality to numchannels, should always be numXnum size
         countresults.Add(cop, cr);
         cr.TransferRawResult(cor);
     }
     catch (OutOfMemoryException e)
     {
         cop.reason = "Coincidence matrix transfer " + e.Message;
         res = false;
         logger.TraceEvent(LogLevels.Error, 87410, cop.reason);
     }
     return res;
 }
Beispiel #7
0
 public bool AddCoincidenceMatrix(Coincidence co)
 {
     bool good;
     good = handler.InstantiateCoincidenceAnalyzerSlowBackground(co.SR.gateLength, co.SR.predelay, co.AccidentalsGateDelayInTics);
     if (!good)
         logger.TraceEvent(LogLevels.Warning, 1506, "CoincidenceMatrix analyzer trouble, que no? ", co.SR.ToString());
     return good;
 }
Beispiel #8
0
        void ConstructNewRow(DataGridViewRow row, Type t, FAType FA)
        {
            SpecificCountingAnalyzerParams s = null;
            if (t.Equals(typeof(Multiplicity)))
            {
                Multiplicity m = new Multiplicity(FA);
                row.Cells[3].Value = det.SRParams.predelay.ToString();
                row.Cells[3].Tag = det.SRParams.predelay;
                if (FA == FAType.FAOn)
                {
                    row.Cells[4].Value = m.BackgroundGateTimeStepInTics.ToString();
                    row.Cells[4].Tag = m.BackgroundGateTimeStepInTics;
                }
                else
                {
                    row.Cells[4].Value = m.AccidentalsGateDelayInTics.ToString();
                    row.Cells[4].Tag = m.AccidentalsGateDelayInTics;
                }
                m.gateWidthTics = det.SRParams.gateLength;
                s = m;
            }
            else if (t.Equals(typeof(Feynman)))
            {
                s = new Feynman();
            }
            else if (t.Equals(typeof(Rossi)))
            {
                s = new Rossi();
            }
            else if (t.Equals(typeof(TimeInterval)))
            {
                s = new TimeInterval();
            }
            else if (t.Equals(typeof(Coincidence)))
            {
                Coincidence c = new Coincidence();
                row.Cells[3].Value = det.SRParams.predelay.ToString();
                row.Cells[3].Tag = det.SRParams.predelay;
                row.Cells[4].Value = c.AccidentalsGateDelayInTics.ToString();
                row.Cells[4].Tag = c.AccidentalsGateDelayInTics;
                c.gateWidthTics = det.SRParams.gateLength;
                s = c;
            }

            row.Cells[0].Tag = s.Active;
            row.Cells[2].Tag = s.gateWidthTics;
            row.Cells[2].Value = s.gateWidthTics.ToString();
            row.Tag = s;
            SetRODetails(row, t);
        }
Beispiel #9
0
 SpecificCountingAnalyzerParams Constructed(DataGridViewRow row)
 {
     SpecificCountingAnalyzerParams s = null;
     Type t; FAType FA;
     if (row.Cells[1].Value == null)
         return null;
     TTypeMap((string)row.Cells[1].Value, out t, out FA);
     if (t.Equals(typeof(Multiplicity)))
     {
         s = new Multiplicity(FA);
         ((Multiplicity)s).SR.predelay = Construct(row.Cells[3]);
         ((Multiplicity)s).SR.gateLength = Construct(row.Cells[2]);
         ((Multiplicity)s).SR.gateLengthMS = Construct(row.Cells[2])/10;
         if (FA == FAType.FAOn)
             ((Multiplicity)s).BackgroundGateTimeStepInTics = Construct(row.Cells[4]);
         else
             ((Multiplicity)s).AccidentalsGateDelayInTics = Construct(row.Cells[4]);
     }
     else if (t.Equals(typeof(Feynman)))
     {
         s = new Feynman();
     }
     else if (t.Equals(typeof(Rossi)))
     {
         s = new Rossi();
     }
     else if (t.Equals(typeof(TimeInterval)))
     {
         s = new TimeInterval();
     }
     else if (t.Equals(typeof(Coincidence)))
     {
         s = new Coincidence();
         ((Coincidence)s).SR.predelay = Construct(row.Cells[3]);
         ((Coincidence)s).AccidentalsGateDelayInTics = Construct(row.Cells[4]);
     }
     s.gateWidthTics = Construct(row.Cells[2]);
     s.Active = CheckedRow(row);
     return s;
 }
Beispiel #10
0
 public ActionResult <Coincidence> Update(int id, [FromBody] Coincidence newDetails)
 {
     context.Entry(newDetails).State = EntityState.Modified;
     context.SaveChanges();
     return(newDetails);
 }
Beispiel #11
0
 public ActionResult <Coincidence> InsertData([FromBody] Coincidence insertion)
 {
     context.Coincidence.Add(insertion);
     context.SaveChanges();
     return(insertion);
 }