#!/bin/bash 
mkdir -p /home/xdaq/ltdata/plots
firstrec=MODULLTFIRST
coldrec=MODULLTCOLD	
lastrec=MODULLTLAST
name=`realpath ${1}`
rootdir=`dirname $name`
filename=`basename $name`
rootname=`basename $name .root`
plotsdir=/home/xdaq/ltdata/plots/${rootname}
mkdir -p ${plotsdir}
temp=/tmp/${rootname}_FIRST.dat
echo Creating RootInfoFile ${temp} for ${1}
cat <<! >${temp}
RootFileInfo
${rootdir}
${filename}
${plotsdir}
${firstrec}
#
PedestalCuts
Percentage
PeakOn
0.5
0.5
DecOn
0.5
0.5
#
NoiseCuts
Relative
PeakOn
1.0
0.5
0.25
0.5
DecOn
1.0
0.5
0.25
0.5
#
PeakTimeCuts
Absolute
PeakOn
-30.0
-12.0
-6.0
10.0
DecOn
-30.0
-4.0
-2.1
10.0
#
GainCuts
Percentage
PeakOn
100
0.20
0.20
100
DecOn
100
0.20
0.20
100
#
PinholeCuts
Absolute
PeakOn
15.0
40.0
DecOn
15.0
40.0
#
PulseHeightCuts
Percentage
PeakOn
0.25
0.25
DecOn
0.25
0.25
#
!
echo Running root -b -l -q \'LT.cc\(\"$temp\",\"MODLTFIRST\",0,0\)\'
date=`date +%s`
echo root -b -l -q \'LT.cc\(\"$temp\",\"MODLTFIRST\",0,0\)\' >/tmp/${date}.bash
chmod +x /tmp/${date}.bash
/tmp/${date}.bash
mv ${temp} ${plotsdir}
rm /tmp/${date}.bash

temp=${rootname}_COLD.dat
echo Creating RootInfoFile ${temp} for ${1}
cat <<! >${temp}
RootFileInfo
${rootdir}
${1}
${plotsdir}
${coldrec}
#
PedestalCuts
Percentage
PeakOn
0.5
0.5
DecOn
0.5
0.5
#
NoiseCuts
Relative
PeakOn
1.0
0.5
0.25
0.5
DecOn
1.0
0.5
0.25
0.5
#
PeakTimeCuts
Absolute
PeakOn
-30.0
-12.0
-6.0
10.0
DecOn
-30.0
-4.0
-2.1
10.0
#
GainCuts
Percentage
PeakOn
100
0.20
0.20
100
DecOn
100
0.20
0.20
100
#
PinholeCuts
Absolute
PeakOn
15.0
40.0
DecOn
15.0
40.0
#
PulseHeightCuts
Percentage
PeakOn
0.25
0.25
DecOn
0.25
0.25
#
!
echo Running root -b -l -q \'LT.cc\(\"$temp\",\"MODLTCOLD\",0,0\)\'
date=`date +%s`
echo root -b -l -q \'LT.cc\(\"$temp\",\"MODLTCOLD\",0,0\)\' >/tmp/${date}.bash
chmod +x /tmp/${date}.bash
/tmp/${date}.bash
mv ${temp} ${plotsdir}
rm /tmp/${date}.bash

temp=${rootname}_LAST.dat
echo Creating RootInfoFile ${temp} for ${1}
cat <<! >${temp}
RootFileInfo
${rootdir}
${1}
${plotsdir}
${lastrec}
#
PedestalCuts
Percentage
PeakOn
0.5
0.5
DecOn
0.50
0.50
#
NoiseCuts
Relative
PeakOn
1.0
0.5
0.25
0.5
DecOn
1.0
0.5
0.25
0.5
#
PeakTimeCuts
Absolute
PeakOn
-30.0
-12.0
-6.0
10.0
DecOn
-30.0
-4.0
-2.1
10.0
#
GainCuts
Percentage
PeakOn
100
0.20
0.20
100
DecOn
100
0.20
0.20
100
#
PinholeCuts
Absolute
PeakOn
15.0
40.0
DecOn
15.0
40.0
#
PulseHeightCuts
Percentage
PeakOn
0.25
0.25
DecOn
0.250
0.250
#
!
echo Running root -b -l -q \'LT.cc\(\"$temp\",\"MODLTLAST\",0,0\)\'
date=`date +%s`
echo root -b -l -q \'LT.cc\(\"$temp\",\"MODLTLAST\",0,0\)\' >/tmp/${date}.bash
chmod +x /tmp/${date}.bash
/tmp/${date}.bash
mv ${temp} ${plotsdir}
rm /tmp/${date}.bash
