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 on the surface of a
4source with the expected value. A uniform spectrum between 15keV-25keV in a
5near-vaccuum source is used so the expected spectrum can easily be calculated
6analytically.
7
8"""
9
10import math
11import re
12
13from eb_tests.utils import read_csv_spectrum, values_close
14
15EGSINP = "spec_eflu.egsinp"
16TIME_LIMIT_S_PER_MHZ = 6/2993. # s / MHz
17
18EMIN, EMAX = 0.015, 0.025
19
20NHIST = 1
21
22BIN_WIDTH = 0.001
23AVG_E = (EMAX+EMIN)/2.
24TOTAL_E = AVG_E * NHIST
25N_BINS_IN_RANGE = (EMAX-EMIN)/BIN_WIDTH
26
27SCORED_IN_BIN = NHIST/N_BINS_IN_RANGE
28SCORED_IN_BIN_PER_MEV = SCORED_IN_BIN / BIN_WIDTH
29
30def expected(e):
31 if EMIN <= e <= EMAX:
32 return e*SCORED_IN_BIN_PER_MEV / TOTAL_E
33 return 0
34
35def compare_results(egslst, inp_name):
36
37 energies, counts, uncs = read_csv_spectrum(inp_name+".ewsurf.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.0001):
42 return False, "Fluence at E = %f MeV was %f" %(e, c), "Expected %f" % exp
43
44 return True, [], []