#!/bin/bash
#
#  This runs MadAnalysis on the unweighted_events.lhe
#
#  Usage: run_plot run_name [madir [tddir]]
#  where madir is the path to the MadAnalysis package

main=`pwd`

if [ "$1" != "" ]
then
  run=$1
else
  echo "Usage: run_plot runname [MAdir [tddir]]"
  exit
fi

if [ "$2" != "" ]
then
  MAdir=$main/$2
else
  MAdir=$main/../../MadAnalysis
fi

if [ "$3" != "" ]; then
  td=$main/$3
else
  td=$main/../../td
fi

dirbin=$main/../bin

if [[ $run != "" && -e ${run}_pgs_events.lhco.gz ]];then
    gunzip -c ${run}_pgs_events.lhco.gz > pgs_events.lhco
fi

if [[ (-x $MAdir/plot_events) && (-e pgs_events.lhco) && (-e ../Cards/plot_card.dat) ]]; then
    echo "Creating Plots"
    mkdir ${run}_pgs
    cd ${run}_pgs
    echo "../pgs_events.lhco" > events.list
    $dirbin/plot $MAdir $td > plot.log
    cd ..
    $dirbin/plot_page-pl ${run}_pgs PGS
    mv plots.html ${run}_plots_pgs.html
fi

