#!/bin/bash

# setup paths and environment to run AGILE and Rivet
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.2.0/$LCG_PLATFORM
  local RIVET=$MCGENERATORS_HEPMC206/rivet/1.4.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.5/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

rm -rf p1 1.aida 1.hepmc

agile-runmc Pythia6:423 --paramfile=pythia6-mb.params --beam=pp:53 --nevts=100 --out=1.hepmc
rivet -a UA5_1982_S875503 -H 1.aida 1.hepmc
rivet-mkhtml -s 1.aida -o p1
