| 1 |
package Ifeffit::Group; # -*- cperl -*- |
| 2 |
###################################################################### |
| 3 |
## Ifeffit::Group: Object oriented data group manipulation for Ifeffit |
| 4 |
## |
| 5 |
## Athena is copyright (c) 2001-2010 Bruce Ravel |
| 6 |
## bravel AT bnl DOT gov |
| 7 |
## http://cars9.uchicago.edu/~ravel/software/ |
| 8 |
## |
| 9 |
## Ifeffit is copyright (c) 1992-2010 Matt Newville |
| 10 |
## newville AT cars DOT uchicago DOT edu |
| 11 |
## http://cars9.uchicago.edu/~newville/ifeffit/ |
| 12 |
## |
| 13 |
## The latest version of Athena can always be found at |
| 14 |
## http://cars9.uchicago.edu/~ravel/software/ |
| 15 |
## |
| 16 |
## ------------------------------------------------------------------- |
| 17 |
## All rights reserved. This program is free software; you can |
| 18 |
## redistribute it and/or modify it provided that the above notice |
| 19 |
## of copyright, these terms of use, and the disclaimer of |
| 20 |
## warranty below appear in the source code and documentation, and |
| 21 |
## that none of the names of NIST, Argonne National Laboratory, |
| 22 |
## The Naval Research Laboratory, The University of Chicago, |
| 23 |
## University of Washington, or the authors appear in advertising |
| 24 |
## or endorsement of works derived from this software without |
| 25 |
## specific prior written permission from all parties. |
| 26 |
## |
| 27 |
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 28 |
## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 29 |
## OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 30 |
## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 31 |
## HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 32 |
## WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 33 |
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 34 |
## OTHER DEALINGS IN THIS SOFTWARE. |
| 35 |
## ------------------------------------------------------------------- |
| 36 |
###################################################################### |
| 37 |
|
| 38 |
use strict; |
| 39 |
use vars qw($VERSION $cvs_info $module_version @ISA @EXPORT @EXPORT_OK); |
| 40 |
use constant ETOK=>0.262468292; |
| 41 |
use Text::Wrap; |
| 42 |
use Ifeffit; |
| 43 |
use Ifeffit::Tools; |
| 44 |
use Ifeffit::FindFile; |
| 45 |
use Chemistry::Elements qw(get_Z); |
| 46 |
use File::Basename; |
| 47 |
use constant EPSILON => 1e-8; |
| 48 |
use constant DELTA => 1e-3; |
| 49 |
|
| 50 |
require Exporter; |
| 51 |
|
| 52 |
@ISA = qw(Exporter AutoLoader Ifeffit::Tools Ifeffit::FindFile); |
| 53 |
@EXPORT_OK = qw(); |
| 54 |
|
| 55 |
$VERSION = "0.8.061"; |
| 56 |
$cvs_info = '$Id: $ '; |
| 57 |
$module_version = (split(' ', $cvs_info))[2] || 'pre_release'; |
| 58 |
|
| 59 |
my $echocmd = \&::Echonow; |
| 60 |
my $errorcmd = \&::Error; |
| 61 |
my $rpf = \%::plot_features; |
| 62 |
use vars qw($rmax_out); |
| 63 |
$rmax_out = 10; |
| 64 |
my $is_windows = (($^O eq 'MSWin32') or ($^O eq 'cygwin')); |
| 65 |
my @done = (" ... done!", 1); |
| 66 |
my $screen; |
| 67 |
my $default = Ifeffit::Group -> new(not_data=>1); |
| 68 |
use vars qw/$last_plot/; |
| 69 |
|
| 70 |
|
| 71 |
use vars qw/$thisdir $libdir/; |
| 72 |
use File::Spec; |
| 73 |
$thisdir = $Ifeffit::FindFile::thisdir; |
| 74 |
$libdir = File::Spec->catfile($thisdir, "lib", "athena"); |
| 75 |
#$libdir =~ s/^\//\.\//; |
| 76 |
my %clamp = ("Slight" => 3, "Weak" => 6, "Medium" =>12, "Strong" => 24, "Rigid" => 96); |
| 77 |
|
| 78 |
|
| 79 |
## the use of the $default to set the default values allows the user |
| 80 |
## the options of changing these defaults while using Athena. |
| 81 |
sub new { |
| 82 |
my $classname = shift; |
| 83 |
my $self = {}; |
| 84 |
|
| 85 |
$self->{line} = 0; # meta data |
| 86 |
$self->{group} = ""; |
| 87 |
$self->{is_xmu} = 0; |
| 88 |
$self->{is_xmudat} = 0; |
| 89 |
$self->{is_nor} = 0; |
| 90 |
$self->{is_xanes} = 0; |
| 91 |
$self->{is_chi} = 0; |
| 92 |
$self->{is_rsp} = 0; |
| 93 |
$self->{is_qsp} = 0; |
| 94 |
$self->{is_merge} = 0; |
| 95 |
$self->{is_diff} = 0; |
| 96 |
$self->{is_bkg} = 0; |
| 97 |
$self->{not_data} = 0; |
| 98 |
$self->{is_pixel} = 0; |
| 99 |
$self->{is_proj} = 0; |
| 100 |
$self->{reference} = 0; |
| 101 |
$self->{refsame} = 0; |
| 102 |
$self->{is_ref} = 0; |
| 103 |
|
| 104 |
$self->{is_raw} = 0; # raw data files |
| 105 |
$self->{is_rec} = 0; |
| 106 |
$self->{en_str} = ""; |
| 107 |
$self->{mu_str} = ""; |
| 108 |
|
| 109 |
$self->{file} = ""; # data input parameters |
| 110 |
$self->{ecol} = 1; |
| 111 |
$self->{xcol} = 2; |
| 112 |
$self->{importance} = 1; |
| 113 |
|
| 114 |
$self->{bkg_e0} = 0; # background removal parameters |
| 115 |
$self->{bkg_kw} = (exists $default->{bkg_kw}) ? $default->{bkg_kw} : 1; |
| 116 |
$self->{bkg_rbkg} = (exists $default->{bkg_rbkg}) ? $default->{bkg_rbkg} : 1; |
| 117 |
$self->{bkg_dk} = 0; |
| 118 |
$self->{bkg_pre1} = (exists $default->{bkg_pre1}) ? $default->{bkg_pre1} : -150; |
| 119 |
$self->{bkg_pre2} = (exists $default->{bkg_pre2}) ? $default->{bkg_pre2} : -30; |
| 120 |
$self->{bkg_nor1} = (exists $default->{bkg_nor1}) ? $default->{bkg_nor1} : 100; |
| 121 |
$self->{bkg_nor2} = (exists $default->{bkg_nor2}) ? $default->{bkg_nor2} : 400; |
| 122 |
$self->{bkg_spl1} = (exists $default->{bkg_spl1}) ? $default->{bkg_spl1} : 0.5; |
| 123 |
$self->{bkg_spl2} = (exists $default->{bkg_spl2}) ? $default->{bkg_spl2} : 12; |
| 124 |
$self->{bkg_spl1e} = 0; |
| 125 |
$self->{bkg_spl2e} = 0; |
| 126 |
$self->{bkg_win} = $default->{bkg_win} || "kaiser-bessel"; |
| 127 |
$self->{bkg_slope} = 0; # these six are set whenever |
| 128 |
$self->{bkg_int} = 0; # a background is removed |
| 129 |
$self->{bkg_step} = 0; |
| 130 |
$self->{bkg_fitted_step} = 0; |
| 131 |
$self->{bkg_fixstep} = 0; |
| 132 |
$self->{bkg_nc0} = 0; |
| 133 |
$self->{bkg_nc1} = 0; |
| 134 |
$self->{bkg_nc2} = 0; |
| 135 |
$self->{bkg_flatten} = (exists $default->{bkg_flatten}) ? $default->{bkg_flatten} : 0; |
| 136 |
$self->{bkg_fnorm} = (exists $default->{bkg_fnorm}) ? $default->{bkg_fnorm} : 0; |
| 137 |
$self->{bkg_nnorm} = (exists $default->{bkg_nnorm}) ? $default->{bkg_nnorm} : 3; |
| 138 |
$self->{bkg_stan} = 'None'; |
| 139 |
$self->{bkg_stan_lab} = '0: None'; |
| 140 |
$self->{bkg_clamp1} = $default->{bkg_clamp1} || 'None'; |
| 141 |
$self->{bkg_clamp2} = $default->{bkg_clamp2} || 'Strong'; |
| 142 |
##$self->{bkg_nclamp} = 5; |
| 143 |
$self->{bkg_tie_e0} = 0; |
| 144 |
$self->{bkg_former_e0} = 0; |
| 145 |
|
| 146 |
$self->{bkg_z} = 'H'; # Cromer-Liberman parameters |
| 147 |
$self->{bkg_cl} = 0; |
| 148 |
|
| 149 |
$self->{fft_arbkw} = $default->{fft_arbkw} || 0.5; # forward FT parameters |
| 150 |
$self->{fft_win} = $default->{fft_win} || "kaiser-bessel"; |
| 151 |
$self->{fft_dk} = (exists $default->{fft_dk}) ? $default->{fft_dk} : 2; |
| 152 |
$self->{fft_kmin} = (exists $default->{fft_kmin}) ? $default->{fft_kmin} : 2; |
| 153 |
$self->{fft_kmax} = (exists $default->{fft_kmax}) ? $default->{fft_kmax} : 12; |
| 154 |
$self->{fft_pc} = $default->{fft_pc} || 'off'; |
| 155 |
$self->{fft_edge} = 'K'; |
| 156 |
|
| 157 |
$self->{bft_win} = $default->{bft_win} || "kaiser-bessel"; # back FT parameters |
| 158 |
$self->{bft_rmin} = (exists $default->{bft_rmin}) ? $default->{bft_rmin} : 1; |
| 159 |
$self->{bft_rmax} = (exists $default->{bft_rmax}) ? $default->{bft_rmax} : 3; |
| 160 |
$self->{bft_dr} = (exists $default->{bft_dr}) ? $default->{bft_dr} : 0.5; |
| 161 |
|
| 162 |
$self->{update_bkg} = 1; # these are for flagging chores that need |
| 163 |
$self->{update_fft} = 1; # to be done |
| 164 |
$self->{update_bft} = 1; |
| 165 |
$self->{frozen} = 0; |
| 166 |
|
| 167 |
$self->{check} = 0; # canvas id's of checkbutton, text, |
| 168 |
$self->{rect} = 0; # and rectangle so I can easily |
| 169 |
$self->{text} = 0; # manipulate the group list |
| 170 |
|
| 171 |
$self->{bkg_eshift} = 0; |
| 172 |
$self->{deg_tol} = 0; # deglitching tolerance |
| 173 |
|
| 174 |
$self->{plot_scale} = 1; # plotting parameters |
| 175 |
$self->{plot_yoffset} = 0; |
| 176 |
|
| 177 |
$self->{detectors} = []; # communication with daughter |
| 178 |
$self->{numerator} = ""; # detector groups |
| 179 |
$self->{denominator} = ""; |
| 180 |
$self->{i0} = 0; |
| 181 |
|
| 182 |
$self->{peak} = 0; # peak fit flag |
| 183 |
|
| 184 |
bless($self, $classname); |
| 185 |
$self -> make(@_); |
| 186 |
return $self; |
| 187 |
}; |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
###################################################################### |
| 192 |
## General group management methods |
| 193 |
|
| 194 |
## return a list of all parameter keys |
| 195 |
sub Keys { |
| 196 |
my $self = shift; |
| 197 |
return (qw(line file importance bkg_e0 bkg_kw bkg_rbkg |
| 198 |
bkg_pre1 bkg_pre2 bkg_nor1 bkg_nor2 bkg_spl1 bkg_spl2 |
| 199 |
bkg_spl1e bkg_spl2e bkg_stan bkg_stan_lab |
| 200 |
bkg_z bkg_cl bkg_nclamp |
| 201 |
bkg_clamp1 bkg_clamp2 bkg_eshift bkg_step bkg_fixstep |
| 202 |
bkg_fitted_step bkg_flatten bkg_fnorm |
| 203 |
fft_arbkw fft_dk fft_win fft_kmin fft_kmax fft_pc fft_edge |
| 204 |
bft_dr bft_win bft_rmin bft_rmax |
| 205 |
plot_scale plot_yoffset |
| 206 |
)); |
| 207 |
## bkg_dk bkg_win bkg_nclamp |
| 208 |
}; |
| 209 |
|
| 210 |
sub make { |
| 211 |
my $self = shift; |
| 212 |
unless ($#_ % 2) { |
| 213 |
my $this = (caller(0))[3]; |
| 214 |
die "$this error! Odd number of arguments.\n"; |
| 215 |
return; |
| 216 |
}; |
| 217 |
while (@_) { |
| 218 |
my $att = lc(shift); |
| 219 |
next if (($self->{frozen}) and ($att !~ /(update|text)/)); |
| 220 |
my $value = shift; |
| 221 |
$self->{$att} = $value; |
| 222 |
($self->{original_label} = $value) if (($att eq 'label') and (not $self->{original_label})); |
| 223 |
SWITCH: { # deal with related parameters |
| 224 |
($self->{update_fft} = 1), ($self->{update_bft} = 1), last SWITCH |
| 225 |
if (($att eq 'update_bkg') and ($value == 1)); |
| 226 |
($self->{update_bft} = 1), last SWITCH if (($att eq 'update_fft') and ($value == 1)); |
| 227 |
|
| 228 |
($self->{is_raw} = 0), last SWITCH if (($att eq 'is_rec') and ($value == 1)); |
| 229 |
($self->{is_rec} = 0), last SWITCH if (($att eq 'is_raw') and ($value == 1)); |
| 230 |
|
| 231 |
($self->{is_chi} = 0), ($self->{is_chi} = 0), ($self->{is_rsp} = 0), |
| 232 |
($self->{is_qsp} = 0), last SWITCH |
| 233 |
if (($att eq 'not_data') and ($value == 1)); |
| 234 |
|
| 235 |
($self->{is_chi} = 0), ($self->{is_rsp} = 0), ($self->{is_qsp} = 0), |
| 236 |
($self->{not_data} = 0), last SWITCH |
| 237 |
if (($att eq 'is_xmu') and ($value == 1)); |
| 238 |
|
| 239 |
$self->{bkg_fixstep} = 1, $self->{bkg_step} = 1, last SWITCH |
| 240 |
if (($att eq 'is_nor') and ($value == 1)); |
| 241 |
|
| 242 |
($self->{is_xmu} = 0), ($self->{is_rsp} = 0), ($self->{is_qsp} = 0), |
| 243 |
($self->{not_data} = 0), last SWITCH |
| 244 |
if (($att eq 'is_chi') and ($value == 1)); |
| 245 |
|
| 246 |
($self->{is_xmu} = 0), ($self->{is_chi} = 0), ($self->{is_qsp} = 0), |
| 247 |
($self->{not_data} = 0), last SWITCH |
| 248 |
if (($att eq 'is_rsp') and ($value == 1)); |
| 249 |
|
| 250 |
($self->{is_xmu} = 0), ($self->{is_chi} = 0), ($self->{is_rsp} = 0), |
| 251 |
($self->{not_data} = 0), last SWITCH |
| 252 |
if (($att eq 'is_qsp') and ($value == 1)); |
| 253 |
|
| 254 |
$self->{label} =~ s{[\"\']}{}g, last SWITCH if ($att eq 'label'); |
| 255 |
|
| 256 |
|
| 257 |
#($self->{bkg_slope} = 0), last SWITCH |
| 258 |
#if (($att eq 'bkg_slope') and ($value < EPSILON)); |
| 259 |
|
| 260 |
#($self->{bkg_int} = 0), last SWITCH |
| 261 |
#if (($att eq 'bkg_int') and ($value < EPSILON)); |
| 262 |
}; |
| 263 |
## deal with e0 shift in reference channel |
| 264 |
#if ($att eq 'bkg_eshift') { |
| 265 |
# if ($self->{reference}) { |
| 266 |
# if ( |
| 267 |
# }; |
| 268 |
#}; |
| 269 |
}; |
| 270 |
}; |
| 271 |
|
| 272 |
## this is a "private" method that overrides the frozen restriction on |
| 273 |
## make-ing a parameter value |
| 274 |
sub _MAKE { |
| 275 |
my $self = shift; |
| 276 |
my $is_frozen = $self->{frozen}; |
| 277 |
$self->unfreeze; |
| 278 |
$self->make(@_); |
| 279 |
$self->freeze if $is_frozen; |
| 280 |
}; |
| 281 |
|
| 282 |
## this is just like make, except that it overrides frozen-ness in a safe way |
| 283 |
sub MAKE { |
| 284 |
my $self = shift; |
| 285 |
$self->_MAKE(@_); |
| 286 |
}; |
| 287 |
|
| 288 |
sub freeze { |
| 289 |
my $self = shift; |
| 290 |
return if ($self->{is_pixel}); ## it makes no sense at all to freeze a pixel group |
| 291 |
$self->{frozen} = 1; |
| 292 |
}; |
| 293 |
sub unfreeze { |
| 294 |
my $self = shift; |
| 295 |
$self->{frozen} = 0; |
| 296 |
}; |
| 297 |
|
| 298 |
## set parameters from one group to those of another group, taking |
| 299 |
## care to ignore energy parameters for k-, R-, q- records |
| 300 |
sub set_to_another { |
| 301 |
my $self = shift; |
| 302 |
my $other = shift; |
| 303 |
my $is_energy = (($other->{is_xmu}) or ($other->{is_nor})); |
| 304 |
my $is_rq = (($other->{is_rsp}) or ($other->{is_qsp})); |
| 305 |
foreach my $x ($self->Keys, 'bkg_nnorm') { |
| 306 |
next unless ($x =~ m{^(?:bft|bkg|fft|impor|plot)}); |
| 307 |
$self->{$x} = $other->{$x}; |
| 308 |
my $item = $self->{group}; |
| 309 |
SWITCH: { |
| 310 |
($is_energy) and ($x eq 'bkg_e0') and do { |
| 311 |
if ($self->{bkg_e0} <= 0) { |
| 312 |
ifeffit("pre_edge($item.energy, $item.xmu)\n"); |
| 313 |
$self->{bkg_e0} = Ifeffit::get_scalar("e0"); |
| 314 |
}; |
| 315 |
last SWITCH; |
| 316 |
}; |
| 317 |
($is_energy) and ($x eq 'bkg_spl2e') and do { |
| 318 |
if ($self->{bkg_spl2e} <= 1) { |
| 319 |
ifeffit("set ___x = ceil($item.energy)"); |
| 320 |
my $maxE = Ifeffit::get_scalar("___x"); |
| 321 |
$self->{bkg_spl2e} = sprintf("%.2f", $maxE); |
| 322 |
$self->{bkg_spl2} = $self -> e2k($self->{bkg_spl2e}); |
| 323 |
}; |
| 324 |
last SWITCH; |
| 325 |
}; |
| 326 |
(not $is_rq) and ($x eq 'fft_kmax') and do { |
| 327 |
if ($self->{fft_kmax} <= 0.1) { |
| 328 |
ifeffit("set ___x = ceil($item.k)"); |
| 329 |
my $maxk = Ifeffit::get_scalar("___x") || 15; |
| 330 |
$self->{fft_kmax} = ($is_energy) ? $self->{bkg_spl2} : $maxk; |
| 331 |
}; |
| 332 |
last SWITCH; |
| 333 |
}; |
| 334 |
1; |
| 335 |
}; |
| 336 |
}; |
| 337 |
$self -> _MAKE(update_bkg=>1, update_fft=>1, update_bft=>1); |
| 338 |
}; |
| 339 |
|
| 340 |
|
| 341 |
## interpolate $other onto $self |
| 342 |
sub interpolate { |
| 343 |
my $self = shift; |
| 344 |
my ($other, $space, $mode) = @_; |
| 345 |
my ($stan, $this) = ($self->{group}, $other->{group}); |
| 346 |
|
| 347 |
## get $self up to date for interpolation |
| 348 |
if ($self->{update_bkg}) { |
| 349 |
$self->dispatch_bkg($mode); |
| 350 |
$self->_MAKE(update_bkg=>0); |
| 351 |
}; |
| 352 |
if ((lc($space) =~ /[rq]/) and ($self->{update_fft})) { |
| 353 |
$self->do_fft($mode); |
| 354 |
$self->_MAKE(update_fft=>0); |
| 355 |
}; |
| 356 |
if ((lc($space) eq 'q') and ($self->{update_bft})) { |
| 357 |
$self->do_bft($mode); |
| 358 |
$self->_MAKE(update_bft=>0); |
| 359 |
}; |
| 360 |
## get $other up to date for interpolation |
| 361 |
if ($other->{update_bkg}) { |
| 362 |
$other->dispatch_bkg($mode); |
| 363 |
$other->_MAKE(update_bkg=>0); |
| 364 |
}; |
| 365 |
if ((lc($space) =~ /[rq]/) and ($other->{update_fft})) { |
| 366 |
$other->do_fft($mode); |
| 367 |
$other->_MAKE(update_fft=>0); |
| 368 |
}; |
| 369 |
if ((lc($space) eq 'q') and ($other->{update_bft})) { |
| 370 |
$other->do_bft($mode); |
| 371 |
$other->_MAKE(update_bft=>0); |
| 372 |
}; |
| 373 |
|
| 374 |
my ($x, $y1, $y2, $y3, $y4); |
| 375 |
SWITCH: { # get columns |
| 376 |
($x, $y1, $y2) = ("energy", "xmu", ""), last SWITCH if (lc($space) eq 'e'); |
| 377 |
($x, $y1, $y2) = ("energy", "norm", ""), last SWITCH if (lc($space) eq 'n'); |
| 378 |
($x, $y1, $y2) = ("k", "chi", ""), last SWITCH if (lc($space) eq 'k'); |
| 379 |
($x, $y1, $y2) = ("r", "chir_re", "chir_im"), last SWITCH if (lc($space) eq 'r'); |
| 380 |
($x, $y1, $y2) = ("q", "chiq_re", "chiq_im"), last SWITCH if (lc($space) eq 'q'); |
| 381 |
}; |
| 382 |
MP: { # handle complex data (rsp and qsp) |
| 383 |
($y3, $y4) = ("chir_mag", "chir_pha"), last MP if (lc($space) eq 'r'); |
| 384 |
($y3, $y4) = ("chiq_mag", "chiq_pha"), last MP if (lc($space) eq 'q'); |
| 385 |
}; |
| 386 |
## need to snarf the portion of $stan.$x that is covered by $this.$x |
| 387 |
my @xstan = Ifeffit::get_array("$stan.$x"); |
| 388 |
$self -> dispose("set ___x = max($this.$x)", 1); |
| 389 |
my $xmax = Ifeffit::get_scalar("___x"); |
| 390 |
my @xxx = grep { $_ <= $xmax } @xstan; |
| 391 |
Ifeffit::put_array("$this.xxx", \@xxx); |
| 392 |
my $sets = "set($this.interp = qinterp($this.$x, $this.$y1, $this.xxx),\n"; |
| 393 |
$sets .= " $this.$x = $this.xxx,\n"; |
| 394 |
$sets .= " $this.$y1 = $this.interp)"; |
| 395 |
$self -> dispose($sets, $mode); |
| 396 |
if (lc($space) =~ /[rq]/) { |
| 397 |
$sets = "set($this.interp = qinterp($this.$x, $this.$y2, $this.xxx),\n"; |
| 398 |
$sets .= " $this.$y2 = $this.interp)"; |
| 399 |
$self -> dispose($sets, $mode); |
| 400 |
## fill mag and phase arrays |
| 401 |
}; |
| 402 |
$self -> dispose("erase $this.xxx $this.interp", $mode); # garbage collection |
| 403 |
}; |
| 404 |
|
| 405 |
|
| 406 |
## compute the difference spectrum in some space between $self and |
| 407 |
## $other. store the difference in group diff___diff. this does NOT |
| 408 |
## create a group out of diff___diff. |
| 409 |
sub plot_difference { |
| 410 |
my $self = shift; |
| 411 |
my ($other, $hash_ref, $mode, $rpf) = @_; |
| 412 |
my ($space, $xnot, $xn, $xx, $list, $groups) = ($$hash_ref{space}, $$hash_ref{xnot}, $$hash_ref{xmin}, |
| 413 |
$$hash_ref{xmax}, $$hash_ref{list}, $$hash_ref{groups}); |
| 414 |
my $invert = ($$hash_ref{invert}) ? "-1*" : ""; |
| 415 |
## make sure the background is up to date |
| 416 |
unless ($$hash_ref{space} eq 'e') { |
| 417 |
($self->{update_bkg}) and $self->dispatch_bkg($mode); |
| 418 |
$self->_MAKE(update_bkg=>0); |
| 419 |
($other->{update_bkg}) and $other->dispatch_bkg($mode); |
| 420 |
$other->_MAKE(update_bkg=>0); |
| 421 |
}; |
| 422 |
my ($stan, $this) = ($self->{group}, $other->{group}); |
| 423 |
## various parameters for the plot |
| 424 |
my ($sp, $suff, $suff2, $color, $xmin, $xmax, $xlabel, $ylabel); |
| 425 |
$color = ($$hash_ref{components}) ? $default->{color2} : $default->{color0}; |
| 426 |
my ($command, $plot, $marker); |
| 427 |
SWITCH: { |
| 428 |
($space =~ /[en]/) and do { |
| 429 |
unless ($self->{is_xmu} or $self->{not_data}) { |
| 430 |
&$errorcmd("> Difference plot aborted: \"$self->{label}\" cannot be plotted in energy"); |
| 431 |
return 0; |
| 432 |
}; |
| 433 |
unless ($other->{is_xmu} or $other->{not_data}) { |
| 434 |
&$errorcmd("> Difference plot aborted: \"$other->{label}\" cannot be plotted in energy"); |
| 435 |
return 0; |
| 436 |
}; |
| 437 |
($sp, $suff, $xmin, $xmax) = ('energy', 'xmu', |
| 438 |
$self->{bkg_e0}+$$rpf{emin}, |
| 439 |
$self->{bkg_e0}+$$rpf{emax}); |
| 440 |
if ($space eq 'n') { |
| 441 |
$suff = ($self->{bkg_flatten}) ? "flat" : "norm"; |
| 442 |
}; |
| 443 |
my $esh_s = $self->{bkg_eshift}; # = = |
| 444 |
my $esh_o = $other->{bkg_eshift}; |
| 445 |
## build the difference spetrum |
| 446 |
$command = "set diff___diff.$suff = $invert($stan.$suff - " . |
| 447 |
"interp($this.$sp+$esh_o, $this.$suff, $stan.$sp+$esh_s))\n"; |
| 448 |
## figure out the labels |
| 449 |
$xlabel = "\"E (eV)\""; |
| 450 |
$ylabel = ($space eq 'n') ? "\"difference in normalized x\\gm(E)\"" : |
| 451 |
"\"difference in x\\gm(E)\""; |
| 452 |
## build the plot command |
| 453 |
$plot .= "($stan.$sp+$esh_s, diff___diff.$suff, "; |
| 454 |
$plot .= "style=lines, color=\"$color\", key=difference, "; |
| 455 |
$plot .= "xmin=$xmin, xmax=$xmax, "; |
| 456 |
$plot .= ($invert) ? "title=\"$other->{label} - $self->{label}\", " : "title=\"$self->{label} - $other->{label}\", "; |
| 457 |
$plot .= "xlabel=$xlabel, ylabel=$ylabel)"; |
| 458 |
$marker = "pmarker \"$stan.$sp+$esh_s\", diff___diff.$suff, $xnot+$xn, $default->{marker}, $default->{markercolor}\n"; |
| 459 |
$marker .= "pmarker \"$stan.$sp+$esh_s\", diff___diff.$suff, $xnot+$xx, $default->{marker}, $default->{markercolor}\n"; |
| 460 |
last SWITCH; |
| 461 |
}; |
| 462 |
($space eq 'k') and do { |
| 463 |
($sp, $suff, $xmin, $xmax) = ('k', 'chi', $$rpf{kmin}, $$rpf{kmax}); |
| 464 |
unless ($self->{is_xmu} or $self->{is_chi}) { |
| 465 |
&$errorcmd("> Difference plot aborted: \"$self->{label}\" cannot be plotted in k-space"); |
| 466 |
return 0; |
| 467 |
}; |
| 468 |
unless ($other->{is_xmu} or $other->{is_chi}) { |
| 469 |
&$errorcmd("> Difference plot aborted: \"$other->{label}\" cannot be plotted in k-space"); |
| 470 |
return 0; |
| 471 |
}; |
| 472 |
## build the difference spetrum |
| 473 |
$command = "set diff___diff.$suff = $invert($stan.$suff-$this.$suff)\n"; |
| 474 |
## figure out the labels correctly for this k-weight |
| 475 |
my ($k, $w); |
| 476 |
my $ww = $self->{fft_arbkw}; |
| 477 |
if ($$rpf{k_w} eq 'w') { (($k, $w) = ("k\\u$ww\\d * ", "^$ww")) } |
| 478 |
elsif ($$rpf{k_w} == 0) { (($k, $w) = ("", "")) } |
| 479 |
elsif ($$rpf{k_w} == 1) { (($k, $w) = ("k * ", "^k")) } |
| 480 |
elsif ($$rpf{k_w} >= 2) { (($k, $w) = ("k\\u$$rpf{k_w}\\d * ", "^$$rpf{k_w}")) }; |
| 481 |
$xlabel = "\"k (\\A\\u-1\\d)\""; |
| 482 |
$ylabel = sprintf("\"%s difference in \\gx(k)\"", $k); |
| 483 |
## build the plot command |
| 484 |
$plot .= "($stan.$sp, diff___diff.$suff*$stan.$sp$w, "; |
| 485 |
$plot .= "style=lines, color=\"$color\", key=difference, "; |
| 486 |
$plot .= "xmin=$xmin, xmax=$xmax, title=\"$self->{label} - $other->{label}\", "; |
| 487 |
$plot .= "xlabel=$xlabel, ylabel=$ylabel)"; |
| 488 |
$marker = "pmarker $stan.$sp, diff___diff.$suff $xn $default->{marker}, $default->{markercolor}\n"; |
| 489 |
$marker .= "pmarker $stan.$sp, diff___diff.$suff $xx $default->{marker}, $default->{markercolor}\n"; |
| 490 |
last SWITCH; |
| 491 |
}; |
| 492 |
($space eq 'r') and do { |
| 493 |
unless ($self->{is_xmu} or $self->{is_chi} or $self->{is_rsp}) { |
| 494 |
&$errorcmd("> Difference plot aborted: \"$self->{label}\" cannot be plotted in R-space"); |
| 495 |
return 0; |
| 496 |
}; |
| 497 |
unless ($other->{is_xmu} or $other->{is_chi} or $other->{is_rsp}) { |
| 498 |
&$errorcmd("> Difference plot aborted: \"$other->{label}\" cannot be plotted in R-space"); |
| 499 |
return 0; |
| 500 |
}; |
| 501 |
## is the FT up to date?? |
| 502 |
($self->{update_fft}) and $self->do_fft($mode, $rpf); |
| 503 |
$self->_MAKE(update_fft=>0); |
| 504 |
($other->{update_fft}) and $other->do_fft($mode, $rpf); |
| 505 |
$other->_MAKE(update_fft=>0); |
| 506 |
($sp, $suff, $suff2, $xmin, $xmax) = ('r', 'chir_re', 'chir_im', $$rpf{rmin}, $$rpf{rmax}); |
| 507 |
## build all four parts of the difference spetrum |
| 508 |
my $sets = "set(diff___diff.$suff = $invert($stan.$suff-$this.$suff),\n"; |
| 509 |
$sets .= " diff___diff.$suff2 = $invert($stan.$suff2-$this.$suff2),\n"; |
| 510 |
$sets .= " diff___diff.chir_mag = sqrt(diff___diff.$suff^2 + diff___diff.$suff2^2),\n"; |
| 511 |
$sets .= " diff___diff.chir_pha = atan(diff___diff.$suff2 / diff___diff.$suff))\n"; |
| 512 |
$command .= $sets; |
| 513 |
## figure out the labels for this part of the complex function |
| 514 |
my ($part, $lab, $tit); |
| 515 |
if ($$rpf{r_mag}) {($part,$lab,$tit) = ("chir_mag", "|\\gx(R)|", "magnitude of ")} |
| 516 |
elsif ($$rpf{r_re}) {($part,$lab,$tit) = ("chir_re", "Re[\\gx(R)]", "real part of ")} |
| 517 |
elsif ($$rpf{r_im}) {($part,$lab,$tit) = ("chir_im", "Im[\\gx(R)]", "imaginary part of ")} |
| 518 |
elsif ($$rpf{r_pha}) {($part,$lab,$tit) = ("chir_pha", "Pha[\\gx(R)]", "phase of ")}; |
| 519 |
$xlabel = "\"k (\\A\\u-1\\d)\""; |
| 520 |
$ylabel = sprintf("\"difference in %s\"", $lab); |
| 521 |
## build the plot command |
| 522 |
$plot .= "($stan.$sp, diff___diff.$part, "; |
| 523 |
$plot .= "style=lines, color=\"$color\", key=difference, "; |
| 524 |
$plot .= "xmin=$xmin, xmax=$xmax, title=\"$self->{label} - $other->{label}\", "; |
| 525 |
$plot .= "xlabel=$xlabel, ylabel=$ylabel)"; |
| 526 |
$marker = "pmarker $stan.$sp, diff___diff.$suff $xn $default->{marker}, $default->{markercolor}\"\n"; |
| 527 |
$marker .= "pmarker $stan.$sp, diff___diff.$suff $xx $default->{marker}, $default->{markercolor}\"\n"; |
| 528 |
last SWITCH; |
| 529 |
}; |
| 530 |
($space eq 'q') and do { |
| 531 |
if ($self->{not_data}) { |
| 532 |
&$errorcmd("> Difference plot aborted: \"$self->{label}\" cannot be plotted in q-space"); |
| 533 |
return 0; |
| 534 |
}; |
| 535 |
if ($other->{not_data}) { |
| 536 |
&$errorcmd("> Difference plot aborted: \"$other->{label}\" cannot be plotted in q-space"); |
| 537 |
return 0; |
| 538 |
}; |
| 539 |
## are the FTs up to date?? |
| 540 |
($self->{update_fft}) and $self->do_fft($mode, $rpf); |
| 541 |
$self->_MAKE(update_fft=>0); |
| 542 |
($other->{update_fft}) and $other->do_fft($mode, $rpf); |
| 543 |
$other->_MAKE(update_fft=>0); |
| 544 |
($self->{update_bft}) and $self->do_bft($mode); |
| 545 |
$self->_MAKE(update_bft=>0); |
| 546 |
($other->{update_bft}) and $other->do_bft($mode); |
| 547 |
$other->_MAKE(update_bft=>0); |
| 548 |
($sp, $suff, $suff2, $xmin, $xmax) = ('q', 'chiq_re', 'chiq_im', $$rpf{qmin}, $$rpf{qmax}); |
| 549 |
## build all four parts of the difference spetrum |
| 550 |
my $sets = "set(diff___diff.$suff = $invert($stan.$suff-$this.$suff),\n"; |
| 551 |
$sets .= " diff___diff.$suff2 = $invert($stan.$suff2-$this.$suff2),\n"; |
| 552 |
$sets .= " diff___diff.chiq_mag = sqrt(diff___diff.$suff^2 + diff___diff.$suff2^2),\n"; |
| 553 |
$sets .= " diff___diff.chiq_pha = atan(diff___diff.$suff2 / diff___diff.$suff))\n"; |
| 554 |
$command .= $sets; |
| 555 |
## figure out the labels for this part of the complex function |
| 556 |
my ($part, $lab, $tit); |
| 557 |
if ($$rpf{'q_mag'}) {($part,$lab,$tit) = ("chiq_mag", "|\\gx(q)|", "magnitude of ")} |
| 558 |
elsif ($$rpf{'q_re'}) {($part,$lab,$tit) = ("chiq_re", "Re[\\gx(q)]", "real part of ")} |
| 559 |
elsif ($$rpf{'q_im'}) {($part,$lab,$tit) = ("chiq_im", "Im[\\gx(q)]", "imaginary part of ")} |
| 560 |
elsif ($$rpf{'q_pha'}) {($part,$lab,$tit) = ("chiq_pha", "Pha[\\gx(q)]", "phase of ")}; |
| 561 |
$xlabel = "\"k (\\A\\u-1\\d)\""; |
| 562 |
$ylabel = sprintf("\"difference in %s\"", $lab); |
| 563 |
## build the plot command |
| 564 |
$plot .= "($stan.$sp, diff___diff.$part, "; |
| 565 |
$plot .= "style=lines, color=\"$color\", key=difference, "; |
| 566 |
$plot .= "xmin=$xmin, xmax=$xmax, title=\"$self->{label} - $other->{label}\", "; |
| 567 |
$plot .= "xlabel=$xlabel, ylabel=$ylabel)"; |
| 568 |
$marker = "pmarker $stan.$sp, diff___diff.$suff $xn $default->{marker}, $default->{markercolor}\"\n"; |
| 569 |
$marker .= "pmarker $stan.$sp, diff___diff.$suff $xx $default->{marker}, $default->{markercolor}\"\n"; |
| 570 |
last SWITCH; |
| 571 |
}; |
| 572 |
}; |
| 573 |
my $pp = ($$hash_ref{components}) ? "plot" : "newplot"; |
| 574 |
if ($$hash_ref{components}) { |
| 575 |
my $str = $space; |
| 576 |
($str = $$rpf{k_w}) if ($space eq 'k'); |
| 577 |
($str = $$rpf{$space."_marked"}) if ($space =~ /[rq]/); |
| 578 |
$self->plot_marked($str, $mode, $groups, {$other->{group}=>1, $self->{group}=>1}, $rpf, $list) |
| 579 |
}; |
| 580 |
$plot = wrap($pp, " ", $plot); |
| 581 |
##$command .= $plot . "\n"; |
| 582 |
$self->dispose($command, $mode); |
| 583 |
unless ($$hash_ref{noplot}) { |
| 584 |
$self->dispose($plot, $mode); |
| 585 |
$self->dispose($marker, $mode); |
| 586 |
}; |
| 587 |
return 1; |
| 588 |
}; |
| 589 |
|
| 590 |
|
| 591 |
## erase a group from memory, preserving the initial state of the |
| 592 |
## record |
| 593 |
## what about title lines? |
| 594 |
sub erase { |
| 595 |
my $self = shift; |
| 596 |
my $group = $self->{group}; |
| 597 |
&$errorcmd("> Cannot erase defaults."), return if ($group eq "Default Parameters"); |
| 598 |
my (@x, @y1, @y2, @z1, @z2); |
| 599 |
## save initial data |
| 600 |
SWITCH: { |
| 601 |
($self->{is_xmu}) and do { |
| 602 |
@x = Ifeffit::get_array($group.".energy"); |
| 603 |
@y1 = Ifeffit::get_array($group.".xmu"); |
| 604 |
last SWITCH; |
| 605 |
}; |
| 606 |
($self->{is_chi}) and do { |
| 607 |
@x = Ifeffit::get_array($group.".k"); |
| 608 |
@y1 = Ifeffit::get_array($group.".chi"); |
| 609 |
last SWITCH; |
| 610 |
}; |
| 611 |
($self->{is_rsp}) and do { |
| 612 |
@x = Ifeffit::get_array($group.".r"); |
| 613 |
@y1 = Ifeffit::get_array($group.".chir_re"); |
| 614 |
@y2 = Ifeffit::get_array($group.".chir_im"); |
| 615 |
@z1 = Ifeffit::get_array($group.".chir_mag"); |
| 616 |
@z2 = Ifeffit::get_array($group.".chir_pha"); |
| 617 |
last SWITCH; |
| 618 |
}; |
| 619 |
($self->{is_qsp}) and do { |
| 620 |
@x = Ifeffit::get_array($group.".q"); |
| 621 |
@y1 = Ifeffit::get_array($group.".chiq_re"); |
| 622 |
@y2 = Ifeffit::get_array($group.".chiq_im"); |
| 623 |
@z1 = Ifeffit::get_array($group.".chiq_mag"); |
| 624 |
@z2 = Ifeffit::get_array($group.".chiq_pha"); |
| 625 |
last SWITCH; |
| 626 |
}; |
| 627 |
}; |
| 628 |
## erase group |
| 629 |
$self -> dispose("erase \@group $group\n"); |
| 630 |
## restore intial data |
| 631 |
SWITCH: { |
| 632 |
($self->{is_xmu}) and do { |
| 633 |
Ifeffit::put_array($group.".energy", \@x); |
| 634 |
Ifeffit::put_array($group.".xmu", \@y1); |
| 635 |
$self -> _MAKE(update_bkg=>1, update_fft=>1, update_bft=>1); |
| 636 |
last SWITCH; |
| 637 |
}; |
| 638 |
($self->{is_chi}) and do { |
| 639 |
Ifeffit::put_array($group.".k", \@x); |
| 640 |
Ifeffit::put_array($group.".chi", \@y1); |
| 641 |
$self -> _MAKE(update_bkg=>0, update_fft=>1, update_bft=>1); |
| 642 |
last SWITCH; |
| 643 |
}; |
| 644 |
($self->{is_rsp}) and do { |
| 645 |
Ifeffit::put_array($group.".r", \@x); |
| 646 |
Ifeffit::put_array($group.".chir_re", \@y1); |
| 647 |
Ifeffit::put_array($group.".chir_im", \@y2); |
| 648 |
Ifeffit::put_array($group.".chir_mag", \@z1); |
| 649 |
Ifeffit::put_array($group.".chir_pha", \@z2); |
| 650 |
$self -> _MAKE(update_bkg=>0, update_fft=>0, update_bft=>1); |
| 651 |
last SWITCH; |
| 652 |
}; |
| 653 |
($self->{is_qsp}) and do { |
| 654 |
Ifeffit::put_array($group.".q", \@x); |
| 655 |
Ifeffit::put_array($group.".chiq_re", \@y1); |
| 656 |
Ifeffit::put_array($group.".chiq_im", \@y2); |
| 657 |
Ifeffit::put_array($group.".chiq_mag", \@z1); |
| 658 |
Ifeffit::put_array($group.".chiq_pha", \@z2); |
| 659 |
$self -> _MAKE(update_bkg=>0, update_fft=>0, update_bft=>0); |
| 660 |
last SWITCH; |
| 661 |
}; |
| 662 |
}; |
| 663 |
}; |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
## reset bkg_e0 to the value found by pre_edge and update the spline |
| 668 |
## energy range values |
| 669 |
sub reset_e0 { |
| 670 |
my $self = shift; |
| 671 |
my $group = $self->{group}; |
| 672 |
my $esh = $self->{bkg_eshift}; |
| 673 |
my $dmode = $_[0] || 5; |
| 674 |
$self -> dispose("## resetting e0 to its default value\n", $dmode); |
| 675 |
$self -> dispose("pre_edge(\"$group.energy+$esh\", $group.xmu)\n", $dmode); |
| 676 |
my $e0 = Ifeffit::get_scalar("e0"); |
| 677 |
unless ($e0) { # deal with situation where pre_edge |
| 678 |
$self -> # fails to return an e0 value |
| 679 |
dispose("## failed to find e0 with the pre_edge command, take max of derivative", |
| 680 |
$dmode); |
| 681 |
my $sets = "set($group.deriv = deriv($group.xmu),"; |
| 682 |
$sets .= " i___i = ceil($group.deriv),"; |
| 683 |
$sets .= " i___i = nofx($group.deriv, i___i))"; |
| 684 |
$self -> dispose($sets, $dmode); |
| 685 |
$e0 = Ifeffit::get_scalar("i___i"); |
| 686 |
if ($e0 < 5) { |
| 687 |
$e0 = 15; |
| 688 |
$self -> dispose("## max of derivative was very close to the beginning of the data, e0 set to 15th data point", $dmode); |
| 689 |
}; |
| 690 |
my @array = Ifeffit::get_array("$group.energy"); |
| 691 |
$e0 = $array[$e0-1]; |
| 692 |
$self -> dispose("erase i___i $group.deriv", $dmode); |
| 693 |
}; |
| 694 |
$self -> _MAKE(bkg_e0=>$e0); |
| 695 |
my $k = $self->{bkg_spl1}; |
| 696 |
$self -> _MAKE(bkg_spl1e=>$self->k2e($k)); |
| 697 |
$k = $self->{bkg_spl2}; |
| 698 |
$self -> _MAKE(bkg_spl2e=>$self->k2e($k)); |
| 699 |
$self -> _MAKE(update_bkg=>1); |
| 700 |
}; |
| 701 |
|
| 702 |
## reset bkg_e0 to half the edge step and update the spline |
| 703 |
## energy range values |
| 704 |
sub e0_half_step { |
| 705 |
my $self = shift; |
| 706 |
my $fraction = $_[1]; |
| 707 |
$fraction ||= 0.5; |
| 708 |
($fraction = 0.5) if ($fraction <= 0); |
| 709 |
($fraction = 1.0) if ($fraction > 1); |
| 710 |
my $group = $self->{group}; |
| 711 |
my $esh = $self->{bkg_eshift}; |
| 712 |
my $dmode = $_[0] || 5; |
| 713 |
my $prior = 0; |
| 714 |
my $count = 1; |
| 715 |
while (abs($self->{bkg_e0}-$prior) > DELTA) { |
| 716 |
&$echocmd("> Resetting E0 to half edge step, iteration $count"); |
| 717 |
$prior = $self->{bkg_e0}; |
| 718 |
$self->dispatch_bkg($dmode) if $self->{update_bkg}; |
| 719 |
my $halfstep = $fraction * $self->{bkg_step}; |
| 720 |
my @x = Ifeffit::get_array("$group.energy"); |
| 721 |
my @y = Ifeffit::get_array("$group.pre"); |
| 722 |
my $ehalf = 0; |
| 723 |
foreach my $i (0 .. $#x) { |
| 724 |
next if ($y[$i] < $halfstep); |
| 725 |
my $frac = ($halfstep - $y[$i-1]) / ($y[$i] - $y[$i-1]); |
| 726 |
$ehalf = $x[$i-1] + $frac*($x[$i] - $x[$i-1]); |
| 727 |
last; |
| 728 |
}; |
| 729 |
$self -> _MAKE(bkg_e0=>$ehalf+$esh); |
| 730 |
my $k = $self->{bkg_spl1}; |
| 731 |
$self -> _MAKE(bkg_spl1e=>$self->k2e($k)); |
| 732 |
$k = $self->{bkg_spl2}; |
| 733 |
$self -> _MAKE(bkg_spl2e=>$self->k2e($k)); |
| 734 |
$self -> _MAKE(update_bkg=>1); |
| 735 |
++$count; |
| 736 |
return if ($count > 5); # it shouldn't take more than three |
| 737 |
# unless something is very wrong with |
| 738 |
# these data |
| 739 |
}; |
| 740 |
}; |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
###################################################################### |
| 745 |
## Plotting methods |
| 746 |
|
| 747 |
sub SetDefault { |
| 748 |
my $self = shift; |
| 749 |
$default -> _MAKE(@_); |
| 750 |
#$default = Ifeffit::Group -> new(@_); |
| 751 |
}; |
| 752 |
|
| 753 |
|
| 754 |
sub Default { |
| 755 |
my $self = shift; |
| 756 |
return $default->{$_[0]} || 0; |
| 757 |
}; |
| 758 |
|
| 759 |
|
| 760 |
## the argument is a character string that is decoded to indicate |
| 761 |
|
| 762 |
## plotting of mu, mu0, pre and whether data should be normalized or |
| 763 |
## differentiated |
| 764 |
sub plotE { |
| 765 |
my $self = shift; |
| 766 |
my ($group, $lab) = ($self->{group}, $self->{label}); |
| 767 |
my $not_data = $self->{not_data}; |
| 768 |
unless (($self->{is_xmu}) or ($not_data)) { |
| 769 |
if ($group eq "Default Parameters") { |
| 770 |
&$errorcmd("> No data!"); |
| 771 |
return 0; |
| 772 |
}; |
| 773 |
&$errorcmd("> The group \"$lab\" cannot be plotted in energy."); |
| 774 |
return 0; |
| 775 |
}; |
| 776 |
my ($str, $mode, $rpf, $indicators) = (lc($_[0]), $_[1], $_[2], $_[3]); |
| 777 |
($str eq 'e') and ($str = 'em'); |
| 778 |
my ($mu, $not, $pre, $post, $norm, $clnorm, $der, $second, $smooth, $deg) = (0,0,0,0,0,0,0,0,0,0); |
| 779 |
my $plot_scale = $self->{plot_scale}; |
| 780 |
my $yoffset = $self->{plot_yoffset}; |
| 781 |
my $cnt = 0; |
| 782 |
my $color; |
| 783 |
my (@markers_e, @markers_x); |
| 784 |
## determine parameters for legend |
| 785 |
($str =~ /m/) and ($mu = 1); # parse the inicator argument |
| 786 |
($str =~ /z/) and ($not = 1); |
| 787 |
($str =~ /p/) and ($pre = 1); |
| 788 |
($str =~ /t/) and ($post = 1); |
| 789 |
($str =~ /n/) and ($norm = 1); |
| 790 |
($str =~ /d/) and (($der, $second) = (1, 0)); |
| 791 |
($str =~ /2/) and (($der, $second) = (0, 1)); |
| 792 |
($str =~ /s/) and ($smooth = 1); |
| 793 |
($str =~ /g/) and ($deg = 1); |
| 794 |
($self->{bkg_cl}) and ($clnorm = 1); |
| 795 |
($clnorm == 1) and (($pre, $post) = (0,0)); |
| 796 |
my $markers = $default->{showmarkers}; |
| 797 |
my ($plot, $this, $command, $scr, $title) = |
| 798 |
("newplot", "", "", $default->{screen}, ", title=\"$lab\""); |
| 799 |
my $esh = $self->{bkg_eshift}; |
| 800 |
if ($norm) { ($pre, $post) = (0,0); }; # no pre or post in norm or deriv |
| 801 |
if ($der) { ($not, $pre, $post) = (0,0,0); }; |
| 802 |
if ($second) { ($not, $pre, $post) = (0,0,0); }; |
| 803 |
if ($deg) { $not = 0; }; |
| 804 |
if ($deg and ($self->{deg_emax} < $self->{bkg_e0})) { ($pre, $post) = (1,0); }; |
| 805 |
if ($deg and ($self->{deg_emin} > $self->{bkg_e0})) { ($pre, $post) = (0,1); }; |
| 806 |
if ($self->{not_data}) { ($not, $pre, $post) = (0,0,0); }; |
| 807 |
if ($self->{is_xanes}) { $not = 0;}; |
| 808 |
|
| 809 |
my $xrange = ""; |
| 810 |
|
| 811 |
if ($rpf) { |
| 812 |
my @xrange = ($self->{bkg_e0}+$$rpf{emin}, $self->{bkg_e0}+$$rpf{emax}); |
| 813 |
$xrange = ", xmin=$xrange[0], xmax=$xrange[1]"; |
| 814 |
}; |
| 815 |
my $func = ""; |
| 816 |
## y-axis label |
| 817 |
if ($norm and $der) { |
| 818 |
$func = "deriv of norm "; |
| 819 |
} elsif ($norm) { |
| 820 |
$func = "norm "; |
| 821 |
} elsif ($der) { |
| 822 |
$func = "deriv "; |
| 823 |
} elsif ($second) { |
| 824 |
$func = "second deriv "; |
| 825 |
}; |
| 826 |
($func = "smoothed $func") if $smooth; |
| 827 |
my $labels = ", xlabel=\"E (eV)\", ylabel=\"${func}x\\gm(E)\""; |
| 828 |
($self->{update_bkg}) and $self->dispatch_bkg($mode); |
| 829 |
## this next bit must be done after the call to dispatch_bkg |
| 830 |
if ($not_data) { |
| 831 |
my @e = Ifeffit::get_array("$group.energy"); |
| 832 |
$self->_MAKE(bkg_e0=>$e[0]-$$rpf{emin}) unless $self->{bkg_e0}; |
| 833 |
} elsif ($self->{is_nor}) { |
| 834 |
my $cmd = sprintf("set(___x = npts(%s.energy), %s.preline = zeros(___x))", $group, $group); |
| 835 |
$self->dispose("$cmd", $mode); |
| 836 |
#} else { |
| 837 |
##print "in plotE: ", Ifeffit::get_scalar("pre_slope"), " ", |
| 838 |
##Ifeffit::get_scalar("pre_offset"), $/; |
| 839 |
## $self->_MAKE(bkg_slope => Ifeffit::get_scalar("pre_slope"), |
| 840 |
## bkg_int => Ifeffit::get_scalar("pre_offset"),); |
| 841 |
## my $cmd = sprintf("set %s.preline = %g+%g*(%s.energy + %g)", |
| 842 |
## $group, $self->{bkg_int}, $self->{bkg_slope}, $group, $self->{bkg_eshift}); |
| 843 |
## $self->dispose("$cmd", $mode); |
| 844 |
}; |
| 845 |
$self->_MAKE(update_bkg=>0); |
| 846 |
|
| 847 |
if ($str =~ /(s+)/) { |
| 848 |
my $iterations = length($1); |
| 849 |
my $suff = 'xmu'; |
| 850 |
if ($self->{not_data}) { |
| 851 |
$suff = 'det'; |
| 852 |
} elsif ($norm) { |
| 853 |
$suff = 'norm'; |
| 854 |
}; |
| 855 |
$self->dispose("set $group.smooth = $group.$suff", $mode); |
| 856 |
foreach (1 .. $iterations) { |
| 857 |
$self->dispose("set $group.smooth = smooth($group.smooth)", $mode); |
| 858 |
}; |
| 859 |
}; |
| 860 |
|
| 861 |
if ($not) { # plot the background as raw or normalized |
| 862 |
$color = $default->{'color1'}; |
| 863 |
##my $plot_scale_this = ($self->{is_diff}) ? "$plot_scale" : "1"; |
| 864 |
my $plot_scale_this = "$plot_scale"; |
| 865 |
if ($norm) { |
| 866 |
if ($clnorm) { |
| 867 |
$this= sprintf("%s(%s.energy+%s, \"%s*%s.f2norm+%s\"%s%s %s, style=lines, color=\"%s\", key=bkg%s)", |
| 868 |
$plot, $group, $esh, $plot_scale_this, $group, $yoffset, |
| 869 |
$labels, $scr, $xrange, $color, $title); |
| 870 |
} elsif ($self->{is_nor}) { |
| 871 |
$this= sprintf("%s(%s.energy+%s, \"%s*%s.fbkg+%s\"%s%s%s, style=lines, color=\"%s\", key=bkg%s)", |
| 872 |
$plot, $group, $esh, $plot_scale_this, $group, $yoffset, |
| 873 |
$labels, $scr, $xrange, $color, $title); |
| 874 |
} elsif ($self->{bkg_flatten}) { |
| 875 |
$this= sprintf("%s(%s.energy+%s, \"%s*%s.fbkg+%s\"%s%s%s, style=lines, color=\"%s\", key=bkg%s)", |
| 876 |
$plot, $group, $esh, $plot_scale_this, $group, $yoffset, |
| 877 |
$labels, $scr, $xrange, $color, $title); |
| 878 |
} else { |
| 879 |
$this= sprintf("%s(%s.energy+%s, \"%s*(%s.bkg-%s.preline)/%f+%s\"%s%s %s, style=lines, color=\"%s\", key=bkg%s)", |
| 880 |
$plot, $group, $esh, $plot_scale_this, $group, |
| 881 |
$group, $self->{bkg_step}, $yoffset, |
| 882 |
$labels, $scr, $xrange, $color, $title); |
| 883 |
}; |
| 884 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 885 |
$command .= $this; |
| 886 |
$markers and |
| 887 |
push @markers_e, $self->{bkg_e0}; #+$self->{bkg_eshift}; |
| 888 |
} else { |
| 889 |
if ($clnorm) { |
| 890 |
$this = sprintf("%s(%s.energy+%s, \"%s*%s.f2+%s\"%s%s %s, style=lines, color=\"%s\", key=bkg%s)", |
| 891 |
$plot, $group, $esh, $plot_scale_this, $group, $yoffset, $labels, $scr, $xrange, $color, $title); |
| 892 |
} else { |
| 893 |
$this = sprintf("%s(%s.energy+%s, \"%s*%s.bkg+%s\"%s%s %s, style=lines, color=\"%s\", key=bkg%s)", |
| 894 |
$plot, $group, $esh, $plot_scale_this, $group, $yoffset, $labels, $scr, $xrange, $color, $title); |
| 895 |
}; |
| 896 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 897 |
$command .= $this; |
| 898 |
$markers and |
| 899 |
push @markers_e, $self->{bkg_e0}; #+$self->{bkg_eshift}; |
| 900 |
}; |
| 901 |
($plot, $labels, $scr, $title) = ("plot", "", "", ""); |
| 902 |
++$cnt; |
| 903 |
}; |
| 904 |
if ($mu) { # plot the data as raw, normalized, or derivative |
| 905 |
$color = $default->{'color0'}; |
| 906 |
my $style = $$rpf{linestyle}; |
| 907 |
if ($der and $norm) { |
| 908 |
my $suff = ($not_data) ? 'det' : 'norm'; |
| 909 |
my $task = "deriv"; |
| 910 |
if ($smooth) { |
| 911 |
#$command .= "set $group.der = deriv($group.smooth)\n"; |
| 912 |
($task, $suff) = ("deriv", "smooth"); |
| 913 |
}; |
| 914 |
$this = sprintf("%s(%s.energy+%s, \"%s*(%s(%s.%s)/deriv(%s.energy))+%s\"%s%s %s, style=%s, color=\"%s\", key=\"\\gm\"%s)", |
| 915 |
$plot, $group, $esh, $plot_scale, $task, $group, $suff, $group, |
| 916 |
$yoffset, $labels, $scr, |
| 917 |
$xrange, $style, $color, $title); |
| 918 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 919 |
$command .= $this; |
| 920 |
$markers and push @markers_e, $self->{bkg_e0}; #+$self->{bkg_eshift}; |
| 921 |
} elsif ($norm) { |
| 922 |
my $suff; |
| 923 |
if ($smooth) { |
| 924 |
$suff = 'smooth'; |
| 925 |
} elsif ($not_data) { |
| 926 |
$suff = 'det'; |
| 927 |
} elsif ($self->{bkg_flatten}) { |
| 928 |
$suff = 'flat'; |
| 929 |
} else { |
| 930 |
$suff = 'norm'; |
| 931 |
}; |
| 932 |
#($self->{is_nor}) and ($suff = 'xmu'); |
| 933 |
#my $plot_scale_this = ($self->{is_diff}) ? "$plot_scale" : "1"; |
| 934 |
my $plot_scale_this = "$plot_scale"; |
| 935 |
$this = sprintf("%s(%s.energy+%s, \"%s*%s.%s+%s\"%s%s %s, style=%s, color=\"%s\", key=\"\\gm\"%s)", |
| 936 |
$plot, $group, $esh, |
| 937 |
$plot_scale_this, $group, $suff, $yoffset, |
| 938 |
$labels, $scr, $xrange, $style, $color, $title); |
| 939 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 940 |
$command .= $this; |
| 941 |
} elsif ($der) { |
| 942 |
my $suff = ($not_data) ? 'det' : 'xmu'; |
| 943 |
my $task = "deriv"; |
| 944 |
if ($smooth) { |
| 945 |
#$command .= "set $group.der = deriv($group.smooth)\n"; |
| 946 |
($task, $suff) = ("deriv", "smooth"); |
| 947 |
}; |
| 948 |
$this = sprintf("%s(%s.energy+%s, \"%s*(%s(%s.%s)/deriv(%s.energy))+%s\"%s%s %s, style=%s, color=\"%s\", key=\"\\gm\"%s)", |
| 949 |
$plot, $group, $esh, $plot_scale, $task, $group, $suff, $group, |
| 950 |
$yoffset, $labels, $scr, |
| 951 |
$xrange, $style, $color, $title); |
| 952 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 953 |
$command .= $this; |
| 954 |
$markers and push @markers_e, $self->{bkg_e0}; #+$self->{bkg_eshift}; |
| 955 |
} elsif ($second) { |
| 956 |
my $suff = ($not_data) ? 'det' : 'xmu'; |
| 957 |
$suff = 'smooth' if $smooth; |
| 958 |
my $task = "deriv"; |
| 959 |
$command .= "## plotting second derivative\n"; |
| 960 |
$command .= "set $group.der = deriv($group.$suff)/deriv($group.energy)\n"; |
| 961 |
$suff = 'der'; |
| 962 |
$this = sprintf("%s(%s.energy+%s, \"%s*(%s(%s.%s)/deriv(%s.energy))+%s\"%s%s %s, style=%s, color=\"%s\", key=\"\\gm\"%s)", |
| 963 |
$plot, $group, $esh, $plot_scale, $task, $group, $suff, $group, |
| 964 |
$yoffset, $labels, $scr, |
| 965 |
$xrange, $style, $color, $title); |
| 966 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 967 |
$command .= $this; |
| 968 |
$markers and push @markers_e, $self->{bkg_e0}; #+$self->{bkg_eshift}; |
| 969 |
} else { |
| 970 |
my $suff = ($not_data) ? 'det' : 'xmu'; |
| 971 |
($suff = "smooth") if $smooth; |
| 972 |
#my $plot_scale_this = ($self->{is_diff}) ? "$plot_scale" : "1"; |
| 973 |
my $plot_scale_this = "$plot_scale"; |
| 974 |
$this = sprintf("%s(%s.energy+%s, \"%s*%s.%s+%s\"%s%s %s, style=%s, color=\"%s\", key=\"\\gm\"%s)", |
| 975 |
$plot, $group, $esh, $plot_scale_this, $group, $suff, $yoffset, $labels, $scr, |
| 976 |
$xrange, $style, $color, $title); |
| 977 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 978 |
$command .= $this; |
| 979 |
}; |
| 980 |
($plot, $labels, $scr, $title) = ("plot", "", "", ""); |
| 981 |
++$cnt; |
| 982 |
}; |
| 983 |
if ($pre) { # plot the pre-edge lines and pre? markers |
| 984 |
$color = $default->{'color2'}; |
| 985 |
$this = sprintf("%s(%s.energy+%s, \"%s.preline+%s\"%s%s %s, style=lines, color=\"%s\", key=pre%s)", |
| 986 |
$plot, $group, $esh, $group, $yoffset, $labels, $scr, $xrange, $color, $title); |
| 987 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 988 |
$command .= $this; |
| 989 |
($plot, $labels, $scr, $title) = ("plot", "", "", "", ""); |
| 990 |
++$cnt; |
| 991 |
$markers and (not $deg) and |
| 992 |
push @markers_e, $self->{bkg_pre1}+$self->{bkg_e0}, #+$self->{bkg_eshift}, |
| 993 |
$self->{bkg_pre2}+$self->{bkg_e0}; #+$self->{bkg_eshift}; |
| 994 |
## plot deglitching line in pre-edge |
| 995 |
if ($deg) { |
| 996 |
$color = $default->{'color4'}; |
| 997 |
my @x = Ifeffit::get_array("$group.energy"); |
| 998 |
my @y = Ifeffit::get_array("$group.preline"); |
| 999 |
my ($i, $j) = (0,0); |
| 1000 |
foreach (@x) { |
| 1001 |
last if ($_ > $self->{deg_emin}); |
| 1002 |
++$i; |
| 1003 |
}; |
| 1004 |
foreach (@x) { |
| 1005 |
last if ($_ > $self->{deg_emax}); |
| 1006 |
++$j; |
| 1007 |
}; |
| 1008 |
@x=splice(@x, $i, $j-$i); |
| 1009 |
@y=splice(@y, $i, $j-$i); |
| 1010 |
Ifeffit::put_array("$group.edeg", \@x); |
| 1011 |
Ifeffit::put_array("$group.xdeg", \@y); |
| 1012 |
$command .= "## deglitching margin lines are not available for plotting in a macro.\n"; |
| 1013 |
$command .= sprintf("plot(%s.edeg+%s, \"%s.xdeg+%g+%s\", style=lines, color=\"%s\", key=toler)\n", |
| 1014 |
$group, $esh, $group, $self->{deg_tol}, $yoffset, $color); |
| 1015 |
$command .= sprintf("plot(%s.edeg+%s, \"%s.xdeg-%g+%s\", style=lines, color=\"%s\")\n", |
| 1016 |
$group, $esh, $group, $self->{deg_tol}, $yoffset, $color); |
| 1017 |
push @markers_e, $self->{deg_emin}, #+$self->{bkg_eshift}, |
| 1018 |
$self->{deg_emax}; #+$self->{bkg_eshift}; |
| 1019 |
++$cnt; |
| 1020 |
}; |
| 1021 |
}; |
| 1022 |
if ($post and (not $self->{bkg_fixstep})) { # plot the post-edge line and nor? markers |
| 1023 |
$color = $default->{'color3'}; |
| 1024 |
my $cmd; |
| 1025 |
if ($self->{is_merge} eq 'n') { |
| 1026 |
|
| 1027 |
my ($flat1, $flat2) = ($self->{bkg_e0}+$self->{bkg_nor1}-$self->{bkg_eshift}, |
| 1028 |
$self->{bkg_e0}+$self->{bkg_nor2}-$self->{bkg_eshift}); |
| 1029 |
my $shift = $self->{bkg_eshift}; |
| 1030 |
my $suff = 'xmu'; |
| 1031 |
$cmd = "# postline for normalized records\n"; |
| 1032 |
$cmd = "guess(flat_c0=0)\n"; |
| 1033 |
if (($flat2-$flat1) < 300) { |
| 1034 |
if ($self->{bkg_nnorm} == 1) { |
| 1035 |
$cmd .= "set(flat_c1=0)\n"; |
| 1036 |
} else { |
| 1037 |
$cmd .= "guess(flat_c1=0)\n"; |
| 1038 |
}; |
| 1039 |
$cmd .= "set (flat_c2=0)\n"; |
| 1040 |
} elsif ($self->{bkg_nnorm} == 2) { |
| 1041 |
$cmd .= "guess(flat_c1=0)\n"; |
| 1042 |
$cmd .= "set (flat_c2=0)\n"; |
| 1043 |
} elsif ($self->{bkg_nnorm} == 1) { |
| 1044 |
$cmd .= "set(flat_c1=0, flat_c2=0)\n"; |
| 1045 |
} else { |
| 1046 |
$cmd .= "guess(flat_c1=0, flat_c2=0)\n"; |
| 1047 |
}; |
| 1048 |
$cmd .= "def($group.postline = (flat_c0 + flat_c1*($group.energy+$shift) + flat_c2*($group.energy+$shift)**2)),\n"; |
| 1049 |
$cmd .= " $group.resid = $group.$suff - $group.postline)\n"; |
| 1050 |
$cmd .= "minimize($group.resid, x=$group.energy, xmin=$flat1, xmax=$flat2)\n"; |
| 1051 |
$cmd .= "unguess\n"; |
| 1052 |
} else { |
| 1053 |
$cmd = sprintf("# postline for non-normalized records\nset %s.postline = %g+%g*(%s.energy+%g)+%g*(%s.energy+%g)**2\n", |
| 1054 |
$group, $self->{bkg_nc0}, |
| 1055 |
$self->{bkg_nc1}, $group, $self->{bkg_eshift}, |
| 1056 |
$self->{bkg_nc2}, $group, $self->{bkg_eshift}); |
| 1057 |
}; |
| 1058 |
$self->dispose($cmd, $mode); |
| 1059 |
$this = sprintf("%s(%s.energy+%s, \"%s.postline+%s\"%s%s %s, style=lines, color=\"%s\", key=post%s)", |
| 1060 |
$plot, $group, $esh, $group, $yoffset, $labels, $scr, $xrange, $color, $title); |
| 1061 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 1062 |
$command .= $this; |
| 1063 |
($plot, $labels, $scr, $title, $xrange) = ("plot", "", "", ""); |
| 1064 |
++$cnt; |
| 1065 |
$markers and (not $deg) and |
| 1066 |
push @markers_e, $self->{bkg_nor1}+$self->{bkg_e0}, #+$self->{bkg_eshift}, |
| 1067 |
$self->{bkg_nor2}+$self->{bkg_e0}; #+$self->{bkg_eshift}; |
| 1068 |
## plot deglitching line in post-edge |
| 1069 |
if ($deg) { |
| 1070 |
$color = $default->{'color4'}; |
| 1071 |
my @x = Ifeffit::get_array("$group.energy"); |
| 1072 |
my @y = Ifeffit::get_array("$group.postline"); |
| 1073 |
my ($i, $j) = (0,0); |
| 1074 |
foreach (@x) { |
| 1075 |
last if ($_ > $self->{deg_emin}); |
| 1076 |
++$i; |
| 1077 |
}; |
| 1078 |
foreach (@x) { |
| 1079 |
last if ($_ > $self->{deg_emax}); |
| 1080 |
++$j; |
| 1081 |
}; |
| 1082 |
@x=splice(@x, $i, $j-$i); |
| 1083 |
@y=splice(@y, $i, $j-$i); |
| 1084 |
Ifeffit::put_array("$group.edeg", \@x); |
| 1085 |
Ifeffit::put_array("$group.xdeg", \@y); |
| 1086 |
$command .= "## deglitching margin lines are not available for plotting in a macro.\n"; |
| 1087 |
$command .= sprintf("plot(%s.edeg+%s, \"%s.xdeg+%g+%s\", style=lines, color=\"%s\", key=toler)\n", |
| 1088 |
$group, $esh, $group, $self->{deg_tol}, $yoffset, $color); |
| 1089 |
$command .= sprintf("plot(%s.edeg+%s, \"%s.xdeg-%g+%s\", style=lines, color=\"%s\")\n", |
| 1090 |
$group, $esh, $group, $self->{deg_tol}, $yoffset, $color); |
| 1091 |
push @markers_e, $self->{deg_emin}, #+$self->{bkg_eshift}, |
| 1092 |
$self->{deg_emax}; #+$self->{bkg_eshift}; |
| 1093 |
++$cnt; |
| 1094 |
}; |
| 1095 |
}; |
| 1096 |
if (not $deg and @markers_e and not $$rpf{suppress_markers}) { |
| 1097 |
@markers_e = sort {$a <=> $b} @markers_e; |
| 1098 |
my $suff = ($norm) ? "norm" : "xmu"; |
| 1099 |
($suff = 'flat') if ($norm and $self->{bkg_flatten}); |
| 1100 |
#($self->{is_nor}) and ($suff = "xmu"); |
| 1101 |
if ($der) { |
| 1102 |
foreach my $e (@markers_e) { |
| 1103 |
if ($smooth) { |
| 1104 |
$command .= "pmarker \"$group.energy+$self->{bkg_eshift}\", \"deriv($group.smooth)/deriv($group.energy)\", $e, $default->{marker}, $default->{markercolor}, $yoffset\n"; |
| 1105 |
} else { |
| 1106 |
$command .= "pmarker \"$group.energy+$self->{bkg_eshift}\", \"deriv($group.$suff)/deriv($group.energy)\", $e, $default->{marker}, $default->{markercolor}, $yoffset\n"; |
| 1107 |
}; |
| 1108 |
}; |
| 1109 |
} elsif ($second) { |
| 1110 |
foreach my $e (@markers_e) { |
| 1111 |
if ($smooth) { |
| 1112 |
$command .= "set $group.der = deriv($group.smooth)/deriv($group.energy)\n"; |
| 1113 |
} else { |
| 1114 |
$command .= "set $group.der = deriv($group.$suff)/deriv($group.energy)\n"; |
| 1115 |
}; |
| 1116 |
$command .= "pmarker \"$group.energy+$self->{bkg_eshift}\", \"deriv($group.der)/deriv($group.energy)\", $e, $default->{marker}, $default->{markercolor}, $yoffset\n"; |
| 1117 |
}; |
| 1118 |
} else { |
| 1119 |
foreach my $e (@markers_e) { |
| 1120 |
$command .= "pmarker \"$group.energy+$self->{bkg_eshift}\", $group.$suff, $e, $default->{marker}, $default->{markercolor}, $yoffset\n"; |
| 1121 |
}; |
| 1122 |
}; |
| 1123 |
}; |
| 1124 |
|
| 1125 |
&$echocmd("> plotting in energy from group \`$lab\'"); |
| 1126 |
##$command = wrap("", "", $command); |
| 1127 |
$self->dispose("$command", $mode); |
| 1128 |
$last_plot = $command; |
| 1129 |
|
| 1130 |
if ($$indicators[0]) { |
| 1131 |
my $suff = ($norm) ? "norm" : "xmu"; |
| 1132 |
($suff = "det") if $not_data; |
| 1133 |
my $sets = q{}; |
| 1134 |
if ($der) { |
| 1135 |
$sets = "set(i___ndic.y = deriv($group.$suff)/deriv($group.energy)+$yoffset,\n"; |
| 1136 |
} else { |
| 1137 |
$sets = "set(i___ndic.y = $group.$suff+$yoffset,\n"; |
| 1138 |
}; |
| 1139 |
my $eshift = $self->{bkg_eshift}; |
| 1140 |
$sets .= " i___ndic.x = $group.energy+$eshift)"; |
| 1141 |
$self->dispose($sets, $mode); |
| 1142 |
my @x = Ifeffit::get_array("i___ndic.x"); |
| 1143 |
my @y = Ifeffit::get_array("i___ndic.y"); |
| 1144 |
my ($ymin, $ymax) = $self->floor_ceil(\@x, \@y, $rpf, 'e', $self->{bkg_e0}); |
| 1145 |
#print join("|", $not_data, $ymin, $ymax), $/; |
| 1146 |
#(($ymin, $ymax) = ($plot_scale*$ymin, $plot_scale*$ymax)) if ($not_data); |
| 1147 |
my $diff = $ymax-$ymin; |
| 1148 |
$ymin -= $diff/20; |
| 1149 |
$ymax += $diff/20; |
| 1150 |
foreach my $i (@$indicators) { |
| 1151 |
next if ($i =~ /^[01]$/); |
| 1152 |
next if (lc($i->[1]) =~ /[r\s]/); |
| 1153 |
next if (lc($i->[2]) =~ /\A\s*\z/); |
| 1154 |
my $val = $i->[2]; |
| 1155 |
($val = $self->k2e($val)+$self->{bkg_e0}) if (lc($i->[1]) =~ /[kq]/); |
| 1156 |
next if ($val < 0); |
| 1157 |
$self->plot_vertical_line($val, $ymin, $ymax, $mode, "", 0, 0, 1) |
| 1158 |
}; |
| 1159 |
}; |
| 1160 |
|
| 1161 |
|
| 1162 |
&$echocmd("> plotting in energy from group \`$lab\' ... done!"); |
| 1163 |
if ($post and ($self->{bkg_fixstep})) { |
| 1164 |
&$echocmd("> Post edge line not plotted because the edge step was fixed.") |
| 1165 |
}; |
| 1166 |
&$errorcmd("> \`$lab\' has a plot multiplier of zero. Is that what you want?") |
| 1167 |
unless ($self->{plot_scale}); |
| 1168 |
}; |
| 1169 |
|
| 1170 |
sub floor_ceil { |
| 1171 |
my $self = shift; |
| 1172 |
my ($x, $y, $rpf, $space, $e0) = @_; |
| 1173 |
my ($ymin, $ymax, $i) = (1e10, -1e10, -1); |
| 1174 |
foreach my $xx (@$x) { |
| 1175 |
++$i; |
| 1176 |
next if ($xx < $$rpf{$space.'min'}+$e0); |
| 1177 |
last if ($xx > $$rpf{$space.'max'}+$e0); |
| 1178 |
($ymin = $$y[$i]) if ($$y[$i] < $ymin); |
| 1179 |
($ymax = $$y[$i]) if ($$y[$i] > $ymax); |
| 1180 |
}; |
| 1181 |
return ($ymin, $ymax); |
| 1182 |
}; |
| 1183 |
|
| 1184 |
## the argument is a character string which is decoded to indicate the |
| 1185 |
## k-weighting and whether the k-window should be plotted |
| 1186 |
sub plotk { |
| 1187 |
my $self = shift; |
| 1188 |
my ($group, $lab) = ($self->{group}, $self->{label}); |
| 1189 |
my $e0 = $self->{bkg_e0}; |
| 1190 |
unless (($self->{is_xmu}) or ($self->{is_chi})) { |
| 1191 |
if ($group eq "Default Parameters") { |
| 1192 |
&$errorcmd("> No data!"); |
| 1193 |
return 0; |
| 1194 |
}; |
| 1195 |
&$errorcmd("> The group \"$lab\" cannot be plotted in k-space."); |
| 1196 |
return 0; |
| 1197 |
}; |
| 1198 |
my ($str, $mode, $rpf, $indicators) = (lc($_[0]), $_[1], $_[2], $_[3]); |
| 1199 |
##($str eq 'k') and ($str = 'kw'); |
| 1200 |
my $win = $$rpf{k_win}; #((length($str) > 2) and ($str =~ /w$/)) ? 1 : 0; |
| 1201 |
my ($this, $command, $scale, $weight, $scr, $plot_scale, $yoffset) = |
| 1202 |
("", "", 1, 1, $default->{screen}, $self->{plot_scale}, $self->{plot_yoffset}); |
| 1203 |
my $color = $default->{color0}; |
| 1204 |
($self->{is_xmu}) and ($self->{update_bkg}) and $self->dispatch_bkg($mode); |
| 1205 |
$self->_MAKE(update_bkg=>0); |
| 1206 |
|
| 1207 |
##($str =~ /^kw/) and ($weight = $self->{fft_arbkw}); # parse indicator string |
| 1208 |
##($str =~ /^k([\d])/) and ($weight=$1); |
| 1209 |
##--- |
| 1210 |
## getting the new k-weighting scheme working.... |
| 1211 |
$weight = ($$rpf{kw} eq 'kw') ? $self->{fft_arbkw} : $$rpf{kw}; |
| 1212 |
$str .= $$rpf{chie}; |
| 1213 |
##--- |
| 1214 |
my $xrange = ""; |
| 1215 |
if ($rpf) { |
| 1216 |
$xrange = "xmin=$$rpf{kmin}, xmax=$$rpf{kmax}, "; |
| 1217 |
}; |
| 1218 |
|
| 1219 |
## determine parameters for legend |
| 1220 |
|
| 1221 |
my $k; |
| 1222 |
$k = "k\\u$weight\\d "; |
| 1223 |
($weight == 0) and ($k = ""); |
| 1224 |
($weight == 1) and ($k = "k "); |
| 1225 |
($weight >= 2) and ($k = "k\\u$weight\\d "); |
| 1226 |
my $suff = "k"; |
| 1227 |
$this = sprintf("newplot(%s.%s, \"(%s*%s.chi*%s.k^%.3g)+%s\",%s xlabel=\"k (\\A\\u-1\\d)\",ylabel=\"%s\\gx(k)\"%s, style=lines, color=\"%s\", key=\\gx(k), title=\"%s\")", |
| 1228 |
$group, $suff, $plot_scale, $group, $group, $weight, $yoffset, |
| 1229 |
$xrange, $k, $scr, $color, $lab); |
| 1230 |
if ($str =~ /e/) { |
| 1231 |
$suff = 'eee'; |
| 1232 |
$command .= "$group.eee = $group.k^2/etok+$e0$/"; |
| 1233 |
$xrange = ""; |
| 1234 |
if ($rpf) { |
| 1235 |
my @xrange = ($self->{bkg_e0}+$$rpf{emin}, $self->{bkg_e0}+$$rpf{emax}); |
| 1236 |
$xrange = " xmin=$xrange[0], xmax=$xrange[1], "; |
| 1237 |
}; |
| 1238 |
## labels are different for a chi(E) plot |
| 1239 |
$this = sprintf("newplot(%s.%s, \"(%s*%s.chi*%s.k^%.3g)+%s\",%s xlabel=\"E (eV)\",ylabel=\"%s\\gx(E)\"%s, style=lines, color=\"%s\", key=\\gx(E), title=\"%s\")", |
| 1240 |
$group, $suff, $plot_scale, $group, $group, $weight, $yoffset, |
| 1241 |
$xrange, $k, $scr, $color, $lab); |
| 1242 |
}; |
| 1243 |
## test if background removal is up to date |
| 1244 |
$this = wrap("", " ", $this) . $/; |
| 1245 |
$command .= $this; |
| 1246 |
if ($win) { |
| 1247 |
($self->{update_fft}) and $self->do_fft($mode, $rpf); |
| 1248 |
$self->_MAKE(update_fft=>0); |
| 1249 |
ifeffit("set ___x = ceil($group.chi*$plot_scale*$group.k^$weight)"); # scale window to plot |
| 1250 |
$scale = 1.05 * Ifeffit::get_scalar("___x"); |
| 1251 |
$color = $default->{color1}; |
| 1252 |
my $suff = ($str =~ /e/) ? "eee" : "k"; |
| 1253 |
$this = sprintf("plot(%s.$suff, \"%s.win*%f+%s\", style=lines, color=\"%s\", key=window)", |
| 1254 |
$group, $group, $scale, $yoffset, $color); |
| 1255 |
$this = wrap("", " ", $this) . $/; |
| 1256 |
$command .= $this; |
| 1257 |
}; |
| 1258 |
#$command .= ("plot(title=$group)\n"); |
| 1259 |
##print $command; |
| 1260 |
&$echocmd("> plotting in k-space from group \`$lab\'"); |
| 1261 |
##$command = wrap("", "", $command); |
| 1262 |
$self->dispose($command, $mode); |
| 1263 |
|
| 1264 |
if ($$indicators[0]) { |
| 1265 |
ifeffit("set i___ndic.x = $plot_scale*$group.chi*$group.k^$weight+$yoffset"); |
| 1266 |
my @x = Ifeffit::get_array("$group.$suff"); |
| 1267 |
my @y = Ifeffit::get_array("i___ndic.x"); |
| 1268 |
my $this = ($suff eq 'k') ? 0 : $e0; |
| 1269 |
my ($ymin, $ymax) = $self->floor_ceil(\@x, \@y, $rpf, 'e', $this); |
| 1270 |
$ymin *= 1.05; |
| 1271 |
$ymax *= 1.05; |
| 1272 |
foreach my $i (@$indicators) { |
| 1273 |
next if ($i =~ /^[01]$/); |
| 1274 |
next if (lc($i->[1]) =~ /[r\s]/); |
| 1275 |
next if (lc($i->[2]) =~ /\A\s*\z/); |
| 1276 |
my $val = $i->[2]; |
| 1277 |
($val = $self->e2k($val)) if ((lc($i->[1]) eq "e") and ($suff eq 'k')); |
| 1278 |
($val = $self->k2e($val)) if ((lc($i->[1]) ne "e") and ($suff ne 'k')); |
| 1279 |
next if ($val < 0); |
| 1280 |
$self->plot_vertical_line($val, $ymin, $ymax, $mode, "", 0, 0, 1) |
| 1281 |
}; |
| 1282 |
|
| 1283 |
## foreach my $i (@$indicators) { |
| 1284 |
## next if ($i =~ /^[01]$/); |
| 1285 |
## next if (lc($i->[1]) =~ /[r\s]/); |
| 1286 |
## my $val = $i->[2]; |
| 1287 |
## ($val = $self->e2k($val)) if (lc($i->[1]) eq "e"); |
| 1288 |
## next if ($val < 0); |
| 1289 |
## ifeffit("set ___x = ceil($plot_scale*$group.chi*$group.k^$weight+$yoffset)"); |
| 1290 |
## my $ymax = Ifeffit::get_scalar("___x") * 1.05; |
| 1291 |
## ifeffit("set ___x = floor($plot_scale*$group.chi*$group.k^$weight+$yoffset)"); |
| 1292 |
## my $ymin = Ifeffit::get_scalar("___x") * 1.05; |
| 1293 |
## $self->plot_vertical_line($val, $ymin, $ymax, $mode, "", 0, 0, 1) |
| 1294 |
## }; |
| 1295 |
}; |
| 1296 |
|
| 1297 |
$last_plot = $command; |
| 1298 |
($self->{plot_scale}) ? &$echocmd("> plotting in k-space from group \`$lab\' ... done!") : |
| 1299 |
&$errorcmd("> \`$lab\' has a plot multiplier of zero. Is that what you want?"); |
| 1300 |
}; |
| 1301 |
|
| 1302 |
## the argument is a character string which is decoded to indicate |
| 1303 |
## which of magnitude, phase, real, and imaginary should be plotted |
| 1304 |
## and whether the R-window should be plotted. There is also the |
| 1305 |
## option of plotting the envelope, which is the magnitude plotted |
| 1306 |
## with the negated magnitude |
| 1307 |
sub plotR { |
| 1308 |
my $self = shift; |
| 1309 |
my ($group, $lab) = ($self->{group}, $self->{label}); |
| 1310 |
if (($self->{is_qsp}) or ($group eq 'Default Parameters') or ($self->{not_data})) { |
| 1311 |
if ($group eq "Default Parameters") { |
| 1312 |
&$errorcmd("> No data!"); |
| 1313 |
return 0; |
| 1314 |
}; |
| 1315 |
&$errorcmd("> The group \"$lab\" cannot be plotted in R space."); |
| 1316 |
return 0; |
| 1317 |
}; |
| 1318 |
#my $w = $self->{fft_kw} + 1; |
| 1319 |
my ($str, $mode, $rpf, $indicators) = (lc(substr($_[0], 1)), $_[1], $_[2], $_[3]); |
| 1320 |
my $w = $$rpf{kw} + 1; |
| 1321 |
#($str eq 'r') and ($str = 'rm'); |
| 1322 |
my $win = 0; |
| 1323 |
($str =~ /w$/) and ($win = 1); |
| 1324 |
my ($this, $command, $plot, $scale, $scr, $title, $plot_scale, $yoffset) = |
| 1325 |
("", "", "newplot", 1, $default->{screen}, ", title=\"$lab\"", $self->{plot_scale}, $self->{plot_yoffset}); |
| 1326 |
my $labels = sprintf(", xlabel=\"R (\\A)\", ylabel=\"|\\gx(R)| (\\A\\u-%d\\d)\"", $w); |
| 1327 |
my $cnt = 0; |
| 1328 |
my $color; |
| 1329 |
my $xrange = ""; |
| 1330 |
if ($rpf) { |
| 1331 |
$xrange = ", xmin=$$rpf{rmin}, xmax=$$rpf{rmax}"; |
| 1332 |
}; |
| 1333 |
($self->{update_bkg}) and $self->dispatch_bkg($mode); |
| 1334 |
$self->_MAKE(update_bkg=>0); |
| 1335 |
($self->{update_fft}) and $self->do_fft($mode, $rpf); |
| 1336 |
$self->_MAKE(update_fft=>0); |
| 1337 |
|
| 1338 |
if ($str =~ /e/) { |
| 1339 |
$color = $default->{'color'.$cnt}; |
| 1340 |
$this = sprintf("%s(%s.r, \"%s*%s.chir_mag+%s\"%s%s %s, style=lines, color=\"%s\", key=\"Env[\\gx(R)]\"%s)", |
| 1341 |
$plot, $group, $plot_scale, $group, $yoffset, |
| 1342 |
$labels, $scr, $xrange, $color, $title); |
| 1343 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 1344 |
$command .= $this; |
| 1345 |
$this = sprintf("plot(%s.r, \"-%s*%s.chir_mag+%s\", style=lines, color=\"%s\", key=\"\")", |
| 1346 |
$group, $plot_scale, $group, $yoffset, $color); |
| 1347 |
$this = wrap("", " ", $this) . $/; |
| 1348 |
$command .= $this; |
| 1349 |
($plot, $labels, $scr, $title) = ("plot", "", "", ""); |
| 1350 |
++$cnt; |
| 1351 |
}; |
| 1352 |
if ($str =~ /m/) { |
| 1353 |
$color = $default->{'color'.$cnt}; |
| 1354 |
$this = sprintf("%s(%s.r, \"%s*%s.chir_mag+%s\"%s%s %s, style=lines, color=\"%s\", key=\"|\\gx(R)|\"%s)", |
| 1355 |
$plot, $group, $plot_scale, $group, $yoffset, |
| 1356 |
$labels, $scr, $xrange, $color, $title); |
| 1357 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 1358 |
$command .= $this; |
| 1359 |
($plot, $labels, $scr, $title) = ("plot", "", "", ""); |
| 1360 |
++$cnt; |
| 1361 |
}; |
| 1362 |
if ($str =~ /r/) { |
| 1363 |
$color = $default->{'color'.$cnt}; |
| 1364 |
$this = sprintf("%s(%s.r, \"%s*%s.chir_re+%s\"%s%s %s, style=lines, color=\"%s\", key=\"Re[\\gx(R)]\"%s)", |
| 1365 |
$plot, $group, $plot_scale, $group, $yoffset, |
| 1366 |
$labels, $scr, $xrange, $color, $title); |
| 1367 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 1368 |
$command .= $this; |
| 1369 |
($plot, $labels, $scr, $title) = ("plot", "", "", ""); |
| 1370 |
++$cnt; |
| 1371 |
}; |
| 1372 |
if ($str =~ /i/) { |
| 1373 |
$color = $default->{'color'.$cnt}; |
| 1374 |
$this = sprintf("%s(%s.r, \"%s*%s.chir_im+%s\"%s%s %s, style=lines, color=\"%s\", key=\"Im[\\gx(R)]\"%s)", |
| 1375 |
$plot, $group, $plot_scale, $group, $yoffset, |
| 1376 |
$labels, $scr, $xrange, $color); |
| 1377 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 1378 |
$command .= $this; |
| 1379 |
($plot, $labels, $scr, $title) = ("plot", "", "", ""); |
| 1380 |
++$cnt; |
| 1381 |
}; |
| 1382 |
if ($str =~ /p/) { |
| 1383 |
$color = $default->{'color'.$cnt}; |
| 1384 |
$this = sprintf("%s(%s.r, \"%s.chir_pha+%s\"%s%s %s, style=lines, color=\"%s\", key=\"Phase[\\gx(R)]\"%s)", |
| 1385 |
$plot, $group, $group,, $yoffset, |
| 1386 |
$labels, $scr, $xrange, $color, $title); |
| 1387 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 1388 |
$command .= $this; |
| 1389 |
($plot, $labels, $scr, $title) = ("plot", "", "", ""); |
| 1390 |
++$cnt; |
| 1391 |
}; |
| 1392 |
if ($win) { # need to scale it |
| 1393 |
($self->{update_bft}) and $self->do_bft($mode); |
| 1394 |
$self->_MAKE(update_bft=>0); |
| 1395 |
ifeffit("set ___x = ceil($group.chir_mag)"); # scale window to plot |
| 1396 |
$scale = 1.05 * $plot_scale * Ifeffit::get_scalar("___x"); |
| 1397 |
$color = $default->{'color'.$cnt}; |
| 1398 |
$this = sprintf("%s(%s.r, \"%s.rwin*%.2f+%s\"%s%s %s, style=lines, color=\"%s\", key=window%s)", |
| 1399 |
$plot, $group, $group, $scale, $yoffset, |
| 1400 |
$labels, $scr, $xrange, $color, $title); |
| 1401 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 1402 |
$command .= $this; |
| 1403 |
($plot, $labels, $scr) = ("plot", "", "", ""); |
| 1404 |
++$cnt; |
| 1405 |
}; |
| 1406 |
##print $command; |
| 1407 |
&$echocmd("> plotting in R-space from group \`$lab\'"); |
| 1408 |
## $command = wrap("", "", $command); |
| 1409 |
$self->dispose($command, $mode); |
| 1410 |
if ($$indicators[0]) { |
| 1411 |
my $suff = "chir_re"; |
| 1412 |
($suff = "chir_mag") if ($str !~ /[eir]/); |
| 1413 |
($suff = "chir_pha") if ($str =~ /p/); |
| 1414 |
ifeffit("set i___ndic.x = $plot_scale*$group.$suff+$yoffset"); |
| 1415 |
my @x = Ifeffit::get_array("$group.r"); |
| 1416 |
my @y = Ifeffit::get_array("i___ndic.x"); |
| 1417 |
my ($ymin, $ymax) = $self->floor_ceil(\@x, \@y, $rpf, 'r', 0); |
| 1418 |
$ymin *= 1.05; |
| 1419 |
$ymax *= 1.05; |
| 1420 |
foreach my $i (@$indicators) { |
| 1421 |
next if ($i =~ /^[01]$/); |
| 1422 |
next unless (lc($i->[1]) eq 'r'); |
| 1423 |
next if (lc($i->[2]) =~ /\A\s*\z/); |
| 1424 |
my $val = $i->[2]; |
| 1425 |
next if ($val < 0); |
| 1426 |
$self->plot_vertical_line($val, $ymin, $ymax, $mode, "", 0, 0, 1) |
| 1427 |
}; |
| 1428 |
|
| 1429 |
}; |
| 1430 |
|
| 1431 |
|
| 1432 |
$last_plot = $command; |
| 1433 |
($self->{plot_scale}) ? &$echocmd("> plotting in R-space from group \`$lab\' ... done!") : |
| 1434 |
&$errorcmd("> \`$lab\' has a plot multiplier of zero. Is that what you want?"); |
| 1435 |
}; |
| 1436 |
|
| 1437 |
## the argument is a character string which is decoded to indicate |
| 1438 |
## which of magnitude, phase, real, and imaginary should be plotted |
| 1439 |
## and whether the k-window should be plotted. There is also the |
| 1440 |
## option of plotting the envelope, which is the magnitude plotted |
| 1441 |
## with the negated magnitude |
| 1442 |
sub plotq { |
| 1443 |
my $self = shift; |
| 1444 |
my ($group, $lab) = ($self->{group}, $self->{label}); |
| 1445 |
if (($group eq 'Default Parameters') or ($self->{not_data})) { |
| 1446 |
if ($group eq "Default Parameters") { |
| 1447 |
&$errorcmd("> No data!"); |
| 1448 |
return 0; |
| 1449 |
}; |
| 1450 |
&$errorcmd("> The group \"$lab\" cannot be plotted in q space."); |
| 1451 |
return 0; |
| 1452 |
}; |
| 1453 |
my ($str, $mode, $rpf, $indicators) = (lc($_[0]), $_[1], $_[2], $_[3]); |
| 1454 |
($str eq 'q') and ($str = 'qi'); |
| 1455 |
my $win = 0; |
| 1456 |
($str =~ /w$/) and ($win = 1); |
| 1457 |
my ($this, $command, $plot, $scale, $scr, $title, $plot_scale, $yoffset) = |
| 1458 |
("", "", "newplot", 1, $default->{screen}, ", title=\"$lab\"", $self->{plot_scale}, $self->{plot_yoffset}); |
| 1459 |
#my $w = $self->{fft_kw}; |
| 1460 |
my $w = $$rpf{kw}; |
| 1461 |
my $labels = sprintf(", xlabel=\"k (\\A\\u-1\\d)\",ylabel=\"|\\gx(q)| (\\A\\u-%d\\d)\"", $w); |
| 1462 |
my $cnt = 0; |
| 1463 |
my $color; |
| 1464 |
my $xrange = ""; |
| 1465 |
if ($rpf) { |
| 1466 |
$xrange = "xmin=$$rpf{qmin}, xmax=$$rpf{qmax}, "; |
| 1467 |
}; |
| 1468 |
($self->{update_bkg}) and $self->dispatch_bkg($mode); |
| 1469 |
$self->_MAKE(update_bkg=>0); |
| 1470 |
($self->{update_fft}) and $self->do_fft($mode, $rpf); |
| 1471 |
$self->_MAKE(update_fft=>0); |
| 1472 |
($self->{update_bft}) and $self->do_bft($mode); |
| 1473 |
$self->_MAKE(update_bft=>0); |
| 1474 |
|
| 1475 |
if ($str =~ /e/) { |
| 1476 |
$color = $default->{'color'.$cnt}; |
| 1477 |
$this = sprintf("%s(%s.q, \"%s*%s.chiq_mag+%s\"%s%s, style=lines, color=\"%s\",%s key=\"Env[\\gx(q)]\"%s)", |
| 1478 |
$plot, $group, $plot_scale, $group, $yoffset, |
| 1479 |
$labels, $scr, $color, $xrange, $title); |
| 1480 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 1481 |
$command .= $this; |
| 1482 |
$this = sprintf("plot(%s.q, \"-%s*%s.chiq_mag+%s\", style=lines, color=\"%s\", key=\"\")", |
| 1483 |
$group, $plot_scale, $group, $yoffset, $color); |
| 1484 |
$this = wrap("", " ", $this) . $/; |
| 1485 |
$command .= $this; |
| 1486 |
($plot, $labels, $scr, $title) = ("plot", "", "", ""); |
| 1487 |
++$cnt; |
| 1488 |
}; |
| 1489 |
if ($str =~ /m/) { |
| 1490 |
$color = $default->{'color'.$cnt}; |
| 1491 |
$this = sprintf("%s(%s.q, \"%s*%s.chiq_mag+%s\"%s%s, style=lines, color=\"%s\",%s key=\"|\\gx(q)|\"%s)", |
| 1492 |
$plot, $group, $plot_scale, $group, $yoffset, |
| 1493 |
$labels, $scr, $color, $xrange, $title); |
| 1494 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 1495 |
$command .= $this; |
| 1496 |
($plot, $labels, $scr, $title) = ("plot", "", "", ""); |
| 1497 |
++$cnt; |
| 1498 |
}; |
| 1499 |
if ($str =~ /r/) { |
| 1500 |
$color = $default->{'color'.$cnt}; |
| 1501 |
$this = sprintf("%s(%s.q, \"%s*%s.chiq_re+%s\"%s%s, style=lines, color=\"%s\",%s key=\"Re[\\gx(q)]\"%s)", |
| 1502 |
$plot, $group, $plot_scale, $group, $yoffset, |
| 1503 |
$labels, $scr, $color, $xrange, $title); |
| 1504 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 1505 |
$command .= $this; |
| 1506 |
($plot, $labels, $scr, $title) = ("plot", "", "", ""); |
| 1507 |
++$cnt; |
| 1508 |
}; |
| 1509 |
if ($str =~ /i/) { |
| 1510 |
$color = $default->{'color'.$cnt}; |
| 1511 |
$this = sprintf("%s(%s.q, \"%s*%s.chiq_im+%s\"%s%s, style=lines, color=\"%s\",%s key=\"Im[\\gx(q)]\"%s)", |
| 1512 |
$plot, $group, $plot_scale, $group, $yoffset, |
| 1513 |
$labels, $scr, $color, $xrange, $title); |
| 1514 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 1515 |
$command .= $this; |
| 1516 |
($plot, $labels, $scr, $title) = ("plot", "", "", ""); |
| 1517 |
++$cnt; |
| 1518 |
}; |
| 1519 |
if ($str =~ /p/) { |
| 1520 |
$color = $default->{'color'.$cnt}; |
| 1521 |
$this = sprintf("%s(%s.q, \"%s.chiq_pha+%s\"%s%s, style=lines, color=\"%s\",%s key=\"Phase[\\gx(q)]\"%s)", |
| 1522 |
$plot, $group, $group, $yoffset, |
| 1523 |
$labels, $scr, $color, $xrange, $title); |
| 1524 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 1525 |
$command .= $this; |
| 1526 |
($plot, $labels, $scr, $title) = ("plot", "", "", ""); |
| 1527 |
++$cnt; |
| 1528 |
}; |
| 1529 |
if ($win) { # need to scale it correctly |
| 1530 |
$color = $default->{'color'.$cnt}; |
| 1531 |
ifeffit("set ___x = ceil($group.chiq_mag)"); # scale window to plot |
| 1532 |
$scale = 1.05 * $plot_scale * Ifeffit::get_scalar("___x"); |
| 1533 |
$this = sprintf("%s(%s.q, \"%s.win*%.2f+%s\", style=lines, color=\"%s\",%s key=window%s)", |
| 1534 |
$plot, $group, $group, $scale, $yoffset, $color, $title); |
| 1535 |
$this = wrap("", " " x (length($plot)+1), $this) . $/; |
| 1536 |
$command .= $this; |
| 1537 |
($plot, $labels, $scr, $title) = ("plot", "", "", ""); |
| 1538 |
++$cnt; |
| 1539 |
}; |
| 1540 |
##print $command; |
| 1541 |
&$echocmd("> plotting in q-space from group \`$lab\'"); |
| 1542 |
##$command = wrap("", "", $command); |
| 1543 |
$self->dispose($command, $mode); |
| 1544 |
if ($$indicators[0]) { |
| 1545 |
my $suff = "chiq_re"; |
| 1546 |
($suff = "chiq_mag") if ($str !~ /[eir]/); |
| 1547 |
($suff = "chiq_pha") if ($str =~ /p/); |
| 1548 |
ifeffit("set i___ndic.x = $plot_scale*$group.$suff+$yoffset"); |
| 1549 |
my @x = Ifeffit::get_array("$group.q"); |
| 1550 |
my @y = Ifeffit::get_array("i___ndic.x"); |
| 1551 |
my ($ymin, $ymax) = $self->floor_ceil(\@x, \@y, $rpf, 'q', 0); |
| 1552 |
$ymin *= 1.05; |
| 1553 |
$ymax *= 1.05; |
| 1554 |
foreach my $i (@$indicators) { |
| 1555 |
next if ($i =~ /^[01]$/); |
| 1556 |
next if (lc($i->[1]) =~ /[r\s]/); |
| 1557 |
next if (lc($i->[2]) =~ /\A\s*\z/); |
| 1558 |
my $val = $i->[2]; |
| 1559 |
($val = $self->e2k($val)) if (lc($i->[1]) eq "e"); |
| 1560 |
next if ($val < 0); |
| 1561 |
$self->plot_vertical_line($val, $ymin, $ymax, $mode, "", 0, 0, 1) |
| 1562 |
}; |
| 1563 |
}; |
| 1564 |
$last_plot = $command; |
| 1565 |
($self->{plot_scale}) ? &$echocmd("> plotting in q-space from group \`$lab\' ... done!") : |
| 1566 |
&$errorcmd("> \`$lab\' has a plot multiplier of zero. Is that what you want?"); |
| 1567 |
}; |
| 1568 |
|
| 1569 |
|
| 1570 |
## the argument is a character string which is decoded to indicate the |
| 1571 |
## k-weighting and whether the k-window should be plotted |
| 1572 |
sub plotkq { |
| 1573 |
my $self = shift; |
| 1574 |
my ($group, $lab) = ($self->{group}, $self->{label}); |
| 1575 |
unless (($self->{is_xmu}) or ($self->{is_chi})) { |
| 1576 |
if ($group eq "Default Parameters") { |
| 1577 |
&$errorcmd("> No data!"); |
| 1578 |
return 0; |
| 1579 |
}; |
| 1580 |
&$errorcmd("> The group \"$lab\" cannot be plotted in k-space."); |
| 1581 |
return 0; |
| 1582 |
}; |
| 1583 |
my ($str, $mode, $rpf, $indicators) = (lc($_[0]), $_[1], $_[2], $_[3]); |
| 1584 |
my $win = ($str =~ /w/) ? 1 : 0; |
| 1585 |
my ($this, $command, $scale, $weight, $scr, $plot_scale, $yoffset) = |
| 1586 |
("", "", 1, 1, $default->{screen}, $self->{plot_scale}, $self->{plot_yoffset}); |
| 1587 |
my $color = $default->{color0}; |
| 1588 |
#$weight = $self->{fft_kw}; |
| 1589 |
$weight = $$rpf{kw}; |
| 1590 |
my $xrange = ""; |
| 1591 |
if ($rpf) { |
| 1592 |
$xrange = "xmin=$$rpf{kmin}, xmax=$$rpf{kmax}, "; |
| 1593 |
}; |
| 1594 |
|
| 1595 |
($self->{is_xmu}) and ($self->{update_bkg}) and $self->dispatch_bkg($mode); |
| 1596 |
($self->{update_bkg}) and $self->dispatch_bkg($mode); |
| 1597 |
$self->_MAKE(update_bkg=>0); |
| 1598 |
($self->{update_fft}) and $self->do_fft($mode, $rpf); |
| 1599 |
$self->_MAKE(update_fft=>0); |
| 1600 |
($self->{update_bft}) and $self->do_bft($mode); |
| 1601 |
$self->_MAKE(update_bft=>0); |
| 1602 |
|
| 1603 |
## determine parameters for legend |
| 1604 |
|
| 1605 |
my $k; |
| 1606 |
($weight == 0) and ($k = ""); |
| 1607 |
($weight == 1) and ($k = "k "); |
| 1608 |
($weight >= 2) and ($k = "k\\u$weight\\d "); |
| 1609 |
## test if background removal is up to date |
| 1610 |
$this = sprintf("newplot(%s.k, \"%s.chi*%s.k^%d+%s\",%s xlabel=\"k (\\A\\u-1\\d)\",ylabel=\"%s\\gx(k)\"%s, style=lines, color=\"%s\", key=\\gx(k), title=\"%s\")", |
| 1611 |
$group, $group, $group, $weight, $yoffset, |
| 1612 |
$xrange, $k, $scr, $color, $lab); |
| 1613 |
$this = wrap("", " ", $this) . $/; |
| 1614 |
$command .= $this; |
| 1615 |
|
| 1616 |
$color = $default->{color1}; |
| 1617 |
$this = sprintf("plot(%s.q, \"%s.chiq_re+%s\", style=lines, color=\"%s\", key=\"Re[\\gx(q)]\")", |
| 1618 |
$group, $group, $yoffset, $color); |
| 1619 |
$this = wrap("", " ", $this) . $/; |
| 1620 |
$command .= $this; |
| 1621 |
|
| 1622 |
if ($win) { |
| 1623 |
($self->{update_fft}) and $self->do_fft($mode, $rpf); |
| 1624 |
$self->_MAKE(update_fft=>0); |
| 1625 |
ifeffit("set ___x = ceil($group.chi*$plot_scale*$group.k^$weight)"); # scale window to plot |
| 1626 |
$scale = 1.05 * Ifeffit::get_scalar("___x"); |
| 1627 |
$color = $default->{color2}; |
| 1628 |
$this = sprintf("plot(%s.k, \"%s.win*%f+%s\", style=lines, color=\"%s\", key=window)", |
| 1629 |
$group, $group, $scale, $yoffset, $color); |
| 1630 |
$this = wrap("", " ", $this) . $/; |
| 1631 |
$command .= $this; |
| 1632 |
}; |
| 1633 |
|
| 1634 |
|
| 1635 |
&$echocmd("> plotting in k/q from group \`$lab\'"); |
| 1636 |
##$command = wrap("", "", $command); |
| 1637 |
$self->dispose($command, $mode); |
| 1638 |
if ($$indicators[0]) { |
| 1639 |
foreach my $i (@$indicators) { |
| 1640 |
next if ($i =~ /^[01]$/); |
| 1641 |
next if (lc($i->[1]) =~ /[r\s]/); |
| 1642 |
next if (lc($i->[2]) =~ /\A\s*\z/); |
| 1643 |
my $val = $i->[2]; |
| 1644 |
($val = $self->e2k($val)) if (lc($i->[1]) eq "e"); |
| 1645 |
next if ($val < 0); |
| 1646 |
ifeffit("set ___x = ceil($plot_scale*$group.chi*$group.k^$weight+$yoffset)"); |
| 1647 |
my $ymax = Ifeffit::get_scalar("___x") * 1.05; |
| 1648 |
ifeffit("set ___x = floor($plot_scale*$group.chi*$group.k^$weight+$yoffset)"); |
| 1649 |
my $ymin = Ifeffit::get_scalar("___x") * 1.05; |
| 1650 |
$self->plot_vertical_line($val, $ymin, $ymax, $mode, "", 0, 0, 1) |
| 1651 |
}; |
| 1652 |
}; |
| 1653 |
$last_plot = $command; |
| 1654 |
&$echocmd("> plotting in k/q from group \`$lab\' ... done!"); |
| 1655 |
|
| 1656 |
##&$echocmd(@done); |
| 1657 |
}; |
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
## the first argument indicates the type of multi-data set plot, the |
| 1663 |
## second and third are references to the groups and marked hashes. |
| 1664 |
## The options are |
| 1665 |
## e, n, d mu, normalized mu, or deriv of mu |
| 1666 |
## kw, 0, 1, 2, 3, e chi(k) with k-weight or chi(E) with k-weight |
| 1667 |
## rm, rp, rr, ri chi(R), magnitude, phase, real, imaginary |
| 1668 |
## qm, qp, qr, qi chi(q), magnitude, phase, real, imaginary |
| 1669 |
sub plot_marked { |
| 1670 |
my $self = shift; |
| 1671 |
my $group = $self->{group}; |
| 1672 |
my ($space, $mode, $r_groups, $r_marked, $rpf, $canvas, $indicators) = @_; |
| 1673 |
my $m = 0; # check that something is marked |
| 1674 |
map {$m ||= $_} values %$r_marked; |
| 1675 |
unless ($m) { |
| 1676 |
&$errorcmd("> Multiple group plot aborted. There are no marked groups."); |
| 1677 |
return 1; |
| 1678 |
}; |
| 1679 |
$space = lc($space); |
| 1680 |
$space .= $$rpf{chie} if ($space !~ /^[enqr]/); |
| 1681 |
my ($x, $y, $this, $command, $plot, $w, $defw) = |
| 1682 |
("", "", "", "", "newplot", -1, $$r_groups{'Default Parameters'}->{fft_arbkw}); |
| 1683 |
my $scr = $default->{screen}; |
| 1684 |
my $title_string = ($$rpf{project}) ? basename($$rpf{project}) : "all marked groups"; |
| 1685 |
$title_string =~ s{\.prj$}{}; |
| 1686 |
my $title = ", title='$title_string'"; |
| 1687 |
my ($xo, $xf, $yf, $yi); |
| 1688 |
## need to get kw from default parameters |
| 1689 |
## get the list in the order placed on the skinny canvas |
| 1690 |
my @keys = sort {($canvas->bbox($$r_groups{$a}->{text}))[1] <=> |
| 1691 |
($canvas->bbox($$r_groups{$b}->{text}))[1]} (keys (%$r_marked)); |
| 1692 |
my $first; |
| 1693 |
foreach (@keys) { # find the first marked group name |
| 1694 |
$first = $_, last if $$r_marked{$_}; |
| 1695 |
}; |
| 1696 |
|
| 1697 |
SWITCH: { # set column names |
| 1698 |
($x, $y) = ("energy", "xmu"), last SWITCH if ($space eq 'e'); |
| 1699 |
#($x, $y) = ("energy", "flat"), last SWITCH if (($space eq 'n') and $default->{flatten}); |
| 1700 |
($x, $y) = ("energy", "norm"), last SWITCH if ($space eq 'n'); |
| 1701 |
#($x, $y) = ("energy", "der"), last SWITCH if ($space eq 'd'); |
| 1702 |
($x, $y, $w) = ("k", "chi", 'w'), last SWITCH if ($space eq 'kw'); |
| 1703 |
($x, $y, $w) = ("k", "chi", 0), last SWITCH if ($space eq '0'); |
| 1704 |
($x, $y, $w) = ("k", "chi", 1), last SWITCH if ($space eq '1'); |
| 1705 |
($x, $y, $w) = ("k", "chi", 2), last SWITCH if ($space eq '2'); |
| 1706 |
($x, $y, $w) = ("k", "chi", 3), last SWITCH if ($space eq '3'); |
| 1707 |
($x, $y, $w) = ("eee", "chi", 'w'), last SWITCH if ($space eq 'kwe'); |
| 1708 |
($x, $y, $w) = ("eee", "chi", 0), last SWITCH if ($space eq '0e'); |
| 1709 |
($x, $y, $w) = ("eee", "chi", 1), last SWITCH if ($space eq '1e'); |
| 1710 |
($x, $y, $w) = ("eee", "chi", 2), last SWITCH if ($space eq '2e'); |
| 1711 |
($x, $y, $w) = ("eee", "chi", 3), last SWITCH if ($space eq '3e'); |
| 1712 |
($x, $y) = ("r", "chir_mag"), last SWITCH if ($space eq 'rm'); |
| 1713 |
($x, $y) = ("r", "chir_re"), last SWITCH if ($space eq 'rr'); |
| 1714 |
($x, $y) = ("r", "chir_im"), last SWITCH if ($space eq 'ri'); |
| 1715 |
($x, $y) = ("r", "chir_pha"), last SWITCH if ($space eq 'rp'); |
| 1716 |
($x, $y) = ("q", "chiq_mag"), last SWITCH if ($space eq 'qm'); |
| 1717 |
($x, $y) = ("q", "chiq_re"), last SWITCH if ($space eq 'qr'); |
| 1718 |
($x, $y) = ("q", "chiq_im"), last SWITCH if ($space eq 'qi'); |
| 1719 |
($x, $y) = ("q", "chiq_pha"), last SWITCH if ($space eq 'qp'); |
| 1720 |
}; |
| 1721 |
##print join(" ", $space, $x, $y, $w), $/; |
| 1722 |
return unless &::verify_ranges($first, $x, 1); |
| 1723 |
my $cnt = 0; |
| 1724 |
my $color; |
| 1725 |
my $labels; |
| 1726 |
my $xrange = ""; |
| 1727 |
SWITCH: { |
| 1728 |
($x eq 'energy') and do { |
| 1729 |
my ($xn, $xx) = ($$r_groups{$first}->{bkg_e0}+$$rpf{emin}, |
| 1730 |
$$r_groups{$first}->{bkg_e0}+$$rpf{emax}); |
| 1731 |
$xrange = ", xmin=$xn, xmax=$xx"; |
| 1732 |
last SWITCH; |
| 1733 |
}; |
| 1734 |
($x eq 'k') and do { |
| 1735 |
$xrange = ", xmin=$$rpf{kmin}, xmax=$$rpf{kmax}"; |
| 1736 |
last SWITCH; |
| 1737 |
}; |
| 1738 |
($x eq 'eee') and do { |
| 1739 |
my ($xn, $xx) = ($$r_groups{$first}->{bkg_e0}+$$rpf{emin}, |
| 1740 |
$$r_groups{$first}->{bkg_e0}+$$rpf{emax}); |
| 1741 |
$xrange = ", xmin=$xn, xmax=$xx"; |
| 1742 |
#$self->dispose("$first.eee = $first.k^2 / etok + $$r_groups{$first}->{bkg_e0}\n", $mode); |
| 1743 |
last SWITCH; |
| 1744 |
}; |
| 1745 |
($x eq 'r') and do { |
| 1746 |
$xrange = ", xmin=$$rpf{rmin}, xmax=$$rpf{rmax}"; |
| 1747 |
last SWITCH; |
| 1748 |
}; |
| 1749 |
($x eq 'q') and do { |
| 1750 |
$xrange = ", xmin=$$rpf{qmin}, xmax=$$rpf{qmax}"; |
| 1751 |
last SWITCH; |
| 1752 |
}; |
| 1753 |
}; |
| 1754 |
|
| 1755 |
##my $first = (keys (%$r_marked))[0]; |
| 1756 |
if ($x eq "energy") { |
| 1757 |
## handle norm and deriv |
| 1758 |
my $type = ""; |
| 1759 |
my $smoothed = ($$rpf{smoothderiv}) ? "smoothed " : q{}; |
| 1760 |
SWITCH: { |
| 1761 |
($type = $smoothed."derivative of normalized"), last SWITCH if ($$rpf{e_mderiv} and ($y eq 'norm')); |
| 1762 |
($type = $smoothed."derivative of"), last SWITCH if $$rpf{e_mderiv}; |
| 1763 |
($type = "normalized"), last SWITCH if ($y eq 'norm'); |
| 1764 |
($type = "flattened, normalized"), last SWITCH if ($y eq 'flat'); |
| 1765 |
($type = $smoothed."derivative of"), last SWITCH if ($y eq 'der'); |
| 1766 |
}; |
| 1767 |
$labels = ", xlabel=\"E (eV)\", ylabel=\"$type x\\gm(E)\""; |
| 1768 |
my $sp = ($y eq 'norm') ? 'n' : 'e'; |
| 1769 |
} elsif ($x eq "k") { |
| 1770 |
my $k; |
| 1771 |
SWITCH: { |
| 1772 |
($k = "k\\ukw\\d "), last SWITCH if ($w eq 'w'); |
| 1773 |
($k = ""), last SWITCH if ($w == 0); |
| 1774 |
($k = "k "), last SWITCH if ($w == 1); |
| 1775 |
($k = "k\\u$w\\d "), last SWITCH if ($w >= 2); |
| 1776 |
}; |
| 1777 |
$labels = sprintf(", xlabel=\"k (\\A\\u-1\\d)\",ylabel=\"%s\\gx(k) (\\A\\u-%s\\d)\"", |
| 1778 |
$k, $w); |
| 1779 |
} elsif ($x eq "eee") { |
| 1780 |
my $k; |
| 1781 |
SWITCH: { |
| 1782 |
($k = "k\\ukw\\d "), last SWITCH if ($w eq 'w'); |
| 1783 |
($k = ""), last SWITCH if ($w == 0); |
| 1784 |
($k = "k "), last SWITCH if ($w == 1); |
| 1785 |
($k = "k\\u$w\\d "), last SWITCH if ($w >= 2); |
| 1786 |
}; |
| 1787 |
$labels = sprintf(", xlabel=\"E (eV)\",ylabel=\"%s\\gx(E) (\\A\\u-%s\\d)\"", |
| 1788 |
$k, $w); |
| 1789 |
} elsif ($x eq "r") { |
| 1790 |
#my $w = $self->{fft_kw}+1; |
| 1791 |
my $w = ($$rpf{kw} eq 'kw') ? $self->{fft_arbkw}+1 : $$rpf{kw}+1; |
| 1792 |
my $y = "|\\gx(R)|"; |
| 1793 |
($y = "Re[\\gx(R)]") if ($space eq 'rr'); |
| 1794 |
($y = "Im[\\gx(R)]") if ($space eq 'ri'); |
| 1795 |
($y = "Phase[\\gx(R)]") if ($space eq 'rp'); |
| 1796 |
$labels = sprintf(", xlabel=\"R (\\A)\",ylabel=\"%s (\\A\\u-%.3g\\d)\"", $y,$w); |
| 1797 |
} elsif ($x eq "q") { |
| 1798 |
my $w = ($$rpf{kw} eq 'kw') ? $self->{fft_arbkw} : $$rpf{kw}; |
| 1799 |
$labels = sprintf(", xlabel=\"k (\\A\\u-1\\d)\",ylabel=\"\\gx(q) (\\A\\u-%.3g\\d)\"", $w); |
| 1800 |
}; |
| 1801 |
my $xx = ($x eq 'r') ? 'R' : $x; |
| 1802 |
&$echocmd("> plotting in $xx for all marked groups"); |
| 1803 |
##foreach (keys (%$r_marked)) { |
| 1804 |
my $some_zero = 0; |
| 1805 |
my ($indic_min, $indic_max) = (1000000, -1000000); |
| 1806 |
my $counter = 0; |
| 1807 |
foreach (@keys) { |
| 1808 |
## need to check what needs updating |
| 1809 |
my $plot_scale = $$r_groups{$_}->{plot_scale}; |
| 1810 |
my $lab = $$r_groups{$_}->{label}; |
| 1811 |
++$some_zero if not $plot_scale; |
| 1812 |
my $yoffset = $$r_groups{$_}->{plot_yoffset}; |
| 1813 |
if ($$r_marked{$_}) { |
| 1814 |
## determine the line type for this 'un |
| 1815 |
$counter++; |
| 1816 |
my $style = 'lines'; |
| 1817 |
if ($default->{linetypes}) { |
| 1818 |
use integer; |
| 1819 |
if ($counter < 40) { |
| 1820 |
$style = (qw[lines dashed dotted dot-dash])[$counter / 10]; |
| 1821 |
} else { |
| 1822 |
$style = "linespoints" . ($counter/10 - 3); |
| 1823 |
}; |
| 1824 |
}; |
| 1825 |
|
| 1826 |
next if (($x ne 'energy') and ($$r_groups{$_}->{not_data})); |
| 1827 |
next if (($x ne 'energy') and ($$r_groups{$_}->{is_xanes})); |
| 1828 |
next if (($x eq 'energy') and (not ($$r_groups{$_}->{is_xmu} or $$r_groups{$_}->{is_nor} or $$r_groups{$_}->{not_data}))); |
| 1829 |
next if (($x eq 'eee') and (not ($$r_groups{$_}->{is_xmu} or $$r_groups{$_}->{is_nor} or $$r_groups{$_}->{is_chi}))); |
| 1830 |
next if (($x eq 'eee') and ($$r_groups{$_}->{not_data})); |
| 1831 |
## verify ranges are in correct order |
| 1832 |
next if ($$r_groups{$_}->{is_xmu} and |
| 1833 |
($$r_groups{$_}->{bkg_pre1} > $$r_groups{$_}->{bkg_pre2})); |
| 1834 |
next if ($$r_groups{$_}->{is_xmu} and |
| 1835 |
($$r_groups{$_}->{bkg_nor1} > $$r_groups{$_}->{bkg_nor2})); |
| 1836 |
next if ($$r_groups{$_}->{is_xmu} and |
| 1837 |
($$r_groups{$_}->{bkg_spl1} > $$r_groups{$_}->{bkg_spl2})); |
| 1838 |
next if (($space =~ /^[qr]/) and ($$r_groups{$_}->{fft_kmin} > $$r_groups{$_}->{fft_kmax})); |
| 1839 |
next if (($space =~ /^q/) and ($$r_groups{$_}->{bft_rmin} > $$r_groups{$_}->{bft_rmax})); |
| 1840 |
unless (($y eq 'xmu') or ($x eq 'eee')) { # don't need to update bkg if plotting mu(E) |
| 1841 |
$$r_groups{$_}->dispatch_bkg($mode) if ($$r_groups{$_}->{update_bkg}); |
| 1842 |
$$r_groups{$_}->_MAKE(update_bkg=>0); |
| 1843 |
}; |
| 1844 |
if ($space =~ /^[qr]/) { |
| 1845 |
($$r_groups{$_}->{update_fft}) and $$r_groups{$_}->do_fft($mode, $rpf); |
| 1846 |
$$r_groups{$_}->_MAKE(update_fft=>0); |
| 1847 |
}; |
| 1848 |
if ($space =~ /^q/) { |
| 1849 |
($$r_groups{$_}->{update_bft}) and $$r_groups{$_}->do_bft($mode); |
| 1850 |
$$r_groups{$_}->_MAKE(update_bft=>0); |
| 1851 |
}; |
| 1852 |
|
| 1853 |
$color = $default->{'color'.$cnt%10}; |
| 1854 |
my $indent = " " x (length($plot) + 1); |
| 1855 |
## kw-weighted chi(k) data |
| 1856 |
if (($x eq 'k') and ($w eq 'w')) { |
| 1857 |
my $w = ($$rpf{kw} eq 'kw') ? $$r_groups{$_}->{fft_arbkw} : $$rpf{kw}; |
| 1858 |
$this = sprintf("%s(%s.k, \"%s*%s.chi*%s.k^%s+%s\"%s%s%s, style=%s, color=\"%s\", key=\"%s\"%s)", |
| 1859 |
$plot, $_, $plot_scale, $_, $_, $w, $yoffset, |
| 1860 |
$labels, $scr, $xrange, $style, $color, $lab, $title); |
| 1861 |
$this = wrap("", $indent, $this) . $/; |
| 1862 |
$command .= $this; |
| 1863 |
## determine indicator boundries |
| 1864 |
ifeffit("set i___ndic.x = $plot_scale*$_.chi*$_.k^$w+$yoffset"); |
| 1865 |
my @x = Ifeffit::get_array("$_.k"); |
| 1866 |
my @y = Ifeffit::get_array("i___ndic.x"); |
| 1867 |
my ($ymin, $ymax) = $self->floor_ceil(\@x, \@y, $rpf, 'k', 0); |
| 1868 |
$ymin *= 1.05; |
| 1869 |
$ymax *= 1.05; |
| 1870 |
($indic_max = $ymax) if ($ymax > $indic_max); |
| 1871 |
($indic_min = $ymin) if ($ymin < $indic_min); |
| 1872 |
## integer weighted chi(k) data |
| 1873 |
} elsif (($x eq 'k') and ($w != 0)) { |
| 1874 |
$this= sprintf("%s(%s.k, \"%s*%s.chi*%s.k^%s+%s\"%s%s%s, style=%s, color=\"%s\", key=\"%s\"%s)", |
| 1875 |
$plot, $_, $plot_scale, $_, $_, $w, $yoffset, |
| 1876 |
$labels, $scr, $xrange, $style, $color, $lab, $title); |
| 1877 |
$this = wrap("", $indent, $this) . $/; |
| 1878 |
$command .= $this; |
| 1879 |
## determine indicator boundries |
| 1880 |
ifeffit("set i___ndic.x = $plot_scale*$_.chi*$_.k^$w+$yoffset"); |
| 1881 |
my @x = Ifeffit::get_array("$_.k"); |
| 1882 |
my @y = Ifeffit::get_array("i___ndic.x"); |
| 1883 |
my ($ymin, $ymax) = $self->floor_ceil(\@x, \@y, $rpf, 'k', 0); |
| 1884 |
$ymin *= 1.05; |
| 1885 |
$ymax *= 1.05; |
| 1886 |
($indic_max = $ymax) if ($ymax > $indic_max); |
| 1887 |
($indic_min = $ymin) if ($ymin < $indic_min); |
| 1888 |
## kw weighted chi(E) data |
| 1889 |
} elsif (($x eq 'eee') and ($w eq 'w')) { |
| 1890 |
$self->dispose("set $_.eee = $_.k^2 / etok + $$r_groups{$_}->{bkg_e0}\n", $mode); |
| 1891 |
my $ww = ($$rpf{kw} eq 'kw') ? $$r_groups{$_}->{fft_arbkw} : $$rpf{kw}; |
| 1892 |
$this = sprintf("%s(%s.eee, \"%s*%s.chi*%s.k^%s+%s\"%s%s%s, style=%s, color=\"%s\", key=\"%s\"%s)", |
| 1893 |
$plot, $_, $plot_scale, $_, $_, $ww, $yoffset, |
| 1894 |
$labels, $scr, $xrange, $style, $color, $lab, $title); |
| 1895 |
$this = wrap("", $indent, $this) . $/; |
| 1896 |
$command .= $this; |
| 1897 |
## determine indicator boundries |
| 1898 |
ifeffit("set i___ndic.x = $plot_scale*$_.chi*$_.k^$ww+$yoffset"); |
| 1899 |
my @x = Ifeffit::get_array("$first.eee"); |
| 1900 |
my @y = Ifeffit::get_array("i___ndic.x"); |
| 1901 |
my ($ymin, $ymax) = $self->floor_ceil(\@x, \@y, $rpf, 'e', $$r_groups{$first}->{bkg_e0}); |
| 1902 |
$ymin *= 1.05; |
| 1903 |
$ymax *= 1.05; |
| 1904 |
($indic_max = $ymax) if ($ymax > $indic_max); |
| 1905 |
($indic_min = $ymin) if ($ymin < $indic_min); |
| 1906 |
## integer weighted chi(E) data |
| 1907 |
} elsif (($x eq 'eee') and ($w =~ /[123]/)) { |
| 1908 |
$self->dispose("set $_.eee = $_.k^2 / etok + $$r_groups{$_}->{bkg_e0}\n", $mode); |
| 1909 |
$this= sprintf("%s(%s.eee, \"%s*%s.chi*%s.k^%s+%s\"%s%s%s, style=%s, color=\"%s\", key=\"%s\"%s)", |
| 1910 |
$plot, $_, $plot_scale, $_, $_, $w, $yoffset, |
| 1911 |
$labels, $scr, $xrange, $style, $color, $lab, $title); |
| 1912 |
$this = wrap("", $indent, $this) . $/; |
| 1913 |
$command .= $this; |
| 1914 |
## determine indicator boundries |
| 1915 |
ifeffit("set i___ndic.x = $plot_scale*$_.chi*$_.k^$w+$yoffset"); |
| 1916 |
my @x = Ifeffit::get_array("$first.eee"); |
| 1917 |
my @y = Ifeffit::get_array("i___ndic.x"); |
| 1918 |
my ($ymin, $ymax) = $self->floor_ceil(\@x, \@y, $rpf, 'e', $$r_groups{$first}->{bkg_e0}); |
| 1919 |
$ymin *= 1.05; |
| 1920 |
$ymax *= 1.05; |
| 1921 |
($indic_max = $ymax) if ($ymax > $indic_max); |
| 1922 |
($indic_min = $ymin) if ($ymin < $indic_min); |
| 1923 |
## deriv(mu(E)) data |
| 1924 |
} elsif (($$rpf{e_mderiv} eq 'd') and ($x eq 'energy') and (not $$r_groups{$_}->{not_data})) { |
| 1925 |
my $eshift = $$r_groups{$_}->{bkg_eshift}; |
| 1926 |
|
| 1927 |
$self->dispose("set $_.smooth = deriv($_.$y)/deriv($group.energy)", $mode); |
| 1928 |
if ($$rpf{smoothderiv}) { |
| 1929 |
foreach my $it (1 .. $$rpf{smoothderiv}) { |
| 1930 |
$self->dispose("set $_.smooth = smooth($_.smooth)", $mode); |
| 1931 |
}; |
| 1932 |
}; |
| 1933 |
|
| 1934 |
$this = sprintf("%s(%s.%s+%s, \"%s*%s.smooth+%s\"%s%s%s, style=%s, color=\"%s\", key=\"%s\"%s)", |
| 1935 |
$plot, $_, $x, $eshift, $plot_scale, $_, $yoffset, |
| 1936 |
$labels, $scr, $xrange, $style, $color, $lab, $title); |
| 1937 |
$this = wrap("", $indent, $this) . $/; |
| 1938 |
$command .= $this; |
| 1939 |
## determine indicator boundries |
| 1940 |
ifeffit("set i___ndic.x = $plot_scale*(deriv($_.$y)/deriv($group.energy))+$yoffset"); |
| 1941 |
my @x = Ifeffit::get_array("$_.energy"); |
| 1942 |
my @y = Ifeffit::get_array("i___ndic.x"); |
| 1943 |
my ($ymin, $ymax) = $self->floor_ceil(\@x, \@y, $rpf, 'e', $$r_groups{$first}->{bkg_e0}); |
| 1944 |
$ymin *= 1.05; |
| 1945 |
$ymax *= 1.05; |
| 1946 |
($indic_max = $ymax) if ($ymax > $indic_max); |
| 1947 |
($indic_min = $ymin) if ($ymin < $indic_min); |
| 1948 |
## all other data in energy |
| 1949 |
} elsif ($x eq 'energy') { |
| 1950 |
my $eshift = $$r_groups{$_}->{bkg_eshift}; |
| 1951 |
my $yy = $y; |
| 1952 |
(($$r_groups{$_}->{is_nor}) and ($y eq 'norm')) and ($yy = 'xmu'); |
| 1953 |
(($y eq 'norm') and ($$r_groups{$_}->{bkg_flatten})) and ($yy = 'flat'); |
| 1954 |
($$r_groups{$_}->{not_data}) and ($yy = 'det'); |
| 1955 |
my $mult = ($$r_groups{$_}->{not_data} or $$r_groups{$_}->{is_xanes} or $$r_groups{$_}->{is_nor}) ? |
| 1956 |
"$plot_scale*" : ''; |
| 1957 |
$this = sprintf("%s(%s.%s+%s, \"%s%s.%s+%s\"%s%s%s, style=%s, color=\"%s\", key=\"%s\"%s)", |
| 1958 |
$plot, $_, $x, $eshift, $mult, $_, $yy, $yoffset, |
| 1959 |
$labels, $scr, $xrange, $style, $color, $lab, $title); |
| 1960 |
$this = wrap("", $indent, $this) . $/; |
| 1961 |
$command .= $this; |
| 1962 |
## determine indicator boundries |
| 1963 |
ifeffit("set i___ndic.x = $mult$_.$yy+$yoffset"); |
| 1964 |
my @x = Ifeffit::get_array("$_.energy"); |
| 1965 |
my @y = Ifeffit::get_array("i___ndic.x"); |
| 1966 |
my ($ymin, $ymax) = $self->floor_ceil(\@x, \@y, $rpf, 'e', $$r_groups{$first}->{bkg_e0}); |
| 1967 |
my $diff = $ymax-$ymin; |
| 1968 |
$ymin -= $diff/20; |
| 1969 |
$ymax += $diff/20; |
| 1970 |
($indic_max = $ymax) if ($ymax > $indic_max); |
| 1971 |
($indic_min = $ymin) if ($ymin < $indic_min); |
| 1972 |
## all other data |
| 1973 |
} else { |
| 1974 |
$this = sprintf("%s(%s.%s, \"%s*%s.%s+%s\"%s%s%s, style=%s, color=\"%s\", key=\"%s\"%s)", |
| 1975 |
$plot, $_, $x, $plot_scale, $_, $y, $yoffset, |
| 1976 |
$labels, $scr, $xrange, $style, $color, $lab, $title); |
| 1977 |
$this = wrap("", $indent, $this) . $/; |
| 1978 |
$command .= $this; |
| 1979 |
## determine indicator boundries |
| 1980 |
ifeffit("set i___ndic.x = $plot_scale*$_.$y+$yoffset"); |
| 1981 |
my @x = Ifeffit::get_array("$_.$x"); |
| 1982 |
my @y = Ifeffit::get_array("i___ndic.x"); |
| 1983 |
my ($ymin, $ymax) = $self->floor_ceil(\@x, \@y, $rpf, lc($x), 0); |
| 1984 |
$ymin *= 1.05; |
| 1985 |
$ymax *= 1.05; |
| 1986 |
($indic_max = $ymax) if ($ymax > $indic_max); |
| 1987 |
($indic_min = $ymin) if ($ymin < $indic_min); |
| 1988 |
}; |
| 1989 |
($plot, $labels, $scr, $title) = ("plot", "", "", ""); |
| 1990 |
++$cnt; |
| 1991 |
#$title .= "$_ "; |
| 1992 |
}; |
| 1993 |
}; |
| 1994 |
#$command .= ("plot(title=$title)\n"); |
| 1995 |
##print $command; |
| 1996 |
##$command = wrap("", "", $command); |
| 1997 |
$self->dispose($command, $mode); |
| 1998 |
if ($$indicators[0]) { |
| 1999 |
foreach my $i (@$indicators) { |
| 2000 |
next if ($i =~ /^[01]$/); |
| 2001 |
next if (lc($i->[1]) =~ /^\s*$/); |
| 2002 |
next if (($x ne "r") and (lc($i->[1]) eq "r")); |
| 2003 |
next if (($x eq "r") and (lc($i->[1]) ne "r")); |
| 2004 |
my $val = $i->[2]; |
| 2005 |
($val = $self->e2k($val)) if (($x =~ /[kq]/) and (lc($i->[1]) eq "e")); |
| 2006 |
($val = $self->k2e($val) + $$r_groups{$first}->{bkg_e0}) |
| 2007 |
if (($x =~ /^e/) and (lc($i->[1]) =~ /[kq]/)); |
| 2008 |
next if ($val < 0); |
| 2009 |
$self->plot_vertical_line($val, $indic_min, $indic_max, $mode, "", 0, 0, 1) |
| 2010 |
}; |
| 2011 |
}; |
| 2012 |
$last_plot = $command; |
| 2013 |
($xx = "chi(E)") if ($xx eq 'eee'); |
| 2014 |
($some_zero) ? |
| 2015 |
&$errorcmd("> WARNING: One or more of the groups plotted had plot multipliers set to zero.") : |
| 2016 |
&$echocmd("> plotting in $xx for all marked groups ... done!"); |
| 2017 |
}; |
| 2018 |
|
| 2019 |
|
| 2020 |
## args are: x-position, y-range, plotting mode, key, yoffset, and |
| 2021 |
## newplot flag |
| 2022 |
sub plot_vertical_line { |
| 2023 |
my $self = shift; |
| 2024 |
my ($x, $ymin, $ymax, $mode, $key, $yoffset, $new, $style) = @_; |
| 2025 |
my $delta = $ymax - $ymin; |
| 2026 |
my ($line, $color) = ($style==1) ? |
| 2027 |
($default->{indicatorline}, $default->{indicatorcolor}) : |
| 2028 |
($default->{borderline}, $default->{bordercolor}); |
| 2029 |
$self->dispose("set(v___ert.x = $x*ones(2), v___ert.y = range($ymin, $ymax, $delta))", $mode); |
| 2030 |
if ($new) { |
| 2031 |
$self->dispose("newplot(v___ert.x, \"v___ert.y+$yoffset\", key=\"$key\", style=$line, color=\"$color\")", $mode); |
| 2032 |
} else { |
| 2033 |
$self->dispose("plot(v___ert.x, \"v___ert.y+$yoffset\", key=\"$key\", style=$line, color=\"$color\")", $mode); |
| 2034 |
}; |
| 2035 |
}; |
| 2036 |
|
| 2037 |
|
| 2038 |
sub plot_window { |
| 2039 |
my $self = shift; |
| 2040 |
my ($new, $space, $mode, $color, $rpf) = @_; |
| 2041 |
my $group = $self->{group}; |
| 2042 |
my $yoffset = $self->{plot_yoffset}; |
| 2043 |
my $plot_scale = $self->{plot_scale}; |
| 2044 |
my $plot = ($new) ? "newplot" : "plot"; |
| 2045 |
my $this; |
| 2046 |
SWITCH: { |
| 2047 |
(lc($space) =~ /^[kq]$/) and do { |
| 2048 |
($self->{update_fft}) and $self->do_fft($mode, $rpf); |
| 2049 |
$self->_MAKE(update_fft=>0); |
| 2050 |
my $weight = $$rpf{kw}; |
| 2051 |
ifeffit("set ___x = ceil($group.chi*$plot_scale*$group.k^$weight)"); # scale window to plot |
| 2052 |
my $scale = 1.05 * Ifeffit::get_scalar("___x"); |
| 2053 |
$color ||= $default->{color9}; |
| 2054 |
$this = sprintf("%s(%s.k, \"%s.win*%f+%s\", style=lines, color=\"%s\", key=window)", |
| 2055 |
$plot, $group, $group, $scale, $yoffset, $color); |
| 2056 |
$this = wrap("", " ", $this) . $/; |
| 2057 |
last SWITCH; |
| 2058 |
}; |
| 2059 |
(lc($space) eq 'r') and do { |
| 2060 |
($self->{update_bft}) and $self->do_bft($mode); |
| 2061 |
$self->_MAKE(update_bft=>0); |
| 2062 |
ifeffit("set ___x = ceil($group.chir_mag)"); # scale window to plot |
| 2063 |
my $scale = 1.05 * $plot_scale * Ifeffit::get_scalar("___x"); |
| 2064 |
$color ||= $default->{color9}; |
| 2065 |
$this = sprintf("%s(%s.r, \"%s.rwin*%.2f+%s\", style=lines, color=\"%s\", key=window)", |
| 2066 |
$plot, $group, $group, $scale, $yoffset, $color); |
| 2067 |
last SWITCH; |
| 2068 |
}; |
| 2069 |
}; |
| 2070 |
$self->dispose($this, $mode); |
| 2071 |
}; |
| 2072 |
|
| 2073 |
|
| 2074 |
###################################################################### |
| 2075 |
## Analysis methods |
| 2076 |
|
| 2077 |
## These methods do not rely on ifeffit program variables. Instead |
| 2078 |
## they construct the full command from the hash values for the |
| 2079 |
## group. This obviates the need to keep track of the current state of |
| 2080 |
## the program variables at the cost of longer commands and keeping |
| 2081 |
## clear which is the current group. |
| 2082 |
|
| 2083 |
sub dispatch_bkg { |
| 2084 |
my $self = shift; |
| 2085 |
return if $self->{not_data}; |
| 2086 |
my $mode = $_[0]; |
| 2087 |
if ($self->{bkg_cl}) { |
| 2088 |
$self -> do_bkg_cl($mode); |
| 2089 |
} else { |
| 2090 |
$self -> do_background($mode); |
| 2091 |
}; |
| 2092 |
}; |
| 2093 |
|
| 2094 |
sub set_clamp { |
| 2095 |
my $self = shift; |
| 2096 |
my $key = ucfirst(lc($_[0])); |
| 2097 |
my $val = int($_[1]); |
| 2098 |
$clamp{$key} = $val; |
| 2099 |
return 1; |
| 2100 |
}; |
| 2101 |
|
| 2102 |
sub do_background { |
| 2103 |
my $self = shift; |
| 2104 |
my $mode = $_[0]; |
| 2105 |
my $group = $self->{group}; |
| 2106 |
my $label = $self->{label}; |
| 2107 |
## why is this necessary??? |
| 2108 |
my $precmd = "(\"$group.energy+$self->{bkg_eshift}\", $group.xmu, "; |
| 2109 |
$precmd .= "e0=$self->{bkg_e0}, "; |
| 2110 |
$precmd .= "pre1=$self->{bkg_pre1}, "; |
| 2111 |
$precmd .= "pre2=$self->{bkg_pre2}, "; |
| 2112 |
$precmd .= "norm_order=$self->{bkg_nnorm}, "; |
| 2113 |
$precmd .= "norm1=$self->{bkg_nor1}, "; |
| 2114 |
$precmd .= "norm2=$self->{bkg_nor2})\n"; |
| 2115 |
$precmd = wrap("pre_edge", " ", $precmd); |
| 2116 |
## vvvvvvvvvvvvv Is this the right thing to do?? |
| 2117 |
my $command = "(\"$group.energy+$self->{bkg_eshift}\", $group.xmu, "; |
| 2118 |
unless ($self->{bkg_stan} =~ /None/) { |
| 2119 |
## selecting the standard back on the main window checks to see |
| 2120 |
## that it is up to date |
| 2121 |
$command .= "k_std=$self->{bkg_stan}.k, chi_std=$self->{bkg_stan}.chi, "; |
| 2122 |
}; |
| 2123 |
$command .= "e0=$self->{bkg_e0}, "; |
| 2124 |
my $fixed = 0; |
| 2125 |
if ($self->{bkg_fixstep}) { $command .= "edge_step=$self->{bkg_step}, do_pre=F, "; |
| 2126 |
$fixed = $self->{bkg_step}; }; |
| 2127 |
#elsif ($self->{is_nor}) { $command .= "edge_step=1, "; } |
| 2128 |
$command .= "rbkg=$self->{bkg_rbkg}, "; |
| 2129 |
$command .= "kmin=$self->{bkg_spl1}, "; |
| 2130 |
$command .= "kmax=$self->{bkg_spl2}, "; |
| 2131 |
$command .= "kweight=$self->{bkg_kw}, "; |
| 2132 |
$command .= "dk=$self->{bkg_dk}, "; |
| 2133 |
$command .= "kwindow=$self->{bkg_win}"; |
| 2134 |
#$command .= "do_pre=false"; |
| 2135 |
#unless ($self->{is_nor}) { |
| 2136 |
$command .= ", pre1=$self->{bkg_pre1}"; |
| 2137 |
$command .= ", pre2=$self->{bkg_pre2}"; |
| 2138 |
$command .= ", fnorm=yes" if ($self->{bkg_fnorm}); |
| 2139 |
$command .= ", norm_order=$self->{bkg_nnorm}"; |
| 2140 |
$command .= ", norm1=$self->{bkg_nor1}"; |
| 2141 |
$command .= ", norm2=$self->{bkg_nor2}"; |
| 2142 |
#}; |
| 2143 |
($self->{bkg_clamp1} ne 'None') and $command .= ", clamp1=$clamp{$self->{bkg_clamp1}}"; |
| 2144 |
($self->{bkg_clamp2} ne 'None') and $command .= ", clamp2=$clamp{$self->{bkg_clamp2}}"; |
| 2145 |
if (($self->{bkg_clamp1} ne 'None') or ($self->{bkg_clamp2} ne 'None')) { |
| 2146 |
my $n = int($self->{bkg_nclamp}); |
| 2147 |
$command .= ", nclamp=$n"; |
| 2148 |
}; |
| 2149 |
$command .= ", interp=$default->{interp}"; |
| 2150 |
$command .= ")\n"; |
| 2151 |
$command = wrap("spline", " ", $command); |
| 2152 |
if ($self->{is_xanes}) { |
| 2153 |
&$echocmd("> normalizing \`$label\' ..."); |
| 2154 |
} else { |
| 2155 |
&$echocmd("> removing background from \`$label\' ..."); |
| 2156 |
}; |
| 2157 |
## print $command; |
| 2158 |
#$self->{is_nor} or |
| 2159 |
$self->dispose($precmd, $mode); |
| 2160 |
$self->_MAKE(bkg_nc0 => Ifeffit::get_scalar("norm_c0"), |
| 2161 |
bkg_nc1 => Ifeffit::get_scalar("norm_c1"), |
| 2162 |
bkg_nc2 => Ifeffit::get_scalar("norm_c2")); |
| 2163 |
my $before = Ifeffit::get_scalar("edge_step"); |
| 2164 |
$self->_MAKE(bkg_slope => ($self->{is_xmudat}) ? 0 : Ifeffit::get_scalar("pre_slope")); |
| 2165 |
$self->_MAKE(bkg_int => ($self->{is_xmudat}) ? 0 : Ifeffit::get_scalar("pre_offset")); |
| 2166 |
$self->_MAKE(bkg_step => $fixed || sprintf "%.7f", Ifeffit::get_scalar("edge_step")); |
| 2167 |
$self->_MAKE(bkg_fitted_step => $self->{bkg_step}) unless $fixed; |
| 2168 |
$self->_MAKE(bkg_fitted_step => 1) if ($self->{is_nor}); |
| 2169 |
$self->dispose("$command", $mode) unless $self->{is_xanes}; |
| 2170 |
my $after = Ifeffit::get_scalar("edge_step"); |
| 2171 |
my $correction = ($before) ? $after/$before : 0; |
| 2172 |
my $cmd = ($self->{is_nor}) ? |
| 2173 |
sprintf("set ___x = npts(%s.energy)\nset %s.preline = zeros(___x)\n", $group, $group) : |
| 2174 |
sprintf("set %s.preline = %g+%g*(%s.energy + %g)\n", |
| 2175 |
$group, $self->{bkg_int}, $self->{bkg_slope}, $group, $self->{bkg_eshift}); |
| 2176 |
$self->dispose($cmd, $mode); |
| 2177 |
$self->_MAKE(update_bkg => 0, |
| 2178 |
update_fft => 1, |
| 2179 |
bkg_cl => 0); |
| 2180 |
my $xcmd = q{}; |
| 2181 |
if ($self->{is_xanes}) { |
| 2182 |
$xcmd = sprintf("set(%s.prex = (%s.xmu-%s.preline),\n", |
| 2183 |
$group, $group, $group); |
| 2184 |
$xcmd .= sprintf(" %s.norm = (%s.xmu-%s.preline)/%g,\n", |
| 2185 |
$group, $group, $group, $self->{bkg_step}); |
| 2186 |
$xcmd .= sprintf(" %s.postline = %g+%g*(%s.energy+%f)+%g*(%s.energy+%f)**2)\n", |
| 2187 |
$group, $self->{bkg_nc0}, |
| 2188 |
$self->{bkg_nc1}, $group, $self->{bkg_eshift}, |
| 2189 |
$self->{bkg_nc2}, $group, $self->{bkg_eshift}); |
| 2190 |
} elsif ($self->{is_xmudat}) { |
| 2191 |
$xcmd = sprintf("set(%s.prex = %s.xmu,\n", $group, $group); |
| 2192 |
$xcmd .= sprintf(" %s.norm = %s.xmu)\n", $group, $group); |
| 2193 |
} else { |
| 2194 |
$xcmd = sprintf("set %s.prex = %s.pre\n", $group, $group); |
| 2195 |
if (abs($correction - 1) > DELTA) { |
| 2196 |
$xcmd .= "## the next line corrects a bug in Ifeffit 1.2.11 in which the spline command does not respect the supplied value of norm_order \n"; |
| 2197 |
$xcmd .= sprintf("set %s.norm = %f*%s.norm\n", $group, $correction, $group) |
| 2198 |
}; |
| 2199 |
}; |
| 2200 |
$self->dispose($xcmd, $mode); |
| 2201 |
|
| 2202 |
## why am I having trouble with these two??????? this should not be necessary!!!! |
| 2203 |
$self->{bkg_slope} = ($self->{is_xmudat}) ? 0 : Ifeffit::get_scalar("pre_slope"); |
| 2204 |
$self->{bkg_int} = ($self->{is_xmudat}) ? 0 : Ifeffit::get_scalar("pre_offset"); |
| 2205 |
|
| 2206 |
## make flattened normalized data |
| 2207 |
$command = "## make the flattened, normalized spectrum\n"; |
| 2208 |
$command .= "## flat_cN are the difference in slope and curvature between\n"; |
| 2209 |
$command .= "## the pre- and post-edge polynomials\n"; |
| 2210 |
$command .= sprintf("set %s.postline = %g+%g*(%s.energy+%f)+%g*(%s.energy+%f)**2\n", |
| 2211 |
$group, $self->{bkg_nc0}, |
| 2212 |
$self->{bkg_nc1}, $group, $self->{bkg_eshift}, |
| 2213 |
$self->{bkg_nc2}, $group, $self->{bkg_eshift}); |
| 2214 |
$command .= "step $group.energy $self->{bkg_eshift} $self->{bkg_e0} $group.theta\n"; |
| 2215 |
|
| 2216 |
if ($self->{bkg_fixstep} or $self->{is_nor} or $self->{is_xanes}) { |
| 2217 |
## the edge step is fixed, so we have to regress the flat_c? values |
| 2218 |
my ($flat1, $flat2) = ($self->{bkg_e0}+$self->{bkg_nor1}-$self->{bkg_eshift}, |
| 2219 |
$self->{bkg_e0}+$self->{bkg_nor2}-$self->{bkg_eshift}); |
| 2220 |
my $shift = $self->{bkg_eshift}; |
| 2221 |
$command .= "guess(flat_c0=0, flat_c1=0)\n"; |
| 2222 |
if (($flat2-$flat1) < 300) { |
| 2223 |
$command .= "set(flat_c2=0)\n"; |
| 2224 |
} elsif ($self->{bkg_nnorm} == 2) { |
| 2225 |
$command .= "set(flat_c2=0)\n"; |
| 2226 |
} else { |
| 2227 |
$command .= "guess(flat_c2=0)\n"; |
| 2228 |
}; |
| 2229 |
$command .= "def($group.line = (flat_c0 + flat_c1*($group.energy+$shift) + flat_c2*($group.energy+$shift)**2),\n"; |
| 2230 |
$command .= " $group.resid = $group.prex - $group.line)\n"; |
| 2231 |
$command .= "minimize($group.resid, x=$group.energy, xmin=$flat1, xmax=$flat2)\n"; |
| 2232 |
#$command .= "show flat_c0 flat_c1 flat_c2\n"; |
| 2233 |
$command .= "unguess\n"; |
| 2234 |
#$command .= "set $group.line = $group.line * $self->{bkg_step} / $self->{bkg_fitted_step}\n"; |
| 2235 |
#$command .= "set $group.line = (flat_c0 * $self->{bkg_step} / $self->{bkg_fitted_step}) + flat_c1*($group.energy+$shift) + flat_c2*($group.energy+$shift)**2\n" |
| 2236 |
# if $fixed; |
| 2237 |
} else { |
| 2238 |
my $shift = $self->{bkg_eshift}; |
| 2239 |
$command .= "set(flat_c0=$self->{bkg_nc0} - $self->{bkg_int},\n"; |
| 2240 |
$command .= " flat_c1=$self->{bkg_nc1} - $self->{bkg_slope},\n"; |
| 2241 |
if ($self->{bkg_nnorm} == 2) { |
| 2242 |
$command .= " flat_c2=0,\n"; |
| 2243 |
} else { |
| 2244 |
$command .= " flat_c2=$self->{bkg_nc2},\n"; |
| 2245 |
}; |
| 2246 |
$command .= " $group.line = (flat_c0 + flat_c1*($group.energy+$shift) + flat_c2*($group.energy+$shift)**2))\n"; |
| 2247 |
}; |
| 2248 |
|
| 2249 |
## make sure that a fitted edge step actually exists... |
| 2250 |
$self->_MAKE(bkg_fitted_step => $self->{bkg_step}) unless $self->{bkg_fitted_step}; |
| 2251 |
$command .= "set($group.flat = (($self->{bkg_fitted_step} - $group.line)*$group.theta + $group.prex) / $self->{bkg_step})\n"; |
| 2252 |
$command .= "set($group.fbkg = ($group.bkg-$group.preline+($self->{bkg_fitted_step}-$group.line)*$group.theta)/$self->{bkg_step})\n" |
| 2253 |
unless $self->{is_xanes}; |
| 2254 |
$self->dispose($command, $mode); |
| 2255 |
##&$echocmd("---> flattened"); |
| 2256 |
|
| 2257 |
if ($self->{is_xanes}) { |
| 2258 |
&$echocmd("> normalizing \`$label\' ... done!"); |
| 2259 |
} else { |
| 2260 |
&$echocmd("> removing background from \`$label\' ... done!"); |
| 2261 |
}; |
| 2262 |
}; |
| 2263 |
|
| 2264 |
## $command .= "guess(flat_c0=0, flat_c1=0, flat_c2=0)\n"; |
| 2265 |
## $command .= "def $group.line = (flat_c0 + flat_c1*$group.energy + flat_c2*$group.energy**2)\n"; |
| 2266 |
## $command .= "def $group.resid = $group.pre - $group.line\n"; |
| 2267 |
## $command .= "minimize($group.resid, x=$group.energy, xmin=$flat1, xmax=$flat2)\n"; |
| 2268 |
## $command .= "unguess\n"; |
| 2269 |
|
| 2270 |
|
| 2271 |
|
| 2272 |
sub do_bkg_cl { |
| 2273 |
my $self = shift; |
| 2274 |
my $mode = $_[0]; |
| 2275 |
my $group = $self->{group}; |
| 2276 |
my $label = $self->{label}; |
| 2277 |
my $iz = get_Z($self->{bkg_z}); |
| 2278 |
my $command = "(z=$iz, group=$group, "; |
| 2279 |
## vvvvvvvv Is this the right thing to do?? |
| 2280 |
$command .= "energy=$group.energy+$self->{bkg_eshift}, xmu=$group.xmu, "; |
| 2281 |
$command .= "e0=$self->{bkg_e0}, "; |
| 2282 |
my $fixed = 0; |
| 2283 |
if ($self->{bkg_fixstep}) { $command .= "edge_step=$self->{bkg_step}, "; |
| 2284 |
$fixed = $self->{bkg_step}; } |
| 2285 |
elsif ($self->{is_nor}) { $command .= "edge_step=1, "; } |
| 2286 |
$command .= "pre1=$self->{bkg_pre1}, "; |
| 2287 |
$command .= "pre2=$self->{bkg_pre2}, "; |
| 2288 |
$command .= "norm1=$self->{bkg_nor1}, "; |
| 2289 |
$command .= "norm2=$self->{bkg_nor2}, "; |
| 2290 |
$command .= "interp=$default->{interp})\n"; |
| 2291 |
$command = wrap("bkg_cl", " ", $command); |
| 2292 |
&$echocmd("> removing background from \`$label\'"); |
| 2293 |
## print $command; |
| 2294 |
$self->dispose($command, $mode); |
| 2295 |
$self->_MAKE(bkg_slope => Ifeffit::get_scalar("pre_slope"), |
| 2296 |
bkg_int => Ifeffit::get_scalar("pre_offset"), |
| 2297 |
bkg_nc0 => Ifeffit::get_scalar("norm_c0"), |
| 2298 |
bkg_nc1 => Ifeffit::get_scalar("norm_c1"), |
| 2299 |
bkg_nc2 => Ifeffit::get_scalar("norm_c2"), |
| 2300 |
update_bkg => 0, |
| 2301 |
update_fft => 1, |
| 2302 |
bkg_cl => 1); |
| 2303 |
$self->_MAKE(bkg_step => $fixed || sprintf "%.7f", Ifeffit::get_scalar("edge_step")); |
| 2304 |
$self->_MAKE(bkg_fitted_step => $self->{bkg_step}) unless $fixed; |
| 2305 |
&$echocmd("> removing background from \`$label\' ... done!"); |
| 2306 |
}; |
| 2307 |
|
| 2308 |
|
| 2309 |
sub do_fft { |
| 2310 |
my $self = shift; |
| 2311 |
return if $self->{not_data}; |
| 2312 |
my ($mode, $rpf) = @_; |
| 2313 |
my $group = $self->{group}; |
| 2314 |
my $label = $self->{label}; |
| 2315 |
my $kw = ($$rpf{kw} eq 'kw') ? $self->{fft_arbkw} : $$rpf{kw}; |
| 2316 |
## verify values |
| 2317 |
my $command = "($group.chi, "; |
| 2318 |
$command .= "k=$group.k, ", |
| 2319 |
$command .= "kweight=$kw, "; |
| 2320 |
$command .= "kmin=$self->{fft_kmin}, "; |
| 2321 |
$command .= "kmax=$self->{fft_kmax}, "; |
| 2322 |
$command .= "dk=$self->{fft_dk}, "; |
| 2323 |
$command .= "kwindow=$self->{fft_win}, "; |
| 2324 |
$command .= "rmax_out=$Ifeffit::Group::rmax_out"; |
| 2325 |
if (lc($self->{fft_pc}) eq 'on') { |
| 2326 |
my $str = join(" ", lc($self->{bkg_z}), lc($self->{fft_edge})); |
| 2327 |
($command .= ", pc_edge=\"$str\", pc_caps=1"); |
| 2328 |
}; |
| 2329 |
$command .= ")\n"; |
| 2330 |
$command = wrap("fftf", " ", $command); |
| 2331 |
&$echocmd("> forward transforming \`$label\'"); |
| 2332 |
$self->dispose($command, $mode); |
| 2333 |
$self->_MAKE(update_fft=>0); |
| 2334 |
&$echocmd("> forward transforming \`$label\' ... done!"); |
| 2335 |
##print $command; |
| 2336 |
}; |
| 2337 |
|
| 2338 |
|
| 2339 |
sub do_bft { |
| 2340 |
my $self = shift; |
| 2341 |
return if $self->{not_data}; |
| 2342 |
my $mode = $_[0]; |
| 2343 |
my $group = $self->{group}; |
| 2344 |
my $label = $self->{label}; |
| 2345 |
## verify values |
| 2346 |
my $command = "(real=$group.chir_re, imag=$group.chir_im, "; |
| 2347 |
$command .= "rmin=$self->{bft_rmin}, "; |
| 2348 |
$command .= "rmax=$self->{bft_rmax}, "; |
| 2349 |
$command .= "dr=$self->{bft_dr}, "; |
| 2350 |
$command .= "rwindow=$self->{bft_win})\n"; |
| 2351 |
$command = wrap("fftr", " ", $command); |
| 2352 |
##print $command; |
| 2353 |
&$echocmd("> back transforming \`$label\'"); |
| 2354 |
$self->_MAKE(update_bft=>0); |
| 2355 |
$self->dispose($command, $mode); |
| 2356 |
&$echocmd("> back transforming \`$label\' ... done!"); |
| 2357 |
}; |
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
###################################################################### |
| 2362 |
## Merging methods |
| 2363 |
|
| 2364 |
sub merge { |
| 2365 |
my $self = shift; |
| 2366 |
my ($space, $weight, $mode, $r_groups, $r_marked, $rpf, $canvas) = @_; |
| 2367 |
&$echocmd("> Merging ... "); |
| 2368 |
push @{$self->{titles}}, "Merge in $space space of:"; |
| 2369 |
my $group = $self->{group}; |
| 2370 |
$self -> _MAKE(is_merge=>lc($space)); |
| 2371 |
my $is_xanes = 0; |
| 2372 |
my ($x, $y1, $y2, $y3, $y4); |
| 2373 |
SWITCH: { # get columns |
| 2374 |
($x, $y1, $y2) = ("energy", "xmu", ""), last SWITCH if (lc($space) eq 'e'); |
| 2375 |
($x, $y1, $y2) = ("energy", "norm", ""), last SWITCH if (lc($space) eq 'n'); |
| 2376 |
($x, $y1, $y2) = ("k", "chi", ""), last SWITCH if (lc($space) eq 'k'); |
| 2377 |
($x, $y1, $y2) = ("r", "chir_re", "chir_im"), last SWITCH if (lc($space) eq 'r'); |
| 2378 |
($x, $y1, $y2) = ("q", "chiq_re", "chiq_im"), last SWITCH if (lc($space) eq 'q'); |
| 2379 |
}; |
| 2380 |
MP: { # handle complex data (rsp and qsp) |
| 2381 |
($y3, $y4) = ("chir_mag", "chir_pha"), last MP if (lc($space) eq 'r'); |
| 2382 |
($y3, $y4) = ("chiq_mag", "chiq_pha"), last MP if (lc($space) eq 'q'); |
| 2383 |
}; |
| 2384 |
## get the list of marked groups in the order placed on the group list |
| 2385 |
my @ll = sort {($canvas->bbox($$r_groups{$a}->{text}))[1] <=> |
| 2386 |
($canvas->bbox($$r_groups{$b}->{text}))[1]} (keys (%$r_marked)); |
| 2387 |
my (@list, @list2); # get the list of marked groups |
| 2388 |
map {if ($$r_marked{$_}) {push @list, $_; push @list2, $_}} @ll; |
| 2389 |
my $first = $list[0]; |
| 2390 |
SWITCH: { # deal with the first element in the |
| 2391 |
($y1 eq 'norm') and do { # list to get the command strings started |
| 2392 |
($$r_groups{$first} -> {update_bkg}) and $$r_groups{$first} -> dispatch_bkg($mode); |
| 2393 |
last SWITCH; |
| 2394 |
}; |
| 2395 |
($x eq 'k') and do { |
| 2396 |
($$r_groups{$first} -> {update_bkg}) and $$r_groups{$first} -> dispatch_bkg($mode); |
| 2397 |
last SWITCH; |
| 2398 |
}; |
| 2399 |
($x eq 'r') and do { |
| 2400 |
($$r_groups{$first} -> {update_bkg}) and $$r_groups{$first} -> dispatch_bkg($mode); |
| 2401 |
($$r_groups{$first} -> {update_fft}) and $$r_groups{$first} -> do_fft($mode); |
| 2402 |
last SWITCH; |
| 2403 |
}; |
| 2404 |
($x eq 'q') and do { |
| 2405 |
($$r_groups{$first} -> {update_bkg}) and $$r_groups{$first} -> dispatch_bkg($mode); |
| 2406 |
($$r_groups{$first} -> {update_fft}) and $$r_groups{$first} -> do_fft($mode); |
| 2407 |
($$r_groups{$first} -> {update_bft}) and $$r_groups{$first} -> do_bft($mode); |
| 2408 |
last SWITCH; |
| 2409 |
}; |
| 2410 |
}; |
| 2411 |
## find longest common abscissa range in the marked groups. |
| 2412 |
## interpolate over this range. intrpolating just over the range of |
| 2413 |
## the first group might lead to extrapolation in other groups. |
| 2414 |
my @first_absc = Ifeffit::get_array("$first.$x"); |
| 2415 |
my ($xmin, $xmax) = ($first_absc[0], $first_absc[$#first_absc]); |
| 2416 |
foreach (@list) { # make sure they are all up-to-date |
| 2417 |
SWITCH: { |
| 2418 |
&$echocmd("> bringing \"" . $$r_groups{$_} -> {label} . "\" up to date for merge in $y1..."); |
| 2419 |
($y1 eq 'xmu') and do{ |
| 2420 |
$is_xanes ||= $$r_groups{$_} -> {is_xanes}; |
| 2421 |
last SWITCH; |
| 2422 |
}; |
| 2423 |
($y1 eq 'norm') and do{ |
| 2424 |
($$r_groups{$_} -> {update_bkg}) and $$r_groups{$_} -> dispatch_bkg($mode); |
| 2425 |
$is_xanes ||= $$r_groups{$_} -> {is_xanes}; |
| 2426 |
last SWITCH; |
| 2427 |
}; |
| 2428 |
($x eq 'k') and do{ |
| 2429 |
($$r_groups{$_} -> {update_bkg}) and $$r_groups{$_} -> dispatch_bkg($mode); |
| 2430 |
last SWITCH; |
| 2431 |
}; |
| 2432 |
($x eq 'r') and do{ |
| 2433 |
($$r_groups{$_} -> {update_bkg}) and $$r_groups{$_} -> dispatch_bkg($mode); |
| 2434 |
($$r_groups{$_} -> {update_fft}) and $$r_groups{$_} -> do_fft($mode); |
| 2435 |
last SWITCH; |
| 2436 |
}; |
| 2437 |
($x eq 'q') and do{ |
| 2438 |
($$r_groups{$_} -> {update_bkg}) and $$r_groups{$_} -> dispatch_bkg($mode); |
| 2439 |
($$r_groups{$_} -> {update_fft}) and $$r_groups{$_} -> do_fft($mode); |
| 2440 |
($$r_groups{$_} -> {update_bft}) and $$r_groups{$_} -> do_bft($mode); |
| 2441 |
last SWITCH; |
| 2442 |
}; |
| 2443 |
}; |
| 2444 |
my @this = Ifeffit::get_array("$_.$x"); |
| 2445 |
my ($x1, $x2) = ($this[0], $this[$#this]); |
| 2446 |
($xmin = $x1) if ($x1 > $xmin); |
| 2447 |
($xmax = $x2) if ($x2 < $xmax); |
| 2448 |
}; |
| 2449 |
$self->dispose("set(i___n = nofx($first.$x, $xmin), i___x = nofx($first.$x, $xmax))", 1); |
| 2450 |
my $imin = int Ifeffit::get_scalar("i___n") - 1; |
| 2451 |
my $imax = int Ifeffit::get_scalar("i___x") - 1; |
| 2452 |
$self->dispose("erase i___n i___x", 1); |
| 2453 |
my @abscissa = @first_absc[$imin .. $imax]; |
| 2454 |
Ifeffit::put_array("$group.$x", \@abscissa); |
| 2455 |
|
| 2456 |
## start command strings |
| 2457 |
if ($x eq 'energy') { |
| 2458 |
$self -> dispose("set $group.$x = $group.$x+$$r_groups{$first}->{bkg_eshift}", $mode); |
| 2459 |
}; |
| 2460 |
my ($cmd, $cmd2, $file, $n) = ("set $group.$x = $first.$x\n", "", "merge of ", 0); |
| 2461 |
|
| 2462 |
my $sets = "set(___x = npts($group.$x),\n"; |
| 2463 |
$sets .= " $group.$y1 = zeros(___x),\n"; |
| 2464 |
$sets .= " $group.stddev = zeros(___x))"; |
| 2465 |
$self -> dispose($sets, $mode); |
| 2466 |
|
| 2467 |
(($x eq 'r') or ($x eq 'q')) and ($self -> dispose("set $group.$y2 = zeros(___x)", $mode)); |
| 2468 |
my $is_detector = 0; |
| 2469 |
my $sum = 0; |
| 2470 |
foreach (@list) { |
| 2471 |
&$echocmd("> interpolating \"" . $$r_groups{$_} -> {label} . "\" to merge grid ..."); |
| 2472 |
my $noise = $$r_groups{$_}->{importance}; |
| 2473 |
if ($weight ne 'u') { |
| 2474 |
my @noise = $$r_groups{$_}->chi_noise($rpf); |
| 2475 |
$noise = ($x eq 'r') ? $noise[1] : $noise[0]; |
| 2476 |
}; |
| 2477 |
$sum += $noise; |
| 2478 |
$file .= $$r_groups{$_}->{label} . ", "; |
| 2479 |
my $esh = ($x eq 'energy') ? $$r_groups{$_}->{bkg_eshift} : 0; |
| 2480 |
## keep a running tally for mean and std. dev. |
| 2481 |
if ($x eq 'energy') { # worry about e0 shifts |
| 2482 |
my $yy = $y1; # worry about summing detector data |
| 2483 |
(($yy, $is_detector) = ("det", 1)) if $$r_groups{$_}->{not_data}; |
| 2484 |
($yy = 'flat') if ((lc($space) eq 'n') and $$r_groups{$_}->{bkg_flatten}); |
| 2485 |
$self -> dispose("set($_.merge = qinterp($_.$x+$esh, $_.$yy, $group.$x), $group.$y1 = $group.$y1 + $noise*$_.merge)", $mode); |
| 2486 |
} else { |
| 2487 |
$self -> dispose("set($_.merge = qinterp($_.$x, $_.$y1, $group.$x),$group.$y1 = $group.$y1 + $noise*$_.merge)", $mode); |
| 2488 |
}; |
| 2489 |
++$n; |
| 2490 |
if (($x eq 'r') or ($x eq 'q')) { |
| 2491 |
$self -> dispose("set($_.merge2 = qinterp($_.$x, $_.$y2, $group.$x), $group.$y2 = $group.$y2 + $noise*$_.merge2)", $mode); |
| 2492 |
## need a standard deviation of this part as well |
| 2493 |
$self -> dispose("erase $_.merge2", $mode); |
| 2494 |
}; |
| 2495 |
}; |
| 2496 |
my $yy = $y1; # worry about summing detector data |
| 2497 |
($yy = "det") if $is_detector; |
| 2498 |
$self -> dispose("set $group.$yy = $group.$y1 / $sum", $mode); |
| 2499 |
foreach (@list2) { # compute the variance, title lines |
| 2500 |
&$echocmd("> computing contribution of \"" . $$r_groups{$_} -> {label} . "\" to varience ..."); |
| 2501 |
my $noise = $$r_groups{$_}->{importance}; |
| 2502 |
if ($weight ne 'u') { |
| 2503 |
my @noise = $$r_groups{$_}->chi_noise($rpf); |
| 2504 |
$noise = ($x eq 'r') ? $noise[1] : $noise[0]; |
| 2505 |
}; |
| 2506 |
my $esh = 0; |
| 2507 |
my $string = "** " . $$r_groups{$_} -> {file}; |
| 2508 |
##$$r_groups{$_}->{is_rec} && ($string .= ", $_"); |
| 2509 |
push @{$self->{titles}}, $string; |
| 2510 |
if ($x eq 'energy') { # worry about e0 shifts |
| 2511 |
my $yy = $y1; # worry about summing detector data |
| 2512 |
($yy = "det") if $$r_groups{$_}->{not_data}; |
| 2513 |
my $yyy = $y1; # worry about summing detector data |
| 2514 |
($yyy = "det") if $$r_groups{$_}->{not_data}; |
| 2515 |
($yyy = 'flat') if ((lc($space) eq 'n') and $$r_groups{$_}->{bkg_flatten}); |
| 2516 |
$esh = $$r_groups{$_}->{bkg_eshift}; |
| 2517 |
$self -> dispose("set($_.merge = qinterp($_.$x+$esh, $_.$yyy, $group.$x), $group.stddev = $group.stddev + $noise*($_.merge-$group.$yy)**2)", $mode); |
| 2518 |
} else { |
| 2519 |
$self -> dispose("set($_.merge = qinterp($_.$x, $_.$y1, $group.$x), $group.stddev = $group.stddev + $noise*($_.merge-$group.$y1)**2)", $mode); |
| 2520 |
}; |
| 2521 |
$self -> dispose("erase $_.merge", $mode); |
| 2522 |
## need second column standard deviation also |
| 2523 |
}; |
| 2524 |
$self -> dispose("set $group.stddev = sqrt(($group.stddev * $n) / ($sum*($n-1)))", $mode); |
| 2525 |
$self -> put_titles(); |
| 2526 |
if ($y1 eq 'norm') { |
| 2527 |
$self -> dispose("set $group.xmu = $group.norm\n", $mode); |
| 2528 |
}; |
| 2529 |
if (($x eq 'r') or ($x eq 'q')) { |
| 2530 |
$self -> dispose("set $group.$y2 = $group.$y2 / $n", $mode); |
| 2531 |
$self -> dispose($cmd2, $mode); |
| 2532 |
my $str = sprintf("set(%s.%s = sqrt(%s.%s**2 + %s.%s**2),\n", |
| 2533 |
$group, $y3, $group, $y1, $group, $y2); |
| 2534 |
$str .= sprintf(" %s.%s = atan(%s.%s / %s.%s))\n", |
| 2535 |
$group, $y4, $group, $y2, $group, $y1); |
| 2536 |
$self -> dispose($str, $mode); |
| 2537 |
## } elsif ($x eq 'energy') { |
| 2538 |
## $self -> dispose("set $group.xmu = $group.norm\n", $mode); |
| 2539 |
}; |
| 2540 |
$file =~ s/, $//; |
| 2541 |
&$echocmd("> Merging ... done!"); |
| 2542 |
return ($file, $first, $is_detector, $is_xanes); |
| 2543 |
}; |
| 2544 |
|
| 2545 |
|
| 2546 |
sub chi_noise { |
| 2547 |
my $self = shift; |
| 2548 |
my ($rpf) = @_; |
| 2549 |
$self ->dispatch_bkg if $self->{update_bkg}; |
| 2550 |
my $group = $self->{group}; |
| 2551 |
my $string = "($group.chi, k=$group.k, "; |
| 2552 |
foreach (qw(kmin kmax dk kwindow)) { |
| 2553 |
my $this = "fft_".$_; |
| 2554 |
($this = "fft_win") if ($_ eq 'kwindow'); |
| 2555 |
my $val = $self->{$this}; |
| 2556 |
if (($_ eq 'kmax') and ($val == 999)) { |
| 2557 |
$self -> dispose("___x = ceil($self->{group}.k)\n", 1); |
| 2558 |
$val = Ifeffit::get_scalar("___x"); |
| 2559 |
}; |
| 2560 |
$string .= "$_=$val, "; |
| 2561 |
}; |
| 2562 |
$string .= "kweight=$$rpf{kw}, "; |
| 2563 |
$string =~ s/, $/\)\n/; |
| 2564 |
$string = wrap("\nchi_noise", " ", $string); |
| 2565 |
$self->dispose($string, 5); |
| 2566 |
$string = sprintf("## epsk=%.6g epsR=%.6g kmax_suggest=%.3f\n\n", |
| 2567 |
Ifeffit::get_scalar("epsilon_k"), |
| 2568 |
Ifeffit::get_scalar("epsilon_r"), |
| 2569 |
Ifeffit::get_scalar("kmax_suggest")); |
| 2570 |
$self->dispose($string, 5); |
| 2571 |
return (Ifeffit::get_scalar("epsilon_k"), |
| 2572 |
Ifeffit::get_scalar("epsilon_r"), |
| 2573 |
Ifeffit::get_scalar("kmax_suggest")); |
| 2574 |
}; |
| 2575 |
|
| 2576 |
|
| 2577 |
sub kmax_suggest { |
| 2578 |
my $self = shift; |
| 2579 |
my ($rpf) = @_; |
| 2580 |
my @noise = $self->chi_noise($rpf); |
| 2581 |
$self -> _MAKE(fft_kmax => $noise[2], update_fft=>1); |
| 2582 |
return $noise[2]; |
| 2583 |
}; |
| 2584 |
|
| 2585 |
|
| 2586 |
sub param_summary { |
| 2587 |
my $self = shift; |
| 2588 |
my $text = ""; |
| 2589 |
$text .= sprintf(". Element=%s Edge=%s\n", |
| 2590 |
$self->{bkg_z}, $self->{fft_edge}); |
| 2591 |
|
| 2592 |
$text .= "Background parameters\n"; |
| 2593 |
$text .= sprintf(". E0=%.3f Eshift=%.3f Rbkg=%.3f |
| 2594 |
. Standard=%s |
| 2595 |
. Kweight=%.1f Edge step=%.3f |
| 2596 |
. Fixed step=%s Flatten=%s |
| 2597 |
. Pre-edge range: [ %.3f : %.3f ] |
| 2598 |
. Pre-edge line: %.5g + %.5g * E |
| 2599 |
. Normalization range: [ %.3f : %.3f ] |
| 2600 |
. Post-edge polynomial: %.5g + %.5g * E + %.5g * E^2 |
| 2601 |
. Spline range: [ %.3f : %.3f ] Clamps: %s/%s |
| 2602 |
", |
| 2603 |
$self->{bkg_e0}, $self->{bkg_eshift}, $self->{bkg_rbkg}, |
| 2604 |
$self->{bkg_stan_lab}, |
| 2605 |
$self->{bkg_kw}, $self->{bkg_step}, |
| 2606 |
($self->{bkg_fixstep}?'yes':'no'), ($self->{bkg_flatten}?'yes':'no'), |
| 2607 |
$self->{bkg_pre1}, $self->{bkg_pre2}, |
| 2608 |
$self->{bkg_int}, $self->{bkg_slope}, |
| 2609 |
$self->{bkg_nor1}, $self->{bkg_nor2}, |
| 2610 |
$self->{bkg_nc0}, $self->{bkg_nc1}, $self->{bkg_nc2}, |
| 2611 |
$self->{bkg_spl1e}, $self->{bkg_spl2e}, $self->{bkg_clamp1}, $self->{bkg_clamp2}, |
| 2612 |
); |
| 2613 |
|
| 2614 |
$text .= "Foreward FT parameters\n"; |
| 2615 |
$text .= sprintf(". Kweight=%s Window=%s Phase correction=%s |
| 2616 |
. k-range: [ %.3f : %.3f ] dk=%.2f |
| 2617 |
", |
| 2618 |
$self->{fft_arbkw}, $self->{fft_win}, $self->{fft_pc}, |
| 2619 |
$self->{fft_kmin}, $self->{fft_kmax}, $self->{fft_dk}, |
| 2620 |
); |
| 2621 |
|
| 2622 |
$text .= "Backward FT parameters\n"; |
| 2623 |
$text .= sprintf(". R-range: [ %.3f : %.3f ] |
| 2624 |
. dR=%.2f Window=%s |
| 2625 |
", |
| 2626 |
$self->{bft_rmin}, $self->{bft_rmax}, |
| 2627 |
$self->{fft_dr}, $self->{bft_win}, |
| 2628 |
); |
| 2629 |
|
| 2630 |
$text .= "Plotting parameters\n"; |
| 2631 |
$text .= sprintf(". Multiplier=%.5g Y-offset=%.3f\n", |
| 2632 |
$self->{plot_scale}, $self->{plot_yoffset}); |
| 2633 |
|
| 2634 |
$text .= ". \n"; |
| 2635 |
return $text; |
| 2636 |
}; |
| 2637 |
|
| 2638 |
|
| 2639 |
sub sanity { |
| 2640 |
my $self = shift; |
| 2641 |
my $message = q{}; |
| 2642 |
|
| 2643 |
## background removal values |
| 2644 |
$message .= "The edge energy is unset\n" if ($self->{bkg_e0} =~ m{\A\s*\z}); |
| 2645 |
$message .= "The lower bound for the pre-edge range is very large ($self->{bkg_pre1})\n" if (abs($self->{bkg_pre1}) > 1000); |
| 2646 |
$message .= "The upper bound for the pre-edge range is very large ($self->{bkg_pre2})\n" if (abs($self->{bkg_pre2}) > 1000); |
| 2647 |
$message .= "The lower bound for the normalization range is very large ($self->{bkg_nor1})\n" if (abs($self->{bkg_nor1}) > 5000); |
| 2648 |
$message .= "The upper bound for the normalization range is very large ($self->{bkg_nor2})\n" if (abs($self->{bkg_nor2}) > 5000); |
| 2649 |
$message .= "The lower bound for the spline range is very large ($self->{bkg_spl1e})\n" if (abs($self->{bkg_spl1e}) > 5000); |
| 2650 |
$message .= "The upper bound for the spline range is very large ($self->{bkg_spl2e})\n" if (abs($self->{bkg_spl2e}) > 5000); |
| 2651 |
$message .= "The normalization order is not an allowed value ($self->{bkg_nnorm})\n" if (abs($self->{bkg_nnorm}) !~ m{[123]}); |
| 2652 |
|
| 2653 |
## Fourier transform values |
| 2654 |
$message .= "The kmin for the forward transfer is negative ($self->{fft_kmin})\n" if ($self->{fft_kmin} < 0); |
| 2655 |
$message .= "The kmax for the forward transfer is negative ($self->{fft_kmax})\n" if ($self->{fft_kmax} < 0); |
| 2656 |
$message .= "The kmin for the forward transfer is very large ($self->{fft_kmin})\n" if ($self->{fft_kmin} > 25); |
| 2657 |
$message .= "The kmax for the forward transfer is very large ($self->{fft_kmax})\n" if ($self->{fft_kmax} > 25); |
| 2658 |
$message .= "The dk for the forward transfer is negative ($self->{fft_dk})\n" if ($self->{fft_dk} < 0); |
| 2659 |
$message .= "The dk for the forward transfer is very large ($self->{fft_dk})\n" if ($self->{fft_dk} > 10); |
| 2660 |
$message .= "The arbitrary k-weight for the forward transfer is negative ($self->{fft_arbkw})\n" if ($self->{fft_arbkw} < 0); |
| 2661 |
$message .= "The arbitrary k-weight for the forward transfer is very large ($self->{fft_arbkw})\n" if ($self->{fft_arbkw} > 5); |
| 2662 |
|
| 2663 |
## backward Fourier transform values |
| 2664 |
$message .= "The Rmin for the backward transfer is negative ($self->{fft_rmin})\n" if ($self->{fft_rmin} < 0); |
| 2665 |
$message .= "The Rmax for the backward transfer is negative ($self->{fft_rmax})\n" if ($self->{fft_rmax} < 0); |
| 2666 |
$message .= "The Rmin for the backward transfer is very large ($self->{fft_rmin})\n" if ($self->{fft_rmin} > 31); |
| 2667 |
$message .= "The Rmax for the backward transfer is very large ($self->{fft_rmax})\n" if ($self->{fft_rmax} > 31); |
| 2668 |
$message .= "The dR for the backward transfer is negative ($self->{fft_dr})\n" if ($self->{fft_dr} < 0); |
| 2669 |
$message .= "The dR for the backward transfer is very large ($self->{fft_dr})\n" if ($self->{fft_dr} > 10); |
| 2670 |
|
| 2671 |
return 0 if ($message =~ m{\A\s*\z}); |
| 2672 |
|
| 2673 |
my $i = 0; |
| 2674 |
my $processed = q{}; |
| 2675 |
foreach my $line (split(/\n/, $message)) { |
| 2676 |
$processed .= sprintf(" %-3d: %s\n", ++$i, $line); |
| 2677 |
}; |
| 2678 |
return $processed; |
| 2679 |
}; |
| 2680 |
|
| 2681 |
|
| 2682 |
|
| 2683 |
1; |
| 2684 |
__END__ |