Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JORCAMuonReconstruction:parameters.sh
Go to the documentation of this file.
1#!/bin/env zsh
2script=${0##*/}
3
4source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
5
6set_variable: DEBUG RECONSTRUCTION_DEBUG 2
7set_variable: WORKDIR RECONSTRUCTION_WORKDIR ${TMPDIR:-/tmp}/
8set_variable: FORMAT GRAPHICS_FORMAT gif
9set_variable+ BATCH GRAPHICS_BATCH -B
10
11if do_usage $*; then
12 usage "$script <option> [<detector> (input file)+]"\
13 "\nPossible options: run, plot, update and clean."\
14 "\nThe option run should be followed by a detector file and one or more input files (output of JTriggerEfficiency)."\
15 "\nThe option plot could be followed by the name of the fit (prefit, simplex or gandalf) and the quantity (50%, 90%, 99% or efficiency)."
16fi
17
18if (( $# == 1 )); then
19 set_variable OPTION ${argv[1]}
20elif (( $# >= 3 )) && [[ $1 == "run" ]]; then
21 set_variable OPTION ${argv[1]}
22 set_variable DETECTOR ${argv[2]:a}
23 set_array INPUT_FILES ${argv[3,-1]:a}
24elif (( $# >= 1 )) && [[ $1 == "plot" ]]; then
25 set_variable OPTION ${argv[1]}
26 set_array APPS ${argv[2]}
27 set_variable QUANTITY ${argv[3]}
28else
29 fatal "Wrong number of arguments."
30fi
31
32if [[ $OPTION != "run" && $OPTION != "plot" && $OPTION != "update" && $OPTION != "clean" ]]; then
33 fatal "Invalid option $OPTION."
34fi
35
36if (( ${#APPS} == 0 )); then
37 APPS=(prefit simplex gandalf)
38fi
39
40typeset -A NUMBER_OF_FIT
41
42NUMBER_OF_FIT=(prefit 0
43 simplex 0
44 gandalf 1
45 energy 1
46 start 1)
47
48typeset -A ENUMERATION
49
50ENUMERATION=(prefit 1
51 simplex 2
52 gandalf 3
53 energy 4
54 start 5)
55
56typeset -A PARAMETERS
57
58PARAMETERS[prefit.gridAngle_deg]="4.0 5.0 6.0"
59PARAMETERS[prefit.roadWidth_m]="35.0 40.0 45.0 50.0 55.0 60.0"
60PARAMETERS[prefit.TMaxLocal_ns]="10.0 12.5 15.0 17.5 20.0"
61PARAMETERS[prefit.sigma_ns]="4.0 5.0 6.0 7.0"
62PARAMETERS[prefit.ctMin]="-0.1 0.0 0.1 0.2 0.3"
63PARAMETERS[prefit.numberOfPrefits]="10 25 50 75 100"
64PARAMETERS[prefit.numberOfPostfits]="0 10 20 50"
65PARAMETERS[prefit.Qwatershed]="0 0.5 1.0 1.5 2.0 2.5"
66#PARAMETERS[prefit.numberOfOutliers]="0 1 2 3 4 5"
67#PARAMETERS[prefit.factoryLimit]="7 8 9 10"
68PARAMETERS[prefit.useL0]="0 1"
69
70PARAMETERS[simplex.sigma_ns]="2.0 2.5 3.0 3.5 4.0"
71PARAMETERS[simplex.TMaxLocal_ns]="10.0 12.5 15.0 17.5 20.0"
72PARAMETERS[simplex.ctMin]="-0.1 0.0 0.1 0.2 0.3"
73PARAMETERS[simplex.roadWidth_m]="35.0 40.0 45.0 50.0 55.0 60.0"
74
75PARAMETERS[start.roadWidth_m]="35.0 40.0 45.0 50.0 55.0 60.0"
76PARAMETERS[start.TMin_ns]="-30.0 -25.0 -20.0 -15.0"
77PARAMETERS[start.TMax_ns]="+15.0 +20.0 +25.0 +30.0"
78PARAMETERS[start.Pmin1]="0.5e-3 1.0e-3 1.5e-3"
79PARAMETERS[start.Pmin2]="0.5e-2 1.0e-2 1.5e-2"
80
81PARAMETERS[gandalf.TTS_ns]="0.0 0.5 1.0 1.5 2.0 2.5"
82PARAMETERS[gandalf.E_GeV]="5.0 10.0 15.0 20.0"
83PARAMETERS[gandalf.TMin_ns]="-60.0 -50.0 -40.0 -30.0 -20.0"
84PARAMETERS[gandalf.TMax_ns]="+350.0 +400.0 +450.0 +500.0 +550.0"
85PARAMETERS[gandalf.ZMin_m]="-1.0 -2.0 -3.0 -4.0 -5.0"
86PARAMETERS[gandalf.ZMax_m]="+7.0 +8.0 +9.0 +10.0 +11.0"
87PARAMETERS[gandalf.roadWidth_m]="35.0 40.0 45.0 50.0 55.0 60.0"
88
89if [[ $OPTION == "run" ]]; then
90
91 set_variable DIR `pwd`
92 set_variable WORKDIR `mktemp -d $WORKDIR/XXXXXX`
93
94 pushd $WORKDIR
95
96 set_variable RECONSTRUCTION_NUMBER_OF_THREADS 10
97
98 for PARAMETER VALUES in ${(kv)PARAMETERS}; do
99
100 VALUES=($(echo $VALUES))
101
102 if [[ ! -f $DIR/$PARAMETER.$APPS[1].txt ]]; then
103
104 for VALUE in $VALUES[*]; do
105
106 set_variable RECONSTRUCTION_OPTION -@ $PARAMETER=$VALUE
107
108 { rm -f jmuon.*.root } >& /dev/null
109
110 for (( i = 1; $i <= ${#INPUT_FILES}; i += 1 )); do
111 JORCAMuonReconstruction.sh $DETECTOR $INPUT_FILES[$i] jmuon.$i.root $JPP_DATA/PMT_parameters.txt >& /dev/null
112 done
113
114 for APP in $APPS[*]; do
115
116 JMuonPostfit -fjmuon.{1..${#INPUT_FILES}}.root -A $ENUMERATION[$APP] -N $NUMBER_OF_FIT[$APP] -o /dev/null >& $PARAMETER.$APP.log
117
118 set_variable N0 $(JPrintChain -fjmuon.{1..${#INPUT_FILES}}.root | awk '/^EVT/ {print $2}')
119 set_variable N1 $(awk '/Number of events with fit/ {print $NF}' $PARAMETER.$APP.log)
120 set_array N2 $(awk '/Space angle/ {print $NF}' $PARAMETER.$APP.log)
121
122 printf "%-1s %7.3f %7.3f %7.3f %6.4f\n" ${VALUE} ${N2[1]:-0} ${N2[2]:-0} ${N2[3]:-0} $(((1.0 * ${N1:-0}) / (1.0 * ${N0:-1}))) >> $DIR/$PARAMETER.$APP.txt
123 done
124 done
125 fi
126 done
127
128 popd
129
130 rm -rf $WORKDIR >& /dev/null
131
132elif [[ $OPTION == "plot" ]]; then
133
134 if [[ "$QUANTITY" == "" ]]; then
135 set_variable QUANTITY 50%
136 fi
137
138 case $QUANTITY in
139 50%) let "COLUMN = 2"; set_variable Y_LABEL "$QUANTITY angle [deg]";;
140 90%) let "COLUMN = 3"; set_variable Y_LABEL "$QUANTITY angle [deg]";;
141 99%) let "COLUMN = 4"; set_variable Y_LABEL "$QUANTITY angle [deg]";;
142 efficiency) let "COLUMN = 5"; set_variable Y_LABEL "$QUANTITY";;
143 *) fatal "Invalid quantity $QUANTITY."
144 esac
145
146 let "YMIN = 0.0"
147 let "YMAX = 0.0"
148
149 for PARAMETER in ${(k)PARAMETERS}; do
150
151 Y=$(sort -gr -k 2 $PARAMETER.${^APPS}.txt | awk -v COLUMN=$COLUMN '{if (NR == 1) {print $COLUMN}}')
152
153 if (( $Y > $YMAX )); then
154 let "YMAX = $Y"
155 fi
156 done
157
158 YMAX=$(printf "%1.1f" $(($YMAX * 1.1)))
159
160 for PARAMETER VALUES in ${(kv)PARAMETERS}; do
161
162 echo "Generating graphics for $PARAMETER."
163
164 VALUES=($(echo $VALUES | sed 's/[[:space:]][[:space:]]*/\n/g' | sort -g))
165
166 set_variable RECONSTRUCTION_OPTION -h!
167
168 typeset -T PARAMETER ARRAY .
169
170 set_variable X $(eval JORCAMuonReconstruction.sh - - - - \| sed -n \'/\^$ARRAY[1]\\\./,/\^\$/s/\.\*$ARRAY[2] \*= \*//p\')
171
172 JLine \
173 -p "$X $YMIN $X $YMAX" \
174 -o line.root
175
176 for APP in $APPS[*]; do
177 JGraph \
178 -f $PARAMETER.$APP.txt \
179 -o $PARAMETER\[$APP\].root \
180 -T "$PARAMETER" \
181 -M
182 done
183
184 let "NX = ${#VALUES}"
185 let "XMIN = $VALUES[+1]"
186 let "XMAX = $VALUES[-1]"
187 let "DX = ($XMAX - $XMIN) / ($NX - 1)"
188
189 JPlot1D \
190 -f$PARAMETER\[${^APPS}\].root:"${PARAMETER}\[$(($COLUMN - 2))\]" \
191 -f line.root:\.\* \
192 -x "$(($XMIN - 0.5*$DX)) $(($XMAX + 0.5*$DX))" \
193 -y "$YMIN $YMAX" \
194 -> "$PARAMETER" \
195 -\^ "$Y_LABEL" \
196 -G Y \
197 -T "" \
198 -L "TL 0.9" \
199 -o $PARAMETER.$FORMAT $BATCH
200
201 { rm -f $PARAMETER\[${^APPS}\].root line.root } >& /dev/null
202 done
203
204elif [[ $OPTION == "update" ]]; then
205
206 let "EPS = 1.0e-3"
207
208 APP=gandalf
209
210 for PARAMETER in ${(k)PARAMETERS}; do
211
212 if [[ -f $PARAMETER.$APP.txt ]]; then
213
214 VALUES=($(sort -g -k 2 $PARAMETER.$APP.txt | awk '{print $2}'))
215
216 if (( $VALUES[+1] < $VALUES[-1] - $EPS )); then
217
218 VALUE=$(sort -g -k 2 $PARAMETER.$APP.txt | awk '{if (NR == 1) {print $1}}')
219
220 eval sed -i \'s/\\\‍(${PARAMETER} \*\\\‍)\[\^\‍)\]\*/\\\1${VALUE}/\' $JPP_DIR/software/JReconstruction/JORCAMuonReconstruction.sh
221 fi
222 fi
223 done
224
225elif [[ $OPTION == "clean" ]]; then
226
227 for PARAMETER in ${(k)PARAMETERS}; do
228 for APP in $APPS[*]; do
229 rm -f $PARAMETER.$APP.txt >& /dev/null
230 done
231 done
232fi