#!/bin/sh

# HistFactory workplace setup script

ROOTETCDIR=`root -b -q -l -n -e "std::cout << TROOT::GetEtcDir() << std::endl;" | tail -1`
echo "Using etcdir "$ROOTETCDIR
ROOTTUTDIR=`root -b -q -l -n -e "std::cout << TROOT::GetTutorialDir() << std::endl;" | tail -1`
echo "Using tutorials dir" $ROOTTUTDIR 

if [ $# -eq 1 ]
then
  DIR=$1
  echo "HistFactory workplace will be created in: " $DIR
else
  DIR=.
  echo "HistFactory workplace will be created in the current directory"
fi

echo "Creating directory structure..."
mkdir -p $DIR/config
mkdir -p $DIR/config/examples
mkdir -p $DIR/data
mkdir -p $DIR/results

echo "Copying skeleton configuration files..."
cp $ROOTETCDIR/HistFactorySchema.dtd $DIR/config/
cp $ROOTTUTDIR/histfactory/example.xml $DIR/config/
cp $ROOTTUTDIR/histfactory/example_channel.xml $DIR/config/

cp $ROOTETCDIR/HistFactorySchema.dtd $DIR/config/examples
cp $ROOTTUTDIR/histfactory/example_Expression.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_Expression_channel.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_ShapeSys.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_ShapeSys_channel.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_ShapeSys2D.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_ShapeSys2D_channel.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_DataDriven.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_DataDriven_signalRegion.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_DataDriven_controlRegion.xml $DIR/config/examples/


#echo "Making skeleton data files..."
root -b -q $ROOTTUTDIR/histfactory/makeExample.C
mv ShapeSys.root ShapeSys2D.root StatError.root  dataDriven.root example.root $DIR/data

echo "Done!"
#echo "You can run the example with: hist2workspace $DIR/config/example.xml"

exit
