Jpp test-rotations-old-533-g2bdbdb559
the software that should make you happy
Loading...
Searching...
No Matches
discovery.sh
Go to the documentation of this file.
1#!/bin/env zsh
2#
3# \author mdejong
4#
5version=1.0
6script=${0##*/}
7
8source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
9
10set_variable DEBUG 2
11set_variable: NUISANCE ASTRONOMY_NUISANCE fixed fixed
12set_variable: FORMAT GRAPHICS_FORMAT gif
13set_variable+ BATCH GRAPHICS_BATCH -B
14
15if do_usage $*; then
16 usage "$script <signal histogram> <background histogram> <number of tests> <probability>"\
17 "\nThe histograms correspond to \"<file name>:<histogram name>\"."
18fi
19
20if (( $# != 4 )); then
21 fatal "Wrong number of arguments."
22fi
23
24set_variable HS $argv[1]
25set_variable HB $argv[2]
26let "NUMBER_OF_TESTS = $argv[3]"
27let "PROBABILITY = $argv[4]"
28
29if (( $PROBABILITY <= 0.0 || $PROBABILITY >= 1.0 )); then
30 fatal "Invalid probability $PROBABILITY"
31fi
32
33if (( $NUMBER_OF_TESTS * $PROBABILITY <= 1.0 )); then
34 warning "Insufficient number of tests $NUMBER_OF_TESTS given probability $PROBABILITY."
35fi
36
37timer_start
38
39# pseudo experiments
40
41let "N = 0" # zero signal
42
43$JPP_DIR/examples/JAstronomy/JPseudoExperiment \
44 -o benchmark\[$N\].root \
45 -E "$HS $HB" \
46 -n $NUMBER_OF_TESTS \
47 -s $N \
48 -x "10000 -10 100" \
49 -N "$NUISANCE" \
50 -P $PROBABILITY \
51 -d $DEBUG --! >& benchmark.$N.log
52
53cat benchmark.$N.log
54
55awk '/Minimal likelihood ratio:/ { print $(NF - 1) }' benchmark.$N.log | read LIKELIHOOD_RATIO
56
57printf "Minimal likelihood ratio: %9.5f\n" $LIKELIHOOD_RATIO
58
59
60# check
61
62JZoom1D \
63 -f benchmark\[$N\].root:hl \
64 -x "$LIKELIHOOD_RATIO 1.0e99" \
65 -o zoom\[$N\].root
66
67JPrintResult -f benchmark\[$N\].root:hl -F GetSumOfWeights | read Y0
68JPrintResult -f zoom\[$N\].root:hl -F GetSumOfWeights | read Y1
69
70printf "Check of probability: %12.3e %12.3e\n" $PROBABILITY $(($Y1 / $Y0))
71
72
73# binary search
74
75let "NUMBER_OF_TESTS = 100000"
76
77let "XMIN = 1.0"
78let "XMAX = 2.0"
79let "EPS = 1.0e-2"
80let "QUANTILE = 0.5"
81
82for (( ; 1 ; )); do # lower limit
83
84 $JPP_DIR/examples/JAstronomy/JPseudoExperiment \
85 -o /dev/null \
86 -E "$HS $HB" \
87 -n $NUMBER_OF_TESTS \
88 -s $XMIN \
89 -Q $LIKELIHOOD_RATIO \
90 -d $DEBUG >& benchmark.log
91
92 awk '/Maximal probability:/ { print $(NF - 1) }' benchmark.log | read PROBABILITY
93
94 printf "lower limit: %9.5f -> P = %9.5f\n" $XMIN $PROBABILITY
95
96 if (( $PROBABILITY > $QUANTILE )); then
97 let "XMAX = $XMIN"
98 let "XMIN *= 0.5"
99 else
100 break
101 fi
102done
103
104for (( ; 1 ; )); do # upper limit
105
106 $JPP_DIR/examples/JAstronomy/JPseudoExperiment \
107 -o /dev/null \
108 -E "$HS $HB" \
109 -n $NUMBER_OF_TESTS \
110 -s $XMAX \
111 -Q $LIKELIHOOD_RATIO \
112 -d $DEBUG >& benchmark.log
113
114 awk '/Maximal probability:/ { print $(NF - 1) }' benchmark.log | read PROBABILITY
115
116 printf "upper limit: %9.5f -> P = %9.5f\n" $XMAX $PROBABILITY
117
118 if (( $PROBABILITY < $QUANTILE )); then
119 let "XMIN = $XMAX"
120 let "XMAX *= 2.0"
121 else
122 break
123 fi
124done
125
126for (( ; $XMAX - $XMIN > $EPS; )); do
127
128 let "X = 0.5 * ($XMIN + $XMAX)"
129
130 $JPP_DIR/examples/JAstronomy/JPseudoExperiment \
131 -o /dev/null \
132 -E "$HS $HB" \
133 -n $NUMBER_OF_TESTS \
134 -s $X \
135 -Q $LIKELIHOOD_RATIO \
136 -d $DEBUG >& benchmark.log
137
138 #cat benchmark.log
139
140 awk '/Maximal probability:/ { print $(NF - 1) }' benchmark.log | read PROBABILITY
141
142 printf "search: %9.5f <= %9.5f <= %9.5f -> P = %9.5f\n" $XMIN $X $XMAX $PROBABILITY
143
144 if (( $PROBABILITY < $QUANTILE )); then
145 let "XMIN = $X"
146 else
147 let "XMAX = $X"
148 fi
149done
150
151let "X = 0.5 * ($XMIN + $XMAX)"
152
153$JPP_DIR/examples/JAstronomy/JPseudoExperiment \
154 -o benchmark.root \
155 -E "$HS $HB" \
156 -n $NUMBER_OF_TESTS \
157 -s $X \
158 -x "1000 -10 100" \
159 -S 0 \
160 -d $DEBUG >& benchmark.log
161
162printf "signal: %9.5f\n" $X
163
164timer_stop
165timer_print