set_environment () {
  echo "Setting environment..."
  
  # assume "x86_64-slc5-gcc43-opt" platform:
  LCG_PLATFORM=x86_64-slc5-gcc43-opt
  source /afs/cern.ch/sw/lcg/contrib/gcc/4.3/$LCG_PLATFORM/setup.sh
  
  MCGENERATORS=/afs/cern.ch/sw/lcg/external/MCGenerators
  MCGENERATORS_HEPMC206=/afs/cern.ch/sw/lcg/external/MCGenerators_hepmc20603
  local AGILE=$MCGENERATORS_HEPMC206/agile/1.3.0/$LCG_PLATFORM
  local RIVET=$MCGENERATORS_HEPMC206/rivet/1.6.0/$LCG_PLATFORM
  HEPMC=/afs/cern.ch/sw/lcg/external/HepMC/2.06.03/$LCG_PLATFORM
  local PYTHON=/afs/cern.ch/sw/lcg/external/Python/2.6.5/$LCG_PLATFORM
  
  export PYTHONPATH=$AGILE/lib/python2.6/site-packages:$RIVET/lib/python2.6/site-packages:$PYTHONPATH
  export LD_LIBRARY_PATH=$HEPMC/lib:$AGILE/lib:$RIVET/lib:$PYTHON/lib:$LD_LIBRARY_PATH
  export PATH=$PYTHON/bin:$RIVET/bin:$AGILE/bin:$PATH
  export AGILE_GEN_PATH=$MCGENERATORS
  export AGILE_PARAM_PATH=$(pwd)/configuration
  export RIVET_REF_PATH=$(rivet-config --datadir)
  
  echo "LCG_PLATFORM=$LCG_PLATFORM"
  echo "gcc version = $(gcc -dumpversion)"
  echo "AGILE=$AGILE"
  echo "RIVET=$RIVET"
  echo "HEPMC=$HEPMC"
  echo "AGILE_GEN_PATH=$AGILE_GEN_PATH"
  echo "AGILE_PARAM_PATH=$AGILE_PARAM_PATH"
  echo "RIVET_REF_PATH=$RIVET_REF_PATH"
  echo ""
}

set_environment

td=$(mktemp -d)

mkfifo $td/events.hepmc
agile-runmc Pythia6:425 --paramfile=z2.params --out=$td/events.hepmc &
rivet -a OPAL_2004_S6132243 -H S6132243.aida $td/events.hepmc
rm -rf $td

rivet-mkhtml -s S6132243.aida -o S6132243
 