]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/liteAnalysis.sh
Updates
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / liteAnalysis.sh
1 #!/bin/bash
2
3 # BEGIN_MANUAL
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. 
9
10 # Then, one needs to run this script in set-up mode e.g., 
11
12 #   $0 --what=setup  \
13 #       --name=LHC10c \
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
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. 
28
29 # Next, we need to generate the corrections.  Do 
30
31 #   $0 --what=corr 
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
36 #   $0 --what=corr --step=upload 
37 #   $0 --what=corr --step=draw
38
39 # If you already have the corrections, you can pass the option
40 # --corrections in the setup phase and skip this step.
41
42 # Now we can submit our AOD generation jobs.  Do 
43
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
51
52 # Next, we need to draw the summary results
53
54 #   $0 --what=aod --step=draw 
55
56 # Now, we should do the dN/deta analysis.  Do 
57
58 #   $0 --what=dndeta
59
60 # and wait for the jobs to finish and terminate.  Again, additional
61 # options to the train can be passed after --.  If you passed the
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
65
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 
72
73 # To collect all PDFs into a single directory do 
74
75 #   $0 --what=collect
76
77 # Enjoy.
78
79 # Comments, questions, bugs, flames, suggestions, etc. should be sent
80 # to Christian Holm Christensen <cholm@nbi.dk>
81
82 # END_MANUAL
83 if test ! -f $ALICE_ROOT/PWGLF/FORWARD/analysis2/baseAnalysis.sh  ; then 
84     echo "baseAnalysis not found!" > /dev/stderr 
85     exit 1
86 fi
87 . $ALICE_ROOT/PWGLF/FORWARD/analysis2/baseAnalysis.sh 
88
89 run=
90 real_dir=
91 real_pat=
92 real_idx=
93 mc_dir=
94 mc_pat=
95 mc_idx=
96 my_real_dir=
97 my_mc_dir=
98 par=0
99
100 # === Various functions ==============================================
101
102
103 # === Implement base functions =======================================
104 # --- Usage ----------------------------------------------------------
105 setup_usage()
106 {
107     cat <<EOF
108   -r,--run=NUMBER           Specify run number ($run)
109   -d,--real-dir=DIR         Directory holding real data ($real_dir)
110   -p,--real-pattern=PATTERN Glob pattern to match when searching ($real_pat)
111   -D,--mc-dir=DIR           Directory holding MC data ($mc_dir)
112   -P,--mc-pattern=PATTERN   Glob pattern to match when searching ($mc_pat)
113   -W,--workers=N            Number of workers ($nwrks)
114   -a,--par                  Use par files ($par)
115 EOF
116 }
117 # --- handle setup options -------------------------------------------
118 handle_setup_option()
119 {
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
132 }
133
134 # --- Generic draw ---------------------------------------------------
135 draw()
136 {
137     _draw $@ 
138 }
139 # --- Draw dN/deta ---------------------------------------------------
140 dndeta_draw()
141 {
142     _dndeta_draw $@ 
143 }
144 # --- Extract and upload ---------------------------------------------
145 extract_upload()
146 {
147     echo "=== Download, extract, and uploade in `basename $PWD` ==="
148     extract
149     upload
150 }
151
152 # --- Get the grid home dir ------------------------------------------
153 outputs()
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 }
161 # --- Dump the setup -------------------------------------------------
162 dump_setup()
163 {
164     local out=$1 
165     cat >> ${out} <<-EOF 
166         # Run analysed 
167         run=${run}      
168         # Real data 
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}
175         # Output 
176         my_real_dir=${my_real_dir}
177         my_mc_dir=${my_mc_dir}
178         par=${par}
179         EOF
180 }
181
182 run_for_acc()
183 {
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
189 }
190 # --- Run set-ups ----------------------------------------------------
191 setup()
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 }    
220
221 # --- Check settings -------------------------------------------------
222 check_setup()
223 {
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
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 
234         # exit 1
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 
242         # exit 1
243     fi
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 }
251 # --- Run clean-up ----------------------------------------------------
252 cleanup()
253 {
254     rm -f ${real_idx} ${mc_idx} 
255     _cleanup
256 }
257
258
259 # === Script specific functions ======================================
260 # --- Create the index -----------------------------------------------
261 index()
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
276     if test ! -d $d && test ! -f $d ;then 
277         echo "Specified input ($d) for $t data is not a directory or file " \
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++
286 ChainBuilder::CreateCollection("${o}", "file://${d}?recursive&scan&pattern=${p}${n}#esdTree");
287 .q
288 EOF
289     
290 }
291  
292
293 # --- Show the setup -------------------------------------------------
294 print_setup()
295 {
296     cat <<-EOF
297         Run:                    ${run}
298         Real data:
299           Directory:            ${real_dir}
300           Pattern:              ${real_pat}
301           Output:               ${my_real_dir}
302         MC data:
303           Directory:            ${mc_dir}
304           Pattern:              ${mc_pat}
305           Output:               ${my_mc_dir}
306         Use PAR files:          ${par}
307         Number of workers:      ${nwrks}/${ncpu}
308         EOF
309 }
310
311 # --- Make URI -------------------------------------------------------
312 url_opts()
313 {
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
324
325     case $type in 
326         *dndeta|*multdists)
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             ;;
334     esac
335     if test ! -f $inp ; then 
336         echo "No input for $nme, giving up" > /dev/stderr 
337         return 
338     fi
339     if test $mc -gt 0; then 
340         uopt="${uopt}&mc"
341     fi
342     if test $par -gt 0 ; then 
343         uopt="${uopt}&par=tasks"
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}"
364
365 }
366
367
368 # === Procedual code =================================================
369 runIt $@
370
371 #
372 # EOF
373 #
374