Files
Estia-McStas/bin/map_normalizer.pl
T

106 lines
2.6 KiB
Perl
Executable File

#!/usr/bin/perl -w
#
use Math::Trig ;
use Getopt::Std ;
my %options=();
getopts("f:r:e:b:", \%options);
# otions:
# -f <mesaurement file>
# -r <reference file>
# -e <exposure time>
# -b <background>
$zero = 1e-20 ;
$omega_mono = 3.7065 ;
$dl = 0.1 ;
print "\nmap_normaliser\n" ;
# create names
$samplefile = $options{f}."/Ilt" ;
$referencefile = $options{r}."/Ilt" ;
$normalisedfile = $options{f}."/Rlt" ;
# the measurement times
if ($options{e}) {$tms = $options{e}} else {$tms = 1} ;
$tmr = 1e8 ;
# background
if ($options{b}) {$bg = $options{b}} else {$bg = 0} ;
# read in SM reference
unless(open IN, "<$referencefile"){die "\n*** $referencefile does not exist!\n\n"} ;
print " reading $referencefile\n" ;
while (<IN>) {
unless (/#/) {
chomp ;
@line = split / */ ;
if ($line[3]) {
(undef,$t,$z,undef,undef,undef,undef,undef) = @line ;
$ir[$t][$z] = $line[7] ;
} ;
} ;
} ;
close IN ;
# read in sample measurements and print
open OUT, ">$normalisedfile" ;
print OUT "# normalised reflectivity map created with map_normaliser.pl\n" ;
print OUT "# sample file: $samplefile\n" ;
print OUT "# reference file: $referencefile\n" ;
if ($bg) {
print OUT "# added background: $samplefile + $bg * $referencefile\n" ,
} ;
print OUT "#\n# t z lambda theta time qz R(t,z) sigma I(t,z), I0(t,z) qz-error \n" ;
unless(open IN, "<$samplefile") {die "\n*** $samplefile does not exist!\n\n"} ;
print " reading $samplefile\n" ;
print " writing to $normalisedfile " ;
while (<IN>) {
unless (/#/) {
chomp ;
@line = split / */ ;
if ($line[3]) {
(undef, $t, $z, $lambda, $theta, $time, $qz, $is, $qzerr) = @line ;
$lot = 4*pi * sin(deg2rad( $omega + $omega_mono - $theta )) / (3.4*0.022) ; # lambda of theta
# normalize
$iq = 0 ;
$diq = 1/$zero ;
if ($ir[$t][$z]) {
if ($bg) {$is += $bg*$ir[$t][$z]} ;
if ($is > $zero and $ir[$t][$z] > $zero) {
$iq = $is / $ir[$t][$z] ;
$diq = $iq * sqrt( 1/($tms*$is) + 1/($tmr*$ir[$t][$z]) ) ;
} ;
} else {
$ir[$t][$z] = 0 ;
} ;
if ($lambda<$lot-$dl or $lambda>$lot+$dl) {$w=0} else {$w=1} ;
printf OUT " %4i %4i %6.3f %6.4f %12.5f %8.6f %10.4e %10.4e %10.4e %10.4e %8.6f %1i\n"
, $t
, $z
, $lambda
, $theta
, $time
, $qz
, $iq
, $diq
, $is
, $ir[$t][$z]
, $qzerr
, $w
;
} else {
print OUT "\n" ;
} ;
} else {
print OUT "$_" ;
if (/omega/) {
chomp ;
(undef,$omega) = split /=/ ;
} ;
} ;
} ;
close IN ;
close OUT ;
print "...done\n" ;