%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plotting routine for CDMS Low Energy Data Release
%
% Run this matlab function in the same directory as the downloaded data
% file AllDet_qindata.tar.gz. It produces 3 plots: the energy distrubtion
% of the charge and recoil energy for the single and multiple events, and
% the trigger and quality cut efficiencies for each detector. The figures
% are saved as .png files in the new subdirectory plts.
%
% plot_data(view_plots)
%
% view_plots determines whether the matlab figures will stay open (1) or
% will be automatically closed (0). If there is no argument, the script
% will close the figures by default.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function plot_data(view_plots,varargin)
if nargin == 0
view_plots = 0;
elseif nargin > 1;
display('---------------------------Caution---------------------------')
display('plot_data takes at most 1 argument: further arguments ignored')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Load datafiles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Define list of detectors to be used, include T3Z5 at end for easy
%exclusion
DetName = ['T1Z2'; 'T1Z5'; 'T2Z3'; 'T2Z5'; 'T3Z2'; 'T3Z4'; 'T3Z6'; 'T3Z5'];
% Load each individual detector's data
Mult = [];
Sing = [];
for i = 1:8
file1 = strcat(['efficiencies/qual_effs_' DetName(i,:) '.txt']);
file2 = strcat(['efficiencies/trig_effs_' DetName(i,:) '.txt']);
file3 = strcat([DetName(i,:) '_qin_mult_data.txt']);
file4 = strcat([DetName(i,:) '_qin_singles_data.txt']);
QE(i) = importdata(file1);
TE(i) = importdata(file2);
M(i) = importdata(file3);
S(i) = importdata(file4);
Mult = [Mult; M(i).data];
Sing = [Sing; S(i).data];
end
NRload = importdata('bands/nr_band_fits.txt');
display('Data Loaded')
pause(.5)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Make figures
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (~exist('plts'))
unix('mkdir plts');
end
% Figure Information
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
width = 5.5;
height = 3*10.5/8.3;
left = 1.5;
bottom = 4;
myfiguresize = [left, bottom, width, height];
% Event Distribution Plots
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
edges{1} = 3:.2:14;
edges{2} = -.5:.2:8;
%Include explicit cut on energy range to avoid boundary issues
cEn_M = Mult(:,1) <= 14 & Mult(:,1) >= 3 & ... %Phonon Energy Range 3keVnr < Er < 14 keVnr
Mult(:,2) >= -.5 & Mult(:,2) <= 8; %Charge Energy Range -.5keVee < Ei < 8 keVee
cEn_S = Sing(:,1) <= 14 & Sing(:,1) >= 3 & ...
Sing(:,2) >= -.5 & Sing(:,2) <= 8;
%Populate 2D Histograms
A1 = hist3(Mult(cEn_M,:),'Edges',edges);
A2 = hist3(Sing(cEn_S,:),'Edges',edges);
%Draw figures for singles and multiples distributions both with and without
%T3Z5
f1 = figure;
hold on
pcolor(edges{1},edges{2},A1')
shading flat
xlabel('recoil energy [keVnr]')
ylabel('ionization energy [keVee]')
axis([3 14 -.5 8])
set(gcf,'ColorMap',flipud(bone))
colorbar
title('Multiples Distribution')
set(gcf, 'PaperUnits', 'inches')
set(gcf, 'PaperPosition', myfiguresize);
saveas(gcf,'plts\MultDist.png')
f2 = figure;
hold on
pcolor(edges{1},edges{2},A2')
shading flat
xlabel('recoil energy [keVnr]')
ylabel('ionization energy [keVee]')
axis([3 14 -.5 8])
set(gcf,'ColorMap',flipud(bone))
colorbar
title('Singles Distribution')
set(gcf, 'PaperUnits', 'inches')
set(gcf, 'PaperPosition', myfiguresize);
saveas(gcf,'plts\SingDist.png')
% Efficiency Plots
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Specify eight colors
ColorSet = [1 0 1;0 1 1;1 0 0;0 1 0;0 0 1;.4 0 0;0 .4 0;0 0 .4];
%Draw Figure
f3 = figure;
hold on
for i = 1:8
plot(QE(i).data(:,1),QE(i).data(:,2),'color',ColorSet(i,:),'linewidth',1);
end
for i = 1:8
plot(TE(i).data(:,1),TE(i).data(:,2),'color',ColorSet(i,:),'linestyle','--','linewidth',1);
end
plot([3 3],[0 1.05],'k-')
text(10,.95,'trigger', 'Color', 'k','FontSize',12);
text(9,.55,'quality', 'Color', 'k','FontSize',12);
text(4,.15,'threshold', 'Color', 'k','FontSize',12);
annotation('arrow',[.22 .32],[.2 .2])
ylim([0 1.05])
Leg = legend(DetName,'Location','SE');
set(Leg,'FontSize',12)
xlabel('recoil energy [keVnr]')
ylabel('efficiency')
title('Detector Efficiencies')
set(gcf, 'PaperUnits', 'inches')
set(gcf, 'PaperPosition', myfiguresize);
saveas(gcf,'plts/Eff.png')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File/Workspace Cleanup
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% close opened figures if input view_plots = 0
if(~view_plots)
close(f1)
close(f2)
close(f3)
end