Esempio n. 1
0
 internal MIPBaseTrack(int id, SySal.Tracking.MIPEmulsionTrackInfo info, MIPIndexedEmulsionTrack top, MIPIndexedEmulsionTrack bottom)
 {
     m_Id     = id;
     m_Info   = info;
     m_Top    = top;
     m_Bottom = bottom;
 }
Esempio n. 2
0
        private static int FitTrackLine(System.Collections.ArrayList tr, out float x, out float y, out float z, out float tx, out float ty, out float w)
        {
            // track fit by averaging of segments parameters and return the mean values

            int nseg = tr.Count;

            x = 0; y = 0; z = 0; tx = 0; ty = 0; w = 0;
            SySal.Tracking.MIPEmulsionTrackInfo seg = null;
            for (int i = 0; i < nseg; i++)
            {
                seg = (SySal.Tracking.MIPEmulsionTrackInfo)tr[i];
                x  += (float)seg.Intercept.X;
                y  += (float)seg.Intercept.Y;
                z  += (float)seg.Intercept.Z;
                tx += (float)seg.Slope.X;
                ty += (float)seg.Slope.Y;
                w  += (float)seg.Count;
            }
            x  /= nseg;
            y  /= nseg;
            z  /= nseg;
            tx /= nseg;
            ty /= nseg;
            return(nseg);
        }
Esempio n. 3
0
        private SySal.Tracking.MIPEmulsionTrackInfo Extrapolate(SySal.Tracking.MIPEmulsionTrackInfo data1, SySal.Tracking.MIPEmulsionTrackInfo data2, double z)
        {
            SySal.Tracking.MIPEmulsionTrackInfo Result = new SySal.Tracking.MIPEmulsionTrackInfo();
            double mult = (data2.Intercept.X - data1.Intercept.X) / (data2.Intercept.Z - data1.Intercept.Z);

            Result.Intercept.X = data1.Intercept.X + (z - data1.Intercept.Z) * mult;
            mult = (data2.Intercept.Y - data1.Intercept.Y) / (data2.Intercept.Z - data1.Intercept.Z);
            Result.Intercept.Y = data1.Intercept.Y + (z - data1.Intercept.Z) * mult;
            Result.Intercept.Z = z;
            return(Result);
        }
Esempio n. 4
0
        /// <summary>
        /// Seeks a kink in a track.
        /// </summary>
        /// <param name="t">the track where the kink is to be sought.</param>
        /// <param name="allowedkink">the number of entries must be identical to the number of segments of the track; then, the kink is checked for segments whose corresponding entry is set to <c>true</c> in this array.</param>
        public KinkSearchResult(SySal.TotalScan.Track t, bool[] allowedkink)
        {
            SySal.TotalScan.Segment[] segs = new SySal.TotalScan.Segment[t.Length];
            int i;

            for (i = 0; i < t.Length; i++)
            {
                SySal.Tracking.MIPEmulsionTrackInfo info = t[i].Info;
                segs[i] = new SySal.TotalScan.Segment(info, new SySal.TotalScan.NullIndex());
            }
            ComputeResult(segs, allowedkink);
        }
Esempio n. 5
0
 public static void ApplyTransformation(SySal.Tracking.MIPEmulsionTrack tk)
 {
     SySal.Tracking.MIPEmulsionTrackInfo info = tMIPEmulsionTrack.AccessInfo(tk);
     MyTransformation.Transform(info.Intercept.X, info.Intercept.Y, ref info.Intercept.X, ref info.Intercept.Y);
     MyTransformation.Deform(info.Slope.X, info.Slope.Y, ref info.Slope.X, ref info.Slope.Y);
     SySal.Tracking.Grain [] grains = tMIPEmulsionTrack.AccessGrains(tk);
     if (grains != null)
     {
         foreach (SySal.Tracking.Grain g in grains)
         {
             MyTransformation.Transform(g.Position.X, g.Position.Y, ref g.Position.X, ref g.Position.Y);
         }
     }
 }
Esempio n. 6
0
 internal MIPIndexedEmulsionTrack(int id, SySal.Tracking.MIPEmulsionTrackInfo info, bool istop, View vw)
 {
     m_Grains                   = null;
     m_Id                       = id;
     m_Info                     = (SySal.Tracking.MIPEmulsionTrackInfo)info.Clone();
     m_Info.Intercept.X        += m_Info.Slope.X * ((istop ? -200.0 : 0.0) - m_Info.Intercept.Z);
     m_Info.Intercept.Y        += m_Info.Slope.Y * ((istop ? -200.0 : 0.0) - m_Info.Intercept.Z);
     m_Info.Intercept.Z         = istop ? -200.0 : 0.0;
     m_Info.TopZ                = istop ? 43.0 : -200.0;
     m_Info.BottomZ             = istop ? 0.0 : -243.0;
     m_OriginalRawData.Fragment = 0;
     m_OriginalRawData.View     = 0;
     m_OriginalRawData.Track    = id;
     m_View                     = vw;
 }
Esempio n. 7
0
        /// <summary>
        /// Adds segments to an existing layer with a specified mapping transformation.
        /// </summary>
        /// <param name="lay">the layer that is to receive the new segments.</param>
        /// <param name="addsegs">the segments to be added.</param>
        /// <param name="calinfo">the mapping transformation to be used.</param>
        public void AddToLayer(SySal.TotalScan.Flexi.Layer lay, SySal.TotalScan.Flexi.Segment [] addsegs, SySal.DAQSystem.Scanning.IntercalibrationInfo calinfo)
        {
            int i;

            SySal.TotalScan.Segment [] segs = new SySal.TotalScan.Segment[addsegs.Length];
            for (i = 0; i < addsegs.Length; i++)
            {
                SySal.Tracking.MIPEmulsionTrackInfo info = addsegs[i].Info;
                info.Slope     = calinfo.Deform(info.Slope);
                info.Intercept = calinfo.Transform(info.Intercept);
                addsegs[i].SetInfo(info);
                segs[i] = addsegs[i];
            }
            lay.AddSegments(segs);
        }
Esempio n. 8
0
        static SySal.Tracking.MIPEmulsionTrackInfo[] layExtractMap(SySal.TotalScan.Layer lay, dMapFilter flt, bool useoriginal)
        {
            System.Collections.ArrayList ar = new System.Collections.ArrayList();
            int n = lay.Length;
            int i;

            for (i = 0; i < n; i++)
            {
                SySal.Tracking.MIPEmulsionTrackInfo info = useoriginal ? lay[i].OriginalInfo : lay[i].Info;
                if (flt == null || flt(lay[i]))
                {
                    ar.Add(info);
                }
            }
            return((SySal.Tracking.MIPEmulsionTrackInfo[])ar.ToArray(typeof(SySal.Tracking.MIPEmulsionTrackInfo)));
        }
Esempio n. 9
0
        public LinkedZone(System.IO.StreamReader r)
        {
            this.m_Transform.MXX = this.m_Transform.MYY = 1.0;
            this.m_Transform.MXY = this.m_Transform.MYX = 0.0;
            this.m_Transform.TX  = this.m_Transform.TY = this.m_Transform.TZ = 0.0;
            this.m_Transform.RX  = this.m_Transform.RY = 0.0;
            System.Collections.ArrayList ar = new System.Collections.ArrayList();
            string line;

            while (((line = r.ReadLine()) != null) && ((line = line.Trim()) != ""))
            {
                int pos = 0;
                SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo();
                info.Count       = Convert.ToUInt16(GetNextToken(line, ref pos));
                info.Field       = 0;
                info.AreaSum     = Convert.ToUInt32(GetNextToken(line, ref pos));
                info.Intercept.X = Convert.ToDouble(GetNextToken(line, ref pos));
                info.Intercept.Y = Convert.ToDouble(GetNextToken(line, ref pos));
                info.Intercept.Z = 0.0;
                info.Slope.X     = Convert.ToDouble(GetNextToken(line, ref pos));
                info.Slope.Y     = Convert.ToDouble(GetNextToken(line, ref pos));
                info.Slope.Z     = 1.0;
                info.Sigma       = Convert.ToDouble(GetNextToken(line, ref pos));
                info.TopZ        = 43.0;
                info.BottomZ     = -243.0;
                ar.Add(info);
            }
            int i;

            MIPIndexedEmulsionTrack [] ttkarr = new MIPIndexedEmulsionTrack[ar.Count];
            m_Top = new Side(ttkarr, 43.0, 0.0);
            for (i = 0; i < ttkarr.Length; i++)
            {
                ttkarr[i] = new MIPIndexedEmulsionTrack(i, (SySal.Tracking.MIPEmulsionTrackInfo)ar[i], true, (View)((Side)m_Top).View(0));
            }
            MIPIndexedEmulsionTrack [] btkarr = new MIPIndexedEmulsionTrack[ar.Count];
            m_Bottom = new Side(btkarr, -200.0, -243.0);
            for (i = 0; i < btkarr.Length; i++)
            {
                btkarr[i] = new MIPIndexedEmulsionTrack(i, (SySal.Tracking.MIPEmulsionTrackInfo)ar[i], false, (View)((Side)m_Bottom).View(0));
            }
            m_Tracks = new MIPBaseTrack[ar.Count];
            for (i = 0; i < m_Tracks.Length; i++)
            {
                m_Tracks[i] = new MIPBaseTrack(i, (SySal.Tracking.MIPEmulsionTrackInfo)ar[i], ttkarr[i], btkarr[i]);
            }
        }
Esempio n. 10
0
        private scattDifference[] calcScattDiff(Geometry gm, SySal.Tracking.MIPEmulsionTrackInfo[] data)
        {
            int i, k;

            Geometry.LayerStart[] geom         = gm.Layers;
            scattDifference[]     myScattering = new scattDifference[data.Length - 1];

            double value = 0.0;

            for (i = 0; i < data.Length - 1; i++)
            {
                value = 0.0;
                for (k = 0; data[i].Intercept.Z >= geom[k].ZMin; k++)
                {
                    ;
                }
                if (data[i + 1].Intercept.Z > geom[k].ZMin)
                {
                    myScattering[i].first  = i;
                    myScattering[i].second = i + 1;
                    SySal.Tracking.MIPEmulsionTrackInfo info2 = new SySal.Tracking.MIPEmulsionTrackInfo();
                    info2 = data[i];
                    do
                    {
                        SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo();
                        info  = (geom[k].ZMin == data[i + 1].Intercept.Z) ? data[i + 1] : Extrapolate(data[i], data[i + 1], geom[k].ZMin);
                        value = value + calculateSingleScatt(info2, info, geom[k - 1].RadiationLength);
                        info2 = info;
                    }while ((i + 1) < data.Length - 1 && data[i + 1].Intercept.Z >= geom[++k].ZMin);

                    if (data[i + 1].Intercept.Z < geom[k].ZMin)
                    {
                        value = value + calculateSingleScatt(info2, data[i + 1], geom[k - 1].RadiationLength);
                    }
                    myScattering[i].value = value;
                }
                else
                {
                    value = calculateSingleScatt(data[i], data[i + 1], geom[k - 1].RadiationLength);
                    myScattering[i].value  = value;
                    myScattering[i].first  = i;
                    myScattering[i].second = i + 1;
                }
            }
            return(myScattering);
        }
Esempio n. 11
0
        /// <summary>
        /// Sets the Z references of the layers, also adjusting segment positions.
        /// </summary>
        /// <param name="newupz">the new value of the upstream Z.</param>
        /// <param name="newdownz">the new value of the downstream Z.</param>
        /// <remarks>The new value of the Z of the reference center is computed by an affine transformation, as well as those of segments.</remarks>
        public virtual void DisplaceAndClampZ(double newupz, double newdownz)
        {
            double idz = (newdownz - newupz) / (m_DownstreamZ - m_UpstreamZ);
            int    i;

            for (i = 0; i < Segments.Length; i++)
            {
                SySal.Tracking.MIPEmulsionTrackInfo info = Segments[i].Info;
                info.Intercept.Z = (info.Intercept.Z - m_UpstreamZ) * idz + newupz;
                info.TopZ        = (info.TopZ - m_UpstreamZ) * idz + newupz;
                info.BottomZ     = (info.BottomZ - m_UpstreamZ) * idz + newupz;
                ((Segment)Segments[i]).SetInfo(info);
            }
            m_RefCenter.Z       = (m_RefCenter.Z - m_UpstreamZ) * idz + newupz;
            m_UpstreamZ         = newupz;
            m_DownstreamZ       = newdownz;
            m_UpstreamZ_Updated = m_DownstreamZ_Updated = true;
        }
Esempio n. 12
0
        static SySal.Tracking.MIPEmulsionTrackInfo[] layExtractMap(SySal.TotalScan.Layer lay, SySal.BasicTypes.Rectangle r, dMapFilter flt, bool useoriginal)
        {
            System.Collections.ArrayList ar = new System.Collections.ArrayList();
            int n = lay.Length;
            int i;

            for (i = 0; i < n; i++)
            {
                SySal.Tracking.MIPEmulsionTrackInfo info = useoriginal ? lay[i].OriginalInfo : lay[i].Info;
                if (info.Intercept.X < r.MinX || info.Intercept.X > r.MaxX || info.Intercept.Y < r.MinY || info.Intercept.Y > r.MaxY)
                {
                    continue;
                }
                if (flt == null || flt(lay[i]))
                {
                    ar.Add(info);
                }
            }
            return((SySal.Tracking.MIPEmulsionTrackInfo[])ar.ToArray(typeof(SySal.Tracking.MIPEmulsionTrackInfo)));
        }
Esempio n. 13
0
 /// <summary>
 /// Reads a microtrack from disk.
 /// </summary>
 /// <param name="s">the Side that contains the microtrack.</param>
 /// <param name="id">the Id of the microtrack to be accessed.</param>
 /// <param name="r">the <c>BinaryReader</c> wrapping the data containing file.</param>
 public MIPIndexedEmulsionTrack(Side s, int id, System.IO.BinaryReader r)
 {
     m_Side = s;
     SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo();
     info.Field                 = r.ReadUInt32();
     info.AreaSum               = r.ReadUInt32();
     info.Count                 = (ushort)r.ReadUInt32();
     info.Intercept.X           = r.ReadDouble();
     info.Intercept.Y           = r.ReadDouble();
     info.Intercept.Z           = r.ReadDouble();
     info.Slope.X               = r.ReadDouble();
     info.Slope.Y               = r.ReadDouble();
     info.Slope.Z               = r.ReadDouble();
     info.Sigma                 = r.ReadDouble();
     info.TopZ                  = r.ReadDouble();
     info.BottomZ               = r.ReadDouble();
     m_OriginalRawData.Fragment = 0;
     m_Info   = info;
     m_Id     = id;
     m_IdView = r.ReadInt32();
 }
Esempio n. 14
0
 /// <summary>
 /// Reads a MIPBaseTrack from file, along with its associated microtracks.
 /// </summary>
 /// <param name="t">the top Side of the LinkedZone.</param>
 /// <param name="b">the bottom Side of the LinkedZone.</param>
 /// <param name="id">the Id of the track to be read.</param>
 /// <param name="r">the <c>BinaryReader</c> wrapping the data containing file.</param>
 public MIPBaseTrack(Side t, Side b, int id, System.IO.BinaryReader r)
 {
     m_TopSide    = t;
     m_BottomSide = b;
     m_Id         = id;
     SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo();
     info.AreaSum     = (ushort)r.ReadUInt32();
     info.Count       = (ushort)r.ReadUInt32();
     info.Intercept.X = r.ReadDouble();
     info.Intercept.Y = r.ReadDouble();
     info.Intercept.Z = r.ReadDouble();
     info.Slope.X     = r.ReadDouble();
     info.Slope.Y     = r.ReadDouble();
     info.Slope.Z     = r.ReadDouble();
     info.Sigma       = r.ReadDouble();
     m_IdTop          = r.ReadUInt32();
     m_IdBottom       = r.ReadUInt32();
     info.TopZ        = t[(int)m_IdTop].Info.TopZ;
     info.BottomZ     = b[(int)m_IdBottom].Info.BottomZ;
     m_Info           = info;
 }
Esempio n. 15
0
        private double calculateSingleScatt(SySal.Tracking.MIPEmulsionTrackInfo data1, SySal.Tracking.MIPEmulsionTrackInfo data2, double X0)
        {
            //Calcolo solo DL/XO mi devo ricordare di moltiplicare per 13.6 al quadrato e dividere per p^2 e fare la radice
            double result;
            double dx = data1.Intercept.X - data2.Intercept.X;
            double dy = data1.Intercept.Y - data2.Intercept.Y;
            double dz = data1.Intercept.Z - data2.Intercept.Z;

            result = Math.Sqrt(dx * dx + dy * dy + dz * dz) / X0;
#if _USE_LOG_
#if _USE_G4_
            double lg = 1.0 + 0.038 * Math.Log(result);
            result *= (lg * lg);
#else
            double lg = 1.0 + 0.038 * Math.Log(result);
            result *= (lg * lg);
#endif
#endif

            return(result);
        }
Esempio n. 16
0
        private SySal.Tracking.MIPEmulsionTrackInfo[] orderElementData(SySal.Tracking.MIPEmulsionTrackInfo[] toOrder)
        {
            SySal.Tracking.MIPEmulsionTrackInfo[] myData = new SySal.Tracking.MIPEmulsionTrackInfo[toOrder.Length];
            ArrayList data = new ArrayList();
            int       i;

            for (i = 0; i < toOrder.Length; i++)
            {
                SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo();
                info = toOrder[i];
                data.Add(info);
            }

            IComparer myComparer = new MomentumEstimator.order();

            data.Sort(myComparer);

            SySal.Tracking.MIPEmulsionTrackInfo[] tkArray = (SySal.Tracking.MIPEmulsionTrackInfo[])data.ToArray(typeof(SySal.Tracking.MIPEmulsionTrackInfo));
            myData = tkArray;
            return(myData);
        }
Esempio n. 17
0
            public void AddMIPBasetrack(SySal.Tracking.MIPEmulsionTrackInfo info, int id, int topid, int botid)
            {
                if (id < 0)
                {
                    throw new Exception("Only positive Ids are accepted. " + id + " is rejected.");
                }
                if (id >= linked)
                {
                    t_linked.Seek(0, System.IO.SeekOrigin.End);
                    while (linked < id)
                    {
                        b_linked.Write(empty_lk);
                        linked++;
                    }
                }
                else
                {
                    t_linked.Seek(((long)id) * MIPBaseTrack.Size, System.IO.SeekOrigin.Begin);
                }
                long chkpos = t_linked.Position;

                b_linked.Write(info.AreaSum);
                b_linked.Write((uint)info.Count);
                b_linked.Write(info.Intercept.X);
                b_linked.Write(info.Intercept.Y);
                b_linked.Write(info.Intercept.Z);
                b_linked.Write(info.Slope.X);
                b_linked.Write(info.Slope.Y);
                b_linked.Write(info.Slope.Z);
                b_linked.Write(info.Sigma);
                b_linked.Write(topid);
                b_linked.Write(botid);
                if (t_linked.Position - chkpos != MIPBaseTrack.Size)
                {
                    throw new Exception("A");
                }
                linked = Math.Max(id + 1, linked);
            }
Esempio n. 18
0
 public static void AdjustSlopes(SySal.Scanning.MIPIndexedEmulsionTrack t, double slopemultiplier, double slopedx, double slopedy)
 {
     SySal.Tracking.MIPEmulsionTrackInfo info = MIPEmulsionTrack.AccessInfo(t);
     info.Slope.X = info.Slope.X * slopemultiplier + slopedx;
     info.Slope.Y = info.Slope.Y * slopemultiplier + slopedy;
 }
Esempio n. 19
0
        static void Main(string[] args)
        {
            bool   inputFileDefined   = false;
            bool   inputConfigDefined = false;
            bool   fitLoggerDefined   = false;
            bool   diffLoggerDefined  = false;
            bool   editconfigDefined  = false;
            bool   radlenDefined      = false;
            bool   minentrDefined     = false;
            bool   noise0Defined      = false;
            bool   noise1Defined      = false;
            bool   noise2Defined      = false;
            bool   zstepDefined       = false;
            bool   zmaxDefined        = false;
            bool   platedownDefined   = false;
            bool   useProjDefined     = false;
            double uRL        = -1.0;
            double radlen     = -1.0;
            int    minentr    = -1;
            double noise0     = -1.0;
            double noise1     = -1.0;
            double noise2     = -1.0;
            string FileIn     = "";
            string FileConfig = "";
            string FitLog     = "";
            string DiffLog    = "";
            double zstep      = 1300.0;
            double zmax       = 0.0;
            bool   ignT       = false;
            bool   ignL       = false;
            int    platedown  = 57;

            try
            {
                int argnum;
                for (argnum = 0; argnum < args.Length; argnum++)
                {
                    switch (args[argnum].ToLower())
                    {
                    case "/radlen":
                    {
                        radlenDefined = true;
                        radlen        = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture);
                        argnum++;
                        break;
                    }

                    case "/minentr":
                    {
                        minentrDefined = true;
                        minentr        = System.Convert.ToInt32(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture);
                        argnum++;
                        break;
                    }

                    case "/use":
                    {
                        useProjDefined = true;
                        switch (args[argnum + 1].ToLower())
                        {
                        case "t": ignT = false; ignL = true; break;

                        case "l": ignT = true; ignL = false; break;

                        case "3d": ignT = false; ignL = false; break;

                        default: throw new Exception("Unknown projection switch \"" + args[argnum + 1] + "\".");
                        }
                        argnum++;
                        break;
                    }

                    case "/noise0":
                    {
                        noise0Defined = true;
                        noise0        = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture);
                        argnum++;
                        break;
                    }

                    case "/noise1":
                    {
                        noise1Defined = true;
                        noise1        = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture);
                        argnum++;
                        break;
                    }

                    case "/noise2":
                    {
                        noise2Defined = true;
                        noise2        = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture);
                        argnum++;
                        break;
                    }

                    case "/zstep":
                    {
                        zstepDefined = true;
                        zstep        = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture);
                        argnum++;
                        break;
                    }

                    case "/zmax":
                    {
                        zmaxDefined = true;
                        zmax        = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture);
                        argnum++;
                        break;
                    }

                    case "/platedown":
                    {
                        platedownDefined = true;
                        platedown        = System.Convert.ToInt32(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture);
                        argnum++;
                        break;
                    }

                    case "/fitlogfile":
                    {
                        fitLoggerDefined = true;
                        FitLog           = args[argnum + 1];
                        argnum++;
                        break;
                    }

                    case "/difflogfile":
                    {
                        diffLoggerDefined = true;
                        DiffLog           = args[argnum + 1];
                        argnum++;
                        break;
                    }

                    case "/inputfile":
                    {
                        inputFileDefined = true;
                        FileIn           = args[argnum + 1];
                        argnum++;
                        break;
                    }

                    case "/configfile":
                    {
                        inputConfigDefined = true;
                        FileConfig         = args[argnum + 1];
                        argnum++;
                        break;
                    }

                    case "/editconfigfile":
                    {
                        editconfigDefined = true;
                        FileConfig        = args[argnum + 1];
                        break;
                    }
                    }
                }

                if (editconfigDefined)
                {
                    System.Windows.Forms.Application.EnableVisualStyles();
                    EditConfigForm         ec = new EditConfigForm();
                    System.IO.StreamReader r1 = null;
                    System.IO.StreamWriter w  = null;
                    System.Xml.Serialization.XmlSerializer xmls1 = new System.Xml.Serialization.XmlSerializer(typeof(SySal.Processing.MCSAnnecy.Configuration));
                    try
                    {
                        r1   = new System.IO.StreamReader(FileConfig);
                        ec.C = (SySal.Processing.MCSAnnecy.Configuration)xmls1.Deserialize(r1);
                    }
                    catch (Exception)
                    {
                        ec.C = (SySal.Processing.MCSAnnecy.Configuration) new SySal.Processing.MCSAnnecy.MomentumEstimator().Config;
                    }
                    finally
                    {
                        if (r1 != null)
                        {
                            r1.Close();
                        }
                    }
                    if (ec.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        try
                        {
                            w = new StreamWriter(FileConfig);
                            xmls1.Serialize(w, ec.C);
                            w.Flush();
                            w.Close();
                        }
                        catch (Exception x)
                        {
                            System.Windows.Forms.MessageBox.Show("Can't write to file \"" + FileConfig + "\"!", "File Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        }
                        finally
                        {
                            if (w != null)
                            {
                                w.Close();
                            }
                        }
                    }
                    return;
                }
                else if (inputFileDefined == false /* || inputConfigDefined == false*/)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Usage: BatchMCSAnnecy.exe {parameters}");
                Console.WriteLine("parameters");
                Console.WriteLine("/radlen <p> - radiation length (total) between two measurements");
                Console.WriteLine("/minentr <p> - minimum number of entries per cell");
                Console.WriteLine("/use <p> - can be T, L or 3D to use transverse, longitudinal or 3D data");
                Console.WriteLine("/noise0 <p> - 3D slope measurement error (0th order coefficient)");
                Console.WriteLine("/noise1 <p> - 3D slope measurement error (1st order coefficient)");
                Console.WriteLine("/noise2 <p> - 3D slope measurement error (2nd order coefficient)");
                Console.WriteLine("/zstep <p> - distance between two plates (default = 1300.0)");
                Console.WriteLine("/zmax <p> - Z of most downstream plate (default = 0.0)");
                Console.WriteLine("/platedown <p> - Id of the most downstream plate (default = 57)");
                Console.WriteLine("/inputfile <p> - input file");
                Console.WriteLine("/fitlogfile <p> - optional file to log the progress of fitting");
                Console.WriteLine("/difflogfile <p> - optional file to log slope differences");
                Console.WriteLine("/configfile<p> - geometry configuration file");
                Console.WriteLine("/editconfigfile <p> - geometry configuration file to be edited/created");
                Console.WriteLine();
                Console.WriteLine("Input data format:");
                Console.WriteLine("ID\tPlate\tZ\tSX\tSY\tX\tY");
                return;
            }

            SySal.Processing.MCSAnnecy.Configuration C = new SySal.Processing.MCSAnnecy.Configuration();
            if (noise0Defined)
            {
                C.SlopeError3D_0 = noise0;
            }
            if (noise1Defined)
            {
                C.SlopeError3D_1 = noise1;
            }
            if (noise2Defined)
            {
                C.SlopeError3D_2 = noise2;
            }
            if (minentrDefined)
            {
                C.MinEntries = minentr;
            }
            if (radlenDefined)
            {
                C.RadiationLength = radlen;
            }
            C.IgnoreLongitudinal = ignL;
            C.IgnoreTransverse   = ignT;

            if (FileConfig != null && FileConfig.Trim().Length > 0)
            {
                System.Xml.Serialization.XmlSerializer xmls = new System.Xml.Serialization.XmlSerializer(typeof(Geometry));
                System.IO.StreamReader r = new System.IO.StreamReader(FileConfig);
                r.Close();
            }

            System.Text.RegularExpressions.Regex         colfmt_rx      = new System.Text.RegularExpressions.Regex(@"\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*");
            SySal.Processing.MCSAnnecy.MomentumEstimator momCalculation = new SySal.Processing.MCSAnnecy.MomentumEstimator();
            momCalculation.Config = C;

            System.IO.StreamWriter logstream = null;
            if (FitLog.Trim().Length > 0)
            {
                logstream             = new System.IO.StreamWriter(FitLog);
                logstream.AutoFlush   = true;
                momCalculation.FitLog = logstream;
            }

            System.IO.StreamWriter difflogstream = null;
            if (DiffLog.Trim().Length > 0)
            {
                difflogstream           = new System.IO.StreamWriter(DiffLog);
                difflogstream.AutoFlush = true;
                momCalculation.DiffLog  = difflogstream;
            }

            ArrayList InputData = new ArrayList();

            int          idTrack;
            int          idTrack0  = -1;
            bool         isfirst   = true;
            StreamReader FileInput = new StreamReader(FileIn);
            string       rLine;

            while ((rLine = FileInput.ReadLine()) != null)
            {
                System.Text.RegularExpressions.Match rx_m = colfmt_rx.Match((string)(rLine));
                if (rx_m.Success)
                {
                    SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo();
                    idTrack          = System.Convert.ToInt32(rx_m.Groups[1].Value);
                    info.Slope.X     = System.Convert.ToDouble(rx_m.Groups[4].Value);
                    info.Slope.Y     = System.Convert.ToDouble(rx_m.Groups[5].Value);
                    info.Intercept.Z = System.Convert.ToDouble(rx_m.Groups[3].Value);
                    info.Intercept.X = System.Convert.ToDouble(rx_m.Groups[6].Value);
                    info.Intercept.Y = System.Convert.ToDouble(rx_m.Groups[7].Value);
                    info.Field       = (uint)System.Convert.ToDouble(rx_m.Groups[2].Value);
                    //info.Field = (uint)(Math.Round((info.Intercept.Z - zmax) / zstep) + platedown);
                    if (isfirst)
                    {
                        idTrack0 = idTrack;
                    }
                    if (idTrack0 != idTrack)
                    {
                        ComputeAndShowResult(FileIn, idTrack0, InputData, momCalculation);
                        InputData.Clear();
                        idTrack0 = idTrack;
                    }
                    isfirst = false;
                    InputData.Add(info);
                }
                else
                {
                    Console.WriteLine("Format error at line " + rLine);
                    return;
                }
            }
            if (InputData.Count > 0)
            {
                ComputeAndShowResult(FileIn, idTrack0, InputData, momCalculation);
            }
            FileInput.Close();
            if (logstream != null)
            {
                logstream.Close();
            }
            if (difflogstream != null)
            {
                difflogstream.Close();
            }
        }
Esempio n. 20
0
        public static MomentumResult ProcessData(IMCSMomentumEstimator algo, Track tk)
        {
            int i, j;

            SySal.Tracking.MIPEmulsionTrackInfo[] tkinfo = new SySal.Tracking.MIPEmulsionTrackInfo[tk.Length];
            if (algo is SySal.Processing.MCSLikelihood.MomentumEstimator)
            {
                Geometry geom = ((SySal.Processing.MCSLikelihood.Configuration)(((SySal.Management.IManageable)((object)algo)).Config)).Geometry;
                for (i = 0; i < tkinfo.Length; i++)
                {
                    if (tk[i].LayerOwner.Side != 0)
                    {
                        throw new Exception("This functionality is only available for base-tracks.\r\nConsider using the interactive version, available in the interactive display.");
                    }
                    tkinfo[i] = tk[i].Info;
                    for (j = 0; j < geom.Layers.Length && tk[i].LayerOwner.SheetId != geom.Layers[j].Plate; j++)
                    {
                        ;
                    }
                    if (j == geom.Layers.Length)
                    {
                        throw new Exception("Layer " + i + " Sheet " + tk[i].LayerOwner.SheetId + " does not map to any plate in momentum geometry.\r\nPlease check your geometry information.");
                    }
                    double z = (tkinfo[i].TopZ + tkinfo[i].BottomZ) * 0.5;
                    if (z < tk[i].LayerOwner.UpstreamZ)
                    {
                        z = tk[i].LayerOwner.UpstreamZ;
                    }
                    else if (z > tk[i].LayerOwner.DownstreamZ)
                    {
                        z = tk[i].LayerOwner.DownstreamZ;
                    }
                    tkinfo[i].Intercept.X += tkinfo[i].Slope.X * (z - tkinfo[i].Intercept.Z);
                    tkinfo[i].Intercept.Y += tkinfo[i].Slope.Y * (z - tkinfo[i].Intercept.Z);
                    tkinfo[i].Intercept.Z  = geom.Layers[j].ZMin + z - tk[i].LayerOwner.UpstreamZ;
                }
            }
            else if (algo is SySal.Processing.MCSAnnecy.MomentumEstimator)
            {
                for (i = 0; i < tkinfo.Length; i++)
                {
                    if (tk[i].LayerOwner.Side != 0)
                    {
                        throw new Exception("This functionality is only available for base-tracks.\r\nConsider using the interactive version, available in the interactive display.");
                    }
                    tkinfo[i]       = tk[i].Info;
                    tkinfo[i].Field = (uint)tk[i].LayerOwner.Id;
                }
            }
            else
            {
                throw new Exception("Unsupported algorithm.");
            }
            MomentumResult res = algo.ProcessData(tkinfo);

            if (res.Value < 0.0)
            {
                throw new Exception("Invalid measurement");
            }
            tk.SetAttribute(new SySal.TotalScan.NamedAttributeIndex("P"), res.Value);
            tk.SetAttribute(new SySal.TotalScan.NamedAttributeIndex("PMin" + (res.ConfidenceLevel * 100.0).ToString("F0", System.Globalization.CultureInfo.InvariantCulture)), res.LowerBound);
            tk.SetAttribute(new SySal.TotalScan.NamedAttributeIndex("PMax" + (res.ConfidenceLevel * 100.0).ToString("F0", System.Globalization.CultureInfo.InvariantCulture)), res.UpperBound);
            return(res);
        }
Esempio n. 21
0
 /// <summary>
 /// Sets the geometrical parameters for the segment.
 /// </summary>
 /// <param name="info">the new geometrical parameters.</param>
 /// <remarks>The owner track (if any) receives no notification of the change. External code must maintain the consistency.</remarks>
 public virtual void SetInfo(SySal.Tracking.MIPEmulsionTrackInfo info)
 {
     m_Info = info;
 }
Esempio n. 22
0
        private void Compute(bool comp_x, bool comp_y, object btn)
        {
            m_Running = true;
            EnableButtons(btn);
            m_Stop           = false;
            pbProgress.Value = 0.0;
            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
            {
                try
                {
                    SySal.Processing.QuickMapping.QuickMapper QM    = new SySal.Processing.QuickMapping.QuickMapper();
                    SySal.Processing.QuickMapping.Configuration qmc = (SySal.Processing.QuickMapping.Configuration)QM.Config;
                    qmc.FullStatistics       = false;
                    qmc.UseAbsoluteReference = true;
                    qmc.PosTol   = S.PosTolerance;
                    qmc.SlopeTol = 1.0;
                    QM.Config    = qmc;
                    System.Collections.ArrayList xconv = new System.Collections.ArrayList();
                    System.Collections.ArrayList yconv = new System.Collections.ArrayList();
                    int sfi;
                    for (sfi = 0; sfi < SummaryFiles.Length; sfi++)
                    {
                        QuasiStaticAcquisition Q = new QuasiStaticAcquisition(SummaryFiles[sfi]);
                        foreach (QuasiStaticAcquisition.Sequence seq in Q.Sequences)
                        {
                            int ly;
                            SySal.Imaging.Cluster[] prevC = FilterClusters(seq.Layers[0].ReadClusters());
                            SySal.Imaging.Cluster[] nextC = null;
                            SySal.BasicTypes.Vector prevP = seq.Layers[0].Position;
                            SySal.BasicTypes.Vector nextP = new SySal.BasicTypes.Vector();
                            for (ly = 1; ly < seq.Layers.Length; ly++)
                            {
                                if (m_Stop)
                                {
                                    throw new Exception("Stopped.");
                                }
                                nextC = FilterClusters(seq.Layers[ly].ReadClusters());
                                nextP = seq.Layers[ly].Position;
                                this.Invoke(new dSetValue(SetValue), 100.0 * (((double)seq.Id + (double)(ly - 1) / (double)(seq.Layers.Length - 1)) / (double)(Q.Sequences.Length) + sfi) / SummaryFiles.Length);
                                SySal.BasicTypes.Vector2 dp   = new SySal.BasicTypes.Vector2(seq.Layers[ly].Position - seq.Layers[ly - 1].Position);
                                SySal.BasicTypes.Vector2 dp1  = dp; dp1.X /= S.MinConv; dp1.Y /= S.MinConv;
                                SySal.BasicTypes.Vector2 dp2  = dp; dp2.X /= S.MaxConv; dp2.Y /= S.MaxConv;
                                SySal.BasicTypes.Vector2 da   = new SySal.BasicTypes.Vector2(); da.X = 0.5 * (dp1.X + dp2.X); da.Y = 0.5 * (dp1.Y + dp2.Y);
                                SySal.BasicTypes.Vector2 dext = new SySal.BasicTypes.Vector2(); dext.X = Math.Abs(dp1.X - dp2.X); dext.Y = Math.Abs(dp1.Y - dp2.Y);
                                SySal.Tracking.MIPEmulsionTrackInfo[] prevmap = new SySal.Tracking.MIPEmulsionTrackInfo[prevC.Length];
                                int i;
                                for (i = 0; i < prevC.Length; i++)
                                {
                                    SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo();
                                    info.Intercept.X = prevC[i].X;
                                    info.Intercept.Y = prevC[i].Y;
                                    prevmap[i]       = info;
                                }
                                SySal.Tracking.MIPEmulsionTrackInfo[] nextmap = new SySal.Tracking.MIPEmulsionTrackInfo[nextC.Length];
                                for (i = 0; i < nextC.Length; i++)
                                {
                                    nextmap[i] = new SySal.Tracking.MIPEmulsionTrackInfo();
                                }
                                double[,] convopt = new double[, ] {
                                    { 1.0, 1.0 }, { -1.0, 1.0 }, { -1.0, -1.0 }, { 1.0, -1.0 }
                                };
                                int o;
                                SySal.Scanning.PostProcessing.PatternMatching.TrackPair[] bestpairs = new SySal.Scanning.PostProcessing.PatternMatching.TrackPair[0];
                                SySal.BasicTypes.Vector2 bestda = new SySal.BasicTypes.Vector2();
                                for (o = 0; o < convopt.GetLength(0); o++)
                                {
                                    try
                                    {
                                        for (i = 0; i < nextC.Length; i++)
                                        {
                                            SySal.Tracking.MIPEmulsionTrackInfo info = nextmap[i];
                                            info.Intercept.X = nextC[i].X + da.X * convopt[o, 0];
                                            info.Intercept.Y = nextC[i].Y + da.Y * convopt[o, 1];
                                            nextmap[i]       = info;
                                        }
                                        SySal.Scanning.PostProcessing.PatternMatching.TrackPair[] prs = QM.Match(prevmap, nextmap, 0.0, dext.X, dext.Y);
                                        if (prs.Length > bestpairs.Length)
                                        {
                                            bestda.X  = da.X * convopt[o, 0];
                                            bestda.Y  = da.Y * convopt[o, 1];
                                            bestpairs = prs;
                                        }
                                    }
                                    catch (Exception xc) { }
                                }

                                if (bestpairs.Length >= S.MinMatches)
                                {
                                    double[] deltas = new double[bestpairs.Length];
                                    for (i = 0; i < bestpairs.Length; i++)
                                    {
                                        deltas[i] = bestpairs[i].First.Info.Intercept.X - nextC[bestpairs[i].Second.Index].X;
                                    }
                                    bestda.X = NumericalTools.Fitting.Quantiles(deltas, new double[] { 0.5 })[0];
                                    if (bestda.X != 0.0)
                                    {
                                        double v = dp.X / bestda.X;
                                        int pos  = xconv.BinarySearch(v);
                                        if (pos < 0)
                                        {
                                            pos = ~pos;
                                        }
                                        xconv.Insert(pos, v);
                                    }
                                    for (i = 0; i < bestpairs.Length; i++)
                                    {
                                        deltas[i] = bestpairs[i].First.Info.Intercept.Y - nextC[bestpairs[i].Second.Index].Y;
                                    }
                                    bestda.Y = NumericalTools.Fitting.Quantiles(deltas, new double[] { 0.5 })[0];
                                    if (bestda.Y != 0.0)
                                    {
                                        double v = dp.Y / bestda.Y;
                                        int pos  = yconv.BinarySearch(v);
                                        if (pos < 0)
                                        {
                                            pos = ~pos;
                                        }
                                        yconv.Insert(pos, v);
                                    }
                                    if (comp_x && xconv.Count > 0)
                                    {
                                        int bmin, bmax;
                                        bmin = (int)Math.Ceiling(xconv.Count * 0.16);
                                        bmax = (int)Math.Floor(xconv.Count * 0.84);
                                        if (bmax < bmin)
                                        {
                                            bmin = bmax;
                                        }
                                        double[] sample1s = (double[])xconv.GetRange(bmin, bmax - bmin + 1).ToArray(typeof(double));
                                        XConv             = NumericalTools.Fitting.Average(sample1s);
                                        this.Invoke(new dSetConv(SetConv), new object[] { true, XConv, 0.5 * (sample1s[sample1s.Length - 1] - sample1s[0]) / Math.Sqrt(sample1s.Length) });
                                    }
                                    if (comp_y && yconv.Count > 0)
                                    {
                                        int bmin, bmax;
                                        bmin = (int)Math.Ceiling(yconv.Count * 0.16);
                                        bmax = (int)Math.Floor(yconv.Count * 0.84);
                                        if (bmax < bmin)
                                        {
                                            bmin = bmax;
                                        }
                                        double[] sample1s = (double[])yconv.GetRange(bmin, bmax - bmin + 1).ToArray(typeof(double));
                                        YConv             = NumericalTools.Fitting.Average(sample1s);
                                        this.Invoke(new dSetConv(SetConv), new object[] { false, YConv, 0.5 * (sample1s[sample1s.Length - 1] - sample1s[0]) / Math.Sqrt(sample1s.Length) });
                                    }
                                }
                                prevP = nextP;
                                prevC = nextC;
                            }
                        }
                    }
                }
                catch (Exception xc1)
                {
                    iLog.Log("Compute", xc1.ToString());
                }
                m_Running = false;
                this.Invoke(new dEnableButtons(EnableButtons), btn);
            }));
            thread.Start();
        }
Esempio n. 23
0
        private static void ThreeZoneIntercalibration(string [] args, ref SySal.DAQSystem.Scanning.IntercalibrationInfo intercal, bool rewrite)
        {
            int i, n;
            int MinMatches = Convert.ToInt32(args[11]);

            SySal.Processing.QuickMapping.QuickMapper   QMap = new SySal.Processing.QuickMapping.QuickMapper();
            SySal.Processing.QuickMapping.Configuration C    = (SySal.Processing.QuickMapping.Configuration)QMap.Config;
            C.PosTol    = Convert.ToDouble(args[8], System.Globalization.CultureInfo.InvariantCulture);
            C.SlopeTol  = Convert.ToDouble(args[9], System.Globalization.CultureInfo.InvariantCulture);
            QMap.Config = C;
            double ZProj     = Convert.ToDouble(args[7], System.Globalization.CultureInfo.InvariantCulture);
            double maxoffset = Convert.ToDouble(args[10], System.Globalization.CultureInfo.InvariantCulture);

            MapPos [] mappositions = new MapPos[3];

            SySal.Scanning.Plate.IO.OPERA.LinkedZone [] savezones = new SySal.Scanning.Plate.IO.OPERA.LinkedZone[3];
            for (n = 0; n < 3; n++)
            {
                SySal.Scanning.Plate.IO.OPERA.LinkedZone reflz   = (SySal.Scanning.Plate.IO.OPERA.LinkedZone)SySal.OperaPersistence.Restore(args[1 + n * 2], typeof(SySal.Scanning.Plate.IO.OPERA.LinkedZone));
                SySal.Tracking.MIPEmulsionTrackInfo []   refzone = new SySal.Tracking.MIPEmulsionTrackInfo[reflz.Length];
                for (i = 0; i < refzone.Length; i++)
                {
                    refzone[i] = reflz[i].Info;
                }
                reflz = null;
                SySal.Scanning.Plate.IO.OPERA.LinkedZone caliblz = (SySal.Scanning.Plate.IO.OPERA.LinkedZone)SySal.OperaPersistence.Restore(args[2 + n * 2], typeof(SySal.Scanning.Plate.IO.OPERA.LinkedZone));
                if (rewrite)
                {
                    savezones[n] = caliblz;
                }
                SySal.Tracking.MIPEmulsionTrackInfo [] calibzone = new SySal.Tracking.MIPEmulsionTrackInfo[caliblz.Length];
                for (i = 0; i < calibzone.Length; i++)
                {
                    calibzone[i] = caliblz[i].Info;
                }
                caliblz = null;
                GC.Collect();
                Console.Write("Zone #" + n.ToString() + " ");
                SySal.Scanning.PostProcessing.PatternMatching.TrackPair [] pairs = QMap.Match(refzone, calibzone, ZProj, maxoffset, maxoffset);
                if (pairs.Length < MinMatches)
                {
                    Console.Error.WriteLine("Too few matching tracks: " + MinMatches.ToString() + " required, " + pairs.Length + " obtained. Aborting.");
                    return;
                }
                Console.WriteLine("Matches: " + pairs.Length);
                mappositions[n].SetFromPairs(pairs);
                mappositions[n].X -= intercal.RX;
                mappositions[n].Y -= intercal.RY;
            }
            double x20 = mappositions[2].X - mappositions[0].X;
            double x10 = mappositions[1].X - mappositions[0].X;
            double y20 = mappositions[2].Y - mappositions[0].Y;
            double y10 = mappositions[1].Y - mappositions[0].Y;
            double det = 1.0 / (x10 * y20 - x20 * y10);
            double u20 = mappositions[2].DX - mappositions[0].DX;
            double v20 = mappositions[2].DY - mappositions[0].DY;
            double u10 = mappositions[1].DX - mappositions[0].DX;
            double v10 = mappositions[1].DY - mappositions[0].DY;

            intercal.MXX  = (u10 * y20 - u20 * y10) * det;
            intercal.MXY  = (u20 * x10 - u10 * x20) * det;
            intercal.MYX  = (v10 * y20 - v20 * y10) * det;
            intercal.MYY  = (v20 * x10 - v10 * x20) * det;
            intercal.TX   = mappositions[0].DX - intercal.MXX * mappositions[0].X - intercal.MXY * mappositions[0].Y;
            intercal.TY   = mappositions[0].DY - intercal.MYX * mappositions[0].X - intercal.MYY * mappositions[0].Y;
            intercal.MXX += 1.0;
            intercal.MYY += 1.0;
            CheckIntercalibration(intercal);
            if (rewrite)
            {
                MyTransformation.Transformation = intercal;
                for (n = 0; n < 3; n++)
                {
                    SySal.OperaPersistence.Persist(args[2 + n * 2], new LinkedZone(savezones[n]));
                }
            }
        }
Esempio n. 24
0
        public SySal.Imaging.Grain3D[] MakeGrainsFromClusters(SySal.Imaging.Cluster3D[][] cls, SySal.BasicTypes.Vector[] positions)
        {
            this.DemagCoefficients = new double[0];
            this.MatchDX           = new double[0];
            this.MatchDY           = new double[0];
            System.Collections.ArrayList adx = new System.Collections.ArrayList();
            System.Collections.ArrayList ady = new System.Collections.ArrayList();
            int i;
            int halfw = (int)(C.ImageWidth / 2);
            int halfh = (int)(C.ImageHeight / 2);

            ChainCluster[][]             planes = new ChainCluster[positions.Length][];
            System.Collections.ArrayList demags = new System.Collections.ArrayList();
            int    plane;
            double c2x, c2y;
            double px0 = positions[0].X;
            double py0 = positions[0].Y;
            double pz0 = positions[0].Z;

            for (plane = 0; plane < planes.Length; plane++)
            {
                if (Progress != null)
                {
                    Progress((double)plane / (double)planes.Length * 0.5);
                }
                if (ShouldStop != null && ShouldStop())
                {
                    return(null);
                }
                planes[plane] = new ChainCluster[cls[plane].Length];
                SySal.Imaging.Cluster3D [] cplanes = cls[plane];
                double px  = positions[plane].X;
                double py  = positions[plane].Y;
                double pz  = positions[plane].Z;
                double pxd = px - px0;
                double pyd = py - py0;
                double pzd = pz - pz0;
                double dmz = OptimizeDemagCoefficient ? 1 : Math.Pow(1.0 + C.DMagDZ, pzd);
                for (i = 0; i < planes[plane].Length; i++)
                {
                    ChainCluster cc = new ChainCluster();
                    cc.Cluster       = cplanes[i].Cluster;
                    cc.Id            = i;
                    cc.Plane         = plane;
                    cc.Z             = pz;
                    cc.Cluster.X     = (cc.Cluster.X - halfw) * C.Pixel2Micron.X * dmz; // +px;
                    cc.Cluster.Y     = (cc.Cluster.Y - halfh) * C.Pixel2Micron.Y * dmz; // +py;
                    c2y              = cc.Cluster.X * cc.Cluster.X * C.XYCurvature * cc.Cluster.Y;
                    c2x              = cc.Cluster.Y * cc.Cluster.Y * C.XYCurvature * cc.Cluster.X;
                    cc.Cluster.X    += c2x;
                    cc.Cluster.Y    += c2y;
                    cc.Z            += C.ZCurvature * (cc.Cluster.X * cc.Cluster.X + cc.Cluster.Y * cc.Cluster.Y);
                    cc.Cluster.X    += pxd;
                    cc.Cluster.Y    += pyd;
                    planes[plane][i] = cc;
                }
            }
            if (Progress != null)
            {
                Progress(0.5);
            }

            for (i = 0; i < planes.Length - 1; i++)
            {
                if (Progress != null)
                {
                    Progress(0.5 + 0.5 * (double)i / (double)(planes.Length - 1));
                }
                if (ShouldStop != null && ShouldStop())
                {
                    return(null);
                }
                SySal.Tracking.MIPEmulsionTrackInfo[] t1 = new SySal.Tracking.MIPEmulsionTrackInfo[planes[i].Length];
                SySal.Tracking.MIPEmulsionTrackInfo[] t2 = new SySal.Tracking.MIPEmulsionTrackInfo[planes[i + 1].Length];
                int j;
                for (j = 0; j < t1.Length; j++)
                {
                    ChainCluster cc = planes[i][j];
                    SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo();
                    info.Count       = (ushort)cc.Cluster.Area;
                    info.AreaSum     = (uint)j;
                    info.Intercept.X = cc.Cluster.X;
                    info.Intercept.Y = cc.Cluster.Y;
                    info.Intercept.Z = 0.0;
                    info.Slope.X     = info.Slope.Y = info.Slope.Z = 0.0;
                    t1[j]            = info;
                }
                for (j = 0; j < t2.Length; j++)
                {
                    ChainCluster cc = planes[i + 1][j];
                    SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo();
                    info.Count       = (ushort)cc.Cluster.Area;
                    info.AreaSum     = (ushort)j;// cls.Id;
                    info.Intercept.X = cc.Cluster.X + 2.0 * (C.ClusterMatchMaxOffset + C.ClusterMatchPositionTolerance);
                    info.Intercept.Y = cc.Cluster.Y + 2.0 * (C.ClusterMatchMaxOffset + C.ClusterMatchPositionTolerance);
                    info.Intercept.Z = 0.0;
                    info.Slope.X     = info.Slope.Y = info.Slope.Z = 0.0;
                    t2[j]            = info;
                }
                try
                {
                    SySal.Processing.QuickMapping.Configuration qmc = (SySal.Processing.QuickMapping.Configuration)QM.Config;
                    qmc.FullStatistics       = false;
                    qmc.UseAbsoluteReference = true;
                    qmc.PosTol   = C.ClusterMatchPositionTolerance * 0.5;
                    qmc.SlopeTol = 1.0;
                    QM.Config    = qmc;
                    int bkg = QM.Match(t1, t2, 0.0, C.ClusterMatchPositionTolerance * 0.25, C.ClusterMatchPositionTolerance * 0.25).Length;
                    for (j = 0; j < t2.Length; j++)
                    {
                        ChainCluster cc = planes[i + 1][j];
                        t2[j].Intercept.X = cc.Cluster.X;
                        t2[j].Intercept.Y = cc.Cluster.Y;
                    }
                    qmc.PosTol = C.ClusterMatchMaxOffset * 0.5;
                    QM.Config  = qmc;
                    SySal.Scanning.PostProcessing.PatternMatching.TrackPair[] tp = QM.Match(t1, t2, 0.0, C.ClusterMatchMaxOffset * 0.25, C.ClusterMatchMaxOffset * 0.25);
                    double deltax = 0.0, deltay = 0.0, demagx = 0.0, demagy = 0.0;
                    double dummy = 0.0;
                    double q = (1.0 - (double)bkg / (double)tp.Length) * 0.25;
                    double[,] deltas = new double[tp.Length, 4];
                    for (j = 0; j < tp.Length; j++)
                    {
                        deltas[j, 0] = tp[j].Second.Info.Intercept.X;
                        deltas[j, 1] = tp[j].Second.Info.Intercept.Y;
                        deltas[j, 2] = tp[j].First.Info.Intercept.X - tp[j].Second.Info.Intercept.X;
                        deltas[j, 3] = tp[j].First.Info.Intercept.Y - tp[j].Second.Info.Intercept.Y;
                    }
                    int[]    ids = NumericalTools.Fitting.PeakDataSel(deltas, new double[] { Math.Abs(halfw * C.Pixel2Micron.X) * 0.25, Math.Abs(halfh * C.Pixel2Micron.Y) * 0.25, C.ClusterMatchPositionTolerance * 0.5, C.ClusterMatchPositionTolerance * 0.5 }, -1.0, q);
                    double[] ws = new double[ids.Length];
                    double[] dws = new double[ids.Length];
                    for (j = 0; j < ids.Length; j++)
                    {
                        ws[j]  = deltas[ids[j], 0];
                        dws[j] = deltas[ids[j], 2];
                    }
                    NumericalTools.ComputationResult resx = NumericalTools.Fitting.LinearFitSE(ws, dws, ref demagx, ref deltax, ref dummy, ref dummy, ref dummy, ref dummy, ref dummy);
                    for (j = 0; j < ids.Length; j++)
                    {
                        ws[j]  = deltas[ids[j], 1];
                        dws[j] = deltas[ids[j], 3];
                    }
                    double dmagdeltaz = positions[i + 1].Z - positions[i].Z;
                    NumericalTools.ComputationResult resy = NumericalTools.Fitting.LinearFitSE(ws, dws, ref demagy, ref deltay, ref dummy, ref dummy, ref dummy, ref dummy, ref dummy);
                    if (resx == NumericalTools.ComputationResult.OK && resy == NumericalTools.ComputationResult.OK)
                    {
                        demags.Add(Math.Log(1.0 + demagx) / dmagdeltaz);
                        demags.Add(Math.Log(1.0 + demagy) / dmagdeltaz);
                    }
                    for (j = 0; j < t2.Length; j++)
                    {
                        ChainCluster cc = planes[i + 1][j];
                        t2[j].Intercept.X += deltax;
                        t2[j].Intercept.Y += deltay;
                        cc.Cluster.X      += deltax;
                        cc.Cluster.Y      += deltay;
                    }
                    qmc.PosTol = C.ClusterMatchPositionTolerance * 0.5;
                    QM.Config  = qmc;
                    tp         = QM.Match(t1, t2, 0.0, C.ClusterMatchPositionTolerance * 0.25, C.ClusterMatchPositionTolerance * 0.25);
                    foreach (SySal.Scanning.PostProcessing.PatternMatching.TrackPair tp1 in tp)
                    {
                        if (planes[i][tp1.First.Info.AreaSum].Next == null && planes[i + 1][tp1.Second.Info.AreaSum].PreviousSize == 0 &&
                            (planes[i][tp1.First.Info.AreaSum].Cluster.Area < planes[i + 1][tp1.Second.Info.AreaSum].Cluster.Area &&
                             planes[i][tp1.First.Info.AreaSum].Cluster.Area < planes[i][tp1.First.Info.AreaSum].PreviousSize) == false)
                        {
                            planes[i][tp1.First.Info.AreaSum].Next = planes[i + 1][tp1.Second.Info.AreaSum];
                            planes[i + 1][tp1.Second.Info.AreaSum].PreviousSize = planes[i][tp1.First.Info.AreaSum].Cluster.Area;
                            adx.Add(tp1.First.Info.Intercept.X - tp1.Second.Info.Intercept.X);
                            ady.Add(tp1.First.Info.Intercept.Y - tp1.Second.Info.Intercept.Y);
                        }
                    }
                }
                catch (Exception) { }
            }

            System.Collections.ArrayList achains = new System.Collections.ArrayList();
            System.Collections.ArrayList grains  = new System.Collections.ArrayList();
            foreach (ChainCluster[] cplane in planes)
            {
                foreach (ChainCluster cc in cplane)
                {
                    if (cc.Next != null)
                    {
                        cc.Next.Id = -1;
                    }
                    if (cc.Id >= 0)
                    {
                        achains.Add(cc);
                    }
                }
            }
            foreach (ChainCluster cc in achains)
            {
                int          totalc = 1;
                ChainCluster cc1    = cc.Next;
                while (cc1 != null)
                {
                    cc1 = cc1.Next;
                    totalc++;
                }
                SySal.Imaging.Cluster3D[] cl3d = new SySal.Imaging.Cluster3D[totalc];
                totalc = 0;
                cc1    = cc;
                uint gvolume = 0;
                while (cc1 != null)
                {
                    double dmz = OptimizeDemagCoefficient ? 1 : Math.Pow(1.0 + C.DMagDZ, positions[cc1.Plane].Z - positions[0].Z);
                    cl3d[totalc].Cluster   = cc1.Cluster;
                    cl3d[totalc].Cluster.X = cl3d[totalc].Cluster.X / dmz + positions[0].X;
                    cl3d[totalc].Cluster.Y = cl3d[totalc].Cluster.Y / dmz + positions[0].Y;
                    cl3d[totalc].Layer     = (uint)cc1.Plane;
                    cl3d[totalc].Z         = cc1.Z;
                    gvolume += cc1.Cluster.Area;
                    cc1      = cc1.Next;
                    totalc++;
                }
                if (gvolume < C.MinGrainVolume)
                {
                    continue;
                }

                grains.Add(SySal.Imaging.Grain3D.FromClusterCenters(cl3d));
            }

            this.DemagCoefficients = (double[])demags.ToArray(typeof(double));
            this.MatchDX           = (double[])adx.ToArray(typeof(double));
            this.MatchDY           = (double[])ady.ToArray(typeof(double));
            if (Progress != null)
            {
                Progress(1.0);
            }
            return((SySal.Imaging.Grain3D[])grains.ToArray(typeof(SySal.Imaging.Grain3D)));
        }
Esempio n. 25
0
        private static long DumpZone(string tlgpath, SySal.Scanning.Plate.IO.OPERA.LinkedZone lz, long db_brick_id, long db_plate_id, long db_procop_id, long series, string rawdatapath, DateTime starttime, DateTime endtime, SySal.OperaDb.OperaDbConnection conn, SySal.OperaDb.OperaDbTransaction trans)
        {
            try
            {
                long db_id_zone = 0;

                int    s, i, n;
                double dz, basez;
                SySal.Scanning.Plate.Side side;

                SySal.DAQSystem.Scanning.IntercalibrationInfo transform = lz.Transform;
                double TDX = transform.TX - transform.MXX * transform.RX - transform.MXY * transform.RY;
                double TDY = transform.TY - transform.MYX * transform.RX - transform.MYY * transform.RY;

                //zone
                db_id_zone = SySal.OperaDb.Schema.TB_ZONES.Insert(db_brick_id, db_plate_id, db_procop_id, db_id_zone,
                                                                  lz.Extents.MinX, lz.Extents.MaxX, lz.Extents.MinY, lz.Extents.MaxY,
                                                                  tlgpath, starttime, endtime, series,
                                                                  transform.MXX, transform.MXY, transform.MYX, transform.MYY, TDX, TDY);

                if (FullZoneDump == false)
                {
                    return(db_id_zone);
                }

                //views
                for (s = 0; s < 2; s++)
                {
                    if (s == 0)
                    {
                        side  = lz.Top;
                        basez = lz.Top.BottomZ;
                    }
                    else
                    {
                        side  = lz.Bottom;
                        basez = lz.Bottom.TopZ;
                    }
                    n = ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.Side)side).ViewCount;
                    for (i = 0; i < n; i++)
                    {
                        SySal.Scanning.Plate.IO.OPERA.LinkedZone.View vw = ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.Side)side).View(i);
                        SySal.OperaDb.Schema.TB_VIEWS.Insert(db_brick_id, db_id_zone, s + 1,
                                                             //i + 1,
                                                             vw.Id + 1,
                                                             vw.TopZ, vw.BottomZ, vw.Position.X, vw.Position.Y);
                    }
                }
                SySal.OperaDb.Schema.TB_VIEWS.Flush();

                int TrackId     = 0;
                int UpTrackId   = 0;
                int DownTrackId = 0;

                SySal.Tracking.MIPEmulsionTrackInfo info  = null;
                SySal.Tracking.MIPEmulsionTrackInfo tinfo = null;
                SySal.Tracking.MIPEmulsionTrackInfo binfo = null;

                //Basetracks
                for (i = 0; i < lz.Length; i++)
                {
                    if (lz[i].Info.Sigma >= 0)
                    {
                        info  = lz[i].Info;
                        tinfo = lz[i].Top.Info;
                        binfo = lz[i].Bottom.Info;
                    }
                    else
                    {
                        continue;
                    }

                    DownTrackId++;
                    basez = lz.Top.BottomZ;
                    dz    = (basez - tinfo.Intercept.Z);
                    SySal.OperaDb.Schema.TB_MIPMICROTRACKS.Insert(db_brick_id, db_id_zone,
                                                                  1, DownTrackId,
                                                                  tinfo.Intercept.X + tinfo.Slope.X * dz,
                                                                  tinfo.Intercept.Y + tinfo.Slope.Y * dz,
                                                                  tinfo.Slope.X,
                                                                  tinfo.Slope.Y,
                                                                  tinfo.Count,
                                                                  tinfo.AreaSum,
                                                                  System.DBNull.Value,
                                                                  tinfo.Sigma, ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.MIPIndexedEmulsionTrack)(lz.Top[i])).View.Id + 1);

                    UpTrackId++;
                    basez = lz.Bottom.TopZ;
                    dz    = (basez - binfo.Intercept.Z);
                    SySal.OperaDb.Schema.TB_MIPMICROTRACKS.Insert(db_brick_id, db_id_zone,
                                                                  2, UpTrackId,
                                                                  binfo.Intercept.X + binfo.Slope.X * dz,
                                                                  binfo.Intercept.Y + binfo.Slope.Y * dz,
                                                                  binfo.Slope.X,
                                                                  binfo.Slope.Y,
                                                                  binfo.Count,
                                                                  binfo.AreaSum,
                                                                  System.DBNull.Value,
                                                                  binfo.Sigma, ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.MIPIndexedEmulsionTrack)(lz.Bottom[i])).View.Id + 1);

                    TrackId++;
                    basez = ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.MIPIndexedEmulsionTrack)(lz[i].Top)).View.BottomZ;
                    dz    = 0; //TODO (basez - info.Intercept.Z);
                    SySal.OperaDb.Schema.TB_MIPBASETRACKS.Insert(db_brick_id, db_id_zone,
                                                                 TrackId,
                                                                 info.Intercept.X + info.Slope.X * dz,
                                                                 info.Intercept.Y + info.Slope.Y * dz,
                                                                 info.Slope.X,
                                                                 info.Slope.Y,
                                                                 info.Count,
                                                                 info.AreaSum, System.DBNull.Value, info.Sigma,
                                                                 1, DownTrackId, 2, UpTrackId);
                }

                //Microtracks
                for (i = 0; i < lz.Length; i++)
                {
                    if (lz[i].Info.Sigma >= 0)
                    {
                        continue;
                    }
                    else if (lz[i].Top.Info.Sigma >= 0)
                    {
                        tinfo = lz[i].Top.Info;

                        DownTrackId++;
                        basez = lz.Top.BottomZ;
                        dz    = (basez - tinfo.Intercept.Z);
                        SySal.OperaDb.Schema.TB_MIPMICROTRACKS.Insert(db_brick_id, db_id_zone,
                                                                      1, DownTrackId,
                                                                      tinfo.Intercept.X + tinfo.Slope.X * dz,
                                                                      tinfo.Intercept.Y + tinfo.Slope.Y * dz,
                                                                      tinfo.Slope.X,
                                                                      tinfo.Slope.Y,
                                                                      tinfo.Count,
                                                                      tinfo.AreaSum,
                                                                      System.DBNull.Value,
                                                                      tinfo.Sigma, ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.MIPIndexedEmulsionTrack)(lz.Top[i])).View.Id + 1);
                    }
                    else if (lz[i].Bottom.Info.Sigma >= 0)
                    {
                        binfo = lz[i].Bottom.Info;
                        UpTrackId++;
                        basez = lz.Bottom.TopZ;
                        dz    = (basez - binfo.Intercept.Z);
                        SySal.OperaDb.Schema.TB_MIPMICROTRACKS.Insert(db_brick_id, db_id_zone,
                                                                      2, UpTrackId,
                                                                      binfo.Intercept.X + binfo.Slope.X * dz,
                                                                      binfo.Intercept.Y + binfo.Slope.Y * dz,
                                                                      binfo.Slope.X,
                                                                      binfo.Slope.Y,
                                                                      binfo.Count,
                                                                      binfo.AreaSum,
                                                                      System.DBNull.Value,
                                                                      binfo.Sigma, ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.MIPIndexedEmulsionTrack)(lz.Bottom[i])).View.Id + 1);
                    }
                }

                SySal.OperaDb.Schema.TB_MIPMICROTRACKS.Flush();
                SySal.OperaDb.Schema.TB_MIPBASETRACKS.Flush();

                return(db_id_zone);
            }
            catch (Exception x)
            {
                throw x;
            }
        }
Esempio n. 26
0
        static void Main(string[] args)
        {
            bool   minpDefined        = false;
            bool   maxpDefined        = false;
            bool   stepPDefined       = false;
            bool   inputFileDefined   = false;
            bool   inputConfigDefined = false;
            bool   angDiffDumpDefined = false;
            bool   tkDumpDefined      = false;
            bool   cvDumpDefined      = false;
            bool   lkDumpDefined      = false;
            bool   lvCfDefined        = false;
            bool   editconfigDefined  = false;
            bool   radlenDefined      = false;
            bool   noiseDefined       = false;
            double pMin            = -1.0;
            double pMax            = -1.0;
            double stepP           = -1.0;
            double lvCf            = -1.0;
            double uRL             = -1.0;
            double noise           = -1.0;
            string FileIn          = "";
            string FileConfig      = "";
            string tkDumpFile      = null;
            string cvDumpFile      = null;
            string lkDumpFile      = null;
            string angDiffDumpFile = null;

            try
            {
                int argnum;
                for (argnum = 0; argnum < args.Length; argnum++)
                {
                    switch (args[argnum].ToLower())
                    {
                    case "/noise":
                    {
                        noiseDefined = true;
                        noise        = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture);
                        argnum++;
                        break;
                    }

                    case "/minp":
                    {
                        minpDefined = true;
                        pMin        = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture);
                        argnum++;
                        break;
                    }

                    case "/maxp":
                    {
                        maxpDefined = true;
                        pMax        = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture);
                        argnum++;
                        break;
                    }

                    case "/stepp":
                    {
                        stepPDefined = true;
                        stepP        = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture);
                        argnum++;
                        break;
                    }

                    case "/inputfile":
                    {
                        inputFileDefined = true;
                        FileIn           = args[argnum + 1];
                        argnum++;
                        break;
                    }

                    case "/configfile":
                    {
                        inputConfigDefined = true;
                        FileConfig         = args[argnum + 1];
                        argnum++;
                        break;
                    }

                    case "/cl":
                    {
                        lvCfDefined = true;
                        lvCf        = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture);
                        argnum++;
                        break;
                    }

                    case "/angdiffdump":
                    {
                        angDiffDumpDefined = true;
                        angDiffDumpFile    = args[argnum + 1];
                        argnum++;
                        break;
                    }

                    case "/trackingdump":
                    {
                        tkDumpDefined = true;
                        tkDumpFile    = args[argnum + 1];
                        argnum++;
                        break;
                    }

                    case "/covariancedump":
                    {
                        cvDumpDefined = true;
                        cvDumpFile    = args[argnum + 1];
                        argnum++;
                        break;
                    }

                    case "/likelihooddump":
                    {
                        lkDumpDefined = true;
                        lkDumpFile    = args[argnum + 1];
                        argnum++;
                        break;
                    }

                    case "/editconfigfile":
                    {
                        editconfigDefined = true;
                        FileConfig        = args[argnum + 1];
                        break;
                    }

                    case "/radlen":
                    {
                        radlenDefined = true;
                        uRL           = System.Convert.ToDouble(args[argnum + 1], System.Globalization.CultureInfo.InvariantCulture);
                        break;
                    }
                    }
                }

                if (editconfigDefined)
                {
                    System.Windows.Forms.Application.EnableVisualStyles();
                    EditConfigForm         ec = new EditConfigForm();
                    System.IO.StreamReader r1 = null;
                    System.IO.StreamWriter w  = null;
                    System.Xml.Serialization.XmlSerializer xmls1 = new System.Xml.Serialization.XmlSerializer(typeof(SySal.Processing.MCSLikelihood.Configuration));
                    try
                    {
                        r1   = new System.IO.StreamReader(FileConfig);
                        ec.C = (SySal.Processing.MCSLikelihood.Configuration)xmls1.Deserialize(r1);
                    }
                    catch (Exception)
                    {
                        ec.C = (SySal.Processing.MCSLikelihood.Configuration) new SySal.Processing.MCSLikelihood.MomentumEstimator().Config;
                    }
                    finally
                    {
                        if (r1 != null)
                        {
                            r1.Close();
                        }
                    }
                    if (ec.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        try
                        {
                            w = new StreamWriter(FileConfig);
                            xmls1.Serialize(w, ec.C);
                            w.Flush();
                            w.Close();
                        }
                        catch (Exception x)
                        {
                            System.Windows.Forms.MessageBox.Show("Can't write to file \"" + FileConfig + "\"!", "File Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        }
                        finally
                        {
                            if (w != null)
                            {
                                w.Close();
                            }
                        }
                    }
                    return;
                }
                else if (noiseDefined == false || minpDefined == false || maxpDefined == false || stepPDefined == false || inputFileDefined == false || inputConfigDefined == false || lvCfDefined == false || radlenDefined == false)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Usage: BatchMomentumEstimation.exe {parameters}");
                Console.WriteLine("parameters");
                Console.WriteLine("/noise <p> - measurement error");
                Console.WriteLine("/minp <p> - minimum momentum");
                Console.WriteLine("/maxp <p> - maximum momentum");
                Console.WriteLine("/stepp <p> - step momentum");
                Console.WriteLine("/cl <p> - confidence level");
                Console.WriteLine("/inputfile <p> - input file");
                Console.WriteLine("/configfile<p> - geometry configuration file");
                Console.WriteLine("/angdiffdump <p> - angular difference dump to debug");
                Console.WriteLine("/trackingdump <p> - tracking dump to debug");
                Console.WriteLine("/covariancedump <p> - covariance dump to debug");
                Console.WriteLine("/likelihooddump <p> - likelihood dump to debug");
                Console.WriteLine("/editconfigfile <p> - geometry configuration file to be edited/created");
                Console.WriteLine("/radlen <p> - unit of Radiation Length");
                Console.WriteLine();
                Console.WriteLine("Input data format:");
                Console.WriteLine("ID\tPlate\tZ\tSX\tSY\tX\tY");
                return;
            }

            SySal.Processing.MCSLikelihood.Configuration C = new SySal.Processing.MCSLikelihood.Configuration();
            C.ConfidenceLevel         = lvCf;
            C.MaximumMomentum         = pMax;
            C.MinimumMomentum         = pMin;
            C.MomentumStep            = stepP;
            C.SlopeError              = noise;
            C.MinimumRadiationLengths = uRL; // da parametri!
            System.Xml.Serialization.XmlSerializer xmls = new System.Xml.Serialization.XmlSerializer(typeof(Geometry));
            System.IO.StreamReader r = new System.IO.StreamReader(FileConfig);
            C.Geometry = (Geometry)xmls.Deserialize(r);
            r.Close();

            System.Text.RegularExpressions.Regex             colfmt_rx      = new System.Text.RegularExpressions.Regex(@"\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*");
            SySal.Processing.MCSLikelihood.MomentumEstimator momCalculation = new SySal.Processing.MCSLikelihood.MomentumEstimator();
            momCalculation.Config = C;
            if (angDiffDumpDefined == true)
            {
                momCalculation.AngularDiffDumpFile = angDiffDumpFile;
            }
            if (tkDumpDefined == true)
            {
                momCalculation.TrackingDumpFile = tkDumpFile;
            }
            if (cvDumpDefined == true)
            {
                momCalculation.CovarianceDumpFile = cvDumpFile;
            }
            if (lkDumpDefined == true)
            {
                momCalculation.LikelihoodDumpFile = lkDumpFile;
            }

            //legge il file con i dati


            ArrayList InputData = new ArrayList();

            int          idTrack;
            int          idTrack0  = -1;
            bool         isfirst   = true;
            StreamReader FileInput = new StreamReader(FileIn);
            string       rLine;

            while ((rLine = FileInput.ReadLine()) != null)
            {
                System.Text.RegularExpressions.Match rx_m = colfmt_rx.Match((string)(rLine));
                if (rx_m.Success)
                {
                    SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo();
                    idTrack          = System.Convert.ToInt32(rx_m.Groups[1].Value);
                    info.Slope.X     = System.Convert.ToDouble(rx_m.Groups[4].Value);
                    info.Slope.Y     = System.Convert.ToDouble(rx_m.Groups[5].Value);
                    info.Intercept.Z = System.Convert.ToDouble(rx_m.Groups[3].Value);
                    info.Intercept.X = System.Convert.ToDouble(rx_m.Groups[6].Value);
                    info.Intercept.Y = System.Convert.ToDouble(rx_m.Groups[7].Value);
                    if (isfirst)
                    {
                        idTrack0 = idTrack;
                    }
                    if (idTrack0 != idTrack)
                    {
                        ComputeAndShowResult(FileIn, idTrack0, InputData, momCalculation);
                        InputData.Clear();
                        idTrack0 = idTrack;
                    }
                    isfirst = false;
                    InputData.Add(info);
                }
                else
                {
                    Console.WriteLine("Format error at line " + rLine);
                    return;
                }
            }
            if (InputData.Count > 0)
            {
                ComputeAndShowResult(FileIn, idTrack0, InputData, momCalculation);
            }
            FileInput.Close();
        }
Esempio n. 27
0
        static void Main(string[] args)
        {
            if (args.Length != 7)
            {
                Console.WriteLine("usage: CSRelatedGraphSelector.exe <tlg file> <ascii file> <brick> <plate> <mingrains> <postol> <slopetol>");
                Console.WriteLine("output: BRICK PLATE GRAINS PX PY PZ SX SY SIGMA DPX DPY DSX DSY");
                return;
            }
            int brickid = Convert.ToInt32(args[2]);

            if (brickid > 1999999)
            {
                Console.WriteLine("No track to select on a CS.");
                System.IO.File.WriteAllText(args[1], "\r\n");
                return;
            }
            SySal.OperaDb.OperaDbConnection conn = SySal.OperaDb.OperaDbCredentials.CreateFromRecord().Connect();
            conn.Open();
            int csid = brickid;

            try
            {
                csid = SySal.OperaDb.Convert.ToInt32(new SySal.OperaDb.OperaDbCommand("SELECT MAX(ID) FROM TB_EVENTBRICKS WHERE MOD(ID,1000000) = " + (brickid - (brickid / 1000000) * 1000000), conn).ExecuteScalar());
            }
            catch (Exception) { }
            SySal.OperaDb.OperaDbDataReader csr = new SySal.OperaDb.OperaDbCommand("SELECT (ID_PLATE - 1) * 300 + 4850 as Z, POSX, POSY, SLOPEX, SLOPEY FROM VW_LOCAL_CS_CANDIDATES WHERE ID_CS_EVENTBRICK = " + csid, conn).ExecuteReader();
            System.Collections.ArrayList    arr = new System.Collections.ArrayList();
            while (csr.Read())
            {
                SySal.Tracking.MIPEmulsionTrackInfo info = new SySal.Tracking.MIPEmulsionTrackInfo();
                info.Intercept.Z = csr.GetDouble(0);
                info.Intercept.X = csr.GetDouble(1);
                info.Intercept.Y = csr.GetDouble(2);
                info.Slope.X     = csr.GetDouble(3);
                info.Slope.Y     = csr.GetDouble(4);
                arr.Add(info);
            }
            csr.Close();
            double Z = SySal.OperaDb.Convert.ToDouble(new SySal.OperaDb.OperaDbCommand("SELECT Z FROM TB_PLATES WHERE ID_EVENTBRICK = " + brickid + " AND ID = " + Convert.ToInt32(args[3]).ToString(), conn).ExecuteScalar());

            conn.Close();
            SySal.DataStreams.OPERALinkedZone lz = new SySal.DataStreams.OPERALinkedZone(args[0]);
            int    basen = lz.Length;
            int    i;
            int    mingrains = Convert.ToInt32(args[4]);
            double postol    = Convert.ToDouble(args[5]);
            double slopetol  = Convert.ToDouble(args[6]);
            string outstr    = "";
            int    sel       = 0;

            for (i = 0; i < basen; i++)
            {
                SySal.Tracking.MIPEmulsionTrackInfo lzinfo = lz[i].Info;
                if (lzinfo.Count < mingrains)
                {
                    continue;
                }
                foreach (SySal.Tracking.MIPEmulsionTrackInfo csinfo in arr)
                {
                    double dz         = Math.Abs(csinfo.Intercept.Z - Z);
                    double slopescatt = 0.014 * Math.Sqrt(dz / (1.3 * 5600.0)); /* assume 1 GeV */
                    double posscatt   = slopescatt * dz / Math.Sqrt(3.0);
                    double dsx        = csinfo.Slope.X - lzinfo.Slope.X;
                    double dsy        = csinfo.Slope.Y - lzinfo.Slope.Y;
                    if (dsx * dsx + dsy * dsy > (2.0 * (slopescatt * slopescatt + slopetol * slopetol)))
                    {
                        continue;
                    }
                    double dpx = csinfo.Intercept.X + (Z - csinfo.Intercept.Z) * (csinfo.Slope.X + lzinfo.Slope.X) * 0.5 - lzinfo.Intercept.X;
                    double dpy = csinfo.Intercept.Y + (Z - csinfo.Intercept.Z) * (csinfo.Slope.Y + lzinfo.Slope.Y) * 0.5 - lzinfo.Intercept.Y;
                    if (dpx * dpx + dpy * dpy > (2.0 * (posscatt * posscatt + postol * postol)))
                    {
                        continue;
                    }
                    outstr += "\r\n" + brickid + " " + args[3] + " " + lzinfo.Count + " " + lzinfo.Intercept.X + " " + lzinfo.Intercept.Y + " " + Z + " " + lzinfo.Slope.X + " " + lzinfo.Slope.Y + " " + lzinfo.Sigma + " " + dpx + " " + dpy + " " + dsx + " " + dsy;
                    sel++;
                    break;
                }
            }
            Console.WriteLine("Selected: " + sel + " track(s)");
            System.IO.File.WriteAllText(args[1], outstr);
        }
Esempio n. 28
0
 public static void ApplyTransformation(SySal.Scanning.MIPBaseTrack tk)
 {
     SySal.Tracking.MIPEmulsionTrackInfo info = tMIPBaseTrack.AccessInfo(tk);
     MyTransformation.Transform(info.Intercept.X, info.Intercept.Y, ref info.Intercept.X, ref info.Intercept.Y);
     MyTransformation.Deform(info.Slope.X, info.Slope.Y, ref info.Slope.X, ref info.Slope.Y);
 }
Esempio n. 29
0
        static void Main(string[] args)
        {
            //
            // TODO: Add code to start application here
            //
            if (args.Length != 3)
            {
                System.Xml.Serialization.XmlSerializer xmls = null;
                Console.WriteLine("BatchReconstruct - performs volume reconstruction using LinkedZones from TLG files or OPERA DB tables.");
                Console.WriteLine("usage: batchreconstruct <XML list file> <output Opera persistence path> <XML config Opera persistence path>");
                Console.WriteLine("or:    batchreconstruct <DB volume> <output Opera persistence path> <XML config Opera persistence path>");
                Console.WriteLine("or:    batchreconstruct <input OPERA persistence path> <output Opera persistence path> <XML config Opera persistence path>");
                Console.WriteLine("Full volumes are reprocessed for topological reconstruction only.");
                Console.WriteLine("---------------- DB volume example: db:\\8\\17723900.vol");
                Console.WriteLine("First number is ID_EVENTBRICK, second is ID_VOLUME");
                Console.WriteLine("---------------- XML list file example (source = filesystem):");
                Input inputlist = new Input();
                inputlist.Zones            = new Zone[3];
                inputlist.Zones[0]         = new Zone();
                inputlist.Zones[0].SheetId = 8;
                inputlist.Zones[0].Source  = @"\\myserver.mydomain\myshare\plate_08.tlg";
                inputlist.Zones[0].Z       = 0.0;
                inputlist.Zones[0].AlignmentIgnoreListPath = @"\\myserver\mydomain\myshare\alignignore_plate_08.txt";
                inputlist.Zones[1]         = new Zone();
                inputlist.Zones[1].SheetId = 9;
                inputlist.Zones[1].Source  = @"\\myserver.mydomain\myshare\plate_09.tlg";
                inputlist.Zones[1].Z       = -1300.0;
                inputlist.Zones[2]         = new Zone();
                inputlist.Zones[2].SheetId = 10;
                inputlist.Zones[2].Source  = @"\\myserver.mydomain\myshare\plate_10.tlg";
                inputlist.Zones[2].Z       = -2600.0;
                xmls = new System.Xml.Serialization.XmlSerializer(typeof(BatchReconstruct.Input));
                xmls.Serialize(Console.Out, inputlist);
                Console.WriteLine();
                Console.WriteLine("---------------- XML list file example (source = OperaDB):");
                inputlist.Zones[0].Source = @"db:\1002323.tlg";
                inputlist.Zones[1].Source = @"db:\1006326.tlg";
                inputlist.Zones[2].Source = @"db:\1009724.tlg";
                xmls.Serialize(Console.Out, inputlist);
                Console.WriteLine();
                Console.WriteLine("---------------- XML config file syntax:");
                Console.WriteLine("XML configuration syntax:");
                BatchReconstruct.Config C = new BatchReconstruct.Config();
                C.ReconstructorConfig = (Configuration) new AlphaOmegaReconstructor().Config;
                xmls = new System.Xml.Serialization.XmlSerializer(typeof(BatchReconstruct.Config));
                xmls.Serialize(Console.Out, C);
                Console.WriteLine();
                return;
            }
#if !(DEBUG)
            try
#endif
            {
                AlphaOmegaReconstructor R = new AlphaOmegaReconstructor();
                System.Xml.Serialization.XmlSerializer xmls = null;

                xmls = new System.Xml.Serialization.XmlSerializer(typeof(BatchReconstruct.Config));
                Config config = (Config)xmls.Deserialize(new System.IO.StringReader(((SySal.OperaDb.ComputingInfrastructure.ProgramSettings)SySal.OperaPersistence.Restore(args[2], typeof(SySal.OperaDb.ComputingInfrastructure.ProgramSettings))).Settings));
                R.Config   = (SySal.Management.Configuration)config.ReconstructorConfig;
                R.Progress = new SySal.TotalScan.dProgress(Progress);
                R.Report   = new SySal.TotalScan.dReport(Report);

                System.Text.RegularExpressions.Regex volrgx = new System.Text.RegularExpressions.Regex(@"db:\\(\d+)\\(\d+)\.vol");
                System.Text.RegularExpressions.Match mrgx   = volrgx.Match(args[0].ToLower());
                Input inputlist = null;
                SySal.TotalScan.Volume OldVol = null;
                if (args[0].ToLower().EndsWith(".tsr"))
                {
                    OldVol = (SySal.TotalScan.Volume)SySal.OperaPersistence.Restore(args[0], typeof(SySal.TotalScan.Volume));
                }
                else
                {
                    if (mrgx.Success && mrgx.Length == args[0].Length)
                    {
                        SySal.OperaDb.OperaDbCredentials cred = SySal.OperaDb.OperaDbCredentials.CreateFromRecord();
                        SySal.OperaDb.OperaDbConnection  conn = new SySal.OperaDb.OperaDbConnection(cred.DBServer, cred.DBUserName, cred.DBPassword);
                        conn.Open();
                        System.Data.DataSet ds = new System.Data.DataSet();
                        new SySal.OperaDb.OperaDbDataAdapter("SELECT TB_VOLUME_SLICES.ID_PLATE, TB_VOLUME_SLICES.ID_ZONE, VW_PLATES.Z FROM TB_VOLUME_SLICES INNER JOIN VW_PLATES ON (TB_VOLUME_SLICES.ID_EVENTBRICK = VW_PLATES.ID_EVENTBRICK AND TB_VOLUME_SLICES.ID_PLATE = VW_PLATES.ID) WHERE TB_VOLUME_SLICES.DAMAGED = 'N' AND TB_VOLUME_SLICES.ID_EVENTBRICK = " + mrgx.Groups[1].Value + " AND TB_VOLUME_SLICES.ID_VOLUME = " + mrgx.Groups[2].Value + " ORDER BY VW_PLATES.Z DESC", conn, null).Fill(ds);
                        inputlist       = new Input();
                        inputlist.Zones = new Zone[ds.Tables[0].Rows.Count];
                        int sli;
                        for (sli = 0; sli < ds.Tables[0].Rows.Count; sli++)
                        {
                            inputlist.Zones[sli]         = new Zone();
                            inputlist.Zones[sli].SheetId = Convert.ToInt32(ds.Tables[0].Rows[sli][0]);
                            inputlist.Zones[sli].Source  = "db:\\" + mrgx.Groups[1] + "\\" + ds.Tables[0].Rows[sli][1].ToString() + ".tlg";
                            inputlist.Zones[sli].Z       = Convert.ToDouble(ds.Tables[0].Rows[sli][2]);
                        }
                        SySal.OperaPersistence.Connection            = conn;
                        SySal.OperaPersistence.LinkedZoneDetailLevel = SySal.OperaDb.Scanning.LinkedZone.DetailLevel.BaseFull;
                    }
                    else
                    {
                        System.IO.StreamReader r = new System.IO.StreamReader(args[0]);
                        xmls      = new System.Xml.Serialization.XmlSerializer(typeof(BatchReconstruct.Input));
                        inputlist = (Input)xmls.Deserialize(r);
                        r.Close();
                    }

                    int i, j, c;
                    for (i = 0; i < inputlist.Zones.Length; i++)
                    {
                        for (j = i + 1; j < inputlist.Zones.Length; j++)
                        {
                            if (inputlist.Zones[i].SheetId == inputlist.Zones[j].SheetId)
                            {
                                Console.WriteLine("Duplicate SheetId found. Sheets will be renumbered with the default sequence.");
                                for (j = 0; j < inputlist.Zones.Length; j++)
                                {
                                    inputlist.Zones[j].SheetId = j;
                                }
                                i = inputlist.Zones.Length;
                                break;
                            }
                        }
                    }
                    for (i = 0; i < inputlist.Zones.Length; i++)
                    {
                        SySal.Scanning.Plate.IO.OPERA.LinkedZone lz = (SySal.Scanning.Plate.IO.OPERA.LinkedZone)SySal.OperaPersistence.Restore(inputlist.Zones[i].Source, typeof(SySal.Scanning.Plate.IO.OPERA.LinkedZone));
                        c = lz.Length;
                        SySal.TotalScan.Segment[] segs = new SySal.TotalScan.Segment[c];


                        double[] zcor = new double[c];
                        for (j = 0; j < c; j++)
                        {
                            zcor[j] = lz[j].Info.Intercept.Z;
                        }

                        double zmean = NumericalTools.Fitting.Average(zcor);
                        double dgap;
                        for (j = 0; j < c; j++)
                        {
                            SySal.Tracking.MIPEmulsionTrackInfo info = lz[j].Info;
                            segs[j]           = new SySal.TotalScan.Segment(info, new SySal.TotalScan.BaseTrackIndex(j));
                            dgap              = zmean - info.Intercept.Z;
                            info.Intercept.Z  = zmean;
                            info.Intercept.X += info.Slope.X * dgap;
                            info.Intercept.Y += info.Slope.Y * dgap;
                            info.TopZ        += dgap;
                            info.BottomZ     += dgap;

                            info.Intercept.Z = inputlist.Zones[i].Z;
                            double tmptopz = info.TopZ;
                            double tmpbotz = info.BottomZ;
                            dgap         = zmean - tmptopz;
                            info.TopZ    = inputlist.Zones[i].Z - dgap;
                            info.BottomZ = inputlist.Zones[i].Z - (tmptopz - tmpbotz) - dgap;
                        }

                        SySal.BasicTypes.Vector refc = new SySal.BasicTypes.Vector();
                        refc.Z = inputlist.Zones[i].Z;
                        SySal.TotalScan.Layer tmpLayer = new SySal.TotalScan.Layer(i, /*System.Convert.ToInt64(mrgx.Groups[1].Value)*/ 0, (int)inputlist.Zones[i].SheetId, 0, refc);
                        tmpLayer.AddSegments(segs);
                        R.AddLayer(tmpLayer);
                        if (inputlist.Zones[i].AlignmentIgnoreListPath != null && inputlist.Zones[i].AlignmentIgnoreListPath.Trim().Length != 0)
                        {
                            if (inputlist.Zones[i].AlignmentIgnoreListPath.ToLower().EndsWith(".tlg"))
                            {
                                R.SetAlignmentIgnoreList(i, ((SySal.Scanning.Plate.IO.OPERA.LinkedZone.BaseTrackIgnoreAlignment)SySal.OperaPersistence.Restore(inputlist.Zones[i].AlignmentIgnoreListPath, typeof(SySal.Scanning.Plate.IO.OPERA.LinkedZone.BaseTrackIgnoreAlignment))).Ids);
                            }
                            else
                            {
                                System.IO.StreamReader       r             = new System.IO.StreamReader(inputlist.Zones[i].AlignmentIgnoreListPath.Trim());
                                System.Collections.ArrayList tmpignorelist = new System.Collections.ArrayList();
                                string line;
                                while ((line = r.ReadLine()) != null)
                                {
                                    try
                                    {
                                        tmpignorelist.Add(System.Convert.ToInt32(line));
                                    }
                                    catch (Exception) { }
                                }
                                ;
                                r.Close();
                                R.SetAlignmentIgnoreList(i, (int[])tmpignorelist.ToArray(typeof(int)));
                            }
                        }

                        Console.WriteLine("Loaded sheet {0} Id {1} Tracks {2}", i, inputlist.Zones[i].SheetId, c);
                        lz = null;
                    }
                }
                SySal.TotalScan.Volume V = (OldVol == null) ? R.Reconstruct() : R.RecomputeVertices(OldVol);
                Console.WriteLine("Result written to: " + SySal.OperaPersistence.Persist(args[1], V));
            }
#if !(DEBUG)
            catch (Exception x)
            {
                Console.Error.WriteLine(x.ToString());
            }
#endif
        }
Esempio n. 30
0
        private static void OneZoneIntercalibration(string [] args, ref SySal.DAQSystem.Scanning.IntercalibrationInfo intercal, bool rewrite)
        {
            int i, j, n;
            int MinMatches = Convert.ToInt32(args[8]);

            SySal.Scanning.Plate.IO.OPERA.LinkedZone reflz   = (SySal.Scanning.Plate.IO.OPERA.LinkedZone)SySal.OperaPersistence.Restore(args[1], typeof(SySal.Scanning.Plate.IO.OPERA.LinkedZone));
            SySal.Tracking.MIPEmulsionTrackInfo []   refzone = new SySal.Tracking.MIPEmulsionTrackInfo[reflz.Length];
            for (i = 0; i < refzone.Length; i++)
            {
                refzone[i] = reflz[i].Info;
            }
            reflz = null;
            GC.Collect();
            SySal.Scanning.Plate.IO.OPERA.LinkedZone caliblz   = (SySal.Scanning.Plate.IO.OPERA.LinkedZone)SySal.OperaPersistence.Restore(args[2], typeof(SySal.Scanning.Plate.IO.OPERA.LinkedZone));
            SySal.Tracking.MIPEmulsionTrackInfo []   calibzone = new SySal.Tracking.MIPEmulsionTrackInfo[caliblz.Length];
            for (i = 0; i < calibzone.Length; i++)
            {
                calibzone[i] = caliblz[i].Info;
            }
            if (!rewrite)
            {
                caliblz = null;
            }
            GC.Collect();
            SySal.Processing.QuickMapping.QuickMapper   QMap = new SySal.Processing.QuickMapping.QuickMapper();
            SySal.Processing.QuickMapping.Configuration C    = (SySal.Processing.QuickMapping.Configuration)QMap.Config;
            double postol   = Convert.ToDouble(args[4], System.Globalization.CultureInfo.InvariantCulture);
            double leverarm = Convert.ToDouble(args[6], System.Globalization.CultureInfo.InvariantCulture);

            C.PosTol    = postol + leverarm;
            C.SlopeTol  = Convert.ToDouble(args[5], System.Globalization.CultureInfo.InvariantCulture);
            QMap.Config = C;
            double ZProj     = Convert.ToDouble(args[3], System.Globalization.CultureInfo.InvariantCulture);
            double maxoffset = Convert.ToDouble(args[7], System.Globalization.CultureInfo.InvariantCulture);

            SySal.Scanning.PostProcessing.PatternMatching.TrackPair [] pairs = QMap.Match(refzone, calibzone, ZProj, maxoffset, maxoffset);
            if (pairs.Length < MinMatches)
            {
                Console.Error.WriteLine("Too few matching tracks: " + MinMatches.ToString() + " required, " + pairs.Length + " obtained. Aborting.");
                return;
            }
            Console.WriteLine("Matches: " + pairs.Length);

            n = pairs.Length;
            double [,] indep = new double[2, n];
            double [] dep   = new double[n];
            double [] res   = new double[3];
            double    dummy = 0.0;

            for (i = 0; i < n; i++)
            {
                indep[0, i] = ((SySal.Tracking.MIPEmulsionTrackInfo)(pairs[i].Second.Track)).Intercept.X - intercal.RX;
                indep[1, i] = ((SySal.Tracking.MIPEmulsionTrackInfo)(pairs[i].Second.Track)).Intercept.Y - intercal.RY;
                dep[i]      = pairs[i].First.Info.Intercept.X - intercal.RX;
            }
            NumericalTools.Fitting.MultipleLinearRegression(indep, dep, ref res, ref dummy);
            Console.WriteLine("{0}\t{1}\t{2}\t{3}", res[0], res[1], res[2], dummy);
            intercal.TX = res[0]; intercal.MXX = res[1]; intercal.MXY = res[2];
            for (i = 0; i < n; i++)
            {
                indep[0, i] = ((SySal.Tracking.MIPEmulsionTrackInfo)(pairs[i].Second.Track)).Intercept.X - intercal.RX;
                indep[1, i] = ((SySal.Tracking.MIPEmulsionTrackInfo)(pairs[i].Second.Track)).Intercept.Y - intercal.RY;
                dep[i]      = pairs[i].First.Info.Intercept.Y - intercal.RY;
            }
            NumericalTools.Fitting.MultipleLinearRegression(indep, dep, ref res, ref dummy);
            Console.WriteLine("{0}\t{1}\t{2}\t{3}", res[0], res[1], res[2], dummy);
            intercal.TY = res[0]; intercal.MYX = res[1]; intercal.MYY = res[2];

            System.Collections.ArrayList a_goodpairs = new System.Collections.ArrayList();
            foreach (SySal.Scanning.PostProcessing.PatternMatching.TrackPair p in pairs)
            {
                dummy = Math.Abs(intercal.TX + intercal.MXX * (p.Second.Info.Intercept.X - intercal.RX) + intercal.MXY * (p.Second.Info.Intercept.Y - intercal.RY) - p.First.Info.Intercept.X + intercal.RX);
                if (dummy > postol)
                {
                    continue;
                }
                dummy = Math.Abs(intercal.TY + intercal.MYX * (p.Second.Info.Intercept.X - intercal.RX) + intercal.MYY * (p.Second.Info.Intercept.Y - intercal.RY) - p.First.Info.Intercept.Y + intercal.RY);
                if (dummy > postol)
                {
                    continue;
                }
                a_goodpairs.Add(p);
            }
            Console.WriteLine("remaining " + a_goodpairs.Count);

            SySal.Scanning.PostProcessing.PatternMatching.TrackPair [] goodpairs = (SySal.Scanning.PostProcessing.PatternMatching.TrackPair [])a_goodpairs.ToArray(typeof(SySal.Scanning.PostProcessing.PatternMatching.TrackPair));
            n     = goodpairs.Length;
            indep = new double[2, n];
            dep   = new double[n];
            for (i = 0; i < n; i++)
            {
                indep[0, i] = ((SySal.Tracking.MIPEmulsionTrackInfo)(goodpairs[i].Second.Track)).Intercept.X - intercal.RX;
                indep[1, i] = ((SySal.Tracking.MIPEmulsionTrackInfo)(goodpairs[i].Second.Track)).Intercept.Y - intercal.RY;
                dep[i]      = goodpairs[i].First.Info.Intercept.X - intercal.RX;
            }
            NumericalTools.Fitting.MultipleLinearRegression(indep, dep, ref res, ref dummy);
            Console.WriteLine("{0}\t{1}\t{2}\t{3}", res[0], res[1], res[2], dummy);
            intercal.TX = res[0]; intercal.MXX = res[1]; intercal.MXY = res[2];
            for (i = 0; i < n; i++)
            {
                indep[0, i] = ((SySal.Tracking.MIPEmulsionTrackInfo)(goodpairs[i].Second.Track)).Intercept.X - intercal.RX;
                indep[1, i] = ((SySal.Tracking.MIPEmulsionTrackInfo)(goodpairs[i].Second.Track)).Intercept.Y - intercal.RY;
                dep[i]      = goodpairs[i].First.Info.Intercept.Y - intercal.RY;
            }
            NumericalTools.Fitting.MultipleLinearRegression(indep, dep, ref res, ref dummy);
            Console.WriteLine("{0}\t{1}\t{2}\t{3}", res[0], res[1], res[2], dummy);
            intercal.TY = res[0]; intercal.MYX = res[1]; intercal.MYY = res[2];
            CheckIntercalibration(intercal);
            if (rewrite)
            {
                MyTransformation.Transformation = intercal;
                SySal.OperaPersistence.Persist(args[2], new LinkedZone(caliblz));
            }
        }