ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Angles/script/trainAngles.sh
Revision: 1.2
Committed: Thu Jan 24 08:46:00 2013 UTC (12 years, 3 months ago) by dkralph
Content type: application/x-sh
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +71 -93 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #!/bin/bash
2 alias grep='grep --color=auto'
3 label=$1
4 echo "Training $label ----------------------------------------------------------------------------------------"
5 # boolean parameters:
6 if ! [ $label ]; then echo "no label!"; exit 1; fi
7 if echo "$@" | grep ' \-\-interpolate' &>/dev/null; then interpolate=interpolate; echo "interpolate : $interpolate "; else interpolate=; fi
8 if echo "$@" | grep ' \-\-delete' &>/dev/null; then delete=delete; echo "delete : $delete "; else delete=; fi
9 if echo "$@" | grep ' \-\-fakes' &>/dev/null; then fakes=fakes; echo "fakes : $fakes "; else fakes=; fi # include fakes in training
10 if echo "$@" | grep ' \-\-ptvars' &>/dev/null; then ptvars=ptvars; echo "ptvars : $ptvars "; else ptvars=; fi
11 if echo "$@" | grep ' \-\-multiclass' &>/dev/null; then multiclass=multiclass; echo "multiclass : $multiclass "; else multiclass=; fi # set multiclass flag in trainAngles.cc
12 if echo "$@" | grep ' \-\-multisigs' &>/dev/null; then multisigs=multisigs; echo "multisigs : $multisigs "; else multisigs=; fi
13 if echo "$@" | grep ' \-\-noFakeTest' &>/dev/null; then noFakeTest=noFakeTest; echo "noFakeTest : $noFakeTest "; else noFakeTest=; fi # use the whole fake sample for training
14 if echo "$@" | grep ' \-\-condor' &>/dev/null; then condor=condor; echo "condor : $condor "; else condor=; fi
15 if echo "$@" | grep ' \-\-pt4l' &>/dev/null; then pt4l=pt4l; echo "pt4l : $pt4l "; else pt4l=; fi
16 if echo "$@" | grep ' \-\-m4l' &>/dev/null; then m4l=m4l; echo "m4l : $m4l "; else m4l=; fi
17 if echo "$@" | grep ' \-\-jets' &>/dev/null; then jets=jets; echo "jets : $jets "; else jets=; fi # jet variables
18 if echo "$@" | grep ' \-\-spinBDT' &>/dev/null; then spinBDT=spinBDT; echo "spinBDT : $spinBDT "; else spinBDT=; fi
19 if echo "$@" | grep ' \-\-fakeClass' &>/dev/null; then fakeClass=fakeClass; echo "fakeClass : $fakeClass "; else fakeClass=; fi # separate class for fakes
20 if echo "$@" | grep ' \-\-vbfClass' &>/dev/null; then vbfClass=vbfClass; echo "vbfClass : $vbfClass "; else vbfClass=; fi # separate class for vbf
21 if echo "$@" | grep ' \-\-wInterf' &>/dev/null; then wInterf=wInterf; echo "wInterf : $wInterf "; else wInterf=; fi # apply lepton interference weights
22 if echo "$@" | grep ' \-\-twoClassVbf' &>/dev/null; then twoClassVbf=twoClassVbf; echo "twoClassVbf : $twoClassVbf "; else twoClassVbf=; fi
23 if [ $fakeClass ] || [ $vbfClass ]; then if ! [ $multiclass ]; then echo "need to set multiclass!"; exit 1; fi; fi
24 # parameters with args:
25 window=`echo $@ | sed 's/[ ][ ]*/\n/g' | grep -A1 '\-\-window' | grep -v "\-\-window"`; if ! [ $window ]; then window=1; fi
26 NTrees=`echo $@ | sed 's/[ ][ ]*/\n/g' | grep -A1 '\-\-NTrees' | grep -v "\-\-NTrees"`
27 NNodesMax=`echo $@ | sed 's/[ ][ ]*/\n/g' | grep -A1 '\-\-NNodesMax' | grep -v "\-\-NNodesMax"`
28 Shrinkage=`echo $@ | sed 's/[ ][ ]*/\n/g' | grep -A1 '\-\-Shrinkage' | grep -v "\-\-Shrinkage"`
29 nCuts=`echo $@ | sed 's/[ ][ ]*/\n/g' | grep -A1 '\-\-nCuts' | grep -v "\-\-nCuts"`
30 NormMode=`echo $@ | sed 's/[ ][ ]*/\n/g' | grep -A1 '\-\-NormMode' | grep -v "\-\-NormMode"`
31 nMax=`echo $@ | sed 's/[ ][ ]*/\n/g' | grep -A1 '\-\-nMax' | grep -v "\-\-nMax"`
32 fakeSet=`echo $@ | sed 's/[ ][ ]*/\n/g' | grep -A1 '\-\-fakeSet' | grep -v "\-\-fakeSet"`;if ! [ $fakeSet ]; then fakeSet=fakes-histat-withMC; fi # which fake sample to use
33
34 if echo $label | grep 2011 &>/dev/null; then era2011=era2011; else era2011=; fi
35 mHfile=Angles/data/one-mH.conf
36
37 exe=$PWD/Angles/bin/trainAngles.exe
38 #inputdir=/scratch/dkralph/MitHzz4l_028/Selection/root/$resultLabel
39 inputdir=/afs/cern.ch/work/d/dkralph/MitHzz4l/Selection/root
40 #outputdir=/scratch/dkralph/MitHzz4l_028/Angles/root/training/$label
41 outputdir=/afs/cern.ch/work/d/dkralph/MitHzz4l/Angles/root/training/$label
42
43 while read line; do
44 if echo $line | grep '^#' &> /dev/null; then continue; fi
45 if echo $line | grep '^\^' &> /dev/null; then continue; fi
46
47 # skip the samples that don't exist if we're interpolating...
48 haveMCdkr=`echo $line | awk '{print $8}'`
49 if [ "$haveMCdkr" == "0" ] && ! [ $interpolate ]; then continue; fi
50
51 mH=`echo $line | awk '{print $3}'`
52 # if [ "$mH" != "125" ]; then continue; fi
53 echo $mH
54 # set low and high values of mass window
55 if (( window == 0 )); then
56 wL=0
57 wH=1000
58 elif (( window == 1 )); then
59 wL=`echo $line | awk '{print $4}'`
60 wH=`echo $line | awk '{print $5}'`
61 elif (( window == 2 )); then
62 wL=`echo $line | awk '{print $11}'`
63 wH=`echo $line | awk '{print $12}'`
64 elif (( window == 3 )); then
65 wL=`echo $line | awk '{print $13}'`
66 wH=`echo $line | awk '{print $14}'`
67 fi
68
69 # take events from these two masses to interpolate
70 mH_lo_dkr=`echo $line | awk '{print $9}'`
71 mH_hi_dkr=`echo $line | awk '{print $10}'`
72
73 config=$PWD/Angles/data/tmp/trainAngles-$label-$mH-$mH_lo_dkr-$mH_hi_dkr.config
74
75 rm -f $config
76 if [ $NTrees ]; then echo "^NTrees $NTrees" >> $config; fi
77 if [ $NNodesMax ]; then echo "^NNodesMax $NNodesMax" >> $config; fi
78 if [ $Shrinkage ]; then echo "^Shrinkage $Shrinkage" >> $config; fi
79 if [ $nCuts ]; then echo "^nCuts $nCuts" >> $config; fi
80 if [ $nMax ]; then echo "^nMax $nMax" >> $config; fi
81 if [ $NormMode ]; then echo "^NormMode $NormMode" >> $config; fi
82 echo "^inputdir $inputdir" >> $config # not used at the moment...
83 if [ $multiclass ]; then echo "^multiclass multiclass" >> $config; fi
84 if [ $noFakeTest ]; then echo "^noFakeTest noFakeTest" >> $config; fi
85 if [ $multisigs ]; then echo "^multisigs multisigs" >> $config; fi
86 if [ $wInterf ]; then echo "^useMela useMela" >> $config; fi # need a mela instance to get the interference weights
87 if [ $spinBDT ]; then
88 if (( mH != 126 )); then "skipping this mass"; continue; fi
89 echo "Signal 0m 1 1 $inputdir/mergd-jetangles s12-x${mH}zz4l-0m-pu-dkr $mH mc" >> $config
90 echo "Background 0p 1 1 $inputdir/mergd-jetangles s12-x${mH}zz4l-0p-pu-dkr $mH mc" >> $config
91 # echo "sig3 1 $inputdir/s12-x125zz4l-2p-v9/merged.root $mH" >> $config
92 # elif [ $interpolate ] && [ "$haveMCdkr" == "0" ]; then
93 # echo " interpolating with: $mH_lo_dkr $mH_hi_dkr"
94 # test=`echo "($wL < $mH_lo_dkr - 4) || ( $wH > $mH_hi_dkr + 4 )" | bc -l`
95 # if [ "$test" == "0" ]; then echo -e "\nmass window ($wL,$wH) too narrow for this interpolation!\n"; exit 1; fi
96 # echo "Signal -1 $inputdir/$sigStrFirst${mH_lo_dkr}$sigStrSecond/merged.root $mH_lo_dkr" >> $config
97 # echo "Signal -1 $inputdir/$sigStrFirst${mH_hi_dkr}$sigStrSecond/merged.root $mH_hi_dkr" >> $config
98 else
99 # note: file fracs are the yields for 12/fb in the mH=126 GeV data cards
100 if [ $wInterf ]; then
101 echo "Signal gfH 9.6 wInterf $inputdir/jetangles s12-h${mH}zz4l-gf-pu-dkr $mH mc" >> $config
102 else
103 echo "Signal gfH 9.6 1 $inputdir/jetangles s12-h${mH}zz4l-gf-pu-dkr $mH mc" >> $config
104 fi
105 if [ $vbfClass ]; then
106 echo "Signal2 vbfH 0.88 1 $inputdir/jetangles s12-h${mH}-vbf-pu-dkr $mH mc" >> $config
107 # echo "Signal2 vttH 1 $inputdir/jetangles s12-h${mH}-vbf-pu-dkr $mH mc" >> $config
108 elif [ $twoClassVbf ]; then
109 echo "Background vbfH 0.88 1 $inputdir/jetangles s12-h${mH}-vbf-pu-dkr $mH mc" >> $config
110 fi
111 mH_lo_dkr=0
112 mH_hi_dkr=0
113 if ! [ $twoClassVbf ]; then
114 echo "Background qqZZ 1.7 1 $inputdir/jetangles s12-zz4e-pu-dkr -1 mc" >> $config
115 echo "Background qqZZ 5.4 1 $inputdir/jetangles s12-zz4m-pu-dkr -1 mc" >> $config
116 echo "Background qqZZ 5.6 1 $inputdir/jetangles s12-zz2e2m-pu-dkr -1 mc" >> $config
117 fi
118 if [ $fakes ]; then
119 if [ $fakeClass ]; then class=Background2; else class=Background; fi
120 echo "$class lljj 4.4 w $inputdir/fixfsr $fakeSet -1 data" >> $config
121 fi
122 fi
123
124 varstring=costheta1:costheta2:costhetastar:Phi:Phi1:mZ1:mZ2
125 # varstring=costheta1:costheta2:costhetastar:Phi:Phi1:mZ1:mZ2:pt4l:y4l:Z1pt:Z2pt:zzdotz1:zzdotz2:dphi1:dphi2
126 # varstring="$varstring:ZZpt/m4l:ZZy:Z1pt/m4l:Z2pt/m4l:ZZdotZ1/(m4l*mZ1):ZZdotZ2/(m4l*mZ2):ZZptCosDphiZ1pt:ZZptCosDphiZ2pt"
127 if [ $ptvars ]; then varstring="$varstring:ZZpt:ZZy:Z1pt:Z2pt:ZZdotZ1:ZZdotZ2:ZZptCosDphiZ1pt:ZZptCosDphiZ2pt"; fi
128 # if [ $jets ]; then varstring="$varstring:nJets:mjj:dEta:etaProd:dphiJ1HiPtZ:dphiJ1LoPtZ:dEtaJ1HiPtZ:dEtaJ1LoPtZ:J1dotHiPtZ:J1dotLoPtZ:dphiJ2HiPtZ:dphiJ2LoPtZ:dEtaJ2HiPtZ:dEtaJ2LoPtZ:J2dotHiPtZ:J2dotLoPtZ"; fi
129 #
130 # no NJETS!!!!! (was constant in the ntuples for some reason
131 #
132 if [ $jets ]; then varstring="$varstring:mjj:dEta:etaProd:dphiJ1HiPtZ:dphiJ1LoPtZ:dEtaJ1HiPtZ:dEtaJ1LoPtZ:J1dotHiPtZ:J1dotLoPtZ:dphiJ2HiPtZ:dphiJ2LoPtZ:dEtaJ2HiPtZ:dEtaJ2LoPtZ:J2dotHiPtZ:J2dotLoPtZ"; fi
133
134 mkdir -p $outputdir/logs
135 outputfile=$outputdir/hzz4lBDT.${mH}.root
136 weightfile=$outputdir/weights/hzz4l_mH${mH}_BDTG.weights.xml
137 if [ $delete ]; then rm -vf $outputfile $weightfile; fi
138 if [ -s $outputfile ] && [ -s $weightfile ]; then echo " already there..."; continue; fi
139 args="$exe $config $outputfile hzz4l_mH${mH} $varstring ${mH} ${wL} ${wH} $mH_lo_dkr $mH_hi_dkr"
140 if [ $condor ]; then
141 ./scripts/submit.sh $args --output $outputfile
142 else
143 cd $outputdir
144 $args &> $outputdir/logs/hzz4lBDT.${mH}.txt &
145 cd $OLDPWD
146 fi
147
148 sleep 0.2
149 limit_procs `basename $exe`
150
151 done < $mHfile
152
153 #while ps | grep `basename $exe | sed 's/\([a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]\).*/\1/'` &> /dev/null; do
154 # echo "still running... "
155 # sleep 0.5
156 #done
157
158 #mkdir -p ./Angles/root/training/$label/weights/
159 #mv -v ./weights/* ./Angles/root/training/$label/weights/