Пример #1
0
 def remove_doubles(group, tree, only_1cluster=False):
     """ find the tracks which are closer to the cluster in case there are more than 1 track per cluster. """
     s = array(group['Clusters']['Size'])
     cut = s > 0
     nt = get_tree_vec(tree, var='evt_ntracks', dtype='u1')[cut]      # number of tracks
     nc = get_tree_vec(tree, var='evt_nclusters', dtype='u1')[cut]    # number of clusters
     tu, tv = array(group['Tracks']['U'])[cut], array(group['Tracks']['V'])[cut]
     u, v = array(group['Clusters']['U']), array(group['Clusters']['V'])
     r = sqrt((tu - u) ** 2 + (tv - v) ** 2)
     good = nt == 1
     c2 = (nt > 1) & (nc == 2)  # selector for one cluster for two tracks, if nc == 2 and nt > 1 there is always a double
     r2 = r[c2][::2] < r[c2][1::2]
     r2c = concatenate(array([r2, invert(r2)]).T)  # merge with zipper method
     good[c2] = r2c
     # more than 1 cluster
     if not only_1cluster:
         for nt_i in arange(2, 5):
             for nc_i in arange(4, 7, 2):
                 c = (nt == nt_i) & (nc == nc_i)
                 ri = array(split(r[c], arange(nt_i, r[c].size, nt_i)))
                 good[c] = concatenate(ri) == min(ri, axis=1).repeat(nt_i)
     # write changes to the file
     s0 = s[cut]
     s0[invert(good)] = 0
     s[cut] = s0  # set all sizes of the removed clusters to 0
     group['Clusters']['Size'][...] = s
     for name in ['U', 'V', 'X', 'Y', 'Charge']:
         data = array(group['Clusters'][name])[good]
         del group['Clusters'][name]
         group['Clusters'].create_dataset(name, data=data)
Пример #2
0
    def add_clusters(self, group, tree):
        gr = group.create_group('Clusters')

        # tracking
        t = self.TrackFile.Get(group.name.strip('/')).Get('Clusters')
        t.SetEstimate(-1)
        gr.create_dataset('N', data=get_tree_vec(t, 'NClusters', dtype='u1'))

        # matching
        branches = [f'clu_{n}' for n in ['size', 'col', 'row', 'u', 'v']]
        data = get_tree_vec(tree, branches, dtype=['u2'] + ['f2'] * len(branches))
        cluster_size = data[0]
        gr.create_dataset('Size', data=cluster_size)
        for i, name in enumerate(['X', 'Y', 'U', 'V'], 1):
            gr.create_dataset(name, data=data[i][cluster_size > 0])  # filter out the nan events
Пример #3
0
 def add_trigger_info(self, group):
     f = TFile(self.ROOTFileName)
     tree = f.Get(group.name.strip('/')).Get('Hits')
     tree.SetEstimate(tree.GetEntries())
     data = get_tree_vec(tree, ['TriggerPhase', 'TriggerCount'], dtype='u1')
     for i, name in enumerate(['TriggerPhase', 'TriggerCount']):
         group.create_dataset(name, data=data[i])
Пример #4
0
 def get_hits(self, match_tree, group, dut_nr):
     t = info('getting hit charges for DUT Plane {} ...'.format(dut_nr), endl=False)
     calibration = self.get_calibration(dut_nr)
     x, y, adc = get_tree_vec(match_tree, ['hit_col', 'hit_row', 'hit_value'], dtype=['u2', 'u2', 'u1'])
     hits = array([x, y, calibration(x, y, adc)]).T
     group.create_dataset('CalChiSquare', data=calibration.get_chi2s())
     add_to_info(t)
     return hits
Пример #5
0
    def add_track_vars(self):
        info('add track information ...')
        g = self.F.create_group('Tracks')

        track_types = {'Chi2': 'f2', 'Dof': 'u1', 'X': 'f2', 'Y': 'f2', 'SlopeX': 'f2', 'SlopeY': 'f2'}
        match_types = {'evt_frame': 'u4', 'evt_ntracks': 'u1', 'trk_size': 'f2'}
        self.PBar.start(len(track_types) + len(match_types), counter=True, t='s')

        # from tracking tree
        t_tree = self.TrackFile.Get('Tracks')
        t_tree.SetEstimate(t_tree.GetEntries())
        g.create_dataset('NTracks', data=get_tree_vec(t_tree, var='NTracks', dtype='u1'))
        t_tree.SetEstimate(sum(g['NTracks']))
        for n, t in track_types.items():
            g.create_dataset(n, data=get_tree_vec(t_tree, n, dtype=t))
            self.PBar.update()

        # from match tree
        m_tree = self.MatchFile.Get('C0').Get('tracks_clusters_matched')  # same for all plane dirs
        m_tree.SetEstimate(m_tree.GetEntries())
        for n, t in match_types.items():
            g.create_dataset(n.replace('trk_', '').title().replace('_', ''), data=get_tree_vec(m_tree, n, dtype=t))
            self.PBar.update()
Пример #6
0
    def add_plane(self, i):
        group = self.F.create_group(f'Plane{i}')
        i_dut = i - self.NTelPlanes
        pl_tag = f'C{i_dut}' if i_dut >= 0 else f'M{i}'

        # mask
        m_tree = self.MatchFile.Get(pl_tag).Get('masked_pixels')
        m_tree.SetEstimate(m_tree.GetEntries())
        group.create_dataset('Mask', data=get_tree_vec(m_tree, ['col', 'row'], dtype='u2'))

        # cluster
        tree = self.MatchFile.Get(pl_tag).Get('tracks_clusters_matched')
        tree.SetEstimate(-1)
        self.add_tracks(group, tree)
        self.add_clusters(group, tree)
        if i_dut >= 0:
            self.add_cluster_charge(tree, group, i_dut)
            self.remove_doubles(group, tree)

            # trigger info
            self.add_trigger_info(group)
Пример #7
0
 def add_tracks(self, group, tree):
     gr = group.create_group('Tracks')
     data = get_tree_vec(tree, [f'trk_{n}' for n in ['u', 'v', 'col', 'row', 'du', 'dv']], dtype='f2')
     for i, name in enumerate(['U', 'V', 'X', 'Y', 'dU', 'dV']):
         gr.create_dataset(name, data=data[i])
Пример #8
0
 def add_time_stamp(self):
     tree = self.TrackFile.Get('Event')
     tree.SetEstimate(tree.GetEntries())
     t_vec = get_tree_vec(self.TrackFile.Get('Event'), var='TriggerTime', dtype='u8')
     g = self.F.create_group('Event')
     g.create_dataset('Time', data=((t_vec - t_vec[0]) / 1e9).astype('f4'))  # convert time vec to seconds
Пример #9
0
 def make_cuts(self):
     [t.SetEstimate(t.GetEntries() * 10) for t in self.P]
     n = [get_tree_vec(t, 'NHits', dtype='i2') for t in self.P[:6]]
     c = all([i == 1 for i in n], axis=0)
     return [c.repeat(i) for i in n]