#!/usr/bin/perl -w

#use Getopt::Std;
use strict;

#######################################################################
#### Modify these values ##############################################
#######################################################################

my $nStart = 1;  
my $nStop  = 8;  #nStop<=8

my $que = 1;  #1=express, 2=general
my $testJob = 0; #1=test(do not submit)

my $nEvent = "500000";
#my $nEvent = "10";

my $decDir = "decFiles";
my $tclDir = "tclFiles";
my $scrDir = "scrFiles";
my $ntpDir = "gqahbook";

my $user = "khamano";
my $curDir = "/home1x/hep/khamano/releases/analysis-26/workdir";
my $logDir = "log";

#######################################################################
my $queue = "express";
my $walt = "walltime=5:00:00";
if ($que == 2) {
    $queue = "general";
    $walt = "walltime=48:00:00";
}

#######################################################################

my $decName = "BtoXclnu.dec";
my $tclName = "BtoXclnu.tcl";
my $scrName = "BtoXclnu.pl";
my $ntpName = "BtoXclnu.root";
my $nameBase = "BtoXclnu";

my $i =1;
my $j = 1;

$j=$nStart;
while ($j <= $nStop) {
    if ($j==1) {$nameBase = "BToDlnu";}
    if ($j==2) {$nameBase = "BToDstarlnu";}
    if ($j==3) {$nameBase = "BToD0starlnu";}
    if ($j==4) {$nameBase = "BToD1lnu";}
    if ($j==5) {$nameBase = "BToD2starlnu";}
    if ($j==6) {$nameBase = "BToD1primelnu";}
    if ($j==7) {$nameBase = "BToDpilnu";}
    if ($j==8) {$nameBase = "BToDstarpilnu";}
    $decName = "$decDir/$nameBase.dec";
    $tclName = "$tclDir/$nameBase.tcl";
    $scrName = "$scrDir/$nameBase.pl";
    $ntpName = "$ntpDir/$nameBase.root";
    #print "$decName\n";

    # Create DEC file
    open(DECIN, ">$decName") or die;
    print DECIN "#Define the B0B0bar mass difference\n";
    print DECIN "Define dm 0.489e12\n";
    print DECIN "Define dgamma 0\n";
    print DECIN "Define qoverp 1\n";
    print DECIN "Define phaseqoverp 0\n";
    print DECIN "# Turn on PHOTOS for all decays\n";
    print DECIN "yesPhotos\n";
    print DECIN "#\n";
    print DECIN "Decay vpho\n";
    print DECIN "1.000                     JSCONT 0;\n";
    print DECIN "Enddecay\n";
    print DECIN "#\n";
    #print DECIN "# RVK sets B+B- and B0B0 to values consistent with f+-/f00=1.026\n";
    print DECIN "Decay Upsilon(4S)\n";
    print DECIN "1.00000 B+  B-                          VSS;\n";
    #print DECIN "0.50900 B+  B-                          VSS;\n";
    #print DECIN "0.49100 B0  anti-B0                     VSS_BMIX dm;\n";
    print DECIN "Enddecay\n";
    print DECIN "#\n";
    if ($j==1) { #Dlnu
	print DECIN "Decay anti-B0\n";
	print DECIN "0.5000   D+     e-   anti-nu_e          PHOTOS  ISGW2;\n";
	print DECIN "0.5000   D+     mu-  anti-nu_mu         PHOTOS  ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B0\n";
	print DECIN "0.5000   D-     e+   nu_e           PHOTOS ISGW2;\n";
	print DECIN "0.5000   D-     mu+  nu_mu           PHOTOS ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B-\n";
	print DECIN "0.5000   D0     e-   anti-nu_e         PHOTOS  ISGW2;\n";
	print DECIN "0.5000   D0    mu-  anti-nu_mu         PHOTOS   ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B+\n";
	print DECIN "0.5000   anti-D0    e+   nu_e        PHOTOS  ISGW2;\n";
	print DECIN "0.5000   anti-D0    mu+  nu_mu        PHOTOS  ISGW2;\n";
	print DECIN "Enddecay\n";
    }
    if ($j==2) { #Dstar
	print DECIN "Decay anti-B0\n";
	print DECIN "0.5000   D*+    e-   anti-nu_e          PHOTOS  HQET 0.92 1.18 0.72;\n";
	print DECIN "0.5000   D*+    mu-  anti-nu_mu         PHOTOS  HQET 0.92 1.18 0.72;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B0\n";
	print DECIN "0.5000   D*-    e+   nu_e           PHOTOS HQET 0.92 1.18 0.72;\n";
	print DECIN "0.5000   D*-    mu+  nu_mu           PHOTOS HQET 0.92 1.18 0.72;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B-\n";
	print DECIN "0.5000   D*0    e-   anti-nu_e         PHOTOS  HQET 0.92 1.18 0.72;\n";
	print DECIN "0.5000   D*0   mu-  anti-nu_mu         PHOTOS   HQET 0.92 1.18 0.72;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B+\n";
	print DECIN "0.5000   anti-D*0    e+   nu_e        PHOTOS  HQET 0.92 1.18 0.72;\n";
	print DECIN "0.5000   anti-D*0    mu+  nu_mu       PHOTOS   HQET 0.92 1.18 0.72;\n";
	print DECIN "Enddecay\n";
    }
    if ($j==3) { #D0star
	print DECIN "Decay anti-B0\n";
	print DECIN "0.5000   D_0*+   e-   anti-nu_e          PHOTOS  ISGW2;\n";
	print DECIN "0.5000   D_0*+   mu-  anti-nu_mu         PHOTOS  ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B0\n";
	print DECIN "0.5000   D_0*-   e+   nu_e           PHOTOS ISGW2;\n";
	print DECIN "0.5000   D_0*-   mu+  nu_mu          PHOTOS  ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B-\n";
	print DECIN "0.5000   D_0*0   e-   anti-nu_e         PHOTOS  ISGW2;\n";
	print DECIN "0.5000   D_0*0  mu-  anti-nu_mu        PHOTOS    ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B+\n";
	print DECIN "0.5000   anti-D_0*0   e+   nu_e        PHOTOS  ISGW2;\n";
	print DECIN "0.5000   anti-D_0*0   mu+  nu_mu      PHOTOS    ISGW2;\n";
	print DECIN "Enddecay\n";
    }
    if ($j==4) { #D1
	print DECIN "Decay anti-B0\n";
	print DECIN "0.5000   D_1+   e-   anti-nu_e          PHOTOS  ISGW2;\n";
	print DECIN "0.5000   D_1+   mu-  anti-nu_mu         PHOTOS  ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B0\n";
	print DECIN "0.5000   D_1-   e+   nu_e           PHOTOS ISGW2;\n";
	print DECIN "0.5000   D_1-   mu+  nu_mu           PHOTOS ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B-\n";
	print DECIN "0.5000   D_10   e-   anti-nu_e         PHOTOS  ISGW2;\n";
	print DECIN "0.5000   D_10  mu-  anti-nu_mu         PHOTOS   ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B+\n";
	print DECIN "0.5000   anti-D_10   e+   nu_e        PHOTOS  ISGW2;\n";
	print DECIN "0.5000   anti-D_10   mu+  nu_mu       PHOTOS   ISGW2;\n";
	print DECIN "Enddecay\n";
    }
    if ($j==5) { #D2star
	print DECIN "Decay anti-B0\n";
	print DECIN "0.5000   D_2*+   e-   anti-nu_e          PHOTOS  ISGW2;\n";
	print DECIN "0.5000   D_2*+   mu-  anti-nu_mu         PHOTOS  ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B0\n";
	print DECIN "0.5000   D_2*-   e+   nu_e           PHOTOS ISGW2;\n";
	print DECIN "0.5000   D_2*-   mu+  nu_mu          PHOTOS  ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B-\n";
	print DECIN "0.5000   D_2*0   e-   anti-nu_e         PHOTOS  ISGW2;\n";
	print DECIN "0.5000   D_2*0  mu-  anti-nu_mu        PHOTOS    ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B+\n";
	print DECIN "0.5000   anti-D_2*0   e+   nu_e        PHOTOS  ISGW2;\n";
	print DECIN "0.5000   anti-D_2*0   mu+  nu_mu      PHOTOS    ISGW2;\n";
	print DECIN "Enddecay\n";
    }
    if ($j==6) { #D1prime
	print DECIN "Decay anti-B0\n";
	print DECIN "0.5000   D'_1+   e-   anti-nu_e          PHOTOS  ISGW2;\n";
	print DECIN "0.5000   D'_1+   mu-  anti-nu_mu         PHOTOS  ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B0\n";
	print DECIN "0.5000   D'_1-   e+   nu_e           PHOTOS ISGW2;\n";
	print DECIN "0.5000   D'_1-   mu+  nu_mu          PHOTOS  ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B-\n";
	print DECIN "0.5000   D'_10   e-   anti-nu_e         PHOTOS  ISGW2;\n";
	print DECIN "0.5000   D'_10  mu-  anti-nu_mu        PHOTOS    ISGW2;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B+\n";
	print DECIN "0.5000   anti-D'_10   e+   nu_e        PHOTOS  ISGW2;\n";
	print DECIN "0.5000   anti-D'_10   mu+  nu_mu      PHOTOS    ISGW2;\n";
	print DECIN "Enddecay\n";
    }
    if ($j==7) { #Dpi
	print DECIN "Decay anti-B0\n";
	print DECIN "0.1667   D+   pi0   e-   anti-nu_e      PHOTOS  GOITY_ROBERTS;\n";
	print DECIN "0.3333   D0   pi+   e-   anti-nu_e      PHOTOS  GOITY_ROBERTS;\n";
	print DECIN "0.1667   D+   pi0   mu-  anti-nu_mu    PHOTOS   GOITY_ROBERTS;\n";
	print DECIN "0.3333   D0   pi+   mu-  anti-nu_mu    PHOTOS   GOITY_ROBERTS;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B0\n";
	print DECIN "0.1667   D-   pi0   e+   nu_e       PHOTOS GOITY_ROBERTS;\n";
	print DECIN "0.3333   anti-D0  pi-   e+   nu_e       PHOTOS GOITY_ROBERTS;\n";
	print DECIN "0.1667   D-   pi0   mu+  nu_mu       PHOTOS GOITY_ROBERTS;\n";
	print DECIN "0.3333   anti-D0  pi-   mu+  nu_mu    PHOTOS    GOITY_ROBERTS;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B-\n";
	print DECIN "0.3333   D+   pi-   e-   anti-nu_e     PHOTOS  GOITY_ROBERTS;\n";
	print DECIN "0.1667   D0   pi0   e-   anti-nu_e     PHOTOS  GOITY_ROBERTS;\n";
	print DECIN "0.3333   D+    pi-   mu-   anti-nu_mu  PHOTOS   GOITY_ROBERTS;\n";
	print DECIN "0.1667   D0    pi0   mu-   anti-nu_mu  PHOTOS   GOITY_ROBERTS;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B+\n";
	print DECIN "0.3333   D-   pi+   e+   nu_e    PHOTOS  GOITY_ROBERTS;\n";
	print DECIN "0.1667   anti-D0  pi0   e+   nu_e    PHOTOS  GOITY_ROBERTS;\n";
	print DECIN "0.3333   D-   pi+   mu+   nu_mu       PHOTOS    GOITY_ROBERTS;\n";
	print DECIN "0.1667   anti-D0  pi0   mu+   nu_mu   PHOTOS        GOITY_ROBERTS;\n";
	print DECIN "Enddecay\n";
    }
    if ($j==8) { #Dstarpi
	print DECIN "Decay anti-B0\n";
	print DECIN "0.1667   D*+  pi0   e-   anti-nu_e      PHOTOS  GOITY_ROBERTS;\n";
	print DECIN "0.3333   D*0  pi+   e-   anti-nu_e      PHOTOS  GOITY_ROBERTS;\n";
	print DECIN "0.1667   D*+  pi0   mu-  anti-nu_mu    PHOTOS   GOITY_ROBERTS;\n";
	print DECIN "0.3333   D*0  pi+   mu-  anti-nu_mu    PHOTOS   GOITY_ROBERTS;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B0\n";
	print DECIN "0.1667   D*-  pi0   e+   nu_e       PHOTOS GOITY_ROBERTS;\n";
	print DECIN "0.3333   anti-D*0  pi-   e+   nu_e       PHOTOS GOITY_ROBERTS;\n";
	print DECIN "0.1667   D*-  pi0   mu+  nu_mu       PHOTOS GOITY_ROBERTS;\n";
	print DECIN "0.3333   anti-D*0  pi-   mu+  nu_mu   PHOTOS     GOITY_ROBERTS;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B-\n";
	print DECIN "0.3333   D*+  pi-   e-   anti-nu_e     PHOTOS  GOITY_ROBERTS;\n";
	print DECIN "0.1667   D*0  pi0   e-   anti-nu_e     PHOTOS  GOITY_ROBERTS;\n";
	print DECIN "0.3333   D*+   pi-   mu-   anti-nu_mu  PHOTOS   GOITY_ROBERTS;\n";
	print DECIN "0.1667   D*0   pi0   mu-   anti-nu_mu  PHOTOS   GOITY_ROBERTS;\n";
	print DECIN "Enddecay\n";
	print DECIN "#\n";
	print DECIN "Decay B+\n";
	print DECIN "0.3333   D*-  pi+   e+   nu_e    PHOTOS  GOITY_ROBERTS;\n";
	print DECIN "0.1667   anti-D*0  pi0   e+   nu_e    PHOTOS  GOITY_ROBERTS;\n";
	print DECIN "0.3333   D*-  pi+   mu+   nu_mu       PHOTOS    GOITY_ROBERTS;\n";
	print DECIN "0.1667   anti-D*0  pi0   mu+   nu_mu  PHOTOS         GOITY_ROBERTS;\n";
	print DECIN "Enddecay\n";
    }
    
    print DECIN "#\n";
    print DECIN "Decay D*+\n";
    print DECIN "0.6830    D0  pi+                        VSS;\n";
    print DECIN "0.3060    D+  pi0                        VSS;\n";
    print DECIN "0.0110    D+  gamma                       VSP_PWAVE;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay D*-\n";
    print DECIN "0.6830    anti-D0 pi-                        VSS;\n";
    print DECIN "0.3060    D-  pi0                        VSS;\n";
    print DECIN "0.0110    D-  gamma                       VSP_PWAVE;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay D*0\n";
    print DECIN "0.6190    D0  pi0                        VSS;\n";
    print DECIN "0.3810    D0  gamma                       VSP_PWAVE;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay anti-D*0\n";
    print DECIN "0.6190    anti-D0  pi0                       VSS;\n";
    print DECIN "0.3810    anti-D0  gamma                      VSP_PWAVE;\n";
    print DECIN "Enddecay\n";
    print DECIN "#\n";
    print DECIN "Decay D+\n";
    print DECIN "1.0000   K-  pi+  pi+                    D_DALITZ;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay D-\n";
    print DECIN "1.0000   K+  pi-  pi-                    D_DALITZ;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay D0\n";
    print DECIN "1.0000   K-  pi+                         PHSP;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay anti-D0\n";
    print DECIN "1.0000   K+  pi-                         PHSP;\n";
    print DECIN "Enddecay\n";
    print DECIN "#\n";
    print DECIN "#\n";
    print DECIN "Decay D_0*+\n";
    print DECIN "0.3333   D+  pi0                         PHSP;\n";
    print DECIN "0.6667   D0  pi+                         PHSP;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay D_0*-\n";
    print DECIN "0.3333   D-  pi0                         PHSP;\n";
    print DECIN "0.6667   anti-D0 pi-                         PHSP;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay D_0*0\n";
    print DECIN "0.3333   D0  pi0                         PHSP;\n";
    print DECIN "0.6667   D+  pi-                         PHSP;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay anti-D_0*0\n";
    print DECIN "0.3333   anti-D0 pi0                         PHSP;\n";
    print DECIN "0.6667   D-  pi+                         PHSP;\n";
    print DECIN "Enddecay\n";
    print DECIN "#\n";
    print DECIN "SetLineshapePW D_1+ D*+ pi0 2\n";
    print DECIN "SetLineshapePW D_1+ D*0 pi+ 2\n";
    print DECIN "SetLineshapePW D_1- D*- pi0 2\n";
    print DECIN "SetLineshapePW D_1- anti-D*0 pi- 2\n";
    print DECIN "SetLineshapePW D_10 D*0 pi0 2\n";
    print DECIN "SetLineshapePW D_10 D*+ pi- 2\n";
    print DECIN "SetLineshapePW anti-D_10 anti-D*0 pi0 2\n";
    print DECIN "SetLineshapePW anti-D_10 D*- pi+ 2\n";
    print DECIN "#\n";
    print DECIN "Decay D_1+\n";
    print DECIN "0.3333    D*+ pi0                        VVS_PWAVE  0.0 0.0 0.0 0.0 1.0 0.0;\n";
    print DECIN "0.6667    D*0 pi+                        VVS_PWAVE  0.0 0.0 0.0 0.0 1.0 0.0;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay D_1-\n";
    print DECIN "0.3333    D*- pi0                        VVS_PWAVE  0.0 0.0 0.0 0.0 1.0 0.0;\n";
    print DECIN "0.6667    anti-D*0 pi-                        VVS_PWAVE  0.0 0.0 0.0 0.0 1.0 0.0;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay D_10\n";
    print DECIN "0.3333    D*0 pi0                        VVS_PWAVE  0.0 0.0 0.0 0.0 1.0 0.0;\n";
    print DECIN "0.6667    D*+ pi-                        VVS_PWAVE  0.0 0.0 0.0 0.0 1.0 0.0;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay anti-D_10\n";
    print DECIN "0.3333    anti-D*0 pi0                        VVS_PWAVE  0.0 0.0 0.0 0.0 1.0 0.0;\n";
    print DECIN "0.6667    D*- pi+                        VVS_PWAVE  0.0 0.0 0.0 0.0 1.0 0.0;\n";
    print DECIN "Enddecay\n";
    print DECIN "#\n";
    print DECIN "Decay D'_1+\n";
    print DECIN "0.3333    D*+ pi0                        VVS_PWAVE  1.0 0.0 0.0 0.0 0.0 0.0;\n";
    print DECIN "0.6667    D*0 pi+                        VVS_PWAVE  1.0 0.0 0.0 0.0 0.0 0.0;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay D'_1-\n";
    print DECIN "0.3333    D*- pi0                        VVS_PWAVE  1.0 0.0 0.0 0.0 0.0 0.0;\n";
    print DECIN "0.6667    anti-D*0 pi-                        VVS_PWAVE  1.0 0.0 0.0 0.0 0.0 0.0;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay D'_10\n";
    print DECIN "0.6667    D*+ pi-                        VVS_PWAVE  1.0 0.0 0.0 0.0 0.0 0.0;\n";
    print DECIN "0.3333    D*0 pi0                        VVS_PWAVE  1.0 0.0 0.0 0.0 0.0 0.0;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay anti-D'_10\n";
    print DECIN "0.3333    anti-D*0 pi0                   VVS_PWAVE  1.0 0.0 0.0 0.0 0.0 0.0;\n";
    print DECIN "0.6667    D*- pi+                        VVS_PWAVE  1.0 0.0 0.0 0.0 0.0 0.0;\n";
    print DECIN "Enddecay\n";
    print DECIN "#\n";
    print DECIN "SetLineshapePW D_2*+ D*+ pi0 2\n";
    print DECIN "SetLineshapePW D_2*+ D*0 pi+ 2\n";
    print DECIN "SetLineshapePW D_2*- D*- pi0 2\n";
    print DECIN "SetLineshapePW D_2*- anti-D*0 pi- 2\n";
    print DECIN "SetLineshapePW D_2*0 D*0 pi0 2\n";
    print DECIN "SetLineshapePW D_2*0 D*+ pi- 2\n";
    print DECIN "SetLineshapePW anti-D_2*0 anti-D*0 pi0 2\n";
    print DECIN "SetLineshapePW anti-D_2*0 D*- pi+ 2\n";
    print DECIN "#\n";
    print DECIN "Decay D_2*+\n";
    print DECIN "0.1030    D*+ pi0                        TVS_PWAVE  0.0 0.0 1.0 0.0 0.0 0.0;\n";
    print DECIN "0.2090    D*0 pi+                        TVS_PWAVE  0.0 0.0 1.0 0.0 0.0 0.0;\n";
    print DECIN "0.2290    D+  pi0                        TSS;\n";
    print DECIN "0.4590    D0  pi+                        TSS;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay D_2*-\n";
    print DECIN "0.1030    D*- pi0                        TVS_PWAVE  0.0 0.0 1.0 0.0 0.0 0.0;\n";
    print DECIN "0.2090    anti-D*0 pi-                   TVS_PWAVE  0.0 0.0 1.0 0.0 0.0 0.0;\n";
    print DECIN "0.2290    D-  pi0                        TSS;\n";
    print DECIN "0.4590    anti-D0 pi-                    TSS;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay D_2*0\n";
    print DECIN "0.2090    D*+ pi-                        TVS_PWAVE  0.0 0.0 1.0 0.0 0.0 0.0;\n";
    print DECIN "0.1030    D*0 pi0                        TVS_PWAVE  0.0 0.0 1.0 0.0 0.0 0.0;\n";
    print DECIN "0.2290    D0  pi0                        TSS;\n";
    print DECIN "0.4590    D+  pi-                        TSS;\n";
    print DECIN "Enddecay\n";
    print DECIN "Decay anti-D_2*0\n";
    print DECIN "\0.1030    anti-D*0 pi0                        TVS_PWAVE  0.0 0.0 1.0 0.0 0.0 0.0;n";
    print DECIN "0.2090    D*- pi+                        TVS_PWAVE  0.0 0.0 1.0 0.0 0.0 0.0;\n";
    print DECIN "0.2290    anti-D0 pi0                        TSS;\n";
    print DECIN "0.4590    D-  pi+                        TSS;\n";
    print DECIN "Enddecay\n";
    print DECIN "#\n";
    print DECIN "End\n";
    close DECIN;

    # Create tcl file
    open(TCLIN, ">$tclName") or die;
    print TCLIN "sourceFoundFile GeneratorsQA/common.tcl\n";
    print TCLIN "disableGenerators 0\n";
    print TCLIN "module enable GfiEvtGen\n";
    print TCLIN "mod talk GfiEvtGen\n";
    print TCLIN "  UDECAY set \"$decName\"\n";
    print TCLIN "exit\n";
    print TCLIN "mod talk GqaSemileptonic\n";
    print TCLIN "#  verbose set true\n";
    print TCLIN "#  production set false\n";
    print TCLIN "  makeNtuple set true\n";
    print TCLIN "exit\n";
    print TCLIN "mod talk RooTupleEnv\n";
    print TCLIN "  histFileName set \"$ntpName\"\n";
    print TCLIN "exit\n";
    print TCLIN "mod talk RandomControl\n";
    print TCLIN "  maxEventsPerRun set 500000\n";
    print TCLIN "exit\n";
    print TCLIN "mod talk RacTestInput\n";
    print TCLIN "  run set 4\n";
    print TCLIN "exit\n";
    print TCLIN "ev begin -nev $nEvent\n";
    print TCLIN "exit\n";
    print TCLIN "\n";
    close TCLIN;

    # Create script file to run
    #print "$scrName\n";
    open(SCRIN, ">$scrName") or die;
    print SCRIN "\#\!/usr/bin/perl -w\n";
    print SCRIN "\#use strict;\n";
    print SCRIN "chdir \"$curDir\";\n";
    print SCRIN "my \$cmd = \"GeneratorsQAApp $tclName\";\n";
    print SCRIN "system(\$cmd);\n";
    print SCRIN "exit;\n";
    close SCRIN;
    system("chmod u+x $scrName");

    # Create submit command
    my $jobName = "$nameBase";
    my $logName = $logDir;
    my $subCmd = "qsub -q $queue -u $user -l $walt -V -N $jobName -e $logName -o $logName $scrName";
    
    print "$subCmd\n";
    if ($testJob != 1) {system($subCmd);}


    $j++;
    sleep 1;

}
