Skip to content

Commit

Permalink
Simulate S2AFT
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx committed May 5, 2024
1 parent 9605814 commit 745f36a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 14 additions & 0 deletions axidence/plugins/salting/events_salting.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class EventsSalting(ExhaustPlugin, DownChunkingPlugin, EventPositions, EventBasi
help="Min time delay in [ns] for events towards the run end boundary",
)

assigned_area_fraction_top = straxen.URLConfig(
default=1.0,
type=(int, float, None),
help="Assigned area fraction top for S2",
)

n_drift_time_window = straxen.URLConfig(
default=5,
type=int,
Expand All @@ -89,6 +95,7 @@ def infer_dtype(self):
dtype_reference = self.refer_dtype()
required_names = ["time", "endtime", "s1_center_time", "s2_center_time"]
required_names += ["s1_area", "s2_area", "s1_n_hits", "s1_tight_coincidence"]
required_names += ["s2_area_fraction_top"]
required_names += ["x", "y", "z", "drift_time", "s2_x", "s2_y", "z_naive"]
dtype = copy_dtype(dtype_reference, required_names)
# since event_number is int64 in event_basics
Expand Down Expand Up @@ -164,6 +171,9 @@ def sample_area(distribution, area_range, n_events, rng):
area = interp1d(distribution[0], distribution[1])(cdf)
return area

def sample_area_fraction_top(self, s2_area, s2_x, s2_y):
return self.assigned_area_fraction_top

def sampling(self, start, end):
"""Sample the features of events, (t, x, y, z, S1, S2) et al."""
time = self.sample_time(start, end)
Expand Down Expand Up @@ -214,6 +224,10 @@ def sampling(self, start, end):
self.events_salting["s1_area"] = np.clip(self.events_salting["s1_area"], *s1_area_range)
self.events_salting["s2_area"] = np.clip(self.events_salting["s2_area"], *s2_area_range)

self.events_salting["s2_area_fraction_top"] = self.sample_area_fraction_top(
self.events_salting["s2_area"], self.events_salting["s2_x"], self.events_salting["s2_y"],
)

if np.any(np.diff(self.events_salting["time"]) <= 0):
raise ValueError("The time is not strictly increasing!")

Expand Down
6 changes: 3 additions & 3 deletions axidence/plugins/salting/peaks_salted.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class PeaksSalted(PeakBasics):
__version__ = "0.0.0"
__version__ = "0.0.1"
child_plugin = True
depends_on = "events_salting"
provides = "peaks_salted"
Expand All @@ -32,7 +32,7 @@ def refer_dtype(self):
def infer_dtype(self):
dtype_reference = self.refer_dtype()
required_names = ["time", "endtime", "center_time"]
required_names += ["area", "n_hits", "tight_coincidence", "type"]
required_names += ["area", "area_fraction_top", "n_hits", "tight_coincidence", "type"]
dtype = copy_dtype(dtype_reference, required_names)
# since event_number is int64 in event_basics
dtype += [
Expand Down Expand Up @@ -67,7 +67,7 @@ def compute(self, events_salting):
np.full(len(events_salting), -1),
]
).T.flatten()
for n in "x y".split():
for n in "x y area_fraction_top".split():
peaks_salted[n] = np.vstack(
[
np.full(len(events_salting), np.nan),
Expand Down

0 comments on commit 745f36a

Please sign in to comment.