Exemplo n.º 1
0
 def analyze(self):
     h5_filename = self.output_filename +'.h5'
     
     with tb.open_file(h5_filename, 'r+') as in_file_h5:
         raw_data = in_file_h5.root.raw_data[:]
         meta_data = in_file_h5.root.meta_data[:]
         
         hit_data = self.dut.interpret_raw_data(raw_data, meta_data)
         in_file_h5.createTable(in_file_h5.root, 'hit_data', hit_data, filters=self.filter_tables)
        
     status_plot = plotting.plot_status(h5_filename)
     occ_plot, H = plotting.plot_occupancy(h5_filename)
     tot_plot,_ = plotting.plot_tot_dist(h5_filename)
     lv1id_plot, _ = plotting.plot_lv1id_dist(h5_filename)
     scan_pix_hist, _ = plotting.scan_pix_hist(h5_filename)                   
              
     output_file(self.output_filename + '.html', title=self.run_name)
     save(vplot(hplot(occ_plot, tot_plot, lv1id_plot), scan_pix_hist, status_plot))
Exemplo n.º 2
0
 def tdc_table(self, scanrange):
     h5_filename = self.output_filename + '.h5'
     with tb.open_file(h5_filename, 'r+') as in_file_h5:
         raw_data = in_file_h5.root.raw_data[:]
         meta_data = in_file_h5.root.meta_data[:]
         if (meta_data.shape[0] == 0): return
         repeat_command = in_file_h5.root.meta_data.attrs.kwargs
         a = repeat_command.rfind("repeat_command: ")
         repeat_command = repeat_command[a + len("repeat_command: "):a + len("repeat_command: ") + 7]
         a = repeat_command.rfind("\n")
         repeat_command = int(repeat_command[0:a])
         param, index = np.unique(meta_data['scan_param_id'], return_index=True)
         pxl_list = []
         for p in param:
             pix_no = int(p) / int(len(self.inj_charge))
             pxl_list.append(self.pixel_list[pix_no][0] * 64 + self.pixel_list[pix_no][1])
         index = index[1:]
         index = np.append(index, meta_data.shape[0])
         index = index - 1
         stops = meta_data['index_stop'][index]
         split = np.split(raw_data, stops)
         avg_tdc = []
         avg_tdc_err = []
         avg_del = []
         avg_del_err = []
         hits = []
         deletelist = ()
         for i in range(len(split[:-1])):  # loop on pulses
             rwa_data_param = split[i]
             tdc_data = rwa_data_param & 0xFFF  # take last 12 bit
             tdc_delay = (rwa_data_param & 0x0FF00000) >> 20
             counter = 0.0
             TOT_sum = 0.0
             DEL_sum = 0.0
             if (tdc_data.shape[0] == 0 or tdc_data.shape[0] == 1):
                 counter = 1.0
             for j in range(tdc_data.shape[0]):  # loop on repeats
                 if (j > 0):
                     counter += 1
                     TOT_sum += tdc_data[j]
                     DEL_sum += tdc_delay[j]
             if (counter > 1):
                 hits.append(counter)
                 avg_tdc.append((float(TOT_sum) / float(counter)) * 1.5625)
                 avg_tdc_err.append(1.5625 / (np.sqrt(12.0 * counter)))
                 avg_del.append((float(DEL_sum) / float(counter)) * 1.5625)
                 avg_del_err.append(1.5625 / (np.sqrt(12.0 * counter)))
             else:
                 deletelist = np.append(deletelist, i)
         pxl_list = np.delete(pxl_list, deletelist)
         newpix = [0]
         pix_no_old = pxl_list[0]
         runparam = 0
         for p in pxl_list:
             if p != pix_no_old:
                 newpix = np.append(newpix, runparam)
             pix_no_old = p
             runparam = runparam + 1
             addedvalues = 0
         for pixels in range(len(newpix)):
             missingvalues = 0
             if newpix[pixels] == newpix[-1]:
                 missingvalues = scanrange - abs(newpix[pixels] + addedvalues - len(hits))
             else:
                 if abs(newpix[pixels] - newpix[pixels + 1]) < scanrange:
                     missingvalues = scanrange - abs(newpix[pixels] - newpix[pixels + 1])
             if missingvalues != 0:
                 hits = np.insert(hits, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 avg_tdc = np.insert(avg_tdc, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 avg_tdc_err = np.insert(avg_tdc_err, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 avg_del = np.insert(avg_del, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 avg_del_err = np.insert(avg_del_err, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 pxl_list = np.insert(pxl_list, newpix[pixels] + addedvalues,
                                      (pxl_list[newpix[pixels] + addedvalues]) * np.ones(missingvalues))
             addedvalues = addedvalues + missingvalues
         injections = []
         for pixels in range(int(len(pxl_list) / len(self.inj_charge))):
             for i in range(len(self.inj_charge)):
                 injections = np.append(injections, self.inj_charge[i])
         pix, stop = np.unique(pxl_list, return_index=True)
         stop = np.sort(stop)
         stop = list(stop)
         stop.append(len(avg_tdc))
         repeat_command_dic={}
         repeat_command_dic['repeat_command']=repeat_command
         avg_tab = np.rec.fromarrays([injections, pxl_list, hits, avg_tdc, avg_tdc_err, avg_del, avg_del_err],
                                     dtype=[('charge', float), ('pixel_no', int), ('hits', int),
                                            ('tot_ns', float), ('err_tot_ns', float), ('delay_ns', float),
                                            ('err_delay_ns', float)])
         tdc_table=in_file_h5.createTable(in_file_h5.root, 'tdc_data', avg_tab, filters=self.filter_tables)
         tdc_table.attrs.repeat_command = repeat_command_dic
         thresholds = ()
         expfit0 = ()
         expfit1 = ()
         expfit2 = ()
         expfit3 = ()
         pixels = ()
         for i in range(len(stop) - 1):
             s1 = int(stop[i])
             s2 = int(stop[i + 1])
             A, mu, sigma = analysis.fit_scurve(hits[s1:s2], injections[s1:s2],repeat_command)
             if np.max(hits[s1:s2]) > (repeat_command + 200):  # or mu > 3000:
                 thresholds = np.append(thresholds, 0)
                 expfit0 = np.append(expfit0, 0)
                 expfit1 = np.append(expfit1, 0)
                 expfit2 = np.append(expfit2, 0)
                 expfit3 = np.append(expfit3, 0)
                 pixels = np.append(pixels, pxl_list[s1])
                 continue
             for values in range(s1, s2):
                 if injections[values] >= 5 / 4 * mu:
                     s1 = values
                     break
             numberer = 0
             hitvaluesold = hits[-1]
             for hitvalues in hits[s1:s2]:
                 if abs(hitvalues - hitvaluesold) <= 1 and hitvalues != 0:
                     break
                 numberer = numberer + 1
                 hitvaluesold = hitvalues
             if numberer == len(avg_del[s1:s2]):
                 numberer = 0
             expfit = analysis.fit_exp(injections[s1:s2], avg_del[s1:s2], mu, abs(numberer))
             startexp = -expfit[0] * np.log((25.0 + np.min(avg_del[s1:s2]) - expfit[3]) / expfit[2]) - expfit[1]
             if np.isnan(startexp) or startexp >= 2000:
                 startexp = 0
             thresholds = np.append(thresholds, startexp)
             expfit0 = np.append(expfit0, expfit[0])
             expfit1 = np.append(expfit1, expfit[1])
             expfit2 = np.append(expfit2, expfit[2])
             expfit3 = np.append(expfit3, expfit[3])
             pixels = np.append(pixels, pxl_list[s1])
         thresh = np.rec.fromarrays([pixels, thresholds, expfit0, expfit1, expfit2, expfit3],
                                    dtype=[('pixel_no', int), ('td_threshold', float),
                                           ('expfit0', float), ('expfit1', float), ('expfit2', float),
                                           ('expfit3', float)])
         in_file_h5.createTable(in_file_h5.root, 'td_threshold', thresh, filters=self.filter_tables)
     p1, p2, single_scan = plotting.plot_timewalk(h5_filename)
     output_file(self.output_filename + '.html', title=self.run_name)
     status = plotting.plot_status(h5_filename)
     save(hplot(vplot(p1, p2, status), single_scan))
Exemplo n.º 3
0
 def tdc_table(self, scanrange):
     h5_filename = self.output_filename + '.h5'
     with tb.open_file(h5_filename, 'r+') as in_file_h5:
         raw_data = in_file_h5.root.raw_data[:]
         meta_data = in_file_h5.root.meta_data[:]
         if (meta_data.shape[0] == 0): return
         repeat_command = in_file_h5.root.meta_data.attrs.kwargs
         a = repeat_command.rfind("repeat_command: ")
         repeat_command = repeat_command[a + len("repeat_command: "):a +
                                         len("repeat_command: ") + 7]
         a = repeat_command.rfind("\n")
         repeat_command = int(repeat_command[0:a])
         param, index = np.unique(meta_data['scan_param_id'],
                                  return_index=True)
         pxl_list = []
         for p in param:
             pix_no = int(p) / int(len(self.inj_charge))
             pxl_list.append(self.pixel_list[pix_no][0] * 64 +
                             self.pixel_list[pix_no][1])
         index = index[1:]
         index = np.append(index, meta_data.shape[0])
         index = index - 1
         stops = meta_data['index_stop'][index]
         split = np.split(raw_data, stops)
         avg_tdc = []
         avg_tdc_err = []
         avg_del = []
         avg_del_err = []
         hits = []
         deletelist = ()
         for i in range(len(split[:-1])):  # loop on pulses
             rwa_data_param = split[i]
             tdc_data = rwa_data_param & 0xFFF  # take last 12 bit
             tdc_delay = (rwa_data_param & 0x0FF00000) >> 20
             counter = 0.0
             TOT_sum = 0.0
             DEL_sum = 0.0
             if (tdc_data.shape[0] == 0 or tdc_data.shape[0] == 1):
                 counter = 1.0
             for j in range(tdc_data.shape[0]):  # loop on repeats
                 if (j > 0):
                     counter += 1
                     TOT_sum += tdc_data[j]
                     DEL_sum += tdc_delay[j]
             if (counter > 1):
                 hits.append(counter)
                 avg_tdc.append((float(TOT_sum) / float(counter)) * 1.5625)
                 avg_tdc_err.append(1.5625 / (np.sqrt(12.0 * counter)))
                 avg_del.append((float(DEL_sum) / float(counter)) * 1.5625)
                 avg_del_err.append(1.5625 / (np.sqrt(12.0 * counter)))
             else:
                 deletelist = np.append(deletelist, i)
         pxl_list = np.delete(pxl_list, deletelist)
         newpix = [0]
         pix_no_old = pxl_list[0]
         runparam = 0
         for p in pxl_list:
             if p != pix_no_old:
                 newpix = np.append(newpix, runparam)
             pix_no_old = p
             runparam = runparam + 1
             addedvalues = 0
         for pixels in range(len(newpix)):
             missingvalues = 0
             if newpix[pixels] == newpix[-1]:
                 missingvalues = scanrange - abs(newpix[pixels] +
                                                 addedvalues - len(hits))
             else:
                 if abs(newpix[pixels] - newpix[pixels + 1]) < scanrange:
                     missingvalues = scanrange - abs(newpix[pixels] -
                                                     newpix[pixels + 1])
             if missingvalues != 0:
                 hits = np.insert(hits, newpix[pixels] + addedvalues,
                                  np.zeros(missingvalues))
                 avg_tdc = np.insert(avg_tdc, newpix[pixels] + addedvalues,
                                     np.zeros(missingvalues))
                 avg_tdc_err = np.insert(avg_tdc_err,
                                         newpix[pixels] + addedvalues,
                                         np.zeros(missingvalues))
                 avg_del = np.insert(avg_del, newpix[pixels] + addedvalues,
                                     np.zeros(missingvalues))
                 avg_del_err = np.insert(avg_del_err,
                                         newpix[pixels] + addedvalues,
                                         np.zeros(missingvalues))
                 pxl_list = np.insert(
                     pxl_list, newpix[pixels] + addedvalues,
                     (pxl_list[newpix[pixels] + addedvalues]) *
                     np.ones(missingvalues))
             addedvalues = addedvalues + missingvalues
         injections = []
         for pixels in range(int(len(pxl_list) / len(self.inj_charge))):
             for i in range(len(self.inj_charge)):
                 injections = np.append(injections, self.inj_charge[i])
         pix, stop = np.unique(pxl_list, return_index=True)
         stop = np.sort(stop)
         stop = list(stop)
         stop.append(len(avg_tdc))
         repeat_command_dic = {}
         repeat_command_dic['repeat_command'] = repeat_command
         avg_tab = np.rec.fromarrays([
             injections, pxl_list, hits, avg_tdc, avg_tdc_err, avg_del,
             avg_del_err
         ],
                                     dtype=[('charge', float),
                                            ('pixel_no', int),
                                            ('hits', int),
                                            ('tot_ns', float),
                                            ('err_tot_ns', float),
                                            ('delay_ns', float),
                                            ('err_delay_ns', float)])
         tdc_table = in_file_h5.createTable(in_file_h5.root,
                                            'tdc_data',
                                            avg_tab,
                                            filters=self.filter_tables)
         tdc_table.attrs.repeat_command = repeat_command_dic
         thresholds = ()
         expfit0 = ()
         expfit1 = ()
         expfit2 = ()
         expfit3 = ()
         pixels = ()
         for i in range(len(stop) - 1):
             s1 = int(stop[i])
             s2 = int(stop[i + 1])
             A, mu, sigma = analysis.fit_scurve(hits[s1:s2],
                                                injections[s1:s2],
                                                repeat_command)
             if np.max(
                     hits[s1:s2]) > (repeat_command + 200):  # or mu > 3000:
                 thresholds = np.append(thresholds, 0)
                 expfit0 = np.append(expfit0, 0)
                 expfit1 = np.append(expfit1, 0)
                 expfit2 = np.append(expfit2, 0)
                 expfit3 = np.append(expfit3, 0)
                 pixels = np.append(pixels, pxl_list[s1])
                 continue
             for values in range(s1, s2):
                 if injections[values] >= 5 / 4 * mu:
                     s1 = values
                     break
             numberer = 0
             hitvaluesold = hits[-1]
             for hitvalues in hits[s1:s2]:
                 if abs(hitvalues - hitvaluesold) <= 1 and hitvalues != 0:
                     break
                 numberer = numberer + 1
                 hitvaluesold = hitvalues
             if numberer == len(avg_del[s1:s2]):
                 numberer = 0
             expfit = analysis.fit_exp(injections[s1:s2], avg_del[s1:s2],
                                       mu, abs(numberer))
             startexp = -expfit[0] * np.log(
                 (25.0 + np.min(avg_del[s1:s2]) - expfit[3]) /
                 expfit[2]) - expfit[1]
             if np.isnan(startexp) or startexp >= 2000:
                 startexp = 0
             thresholds = np.append(thresholds, startexp)
             expfit0 = np.append(expfit0, expfit[0])
             expfit1 = np.append(expfit1, expfit[1])
             expfit2 = np.append(expfit2, expfit[2])
             expfit3 = np.append(expfit3, expfit[3])
             pixels = np.append(pixels, pxl_list[s1])
         thresh = np.rec.fromarrays(
             [pixels, thresholds, expfit0, expfit1, expfit2, expfit3],
             dtype=[('pixel_no', int), ('td_threshold', float),
                    ('expfit0', float), ('expfit1', float),
                    ('expfit2', float), ('expfit3', float)])
         in_file_h5.createTable(in_file_h5.root,
                                'td_threshold',
                                thresh,
                                filters=self.filter_tables)
     p1, p2, single_scan = plotting.plot_timewalk(h5_filename)
     output_file(self.output_filename + '.html', title=self.run_name)
     status = plotting.plot_status(h5_filename)
     save(hplot(vplot(p1, p2, status), single_scan))