% 2001.05.16
% compare fits w/ old and new qe in garf.

slib=getenv("HOME")+"/libisis/";
()=evalfile(slib+"presid.sl");


p1=open_plot("/xwin",1,2,[3,1]);resize(23);
p2=open_plot("/xwin");resize(23);

label("Wavelength [A]", "Flux [cts/bin]", "3C273 (ObsID 1198; LETG/ACIS-S)");

load_data("../Pha/acisf01198_001N001_pha2.fits",[3,4]);
load_data("../Pha/acisf01198_001N001_pha2.fits",[3,4]); % load twice on purpose

load_arf("acisf01198_002N001LEG_-1_garf.fits");  % new
load_arf("acisf01198_002N001LEG_1_garf.fits");

load_arf("acisf01198_001N001LEG_-1_garf.fits");  % old
load_arf("acisf01198_001N001LEG_1_garf.fits");

assign_arf(1,1);assign_arf(2,2);    % new
assign_arf(3,3);assign_arf(4,4);    % old

group_data(1,4);group_data(2,4);
group_data(3,4);group_data(4,4);

flux_corr(1);flux_corr(2);
flux_corr(3);flux_corr(4);

xrange(0,70);

import("xspec");
fit_fun("wabs(1)*powerlaw(1)");

set_par(1, 0.01, 0, 0.0001, 0,1);
set_par(2, 0.02, 0, 0.0,    1.0);
set_par(3, -1.5, 0, -3.0, 0.0);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% fit new version:

ignore([3,4]); xnotice(1,0,65); xnotice(2,0,40);

fit_counts;
list_par;

window(p2);
xrange(0,70);
plot_data_counts(1);oplot_model_counts(1);
oplot_data_counts(2);oplot_model_counts(2);

d1=get_data_counts(1);d2=get_data_counts(2);
m1=get_model_counts(1);m2=get_model_counts(2);

window(p1);

psid=dup_plot("Obs_1198_m1_newqe.ps/cps",p1);
presid(p1,[0,70,0,500],d1.bin_lo,d1.bin_hi,d1.value,m1.value);
xylabel(10,50,"New ACIS-S QE; m = -1");
close_plot(psid);window(p1);

psid=dup_plot("Obs_1198_p1_newqe.ps/cps",p1);
presid(p1,[0,40,0,500],d2.bin_lo,d2.bin_hi,d2.value,m2.value);
xylabel(10,30,"New ACIS-S QE; m = +1");
close_plot(psid);window(p1);


%%%%%%%%%%%% or gif versions:
gifid=dup_plot("Obs_1198_m1_newqe.gif/gif",p1);
presid(p1,[0,70,0,500],d1.bin_lo,d1.bin_hi,d1.value,m1.value);
xylabel(10,50,"New ACIS-S QE; m = -1");
close_plot(gifid);window(p1);

gifid=dup_plot("Obs_1198_p1_newqe.gif/gif",p1);
presid(p1,[0,40,0,500],d2.bin_lo,d2.bin_hi,d2.value,m2.value);
xylabel(10,30,"New ACIS-S QE; m = +1");
close_plot(gifid);window(p1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

conf(1,1);  % 90% limits
conf(2,1);
conf(3,1);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% fit old-garf spectrum:

ignore([1,2]); xnotice(3,0,65); xnotice(4,0,40);

fit_counts;
list_par;

window(p2);
xrange(0,70);
plot_data_counts(3);oplot_model_counts(3);
oplot_data_counts(4);oplot_model_counts(4);

d1=get_data_counts(3);d2=get_data_counts(4);
m1=get_model_counts(3);m2=get_model_counts(4);

window(p1);
psid=dup_plot("Obs_1198_m1_oldqe.ps/cps",p1);
presid(p1,[0,70,0,500],d1.bin_lo,d1.bin_hi,d1.value,m1.value);
xylabel(10,50,"Old ACIS-S QE; m = -1");
close_plot(psid);window(p1);

psid=dup_plot("Obs_1198_p1_oldqe.ps/cps",p1);
presid(p1,[0,40,0,500],d2.bin_lo,d2.bin_hi,d2.value,m2.value);
xylabel(10,30,"Old ACIS-S QE; m = +1");
close_plot(psid);window(p1);


%%%%%%%%%%% or gif versions
gifid=dup_plot("Obs_1198_m1_oldqe.gif/gif",p1);
presid(p1,[0,70,0,500],d1.bin_lo,d1.bin_hi,d1.value,m1.value);
xylabel(10,50,"Old ACIS-S QE; m = -1");
close_plot(gifid);window(p1);

gifid=dup_plot("Obs_1198_p1_oldqe.gif/gif",p1);
presid(p1,[0,40,0,500],d2.bin_lo,d2.bin_hi,d2.value,m2.value);
xylabel(10,30,"Old ACIS-S QE; m = +1");
close_plot(gifid);window(p1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



conf(1,1);  % 90% limits
conf(2,1);
conf(3,1);


