Skip to content

Commit

Permalink
Merge pull request #87 from ronandoherty1/feature_optimise
Browse files Browse the repository at this point in the history
Remove large initialised arrays
  • Loading branch information
krwood committed Dec 11, 2023
2 parents bd0d1c0 + e6321e0 commit 76b410e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/proto_nd_flow/reco/charge/calib_hit_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ def merge_hits(self,hits, weights, seg_fracs, dt_cut, sum_fields=None, weighted_

# calculate segment contributions for each merged hit
if has_mc_truth:
tmp_bt = np.full(shape=new_hits.shape+(2,self.max_contrib_segments),fill_value=0.)
back_track = np.full(shape=new_hits.shape,fill_value=0.,dtype=self.hit_frac_dtype)
# loop over hits
for hit_it, hit in np.ndenumerate(new_hits):
Expand All @@ -250,12 +249,12 @@ def merge_hits(self,hits, weights, seg_fracs, dt_cut, sum_fields=None, weighted_
# renormalize the fractional contributions given the charge weighted average
norm = np.sum(np.multiply(hit_contr[0],hit_contr[1]))
if norm == 0.: norm = 1.
tmp_bt[hit_it][0] = np.multiply(hit_contr[0],hit_contr[1])/norm # fractional contributions
tmp_bt[hit_it][1] = hit_contr[2] # segment_ids
tmp_bt_0 = np.multiply(hit_contr[0],hit_contr[1])/norm # fractional contributions
tmp_bt_1 = hit_contr[2] # segment_ids

# merge unique track contributions
track_dict = defaultdict(lambda:0)
for track in zip(tmp_bt[hit_it][0],tmp_bt[hit_it][1]):
for track in zip(tmp_bt_0,tmp_bt_1):
track_dict[track[1]] += track[0]
track_dict = dict(track_dict)
bt_unique_segs = np.array(list(track_dict.keys()))
Expand Down

0 comments on commit 76b410e

Please sign in to comment.