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