def _make_edge(self, id1, id2, ruler): ''' id1, id2 are the unique ids of the two items ruler is something that measures distance between two objects eg track and hcal (see Distance class for example) it should take the two objects as arguments and return a tuple of the form link_type = 'ecal_ecal', 'ecal_track' etc is_link = true/false distance = float an edge object is returned which contains the link_type, is_link (bool) and distance between the objects. ''' #find the original items and pass to the ruler to get the distance info obj1 = self.pfevent.get_object(id1) obj2 = self.pfevent.get_object(id2) link_type, is_linked, distance = ruler( obj1, obj2 ) #some redundancy in link_type as both distance and Edge make link_type #not sure which to get rid of #for the event we do not want ehal_hcal links if link_type == "ecal_hcal": is_linked = False #make the edge return Edge(id1, id2, is_linked, distance)
def __init__(self, clusters, ruler, history_nodes = None): ''' clusters a dictionary : {id1:ecal1, id2:ecal2, ...} ruler is something that measures distance between two objects eg track and hcal (see Distance class for example) it should take the two objects as arguments and return a tuple of the form link_type = 'ecal_ecal', 'ecal_track' etc is_link = true/false distance = float hist_nodes is an optional dictionary of Nodes : { id:Node1, id: Node2 etc} it could for example contain the simulation history nodes A Node contains the id of an item (cluster, track, particle etc) and says what it is linked to (its parents and children) if hist_nodes is provided it will be added to with the new block information If hist_nodes is not provided one will be created, it will contain nodes corresponding to each of the tracks, ecal etc and also for the blocks that are created by the event block builder. ''' self.clusters = clusters # the merged clusters will be stored here self.merged = dict() # collate ids of clusters uniqueids = list(clusters.keys()) #make the edges match cpp by using the same approach as cpp edges = dict() for obj1 in clusters.values(): for obj2 in clusters.values(): if obj1.uniqueid < obj2.uniqueid : link_type, is_linked, distance = ruler(obj1, obj2) edge = Edge(obj1.uniqueid, obj2.uniqueid, is_linked, distance) #the edge object is added into the edges dictionary edges[edge.key] = edge #make the subgraphs of clusters super(MergedClusterBuilder, self).__init__(uniqueids, edges) #make sure we use the original history and update it as needed self.history_nodes = history_nodes self._make_merged_clusters()
def __init__(self, clusters, ruler, history_nodes): ''' @param clusters: a dictionary : {id1:ecal1, id2:ecal2, ...}. @param ruler: measures distance between two clusters, see Distance class for example. It should take the two objects as arguments and return a tuple of the form: link_type = 'ecal_ecal' is_link = true/false distance = float @param history_nodes: a dictionary of Nodes : { id:Node1, id: Node2 etc}. It could for example contain the simulation history nodes. A Node contains the id of a cluster. and says what it is linked to (its parents and children). New mergedcluster history detailing which clusters the mergedcluster was made from will be added to the existing history ''' self.clusters = clusters # the merged clusters will be stored here self.merged_clusters = dict() # collate ids of clusters uniqueids = list(clusters.keys()) #make the edges match cpp by using the same approach as cpp edges = dict() for obj1 in clusters.values(): for obj2 in clusters.values(): if obj1.uniqueid < obj2.uniqueid: link_type, is_linked, distance = ruler(obj1, obj2) edge = Edge(obj1.uniqueid, obj2.uniqueid, is_linked, distance) #the edge object is added into the edges dictionary edges[edge.key] = edge #make the subgraphs of clusters super(MergedClusterBuilder, self).__init__(uniqueids, edges) #make sure we use the original history and update it as needed self.history_nodes = history_nodes self._make_and_store_merged_clusters()