source: trunk/Mars/datacenter/scripts/mcsequences@ 9898

Last change on this file since 9898 was 9491, checked in by hoehne, 15 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 7.5 KB
Line 
1#!/bin/sh
2#
3# ========================================================================
4#
5# *
6# * This file is part of MARS, the MAGIC Analysis and Reconstruction
7# * Software. It is distributed to you in the hope that it can be a useful
8# * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
9# * It is distributed WITHOUT ANY WARRANTY.
10# *
11# * Permission to use, copy, modify and distribute this software and its
12# * documentation for any purpose is hereby granted without fee,
13# * provided that the above copyright notice appear in all copies and
14# * that both that copyright notice and this permission notice appear
15# * in supporting documentation. It is provided "as is" without express
16# * or implied warranty.
17# *
18#
19#
20# Author(s): Daniela Dorner 12/2005 <mailto:dorner@astro.uni-wuerzburg.de>
21# Author(s): Daniel Hoehne-Moench 08/2009 <mailto:hoehne@astro.uni-wuerzburg.de>
22#
23# Copyright: MAGIC Software Development, 2000-2009
24#
25#
26# ========================================================================
27#
28# The script is building one sequence per mc run. The relevant parameters
29# are taken from the MC database.
30#
31
32source `dirname $0`/sourcefile
33printprocesslog "INFO starting $0"
34program=mcsequences
35
36set -C
37
38# check if script is already running
39lockfile=$lockpath/lock-$program.txt
40checklock
41
42# find montecarlo directories, build one sequence per run
43printprocesslog "INFO building one sequence per run"
44
45getdbsetup
46
47dirs=`find $mcrawpath -type d`
48for dir in ${dirs[@]}
49do
50 cont=`echo $dir | cut -d/ -f7`
51 #cont=`echo $dir | cut -d/ -f10`
52 if [ "$cont" == "" ]
53 then
54 continue
55 fi
56 printprocesslog "INFO dir: "$dir
57
58 epochs=`ls -l $mcpath/camera | cut -d' ' -f8`
59 for epoch in ${epochs[@]}
60 do
61 printprocesslog "INFO epoch: "$epoch
62
63 calfile=`find $dir -lname *${epoch}/*.root | grep "_C_"`
64 pedfile=`find $dir -lname *${epoch}/*.root | grep "_P_"`
65 calrun=`echo $calfile | cut -d_ -f2`
66 pedrun=`echo $pedfile | cut -d_ -f2`
67
68 modes=("Gamma" "GammaW1" "GammaW2" "GammaFW" "GammaDiff" "GammaHE" "GammaHEW1" "GammaHEW2" "GammaHEFW" "GammaHEDiff" "ProtonDiff" "ProtonHEDiff" "MuonDiff" "MuonHEDiff" "GammaSUM" "GammaW1SUM" "GammaW2SUM" "GammaFWSUM" "GammaDiffSUM" "GammaHESUM" "GammaHEW1SUM" "GammaHEW2SUM" "GammaHEFWSUM" "GammaHEDiffSUM" "ProtonDiffSUM" "ProtonHEDiffSUM" "MuonDiffSUM" "MuonHEDiffSUM")
69 for mode in ${modes[@]}
70 do
71 datruns=`find $dir -lname *${epoch}/*.root | grep ${mode}_ | grep "_D_" | cut -d_ -f2 | tr "\n" " "`
72 if [ "$datruns" != "" ]
73 then
74 date=`echo $dir | cut -c 28-37 | sed -e 's/\//-/g'`
75 #date=`echo $dir | cut -c 57-66 | sed -e 's/\//-/g'`
76 zbin=`echo $date | cut -c 3,4`
77
78 for datrun in ${datruns[@]}
79 do
80 query1=" select fSpectrumKEY, fPSFKEY, fAmplFadcKEY, fAtmosphericModelKEY, fObservationModeKEY, fMCParticleKEY, fReflectorVersionKEY, fCorsikaVersionKEY, fCameraVersionKEY, fViewConeAngleOKEY, fAddSpotSizeKEY, fTriggerFlagKEY, fPhiMax, fPhiMin from MCRunData where fRunNumber=\"$datrun\" "
81 query2=" select sum(fNumEvents), sum(fNumTriggers), sum(fNumSumTriggers) from MCRunData where fRunNumber=\"$datrun\" "
82 values=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $query1 "`
83 values2=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $query2 "`
84 spec=`echo $values | cut -d" " -f1`
85 psf=`echo $values | cut -d" " -f2`
86 amplfadc=`echo $values | cut -d" " -f3`
87 atmo=`echo $values | cut -d" " -f4`
88 obs=`echo $values | cut -d" " -f5`
89 part=`echo $values | cut -d" " -f6`
90 refl=`echo $values | cut -d" " -f7`
91 cors=`echo $values | cut -d" " -f8`
92 cam=`echo $values | cut -d" " -f9`
93 view=`echo $values | cut -d" " -f10`
94 ass=`echo $values | cut -d" " -f11`
95 trig=`echo $values | cut -d" " -f12`
96 azmax=`echo $values | cut -d" " -f13`
97 azmin=`echo $values | cut -d" " -f14`
98 events=`echo $values2 | cut -d" " -f1`
99 triggers=`echo $values2 | cut -d" " -f2`
100 sumtriggers=`echo $values2 | cut -d" " -f3`
101 query3=" select fSequenceFirst from MCSequenceProcessStatus where fSequenceFirst=\"$datrun\" "
102 query4=" select fSequenceFirst from MCSequences where fSequenceFirst=\"$datrun\" "
103 insert1=" insert MCSequenceProcessStatus set fSequenceFirst=\"$datrun\", fPriority=\"$datrun\", fSequenceFileWritten=Now() "
104 insert2=" insert MCSequences set fSequenceFirst=\"$datrun\", fRunStart=\"$date\", fNumEvents=\"$trainevents\", fNumTriggers=\"$triggers\", fNumSumTriggers=\"$sumtriggers\", fZBin=\"$zbin\", fSpectrumKEY=\"$spec\", fPSFKEY=\"$psf\", fAddSpotSizeKEY=\"$ass\", fAmplFadcKEY=\"$amplfadc\", fAtmosphericModelKEY=\"$atmo\", fObservationModeKEY=\"$obs\", fMCParticleKEY=\"$part\", fReflectorVersionKEY=\"$refl\", fCorsikaVersionKEY=\"$cors\", fCameraVersionKEY=\"$cam\", fViewConeAngleOKEY=\"$view\", fTriggerFlagKEY=\"$trig\", fPhiMax=\"$azmax\", fPhiMin=\"$azmin\", fTestTrainKEY=2 "
105 update1=" update MCRunData set fSequenceFirst=\"$datrun\" where fRunNumber=\"$datrun\" "
106 update2=" update MCSequences set fRunStart=\"$date\", fNumEvents=\"$events\", fNumTriggers=\"$triggers\", fNumSumTriggers=\"$sumtriggers\", fZBin=\"$zbin\", fSpectrumKEY=\"$spec\", fPSFKEY=\"$psf\", fAddSpotSizeKEY=\"$ass\", fAmplFadcKEY=\"$amplfadc\", fAtmosphericModelKEY=\"$atmo\", fObservationModeKEY=\"$obs\", fMCParticleKEY=\"$part\", fReflectorVersionKEY=\"$refl\", fCorsikaVersionKEY=\"$cors\", fCameraVersionKEY=\"$cam\", fViewConeAngleOKEY=\"$view\", fTriggerFlagKEY=\"$trig\", fPhiMax=\"$azmax\", fPhiMin=\"$azmin\", fTestTrainKEY=2 where fSequenceFirst=\"$datrun\" "
107
108 mysql -ss -u $us --password=$pw --host=$ho $db -e " $update1 "
109 check3=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $query3 "`
110 check4=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $query4 "`
111 if [ "$check3" == "" ]
112 then
113 mysql -ss -u $us --password=$pw --host=$ho $db -e " $insert1 "
114 fi
115 if [ "$check4" == "" ]
116 then
117 mysql -ss -u $us --password=$pw --host=$ho $db -e " $insert2 "
118 else
119 mysql -ss -u $us --password=$pw --host=$ho $db -e " $update2 "
120 fi
121
122 no=`echo $datrun | cut -c 1-4`
123 sequpath=$mcsequpath/$no
124 makedir $sequpath
125 sequfile=$sequpath/sequence$datrun.txt
126 printprocesslog "INFO writing sequencefile $sequfile"
127
128 echo "Sequence: $datrun" >| $sequfile
129 echo "Night: $date" >> $sequfile
130 echo "Epoch: $epoch" >> $sequfile
131 echo "Mode: $mode" >> $sequfile
132 echo "Azimuth: $azmin - $azmax" >> $sequfile
133 echo "" >> $sequfile
134 echo "CalRuns: $calrun" >> $sequfile
135 echo "PedRuns: $pedrun" >> $sequfile
136 echo "DatRuns: $datrun" >> $sequfile
137 echo "" >> $sequfile
138 echo "MonteCarlo: Yes" >> $sequfile
139 echo "" >> $sequfile
140
141 done
142 fi
143 done
144 done
145done
146
147finish
148
Note: See TracBrowser for help on using the repository browser.