Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add efield position dependence #188

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions appletree/components/yields.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.register(apt.plugins.MonoEnergiesSpectra)
self.register(apt.plugins.PositionSpectra)
self.register(apt.plugins.TotalQuanta)
self.register(apt.plugins.EField)
self.register(apt.plugins.ThomasImelBox)
self.register(apt.plugins.QyNR)
self.register(apt.plugins.LyNR)
Expand All @@ -20,7 +22,9 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.register(apt.plugins.UniformEnergiesSpectra)
self.register(apt.plugins.PositionSpectra)
self.register(apt.plugins.TotalQuanta)
self.register(apt.plugins.EField)
self.register(apt.plugins.ThomasImelBox)
self.register(apt.plugins.QyNR)
self.register(apt.plugins.LyNR)
Expand Down
2 changes: 1 addition & 1 deletion appletree/instructs/literature_lyqy.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"ly_lux_2022": 2.5,
"qy_lux_2022": 2.5
},
"literature_field": {
"field": {
"ly_lux_2016": 180.0,
"qy_lenardo_2019": 220.0,
"ly_lux_2022": 400.0,
Expand Down
1 change: 1 addition & 0 deletions appletree/maps/_efield_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"coordinate_lowers": [-140, 0], "coordinate_uppers": [0, 70], "coordinate_type": "regbin", "coordinate_name": ["r", "z"], "map": [[23.0, 23.0, 23.0, 23.0, 23.0], [23.0, 23.0, 23.0, 23.0, 23.0], [23.0, 23.0, 23.0, 23.0, 23.0], [23.0, 23.0, 23.0, 23.0, 23.0], [23.0, 23.0, 23.0, 23.0, 23.0]]}
11 changes: 11 additions & 0 deletions appletree/parameters/nestv2.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
"unit": "g/cm^3",
"doc": "Density of the lXe"
},
"field": {
"prior_type": "fixed",
"prior_args": {
"val": 23.0
},
"allowed_range": null,
"init_mean": null,
"init_std": null,
"unit": "V/cm",
"doc": "Drift field"
},
"alpha": {
"prior_type": "twohalfnorm",
"prior_args": {
Expand Down
11 changes: 11 additions & 0 deletions appletree/parameters/nestv2_yield_only.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
"unit": "g/cm^3",
"doc": "Density of the lXe"
},
"field": {
"prior_type": "fixed",
"prior_args": {
"val": 23.0
},
"allowed_range": null,
"init_mean": null,
"init_std": null,
"unit": "V/cm",
"doc": "Drift field"
},
"alpha": {
"prior_type": "twohalfnorm",
"prior_args": {
Expand Down
31 changes: 30 additions & 1 deletion appletree/plugins/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from appletree import randgen
from appletree.plugin import Plugin
from appletree.config import takes_config, Map
from appletree.config import takes_config, Map, Constant
from appletree.utils import exporter

export, __all__ = exporter(export_self=False)
Expand Down Expand Up @@ -48,6 +48,35 @@ def simulate(self, key, parameters, x, y):
return key, s2_lce


@export
@takes_config(
Constant(
name="efield_position_dependence",
type=bool,
default=False,
help="Whether to enable position-dependent efield",
),
Map(
name="efield_map",
default="_efield_map.json",
help="Electric field map",
),
)
class EField(Plugin):
depends_on = ["x", "y", "z"]
provides = ["field"]
parameters = ("field",)

@partial(jit, static_argnums=(0,))
def simulate(self, key, parameters, x, y, z):
# Safe to use "if" because we expect config to be fixed
if not self.efield_position_dependence.value:
return key, jnp.ones(x.shape) * parameters["field"]
r = jnp.sqrt(x**2 + y**2)
pos_true = jnp.stack([r, z]).T
return key, self.efield_map.apply(pos_true)


@export
class PhotonDetection(Plugin):
depends_on = ["num_photon", "s1_lce"]
Expand Down
8 changes: 4 additions & 4 deletions appletree/plugins/er_microphys.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ def simulate(self, key, parameters, num_quanta):

@export
class mTI(Plugin):
depends_on = ["energy"]
depends_on = ["energy", "field"]
provides = ["recomb_mean"]
parameters = ("w", "nex_ni_ratio", "py0", "py1", "py2", "py3", "py4", "field")
parameters = ("w", "nex_ni_ratio", "py0", "py1", "py2", "py3", "py4")

@partial(jit, static_argnums=(0,))
def simulate(self, key, parameters, energy):
def simulate(self, key, parameters, energy, field):
ni = energy / parameters["w"] / (1.0 + parameters["nex_ni_ratio"])
ti = (
ni
* parameters["py0"]
* jnp.exp(-energy / parameters["py1"])
* parameters["field"] ** parameters["py2"]
* field ** parameters["py2"]
/ 4.0
)
fd = 1.0 / (1.0 + jnp.exp(-(energy - parameters["py3"]) / parameters["py4"]))
Expand Down
11 changes: 3 additions & 8 deletions appletree/plugins/nestv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,15 @@ def simulate(self, key, parameters, energy):


@export
@takes_config(
Constant(
name="literature_field", type=float, default=23.0, help="Drift field in each literature"
),
)
class ThomasImelBox(Plugin):
depends_on = ["energy"]
depends_on = ["energy", "field"]
provides = ["ThomasImel"]
parameters = ("gamma", "delta", "liquid_xe_density")

@partial(jit, static_argnums=(0,))
def simulate(self, key, parameters, energy):
def simulate(self, key, parameters, energy, field):
ThomasImel = jnp.ones(shape=jnp.shape(energy))
ThomasImel *= parameters["gamma"] * self.literature_field.value ** parameters["delta"]
ThomasImel *= parameters["gamma"] * field ** parameters["delta"]
ThomasImel *= (parameters["liquid_xe_density"] / 2.9) ** 0.3
return key, ThomasImel

Expand Down
14 changes: 13 additions & 1 deletion tests/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ def benchmark(key):
)
er.compile()
er.lineage_hash
er.simulate_hist(key, batch_size, parameters)
key, h = er.simulate_hist(key, batch_size, parameters)
with pytest.raises(RuntimeError):
key, r = er.multiple_simulations(key, batch_size, parameters, 5, apply_eff=True)

# test efield dependence
er.set_config({"efield_position_dependence": True})
_cached_functions.clear()
er.deduce(
data_names=("cs1", "cs2"),
func_name="er_sim",
force_no_eff=True,
)
er.compile()
er.lineage_hash
key, h = er.simulate_hist(key, batch_size, parameters)
Loading