EGS Brachy
An egs++ user code for rapid brachytherapy calculations
Loading...
Searching...
No Matches
test.py
Go to the documentation of this file.
1"""
2
3A test for comparing the calculated energy fluence spectrum in a phantom region
4with the expected value. A uniform spectrum between 15keV-25keV in a
5near-vaccuum geometry is used so the expected spectrum can easily be calculated
6analytically.
7
8"""
9import math
10import re
11
12from eb_tests.utils import read_csv_spectrum, values_close
13
14EGSINP = "spec_vox.egsinp"
15TIME_LIMIT_S_PER_MHZ = 7/2993. # s / MHz
16
17BIN_WIDTH = 0.001
18EMIN, EMAX = 0.015, 0.025
19R1, R2 = 0.1, 0.2
20
21# vacuum and point source in spherical region so tracklength should just be R2-R1
22TRACK_LENGTH = R2 - R1
23
24N_BINS_IN_RANGE = (EMAX-EMIN)/BIN_WIDTH
25
26SCORED_IN_BIN = TRACK_LENGTH/N_BINS_IN_RANGE
27
28VOLUME = 4/3.*math.pi*(0.2**3-0.1**3)
29
30def expected(e):
31 if EMIN <= e <= EMAX:
32 return SCORED_IN_BIN/(VOLUME*BIN_WIDTH)
33 return 0
34
35def compare_results(egslst, inp_name):
36
37 energies, counts, uncs = read_csv_spectrum(inp_name+".voxelflu.csv")
38
39 for e, c in zip(energies, counts):
40 exp = expected(e)
41 if (exp > 0 and not values_close(c, exp, 0.005)) or (exp == 0 and c > 0.01):
42 return False, "Fluence at E = %f MeV was %f" %(e, c), "Expected %f" % exp
43
44 return True, [], []