Jpp
JRA_report.sh
Go to the documentation of this file.
1 #!/bin/zsh
2 #
3 # \author rgruiz
4 #
5 script=${0##*/}
6 
7 source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
8 
9 if ( do_usage $* ); then
10  usage "$script <daq_file> <detector_file> <jra_file> <output_file(.pdf)>"
11 fi
12 
13 if (( $# < 3 )); then
14  fatal "No input files."
15 fi
16 
17 set_variable DAQ_FILE $1
18 
19 set_variable DETECTOR_FILE $2
20 
21 set_variable JRA_FILE $3
22 
23 set_variable JRA_REPORT $4
24 
25 set_variable OUT_DIR `readlink -f $(dirname ${JRA_REPORT})`
26 
27 if [ ! -d ${OUT_DIR} ]
28 then
29  mkdir -p ${OUT_DIR}
30 fi
31 
32 set_variable REPORT_NAME `echo $(basename ${JRA_REPORT} .pdf)`
33 
34 set_variable TEMPLATE_DIR ${JPP_DIR}/software/JRunAnalyzer/report
35 
36 set_variable PALETTE 112
37 
38 set_array DAQ_HEADER `JPrintDAQHeader -f ${DAQ_FILE} -d 0`
39 
40 typeset -Z 8 RUN_NUMBER=${DAQ_HEADER[2]}
41 
42 set_variable REPORT_DIR `readlink -f ${OUT_DIR}/JRA_report_${RUN_NUMBER}`
43 
44 set_variable FIGURE_DIR ${REPORT_DIR}/figures
45 
46 set_variable INCLUDE_DIR ${REPORT_DIR}/include
47 
48 if [ ! -d ${REPORT_DIR} ]
49 then
50  mkdir -p ${REPORT_DIR}
51 fi
52 
53 if [ ! -d ${FIGURE_DIR} ]
54 then
55  mkdir -p ${FIGURE_DIR}
56 fi
57 
58 if [ ! -d ${INCLUDE_DIR} ]
59 then
60  mkdir -p ${INCLUDE_DIR}
61 fi
62 
63 cp -r ${TEMPLATE_DIR}/figures/logo ${REPORT_DIR}/figures
64 
65 cp -r ${TEMPLATE_DIR}/Makefile ${REPORT_DIR}
66 
67 DET_FILE=$(basename ${DETECTOR_FILE} .detx).detx
68 
69 TEX_DETFILE=$(sed -e "s/_/\$\\\\\\\\\\\_\$/g" <<< "${DET_FILE}")
70 
71 # Here we start appending sed commands to a script that we will later apply to the template.
72 # These commands search a pattern in the template and substitute this pattern by some information obtained from the DAQ files.
73 
74 printf 's/%s/%s/g\n' "--runNumber--" "${RUN_NUMBER}">script.sed
75 printf 's/%s/%s/g\n' "--detectorFile--" "${TEX_DETFILE}">>script.sed
76 printf 's/%s/%s/g\n' "--instrument--" "${INSTRUMENT}">>script.sed
77 
78 ################################################################################################
79 # Get detector information such as the number of modules, number of DUs and number of floors. #
80 ################################################################################################
81 
82 eval `JPrintDetector -a $DETECTOR_FILE -O SUMMARY`
83 
84 printf 's/%s/%s/g\n' "--nStrings--" "${NUMBER_OF_STRINGS}">>script.sed
85 printf 's/%s/%s/g\n' "--nFloors--" "${NUMBER_OF_FLOORS}">>script.sed
86 printf 's/%s/%s/g\n' "--nModules--" "${NUMBER_OF_MODULES}">>script.sed
87 
88 
89 ##############################################
90 # Extract JDAQ Types present in the run file #
91 ##############################################
92 
93 JDAQTYPES=()
94 
95 TIMESLICES=("TimesliceL0" "TimesliceL1" "TimesliceSN" "TimesliceL2")
96 
97 set_array trees `JPrintTree -f $DAQ_FILE 2>&1`
98 
99 c=0
100 for i in "${trees[@]}"; do
101  if [[ $i =~ '::JDAQ'(.*) ]]
102  then
103  printf 's/%s/%s/g\n' "--n${match[1]}--" "${trees[$((c+2))]}"
104  printf 's/%s/%s/g\n' "--s${match[1]}--" "${trees[$((c+3))]}"
105  if [ $trees[$((c+2))] -ne 0 ]
106  then
107  JDAQTYPES+=(${match[1]})
108  fi
109  fi
110  c=$((c+1))
111 done >>script.sed
112 
113 least_bias_slice=""
114 
115 for i in "${TIMESLICES[@]}"; do
116  if [[ ${JDAQTYPES[(ie)$i]} -le ${#JDAQTYPES} ]]
117  then
118  least_bias_type=$i
119  break
120  fi
121 done
122 
123 ############################################################
124 # Extract ROOT versions of objects present in the run file #
125 ############################################################
126 
127 set_array trees `JPrintRootVersion -f $DAQ_FILE 2>&1`
128 
129 c=0
130 for i in "${trees[@]}"; do
131  if [[ $i =~ '::JDAQ'(.*) ]]
132  then
133  printf 's/%s/%s/g\n' "--r1${match[1]}--" "${trees[$((c+2))]}"
134  printf 's/%s/%s/g\n' "--r2${match[1]}--" "${trees[$((c+3))]}"
135  fi
136  c=$((c+1))
137 done >>script.sed
138 
139 ##########################################
140 # Extract Trigger Parameters from JPrint #
141 ##########################################
142 
143 parameter_list=("trigger3DShower.enabled" "trigger3DShower.numberOfHits" "trigger3DShower.numberOfModules" "trigger3DShower.DMax_m" "trigger3DShower.TMaxExtra_ns" "trigger3DShower.factoryLimit" "triggerMXShower.enabled" "triggerMXShower.numberOfHits" "triggerMXShower.numberOfModules" "triggerMXShower.DMax_m" "triggerMXShower.TMaxExtra_ns" "triggerMXShower.factoryLimit" "trigger3DMuon.enabled" "trigger3DMuon.numberOfHits" "trigger3DMuon.numberOfModules" "trigger3DMuon.DMax_m" "trigger3DMuon.roadWidth_m" "trigger3DMuon.gridAngle_deg" "trigger3DMuon.TMaxExtra_ns" "trigger3DMuon.factoryLimit" "highRateVeto_Hz" "writeTimeslices.prescale" "writeSummary.prescale" "writeL0.prescale" "writeL1.prescale" "writeL2.prescale" "writeSN.prescale")
144 
145 for i in "${parameter_list[@]}"
146 do
147  TEX_REMATCH=$(sed -e "s/_/\\\\\\\_/g" <<< "${i}")
148  printf 's/%s/%s/g\n' "--${TEX_REMATCH}--" "$(JPrintTriggerParameters -f $DAQ_FILE -k ${i})"
149 done >>script.sed
150 
151 
152 #######################################
153 # Extract information from JPrintMeta #
154 #######################################
155 
156 set_array run_info `JPrintMeta -f $DAQ_FILE 2>&1`
157 
158 printf 's:%s:%s:g\n' "--rootdaq--" "${run_info[4]}">>script.sed
159 TEX_JPP=$(sed -e "s/_/\\\\\\\_/g" <<< "${run_info[2]}")
160 printf 's/%s/%s/g\n' "--jppdaq--" "${TEX_JPP}">>script.sed
161 
162 set_array run_info `JPrintMeta -f $JRA_FILE 2>&1`
163 
164 printf 's:%s:%s:g\n' "--rootjra--" "${run_info[4]}">>script.sed
165 TEX_JPP=$(sed -e "s/_/\\\\\\\_/g" <<< "${run_info[2]}")
166 printf 's/%s/%s/g\n' "--jppjra--" "${TEX_JPP}">>script.sed
167 
168 root_v=`echo $run_info[4] | cut -c1`
169 
170 if [[ $root_v -lt 6 ]];
171 then
172  PALETTE=53
173 fi
174 
175 set_array QAQC_V `${JPP_DIR}/software/JGizmo/JQAQC.sh $DETECTOR_FILE $DAQ_FILE`
176 
177 set_array QAQC_H `${JPP_DIR}/software/JGizmo/JQAQC.sh -h!`
178 
179 QAQC_P=("${QAQC_H[@]:5}")
180 
181 i=1
182 for KEY in ${QAQC_P[*]}; do
183  TEX_KEY=$(sed -e "s/_/\\\\\\\_/g" <<< "${KEY}")
184  printf 's/%s/%s/g\n' "--${TEX_KEY}--" "${QAQC_V[$i]}"
185  i=$i+1
186 done>>script.sed
187 
188 ####################################################
189 # Create subsections in report for the desired DUs #
190 ####################################################
191 
192 if [ "${#STRINGS[@]}" -gt 0 ];then
193  printf '/%%DU_SECTION%%/i \\\\\section{DU plots} \\\\\\nThe following section contains figures for specific DUs which are based on the explanations given in the previous sections. The axes titles and labels should be enough to understand the plots.
194 '>>script.sed
195  for du in "${STRINGS[@]}"; do
196  du_report=${INCLUDE_DIR}/DU_${du}.tex
197  printf 's/%s/%s/g\n' "--DUXX--" "${du}">script_${du}.sed
198  printf 's/%s/%s/g\n' "--least_bias_type--" "${least_bias_type}">>script_${du}.sed
199  JPlot2D -f "${JRA_FILE}":Detector/DU"${du}"/h_mean_summary_rate -p "${PALETTE}" -O "colz" -T "DU${du} summary rates" -o "$FIGURE_DIR/mean_rate_summary_S${du}.png" -B
200  CHECK_EXIT_CODE
201  JPlot2D -f "${JRA_FILE}":Detector/DU"${du}"/h_Snapshot_hits_per_pmt -p "${PALETTE}" -O "colz" -T "DU${du} Snapshot hits" -o "$FIGURE_DIR/snapshot_hits_pmt_S${du}.png" -B
202  CHECK_EXIT_CODE
203  JPlot2D -f "${JRA_FILE}":Detector/DU"${du}"/h_Trigger_map -p "${PALETTE}" -O "colz" -T "DU${du} Trigger map" -o "$FIGURE_DIR/trigger_map_S${du}.png" -B
204  CHECK_EXIT_CODE
205  JPlot2D -f "${JRA_FILE}":Detector/DU"${du}"/h_mean_ToT_"${least_bias_type}" -p "${PALETTE}" -O "colz" -T "mean ToT DU${du}" -o "$FIGURE_DIR/mean_ToT_S${du}_${least_bias_type}.png" -B
206  CHECK_EXIT_CODE
207  JPlot2D -f "${JRA_FILE}":Detector/DU"${du}"/h_ToT_255_"${least_bias_type}" -p "${PALETTE}" -O "colz" -T "ToT = 255 ns DU${du}" -o "$FIGURE_DIR/ToT_255_S${du}_${least_bias_type}.png" -B
208  CHECK_EXIT_CODE
209  for f ({1..18}) do
210  JPlot1D -f "${JRA_FILE}":Detector/DU"${du}"/F"${f}"/h_module_rate_vs_t. -O hist -L "TR" -y "1 2000000" -Y -T "" -o "$FIGURE_DIR/module_rates_S${du}F${f}.png" -B
211  CHECK_EXIT_CODE
212  JPlot2D -f "${JRA_FILE}":Detector/DU"${du}"/F"${f}"/"._${least_bias_type}_2SToT" -p "${PALETTE}" -O "colz" -T "DU${du}F${f} ${least_bias_type}" -o "$FIGURE_DIR/pmt_tot_S${du}F${f}_${least_bias_type}.png" -B
213  CHECK_EXIT_CODE
214  JPlot2D -f "${JRA_FILE}":Detector/DU"${du}"/F"${f}"/h_Trigger_map -p "${PALETTE}" -O "colz" -T "Trigger Map DU${du}F${f}" -o "$FIGURE_DIR/trigger_map_S${du}F${f}.png" -B
215  CHECK_EXIT_CODE
216  JPlot2D -f "${JRA_FILE}":Detector/DU"${du}"/F"${f}"/h_pmt_rate_distributions_"${least_bias_type}" -p "${PALETTE}" -O "colz" -x "1e-3 2e1" -X -T "DU${du}F${f} ${least_bias_type}" -o "$FIGURE_DIR/pmt_rates_S${du}F${f}_${least_bias_type}.png" -B
217  CHECK_EXIT_CODE
218  JPlot2D -f "${JRA_FILE}":Detector/DU"${du}"/F"${f}"/ToT_vs_time_"${least_bias_type}" -p "${PALETTE}" -O "colz" -z "1 100" -Z -T "DU${du}F${f} ${least_bias_type}" -o "$FIGURE_DIR/pmt_tot_vs_t_S${du}F${f}_${least_bias_type}.png" -B
219  CHECK_EXIT_CODE
220  JPlot2D -f "${JRA_FILE}":Detector/DU"${du}"/F"${f}"/h_rate_vs_time_"${least_bias_type}" -p "${PALETTE}" -O "colz" -z "1e0 5e2" -Z -T "DU${du}F${f} ${least_bias_type}" -o "$FIGURE_DIR/pmt_rate_vs_t_S${du}F${f}_${least_bias_type}.png" -B
221  CHECK_EXIT_CODE
222  JPlot2D -f "${JRA_FILE}":Detector/DU"${du}"/F"${f}"/h_dt_consecutive_hits_"${least_bias_type}" -p "${PALETTE}" -O "colz" -T "DU${du}F${f} ${least_bias_type}" -o "$FIGURE_DIR/pmt_consecutive_hits_S${du}F${f}_${least_bias_type}.png" -B
223  CHECK_EXIT_CODE
224  done
225 
226  sed -f script_${du}.sed <${TEMPLATE_DIR}/include/DU.template >${du_report} && rm -f script_${du}.sed
227  printf '/%%DU_SECTION%%/i \\\\\input{%s}\n' "${du_report}"
228  done >>script.sed
229  fi
230 
231 ################################################################
232 # Now the sed script is used to replace in the template report #
233 ################################################################
234 
235 sed -f script.sed <${TEMPLATE_DIR}/JRA_report.template >${REPORT_DIR}/${REPORT_NAME}.tex && rm -f script.sed
236 
237 
238 ############################
239 # Plot rest of the figures #
240 ############################
241 
242 # DAQ STATUS PLOTS
243 
244 JPlot1D -f "${JRA_FILE}":Detector/h_fifo -O hist -L "TR" -T "" -o "$FIGURE_DIR/fifo_vs_time.png" -B
245 CHECK_EXIT_CODE
246 JPlot1D -f "${JRA_FILE}":Detector/h_daq_status -O hist -L "TR" -T "" -o "$FIGURE_DIR/daq_status_vs_time.png" -B
247 CHECK_EXIT_CODE
248 JPlot1D -f "${JRA_FILE}":Detector/h_hrv -O hist -L "TR" -T "" -o "$FIGURE_DIR/hrv_vs_time.png" -B
249 CHECK_EXIT_CODE
250 JPlot2D -f "${JRA_FILE}":Detector/h_fifo_per_dom -p "${PALETTE}" -O "colz" -T "" -o "$FIGURE_DIR/fifo_doms.png" -B
251 CHECK_EXIT_CODE
252 JPlot2D -f "${JRA_FILE}":Detector/h_daq_status_per_dom -p "${PALETTE}" -O "colz" -T "" -o "$FIGURE_DIR/daq_status_doms.png" -B
253 CHECK_EXIT_CODE
254 JPlot2D -f "${JRA_FILE}":Detector/h_hrv_per_dom -p "${PALETTE}" -O "colz" -T "" -o "$FIGURE_DIR/hrv_doms.png" -B
255 CHECK_EXIT_CODE
256 
257 
258 # RATEs
259 
260 JPlot1D -f "${JRA_FILE}":Detector/h_pmt_rate_distribution -O hist -L "TR" -T "" -G "[X][Y]" -X -Y -s "1" -o "$FIGURE_DIR/pmt_rates_summary.png" -B
261 CHECK_EXIT_CODE
262 JPlot2D -f "${JRA_FILE}":Detector/h_rate_summary -p "${PALETTE}" -O "colz" -T "" -o "$FIGURE_DIR/mean_rates_summary.png" -B
263 CHECK_EXIT_CODE
264 JPlot1D -f "${JRA_FILE}":Detector/Rate/. -O hist -L "TR" -y "1 20000" -Y -T "" -o "$FIGURE_DIR/rates_vs_time.png" -B
265 CHECK_EXIT_CODE
266 JPlot2D -f "${JRA_FILE}":Detector/DOM_mean_rates/h_mean_dom_rates_"$least_bias_type" -p "${PALETTE}" -O "colz" -z "1 10000" -Z -T "$least_bias_type" -o "$FIGURE_DIR/mean_rates_DOM.png" -B
267 CHECK_EXIT_CODE
268 
269 
270 # ACTIVE MODULES
271 
272 JPlot1D -f "${JRA_FILE}":Detector/Active_modules_detector/. -O hist -L "TR" -y "0 1.3" -T "" -o "$FIGURE_DIR/active_modules_vs_time.png" -B
273 CHECK_EXIT_CODE
274 JPlot2D -f "${JRA_FILE}":Detector/Active_modules_du/h_du_active_DOMS_"$least_bias_type" -p "${PALETTE}" -z "0 18" -O "colz" -T "$least_bias_type" -o "$FIGURE_DIR/active_modules_DU_vs_time.png" -B
275 CHECK_EXIT_CODE
276 
277 # ToT 255
278 
279 JPlot1D -f "${JRA_FILE}":Detector/ToT_255_vs_time/. -O hist -L "TR" -T "Hits with ToT=255 ns" -X -G "[X][Y]" -o "$FIGURE_DIR/ToT_255_vs_time.png" -B
280 CHECK_EXIT_CODE
281 JPlot2D -f "${JRA_FILE}":Detector/ToT_255_Floor_vs_time/ToT_255_Floor_vs_time_2"$least_bias_type" -p "${PALETTE}" -O "colz" -T "Hits with ToT=255 ns ($i)" -o "$FIGURE_DIR/ToT_255_Floor_vs_time_.png" -B
282 CHECK_EXIT_CODE
283 
284 # Triggers
285 
286 JPlot1D -f "${JRA_FILE}":JDAQEvent/hits_per_event/. -O hist -L "TR" -T "" -G "[X][Y]" -X -o "$FIGURE_DIR/event_hits.png" -B
287 CHECK_EXIT_CODE
288 JPlot1D -f "${JRA_FILE}":JDAQEvent/hits_pmt_distributions/. -O hist -L "TR" -T "" -G "[X][Y]" -s "0" -o "$FIGURE_DIR/pmt_event_hits.png" -B
289 CHECK_EXIT_CODE
290 JPlot1D -f "${JRA_FILE}":JDAQEvent/hits_tot_distributions/. -O hist -L "TR" -T "" -y "0.5e-3 0.5" -Y -G "[X][Y]" -s "0" -o "$FIGURE_DIR/tot_event_hits.png" -B
291 CHECK_EXIT_CODE
292 JPlot1D -f "${JRA_FILE}":JDAQEvent/trigger_rates/. -O hist -L "BL" -T "Trigger rates" -y "0.5e-3 5" -Y -G "[X][Y]" -s "0" -o "$FIGURE_DIR/trigger_rates.png" -B
293 CHECK_EXIT_CODE
294 JPlot2D -f "${JRA_FILE}":JDAQEvent/h_Triggered_hits_per_module -p "${PALETTE}" -O "colz" -T "Triggered hits" -o "$FIGURE_DIR/triggered_hits_module.png" -B
295 CHECK_EXIT_CODE
296 JPlot2D -f "${JRA_FILE}":JDAQEvent/h_Snapshot_hits_per_module -p "${PALETTE}" -O "colz" -T "" -o "$FIGURE_DIR/snapshot_hits_module.png" -B
297 CHECK_EXIT_CODE
298 
299 
300 # Compile the report
301 
302 cd ${REPORT_DIR}
303 
304 make doc >& /dev/null
305 
306 CHECK_EXIT_CODE
307 
308 mv *PDF ./../
309 
310 cd ${OUT_DIR}
311 
312 rm -rf ${REPORT_DIR}
313 
314 exit