]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AlirootRun_MUONtest.sh
Improved documentation: adding all subpages via \subpage instead of \ref
[u/mrichter/AliRoot.git] / MUON / AlirootRun_MUONtest.sh
1 #!/bin/sh
2 # $Id$
3
4 # first declare default values
5
6 # path to macros
7 MACROPATH=$ALICE_ROOT/MUON/macros
8
9 SIMULATION=1 # will perform simulation
10 RECONSTRUCTION=1 # will perform reconstruction
11 RAW=1 # will reconstruct from raw data
12 CHECKS=1 # will perform checks
13 SLASHTMP=1 #will use /tmp to put the temporary raw data 
14 NEVENTS=50 # will simulate 100 events
15
16 #RECOPTIONS="SAVEDIGITS NOFASTDECODERS" # reconstruction options with non-high performance decoders
17 RECOPTIONS="SAVEDIGITS" # default reconstruction options
18 MC=""    # G3 Simulation with old Config.C 
19 #MC="g3"  # G3 Simulation (with new config macros)
20 #MC="g4"  # G4 Simulation (with new config macros)
21
22 OUTDIR=""
23 CURDIR=`pwd`
24
25 #RUN=0 # run number for OCDB access
26 SEED=1234567 # random number generator seed
27 SIMDIR="generated" # sub-directory where to move simulated files prior to reco
28 DUMPEVENT=5 # event to be dump on files (set to negative to skip dumps)
29
30 SIMCONFIG="$MACROPATH/"$MC"Config.C"
31 EMBEDWITH="" # no embedding by default
32 REALISTIC=0 # ideal simulation by default
33
34 # next try to see if there are options of this script that want to change the
35 # defaults
36  
37 EXIT=0
38
39 while getopts "SRZX:srxzn:tg:p:d:c:e:b:" option
40 do
41   case $option in
42     R ) RECONSTRUCTION=1;;
43     S ) SIMULATION=1;;
44     X ) 
45     CHECKS=1
46     DUMPEVENT=$OPTARG
47     ;;
48     Z ) RAW=1;;
49     r ) RECONSTRUCTION=0;;
50     s ) SIMULATION=0;;
51     x ) CHECKS=0;;
52     t ) SLASHTMP=0;;
53     z ) RAW=0;;
54     c ) SIMCONFIG=$OPTARG;;
55     d ) OUTDIR=$OPTARG;;
56     n ) NEVENTS=$OPTARG;;
57     g ) SEED=$OPTARG;;
58     p ) RECOPTIONS=$OPTARG;; 
59     e ) EMBEDWITH=$OPTARG;;
60     b ) 
61     REALISTIC=$OPTARG
62     RAW=0
63     ;;
64     *     ) echo "Unimplemented option chosen."
65     EXIT=1
66     ;;
67   esac
68 done
69
70 if [ ! -n "$OUTDIR" ]; then
71   if [ "$MC" = "" ]; then
72     OUTDIR=$CURDIR"/test_out."$NEVENTS
73   else  
74     OUTDIR=$CURDIR"/"$MC"_test_out."$NEVENTS
75   fi  
76 fi
77
78 # look if there are some leftover options
79 shift $(($OPTIND - 1))
80
81 if [ $# -gt 0 ] || [ "$EXIT" -eq 1 ]; then
82   echo "ERROR : extra option not recognized"
83   echo "Usage: `basename $0` options (-SRXsrxn:tg:p:d:c:)"
84   echo "       -S (-s) perform (or not) simulation (default is do it, i.e -S)"
85   echo "       -R (-r) perform (or not) reconstruction (default is do it, i.e. -R)"
86   echo "       -X event (-x) perform (or not) checks and dumps (default is do it for event $DUMPEVENT, i.e. -X $DUMPEVENT)"
87   echo "       -Z (-z) perform reconstruction from raw data (from digits) (default is from raw data, i.e. -Z)"
88   echo "       -n nevents (int) number of events to simulate (default $NEVENTS)"
89   echo "       -t will use OUTDIR as a tmp directory to generate raw data  "
90   echo "       -g seed (uint) seed to be used in simulation (default $SEED)"
91   echo "       -p recoptions (quotified string) reconstruction options to use (default \"$RECOPTIONS\")"
92   echo "       -d full path to output directory (default $OUTDIR)"
93   echo "       -c full path to configuration file for simulation (default $SIMCONFIG)"
94   echo "       -e full path to a galice.root file relating to SDigits to be merged (embedding)"
95   echo "       -b runnumber (int) make a realistic simulation using runnumber as anchor (default 0=ideal simulation)"
96   exit 4;
97 fi
98
99
100 # printout the options
101 echo "sim $SIMULATION rec $RECONSTRUCTION check $CHECKS"
102 if [ "$SIMULATION" -eq 1 ]; then
103   echo "$NEVENTS events will be simulated, using the config found at $SIMCONFIG"
104 fi
105 if [ -n "$EMBEDWITH" ]; then
106   echo "Will embed simulation with $EMBEDWITH"
107 fi
108 if [ "$REALISTIC" -gt 0 ]; then
109   echo "Will use anchor run $REALISTIC"
110 fi
111 if [ "$RECONSTRUCTION" -eq 1 ]; then
112 echo "Reconstruction options to be used : $RECOPTIONS"
113 if [ "$RAW" -eq 0 ]; then
114 echo "Will reconstruct from digits only (not from raw data)"
115 fi
116 fi
117 echo "Output directory will be : $OUTDIR"
118
119 if [ "$SIMULATION" -eq 1 ]; then
120
121   rm -fr $OUTDIR
122   mkdir $OUTDIR
123
124 fi
125
126 # Copy *ALL* the macros we need in the output directory, not to mess
127 # with our source dir in any way.
128 cp $MACROPATH/.rootrc \
129   $MACROPATH/rootlogon.C \
130   $MACROPATH/runReconstruction.C \
131   $MACROPATH/runSimulation.C \
132   $MACROPATH/UpdateCDBCTPConfig.C \
133   $MACROPATH/MUONefficiency.C \
134   $MACROPATH/MUONTriggerEfficiency.C \
135   $MACROPATH/MUONCheck.C \
136   $OUTDIR
137
138 cd $OUTDIR
139
140 if [ "$SLASHTMP" -eq 0 ]; then
141   mkdir ./tmp
142   mkdir ./tmp/mdc1
143   mkdir ./tmp/mdc2
144   mkdir ./tmp/mdc1/tags
145
146   chmod 777 ./tmp
147   chmod 777 ./tmp/mdc1
148   chmod 777 ./tmp/mdc2
149   chmod 777 ./tmp/mdc1/tags
150
151   export ALIMDC_RAWDB1=./tmp/mdc1
152   export ALIMDC_RAWDB2=./tmp/mdc2
153   export ALIMDC_TAGDB=./tmp/mdc1/tags
154 fi
155
156 ###############################################################################
157
158 # Update CTP in OCDB for MUON Trigger
159 #
160 ###############################################################################
161
162 if [ ! -f $ALICE_ROOT/OCDB/GRP/CTP/Config/Run0_999999999_v0_s1.root ]; then
163
164   echo "Updating GRP CTP config  ..."
165
166   aliroot -b > $OUTDIR/updateCDBCTPConfig.out 2>&1 << EOF
167   .L UpdateCDBCTPConfig.C++g
168   UpdateCDBCTPConfig();
169   .q
170 EOF
171   
172 fi
173
174
175 ###############################################################################
176
177 # Performing SIMULATION
178 #
179 ###############################################################################
180
181 if [ "$SIMULATION" -eq 1 ]; then
182
183   echo "Running simulation  ..."
184
185   aliroot -l -b -q runSimulation.C\($SEED,$NEVENTS,\""$SIMCONFIG"\"\,\""$EMBEDWITH"\"\,$REALISTIC\) > $OUTDIR/testSim.out 2>&1
186
187   mkdir $OUTDIR/$SIMDIR
188
189   if [ "$RAW" -eq 1 ]; then
190     if [ "$REALISTIC" -eq 0 ]; then # we can not move for realistic simulations as we need e.g. kinematics to propagate the simulated vertex to the reco.
191       echo "Moving generated files to $SIMDIR"
192       mv $OUTDIR/*QA*.root $OUTDIR/*.log $OUTDIR/$SIMDIR
193       mv $OUTDIR/MUON*.root $OUTDIR/TrackRefs*.root $OUTDIR/$SIMDIR
194       mv $OUTDIR/Kinematics*.root $OUTDIR/galice.root $OUTDIR/$SIMDIR
195     fi
196   else  
197     echo "Copying generated files to $SIMDIR"
198     cp $OUTDIR/*QA*.root $OUTDIR/*.log $OUTDIR/$SIMDIR
199     cp $OUTDIR/MUON*.root $OUTDIR/Kinematics*.root $OUTDIR/galice.root $OUTDIR/TrackRefs*.root $OUTDIR/$SIMDIR
200   fi
201
202   # save geometry file in a separate directory
203   if [ "$MC" = "g3" ]; then
204     rm -fr $OUTDIR/geometry
205     mkdir $OUTDIR/geometry
206     cp $OUTDIR/geometry.root $OUTDIR/geometry
207   fi 
208
209   # copy input geometry file in a current directory
210   if [ "$MC" = "g4" ]; then
211     cp $OUTDIR/geometry/geometry.root $OUTDIR
212   fi 
213   
214   cp $OUTDIR/geometry.root $OUTDIR/$SIMDIR/geometry.root
215   
216 fi
217
218 ###############################################################################
219
220 # Performing RECONSTRUCTION
221 #
222 ###############################################################################
223
224 if [ "$RECONSTRUCTION" -eq 1 ]; then
225
226   if [ "$RAW" -eq 1 ]; then
227     if [ "$REALISTIC" -eq 0 ]; then
228       rm -f galice.root
229     fi
230   fi  
231
232   if [ "$REALISTIC" -ne 0 ]; then
233     rm -f geometry.root
234   fi
235   
236   rm -f AliESD*.root *QA*.root
237   
238   echo "Running reconstruction  ..."
239
240   cd $OUTDIR
241   
242   RAWOCDB=kFALSE
243   
244   if [ -n "$EMBEDWITH" ]; then
245     RAWOCDB=kTRUE
246   fi
247   
248   if [ "$REALISTIC" -gt 0 ]; then
249     RAWOCDB=kTRUE
250   fi
251   
252   if [ "$RAW" -eq 1 ]; then
253   
254     aliroot -l -b -q runReconstruction\.C\($SEED,\""$OUTDIR/raw.root"\",\""$RECOPTIONS"\",$RAWOCDB\) > $OUTDIR/testReco.out 2>&1
255
256   else
257
258     aliroot -l -b -q runReconstruction\.C\($SEED,\"""\",\""$RECOPTIONS"\",$RAWOCDB\) > $OUTDIR/testReco.out  2>&1
259   
260   fi
261   
262 fi
263
264 ###############################################################################
265
266 # Performing CHECKS (and dumps)
267 #
268 ###############################################################################
269
270 if [ "$CHECKS" -eq 1 ]; then
271
272   if [ -f "$OUTDIR/$SIMDIR/galice.root" ]; then
273
274     echo "Running efficiency  ..."
275
276     aliroot -b > $OUTDIR/testResults.out 2>&1 << EOF
277     .L MUONefficiency.C++g
278     // no argument assumes Upsilon but MUONefficiency(443) works on Jpsi
279     MUONefficiency("$OUTDIR/$SIMDIR/galice.root");
280     .q
281 EOF
282
283   if [ -f "$OUTDIR/galice.root" ]; then
284
285       echo "Running Trigger efficiency  ..."
286       aliroot -b > $OUTDIR/testTriggerResults.out 2>&1 << EOF
287       .L MUONTriggerEfficiency.C++g
288       MUONTriggerEfficiency("$OUTDIR/$SIMDIR/galice.root", "$OUTDIR/galice.root", 1);
289       .q
290 EOF
291
292       if [ -f "$OUTDIR/AliESDs.root" ]; then
293
294         echo "Running check ..."
295         aliroot -b > $OUTDIR/testCheck.out 2>&1 << EOF
296         gSystem->Load("libMUONevaluation");
297         .L MUONCheck.C++g
298         MUONCheck(0, $NEVENTS-1, "$OUTDIR/$SIMDIR/galice.root", "$OUTDIR/galice.root", "$OUTDIR/AliESDs.root"); 
299         .q
300 EOF
301       fi
302     fi
303   fi
304   
305 if [ "$DUMPEVENT" -ge 0 ]; then
306
307   echo "Running dumps for selected event ($DUMPEVENT) ..."
308
309   if [ -f "$OUTDIR/$SIMDIR/galice.root" ]; then
310     aliroot -l -b  << EOF
311     AliCDBManager* man = AliCDBManager::Instance();    
312     man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
313     AliMUONMCDataInterface mcdSim("$OUTDIR/$SIMDIR/galice.root");
314     mcdSim.DumpKine($DUMPEVENT);       > $OUTDIR/dump.$DUMPEVENT.kine
315     mcdSim.DumpHits($DUMPEVENT);       > $OUTDIR/dump.$DUMPEVENT.hits
316     mcdSim.DumpTrackRefs($DUMPEVENT);  > $OUTDIR/dump.$DUMPEVENT.trackrefs
317     mcdSim.DumpDigits($DUMPEVENT,true);     > $OUTDIR/dump.$DUMPEVENT.simdigits
318     mcdSim.DumpSDigits($DUMPEVENT,true);    > $OUTDIR/dump.$DUMPEVENT.sdigits
319     .q
320 EOF
321   else
322     echo "$OUTDIR/$SIMDIR/galice.root is not there. Skipping sim dumps"
323   fi
324
325   if [ -f "$OUTDIR/galice.root" ]; then
326     aliroot -l -b << EOF
327     AliCDBManager* man = AliCDBManager::Instance();
328     man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
329     AliMUONDataInterface dRec("$OUTDIR/galice.root");
330     dRec.DumpDigits($DUMPEVENT,true); > $OUTDIR/dump.$DUMPEVENT.recdigits
331     dRec.DumpRecPoints($DUMPEVENT);  > $OUTDIR/dump.$DUMPEVENT.recpoints
332     dRec.DumpTrigger($DUMPEVENT); > $OUTDIR/dump.$DUMPEVENT.trigger
333     .q
334 EOF
335   else
336     echo "$OUTDIR/galice.root is not there. Skipping rec dumps"
337   fi
338 fi
339
340 fi
341
342 echo "Finished"  
343 echo "... see results in $OUTDIR"
344
345 cd $CURDIR