4 # Script to help do PWGLF-Forward analsysis using ProofLite
5 # =========================================================
6 # First, one need to figure out what to analyse. We assume we have
7 # the ESDs from a real run in some directory - possibly in
8 # sub-directories, and similar for the MC data.
10 # Then, one needs to run this script in set-up mode e.g.,
15 # --real-dir=/data/alice/data/pp/lhc10c/000118560/pass3 \
16 # --real-pattern=AliESDs_*.root \
17 # --mc-dir=/data/alice/data/pp/lhc10c/sim/lhc13d4/118560 \
18 # --mc-pattern=root_archive.zip@AliESDs.root
20 # Note, all the settings are written to the file .config in the
21 # current directory, so you do not need to give the parameters at
22 # subsequent steps. Note, you need a valid AliEn token to at this
23 # point to get the acceptance corrections. The run number specified
24 # is only used for getting the acceptance correction.
26 # Note, the use of the ZIP archives root_archive.zip and the sub-part
27 # specification @AliESDs.root for MC data.
29 # Next, we need to generate the corrections. Do
33 # and wait for the jobs to finish and terminate. Next, we need to
34 # extract and upload the corrections to our local corrections folder
36 # $0 --what=corr --step=upload
38 # If you already have the corrections, you can pass the option
39 # --corrections in the setup phase and skip this step.
41 # Now we can submit our AOD generation jobs. Do
45 # and wait for the jobs to finish and terminate. If you need to pass
46 # additional options to the train, one can do so after the special
47 # option -- e.g., to limit the number of events to 100000, do
49 # $0 --what=aod -- --events=100000
51 # Next, we need to draw the summary results
53 # $0 --what=aod --step=draw
55 # Now, we should do the dN/deta analysis. Do
59 # and wait for the jobs to finish and terminate. Again, additional
60 # options to the train can be passed after --. if you passed the
61 # option --sys=1 in the setup phase, then this will run 3 jobs for
62 # real and MC each - one for INEL, INEL>0, and NSD (V0-AND). Next, we
63 # need to draw the summary and final plot
65 # $0 --what=dndeta --step=draw
67 # To generate the P(Nch) data, do
70 # $0 --what=multdists --step=draw
72 # To collect all PDFs into a single directory do
78 # Comments, questions, bugs, flames, suggestions, etc. should be sent
79 # to Christian Holm Christensen <cholm@nbi.dk>
94 fwd_dir=$ALICE_ROOT/PWGLF/FORWARD/analysis2
111 # === Various functions ==============================================
112 # --- Usage ----------------------------------------------------------
116 Usage: $0 --what OPERATION [OPTIONS]
119 -r,--run=NUMBER Specify run number ($run)
120 -n,--name=STRING Base name of jobs ($name)
121 -S,--sys=SYSTEM Collision system ($sys)
122 -E,--snn=ENERGY Center of mass energy per nuclean pair ($snn)
123 -F,--field=FIELD L3 magnetic field ($field)
124 -d,--real-dir=ALIEN_DIR Directory holding real data ($real_dir)
125 -p,--real-pattern=PATTERN Glob pattern to match when searching ($real_pat)
126 -D,--mc-dir=ALIEN_DIR Directory holding MC data ($mc_dir)
127 -P,--mc-pattern=PATTERN Glob pattern to match when searching ($mc_pat)
128 -s,--step=STEP Run stage ($step)
129 -w,--what=TRAINS What to do
130 -c,--corrections=DIR Directory where corrections are stored ($corrs)
131 -W,--workers=N Number of workers ($nwrks)
132 -a,--par Use par files ($par)
133 -u,--url-opts=OPTIONS Additional user options ($uuopts)
134 -M,--man Show the manual
135 -N,--noact Show what will be done
139 clean Clean directory
140 setup Do intial setup
141 corrs Generate corrections
143 dndeta Generate dNdeta
145 and must be executed in that order. STEP is one of
147 full Run the analysis
148 upload Upload corrections (only for TRAINS=corrs)
149 draw Draw (partial) results
153 # --- Manual ---------------------------------------------------------
158 sed -n -e '/BEGIN_MANUAL/,/END_MANUAL/ p' | \
159 sed -e '/\(BEGIN\|END\)_MANUAL/ d' -e 's/^# //' \
163 # === Utilities to execute scripts ===================================
164 # --- Check AliEn token ----------------------------------------------
168 genv_file=/tmp/gclient_env_${uid}
170 if test ! -f ${genv_file} ; then
171 echo "No such file: ${genv_file}, please do alien-token-init" \
176 alien-token-info | grep -q "Token is still valid"
177 if test $? -ne 0 ; then
178 echo "Token not valid, please re-new" > /dev/stderr
182 # --- Run script -----------------------------------------------------
186 local args=$1 ; shift
187 echo "Will run aliroot -l -b -q $scr($args)"
188 if test $noact -gt 0 ; then return ; fi
194 # --- Run acceptance generation --------------------------------------
199 script ${fwd_dir}/corrs/ExtractAcceptance.C "${run}"
201 # --- Create the index -----------------------------------------------
209 if test $m -gt 0 ; then
213 .L $ALICE_ROOT/PWGLF/FORWARD/trains/ChainBuilder.C++
214 ChainBuilder::CreateCollection("${o}", "file://${d}?recursive&scan&pattern=${p}${n}#esdTree");
220 # --- Extract corrections --------------------------------------------
223 test -f .extract && return 0
227 # --- Upload a file --------------------------------------------------
230 if test -f .upload ; then
231 echo "Already uploaded in `basename $PWD`"
235 script Upload.C \"file://${here}/${name}_corrs_${now}/\" >/dev/null 2>&1
238 # --- Extract and upload ---------------------------------------------
245 # --- Draw -----------------------------------------------------------
253 echo "=== $d ================================================"
255 draw ${fwd_dir}/DrawdNdetaSummary.C && \
259 # --- Get the grid home dir ------------------------------------------
263 my_real_dir="$l/${name}_aod_${now}"
264 my_mc_dir="$l/${name}_mcaod_${now}"
265 real_idx="$l/${name}_index_${now}.root"
266 mc_idx="$l/${name}_mcindex_${now}.root"
269 # === Trains =========================================================
270 # --- Run set-ups ----------------------------------------------------
273 if test x$run = "x" || test $run -lt 1; then
274 echo "No run for acceptance correction specified" > /dev/stderr
278 now=`date '+%Y%m%d_%H%M'`
281 # Write settings to a file, which we later can source
283 if test $par -gt 0 ; then dumpvar="--par " ; fi
284 cat > ${dotconf} <<EOF
297 my_real_dir=${my_real_dir}
298 my_mc_dir=${my_mc_dir}
302 # Trigger efficiencies - edit here to set them
304 inelgt0_eff=$inelgt0_eff
308 $0 --what=setup --name="$name" --run="$run" \
309 --sys="$sys" --snn="$snn" --field="$field" \
310 --real-dir="${real_dir}" --real-pattern="${real_pat}" \
311 --mc-dir="${mc_dir}" --mc-pattern="${mc_pat}" \
312 --now=${now} --url-opts="${uuopts}" ${dumpvar}
315 corrdir=${name}_corrs_${now}
316 if test "x$corrs" != "x" && test -d ${corrs} ; then
317 echo "Linking ${corrs} to ${corrdir}"
318 ln -sf $corrs ${corrdir}
319 ln -sf $corrs last_${name}_corrs
321 elif test $noact -lt 1 ; then
322 mkdir -p ${name}_acc_${now}
324 rm -f last_${name}_acc last_${name}_corrs
325 ln -sf ${name}_acc_${now} last_${name}_acc
326 ln -sf ${name}_corrs_${now} last_${name}_corrs
327 cat <<-EOF > ${corrdir}/Browse.C
330 const char* fwd = "$ALICE_ROOT/PWGLF/FORWARD/analysis2";
331 if (!gROOT->GetClass("AliOADBForward"))
332 gROOT->Macro(Form("%s/scripts/LoadLibs.C", fwd));
333 gROOT->LoadMacro(Form("%s/corrs/ForwardOADBGui.C++g", fwd));
335 AliOADBForward* db = new AliOADBForward;
336 db->Open("fmd_corrections.root", "*");
343 echo "Make acceptance corrections"
344 (cd ${name}_acc_${now} && \
345 accGen $run_for_acc && \
348 for i in fmd_corrections.root spd_corrections.root deadstrips.C ; do
349 if test ! -f ${corrdir}/$i ; then continue ; fi
350 echo "Linking ${corrdir}/$i here"
351 ln -fs ${corrdir}/$i .
354 # create index - unless there's one in the input directory - then
355 # take that and link here
356 if test -f ${real_dir}/index.root ; then
357 ln -fs ${real_dir}/index.root ${real_idx}
359 if test ! -f ${real_idx} ; then
360 index ${real_idx} ${real_dir} "${real_pat}" 0
364 # create index - unless there's one in the input directory - then
365 # take that and link here
366 if test -f ${mc_dir}/index.root ; then
367 ln -fs ${mc_dir}/index.root ${mc_idx}
369 if test ! -f ${mc_idx} ; then
370 index ${mc_idx} ${mc_dir} "${mc_pat}" 0
376 # --- Run set-ups ----------------------------------------------------
381 ${name}_mccorr_${now} \
382 ${name}_mceloss_${now} \
383 ${name}_eloss_${now} \
384 ${name}_mcaod_${now} \
386 ${name}_mcdndeta_${now} \
387 ${name}_dndeta_${now} \
388 ${name}_corrs_${now} \
394 # --- Check settings -------------------------------------------------
398 if test "x$run" = "x" || test $run -lt 1 ; then
399 echo "Run not specified, or invalid ($run)" > /dev/stderr
402 if test "X$name" = X ; then
403 echo "No name specified" > /dev/stderr
406 # if test "x$sys" = "x" ; then
407 # echo "No collision system specified" > /dev/stderr
410 # if test "x$snn" = "x" ; then
411 # echo "No center of mass energy specified" > /dev/stderr
414 # if test "x$field" = "x" ; then
415 # echo "No L3 field setting specified" > /dev/stderr
418 if test "x$real_dir" = "x" ; then
419 echo "No real data directory specified" > /dev/stderr
422 if test "x$mc_dir" = "x" ; then
423 echo "No MC data directory specified" > /dev/stderr
426 if test "x$real_pat" = "x" ; then
427 echo "No real data pattern specified" > /dev/stderr
430 if test "x$mc_pat" = "x" ; then
431 echo "No MC data pattern specified" > /dev/stderr
434 if test "X$w" != "Xsetup" && test "x$now" = "x" ; then
435 echo "No date/time specified" > /dev/stderr
438 # sys==0 is OK - autoselect
441 xpbpb|xpb-pb|xaa|xa-a) sys=2 ;;
442 xppb|xp-pb|xpa|xp-a) sys=3 ;;
445 *) echo "$0: Unknown system: $sys" ; exit 1 ;;
448 ncpu=`cat /proc/cpuinfo|sed -n 's/^processor[ \t]*: \(.*\)/\1/p'|wc -l`
449 if test "x$nwrks" = "x" || test $nwrks -lt 1 ; then
451 echo "Setting number of workers to $nwrks / $ncpu"
455 # --- Show the setup -------------------------------------------------
461 Collision system: $sys
462 sqrt(s_NN): ${snn}GeV
464 Real input directory: ${real_dir}
465 Real file pattern: ${real_pat}
466 MC input directory: ${mc_dir}
467 MC file pattern: ${mc_pat}
468 Real output: ${my_real_dir}
469 MC output directory: ${my_mc_dir}
470 Use PAR files: ${par}
472 Additional URL options: ${uuopts}
473 Number of workers: ${nwrks}/${ncpu}
477 # --- Run the train --------------------------------------------------
489 uopt="mode=default&workers=${nwrks}"
499 # Default dirs are production dirs
505 *corr) cl=MakeMCCorrTrain ; mc=1 ;;
506 *eloss) cl=MakeFMDELossTrain ;;
507 *aod) cl=MakeAODTrain
508 opts="${opts} --corr=."
509 # opts="--corr=${name}_corrs_${now} --cent"
510 # if test $sys -gt 0 && test $snn -gt 0 ; then
511 # opts="$opts --sys=${sys} --snn=${snn} --field=${field}"
514 *dndeta) cl=MakedNdetaTrain
516 opts="${opts} --cut-edges"
519 opts="$opts --scheme=trigger,event,background"
520 opts="$opts --trig=INEL"
523 opts="$opts --scheme=trigger,event"
524 opts="$opts --trig=V0AND"
527 opts="$opts --scheme=trigger,event"
528 opts="$opts --trig=INELGT0"
532 if test "x$trig" != "x" ; then
535 # Modify for input dir for our files
536 inp=$my_real_dir/AliAOD.root
537 if test $mc -gt 0 ; then
538 inp=$my_mc_dir/AliAOD.root
543 cl=MakeMultDistsTrain
545 # Modify for input dir for our files
546 inp=$my_real_dir/AliAOD.root
547 if test $mc -gt 0 ; then
548 inp=$my_mc_dir/AliAOD.root
551 *) echo "$0: Unknown type of train: $type" > /dev/stderr ; exit 1 ;;
553 # add centrality flag if we do not know what collision system we're
554 # looking at, or it's PbPb or pPb.
556 0|2|3) opts="$opts --cent" ;;
559 if test $mc -gt 0; then
562 if test $par -gt 0 ; then
565 if test x$uuopts != x ; then
566 uopt="${uopt}&${uuopts}"
568 # PROOF-lite URL form:
570 # lite://<datadir_or_list>[?<options>][#<treeName]
573 # clear=PKGS Clear packages ','-separated
574 # mc Assume simulation input
575 # mode=default|rec|sim AliROOT mode
576 # par=tasks|all Use par files
577 # pattern=GLOB File name pattern
578 # recursive Recursive scan [true]
579 # reset=soft|hard Reset cluster [hard]
580 # workers=N[x] Number of workers to use [8]
581 # wrapper=CMD Wrapper command []
583 url="lite://${inp}?${uopt}#${tree}"
584 opts="${opts} --include=$ALICE_ROOT/PWGLF/FORWARD/analysis2/trains"
585 opts="${opts} --date=${now} --class=$cl --name=$nme --verbose=0"
587 echo "Running train: runTrain ${opts} --url=${url} $@"
588 if test $noact -gt 0 ; then return ; fi
590 runTrain ${opts} --url=${url} $@
594 # === Wrappers =======================================================
595 # --- Run all correction jobs ----------------------------------------
598 allAboard mccorr "" $@
599 allAboard mceloss "" $@
600 allAboard eloss "" $@
604 (cd ${name}_mccorr_${now} && extract_upload)
605 (cd ${name}_mceloss_${now} && extract_upload)
606 (cd ${name}_eloss_${now} && extract_upload)
607 rm -f fmd_corrections.root spd_corrections.root
608 ln -s ${name}_corrs_${now}/fmd_corrections.root .
609 ln -s ${name}_corrs_${now}/spd_corrections.root .
613 (cd ${name}_mccorr_${now} && draw ${fwd_dir}/DrawMCCorrSummary.C)
614 (cd ${name}_mceloss_${now} && draw ${fwd_dir}/corrs/DrawCorrELoss.C 1)
615 (cd ${name}_eloss_${now} && draw ${fwd_dir}/corrs/DrawCorrELoss.C 0)
617 # --- Run all AOD jobs -----------------------------------------------
620 allAboard mcaod "" $@
625 echo "Upload does not make sense for AOD jobs"
629 (cd ${name}_mcaod_${now} && draw Summarize.C)
630 (cd ${name}_aod_${now} && draw Summarize.C)
633 # --- Run all dN/deta jobs -------------------------------------------
636 if test $sys -eq 1 ; then
637 allAboard mcdndeta inel $@
638 allAboard mcdndeta nsd $@
639 allAboard mcdndeta inelgt0 $@
640 allAboard dndeta inel $@
641 allAboard dndeta nsd $@
642 allAboard dndeta inelgt0 $@
644 allAboard mcdndeta "" $@
645 allAboard dndeta "" $@
650 echo "Upload does not make sense for dN/deta jobs"
654 if test $sys -eq 1 ; then
655 dndeta_draw ${name}_mcdndeta_inel_${now}
656 dndeta_draw ${name}_mcdndeta_nsd_${now}
657 dndeta_draw ${name}_mcdndeta_inelgt0_${now}
658 dndeta_draw ${name}_dndeta_inel_${now}
659 dndeta_draw ${name}_dndeta_nsd_${now}
660 dndeta_draw ${name}_dndeta_inelgt0_${now}
662 dndeta_draw ${name}_mcdndeta_${now}
663 dndeta_draw ${name}_dndeta_${now}
667 # --- Run all MultDists -------------------------------------------
670 allAboard mcmultdists "" $@
671 allAboard multdists "" $@
675 echo "Upload does not make sense for dN/deta jobs"
679 (cd ${name}_mcmultdists_${now} && draw Summarize.C)
680 (cd ${name}_multdists_${now} && draw Summarize.C)
683 # --- Collect PDFs ---------------------------------------------------
686 out=${name}_pdfs_${now}
689 dirs="corr eloss aod dndeta dndeta_inel dndeta_nsd dndeta_inelgt0 multdists"
690 for d in ${dirs} ; do
691 for m in "" "mc" ; do
692 dir=${name}_${m}${d}_${now}
698 if test ! -d $dir ; then
699 # echo "Directory ${dir} doesn't exist"
702 # echo "Will look in $dir"
705 corr) files="forward_mccorr.pdf" ;;
706 eloss) files="corrs*.pdf" ;;
707 aod) files="forward.pdf" ;;
708 dndeta*) files="forward_dndeta.pdf dndeta*.pdf" ;;
709 multdists) files="forward_multdists.pdf" ;;
710 *) echo "Unknown directory type: $d" > /dev/stder
718 */forward_mccorr.pdf) tgt=summary_mccorr.pdf ;;
719 */forward.pdf) tgt=summary_${d}_${M}.pdf ;;
720 */forward_dndeta.pdf) tgt=summary_${d}_${M}.pdf ;;
721 */forward_multdists.pdf) tgt=summary_${d}_${M}.pdf ;;
722 */corr*.pdf) tgt=summary_${d}_${M}.pdf ;;
723 */dndeta*.pdf) tgt=${d}_${M}.pdf ;;
724 *) echo "Don't know how to deal with $ff" >/dev/stderr
728 # printf "%100s -> %s\n" $ff $tgt
733 (cd ${out} && pdfjoin -q -o tmp.pdf \
734 --pdftitle "${name} summary ($now)" \
735 --twoside summary_*.pdf dndeta_*.pdf && \
736 pdfnup -q --nup 2x1 -o ${name}_summary_${now}.pdf tmp.pdf && \
738 (cd ${out} && pdfjoin -q -o tmp.pdf \
739 --pdftitle "${name} dN/deta ($now)" \
740 --twoside dndeta_*.pdf && \
741 pdfnup -q --nup 2x1 -o ${name}_dndeta_${now}.pdf tmp.pdf && \
743 echo "Made ${name}_summary_${now}.pdf and ${name}_dndeta_${now}.pdf"
745 # === Procedual code =================================================
746 # --- Source settings if found ---------------------------------------
747 if test -f $dotconf ; then
752 # --- Process command line -------------------------------------------
755 while test $# -gt 0 ; do
761 arg=`echo $1 | sed 's/=.*//'` ;
762 opt=`echo $1 | sed 's/--[^=][^=]*=//'`
767 -*) opt=$2 ; shift ;;
772 -r|--run) run=$opt ;;
773 -n|--name) name=$opt ;;
774 -S|--sys) sys=`echo $opt | tr '[A-Z]' '[a-z]'` ;;
775 -E|--snn) snn=$opt ;;
776 -F|--field) field=$opt ;;
777 -d|--real-dir) real_dir=$opt ;;
778 -p|--real-pattern) real_pat=$opt ;;
779 -D|--mc-dir) mc_dir=$opt ;;
780 -P|--mc-pattern) mc_pat=$opt ;;
781 -w|--what) what=`echo $opt | tr '[A-Z]' '[a-z]'` ;;
782 -s|--step) step=`echo $opt | tr '[A-Z]' '[a-z]'` ;;
783 -W|--workers) nwrks=${opt} ;;
784 -N|--noact) noact=1 ;;
785 -c|--corrections) corrs=$opt ;;
787 -u|--url-opts) uuopts="$opt" ;;
788 -h|--help) usage ; exit 0 ;;
789 -H|--manual) manual ; exit 0 ;;
791 *) echo "$0: Unknown option $arg" ; exit 1 ;;
795 # --- Check settings -------------------------------------------------
798 # --- Select what to do ----------------------------------------------
801 setup) setup ; exit 0 ;;
802 clean) cleanup ; exit 0 ;;
805 dndeta*) func=dndetas ;;
806 multdist*)func=multdists ;;
807 collect*) func=collect ;;
808 *) echo "$0: Unknown operation: $what" > /dev/stderr ; exit 1 ;;
814 xterm*) func=${func}_terminate ;;
815 xup*) func=${func}_upload ;;
816 xdr*) func=${func}_draw ;;
817 *) echo "$0: Unknown step $step" > /dev/stderr ; exit 1 ;;
820 echo "Will execute $func"