The following piece of code optimizes the centers of two slits. Notice that the devices which are used during the measurement are supplied as a (local) profile. This does not alter the device selection.
#!/bin/env perl use Spectra; my $vc = "VC17"; my %profile = ( timer => [ qw( exp_t01)], counter => [ $vc, "ipetra"], flags => [ qw( write_to_disk 1 display_deadtime 1 bell_on_scan_end 1)]); # # slitName "s1" # center "cx" # opening "dx" # range 2.5, np 51, openingFinal # np 51 # openingFinal 1.25, where opening is eventually moved # sub doScan { my ( $slitName, $center, $opening, $range, $np, $openingFinal) = @_; my $status = 1; Spectra::log( "doScan: scanning ${slitName}, ${center}"); $Spectra::SYM{ "generic_scan_name"} = $slitName . $opening; if( !Spectra::slit( $slitName, $opening, 0.1)) { $status = Spectra::error( "slitscans: failed to move ${slitName} ${opening}"); goto finish; } if( !Spectra::scan( type => "slit", device => "(${slitName}, ${center})", range => $range, np => $np, st => 0.2, title => "A Slit Scan", generic_macro_name => "auto_scan", profile => \%profile)) { $status = Spectra::error( "slitscans: failed to execute $slitName ${center} scan"); goto finish; } my $sname = $Spectra::SYM{ scan_name} . "_$vc"; ($ssa_status, $cms, $midpoint, $int, $bg_int, $fwhm, $peak_x, $peak_y, $bg_l, $bg_r) = Spectra::ssa( name => $sname); if( !$ssa_status) { $status = Spectra::error( "slitscans: ssa_status == 0, ${slitName} ${center}"); goto finish; } Spectra::log( "doScan: ${slitName} ${center}, result cms $cms"); if( !Spectra::slit( $slitName, $center, $cms)) { $status = Spectra::error( "slitscans: failed to move ${slitName} ${center}"); goto finish; } if( !Spectra::slit( $slitName, $opening, $openingFinal)) { $status = Spectra::error( "slitscans: failed to move ${slitName} ${opening}"); goto finish; } finish: return $status; } # # main # my $status = 0; if( !Spectra::slit( "s2", "dx", 3)) { Spectra::error( "slitscans: failed to move s2_dx"); goto finish; } if( !Spectra::slit( "s2", "dy", 3)) { Spectra::error( "slitscans: failed to move s2_dy"); goto finish; } if( !doScan( "s1", "cx", "dx", 2.5, 51, 1)) { goto finish; } if( !doScan( "s1", "cy", "dy", 2.5, 51, 1)) { goto finish; } if( !doScan( "s2", "cx", "dx", 2.5, 51, 1.25)) { goto finish; } if( !doScan( "s2", "cy", "dy", 2.5, 51, 1.25)) { goto finish; } Spectra::log( "slitscans: DONE"); $status = 1; finish: $status;