Skip to content

Commit

Permalink
Reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
paolafer committed May 2, 2024
1 parent cf97eb6 commit d9fa6e6
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions invisible_cities/cities/detsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,17 @@ def hits_selector(active_only: bool=True):
function that select the hits depending on :active_only: parameter
"""
def select_hits(x, y, z, energy, time, label, name, name_id):
if len(label) == 0:
return [], [], [], [], [], []
if type(label[0]) == str:
sel = (label == "ACTIVE")
if not active_only:
sel = sel | (label == "BUFFER")

if label.dtype == np.int32 :
active = name_id[name == "ACTIVE"][0]
buff = name_id[name == "BUFFER"][0]
else:
active_id = name_id[name == "ACTIVE"][0]
sel = (label == active_id)
if not active_only:
buffer_id = name_id[name == "BUFFER"][0]
sel = sel | (label == buffer_id)
active = 'ACTIVE'
buff = 'BUFFER'

sel = (label == active)
if not active_only:
sel = sel | (label == buff)

return x[sel], y[sel], z[sel], energy[sel], time[sel], label[sel]
return select_hits
Expand Down

0 comments on commit d9fa6e6

Please sign in to comment.