Skip to content

Commit

Permalink
Embellish some codes (#188)
Browse files Browse the repository at this point in the history
* Embellish some codes

* Fix bug

* Usually the data_kind is in lower case
  • Loading branch information
dachengx committed Apr 10, 2024
1 parent 8ee3296 commit e23c6ab
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 105 deletions.
6 changes: 3 additions & 3 deletions docs/source/build_plugin_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
tpc_interactions="#F44E43",
below_cathode_interactions="#F44E43",
interactions_in_roi="#56C46C",
S1_photons="#54E4CF",
S2_photons="#54E4CF",
AP_photons="#54E4CF",
s1_photons="#54E4CF",
s2_photons="#54E4CF",
ap_photons="#54E4CF",
propagated_photons="#54E4CF",
pulse_ids="#54E4CF",
pulse_windows="#F78C27",
Expand Down
2 changes: 0 additions & 2 deletions fuse/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ def dynamic_chunking(data, scale, n_min):
if value <= scale:
clusters.append(c)
n_cluster += 1

elif n_cluster + 1 < n_min:
clusters.append(c)
n_cluster += 1

elif value > scale:
c = c + 1
clusters.append(c)
Expand Down
4 changes: 2 additions & 2 deletions fuse/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class FuseBasePlugin(strax.Plugin):
deterministic_seed = straxen.URLConfig(
default=True,
type=bool,
help="Set the random seed from lineage and run_id, or pull the seed from the OS.",
help="Set the random seed from lineage and run_id, or pull the seed from the OS",
)

user_defined_random_seed = straxen.URLConfig(
default=None,
help="Define the random seed manually. You need to set deterministic_seed to False.",
help="Define the random seed manually. You need to set deterministic_seed to False",
)

def setup(self):
Expand Down
24 changes: 12 additions & 12 deletions fuse/plugins/detector_physics/csv_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ChunkCsvInput(FuseBasePlugin):
"""Plugin which reads a CSV file containing instructions for the detector
physics simulation and returns the data in chunks."""

__version__ = "0.2.0"
__version__ = "0.2.1"

depends_on: Tuple = tuple()
provides = "microphysics_summary"
Expand All @@ -34,9 +34,9 @@ class ChunkCsvInput(FuseBasePlugin):
(("x position of the cluster [cm]", "x"), np.float32),
(("y position of the cluster [cm]", "y"), np.float32),
(("z position of the cluster [cm]", "z"), np.float32),
(("Number of photons at interaction position.", "photons"), np.int32),
(("Number of electrons at interaction position.", "electrons"), np.int32),
(("Number of excitons at interaction position.", "excitons"), np.int32),
(("Number of photons at interaction position", "photons"), np.int32),
(("Number of electrons at interaction position", "electrons"), np.int32),
(("Number of excitons at interaction position", "excitons"), np.int32),
(("Electric field value at the cluster position [V/cm]", "e_field"), np.float32),
(("Energy of the cluster [keV]", "ed"), np.float32),
(("NEST interaction type", "nestid"), np.int8),
Expand All @@ -62,15 +62,15 @@ class ChunkCsvInput(FuseBasePlugin):
separation_scale = straxen.URLConfig(
default=1e8,
type=(int, float),
help="separation_scale",
help="Start a new chunk when the previous cluster is separated by this time scale",
)

source_rate = straxen.URLConfig(
default=1,
type=(int, float),
help="Source rate used to generate event times"
"Use a value >0 to generate event times in fuse"
"Use source_rate = 0 to use event times from the input file (only for csv input)",
help="Source rate used to generate event times. "
"Use a value >0 to generate event times in fuse. "
"Use source_rate = 0 to use event times from the input file (only for csv input).",
)

n_interactions_per_chunk = straxen.URLConfig(
Expand Down Expand Up @@ -150,9 +150,9 @@ def __init__(
(("x position of the cluster [cm]", "x"), np.float32),
(("y position of the cluster [cm]", "y"), np.float32),
(("z position of the cluster [cm]", "z"), np.float32),
(("Number of photons at interaction position.", "photons"), np.int32),
(("Number of electrons at interaction position.", "electrons"), np.int32),
(("Number of excitons at interaction position.", "excitons"), np.int32),
(("Number of photons at interaction position", "photons"), np.int32),
(("Number of electrons at interaction position", "electrons"), np.int32),
(("Number of excitons at interaction position", "excitons"), np.int32),
(("Electric field value at the cluster position [V/cm]", "e_field"), np.float32),
(("Energy of the cluster [keV]", "ed"), np.float32),
(("NEST interaction type", "nestid"), np.int8),
Expand Down Expand Up @@ -225,7 +225,7 @@ def output_chunk(self):
chunk_bounds = chunk_end + np.int64(self.chunk_delay_fraction * gap_length)
self.chunk_bounds = np.append(chunk_start[0] - self.first_chunk_left, chunk_bounds)
else:
log.warning("Only one Chunk! Rate to high?")
log.warning("Only one Chunk! Rate too high?")
self.chunk_bounds = [
chunk_start[0] - self.first_chunk_left,
chunk_end[0] + self.last_chunk_length,
Expand Down
6 changes: 2 additions & 4 deletions fuse/plugins/detector_physics/electron_timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ class ElectronTiming(FuseBasePlugin):
extraction.
"""

__version__ = "0.2.0"
__version__ = "0.2.1"

depends_on = ("drifted_electrons", "extracted_electrons", "microphysics_summary")
depends_on = ("microphysics_summary", "drifted_electrons", "extracted_electrons")
provides = "electron_time"
data_kind = "individual_electrons"

save_when = strax.SaveWhen.TARGET

data_kind = "individual_electrons"

dtype = [
(("x position of the electron [cm]", "x"), np.float32),
(("y position of the electron [cm]", "y"), np.float32),
Expand Down
6 changes: 3 additions & 3 deletions fuse/plugins/detector_physics/s1_photon_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class S1PhotonPropagationBase(FuseBasePlugin):
Note: The timing calculation is defined in the child plugin.
"""

__version__ = "0.3.0"
__version__ = "0.3.1"

depends_on = ("s1_photons", "microphysics_summary")
depends_on = ("microphysics_summary", "s1_photons")
provides = "propagated_s1_photons"
data_kind = "S1_photons"
data_kind = "s1_photons"

save_when = strax.SaveWhen.TARGET

Expand Down
20 changes: 10 additions & 10 deletions fuse/plugins/detector_physics/s2_photon_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ class S2PhotonPropagationBase(FuseBaseDownChunkingPlugin):
Note: The timing calculation is defined in the child plugin.
"""

__version__ = "0.3.2"
__version__ = "0.3.3"

depends_on = (
"electron_time",
"s2_photons",
"microphysics_summary",
"extracted_electrons",
"drifted_electrons",
"s2_photons_sum",
"microphysics_summary",
"electron_time",
"s2_photons",
)
provides = "propagated_s2_photons"
data_kind = "S2_photons"
data_kind = "s2_photons"

save_when = strax.SaveWhen.TARGET

Expand Down Expand Up @@ -318,7 +318,7 @@ def rz_map(z, xy, **kwargs):

self.field_dependencies_map = rz_map

def compute(self, individual_electrons, interactions_in_roi, start, end):
def compute(self, interactions_in_roi, individual_electrons, start, end):
# Just apply this to clusters with photons
mask = interactions_in_roi["n_electron_extracted"] > 0

Expand Down Expand Up @@ -689,14 +689,14 @@ class S2PhotonPropagationSimple(S2PhotonPropagationBase):
default="take://resource://SIMULATION_CONFIG_FILE.json?&fmt=json&take=pressure",
type=(int, float),
cache=True,
help="pressure",
help="Pressure of liquid xenon [bar/e], while e is the elementary charge",
)

temperature = straxen.URLConfig(
default="take://resource://SIMULATION_CONFIG_FILE.json?&fmt=json&take=temperature",
type=(int, float),
cache=True,
help="temperature",
help="Temperature of liquid xenon [K]",
)

gas_drift_velocity_slope = straxen.URLConfig(
Expand Down Expand Up @@ -759,14 +759,14 @@ class S2PhotonPropagationSimple(S2PhotonPropagationBase):
"&take=gate_to_anode_distance",
type=(int, float),
cache=True,
help="gate_to_anode_distance",
help="Top of gate to bottom of anode (not considering perpendicular wires) [cm]",
)

anode_voltage = straxen.URLConfig(
default="take://resource://SIMULATION_CONFIG_FILE.json?&fmt=json&take=anode_voltage",
type=(int, float),
cache=True,
help="anode_voltage",
help="Voltage of anode [V]",
)

lxe_dielectric_constant = straxen.URLConfig(
Expand Down
2 changes: 1 addition & 1 deletion fuse/plugins/detector_physics/secondary_scintillation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class SecondaryScintillation(FuseBasePlugin):
result_name_photons_sum = "s2_photons_sum"

depends_on = (
"microphysics_summary",
"drifted_electrons",
"extracted_electrons",
"electron_time",
"microphysics_summary",
)
provides = (result_name_photons, result_name_photons_sum)
data_kind = {
Expand Down
34 changes: 17 additions & 17 deletions fuse/plugins/micro_physics/detector_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class XENONnT_TPC(VolumePlugin):

provides = "tpc_interactions"
data_kind = "tpc_interactions"
__version__ = "0.3.0"
__version__ = "0.3.1"

# Can we import this from MergeCluster and just add the needed fields?
dtype = [
Expand All @@ -57,9 +57,9 @@ class XENONnT_TPC(VolumePlugin):
(("y position of the primary particle [cm]", "y_pri"), np.float32),
(("z position of the primary particle [cm]", "z_pri"), np.float32),
(("ID of the cluster", "cluster_id"), np.int32),
(("Xenon density at the cluster position.", "xe_density"), np.float32),
(("ID of the volume in which the cluster occured.", "vol_id"), np.int8),
(("Flag indicating if a cluster can create a S2 signal.", "create_S2"), np.bool_),
(("Xenon density at the cluster position", "xe_density"), np.float32),
(("ID of the volume in which the cluster occured", "vol_id"), np.int8),
(("Flag indicating if a cluster can create a S2 signal", "create_S2"), np.bool_),
]

dtype = dtype + strax.time_fields
Expand Down Expand Up @@ -126,7 +126,7 @@ class XENONnT_BelowCathode(VolumePlugin):

provides = "below_cathode_interactions"
data_kind = "below_cathode_interactions"
__version__ = "0.3.0"
__version__ = "0.3.1"

# Can we import this from MergeCluster and just add the needed fields?
dtype = [
Expand All @@ -142,9 +142,9 @@ class XENONnT_BelowCathode(VolumePlugin):
(("y position of the primary particle [cm]", "y_pri"), np.float32),
(("z position of the primary particle [cm]", "z_pri"), np.float32),
(("ID of the cluster", "cluster_id"), np.int32),
(("Xenon density at the cluster position.", "xe_density"), np.float32),
(("ID of the volume in which the cluster occured.", "vol_id"), np.int8),
(("Flag indicating if a cluster can create a S2 signal.", "create_S2"), np.bool_),
(("Xenon density at the cluster position", "xe_density"), np.float32),
(("ID of the volume in which the cluster occured", "vol_id"), np.int8),
(("Flag indicating if a cluster can create a S2 signal", "create_S2"), np.bool_),
]

dtype = dtype + strax.time_fields
Expand Down Expand Up @@ -209,7 +209,7 @@ class XENONnT_GasPhase(VolumePlugin):

provides = "gas_phase_interactions"
data_kind = "gas_phase_interactions"
__version__ = "0.3.0"
__version__ = "0.3.1"

# Can we import this from MergeCluster and just add the needed fields?
dtype = [
Expand All @@ -225,9 +225,9 @@ class XENONnT_GasPhase(VolumePlugin):
(("y position of the primary particle [cm]", "y_pri"), np.float32),
(("z position of the primary particle [cm]", "z_pri"), np.float32),
(("ID of the cluster", "cluster_id"), np.int32),
(("Xenon density at the cluster position.", "xe_density"), np.float32),
(("ID of the volume in which the cluster occured.", "vol_id"), np.int8),
(("Flag indicating if a cluster can create a S2 signal.", "create_S2"), np.bool_),
(("Xenon density at the cluster position", "xe_density"), np.float32),
(("ID of the volume in which the cluster occured", "vol_id"), np.int8),
(("Flag indicating if a cluster can create a S2 signal", "create_S2"), np.bool_),
]

dtype = dtype + strax.time_fields
Expand All @@ -237,31 +237,31 @@ class XENONnT_GasPhase(VolumePlugin):
xenonnt_z_top_pmts = straxen.URLConfig(
default=7.3936, # cm
type=(int, float),
help="xenonnt_z_top_pmts",
help="Position of the top of gas phase [cm]",
)

xenonnt_z_lxe = straxen.URLConfig(
default=0.416, # cm ... liquid-gas interface
type=(int, float),
help="xenonnt_z_lxe",
help="Position of the bottom of gas phase [cm]",
)

xenonnt_sensitive_volume_radius = straxen.URLConfig(
default=66.4, # cm
type=(int, float),
help="xenonnt_sensitive_volume_radius",
help="Radius of the XENONnT TPC [cm]",
)

xenon_density_gas_phase = straxen.URLConfig(
default=0.0177,
type=(int, float),
help="xenon_density",
help="Density of XENON in the gas phase [g/cm3]",
)

create_S2_xenonnt_gas_phase = straxen.URLConfig(
default=False,
type=bool,
help="No S2s in gas",
help="Whether generate S2s in gas phase",
)

def compute(self, clustered_interactions):
Expand Down
2 changes: 1 addition & 1 deletion fuse/plugins/micro_physics/electric_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ElectricField(FuseBasePlugin):

__version__ = "0.2.2"

depends_on = ("interactions_in_roi",)
depends_on = "interactions_in_roi"
provides = "electric_field_values"
data_kind = "interactions_in_roi"

Expand Down
14 changes: 7 additions & 7 deletions fuse/plugins/micro_physics/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ChunkInput(FuseBasePlugin):
and will create multiple chunks of data if needed.
"""

__version__ = "0.3.1"
__version__ = "0.3.2"

depends_on: Tuple = tuple()
provides = "geant4_interactions"
Expand All @@ -47,9 +47,9 @@ class ChunkInput(FuseBasePlugin):
(("Geant4 process creating the particle", "creaproc"), "<U25"),
(("Geant4 process responsible for the energy deposit", "edproc"), "<U25"),
(("Geant4 event ID", "evtid"), np.int32),
(("x position of the primary particle", "x_pri"), np.float32),
(("y position of the primary particle", "y_pri"), np.float32),
(("z position of the primary particle", "z_pri"), np.float32),
(("x position of the primary particle [cm]", "x_pri"), np.float32),
(("y position of the primary particle [cm]", "y_pri"), np.float32),
(("z position of the primary particle [cm]", "z_pri"), np.float32),
]

dtype = dtype + strax.time_fields
Expand Down Expand Up @@ -86,7 +86,7 @@ class ChunkInput(FuseBasePlugin):
cut_delayed = straxen.URLConfig(
default=9e18,
type=(int, float),
help="All interactions happening after this time (including the event time) will be cut.",
help="All interactions happening after this time (including the event time) will be cut",
)

n_interactions_per_chunk = straxen.URLConfig(
Expand All @@ -98,12 +98,12 @@ class ChunkInput(FuseBasePlugin):
entry_start = straxen.URLConfig(
default=0,
type=(int, float),
help="Geant4 event to start simulation from.",
help="Geant4 event to start simulation from",
)

entry_stop = straxen.URLConfig(
default=None,
help="Geant4 event to stop simulation at. If None, all events are simulated.",
help="Geant4 event to stop simulation at. If None, all events are simulated",
)

cut_by_eventid = straxen.URLConfig(
Expand Down
Loading

0 comments on commit e23c6ab

Please sign in to comment.