Jpp 20.0.0-rc.7
the software that should make you happy
Loading...
Searching...
No Matches
discovery_mset.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: SNR ASTRONOMY_SNR 0.2
13set_variable: M_SIZE ASTRONOMY_M_SIZE 10000
14set_variable: FORMAT GRAPHICS_FORMAT gif
15set_variable+ BATCH GRAPHICS_BATCH -B
16
17if do_usage $*; then
18 usage "$script <config file name> <number of tests> <probability>"\
19 "\nThe histograms correspond to \"<file name>:<histogram name>\"."
20fi
21
22if (( $# != 3 )); then
23 fatal "Wrong number of arguments."
24fi
25
26set_variable CONFIG $argv[1]
27let "NUMBER_OF_TESTS = $argv[2]"
28let "PROBABILITY = $argv[3]"
29
30if (( $PROBABILITY <= 0.0 || $PROBABILITY >= 1.0 )); then
31 fatal "Invalid probability $PROBABILITY"
32fi
33
34if (( $NUMBER_OF_TESTS * $PROBABILITY <= 1.0 )); then
35 warning "Insufficient number of tests $NUMBER_OF_TESTS given probability $PROBABILITY."
36fi
37
38timer_start
39
40# H0 pseudo experiments
41
42let "N = 0" # zero signal
43
44H0=$N
45
46echo -n "Running H0 pseudo experiments... "
47
48$JPP_DIR/examples/JAstronomy/JGen2 \
49 -o benchmark\[$H0\].root \
50 -E $CONFIG \
51 -n $NUMBER_OF_TESTS \
52 -s $N \
53 -x "10000 -10 100" \
54 -P $PROBABILITY \
55 -R $SNR \
56 -M $M_SIZE \
57 -S 0 \
58 -d $DEBUG >& benchmark.$H0.log
59
60echo OK
61cat benchmark.$H0.log
62
63awk '/Minimal likelihood ratio:/ { print $(NF - 1) }' benchmark.$H0.log | read LIKELIHOOD_RATIO
64
65printf "Minimal likelihood ratio: %9.5f\n" $LIKELIHOOD_RATIO
66
67
68# H1 pseudo experiments
69
70let "NUMBER_OF_TESTS = 100000"
71let "QUANTILE = 0.5"
72
73$JPP_DIR/examples/JAstronomy/JGen2 \
74 -o /dev/null \
75 -E $CONFIG \
76 -n $NUMBER_OF_TESTS \
77 -s 1.0 \
78 -Q $LIKELIHOOD_RATIO \
79 -P $QUANTILE \
80 -R $SNR \
81 -M $M_SIZE \
82 -S 0 \
83 -d $DEBUG >& benchmark.log
84
85awk '/Signal strength:/ { print $NF }' benchmark.log | read X
86
87printf "%1.1f" $X | read H1
88
89$JPP_DIR/examples/JAstronomy/JGen2 \
90 -o benchmark\[$H1\].root \
91 -E $CONFIG \
92 -n $NUMBER_OF_TESTS \
93 -s $X \
94 -x "1000 -10 100" \
95 -R $SNR \
96 -M $M_SIZE \
97 -S 0 \
98 -d $DEBUG >& benchmark.log
99
100printf "signal: %9.5f\n" $X
101
102timer_stop
103timer_print
104
105
106# check
107
108if (( 1 )); then
109
110 typeset -A HYPOTHESES
111
112 HYPOTHESES[H0]=$PROBABILITY
113 HYPOTHESES[H1]=$QUANTILE
114
115 for KEY VALUE in ${(kv)HYPOTHESES}; do
116
117 JZoom1D \
118 -f benchmark\[${(P)KEY}\].root:hl \
119 -x "$LIKELIHOOD_RATIO 1.0e99" \
120 -o zoom.root
121
122 JPrintResult -f benchmark\[${(P)KEY}\].root:hl -F GetSumOfWeights | read Y0
123 JPrintResult -f zoom.root:hl -F GetSumOfWeights | read Y1
124
125 printf "Hypothesis %s - check probability: %10.3e == %10.3e\n" $KEY $VALUE $(($Y1 / $Y0))
126
127 rm -f zoom.root
128 done
129fi
130
131
132# plot
133
134let "X1 = $LIKELIHOOD_RATIO"
135let "X2 = $LIKELIHOOD_RATIO"
136let "Y1 = 1.0"
137let "Y2 = $(JPrintResult -f benchmark\[$N\].root:hl -F GetMaximum)"
138
139JLine -p "$X1 $Y1 $X2 $Y2" -@ "style = 2" -o line.root
140
141JPlot1D \
142 -f benchmark\[$H0\].root:hl \
143 -f benchmark\[$H1\].root:hl \
144 -f line.root:\.\* \
145 -Y \
146 -> "likelihood ratio" \
147 -\^ "number of experiments" \
148 -T "" \
149 -O HIST \
150 -L TR \
151 -o discovery.$FORMAT $BATCH