#---------------------------------------------------------- def get_clusters(hits): """ Constructs a list of clusters from adjacent hits in the supplied list of hits. """ clusters = [] # Initialise the list of clusters. # Loop over hits making new clusters from any hits not yet clustered for hit in hits: if hit.isClustered(): continue # Ignore hits that have been clustered already. cluster = cluster() # Create a new (empty) cluster. cluster.add(hit) # Add the (unclustered) hit. clusters.append(cluster) # Add the new cluster to the list. # Now we loop over all of the other hits, looking for adjacent hits. # The loop only ends when we have run out of adjacent his. # found = True # Initialise our oop test as true. while (found): # Loops until nothing more is found found = False for nhit in hits: # Loops around all other hits to see # if they are cllustered if nhit.isClustered(): # Hit already clustered, ignore it. continue if cluster.isNear(nhit): # Hit is in cluster! Woohoo! cluster.add(nhit) # Add to the cluster. found = True # Make sure we loop again. return clusters print len(clusters)