(* Definition of a normalized Lorentzian; parameter is FWHM time *)
Lorentzian[t_,tj_]:=1/Pi/(tj/2+t^2/tj*2)
Integrate[Lorentzian[t,u],{t,-Infinity,Infinity},Assumptions->{u>0}]

(* Definition of a normalized Gaussianian; parameter sigma *)
Gaussian[t_,sigma_]:=Exp[-t^2/2/sigma^2]/Sqrt[2 Pi sigma^2]
Integrate[Gaussian[t,u],{t,-Infinity,Infinity},Assumptions->{u>0}]

(* To convert a sigma into a fwhm *)
sigmatofwhm=2*Sqrt[2*Log[2]]//N

Gaussian[sigmatofwhm/2,1]/Gaussian[0,1]

(* Definition of our decay profile *)
Expo[t_,tc_]:=Exp[-Abs[2t]/tc]

(* This should be the distribution after convolution *)
convo1[t_,tc_,tj_]:=Integrate[Lorentzian[t-tau,tj]*Expo[tau,tc],{tau,-Infinity,Infinity}]

convo2[t_,tc_,tj_]:=Integrate[Gaussian[t-tau,tj]*Expo[tau,tc],{tau,-Infinity,Infinity}]

convo1[0,374,40]//N

convo2[0,374,40/sigmatofwhm]

(* Convolution of ideal etalon response 500ps, Gaussian sigma 11.1ps plus exponential 163ps *)Integrate[(0.51*Gaussian[0-tau,11.1]+0.49*(2/163)*Exp[-Abs[0-tau]/163])*Expo[tau,500],{tau,-Infinity,Infinity}]

(* Convolution of ideal etalon response 500ps, Lorentzian FWHM 40ps plus exponential 225ps *)

Integrate[(0.50*Lorentzian[0-tau,40]+0.50*(2/225)*Exp[-Abs[0-tau]/225])*Expo[tau,500],{tau,-Infinity,Infinity}]

Attempt of reading in raw data of APD test and convolute it with ideal lorentz shape

(* Read in raw data, and strip off first line, then take 4000 entries *)
graw=Take[Drop[Import["apd_mpd.dat"],1],4000];
(* Sanity check if first and last element makes sense *)
graw[[1]]
graw[[-1]]

(* make list that contains time in nsec and MPD data only *)
g13=Transpose[Transpose[graw][[{1,3}]]];
(* again, sanity check *)
g13[[1]]
g13[[-1]]

(* evaluate this only for check purposes *)
ListLogPlot[g13, PlotRange->All]
Plot[Expo[t,500],{t,-2000,2000},PlotRange->All]

(* This is to normalize the measured distribution *)
sum=Apply[Plus,Transpose[g13][[2]]]
g13n=Transpose[Transpose[g13]*{1,1/sum}];

(* ugly way of generating convolution *)
gconv[t_]:=Apply[Plus,Map[(#[[2]]*Expo[t-#[[1]],.194])&,g13n]]
gconv[0]

gconvlist=Table[{t,gconv[t]},{t,-2,2,.02}];
ListPlot[gconvlist,PlotRange->All]

Fitting convoluted lorentz spectrum to sun data

sunraw=Drop[Import["g2sun.txt","Table"],5];

sundata=Map[({10^9,1}*#)&,Take[sunraw,{51,209}]];
sundataerr=Map[Append[#,Sqrt[#[[2]]]]&,sundata];

ListPlot[sundata,PlotRange->All]

(* Convolution of etalon response with parameter tc: characteristic time (kn nsec) *)
gconv2[t_, tc_]:=Apply[Plus,Map[(#[[2]]*Expo[t-#[[1]],tc])&,g13n]]

gconv2[0.2,0.5]

nlm=NonlinearModelFit[sundata,a+b*gconv2[t-t0,tc],{{a,2000},{b,1200},{t0,-4},{tc,0.5}},t]

nlm[{"BestFitParameters", "ParameterErrors"}]

sl2=Map[(#+{3.82258,0})&,sundata];

Show[{ListPlot[sl2],Plot[2000+2831.*gconv2[x,0.194],{x,-2.,2.},PlotRange->All]},PlotRange->{{-2,2},{0,4000}}]