pixel_clusterizer/cluster_functions.py
def _finish_cluster(hits, clusters, cluster_size, cluster_hit_indices, cluster_index, cluster_id, charge_correction, noisy_pixels, disabled_pixels):
    ''' Set hit and cluster information of the cluster (e.g. number of hits in the cluster (cluster_size), total cluster charge (charge), ...).
    '''
    cluster_charge = 0
    max_cluster_charge = -1
    # necessary for charge weighted hit position
    total_weighted_column = 0
    total_weighted_row = 0

    for i in range(cluster_size):
        hit_index = cluster_hit_indices[i]
        if hits[hit_index]['charge'] > max_cluster_charge:
            seed_hit_index = hit_index
            max_cluster_charge = hits[hit_index]['charge']
        hits[hit_index]['is_seed'] = 0
        hits[hit_index]['cluster_size'] = cluster_size
        # include charge correction in sum
        total_weighted_column += hits[hit_index]['column'] * (hits[hit_index]['charge'] + charge_correction)
        total_weighted_row += hits[hit_index]['row'] * (hits[hit_index]['charge'] + charge_correction)
        cluster_charge += hits[hit_index]['charge']
        hits[hit_index]['cluster_ID'] = cluster_id

    hits[seed_hit_index]['is_seed'] = 1

    clusters[cluster_index]["ID"] = cluster_id
    clusters[cluster_index]["n_hits"] = cluster_size
    clusters[cluster_index]["charge"] = cluster_charge
    clusters[cluster_index]['seed_column'] = hits[seed_hit_index]['column']
    clusters[cluster_index]['seed_row'] = hits[seed_hit_index]['row']
    # correct total charge value and calculate mean column and row
    clusters[cluster_index]['mean_column'] = float(total_weighted_column) / (cluster_charge + cluster_size * charge_correction)
    clusters[cluster_index]['mean_row'] = float(total_weighted_row) / (cluster_charge + cluster_size * charge_correction)

    # Call end of cluster function hook
    _end_of_cluster_function(
        hits=hits,
        clusters=clusters,
        cluster_size=cluster_size,
        cluster_hit_indices=cluster_hit_indices,
        cluster_index=cluster_index,
        cluster_id=cluster_id,
        charge_correction=charge_correction,
        noisy_pixels=noisy_pixels,
        disabled_pixels=disabled_pixels,
        seed_hit_index=seed_hit_index)
def _finish_cluster(hits, clusters, cluster_size, cluster_hit_indices, cluster_index, cluster_id, charge_correction, noisy_pixels, disabled_pixels):
    ''' Set hit and cluster information of the cluster (e.g. number of hits in the cluster (cluster_size), total cluster charge (charge), ...).
    '''
    cluster_charge = 0
    max_cluster_charge = -1
    # necessary for charge weighted hit position
    total_weighted_column = 0
    total_weighted_row = 0

    for i in range(cluster_size):
        hit_index = cluster_hit_indices[i]
        if hits[hit_index]['charge'] > max_cluster_charge:
            seed_hit_index = hit_index
            max_cluster_charge = hits[hit_index]['charge']
        hits[hit_index]['is_seed'] = 0
        hits[hit_index]['cluster_size'] = cluster_size
        # include charge correction in sum
        total_weighted_column += hits[hit_index]['column'] * (hits[hit_index]['charge'] + charge_correction)
        total_weighted_row += hits[hit_index]['row'] * (hits[hit_index]['charge'] + charge_correction)
        cluster_charge += hits[hit_index]['charge']
        hits[hit_index]['cluster_ID'] = cluster_id

    hits[seed_hit_index]['is_seed'] = 1

    clusters[cluster_index]["ID"] = cluster_id
    clusters[cluster_index]["n_hits"] = cluster_size
    clusters[cluster_index]["charge"] = cluster_charge
    clusters[cluster_index]['seed_column'] = hits[seed_hit_index]['column']
    clusters[cluster_index]['seed_row'] = hits[seed_hit_index]['row']
    # correct total charge value and calculate mean column and row
    clusters[cluster_index]['mean_column'] = float(total_weighted_column) / (cluster_charge + cluster_size * charge_correction)
    clusters[cluster_index]['mean_row'] = float(total_weighted_row) / (cluster_charge + cluster_size * charge_correction)

    # Call end of cluster function hook
    _end_of_cluster_function(
        hits=hits,
        clusters=clusters,
        cluster_size=cluster_size,
        cluster_hit_indices=cluster_hit_indices,
        cluster_index=cluster_index,
        cluster_id=cluster_id,
        charge_correction=charge_correction,
        noisy_pixels=noisy_pixels,
        disabled_pixels=disabled_pixels,
        seed_hit_index=seed_hit_index)
Set hit and cluster information of the cluster (e.g. number of hits in the cluster (cluster_size), total cluster charge (charge), ...).