Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JARCAMuonReconstruction: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]="0.7 1.0 1.5"
59PARAMETERS[prefit.roadWidth_m]="150.0 175.0 200.0 225.0 250.0 275.0 300.0"
60PARAMETERS[prefit.TMaxLocal_ns]="15.0 17.5 20.0 22.5 25.0 27.5 30.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]="12.5 15.0 17.5 20.0 22.5 25.0"
72PARAMETERS[simplex.ctMin]="-0.1 0.0 0.1 0.2 0.3"
73PARAMETERS[simplex.roadWidth_m]="175.0 200.0 225.0 250.0"
74
75PARAMETERS[gandalf.TTS_ns]="0.0 0.5 1.0 1.5 2.0 2.5"
76PARAMETERS[gandalf.E_GeV]="0.5e3 1.0e3 1.5e3 2.0e3"
77PARAMETERS[gandalf.TMin_ns]="-60.0 -50.0 -40.0 -30.0 -20.0"
78PARAMETERS[gandalf.TMax_ns]="+350.0 +400.0 +450.0 +500.0 +550.0"
79PARAMETERS[gandalf.roadWidth_m]="150.0 175.0 200.0 225.0 250.0"
80
81if [[ $OPTION == "run" ]]; then
82
83 set_variable DIR `pwd`
84 set_variable WORKDIR `mktemp -d $WORKDIR/XXXXXX`
85
86 pushd $WORKDIR
87
88 set_variable RECONSTRUCTION_NUMBER_OF_THREADS 10
89
90 for PARAMETER VALUES in ${(kv)PARAMETERS}; do
91
92 VALUES=($(echo $VALUES))
93
94 if [[ ! -f $DIR/$PARAMETER.$APPS[1].txt ]]; then
95
96 for VALUE in $VALUES[*]; do
97
98 set_variable RECONSTRUCTION_OPTION -@ $PARAMETER=$VALUE
99
100 { rm -f jmuon.*.root } >& /dev/null
101
102 for (( i = 1; $i <= ${#INPUT_FILES}; i += 1 )); do
103 JARCAMuonReconstruction.sh $DETECTOR $INPUT_FILES[$i] jmuon.$i.root $JPP_DATA/PMT_parameters.txt >& /dev/null
104 done
105
106 for APP in $APPS[*]; do
107
108 JMuonPostfit -fjmuon.{1..${#INPUT_FILES}}.root -A $ENUMERATION[$APP] -N $NUMBER_OF_FIT[$APP] -o /dev/null >& $PARAMETER.$APP.log
109
110 set_variable N0 $(JPrintChain -fjmuon.{1..${#INPUT_FILES}}.root | awk '/^EVT/ {print $2}')
111 set_variable N1 $(awk '/Number of events with fit/ {print $NF}' $PARAMETER.$APP.log)
112 set_array N2 $(awk '/Space angle/ {print $NF}' $PARAMETER.$APP.log)
113
114 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
115 done
116 done
117 fi
118 done
119
120 popd
121
122 rm -rf $WORKDIR >& /dev/null
123
124elif [[ $OPTION == "plot" ]]; then
125
126 if [[ "$QUANTITY" == "" ]]; then
127 set_variable QUANTITY 50%
128 fi
129
130 case $QUANTITY in
131 50%) let "COLUMN = 2"; set_variable Y_LABEL "$QUANTITY angle [deg]";;
132 90%) let "COLUMN = 3"; set_variable Y_LABEL "$QUANTITY angle [deg]";;
133 99%) let "COLUMN = 4"; set_variable Y_LABEL "$QUANTITY angle [deg]";;
134 efficiency) let "COLUMN = 5"; set_variable Y_LABEL "$QUANTITY";;
135 *) fatal "Invalid quantity $QUANTITY."
136 esac
137
138 let "YMIN = 0.0"
139 let "YMAX = 0.0"
140
141 for PARAMETER in ${(k)PARAMETERS}; do
142
143 Y=$(sort -gr -k 2 $PARAMETER.${^APPS}.txt | awk -v COLUMN=$COLUMN '{if (NR == 1) {print $COLUMN}}')
144
145 if (( $Y > $YMAX )); then
146 let "YMAX = $Y"
147 fi
148 done
149
150 YMAX=$(printf "%1.1f" $(($YMAX * 1.1)))
151
152 for PARAMETER VALUES in ${(kv)PARAMETERS}; do
153
154 echo "Generating graphics for $PARAMETER."
155
156 VALUES=($(echo $VALUES | sed 's/[[:space:]][[:space:]]*/\n/g' | sort -g))
157
158 set_variable RECONSTRUCTION_OPTION -h!
159
160 typeset -T PARAMETER ARRAY .
161
162 set_variable X $(eval JARCAMuonReconstruction.sh - - - - \| sed -n \'/\^$ARRAY[1]\\\./,/\^\$/s/\.\*$ARRAY[2] \*= \*//p\')
163
164 JLine \
165 -p "$X $YMIN $X $YMAX" \
166 -o line.root
167
168 for APP in $APPS[*]; do
169 JGraph \
170 -f $PARAMETER.$APP.txt \
171 -o $PARAMETER\[$APP\].root \
172 -T "$PARAMETER" \
173 -M
174 done
175
176 let "NX = ${#VALUES}"
177 let "XMIN = $VALUES[+1]"
178 let "XMAX = $VALUES[-1]"
179 let "DX = ($XMAX - $XMIN) / ($NX - 1)"
180
181 JPlot1D \
182 -f$PARAMETER\[${^APPS}\].root:"${PARAMETER}\[$(($COLUMN - 2))\]" \
183 -f line.root:\.\* \
184 -x "$(($XMIN - 0.5*$DX)) $(($XMAX + 0.5*$DX))" \
185 -y "$YMIN $YMAX" \
186 -> "$PARAMETER" \
187 -\^ "$Y_LABEL" \
188 -G Y \
189 -T "" \
190 -L "TL 0.9" \
191 -o $PARAMETER.$FORMAT $BATCH
192
193 { rm -f $PARAMETER\[${^APPS}\].root line.root } >& /dev/null
194 done
195
196elif [[ $OPTION == "update" ]]; then
197
198 let "EPS = 1.0e-3"
199
200 APP=gandalf
201
202 for PARAMETER in ${(k)PARAMETERS}; do
203
204 if [[ -f $PARAMETER.$APP.txt ]]; then
205
206 VALUES=($(sort -g -k 2 $PARAMETER.$APP.txt | awk '{print $2}'))
207
208 if (( $VALUES[+1] < $VALUES[-1] - $EPS )); then
209
210 VALUE=$(sort -g -k 2 $PARAMETER.$APP.txt | awk '{if (NR == 1) {print $1}}')
211
212 eval sed -i \'s/\\\‍(${PARAMETER} \*\\\‍)\[\^\‍)\]\*/\\\1${VALUE}/\' $JPP_DIR/software/JReconstruction/JARCAMuonReconstruction.sh
213 fi
214 fi
215 done
216
217elif [[ $OPTION == "clean" ]]; then
218
219 for PARAMETER in ${(k)PARAMETERS}; do
220 for APP in $APPS[*]; do
221 rm -f $PARAMETER.$APP.txt >& /dev/null
222 done
223 done
224fi