def callgenerate(options):
    from MadGraphControl.MadGraphUtils import print_cards, generate, arrange_output

    print_cards()
    generate(
        run_card_loc="run_card.dat",
        param_card_loc="param_card_new.dat",
        mode=options["mode"],
        proc_dir=options["processdir"],
        run_name=options["runName"],
    )
    arrange_output(
        run_name=options["runName"],
        proc_dir=options["processdir"],
        outputDS=options["runName"] + "._00001.events.tar.gz",
    )
def BulkRS_Generation(run_number=100000,
                      gentype="tt",
                      scenario="c10",
                      stringy="m1000",
                      mass=1000,
                      nevts=5000,
                      rand_seed=1234,
                      beamEnergy=6500.,
                      scalevariation=1.0,
                      alpsfact=1.0,
                      pdf='nn23lo',
                      lhaid=247000):

    # -----------------------------------------------------------------------
    # Need to arrange several things:
    # -- proc_card.dat, this will be determined mostly by the run number.
    #    once we have this, we can also initialize the process in madgraph
    #
    # -- param_card.dat, this is mostly invariant, but does depend on the model scenario
    #
    # -- run_card.dat, this is also mostly invariant
    #
    # At that point we can generate the events, arrange the output, and cleanup.
    # -----------------------------------------------------------------------
    
    # -----------------------------------------------------------------------
    # proc card
    #
    # first, figure out what process we should run
    processes=[]
    pythiachans=[]
    if gentype == "tt":
        processes.append("p p > hh, (hh > t t~, t > j l+ vl, t~ > j l- vl~)")
        processes.append("p p > hh, (hh > t t~, t > j j j, t~ > j j j)")
        processes.append("p p > hh, (hh > t t~, t > j j j, t~ > j l- vl~)")
        processes.append("p p > hh, (hh > t t~, t > j l+ vl, t~ > j j j)")
    else:
        mglog.error('Could not configure process for %s' % (gentype))
        return -1,pythiachans
            

    # Now, import the template.  Could have just written this whole thing out in the
    # script, but a template is nicer for people perusing SVN.
    proccard = subprocess.Popen(['get_files','-data','MadGraph_proc_card_BulkRS.dat'])
    proccard.wait()
    
    # Figure out how to modify the template.
    processstring=""
    processcount=1
    for i in processes:
        if processstring=="":
            processstring="generate %s QED=99 QCD=99 @%d " % (i, processcount)
        else:
            processstring+="\nadd process %s QED=99 QCD=99 @%d " % (i, processcount)
        processcount+=1

    calcwidthstring="""
generate hh > all all
output SMRS_widths -f
launch
set c %f
set Mh %f
set MH %f
set Mhh %f
""" % (float(scenario[1:])/10., 125., 125., float(mass))

    # check that we're in a clean directory
    if not os.access('MadGraph_proc_card_BulkRS.dat',os.R_OK):
        mglog.error('Could not retrieve process card template')
        return -1,pythiachans
    if os.access('proc_card_mg5.dat',os.R_OK) or os.access('proc_card_mg5_step1.dat',os.R_OK):
        mglog.error('Old process card in the current directory.  Do not want to clobber it.  Please move it first.')
        return -1,pythiachans

    # now, modify the process cards.  note that we need two here: one that will 
    oldcard = open('MadGraph_proc_card_BulkRS.dat','r')
    newcardgen = open('proc_card_mg5.dat','w')
    newcardwidths = open('proc_card_mg5_step1.dat','w')
    for line in oldcard.readlines():
        if 'generate' in line: 
            newcardgen.write(processstring)
            newcardwidths.write(calcwidthstring)
        elif "output -f" in line:
            newcardgen.write(line)
        else: 
            newcardgen.write(line)
            newcardwidths.write(line)
    oldcard.close()
    newcardgen.close()
    newcardwidths.close()
    # -----------------------------------------------------------------------


    # -----------------------------------------------------------------------
    # run card
    extras={}
    extras["scale"] = mass
    extras["dsqrt_q2fact1"] = mass
    extras["dsqrt_q2fact2"] = mass
    extras["pdlabel"]=pdf
    extras["lhaid"]=lhaid
    build_run_card(run_card_old='MadGraph_run_card_BulkRS.dat',
                   run_card_new='run_card.dat',
                   xqcut=0,
                   nevts=nevts,
                   rand_seed=rand_seed,
                   beamEnergy=beamEnergy, 
                   scalefact=scalevariation, 
                   alpsfact=alpsfact,
                   extras=extras)
    # -----------------------------------------------------------------------


    # -----------------------------------------------------------------------
    # param card needs to be built with correct widths
    process_dir = new_process(card_loc='proc_card_mg5_step1.dat')
    print "printing process dir"
    print process_dir
    print "printed process dir"
    generate(run_card_loc='run_card.dat', 
             param_card_loc=None, 
             mode=0, 
             njobs=1, 
             run_name='run_01', 
             proc_dir=process_dir)
    str_param_card='SMRS_widths/Events/run_01/param_card.dat'
    # -----------------------------------------------------------------------

    # -----------------------------------------------------------------------
    # Now configure the generation process directory/etc
    thedir = new_process(card_loc='proc_card_mg5.dat')
    if 1==thedir:
        mglog.error('Error in process generation!')
        return -1,pythiachans
    
    # See if things are where we expected them to be...
    if not os.access(thedir,os.R_OK):
        mglog.error('Could not find process directory '+thedir+' !!  Bailing out!!')
        return -1,pythiachans
    else:
        mglog.info('Using process directory '+thedir)
    # -----------------------------------------------------------------------

    # -----------------------------------------------------------------------
    # Generation
    if generate(run_card_loc='run_card.dat',
                param_card_loc=str_param_card,
                mode=0,
                njobs=1,
                run_name='Test',
                proc_dir=thedir,
                grid_pack=False):
        mglog.error('Error generating events!')
        return -1,pythiachans
    # -----------------------------------------------------------------------

    # -----------------------------------------------------------------------
    # Cleanup
    outputDS=""
    try:
        outputDS=arrange_output(run_name='Test',
                                proc_dir=thedir,
                                outputDS='madgraph.%i.madgraph_BulkRS_%s_%s_%s._00001.events.tar.gz'%(run_number,scenario,gentype,stringy))
    except:
        mglog.error('Error arranging output dataset!')
        return -1,pythiachans

    keepOutput=False
    if not keepOutput:
        mglog.info('Removing process directory...')
        shutil.rmtree(thedir,ignore_errors=True)
        shutil.rmtree(process_dir,ignore_errors=True)

    mglog.info('All done generating events!!')
    return outputDS,pythiachans
def HVT_Generation(run_number=100000,
                   gentype="Zh",
                   decaytype="lljj",
                   scenario="Agv1",
                   stringy="126",
                   mass=1000,
                   nevts=5000,
                   rand_seed=1234,
                   beamEnergy=6500.,
                   scalevariation=1.0,
                   alpsfact=1.0,
                   pdf='nn23lo',
                   lhaid=247000):

    # -----------------------------------------------------------------------
    # Need to arrange several things:
    # -- proc_card.dat, this will be determined mostly by the run number.
    #    once we have this, we can also initialize the process in madgraph
    #
    # -- param_card.dat, this is mostly invariant, but does depend on the model scenario
    #
    # -- run_card.dat, this is also mostly invariant
    #
    # At that point we can generate the events, arrange the output, and cleanup.
    # -----------------------------------------------------------------------
    
    # -----------------------------------------------------------------------
    # proc card and process generation
    #
    # first, figure out what process we should run.
    # Note that the syntax 'p p > vz, (vz > z h)' means that the vz is always
    # on shell, with mass within some multiple of the width of the vz (usually 15, see 
    # bwcutoff in the run card).  If we want to allow the low-mass tail as well as the
    # peak, then generate 'p p > vz > z h' instead.
    processes=[]
    addHbb=False
    addHcc=False
    if gentype == "Zh" or gentype == "ZH" or gentype == "zh" or gentype == "zH":
        addHbb=True
        if decaytype == "lljj" or decaytype == "llqq":
            processes.append("p p > vz, (vz > z h, z > l+ l-)")
            addHcc=True
        elif decaytype == "jjjj" or decaytype == "qqqq":
            processes.append("p p > vz, (vz > z h, z > j j)") 
            addHcc=True
        elif decaytype == "vvqq" or decaytype == "vvjj":
            processes.append("p p > vz, (vz > z h, z > vl vl~)")
            addHcc=True
        elif decaytype == "llbb" or decaytype == "llbb":
            processes.append("p p > vz, (vz > z h, z > l+ l-)")
        elif decaytype == "jjbb" or decaytype == "qqbb":
            processes.append("p p > vz, (vz > z h, z > j j)")
        elif decaytype == "vvbb" or decaytype == "vvbb":
            processes.append("p p > vz, (vz > z h, z > vl vl~)")
        elif decaytype == "all":
            processes.append("p p > vz, (vz > z h)")
            addHbb=False
            addHcc=False
        else:
            mglog.error('Could not configure process for %s > %s' % (gentype, decaytype))
            return -1,''
    elif gentype == "WW" or gentype == "ww":
        if decaytype == "lvlv" or decaytype == "llvv":
            processes.append("p p > vz, (vz > w+ w-, w+ > l+ vl, w- > l- vl~)")
        elif decaytype == "jjjj" or decaytype == "qqqq":
            processes.append("p p > vz, (vz > w+ w-, w+ > j j, w- > j j)")
        elif decaytype == "lvqq" or decaytype == "lvjj":
            processes.append("p p > vz, (vz > w+ w-, w+ > j j, w- > l- vl~)")
            processes.append("p p > vz, (vz > w+ w-, w- > j j, w+ > l+ vl)")
        elif decaytype == "all":
            processes.append("p p > vz, (vz > w+ w-)")
        else:
            mglog.error('Could not configure process for %s > %s' % (gentype, decaytype))
            return -1,''
    elif gentype == "Wh" or gentype == "WH" or gentype == "wh" or gentype == "wH":
        addHbb=True
        if decaytype == "lvqq" or decaytype == "lvjj":
            processes.append("p p > vc+, (vc+ > w+ h, w+ > l+ vl)")
            processes.append("p p > vc-, (vc- > w- h, w- > l- vl~)")
            addHcc=True
        elif decaytype == "qqqq" or decaytype == "qqjj":
            processes.append("p p > vc+, (vc+ > w+ h, w+ > j j)")
            processes.append("p p > vc-, (vc- > w- h, w- > j j)")
            addHcc=True
        elif decaytype == "lvbb" or decaytype == "lvbb":
            processes.append("p p > vc+, (vc+ > w+ h, w+ > l+ vl)")
            processes.append("p p > vc-, (vc- > w- h, w- > l- vl~)")
        elif decaytype == "qqbb" or decaytype == "qqbb":
            processes.append("p p > vc+, (vc+ > w+ h, w+ > j j)")
            processes.append("p p > vc-, (vc- > w- h, w- > j j)")
        elif decaytype == "all":
            processes.append("p p > vc+, (vc+ > w+ h)")
            processes.append("p p > vc-, (vc- > w- h)")
            addHbb=False
            addHcc=False
        else:
            mglog.error('Could not configure process for %s > %s' % (gentype, decaytype))
            return -1,''
    elif gentype == "WZ" or gentype == "wz":
        if decaytype == "qqqq" or decaytype == "jjjj": 
            processes.append("p p > vc+, (vc+ > w+ z, w+ > j j, z > j j)")
            processes.append("p p > vc-, (vc- > w- z, w- > j j, z > j j)")
        elif decaytype == "lvqq" or decaytype == "lvjj": 
            processes.append("p p > vc+, (vc+ > w+ z, w+ > l+ vl, z > j j)")
            processes.append("p p > vc-, (vc- > w- z, w- > l- vl~, z > j j)")
        elif decaytype == "lvll" or decaytype == "lnull": 
            processes.append("p p > vc+, (vc+ > w+ z, w+ > l+ vl, z > l+ l-)")
            processes.append("p p > vc-, (vc- > w- z, w- > l- vl~, z > l+ l-)")
        elif decaytype == "llqq" or decaytype == "lljj" or decaytype == "qqll" or decaytype == "jjll": 
            processes.append("p p > vc+, (vc+ > w+ z, w+ > j j, z > l+ l-)")
            processes.append("p p > vc-, (vc- > w- z, w- > j j, z > l+ l-)")
        elif decaytype == "vvqq" or decaytype == "vvjj" or decaytype == "nunuqq" or decaytype == "nunujj":
            processes.append("p p > vc+, (vc+ > w+ z, w+ > j j, z > vl vl~)")
            processes.append("p p > vc-, (vc- > w- z, w- > j j, z > vl vl~)")
        elif decaytype == "lvvv" or decaytype == "lnununu": 
            processes.append("p p > vc+, (vc+ > w+ z, w+ > l+ vl, z > vl vl~)")
            processes.append("p p > vc-, (vc- > w- z, w- > l- vl~, z > vl vl~)")
        elif decaytype == "all": 
            processes.append("p p > vc+, (vc+ > w+ z)")
            processes.append("p p > vc-, (vc- > w- z)")
        else:
            mglog.error('Could not configure process for %s > %s' % (gentype, decaytype))
            return -1,''
    elif gentype == "Wg" or gentype == "Wgamma" or gentype == "wg" or gentype == "wgamma" or gentype == "Wa" or gentype == "wa" or gentype == "Wy" or gentype == "wy":
        if ("lv" in decaytype) or ("lnu" in decaytype):
            processes.append("p p > vc+, (vc+ > w+ a, w+ > l+ vl)")
            processes.append("p p > vc-, (vc- > w- a, w- > l- vl~)")
        elif ("qq" in decaytype) or ("jj" in decaytype):
            processes.append("p p > vc+, (vc+ > w+ a, w+ > j j)")
            processes.append("p p > vc-, (vc- > w- a, w- > j j)")
        else:
            mglog.error('Could not configure process for %s > %s' % (gentype, decaytype))
            return -1,''
    else:
        mglog.error('Could not configure process for %s > %s' % (gentype, decaytype))
        return -1,''
            
    # If we've got Higgs, and we only want H->bb or H->bb/cc, tell Pythia:
    pythiachans=[]
    if addHbb:
        pythiachans.append("25:oneChannel = on 0.569 100 5 -5 ")
        if addHcc:
            pythiachans.append("25:addChannel = on 0.0287 100 4 -4 ")
    elif addHcc:
        pythiachans.append("25:oneChannel = on 0.0287 100 4 -4 ")

    proccard = subprocess.Popen(['get_files','-data','MadGraph_proc_card_HVT.dat'])
    proccard.wait()
    
    processstring=""
    processcount=1
    for i in processes:
        if processstring=="":
            processstring="generate %s QED=99 QCD=99 @%d " % (i, processcount)
        else:
            processstring+="\nadd process %s QED=99 QCD=99 @%d" % (i, processcount)
        processcount+=1

    if not os.access('MadGraph_proc_card_HVT.dat',os.R_OK):
        mglog.error('Could not retrieve process card template')
        return -1,''
    if os.access('proc_card_mg5.dat',os.R_OK):
        mglog.error('Old process card in the current directory.  Do not want to clobber it.  Please move it first.')
        return -1,''
    oldcard = open('MadGraph_proc_card_HVT.dat','r')
    newcard = open('proc_card_mg5.dat','w')
    for line in oldcard.readlines():
        if 'generate' in line: newcard.write(processstring)
        else: newcard.write(line)
    oldcard.close()
    newcard.close()

    # Generate the new process!
    thedir = new_process(card_loc='proc_card_mg5.dat')
    if 1==thedir:
        mglog.error('Error in process generation!')
        return -1,''
    
    # See if things are where we expected them to be...
    if not os.access(thedir,os.R_OK):
        mglog.error('Could not find process directory '+thedir+' !!  Bailing out!!')
        return -1,''
    else:
        mglog.info('Using process directory '+thedir)
    # -----------------------------------------------------------------------


    # -----------------------------------------------------------------------
    # param card
    str_param_card='MadGraph_param_card_HVT_%s_M%04d.dat' % (scenario,mass)
    proc_paramcard = subprocess.Popen(['get_files','-data',str_param_card])
    proc_paramcard.wait()
    if not os.access(str_param_card,os.R_OK):
        mglog.info('Could not get param card '+str_param_card)
    # -----------------------------------------------------------------------

    # -----------------------------------------------------------------------
    # run card
    extras={}
    extras["scale"] = mass
    extras["dsqrt_q2fact1"] = mass
    extras["dsqrt_q2fact2"] = mass
    extras["pdlabel"]=pdf
    extras["lhaid"]=lhaid
    build_run_card(run_card_old='MadGraph_run_card_HVT.dat',
                   run_card_new='run_card.dat',
                   xqcut=0,
                   nevts=nevts,
                   rand_seed=rand_seed,
                   beamEnergy=beamEnergy, 
                   scalefact=scalevariation, 
                   alpsfact=alpsfact,
                   extras=extras)
    # -----------------------------------------------------------------------

    # -----------------------------------------------------------------------
    # Generation
    if generate(run_card_loc='run_card.dat',
                param_card_loc=str_param_card,
                mode=0,
                njobs=1,
                run_name='Test',
                proc_dir=thedir,
                grid_pack=False):
        mglog.error('Error generating events!')
        return -1
    # -----------------------------------------------------------------------

    # -----------------------------------------------------------------------
    # Cleanup
    outputDS=""
    try:
        outputDS=arrange_output(run_name='Test',
                                proc_dir=thedir,
                                outputDS='madgraph.%i.madgraph_HVT_%s_%s_%s_%s._00001.events.tar.gz'%(run_number,scenario,gentype,decaytype,stringy))
    except:
        mglog.error('Error arranging output dataset!')
        return -1

    keepOutput=True
    if not keepOutput:
        mglog.info('Removing process directory...')
        shutil.rmtree(thedir,ignore_errors=True)

    mglog.info('All done generating events!!')
    return outputDS,pythiachans
Example #4
0
def BulkRS_Generation(run_number=100000,
                      gentype="WW",
                      decaytype="lvqq",
                      scenario="c10",
                      stringy="m1000",
                      mass=1000,
                      nevts=5000,
                      rand_seed=1234,
                      beamEnergy=6500.,
                      scalevariation=1.0,
                      alpsfact=1.0,
                      pdf='nn23lo',
                      lhaid=247000):

    # -----------------------------------------------------------------------
    # Need to arrange several things:
    # -- proc_card.dat, this will be determined mostly by the run number.
    #    once we have this, we can also initialize the process in madgraph
    #
    # -- param_card.dat, this is mostly invariant, but does depend on the model scenario
    #
    # -- run_card.dat, this is also mostly invariant
    #
    # At that point we can generate the events, arrange the output, and cleanup.
    # -----------------------------------------------------------------------
    
    # -----------------------------------------------------------------------
    # proc card
    #
    # first, figure out what process we should run
    processes=[]
    pythiachans=[]
    if gentype == "WW" or gentype == "ww":
        if decaytype == "lvlv" or decaytype == "llvv":
            processes.append("p p > hh, (hh > w+ w-, w+ > l+ vl, w- > l- vl~)")
        elif decaytype == "jjjj" or decaytype == "qqqq":
            processes.append("p p > hh, (hh > w+ w-, w+ > j j, w- > j j)")
        elif decaytype == "lvqq" or decaytype == "lvjj":
            processes.append("p p > hh, (hh > w+ w-, w+ > j j, w- > l- vl~)")
            processes.append("p p > hh, (hh > w+ w-, w- > j j, w+ > l+ vl)")
        else:
            mglog.error('Could not configure process for %s > %s' % (gentype, decaytype))
            return -1,pythiachans

    elif gentype == "ZZ" or gentype == "zz":
        if decaytype == "llll":
            processes.append("p p > hh, (hh > z z, z > l+ l-, z > l- l+)")
        elif decaytype == "llvv" or gentype == "vvll":
            processes.append("p p > hh, (hh > z z, z > l+ l-, z > vl vl~)")
        elif decaytype == "jjjj" or decaytype == "qqqq":
            processes.append("p p > hh, (hh > z z, z > j j, z > j j)")
        elif decaytype == "llqq" or decaytype == "lljj":
            processes.append("p p > hh, (hh > z z, z > j j, z > l- l+)")
        elif decaytype == "vvqq" or decaytype == "vvjj" or decaytype == "qqvv" or decaytype == "jjvv":
            processes.append("p p > hh, (hh > z z, z > j j, z > vl vl~)")
        else:
            mglog.error('Could not configure process for %s > %s' % (gentype, decaytype))
            return -1,pythiachans

    elif gentype == "HH" or gentype == "hh":
        processes.append("p p > hh, (hh > h h)")

        # let pythia decay the Higgs' to get the right BR's
        if decaytype == "qqqq" or decaytype == "jjjj":
            pythiachans.append("25:oneChannel = on 0.569 100 5 -5 ")
            pythiachans.append("25:addChannel = on 0.0287 100 4 -4 ")
        elif decaytype == "bbbb":
            pythiachans.append("25:oneChannel = on 0.569 100 5 -5 ")
        else:
            mglog.error('Could not configure process for %s > %s' % (gentype, decaytype))
            return -1,pythischans

    else:
        mglog.error('Could not configure process for %s > %s' % (gentype, decaytype))
        return -1,pythiachans
            

    # Now, import the template.  Could have just written this whole thing out in the
    # script, but a template is nicer for people perusing SVN.
    proccard = subprocess.Popen(['get_files','-data','MadGraph_proc_card_BulkRS.dat'])
    proccard.wait()
    
    # Figure out how to modify the template.
    processstring=""
    processcount=1
    for i in processes:
        if processstring=="":
            processstring="generate %s QED=99 QCD=99 @%d " % (i, processcount)
        else:
            processstring+="\nadd process %s QED=99 QCD=99 @%d " % (i, processcount)
        processcount+=1

    calcwidthstring="""
generate hh > all all
output SMRS_widths -f
launch
set c %f
set Mh %f
set MH %f
set Mhh %f
""" % (float(scenario[1:])/10., 125., 125., float(mass))

    # check that we're in a clean directory
    if not os.access('MadGraph_proc_card_BulkRS.dat',os.R_OK):
        mglog.error('Could not retrieve process card template')
        return -1,pythiachans
    if os.access('proc_card_mg5.dat',os.R_OK) or os.access('proc_card_mg5_step1.dat',os.R_OK):
        mglog.error('Old process card in the current directory.  Do not want to clobber it.  Please move it first.')
        return -1,pythiachans

    # now, modify the process cards.  note that we need two here: one that will 
    oldcard = open('MadGraph_proc_card_BulkRS.dat','r')
    newcardgen = open('proc_card_mg5.dat','w')
    newcardwidths = open('proc_card_mg5_step1.dat','w')
    for line in oldcard.readlines():
        if 'generate' in line: 
            newcardgen.write(processstring)
            newcardwidths.write(calcwidthstring)
        elif "output -f" in line:
            newcardgen.write(line)
        else: 
            newcardgen.write(line)
            newcardwidths.write(line)
    oldcard.close()
    newcardgen.close()
    newcardwidths.close()
    # -----------------------------------------------------------------------


    # -----------------------------------------------------------------------
    # run card
    extras={}
    extras["scale"] = mass
    extras["dsqrt_q2fact1"] = mass
    extras["dsqrt_q2fact2"] = mass
    extras["pdlabel"]=pdf
    extras["lhaid"]=lhaid
    build_run_card(run_card_old='MadGraph_run_card_BulkRS.dat',
                   run_card_new='run_card.dat',
                   xqcut=0,
                   nevts=nevts,
                   rand_seed=rand_seed,
                   beamEnergy=beamEnergy, 
                   scalefact=scalevariation, 
                   alpsfact=alpsfact,
                   extras=extras)
    # -----------------------------------------------------------------------


    # -----------------------------------------------------------------------
    # param card needs to be built with correct widths
    process_dir = new_process(card_loc='proc_card_mg5_step1.dat')
    print "printing process dir"
    print process_dir
    print "printed process dir"
    generate(run_card_loc='run_card.dat', 
             param_card_loc=None, 
             mode=0, 
             njobs=1, 
             run_name='run_01', 
             proc_dir=process_dir)
    str_param_card='SMRS_widths/Events/run_01/param_card.dat'
    # -----------------------------------------------------------------------

    # -----------------------------------------------------------------------
    # Now configure the generation process directory/etc
    thedir = new_process(card_loc='proc_card_mg5.dat')
    if 1==thedir:
        mglog.error('Error in process generation!')
        return -1,pythiachans
    
    # See if things are where we expected them to be...
    if not os.access(thedir,os.R_OK):
        mglog.error('Could not find process directory '+thedir+' !!  Bailing out!!')
        return -1,pythiachans
    else:
        mglog.info('Using process directory '+thedir)
    # -----------------------------------------------------------------------

    # -----------------------------------------------------------------------
    # Generation
    if generate(run_card_loc='run_card.dat',
                param_card_loc=str_param_card,
                mode=0,
                njobs=1,
                run_name='Test',
                proc_dir=thedir,
                grid_pack=False):
        mglog.error('Error generating events!')
        return -1,pythiachans
    # -----------------------------------------------------------------------

    # -----------------------------------------------------------------------
    # Cleanup
    outputDS=""
    try:
        outputDS=arrange_output(run_name='Test',
                                proc_dir=thedir,
                                outputDS='madgraph.%i.madgraph_BulkRS_%s_%s_%s_%s._00001.events.tar.gz'%(run_number,scenario,gentype,decaytype,stringy))
    except:
        mglog.error('Error arranging output dataset!')
        return -1,pythiachans

    keepOutput=True
    if not keepOutput:
        mglog.info('Removing process directory...')
        shutil.rmtree(thedir,ignore_errors=True)

    mglog.info('All done generating events!!')
    return outputDS,pythiachans