#########################################################
# file: plot_TunedDBR_spectrum.lsf
#
# Description:
#   Plot the tuned DBR laser spectrum used to
#   reproduce Figure 9.
#
# Prerequisites:
#   1. Open LaserDBRonlyLossModQ20shifted.icp.
#   2. Run the simulation.
#   3. Execute this script.
#
#########################################################

# OSA result
osa = getresult("OSA_1","sum/signal");
f = osa.Frequency/1e12;        # THz
P_DBR = getresultdata("OSA_1","sum/signal");  # Power [dBm]

# Gain element result
gain = getresult("TWLM_1","diagnostic/gain/fitted spectrum");
fg= gain.frequency/1e12; 
g = getresultdata("TWLM_1","diagnostic/gain/fitted spectrum");

# Scale gain shape for visualization
gnorm = abs(g)/max(abs(g));
gscaled = 100*(gnorm^2) - 100;

#########################################################
# Figure 9a
#########################################################
plot(f,P_DBR);
holdon;
plot(fg,gscaled);
setplot("x label", "Frequency (THz)");
setplot("y label", "Power (dBm)");
legend("Laser Spectrum","Scaled Gain Profile");
holdoff;

#########################################################
# Figure 9b
#########################################################
plot(f,P_DBR);
setplot("x label", "Frequency (THz)");
setplot("y label", "Power (dBm)");
setplot("x min",349.5);
setplot("x max",350.5);
setplot("y min",-80);
setplot("y max",20);
setplot("show legend",0);