% INPUT parameters
% ----------------------------------------------------------------------
%pname1 = '/home/preston/matlabs3/bin/workspaces/L2_processed/MCP_72_88_scan/';
pname1 = '/home/preston/matlabs3/bin/workspaces/L2_processed/5-27_MCPscriptbasedMeasurementsy72-78/';

fname1 = '1000_2300_3600_3mvsc/data.mat'; 

% ---------------------------------------------------------------------
disp([pname1 fname1])


TTn= [pname1 fname1];
load(TTn);

ampsLow = amplifications(:,5);
VmaxsLow = Vmaxs;
wavesLow = newWaves;

% Need to remove some low amplification events before we do rt fwhm and arrival time
% data with low amplification events removed becomes timing*
ampMin = 1.2e6;
[timingWavesLow,timingAmplificationsLow,~] = amplificationControl(newWaves,time,ampMin,2e7,rawevstatsL2);
[timingVmaxsLow,~] = getMaxs(timingWavesLow);

clear TTn pname1 pname2 fname1 fname2
clear DBLbadwaves DHwaves RTFWHMbadwaves rawevstatsL2 oldWaves
clear flattops scopescale triglevel newWaves Vmaxs imaxs

%%%%%%%%%%%%%%%%%%%

% rise time and fwhm info gathering


[~,gg,~] = size(timingWavesLow);
tinc = time(5)-time(4);

risetimeLow = zeros(1,gg);
fwhmsLow = zeros(1,gg);
for j = 1:gg
    [~,~,twidthhm,~]=findThresholds(timingWavesLow(:,j,2),.5*timingVmaxsLow(j,2),time);        

    fwhmsLow(j)=twidthhm*tinc; 

    [~,~,rt]=findCFThreshold(timingWavesLow(:,j,2),time,0.2);
    risetimeLow(j)=rt;
end

% Don't want rise times less than .2 ns or fwhms less than 1 ns, they are noisy events contaminating my plots
xx = risetimeLow < .2e-9;
ww = fwhmsLow < .5e-9;
xx = xx+ww;


risetimeLow = risetimeLow(~xx);
fwhmsLow = fwhmsLow(~xx);
timingWavesLow = timingWavesLow(:,~xx,:);
[timingVmaxsLow,~] = getMaxs(timingWavesLow);


clear xx yy ww
evstats(1) = ( sum(risetimeLow) )/( gg );
evstats(2) = ( sum(fwhmsLow) )/( gg );

% Plotting
performL3plotsv2

clear twidthhm rt j hh gg
