% Make the plots for the Ion Pump 2 Stray Field Study
%
%   only transverse fields  Bx, By
%
function plot1diff2tr(A1,Ab,fignumber, figtitle)
[n,p]=size(Ab);
t=1:n;
d=Ab(t,1);
Bxb=Ab(t,2)/10.; % Now in Gauss or 0.1mT
Byb=Ab(t,3)/10.;
Bzb=Ab(t,4)/10.;
% [n,p]=size(A1); should be the same
d=A1(t,1);
Bxp=A1(t,2)/10.; % Now in Gauss or 0.1mT
Byp=A1(t,3)/10.;
Bzp=A1(t,4)/10.;
Bxpd=Bxp-Bxb; % Subtract background field
Bypd=Byp-Byb;
Bzpd=Bzp-Bzb;
%%
%figure(fignumber)
%subplot(2,1,1)
%plot(d,Bxpd,'-+b')
%
%xlabel('d [cm]');
%ylabel('Bx, By [Gauss]')
%hold on
%plot(d,Bypd,'-+g')
%axis([0.,100.,-1.,1.])
%legend('Bx','By')
%grid on
%
%subplot(2,1,2)
%plot(d,Bzpd,'-+r')
%axis([0.,100.,-0.25,0.15])
%legend('Bz')
%grid on
%title(figtitle1)
%xlabel('d [cm]');
%ylabel('Bz [Gauss]')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  Field^2  bg-sub
for i=1:1:51
Bt(i)  = sqrt(Bxpd(i)^2 + Bypd(i)^2);  % + Bzpd(i)^2); bg-subtracted
Btp(i) = sqrt(Bxp(i)^2 + Byp(i)^2);    % + Bzp(i)^2);  not bg
%  Bg Field
Btb(i)= sqrt(Bxb(i)^2 + Byb(i)^2);     % + Bzb(i)^2);   bg field
end
%
figure(fignumber)
%subplot(2,1,1)
plot(d,Bt,'-+r')                   % bg-subtracted
xlabel('d [cm]');ylabel('|Bxy-backgd| [Gauss]')
hold on
grid on
%subplot(2,1,2)
plot(d,Btb,'-+b')                  % bg field
plot(d,Btp,'-+g')                   % not bg-subtracted      
title(figtitle)
legend('|Bxy-backgd|','|Bxy-backgd|', '|Bxy|')
%xlabel('d [cm]');ylabel('|BBackgd| [Gauss]')
%subplot(3,1,3)
%plot(d,Btp-Btb,'-+b')
%xlabel('d [cm]');ylabel('|B|-|backgd| [Gauss]')

%bg-sub integral 
sum(Bt)/51.
mean(Bt)
integral = 2.0*sum(Bt)
integral2 = 100.0*mean(Bt)
% All done


