% LCLS-II 7 mil mu-metal tests on 2" beam pipe.  Beam pipe put into
% helmholtz coil, which was set to 1 G.  Measurements were made with 1
% layer, 2 layers, and none.  The mu-metal was long enough to cover almost
% half the pipe and measurements were made at the z 1/2 and 1/4 points of
% the mu-metal.  The 1/2 point is were the two halves come together and the 1/4 point is in the midle of one half.  The two halves were overlapped.   

T2G = 10000.0;  % Tesla to Gauss conversion factor.
% close all
%% Get data
cd('C:\Magnet_Data\LCLS-II\Mu-Metal\7_mil_layers');

BP_Layer_2_center = Load_tunnelfluxplt(1);  % 2 layers
BP_Layer_1_center = Load_tunnelfluxplt(2);  % 1 layer
BP_Layer_0_center = Load_tunnelfluxplt(3);  % No mu metal
BP_Layer_1_quarter = Load_tunnelfluxplt(4);  % 1 Layer
BP_Layer_2_quarter = Load_tunnelfluxplt(5);  % 2 Layers
BP_Layer_0_quarter = Load_tunnelfluxplt(6);  % No Mu-metal

BP_Layer_2_center_Bx_mean_all = mean(BP_Layer_2_center.Bx)*T2G;
BP_Layer_2_center_By_mean_all = mean(BP_Layer_2_center.By)*T2G;
BP_Layer_2_center_Bz_mean_all = mean(BP_Layer_2_center.Bz)*T2G;

BP_Layer_1_center_Bx_mean_all = mean(BP_Layer_1_center.Bx)*T2G;
BP_Layer_1_center_By_mean_all = mean(BP_Layer_1_center.By)*T2G;
BP_Layer_1_center_Bz_mean_all = mean(BP_Layer_1_center.Bz)*T2G;

BP_Layer_0_center_Bx_mean_all = mean(BP_Layer_0_center.Bx)*T2G;
BP_Layer_0_center_By_mean_all = mean(BP_Layer_0_center.By)*T2G;
BP_Layer_0_center_Bz_mean_all = mean(BP_Layer_0_center.Bz)*T2G;

BP_Layer_2_quarter_Bx_mean_all = mean(BP_Layer_2_quarter.Bx)*T2G;
BP_Layer_2_quarter_By_mean_all = mean(BP_Layer_2_quarter.By)*T2G;
BP_Layer_2_quarter_Bz_mean_all = mean(BP_Layer_2_quarter.Bz)*T2G;

BP_Layer_1_quarter_Bx_mean_all = mean(BP_Layer_1_quarter.Bx)*T2G;
BP_Layer_1_quarter_By_mean_all = mean(BP_Layer_1_quarter.By)*T2G;
BP_Layer_1_quarter_Bz_mean_all = mean(BP_Layer_1_quarter.Bz)*T2G;

BP_Layer_0_quarter_Bx_mean_all = mean(BP_Layer_0_quarter.Bx)*T2G;
BP_Layer_0_quarter_By_mean_all = mean(BP_Layer_0_quarter.By)*T2G;
BP_Layer_0_quarter_Bz_mean_all = mean(BP_Layer_0_quarter.Bz)*T2G;

Reduction_factor_Bx_1_Layer = [(BP_Layer_0_center_Bx_mean_all/BP_Layer_1_center_Bx_mean_all), (BP_Layer_0_quarter_Bx_mean_all/BP_Layer_1_quarter_Bx_mean_all)];
 Reduction_factor_Bx_2_Layer = [(BP_Layer_0_center_Bx_mean_all/BP_Layer_2_center_Bx_mean_all), (BP_Layer_0_quarter_Bx_mean_all/BP_Layer_2_quarter_Bx_mean_all)]; 
  Reduction_factor_By_1_Layer = [(BP_Layer_0_center_By_mean_all/BP_Layer_1_center_By_mean_all), (BP_Layer_0_quarter_By_mean_all/BP_Layer_1_quarter_By_mean_all)];
   Reduction_factor_By_2_Layer = [(BP_Layer_0_center_By_mean_all/BP_Layer_2_center_By_mean_all), (BP_Layer_0_quarter_By_mean_all/BP_Layer_2_quarter_By_mean_all)];   


Layer = [0,1,2];
Bx_center_data = [abs(BP_Layer_0_center_Bx_mean_all), abs(BP_Layer_1_center_Bx_mean_all), abs(BP_Layer_2_center_Bx_mean_all)];
By_center_data = [abs(BP_Layer_0_center_By_mean_all), abs(BP_Layer_1_center_By_mean_all), abs(BP_Layer_2_center_By_mean_all)];
Bx_quarter_data = [abs(BP_Layer_0_quarter_Bx_mean_all), abs(BP_Layer_1_quarter_Bx_mean_all), abs(BP_Layer_2_quarter_Bx_mean_all)];
By_quarter_data = [abs(BP_Layer_0_quarter_By_mean_all), abs(BP_Layer_1_quarter_By_mean_all), abs(BP_Layer_2_quarter_By_mean_all)];

% plot center quarter Bx data
figure('units','normalized','outerposition',[0 0 0.75 0.7])

semilogy(Layer,Bx_center_data,marker_make3(1))
hold
semilogy(Layer,Bx_quarter_data,marker_make3(2))
xlabel('Number of Layers');
ylabel('Log of Magnetic Field (G)');
title('LCLS-II Number of Layers vs Bx Field')
legend('Bx (G) Z 1/2 Point', 'Bx (G) Z 1/4 Point', 'Location', 'Best');


% plot center quarter By data
figure('units','normalized','outerposition',[0 0 0.75 0.7])

semilogy(Layer,By_center_data,marker_make3(1))
hold
semilogy(Layer,By_quarter_data,marker_make3(2))
xlabel('Number of Layers');
ylabel('Log of Magnetic Field (G)');
title('LCLS-II Number of Layers vs By Field')
legend('By (G) Z 1/2 Point',  'By (G) Z 1/4 Point', 'Location', 'Best');

