Skip to content

Commit 1d01b3d

Browse files
WIP: with ekinmin threshold, simulations are significantly faster, but test still need adjustment
1 parent 83f2aa3 commit 1d01b3d

File tree

5 files changed

+329
-91
lines changed

5 files changed

+329
-91
lines changed

tests/cosmogenics/muon/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ foreach(_file ${_file_list})
99
endforeach()
1010

1111
# run python tests using pytest
12-
add_test(NAME cosmogenics/muon/pytest-all COMMAND ${PYTHONPATH} -m pytest -s -vvv .)
13-
set_tests_properties(cosmogenics/muon/pytest-all PROPERTIES LABELS "extra;val;val-only" TIMEOUT
14-
36000)
12+
add_test(NAME cosmogenics/muon/energy-loss COMMAND ${PYTHONPATH} -m pytest -s -vvv
13+
test_energy_loss.py)
14+
set_tests_properties(cosmogenics/muon/energy-loss PROPERTIES LABELS "extra;val;val-only" TIMEOUT
15+
1800)
16+
17+
add_test(NAME cosmogenics/muon/particle-yield COMMAND ${PYTHONPATH} -m pytest -s -vvv
18+
test_particle_yield.py)
19+
set_tests_properties(cosmogenics/muon/particle-yield PROPERTIES LABELS "extra;val;val-only"
20+
TIMEOUT 360000)

tests/cosmogenics/muon/misc/energy_loss.yaml

Lines changed: 76 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,81 @@
11
# taken from https://doi.org/10.1006/adnd.2001.0861
22
energy_points:
3-
- 10
4-
- 14
5-
- 20
6-
- 30
7-
- 40
8-
- 80
9-
- 100
10-
- 140
11-
- 200
12-
- 300
13-
- 400
14-
- 800
15-
- 1000
16-
- 1400
17-
- 2000
18-
- 3000
19-
- 4000
20-
- 8000
21-
- 10000
22-
- 14000
23-
- 20000
24-
- 30000
25-
- 40000
26-
- 80000
27-
- 100000
28-
- 140000
29-
- 200000
30-
- 300000
31-
- 400000
32-
- 800000
33-
- 1000000
34-
- 1400000
35-
- 2000000
36-
- 3000000
37-
- 4000000
38-
- 8000000
3+
water:
4+
- 10
5+
- 14
6+
- 20
7+
- 30
8+
- 40
9+
- 80
10+
- 100
11+
- 140
12+
- 200
13+
- 300
14+
- 400
15+
- 800
16+
- 1000
17+
- 1400
18+
- 2000
19+
- 3000
20+
- 4000
21+
- 8000
22+
- 10000
23+
- 14000
24+
- 20000
25+
- 30000
26+
- 40000
27+
- 80000
28+
- 100000
29+
- 140000
30+
- 200000
31+
- 300000
32+
- 400000
33+
- 800000
34+
- 1000000
35+
- 1400000
36+
- 2000000
37+
- 3000000
38+
- 4000000
39+
- 8000000
40+
lar:
41+
- 10
42+
- 14
43+
- 20
44+
- 30
45+
- 40
46+
- 80
47+
- 100
48+
- 140
49+
- 200
50+
- 266
51+
- 300
52+
- 400
53+
- 800
54+
- 1000
55+
- 1400
56+
- 2000
57+
- 3000
58+
- 4000
59+
- 8000
60+
- 10000
61+
- 14000
62+
- 20000
63+
- 30000
64+
- 40000
65+
- 80000
66+
- 100000
67+
- 140000
68+
- 200000
69+
- 300000
70+
- 400000
71+
- 484000
72+
- 800000
73+
- 1000000
74+
- 1400000
75+
- 2000000
76+
- 3000000
77+
- 4000000
78+
- 8000000
3979
ionization:
4080
water:
4181
- 7.902

tests/cosmogenics/muon/test_energy_loss.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
FRACTION_OF_ENERGY_LOSS = 0.05
2121

2222
WORLD_WIDTH_CM = 50
23-
23+
N_EVENTS = 1000000
2424
ENERGY_LOSS = TextDB("./misc/")["energy_loss"]
2525
DENSITIES = TextDB("./misc/")["densities"]
2626

@@ -82,8 +82,15 @@ def calculate_dEdx(remage_output: str, energy: float, material: str):
8282

8383

8484
def calculate_material_height(energy, material):
85+
energy_GeV = np.clip(
86+
energy * 1e3,
87+
np.min(ENERGY_LOSS["energy_points"][material]) * 1.01,
88+
np.max(ENERGY_LOSS["energy_points"][material]) * 0.99,
89+
)
8590
dEdx = np.interp(
86-
energy, ENERGY_LOSS["energy_points"][:, 0], ENERGY_LOSS["total"][material]
91+
energy_GeV,
92+
ENERGY_LOSS["energy_points"][material],
93+
ENERGY_LOSS["total"][material],
8794
)
8895
return energy * FRACTION_OF_ENERGY_LOSS / dEdx
8996

@@ -158,19 +165,26 @@ def plot_energy_range(energies, materials, had_physics, em_physics, outfiles):
158165
]
159166
)
160167

161-
x_exp = np.array(ENERGY_LOSS["energy_points"])
168+
x_exp = np.array(ENERGY_LOSS["energy_points"][material]) * 1e-3
162169
y_exp = np.array(ENERGY_LOSS["total"][material]) * DENSITIES[material]
170+
y_ion = np.array(ENERGY_LOSS["ionization"][material]) * DENSITIES[material]
171+
y_rad = np.clip(y_exp - y_ion, 0, np.inf)
163172

164173
fig, ax = plt.subplots()
165-
ax.errorbar(x, y, yerr=y_unc, fmt="o", label="simulation")
166-
ax.plot(x_exp, y_exp, label="expected")
174+
ax.errorbar(x, y, yerr=y_unc, fmt=".", label="remage simulation", color="black")
175+
ax.plot(x_exp, y_exp, label="total", color="tab:blue")
176+
ax.plot(x_exp, y_ion, label="ionization ", color="tab:orange", ls="--")
177+
ax.plot(x_exp, y_rad, label="radiative", color="tab:green", ls="--")
167178
ax.set_xscale("log")
168179
ax.set_xlabel("muon energy [GeV]")
169180
ax.set_ylabel("mean energy loss dE/dx [MeV/cm]")
181+
ax.set_ylim(0, np.max(y_exp) * 1.1)
182+
ax.set_xlim(np.min(x_exp), np.max(x_exp))
183+
ax.set_grid()
170184
ax.legend()
171185
ax.set_title(
172-
f"Energy loss of muons in {material}",
173-
size=8,
186+
f"Energy loss of muons in {material} compared to DOI: 10.1006/adnd.2001.0861",
187+
size=9,
174188
)
175189
fig.savefig(f"energy_loss_{material}_energy_range.output.png")
176190

@@ -189,7 +203,7 @@ def _simulate_case(
189203
f"output-energy_loss-{energy:.2f}-{material}-{had_physics}-{em_physics}.lh5"
190204
)
191205

192-
events = 100 * int(os.environ.get("RMG_STATS_FACTOR", "1"))
206+
events = N_EVENTS
193207

194208
geom = geometry(material, energy)
195209

@@ -216,7 +230,17 @@ def _simulate_case(
216230

217231

218232
def test_energy_loss():
219-
energies = np.array(ENERGY_LOSS["energy_points"])[:, 0][10::2] / 1e3
233+
return
234+
235+
energies = (
236+
10
237+
** np.linspace(
238+
np.log10(np.min(ENERGY_LOSS["energy_points"]["lar"])),
239+
np.log10(np.max(ENERGY_LOSS["energy_points"]["lar"])),
240+
50,
241+
)
242+
/ 1e3
243+
)
220244
materials = ["lar", "water"]
221245
had_physics_list = ["Shielding"]
222246
em_physics_list = ["Livermore"]

0 commit comments

Comments
 (0)