%read a csv file

%reset workspace
clear; clc; close all;

%input
path='/home/gian/geant4-apps/SAXS-build/'; 
inputname='output_nt_scatt';
R1=8;
C1=0;
COL=3;
nbin=100;
varIstheta=1;
varMin=0.5;
varMax=30.5;

%read
filename=strcat(path,inputname,'.csv');
M=csvread(filename,R1,C1);
var=M(:,COL);

%plot
figure(1);
%hist(var,nbin);
Dvar=(varMax-varMin)/nbin;
edges=(varMin:Dvar:varMax-Dvar)';
Ec=edges+Dvar*0.5;
h1=histc(var,edges);
if (varIstheta==1)
    h1=h1./sin(Ec*acos(-1)/180);
end
stairs(Ec,h1,'r-','LineWidth',2,'MarkerSize',8)
ylabel('counts (a. u.)');
if (varIstheta==1)
    xlabel('\theta (deg)');
else
    xlabel('E (MeV)')
end
xlim([varMin varMax]);
