@njit()<EOL>def _cluster_hits(hits, clusters, assigned_hit_array, cluster_hit_indices, column_cluster_distance, row_cluster_distance, frame_cluster_distance, min_hit_charge, max_hit_charge, ignore_same_hits, noisy_pixels, disabled_pixels):
total_hits = hits.shape[<NUM_LIT:0>]<EOL>if total_hits == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:0>  <EOL><DEDENT>max_cluster_hits = cluster_hit_indices.shape[<NUM_LIT:0>]<EOL>if total_hits != clusters.shape[<NUM_LIT:0>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if total_hits != assigned_hit_array.shape[<NUM_LIT:0>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if min_hit_charge == <NUM_LIT:0>:<EOL><INDENT>charge_correction = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>charge_correction = <NUM_LIT:0><EOL><DEDENT>start_event_hit_index = <NUM_LIT:0><EOL>start_event_cluster_index = <NUM_LIT:0><EOL>cluster_size = <NUM_LIT:0><EOL>event_number = hits[<NUM_LIT:0>]['<STR_LIT>']<EOL>event_cluster_index = <NUM_LIT:0><EOL>for i in range(total_hits):<EOL><INDENT>if _new_event(hits[i]['<STR_LIT>'], event_number):<EOL><INDENT>_finish_event(<EOL>hits=hits,<EOL>clusters=clusters,<EOL>start_event_hit_index=start_event_hit_index,<EOL>stop_event_hit_index=i,<EOL>start_event_cluster_index=start_event_cluster_index,<EOL>stop_event_cluster_index=start_event_cluster_index + event_cluster_index)<EOL>start_event_hit_index = i<EOL>start_event_cluster_index = start_event_cluster_index + event_cluster_index<EOL>event_number = hits[i]['<STR_LIT>']<EOL>event_cluster_index = <NUM_LIT:0><EOL><DEDENT>if assigned_hit_array[i] > <NUM_LIT:0>:  <EOL><INDENT>continue<EOL><DEDENT>if not _hit_ok(<EOL>hit=hits[i],<EOL>min_hit_charge=min_hit_charge,<EOL>max_hit_charge=max_hit_charge) or (disabled_pixels.shape[<NUM_LIT:0>] != <NUM_LIT:0> and _pixel_masked(hits[i], disabled_pixels)):<EOL><INDENT>_set_hit_invalid(hit=hits[i], cluster_id=-<NUM_LIT:1>)<EOL>assigned_hit_array[i] = <NUM_LIT:1><EOL>continue<EOL><DEDENT>_set_1d_array(cluster_hit_indices, -<NUM_LIT:1>, cluster_size)<EOL>cluster_hit_indices[<NUM_LIT:0>] = i<EOL>assigned_hit_array[i] = <NUM_LIT:1><EOL>cluster_size = <NUM_LIT:1>  <EOL>for j in cluster_hit_indices:  <EOL><INDENT>if j < <NUM_LIT:0>:  <EOL><INDENT>break<EOL><DEDENT>for k in range(cluster_hit_indices[<NUM_LIT:0>] + <NUM_LIT:1>, total_hits):<EOL><INDENT>if _new_event(hits[k]['<STR_LIT>'], event_number):<EOL><INDENT>break<EOL><DEDENT>if assigned_hit_array[k] > <NUM_LIT:0>:<EOL><INDENT>continue<EOL><DEDENT>if not _hit_ok(<EOL>hit=hits[k],<EOL>min_hit_charge=min_hit_charge,<EOL>max_hit_charge=max_hit_charge) or (disabled_pixels.shape[<NUM_LIT:0>] != <NUM_LIT:0> and _pixel_masked(hits[k], disabled_pixels)):<EOL><INDENT>_set_hit_invalid(hit=hits[k], cluster_id=-<NUM_LIT:1>)<EOL>assigned_hit_array[k] = <NUM_LIT:1><EOL>continue<EOL><DEDENT>if _is_in_max_difference(hits[j]['<STR_LIT>'], hits[k]['<STR_LIT>'], column_cluster_distance) and _is_in_max_difference(hits[j]['<STR_LIT>'], hits[k]['<STR_LIT>'], row_cluster_distance) and _is_in_max_difference(hits[j]['<STR_LIT>'], hits[k]['<STR_LIT>'], frame_cluster_distance):<EOL><INDENT>if not ignore_same_hits or hits[j]['<STR_LIT>'] != hits[k]['<STR_LIT>'] or hits[j]['<STR_LIT>'] != hits[k]['<STR_LIT>']:<EOL><INDENT>cluster_size += <NUM_LIT:1><EOL>if cluster_size > max_cluster_hits:<EOL><INDENT>raise IndexError('<STR_LIT>')<EOL><DEDENT>cluster_hit_indices[cluster_size - <NUM_LIT:1>] = k<EOL>assigned_hit_array[k] = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>_set_hit_invalid(hit=hits[k], cluster_id=-<NUM_LIT:2>)<EOL>assigned_hit_array[k] = <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT><DEDENT>if cluster_size == <NUM_LIT:1> and noisy_pixels.shape[<NUM_LIT:0>] != <NUM_LIT:0> and _pixel_masked(hits[cluster_hit_indices[<NUM_LIT:0>]], noisy_pixels):<EOL><INDENT>_set_hit_invalid(hit=hits[cluster_hit_indices[<NUM_LIT:0>]], cluster_id=-<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>_finish_cluster(<EOL>hits=hits,<EOL>clusters=clusters,<EOL>cluster_size=cluster_size,<EOL>cluster_hit_indices=cluster_hit_indices,<EOL>cluster_index=start_event_cluster_index + event_cluster_index,<EOL>cluster_id=event_cluster_index,<EOL>charge_correction=charge_correction,<EOL>noisy_pixels=noisy_pixels,<EOL>disabled_pixels=disabled_pixels)<EOL>event_cluster_index += <NUM_LIT:1><EOL><DEDENT><DEDENT>_finish_event(<EOL>hits=hits,<EOL>clusters=clusters,<EOL>start_event_hit_index=start_event_hit_index,<EOL>stop_event_hit_index=total_hits,<EOL>start_event_cluster_index=start_event_cluster_index,<EOL>stop_event_cluster_index=start_event_cluster_index + event_cluster_index)<EOL>total_clusters = start_event_cluster_index + event_cluster_index<EOL>return total_clusters<EOL>
Main precompiled function that loopes over the hits and clusters them