/// <summary> /// method to tally to detector /// </summary> /// <param name="photon">photon data needed to tally</param> public void Tally(Photon photon) { if (!IsWithinDetectorAperture(photon)) { return; } // ray trace exit location and direction to location at ZPlane var positionAtZPlane = LayerTissueRegionToolbox.RayExtendToInfinitePlane( photon.DP.Position, photon.DP.Direction, ZPlane); // WhichBin to match ROfRhoAndTimeDetector var ir = DetectorBinning.WhichBin(DetectorBinning.GetRho(positionAtZPlane.X, positionAtZPlane.Y), Rho.Count - 1, Rho.Delta, Rho.Start); var it = DetectorBinning.WhichBin(photon.DP.TotalTime, Time.Count - 1, Time.Delta, Time.Start); if ((ir != -1) && (it != -1)) { double weightFactor = _absorbAction( photon.History.SubRegionInfoList.Select(c => c.NumberOfCollisions).ToList(), photon.History.SubRegionInfoList.Select(p => p.PathLength).ToList(), _perturbedOps, _referenceOps, _perturbedRegionsIndices); Mean[ir, it] += photon.DP.Weight * weightFactor; if (TallySecondMoment) { SecondMoment[ir, it] += photon.DP.Weight * weightFactor * photon.DP.Weight * weightFactor; } TallyCount++; } }
/// <summary> /// method to tally to detector /// </summary> /// <param name="photon">photon data needed to tally</param> public void Tally(Photon photon) { if (!IsWithinDetectorAperture(photon)) { return; } // ray trace exit location and direction to location at ZPlane var positionAtZPlane = LayerTissueRegionToolbox.RayExtendToInfinitePlane( photon.DP.Position, photon.DP.Direction, ZPlane); var ix = DetectorBinning.WhichBin(positionAtZPlane.X, X.Count - 1, X.Delta, X.Start); var iy = DetectorBinning.WhichBin(positionAtZPlane.Y, Y.Count - 1, Y.Delta, Y.Start); Mean[ix, iy] += photon.DP.Weight; if (TallySecondMoment) { SecondMoment[ix, iy] += photon.DP.Weight * photon.DP.Weight; } TallyCount++; }
/// <summary> /// method to tally to detector /// </summary> /// <param name="photon">photon data needed to tally</param> public void Tally(Photon photon) { if (!IsWithinDetectorAperture(photon)) { return; } // ray trace exit location and direction to location at ZPlane in air var positionAtHeight = LayerTissueRegionToolbox.RayExtendToInfinitePlane( photon.DP.Position, photon.DP.Direction, ZPlane); var ir = DetectorBinning.WhichBin(DetectorBinning.GetRho(positionAtHeight.X, positionAtHeight.Y), Rho.Count - 1, Rho.Delta, Rho.Start); double maxDepth = photon.History.HistoryData.Max(d => d.Position.Z); var id = DetectorBinning.WhichBin(maxDepth, MaxDepth.Count - 1, MaxDepth.Delta, MaxDepth.Start); Mean[ir, id] += photon.DP.Weight; // mean integrated over max depth = R(rho) if (TallySecondMoment) { SecondMoment[ir, id] += photon.DP.Weight * photon.DP.Weight; } TallyCount++; }
public void validate_RayExtendToInfinitePlane_results() { var zPlane = -1; var pos = new Position(0, 0, 0); // check vertical direction var dir = new Direction(0, 0, -1); var newPos = LayerTissueRegionToolbox.RayExtendToInfinitePlane(pos, dir, zPlane); Assert.Less(Math.Abs(pos.X - newPos.X), 0.000001); Assert.Less(Math.Abs(pos.Y - newPos.Y), 0.000001); Assert.Less(Math.Abs(-1 - newPos.Z), 0.000001); dir = new Direction(1.0 / Math.Sqrt(2), 0, -1.0 / Math.Sqrt(2)); newPos = LayerTissueRegionToolbox.RayExtendToInfinitePlane(pos, dir, zPlane); Assert.Less(Math.Abs(1.0 - newPos.X), 0.000001); Assert.Less(Math.Abs(0.0 - newPos.Y), 0.000001); Assert.Less(Math.Abs(-1 - newPos.Z), 0.000001); dir = new Direction(-1.0 / Math.Sqrt(2), 0, -1.0 / Math.Sqrt(2)); newPos = LayerTissueRegionToolbox.RayExtendToInfinitePlane(pos, dir, zPlane); Assert.Less(Math.Abs(-1.0 - newPos.X), 0.000001); Assert.Less(Math.Abs(0.0 - newPos.Y), 0.000001); Assert.Less(Math.Abs(-1 - newPos.Z), 0.000001); dir = new Direction(0.0, 1.0 / Math.Sqrt(2), -1.0 / Math.Sqrt(2)); newPos = LayerTissueRegionToolbox.RayExtendToInfinitePlane(pos, dir, zPlane); Assert.Less(Math.Abs(0.0 - newPos.X), 0.000001); Assert.Less(Math.Abs(1.0 - newPos.Y), 0.000001); Assert.Less(Math.Abs(-1 - newPos.Z), 0.000001); dir = new Direction(0.0, -1.0 / Math.Sqrt(2), -1.0 / Math.Sqrt(2)); newPos = LayerTissueRegionToolbox.RayExtendToInfinitePlane(pos, dir, zPlane); Assert.Less(Math.Abs(0.0 - newPos.X), 0.000001); Assert.Less(Math.Abs(-1.0 - newPos.Y), 0.000001); Assert.Less(Math.Abs(-1 - newPos.Z), 0.000001); // try parallel direction dir = new Direction(1.0 / Math.Sqrt(2), -1.0 / Math.Sqrt(2), 0.0); newPos = LayerTissueRegionToolbox.RayExtendToInfinitePlane(pos, dir, zPlane); Assert.IsTrue(newPos == null); }