]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/gridAnalysis.sh
Updates
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / gridAnalysis.sh
1 #!/bin/bash
2
3 # BEGIN_MANUAL
4 #       Script to help do PWGLF-Forward analsysis using AliEn
5 #       =====================================================
6 # First, one need to figure out what to analyse.  Visit the MonAlisa
7 # pages and find
8
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 
14
15 # Then, one needs to run this script in set-up mode e.g., 
16
17 #   $0 --what=setup  \
18 #       --name=LHC10h \
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 \
23 #       --runs=LHC10.list \
24 #       --par
25
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.
30
31 # Next, we need to generate the corrections.  Do 
32
33 #   $0 --what=corrs 
34
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
38
39 #   $0 --what=corrs --step=terminate 
40
41 # enough times to get the final merged result.  Next, we need to
42 # extract and upload the corrections to our local corrections folder
43
44 #   $0 --what=corrs --step=upload 
45 #   $0 --what=corrs --step=draw
46
47 # Now we can submit our AOD generation jobs.  Do 
48
49 #   $0 --what=aod
50
51 # and wait for the jobs to finish and terminate.  If 'watching' is
52 # turned off, one can also monitor output on MonAlisa, and then when
53 # enough has finished, execute
54
55 #   $0 --what=aod --step=terminate 
56
57 # enough times to get the final merged result.  Next, we need to
58 # download the results and we draw the summary results
59
60 #   $0 --what aod --step=draw 
61
62 # Now, we should do the dN/deta analysis.  Do 
63
64 #   $0 --what=dndeta
65
66 # and wait for the jobs to finish and terminate.  If 'watching' is
67 # turned off, one can also monitor output on MonAlisa, and then when
68 # enough has finished, execute
69
70 #   $0 --what=dndeta --step=terminate 
71
72 # enough times to get the final merged result.  If you passed the
73 # option --sys=1 in the setup phase, then this will run 3 jobs for
74 # real and MC each - one for INEL, INEL>0, and NSD (V0-AND). Next, we
75 # need to download the results and we can draw the summary and final
76 # plot
77
78 #   $0 --what=dndeta --step=draw 
79
80 # When running the trains, one can pass additional options to the
81 # train after the special option -- e.g., 
82 #   
83 #   $0 --what=aod -- --verbose=2 --branches --satellite
84
85 # Enjoy
86
87 # Comments, questions, bugs, flames, suggestions, etc. should be sent
88 # to Christian Holm Christensen <cholm@nbi.dk>
89
90 # END_MANUAL
91 if test ! -f $ALICE_ROOT/PWGLF/FORWARD/analysis2/baseAnalysis.sh  ; then 
92     echo "baseAnalysis not found!" > /dev/stderr 
93     exit 1
94 fi
95 . $ALICE_ROOT/PWGLF/FORWARD/analysis2/baseAnalysis.sh 
96
97 runs=
98 mcruns=
99 par=0
100 real_dir=
101 real_pat=
102 mc_dir=
103 mc_pat=
104 my_real_dir=
105 my_mc_dir=
106 watch=0
107
108 # === Various functions ==============================================
109
110
111 # === Implement base functions =======================================
112 # --- Usage ----------------------------------------------------------
113 setup_usage()
114 {
115     cat <<EOF
116   -r,--runs=FILENAME        Specify list of runs file ($runs)
117   -R,--mc-runs=FILENAME     Specify list of MC runs file ($mcruns)
118   -d,--real-dir=ALIEN_DIR   Directory holding real data ($real_dir)
119   -p,--real-pattern=PATTERN Glob pattern to match when searching ($real_pat)
120   -D,--mc-dir=ALIEN_DIR     Directory holding MC data ($mc_dir)
121   -P,--mc-pattern=PATTERN   Glob pattern to match when searching ($mc_pat)
122   -W,--watch                Watch for job status and terminate automatically
123   -a,--par                  Use par files ($par)
124 EOF
125 }
126 handle_setup_option()
127 {
128     local arg="$1"
129     local opt="$2"
130     # echo "Grid: Processing '$arg' ('$opt')"
131     case $arg in 
132         -r|--runs)         runs=$opt     ;; 
133         -R|--mc-runs)      mcruns=$opt   ;;
134         -d|--real-dir)     real_dir=$opt ;;
135         -p|--real-pattern) real_pat=$opt ;; 
136         -D|--mc-dir)       mc_dir=$opt   ;; 
137         -P|--mc-pattern)   mc_pat=$opt   ;; 
138         -W|--watch)        let watch=\!$watch ;;
139         -a|--par)          par=1         ;;
140         *) echo "$0: [SETUP] Unknown option $arg"  ; exit 1 ;; 
141     esac
142 }    
143 # --- Extract corrections --------------------------------------------
144 terminate()
145 {
146     script Terminate.C 
147 }
148
149 # --- Extract and upload ---------------------------------------------
150 extract_upload()
151 {
152     echo "=== Download, extract, and uploade in `basename $PWD` ==="
153     download
154     for i in *.zip ; do 
155         if test ! -f $i ; then continue ; fi 
156         if test $noact -gt 0 ; then continue ; fi
157         local d=`basename $i .zip` 
158         if test ! -d $d ; then 
159             mkdir $d 
160         fi
161         cd $d 
162         if test ! -f .zip ; then 
163             echo "= Unpacking ../$i"
164             unzip ../$i > /dev/null 2>&1
165             touch .zip 
166         fi
167         _extract ../Extract.C 
168         upload
169         cd ..
170     done
171 }
172
173 # --- Draw -----------------------------------------------------------
174 draw()
175 {
176     local dd=`pwd` 
177     dd=`basename $dd` 
178     echo "=== Drawing in $dd using $1"
179     local scr=$1  ; shift    
180     case x$scr in 
181         x/*) ;; 
182         x*)  scr=../$scr ;; 
183     esac
184     # local args=$1 ; shift
185     download 
186     for i in *.zip ; do 
187         if test "X$i" = "X*.zip" ; then continue ; fi
188         echo "--- Will extract $i in $dd"
189         d=`basename $i .zip` 
190         if test ! -d $d ; then 
191             mkdir -p $d 
192             unzip $i -d $d
193         fi
194         (cd $d && _draw $scr $@)
195     done
196 }
197 dndeta_draw()
198 {
199     echo "=== Drawing dN/deta in $1"
200     local top=$1 ; shift 
201     cd $top
202     download 
203     for i in *.zip ; do 
204         if test "X$i" = "X*.zip" ; then continue ; fi
205         echo "--- Will extract $i"
206         d=`basename $i .zip` 
207         if test ! -d $d ; then 
208             mkdir -p $d 
209             unzip $i -d $d
210         fi
211         (cd $d && \
212             script ${fwd_dir}/DrawdNdetaSummary.C && \
213             script ../Draw.C)
214     done
215     cd ..
216 }
217
218 # === Script specific functions ======================================
219 # --- Extract corrections --------------------------------------------
220 download()
221 {
222     echo "=== Executing download in `pwd`"
223     if test -f .download ; then 
224         echo "--- Already downloaded in `basename $PWD`"
225         return 0 
226     fi
227     script Download.C 
228     touch .download
229 }
230     
231 # --- Get the grid home dir ------------------------------------------
232 outputs()
233 {
234     l=`aliroot -l -b <<EOF
235 gSystem->RedirectOutput("/dev/null");
236 TGrid::Connect("alien://");
237 gSystem->RedirectOutput(0);
238 std::cout << gGrid->GetHomeDirectory() << std::endl;
239 EOF`
240     my_real_dir="$l/${name}_aod_${now}/output"
241     my_mc_dir="$l/${name}_mcaod_${now}/output"
242 }
243
244
245 run_for_acc()
246 {
247     local r=`grep -v ^# ../$runs | awk '{FS=" \n\t"}{printf "%d\n", $1}' | head -n 1` 
248     if test x$r = "x" || test $r -lt 1; then 
249         echo "No run for acceptance correction specified" > /dev/stderr 
250         exit 1
251     fi
252     echo $r 
253 }
254
255 # --- Dump the setup -------------------------------------------------
256 dump_setup()
257 {
258     local out=$1 
259     cat >> ${out} <<-EOF 
260         # Real data 
261         runs=${runs}
262         real_dir=${real_dir}
263         real_pat=${real_pat}
264         # Simulated data
265         mcruns=${mcruns}
266         mc_dir=${mc_dir}
267         mc_pat=${mc_pat}
268         # Output directories 
269         my_real_dir=${my_real_dir}
270         my_mc_dir=${my_mc_dir}
271         # Other options 
272         par=${par}
273         watch=${watch}
274         EOF
275 }
276
277 # --- Run set-ups ----------------------------------------------------
278 setup()
279 {
280     _setup $@
281 }    
282
283
284 # --- Check settings -------------------------------------------------
285 check_setup()
286 {
287     check_token
288
289     if test "x$runs" = "x" || test ! -f $runs ; then 
290         echo "List of run file $runs not found" > /dev/stderr 
291         exit 1
292     fi
293     if test "x$mcruns" = "x" ; then mcruns=$runs ; fi 
294     if test ! -f $mcruns ; then 
295         echo "List of MC runs file $mcruns not found" > /dev/stderr 
296         exit 1
297     fi
298     if test "x$real_dir" = "x" ; then 
299         echo "No real data directory specified" > /dev/stderr 
300         exit 1
301     fi
302     if test "x$mc_dir" = "x" ; then 
303         echo "No MC data directory specified" > /dev/stderr 
304         exit 1
305     fi
306     if test "x$real_pat" = "x" ; then 
307         echo "No real data pattern specified" > /dev/stderr 
308         exit 1
309     fi
310     if test "x$mc_pat" = "x" ; then 
311         echo "No MC data pattern specified" > /dev/stderr 
312         exit 1
313     fi
314
315 }
316
317 # --- Show the setup -------------------------------------------------
318 print_setup()
319 {
320     cat <<-EOF
321         Real data:
322           Run file:             ${runs}
323           Directory:            ${real_dir}
324           Pattern:              ${real_pat}
325           Output:               ${my_real_dir}
326         MC data:
327           Run file:             ${mcruns}
328           Directory:            ${mc_dir}
329           Pattern:              ${mc_pat}
330           Output:               ${my_mc_dir}
331         Use PAR files:          ${par}
332         EOF
333 }
334
335
336
337 # --- Make URI -------------------------------------------------------
338 # Must modify URL 
339 url_opts()
340 {
341     local mc=$1         ; shift
342     local type=$1       ; shift 
343     local trig=$1       ; shift
344
345     local uopt="&merge=50&split=50&aliroot=last,regular"
346
347     local dir=$real_dir
348     local pat=$real_pat
349     local rl=$runs
350     local tree=esdTree
351
352     if test $mc -gt 0 ; then 
353         dir=$mc_dir
354         pat=$mc_pat
355         rl=$mcruns
356     fi
357     case $type in 
358         *dndeta|*multdists) 
359             uopt="${uopt}&concat"
360             tree=aodTree 
361             # Modify for input dir for our files
362             dir=$my_real_dir
363             pat="*/AliAOD.root"
364             if test $mc -gt 0 ; then 
365                 dir=$my_mc_dir
366             fi
367             ;;
368     esac
369     if test $mc -gt 0; then 
370         uopt="${uopt}&mc"
371     fi
372     if test $par -gt 0 ; then 
373         uopt="${uopt}&par"
374     fi
375     if test x$uuopts != x ; then 
376         uopt="${uopt}&${uuopts}"
377     fi
378     url="alien://${dir}?run=${rl}&pattern=${pat}${uopt}#${tree}"    
379 }
380
381     
382 # --- Run the train --------------------------------------------------
383 # Usage:
384
385 allAboard()
386 {
387     local type=$1 ; shift
388     local trig=$1 ; shift
389     _allAboard "$type" "$trig" --batch $@ 
390
391     if test $watch -lt 1 ; then 
392         cat <<-EOF
393         Check https://alimonitor.cern.ch/users/jobs.jsp for progress 
394         
395         Remember to do 
396         
397           $0 --what=... --step=terminate
398         
399         until the final merge stage to get the results. 
400         EOF
401         
402         case $type in 
403             *corr|*esd) 
404                 cat <<-EOF
405         Then, do 
406         
407           $0 --what=... --step=upload 
408         
409         to upload the results to our local corrections store. 
410         EOF
411                 ;; 
412             *aod|*dndeta)
413                 cat <<-EOF
414         Then, do 
415          
416           $0 --what=... --step=draw
417         
418         to get a PDF of the diagnostics histograms and the final plots. 
419         EOF
420                 ;;
421         esac
422     else 
423         echo "Now waiting for jobs to finish"
424         (cd ${nme}_${now} && \
425             nice aliroot -l -b -x -q Watch.C\(1\) 2>&1 | \
426             tee watch.log > /dev/null &)
427     fi
428 }
429
430 # --- Collect a directory --------------------------------------------
431 collect_files()
432 {
433     local dir=$1 ; shift
434     local d=$1 ; shift 
435     local M=$1 ; shift 
436     local out=$1 ; shift
437     local r=$1 ; shift
438     local files="$1"
439
440     for ad in $dir/root_archive_* ; do 
441         if test ! -d $ad ; then continue ; fi 
442         local r=`basename $ad | sed 's/root_archive_0*//'` 
443         _collect_files "$ad" "$d" "$M" "$out" "$r" "$files"
444     done # for ad in ...
445 }
446
447     
448 # === Procedual code =================================================
449 runIt $@
450
451 #
452 # EOF
453 #
454