#!/bin/sh
export SCRAM_ARCH=slc4_ia32_gcc345
export BUILD_ARCH=slc4_ia32_gcc345
export VDT_LOCATION=/OSG
source $VDT_LOCATION/setup.sh
mkdir -p alpgen_prod
cd alpgen_prod
TOP=$PWD
if [ $? == 1 ] ; then
    voms-proxy-init -voms cms:/cms/uscms
fi
export X509_USER_PROXY=$(voms-proxy-info -path)
# define versions
project=CMSSW
version=2_2_9
# set up a CMSSW area
export SW_DIR=/home/OSG_app/app/cmssoft/cms
source $SW_DIR/cmsset_default.sh ${project}_${version}
scramv1 project $project ${project}_${version}
cd ${project}_${version}/src
eval `scramv1 runtime -sh`
#get grids from cvs
export CVSROOT=:ext:mafd@cmscvs.cern.ch:/cvs_server/repositories/CMSSW
export CVS_RSH=/usr/bin/ssh
cvs co -r ${project}_${version}  GeneratorInterface/AlpgenInterface
#write your input form
input_file=input
cat >> $input_file << EOF
1          ! generation mode
ttbar4j_40 ! string labeling the output files
0          ! start with: 0=new grid, 1=previous warmup grid, 2=previous generation grid
0 0        ! N(events)/iteration and N(iter's) for initial grid optimiz. Use 0 0 if starting from existing grid
50000000   ! number evts to generate
*** The above 5 lines provide mandatory inputs for all processes
*** (Comment lines are introduced by the three asteriscs)
*** The lines below modify existing defaults for the hard process under study
*** For a complete list of accessible parameters and their values,
*** input 'print 1' (to display on the screen) or 'print 2' to write to file
njets 4
ebeam 5000
ih2 1
ickkw 1
ptjmin 40
etajmax 5
drjmin 0.7
mt 175
ihvy 6
itdecmode 7
EOF
#setup your alpgen version
alpversion=213-cms2
alpgen_exec=$CMS_PATH/$SCRAM_ARCH/external/alpgen/$alpversion/bin/2Qgen
#setup which grid we will use
alpgen_grid=GeneratorInterface/AlpgenInterface/data/ttbar4j_40GeV.grid2
#Making it executable
wget http://www.sprace.org.br/Twiki/pub//Main/AlpgenTimeAndSizeStudies/sprace_ALPGEN_submit.py.txt -O sprace_ALPGEN_submit.py
python sprace_ALPGEN_submit.py $input_file $alpgen_exec $alpgen_grid