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 5a597c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion invisible_cities/cities/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def MC_hits_from_files(files_in : List[str], rate: float) -> Generator:
strings = False

l_type = hits_df.dtypes['label']
if l_type == np.int32 :
if l_type == np.int32:
map_df = load_mcstringmap(filename)
else:
strings = True
Expand Down
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 5a597c8

Please sign in to comment.