Ejemplo n.º 1
0
        public void Run()
        {
            if (string.IsNullOrEmpty(SavePath))
            {
                Logger.Log("Save path is empty. Will save to desktop\n");
                SavePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "edwFactors.txt");
            }
            ;

            var states = BuildMeasurementList();

            foreach (var m in states)
            {
                var jr = new Job(m);
                jr.DepthOfMeasurentMM = DepthOfMeasurementMM;
                if (Math.Abs(_scan1D.LastKnowPositionMM - DepthOfMeasurementMM) > 0.1)
                {
                    Logger.Log($"Changing depth to {DepthOfMeasurementMM} mm\n");
                    _scan1D.GoToDepth(jr.DepthOfMeasurentMM);
                }

                for (int n = 0; n < RepeatMeasurements; n++)
                {
                    var fov = EnergyHelper.IsPhoton(m.Energy) ? $"{m.X1 * 2} x {m.Y1 * 2}" : m.Accessory;
                    Logger.Log($"Working on {m.Energy}, Depth {jr.DepthOfMeasurentMM}, {m.Accessory} ,  Measurement {n + 1}\n\n");

                    _linac.SetMachineState(m);

                    //Start measuring
                    _el.Reset();
                    _el.StartMeasurement();

                    if (n == 0)
                    {
                        _linac.BeamOn();
                    }
                    else
                    {
                        _linac.RepeatBeam();
                    }

                    var waitTime = _linac.WaitMsForMU(m.MU, true);
                    using (var t = new TimerLogger("Waiting on beam completion", waitTime, 1000, this.Logger))
                    {
                        Thread.Sleep(waitTime);
                    }
                    //Stop and get measurement
                    _el.StopMeasurement();
                    var measured = _el.GetValue().Measurement;
                    Logger?.Log($"Measured : {measured}\n");

                    jr.AddMeasurement(_el.GetValue().Measurement);
                }
                //Save results
                JobWriter.AppendResult(SavePath, jr);
            }
        }
Ejemplo n.º 2
0
        private List <Job> BuildMeasurementList(bool photons = true, bool electrons = true)
        {
            var machineState    = MachineState.InitNew();
            var measurementList = new List <Job>();

            var lastPhotonFovHalf = 0.5;

            if (photons)
            {
                var changeState = machineState.Copy();
                lastPhotonFovHalf    = changeState.X1 = changeState.X2 = photonFovCM / 2;
                changeState.Y1       = changeState.Y2 = photonFovCM / 2;
                changeState.MU       = MUPerShot;
                changeState.DoseRate = DoseRate._600;
                foreach (var en in energyDepths.Where(e => EnergyHelper.IsPhoton(e.Item1)))
                {
                    var copy = changeState.Copy();
                    copy.Energy = en.Item1;
                    measurementList.Add(new Job(copy)
                    {
                        DepthOfMeasurentMM = en.Item2
                    });
                }
            }
            if (electrons)
            {
                //ELECTRONS
                var changeState = machineState.Copy();
                changeState.X1        = changeState.X2 = changeState.Y1 = changeState.Y2 = lastPhotonFovHalf;
                changeState.DoseRate  = DoseRate._600;
                changeState.Accessory = electronCone;
                changeState.MU        = MUPerShot;

                foreach (var en in energyDepths.Where(e => !EnergyHelper.IsPhoton(e.Item1)))
                {
                    var copy = changeState.Copy();
                    copy.Energy = en.Item1;
                    measurementList.Add(new Job(copy)
                    {
                        DepthOfMeasurentMM = en.Item2
                    });
                }
            }
            return(measurementList);
        }
Ejemplo n.º 3
0
        private List <MachineState> BuildMeasurementList(bool photons = true, bool electrons = true)
        {
            var machineState    = MachineState.InitNew();
            var measurementList = new List <MachineState>();

            if (photons)
            {
                //PHOTONS
                photonsFovs.ToList().ForEach(fov =>
                {
                    var changeState = machineState.Copy();
                    changeState.X1  = changeState.X2 = fov / 2;
                    changeState.Y1  = changeState.Y2 = fov / 2;
                    changeState.MU  = MUPerShot;

                    foreach (var en in energyDepths.Where(e => EnergyHelper.IsPhoton(e.Key)))
                    {
                        var copy    = changeState.Copy();
                        copy.Energy = en.Key;
                        measurementList.Add(copy);
                    }
                });
            }

            if (electrons)
            {
                //ELECTRONS
                electronCones.ToList().ForEach(cone =>
                {
                    var changeState       = machineState.Copy();
                    changeState.Accessory = cone;
                    changeState.MU        = MUPerShot;

                    foreach (var en in energyDepths.Where(e => !EnergyHelper.IsPhoton(e.Key)))
                    {
                        var copy    = changeState.Copy();
                        copy.Energy = en.Key;
                        measurementList.Add(copy);
                    }
                });
            }
            return(measurementList);
        }
Ejemplo n.º 4
0
        public void Run(bool photons = true, bool electrons = true)
        {
            if (string.IsNullOrEmpty(SavePath))
            {
                Logger.Log("Save path is empty. Will save to desktop\n");
                SavePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "outputFactors.txt");
            }
            ;

            var measurementList = BuildMeasurementList(photons, electrons);

            foreach (var m in measurementList)
            {
                var jr = new Job(m);
                jr.DepthOfMeasurentMM = energyDepths[m.Energy];
                _scan1D.GoToDepth(jr.DepthOfMeasurentMM);

                for (int n = 0; n < RepeatMeasurements; n++)
                {
                    var fov = EnergyHelper.IsPhoton(m.Energy) ? $"{m.X1 * 2} x {m.Y1 * 2}" : m.Accessory;
                    Logger.Log($"Working on {m.Energy}, Depth {jr.DepthOfMeasurentMM}, {fov} ,  Measurement {n + 1}");

                    var state = _linac.GetMachineStateCopy();
                    //Check for cone change
                    if (_linac.GetMachineStateCopy().Accessory != m.Accessory)
                    {
                        Console.Beep(4000, 1000);
                        Logger.Log($"Please change the cone to {m.Accessory}\n");
                        Logger.Log($"Press ENTER when complete\n");
                        while (Console.ReadKey().Key != ConsoleKey.Enter)
                        {
                        }
                        Logger.Log($"{m.Accessory} inserted! Continuing...\n");
                    }

                    _linac.SetMachineState(m);

                    //Start measuring
                    _el.Reset();
                    _el.StartMeasurement();

                    if (n == 0)
                    {
                        _linac.BeamOn();
                    }
                    else
                    {
                        _linac.RepeatBeam();
                    }

                    Thread.Sleep(_linac.WaitMsForMU(m.MU));

                    //Stop and get measurement
                    _el.StopMeasurement();
                    var measured = _el.GetValue().Measurement;
                    Logger?.Log($"Measured : {measured}\n");

                    jr.AddMeasurement(_el.GetValue().Measurement);
                }

                //Save results
                JobWriter.AppendResult(SavePath, jr);
            }
        }