%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function r = correction_gen(coeffFile,coeffSched,mode) Generates schedules for properly setting the nonlinearity and alpha/r corrections on the Northern digital backend. Normalization of the corrections in the input file are arbitrary; the coefficients are re-scaled automatically to maximize dynamic range in the backend's filter chain. coeffFile: an ascii file containing the arbitrarily normalized coefficients. For nonlinearity correction, this will be two columns of twelve numbers. For alpha/r correction, this will be two columns of two numbers. coeffSched: The filename of the output schedule. mode: 1 == nonlinearity; 2 == alpha/r. 14-Nov-2011 (MAS): Created. 02-Apr-2012 (MAS): Fixed a bug. Needed to specify 'channel' and 'stage' in the cbassViewer commands. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function r = correction_gen(coeffFile,coeffSched,mode) 0002 0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0004 % function r = correction_gen(coeffFile,coeffSched,mode) 0005 % 0006 % Generates schedules for properly setting the nonlinearity and alpha/r 0007 % corrections on the Northern digital backend. Normalization of the 0008 % corrections in the input file are arbitrary; the coefficients are 0009 % re-scaled automatically to maximize dynamic range in the backend's 0010 % filter chain. 0011 % 0012 % 0013 % coeffFile: an ascii file containing the arbitrarily normalized 0014 % coefficients. For nonlinearity correction, this will be two columns of 0015 % twelve numbers. For alpha/r correction, this will be two columns of 0016 % two numbers. 0017 % 0018 % coeffSched: The filename of the output schedule. 0019 % 0020 % mode: 1 == nonlinearity; 2 == alpha/r. 0021 % 0022 % 0023 % 14-Nov-2011 (MAS): Created. 0024 % 02-Apr-2012 (MAS): Fixed a bug. Needed to specify 'channel' and 'stage' in the cbassViewer commands. 0025 % 0026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0027 0028 0029 0030 % Read in the coefficient file: 0031 coeffs = load(coeffFile); 0032 0033 0034 % Check for invalid inputs... 0035 if sum(coeffs(:) < 0) 0036 error('COEFFICIENTS MUST BE GREATER THAN ZERO!'); 0037 end 0038 0039 0040 0041 if (mode == 1) 0042 % Here is the nonlinearity correction numbers: 0043 0044 % Check for right number of inputs: 0045 if (size(coeffs,1) ~= 12 || size(coeffs,2) ~= 2) 0046 error('COEFFICIENT FILE IS IMPROPERLY FORMATTED!'); 0047 end 0048 0049 0050 x_sum = coeffs(:,1) * (2^13 - 1) * 2^4 + coeffs(:,2) * 2^4; 0051 x_prod = coeffs(:,1) * 2^17; 0052 0053 x_max = max(cat(1,x_sum,x_prod)); 0054 0055 coeffcoeff = (2^17 - 1) / x_max; 0056 0057 coeffs_A = round(coeffs(:,1) * coeffcoeff * 2^17); 0058 coeffs_B = round(coeffs(:,2) * coeffcoeff * 2^4); 0059 0060 0061 % Write the file... 0062 fid = fopen(coeffSched, 'w'); 0063 0064 fprintf(fid, 'log \"Setting the Nonlinearity Coefficients\"\n'); 0065 fprintf(fid, 'setNonlinCorrection channel=%u, stage=%u, 0\n', cat(2,coeffs_A, (1:12)')'); 0066 fprintf(fid, 'setNonlinCorrection channel=%u, stage=%u, 1\n', cat(2,coeffs_B, (1:12)')'); 0067 0068 fclose(fid); 0069 elseif (mode == 2) 0070 % Here is the alpha correction numbers: 0071 0072 % Check for right number of inputs: 0073 if (size(coeffs,1) ~= 2 || size(coeffs,2) ~= 2) 0074 error('COEFFICIENT FILE IS IMPROPERLY FORMATTED!'); 0075 end 0076 0077 0078 coeffcoeff = 2^16 ./ max(coeffs,[],2); 0079 0080 coeffs_A = round(coeffs(:,1) .* coeffcoeff); 0081 coeffs_B = round(coeffs(:,2) .* coeffcoeff); 0082 0083 0084 % Write the file... 0085 fid = fopen(coeffSched, 'w'); 0086 0087 fprintf(fid, 'log \"Setting the Alpha/r-factor Coefficients\"\n'); 0088 fprintf(fid, 'setAlphaCorrection channel=%u, stage=%u, 0\n', cat(2,coeffs_A, (1:2)')'); 0089 fprintf(fid, 'setAlphaCorrection channel=%u, stage=%u, 1\n', cat(2,coeffs_B, (1:2)')'); 0090 0091 fclose(fid); 0092 else 0093 error('MODE MUST BE 1 OR 2!'); 0094 end 0095 0096 0097 %save(coeffSched,'coeffs_A','coeffs_B','-ascii'); 0098 % 0099 %disp(coeffs_A); 0100 %disp(coeffs_B); 0101 0102 0103 r = 1; 0104 0105 end