def get_offs(): """ Get and print the offsets for the four cores of the ADC. """ for i in range(1, 5): print "%.3f " % adc5g.get_spi_offset(roach2, zdok, i), print
def get_offs(): """ Get and print the offsets for the four cores of the ADC. """ for i in range(1,5): print "%.3f " % adc5g.get_spi_offset(roach2,zdok,i), print
def get_ogp(self): ''' Returns the OGP matrix (4 rows of 3 values). ''' ogp = np.zeros((12), dtype='float') indx = 0 for chan in range(1,5): ogp[indx] = adc.get_spi_offset(self._roach, 0, chan) indx += 1 ogp[indx] = adc.get_spi_gain(self._roach, 0, chan) indx += 1 ogp[indx] = adc.get_spi_phase(self._roach, 0, chan) indx += 1 return ogp.reshape(4, 3)
def get_ogp_array(): """ Read the Offset, Gain and Phase corrections for each core from the ADC and return in a 1D array """ ogp = np.zeros((12), dtype='float') indx = 0 for chan in range(1,5): ogp[indx] = adc5g.get_spi_offset(roach2,zdok,chan) indx += 1 ogp[indx] = adc5g.get_spi_gain(roach2,zdok,chan) indx += 1 ogp[indx] = adc5g.get_spi_phase(roach2,zdok,chan) indx += 1 return ogp
def get_ogp_array(): """ Read the Offset, Gain and Phase corrections for each core from the ADC and return in a 1D array """ ogp = np.zeros((12), dtype='float') indx = 0 for chan in range(1, 5): ogp[indx] = adc5g.get_spi_offset(roach2, zdok, chan) indx += 1 ogp[indx] = adc5g.get_spi_gain(roach2, zdok, chan) indx += 1 ogp[indx] = adc5g.get_spi_phase(roach2, zdok, chan) indx += 1 return ogp
def get_ogp_chan(self, chan): """ Returns ogp values for a channel 'chan' """ ogp_chan = [] zdok, cores = self.get_channel_core_spi(chan) for core in cores: off = adc5g.get_spi_offset(self.roach, zdok, core) gain = adc5g.get_spi_gain(self.roach, zdok, core) phase = adc5g.get_spi_phase(self.roach, zdok, core) ogp_core = [off, gain, phase] ogp_chan.append(ogp_core) return ogp_chan
def calibrate_adc_offset(self, zdok=0, oiter=10, otol=0.005, verbose=10): """ Attempt to match the core offsets within the ADC. See ArtooDaq.calibrate_adc_ogp for more details. """ # offset controlled by float varying over [-50,50] mV with 0.4 mV resolution res_offset = 0.4 lim_offset = [-50.0, 50.0] groups = 8 test_step = 10 * res_offset if verbose > 3: print " Offset calibration ZDOK{0}:".format(zdok) for ic in xrange(1, 5): adc5g.set_spi_offset(self.roach2, zdok, ic, 0) x1 = self._snap_per_core(zdok=zdok, groups=groups) sx1 = x1.std(axis=0) mx1 = x1.mean(axis=0) / sx1 if verbose > 5: print " ...offset: with zero-offsets, means are [{0}]".format( ", ".join(["{0:+7.4f}".format(imx) for imx in mx1])) for ic in xrange(1, 5): adc5g.set_spi_offset(self.roach2, zdok, ic, test_step) x2 = self._snap_per_core(zdok=zdok, groups=groups) sx2 = x2.std(axis=0) mx2 = x2.mean(axis=0) / sx2 if verbose > 5: print " ...offset: with {0:+4.1f} mV offset, means are [{1}]".format( test_step, ", ".join(["{0:+7.4f}".format(imx) for imx in mx2])) d_mx = (mx2 - mx1) / test_step core_offsets = -mx1 / d_mx for ic in xrange(1, 5): adc5g.set_spi_offset(self.roach2, zdok, ic, core_offsets[ic - 1]) core_offsets[ic - 1] = adc5g.get_spi_offset(self.roach2, zdok, ic) x = self._snap_per_core(zdok=zdok, groups=groups) sx = x.std(axis=0) mx = x.mean(axis=0) / sx if verbose > 5: print " ...offset: solution offsets are [{0}] mV, means are [{1}]".format( ", ".join(["{0:+6.2f}".format(ico) for ico in core_offsets]), ", ".join(["{0:+7.4f}".format(imx) for imx in mx])) if any(abs(mx) >= otol): if verbose > 5: print " ...offset: solution not good enough, iterating (tol={0:4.4f},iter={1:d})".format( otol, oiter) for ii in xrange(0, oiter): for ic in xrange(1, 5): if mx[ic - 1] > otol: adc5g.set_spi_offset(self.roach2, zdok, ic, core_offsets[ic - 1] - res_offset) elif mx[ic - 1] < -otol: adc5g.set_spi_offset(self.roach2, zdok, ic, core_offsets[ic - 1] + res_offset) core_offsets[ic - 1] = adc5g.get_spi_offset( self.roach2, zdok, ic) x = self._snap_per_core(zdok=zdok, groups=groups) sx = x.std(axis=0) mx = x.mean(axis=0) / sx if verbose > 7: print " ...offset: solution offsets are [{0}] mV, means are [{1}]".format( ", ".join( ["{0:+6.2f}".format(ico) for ico in core_offsets]), ", ".join(["{0:+7.4f}".format(imx) for imx in mx])) if all(abs(mx) < otol): if verbose > 5: print " ...offset: solution good enough" break if ii == oiter - 1: if verbose > 5: print " ...offset: maximum number of iterations reached, aborting" else: if verbose > 5: print " ...offset: solution good enough" return core_offsets
def calibrate_adc_offset(self,zdok=0,oiter=10,otol=0.005,verbose=10): """ Attempt to match the core offsets within the ADC. See ArtooDaq.calibrate_adc_ogp for more details. """ # offset controlled by float varying over [-50,50] mV with 0.4 mV resolution res_offset = 0.4 lim_offset = [-50.0,50.0] groups = 8 test_step = 10*res_offset if verbose > 3: print " Offset calibration ZDOK{0}:".format(zdok) for ic in xrange(1,5): adc5g.set_spi_offset(self.roach2,zdok,ic,0) x1 = self._snap_per_core(zdok=zdok,groups=groups) sx1 = x1.std(axis=0) mx1 = x1.mean(axis=0)/sx1 if verbose > 5: print " ...offset: with zero-offsets, means are [{0}]".format( ", ".join(["{0:+7.4f}".format(imx) for imx in mx1]) ) for ic in xrange(1,5): adc5g.set_spi_offset(self.roach2,zdok,ic,test_step) x2 = self._snap_per_core(zdok=zdok,groups=groups) sx2 = x2.std(axis=0) mx2 = x2.mean(axis=0)/sx2 if verbose > 5: print " ...offset: with {0:+4.1f} mV offset, means are [{1}]".format( test_step, ", ".join(["{0:+7.4f}".format(imx) for imx in mx2]) ) d_mx = (mx2 - mx1)/test_step core_offsets = -mx1/d_mx for ic in xrange(1,5): adc5g.set_spi_offset(self.roach2,zdok,ic,core_offsets[ic-1]) core_offsets[ic-1] = adc5g.get_spi_offset(self.roach2,zdok,ic) x = self._snap_per_core(zdok=zdok,groups=groups) sx = x.std(axis=0) mx = x.mean(axis=0)/sx if verbose > 5: print " ...offset: solution offsets are [{0}] mV, means are [{1}]".format( ", ".join(["{0:+6.2f}".format(ico) for ico in core_offsets]), ", ".join(["{0:+7.4f}".format(imx) for imx in mx]) ) if any(abs(mx) >= otol): if verbose > 5: print " ...offset: solution not good enough, iterating (tol={0:4.4f},iter={1:d})".format(otol,oiter) for ii in xrange(0,oiter): for ic in xrange(1,5): if mx[ic-1] > otol: adc5g.set_spi_offset(self.roach2,zdok,ic,core_offsets[ic-1]-res_offset) elif mx[ic-1] < -otol: adc5g.set_spi_offset(self.roach2,zdok,ic,core_offsets[ic-1]+res_offset) core_offsets[ic-1] = adc5g.get_spi_offset(self.roach2,zdok,ic) x = self._snap_per_core(zdok=zdok,groups=groups) sx = x.std(axis=0) mx = x.mean(axis=0)/sx if verbose > 7: print " ...offset: solution offsets are [{0}] mV, means are [{1}]".format( ", ".join(["{0:+6.2f}".format(ico) for ico in core_offsets]), ", ".join(["{0:+7.4f}".format(imx) for imx in mx]) ) if all(abs(mx) < otol): if verbose > 5: print " ...offset: solution good enough" break if ii==oiter-1: if verbose > 5: print " ...offset: maximum number of iterations reached, aborting" else: if verbose > 5: print " ...offset: solution good enough" return core_offsets
statslabel = r'$\mu$:%.1f, $\sigma$:%.1f' % (ret[1], ret[2]) # h0 = plt.errorbar(x, y, yerr, fmt='.', label='IF%d core %d' % (i,j)) h0 = plt.plot(x, y, '.', label='IF%d core %d' % (i,j)) h1 = plt.plot(xx, gaussian(xx, *ret), label=r'$\mu$:%.1f, $\sigma$:%.1f' % (ret[1], ret[2])) plt.text(0.05, 0.95, iflabel, ha='left', va='top', transform=plt.gca().transAxes) plt.text(0.95, 0.95, statslabel, ha='right', va='top', transform=plt.gca().transAxes) plt.xlim(-128, 128) plt.ylim(0, 1.05 * np.max(counts)) plt.yticks([]) plt.xticks([]) means[j] = ret[1] stds[j] = ret[2] print "IF%d Core %d: mean %5.2f std %5.2f" % (i, j, ret[1], ret[2]) avg_std = np.mean(stds) # target std for j in [0,1,2,3]: orig_off = adc5g.get_spi_offset(r2, i, corder[j]) orig_gain = adc5g.get_spi_gain(r2, i, corder[j]) new_off = orig_off - means[j] * 500./256. new_gain = (100. + orig_gain) * (avg_std / stds[j]) - 100. if setog: adc5g.set_spi_offset(r2, i, corder[j], new_off) adc5g.set_spi_gain(r2, i, corder[j], new_gain) sol[i,j,0] = new_off sol[i,j,1] = new_gain if doplot: plt.suptitle('%s ADC 8bit population\n%s' % (open('/etc/hostname').read().strip(), tag)) plt.subplots_adjust(hspace=0, wspace=0) plt.setp(plt.gcf(), figwidth=8, figheight=12) figfile = 'ogplot-%s.png' % tag print "saving figure to: %s" % figfile