]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/analysis2/liteAnalysis.sh
Major refactoring of the code.
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / liteAnalysis.sh
CommitLineData
bfab35d9 1#!/bin/bash
2#
3# BEGIN_MANUAL
1f7aa5c7 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.
bfab35d9 9#
10# Then, one needs to run this script in set-up mode e.g.,
11#
12# $0 --what=setup \
1f7aa5c7 13# --name=LHC10c \
bfab35d9 14# --run=118560 \
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
19#
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
1f7aa5c7 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.
25#
26# Note, the use of the ZIP archives root_archive.zip and the sub-part
27# specification @AliESDs.root for MC data.
bfab35d9 28#
29# Next, we need to generate the corrections. Do
30#
1f7aa5c7 31# $0 --what=corr
bfab35d9 32#
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
35#
1f7aa5c7 36# $0 --what=corr --step=upload
81775aba 37# $0 --what=corr --step=draw
1f7aa5c7 38#
39# If you already have the corrections, you can pass the option
40# --corrections in the setup phase and skip this step.
bfab35d9 41#
42# Now we can submit our AOD generation jobs. Do
43#
1f7aa5c7 44# $0 --what=aod
45#
46# and wait for the jobs to finish and terminate. If you need to pass
47# additional options to the train, one can do so after the special
48# option -- e.g., to limit the number of events to 100000, do
49#
50# $0 --what=aod -- --events=100000
bfab35d9 51#
1f7aa5c7 52# Next, we need to draw the summary results
bfab35d9 53#
1f7aa5c7 54# $0 --what=aod --step=draw
bfab35d9 55#
56# Now, we should do the dN/deta analysis. Do
57#
1f7aa5c7 58# $0 --what=dndeta
bfab35d9 59#
1f7aa5c7 60# and wait for the jobs to finish and terminate. Again, additional
81775aba 61# options to the train can be passed after --. If you passed the
1f7aa5c7 62# option --sys=1 in the setup phase, then this will run 3 jobs for
63# real and MC each - one for INEL, INEL>0, and NSD (V0-AND). Next, we
64# need to draw the summary and final plot
bfab35d9 65#
1f7aa5c7 66# $0 --what=dndeta --step=draw
67#
68# To generate the P(Nch) data, do
69#
70# $0 --what=multdists
71# $0 --what=multdists --step=draw
bfab35d9 72#
73# To collect all PDFs into a single directory do
1f7aa5c7 74#
bfab35d9 75# $0 --what=collect
1f7aa5c7 76#
77# Enjoy.
78#
79# Comments, questions, bugs, flames, suggestions, etc. should be sent
80# to Christian Holm Christensen <cholm@nbi.dk>
bfab35d9 81#
82# END_MANUAL
c7a8b4d9 83if test ! -f $ALICE_ROOT/PWGLF/FORWARD/analysis2/baseAnalysis.sh ; then
84 echo "baseAnalysis not found!" > /dev/stderr
85 exit 1
86fi
87. $ALICE_ROOT/PWGLF/FORWARD/analysis2/baseAnalysis.sh
bfab35d9 88
89run=
bfab35d9 90real_dir=
91real_pat=
92real_idx=
93mc_dir=
94mc_pat=
95mc_idx=
96my_real_dir=
97my_mc_dir=
c8b1a7db 98par=0
bfab35d9 99
100# === Various functions ==============================================
c7a8b4d9 101
102
103# === Implement base functions =======================================
bfab35d9 104# --- Usage ----------------------------------------------------------
c7a8b4d9 105setup_usage()
bfab35d9 106{
107 cat <<EOF
bfab35d9 108 -r,--run=NUMBER Specify run number ($run)
d43c6cd0 109 -d,--real-dir=DIR Directory holding real data ($real_dir)
bfab35d9 110 -p,--real-pattern=PATTERN Glob pattern to match when searching ($real_pat)
d43c6cd0 111 -D,--mc-dir=DIR Directory holding MC data ($mc_dir)
bfab35d9 112 -P,--mc-pattern=PATTERN Glob pattern to match when searching ($mc_pat)
bfab35d9 113 -W,--workers=N Number of workers ($nwrks)
114 -a,--par Use par files ($par)
bfab35d9 115EOF
116}
c7a8b4d9 117# --- handle setup options -------------------------------------------
118handle_setup_option()
bfab35d9 119{
c7a8b4d9 120 local arg="$1"
121 local opt="$2"
122 case $arg in
123 -r|--run) run=$opt ;;
124 -d|--real-dir) real_dir=$opt ;;
125 -p|--real-pattern) real_pat=$opt ;;
126 -D|--mc-dir) mc_dir=$opt ;;
127 -P|--mc-pattern) mc_pat=$opt ;;
128 -W|--workers) nwrks=${opt} ;;
129 -a|--par) par=1 ;;
130 *) echo "$0: [SETUP] Unknown option $arg" ; exit 1 ;;
131 esac
bfab35d9 132}
bfab35d9 133
c7a8b4d9 134# --- Generic draw ---------------------------------------------------
135draw()
bfab35d9 136{
c7a8b4d9 137 _draw $@
bfab35d9 138}
c7a8b4d9 139# --- Draw dN/deta ---------------------------------------------------
140dndeta_draw()
bfab35d9 141{
c7a8b4d9 142 _dndeta_draw $@
bfab35d9 143}
144# --- Extract and upload ---------------------------------------------
145extract_upload()
146{
c7a8b4d9 147 echo "=== Download, extract, and uploade in `basename $PWD` ==="
bfab35d9 148 extract
149 upload
150}
151
bfab35d9 152# --- Get the grid home dir ------------------------------------------
153outputs()
154{
155 l=`pwd`
156 my_real_dir="$l/${name}_aod_${now}"
157 my_mc_dir="$l/${name}_mcaod_${now}"
158 real_idx="$l/${name}_index_${now}.root"
159 mc_idx="$l/${name}_mcindex_${now}.root"
160}
c7a8b4d9 161# --- Dump the setup -------------------------------------------------
162dump_setup()
bfab35d9 163{
c7a8b4d9 164 local out=$1
165 cat >> ${out} <<-EOF
166 # Run analysed
167 run=${run}
168 # Real data
81775aba 169 real_dir=${real_dir}
170 real_pat=${real_pat}
171 real_idx=${real_idx}
172 mc_dir=${mc_dir}
173 mc_pat=${mc_pat}
174 mc_idx=${mc_idx}
c7a8b4d9 175 # Output
81775aba 176 my_real_dir=${my_real_dir}
177 my_mc_dir=${my_mc_dir}
178 par=${par}
81775aba 179 EOF
c7a8b4d9 180}
bfab35d9 181
c7a8b4d9 182run_for_acc()
bfab35d9 183{
c7a8b4d9 184 if test x$run = "x" || test $run -lt 1; then
185 echo "No run for acceptance correction specified" > /dev/stderr
186 exit 1
187 fi
188 echo $run
bfab35d9 189}
c7a8b4d9 190# --- Run set-ups ----------------------------------------------------
191setup()
192{
193 echo "Calling _setup with $@"
194 _setup $@
195
196 # create index - unless there's one in the input directory - then
197 # take that and copy here
198 # [We'd like to link only, but ChainBuilder needs to be updated for that]
199 if test "x$real_dir" != x && test -f ${real_dir}/index.root ; then
200 rm -f ${real_idx}
201 cp ${real_dir}/index.root ${real_idx}
202 else
203 if test ! -f ${real_idx} ; then
204 index ${real_idx} ${real_dir} "${real_pat}" 0
205 fi
206 fi
207
208 # create index - unless there's one in the input directory - then
209 # take that and copy here
210 # [We'd like to link only, but ChainBuilder needs to be updated for that]
211 if test "x$real_dir" != x && test -f ${mc_dir}/index.root ; then
212 rm -f ${mc_idx}
213 cp ${mc_dir}/index.root ${mc_idx}
214 else
215 if test ! -f ${mc_idx} ; then
216 index ${mc_idx} ${mc_dir} "${mc_pat}" 0
217 fi
218 fi
219}
bfab35d9 220
221# --- Check settings -------------------------------------------------
c7a8b4d9 222check_setup()
bfab35d9 223{
bfab35d9 224 if test "x$run" = "x" || test $run -lt 1 ; then
225 echo "Run not specified, or invalid ($run)" > /dev/stderr
226 exit 1
227 fi
bfab35d9 228 if test "x$real_dir" = "x" ; then
229 echo "No real data directory specified" > /dev/stderr
230 exit 1
231 fi
232 if test "x$mc_dir" = "x" ; then
233 echo "No MC data directory specified" > /dev/stderr
d43c6cd0 234 # exit 1
bfab35d9 235 fi
236 if test "x$real_pat" = "x" ; then
237 echo "No real data pattern specified" > /dev/stderr
238 exit 1
239 fi
240 if test "x$mc_pat" = "x" ; then
241 echo "No MC data pattern specified" > /dev/stderr
d43c6cd0 242 # exit 1
bfab35d9 243 fi
bfab35d9 244
245 ncpu=`cat /proc/cpuinfo|sed -n 's/^processor[ \t]*: \(.*\)/\1/p'|wc -l`
246 if test "x$nwrks" = "x" || test $nwrks -lt 1 ; then
247 let nwrks=7*$ncpu/10
248 echo "Setting number of workers to $nwrks / $ncpu"
249 fi
250}
c7a8b4d9 251# --- Run clean-up ----------------------------------------------------
252cleanup()
253{
254 rm -f ${real_idx} ${mc_idx}
255 _cleanup
256}
257
258
259# === Script specific functions ======================================
260# --- Create the index -----------------------------------------------
261index()
262{
263 local o=$1 ; shift
264 local d=$1 ; shift
265 local p=$1 ; shift
266 local m=$1 ; shift
267
268 t=real
269 if test $m -gt 0 ; then
270 t=MC
271 fi
272 if test "x$d" = "x" ;then
273 echo "No input specified for index for $t data" > /dev/stderr
274 return;
275 fi
c8b1a7db 276 if test ! -d $d && test ! -f $d ;then
277 echo "Specified input ($d) for $t data is not a directory or file " \
c7a8b4d9 278 > /dev/stderr
279 return;
280 fi
281 if test $m -gt 0 ; then
282 n="&mc"
283 fi
284 aliroot -l -b <<EOF
285.L $ALICE_ROOT/PWGLF/FORWARD/trains/ChainBuilder.C++
286ChainBuilder::CreateCollection("${o}", "file://${d}?recursive&scan&pattern=${p}${n}#esdTree");
287.q
288EOF
289
290}
291
bfab35d9 292
293# --- Show the setup -------------------------------------------------
294print_setup()
295{
81775aba 296 cat <<-EOF
81775aba 297 Run: ${run}
c7a8b4d9 298 Real data:
c8b1a7db 299 Directory: ${real_dir}
300 Pattern: ${real_pat}
301 Output: ${my_real_dir}
c7a8b4d9 302 MC data:
c8b1a7db 303 Directory: ${mc_dir}
304 Pattern: ${mc_pat}
305 Output: ${my_mc_dir}
81775aba 306 Use PAR files: ${par}
81775aba 307 Number of workers: ${nwrks}/${ncpu}
81775aba 308 EOF
bfab35d9 309}
310
c7a8b4d9 311# --- Make URI -------------------------------------------------------
312url_opts()
bfab35d9 313{
c7a8b4d9 314 local mc=$1 ; shift
315 local type=$1 ; shift
316 local trig=$1 ; shift
317 local uopt="mode=default&workers=${nwrks}"
318 local tree=esdTree
319
320 local inp=${real_idx}
321 if test $mc -gt 0 ; then
322 inp=${mc_idx}
323 fi
bfab35d9 324
325 case $type in
c7a8b4d9 326 *dndeta|*multdists)
bfab35d9 327 tree=aodTree
328 # Modify for input dir for our files
329 inp=$my_real_dir/AliAOD.root
330 if test $mc -gt 0 ; then
331 inp=$my_mc_dir/AliAOD.root
332 fi
333 ;;
bfab35d9 334 esac
d43c6cd0 335 if test ! -f $inp ; then
336 echo "No input for $nme, giving up" > /dev/stderr
337 return
338 fi
bfab35d9 339 if test $mc -gt 0; then
340 uopt="${uopt}&mc"
341 fi
342 if test $par -gt 0 ; then
c8b1a7db 343 uopt="${uopt}&par=tasks"
bfab35d9 344 fi
345 if test x$uuopts != x ; then
346 uopt="${uopt}&${uuopts}"
347 fi
348 # PROOF-lite URL form:
349 #
350 # lite://<datadir_or_list>[?<options>][#<treeName]
351 #
352 # Options:
353 # clear=PKGS Clear packages ','-separated
354 # mc Assume simulation input
355 # mode=default|rec|sim AliROOT mode
356 # par=tasks|all Use par files
357 # pattern=GLOB File name pattern
358 # recursive Recursive scan [true]
359 # reset=soft|hard Reset cluster [hard]
360 # workers=N[x] Number of workers to use [8]
361 # wrapper=CMD Wrapper command []
362
363 url="lite://${inp}?${uopt}#${tree}"
bfab35d9 364
bfab35d9 365}
366
bfab35d9 367
bfab35d9 368# === Procedual code =================================================
c7a8b4d9 369runIt $@
bfab35d9 370
371#
372# EOF
373#
374