-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathtest013_phys_lists_6.py
executable file
·80 lines (67 loc) · 2.61 KB
/
test013_phys_lists_6.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import opengate as gate
import opengate.tests.utility as tu
if __name__ == "__main__":
paths = tu.get_default_test_paths(__file__, output_folder="test013_6")
# create simulation
sim = gate.Simulation()
sim.g4_verbose = True
sim.output_dir = paths.output
# units
m = gate.g4_units.m
cm = gate.g4_units.cm
mm = gate.g4_units.mm
eV = gate.g4_units.eV
MeV = gate.g4_units.MeV
Bq = gate.g4_units.Bq
# add a material database
print(f"Inside the test file - {paths.data}")
sim.volume_manager.add_material_database(paths.data / "GateMaterials.db")
# set the world size like in the Gate macro
world = sim.world
world.size = [3 * m, 3 * m, 3 * m]
# add a simple crystal volume
crystal = sim.add_volume("Box", "crystal")
crystal.size = [3 * mm, 3 * mm, 20 * mm]
crystal.translation = [0 * cm, 0 * cm, 0 * cm]
crystal.material = "BGO"
crystal.set_production_cut("electron", 0.1 * mm)
# change physics
# For the generation of Cerenkov, physics_list_name must
# be set to G4EmStandardPhysics_option4 and production cuts
# of electron must be set to 0.1 mm (Reason unknown)
# Reference - https://opengate.readthedocs.io/en/latest/generating_and_tracking_optical_photons.html
sim.physics_manager.physics_list_name = "G4EmStandardPhysics_option4"
sim.physics_manager.energy_range_min = 10 * eV
sim.physics_manager.energy_range_max = 1 * MeV
sim.physics_manager.special_physics_constructors.G4OpticalPhysics = True
# Users can specify their own path optical properties file by
# sim.physics_manager.optical_properties_file = PATH_TO_FILE
# By default, Gate uses the file opengate/data/OpticalProperties.xml
# Change source
source = sim.add_source("GenericSource", "gamma1")
source.particle = "gamma"
source.energy.mono = 0.511 * MeV
source.activity = 10 * Bq
source.direction.type = "momentum"
source.direction.momentum = [0, 0, -1]
source.position.translation = [0 * cm, 0 * cm, 2.2 * cm]
# add phase actor
phase = sim.add_actor("PhaseSpaceActor", "Phase")
phase.attached_to = crystal.name
phase.attributes = [
"Position",
"PostPosition",
"PrePosition",
"ParticleName",
"TrackCreatorProcess",
"EventKineticEnergy",
"KineticEnergy",
"PDGCode",
]
phase.output_filename = "test013_phys_lists_6.root"
sim.user_hook_after_run = gate.userhooks.user_hook_dump_material_properties
sim.run()
is_ok = all(t is True for t in sim.user_hook_log)
tu.test_ok(is_ok)