Jpp
Optimize_Voltage_local.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 #
32 # Script to find the optimal voltage of the nanobeacons in a DU
33 #
34 # ------------------------------------------------------------------------------------------
35 
36 echo $*
37 
38 WORKDIR=$PWD
39 
40 JNANODIR="/data/stu18q3km3/src/Jpp/trunk/examples/JNanobeacon"
41 
42 function usage()
43 
44 {
45 
46  print -u2 "$script"
47 
48  exit 1
49 
50 }
51 
52 #------------------------------------
53 # Input-Output definitions
54 #------------------------------------
55 
56 # ____ ___ _____ ___
57 # / __ \ / _ \ / ___/ / _ |
58 # / /_/ / / , _// /__ / __ |
59 # \____/ /_/|_| \___/ /_/ |_|
60 #
61 
62 detector="ORCA"
63 
64 string=2
65 
66 path_to_run_files="/data/stu18q3km3/data/KM3NeT_00000029/"
67 
68 filename="KM3NeT_00000029_0000"
69 
70 #runs=(2660 2661 2662 2663 2664 2665 2666 2667 2668)
71 
72 runs=(2745 2746 2747 2748 2749 2750 2751 2752 2753)
73 
74 #runs=(2813 2814 2815 2816 2817 2818 2819 2820 2821)
75 
76 #runs=(2906 2907 2908 2909 2910 2911 2912 2913 2914)
77 
78 #runs=(2986 2987 2988 2989 2990 2991 2992 2993 2994)
79 
80 voltages=(5.5 6 6.5 7 7.5 8 8.5 10 15)
81 
82 in_detx="/data/stu18q3km3/detectors/KM3NeT_00000029_20170920.detx"
83 
84 analysis_level=0
85 
86 top_pmts=1
87 
88 bottom_pmts=4
89 
90 max_neighbors=2
91 
92 max_tot=26.4
93 
94 pulse_period=6250 #in units of 16 ns
95 
96 stagger_period=220 #in units of 16 ns
97 
98 
99 #####################################################################################################################
100 
101 
102 ##################################
103 # ___ ___ _____ ___ #
104 # / _ | / _ \ / ___/ / _ | #
105 # / __ | / , _// /__ / __ | #
106 # /_/ |_|/_/|_| \___/ /_/ |_| #
107 # #
108 ##################################
109 
110 #detector="ARCA"
111 
112 #string=1
113 
114 #path_to_run_files="/in2p3/km3net/data/raw/darkroom/KM3NeT_00000038/0/"
115 
116 #filename="KM3NeT_00000..."
117 
118 #runs=()
119 
120 #voltages=()
121 
122 #in_detx="path_to_the_following_detector_file/KM3NeT_00000014_20170327.detx"
123 
124 #####################################################################################################################
125 
126 cd "${JNANODIR}"
127 
128 ################################################################################################################
129 #LAUNCH JPULSEFINDER FOR EACH OF THE RUN FILES GRABBED FROM IRODS. STORE THE OUTPUT, AND REMOVE THE RUN FILES.
130 ################################################################################################################
131 
132 outdir_pulse="${WORKDIR}/out/$detector/JPulseFinder"
133 
134 if [ ! -d ${outdir_pulse} ]
135 
136 then
137 
138  mkdir -p ${outdir_pulse}
139 
140 fi
141 
142 outfiles_pulse=""
143 
144 for i in {1..$((${#runs[@]}))}
145 
146 do
147 
148  infile=$path_to_run_files/${filename}${runs[i]}.root
149 
150  outfile=$outdir_pulse/JPF_${runs[i]}.root
151 
152  outfiles_pulse="${outfiles_pulse} ${outfile}"
153 
154  if [ ! -f $outfile ]; then
155 
156  JPulseFinder \
157  -f $infile \
158  -a $in_detx \
159  -s $string \
160  -p $pulse_period \
161  -stagger $stagger_period \
162  -o $outfile \
163  -V ${voltages[i]} \
164  -n $max_neighbors \
165  -t $top_pmts \
166  -b $bottom_pmts
167 
168  else
169 
170  echo "\nThe pulses for run $runs[i] already exist in file\n$outfile\nContinue..."
171 
172  fi
173 
174 done
175 
176 
177 ###############################################################################
178 #LAUNCH JVOLTAGEOPTIMIZER USING THE OUTPUT FROM JPULSEFINDER. STORE THE OUTPUT.
179 ###############################################################################
180 
181 outdir_optimizer="${WORKDIR}/out/$detector/JVoltageOptimizer"
182 
183 if [ ! -d ${outdir_optimizer} ]
184 
185 then
186 
187  mkdir -p ${outdir_optimizer}
188 
189 fi
190 
191 outfile_opt="$outdir_optimizer/JVO_OPT_${runs[1]}_${runs[${#runs[@]}]}.root"
192 
193 outfile_cal="$outdir_optimizer/JVO_CAL_${runs[1]}_${runs[${#runs[@]}]}.root"
194 
195 outfile_txt="$outdir_optimizer/JVO_OPT_${runs[1]}_${runs[${#runs[@]}]}.txt"
196 
197 if [[ ! -f $outfile_opt || ! -f $outfile_cal || ! -f $outfile_txt ]]; then
198 
199  JVoltageOptimizer \
200  -f "${outfiles_pulse}" \
201  -a $in_detx \
202  -s $string \
203  -o $outfile_opt \
204  -t $outfile_txt \
205  -c $outfile_cal \
206  -u $top_pmts \
207  -d $bottom_pmts \
208  -n $max_neighbors \
209  -S $max_tot
210 
211 else
212 
213  echo "\n\nThe voltage has been optimized. Continue...\n"
214 
215 fi
216 
217 outdir_calibrator="${WORKDIR}/out/$detector/JInterDomCal"
218 
219 if [ ! -d ${outdir_calibrator} ]
220 
221 then
222 
223  mkdir -p ${outdir_calibrator}
224 
225 fi
226 
227 outfile_txt="$outdir_calibrator/JNBCal_${runs[1]}_${runs[${#runs[@]}]}.txt"
228 
229 outfile_checks="$outdir_calibrator/JNBCal_${runs[1]}_${runs[${#runs[@]}]}.root"
230 
231 outfile_detx="$outdir_calibrator/JNBCal_${runs[1]}_${runs[${#runs[@]}]}.detx"
232 
233 
234 #####################################################################
235 #LAUNCH JINTERDOMCAL USING THE OUTPUT PRODUCED BY JVOLTAGEOPTIMIZER.#
236 #####################################################################
237 
238 
239 JInterDomCal \
240  -a $in_detx \
241  -f $outfile_cal \
242  -s $string \
243  -t $outfile_txt \
244  -x $outfile_detx \
245  -c $outfile_checks \
246  -u $top_pmts \
247  -d $bottom_pmts \
248  -l $analysis_level
249 
250 
251 
252 ##########################################################################
253 #PRODUCE REPORTS FROM THE OUTPUT FILES FROM CALIBRATION AND OPTIMIZATION.#
254 ##########################################################################
255 
256 
257 
258 calibration_report_name="$outdir_calibrator/calibration_report_${runs[1]}_${runs[${#runs[@]}]}.pdf"
259 
260 optimization_report_name="$outdir_optimizer/optimization_report_${runs[1]}_${runs[${#runs[@]}]}.pdf"
261 
262 
263 echo "Writing calibration report in file:"
264 echo $calibration_report_name
265 echo "------------------------------------\n"
266 
267 python plot_report_calibration.py -ir $outfile_checks -it $outfile_txt -o $calibration_report_name
268 
269 echo "\nDone!"
270 
271 echo "Writing optimization report in file:"
272 echo $optimization_report_name
273 echo "------------------------------------\n"
274 
275 python plot_report_optimization.py -i $outfile_opt -o $optimization_report_name
276 
277 echo "Done... Hasta pronto!"
278