3# \author rgruiz, mdejong
7# ------------------------------------------------------------------------------------------
9# Script to run complete PMT calibration.
11# ------------------------------------------------------------------------------------------
13if [ -z $JPP_DIR ]; then
14 echo "Variable JPP_DIR undefined."
18source $JPP_DIR/setenv.sh $JPP_DIR
20set_variable: WORKDIR CALIBRATION_WORKDIR ./
21set_variable: DEBUG CALIBRATION_DEBUG 2
22set_variable+ OPTION CALIBRATION_OPTION -A
23set_variable+ ANGLE_DEPENDENCE CALIBRATION_ANGLE_DEPENDENCE -D
24set_variable+ NOISE_DEPENDENCE CALIBRATION_NOISE_DEPENDENCE -B
25set_variable: TEROSTAT_R1 CALIBRATION_TEROSTAT_R1 1.0
26set_variable: BELL_SHAPE CALIBRATION_BELL_SHAPE 2.0
27set_variable: QE_MAX CALIBRATION_QEMAX 2.0
28set_variable: MU CALIBRATION_MU 0.25
29set_variable: TOT_MIN_NS CALIBRATION_TOT_MIN_NS 0.0
30set_variable: TOT_MAX_NS CALIBRATION_TOT_MAX_NS 35.0
33 usage "$script <detector_file> (input file)+ <PMT parameters file>"
37 fatal "Wrong number of arguments."
40set_variable DETECTOR $argv[1]
41set_array INPUT_FILES $argv[2,-2]
42set_variable PMT_FILE $argv[-1]
44if [[ ! -d $WORKDIR ]]; then
50eval `JPrintDetector -a $DETECTOR -O IDENTIFIER`
51eval `JPrintDetector -a $DETECTOR -O SUMMARY`
53debug "$DETECTOR $DETECTOR_ID"
55if [[ "$DETECTOR_ID" != [1-9][0-9]* ]]; then
56 fatal "Invalid detector identifier \"$DETECTOR_ID\"."
61set_variable RUNSETUPID
67for INPUT_FILE in $INPUT_FILES[*]; do
69 JPrintDAQHeader -f $INPUT_FILE | read ID RUN FRAME_INDEX UTC
71 if (( $DETECTOR_ID != $ID )); then
72 fatal "Inconsistent detector identifier $DETECTOR_ID != $ID."
75 JRuns -D $DETECTOR_ID -@ "RUN = $RUN" -F RUNSETUPID | read SETUP
77 debug "Run $RUN -> $SETUP."
79 if (( $RUN < $RANGE[1] )); then; RANGE[1]=$RUN; fi
80 if (( $RUN > $RANGE[2] )); then; RANGE[2]=$RUN; fi
82 if [[ -z "$SETUP" ]]; then
83 fatal "Missing setup identifier for run $RUN."
85 if [[ -n "$RUNSETUPID" && $RUNSETUPID != $SETUP ]]; then
86 fatal "Inconsistent run setup identifiers $RUNSETUPID != $SETUP $RUN."
89 set_variable RUNSETUPID $SETUP
95for DAQ_TIMESLICE in JDAQTimesliceL1 JDAQTimeslice; do
97 VALUES=(`JPrintTree -f${^INPUT_FILES} -@ "type = ${DAQ_TIMESLICE}" -k number_of_entries`)
99 if [[ -n "$VALUES" ]] && (( ${#VALUES} == ${#INPUT_FILES} )); then
104if [[ -z "$VALUES" ]] || (( ${#VALUES} != ${#INPUT_FILES} )); then
105 fatal "No valid data in input file(s)."
126# PMT gain and gain spread
128set_variable OUTPUT_FILE $WORKDIR/KM3NeT_${(l:8::0::0:)DETECTOR_ID}_${(l:8::0::0:)RANGE[1]}-${(l:8::0::0:)RANGE[2]}_%.root
133 -o ${OUTPUT_FILE/\%/calibratetot} \
140 -f ${OUTPUT_FILE/\%/calibratetot} \
141 -o ${OUTPUT_FILE/\%/mergetot} \
148 -f ${OUTPUT_FILE/\%/mergetot} \
149 -o ${OUTPUT_FILE/\%/fittot} \
152 -x "$TOT_MIN_NS $TOT_MAX_NS" \
163 -o ${OUTPUT_FILE/\%/calibratek40} \
170 -f ${OUTPUT_FILE/\%/calibratek40} \
171 -o ${OUTPUT_FILE/\%/mergek40} \
177 -@ "TEROSTAT_R1 = $TEROSTAT_R1" \
178 -@ "BELL_SHAPE = $BELL_SHAPE" \
180 -f ${OUTPUT_FILE/\%/mergek40} \
181 -o ${OUTPUT_FILE/\%/fitk40} \
197 -T "$TOT_MIN_NS $TOT_MAX_NS" \