| 1 |
## -*- cperl -*- |
| 2 |
## |
| 3 |
## This file is part of Athena, copyright (c) 2001-2010 Bruce Ravel |
| 4 |
## |
| 5 |
## This section of the code contains subroutines associated with |
| 6 |
## multi-electron excitation removal |
| 7 |
|
| 8 |
sub mee { |
| 9 |
Echo("No data!"), return unless $current; |
| 10 |
|
| 11 |
my $key = join("_", lc($groups{$current}->{bkg_z}), lc($groups{$current}->{fft_edge})); |
| 12 |
my %mee_params = ( |
| 13 |
shift => $groups{$current}->{mee_en} || $mee_energies{energies}{$key} || $config{mee}{shift}, |
| 14 |
width => $groups{$current}->{mee_wi} || $config{mee}{width}, |
| 15 |
amp => $groups{$current}->{mee_am} || $config{mee}{amp}, |
| 16 |
key => $key, |
| 17 |
choice => $groups{$current}->{mee_choice} || $config{mee}{choice} || 'Edge', |
| 18 |
); |
| 19 |
my $color = $plot_features{c1}; |
| 20 |
my $ps = $project_saved; |
| 21 |
my @save = ($plot_features{emin}, $plot_features{emax}); |
| 22 |
$plot_features{emin} = -200; #$config{mee}{emin}; |
| 23 |
$plot_features{emax} = 1100; #$config{mee}{emax}; |
| 24 |
project_state($ps); # don't toggle if currently saved |
| 25 |
|
| 26 |
Echo("No data!"), return if ($current eq "Default Parameters"); |
| 27 |
|
| 28 |
my @label = (-font=>$config{fonts}{small}, -foreground=>'black', ); |
| 29 |
|
| 30 |
$fat_showing = 'mee'; |
| 31 |
$hash_pointer = \%mee_params; |
| 32 |
map {$_ -> configure(-state=>'disabled')} |
| 33 |
($data_menu, $merge_menu, $anal_menu, $settings_menu); |
| 34 |
$fat -> packForget; |
| 35 |
my $mee = $container->Frame(@fatgeom, -relief=>'sunken', -borderwidth=>3) |
| 36 |
-> pack(-fill=>'both', -expand=>1); |
| 37 |
$which_showing = $mee; |
| 38 |
|
| 39 |
$mee -> Label(-text=>"Multi-electron excitation removal", |
| 40 |
-font=>$config{fonts}{large}, |
| 41 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 42 |
-> pack(-side=>'top', -fill=>'x', -anchor=>'w'); |
| 43 |
|
| 44 |
## select the alignment standard |
| 45 |
my $frame = $mee -> Frame(-borderwidth=>2, -relief=>'flat') |
| 46 |
-> pack(-side=>'top', -fill=>'x', -pady=>8); |
| 47 |
$frame -> Label(-text=>"Data: ", @label,) |
| 48 |
-> grid(-row=>0, -column=>0, -sticky=>'e', -ipady=>2); |
| 49 |
$widget{mee_data} = $frame -> Label(-text=>$groups{$current}->{label}, |
| 50 |
-foreground=>$config{colors}{button}) |
| 51 |
-> grid(-row=>0, -column=>1, -columnspan=>3, -sticky=>'w', -pady=>2, -padx=>2); |
| 52 |
|
| 53 |
my $t = $frame -> Label(-text=>"Functional form: ", @label,) |
| 54 |
-> grid(-row=>1, -column=>0, -sticky=>'e', -ipady=>2); |
| 55 |
$widget{mee_choice} = $frame -> Optionmenu(-textvariable => \$mee_params{choice}, |
| 56 |
-options => ['Edge', 'Arctangent'], |
| 57 |
-borderwidth => 1, |
| 58 |
-width=>10, -justify=>'right') |
| 59 |
-> grid(-row=>1, -column=>1, -sticky=>'w'); |
| 60 |
|
| 61 |
|
| 62 |
$t = $frame -> Label(-text=>"Energy offset: ", @label,) |
| 63 |
-> grid(-row=>2, -column=>0, -sticky=>'e', -ipady=>2); |
| 64 |
&click_help($t,"mee_en"); |
| 65 |
$widget{mee_en} = $frame -> RetEntry(-textvariable=>\$mee_params{shift}, |
| 66 |
-validate=>'key', |
| 67 |
-command=>sub{ mee_plot($config{mee}{plot}, \%mee_params)}, |
| 68 |
-validatecommand=>[\&set_variable, 'mee_en'], |
| 69 |
-width=>8) |
| 70 |
-> grid(-row=>2, -column=>1, -sticky=>'w', -pady=>2, -padx=>2); |
| 71 |
$frame -> Label(-text=>" eV", @label,) |
| 72 |
-> grid(-row=>2, -column=>2, -sticky=>'w', -ipady=>2); |
| 73 |
|
| 74 |
$t = $frame -> Label(-text=>"Broadening: ", @label,) |
| 75 |
-> grid(-row=>3, -column=>0, -sticky=>'e', -ipady=>2); |
| 76 |
&click_help($t,"mee_wi"); |
| 77 |
$widget{mee_wi} = $frame -> RetEntry(-textvariable=>\$mee_params{width}, |
| 78 |
-validate=>'key', |
| 79 |
-command=>sub{ mee_plot($config{mee}{plot}, \%mee_params)}, |
| 80 |
-validatecommand=>[\&set_variable, 'mee_wi'], |
| 81 |
-width=>8) |
| 82 |
-> grid(-row=>3, -column=>1, -sticky=>'w', -pady=>2, -padx=>2); |
| 83 |
$frame -> Label(-text=>" eV", @label,) |
| 84 |
-> grid(-row=>3, -column=>2, -sticky=>'w', -ipady=>2); |
| 85 |
|
| 86 |
$t = $frame -> Label(-text=>"Amplitude: ", @label,) |
| 87 |
-> grid(-row=>4, -column=>0, -sticky=>'e', -ipady=>2); |
| 88 |
&click_help($t,"mee_am"); |
| 89 |
$widget{mee_am} = $frame -> RetEntry(-textvariable=>\$mee_params{amp}, |
| 90 |
-validate=>'key', |
| 91 |
-command=>sub{ mee_plot($config{mee}{plot}, \%mee_params)}, |
| 92 |
-validatecommand=>[\&set_variable, 'mee_am'], |
| 93 |
-width=>8) |
| 94 |
-> grid(-row=>4, -column=>1, -sticky=>'w', -pady=>2, -padx=>2); |
| 95 |
|
| 96 |
$frame = $mee -> Frame(-borderwidth=>2, -relief=>'flat') |
| 97 |
-> pack(-side=>'top', -pady=>8, -fill=>'x'); |
| 98 |
$frame -> Label(-text=>"Plot data and correction in:", |
| 99 |
-foreground=>$config{colors}{activehighlightcolor}, |
| 100 |
) |
| 101 |
-> pack(-side=>'top', -fill=>'x', -pady=>2); |
| 102 |
my $fr = $frame -> Frame() |
| 103 |
-> pack(-side=>'top', -pady=>2, -fill=>'x', -expand=>1); |
| 104 |
$widget{mee_e} = $fr -> Button(-text => 'E', @button_list, |
| 105 |
-command => sub{mee_plot('e', \%mee_params)}) |
| 106 |
-> pack(-side=>'left', -padx=>2, -fill=>'x', -expand=>1); |
| 107 |
$widget{mee_k} = $fr -> Button(-text => 'k', @button_list, |
| 108 |
-command => sub{mee_plot('k', \%mee_params)}) |
| 109 |
-> pack(-side=>'left', -padx=>2, -fill=>'x', -expand=>1); |
| 110 |
$widget{mee_r} = $fr -> Button(-text => 'R', @button_list, |
| 111 |
-command => sub{mee_plot('r', \%mee_params)}) |
| 112 |
-> pack(-side=>'left', -padx=>2, -fill=>'x', -expand=>1); |
| 113 |
$widget{mee_q} = $fr -> Button(-text => 'q', @button_list, |
| 114 |
-command => sub{mee_plot('q', \%mee_params)}) |
| 115 |
-> pack(-side=>'left', -padx=>2, -fill=>'x', -expand=>1); |
| 116 |
$widget{mee_make} = $mee |
| 117 |
-> Button(-text=>"Make corrected data group", @button_list, |
| 118 |
-command=>sub{mee_group(\%mee_params)}) |
| 119 |
-> pack(-side=>'top', -fill=>'x', -anchor=>'w'); |
| 120 |
$widget{mee_store} = $mee |
| 121 |
-> Button(-text=>"Store this MEE offset energy", @button_list, |
| 122 |
-command=> |
| 123 |
sub { |
| 124 |
$mee_energies{energies}{$mee_params{key}} = $mee_params{shift}; |
| 125 |
my $tenergies = tied %mee_energies; |
| 126 |
$tenergies -> WriteConfig($groups{"Default Parameters"} -> find('athena', 'mee')); |
| 127 |
my $message = sprintf("Stored %s as the energy shift for the %s %s edge.", |
| 128 |
$mee_params{shift}, |
| 129 |
ucfirst($groups{$current}->{bkg_z}), |
| 130 |
ucfirst($groups{$current}->{fft_edge})); |
| 131 |
Echo($message); |
| 132 |
}) |
| 133 |
-> pack(-side=>'top', -fill=>'x', -anchor=>'w', -pady=>4); |
| 134 |
|
| 135 |
$mee -> Button(-text=>'Return to the main window', @button_list, |
| 136 |
-background=>$config{colors}{background2}, |
| 137 |
-activebackground=>$config{colors}{activebackground2}, |
| 138 |
-command=>sub{ |
| 139 |
&reset_window($mee, "multi-electron removal", \@save); |
| 140 |
}) |
| 141 |
-> pack(-side=>'bottom', -fill=>'x'); |
| 142 |
## help button |
| 143 |
$mee -> Button(-text=>'Document section: multi-electron excitation removal', @button_list, |
| 144 |
-command=>sub{pod_display("process::mee.pod")}) |
| 145 |
-> pack(-side=>'bottom', -fill=>'x', -pady=>4); |
| 146 |
|
| 147 |
if (not $groups{$current}->{is_xmu}) { |
| 148 |
map {$widget{"mee_$_"} -> configure(-state=>'disabled')} qw(store make e k r q); |
| 149 |
}; |
| 150 |
$top -> update; |
| 151 |
}; |
| 152 |
|
| 153 |
|
| 154 |
sub mee_correct { |
| 155 |
my ($rmp, $plot) = @_;; |
| 156 |
|
| 157 |
($groups{$current}->{update_bkg}) and $groups{$current}->dispatch_bkg($dmode); |
| 158 |
|
| 159 |
# A*[atan((e-E0)/W)/pi + 0.5] |
| 160 |
|
| 161 |
my $commands = q{}; |
| 162 |
if ($$rmp{choice} eq 'Edge') { |
| 163 |
$commands .= "##\n## performing multi-electron excitation removal using a reflection of the Edge\n"; |
| 164 |
$commands .= "set(m___ee.nn = lconvolve($current.energy, $current.norm, $$rmp{width}),\n"; |
| 165 |
$commands .= " m___ee.energy = $current.energy,\n"; |
| 166 |
$commands .= " m___ee.ee = m___ee.energy + $$rmp{shift},\n"; |
| 167 |
$commands .= " m___ee.xint = interp(m___ee.ee, m___ee.nn, $current.energy))\n"; |
| 168 |
$commands .= "## use perl to pad zeros at the beginning of the shifted array\n"; |
| 169 |
$groups{$current} -> dispose($commands, $dmode); |
| 170 |
|
| 171 |
my @x = Ifeffit::get_array("$current.energy"); |
| 172 |
my $e1 = $x[0] + $$rmp{shift}; |
| 173 |
my @y = Ifeffit::get_array("m___ee.xint"); |
| 174 |
my $yoff = 0; |
| 175 |
my $edgestep = $groups{$current}->{bkg_step}; |
| 176 |
foreach my $i (0 .. $#x) { |
| 177 |
if ($x[$i] < $e1) { |
| 178 |
## this replaces the extrapolated part of the shifted spectrum |
| 179 |
## with zeros in the pre-edge |
| 180 |
$yoff = $y[$i]; |
| 181 |
$y[$i] = 0; |
| 182 |
} else { |
| 183 |
## this corrects for the pre-edge not going to the baseline |
| 184 |
## after the convolution and approximately corrects the edge |
| 185 |
## step of the convoluted mu(E) data |
| 186 |
## $y[$i] = ($y[$i] - $yoff);# * (1 + $yoff); |
| 187 |
}; |
| 188 |
}; |
| 189 |
Ifeffit::put_array("m___ee.xint", \@y); |
| 190 |
} else { |
| 191 |
my $e0 = $groups{$current}->{bkg_e0}+$$rmp{shift}; |
| 192 |
$commands .= "##\n## performing multi-electron excitation removal using an arctangent\n"; |
| 193 |
$commands .= "set(m___ee.energy = $current.energy,\n"; |
| 194 |
$commands .= " m___ee.xint = atan((m___ee.energy-$e0)/$$rmp{width})/pi + 0.5 )\n"; |
| 195 |
|
| 196 |
}; |
| 197 |
|
| 198 |
$commands .= "set(m___ee.xmu = $current.norm - $$rmp{amp}*m___ee.xint)\n"; |
| 199 |
$groups{$current} -> dispose($commands, $dmode); |
| 200 |
|
| 201 |
mee_plot($config{mee}{plot}, $rmp) if $plot; |
| 202 |
|
| 203 |
|
| 204 |
#$groups{$current} -> plotE('em',$dmode,\%plot_features, \@indicator); |
| 205 |
#$groups{$current} -> dispose("plot($current.energy, m___ee.corr)"); |
| 206 |
|
| 207 |
}; |
| 208 |
|
| 209 |
sub mee_plot { |
| 210 |
my ($space, $rmp) = @_; |
| 211 |
Echonow("Correcting multi-electron excitation in \"$groups{$current}->{label}\" ..."); |
| 212 |
$top->Busy; |
| 213 |
my $mode = $dmode; |
| 214 |
($mode & 2) or ($mode += 2); |
| 215 |
@ifeffit_buffer = (); |
| 216 |
mee_correct($rmp, 0); |
| 217 |
my $save = $groups{$current}->{bkg_flatten}; |
| 218 |
$groups{$current} -> make(update_bkg=>1, bkg_flatten=>0); |
| 219 |
my $command = q{}; |
| 220 |
SWITCH: { |
| 221 |
($space eq 'e') and do { |
| 222 |
$groups{$current} -> plotE('emn',$mode,\%plot_features, \@indicator); |
| 223 |
last SWITCH; |
| 224 |
}; |
| 225 |
($space eq 'k') and do { |
| 226 |
$groups{$current} -> plotk('k',$mode,\%plot_features, \@indicator); |
| 227 |
last SWITCH; |
| 228 |
}; |
| 229 |
($space eq 'r') and do { |
| 230 |
my $str = $plot_features{r_marked}; |
| 231 |
$groups{$current} -> plotR($str,$mode,\%plot_features, \@indicator); |
| 232 |
last SWITCH; |
| 233 |
}; |
| 234 |
($space eq 'q') and do { |
| 235 |
my $str = $plot_features{q_marked}; |
| 236 |
$groups{$current} -> plotq($str,$mode,\%plot_features, \@indicator); |
| 237 |
last SWITCH; |
| 238 |
}; |
| 239 |
}; |
| 240 |
foreach my $line (@ifeffit_buffer) { |
| 241 |
($command .= $line) =~ s{$current\.}{m___ee.}g; |
| 242 |
}; |
| 243 |
$command =~ s{newplot}{plot}g; |
| 244 |
$command =~ s{\.norm}{.xmu}g; |
| 245 |
$command =~ s{pre1=}{find_e0=F, pre1=}g; |
| 246 |
$command =~ s{$config{plot}{c0}}{$config{plot}{c1}}g; |
| 247 |
@ifeffit_buffer = (); |
| 248 |
## print $command; |
| 249 |
$groups{$current} -> dispose($command, $dmode); |
| 250 |
$groups{$current} -> make(bkg_flatten=>$save); |
| 251 |
Echonow("Correcting multi-electron excitation in \"$groups{$current}->{label}\" ... done!"); |
| 252 |
$top->Unbusy; |
| 253 |
}; |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
## make a new data group out of the mee-corrected data, make this an |
| 258 |
## xmu group so it can be treated like normal data |
| 259 |
sub mee_group { |
| 260 |
my $rhash = $_[0]; |
| 261 |
$top->Busy; |
| 262 |
mee_correct($rhash, 0); |
| 263 |
my $group = $groups{$current}->{group}; |
| 264 |
my ($new, $label) = group_name("MEE $group"); |
| 265 |
$label = "MEE " . $groups{$current}->{label} . ": e " . $$rhash{shift} . " a " . $$rhash{amp}; |
| 266 |
$groups{$new} = Ifeffit::Group -> new(group=>$new, label=>$label); |
| 267 |
$groups{$new} -> set_to_another($groups{$group}); |
| 268 |
$groups{$new} -> make(is_xmu => 1, is_chi => 0, is_rsp => 0, |
| 269 |
is_qsp => 0, is_bkg => 0, is_nor => 1, |
| 270 |
not_data => 0); |
| 271 |
$groups{$new} -> make(bkg_e0 => $groups{$group}->{bkg_e0}); |
| 272 |
$groups{$new} -> make(file => "MEE correction using $$rhash{choice} of $groups{$current}->{label} at $$rhash{shift} eV"); |
| 273 |
$groups{$new}->{titles} = []; |
| 274 |
push @{$groups{$new}->{titles}}, |
| 275 |
"MEE correction using $$rhash{choice} of $groups{$current}->{label}: shift=$$rhash{shift} eV", |
| 276 |
"broadening=$$rhash{width}, amplitude=$$rhash{amp}"; |
| 277 |
$groups{$new} -> put_titles; |
| 278 |
$groups{$new} -> dispose("set($new.energy = $group.energy, $new.xmu = m___ee.xmu)", $dmode); |
| 279 |
++$line_count; |
| 280 |
$reading_project = 1; # sloppy ... see main_window.pl |
| 281 |
fill_skinny($list, $new, 1, 1); |
| 282 |
$reading_project = 0; |
| 283 |
project_state(0); |
| 284 |
my $memory_ok = $groups{$new} |
| 285 |
-> memory_check($top, \&Echo, \%groups, $max_heap, 0, 0); |
| 286 |
Echo("WARNING: Ifeffit is out of memory!"), return if ($memory_ok == -1); |
| 287 |
Echo("Saved MEE correction of \"$groups{$current}->{label}\" as a new data group"); |
| 288 |
$top->Unbusy; |
| 289 |
}; |