ccd_select.pl (version 0.0)
You can also look at:
#!/usr/local/bin/perl
#############################################################################
#
# VERSION: 0.0
#
#############################################################################
$instno = $ARGV[0];
$mkfilterVers = 2;
$ccdlst = $ARGV[1];
@results = &ccdThresh($instno,$mkfilterVers,$ccdlst);
($chipno,$thresh_templ) = splice(@results,0,2);
%ThreshDefaults = @results;
#print "\nChipno = $chipno\n\nThreshold Expression:\n $thresh_templ\n\n";
#print "Threshhold Defaults = ",join(" ",%ThreshDefaults),"\n\n";
foreach $keyval(keys(%ThreshDefaults)) {
$thresh_templ =~ s/THRESH$keyval/$ThreshDefaults{$keyval}/g;
}
#print "Converted Expression:\n $thresh_templ\n";
print "$thresh_templ\n";
######################################################################
# SUBROUTINE: ccdThresh2($instno,$ccdlst,$nevents,$ontime)
# ARGUMENTS:
# $instno - Instrument number (0 or 1)
# $ccdlst - value of S${instno}_CCDLST keyword
# $nevents - (optional) number of events
# $ontime - (optional) ontime for the data
# The latter two are not used yet, but when we know how to set the
# defaults for bright sources, they will be...
# RETURNS:
# $chipno (for 1ccd mode this is the number of the active
# chip, otherwise it is -1 )
# $threshExpr - String with the default MKF selection expression
# THRESH$i in place of actual values, where
# $i is the index into %defValues
# %defValues - keys - chip list for this default
# (comma delimited) ( i.e. 0,1 )
# values - their Threshold default
# Description:
# This gets the default values and thresh expression for MKFILTER selection
#
############################################################################
sub ccdThresh
{
local($instno,$mkfver,$ccdlst,$nevents,$ontime) = splice(@_,0,5);
local($useIntensity,@ccdlst,@ccdpow,%usedChips,%hits,@chipList);
local($chipno,%result,$key,%hitsToThresh,$threshTempl);
$useIntensity = 1 if(defined $nevents && defined $ontime);
#
# Get the default right for either MKF version:
# Note, if a chip appears 3 times, we will give 0 for the default.
# In fact we do not know what the default should be, so this is OK
#
if ( $mkfver == 1 ) {
if ( $useIntensity ) {
%hitsToThresh = ( 1 , 800,
2 , 600,
3 , 400,
4, 400 );
}
else {
%hitsToThresh = ( 1 , 800,
2 , 600,
3 , 400,
4, 400 );
}
}
else {
if ( $useIntensity ) {
%hitsToThresh = ( 1 , 50,
2 , 75,
3 , 100,
4, 100 );
}
else {
%hitsToThresh = ( 1 , 50,
2 , 75,
3 , 100,
4, 100 );
}
}
#
# %usedChips will contain the chips used
# Key will be the chip number, Value will be the number of times it appears
#
grep($usedChips{$_}++,split(' ',$ccdlst));
#
# How many distinct # of hits are there?
# Key will be # of hits,
# Value the chip list (comma delimited) with those hits...
#
foreach (keys(%usedChips)) {
$hits{$usedChips{$_}} .= ",$_";
push(@chipList,$_);
}
#
# Strip off the leading ,:
#
foreach (keys(%hits)) { substr($hits{$_},0,1) = ''; }
#
# Set the chipno:
#
if ( $#chipList == 0 ) {
$chipno = $chipList[0];
}
else {
$chipno = -1;
}
#
# Run over the distinct hits:
#
foreach $key (keys(%hits)) {
$THRESH = 'THRESH'.$hits{$key};
$result{$hits{$key}} = $hitsToThresh{$key};
#
# Now add each chip to the template:
#
foreach (split(',',$hits{$key})) {
$threshTempl .=
"\&\&(S${instno}_PIXL$_>0)&&(S${instno}_PIXL$_<$THRESH)\n";
}
}
chop $threshTempl;
($chipno,$threshTempl,%result);
}