Example #1
0
        // Recalculate (X+...) from (I, J)
        public static void CalculateXYEventFromIJ(PETSingleDigitalEvent In, ref PETSingleEvent Out)
        {
            Out.Position  = In.Position;
            Out.Timestamp = In.Timestamp;

            // не совсем точно с энергией. она должна быть взята из пакета, но пока её нет в протоколе
            GetXYFromIJ(In.I, In.J, 511, out Out.XPlus, out Out.XMinus, out Out.YPlus, out Out.YMinus);
            // Out.E = 511; или In.E
        }
Example #2
0
        // Recalculate (I,J) from (X+, X-, Y+, Y-) and copy other parameters
        public static void CalculateDigitalEvent(PETSingleEvent In, ref PETSingleDigitalEvent OutE)
        {
            OutE.I = (byte)iForX(In.XPlus, In.XMinus);
            OutE.J = (byte)iForX(In.YPlus, In.YMinus);

            OutE.Position  = In.Position;
            OutE.Timestamp = In.Timestamp;

            // OutE.Flags = In.Flags;
        }
 public bool CompareTo(PETSingleEvent p)
 {
     return((p.Timestamp == this.Timestamp) &&
            (p.Position == this.Position) &&
            (p.XPlus == this.XPlus) &&
            (p.YPlus == this.YPlus) &&
            (p.XMinus == this.XMinus) &&
            (p.YMinus == this.YMinus) &&
            (p.Flags == this.Flags));
 }
Example #4
0
        public static PETSingleEvent[] ConvertIJToXYEvents(PETSingleDigitalEvent[] events)
        {
            var res = new PETSingleEvent[events.Length];

            for (int i = 0; i < res.Length; i++)
            {
                //                res[i] =
            }

            return(res);
        }
Example #5
0
        public static void CalculateEventForDigital(PETSingleDigitalEvent In, ref PETSingleEvent OutE)
        {
            OutE.XPlus  = XPlusForI(In.I);
            OutE.XMinus = XMinusForI(In.I);

            OutE.YPlus  = YPlusForJ(In.J);
            OutE.YMinus = YMinusForJ(In.J);

            OutE.Position  = In.Position;
            OutE.Timestamp = In.Timestamp;

            // OutE.Flags = In.Flags;
        }
        public static PETSingleEvent[] DecodeArray(byte[] b, int Offset, int Size)
        {
            int ofs = Offset;
            int num = (Size) / PETStructSizes.PETSingleEvent_Size;
            var res = new PETSingleEvent[num];

            for (int i = 0; i < num; i++)
            {
                res[i].FromBytes(ofs, b);
                ofs += PETStructSizes.PETSingleEvent_Size;
            }

            return(res);
        }
        //public PETCoincidenceTOF()
        //{
        //}

        public PETCoincidenceTOF(PETSingleEvent first, PETSingleEvent second, byte flags = 0)
        {
            this.Timestamp1 = first.Timestamp;
            this.Timestamp2 = second.Timestamp;
            this.Position1  = first.Position;
            this.Position2  = second.Position;
            this.XPlus1     = first.XPlus;
            this.XMinus1    = first.XMinus;
            this.YPlus1     = first.YPlus;
            this.YMinus1    = first.YMinus;
            this.XPlus2     = second.XPlus;
            this.XMinus2    = second.XMinus;
            this.YPlus2     = second.YPlus;
            this.YMinus2    = second.YMinus;
            this.Flags      = flags;
        }
Example #8
0
        //		static int ItemSize = PETSingleEvent.Size; // Marshal.SizeOf(typeof(PETSingleEvent));

        public static PETSingleEventsPacket RandomPacket(System.Random rnd = null)
        {
            var res = new PETSingleEventsPacket();

            var r = (rnd == null) ? new System.Random() : rnd;

            res.Flags     = (byte)r.Next();
            res.ItemCount = (byte)r.Next(1, 10);

            res.Events = new PETSingleEvent[res.ItemCount];

            for (int i = 0; i < res.ItemCount; i++)
            {
                res.Events[i] = PETSingleEvent.RandomEvent(rnd);
            }

            return(res);
        }
        public static PETSingleEvent RandomEvent(System.Random rnd = null)
        {
            var res = new PETSingleEvent();

            var r = (rnd == null) ? new System.Random() : rnd;

            res.Timestamp = (UInt32)r.Next();
            res.Position  = (UInt16)(r.Next(0, 47) + 64 * r.Next(0, 3));

            res.XPlus  = (UInt16)r.Next(0, 255);
            res.YPlus  = (UInt16)r.Next(0, 255);
            res.XMinus = (UInt16)r.Next(0, 255);
            res.YMinus = (UInt16)r.Next(0, 255);

            res.Flags = (byte)r.Next();

            return(res);
        }
Example #10
0
        // один пакет с одним ивентом на детекторе 1
        public static PETSingleEventsPacket[] CreateUnitEventPacket()
        {
            var evt = new PETSingleEvent();

            evt.Flags     = 1;
            evt.Position  = 2;
            evt.XMinus    = 3;
            evt.XPlus     = 4;
            evt.YMinus    = 5;
            evt.YPlus     = 6;
            evt.Timestamp = 255;

            var packet = new PETSingleEventsPacket();

            packet.Flags     = 63;
            packet.ItemCount = 1;
            packet.Events    = new PETSingleEvent[1];
            packet.Events[0] = evt;

            return(new PETSingleEventsPacket[] { packet });
        }
Example #11
0
        public static List <PETSingleEvent> GenerateSinglesNoAtt(List <AnnihilationEvent> eventList, DetectorsConfiguration dc, string outDir, int index)
        {
            List <PETSingleEvent> result = new List <PETSingleEvent>();

            foreach (var ev in eventList)
            {
                Photon ph1 = new Photon(ev)
                {
                    Status = stat.Finished, Energy = 511E3
                },
                         ph2 = new Photon(ev, true)
                {
                    Status = stat.Finished, Energy = 511E3
                };

                PETSingleEvent se        = new PETSingleEvent();
                bool           detection = dc.Detect(ph1, out se);
                if (detection)
                {
                    result.Add(se);
                }

                detection = dc.Detect(ph2, out se);
                if (detection)
                {
                    result.Add(se);
                }
            }

            if (result.Count != 0)
            {
                WorkWithFiles.WriteSingleEventList(string.Format("{1}\\{0}.csv", index++, outDir), result);
            }
            Console.WriteLine("\tRegistered {0} events", result.Count);

            return(result);
        }
        public bool Detect(Photon ph, out PETSingleEvent se)
        {
            se = new PETSingleEvent();

            if (ph.Status != stat.Finished)
            {
                return(false);
            }

            //to cylindrical
            double azimuthalAngle = Math.Atan2(ph.CurrentPosition.Y, ph.CurrentPosition.X);

            if (azimuthalAngle < 0)
            {
                azimuthalAngle += 2 * Math.PI;
            }
            //double rc = Math.Sqrt(ph.CurrentPosition.X * ph.CurrentPosition.X + ph.CurrentPosition.Y * ph.CurrentPosition.Y + ph.CurrentPosition.Z * ph.CurrentPosition.Z) * Math.Sin(ph.Theta);
            double rc = Math.Sqrt(ph.CurrentPosition.X * ph.CurrentPosition.X + ph.CurrentPosition.Y * ph.CurrentPosition.Y);
            double z0 = ph.CurrentPosition.Z;

            var tmpAngle = Math.Asin(rc / this.RingRadius * Math.Sin(azimuthalAngle - ph.Phi));
            //var tmpAngle = this.Phi - azimuthalAngle - Math.Asin(rc / ringRadius * Math.Sin(azimuthalAngle - this.Phi));

            var psi = tmpAngle + ph.Phi; //угол регистрации

            if (psi < 0)
            {
                psi += 2 * Math.PI;
            }
            if (psi >= 2 * Math.PI)
            {
                psi -= 2 * Math.PI;
            }

            var block = (int)(psi / (2 * Math.PI) * this.BlocksCount); // номер блока детекторов

            var r1 = Math.Sqrt(this.RingRadius * this.RingRadius + rc * rc - 2 * this.RingRadius * rc * Math.Cos(azimuthalAngle - psi));
            var dz = (r1 / Math.Tan(ph.Theta)) / this.BlockSize;

            z0 /= this.BlockSize;

            var blockRing = (int)Math.Floor(z0 + dz + this.RingsCount / 2.0); // номер кольца блоков

            //double s = Math.Sqrt((this.CurrentPosition.X - ringRadius * Math.Cos(psi)) * (this.CurrentPosition.X - ringRadius * Math.Cos(psi)) +
            //    (this.CurrentPosition.Y - ringRadius * Math.Sin(psi)) * (this.CurrentPosition.Y - ringRadius * Math.Sin(psi)) +
            //        (this.CurrentPosition.Z - dz * blockSide) * (this.CurrentPosition.Z - dz * blockSide)) + this.Path;
            //this.Time += s / (3e11);

            if (blockRing >= 0 && blockRing < this.RingsCount)
            {
                se.Position  = (UInt16)(((block & 0x3F) << 4) | (blockRing & 0xF));
                se.Timestamp = (UInt32)(ph.Time);

                var I = (byte)((psi - block * 2 * Math.PI / this.BlocksCount) / (2 * Math.PI / (this.BlocksCount * this.DetectorsPerBlock)));
                var J = (byte)((z0 + dz + this.RingsCount / 2.0) * this.DetectorsPerBlock) % this.DetectorsPerBlock;

                EventConverter.GetXYFromIJ(I, (byte)J, ph.Energy, out se.XPlus, out se.XMinus, out se.YPlus, out se.YMinus);
                return(true);
            }
            return(false);
        }
Example #13
0
 // Calculate energy for the event using X/Y detection coordinates
 public static int EnergyForEvent(PETSingleEvent In)
 {
     return((int)(In.XPlus + In.XMinus + In.YPlus + In.YMinus));
 }