#!/bin/bash
#
# phonotree.sh - batch script for running a phonotree simulation
#
# usage: phonotree.sh <processId>
#          where <processId> is an unsigned negative integer less than 2^32
# author: richard.t.jones at uconn.edu
# version: february 4, 2017

if [[ $# -lt 1 ]]; then
    echo "Usage: phonotree.sh <processId> [<nevents>]"
    exit 9
fi

echo Running on `hostname -f`

BMS_OSNAME=Linux_CentOS6-x86_64-gcc4.9.2
ROOTSYS=/usr/local/root
source setup.sh

nevents=2500000
if [[ "$2" != "" ]]; then
    nevents=$2
fi

# This step just to compile the program
root -l loader.C -q

for n in a b c d; do
    echo "#include <TROOT.h>" > run${n}.C
    echo "void run${n}() {" > run${n}.C
    outfile='"phonotree_'${1}${n}'.root"' 
    echo "   generate($nevents, $outfile);" >> run${n}.C
    echo "}" >> run${n}.C
    root -l -b loader.C run${n}.C -q &
done
wait
rm run*.C
