示例#1
0
    def __init__(self, cb_tree, digitizer, channel_map=chidonly_mapper):
        """
        Make the tree DAQ trees in the current file using the cowbells hits tree.

        The header/footer/data trees are available from .h/.f/.d members.
        """
        self.cb_tree = cb_tree
        self.digitizer = digitizer
        self.channel_map = channel_map

        self.h = ROOT.TTree("Header", "DAQ header from simulation")
        self.hobj = branch(self.h, **daq_Header)
        self.f = ROOT.TTree("Footer", "DAQ footer from simulation")
        self.fobj = branch(self.f, **daq_Footer)
        self.d = ROOT.TTree("FADCData", "DAQ FADC data from simulation")
        self.dobj = branch(self.d, **daq_FADCData)

        return
示例#2
0
    def __init__(self, tqtree, debug=False):
        self.tqtree = tqtree
        self.obj = branch(tqtree, **tq_desc)
        self.debug = debug
        if self.debug:
            self.canvas = ROOT.TCanvas("tqtree","tqtree debug", 0,0, 1000, 700)
        self.saved_peaks = []

        return
示例#3
0
def makeFontTree(font_list, matrix):
    print "making font tree from a list of", len(font_list)

    #initialize tree(s) for the shittiest agglomerative clustering algo ever written
    # (but in fairness, i ONLY have distances to work with -- not dimensions)
    trees = []
    for i, font in enumerate(font_list):
        l = tree.leaf()
        l.ptr = i
        trees.append(l)

    # find pairs of fonts in the matrix and cluster them until we have 1 tree left
    while 1 < len(trees):
        print "merges remaining", len(trees) - 1

        # find min font
        (f1, f2) = getMinFontDistance(matrix)
        if (-1, -1) == (f1, f2):
            print matrix

        #iterate through the other trees
        new_trees = []
        for i, t in enumerate(trees):
            if i == f1 or i == f2: continue
            new_trees.append(t)

        new_matrix = []
        #iterate through the rest of the matrix and add those rows here
        for i, r in enumerate(matrix):
            if i == f1 or i == f2: continue
            new_row = []
            for j, c in enumerate(matrix[i]):
                if j == f1 or j == f2: continue
                new_row.append(c)
            new_matrix.append(new_row)


        # create new branch
        t1 = trees[f1]
        t2 = trees[f2]
        br = tree.branch()
        br.set_branches(t1, t2)

        # add as last tree
        new_trees.append(br)


        #this code uses weighted averages to reconcile distances,
        # ... but doesn't produce great results
        """
        # calculate new row... last in the matrix, so the last row is 0
        new_row = []
        weight_t1 = t1.num_leaves()
        weight_t2 = t2.num_leaves()
        weight = weight_t1 + weight_t2
        for i, dist in enumerate(matrix[f1]):
            if i == f1 or i == f2: continue

            #is averaging a bad idea?  what about assuming a worst-case scenario?
            # i guess that would mean a huge pythagorean calculation... maybe later
            s1 = matrix[f1][i] * weight_t1
            s2 = matrix[f2][i] * weight_t2            avg_dist = (s1 + s2) / weight
            new_row.append(avg_dist)
            """

        # calculate new row... pythagorean distance
        new_row = []
        for i, dist in enumerate(matrix[f1]):
            if i == f1 or i == f2: continue

            s1 = matrix[f1][i]
            s2 = matrix[f2][i]
            pythag_dist = math.sqrt(s1**2 + s2**2)

            new_row.append(pythag_dist)


        new_row.append(0) #this is the last row, distance to self = 0
        new_matrix.append(new_row)



        #complete the last col of the matrix from the last row
        mylen = len(matrix[0])
        for i, dontcare in enumerate(new_matrix):
            if i < mylen - 2:
                new_matrix[i].append(new_row[i])

        #update vars
        trees = new_trees
        matrix = new_matrix

        #repeat until there is 1 left

    return trees[0]
示例#4
0
def makeFontTree(font_list, matrix):
    print "making font tree from a list of", len(font_list)

    #initialize tree(s) for the shittiest agglomerative clustering algo ever written
    # (but in fairness, i ONLY have distances to work with -- not dimensions)
    trees = []
    for i, font in enumerate(font_list):
        l = tree.leaf()
        l.ptr = i
        trees.append(l)

    # find pairs of fonts in the matrix and cluster them until we have 1 tree left
    while 1 < len(trees):
        print "merges remaining", len(trees) - 1

        # find min font
        (f1, f2) = getMinFontDistance(matrix)
        if (-1, -1) == (f1, f2):
            print matrix

        #iterate through the other trees
        new_trees = []
        for i, t in enumerate(trees):
            if i == f1 or i == f2: continue
            new_trees.append(t)

        new_matrix = []
        #iterate through the rest of the matrix and add those rows here
        for i, r in enumerate(matrix):
            if i == f1 or i == f2: continue
            new_row = []
            for j, c in enumerate(matrix[i]):
                if j == f1 or j == f2: continue
                new_row.append(c)
            new_matrix.append(new_row)

        # create new branch
        t1 = trees[f1]
        t2 = trees[f2]
        br = tree.branch()
        br.set_branches(t1, t2)

        # add as last tree
        new_trees.append(br)

        #this code uses weighted averages to reconcile distances,
        # ... but doesn't produce great results
        """
        # calculate new row... last in the matrix, so the last row is 0
        new_row = []
        weight_t1 = t1.num_leaves()
        weight_t2 = t2.num_leaves()
        weight = weight_t1 + weight_t2
        for i, dist in enumerate(matrix[f1]):
            if i == f1 or i == f2: continue

            #is averaging a bad idea?  what about assuming a worst-case scenario?
            # i guess that would mean a huge pythagorean calculation... maybe later
            s1 = matrix[f1][i] * weight_t1
            s2 = matrix[f2][i] * weight_t2            avg_dist = (s1 + s2) / weight
            new_row.append(avg_dist)
            """

        # calculate new row... pythagorean distance
        new_row = []
        for i, dist in enumerate(matrix[f1]):
            if i == f1 or i == f2: continue

            s1 = matrix[f1][i]
            s2 = matrix[f2][i]
            pythag_dist = math.sqrt(s1**2 + s2**2)

            new_row.append(pythag_dist)

        new_row.append(0)  #this is the last row, distance to self = 0
        new_matrix.append(new_row)

        #complete the last col of the matrix from the last row
        mylen = len(matrix[0])
        for i, dontcare in enumerate(new_matrix):
            if i < mylen - 2:
                new_matrix[i].append(new_row[i])

        #update vars
        trees = new_trees
        matrix = new_matrix

        #repeat until there is 1 left

    return trees[0]