Jpp  17.0.0-rc.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 latest
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 # Purge comments from detector file.
135 #
136 # -----------------------------------------------------------------------------------------------------
137 function purge()
138 {
139  JConvertDetectorFormat -a $DETECTOR -o $DETECTOR -r -d 0 >& /dev/null
140 }
141 
142 
143 # -----------------------------------------------------------------------------------------------------
144 # Get center-of-gravity of tripods.
145 #
146 # \return x y z
147 # -----------------------------------------------------------------------------------------------------
148 function getCenter()
149 {
150  typeset -A __TRIPODS__
151 
152  get_tripods $TRIPOD __TRIPODS__
153 
154  let "X = 0.0"
155  let "Y = 0.0"
156  let "Z = 0.0"
157 
158  if (( ${#__TRIPODS__} >= 1 )); then
159 
160  for _X _Y _Z in `echo ${(@v)__TRIPODS__}`; do
161  let "X = $X + $_X"
162  let "Y = $Y + $_Y"
163  let "Z = $Z + $_Z"
164  done
165 
166  let "X = $X / ${#__TRIPODS__}"
167  let "Y = $Y / ${#__TRIPODS__}"
168  let "Z = $Z / ${#__TRIPODS__}"
169  fi
170 
171  printf "%15.5f %15.5f %15.5f" $X $Y $Z
172 }
173 
174 
175 # -----------------------------------------------------------------------------------------------------
176 # Set detector and tripods to given center-of-gravity.
177 #
178 # \param 1 X
179 # \param 2 Y
180 # \param 3 Z
181 # -----------------------------------------------------------------------------------------------------
182 function setCenter()
183 {
184  getCenter | read X Y Z
185 
186  let "X = $X - $1"
187  let "Y = $Y - $2"
188  let "Z = $Z - $3"
189 
190  printf "Fix center %15.5f %15.5f %15.5f\n" $X $Y $Z
191 
192  JEditTripod -f $TRIPOD -T "-1 sub $X $Y $Z" -d 0 >& /dev/null
193  JEditDetector -a $DETECTOR -S "-1 sub $X $Y $Z" -o $DETECTOR -d 0 >& /dev/null
194 }
195 
196 
197 # -----------------------------------------------------------------------------------------------------
198 # Evaluate current chi2 and set value in CHI2 at given index.
199 #
200 # \param 1 index
201 # -----------------------------------------------------------------------------------------------------
202 function setChi2()
203 {
204  for (( m = 0; $m != 3; ++m )); do
205 
206  rm -f $TMPDIR/katoomba.{root,log} >& /dev/null
207 
208  date >& $TMPDIR/katoomba.log
209 
210  JKatoomba \
211  -a $DETECTOR \
212  -f "$INPUT_FILES[*]" \
213  -o $TMPDIR/katoomba.root \
214  -T $TRIPOD \
215  -Y $WORKDIR/transmitter.txt \
216  -V $WORKDIR/sound_velocity.txt \
217  -M $WORKDIR/mechanics.txt \
218  -@ $TMPDIR/acoustics_fit_parameters.txt \
219  -! $WORKDIR/disable.txt \
220  ${HYDROPHONE:+-H $WORKDIR/hydrophone.txt} \
221  -F 2 \
222  -u \
223  -d 2 --! >>& $TMPDIR/katoomba.log
224 
225  ERROR=$?
226 
227  if (( $ERROR == 0 )); then
228 
229  let "VALUE = $(JPrintResult -f $TMPDIR/katoomba.root:chi2 -F GetMean)" >>& $TMPDIR/katoomba.log
230 
231  ERROR=$?
232 
233  if (( $ERROR == 0 )); then
234 
235  eval CHI2\[$1\]=$VALUE
236 
237  return
238  else
239  printf "warning: exit code let %d\n" $ERROR
240  fi
241  else
242  printf "warning: exit code JKatoomba %d\n" $ERROR
243  fi
244 
245  # backup error status
246 
247  set_variable UDIR `mktemp -d $WORKDIR/XXXXXX`
248 
249  cp -p $TMPDIR/katoomba.log $UDIR
250  cp -p $TMPDIR/katoomba.root $UDIR
251  cp -p $DETECTOR $UDIR
252  cp -p $TRIPOD $UDIR
253  cp -p $WORKDIR/transmitter.txt $UDIR
254 
255  printf "warning: backup %s\n" $UDIR
256  done
257 
258  printf "warning: no valid chi2 -> exit\n"
259  exit 1
260 }
261 
262 
263 # -----------------------------------------------------------------------------------------------------
264 # Fit given coordinate of string position.
265 #
266 # \param 1 string identifier
267 # \param 2 coordinate (X|Y|Z)
268 # \param 3 step
269 # -----------------------------------------------------------------------------------------------------
271 {
272  typeset -A BUFFER
273 
274  BUFFER=(X 0.0 Y 0.0 Z 0.0)
275 
276  BUFFER[$2]=$3
277 
278  if [[ "$2" == "Z" ]]; then
279  OPTION=-s # optical modules only
280  else
281  OPTION=-S # all modules
282  fi
283 
284  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
285 
286  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
287 
288  JEditDetector -a $DETECTOR $OPTION "$1 add ${(v)BUFFER}" -o $DETECTOR -d 0 >& /dev/null
289 
290  setChi2 2
291 
292  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
293 
294  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
295 
296  break
297  fi
298 
299  CHI2[1]=$CHI2[2]
300  done
301 
302  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
303 
304  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
305 
306  JEditDetector -a $DETECTOR $OPTION "$1 sub ${(v)BUFFER}" -o $DETECTOR -d 0 >& /dev/null
307 
308  setChi2 2
309 
310  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
311 
312  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
313 
314  break
315  fi
316 
317  CHI2[1]=$CHI2[2]
318  done
319 
320  printf "string %04d %s %6.4f %6d %8.4f\n" $1 $2 $3 $N $CHI2[1]
321 }
322 
323 
324 # -----------------------------------------------------------------------------------------------------
325 # Fit stretching of string.
326 #
327 # \param 1 string identifier
328 # \param 2 multiplication factor
329 # -----------------------------------------------------------------------------------------------------
331 {
332  let "Z = $CAN_ZMAX_M * $2"
333 
334  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
335 
336  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
337 
338  JEditDetector -a $DETECTOR -s "$1 mul $2" -s "$1 sub 0.0 0.0 $Z" -o $DETECTOR -d 0 >& /dev/null
339 
340  setChi2 2
341 
342  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
343 
344  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
345 
346  break
347  fi
348 
349  CHI2[1]=$CHI2[2]
350  done
351 
352  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
353 
354  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
355 
356  JEditDetector -a $DETECTOR -s "$1 add 0.0 0.0 $Z" -s "$1 div $2" -o $DETECTOR -d 0 >& /dev/null
357 
358  setChi2 2
359 
360  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
361 
362  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
363 
364  break
365  fi
366 
367  CHI2[1]=$CHI2[2]
368  done
369 
370  printf "string %04d M %6.4f %6d %8.4f\n" $1 $2 $N $CHI2[1]
371 }
372 
373 
374 # -----------------------------------------------------------------------------------------------------
375 # Fit given coordinate of tripod position.
376 #
377 # \param 1 tripod identifier
378 # \param 2 coordinate (X|Y|Z)
379 # \param 3 step
380 # -----------------------------------------------------------------------------------------------------
382 {
383  typeset -A BUFFER
384 
385  BUFFER=(X 0.0 Y 0.0 Z 0.0)
386 
387  BUFFER[$2]=$3
388 
389  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
390 
391  cp $TRIPOD $TMPDIR/tripod.txt
392 
393  JEditTripod -f $TRIPOD -T "$1 add ${(v)BUFFER}" -r -d 0 >& /dev/null
394 
395  setChi2 2
396 
397  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
398 
399  mv $TMPDIR/tripod.txt $TRIPOD
400 
401  break
402  fi
403 
404  CHI2[1]=$CHI2[2]
405  done
406 
407  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
408 
409  cp $TRIPOD $TMPDIR/tripod.txt
410 
411  JEditTripod -f $TRIPOD -T "$1 sub ${(v)BUFFER}" -r -d 0 >& /dev/null
412 
413  setChi2 2
414 
415  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
416 
417  mv $TMPDIR/tripod.txt $TRIPOD
418 
419  break
420  fi
421 
422  CHI2[1]=$CHI2[2]
423  done
424 
425  printf "tripod %2d %s %6.4f %6d %8.4f\n" $1 $2 $3 $N $CHI2[1]
426 }
427 
428 
429 # -----------------------------------------------------------------------------------------------------
430 # Fit module z-position.
431 #
432 # \param 1 string identifier
433 # \param 2 floor
434 # \param 3 step
435 # -----------------------------------------------------------------------------------------------------
437 {
438  typeset -A BUFFER
439 
440  BUFFER=(X 0.0 Y 0.0 Z $3)
441 
442  set_variable NUMBER_OF_STEPS 10 # limit number of steps
443  set_variable MODULE `getModule -a $DETECTOR -L "$1 $2"`
444 
445  for (( i=0 ; $i != $NUMBER_OF_STEPS && $N != $NUMBER_OF_ITERATIONS; ++i, ++N )); do
446 
447  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
448 
449  JEditDetector -a $DETECTOR -M "$MODULE add ${(v)BUFFER}" -o $DETECTOR -d 0 >& /dev/null
450 
451  setChi2 2
452 
453  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
454 
455  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
456 
457  break
458  fi
459 
460  CHI2[1]=$CHI2[2]
461  done
462 
463  for (( i=0 ; $i != $NUMBER_OF_STEPS && $N != $NUMBER_OF_ITERATIONS; ++i, ++N )); do
464 
465  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
466 
467  JEditDetector -a $DETECTOR -M "$MODULE sub ${(v)BUFFER}" -o $DETECTOR -d 0 >& /dev/null
468 
469  setChi2 2
470 
471  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
472 
473  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
474 
475  break
476  fi
477 
478  CHI2[1]=$CHI2[2]
479  done
480 
481  printf "module %04d.%02d %6.4f %6d %8.4f\n" $1 $2 $3 $N $CHI2[1]
482 }
483 
484 
485 # -----------------------------------------------------------------------------------------------------
486 # Fit given coordinate of anchor position.
487 #
488 # Note that the position of the anchor corresponds to the position of the base module in the detector.
489 # The z-position can independently be changed whereas a change in the (x,y) position
490 # affects the complete string (i.e. including optical modules).
491 #
492 # \param 1 string identifier
493 # \param 2 coordinate (X|Y|Z)
494 # \param 3 step
495 # -----------------------------------------------------------------------------------------------------
497 {
498  typeset -A BUFFER
499 
500  BUFFER=(X 0.0 Y 0.0 Z 0.0)
501 
502  BUFFER[$2]=$3
503 
504  if [[ "$2" == "Z" ]]; then
505 
506  set_variable MODULE `getModule -a $DETECTOR -L "$1 0"`
507 
508  ADD="-M $MODULE add ${(v)BUFFER}" # base module only
509  SUB="-M $MODULE sub ${(v)BUFFER}" # base module only
510  else
511  ADD="-S $1 add ${(v)BUFFER}" # all modules
512  SUB="-S $1 sub ${(v)BUFFER}" # all modules
513  fi
514 
515  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
516 
517  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
518 
519  JEditDetector -a $DETECTOR $ADD -o $DETECTOR -d 0 >& /dev/null
520 
521  setChi2 2
522 
523  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
524 
525  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
526 
527  break
528  fi
529 
530  CHI2[1]=$CHI2[2]
531  done
532 
533  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
534 
535  cp $DETECTOR $TMPDIR/detector.${DETECTOR:e}
536 
537  JEditDetector -a $DETECTOR $SUB -o $DETECTOR -d 0 >& /dev/null
538 
539  setChi2 2
540 
541  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
542 
543  mv $TMPDIR/detector.${DETECTOR:e} $DETECTOR
544 
545  break
546  fi
547 
548  CHI2[1]=$CHI2[2]
549  done
550 
551  printf "anchor %04d %s %6.4f %6d %8.4f\n" $1 $2 $3 $N $CHI2[1]
552 }
553 
554 
555 # -----------------------------------------------------------------------------------------------------
556 # Fit rotation of anchor.
557 #
558 # Note that a rotation of the anchor corresponds to a change of the relative positions of
559 # the hydrophone and emitter with respect to the T-bar.
560 #
561 # \param 1 string identifier
562 # \param 2 rotation angle [rad]
563 # -----------------------------------------------------------------------------------------------------
565 {
566  let "ROT = $2"
567 
568  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
569 
570  cp $WORKDIR/hydrophone.txt $TMPDIR/hydrophone.txt
571  cp $WORKDIR/transmitter.txt $TMPDIR/transmitter.txt
572 
573  JEditHydrophone -f $WORKDIR/hydrophone.txt -S "$1 rot $ROT" -r -d 0 >& /dev/null
574  JEditTransmitter -f $WORKDIR/transmitter.txt -S "$1 rot $ROT" -r -d 0 >& /dev/null
575 
576  setChi2 2
577 
578  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
579 
580  mv $TMPDIR/hydrophone.txt $WORKDIR/hydrophone.txt
581  mv $TMPDIR/transmitter.txt $WORKDIR/transmitter.txt
582 
583  break
584  fi
585 
586  CHI2[1]=$CHI2[2]
587  done
588 
589  let "ROT = -1.0 * $ROT"
590 
591  for (( ; $N != $NUMBER_OF_ITERATIONS; ++N )); do
592 
593  cp $WORKDIR/hydrophone.txt $TMPDIR/hydrophone.txt
594  cp $WORKDIR/transmitter.txt $TMPDIR/transmitter.txt
595 
596  JEditHydrophone -f $WORKDIR/hydrophone.txt -S "$1 rot $ROT" -r -d 0 >& /dev/null
597  JEditTransmitter -f $WORKDIR/transmitter.txt -S "$1 rot $ROT" -r -d 0 >& /dev/null
598 
599  setChi2 2
600 
601  if (( $CHI2[2] >= $CHI2[1] - $PRECISION )); then
602 
603  mv $TMPDIR/hydrophone.txt $WORKDIR/hydrophone.txt
604  mv $TMPDIR/transmitter.txt $WORKDIR/transmitter.txt
605 
606  break
607  fi
608 
609  CHI2[1]=$CHI2[2]
610  done
611 
612  printf "string %04d R %6.4f %6d %8.4f\n" $1 $2 $N $CHI2[1]
613 }
614 
615 
616 # -----------------------------------------------------------------------------------------------------
617 # Stage 0.
618 # This stage can be used to determine the (x,y,z) positions of tripods when a number of strings is fixed.
619 #
620 # -----------------------------------------------------------------------------------------------------
621 function stage_0()
622 {
623  cat>$TMPDIR/acoustics_fit_parameters.txt<<EOF
624 `egrep Tmax_s $WORKDIR/acoustics_fit_parameters.txt`
625 Nmin = 3;
626 sigma_s = 100.0e-6;
627 stdev = 10.0;
628 mestimator = 0;
629 option = 1;
630 EOF
631 
632  if (( ${#STRINGS} > 0 )); then
633  JEditDetector -a $DETECTOR -o $TMPDIR/detector_0.datx -k "$STRINGS[*]" -d 0 >& /dev/null
634  JEditDetector -a $DETECTOR -o $DETECTOR -r "$STRINGS[*]" -d 0 >& /dev/null
635  fi
636 
637  setChi2 1
638 
639  set_variable NUMBER_OF_ITERATIONS 1000
640 
641  for DX_M in 0.2 0.1; do # determine (x,y,z) positions of tripods
642 
643  let "A_RAD = $DX_M / $RADIUS_M" # use maximal horizontal distance between T-bar and emitter/hydrophone
644 
645  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
646 
647  CHI2[3]=$CHI2[1]
648 
649  for ID in ${(k)TRIPODS}; do
650  fitPositionOfTripod $ID X $DX_M
651  fitPositionOfTripod $ID Y $DX_M
652  fitPositionOfTripod $ID Z $DX_M
653  done
654 
655  for STRING in $TRANSMITTERS[*]; do
660  done
661 
662  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
663  break
664  fi
665  done
666 
667  purge
668 
669  if (( $N >= $NUMBER_OF_ITERATIONS )); then
670  printf "warning: reached maximum number of iterations %d - convergence %7.3f\n" $N $(($CHI2[3] - $CHI2[1]))
671  fi
672  done
673 
674  if (( ${#STRINGS} > 0 )); then
675  JMergeDetector -a $DETECTOR -a $TMPDIR/detector_0.datx -o $DETECTOR >& /dev/null
676  fi
677 
678  purge
679 }
680 
681 
682 # -----------------------------------------------------------------------------------------------------
683 # Stage 1A.
684 # This stage can be used to roughly determine the positions of the strings, tripods and modules.
685 # During this procedure, the strings are kept vertical in the global fits.
686 #
687 # -----------------------------------------------------------------------------------------------------
688 function stage_1A()
689 {
690  cat>$TMPDIR/acoustics_fit_parameters.txt<<EOF
691 `egrep Tmax_s $WORKDIR/acoustics_fit_parameters.txt`
692 Nmin = 3;
693 sigma_s = 250.0e-6;
694 stdev = 10.0;
695 mestimator = 2;
696 option = 0;
697 EOF
698 
699  setChi2 1
700 
701  set_variable NUMBER_OF_ITERATIONS 1000
702 
703  for DX_M in 0.5 0.2; do # determine (x,y,z) positions of strings and tripods
704 
705  let "A_RAD = $DX_M / $RADIUS_M" # use maximal horizontal distance between T-bar and emitter/hydrophone
706 
707  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
708 
709  CHI2[3]=$CHI2[1]
710 
711  for STRING in $STRINGS[*]; do
715  done
716 
717  for ID in ${(k)TRIPODS}; do
718  fitPositionOfTripod $ID X $DX_M
719  fitPositionOfTripod $ID Y $DX_M
720  fitPositionOfTripod $ID Z $DX_M
721  done
722 
723  for STRING in $TRANSMITTERS[*]; do
728  done
729 
730  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
731  break
732  fi
733  done
734 
735  purge
736 
737  if (( $N >= $NUMBER_OF_ITERATIONS )); then
738  printf "warning: reached maximum number of iterations %d - convergence %7.3f\n" $N $(($CHI2[3] - $CHI2[1]))
739  fi
740  done
741 
742  setChi2 1
743 
744  set_variable NUMBER_OF_ITERATIONS 2000
745 
746  for DX_M in 0.1; do # determine (z) positions of modules
747 
748  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
749 
750  CHI2[3]=$CHI2[1]
751 
752  for STRING in $STRINGS[*]; do
753  for (( FLOOR = 1; $FLOOR <= 18; FLOOR += 1 )); do
754  fitPositionOfModule $STRING $FLOOR $DX_M
755  done
756  done
757 
758  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
759  break
760  fi
761  done
762 
763  purge
764 
765  if (( $N >= $NUMBER_OF_ITERATIONS )); then
766  printf "warning: reached maximum number of iterations %d - convergence %7.3f\n" $N $(($CHI2[3] - $CHI2[1]))
767  fi
768  done
769 }
770 
771 
772 # -----------------------------------------------------------------------------------------------------
773 # Stage 1B.
774 # This stage can be used to determine the z-positions and stretching of individual strings.
775 #
776 # -----------------------------------------------------------------------------------------------------
777 function stage_1B()
778 {
779  cat>$TMPDIR/acoustics_fit_parameters.txt<<EOF
780 `egrep Tmax_s $WORKDIR/acoustics_fit_parameters.txt`
781 Nmin = 3;
782 sigma_s = 100.0e-6;
783 stdev = 10.0;
784 mestimator = 0;
785 option = 1;
786 EOF
787 
788  for STRING in $STRINGS[*]; do # determine stretching and (z) position of given string
789 
790  JEditDetector -a $DETECTOR -o $TMPDIR/detector_1.datx -r "$STRING" -d 0 >& /dev/null
791  JEditDetector -a $DETECTOR -o $DETECTOR -k "$STRING" -d 0 >& /dev/null
792 
793  setChi2 1
794 
795  set_variable NUMBER_OF_ITERATIONS 1000
796 
797  for MUL in 0.005 0.001; do
798 
799  DX_M=0.2
800 
801  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
802 
803  CHI2[3]=$CHI2[1]
804 
807 
808  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
809  break
810  fi
811  done
812 
813  if (( $N >= $NUMBER_OF_ITERATIONS )); then
814  printf "warning: reached maximum number of iterations %d - convergence %7.3f\n" $N $(($CHI2[3] - $CHI2[1]))
815  fi
816  done
817 
818  JMergeDetector -a $DETECTOR -a $TMPDIR/detector_1.datx -o $DETECTOR >& /dev/null
819 
820  purge
821  done
822 }
823 
824 
825 # -----------------------------------------------------------------------------------------------------
826 # Stage 2.
827 # This stage can be used to improve the determination the positions of the strings, tripods and modules.
828 #
829 # -----------------------------------------------------------------------------------------------------
830 function stage_2()
831 {
832  cat>$TMPDIR/acoustics_fit_parameters.txt<<EOF
833 `egrep Tmax_s $WORKDIR/acoustics_fit_parameters.txt`
834 Nmin = 3;
835 sigma_s = 100.0e-6;
836 stdev = 10.0;
837 mestimator = 0;
838 option = 1;
839 EOF
840 
841  setChi2 1
842 
843  set_variable NUMBER_OF_ITERATIONS 1000
844 
845  for DX_M in 0.2; do # determine (x,y,z) positions of strings and tripods
846 
847  let "A_RAD = $DX_M / $RADIUS_M" # use maximal horizontal distance between T-bar and emitter/hydrophone
848 
849  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
850 
851  CHI2[3]=$CHI2[1]
852 
853  for STRING in $STRINGS[*]; do
857  done
858 
859  for ID in ${(k)TRIPODS}; do
860  fitPositionOfTripod $ID X $DX_M
861  fitPositionOfTripod $ID Y $DX_M
862  fitPositionOfTripod $ID Z $DX_M
863  done
864 
865  for STRING in $TRANSMITTERS[*]; do
870  done
871 
872  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
873  break
874  fi
875  done
876 
877  purge
878 
879  if (( $N >= $NUMBER_OF_ITERATIONS )); then
880  warning "reached maximum number of iterations $N - convergence $(($CHI2[3] - $CHI2[1]))"
881  fi
882  done
883 
884  setChi2 1
885 
886  set_variable NUMBER_OF_ITERATIONS 2000
887 
888  for DX_M in 0.1; do # determine (z) positions of modules and (x,y) positions of strings
889 
890  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
891 
892  CHI2[3]=$CHI2[1]
893 
894  for STRING in $STRINGS[*]; do
895 
896  for (( FLOOR = 1; $FLOOR <= 18; FLOOR += 1 )); do
897  fitPositionOfModule $STRING $FLOOR $DX_M
898  done
899 
902  done
903 
904  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
905  break
906  fi
907  done
908 
909  purge
910 
911  if (( $N >= $NUMBER_OF_ITERATIONS )); then
912  warning "reached maximum number of iterations $N - convergence $(($CHI2[3] - $CHI2[1]))"
913  fi
914  done
915 }
916 
917 # -----------------------------------------------------------------------------------------------------
918 # Stage 3.
919 # This stage can be used to finalise the determination of the positions of the strings, tripods and modules.
920 #
921 # -----------------------------------------------------------------------------------------------------
922 function stage_3()
923 {
924  cat>$TMPDIR/acoustics_fit_parameters.txt<<EOF
925 `egrep Tmax_s $WORKDIR/acoustics_fit_parameters.txt`
926 Nmin = 3;
927 sigma_s = 50.0e-6;
928 stdev = 10.0;
929 mestimator = 0;
930 option = 1;
931 EOF
932 
933  setChi2 1
934 
935  set_variable NUMBER_OF_ITERATIONS 1000
936 
937  for DX_M in 0.10 0.05; do # determine (x,y,z) positions of strings and tripods
938 
939  let "A_RAD = $DX_M / $RADIUS_M" # use maximal horizontal distance between T-bar and emitter/hydrophone
940 
941  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
942 
943  CHI2[3]=$CHI2[1]
944 
945  for STRING in $STRINGS[*]; do
949  done
950 
951  for ID in ${(k)TRIPODS}; do
952  fitPositionOfTripod $ID X $DX_M
953  fitPositionOfTripod $ID Y $DX_M
954  fitPositionOfTripod $ID Z $DX_M
955  done
956 
957  for STRING in $TRANSMITTERS[*]; do
962  done
963 
964  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
965  break
966  fi
967  done
968 
969  purge
970 
971  if (( $N >= $NUMBER_OF_ITERATIONS )); then
972  warning "reached maximum number of iterations $N - convergence $(($CHI2[3] - $CHI2[1]))"
973  fi
974  done
975 
976  setChi2 1
977 
978  set_variable NUMBER_OF_ITERATIONS 2000
979 
980  for DX_M in 0.05; do # determine (z) positions of modules and (x,y) positions of strings
981 
982  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
983 
984  CHI2[3]=$CHI2[1]
985 
986  for STRING in $STRINGS[*]; do
987 
988  for (( FLOOR = 1; $FLOOR <= 18; FLOOR += 1 )); do
989  fitPositionOfModule $STRING $FLOOR $DX_M
990  done
991 
994  done
995 
996  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
997  break
998  fi
999  done
1000 
1001  purge
1002 
1003  if (( $N >= $NUMBER_OF_ITERATIONS )); then
1004  warning "reached maximum number of iterations $N - convergence $(($CHI2[3] - $CHI2[1]))"
1005  fi
1006  done
1007 }
1008 
1009 
1010 # -----------------------------------------------------------------------------------------------------
1011 # Stage D.
1012 # This stage can be used to determine the rotations of the strings and z-positions of the anchors.
1013 # It is followed by a determination of the positions of the strings, tripods and modules.
1014 #
1015 # -----------------------------------------------------------------------------------------------------
1016 function stage_D()
1017 {
1018  cat>$TMPDIR/acoustics_fit_parameters.txt<<EOF
1019 `egrep Tmax_s $WORKDIR/acoustics_fit_parameters.txt`
1020 Nmin = 3;
1021 sigma_s = 50.0e-6;
1022 stdev = 10.0;
1023 mestimator = 0;
1024 option = 1;
1025 EOF
1026 
1027  setChi2 1
1028 
1030  set_variable NUMBER_OF_ITERATIONS 2000
1031 
1032  for DX_M in 0.10; do # determine rotation of string and z-position of anchors
1033 
1034  let "A_RAD = $DX_M / $RADIUS_M" # use maximal horizontal distance between T-bar and emitter/hydrophone
1035 
1036  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
1037 
1038  CHI2[3]=$CHI2[1]
1039 
1040  for STRING in $STRINGS[*]; do
1043  done
1044 
1045  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
1046  break
1047  fi
1048  done
1049 
1050  purge
1051 
1052  if (( $N >= $NUMBER_OF_ITERATIONS )); then
1053  warning "reached maximum number of iterations $N - convergence $(($CHI2[3] - $CHI2[1]))"
1054  fi
1055  done
1056 
1057  setChi2 1
1058 
1059  set_variable NUMBER_OF_ITERATIONS 2000
1060 
1061  for DX_M in 0.05; do # determine position of strings and tripods
1062 
1063  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
1064 
1065  CHI2[3]=$CHI2[1]
1066 
1067  for STRING in $STRINGS[*]; do
1072  done
1073 
1074  for ID in ${(k)TRIPODS}; do
1075  fitPositionOfTripod $ID X $DX_M
1076  fitPositionOfTripod $ID Y $DX_M
1077  fitPositionOfTripod $ID Z $DX_M
1078  done
1079 
1080  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
1081  break
1082  fi
1083  done
1084 
1085  purge
1086 
1087  if (( $N >= $NUMBER_OF_ITERATIONS )); then
1088  warning "reached maximum number of iterations $N - convergence $(($CHI2[3] - $CHI2[1]))"
1089  fi
1090  done
1091 
1092  setChi2 1
1093 
1094  set_variable NUMBER_OF_ITERATIONS 1000
1095 
1096  for DX_M in 0.05; do # determine (z) positions of modules and (x,y) positions of strings
1097 
1098  for (( N = 0; $N < $NUMBER_OF_ITERATIONS; ++N )); do
1099 
1100  CHI2[3]=$CHI2[1]
1101 
1102  for STRING in $STRINGS[*]; do
1103 
1104  for (( FLOOR = 1; $FLOOR <= 18; FLOOR += 1 )); do
1105  fitPositionOfModule $STRING $FLOOR $DX_M
1106  done
1107 
1110  done
1111 
1112  if (( $CHI2[3] - $CHI2[1] < $EPSILON )); then
1113  break
1114  fi
1115  done
1116 
1117  purge
1118 
1119  if (( $N >= $NUMBER_OF_ITERATIONS )); then
1120  warning "reached maximum number of iterations $N - convergence $(($CHI2[3] - $CHI2[1]))"
1121  fi
1122  done
1123 }
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()
do $JPP JMEstimator M
Definition: JMEstimator.sh:37
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
function setChi2()
data_type r[M+1]
Definition: JPolint.hh:758
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()
clean for KEY in pcal ccal tripod transmitter hydrophone
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
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
function purge()
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
then awk F
* usage
then JConvertDetectorFormat a $DETECTOR[1] o
set_array INPUT_FILES argv[2,$((START_INDEX_STRING-1))] set_array STRINGS
do set_variable SIGMA_NS set_variable OUTLIERS set_variable OUTPUT_FILE matrix[${ALPHA_DEG}\deg\] root $JPP JMatrixNZ a $DETECTOR f $INPUT_FILE o $OUTPUT_FILE S
Definition: JMatrixNZ.sh:58
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
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:756
double u[N+1]
Definition: JPolint.hh:755
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
then usage $script< archive >< detectorfile >< run > nGet tripod
esac done
Definition: JAddHDE.sh:21
function stage_D()
do alias $i