Index: trunk/ippScripts/scripts/background_chip.pl
===================================================================
--- trunk/ippScripts/scripts/background_chip.pl	(revision 28532)
+++ trunk/ippScripts/scripts/background_chip.pl	(revision 28536)
@@ -144,6 +144,6 @@
 my $out_image = $ipprc->filename("PPBACKGROUND.OUTPUT", $outroot, $class_id);
 my $out_mask = $ipprc->filename("PPBACKGROUND.OUTPUT.MASK", $outroot, $class_id);
-my $out_stats = $ipprc->filename("PPIMAGE.STATS", $outroot, $class_id);
-my $out_config = $ipprc->filename("PPIMAGE.CONFIG", $outroot, $class_id);
+my $out_stats = $ipprc->filename("PPBACKGROUND.STATS", $outroot, $class_id);
+my $out_config = $ipprc->filename("PPBACKGROUND.CONFIG", $outroot, $class_id);
 my $traceDest = $ipprc->filename("TRACE.IMFILE", $outroot, $class_id);
 
Index: trunk/ippScripts/scripts/dist_advancerun.pl
===================================================================
--- trunk/ippScripts/scripts/dist_advancerun.pl	(revision 28532)
+++ trunk/ippScripts/scripts/dist_advancerun.pl	(revision 28536)
@@ -66,4 +66,5 @@
 my $difftool   = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1);
 my $stacktool   = can_run('stacktool') or (warn "Can't find stacktool" and $missing_tools = 1);
+my $bgtool = can_run('bgtool') or (warn "Can't find bgtool" and $missing_tools = 1);
 if ($missing_tools) {
     &my_die("Can't find required tools.", $dist_id, $PS_EXIT_CONFIG_ERROR);
@@ -82,4 +83,8 @@
     $tool_cmd = "$chiptool -chip_id";
     $list_mode = "-processedimfile";
+    $component_key = "class_id";
+} elsif ($stage eq "chip_bg") {
+    $tool_cmd = "$bgtool -chip_bg_id";
+    $list_mode = "-chip";
     $component_key = "class_id";
 } elsif ($stage eq "camera") {
@@ -94,4 +99,8 @@
     $tool_cmd = "$warptool -warp_id";
     $list_mode = "-warped";
+    $component_key = "skycell_id";
+} elsif ($stage eq "warp_bg") {
+    $tool_cmd = "$bgtool -warp_bg_id";
+    $list_mode = "-warp";
     $component_key = "skycell_id";
 } elsif ($stage eq "stack") {
Index: trunk/ippScripts/scripts/dist_bundle.pl
===================================================================
--- trunk/ippScripts/scripts/dist_bundle.pl	(revision 28532)
+++ trunk/ippScripts/scripts/dist_bundle.pl	(revision 28536)
@@ -35,4 +35,6 @@
                      'PPIMAGE.CHIP.MASK' => 'mask',
                      'PPIMAGE.CHIP.VARIANCE' => 'variance' );
+my %chip_bg_cleaned = ( 'PPBACKGROUND.OUTPUT' => 'image',
+                        'PPBACKGROUND.OUTPUT.MASK' => 'mask' );
 my %camera_cleaned = ( 'PSASTRO.OUTPUT.MASK' => 'mask' );
 my %fake_cleaned;
@@ -40,4 +42,6 @@
                      'PSWARP.OUTPUT.MASK' => 'mask',
                      'PSWARP.OUTPUT.VARIANCE' => 'variance' );
+my %warp_bg_cleaned = ( 'PSWARP.OUTPUT' => 'image',
+                        'PSWARP.OUTPUT.MASK' => 'mask' );
 my %diff_cleaned = ( 'PPSUB.OUTPUT' => 'image',
                      'PPSUB.OUTPUT.MASK' => 'mask',
@@ -246,5 +250,5 @@
         my $fh = open_with_retries($mask_resolved);
         close $fh;
-    } elsif ($stage eq "chip") {
+    } elsif ($stage eq "chip" or $stage eq "chip_bg") {
         $class_id = $component;
     }
@@ -416,4 +420,6 @@
     if ($stage eq "chip") {
         $config_file_rule = "PPIMAGE.CONFIG";
+    } elsif ($stage eq "chip") {
+        $config_file_rule = "PPBACKGROUND.CONFIG";
     } elsif ($stage eq "camera") {
         $config_file_rule = "PSASTRO.CONFIG";
@@ -422,4 +428,6 @@
         return \@file_list;
     } elsif ($stage eq "warp") {
+        $config_file_rule = "PSWARP.CONFIG";
+    } elsif ($stage eq "warp_bg") {
         $config_file_rule = "PSWARP.CONFIG";
     } elsif ($stage eq "diff") {
Index: trunk/ippScripts/scripts/dist_defineruns.pl
===================================================================
--- trunk/ippScripts/scripts/dist_defineruns.pl	(revision 28532)
+++ trunk/ippScripts/scripts/dist_defineruns.pl	(revision 28536)
@@ -83,5 +83,5 @@
     push @stages, $stage;
 } else {
-    @stages = qw( raw chip camera fake warp diff stack SSdiff);
+    @stages = qw( raw chip chip_bg camera fake warp warp_bg diff stack SSdiff);
 }
 
Index: trunk/ippScripts/scripts/dist_make_fileset.pl
===================================================================
--- trunk/ippScripts/scripts/dist_make_fileset.pl	(revision 28532)
+++ trunk/ippScripts/scripts/dist_make_fileset.pl	(revision 28536)
@@ -239,4 +239,6 @@
     } elsif ($stage eq 'chip') {
         $query = "SELECT exp_name FROM chipRun JOIN rawExp USING(exp_id) WHERE chip_id = $stage_id";
+    } elsif ($stage eq 'chip_bg') {
+        $query = "SELECT exp_name FROM chipBackgroundRun JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) WHERE chip_bg_id = $stage_id";
     } elsif ($stage eq 'camera') {
         $query = "SELECT exp_name FROM camRun JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id)"
@@ -248,4 +250,6 @@
         $query = "SELECT exp_name FROM warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id)"
                     . " JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) WHERE warp_id = $stage_id";
+    } elsif ($stage eq 'warp_bg') {
+        $query = "SELECT exp_name FROM warpBackgroundRun JOIN warpRun USING(warp_id) JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) WHERE warp_bg_id = $stage_id";
     } else {
         &my_die("$stage is invalid value for stage\n");
Index: trunk/ippScripts/scripts/magic_destreak.pl
===================================================================
--- trunk/ippScripts/scripts/magic_destreak.pl	(revision 28532)
+++ trunk/ippScripts/scripts/magic_destreak.pl	(revision 28536)
@@ -97,8 +97,8 @@
 my ($skycell_args, $class_id, $skycell_id);
 
-if (($stage eq "raw") or ($stage eq "chip")) {
+if (($stage eq "raw") or ($stage eq "chip") or $stage eq "chip_bg") {
     $class_id = $component;
     $skycell_args = " -class_id $component";
-} elsif ($stage eq "warp") {
+} elsif ($stage eq "warp" or $stage eq "warp_bg") {
     $skycell_id = $component;
     $skycell_args = " -skycell_id $component";
@@ -286,5 +286,9 @@
         # $sources = $ipprc->filename("PSPHOT.OUT.CMF.SPL",  $path_base);
 
-    } elsif ($stage eq "warp") {
+    } elsif ($stage eq "chip_bg") {
+        $image  = $ipprc->filename("PPBACKGROUND.OUTPUT", $path_base, $class_id);
+        $mask = $ipprc->filename("PPBACKGROUND.OUTPUT.MASK", $path_base, $class_id);
+        $astrom = $ipprc->filename("PSASTRO.OUTPUT", $cam_path_base);
+    } elsif ($stage eq "warp" or $stage eq "warp_bg") {
         $image  = $ipprc->filename("PSWARP.OUTPUT", $path_base);
         $mask   = $ipprc->filename("PSWARP.OUTPUT.MASK", $path_base);
