Exemple #1
0
    def _edge_type(self):
        ''' produces an edge_type string eg "ecal_track"
            the order of id1 an id2 does not matter, 
            eg for one track and one ecal the type will always be "ecal_track" (and never be a "track_ecal")         
        '''
        #consider creating an ENUM instead for the edge_type
        shortid1 = IdCoder.type_letter(self.id1)
        shortid2 = IdCoder.type_letter(self.id2)
        if shortid1 == shortid2:
            if shortid1 == "h":
                return "hcal_hcal"
            elif shortid1 == "e":
                return "ecal_ecal"
            elif shortid1 == "t":
                return "track_track"
        elif (shortid1 == "h" and shortid2 == "t"
              or shortid1 == "t" and shortid2 == "h"):
            return "hcal_track"
        elif (shortid1 == "e" and shortid2 == "t"
              or shortid1 == "t" and shortid2 == "e"):
            return "ecal_track"
        elif (shortid1 == "e" and shortid2 == "h"
              or shortid1 == "h" and shortid2 == "e"):
            return "ecal_hcal"

        return "unknown"
Exemple #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
Exemple #3
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
Exemple #4
0
    def edge_matrix_string(self):
        ''' produces a string containing the the lower part of the matrix of distances between elements
        elements are ordered as ECAL(E), HCAL(H), Track(T)
        for example:-

        distances:
                  E0       H1       T2       T3
         E0       .
         H1  0.0267        .
         T2  0.0000   0.0000        .
         T3  0.0287   0.0825      ---        .
         '''

        # make the header line for the matrix
        count = 0
        matrixstr = ""
        if len(self.element_uniqueids) > 1:
            matrixstr = "    distances:\n        "
            for e1 in self.element_uniqueids:
                # will produce short id of form E2 H3, T4 etc in tidy format
                elemstr = IdCoder.type_letter(e1) + str(count)
                matrixstr += "{:>8}".format(elemstr)
                count += 1
            matrixstr += "\n"

            #for each element find distances to all other items that are in the lower part of the matrix
            countrow = 0
            for e1 in self.element_uniqueids:  # this will be the rows
                countcol = 0
                rowstr = ""
                #make short name for the row element eg E3, H5 etc
                rowname = IdCoder.type_letter(e1) + str(countrow)
                for e2 in self.element_uniqueids:  # these will be the columns
                    countcol += 1
                    if e1 == e2:
                        rowstr += "       ."
                        break
                    elif self.get_edge(e1, e2).distance is None:
                        rowstr += "     ---"
                    elif not self.get_edge(e1, e2).linked:
                        rowstr += "     ---"
                    else:
                        rowstr += "{:8.4f}".format(
                            self.get_edge(e1, e2).distance)
                matrixstr += "{:>8}".format(rowname) + rowstr + "\n"
                countrow += 1
        return matrixstr
Exemple #5
0
    def edge_matrix_string(self):
        ''' produces a string containing the the lower part of the matrix of distances between elements
        elements are ordered as ECAL(E), HCAL(H), Track(T)
        for example:-

        distances:
                  E0       H1       T2       T3
         E0       .
         H1  0.0267        .
         T2  0.0000   0.0000        .
         T3  0.0287   0.0825      ---        .
         '''

        # make the header line for the matrix
        count = 0
        matrixstr = ""
        if len(self.element_uniqueids) > 1:
            matrixstr = "    distances:\n        "
            for e1 in self.element_uniqueids :
                # will produce short id of form E2 H3, T4 etc in tidy format
                elemstr = IdCoder.type_letter(e1) + str(count)
                matrixstr += "{:>8}".format(elemstr)
                count += 1
            matrixstr += "\n"

            #for each element find distances to all other items that are in the lower part of the matrix
            countrow = 0
            for e1 in self.element_uniqueids : # this will be the rows
                countcol = 0
                rowstr = ""
                #make short name for the row element eg E3, H5 etc
                rowname = IdCoder.type_letter(e1) +str(countrow)
                for e2 in self.element_uniqueids:  # these will be the columns
                    countcol += 1
                    if e1 == e2:
                        rowstr += "       ."
                        break
                    elif self.get_edge(e1, e2).distance is None:
                        rowstr += "     ---"
                    elif not self.get_edge(e1, e2).linked:
                        rowstr += "     ---"
                    else :
                        rowstr += "{:8.4f}".format(self.get_edge(e1, e2).distance)
                matrixstr += "{:>8}".format(rowname) + rowstr + "\n"
                countrow += 1
        return matrixstr
Exemple #6
0
 def _edge_type(self):
     ''' produces an edge_type string eg "ecal_track"
         the order of id1 an id2 does not matter, 
         eg for one track and one ecal the type will always be "ecal_track" (and never be a "track_ecal")         
     '''
     #consider creating an ENUM instead for the edge_type
     shortid1=IdCoder.type_letter(self.id1);
     shortid2=IdCoder.type_letter(self.id2);
     if shortid1 == shortid2:
         if shortid1 == "h":
             return "hcal_hcal"
         elif shortid1 == "e":
             return "ecal_ecal"
         elif shortid1 == "t":
             return "track_track"           
     elif (shortid1=="h" and shortid2=="t" or shortid1=="t" and shortid2=="h"):
         return "hcal_track"
     elif (shortid1=="e" and shortid2=="t" or shortid1=="t" and shortid2=="e"):
         return "ecal_track"  
     elif (shortid1=="e" and shortid2=="h" or shortid1=="h" and shortid2=="e"):
         return "ecal_hcal"  
     
     return "unknown"