#=============================================== # TkPumpPlobeTHz #=============================================== package TkPumpPlobeTHz; use clib::TkEllipsometry; @ISA = qw(TkEllipsometry); #公開したいサブルーチン #@EXPORT = qw(DelSpace Reduce01 MakePath RegExpQuote); use strict; my $pi = Sci::pi(); my $kB = Sci::kB(); my $c = Sci::c(); my $e = Sci::e(); my $e0 = Sci::e0(); my $me = Sci::me(); my $mp = Sci::mp(); my $mn = Sci::mn(); my $h = Sci::h(); my $hbar = Sci::hbar(); my $torad = Sci::torad(); my $todeg = Sci::todeg(); #============================================================ # 変数等取得関数 #============================================================ #============================================================ # コンストラクタ、デストラクタ #============================================================ #============================================================ # 継承クラスで定義しなおす関数 #============================================================ sub CreateWidgets { my ($this) = @_; my $App = $this->App(); my $args = $App->Args(); my $mw = $this->mw(); $this->{ini} = new IniFile(undef, 0, 0); $this->{dini} = new IniFile(undef, 0, 0); $this->{Ellipsometry} = new Ellipsometry; $this->{nLorentz} = 2 if(!defined $this->{nLorentz}); $this->{nDrude} = 1 if(!defined $this->{nDrude}); $this->SUPER::CreateWidgets(1); $this->mw()->SetTitle("Pump-Probe THz spectrum Fit 2008 / TkPlot"); $this->App()->SetProgram("Pump-Probe THz spectrum Fit 2008 / TkPlot"); #=================================================== # ペインを作製 #=================================================== my $EntryWidth = 12; my $Frame = $mw->MyFrame()->pack(-anchor => 'nw', -fill => 'x'); $this->MakeChooseFileEntry($Frame, 'Param', 'Param:', $this->{ini}->pVariable("ParameterFile", ""), '&Choose', sub { $this->ChooseFile(@_); }, "ChooseParameterFile"); $this->{SaveParamButton} = $Frame->MyButton( -text => '&Save', -takefocus => 1, -command => sub { $this->ButtonPressed('RButtonDown', 'SaveParam'); }, )->pack(-side => 'left'); $this->{EditParamButton} = $Frame->MyButton( -text => 'ed', -takefocus => 1, -command => sub { $this->ButtonPressed('RButtonDown', 'EditParam'); }, )->pack(-side => 'left'); $Frame = $mw->MyFrame()->pack(-anchor => 'nw', -fill => 'x'); $this->MakeChooseFileEntry($Frame, 'SampleCSV', 'Sample:', $this->{ini}->pVariable("SampleCSVFile", ""), '&Choose', sub { $this->ChooseFile(@_); }, "ChooseSampleFile"); $this->{EditDataButton} = $Frame->MyButton( -text => 'ed', -takefocus => 1, -command => sub { $this->ButtonPressed('RButtonDown', 'EditSampleCSV'); }, )->pack(-side => 'left'); $Frame = $mw->MyFrame()->pack(-anchor => 'nw', -fill => 'x'); $this->MakeChooseFileEntry($Frame, 'SubstrateCSV', 'Substrate:', $this->{ini}->pVariable("SubstrateCSVFile", ""), '&Choose', sub { $this->ChooseFile(@_); }, "ChooseSubstrateFile"); $this->{EditDataButton} = $Frame->MyButton( -text => 'ed', -takefocus => 1, -command => sub { $this->ButtonPressed('RButtonDown', 'EditSubstrateCSV'); }, )->pack(-side => 'left'); $Frame = $mw->MyFrame()->pack(-anchor => 'nw', -fill => 'x'); my $lsb1 = $this->{ChooseXListBox} = $Frame->MyBrowseEntry( -label => "X:", -state => "readonly", -takefocus => 1, -width => 5, -Selections => [], -SelIndex => 0, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $lsb1->configure(-browsecmd => [\&SelChangeListBox, $this, "X", $this->{ChooseXListBox}]); my $lsb2 = $this->{ChooseY1ListBox} = $Frame->MyBrowseEntry( -label => "Y1:", -state => "readonly", -takefocus => 1, -width => 5, -Selections => [], -SelIndex => 1, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $lsb2->configure(-browsecmd => [\&SelChangeListBox, $this, "Y1", $this->{ChooseY1ListBox}]); my $lsb3 = $this->{ChooseY2ListBox} = $Frame->MyBrowseEntry( -label => "Y2:", -state => "readonly", -takefocus => 1, -width => 5, -Selections => [], -SelIndex => 2, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $lsb3->configure(-browsecmd => [\&SelChangeListBox, $this, "Y2", $this->{ChooseY2ListBox}]); $Frame = $mw->MyLabFrame( -label => 'Fitting1', -labelside => 'acrosstop', )->pack(-anchor => 'nw', -fill => 'x'); my $lsb4 = $this->{ChooseLSQMethodListBox} = $Frame->MyBrowseEntry( -label => "LSQ Method:", -state => "readonly", -takefocus => 1, -width => 5, -Selections => ['Amoeba::Simplex', 'PDL::Simplex', 'ModifiedNewton'], -SelIndex => 0, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $lsb4->configure(-browsecmd => [\&SelChangeListBox, $this, "LSQMethod", $this->{ChooseLSQMethodListBox}]); my $lsb5 = $this->{ChooseFitToListBox} = $Frame->MyBrowseEntry( -label => "Fit to:", -state => "readonly", -takefocus => 1, -width => 5, -Selections => ['RT', 'R', 'T'], -SelIndex => 2, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $Frame = $mw->MyLabFrame( -label => 'Fitting2', -labelside => 'acrosstop', )->pack(-anchor => 'nw'); $this->MakeLabelEntry($Frame, "FitEmin", "Emin:", $this->{ini}->pVariable('FitEmin', ''), "%s", $EntryWidth, "eV", 0, 0); $this->MakeLabelEntry($Frame, "FitEmax", "Emax:", $this->{ini}->pVariable('FitEmax', ''), "%s", $EntryWidth, "eV", 0, 1); $this->MakeLabelEntry($Frame, "nSkipData", "nSkip:", $this->{ini}->pVariable('nSkipData', 2), "%d", $EntryWidth, "", 0, 2); $this->MakeLabelEntry($Frame, "EPS", "EPS:", $this->{ini}->pVariable('EPS', 1.0e-5), "%12.4g", $EntryWidth, "", 1, 0); $this->MakeLabelEntry($Frame, "nMaxIter", "MaxIter:", $this->{ini}->pVariable('nMaxIter', 1000), "%d", $EntryWidth, "", 1, 1); $this->MakeLabelEntry($Frame, "nSaveSpectraInterval", "SaveIntvl:", $this->{ini}->pVariable('nSaveSpectraInterval', 10), "%d", $EntryWidth, "", 1, 2); $Frame = $mw->MyLabFrame( -label => 'Structure', -labelside => 'acrosstop', )->pack(-anchor => 'nw'); my $Frame1 = $Frame->MyFrame()->pack(-anchor => 'nw'); $this->MakeLabelEntry($Frame1, "TAngle", "TAngle:", $this->{ini}->pVariable('TAngle', 0.0), "%8.4f", $EntryWidth, "deg", 0, 0); $Frame1 = $Frame->MyFrame()->pack(-anchor => 'nw'); $this->MakeCheckEntry($Frame1, "FilmThickness", "Film thickness:", $this->{dini}->pVariable('FilmThicknesscheck', 1), $this->{ini}->pVariable('FilmThickness', 100.0), "%12.6g", $EntryWidth, "nm", 1, 0); $Frame1 = $Frame->MyFrame()->pack(-anchor => 'nw'); $this->MakeCheckEntry($Frame1, "SubstrateThickness", "Substrate thickness:", $this->{dini}->pVariable('SubstrateThicknesscheck', 0), $this->{ini}->pVariable('SubstrateThickness', 0.5), "%12.6g", $EntryWidth, "mm", 0, 1); $Frame1 = $Frame->MyFrame()->pack(-anchor => 'nw'); $Frame = $mw->MyLabFrame( -label => 'Scattering', -labelside => 'acrosstop', )->pack(-anchor => 'nw'); $this->MakeCheckEntry($Frame, "Scale", "scale:", $this->{dini}->pVariable('Scalecheck', 0) , $this->{ini}->pVariable('Scale', 1.0), "%12.6g", $EntryWidth, "", 0, 0); $this->MakeCheckEntry($Frame, "Rayleighl0", "Rayleigh lamba0:", $this->{dini}->pVariable('Rayleighl0check', 0) , $this->{ini}->pVariable('Rayleighl0', 0.0), "%12.6g", $EntryWidth, "", 0, 1); $Frame = $mw->MyLabFrame( -label => 'Dielectric background', -labelside => 'acrosstop', )->pack(-anchor => 'nw'); $this->MakeCheckEntry($Frame, "e1inf", "e1:", $this->{dini}->pVariable('e1infcheck', 1) , $this->{ini}->pVariable('e1inf', 0.155), "%12.6g", $EntryWidth, "e0", 0, 0); $this->MakeCheckEntry($Frame, "e2inf", "e2:", $this->{dini}->pVariable('e2infcheck', 0) , $this->{ini}->pVariable('e2inf', 0.0 ), "%12.6g", $EntryWidth, "e0", 0, 1); $this->MakeCheckEntry($Frame, "Caucy2", "Caucy2:", $this->{dini}->pVariable('Caucy2check', 0) , $this->{ini}->pVariable('Caucy2', 0.0), "%12.6g", $EntryWidth, "", 1, 0); $this->MakeCheckEntry($Frame, "Caucy4", "Caucy4:", $this->{dini}->pVariable('Caucy4check', 0) , $this->{ini}->pVariable('Caucy4', 0.0), "%12.6g", $EntryWidth, "", 1, 1); $Frame = $mw->MyLabFrame( -label => 'Tauc-Lorentz', -labelside => 'acrosstop', )->pack(-anchor => 'nw'); $this->MakeCheckEntry($Frame, "A", "A:", $this->{dini}->pVariable('Acheck', 1) , $this->{ini}->pVariable('A', 122.8), "%12.6g", $EntryWidth, "", 0, 0); $this->MakeCheckEntry($Frame, "C", "C:", $this->{dini}->pVariable('Ccheck', 1) , $this->{ini}->pVariable('C', 10.8), "%12.6g", $EntryWidth, "", 0, 1); $this->MakeCheckEntry($Frame, "Eg", "Eg:", $this->{dini}->pVariable('Egcheck', 1) , $this->{ini}->pVariable('Eg', 4.4), "%12.6g", $EntryWidth, "eV", 1, 0); $this->MakeCheckEntry($Frame, "En0", "En0:", $this->{dini}->pVariable('En0check', 1) , $this->{ini}->pVariable('En0', 155.9), "%12.6g", $EntryWidth, "eV", 1, 1); $Frame = $mw->MyLabFrame( -label => "Lorentz", -labelside => 'acrosstop', )->pack(-anchor => 'nw'); for(my $i = 0 ; $i < $this->{nLorentz} ; $i++) { my $i1 = $i + 1; $this->MakeCheckEntry($Frame, "E0${i1}", "E0:", $this->{dini}->pVariable("E0${i1}check", 1) , $this->{ini}->pVariable("E0${i1}", 2.64), "%12.6g", $EntryWidth, "eV", $i, 0); $this->MakeCheckEntry($Frame, "Ne${i1}", "Ne:", $this->{dini}->pVariable("Ne${i1}check", 1) , $this->{ini}->pVariable("Ne${i1}", 2e26), "%12.6g", $EntryWidth, "m-3", $i, 1); $this->MakeCheckEntry($Frame, "G${i1}", "G:", $this->{dini}->pVariable("G${i1}check", 1) , $this->{ini}->pVariable("G${i1}", 2.64), "%12.6g", $EntryWidth, "eV", $i, 2); } $Frame = $mw->MyLabFrame( -label => "Drude(non-excited)", -labelside => 'acrosstop', )->pack(-anchor => 'nw'); for(my $i = 0 ; $i < $this->{nDrude} ; $i++) { my $i1 = $i + 1; $this->MakeCheckEntry($Frame, "DrudeEp${i1}", "Ep:", $this->{dini}->pVariable("DrudeEp${i1}check", 1) , $this->{ini}->pVariable("DrudeEp${i1}", 0.5), "%12.6g", $EntryWidth, "eV", $i, 1); $this->MakeCheckEntry($Frame, "Drudetau${i1}", "tau:", $this->{dini}->pVariable("Drudetau${i1}check", 1) , $this->{ini}->pVariable("Drudetau${i1}", 1.0e-14), "%12.6g", $EntryWidth, "s", $i, 2); } $Frame = $mw->MyLabFrame( -label => "Drude(excited)", -labelside => 'acrosstop', )->pack(-anchor => 'nw'); for(my $i = 0 ; $i < $this->{nDrude} ; $i++) { my $i1 = $i + 1; $this->MakeCheckEntry($Frame, "DrudeExcEp${i1}", "Ep:", $this->{dini}->pVariable("DrudeExcEp${i1}check", 1) , $this->{ini}->pVariable("DrudeExcEp${i1}", 0.5), "%12.6g", $EntryWidth, "eV", $i, 1); $this->MakeCheckEntry($Frame, "DrudeExctau${i1}", "tau:", $this->{dini}->pVariable("DrudeExctau${i1}check", 1) , $this->{ini}->pVariable("DrudeExctau${i1}", 1.0e-14), "%12.6g", $EntryWidth, "s", $i, 2); } $this->UpdateParameters(); $Frame = $mw->MyFrame()->pack(-anchor => 'nw', -fill => 'x'); $this->{RecalcButton} = $Frame->MyButton( -text => 'Re&calc', -takefocus => 1, -command => sub { $this->ButtonPressed('RButtonDown', 'Recalc'); }, )->pack(-side => 'left'); $this->{FitButton} = $Frame->MyButton( -text => '&Fit', -takefocus => 1, -command => sub { $this->ButtonPressed('RButtonDown', 'Fit'); }, )->pack(-side => 'left'); #ツールバーのOpenボタンをファイル読み込みにバインドする $mw->{OpenButton}->configure( -command => sub { $this->ChooseFile('SampleCSVFile', $this->{SPEFileFileEntry}); }, ) if($mw->{OpenButton}); } sub ButtonPressed { my ($this, $event, $type) = @_; my $App = $this->App(); #print "this=$this event=$event\n"; if($type eq 'Recalc') { $this->Recalc(); $this->CreateGraphFrame(); $this->AssignGraphData(1); $this->Draw(); } else { $this->SUPER::ButtonPressed($event, $type); } } sub SelChangeListBox { my ($this, $type, $lb) = @_; #print "this:$this lb=$lb\n"; my $s = $lb->GetText(); if($type eq 'LayerModel') { if($s eq "Surface(EMA)/Film/Substrate") { $this->{SurfaceThicknessButton}->SetText("Surface thickness:"); } elsif($s eq "Film/Interface(EMA)/Substrate") { $this->{SurfaceThicknessButton}->SetText("Interface thickness:"); } else { } } # $this->CreateGraphFrame(); $this->AssignGraphData(); $this->Draw(); } #=================================================== # データ処理 #=================================================== sub BuildLayerModel { my ($this, $IsPrint, $BuildOptimize) = @_; $IsPrint = 1 if(!defined $IsPrint); $BuildOptimize = 1 if(!defined $BuildOptimize); my $ini = $this->{ini}; my $dini = $this->{dini}; my $el = $this->{Ellipsometry}; #print "el=$el\n"; my $optics = new Optics; my $Layers = new MultiLayer; $ini->{RAngle} = $ini->{TAngle}; $Layers->SetIncidentAngle($ini->{TAngle}); my $LayersExc = new MultiLayer; $LayersExc->SetIncidentAngle($ini->{TAngle}); my $pObsE = $el->GetData('.*eV.*', '.*E.*'); my $pObsEps1 = $el->GetData('e1'); my $pObsEps2 = $el->GetData('e2'); my $pObsR = $el->GetData('R'); my $pObsT = $el->GetData('T'); my $nData = @$pObsE; my $nE = $nData; $ini->{FitEmin} = $pObsE->[0] if($ini->{FitEmin} eq ''); $ini->{FitEmax} = $pObsE->[$nData-1] if($ini->{FitEmax} eq ''); my $Emin = $ini->{FitEmin}; my $Emax = $ini->{FitEmax}; my $Estep = $pObsE->[1] - $pObsE->[0]; $Estep = 0.05 if(!defined $Estep); $nData = int( ($Emax - $Emin) / $Estep + 1.001); my $Air = new OpticalMaterial("air"); my $Film = new OpticalMaterial("Specify", "Film"); my $FilmExc = new OpticalMaterial("Specify", "Film(Excited)"); my $Substrate = new OpticalMaterial("Specify", "Substrate"); $Film->AddDielectricModel( "Constant1", "Constant", "e1inf", $ini->{e1inf}, "e2inf", $ini->{e2inf}, ); $Film->AddDielectricModel( "TaucLorentz1", "TaucLorentz", "A", $ini->{A}, "Eg", $ini->{Eg}, "En0", $ini->{En0}, "C", $ini->{C} ); $Film->AddDielectricModel( "Caucy1", "Caucy", "pA", [$ini->{Caucy2}, $ini->{Caucy4}], "pn", [2, 4], ); for(my $i = 0 ; $i < $this->{nLorentz} ; $i++) { my $i1 = $i + 1; $Film->AddDielectricModel( "Lorentz$i1", "Lorentz", "Ne", $ini->{"Ne$i1"}, "E0", $ini->{"E0$i1"}, "G", $ini->{"G$i1"}, ); } for(my $i = 0 ; $i < $this->{nDrude} ; $i++) { my $i1 = $i + 1; $Film->AddDielectricModel( "Drude$i1", "Drude", "Ep", $ini->{"DrudeEp$i1"}, "tau", $ini->{"Drudetau$i1"}, ); } $FilmExc->AddDielectricModel( "Constant1", "Constant", "e1inf", $ini->{e1inf}, "e2inf", $ini->{e2inf}, ); $FilmExc->AddDielectricModel( "TaucLorentz1", "TaucLorentz", "A", $ini->{A}, "Eg", $ini->{Eg}, "En0", $ini->{En0}, "C", $ini->{C} ); $FilmExc->AddDielectricModel( "Caucy1", "Caucy", "pA", [$ini->{Caucy2}, $ini->{Caucy4}], "pn", [2, 4], ); for(my $i = 0 ; $i < $this->{nLorentz} ; $i++) { my $i1 = $i + 1; $FilmExc->AddDielectricModel( "Lorentz$i1", "Lorentz", "Ne", $ini->{"Ne$i1"}, "E0", $ini->{"E0$i1"}, "G", $ini->{"G$i1"}, ); } for(my $i = 0 ; $i < $this->{nDrude} ; $i++) { my $i1 = $i + 1; $FilmExc->AddDielectricModel( "DrudeExc$i1", "Drude", "Ep", $ini->{"DrudeExcEp$i1"}, "tau", $ini->{"DrudeExctau$i1"}, ); } if($ini->{SubstrateCSVFile}) { my @ret = $Substrate->AddDielectricModel( "Substrate", "EFile", "Path", $ini->{SubstrateCSVFile}, ); if(@ret == 0) { print "Error: Can not read [$ini->{SubstrateCSVFile}].\n"; return; } } $Layers->AddLayer($Air, -1.0, 0.0); $Layers->AddLayer($Film, $ini->{FilmThickness}*1.0e-9, 1.0); $Layers->AddLayer($Substrate, $ini->{SubstrateThickness}*1.0e-3, 0.0); $Layers->AddLayer($Air, -1.0, 0.0); $this->{Layers} = $Layers; $LayersExc->AddLayer($Air, -1.0, 0.0); $LayersExc->AddLayer($FilmExc, $ini->{FilmThickness}*1.0e-9, 1.0); $LayersExc->AddLayer($Substrate, $ini->{SubstrateThickness}*1.0e-3, 0.0); $LayersExc->AddLayer($Air, -1.0, 0.0); $this->{LayersExc} = $LayersExc; $Layers->PrintLayers() if($IsPrint); $LayersExc->PrintLayers() if($IsPrint); #========================================================= # フィッティング設定 #========================================================= return if(!$BuildOptimize); my $ppA = $Film->pVariable('Caucy1::pA'); my $pA = $$ppA; my $optimize = new Optimize(); $optimize->AddParameters( "Scale", \$ini->{Scale}, $dini->{Scalecheck}, $dini->{Scalescale}, $dini->{Scalemin}, $dini->{Scalemax}, sub { $ini->{Scale} = $_[0]; }, "Rayleighl0", \$ini->{Rayleighl0}, $dini->{Rayleighl0check}, $dini->{Rayleighl0scale}, $dini->{Rayleighl0min}, $dini->{Rayleighl0max}, sub { $ini->{Rayleighl0} = $_[0]; }, ); my $iFilm = 1; my $iSubstrate = 2; $optimize->AddParameters( "FilmThickness", $Layers->pLayerThickness($iFilm), $dini->{FilmThicknesscheck}, $dini->{FilmThicknessscale}, $dini->{FilmThicknessmin}, $dini->{FilmThicknessmax}, sub { $Layers->SetLayerThickness($iFilm, $_[0]); $ini->{FilmThickness} = $_[0]*1.0e9; }, "SubstrateThickness", $Layers->pLayerThickness($iSubstrate), $dini->{SubstrateThicknesscheck}, $dini->{SubstrateThicknessscale}, $dini->{SubstrateThicknessmin}, $dini->{SubstrateThicknessmax}, sub { $Layers->SetLayerThickness($iSubstrate, $_[0]); $ini->{SubstrateThickness} = $_[0]*1.0e3; }, "Film-e1", $Layers->pVariable($iFilm, 'Constant1::e1inf'), $dini->{e1infcheck}, $dini->{e1infscale}, $dini->{e1infmin}, $dini->{e1infmax}, sub { $Layers->SetVariable($iFilm, 'Constant1::e1inf', $_[0]); $ini->{e1inf} = $_[0]; }, "Film-e2", $Layers->pVariable($iFilm, 'Constant1::e2inf'), $dini->{e2infcheck}, $dini->{e2infscale}, $dini->{e2infmin}, $dini->{e2infmax}, sub { $Layers->SetVariable($iFilm, 'Constant1::e2inf', $_[0]); $ini->{e2inf} = $_[0]; }, "Film-Caucy2", \$pA->[0], $dini->{Caucy2check}, $dini->{Caucy2scale}, $dini->{Caucy2min}, $dini->{Caucy2max}, sub { $ini->{Caucy2} = $pA->[0] = $_[0]; }, "Film-Caucy4", \$pA->[1], $dini->{Caucy4check}, $dini->{Caucy4scale}, $dini->{Caucy4min}, $dini->{Caucy4max}, sub { $ini->{Caucy4} = $pA->[1] = $_[0]; }, "Film-TLA", $Layers->pVariable($iFilm, 'TaucLorentz1::A'), $dini->{Acheck}, $dini->{Ascale}, $dini->{Amin}, $dini->{Amax}, sub { $Layers->SetVariable($iFilm, 'TaucLorentz1::A', $_[0]); $ini->{A} = $_[0]; }, "Film-TLC", $Layers->pVariable($iFilm, 'TaucLorentz1::C'), $dini->{Ccheck}, $dini->{Cscale}, $dini->{Cmin}, $dini->{Cmax}, sub { $Layers->SetVariable($iFilm, 'TaucLorentz1::C', $_[0]); $ini->{C} = $_[0]; }, "Film-TLEg", $Layers->pVariable($iFilm, 'TaucLorentz1::Eg'), $dini->{Egcheck}, $dini->{Egscale}, $dini->{Egmin}, $dini->{Egmax}, sub { $Layers->SetVariable($iFilm, 'TaucLorentz1::Eg', $_[0]); $ini->{Eg} = $_[0]; }, "Film-TLEn0", $Layers->pVariable($iFilm, 'TaucLorentz1::En0'), $dini->{En0check}, $dini->{En0scale}, $dini->{En0min}, $dini->{En0max}, sub { $Layers->SetVariable($iFilm, 'TaucLorentz1::En0', $_[0]); $ini->{En0} = $_[0]; }, ); for(my $i = 0 ; $i < $this->{nLorentz} ; $i++) { my $i1 = $i + 1; $optimize->AddParameters( "Film-L${i1}E0", $Layers->pVariable($iFilm, "Lorentz${i1}::E0"), $dini->{"E0${i1}check"}, $dini->{"E0${i1}scale"}, $dini->{"E0${i1}min"}, $dini->{"E0${i1}max"}, sub { $Layers->SetVariable($iFilm, "Lorentz${i1}::E0", $_[0]); $ini->{"E0${i1}"} = $_[0]; }, "Film-L${i1}Ne", $Layers->pVariable($iFilm, "Lorentz${i1}::Ne"), $dini->{"Ne${i1}check"}, $dini->{"Ne${i1}scale"}, $dini->{"Ne${i1}min"}, $dini->{"Ne${i1}max"}, sub { $Layers->SetVariable($iFilm, "Lorentz${i1}::Ne", $_[0]); $ini->{"Ne${i1}"} = $_[0]; $ini->{"A${i1}"} = $optics->CalLorentzAfromNe($ini->{"Ne${i1}"}, 1.0); }, "Film-L${i1}G", $Layers->pVariable($iFilm, "Lorentz${i1}::G"), $dini->{"G${i1}check"}, $dini->{"G${i1}scale"}, $dini->{"G${i1}min"}, $dini->{"G${i1}max"}, sub { $Layers->SetVariable($iFilm, "Lorentz${i1}::G", $_[0]); $ini->{"G${i1}"} = $_[0]; }, ); } for(my $i = 0 ; $i < $this->{nDrude} ; $i++) { my $i1 = $i + 1; $optimize->AddParameters( "Film-D${i1}Ep", $Layers->pVariable($iFilm, "Drude${i1}::Ep"), $dini->{"DrudeEp${i1}check"}, $dini->{"DrudeEp${i1}scale"}, $dini->{"DrudeEp${i1}min"}, $dini->{"DrudeEp${i1}max"}, sub { $Layers->SetVariable($iFilm, "Drude${i1}::Ep", $_[0]); $ini->{"DrudeEp${i1}"} = $_[0]; }, "Film-D${i1}tau", $Layers->pVariable($iFilm, "Drude${i1}::tau"), $dini->{"Drudetau${i1}check"}, $dini->{"Drudetau${i1}scale"}, $dini->{"Drudetau${i1}min"}, $dini->{"Drudetau${i1}max"}, sub { $Layers->SetVariable($iFilm, "Drude${i1}::tau", $_[0]); $ini->{"Drudetau${i1}"} = $_[0]; }, ); } $this->{Optimize} = $optimize; } sub Recalc { my ($this) = @_; $this->UpdateParameters(); $this->BuildLayerModel(1, 0); my $el = $this->{Ellipsometry}; my $Layers = $this->{Layers}; my $LayersExc = $this->{LayersExc}; my $pObsE = $el->GetData('.*eV.*', '.*E.*'); my $pObsR = $el->GetData('R.*'); my $pObsT = $el->GetData('T.*'); my $FitTo = $this->{ChooseFitToListBox}->GetText(); my ($pE, $pR, $pT, ) = $this->CalRTArrays($Layers, $pObsE, $pObsR, $pObsT, $FitTo); my ($pE2, $pRExc, $pTExc) = $this->CalRTArrays($LayersExc, $pObsE, $pObsR, $pObsT, $FitTo); $this->{pEArray} = $pE; $this->{pRArray} = $pR; $this->{pTArray} = $pT; $this->{pRExcArray} = $pRExc; $this->{pTExcArray} = $pTExc; # $this->App()->print("Recalc: S2=$S2\n"); # $this->SetS2($S2); # return $S2; } sub Fit { my ($this) = @_; my $ini = $this->{ini}; my $dini = $this->{dini}; $this->UpdateParameters(); $this->BuildLayerModel(0, 1); my $optimize = $this->{Optimize}; my $Method = $this->{ChooseLSQMethodListBox}->GetText(); my $FitTo = $this->{ChooseFitToListBox}->GetText(); print "Method: $Method\n"; print "Fit to: $FitTo\n"; print "nMaxIter: $ini->{nMaxIter}\n"; my $el = $this->{Ellipsometry}; my $pObsE = $el->GetData('.*eV.*', '.*E.*'); my $pObsR = $el->GetData('R.*'); my $pObsT = $el->GetData('T.*'); #========================================================= # 最適化の実行 #========================================================= $optimize->SetnS2Calculation(0); # $this->{nS2} = 0; my ($OptVars, $MinVal) = $optimize->Optimize( $Method, undef, undef, undef, $ini->{EPS}, $ini->{nMaxIter}, $ini->{iPrintLevel}, sub { $this->CalS2($FitTo, $pObsE, $pObsR, $pObsT, @_); }, undef, sub { Optimize::BuildDifferentialMatrixes(@_); }, ); print "\nOptimized at:\n"; $optimize->PrintParameters(1); $optimize->RecoverParameters($OptVars); $this->SetS2($MinVal); $this->UpdateParameters(); } sub CalS2 { my ($this, $FitTo, $pObsE, $pObsR, $pObsT, $pVars, $iPrintLevel) = @_; #print "pVars=", join(',', @$pVars); my $optimize = $this->{Optimize}; my $ini = $this->{ini}; $optimize->RecoverParameters($pVars); # $this->UpdateParameters(); $this->BuildLayerModel(0, 0); my ($pE, $pR, $pT, $S2) = $this->CalRTArrays($this->{Layers}, $pObsE, $pObsR, $pObsT, $FitTo); $optimize->IncrementnS2(); my $nS2 = $optimize->nS2Calculation(); my $nS2Interval = $ini->{nSaveSpectraInterval}; print "S2[$nS2] = $S2 / "; $S2 += $optimize->CalPenalty(1.0e10, $pVars, 1); print "$S2\n"; $optimize->PrintParameters(1, $pVars, $S2, 0); if($nS2Interval > 0 and $nS2 % $nS2Interval == 0) { $this->Recalc(); # $this->CreateGraphFrame(); $this->AssignGraphData(0); $this->Draw(); } $this->UpdateParameters(); $this->mw()->update(); return $S2; } sub CalRT { my ($this, $E, $Layers) = @_; my $ini = $this->{ini}; # my ($Rtots, $Rtotp, $Ttots, $Ttotp) = $Layers->CalEpsRTForSubstrate($E, $this->{ini}->{Angle}); $Layers->SetIncidentAngle($ini->{TAngle}); $this->{Ellipsometry}->SetIncidentAngle($ini->{TAngle}); my ($rs123, $rp123, $ts123, $tp123, $Rtots, $Rtotp, $Ttots, $Ttotp) = $Layers->CalFresnelCoefficient($E); if(abs($ini->{TAngle} - $ini->{RAngle}) > 0.1) { $Layers->SetIncidentAngle($ini->{RAngle}); $this->{Ellipsometry}->SetIncidentAngle($ini->{RAngle}); my ($rs123r, $rp123r, $ts123r, $tp123r, $Rtotsr, $Rtotpr, $Ttotsr, $Ttotpr) = $Layers->CalFresnelCoefficient($E); $rs123 = $rs123r; $rp123 = $rp123r; $Rtots = $Rtotsr; $Rtotp = $Rtotpr; } return ($Rtots, $Rtotp, $Ttots, $Ttotp); } sub CalRTArrays { my ($this, $Layers, $pObsE, $pObsR, $pObsT, $FitTo) = @_; my $ini = $this->{ini}; $Layers->SetIncidentAngle($ini->{TAngle}); $this->{Ellipsometry}->SetIncidentAngle($ini->{TAngle}); my $nData = @$pObsE; my (@E, @R, @T); my $S2 = 0.0; my $c = 0; for(my $i = 0 ; $i < $nData ; $i++) { next if($ini->{nSkipData} > 0 and $i % $ini->{nSkipData} != 0); my $E = $pObsE->[$i]; next if($E < $ini->{FitEmin} or $ini->{FitEmax} < $E); my $lwl = $ini->{Rayleighl0} / Optics::eVTonm($E); my $lwl2 = $lwl * $lwl; my $sf = $ini->{Scale} - $lwl2 * $lwl2; my ($Rs, $Rp, $Ts, $Tp) = $this->CalRT($E, $Layers); if(abs($ini->{TAngle} - $ini->{RAngle}) > 0.1) { $Layers->SetIncidentAngle($ini->{RAngle}); $this->{Ellipsometry}->SetIncidentAngle($ini->{RAngle}); my ($Rsr, $Rpr, $Tsr, $Tpr) = $this->CalRT($E, $Layers); $Rs = $Rsr; $Rp = $Rpr; } #print "$E,[$i]: $rs, $rp\n"; my $R = ($Rs + $Rp) / 2.0; my $T = ($Ts + $Tp) / 2.0; $E[$c] = $E; $R[$c] = $R; $T[$c] = $T; if($FitTo eq 'RT' and $pObsR and $pObsT) { my $dT = ($pObsT->[$i] * $sf - $T); my $dR = ($pObsR->[$i] * $sf - $R); $S2 += $dT * $dT + $dR * $dR; } elsif($FitTo eq 'R' and $pObsR) { my $d = ($pObsR->[$i] * $sf - $R); $S2 += $d * $d; } elsif($FitTo eq 'T' and $pObsT) { my $d = ($pObsT->[$i] * $sf - $T); $S2 += $d * $d; } else { print "Error: Invalid Fitting Target [$FitTo].\n"; return; } $c++; } $S2 = sqrt($S2 / $c); return (\@E, \@R, \@T, $S2); } sub ReadParameterFile { my ($this, $filepath) = @_; my $DirectorySeparator = Deps::DirectorySeparator(); my $RegSeparator = Utils::RegExpQuote($DirectorySeparator); my $ini = $this->{ini}; my $dini = $this->{dini}; $this->Initialize(1, 1); $this->App()->print("\nRead paramter from [$filepath].\n"); $this->{ini}->ReadAll($filepath); $this->{ini}->{ParameterFile} = $filepath; $this->DecomposeParameters($ini, $dini); $this->{ChooseLSQMethodListBox}->SetText($this->{ini}->{Method}) if($this->{ChooseLSQMethodListBox}); $this->{ChooseFitToListBox}->SetText($this->{ini}->{FitTo}) if($this->{ChooseFitToListBox}); $this->{ChooseLayerModelListBox}->SetText($this->{ini}->{LayerModel}) if($this->{ChooseLayerModelListBox}); $this->{ChooseModelListBox}->SetText($this->{ini}->{Model}) if($this->{ChooseModelListBox} and $this->{ini}->{Model}); $this->{ChooseXListBox}->SetText($this->{ini}->{X}) if($this->{ChooseXListBox} and $this->{ini}->{X}); $this->{ChooseY1ListBox}->SetText($this->{ini}->{Y1}) if($this->{ChooseY1ListBox} and $this->{ini}->{Y1}); $this->{ChooseY2ListBox}->SetText($this->{ini}->{Y2}) if($this->{ChooseY2ListBox} and $this->{ini}->{Y2}); if($this->{ini}->{SampleCSVFile}) { # my $ret = $this->ReadSampleDataFile($this->{ini}->{SampleCSVFile}, 1, 0); my $ret; if(-e $this->{ini}->{SampleCSVFile}) { $ret = $this->ReadSampleDataFile($this->{ini}->{SampleCSVFile}, 1, 0, 0); } unless($ret) { my ($drive0, $directory0, $filename0, $ext0, $lastdir0, $filebody0) = Deps::SplitFilePath($this->{ini}->{ParameterFile}); my ($drive1, $directory1, $filename1, $ext1, $lastdir1, $filebody1) = Deps::SplitFilePath($filepath); $this->{ini}->{SampleCSVFile} =~ s/\//$DirectorySeparator/g; my $RelPath = Utils::MakeRelativePath($this->{ini}->{SampleCSVFile}, "$drive0$directory0"); $RelPath =~ s/^\.$RegSeparator/$drive1$directory1/; if(-e $RelPath) { $ret = $this->ReadSampleDataFile($RelPath, 1, 0, 0); } unless($ret) { ($drive0, $directory0, $filename0, $ext0, $lastdir0, $filebody0) = Deps::SplitFilePath($filepath); ($drive1, $directory1, $filename1, $ext1, $lastdir1, $filebody1) = Deps::SplitFilePath($this->{ini}->{SampleCSVFile}); my $f = Deps::MakePath("$drive0$directory0", $filename1, 0); $ret = $this->ReadSampleDataFile($f, 1, 0, 0); return undef unless($ret); $this->{ini}->{SampleCSVFile} = $f; } else { $this->{ini}->{SampleCSVFile} = $RelPath; } } # return undef unless($ret); } if($this->{ini}->{SubstrateCSVFile}) { my $ret = $this->ReadSubstrateDataFile($this->{ini}->{SubstrateCSVFile}, 1, 0); return undef unless($ret); } return 1; } sub ReadSampleDataFile { my ($this, $filepath, $IsPrint) = @_; my $App = $this->App(); #print "type=$type\n"; $this->Initialize(0, 1); $this->{Path} = $filepath; my ($nData, $pLabelArray, @pDataArray) = $this->{Ellipsometry}->Read($filepath); if(!defined $nData) { $App->print("Error: Can not read [$filepath].\n"); return $this->{Path} = undef; } my $nDataArray = $this->{Ellipsometry}->nDataArray(); #print "nDataArray: $nDataArray\n"; $this->{"ChooseXListBox"}->DeleteAllItem(); $this->{"ChooseY1ListBox"}->DeleteAllItem(); $this->{"ChooseY2ListBox"}->DeleteAllItem(); for(my $i = 0 ; $i < $nDataArray ; $i++) { #print "$i: $pLabelArray->[$i]\n"; $this->{"ChooseXListBox"}->AddItem($pLabelArray->[$i]); $this->{"ChooseY1ListBox"}->AddItem($pLabelArray->[$i]); $this->{"ChooseY2ListBox"}->AddItem($pLabelArray->[$i]); } $this->{"ChooseXListBox"}->SetCurSel('.*E.*', '.*eV.*'); $this->{"ChooseY1ListBox"}->SetCurSel('R', 'e1', 'n', 'Psi'); $this->{"ChooseY2ListBox"}->SetCurSel('T', 'e2', 'k', 'Delta'); $this->CreateGraphFrame(); $this->AssignGraphData(); return $filepath; } sub ReadSubstrateDataFile { my ($this, $filepath, $IsPrint) = @_; my $App = $this->App(); #print "type=$type\n"; $this->{Layers} = undef; $this->{Optimize} = undef; $this->{Substrate} = new Ellipsometry; $this->{SubstratePath} = $filepath; my ($nData, $pLabelArray, @pDataArray) = $this->{Substrate}->Read($filepath); if(!defined $nData) { $App->print("Error: Can not read [$filepath].\n"); return $this->{SubstratePath} = undef; } # $this->CreateGraphFrame(); # $this->AssignGraphData(); return $filepath; } sub CreateGraphFrame { my ($this, $canvas, $TargetData) = @_; $canvas = $this->Canvas(); my $App = $this->App(); my $font = $App->{'GraphFrameFont'}; my @font = split(/,/, $font) if($font); my $w = $canvas->width(); my $h = $canvas->height(); # my $FileType = $this->FileType(); # return undef unless($FileType); # my $pDataArray = $this->DataArray(); # return unless($pDataArray); my $GraphFrameArray = $this->{'GraphFrameArray'} = new GraphFrameArray($this->mw()); $GraphFrameArray->SetCanvasSize($w, $h); $GraphFrameArray->AddGraphFrame(); my $GraphFrame0 = $GraphFrameArray->GetGraphFrame(0); my $FramePosStr0 = $App->{"GraphFrame0Position"}; $GraphFrame0->SetXCaption(""); my $XScale0 = $GraphFrame0->GetXScale(0); my $YScale0 = $GraphFrame0->GetYScale(0); $GraphFrame0->SetPositionByStr($FramePosStr0); $XScale0->SetScaleStringVisible(0); $XScale0->SetCaptionVisible(1); $GraphFrameArray->AddGraphFrame(); my $GraphFrame1 = $GraphFrameArray->GetGraphFrame(1); $GraphFrame1->SetYCaption(""); my $FramePosStr1 = $App->{"GraphFrame1Position"}; my $XScale1 = $GraphFrame1->GetXScale(0); my $YScale1 = $GraphFrame1->GetYScale(0); $GraphFrame1->SetPositionByStr($FramePosStr1); $XScale1->SetScaleStringVisible(1); $XScale1->SetCaptionVisible(1); $GraphFrame0->SetViewRange(0, 0, 1, 1); $GraphFrame1->SetViewRange(0, 0, 1, 1); } sub ShowScaleDialog { my ($this, $GraphFrame, $command, $Title, @a) = @_; #$command: "XScale" "YScale" #最初の4つのundefはViewRangeに現在値を使う #次の2つのundefはPlotTypeに現在値を使う設定 #そのあとの1,0は、X,Y軸のPlotTypeの同期をおこなうかどうか #最後の1は、ScaleDialogでOKを押されたらグラフの再描画を行う #  Y軸のViewRangeは同期するが、PlotTypeの同期は無視する return $GraphFrame->ShowScaleDialog($Title, undef, undef, undef, undef, undef, undef, 1, 0, 1); } sub AdjustViewRange($$) { my ($this) = @_; my $GraphFrameArray = $this->GetGraphFrameArray(); my $GraphFrame0 = $GraphFrameArray->GetGraphFrame(0); $GraphFrame0->SetViewRange($GraphFrame0->GetViewRange(), 1) if($GraphFrame0); } sub AssignGraphData { my ($this, $ResetViewRange) = @_; $ResetViewRange = 1 if(!defined $ResetViewRange); my $GraphFrameArray = $this->GetGraphFrameArray(); my $GraphFrame0 = $GraphFrameArray->GetGraphFrame(0); my $GraphFrame1 = $GraphFrameArray->GetGraphFrame(1); $GraphFrame0->ClearAllData(); $GraphFrame1->ClearAllData(); my $XLabel = $this->{"ChooseXListBox"}->GetText(); $XLabel = 'X' if(!$XLabel); my $Y1Label = $this->{"ChooseY1ListBox"}->GetText(); $Y1Label = 'Y1' if(!$Y1Label); my $Y2Label = $this->{"ChooseY2ListBox"}->GetText(); $Y2Label = 'Y2' if(!$Y2Label); $GraphFrame0->SetXCaption($XLabel); my $pX = $this->{Ellipsometry}->GetData($XLabel, '.*E.*', '.*eV.*'); my $pY1 = $this->{Ellipsometry}->GetData($Y1Label); my $pY2 = $this->{Ellipsometry}->GetData($Y2Label); my $nData = $this->{Ellipsometry}->nData(); my $YLabel = ''; $YLabel .= $Y1Label if($pY1); $YLabel .= ",$Y2Label" if($pY2); $GraphFrame0->SetXCaption(""); $GraphFrame0->SetYCaption("$Y1Label,$Y2Label"); if($pX) { my $ini = $this->{ini}; my (@y1, @y2); for(my $i = 0 ; $i < @$pX ; $i++) { my $E = $pX->[$i]; my $lwl = $ini->{Rayleighl0} / Optics::eVTonm($E); my $lwl2 = $lwl * $lwl; my $sf = $ini->{Scale} - $lwl2 * $lwl2; if($pY1) { $y1[$i] = $pY1->[$i] * $sf; } if($pY2) { $y2[$i] = $pY2->[$i] * $sf; } } $GraphFrame1->AddGraphData($pX, \@y1, 2, "black", "", 6, "red", 0, "red", "XAutoSkip", "Energy", "${Y1Label}(obs)") if($pY1); $GraphFrame1->AddGraphData($pX, \@y2, 2, "red", "", 6, "red", 0, "red", "XAutoSkip", "Energy", "${Y2Label}(obs)") if($pY2); } my $pCalE = $this->{pEArray}; my $pCalR = $this->{pRArray}; my $pCalT = $this->{pTArray}; my $pCalRExc = $this->{pRExcArray}; my $pCalTExc = $this->{pTExcArray}; if($pCalE) { $GraphFrame0->AddGraphData($pCalE, $pCalT, 0, "black", "circle", 3, "", 1, "black", "XAutoSkip", "Energy", "T(non-excited,cal)") if($pCalT); $GraphFrame0->AddGraphData($pCalE, $pCalTExc, 0, "red", "circle", 3, "", 1, "red", "XAutoSkip", "Energy", "T(excited,cal)") if($pCalTExc); } if($pCalT and $pCalTExc) { my $nData = @$pCalT; my @RelT; for(my $i = 0 ; $i < $nData ; $i++) { $RelT[$i] = $pCalTExc->[$i] / $pCalT->[$i]; } $GraphFrame1->AddGraphData($pCalE, \@RelT, 0, "black", "circle", 3, "", 1, "black", "XAutoSkip", "Energy", "Relative T(cal)"); } $GraphFrame0->SetYScalePlotType('x'); $GraphFrame1->SetYScalePlotType('x'); $GraphFrame1->SetXCaption("Energy / eV"); $GraphFrame1->SetYCaption(""); if($GraphFrame1) { $GraphFrame0->AddSynchronousFrame('x', $GraphFrame1); $GraphFrame1->AddSynchronousFrame('x', $GraphFrame0); } if($ResetViewRange) { print "CalMinMax\n"; $GraphFrame0->CalMinMax(); $GraphFrame1->CalMinMax(); $GraphFrame0->AdjustViewRange(0.05, 0.05, 0.05, 0.05); $GraphFrame1->AdjustViewRange(0.05, 0.05, 0.05, 0.05); $GraphFrame0->SetViewRange($GraphFrame0->GetViewRange(), 1); } } 1;