Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JRecalibrateK40.sh
Go to the documentation of this file.
1#!/usr/bin/env zsh
2script=${0##*/}
3
4# ------------------------------------------------------------------------------------------
5#
6# Script to run K40 time calibration following HV tuning.
7#
8# ------------------------------------------------------------------------------------------
9
10if [ -z $JPP_DIR ]; then
11 echo "Variable JPP_DIR undefined."
12 exit
13fi
14
15source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
16
17set_variable: DEBUG CALIBRATION_DEBUG 1
18set_variable: WORKDIR CALIBRATION_WORKDIR `pwd`
19set_variable: DAQ_TIMESLICE CALIBRATION_TIMESLICE JDAQTimesliceL1
20set_variable+ DATABASE_OPTION CALIBRATION_USEPMTID -U
21set_variable+ MODEL CALIBRATION_MODEL -D
22
23if do_usage $*; then
24 usage "$script <detector file> <input file> <input file> <input file>"\
25 "\nThe 1st and 3rd input file should correspond to a data taking run in which the HV settings are complete (e.g. \"vendor\" or \"tuned\")."\
26 "\nThe 2nd input file should correspond to a run with hybrid HV settings."\
27 "\nIn this, half of the PMTs should have the same HV settings as either the 1st or 3rd input file."
28fi
29
30if (( $# == 4 )); then
31 set_variable DETECTOR $argv[1]
32 set_array INPUT_FILES $argv[2,-1]
33else
34 fatal "Wrong number of arguments."
35fi
36
37JCookie.sh
38
39#
40# Get background option for given input file.
41#
42# \param 1 input file
43# \return option
44#
45function get_option()
46{
47 if (( `JPrintTree -f $1 -@ "type = JDAQSummaryslice" -k number_of_entries` > 0 )); then
48 echo rates
49 else
50 echo counts
51 fi
52}
53
54
55#
56# Standard calibration.
57#
58# \param 1 detector
59# \param 2 input file
60#
61function calibrate()
62{
63 JPrintDAQHeader -f $2 | read ID RUN FRAME_INDEX UTC
64
65 JCalibrateK40 \
66 -a $1 \
67 -f $2 \
68 -C $DAQ_TIMESLICE \
69 -o $WORKDIR/monitor_${RUN}.root \
70 -b `get_option $2` \
71 -d $DEBUG --!
72
73 JMergeCalibrateK40 \
74 -f $WORKDIR/monitor_${RUN}.root \
75 -o $WORKDIR/merge_${RUN}.root \
76 -@ "LIVETIME_S = 10" \
77 -d $DEBUG
78
79 JConvertDetectorFormat \
80 -a $1 \
81 -o $WORKDIR/detector_${RUN}.datx
82
83 JFitK40 \
84 -a $WORKDIR/detector_${RUN}.datx \
85 -f $WORKDIR/merge_${RUN}.root \
86 -o $WORKDIR/fit_${RUN}.root \
87 $MODEL \
88 -A \
89 -w \
90 -d $DEBUG
91}
92
93
94#
95# Hybrid calibration.
96#
97# \param 1 detector
98# \param 2 reference run
99# \param 3 input file
100#
101function hybrid()
102{
103 JPrintDAQHeader -f $3 | read ID RUN FRAME_INDEX UTC
104
105 JTDC \
106 -D $DETECTOR_ID \
107 -r "$2 $RUN" \
108 $DATABASE_OPTION \
109 -o "$WORKDIR/TDC_${2}_${RUN}.txt"
110
111 JCalibrateK40 \
112 -a $1 \
113 -f $3 \
114 -C $DAQ_TIMESLICE \
115 -o $WORKDIR/monitor_${RUN}.root \
116 -b `get_option $3` \
117 -d $DEBUG --!
118
119 JMergeCalibrateK40 \
120 -f $WORKDIR/monitor_${RUN}.root \
121 -o $WORKDIR/merge_${RUN}.root \
122 -@ "LIVETIME_S = 10" \
123 -d $DEBUG
124
125 JConvertDetectorFormat \
126 -a $1 \
127 -o $WORKDIR/detector_${RUN}.datx
128
129 JFitK40 \
130 -a $WORKDIR/detector_${RUN}.datx \
131 -f $WORKDIR/merge_${RUN}.root \
132 -o $WORKDIR/fit_${RUN}.root \
133 $MODEL \
134 -A \
135 -w \
136 -! $WORKDIR/TDC_${2}_${RUN}.txt \
137 -d $DEBUG
138}
139
140
141# Get run numbers
142
143eval `JPrintDetector -a $DETECTOR -O IDENTIFIER`
144
145RUNS=()
146
147for INPUT_FILE in $INPUT_FILES[*]; do
148
149 JPrintDAQHeader -f $INPUT_FILE | read ID RUN FRAME_INDEX UTC
150
151 if (( $ID != $DETECTOR_ID )); then
152 fatal "Detector identifier from $INPUT_FILE $ID != $DETECTOR_ID"
153 fi
154
155 RUNS+=($RUN)
156
157done
158
159
160calibrate $DETECTOR ${INPUT_FILES[1]}
161
162hybrid $WORKDIR/detector_${RUNS[1]}.datx ${RUNS[1]} ${INPUT_FILES[2]}
163
164hybrid $WORKDIR/detector_${RUNS[2]}.datx ${RUNS[2]} ${INPUT_FILES[3]}