Ejemplo n.º 1
0
 def _graph_add_topological_block(self, graph, graphnodes, pfblock):
     '''this adds the block links (distance, is_linked) onto the DAG in red'''
     for edge in pfblock.edges.itervalues():
         if  edge.linked: 
             label = "{:.1E}".format(edge.distance)
             if edge.distance == 0:
                 label = "0"
             graph.add_edge(pydot.Edge(graphnodes[IdCoder.pretty(edge.id1)],
                                       graphnodes[IdCoder.pretty(edge.id2)],
                                       label=label, style="dashed", color="red", arrowhead="none", arrowtail="none", fontsize='7'))
Ejemplo n.º 2
0
    def short_elements_string(self):
        ''' Construct a string description of each of the elements in a block.

        The elements are given a short name E/H/T according to ecal/hcal/track
        and then sequential numbering starting from 0, this naming is also used to index the
        matrix of distances. The full unique id is also given.
        For example:-
        elements: {
        E0:1104134446736:SmearedCluster : ecal_in       0.57  0.33 -2.78
        H1:2203643940048:SmearedCluster : hcal_in       6.78  0.35 -2.86
        T2:3303155568016:SmearedTrack   :    5.23    4.92  0.34 -2.63
        }
        '''

        count = 0
        elemdetails = "    elements:\n"
        for uid in self.element_uniqueids:
            elemdetails += "{shortname:>7}{count} = {strdescrip:9} value={val:5.1f} ({uid})\n".format(
                shortname=IdCoder.type_letter(uid),
                count=count,
                strdescrip=IdCoder.pretty(uid),
                val=IdCoder.get_value(uid),
                uid=uid)
            count = count + 1
        return elemdetails
Ejemplo n.º 3
0
 def _graph_add_topological_block(self, graph, graphnodes, pfblock):
     '''this adds the block links (distance, is_linked) onto the DAG in red'''
     for edge in pfblock.edges.itervalues():
         if edge.linked:
             label = "{:.1E}".format(edge.distance)
             if edge.distance == 0:
                 label = "0"
             graph.add_edge(
                 pydot.Edge(graphnodes[IdCoder.pretty(edge.id1)],
                            graphnodes[IdCoder.pretty(edge.id2)],
                            label=label,
                            style="dashed",
                            color="red",
                            arrowhead="none",
                            arrowtail="none",
                            fontsize='7'))
Ejemplo n.º 4
0
    def short_elements_string(self):
        ''' Construct a string description of each of the elements in a block.

        The elements are given a short name E/H/T according to ecal/hcal/track
        and then sequential numbering starting from 0, this naming is also used to index the
        matrix of distances. The full unique id is also given.
        For example:-
        elements: {
        E0:1104134446736:SmearedCluster : ecal_in       0.57  0.33 -2.78
        H1:2203643940048:SmearedCluster : hcal_in       6.78  0.35 -2.86
        T2:3303155568016:SmearedTrack   :    5.23    4.92  0.34 -2.63
        }
        '''

        count = 0
        elemdetails = "    elements:\n"
        for uid in self.element_uniqueids:
            elemdetails += "{shortname:>7}{count} = {strdescrip:9} value={val:5.1f} ({uid})\n".format(
                shortname=IdCoder.type_letter(uid),
                count=count,
                strdescrip=IdCoder.pretty(uid),
                val=IdCoder.get_value(uid),
                uid=uid)
            count = count + 1
        return elemdetails
Ejemplo n.º 5
0
 def id_from_pretty(self, pretty):
     ''' Searches to find the true id given a pretty id string
         Not super efficient but OK for occasional use
         eg uid = self.id_from_pretty('et103')
         @param: pretty is the easily readable name from the Identifier class which is shown in prints and plots eg 'et103'
     '''
     for uid in self.history.keys():
         if IdCoder.pretty(uid) == pretty:
             return uid
     return None
Ejemplo n.º 6
0
 def info(self):
     subclusterstr = str('sub(')
     for s in self.subclusters:
         subclusterstr += str('{:}, '.format(IdCoder.pretty(s.uniqueid)))
     subclusterstr += ")"
     return '{energy:7.2f} {theta:5.2f} {phi:5.2f} {sub}'.format(
         energy=self.energy,
         theta=math.pi / 2. - self.position.Theta(),
         phi=self.position.Phi(),
         sub=subclusterstr)
Ejemplo n.º 7
0
 def id_from_pretty(self, pretty):
     ''' Searches to find the true id given a pretty id string
         Not super efficient but OK for occasional use
         eg uid = self.id_from_pretty('et103')
         @param: pretty is the easily readable name from the Identifier class which is shown in prints and plots eg 'et103'
     '''
     for uid in self.history.keys():
         if IdCoder.pretty(uid) == pretty:
             return uid
     return None
Ejemplo n.º 8
0
 def info(self):
     subclusterstr = str('sub(')
     for s in self.subclusters:
         subclusterstr += str('{:}, '.format(IdCoder.pretty(s.uniqueid)))
     subclusterstr += ")"
     return '{energy:7.2f} {theta:5.2f} {phi:5.2f} {sub}'.format(
         energy=self.energy,
         theta=math.pi/2. - self.position.Theta(),
         phi=self.position.Phi(),
         sub=subclusterstr
     )
Ejemplo n.º 9
0
 def __repr__(self):
     ''' Short Block description
     '''
     description = "block:"
     description += str('{shortname:8} :{prettyid:6}: ecals = {count_ecal} hcals = {count_hcal} tracks = {count_tracks}'.format(
         shortname=self.short_info(),
         prettyid=IdCoder.pretty(self.uniqueid),
         count_ecal=self.count_ecal(),
         count_hcal=self.count_hcal(),
         count_tracks=self.count_tracks())
                       )
     return description
Ejemplo n.º 10
0
 def __repr__(self):
     ''' Short Block description
     '''
     description = "block:"
     description += str(
         '{shortname:8} :{prettyid:6}: ecals = {count_ecal} hcals = {count_hcal} tracks = {count_tracks}'
         .format(shortname=self.short_info(),
                 prettyid=IdCoder.pretty(self.uniqueid),
                 count_ecal=self.count_ecal(),
                 count_hcal=self.count_hcal(),
                 count_tracks=self.count_tracks()))
     return description
Ejemplo n.º 11
0
    def test_papasevent(self):
        papasevent = PapasEvent(0)
        ecals = dict()
        tracks = dict()
        mixed = dict()

        for i in range(0, 2):
            uid = IdCoder.make_id(IdCoder.PFOBJECTTYPE.ECALCLUSTER, i, 't',
                                  4.5)
            ecals[uid] = uid
        for i in range(0, 2):
            uid = IdCoder.make_id(IdCoder.PFOBJECTTYPE.TRACK, i, 's', 4.5)
            tracks[uid] = uid

        lastid = IdCoder.make_id(IdCoder.PFOBJECTTYPE.ECALCLUSTER, 3, 't', 3)
        ecals[lastid] = lastid

        papasevent.add_collection(ecals)
        papasevent.add_collection(tracks)

        #check that adding the same collection twice fails
        self.assertRaises(ValueError, papasevent.add_collection, ecals)

        #check that adding a mixed collection fails
        mixed = ecals.copy()
        mixed.update(tracks)
        self.assertRaises(ValueError, papasevent.add_collection, mixed)

        #get we can get back collections OK
        self.assertTrue(len(
            papasevent.get_collection('zz')) == 0)  # this one does not exist
        self.assertTrue(len(papasevent.get_collection('et')) == 3)

        #check get_object
        self.assertTrue(IdCoder.pretty(papasevent.get_object(lastid)) == 'et3')
        self.assertTrue(papasevent.get_object(499) is None)
Ejemplo n.º 12
0
 def __str__(self):
     return '{classname}: {pretty:6}:{uid}: {info}'.format(
         classname=self.__class__.__name__,
         pretty=IdCoder.pretty(self.uniqueid),
         uid=self.uniqueid,
         info=self.info())
Ejemplo n.º 13
0
 def short_info(self, node):
     '''used to label plotted dag nodes
     @param node: a node in the DAG history'''
     obj = self.object(node)
     return IdCoder.pretty(obj.uniqueid) + "\n " +obj.short_info()        
Ejemplo n.º 14
0
 def short_info(self, node):
     '''used to label plotted dag nodes
     @param node: a node in the DAG history'''
     obj = self.object(node)
     return IdCoder.pretty(obj.uniqueid) + "\n " + obj.short_info()
Ejemplo n.º 15
0
 def pretty(self, node):
     ''' pretty form of the unique identifier
     @param node: a node in the DAG history'''
     return IdCoder.pretty(node.get_value())
Ejemplo n.º 16
0
 def pretty(self, node):
     ''' pretty form of the unique identifier
     @param node: a node in the DAG history'''
     return IdCoder.pretty(node.get_value())
Ejemplo n.º 17
0
 def __str__(self):
     return '{classname}: {pretty:6}:{uid}: {info}'.format(
         classname=self.__class__.__name__,
         pretty=IdCoder.pretty(self.uniqueid),
         uid=self.uniqueid,
         info=self.info())