% Compare LCLS and LCSL-II measuerements for Quad 000709

% Load LCLS-II measurement data
cd('C:\Magnet_Data\LCLS-II\Quad\000709')
Load_strplt_dev(11); % Integrated gradient measurements
Load_strplt_dev(17); % Integrated gradient measurements
Load_strplt_dev(18); % Integrated gradient measurements



% Load LCLS original measurement data
cd('C:\Magnet_Data\LCLS\Quad\000709')
Load_strplt_mmcvi2(1); % Integrated gradient measurements
Harplt1 = Load_harplt_mmcvi(1, 16);

% Load LCLS re-measurement data
cd('C:\Magnet_Data\LCLS\Quad\000709\000709_Check')
Load_strplt_mmcvi(8); % Integrated gradient measurements

cd('C:\Magnet_Data\LCLS-II\Quad\000709')
fit_term = 3;

% Fit the -6 to 6 A data for each run.

% LCLS data
[max_SL1,index_max_SL1] = max(Strplt1.Imag);
sign_angle_max1 = sign(Strplt1.THsp(index_max_SL1));
Strplt1.SL = sign_angle_max1*Strplt1.SL.*sign(Strplt1.THsp);
I_BL_up1 = plot_polyfit_res(Strplt1.Imag(1:25),Strplt1.SL(1:25), Strplt1.sigSL(1:25),fit_term); % Polynomial fit for up currents from -6 A to +6 amps. 

% LCLS-II data
[max_SL11,index_max_SL11] = max(Strplt11.Imag);
sign_angle_max11 = sign(Strplt11.THsp(index_max_SL11));
Strplt11.SL = sign_angle_max11*Strplt11.SL.*sign(Strplt11.THsp);
I_BL_up11 = plot_polyfit_res(Strplt11.Imag(1:25),Strplt11.SL(1:25), Strplt11.sigSL(1:25),fit_term); % Polynomial fit for up currents from -6 A to +6 amps. 

% Compare integrated gradient values at the nominal currents of -4.5 and 4.5 A.
Run1_Int_grad = polyval(I_BL_up1, [-4.5,4.5]);
Run11_Int_grad = polyval(I_BL_up11, [-4.5,4.5]);

Nominal_Int_Grad_ratio11_1 = Run11_Int_grad./Run1_Int_grad;  % Compares the LCLS-II data (run 11) to the LCLS data (run 1)

% Compare the data at 6 amps

Ratio_6A_Orig_Remeas = Strplt1.SL_I(25)/mean(Strplt8.SL_I);
Ratio_6A_Orig_LCLSII = Strplt1.SL_I(25)/Strplt11.TF(25);
Ratio_6A_Remeas_LCLSII = mean(Strplt8.SL_I)/Strplt11.TF(25);




