Jpp
Optimize_Voltage.sh
Go to the documentation of this file.
1 #!/bin/zsh
2 
3 #
4 # _ _ _ ____
5 # | | | \ | | | _ \
6 # | | | \| | __ _ _ __ ___ | |_) | ___ __ _ ___ ___ _ __
7 # _ | | | . ` | / _` | | '_ \ / _ \ | _ < / _ \ / _` | / __| / _ \ | '_ \
8 # | |__| | | |\ | | (_| | | | | | | (_) | | |_) | | __/ | (_| | | (__ | (_) | | | | |
9 # \____/ |_| \_| \__,_| |_| |_| \___/ |____/ \___| \__,_| \___| \___/ |_| |_|
10 #
11 #
12 
13 
14 #This script should be launched everytime a new DU is deployed in the sea, and a set of runs with the nanobeacons tuned at different voltages has been taken. It runs several programs.
15 
16 
17 #First, it copies the run files from irods to a temporary directory and launches JPulseFinder to analyze each of them. JPulseFinder searches for the NB pulses detected by the different PMTs in the neighbor DOMs. Once JPulseFinder has finished, its output is stored and the run files removed from the temporary directory.
18 
19 #
20 
21 script=${0##*/}
22 
23 source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
24 
25 if ( do_usage $* ); then
26  usage "$script [edit the different options within]"
27 fi
28 
29 # ------------------------------------------------------------------------------------------
30 #
31 # Script to find the optimal voltage of the nanobeacons in a DU
32 #
33 # ------------------------------------------------------------------------------------------
34 
35 echo $*
36 
37 WORKDIR=$PWD
38 
39 # function usage()
40 
41 # {
42 
43 # print -u2 "$script \n\t [.detx (with complete path)]\n\t [run_number]\n\t [output path]\n\t [string]\n\t [beacon list]\n\t -V [optional if run for V tunning: voltage value]"
44 
45 # exit 1
46 
47 # }
48 
49 #------------------------------------
50 # Input-Output definitions
51 #------------------------------------
52 
53 # ____ ___ _____ ___
54 # / __ \ / _ \ / ___/ / _ |
55 # / /_/ / / , _// /__ / __ |
56 # \____/ /_/|_| \___/ /_/ |_|
57 #
58 
59 detector="ORCA"
60 
61 string=2
62 
63 irods_path="/in2p3/km3net/data/raw/sea/KM3NeT_00000029/${string}/"
64 
65 filename="KM3NeT_00000029_0000"
66 
67 #runs=(2660 2661 2662 2663 2664 2665 2666 2667 2668)
68 
69 runs=(2745 2746 2747 2748 2749 2750 2751 2752 2753)
70 
71 #runs=(2813 2814 2815 2816 2817 2818 2819 2820 2821)
72 
73 #runs=(2906 2907 2908 2909 2910 2911 2912 2913 2914)
74 
75 #runs=(2986 2987 2988 2989 2990 2991 2992 2993 2994)
76 
77 voltages=(5.5 6 6.5 7 7.5 8 8.5 10 15)
78 
79 in_detx="/afs/in2p3.fr/home/r/rgracia/sps/KM3NeT/ORCA/Calibration/data/det/ORCA/KM3NeT_00000029_20170920.detx"
80 
81 analysis_level=0
82 
83 #####################################################################################################################
84 
85 
86 ##################################
87 # ___ ___ _____ ___ #
88 # / _ | / _ \ / ___/ / _ | #
89 # / __ | / , _// /__ / __ | #
90 # /_/ |_|/_/|_| \___/ /_/ |_| #
91 # #
92 ##################################
93 #detector="ARCA"
94 
95 #string=1
96 
97 #irods_path="/in2p3/km3net/data/raw/darkroom/KM3NeT_00000038/0/"
98 
99 #filename="KM3NeT_00000038_00000"
100 
101 #runs=(207 208 209 211)
102 
103 #voltages=(15 15 8 8)
104 
105 #in_detx="/afs/in2p3.fr/home/r/rgracia/sps/KM3NeT/ORCA/Calibration/data/det/ARCA/KM3NeT_00000014_20170327.detx"
106 
107 #in_detx="/afs/in2p3.fr/home/r/rgracia/sps/Soft/src/Jpp_trunk/examples/JMonitor/JNanoBeacon/JPulseFinder/temp/KM3NeT_00000038_intrainterDOM_final_pmt7_v1.detx"
108 
109 #####################################################################################################################
110 
111 
112 
113 
114 ###################################################################################################################
115 #GET RUN FILES FROM IRODS AND STORE THEM IN A TEMPORARY DIRECTORY
116 ###################################################################################################################
117 
118 
119 tmpdir="${WORKDIR}/tmp"
120 
121 if [ ! -d ${tmpdir} ]
122 
123 then
124 
125  mkdir -p ${tmpdir}
126 
127 fi
128 
129 source /usr/local/shared/bin/irods_env.sh >& /dev/null
130 
131 iinit
132 
133 
134 
135 ################################################################################################################
136 #LAUNCH JPULSEFINDER FOR EACH OF THE RUN FILES GRABBED FROM IRODS. STORE THE OUTPUT, AND REMOVE THE RUN FILES.
137 ################################################################################################################
138 
139 
140 outdir_pulse="${WORKDIR}/out/$detector/JPulseFinder"
141 
142 if [ ! -d ${outdir_pulse} ]
143 
144 then
145 
146  mkdir -p ${outdir_pulse}
147 
148 fi
149 
150 pulse_period=6250 #in units of 16 ns
151 
152 stagger_period=220 #in units of 16 ns
153 
154 outfiles_pulse=""
155 
156 for i in {1..$((${#runs[@]}))}
157 
158 do
159 
160  infile=$tmpdir/${filename}${runs[i]}.root
161 
162  outfile=$outdir_pulse/JPF_${runs[i]}.root
163 
164  outfiles_pulse="${outfiles_pulse} ${outfile}"
165 
166  if [ ! -f $outfile ]; then
167 
168  if [ ! -f $infile ]; then
169 
170  echo "\nGetting file ${filename}${runs[i]}.root from ${irods_path}. Please wait..."
171 
172  iget -f ${irods_path}${filename}${${runs[i]}}.root $tmpdir/
173 
174  else
175 
176  echo "\n\nThe file \n${filename}${${runs[i]}}.root \nalready exists in \n$tmpdir.\nContinue..."
177 
178  fi
179 
180  JPulseFinder \
181  -f $infile \
182  -a $in_detx \
183  -s $string \
184  -p $pulse_period \
185  -stagger $stagger_period \
186  -o $outfile \
187  -V ${voltages[i]}
188 
189 # rm -f ${infile}
190 
191  else
192 
193  echo "\nThe pulses for run $runs[i] already exist in file\n$outfile\nContinue..."
194 
195  fi
196 
197 done
198 
199 
200 ###############################################################################
201 #LAUNCH JVOLTAGEOPTIMIZER USING THE OUTPUT FROM JPULSEFINDER. STORE THE OUTPUT.
202 ###############################################################################
203 
204 top_pmts=1
205 
206 bottom_pmts=1
207 
208 max_neighbors=2
209 
210 max_tot=26.4
211 
212 outdir_optimizer="${WORKDIR}/out/$detector/JVoltageOptimizer"
213 
214 if [ ! -d ${outdir_optimizer} ]
215 
216 then
217 
218  mkdir -p ${outdir_optimizer}
219 
220 fi
221 
222 outfile_opt="$outdir_optimizer/JVO_OPT_${runs[1]}_${runs[${#runs[@]}]}.root"
223 
224 outfile_cal="$outdir_optimizer/JVO_CAL_${runs[1]}_${runs[${#runs[@]}]}.root"
225 
226 outfile_txt="$outdir_optimizer/JVO_OPT_${runs[1]}_${runs[${#runs[@]}]}.txt"
227 
228 if [[ ! -f $outfile_opt || ! -f $outfile_cal || ! -f $outfile_txt ]]; then
229 
230  JVoltageOptimizer \
231  -f "${outfiles_pulse}" \
232  -a $in_detx -s $string \
233  -o $outfile_opt \
234  -t $outfile_txt \
235  -c $outfile_cal \
236  -u $top_pmts \
237  -d $bottom_pmts \
238  -n $max_neighbors \
239  -S $max_tot
240 
241 else
242 
243  echo "\n\nThe voltage has been optimized. Continue...\n"
244 
245 fi
246 
247 outdir_calibrator="${WORKDIR}/out/$detector/JInterDomCal"
248 
249 if [ ! -d ${outdir_calibrator} ]
250 
251 then
252 
253  mkdir -p ${outdir_calibrator}
254 
255 fi
256 
257 outfile_txt="$outdir_calibrator/JNBCal_${runs[1]}_${runs[${#runs[@]}]}.txt"
258 
259 outfile_checks="$outdir_calibrator/JNBCal_${runs[1]}_${runs[${#runs[@]}]}.root"
260 
261 outfile_detx="$outdir_calibrator/JNBCal_${runs[1]}_${runs[${#runs[@]}]}.detx"
262 
263 
264 #####################################################################
265 #LAUNCH JINTERDOMCAL USING THE OUTPUT PRODUCED BY JVOLTAGEOPTIMIZER.#
266 #####################################################################
267 
268 
269 JInterDomCal \
270  -a $in_detx \
271  -f $outfile_cal \
272  -s $string \
273  -t $outfile_txt \
274  -x $outfile_detx \
275  -c $outfile_checks \
276  -u $top_pmts \
277  -d $bottom_pmts \
278  -l $analysis_level
279 
280 
281 
282 ##########################################################################
283 #PRODUCE REPORTS FROM THE OUTPUT FILES FROM CALIBRATION AND OPTIMIZATION.#
284 ##########################################################################
285 
286 
287 
288 calibration_report_name="$outdir_calibrator/calibration_report_${runs[1]}_${runs[${#runs[@]}]}.pdf"
289 
290 optimization_report_name="$outdir_optimizer/optimization_report_${runs[1]}_${runs[${#runs[@]}]}.pdf"
291 
292 
293 echo "Writing calibration report in file:"
294 echo $calibration_report_name
295 echo "------------------------------------\n"
296 
297 python plot_report_calibration.py -ir $outfile_checks -it $outfile_txt -o $calibration_report_name
298 
299 
300 echo "Writing optimization report in file:"
301 echo $optimization_report_name
302 echo "------------------------------------\n"
303 
304 python plot_report_optimization.py -i $outfile_opt -o $optimization_report_name
305 
306 echo "Done... Hasta pronto!"
307 
308 
309 
310 
311