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 photoionization plugins #52

Merged
merged 98 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
7afe5e0
Add general structure
HenningSE Jul 3, 2023
d87c1dd
Merge branch 'main' into more_afterpulses
HenningSE Jul 13, 2023
88b87de
Rename
HenningSE Jul 13, 2023
719b996
Add draft for PhotoElectricElectrons plugin
HenningSE Jul 13, 2023
1de091c
Add photo ionization electrons plugin + Bugfix
HenningSE Aug 14, 2023
a73a18d
Multiple Updates
HenningSE Aug 15, 2023
75f3ca6
update contexts, rename things, merger plugins
HenningSE Aug 15, 2023
6178808
Datakind hacks
HenningSE Aug 15, 2023
488b9de
Update README.md
HenningSE Aug 15, 2023
059b8ba
Fix the photo ionization code
HenningSE Aug 16, 2023
97fb83a
Merge branch 'more_afterpulses' of https://github.com/XENONnT/fuse in…
HenningSE Aug 16, 2023
8ecbc7e
Use binomial process in electron drift
HenningSE Aug 16, 2023
a7fba74
Add Logger for delayed electron simulations
HenningSE Aug 16, 2023
412a45f
Add delayed electrons tests
HenningSE Aug 16, 2023
b5416b5
Merge branch 'main' into more_afterpulses
HenningSE Jan 17, 2024
91cb377
Fixing many bugs
HenningSE Jan 17, 2024
29e0e95
Propagate cluster_id to interactions_in_roi
HenningSE Jan 18, 2024
57527ea
Save cluster_id instead of oder_index for indiv. electrons
HenningSE Jan 18, 2024
aaba4d7
Update SecondaryScintillation plugin to not rely on order of individu…
HenningSE Jan 18, 2024
d54e8cc
Use cluster_id in S2PhotonPropagationBase
HenningSE Jan 18, 2024
94b3d64
BugFix
HenningSE Jan 18, 2024
284312f
Add MicrophysicsSummaryMerger
HenningSE Jan 19, 2024
665aaf3
Lots of bugfixing
HenningSE Jan 19, 2024
82915e9
Merge branch 'main' into more_afterpulses
HenningSE Jan 24, 2024
5c0661f
Take normalized hist
HenningSE Jan 26, 2024
9d0dc90
Merge branch 'more_afterpulses' of https://github.com/XENONnT/fuse in…
HenningSE Jan 26, 2024
ad3fd00
Bugfix and cleanup
HenningSE Jan 30, 2024
077de4f
Remove PhotoElectricElectrons
HenningSE Jan 30, 2024
36a0830
Always save photo_ionization_electrons
HenningSE Jan 30, 2024
30336b8
Update the plugin structure figure
HenningSE Jan 30, 2024
38324cd
Small update to the readme
HenningSE Jan 30, 2024
5db7822
Merge branch 'main' into more_afterpulses
HenningSE Feb 1, 2024
8bef585
Merge branch 'main' into more_afterpulses
HenningSE Feb 1, 2024
c53dfa6
Update PI tests
HenningSE Feb 1, 2024
9218f00
Merge branch 'main' into more_afterpulses
dachengx Feb 1, 2024
7c5b1d0
Use base plugin for delayed electrons
HenningSE Feb 1, 2024
729870e
Merge branch 'main' into more_afterpulses
HenningSE Feb 5, 2024
69f9a9c
Merge branch 'main' into more_afterpulses
HenningSE Feb 7, 2024
40b1274
Scale the PI strength
HenningSE Feb 8, 2024
f6070ff
Merge branch 'more_afterpulses' of https://github.com/XENONnT/fuse in…
HenningSE Feb 8, 2024
e759aeb
Merge branch 'main' into more_afterpulses
HenningSE Feb 8, 2024
bfdea39
Code speedup
HenningSE Feb 8, 2024
f2093c7
Merge branch 'more_afterpulses' of https://github.com/XENONnT/fuse in…
HenningSE Feb 8, 2024
9439f05
Merge branch 'main' into more_afterpulses
HenningSE Feb 12, 2024
1c65754
Merge branch 'main' into more_afterpulses
HenningSE Feb 13, 2024
71e9407
Merge branch 'main' into more_afterpulses
HenningSE Feb 14, 2024
c2f6325
Bugfix
HenningSE Feb 14, 2024
207ba89
Update find_cluster.py
HenningSE Feb 19, 2024
19d71b2
Update FindCluster.rst
HenningSE Feb 19, 2024
3597a01
Merge branch 'main' into more_afterpulses
HenningSE Feb 19, 2024
2ae9e73
Add cluster_id
HenningSE Feb 19, 2024
bf51063
Numba problems force me to go to float32 for electric field
HenningSE Feb 20, 2024
672ac8b
Rename t to time
HenningSE Feb 20, 2024
335b94a
Missing field rename
HenningSE Feb 20, 2024
a3d42cf
Merge branch 'main' into more_afterpulses
HenningSE Feb 21, 2024
1ecf614
Merge branch 'main' into more_afterpulses
HenningSE Feb 22, 2024
8a0322b
Get PI from xedocs
HenningSE Feb 22, 2024
e00a742
Merge branch 'main' into more_afterpulses
HenningSE Feb 26, 2024
f3d27ce
Merge branch 'main' into more_afterpulses
HenningSE Mar 6, 2024
3b0d74f
Test Bugfixing
HenningSE Mar 6, 2024
d3022f4
Fix cluster id for delayed electrons
HenningSE Mar 7, 2024
a6b653c
Add empty s1 photon hits for delayed electrons (needed for truth)
HenningSE Mar 7, 2024
ae3e18d
update PeakTruth
HenningSE Mar 7, 2024
ddf8f01
Add test for delayed_s1_photons
HenningSE Mar 7, 2024
72e9a0d
revert some messed up changes
HenningSE Mar 7, 2024
0d82568
follow up on the last commit
HenningSE Mar 7, 2024
e35bb23
Merge branch 'main' into more_afterpulses
HenningSE Mar 14, 2024
cdf3bf5
Merge branch 'main' into more_afterpulses
HenningSE Mar 15, 2024
a174e97
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 15, 2024
920b7a7
cleanup
HenningSE Mar 15, 2024
e722188
fixing
HenningSE Mar 15, 2024
dce96fd
fixing
HenningSE Mar 15, 2024
2c20888
Merge branch 'more_afterpulses' of https://github.com/XENONnT/fuse in…
HenningSE Mar 15, 2024
55edc31
Add logging and cleanup
HenningSE Mar 15, 2024
3ad2809
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 15, 2024
f16d849
remove tuple
HenningSE Mar 15, 2024
9cd2968
Merge branch 'more_afterpulses' of https://github.com/XENONnT/fuse in…
HenningSE Mar 15, 2024
30d0a4b
Cleanup
HenningSE Mar 15, 2024
b3b64d0
Merge branch 'main' into more_afterpulses
HenningSE Mar 15, 2024
599279d
Modify dtype of csv input
HenningSE Mar 16, 2024
056274d
Merge branch 'main' into more_afterpulses
HenningSE Mar 16, 2024
f93dc0c
Merge branch 'main' into more_afterpulses
HenningSE Mar 19, 2024
3f6ed89
Merge branch 'main' into more_afterpulses
HenningSE Mar 19, 2024
2ae7533
Merge branch 'main' into more_afterpulses
ramirezdiego Mar 20, 2024
09b4fb1
Disable electron lifetime for delayed electrons.
HenningSE Mar 25, 2024
d811e72
Get PI delay times from truncated exponential distribution
HenningSE Mar 26, 2024
8c1c58c
Merge branch 'main' into more_afterpulses
HenningSE Apr 3, 2024
6c51d83
exclude PI photons from contributing to raw_area
HenningSE Apr 3, 2024
45ec663
Add number of PI photons in peak
HenningSE Apr 3, 2024
8066304
Merge branch 'main' into more_afterpulses
HenningSE Apr 4, 2024
d71cdd8
Take PI settings from config file
HenningSE Apr 8, 2024
c394270
Update figures
HenningSE Apr 8, 2024
07c5246
Add documentation page for PhotoIonizationElectrons
HenningSE Apr 8, 2024
80e90fe
Merge branch 'main' into more_afterpulses
HenningSE Apr 10, 2024
28a7993
Merge branch 'main' into more_afterpulses
HenningSE Apr 10, 2024
b63ab8e
Add delayed electrons plugins to documentation
HenningSE Apr 10, 2024
51eb7d9
Bugfix
HenningSE Apr 10, 2024
df9836c
Merge branch 'main' into more_afterpulses
ramirezdiego Apr 10, 2024
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
6 changes: 3 additions & 3 deletions docs/source/build_plugin_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ def build_all_pages():
plugin = st._get_plugins(targets=(target,), run_id="00000")[target]

class_string = str(plugin.__class__)
file_path = os.path.join(
this_dir, class_string.split(".")[2], *class_string.split(".")[4:]
)[:-2]
path_components = class_string.split(".")
del path_components[-2] # remove the file name
file_path = os.path.join(this_dir, *path_components[2:])[:-2]

documentation = create_plugin_documentation_text(st, plugin)

Expand Down
9 changes: 7 additions & 2 deletions docs/source/detector_physics.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Detector Physics Simulation
===========================

The detectorphysics simulation is performed in 8 plugins. These are listed below.
The detectorphysics simulation is performed in multiple plugins. They are listed below.

.. toctree::
:maxdepth: 1
Expand All @@ -14,7 +14,12 @@ The detectorphysics simulation is performed in 8 plugins. These are listed below
plugins/detector_physics/ElectronTiming
plugins/detector_physics/SecondaryScintillation
plugins/detector_physics/S2PhotonPropagation
plugins/detector_physics/Delayed_Electrons
plugins/detector_physics/delayed_electrons/PhotoIonizationElectrons
plugins/detector_physics/delayed_electrons/DelayedElectronsDrift
plugins/detector_physics/delayed_electrons/DelayedElectronsExtraction
plugins/detector_physics/delayed_electrons/DelayedElectronsTiming
plugins/detector_physics/delayed_electrons/DelayedElectronsSecondaryScintillation


.. image:: figures/DetectorPhysicsStructure.pdf
:width: 600
Expand Down
Binary file modified docs/source/figures/DetectorPhysicsStructure.pdf
Binary file not shown.
Binary file modified docs/source/figures/fuse_simulation_chain.pdf
Binary file not shown.
Binary file modified docs/source/figures/fuse_simulation_chain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 34 additions & 2 deletions fuse/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@
fuse.detector_physics.S2PhotonPropagation,
]

# Plugins to simulate delayed electrons
delayed_electron_simulation_plugins = [
fuse.detector_physics.delayed_electrons.PhotoIonizationElectrons,
fuse.detector_physics.delayed_electrons.DelayedElectronsDrift,
fuse.detector_physics.delayed_electrons.DelayedElectronsExtraction,
fuse.detector_physics.delayed_electrons.DelayedElectronsTiming,
fuse.detector_physics.delayed_electrons.DelayedElectronsSecondaryScintillation,
fuse.detector_physics.delayed_electrons.S1PhotonHitsEmpty,
]

# Plugins to merge delayed and regular electrons
delayed_electron_merger_plugins = [
fuse.detector_physics.delayed_electrons.DriftedElectronsMerger,
fuse.detector_physics.delayed_electrons.ExtractedElectronsMerger,
fuse.detector_physics.delayed_electrons.ElectronTimingMerger,
fuse.detector_physics.delayed_electrons.SecondaryScintillationPhotonsMerger,
fuse.detector_physics.delayed_electrons.SecondaryScintillationPhotonSumMerger,
fuse.detector_physics.delayed_electrons.MicrophysicsSummaryMerger,
fuse.detector_physics.delayed_electrons.S1PhotonHitsMerger,
]

# Plugins to simulate PMTs and DAQ
pmt_and_daq_plugins = [
fuse.pmt_and_daq.PMTAfterPulses,
Expand Down Expand Up @@ -138,6 +159,14 @@ def full_chain_context(
for plugin in s2_simulation_plugins:
st.register(plugin)

# Register delayed Electrons plugins
for plugin in delayed_electron_simulation_plugins:
st.register(plugin)

# Register merger plugins.
for plugin in delayed_electron_merger_plugins:
st.register(plugin)

# Register PMT and DAQ plugins
for plugin in pmt_and_daq_plugins:
st.register(plugin)
Expand Down Expand Up @@ -183,10 +212,13 @@ def set_simulation_config_file(context, config_file_name):
for option_key, option in plugin.takes_config.items():
if isinstance(option.default, str) and "SIMULATION_CONFIG_FILE.json" in option.default:
context.config[option_key] = option.default.replace(
"SIMULATION_CONFIG_FILE.json",
config_file_name,
"SIMULATION_CONFIG_FILE.json", config_file_name
)

# Special case for the photoionization_modifier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why photoionization_modifier is special?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dachengx, this part is a little trick to properly set the photoionization_modifier config argument. The problem is that it is not written to the context config by st.apply_xedocs_configs(version=corrections_version) (here). As as result the plugin.run_id would not be overwritten by the corrections_run_id here.

I solved this problem by explicitly writing this config argument to the context config in the set_simulation_config_file function as we loop over all plugins and plugin configs anyways so we will also encounter the photoionization_modifier there. As it is now in the context config, plugin.run_id can now be changed to corrections_run_id.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be solved if the photoionization_modifier is added to the global config: https://github.com/XENONnT/corrections/blob/92aa12f5fbae460c990e04bc571af0df3f67e68d/XENONnT/global_versions/global_v14.json?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so yes. Then st.apply_xedocs_configs(version=corrections_version) should already take care of this.

if option_key == "photoionization_modifier":
context.config[option_key] = option.default


@URLConfig.register("pattern_map")
def pattern_map(map_data, pmt_mask, method="WeightedNearestNeighbors"):
Expand Down
4 changes: 2 additions & 2 deletions fuse/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class FuseBasePlugin(strax.Plugin):
# Forbid rechunking
rechunk_on_save = False

# Lets wait 10 minutes for the plugin to finish
input_timeout = 600
# Lets wait 15 minutes for the plugin to finish.. PI takes a while to run
input_timeout = 900

# Config options
debug = straxen.URLConfig(
Expand Down
3 changes: 3 additions & 0 deletions fuse/plugins/detector_physics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@

from . import csv_input
from .csv_input import *

from . import delayed_electrons
from .delayed_electrons import *
12 changes: 3 additions & 9 deletions fuse/plugins/detector_physics/csv_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ class ChunkCsvInput(FuseBasePlugin):
(("Energy of the cluster [keV]", "ed"), np.float32),
(("NEST interaction type", "nestid"), np.int8),
(("ID of the cluster", "cluster_id"), np.int32),
(
("Time of the interaction [ns]", "t"),
np.int64,
), # Remove them later as they are not in the usual micropyhsics summary
(
("Geant4 event ID", "eventid"),
np.int32,
), # Remove them later as they are not in the usual micropyhsics summary
]
dtype = dtype + strax.time_fields

Expand Down Expand Up @@ -96,11 +88,13 @@ def compute(self):
try:
chunk_data, chunk_left, chunk_right, source_done = next(self.file_reader_iterator)
chunk_data["endtime"] = chunk_data["time"]
data = np.zeros(len(chunk_data), dtype=self.dtype)
strax.copy_to_buffer(chunk_data, data, "_bring_data_into_correct_format")

self.source_done = source_done

return self.chunk(
start=chunk_left, end=chunk_right, data=chunk_data, data_type="geant4_interactions"
start=chunk_left, end=chunk_right, data=data, data_type="geant4_interactions"
)

except StopIteration:
Expand Down
20 changes: 20 additions & 0 deletions fuse/plugins/detector_physics/delayed_electrons/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from . import delayed_electrons_drift
from .delayed_electrons_drift import *

from . import delayed_electrons_extraction
from .delayed_electrons_extraction import *

from . import delayed_electrons_timing
from .delayed_electrons_timing import *

from . import delayed_electrons_secondary_scintillation
from .delayed_electrons_secondary_scintillation import *

from . import photo_ionization_electrons
from .photo_ionization_electrons import *

from . import delayed_electrons_merger
from .delayed_electrons_merger import *

from . import delayed_electrons_s1photonhits
from .delayed_electrons_s1photonhits import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import strax
import straxen
import logging
from ..electron_drift import ElectronDrift

export, __all__ = strax.exporter()

logging.basicConfig(handlers=[logging.StreamHandler()])
log = logging.getLogger("fuse.detector_physics.delayed_electrons.delayed_electrons_drift")


@export
class DelayedElectronsDrift(ElectronDrift):
"""This class is used to simulate the drift of electrons from the sources
of electron afterpulses."""

__version__ = "0.0.2"

child_plugin = True

depends_on = "photo_ionization_electrons"
provides = "drifted_delayed_electrons"
data_kind = "delayed_interactions_in_roi"

electron_lifetime_liquid_delayed_electrons = straxen.URLConfig(
default=0,
track=True,
type=(int, float),
child_option=True,
parent_option_name="electron_lifetime_liquid",
help="Electron lifetime in liquid xenon [ns] for delayed electrons",
)

def compute(self, delayed_interactions_in_roi):
return super().compute(interactions_in_roi=delayed_interactions_in_roi)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import strax
import logging
from ..electron_extraction import ElectronExtraction

export, __all__ = strax.exporter()

logging.basicConfig(handlers=[logging.StreamHandler()])
log = logging.getLogger("fuse.detector_physics.delayed_electrons.delayed_electrons_extraction")


@export
class DelayedElectronsExtraction(ElectronExtraction):
"""This class is used to simulate the extraction of electrons from the
sources of electron afterpulses."""

__version__ = "0.0.1"

child_plugin = True

depends_on = ("photo_ionization_electrons", "drifted_delayed_electrons")
provides = "extracted_delayed_electrons"
data_kind = "delayed_interactions_in_roi"

def compute(self, delayed_interactions_in_roi):
return super().compute(interactions_in_roi=delayed_interactions_in_roi)
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import strax

from ....vertical_merger_plugin import VerticalMergerPlugin

export, __all__ = strax.exporter()


@export
class DriftedElectronsMerger(VerticalMergerPlugin):
"""Plugin which concatenates the output of the regular and delayed electron
drift plugins."""

depends_on = ("drifted_electrons", "drifted_delayed_electrons")

provides = "merged_drifted_electrons"
data_kind = "interactions_in_roi"
__version__ = "0.0.1"


@export
class ExtractedElectronsMerger(VerticalMergerPlugin):
"""Plugin which concatenates the output of the regular and delayed electron
extraction plugins."""

depends_on = ("extracted_electrons", "extracted_delayed_electrons")

provides = "merged_extracted_electrons"
data_kind = "interactions_in_roi"
__version__ = "0.0.1"


@export
class SecondaryScintillationPhotonsMerger(VerticalMergerPlugin):
"""Plugin which concatenates the output of the regular and delayed electron
secondary scintillation plugins."""

depends_on = ("s2_photons", "delayed_electrons_s2_photons")

provides = "merged_s2_photons"
data_kind = "individual_electrons"
__version__ = "0.0.1"


@export
class SecondaryScintillationPhotonSumMerger(VerticalMergerPlugin):
"""Plugin which concatenates the output of the regular and delayed electron
secondary scintillation plugins."""

depends_on = ("s2_photons_sum", "delayed_electrons_s2_photons_sum")

provides = "merged_s2_photons_sum"
data_kind = "interactions_in_roi"
__version__ = "0.0.1"


@export
class ElectronTimingMerger(VerticalMergerPlugin):
"""Plugin which concatenates the output of the regular and delayed electron
timing plugins."""

depends_on = ("electron_time", "delayed_electrons_time")

provides = "merged_electron_time"
data_kind = "individual_electrons"
__version__ = "0.0.1"


@export
class MicrophysicsSummaryMerger(VerticalMergerPlugin):
"""Plugin which concatenates the output of the regular and delayed electron
secondary scintillation plugins."""

depends_on = ("microphysics_summary", "photo_ionization_electrons")

provides = "merged_microphysics_summary"
data_kind = "interactions_in_roi"
__version__ = "0.0.1"


@export
class S1PhotonHitsMerger(VerticalMergerPlugin):
"""Plugin which concatenates the output of the regular and delayed s1
photon hits plugins."""

depends_on = ("s1_photons", "delayed_s1_photons")

provides = "merged_s1_photons"
data_kind = "interactions_in_roi"
__version__ = "0.0.1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import strax
import logging
import numpy as np

from ....plugin import FuseBasePlugin

export, __all__ = strax.exporter()

logging.basicConfig(handlers=[logging.StreamHandler()])
log = logging.getLogger("fuse.detector_physics.delayed_electrons.delayed_electrons_s1photonhits")


@export
class S1PhotonHitsEmpty(FuseBasePlugin):
"""Plugin to return zeros for all S1 photon hits of delayed electrons."""

__version__ = "0.0.1"

depends_on = "photo_ionization_electrons"
provides = "delayed_s1_photons"
data_kind = "delayed_interactions_in_roi"

dtype = [
(("Number detected S1 photons", "n_s1_photon_hits"), np.int32),
]
dtype = dtype + strax.time_fields

def compute(self, delayed_interactions_in_roi):
result = np.zeros(len(delayed_interactions_in_roi), dtype=self.dtype)
result["time"] = delayed_interactions_in_roi["time"]
result["endtime"] = delayed_interactions_in_roi["endtime"]
return result
Loading