TrainMVA.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 SIGFILES=''
4 BKGFILES=''
5 JOBNAME=''
6 
7 while getopts "s:b:j:" opt; do
8  case $opt in
9  s)
10  SIGFILES="$SIGFILES $OPTARG"
11  ;;
12  b)
13  BKGFILES="$BKGFILES $OPTARG"
14  ;;
15  j)
16  JOBNAME=$OPTARG
17  ;;
18  \?)
19  echo "Invalid option: -$OPTARG" >&2
20  exit 1
21  ;;
22  :)
23  echo "Option -$OPTARG requires an argument." >&2
24  exit 1
25  ;;
26  esac
27 done
28 
29 echo "Signal files are:"
30 for i in $SIGFILES;do echo $i;done
31 echo "Background files are:"
32 for i in $BKGFILES;do echo $i;done
33 echo "Job name is $JOBNAME"
34 
35 #Hmm, when using mrb then $LARANA_DIR points to source tree, but
36 #in installed version then need to add source to path
37 if [ -d $LARANA_DIR/source ]; then
38  cp $LARANA_DIR/source/ParticleIdentification/scripts/TrainMVA.C ./
39  cp $LARANA_DIR/source/ParticleIdentification/scripts/runPID_noMVA.fcl ./
40 else
41  cp $LARANA_DIR/ParticleIdentification/scripts/TrainMVA.C ./
42  cp $LARANA_DIR/ParticleIdentification/scripts/runPID_noMVA.fcl ./
43 fi
44 
45 if [ -d $LARDATA_DIR/source ]; then
46  cp $LARDATA_DIR/source/AnalysisBase/MVAPIDResult.h ./
47 else
48  cp $LARDATA_DIR/AnalysisBase/MVAPIDResult.h ./
49 fi
50 
51 
52 ##Build CINT dictionary for the MVAResult class
53 echo '
54 #pragma link C++ class anab::MVAPIDResult+;
55 #pragma link C++ class vector<anab::MVAPIDResult>+;
56 #pragma link C++ class map<string,double>+;
57 ' > Linkdef.h
58 
59 rootcint -f MVAResultDict.cxx -c $LARDATA_DIR/AnalysisBase/MVAPIDResult.h Linkdef.h
60 g++ -shared -o MVAResultDict.so `root-config --ldflags` -fPIC -I$ROOTSYS/include MVAResultDict.cxx
61 rm -f MVAResultDict.cxx MVAResultDict.h Linkdef.h
62 
63 ROOTSCRIPT=`mktemp`
64 echo "
65 {
66 gROOT->ProcessLine(\"gSystem->Load(\\\"MVAResultDict.so\\\")\");
67 gROOT->ProcessLine(\".L TrainMVA.C\");
68 std::vector<std::string> sigFiles, bkgFiles;" > $ROOTSCRIPT
69 
70 for i in $SIGFILES
71 do
72 lar -c ./runPID_noMVA.fcl -s $i -n 100000
73 TUPLEFILE=ntuple_`basename $i`
74 mv ntuple.root $TUPLEFILE
75 echo "
76 BuildTree(\"${TUPLEFILE}\",\"train_"`basename $i`"\");
77 sigFiles.push_back(\"train_"`basename $i`"\");" >> $ROOTSCRIPT
78 done
79 
80 for i in $BKGFILES
81 do
82 mv ntuple.root ntuple_$i
83 lar -c ./runPID_noMVA.fcl -s $i -n 100000
84 TUPLEFILE=ntuple_`basename $i`
85 mv ntuple.root $TUPLEFILE
86 echo "
87 BuildTree(\"${TUPLEFILE}\",\"train_"`basename $i`"\");
88 bkgFiles.push_back(\"train_"`basename $i`"\");" >> $ROOTSCRIPT
89 done
90 
91 echo "
92 TrainMVA(sigFiles,bkgFiles,\"mvaPlots.root\",\"$JOBNAME\");
93 }
94 " >> $ROOTSCRIPT
95 
96 cat $ROOTSCRIPT
97 
98 root -l -b -q $ROOTSCRIPT