#!/bin/sh
#
# Generation
#
seq=${1:-1}
#
output=vbf${seq}.pool.root
cat jobOptions.pythia.vbf-out.py |\
  sed s/vbf.pool.root/${output}/g >  \
  jobOptions.pythia.vbf-out${seq}.py
#
athena.py jobOptions.pythia.vbf-out${seq}.py > athena_gen${seq}.out 2>&1 
if [ ! -e ${output} ]; then
  echo "File ${output} not found: exit chain"
  exit
fi
#
# Simulation
# 
output=vbfg4hits${seq}.pool.root
cat  RomeSimulationConfig.py |\
  sed s/vbf.pool.root/vbf${seq}.pool.root/g |  \
  sed s/vbfg4hits.pool.root/${output}/g >  \
  RomeSimulationConfig${seq}.py
#
athena.py RomeSimulationConfig${seq}.py RomeGeo2G4.py > athena_sim${seq}.out 2>&1
if [ ! -e ${output} ]; then
  echo "File ${output} not found: exit chain"
  exit
fi
#
# Digitization
#
output=vbfg4digi${seq}.pool.root
cat  vbfDigiOptions.py |\
  sed s/vbfg4hits.pool.root/vbfg4hits${seq}.pool.root/g |  \
  sed s/vbfg4digi.pool.root/${output}/g >  \
  vbfDigiOptions${seq}.py
#
athena.py vbfDigiOptions${seq}.py Digitization/AtlasDigitization.py > athena_digi${seq}.out 2>&1
if [ ! -e ${output} ]; then
  echo "File ${output} not found: exit chain"
  exit
fi
#
# Reconstruction
#
output=vbfesd${seq}.pool.root
cat  vbfRecOptions.py |\
  sed s/vbfg4digi.pool.root/vbfg4digi${seq}.pool.root/g |  \
  sed s/vbfesd.pool.root/${output}/g >  \
  vbfRecOptions${seq}.py
#
athena.py vbfRecOptions${seq}.py RecExCommon_topOptions.py > athena_rec${seq}.out 2>&1
if [ ! -e ${output} ]; then
  echo "File ${output} not found: exit chain"
  exit
fi
#
# AOD
#
output=vbfaod${seq}.pool.root
cat  optESDtoAOD.py |\
  sed s/vbfesd.pool.root/vbfesd${seq}.pool.root/g |  \
  sed s/vbfaod.pool.root/${output}/g >  \
  optESDtoAOD${seq}.py
athena.py optESDtoAOD${seq}.py RecExCommon_topOptions.py > athena_aod${seq}.out 2>&1
if [ ! -e ${output} ]; then
  echo "File ${output} not found: exit chain"
  exit
fi
