bug fixed
[u/mrichter/AliRoot.git] / MUON / AlirootRun_MUONtest.sh
CommitLineData
fa701981 1#!/bin/sh
2# $Id$
3
aefc4e02 4# first declare default values
5
6SIMULATION=1 # will perform simulation
7RECONSTRUCTION=1 # will perform reconstruction
388c6fb1 8RAW=1 # will reconstruct from raw data
aefc4e02 9CHECKS=1 # will perform checks
0be3d079 10SLASHTMP=1 #will use /tmp to put the temporary raw data
aefc4e02 11NEVENTS=100 # will simulate 100 events
32bf5f82 12
5f3519d9 13#RECOPTIONS="SAVEDIGITS NOFASTDECODERS" # reconstruction options with non-high performance decoders
aefc4e02 14RECOPTIONS="SAVEDIGITS" # default reconstruction options
6ef73001 15MC="" # G3 Simulation with old Config.C
16#MC="g3" # G3 Simulation (with new config macros)
17#MC="g4" # G4 Simulation (with new config macros)
18SIMCONFIG="$ALICE_ROOT/MUON/"$MC"Config.C" # default simulation configuration file
aefc4e02 19OUTDIR=""
fa701981 20CURDIR=`pwd`
fa701981 21
745f6baf 22#RUN=0 # run number for OCDB access
aefc4e02 23SEED=1234567 # random number generator seed
24SIMDIR="generated" # sub-directory where to move simulated files prior to reco
25DUMPEVENT=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
30EXIT=0
31
388c6fb1 32while getopts "SRZX:srxzn:tg:p:d:c:" option
aefc4e02 33do
34 case $option in
35 R ) RECONSTRUCTION=1;;
36 S ) SIMULATION=1;;
37 X )
38 CHECKS=1
39 DUMPEVENT=$OPTARG
40 ;;
388c6fb1 41 Z ) RAW=1;;
aefc4e02 42 r ) RECONSTRUCTION=0;;
43 s ) SIMULATION=0;;
44 x ) CHECKS=0;;
0be3d079 45 t ) SLASHTMP=0;;
388c6fb1 46 z ) RAW=0;;
aefc4e02 47 c ) SIMCONFIG=$OPTARG;;
48 d ) OUTDIR=$OPTARG;;
49 n ) NEVENTS=$OPTARG;;
0be3d079 50 g ) SEED=$OPTARG;;
aefc4e02 51 p ) RECOPTIONS=$OPTARG;;
52 * ) echo "Unimplemented option chosen."
53 EXIT=1
54 ;;
55 esac
56done
57
58if [ ! -n "$OUTDIR" ]; then
6ef73001 59 if [ "$MC" = "" ]; then
60 OUTDIR=$CURDIR"/test_out."$NEVENTS
61 else
62 OUTDIR=$CURDIR"/"$MC"_test_out."$NEVENTS
63 fi
aefc4e02 64fi
65
66# look if there are some leftover options
67shift $(($OPTIND - 1))
68
69if [ $# -gt 0 ] || [ "$EXIT" -eq 1 ]; then
70 echo "ERROR : extra option not recognized"
0be3d079 71 echo "Usage: `basename $0` options (-SRXsrxn:tg:p:d:c:)"
aefc4e02 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)"
388c6fb1 75 echo " -Z (-z) perform reconstruction from raw data (from digits) (default is from raw data, i.e. -Z)"
aefc4e02 76 echo " -n nevents (int) number of events to simulate (default $NEVENTS)"
0be3d079 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)"
aefc4e02 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;
83fi
84
85# printout the options
86echo "sim $SIMULATION rec $RECONSTRUCTION check $CHECKS"
87if [ "$SIMULATION" -eq 1 ]; then
88 echo "$NEVENTS events will be simulated, using the config found at $SIMCONFIG"
89fi
90if [ "$RECONSTRUCTION" -eq 1 ]; then
91echo "Reconstruction options to be used : $RECOPTIONS"
388c6fb1 92if [ "$RAW" -eq 0 ]; then
93echo "Will reconstruct from digits only (not from raw data)"
94fi
aefc4e02 95fi
96echo "Output directory will be : $OUTDIR"
97
98if [ "$SIMULATION" -eq 1 ]; then
99
100 rm -fr $OUTDIR
101 mkdir $OUTDIR
102
103fi
104
8601c864 105# Copy *ALL* the macros we need in the output directory, not to mess
106# with our source dir in any way.
107cp $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
aefc4e02 115
fa701981 116cd $OUTDIR
117
0be3d079 118if [ "$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
132fi
133
aefc4e02 134###############################################################################
135#
cbb5526b 136# Update CTP in OCDB for MUON Trigger
137#
138###############################################################################
139
6468ad42 140if [ ! -f $ALICE_ROOT/OCDB/GRP/CTP/Config/Run0_999999999_v0_s1.root ]; then
cbb5526b 141
142 echo "Updating GRP CTP config ..."
143
81b089d7 144 aliroot -b > $OUTDIR/updateCDBCTPConfig.out 2>&1 << EOF
8601c864 145 .L UpdateCDBCTPConfig.C+
cbb5526b 146 UpdateCDBCTPConfig();
147 .q
148EOF
149
150fi
151
152
153###############################################################################
154#
aefc4e02 155# Performing SIMULATION
156#
157###############################################################################
fa701981 158
aefc4e02 159if [ "$SIMULATION" -eq 1 ]; then
fa701981 160
aefc4e02 161 echo "Running simulation ..."
858e5b75 162
81b089d7 163 aliroot -l -b -q runSimulation.C\($SEED,$NEVENTS,\""$SIMCONFIG"\"\) > $OUTDIR/testSim.out 2>&1
388c6fb1 164
aefc4e02 165 mkdir $OUTDIR/$SIMDIR
fa701981 166
388c6fb1 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
6ef73001 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
aefc4e02 188fi
fa701981 189
aefc4e02 190###############################################################################
191#
192# Performing RECONSTRUCTION
193#
194###############################################################################
195
196if [ "$RECONSTRUCTION" -eq 1 ]; then
197
388c6fb1 198 if [ "$RAW" -eq 1 ]; then
199 rm -f galice.root
200 fi
201
202 rm -f AliESD*.root *QA*.root
203
aefc4e02 204 echo "Running reconstruction ..."
205
206 cd $OUTDIR
207
388c6fb1 208 if [ "$RAW" -eq 1 ]; then
209
81b089d7 210 aliroot -l -b -q runReconstruction\.C\($SEED,\""$OUTDIR/raw.root"\",\""$RECOPTIONS"\"\) > $OUTDIR/testReco.out 2>&1
388c6fb1 211
212 else
aefc4e02 213
81b089d7 214 aliroot -l -b -q runReconstruction\.C\($SEED,\"""\",\""$RECOPTIONS"\"\) > $OUTDIR/testReco.out 2>&1
388c6fb1 215
216 fi
217
aefc4e02 218fi
858e5b75 219
aefc4e02 220###############################################################################
221#
222# Performing CHECKS (and dumps)
223#
224###############################################################################
32bf5f82 225
aefc4e02 226if [ "$CHECKS" -eq 1 ]; then
8dc57946 227
029d450d 228 if [ -f "$OUTDIR/$SIMDIR/galice.root" ]; then
32bf5f82 229
aefc4e02 230 echo "Running efficiency ..."
231
81b089d7 232 aliroot -b > $OUTDIR/testResults.out 2>&1 << EOF
8601c864 233 .L MUONefficiency.C+
aefc4e02 234 // no argument assumes Upsilon but MUONefficiency(443) works on Jpsi
235 MUONefficiency("$OUTDIR/$SIMDIR/galice.root");
236 .q
237EOF
238
029d450d 239 if [ -f "$OUTDIR/galice.root" ]; then
aefc4e02 240
241 echo "Running Trigger efficiency ..."
81b089d7 242 aliroot -b > $OUTDIR/testTriggerResults.out 2>&1 << EOF
8601c864 243 .L MUONTriggerEfficiency.C+
aefc4e02 244 MUONTriggerEfficiency("$OUTDIR/$SIMDIR/galice.root", "$OUTDIR/galice.root", 1);
245 .q
8dc57946 246EOF
858e5b75 247
029d450d 248 if [ -f "$OUTDIR/AliESDs.root" ]; then
249
250 echo "Running check ..."
81b089d7 251 aliroot -b > $OUTDIR/testCheck.out 2>&1 << EOF
029d450d 252 gSystem->Load("libMUONevaluation");
8601c864 253 .L MUONCheck.C+
029d450d 254 MUONCheck(0, $NEVENTS-1, "$OUTDIR/$SIMDIR/galice.root", "$OUTDIR/galice.root", "$OUTDIR/AliESDs.root");
255 .q
aefc4e02 256EOF
029d450d 257 fi
aefc4e02 258 fi
259 fi
260
261 echo "Running dumps for selected event ($DUMPEVENT) ..."
262
263 if [ -f "$OUTDIR/$SIMDIR/galice.root" ]; then
0d2fa09b 264 aliroot -l -b << EOF
07be5a4f 265 AliCDBManager* man = AliCDBManager::Instance();
162637e4 266 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
aefc4e02 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
274EOF
275 else
276 echo "$OUTDIR/$SIMDIR/galice.root is not there. Skipping sim dumps"
277 fi
278
279 if [ -f "$OUTDIR/galice.root" ]; then
0d2fa09b 280 aliroot -l -b << EOF
07be5a4f 281 AliCDBManager* man = AliCDBManager::Instance();
162637e4 282 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
aefc4e02 283 AliMUONDataInterface dRec("$OUTDIR/galice.root");
284 dRec.DumpDigits($DUMPEVENT,true); > $OUTDIR/dump.$DUMPEVENT.recdigits
285 dRec.DumpRecPoints($DUMPEVENT); > $OUTDIR/dump.$DUMPEVENT.recpoints
aefc4e02 286 dRec.DumpTrigger($DUMPEVENT); > $OUTDIR/dump.$DUMPEVENT.trigger
287 .q
288EOF
289 else
290 echo "$OUTDIR/galice.root is not there. Skipping rec dumps"
291 fi
292fi
32bf5f82 293
fa701981 294echo "Finished"
aefc4e02 295echo "... see results in $OUTDIR"
fa701981 296
297cd $CURDIR