You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: BH_SpectrumBowtieLUT.m
    path of file: ./repos/TIGRE/MATLAB/Utilities/IO/VarianCBCT
    
    the code of the file until where you have to start completion: function BHCalib = BH_SpectrumBowtieLUT(geo, BHCalib)
%SPECTRAPROCESS Summary of this function goes here
%   Detailed explanation goes here

%% Thin window filter has been applied to the spectrum already
% Source-to-detector distance: mm
SDD = geo.DSD;
% Source-to-bowtie distance: mm
SBD = BHCalib.bowtie.distance;

%% [u,v] vector: mm
offset=geo.offDetector;
us = ((-geo.nDetector(1)/2+0.5):1:(geo.nDetector(1)/2-0.5))*geo.dDetector(1) + offset(1);
vs = ((-geo.nDetector(2)/2+0.5):1:(geo.nDetector(2)/2-0.5))*geo.dDetector(2) + offset(2);

%% Map Detector Plane to Bowtier Surface
ub = us * SBD/SDD;
% vb = vs * SBD/SDD;

u_s = fix(min(ub)) + sign(min(us))*10;
u_l = fix(max(ub)) + sign(max(us))*10;

sampling_rate = 4002;

xxgd = linspace(u_s, u_l, sampling_rate);
y_l = ceil(max(BHCalib.bowtie.thickness));
yygd = linspace(-y_l, y_l, sampling_rate);
% bowtie height = 55 mm, ref to TrueBeam Technical Reference
zzgd = linspace(-27.5, 27.5, 102);


    
function BHCalib = BH_SpectrumBowtieLUT(geo, BHCalib)
%SPECTRAPROCESS Summary of this function goes here
%   Detailed explanation goes here

%% Thin window filter has been applied to the spectrum already
% Source-to-detector distance: mm
SDD = geo.DSD;
% Source-to-bowtie distance: mm
SBD = BHCalib.bowtie.distance;

%% [u,v] vector: mm
offset=geo.offDetector;
us = ((-geo.nDetector(1)/2+0.5):1:(geo.nDetector(1)/2-0.5))*geo.dDetector(1) + offset(1);
vs = ((-geo.nDetector(2)/2+0.5):1:(geo.nDetector(2)/2-0.5))*geo.dDetector(2) + offset(2);

%% Map Detector Plane to Bowtier Surface
ub = us * SBD/SDD;
% vb = vs * SBD/SDD;

u_s = fix(min(ub)) + sign(min(us))*10;
u_l = fix(max(ub)) + sign(max(us))*10;

sampling_rate = 4002;

xxgd = linspace(u_s, u_l, sampling_rate);
y_l = ceil(max(BHCalib.bowtie.thickness));
yygd = linspace(-y_l, y_l, sampling_rate);
% bowtie height = 55 mm, ref to TrueBeam Technical Reference
zzgd = linspace(-27.5, 27.5, 102);

bt_img = zeros(length(xxgd), length(yygd));


%% Fitting to Model Bowtie Profile: 
[xData, yData] = prepareCurveData(BHCalib.bowtie.uu, BHCalib.bowtie.thickness);

%% Fitting Model: Smoothing Spline 
% Set up fittype and options.
ft = fittype( 'smoothingspline' );

% Fit model to data.
[fitresult, gof] = fit(xData, yData, ft);
disp(['Bowtie Fitting Goodness (R^2): ' num2str(gof.rsquare)])

%% 3D bowtie img matrix
for ii = 1:length(xxgd)
    tmp_thick = fitresult(xxgd(ii));
    tmp = ((yygd>0)&(yygd<tmp_thick));
    bt_img(tmp, ii) = 1;
end