Skip to content

Commit

Permalink
Merge branch 'main' into yields-no-rf
Browse files Browse the repository at this point in the history
  • Loading branch information
HenningSE committed Jul 16, 2024
2 parents d13e47b + 65861a8 commit ec64693
Show file tree
Hide file tree
Showing 26 changed files with 49 additions and 147 deletions.
15 changes: 7 additions & 8 deletions fuse/plugins/detector_physics/csv_input.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
from typing import Tuple

import numpy as np
Expand All @@ -19,9 +18,6 @@
export, __all__ = strax.exporter()
__all__.extend(["microphysics_summary_fields"])

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


# In some cases we might want to change dtype of microphysics_summary
# through microphysics_summary_fields, so do not set microphysics_summary_fields
Expand Down Expand Up @@ -90,6 +86,7 @@ def setup(self):
separation_scale=self.separation_scale,
n_interactions_per_chunk=self.n_interactions_per_chunk,
debug=self.debug,
log=self.log,
)
self.file_reader_iterator = self.file_reader.output_chunk()

Expand Down Expand Up @@ -136,6 +133,7 @@ def __init__(
first_chunk_left=1e6,
last_chunk_length=1e8,
debug=False,
log=None,
):
self.input_file = input_file
self.rng = random_number_generator
Expand All @@ -146,6 +144,7 @@ def __init__(
self.last_chunk_length = np.int64(last_chunk_length)
self.first_chunk_left = np.int64(first_chunk_left)
self.debug = debug
self.log = log

# The csv file needs to have these columns:
_fields = ChunkCsvInput.needed_csv_input_fields()
Expand All @@ -167,7 +166,7 @@ def output_chunk(self):
instructions["time"] = interaction_time + instructions["t"]
elif self.event_rate == 0:
instructions["time"] = instructions["t"]
log.debug("Using event times from provided input file.")
self.log.debug("Using event times from provided input file.")
else:
raise ValueError("Source rate cannot be negative!")

Expand All @@ -193,7 +192,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 too high?")
self.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 All @@ -206,15 +205,15 @@ def output_chunk(self):
):
if c_ix == unique_chunk_index_values[-1]:
source_done = True
log.debug("Build last chunk.")
self.log.debug("Build last chunk.")

yield instructions[chunk_idx == c_ix], chunk_left, chunk_right, source_done

def last_chunk_bounds(self):
return self.chunk_bounds[-1]

def __load_csv_file(self):
log.debug("Load detector simulation instructions from a csv file!")
self.log.debug("Load detector simulation instructions from a csv file!")
df = pd.read_csv(self.input_file)

missing_columns = set(self.columns) - set(df.columns)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import strax
import numpy as np
import logging
from immutabledict import immutabledict
from ..secondary_scintillation import SecondaryScintillation

export, __all__ = strax.exporter()

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


@export
class DelayedElectronsSecondaryScintillation(SecondaryScintillation):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import strax
import logging
from ..electron_timing import ElectronTiming

export, __all__ = strax.exporter()

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


@export
class DelayedElectronsTiming(ElectronTiming):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import strax
import straxen
import numpy as np
import logging
from scipy.stats import truncexpon

from ....plugin import FuseBasePlugin

export, __all__ = strax.exporter()

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


@export
class PhotoIonizationElectrons(FuseBasePlugin):
Expand Down Expand Up @@ -162,7 +158,9 @@ def compute(self, interactions_in_roi, individual_electrons):
mask = interactions_in_roi["sum_s2_photons"] > 0

if not self.enable_delayed_electrons or (len(interactions_in_roi[mask]) == 0):
log.debug("No interactions with S2 photons found or delayed electrons are disabled")
self.log.debug(
"No interactions with S2 photons found or delayed electrons are disabled"
)
return np.zeros(0, self.dtype)

electrons_per_interaction, unique_cluster_id = group_electrons_by_cluster_id(
Expand Down
6 changes: 1 addition & 5 deletions fuse/plugins/detector_physics/electron_drift.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import strax
import straxen
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.electron_drift")


@export
class ElectronDrift(FuseBasePlugin):
Expand Down Expand Up @@ -266,7 +262,7 @@ def compute(self, interactions_in_roi):
n=n_electron.astype(np.int32), p=electron_lifetime_correction
)
else:
log.debug("No electron lifetime applied")
self.log.debug("No electron lifetime applied")

result = np.zeros(len(interactions_in_roi), dtype=self.dtype)
result["time"] = interactions_in_roi["time"]
Expand Down
5 changes: 0 additions & 5 deletions fuse/plugins/detector_physics/electron_extraction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

import numpy as np
import strax
import straxen
Expand All @@ -8,9 +6,6 @@

export, __all__ = strax.exporter()

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


@export
class ElectronExtraction(FuseBasePlugin):
Expand Down
4 changes: 0 additions & 4 deletions fuse/plugins/detector_physics/electron_timing.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import strax
import numpy as np
import straxen
import logging

from ...plugin import FuseBasePlugin

export, __all__ = strax.exporter()

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


@export
class ElectronTiming(FuseBasePlugin):
Expand Down
4 changes: 0 additions & 4 deletions fuse/plugins/detector_physics/s1_photon_hits.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import strax
import straxen
import logging

import numpy as np
from copy import deepcopy
Expand All @@ -10,9 +9,6 @@

export, __all__ = strax.exporter()

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


@export
class S1PhotonHits(FuseBasePlugin):
Expand Down
11 changes: 3 additions & 8 deletions fuse/plugins/detector_physics/s1_photon_propagation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

import numpy as np
import nestpy
import strax
Expand All @@ -16,9 +14,6 @@

export, __all__ = strax.exporter()

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

# Initialize the nestpy random generator
# The seed will be set in the compute method
nest_rng = nestpy.RandomGen.rndm()
Expand Down Expand Up @@ -137,9 +132,9 @@ def setup(self):
if self.deterministic_seed or (self.user_defined_random_seed is not None):
# Dont know but nestpy seems to have a problem with large seeds
self.short_seed = int(repr(self.seed)[-8:])
log.debug(f"Generating nestpy random numbers from seed {self.short_seed}")
self.log.debug(f"Generating nestpy random numbers from seed {self.short_seed}")
else:
log.debug("Generating random numbers with seed pulled from OS")
self.log.debug("Generating random numbers with seed pulled from OS")

self.gains = pmt_gains(
self.gain_model_mc,
Expand Down Expand Up @@ -338,7 +333,7 @@ class S1PhotonPropagation(S1PhotonPropagationBase):
def setup(self):
super().setup()

log.debug(
self.log.debug(
"Using NEST for scintillation time without set calculator\n"
"Creating new nestpy calculator"
)
Expand Down
14 changes: 6 additions & 8 deletions fuse/plugins/detector_physics/s2_photon_propagation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import strax
import straxen
import numpy as np
import logging

from numba import njit
from scipy.stats import skewnorm
Expand All @@ -18,9 +17,6 @@

export, __all__ = strax.exporter()

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

conversion_to_bar = 1 / constants.elementary_charge / 1e1


Expand Down Expand Up @@ -338,7 +334,9 @@ def compute(self, interactions_in_roi, individual_electrons, start, end):

n_chunks = len(electron_chunks)
if n_chunks > 1:
log.info(f"Chunk size exceeding file size target. Downchunking to {n_chunks} chunks")
self.log.info(
f"Chunk size exceeding file size target. Downchunking to {n_chunks} chunks"
)

last_start = start
for i, electron_group in enumerate(electron_chunks):
Expand Down Expand Up @@ -601,7 +599,7 @@ class S2PhotonPropagation(S2PhotonPropagationBase):

def setup(self):
super().setup()
log.debug(
self.log.debug(
"Using Garfield GasGap luminescence timing and optical propagation "
f"with plugin version {self.__version__}"
)
Expand Down Expand Up @@ -783,8 +781,8 @@ class S2PhotonPropagationSimple(S2PhotonPropagationBase):

def setup(self):
super().setup()
log.debug("Using simple luminescence timing and optical propagation")
log.warn(
self.log.debug("Using simple luminescence timing and optical propagation")
self.log.warn(
"This is a legacy option, do you really want to use the simple luminescence model?"
)

Expand Down
4 changes: 0 additions & 4 deletions fuse/plugins/detector_physics/secondary_scintillation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
from immutabledict import immutabledict

import numpy as np
Expand All @@ -10,9 +9,6 @@

export, __all__ = strax.exporter()

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


@export
class SecondaryScintillation(FuseBasePlugin):
Expand Down
4 changes: 0 additions & 4 deletions fuse/plugins/micro_physics/detector_volumes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import strax
import straxen
import logging

from ...dtypes import (
primary_positions_fields,
Expand All @@ -11,9 +10,6 @@
from ...volume_plugin import VolumePlugin
from ...vertical_merger_plugin import VerticalMergerPlugin

logging.basicConfig(handlers=[logging.StreamHandler()])
log = logging.getLogger("fuse.micro_physics.detector_volumes")


class VolumesMerger(VerticalMergerPlugin):
"""Plugin that concatenates the clusters that are in the XENONnT TPC or the
Expand Down
Loading

0 comments on commit ec64693

Please sign in to comment.