def get_gains(): """ Get and print the gains for the four cores of the ADC. """ for i in range(1, 5): print "%.3f " % adc5g.get_spi_gain(roach2, zdok, i), print
def get_gains(): """ Get and print the gains for the four cores of the ADC. """ for i in range(1,5): print "%.3f " % adc5g.get_spi_gain(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_gain(self, zdok=0, giter=10, gtol=0.005, verbose=10): """ Attempt to match the core gains within the ADC. See ArtooDaq.calibrate_adc_ogp for more details. """ # gain controlled by float varying over [-18%,18%] with 0.14% resolution res_gain = 0.14 lim_gain = [-18.0, 18.0] groups = 8 test_step = 10 * res_gain if verbose > 3: print " Gain calibration ZDOK{0}:".format(zdok) for ic in xrange(1, 5): adc5g.set_spi_gain(self.roach2, zdok, ic, 0) x1 = self._snap_per_core(zdok=zdok, groups=groups) sx1 = x1.std(axis=0) s0 = sx1[0] sx1 = sx1 / s0 if verbose > 5: print " ...gain: with zero-offsets, stds are [{0}]".format( ", ".join(["{0:+7.4f}".format(isx) for isx in sx1])) # only adjust gains for last three cores, core1 is the reference for ic in xrange(2, 5): adc5g.set_spi_gain(self.roach2, zdok, ic, test_step) x2 = self._snap_per_core(zdok=zdok, groups=groups) sx2 = x2.std(axis=0) s0 = sx2[0] sx2 = sx2 / s0 if verbose > 5: print " ...gain: with {0:+6.2f}% gain, stds are [{1}]".format( test_step, ", ".join(["{0:+7.4f}".format(isx) for isx in sx2])) d_sx = 100 * (sx2 - sx1) / test_step # give differential for core1 a non-zero value, it won't be used anyway d_sx[0] = 1.0 # gains are in units percentage core_gains = 100 * (1.0 - sx1) / d_sx # set core1 gain to zero core_gains[0] = 0 for ic in xrange(2, 5): adc5g.set_spi_gain(self.roach2, zdok, ic, core_gains[ic - 1]) core_gains[ic - 1] = adc5g.get_spi_gain(self.roach2, zdok, ic) x = self._snap_per_core(zdok=zdok, groups=groups) sx = x.std(axis=0) s0 = sx[0] sx = sx / s0 if verbose > 5: print " ...gain: solution gains are [{0}]%, stds are [{1}]".format( ", ".join(["{0:+6.2f}".format(ico) for ico in core_gains]), ", ".join(["{0:+7.4f}".format(isx) for isx in sx])) if any(abs(1.0 - sx) >= gtol): if verbose > 5: print " ...gain: solution not good enough, iterating (tol={0:4.4f},iter={1:d})".format( gtol, giter) for ii in xrange(0, giter): for ic in xrange(2, 5): if (1.0 - sx[ic - 1]) > gtol: adc5g.set_spi_gain(self.roach2, zdok, ic, core_gains[ic - 1] + res_gain) elif (1.0 - sx[ic - 1]) < -gtol: adc5g.set_spi_gain(self.roach2, zdok, ic, core_gains[ic - 1] - res_gain) core_gains[ic - 1] = adc5g.get_spi_gain( self.roach2, zdok, ic) x = self._snap_per_core(zdok=zdok, groups=groups) sx = x.std(axis=0) s0 = sx[0] sx = sx / s0 if verbose > 7: print " ...gain: solution gains are [{0}]%, stds are [{1}]".format( ", ".join( ["{0:+6.2f}".format(ico) for ico in core_gains]), ", ".join(["{0:+7.4f}".format(isx) for isx in sx])) if all(abs(1.0 - sx) < gtol): if verbose > 5: print " ...gain: solution good enough" break if ii == giter - 1: if verbose > 5: print " ...gain: maximum number of iterations reached, aborting" else: if verbose > 5: print " ...gain: solution good enough" return core_gains
def calibrate_adc_gain(self,zdok=0,giter=10,gtol=0.005,verbose=10): """ Attempt to match the core gains within the ADC. See ArtooDaq.calibrate_adc_ogp for more details. """ # gain controlled by float varying over [-18%,18%] with 0.14% resolution res_gain = 0.14 lim_gain = [-18.0,18.0] groups = 8 test_step = 10*res_gain if verbose > 3: print " Gain calibration ZDOK{0}:".format(zdok) for ic in xrange(1,5): adc5g.set_spi_gain(self.roach2,zdok,ic,0) x1 = self._snap_per_core(zdok=zdok,groups=groups) sx1 = x1.std(axis=0) s0 = sx1[0] sx1 = sx1/s0 if verbose > 5: print " ...gain: with zero-offsets, stds are [{0}]".format( ", ".join(["{0:+7.4f}".format(isx) for isx in sx1]) ) # only adjust gains for last three cores, core1 is the reference for ic in xrange(2,5): adc5g.set_spi_gain(self.roach2,zdok,ic,test_step) x2 = self._snap_per_core(zdok=zdok,groups=groups) sx2 = x2.std(axis=0) s0 = sx2[0] sx2 = sx2/s0 if verbose > 5: print " ...gain: with {0:+6.2f}% gain, stds are [{1}]".format( test_step, ", ".join(["{0:+7.4f}".format(isx) for isx in sx2]) ) d_sx = 100*(sx2 - sx1)/test_step # give differential for core1 a non-zero value, it won't be used anyway d_sx[0] = 1.0 # gains are in units percentage core_gains = 100*(1.0-sx1)/d_sx # set core1 gain to zero core_gains[0] = 0 for ic in xrange(2,5): adc5g.set_spi_gain(self.roach2,zdok,ic,core_gains[ic-1]) core_gains[ic-1] = adc5g.get_spi_gain(self.roach2,zdok,ic) x = self._snap_per_core(zdok=zdok,groups=groups) sx = x.std(axis=0) s0 = sx[0] sx = sx/s0 if verbose > 5: print " ...gain: solution gains are [{0}]%, stds are [{1}]".format( ", ".join(["{0:+6.2f}".format(ico) for ico in core_gains]), ", ".join(["{0:+7.4f}".format(isx) for isx in sx]) ) if any(abs(1.0-sx) >= gtol): if verbose > 5: print " ...gain: solution not good enough, iterating (tol={0:4.4f},iter={1:d})".format(gtol,giter) for ii in xrange(0,giter): for ic in xrange(2,5): if (1.0-sx[ic-1]) > gtol: adc5g.set_spi_gain(self.roach2,zdok,ic,core_gains[ic-1]+res_gain) elif (1.0-sx[ic-1]) < -gtol: adc5g.set_spi_gain(self.roach2,zdok,ic,core_gains[ic-1]-res_gain) core_gains[ic-1] = adc5g.get_spi_gain(self.roach2,zdok,ic) x = self._snap_per_core(zdok=zdok,groups=groups) sx = x.std(axis=0) s0 = sx[0] sx = sx/s0 if verbose > 7: print " ...gain: solution gains are [{0}]%, stds are [{1}]".format( ", ".join(["{0:+6.2f}".format(ico) for ico in core_gains]), ", ".join(["{0:+7.4f}".format(isx) for isx in sx]) ) if all(abs(1.0-sx) < gtol): if verbose > 5: print " ...gain: solution good enough" break if ii==giter-1: if verbose > 5: print " ...gain: maximum number of iterations reached, aborting" else: if verbose > 5: print " ...gain: solution good enough" return core_gains
# 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 plt.savefig(figfile)