Jpp  17.1.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
acoustics-fit-toolkit.sh
Go to the documentation of this file.
1 #!/bin/zsh
2 script=${0##*/}
3 
4 # -----------------------------------------------------------------------------------------------------
5 #
6 # Toolkit for the determination of the fixed parameters in the system, a.k.a. "pre-calibration".
7 # The list of parameters includes (x,y,z) positions of strings and tripods, stretching of strings,
8 # z-positions of the optical modules, orientations of the strings and possibly z-positions of anchors.
9 #
10 # The value of a given parameter is optimised by minimising the average chi2/NDF
11 # of a series of global fits applied to a predefined set of acoustic events.
12 # For each parameter, there exists a designated function.
13 #
14 # There are also steering functions to consistently determine the optimal values for a set of parameters.
15 # In these, the current accuracy of the parameter values is taken into account.
16 # These are therefore referred to as "stages".
17 # The pre-calibration thus consists of a sequence of stages.
18 # For each detector, a complete pre-calibration procedure is implemented in a designated script.
19 #
20 # Mandatory input variables:
21 #
22 # DETECTOR # detector file
23 # TRIPOD # tripod file
24 # INPUT_FILES # list of input files (output of JAcousticsEventBuilder[.sh])
25 #
26 # Optional input variables:
27 #
28 # HYDROPHONE # if defined, use hydrophones in global fit; else do not use hydrophones
29 #
30 # In the following:
31 #
32 # STRINGS corresponds to list of strings to be fitted; this can be changed with function fixStrings.
33 # TRIPODS corresponds to list of tripods to be fitted; this can be changed with function fixTripods.
34 #
35 # TRANSMITTERS corresponds to list of strings which have an emitter on the anchor (maybe empty).
36 # For these strings, the orientations and the z-positions of the anchors will separately be fitted.
37 # This list will also be changed with function fixStrings.
38 # -----------------------------------------------------------------------------------------------------
39 
40 source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
41 
42 if do_usage $*; then
43  usage "source $script"\
44  "\nThis script contains auxiliary functions for the pre-calibration of specific detectors."\
45  "\nIt should be sourced by the detector specific scripts."
46 fi
47 
48 source JAcousticsToolkit.sh
49 
52 
53 typeset -A TRIPODS # tripods
54 typeset -a CHI2 # chi2 values; index [1] corresponds to best value
55 set_variable PRECISION 1.0E-5 # minimal change in chi2 to make step
56 set_variable EPSILON 5.0E-4 # maximal distance to minimum of chi2
57 set_variable RADIUS_M 1.0 # maximal horizontal distance between T-bar and emitter/hydrophone
58 
59 
60 # -----------------------------------------------------------------------------------------------------
61 # Initialise.
62 #
63 # Install input files in working directory and create temporary directory TMPDIR.
64 #
65 # -----------------------------------------------------------------------------------------------------
66 function initialise()
67 {
68  eval `JPrintDetector -a $DETECTOR -O IDENTIFIER`
69  eval `JPrintDetector -a $DETECTOR -O SUMMARY`
70  eval `JPrintDetector -a $DETECTOR -O CAN`
71 
72  JAcoustics.sh $DETECTOR_ID
73 
74  get_tripods $TRIPOD TRIPODS
75 
76  TRANSMITTERS=(`get_strings_with_transmitter $WORKDIR/transmitter.txt`)
77 
78  mkdir -p $TMPDIR
79 }
80 
81 
82 # -----------------------------------------------------------------------------------------------------
83 # Remove temporary directory and restore input files in working directory.
84 #
85 # -----------------------------------------------------------------------------------------------------
86 function clean()
87 {
88  rm -rf $TMPDIR >& /dev/null
89 
90  rm -f {acoustics_fit_parameters,acoustics_trigger_parameters}.txt
91 
92  JAcoustics.sh $DETECTOR_ID
93 }
94 
95 
96 # -----------------------------------------------------------------------------------------------------
97 # Fix strings.
98 #
99 # \param 1-N identifiers
100 # -----------------------------------------------------------------------------------------------------
101 function fixStrings()
102 {
103  typeset -a BUFFER
104 
105  BUFFER=(`echo $*`)
106 
107  if (( ${#BUFFER} > 0 )); then
108  STRINGS=(${STRINGS:|BUFFER})
109  TRANSMITTERS=(${TRANSMITTERS:|BUFFER})
110  fi
111 }
112 
113 
114 # -----------------------------------------------------------------------------------------------------
115 # Fix tripods.
116 #
117 # \param 1-N identifiers
118 # -----------------------------------------------------------------------------------------------------
119 function fixTripods()
120 {
121  typeset -a BUFFER
122 
123  BUFFER=(`echo $*`)
124 
125  if (( ${#BUFFER} > 0 )); then
126  for ID in $BUFFER[*]; do
127  unset "TRIPODS[${ID}]"
128  done
129  fi
130 }
131 
132 
133 # -----------------------------------------------------------------------------------------------------
134 # Get center-of-gravity of tripods.
135 #
136 # \return x y z
137 # -----------------------------------------------------------------------------------------------------
138 function getCenter()
139 {
140  typeset -A __TRIPODS__
141 
142  get_tripods $TRIPOD __TRIPODS__
143 
144  let "X = 0.0"
145  let "Y = 0.0"
146  let "Z = 0.0"
147 
148  if (( ${#__TRIPODS__} >= 1 )); then
149 
150  for _X _Y _Z in `echo ${(@v)__TRIPODS__}`; do
151  let "X = $X + $_X"
152  let "Y = $Y + $_Y"
153  let "Z = $Z + $_Z"
154  done
155 
156  let "X = $X / ${#__TRIPODS__}"
157  let "Y = $Y / ${#__TRIPODS__}"
158  let "Z = $Z / ${#__TRIPODS__}"
159  fi
160 
161  printf "%15.5f %15.5f %15.5f" $X $Y $Z
162 }
163 
164 
165 # -----------------------------------------------------------------------------------------------------
166 # Set detector and tripods to given center-of-gravity.
167 #
168 # \param 1 X
169 # \param 2 Y
170 # \param 3 Z
171 # -----------------------------------------------------------------------------------------------------
172 function setCenter()
173 {
174  getCenter | read X Y Z
175 
176  let "X = $X - $1"
177  let "Y = $Y - $2"
178  let "Z = $Z - $3"
179 
180  printf "Fix center %15.5f %15.5f %15.5f\n" $X $Y $Z
181 
182  JEditTripod -f $TRIPOD -T "-1 sub $X $Y $Z" -o $TRIPOD -d 0 >& /dev/null
183  JEditDetector -a $DETECTOR -S "-1 sub $X $Y $Z" -o $DETECTOR -d 0 >& /dev/null
184 }
185 
186 
187 # -----------------------------------------------------------------------------------------------------
188 # Evaluate current chi2.
189 #
190 # \param 1 variable containing chi2 value on return
191 # -----------------------------------------------------------------------------------------------------
192 function getChi2()
193 {
194  for (( m = 0; $m != 3; ++m )); do
195 
196  rm -f $TMPDIR/katoomba.{root,log} >& /dev/null
197 
198  date >& $TMPDIR/katoomba.log
199 
200  JKatoomba \
201  -a $DETECTOR \
202  -f "$INPUT_FILES[*]" \
203  -o $TMPDIR/katoomba.root \
204  -T $TRIPOD \
205  -Y $WORKDIR/transmitter.txt \
206  -V $WORKDIR/sound_velocity.txt \
207  -M $WORKDIR/mechanics.txt \
208  -@ $TMPDIR/acoustics_fit_parameters.txt \
209  -! $WORKDIR/disable.txt \
210  ${HYDROPHONE:+-H $WORKDIR/hydrophone.txt} \
211  -F 2 \
212  -u \
213  -d 2 --! >>& $TMPDIR/katoomba.log
214 
215  ERROR=$?
216 
217  if (( $ERROR == 0 )); then
218 
219  let "VALUE = $(JPrintResult -f $TMPDIR/katoomba.root:chi2 -F GetMean)" >>& $TMPDIR/katoomba.log
220 
221  ERROR=$?
222 
223  if (( $ERROR == 0 )); then
224 
225  eval $1=$VALUE
226 
227  return
228  else
229  printf "warning: exit code let %d\n" $ERROR
230  fi
231  else
232  printf "warning: exit code JKatoomba %d\n" $ERROR
233  fi
234 
235  # backup error status
236 
237  set_variable UDIR `mktemp -d $WORKDIR/XXXXXX`
238 
239  cp -p $TMPDIR/katoomba.log $UDIR
240  cp -p $TMPDIR/katoomba.root $UDIR
241  cp -p $DETECTOR $UDIR
242  cp -p $TRIPOD $UDIR
243  cp -p $WORKDIR/transmitter.txt $UDIR
244 
245  printf "warning: backup %s\n" $UDIR
246  done
247 
248  printf "warning: no valid chi2 -> exit\n"
249  exit 1
250 }
251 
252 
253 # -----------------------------------------------------------------------------------------------------
254 # Fit given coordinate of string position.
255 #
256 # \param 1 string identifier
257 # \param 2 coordinate (X|Y|Z)
258 # \param 3 step
259 # -----------------------------------------------------------------------------------------------------
261 {
262  typeset -A BUFFER
263 
264  BUFFER=(X 0.0 Y 0.0 Z 0.0)
265 
266  BUFFER[$2]=$3
267 
268  if [[ "$2" == "Z" ]]; then
269  OPTION=-s # optical modules only
270  else
271  OPTION=-S # all modules
272  fi
273 
274  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
275 
276  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
277 
278  JEditDetector -a $DETECTOR $OPTION "$1 add ${(v)BUFFER}" -o $DETECTOR -q -d 0 >& /dev/null
279 
280  getChi2 CHI2\[2\]
281 
282  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
283 
284  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
285 
286  break
287  fi
288 
289  CHI2[1]=$CHI2[2]
290  done
291 
292  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
293 
294  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
295 
296  JEditDetector -a $DETECTOR $OPTION "$1 sub ${(v)BUFFER}" -o $DETECTOR -q -d 0 >& /dev/null
297 
298  getChi2 CHI2\[2\]
299 
300  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
301 
302  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
303 
304  break
305  fi
306 
307  CHI2[1]=$CHI2[2]
308  done
309 
310  printf "string %04d %s %6.4f %6d %8.4f\n" $1 $2 $3 $N $CHI2[1]
311 }
312 
313 
314 # -----------------------------------------------------------------------------------------------------
315 # Fit stretching of string.
316 #
317 # \param 1 string identifier
318 # \param 2 multiplication factor
319 # -----------------------------------------------------------------------------------------------------
321 {
322  let "Z = $CAN_ZMAX_M * $2"
323 
324  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
325 
326  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
327 
328  JEditDetector -a $DETECTOR -s "$1 mul $2" -s "$1 sub 0.0 0.0 $Z" -o $DETECTOR -q -d 0 >& /dev/null
329 
330  getChi2 CHI2\[2\]
331 
332  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
333 
334  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
335 
336  break
337  fi
338 
339  CHI2[1]=$CHI2[2]
340  done
341 
342  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
343 
344  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
345 
346  JEditDetector -a $DETECTOR -s "$1 add 0.0 0.0 $Z" -s "$1 div $2" -o $DETECTOR -q -d 0 >& /dev/null
347 
348  getChi2 CHI2\[2\]
349 
350  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
351 
352  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
353 
354  break
355  fi
356 
357  CHI2[1]=$CHI2[2]
358  done
359 
360  printf "string %04d M %6.4f %6d %8.4f\n" $1 $2 $N $CHI2[1]
361 }
362 
363 
364 # -----------------------------------------------------------------------------------------------------
365 # Fit given coordinate of tripod position.
366 #
367 # \param 1 tripod identifier
368 # \param 2 coordinate (X|Y|Z)
369 # \param 3 step
370 # -----------------------------------------------------------------------------------------------------
372 {
373  typeset -A BUFFER
374 
375  BUFFER=(X 0.0 Y 0.0 Z 0.0)
376 
377  BUFFER[$2]=$3
378 
379  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
380 
381  cp $TRIPOD $TMPDIR/tripod.txt
382 
383  JEditTripod -f $TRIPOD -T "$1 add ${(v)BUFFER}" -o $TRIPOD -q -d 0 >& /dev/null
384 
385  getChi2 CHI2\[2\]
386 
387  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
388 
389  mv $TMPDIR/tripod.txt $TRIPOD
390 
391  break
392  fi
393 
394  CHI2[1]=$CHI2[2]
395  done
396 
397  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
398 
399  cp $TRIPOD $TMPDIR/tripod.txt
400 
401  JEditTripod -f $TRIPOD -T "$1 sub ${(v)BUFFER}" -o $TRIPOD -q -d 0 >& /dev/null
402 
403  getChi2 CHI2\[2\]
404 
405  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
406 
407  mv $TMPDIR/tripod.txt $TRIPOD
408 
409  break
410  fi
411 
412  CHI2[1]=$CHI2[2]
413  done
414 
415  printf "tripod %2d %s %6.4f %6d %8.4f\n" $1 $2 $3 $N $CHI2[1]
416 }
417 
418 
419 # -----------------------------------------------------------------------------------------------------
420 # Fit module z-position.
421 #
422 # \param 1 string identifier
423 # \param 2 floor
424 # \param 3 step
425 # -----------------------------------------------------------------------------------------------------
427 {
428  typeset -A BUFFER
429 
430  BUFFER=(X 0.0 Y 0.0 Z $3)
431 
432  set_variable NUMBER_OF_STEPS 10 # limit number of steps
433  set_variable MODULE `getModule -a $DETECTOR -L "$1 $2"`
434 
435  for (( i=0 ; $i != $NUMBER_OF_STEPS && $N != $NUMBER_OF_ITERATIONS; ++i, ++N )); do
436 
437  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
438 
439  JEditDetector -a $DETECTOR -M "$MODULE add ${(v)BUFFER}" -o $DETECTOR -q -d 0 >& /dev/null
440 
441  getChi2 CHI2\[2\]
442 
443  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
444 
445  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
446 
447  break
448  fi
449 
450  CHI2[1]=$CHI2[2]
451  done
452 
453  for (( i=0 ; $i != $NUMBER_OF_STEPS && $N != $NUMBER_OF_ITERATIONS; ++i, ++N )); do
454 
455  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
456 
457  JEditDetector -a $DETECTOR -M "$MODULE sub ${(v)BUFFER}" -o $DETECTOR -q -d 0 >& /dev/null
458 
459  getChi2 CHI2\[2\]
460 
461  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
462 
463  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
464 
465  break
466  fi
467 
468  CHI2[1]=$CHI2[2]
469  done
470 
471  printf "module %04d.%02d %6.4f %6d %8.4f\n" $1 $2 $3 $N $CHI2[1]
472 }
473 
474 
475 # -----------------------------------------------------------------------------------------------------
476 # Fit given coordinate of anchor position.
477 #
478 # Note that the position of the anchor corresponds to the position of the base module in the detector.
479 # The z-position can independently be changed whereas a change in the (x,y) position
480 # affects the complete string (i.e. including optical modules).
481 #
482 # \param 1 string identifier
483 # \param 2 coordinate (X|Y|Z)
484 # \param 3 step
485 # -----------------------------------------------------------------------------------------------------
487 {
488  typeset -A BUFFER
489 
490  BUFFER=(X 0.0 Y 0.0 Z 0.0)
491 
492  BUFFER[$2]=$3
493 
494  if [[ "$2" == "Z" ]]; then
495 
496  set_variable MODULE `getModule -a $DETECTOR -L "$1 0"`
497 
498  ADD="-M $MODULE add ${(v)BUFFER}" # base module only
499  SUB="-M $MODULE sub ${(v)BUFFER}" # base module only
500  else
501  ADD="-S $1 add ${(v)BUFFER}" # all modules
502  SUB="-S $1 sub ${(v)BUFFER}" # all modules
503  fi
504 
505  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
506 
507  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
508 
509  JEditDetector -a $DETECTOR $ADD -o $DETECTOR -q -d 0 >& /dev/null
510 
511  getChi2 CHI2\[2\]
512 
513  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
514 
515  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
516 
517  break
518  fi
519 
520  CHI2[1]=$CHI2[2]
521  done
522 
523  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
524 
525  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
526 
527  JEditDetector -a $DETECTOR $SUB -o $DETECTOR -q -d 0 >& /dev/null
528 
529  getChi2 CHI2\[2\]
530 
531  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
532 
533  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
534 
535  break
536  fi
537 
538  CHI2[1]=$CHI2[2]
539  done
540 
541  printf "anchor %04d %s %6.4f %6d %8.4f\n" $1 $2 $3 $N $CHI2[1]
542 }
543 
544 
545 # -----------------------------------------------------------------------------------------------------
546 # Fit rotation of anchor.
547 #
548 # Note that a rotation of the anchor corresponds to a change of the relative positions of
549 # the hydrophone and emitter with respect to the T-bar.
550 #
551 # \param 1 string identifier
552 # \param 2 rotation angle [rad]
553 # -----------------------------------------------------------------------------------------------------
555 {
556  let "ROT = $2"
557 
558  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
559 
560  cp $WORKDIR/hydrophone.txt $TMPDIR/hydrophone.txt
561  cp $WORKDIR/transmitter.txt $TMPDIR/transmitter.txt
562 
563  JEditHydrophone -f $WORKDIR/hydrophone.txt -S "$1 rot $ROT" -o $WORKDIR/hydrophone.txt -q -d 0 >& /dev/null
564  JEditTransmitter -f $WORKDIR/transmitter.txt -S "$1 rot $ROT" -o $WORKDIR/transmitter.txt -q -d 0 >& /dev/null
565 
566  getChi2 CHI2\[2\]
567 
568  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
569 
570  mv $TMPDIR/hydrophone.txt $WORKDIR/hydrophone.txt
571  mv $TMPDIR/transmitter.txt $WORKDIR/transmitter.txt
572 
573  break
574  fi
575 
576  CHI2[1]=$CHI2[2]
577  done
578 
579  let "ROT = -1.0 * $ROT"
580 
581  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
582 
583  cp $WORKDIR/hydrophone.txt $TMPDIR/hydrophone.txt
584  cp $WORKDIR/transmitter.txt $TMPDIR/transmitter.txt
585 
586  JEditHydrophone -f $WORKDIR/hydrophone.txt -S "$1 rot $ROT" -o $WORKDIR/hydrophone.txt -q -d 0 >& /dev/null
587  JEditTransmitter -f $WORKDIR/transmitter.txt -S "$1 rot $ROT" -o $WORKDIR/transmitter.txt -q -d 0 >& /dev/null
588 
589  getChi2 CHI2\[2\]
590 
591  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
592 
593  mv $TMPDIR/hydrophone.txt $WORKDIR/hydrophone.txt
594  mv $TMPDIR/transmitter.txt $WORKDIR/transmitter.txt
595 
596  break
597  fi
598 
599  CHI2[1]=$CHI2[2]
600  done
601 
602  printf "string %04d R %6.4f %6d %8.4f\n" $1 $2 $N $CHI2[1]
603 }
604 
605 
606 # -----------------------------------------------------------------------------------------------------
607 # Stage 0.
608 # This stage can be used to determine the (x,y,z) positions of tripods when a number of strings is fixed.
609 #
610 # -----------------------------------------------------------------------------------------------------
611 function stage_0()
612 {
613  cat>$TMPDIR/acoustics_fit_parameters.txt<<EOF
614 `egrep Tmax_s $WORKDIR/acoustics_fit_parameters.txt`
615 Nmin = 3;
616 sigma_s = 100.0e-6;
617 stdev = 10.0;
618 mestimator = 0;
619 option = 1;
620 EOF
621 
622  if (( ${#STRINGS} > 0 )); then
623  JEditDetector -a $DETECTOR -o $TMPDIR/detector_0.datx -k "$STRINGS[*]" -q -d 0 >& /dev/null
624  JEditDetector -a $DETECTOR -o $DETECTOR -r "$STRINGS[*]" -q -d 0 >& /dev/null
625  fi
626 
627  getChi2 CHI2\[1\]
628 
629  set_variable NUMBER_OF_ITERATIONS 1000
630 
631  for DX_M in 0.5 0.2 0.1; do # determine (x,y,z) positions of tripods
632 
633  let "A_RAD = $DX_M / $RADIUS_M" # use maximal horizontal distance between T-bar and emitter/hydrophone
634 
635  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
636 
637  CHI2[3]=$CHI2[1]
638 
639  for ID in ${(k)TRIPODS}; do
640  fitPositionOfTripod $ID X $DX_M
641  fitPositionOfTripod $ID Y $DX_M
642  fitPositionOfTripod $ID Z $DX_M
643  done
644 
645  for STRING in $TRANSMITTERS[*]; do
650  done
651 
652  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
653  break
654  fi
655  done
656 
657  if (( $N >= $NUMBER_OF_ITERATIONS )); then
658  printf "warning: reached maximum number of iterations %d - convergence %7.3f\n" $N $(($CHI2[3] - $CHI2[1]))
659  fi
660  done
661 
662  if (( ${#STRINGS} > 0 )); then
663  JMergeDetector -a $DETECTOR -a $TMPDIR/detector_0.datx -o $DETECTOR >& /dev/null
664  fi
665 }
666 
667 
668 # -----------------------------------------------------------------------------------------------------
669 # Stage 1A.
670 # This stage can be used to roughly determine the positions of the strings, tripods and modules.
671 # During this procedure, the strings are kept vertical in the global fits.
672 #
673 # -----------------------------------------------------------------------------------------------------
674 function stage_1A()
675 {
676  cat>$TMPDIR/acoustics_fit_parameters.txt<<EOF
677 `egrep Tmax_s $WORKDIR/acoustics_fit_parameters.txt`
678 Nmin = 3;
679 sigma_s = 250.0e-6;
680 stdev = 10.0;
681 mestimator = 2;
682 option = 0;
683 EOF
684 
685  getChi2 CHI2\[1\]
686 
687  set_variable NUMBER_OF_ITERATIONS 1000
688 
689  for DX_M in 0.5 0.2; do # determine (x,y,z) positions of strings and tripods
690 
691  let "A_RAD = $DX_M / $RADIUS_M" # use maximal horizontal distance between T-bar and emitter/hydrophone
692 
693  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
694 
695  CHI2[3]=$CHI2[1]
696 
697  for STRING in $STRINGS[*]; do
701  done
702 
703  for ID in ${(k)TRIPODS}; do
704  fitPositionOfTripod $ID X $DX_M
705  fitPositionOfTripod $ID Y $DX_M
706  fitPositionOfTripod $ID Z $DX_M
707  done
708 
709  for STRING in $TRANSMITTERS[*]; do
714  done
715 
716  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
717  break
718  fi
719  done
720 
721  if (( $N >= $NUMBER_OF_ITERATIONS )); then
722  printf "warning: reached maximum number of iterations %d - convergence %7.3f\n" $N $(($CHI2[3] - $CHI2[1]))
723  fi
724  done
725 
726  getChi2 CHI2\[1\]
727 
728  set_variable NUMBER_OF_ITERATIONS 2000
729 
730  for DX_M in 0.1; do # determine (z) positions of modules
731 
732  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
733 
734  CHI2[3]=$CHI2[1]
735 
736  for STRING in $STRINGS[*]; do
737  for (( FLOOR = 1; $FLOOR <= 18; FLOOR += 1 )); do
738  fitPositionOfModule $STRING $FLOOR $DX_M
739  done
740  done
741 
742  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
743  break
744  fi
745  done
746 
747  if (( $N >= $NUMBER_OF_ITERATIONS )); then
748  printf "warning: reached maximum number of iterations %d - convergence %7.3f\n" $N $(($CHI2[3] - $CHI2[1]))
749  fi
750  done
751 }
752 
753 
754 # -----------------------------------------------------------------------------------------------------
755 # Stage 1B.
756 # This stage can be used to determine the z-positions and stretching of individual strings.
757 #
758 # -----------------------------------------------------------------------------------------------------
759 function stage_1B()
760 {
761  cat>$TMPDIR/acoustics_fit_parameters.txt<<EOF
762 `egrep Tmax_s $WORKDIR/acoustics_fit_parameters.txt`
763 Nmin = 3;
764 sigma_s = 100.0e-6;
765 stdev = 10.0;
766 mestimator = 0;
767 option = 1;
768 EOF
769 
770  for STRING in $STRINGS[*]; do # determine stretching and (z) position of given string
771 
772  JEditDetector -a $DETECTOR -o $TMPDIR/detector_1.datx -r "$STRING" -q -d 0 >& /dev/null
773  JEditDetector -a $DETECTOR -o $DETECTOR -k "$STRING" -q -d 0 >& /dev/null
774 
775  getChi2 CHI2\[1\]
776 
777  set_variable NUMBER_OF_ITERATIONS 1000
778 
779  for MUL in 0.005 0.001; do
780 
781  DX_M=0.2
782 
783  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
784 
785  CHI2[3]=$CHI2[1]
786 
789 
790  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
791  break
792  fi
793  done
794 
795  if (( $N >= $NUMBER_OF_ITERATIONS )); then
796  printf "warning: reached maximum number of iterations %d - convergence %7.3f\n" $N $(($CHI2[3] - $CHI2[1]))
797  fi
798  done
799 
800  JMergeDetector -a $DETECTOR -a $TMPDIR/detector_1.datx -o $DETECTOR >& /dev/null
801  done
802 }
803 
804 
805 # -----------------------------------------------------------------------------------------------------
806 # Stage 2.
807 # This stage can be used to improve the determination the positions of the strings, tripods and modules.
808 #
809 # -----------------------------------------------------------------------------------------------------
810 function stage_2()
811 {
812  cat>$TMPDIR/acoustics_fit_parameters.txt<<EOF
813 `egrep Tmax_s $WORKDIR/acoustics_fit_parameters.txt`
814 Nmin = 3;
815 sigma_s = 100.0e-6;
816 stdev = 10.0;
817 mestimator = 0;
818 option = 1;
819 EOF
820 
821  getChi2 CHI2\[1\]
822 
823  set_variable NUMBER_OF_ITERATIONS 1000
824 
825  for DX_M in 0.2; do # determine (x,y,z) positions of strings and tripods
826 
827  let "A_RAD = $DX_M / $RADIUS_M" # use maximal horizontal distance between T-bar and emitter/hydrophone
828 
829  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
830 
831  CHI2[3]=$CHI2[1]
832 
833  for STRING in $STRINGS[*]; do
837  done
838 
839  for ID in ${(k)TRIPODS}; do
840  fitPositionOfTripod $ID X $DX_M
841  fitPositionOfTripod $ID Y $DX_M
842  fitPositionOfTripod $ID Z $DX_M
843  done
844 
845  for STRING in $TRANSMITTERS[*]; do
850  done
851 
852  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
853  break
854  fi
855  done
856 
857  if (( $N >= $NUMBER_OF_ITERATIONS )); then
858  warning "reached maximum number of iterations $N - convergence $(($CHI2[3] - $CHI2[1]))"
859  fi
860  done
861 
862  getChi2 CHI2\[1\]
863 
864  set_variable NUMBER_OF_ITERATIONS 2000
865 
866  for DX_M in 0.1; do # determine (z) positions of modules and (x,y) positions of strings
867 
868  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
869 
870  CHI2[3]=$CHI2[1]
871 
872  for STRING in $STRINGS[*]; do
873 
874  for (( FLOOR = 1; $FLOOR <= 18; FLOOR += 1 )); do
875  fitPositionOfModule $STRING $FLOOR $DX_M
876  done
877 
880  done
881 
882  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
883  break
884  fi
885  done
886 
887  if (( $N >= $NUMBER_OF_ITERATIONS )); then
888  warning "reached maximum number of iterations $N - convergence $(($CHI2[3] - $CHI2[1]))"
889  fi
890  done
891 }
892 
893 # -----------------------------------------------------------------------------------------------------
894 # Stage 3.
895 # This stage can be used to finalise the determination of the positions of the strings, tripods and modules.
896 #
897 # -----------------------------------------------------------------------------------------------------
898 function stage_3()
899 {
900  cat>$TMPDIR/acoustics_fit_parameters.txt<<EOF
901 `egrep Tmax_s $WORKDIR/acoustics_fit_parameters.txt`
902 Nmin = 3;
903 sigma_s = 50.0e-6;
904 stdev = 10.0;
905 mestimator = 0;
906 option = 1;
907 EOF
908 
909  getChi2 CHI2\[1\]
910 
911  set_variable NUMBER_OF_ITERATIONS 1000
912 
913  for DX_M in 0.10 0.05; do # determine (x,y,z) positions of strings and tripods
914 
915  let "A_RAD = $DX_M / $RADIUS_M" # use maximal horizontal distance between T-bar and emitter/hydrophone
916 
917  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
918 
919  CHI2[3]=$CHI2[1]
920 
921  for STRING in $STRINGS[*]; do
925  done
926 
927  for ID in ${(k)TRIPODS}; do
928  fitPositionOfTripod $ID X $DX_M
929  fitPositionOfTripod $ID Y $DX_M
930  fitPositionOfTripod $ID Z $DX_M
931  done
932 
933  for STRING in $TRANSMITTERS[*]; do
938  done
939 
940  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
941  break
942  fi
943  done
944 
945  if (( $N >= $NUMBER_OF_ITERATIONS )); then
946  warning "reached maximum number of iterations $N - convergence $(($CHI2[3] - $CHI2[1]))"
947  fi
948  done
949 
950  getChi2 CHI2\[1\]
951 
952  set_variable NUMBER_OF_ITERATIONS 2000
953 
954  for DX_M in 0.05; do # determine (z) positions of modules and (x,y) positions of strings
955 
956  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
957 
958  CHI2[3]=$CHI2[1]
959 
960  for STRING in $STRINGS[*]; do
961 
962  for (( FLOOR = 1; $FLOOR <= 18; FLOOR += 1 )); do
963  fitPositionOfModule $STRING $FLOOR $DX_M
964  done
965 
968  done
969 
970  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
971  break
972  fi
973  done
974 
975  if (( $N >= $NUMBER_OF_ITERATIONS )); then
976  warning "reached maximum number of iterations $N - convergence $(($CHI2[3] - $CHI2[1]))"
977  fi
978  done
979 }
980 
981 
982 # -----------------------------------------------------------------------------------------------------
983 # Stage D.
984 # This stage can be used to determine the rotations of the strings and z-positions of the anchors.
985 # It is followed by a determination of the positions of the strings, tripods and modules.
986 #
987 # -----------------------------------------------------------------------------------------------------
988 function stage_D()
989 {
990  cat>$TMPDIR/acoustics_fit_parameters.txt<<EOF
991 `egrep Tmax_s $WORKDIR/acoustics_fit_parameters.txt`
992 Nmin = 3;
993 sigma_s = 50.0e-6;
994 stdev = 10.0;
995 mestimator = 0;
996 option = 1;
997 EOF
998 
999  getChi2 CHI2\[1\]
1000 
1002  set_variable NUMBER_OF_ITERATIONS 2000
1003 
1004  for DX_M in 0.10; do # determine rotation of string and z-position of anchors
1005 
1006  let "A_RAD = $DX_M / $RADIUS_M" # use maximal horizontal distance between T-bar and emitter/hydrophone
1007 
1008  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
1009 
1010  CHI2[3]=$CHI2[1]
1011 
1012  for STRING in $STRINGS[*]; do
1015  done
1016 
1017  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
1018  break
1019  fi
1020  done
1021 
1022  if (( $N >= $NUMBER_OF_ITERATIONS )); then
1023  warning "reached maximum number of iterations $N - convergence $(($CHI2[3] - $CHI2[1]))"
1024  fi
1025  done
1026 
1027  getChi2 CHI2\[1\]
1028 
1029  set_variable NUMBER_OF_ITERATIONS 2000
1030 
1031  for DX_M in 0.05; do # determine position of strings and tripods
1032 
1033  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
1034 
1035  CHI2[3]=$CHI2[1]
1036 
1037  for STRING in $STRINGS[*]; do
1042  done
1043 
1044  for ID in ${(k)TRIPODS}; do
1045  fitPositionOfTripod $ID X $DX_M
1046  fitPositionOfTripod $ID Y $DX_M
1047  fitPositionOfTripod $ID Z $DX_M
1048  done
1049 
1050  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
1051  break
1052  fi
1053  done
1054 
1055  if (( $N >= $NUMBER_OF_ITERATIONS )); then
1056  warning "reached maximum number of iterations $N - convergence $(($CHI2[3] - $CHI2[1]))"
1057  fi
1058  done
1059 
1060  getChi2 CHI2\[1\]
1061 
1062  set_variable NUMBER_OF_ITERATIONS 1000
1063 
1064  for DX_M in 0.05; do # determine (z) positions of modules and (x,y) positions of strings
1065 
1066  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
1067 
1068  CHI2[3]=$CHI2[1]
1069 
1070  for STRING in $STRINGS[*]; do
1071 
1072  for (( FLOOR = 1; $FLOOR <= 18; FLOOR += 1 )); do
1073  fitPositionOfModule $STRING $FLOOR $DX_M
1074  done
1075 
1078  done
1079 
1080  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
1081  break
1082  fi
1083  done
1084 
1085  if (( $N >= $NUMBER_OF_ITERATIONS )); then
1086  warning "reached maximum number of iterations $N - convergence $(($CHI2[3] - $CHI2[1]))"
1087  fi
1088  done
1089 }
then cat $TRIPOD_INITIAL<< EOF1 256877.5 4743716.7-2438.42 256815.5 4743395.0-2435.53 257096.2 4743636.0-2439.5EOFfiJEditDetector-a $DETECTOR_INITIAL-s"-1 addz -6.9"-o $DETECTOReval`JPrintDetector-a $DETECTOR-O SUMMARY`for STRING in ${STRINGS[*]};do set_variable MODULE`getModule-a $DETECTOR-L"$STRING 0"`JEditDetector-a $DETECTOR-M"$MODULE setz -2.9"-o $DETECTORdonecp-p $TRIPOD_INITIAL $TRIPODJAcoustics.sh $DETECTOR_IDcat > acoustics_trigger_parameters txt<< EOFQ=0.0;TMax_s=0.020;numberOfHits=90;EOFJAcousticsEventBuilder.sh $DETECTOR $RUNS[*]INPUT_FILES=(`ls KM3NeT_ ${(l:8::0::0:) DETECTOR_ID}_0 *${^RUNS}_event.root`) cd $WORKDIRif[!$HOMEDIR-ef $WORKDIR];then cp-p $HOMEDIR/$DETECTOR $WORKDIR cp-p $HOMEDIR/$TRIPOD $WORKDIR cp-p $HOMEDIR/${^INPUT_FILES}$WORKDIR cp-p $HOMEDIR/{acoustics_fit_parameters, acoustics_trigger_parameters, disable, hydrophone, mechanics, sound_velocity, tripod, waveform}.txt $WORKDIRfisource $JPP_DIR/examples/JAcoustics/acoustics-fit-toolkit.shtimer_startinitialise stage_1B > &stage log
then usage $script< detector >< run >< outputfile > fi case set_variable OPTION
Definition: JTuna.sh:26
function stage_1A()
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
function fitRotationOfAnchor()
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter= ' ')
Read test summary.
clean eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY set_variable STRING
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
then JLigier sh continue fi cat
Definition: JDAQDriver.sh:51
o $QUALITY_ROOT d $DEBUG!JPlot1D f
Definition: JDataQuality.sh:66
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
static const double H
Planck constant [eV s].
exit
Definition: JPizza.sh:36
then fatal Number of tripods
Definition: JFootprint.sh:45
function stage_0()
then usage $script< detector specific pre-calibration script >< option > nAuxiliary script to make scan of pre stretching of detector strings(see JEditDetector)." "\nPossible options
data_type r[M+1]
Definition: JPolint.hh:779
then usage $script< input file > nFor possible input files
Definition: JMechanics.sh:23
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
then usage source $script nThis script contains auxiliary functions for the pre calibration of specific detectors nIt should be sourced by the detector specific scripts fi source JAcousticsToolkit sh set_variable WORKDIR pwd set_variable TMPDIR $WORKDIR typeset A TRIPODS typeset a CHI2 set_variable PRECISION set_variable EPSILON set_variable RADIUS_M function initialise()
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
then fatal Wrong number of arguments fi JConvertDetectorFormat a o
function fixTripods()
then echo Variable JPP_DIR undefined exit fi source $JPP_DIR setenv sh $JPP_DIR &dev null if do_usage *then usage source $script nToolkit for acoustics scripts fi function get_tripods()
function fitPositionOfModule()
then echo
do JCanberra a $DETECTOR f $INPUT_FILE o $WORKDIR canberra[${EMITTER}\] root T $WORKDIR tripod txt V $WORKDIR sound_velocity txt M $WORKDIR mechanics txt H $WORKDIR hydrophone txt E $EMITTER $DISABLE d $DEBUG!done kill_child_processes_at_exit attach getModule a $DETECTOR typeset Z STRING typeset Z FLOOR for STRING in $STRINGS[*]
Definition: JCanberra.sh:68
function stage_1B()
function setCenter()
then fatal Invalid string $STRING
then echo Variable JPP_DIR undefined exit fi source $JPP_DIR setenv sh $JPP_DIR &dev null set_variable
Definition: JAcoustics.sh:21
case $OPTION in clean clean
then echo Variable JPP_DIR undefined exit fi source $JPP_DIR setenv sh $JPP_DIR if do_usage *then usage $script[(input file)+] fi set_variable DEBUG set_variable WORKDIR TMPDIR
do set_variable OUTPUT_DIRECTORY $WORKDIR T
function fitPositionOfString()
#define ERROR(A)
Definition: JMessage.hh:66
function fitStretchingOfString()
then echo Variable JPP_DIR undefined exit fi source $JPP_DIR setenv sh $JPP_DIR &dev null set_variable DEBUG set_variable WORKDIR
Definition: JLegolas.sh:20
function getChi2()
then awk F
* usage
set_array INPUT_FILES argv[2,$((START_INDEX_STRING-1))] set_array STRINGS
do JPlot2D f $WORKDIR detector root
function fitPositionOfTripod()
then $DIR JKatoomba a $DETECTOR o $WORKDIR katoomba root T $TRIPOD n sigma_s
then JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JMuonPath.sh:47
then JCalibrateToT a
Definition: JTuneHV.sh:116
then set_variable MODULE getModule a $DETECTOR L $STRING $FLOOR JEditDetector a $DETECTOR M $MODULE add $X o $DETECTOR else echo No update of detector $DETECTOR
static const JPBS_t HYDROPHONE(4, 5)
PBS of hydrophone
then if[[!-f $DETECTOR]] then JDetector sh $DETECTOR fi cat $WORKDIR trigger_parameters txt<< EOFtrigger3DMuon.enabled=1;trigger3DMuon.numberOfHits=5;trigger3DMuon.gridAngle_deg=1;ctMin=0.0;TMaxLocal_ns=15.0;EOF set_variable TRIGGEREFFICIENCY_TRIGGERED_EVENTS_ONLY INPUT_FILES=() for((i=1;$i<=$NUMBER_OF_RUNS;++i));do JSirene.sh $DETECTOR $JPP_DATA/genhen.km3net_wpd_V2_0.evt.gz $WORKDIR/sirene_ ${i}.root JTriggerEfficiency.sh $DETECTOR $DETECTOR $WORKDIR/sirene_ ${i}.root $WORKDIR/trigger_efficiency_ ${i}.root $WORKDIR/trigger_parameters.txt $JPP_DATA/PMT_parameters.txt INPUT_FILES+=($WORKDIR/trigger_efficiency_ ${i}.root) done for ANGLE_DEG in $ANGLES_DEG[*];do set_variable SIGMA_NS 3.0 set_variable OUTLIERS 3 set_variable OUTPUT_FILE $WORKDIR/matrix\[${ANGLE_DEG}\deg\].root $JPP_DIR/examples/JReconstruction-f"$INPUT_FILES[*]"-o $OUTPUT_FILE-S ${SIGMA_NS}-A ${ANGLE_DEG}-O ${OUTLIERS}-d ${DEBUG}--!fiif[[$OPTION=="plot"]];then if((0));then for H1 in h0 h1;do JPlot1D-f"$WORKDIR/matrix["${^ANGLES_DEG}" deg].root:${H1}"-y"1 2e3"-Y-L TR-T""-\^"number of events [a.u.]"-> o chi2
Definition: JMatrixNZ.sh:106
esac typeset A BUFFER $JPP_DIR examples JAcoustics JCreep f $INPUT_FILE BUFFER
Definition: JCreep.sh:34
then display $WORKDIR
Definition: plot-Domino.sh:128
function stage_2()
function fitPositionOfAnchor()
then cp
no fit printf nominal n $STRING awk v X
function getCenter()
do set_variable MODULE getModule a $WORKDIR detector_a datx L $STRING JEditDetector a $WORKDIR detector_a datx M $MODULE setz o $WORKDIR detector_a datx JEditDetector a $WORKDIR detector_b datx M $MODULE setz o $WORKDIR detector_b datx done echo Output stored at $WORKDIR detector_a datx and $WORKDIR tripod_a txt JDrawDetector2D a $WORKDIR detector_a datx a $WORKDIR detector_b datx L BL o detector $FORMAT $BATCH JDrawDetector2D T $WORKDIR tripod_a txt T $WORKDIR tripod_b txt L BL o tripod $FORMAT $BATCH JCompareDetector a $WORKDIR detector_a datx b $WORKDIR detector_b datx o $WORKDIR abc root &dev null for KEY in X Y Z
possible values
then echo Creating output directory
Definition: JTuneHV.sh:83
set_variable DETECTOR
do set_variable DETECTOR_TXT $WORKDIR detector
data_type v[N+1][M+1]
Definition: JPolint.hh:777
double u[N+1]
Definition: JPolint.hh:776
function fixStrings()
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
source $JPP_DIR setenv csh $JPP_DIR &dev null eval JShellParser o a A
function stage_3()
script
Definition: JAcoustics.sh:2
*fatal Wrong option $OPTION
then fatal Invalid tripod $TRIPOD
esac $JPP_BIN JLogger sh $LOGGER until pgrep JGetMessage</dev/null > dev null
const JModule & getModule(const JDetector &detector, const JModuleLocation &location)
find module with a given string and floor number
esac done
Definition: JAddHDE.sh:21
function stage_D()
do alias $i