]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/Run.sh
Fixed references from PWG2 -> PWGLF - very efficiently done using ETags.
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / Run.sh
1 #!/bin/bash 
2
3 # General options 
4 batch=0
5 proof=0
6 cent=0
7 dopass1=0
8 dopass2=0
9 dopass3=0
10 max_rotate=10
11 prog=aliroot
12
13 # Input (data and scripts)
14 ana=$ALICE_ROOT/PWGLF/FORWARD/analysis2
15 esddir="."
16 nev=-1
17
18 # Pass 1 options 
19 mc=0
20 scheme="full"
21
22 # Pass 2 event selection
23 vzmin=-10
24 vzmax=10
25 type=INEL
26 mcfilename="none"
27
28 # Pass 3 visualisation options 
29 rebin=1
30 tit=
31 others=
32 ratios=1
33 asymm=1 
34 rings=0
35 syserr=1
36
37 # Derived variables 
38 pass1=MakeAOD.C
39 pass2=MakedNdeta.C
40 pass3=DrawdNdeta.C++
41 output1=forward.root
42 output2=forward_dndeta.root
43 outputs1="${output1} AliAOD.root event_stat.root EventStat_temp.root"
44 outputs2="${output2}"
45 gdb_script=$ALICE_ROOT/PWGLF/FORWARD/analysis2/gdb_cmds
46 name=`date +analysis%Y%m%d_%H%M`
47 pass2dir=./
48
49 #_____________________________________________________________________
50 # Print usage
51 usage()
52 {
53 cat<<EOF
54 Usage: $0 [OPTIONS]
55
56 Do Pass1 and Pass2 on ESD files in current directory.  
57
58 Options:
59    General options:
60         -h,--help               This help                  
61         -b,--batch              Do batch processing         ($batch)
62         -P,--proof NWORKERS     Run in PROOF(Lite) mode     ($proof)
63         -1,--pass1              Run pass 1 (AOD)            ($dopass1)
64         -2,--pass2              Run pass 2 (Hists)          ($dopass2)
65         -3,--pass3              Run pass 3 (Vizualisation)  ($dopass3)
66         -n,--events N           Number of events            ($nev)
67         -g,--gdb                Run in GDB mode             ($gdb)
68         -N,--name STRING        Name of analysis            ($name)
69         -E,--eloss              Run energy loss script      
70         -A,--script-dir         Script directory            ($ana)
71         -a,--program            Program to use              ($prog)
72    Pass 1 options and event selection
73         -C,--use-centrality     Run centrality task         ($cent)
74         -M,--mc                 Run over MC data            ($mc)
75         -I,--input-dir PATH     Path to input ESD data      ($esddir)
76    Pass 2 options 
77         -v,--vz-min CM          Minimum value of vz         ($vzmin)
78         -V,--vz-max CM          Maximum value of vz         ($vzmax)
79         -t,--trigger TYPE       Select trigger TYPE         ($type)
80         -S,--scheme SCHEME      Normalisation scheme        ($scheme)
81         -q,--mcfilename         Result of MC analysis       ($mcfilename)
82    Pass 3 options 
83         -r,--rebin              Rebin factor                ($rebin)
84         -O,--others WHICH       Show other data             ($others)
85         -J,--show-rings         Show individual rings       ($rings)
86         -R,--show-ratios        Show ratios to other data   ($ratios)
87         -Z,--show-asymmetry     Show asymmetry              ($asymm)
88         -G,--show-syserror      Show systematic errors      ($syserr)
89         -T,--title STRING       Title on plots              ($tit)
90
91 TYPE is a comma or space separated list of 
92  
93   INEL        Inelastic triggers (V0A|V0C|SPD)
94   INEL>0      As above + N_ch > 0 in -0.5<eta<+0.5
95   NSD         Non-single diffractive ((VOA&VOC)|N_ch > 5 -1.9<eta<+1.9)
96
97 SCHEME is a comma or space separated list of 
98
99   NONE          No event-level normalization except trivial one 
100   EVENT         Event-level normalization 
101   BACKGROUND    Not implemented yet 
102   SHAPE         Shape correction 
103   TRIGGER       Trigger efficiency 
104   FULL          Same as EVENTLEVEL,BACKGROUND,SHAPE,TRIGGER
105
106 WHICH is a comma or space separated list of 
107
108   UA5           UA5 data (900GeV, ppbar, INEL, NSD)
109   CMS           CMS data 
110   ALICE         ALICE published data
111   PYTHIA        Event generator data 
112
113 If NWORKERS is 0, then the analysis will be run in local mode. 
114 EOF
115 }
116
117 #_____________________________________________________________________
118 test_ralien()
119 {
120     aliroot -l -b <<EOF > /dev/null 2>&1
121 int ret = gSystem->Load("libRAliEn");
122 gApplication->Terminate(ret);
123 EOF
124     ret=$?
125     return $ret
126 }
127
128 #_____________________________________________________________________
129 # Toggle a value 
130 toggle()
131 {
132     echo $((($1+1)%2))
133 }
134
135 #_____________________________________________________________________
136 # Rotate files 
137 rotate() 
138 {
139     fname=$1 
140     if test -f ${fname}.${max_rotate} ; then 
141         # echo "Removing ${fname}.${max_rotate}"
142         rm -f ${fname}.${max_rotate}
143         # echo "Maximum number of rotations - $max_rotate - for $fname found" \
144         #     > /dev/stderr 
145         # exit 1
146     fi
147     let max=$max_rotate-1
148     for i in `seq $max -1 1` ; do 
149         if test ! -f ${fname}.${i} ; then continue ; fi 
150         let newn=$i+1
151         # echo "Moving ${fname}.$i to ${fname}.$newn"
152         mv ${fname}.$i ${fname}.$newn
153     done
154     if test -f $fname ; then 
155         # echo "Moving ${fname} to ${fname}.1"
156         mv $fname ${fname}.1 
157     fi
158 }
159
160 #_____________________________________________________________________
161 #
162 # Function to run pass 
163 #
164 # Arguments (in order)
165 #    isBatch:     Should we do batch processing 
166 #    output:      Main output file 
167 #    outputs:     All outputs 
168 #    outdir:      Where the output will be put 
169 #    notlast:     Not last pass 
170 #    script:      Script name 
171 #    args:        Arguments for script 
172 #
173 run_pass()
174 {
175     isbatch=$1    ; shift 
176     output=$1     ; shift
177     outputs=$1    ; shift 
178     outdir=$1     ; shift 
179     notLast=$1    ; shift 
180     script=$1     ; shift 
181     args=$1       
182
183     # --- Log file name ----------------------------------------------
184     if test "x$output" = "x" ; then 
185         log=analysis.log
186     else
187         log=`dirname $output`/`basename $output .root`.log
188     fi
189
190     # --- Make options for AliROOT -----------------------------------
191     opts=
192     if test $isbatch -gt 0 || test $notLast -gt 0 ; then 
193         opts="-q"
194     fi
195     if test $isbatch -gt 0 ; then 
196         opts="-b $opts"
197     fi 
198
199     # --- Rotate output file -----------------------------------------
200     for i in ${outputs} ${log} ; do 
201         rotate ${outdir}${i}
202     done
203
204     # --- Some print out ---------------------------------------------
205     cat <<-EOF
206         Pass parameters: 
207          Batch mode:            $isBatch 
208          Main output:           $output
209          All outputs:           $outputs
210          Output directory:      $outdir
211          More to do:            $notLast
212          Script to run:         $script 
213          Script arguments:      $args
214          Log file:              $log
215          AliROOT options:       $opts
216         EOF
217
218     # --- Run AliROOT ------------------------------------------------
219     echo "Running ${prog} $opts ${script}${args}"
220     if test $isbatch -gt 0 || test $notLast -gt 0 ; then 
221         ${prog} ${opts} ${script}"${args}" 2>&1 | tee ${log}
222     else 
223         ${prog} ${opts} ${script}"${args}"
224     fi
225     fail=$?
226
227     # --- Check exit conditions --------------------------------------
228     if  test $fail -gt 0  ; then 
229         echo "Returned $fail" 
230         exit $fail 
231     fi
232     for i in ${outputs} ; do 
233         if test ! -f ${outdir}${i} ; then 
234             echo "File ${i} not generated in ${outdir}"
235             exit 1
236         fi
237     done
238     echo "Success (log in $log)"
239 }
240
241 #_____________________________________________________________________
242 # Loop over arguments 
243 while test $# -gt 0 ; do
244     case $1 in 
245         # General options 
246         -h|--help)            usage  ; exit 0             ;; 
247         -b|--batch)           batch=`toggle $batch`       ;; 
248         -P|--proof)           proof=$2  ; shift           ;; 
249         -1|--pass1|--aod)     dopass1=`toggle $dopass1`   ;; 
250         -2|--pass2|--hist)    dopass2=`toggle $dopass2`   ;; 
251         -3|--pass3|--draw)    dopass3=`toggle $dopass3`   ;; 
252         -n|--events)          nev=$2 ; shift              ;;
253         -g|--gdb)             gdb=`toggle $gdb`           ;;
254         -N|--name)            name=$2 ; shift             ;; 
255         -A|--script-dir)      ana=$2; shift               ;;
256         -a|--program)         prog=$2 ; shift             ;;
257         -E|--eloss)           pass1=MakeELossFits.C 
258                               pass2=scripts/ExtractELoss.C
259                               pass3=scripts/DrawAnaELoss.C 
260                               output1=forward_eloss.root 
261                               outputs1="${output1} event_stat.root EventStat_temp.root"
262                               outputs2=""
263                               dopass2=1 
264                               ;;
265         # Pass 1 options
266         -C|--use-centrality)  cent=`toggle $cent`       ;;
267         -M|--mc)              mc=`toggle $mc`           ;; 
268         -I|--input-dir)       esddir=$2 ; shift         ;;
269         # Pass 2 options 
270         -v|--vz-min)          vzmin=$2 ; shift          ;; 
271         -V|--vz-max)          vzmax=$2 ; shift          ;; 
272         -S|--scheme)          scheme=`echo $2 | tr ' ' ','` ; shift ;;
273         -t|--type)            type=$2  ; shift ;;
274         -q|--mcname)          mcfilename=$2 ; shift ;;
275         # PAss 3 options 
276         -r|--rebin)           rebin=$2  ; shift         ;;
277         -O|--others)          others=`echo $2 | tr ',' ' '` ; shift     ;;
278         -R|--show-ratios)     ratios=`toggle $ratios`   ;;
279         -J|--show-rings)      rings=`toggle $rings`     ;;
280         -Z|--show-asymmetry)  asymm=`toggle $asymm`     ;;
281         -G|--show-syserror)   syserr=`toggle $syserr`   ;;
282         -T|--title)           tit=$2 ; shift ;;
283         *) echo "$0: Unknown option '$1'" >> /dev/stderr ; exit 1 ;;
284     esac
285     shift
286 done 
287
288 #_____________________________________________________________________
289 # Check for RAlien if needed
290 if test "x$name" != "x" && test_ralien ; then 
291     echo "AliEn plug-in available - output will be in $name"
292     pass2dir=${name}/
293 fi
294
295 #_____________________________________________________________________
296 # Pass 1 
297 if test $dopass1 -gt 0 ; then 
298     args="(\"${esddir}\",$nev,$proof,$mc,$cent,\"${name}\")"
299     echo "Args=$args"
300     run_pass ${batch} ${output1} "${outputs1}" "${pass2dir}" ${dopass2} \
301         ${ana}/${pass1} ${args}
302     echo "Pass 1 done"
303 fi
304
305 #_____________________________________________________________________
306 # Pass 2 
307 if test $dopass2 -gt 0 ; then
308     if test -f forward_dndeta_mc.root ; then
309         if test "x$mcfilename" = "xnone"  || 
310             test "x$mcfilename" = "x" ; then 
311             mcfilename=forward_dndeta_mc.root
312         fi
313     fi
314     args="(\"${pass2dir}\",$nev,\"$type\",$cent,\"$scheme\",$vzmin,$vzmax,$proof,\"$name\",\"$mcfilename\")"
315     if test "x$pass1" = "xMakeELossFits.C" ; then 
316         args=(\(\"${pass2dir}${output1}\"\))
317     fi
318     
319     run_pass ${batch} ${output2} "${outputs2}" "${pass2dir}" ${dopass3} \
320         ${ana}/${pass2} ${args}
321     echo "Pass 2 done"
322 fi
323
324 #_____________________________________________________________________
325 # Pass 3 
326 if test $dopass3 -gt 0 ; then
327     tit=`echo $tit | tr ' ' '@'` 
328     flags=0
329     if test $ratios    -gt 0 ; then let flags=$(($flags|0x1)); fi
330     if test $asymm     -gt 0 ; then let flags=$(($flags|0x2)); fi
331     if test $syserr    -gt 0 ; then let flags=$(($flags|0x4)); fi
332     if test $rings     -gt 0 ; then let flags=$(($flags|0x8)); fi
333     which=0
334     others=`echo $others | tr ',' ' ' | tr '[a-z]' '[A-Z]'` 
335     for i in $others ; do 
336         case $i in 
337             UA5)        let which=$(($which|0x1)) ;; 
338             CMS)        let which=$(($which|0x2)) ;; 
339             ALICE)      let which=$(($which|0x4)) ;; 
340             PYTHIA|MC)  let which=$(($which|0x8)) ;; 
341         esac
342     done 
343
344     args="(\"${pass2dir}${output2}\",\"$tit\",$rebin,${which},${flags})"
345     if test "x$pass1" = "xMakeELossFits.C" ; then 
346         args="(\"${pass2dir}${output1}\")"
347     fi
348
349     run_pass ${batch} "" "" "" 0 ${ana}/${pass3} ${args}
350 fi                               
351
352
353 #
354 # EOF
355 #