2 # This file contain common functions used by liteAnalysis.sh,
3 # gridAnalysis.sh, etc.
6 # === Variables ======================================================
7 fwd_dir=$ALICE_ROOT/PWGLF/FORWARD/analysis2
24 # === Misc. ==========================================================
28 echo "$f: Dummy function. Please implement in $0" > /dev/stderr
32 # --- Manual ---------------------------------------------------------
37 sed -n -e '/BEGIN_MANUAL/,/END_MANUAL/ p' | \
38 sed -e '/\(BEGIN\|END\)_MANUAL/ d' -e 's/^# //' \
41 # --- Check AliEn token ----------------------------------------------
45 genv_file=/tmp/gclient_env_${uid}
47 if test ! -f ${genv_file} ; then
48 echo "No such file: ${genv_file}, please do alien-token-init" \
53 alien-token-info | grep -q "Token is still valid"
54 if test $? -ne 0 ; then
55 echo "Token not valid, please re-new" > /dev/stderr
60 # === Utilities to execute scripts ===================================
61 # --- Run script -----------------------------------------------------
66 echo "Will run aliroot -l -b -q $scr($args)"
67 if test $noact -gt 0 ; then return ; fi
73 # --- Extract corrections --------------------------------------------
76 echo "Nothing to do for terminate"
78 # --- Post processing -----------------------------------------------
83 # --- Extract corrections --------------------------------------------
86 local scr=${1:-Extract.C}
87 if test ! -f ${scr} ; then
89 if test ! -f ${scr} ; then
90 echo "Extract script not found in `pwd` or parent" > /dev/stderr
94 if test -f .extract ; then
95 echo "Aldready extracted in `basename $PWD`"
99 script $scr > /dev/null 2>&1
102 # --- Upload a file --------------------------------------------------
105 if test -f .upload ; then
106 echo "Already uploaded in `basename $PWD`"
110 script Upload.C \"file://${here}/${name}_corrs_${now}/\" >/dev/null 2>&1
113 # --- Extract and upload ---------------------------------------------
116 echo "=== Download, extract, and uploade in `basename $PWD` ==="
120 # --- Draw -----------------------------------------------------------
125 # --- Generic draw ---------------------------------------------------
130 # --- Draw dN/deta results -------------------------------------------
134 local scr=${1:-Draw.C}
135 echo "=== $d ================================================"
137 draw ${fwd_dir}/DrawdNdetaSummary.C && \
141 # --- Draw dN/deta ---------------------------------------------------
146 # === Task functions =================================================
147 # --- Common options help --------------------------------------------
151 Usage: $0 --what=OPERATION [--step=STEP] [OPTIONS]
154 -s,--step=STEP Run stage ($step)
155 -w,--what=TRAINS What to do
156 -M,--man Show the manual
157 -N,--noact Show what will be done
159 Options for 'setup' operation:
160 -n,--name=STRING Base name of jobs ($name)
161 -S,--sys=SYSTEM Collision system ($sys)
162 -E,--snn=ENERGY Center of mass energy per nuclean pair ($snn)
163 -F,--field=FIELD L3 magnetic field ($field)
164 -c,--corrections=DIR Directory where corrections are stored ($corrs)
165 -u,--url-opts=OPTIONS Additional user options ($uuopts)
166 -i,--inel-eff=EFF Set INEL efficiency (only pp - $inel_eff)
167 -0,--inelgt0-eff=EFF Set INEL>0 efficiency (only pp - $inelgt0_eff)
168 -v,--nsd-eff=EFF Set NSD (to V0-AND) efficiency (only pp $nsd_eff)
175 clean Clean directory
176 setup Do intial setup
177 corrs Generate corrections
179 dndeta Generate dNdeta
180 multdists Generate P(Nch)
181 flow Generate v_n{m} - not implemented yet
183 and must be executed in that order. STEP is one of
185 full Run the analysis
186 terminate Terminate the job (may need iterations)
187 upload Upload corrections (only for TRAINS=corrs)
188 draw Draw (partial) results (not for TRAINS=corrs)
197 # === Setup functions ================================================
198 # --- Common setup code ----------------------------------------------
203 while test $# -gt 0 ; do
208 arg=`echo $1 | sed 's/=.*//'` ;
209 opt=`echo $1 | sed 's/--[^=][^=]*=//'`
213 -*) opt=$2 ; shift ;;
218 # echo "Base: Processing '$arg' ('$opt')"
220 -n|--name) name=$opt ;;
221 -c|--corrections) corrs=$opt ;;
222 -i|--inel-eff) inel_eff=$opt ;;
223 -0|--inelgt0-eff) inelgt0_eff=$opt ;;
224 -v|--nsd-eff) nsd_eff=$opt ;;
225 -u|--url-opts) uuopts="$opt" ;;
226 -S|--sys) sys=`echo $opt | tr '[A-Z]' '[a-z]'` ;;
227 -E|--snn) snn=$opt ;;
228 -F|--field) field=$opt ;;
231 if test x$lhandled = "xno" ; then
232 handle_setup_option "$arg" "$opt"
238 # Set the date/time string
239 now=`date '+%Y%m%d_%H%M'`
242 echo "=== Define outputs"
245 # Dump configuration to file
246 echo "=== Dump configuration"
249 # Set-up for corrections
250 corrdir=${name}_corrs_${now}
251 if test "x$corrs" != "x" && test -d ${corrs} ; then
252 echo "Linking ${corrs} to ${corrdir}"
253 ln -sf $corrs ${corrdir}
254 ln -sf $corrs last_${name}_corrs
256 elif test $noact -lt 1 ; then
257 mkdir -p ${name}_acc_${now}
259 rm -f last_${name}_acc last_${name}_corrs
260 ln -sf ${name}_acc_${now} last_${name}_acc
261 ln -sf ${name}_corrs_${now} last_${name}_corrs
262 cat <<-EOF > ${corrdir}/Browse.C
265 const char* fwd = "$ALICE_ROOT/PWGLF/FORWARD/analysis2";
266 if (!gROOT->GetClass("AliOADBForward"))
267 gROOT->Macro(Form("%s/scripts/LoadLibs.C", fwd));
268 gROOT->LoadMacro(Form("%s/corrs/ForwardOADBGui.C", fwd));
270 AliOADBForward* db = new AliOADBForward;
271 db->Open("fmd_corrections.root", "*");
278 echo "=== Make acceptance corrections"
279 (cd ${name}_acc_${now} && \
280 accGen `run_for_acc` && \
283 for i in fmd_corrections.root spd_corrections.root deadstrips.C ; do
284 if test ! -f ${corrdir}/$i ; then continue ; fi
285 echo "Linking ${corrdir}/$i here"
286 ln -fs ${corrdir}/$i .
292 # --- Default implementation -----------------------------------------
295 echo "Default implementation"
298 # --- dummy handler of setup options ---------------------------------
299 handle_setup_option()
301 dummy handle_setup_option
303 # --- Dump configuration to file -------------------------------------
306 cat > ${dotconf} <<-EOF
307 # Generated by command
310 echo -n "# $0 " >> $dotconf
311 while test $# -gt 0 ; do
312 echo -en " \\" >> $dotconf
314 --*) echo -en "\n#\t$1" >> $dotconf;;
315 -*) echo -en "\n#\t$1 $2" >> $dotconf; shift ;;
316 *) echo -en "\n#\t$1" >> $dotconf;;
320 cat >> ${dotconf} <<-EOF
325 # Collision system and similar
329 # Additional URI options
331 # Trigger efficiencies - edit here to set them
333 inelgt0_eff=$inelgt0_eff
336 dump_setup ${dotconf}
337 echo "# EOF" >> ${dotconf}
339 # --- Get the run number to use for acceptance -----------------------
344 # --- Dump settings to output file -----------------------------------
350 # --- Run acceptance generation --------------------------------------
355 script ${fwd_dir}/corrs/ExtractAcceptance.C "${run}"
356 if test -f deadstrips.C ; then
357 cp ${here}/${name}_corrs_${now}/
361 # === Check function =================================================
366 if test "X$name" = X ; then
367 echo "No name specified" > /dev/stderr
370 if test "X$w" != "Xsetup" && test "x$now" = "x" ; then
371 echo "No date/time specified" > /dev/stderr
377 # sys==0 is OK - autoselect
380 xpbpb|xpb-pb|xaa|xa-a) sys=2 ;;
381 xppb|xp-pb|xpa|xp-a) sys=3 ;;
384 *) echo "$0: Unknown system: $sys" ; exit 1 ;;
393 # --- Show the setup -------------------------------------------------
398 Collision system: ${sys}
399 sqrt(s_NN): ${snn}GeV
402 Additional URL options: ${uuopts}
403 Trigger efficiencies:
405 INEL>0: ${inelgt0_eff}
415 # === Task functions =================================================
420 local type=$1 ; shift
421 local trig=$1 ; shift
426 *corr) cl=MakeMCCorrTrain ; mc=1 ;;
427 *eloss) cl=MakeFMDELossTrain ;;
428 *aod) cl=MakeAODTrain ; opts="${opts} --corr=." ;;
429 *dndeta) cl=MakedNdetaTrain
431 opts="${opts} --cut-edges"
434 opts="$opts --scheme=trigger,event,background"
435 opts="$opts --trig=INEL --trigEff=$inel_eff"
438 opts="$opts --scheme=trigger,event"
439 opts="$opts --trig=V0AND --trigEff=$nsd_eff"
442 opts="$opts --scheme=trigger,event"
443 opts="$opts --trig=INELGT0 --trigEff=$inelgt0_eff"
447 if test "x$trig" != "x" ; then
450 if test $mc -gt 0 ; then
455 cl=MakeMultDistsTrain
459 *) echo "$0: Unknown type of train: $type" > /dev/stderr ; exit 1 ;;
461 # add centrality flag if we do not know what collision system we're
462 # looking at, or it's PbPb or pPb.
464 0|2|3) opts="$opts --cent" ;;
467 opts="${opts} --include=$ALICE_ROOT/PWGLF/FORWARD/analysis2/trains"
468 opts="${opts} --date=${now} --class=$cl --name=$nme --verbose=0"
471 # --- Run the train --------------------------------------------------
474 local type=$1 ; shift
475 local trig=$1 ; shift
484 train_opts $mc $type $trig
485 url_opts $mc $type $trig
488 echo "=== Running train: runTrain ${opts} --url=${url} $@"
489 if test $noact -gt 0 ; then return ; fi
491 runTrain ${opts} --overwrite --url=${url} $@
499 local what=$1 ; shift
500 local trig=$1 ; shift
501 echo "=== Running _allAboard '$what' '$trig' $@"
502 _allAboard "$what" "$trig" $@
505 # --- Collect PDFs ---------------------------------------------------
508 local out=${name}_pdfs_${now}
511 dirs="corr eloss aod dndeta dndeta_inel dndeta_nsd dndeta_inelgt0 multdists"
513 for d in ${dirs} ; do
514 for m in "" "mc" ; do
515 dir=${name}_${m}${d}_${now}
521 if test ! -d $dir ; then
522 # echo "Directory ${dir} doesn't exist"
525 # echo "Will look in $dir"
528 corr) files="forward_mccorr.pdf" ;;
529 eloss) files="forward_elossfits.pdf" ;;
530 aod) files="forward.pdf" ;;
531 dndeta*) files="forward_dndeta.pdf dNdeta*.pdf" ;;
532 multdists) files="forward_multdists.pdf" ;;
533 *) echo "Unknown directory type: $d" > /dev/stder
537 collect_files "$dir" "$d" "$M" "$out" "$run" "$files"
541 (cd ${out} && pdfjoin -q -o tmp.pdf \
542 --pdftitle "${name} summary ($now)" \
543 --twoside summary_*.pdf dndeta_*.pdf && \
544 pdfnup -q --nup 2x1 -o ${name}_summary_${now}.pdf tmp.pdf && \
546 (cd ${out} && pdfjoin -q -o tmp.pdf \
547 --pdftitle "${name} dN/deta ($now)" \
548 --twoside dndeta_*.pdf && \
549 pdfnup -q --nup 2x1 -o ${name}_dndeta_${now}.pdf tmp.pdf && \
551 echo "Made ${name}_summary_${now}.pdf and ${name}_dndeta_${now}.pdf"
552 rm -f last_${name}_pdfs
553 ln -s ${out} last_${name}_pdfs
554 (cd ${out} && _pres_collect)
559 local out=results.tex
561 local A=`getent passwd $USER | cut -f5 -d: `
562 local D=`echo $now | sed 's,\(....\)\(..\)\(..\)_\(..\)\(..\),\1/\2/\3 \4:\5,'`
564 \\documentclass[compress]{beamer}
566 \\usepackage[english,british]{babel}
574 dirs="dndeta dndeta_inel dndeta_nsd dndeta_inelgt0 multdists"
575 for i in ${dirs} ; do
576 l=`ls ${i}_real_*.pdf 2>/dev/null`
578 m=`echo $r | sed 's/real/simu/'`
579 R=`basename $r .pdf | sed "s/${i}_real_0*//"`
580 t=`basename $r .pdf | sed 's/dndeta_\(.*\)_real.*/\1/'`
584 xinelgt0) T="INEL\\textgreater0" ;;
588 if test -f $r && test -f $m ; then
590 \\begin{frame}{Run $R --- $T}
592 \\begin{column}{.48\\linewidth}
594 \\includegraphics[keepaspectratio,width=\\linewidth]{%
597 \\begin{column}{.48\\linewidth}
598 \\textbf{Simulated}\\\\
599 \\includegraphics[keepaspectratio,width=\\linewidth]{%
624 tgt=`collect_name "$ff" "$d" "$M"`
625 if test "x$tgt" = "x" ; then
628 tgt=`printf "%s_%09d.pdf" $tgt $run`
629 # printf "%100s -> %s\n" $ff $tgt
630 if test ! -f $ff ; then
631 echo "$ff not found - ignored"
635 done # for f in files
641 local ff="$1" ; shift
645 */forward_mccorr.pdf) tgt=summary_mccorr ;;
646 */forward.pdf) tgt=summary_${d}_${M} ;;
647 */forward_dndeta.pdf) tgt=summary_${d}_${M} ;;
648 */forward_multdists.pdf) tgt=summary_${d}_${M} ;;
649 */forward_elossfits.pdf) tgt=summary_${d}_${M} ;;
650 */dNdeta*.pdf) tgt=${d}_${M} ;;
651 *) echo "Don't know how to deal with $ff" >/dev/stderr
661 # --- Clean up -------------------------------------------------------
664 for i in acc aod corrs dndeta dndeta_inel dndeta_inelgt0 dndeta_nsd \
667 if test ! -d ${name}_${j}${i}_${now} ; then
670 rm -rf ${name}_${j}${i}_${now}
671 rm -f last_${name}_${j}${i}
675 for i in fmd_corrections.root spd_corrections.root deadstrips.C ; do
676 if test ! -L $i ; then
679 rm -f fmd_corrections.root
686 # === Wrappers =======================================================
687 # --- Run all correction jobs ----------------------------------------
688 # This assumes the function allAboard
691 allAboard mccorr "" $@
692 allAboard mceloss "" $@
693 allAboard eloss "" $@
697 (cd ${name}_mccorr_${now} && terminate)
698 (cd ${name}_mceloss_${now} && terminate)
699 (cd ${name}_eloss_${now} && terminate)
701 # Run post processing
704 (cd ${name}_mccorr_${now} && post ../${name}_corrs_${now})
705 (cd ${name}_mceloss_${now} && post ../${name}_corrs_${now} )
706 (cd ${name}_eloss_${now} && post ../${name}_corrs_${now} )
707 rm -f fmd_corrections.root spd_corrections.root
708 ln -s ${name}_corrs_${now}/fmd_corrections.root .
709 ln -s ${name}_corrs_${now}/spd_corrections.root .
712 # This assumes the function extract_upload
721 # --- Run all AOD jobs -----------------------------------------------
724 allAboard mcaod "" $@
729 (cd ${name}_mcaod_${now} && terminate)
730 (cd ${name}_aod_${now} && terminate)
742 (cd ${name}_mcaod_${now} && post)
743 (cd ${name}_aod_${now} && post)
745 # --- Run all dN/deta jobs -------------------------------------------
748 if test $sys -eq 1 ; then
749 allAboard mcdndeta inel $@
750 allAboard mcdndeta nsd $@
751 allAboard mcdndeta inelgt0 $@
752 allAboard dndeta inel $@
753 allAboard dndeta nsd $@
754 allAboard dndeta inelgt0 $@
756 allAboard mcdndeta "" $@
757 allAboard dndeta "" $@
762 if test $sys -eq 1 ; then
763 (cd ${name}_mcdndeta_inel_${now} && terminate)
764 (cd ${name}_mcdndeta_nsd_${now} && terminate)
765 (cd ${name}_mcdndeta_inelgt0_${now} && terminate)
766 (cd ${name}_dndeta_inel_${now} && terminate)
767 (cd ${name}_dndeta_nsd_${now} && terminate)
768 (cd ${name}_dndeta_inelgt0_${now} && terminate)
770 (cd ${name}_mcdndeta_${now} && terminate)
771 (cd ${name}_dndeta_${now} && terminate)
784 if test $sys -eq 1 ; then
785 (cd ${name}_mcdndeta_inel_${now} && post)
786 (cd ${name}_mcdndeta_nsd_${now} && post)
787 (cd ${name}_mcdndeta_inelgt0_${now} && post)
788 (cd ${name}_dndeta_inel_${now} && post)
789 (cd ${name}_dndeta_nsd_${now} && post)
790 (cd ${name}_dndeta_inelgt0_${now} && post)
792 (cd ${name}_mcdndeta_${now} && post)
793 (cd ${name}_dndeta_${now} && post)
796 # --- Run all MultDists -------------------------------------------
799 allAboard mcmultdists "" $@
800 allAboard multdists "" $@
802 multdists_terminate()
804 (cd ${name}_mcmultdists_${now} && terminate)
805 (cd ${name}_multdists_${now} && terminate)
813 (cd ${name}_mcmultdists_${now} && post)
814 (cd ${name}_multdists_${now} && post ../${name}_mcmultdists_${now})
817 # === Driver code ====================================================
820 # handle_option ARG [OPT]
828 # --- Source settings if found -----------------------------------
829 if test -f $dotconf ; then
834 # --- Process command line -------------------------------------------
839 while test $# -gt 0 ; do
847 arg=`echo $1 | sed 's/=.*//'` ;
848 opt=`echo $1 | sed 's/--[^=][^=]*=//'`
853 -*) opt=$2 ; handled_opt=1 ;;
856 # echo "Run: Processing '$arg' ('$opt')"
858 -w|--what) what=`echo $opt | tr '[A-Z]' '[a-z]'` ;;
859 -s|--step) step=`echo $opt | tr '[A-Z]' '[a-z]'` ;;
860 -N|--noact) noact=1 ;;
861 -h|--help) usage ; exit 0 ;;
862 -H|--manual) manual ; exit 0 ;;
865 if test $handled_arg -lt 1 ; then
868 # echo "Pushed $1 -> ${parg[@]}"
869 if test $handled_opt -gt 0 ; then
872 # echo "Pushed $2, gobble $2 -> ${parg[@]}"
876 if test $handled_opt -gt 0 ; then
883 # For backward compatibility
884 while test $# -gt 0 ; do
889 # --- Select what to do ------------------------------------------
892 setup) setup ${parg[@]} ; exit 0 ;;
893 clean) cleanup ; exit 0 ;;
896 dndeta*) func=dndetas ;;
897 multdist*)func=multdists ;;
898 collect*) func=collect ;;
899 *) echo "$0: Unknown operation: $what" > /dev/stderr ; exit 1 ;;
902 # --- Check settings ---------------------------------------------
908 setup|clean|collect) step=full ;;
913 xterm*) func=${func}_terminate ;;
914 xup*) func=${func}_upload ;;
915 xdr*) func=${func}_draw ;;
916 xpo*) func=${func}_post ;;
917 *) echo "$0: Unknown step $step" > /dev/stderr ; exit 1 ;;
920 echo "Will execute $func (${parg[@]})"