1 | NICE="nice -n10"
|
---|
2 | RANGER=~/SW/ranger/build/ranger
|
---|
3 | ROOT2CSV=~/SW/FACT++/build/root2csv
|
---|
4 | CSV2ROOT=~/SW/FACT++/build/csv2root
|
---|
5 | OUT=ranger.csv
|
---|
6 | TRAINRATIO=0.7
|
---|
7 |
|
---|
8 | TRUEVAR="log10(Energy)"
|
---|
9 | #TRUEVAR="Phi*TMath::RadToDeg()"
|
---|
10 | #TRUEVAR="Theta*TMath::RadToDeg()"
|
---|
11 | #TRUEVAR="MeanX*conv"
|
---|
12 | #TRUEVAR="MeanY*conv"
|
---|
13 |
|
---|
14 | echo --------------------------------- Creating input files -------------------------
|
---|
15 |
|
---|
16 | cat > ${OUT}.rc <<EOF
|
---|
17 | # Do some magic to simplify the leaf names
|
---|
18 | auto-alias=MHillas.f/
|
---|
19 | auto-alias=MHillasSrc.f/
|
---|
20 | auto-alias=MHillasExt.f/
|
---|
21 | auto-alias=MNewImagePar.f/
|
---|
22 | auto-alias=MMcEvt.MMcEvtBasic.f/
|
---|
23 |
|
---|
24 | # Some cuts to remove events with strange contents
|
---|
25 | selector=NumUsedPixels>2.5 && lgArea>-1 && abs(SlopeTrans/conv)<1
|
---|
26 |
|
---|
27 | # Define some alias for easier use and use in the selector
|
---|
28 | [alias]
|
---|
29 | conv=1.14112295210361481e-01
|
---|
30 | lgArea=log10(TMath::TwoPi()*Width*Length*conv^2)
|
---|
31 |
|
---|
32 | # Add additonal columns
|
---|
33 | [add]
|
---|
34 | lgSize = log10(Size)
|
---|
35 | lgArea = lgArea
|
---|
36 | WovL = Width/Length
|
---|
37 | Width = Width*conv
|
---|
38 | Length = Length*conv
|
---|
39 | Dist = Dist*conv
|
---|
40 | Delta = Delta
|
---|
41 | Angle = atan2(MeanX, MeanY)
|
---|
42 | M3L = M3Long*TMath::Sign(1, CosDeltaAlpha)*conv
|
---|
43 | M3T = M3Trans*conv
|
---|
44 | Asym = Asym*conv
|
---|
45 | Alpha = Alpha
|
---|
46 | Leakage1 = Leakage1
|
---|
47 | Leakage2 = Leakage2
|
---|
48 | Conc1 = Conc1
|
---|
49 | ConcCore = ConcCore
|
---|
50 | ConcCOG = ConcCOG
|
---|
51 | SlopeL = SlopeLong*TMath::Sign(1, CosDeltaAlpha)/conv
|
---|
52 | SlopeT = SlopeTrans/conv
|
---|
53 |
|
---|
54 | TimeSpread = TimeSpread
|
---|
55 | SlopeSpread = SlopeSpread
|
---|
56 |
|
---|
57 | CosDeltaAlpha = CosDeltaAlpha
|
---|
58 | NumUsedPixels = NumUsedPixels
|
---|
59 |
|
---|
60 | TimeSpreadWeighted = TimeSpreadWeighted
|
---|
61 | SlopeSpredWeighted = SlopeSpreadWeighted
|
---|
62 | EOF
|
---|
63 |
|
---|
64 | # Write files
|
---|
65 | ${NICE} ${ROOT2CSV} \
|
---|
66 | "~/SW/data/star/*_Events.root" -o ${OUT} --config ${OUT}.rc \
|
---|
67 | --force --header 1 --skip \
|
---|
68 | --split-quantile=${TRAINRATIO} \
|
---|
69 | --add.True=${TRUEVAR}
|
---|
70 |
|
---|
71 | if [ $? != 0 ]; then
|
---|
72 | exit
|
---|
73 | fi
|
---|
74 |
|
---|
75 | TRAIN=${OUT}-0
|
---|
76 | TEST=${OUT}-1
|
---|
77 |
|
---|
78 | # Training
|
---|
79 | echo ------------------------------------- Training ---------------------------------
|
---|
80 | ${NICE} ${RANGER} \
|
---|
81 | --file ${TRAIN} --outprefix ${OUT} --depvarname True \
|
---|
82 | --verbose --treetype 3 --impmeasure 1 --write
|
---|
83 |
|
---|
84 | echo ""
|
---|
85 | cat ${OUT}.importance | sed -E 's/([^:]*): (.*)/\2: \1/g' | LC_ALL=C sort -g -r
|
---|
86 | echo ""
|
---|
87 | #cat ${OUT}.confusion
|
---|
88 | #echo ""
|
---|
89 |
|
---|
90 | # Testing
|
---|
91 | echo ------------------------------------- Testing ----------------------------------
|
---|
92 | ${NICE} ${RANGER} \
|
---|
93 | --file ${TEST} --outprefix ${OUT} --predict ${OUT}.forest \
|
---|
94 | --verbose --treetype 3
|
---|
95 |
|
---|
96 | echo --------------------------------- Creating root file ---------------------------
|
---|
97 | ${NICE} ${CSV2ROOT} ${TEST} ${OUT}.root --force
|
---|
98 | if [ $? != 0 ]; then
|
---|
99 | exit
|
---|
100 | fi
|
---|
101 |
|
---|
102 | ${NICE} ${CSV2ROOT} ${OUT}.prediction ${OUT}.root --update
|
---|
103 | if [ $? != 0 ]; then
|
---|
104 | exit
|
---|
105 | fi
|
---|