コード例 #1
0
ファイル: Program.cs プロジェクト: kryssb/SySal.NET
        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();
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: kryssb/SySal.NET
        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();
        }