4 # Script to help do PWGLF-Forward analsysis using AliEn
5 # =====================================================
6 # First, one need to figure out what to analyse. Visit the MonAlisa
9 # * The list of runs and put that in a file - say runs.list
10 # * The directory where the ESD files are stored
11 # - and the pattern that will match these for all runs
12 # * The directory where the MC ESD files are stored
13 # - and the pattern that will match these for all runs
15 # Then, one needs to run this script in set-up mode e.g.,
19 # --real-dir=/alice/data/2010/LHC10h \
20 # --real-pattern=ESDs/pass2/*/AliESDs.root \
21 # --mc-dir=/alice/sim/LHC10h11 \
22 # --mc-pattern=*/AliESDs.root \
26 # Note, all the settings are written to the file .config in the
27 # current directory, so you do not need to give the parameters at
28 # subsequent steps. As an alternative to giving the parameters, one
29 # can create the file by hand.
31 # Next, we need to generate the corrections. Do
35 # and wait for the jobs to finish and terminate. If 'watching' is
36 # turned off, one can also monitor output on MonAlisa, and then when
37 # enough has finished, execute
39 # $0 --what=corrs --step=terminate
41 # enough times to get the final merged result. Next, we need to
42 # extract and upload the corrections to our local corrections folder
44 # $0 --what=corrs --step=upload
46 # Now we can submit our AOD generation jobs. Do
50 # and wait for the jobs to finish and terminate. If 'watching' is
51 # turned off, one can also monitor output on MonAlisa, and then when
52 # enough has finished, execute
54 # $0 --what=aod --step=terminate
56 # enough times to get the final merged result. Next, we need to
57 # download the results and we draw the summary results
59 # $0 --what aod --step=draw
61 # Now, we should do the dN/deta analysis. Do
65 # and wait for the jobs to finish and terminate. If 'watching' is
66 # turned off, one can also monitor output on MonAlisa, and then when
67 # enough has finished, execute
69 # $0 --what=dndeta --step=terminate
71 # enough times to get the final merged result. Next, we need to download
72 # the results and we can draw the summary and final plot
74 # $0 --what=dndeta --step=draw
76 # When running the trains, one can pass additional options to the
77 # train after the special option -- e.g.,
79 # $0 --what=aod -- --verbose=2 --branches --satellite
83 # Comments, questions, bugs, flames, suggestions, etc. should be sent
84 # to Christian Holm Christensen <cholm@nbi.dk>
99 # aliroot="&aliroot=v5-03-75pATF-AN"
100 # root="root=v5-34-02-1"
101 fwd_dir=$ALICE_ROOT/PWGLF/FORWARD/analysis2
112 # === Various functions ==============================================
113 # --- Usage ----------------------------------------------------------
117 Usage: $0 --what OPERATION [OPTIONS]
120 -r,--runs=FILENAME Specify list of runs file ($runs)
121 -R,--mc-runs=FILENAME Specify list of MC runs file ($mcruns)
122 -n,--name=STRING Base name of jobs ($name)
123 -S,--sys=SYSTEM Collision system ($sys)
124 -E,--snn=ENERGY Center of mass energy per nuclean pair ($snn)
125 -F,--field=FIELD L3 magnetic field ($field)
126 -d,--real-dir=ALIEN_DIR Directory holding real data ($real_dir)
127 -p,--real-pattern=PATTERN Glob pattern to match when searching ($real_pat)
128 -D,--mc-dir=ALIEN_DIR Directory holding MC data ($mc_dir)
129 -P,--mc-pattern=PATTERN Glob pattern to match when searching ($mc_pat)
130 -s,--step=STEP Run stage ($step)
131 -w,--what=TRAINS What to do
132 -c,--corrections=DIR Directory where corrections are stored ($corrs)
133 -W,--watch Watch for job status and terminate automatically
134 -a,--par Use par files ($par)
135 -u,--url-opts=OPTIONS Additional user options ($uuopts)
136 -M,--man Show the manual
137 -N,--noact Show what will be done
141 clean Clean directory
142 setup Do intial setup
143 corrs Generate corrections
145 dndeta Generate dNdeta
147 and must be executed in that order. STEP is one of
149 full Run the analysis
150 terminate Terminate the job (may need iterations)
151 upload Upload corrections (only for TRAINS=corrs)
152 draw Draw (partial) results (not for TRAINS=corrs)
156 # --- Manual ---------------------------------------------------------
161 sed -n -e '/BEGIN_MANUAL/,/END_MANUAL/ p' | \
162 sed -e '/\(BEGIN\|END\)_MANUAL/ d' -e 's/^# //' \
166 # === Utilities to execute scripts ===================================
167 # --- Run script -----------------------------------------------------
171 local args=$1 ; shift
172 echo "Will run aliroot -l -b -q $scr($args)"
173 if test $noact -gt 0 ; then return ; fi
179 # --- Run acceptance generation --------------------------------------
183 script ${fwd_dir}/corrs/ExtractAcceptance.C "${run}"
186 # --- Extract corrections --------------------------------------------
191 # --- Extract corrections --------------------------------------------
194 if test -f .download ; then
195 echo "Already downloaded in `basename $PWD`"
201 # --- Extract corrections --------------------------------------------
204 test -f .extract && return 0
208 # --- Extract corrections --------------------------------------------
211 if test -f .extract ; then
212 echo "Aldready extracted in `basename $PWD`"
216 script ../Extract.C > /dev/null 2>&1
219 # --- Upload a file --------------------------------------------------
222 if test -f .upload ; then
223 echo "Already uploaded in `basename $PWD`"
227 script Upload.C \"file://${here}/${name}_corrs_${now}/\" >/dev/null 2>&1
230 # --- Extract and upload ---------------------------------------------
233 echo "=== Download, extract, and uploade in `basename $PWD` ==="
236 if test ! -f $i ; then continue ; fi
237 if test $noact -gt 0 ; then continue ; fi
238 local d=`basename $i .zip`
239 if test ! -d $d ; then
243 if test ! -f .zip ; then
244 echo "= Unpacking ../$i"
245 unzip ../$i > /dev/null 2>&1
254 # --- Draw -----------------------------------------------------------
260 if test "X$i" = "X*.zip" ; then continue ; fi
261 echo "Will extract $i"
263 if test ! -d $d ; then
267 (cd $d && script $scr)
274 draw ${fwd_dir}/DrawdNdetaSummary.C && \
278 # --- Get the grid home dir ------------------------------------------
281 l=`aliroot -l -b <<EOF
282 gSystem->RedirectOutput("/dev/null");
283 TGrid::Connect("alien://");
284 gSystem->RedirectOutput(0);
285 std::cout << gGrid->GetHomeDirectory() << std::endl;
287 my_real_dir="$l/${name}_aod_${now}/output"
288 my_mc_dir="$l/${name}_mcaod_${now}/output"
291 # === Trains =========================================================
292 # --- Run set-ups ----------------------------------------------------
295 run_for_acc=`grep -v ^# $runs | awk '{FS=" \n\t"}{printf "%d\n", $1}' | head -n 1`
296 if test x$run_for_acc = "x" || test $run_for_acc -lt 1; then
297 echo "No run for acceptance correction specified" > /dev/stderr
301 now=`date '+%Y%m%d_%H%M'`
304 # Write settings to a file, which we later can source
306 if test $par -gt 0 ; then dumpvar="--par " ; fi
307 if test $watch -gt 0 ; then dumpvar="${dumpvar} --watch " ; fi
308 cat > ${dotconf} <<EOF
320 my_real_dir=${my_real_dir}
321 my_mc_dir=${my_mc_dir}
328 $0 --what=setup --name="$name" --runs="$runs" --mcruns="$mcruns" \
329 --sys="$sys" --snn="$snn" --field="$field" \
330 --real-dir="${real_dir}" --real-pattern="${real_pat}" \
331 --mc-dir="${mc_dir}" --mc-pattern="${mc_pat}" \
332 --now=${now} --url-opts="${uuopts}" ${dumpvar}
335 corrdir=${name}_corrs_${now}
336 if test "x$corrs" != "x" && test -d ${corrs} ; then
337 echo "Linking ${corrs} to ${corrdir}"
338 ln -sf $corrs ${corrdir}
339 ln -sf $corrs last_${name}_corrs
341 elif test $noact -lt 1 ; then
342 mkdir -p ${name}_acc_${now}
344 rm -f last_${name}_acc last_${name}_corrs
345 ln -sf ${name}_acc_${now} last_${name}_acc
346 ln -sf ${name}_corrs_${now} last_${name}_corrs
347 cat <<-EOF > ${corrdir}/Browse.C
350 const char* fwd = "$ALICE_ROOT/PWGLF/FORWARD/analysis2";
351 if (!gROOT->GetClass("AliOADBForward"))
352 gROOT->Macro(Form("%s/scripts/LoadLibs.C", fwd));
353 gROOT->LoadMacro(Form("%s/corrs/ForwardOADBGui.C++g", fwd));
355 AliOADBForward* db = new AliOADBForward;
356 db->Open("fmd_corrections.root", "*");
363 echo "Make acceptance corrections"
364 (cd ${name}_acc_${now} && \
365 accGen $run_for_acc && \
368 for i in fmd_corrections.root spd_corrections.root deadstrips.C ; do
369 if test ! -f ${corrdir}/$i ; then continue ; fi
370 echo "Linking ${corrdir}/$i here"
371 ln -fs ${corrdir}/$i .
375 # --- Run set-ups ----------------------------------------------------
380 ${name}_mccorr_${now} \
381 ${name}_mceloss_${now} \
382 ${name}_eloss_${now} \
383 ${name}_mcaod_${now} \
385 ${name}_mcdndeta_*${now} \
386 ${name}_dndeta_*${now} \
387 ${name}_corrs_${now} \
390 last_${name}_mceloss \
394 last_${name}_mcdndeta* \
395 last_${name}_dndeta* \
397 if test -L fmd_corrections.root ; then
398 rm fmd_corrections.root
400 if test -L spd_corrections.root ; then
401 rm spd_corrections.root
405 # --- Check AliEn token ----------------------------------------------
409 genv_file=/tmp/gclient_env_${uid}
411 if test ! -f ${genv_file} ; then
412 echo "No such file: ${genv_file}, please do alien-token-init" \
417 alien-token-info | grep -q "Token is still valid"
418 if test $? -ne 0 ; then
419 echo "Token not valid, please re-new" > /dev/stderr
424 # --- Check settings -------------------------------------------------
428 if test "x$runs" = "x" || test ! -f $runs ; then
429 echo "List of run file $runs not found" > /dev/stderr
432 if test "x$mcruns" = "x" ; then mcruns=$runs ; fi
433 if test ! -f $mcruns ; then
434 echo "List of MC runs file $mcruns not found" > /dev/stderr
437 if test "X$name" = X ; then
438 echo "No name specified" > /dev/stderr
441 # if test "x$sys" = "x" ; then
442 # echo "No collision system specified" > /dev/stderr
445 # if test "x$snn" = "x" ; then
446 # echo "No center of mass energy specified" > /dev/stderr
449 # if test "x$field" = "x" ; then
450 # echo "No L3 field setting specified" > /dev/stderr
453 if test "x$real_dir" = "x" ; then
454 echo "No real data directory specified" > /dev/stderr
457 if test "x$mc_dir" = "x" ; then
458 echo "No MC data directory specified" > /dev/stderr
461 if test "x$real_pat" = "x" ; then
462 echo "No real data pattern specified" > /dev/stderr
465 if test "x$mc_pat" = "x" ; then
466 echo "No MC data pattern specified" > /dev/stderr
469 if test "X$w" != "Xsetup" && test "x$now" = "x" ; then
470 echo "No date/time specified" > /dev/stderr
473 # sys==0 is OK - autoselect
476 xpbpb|xpb-pb|xaa|xa-a) sys=2 ;;
477 xppb|xp-pb|xpa|xp-a) sys=3 ;;
480 *) echo "$0: Unknown system: $sys" ; exit 1 ;;
486 # --- Show the setup -------------------------------------------------
492 MC Run file: ${mcruns}
493 Collision system: $sys
494 sqrt(s_NN): ${snn}GeV
496 Real input directory: ${real_dir}
497 Real file pattern: ${real_pat}
498 MC input directory: ${mc_dir}
499 MC file pattern: ${mc_pat}
500 Real output: ${my_real_dir}
501 MC output directory: ${my_mc_dir}
502 Use PAR files: ${par}
504 Additional URL options: ${uuopts}
508 # --- Run the train --------------------------------------------------
519 uopt="&merge=50&split=50&aliroot=last,regular"
528 # Default dirs are production dirs
536 *corr) cl=MakeMCCorrTrain ; mc=1 ;;
537 *eloss) cl=MakeFMDELossTrain ;;
538 *aod) cl=MakeAODTrain
539 opts="${opts} --corr=."
540 # opts="--corr=${name}_corrs_${now} --cent"
541 # if test $sys -gt 0 && test $snn -gt 0 ; then
542 # opts="$opts --sys=${sys} --snn=${snn} --field=${field}"
545 *dndeta) cl=MakedNdetaTrain
547 uopt="${uopt}&concat"
548 opts="${opts} --cut-edges"
551 opts="$opts --scheme=trigger,event,background}"
552 opts="$opts --trig=INEL"
555 opts="$opts --scheme=trigger,event"
556 opts="$opts --trig=V0AND"
559 opts="$opts --scheme=trigger,event"
560 opts="$opts --trig=INELGT0"
564 if test "x$trig" != "x" ; then
567 # Modify for input dir for our files
570 if test $mc -gt 0 ; then
575 *) echo "$0: Unknown type of train: $type" > /dev/stderr ; exit 1 ;;
577 # add centrality flag if we do not know what collision system we're
578 # looking at, or it's PbPb or pPb.
580 0|2|3) opts="$opts --cent" ;;
583 if test $mc -gt 0; then
586 if test $par -gt 0 ; then
589 if test x$uuopts != x ; then
590 uopt="${uopt}&${uuopts}"
592 url="alien://${dir}?run=${rl}&pattern=${pat}${uopt}${aliroot}${root}#${tree}"
593 opts="${opts} --include=$ALICE_ROOT/PWGLF/FORWARD/analysis2/trains"
594 opts="${opts} --date=${now} --class=$cl --name=$nme --verbose=0"
596 echo "Running train: runTrain2 ${opts} --url=${url} $@"
597 if test $noact -gt 0 ; then return ; fi
599 runTrain ${opts} --overwrite --url=${url} $@
601 if test $watch -lt 1 ; then
603 Check https://alimonitor.cern.ch/users/jobs.jsp for progress
607 (cd ${nme}_${now} && aliroot -l -b -q Terminate.C)
609 until the final merge stage, and then do
611 (cd ${nme}_${now} && aliroot -l -b -q Download.C)
621 (cd ${nme}_${now} && aliroot -l -b -q Extract.C)
622 (cd ${nme}_${now} && aliroot -l -b -q 'Upload.C("local://${here}/${nam e}_corrs_${now}")')
624 to upload the results to our local corrections store.
631 (cd ${nme}_${now} && aliroot -l ${fwd_dir}/DrawAODSummary.C)
633 to get a PDF of the diagnostics histograms
640 (cd ${nme}_${now} && aliroot -l ${fwd_dir}/DrawdNdetaSummary.C)
642 to get a PDF of the diagnostics histograms, and
644 (cd ${nme}_${now} && aliroot -l Draw.C)
646 to get the final plot.
651 echo "Now waiting for jobs to finish"
652 (cd ${nme}_${now} && \
653 nice aliroot -l -b -x -q Watch.C\(1\) 2>&1 | \
654 tee watch.log > /dev/null &)
659 # === Wrappers =======================================================
660 # --- Run all correction jobs ----------------------------------------
663 allAboard mccorr "" $@
664 allAboard mceloss "" $@
665 allAboard eloss "" $@
669 (cd ${name}_mccorr_${now} && terminate)
670 (cd ${name}_mceloss_${now} && terminate)
671 (cd ${name}_eloss_${now} && terminate)
675 (cd ${name}_mccorr_${now} && extract_upload)
676 (cd ${name}_mceloss_${now} && extract_upload)
677 (cd ${name}_eloss_${now} && extract_upload)
678 rm -f fmd_corrections.root spd_corrections.root
679 ln -s ${name}_corrs_${now}/fmd_corrections.root .
680 ln -s ${name}_corrs_${now}/spd_corrections.root .
684 echo "Draw does not make sense for Correction jobs"
686 # --- Run all AOD jobs -----------------------------------------------
689 allAboard mcaod "" $@
694 (cd ${name}_mcaod_${now} && terminate)
695 (cd ${name}_aod_${now} && terminate)
699 echo "Upload does not make sense for AOD jobs"
703 (cd ${name}_mcaod_${now} && draw ${fwd_dir}/DrawAODSummary.C)
704 (cd ${name}_aod_${now} && draw ${fwd_dir}/DrawAODSummary.C)
707 # --- Run all dN/deta jobs -------------------------------------------
710 allAboard mcdndeta $@
711 if test $sys -eq 1 ; then
712 allAboard dndeta inel $@
713 allAboard dndeta nsd $@
714 allAboard dndeta inelgt0 $@
716 allAboard dndeta "" $@
721 (cd ${name}_mcdndeta_${now} && terminate)
722 if test $sys -eq 1 ; then
723 (cd ${name}_dndeta_inel_${now} && terminate)
724 (cd ${name}_dndeta_nsd_${now} && terminate)
725 (cd ${name}_dndeta_inelgt0_${now} && terminate)
727 (cd ${name}_dndeta_${now} && terminate)
732 echo "Upload does not make sense for dN/deta jobs"
736 dndeta_draw ${name}_mcdndeta_${now}
737 if test $sys -eq 1 ; then
738 dndeta_draw ${name}_dndeta_inel_${now}
739 dndeta_draw ${name}_dndeta_nsd_${now}
740 dndeta_draw ${name}_dndeta_inelgt0_${now}
742 dndeta_draw ${name}_dndeta_${now}
746 # === Procedual code =================================================
747 # --- Source settings if found ---------------------------------------
748 if test -f $dotconf ; then
753 # --- Process command line -------------------------------------------
756 while test $# -gt 0 ; do
762 arg=`echo $1 | sed 's/=.*//'` ;
763 opt=`echo $1 | sed 's/--[^=][^=]*=//'`
768 -*) opt=$2 ; shift ;;
773 -r|--runs) runs=$opt ;;
774 -R|--mc-runs) mcruns=$opt ;;
775 -n|--name) name=$opt ;;
776 -S|--sys) sys=`echo $opt | tr '[A-Z]' '[a-z]'` ;;
777 -E|--snn) snn=$opt ;;
778 -F|--field) field=$opt ;;
779 -d|--real-dir) real_dir=$opt ;;
780 -p|--real-pattern) real_pat=$opt ;;
781 -D|--mc-dir) mc_dir=$opt ;;
782 -P|--mc-pattern) mc_pat=$opt ;;
783 -w|--what) what=`echo $opt | tr '[A-Z]' '[a-z]'` ;;
784 -s|--step) step=`echo $opt | tr '[A-Z]' '[a-z]'` ;;
785 -W|--watch) let watch=\!$watch ;;
786 -N|--noact) noact=1 ;;
787 -c|--corrections) corrs=$opt ;;
789 -u|--url-opts) uuopts="$opt" ;;
790 -h|--help) usage ; exit 0 ;;
791 -H|--manual) manual ; exit 0 ;;
792 *) echo "$0: Unknown option $arg" ; exit 1 ;;
796 # --- Check settings -------------------------------------------------
799 # --- Select what to do ----------------------------------------------
802 setup) setup ; exit 0 ;;
803 clean) cleanup ; exit 0 ;;
806 dndeta*) func=dndetas ;;
807 *) echo "$0: Unknown operation: $what" > /dev/stderr ; exit 1 ;;
813 xterm*) func=${func}_terminate ;;
814 xup*) func=${func}_upload ;;
815 xdr*) func=${func}_draw ;;
816 *) echo "$0: Unknown step $step" > /dev/stderr ; exit 1 ;;
819 echo "Will execute $func"