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