00001
00002
00003 '''
00004
00005 Configure the full chain of simulation from kinematics to readouts and
00006 with multiple kinematics types mixed together.
00007
00008 usage:
00009 nuwa.py -n50 -o fifteen.root -m "FullChain -T Kinematic" > log
00010
00011 -T: Optional stages are: Kinematic, Detector, Electronic, TrigRead or SingleLoader.
00012
00013 More options are available like -w: wall clock starting time
00014 -s: seed for standalone generators
00015 -F: time format
00016
00017 Here is another example:
00018 nuwa.py -n50 -o fifteen.root -m "FullChain -T Detector -w 2008-04-15T15:15:00 -s 1"
00019
00020 '''
00021 import GaudiKernel.SystemOfUnits as units
00022
00023 class ConfigureFullChain:
00024
00025 '''
00026 Configure a Full Chain of pull simulations.
00027 '''
00028
00029 def __init__(self,argv):
00030 self.parse_args(argv)
00031 return
00032
00033 def parse_args(self,argv):
00034 from optparse import OptionParser
00035 import time
00036 parser = OptionParser(usage=self.__doc__)
00037 default_time_format = '%Y-%m-%dT%H:%M:%S'
00038 parser.add_option("-w","--start-time",
00039 help="Date string to set simulation start, assumed UTC",
00040 default=time.strftime(default_time_format,time.gmtime(0)))
00041 parser.add_option("-F","--time-format",
00042 help="Format for parsing time (see man date), " \
00043 + "default is '%s'"%default_time_format \
00044 + " ('[YYYY]-[MM]-[DD]T[HH]:[MM]:[SS]')",
00045 default=default_time_format)
00046 parser.add_option("-T","--top-stage",
00047 help="Kinematic,Detector,Electronic,TrigRead,SingleLoader",
00048 default="SingleLoader")
00049 parser.add_option("-s","--seed",
00050 help="Random seed for standalone generators",
00051 default=1234567)
00052
00053 (options,args) = parser.parse_args(args=argv)
00054 self.opts = options
00055 self.args = args
00056
00057 timeformat = self.opts.time_format
00058 print "Using time format =",timeformat
00059
00060 try:
00061 datestring = self.opts.start_time
00062 except AttributeError:
00063 self.start_time_seconds = 0
00064 else:
00065
00066
00067 t = time.strptime(datestring,timeformat)
00068 self.start_time_seconds = time.mktime(t) - time.timezone
00069 print 'Start time in seconds UTC =',self.start_time_seconds
00070 print 'Top stage =',self.opts.top_stage
00071
00072 return
00073
00074 def configureKinematic(self):
00075
00076
00077
00078
00079
00080
00081 from FastMuon import FastMuon
00082 fastMuon=FastMuon(stage=self.stage_cfg,
00083 start_time=self.start_time_seconds,
00084 seed=self.opts.seed)
00085
00086
00087
00088
00089
00090
00091 return
00092
00093 def configureDetector(self):
00094 '''Configure the Detector stage'''
00095
00096 import DetSim
00097 ds = DetSim.Configure(physlist=DetSim.physics_list_basic+DetSim.physics_list_nuclear,
00098 use_push_algs = False)
00099
00100
00101 from DetSim.DetSimConf import DsPhysConsOptical
00102 optical = DsPhysConsOptical()
00103 optical.UseScintillation = False
00104
00105 optical.UseCerenkov = False
00106
00107
00108
00109
00110 optical.ApplyWaterQe = True
00111 from DetSim.DetSimConf import DsPmtSensDet
00112 pmtsd = DsPmtSensDet("GiGaGeo.DsPmtSensDet")
00113 pmtsd.WaterCerenQeApplied = optical.ApplyWaterQe
00114
00115
00116 from DetSimProc.DetSimProcConf import DetSimProc
00117 dsp = DetSimProc()
00118 dsp.ThisStageName = "Detector"
00119 dsp.LowerStageName = "Kinematic"
00120
00121 self.stage_cfg.DetectorSequence.Members.append(dsp)
00122 return
00123
00124 def configureElectronic(self):
00125 '''Configure the Electronics stage'''
00126
00127 import ElecSim
00128 es = ElecSim.Configure(use_push_algs = False)
00129
00130 from ElecSimProc.ElecSimProcConf import ElecSimProc
00131 esp = ElecSimProc()
00132 esp.ThisStageName = "Electronic"
00133 esp.LowerStageName = "Detector"
00134
00135 self.stage_cfg.ElectronicSequence.Members.append(esp)
00136 return
00137
00138 def configureTrigRead(self):
00139 '''Configure the Trigger and Readout stage'''
00140 from TrigReadProc.TrigReadProcConf import TrigReadProc
00141 tsp = TrigReadProc()
00142 tsp.ThisStageName = "TrigRead"
00143 tsp.LowerStageName = "Electronic"
00144
00145
00146
00147 self.stage_cfg.TrigReadSequence.Members.append(tsp)
00148 return
00149
00150 def configureSingleLoader(self):
00151 '''Configure the SingleLoader stage'''
00152 from SingleLoader.SingleLoaderConf import SingleLoader
00153 sll = SingleLoader()
00154 sll.ThisStageName = "SingleLoader"
00155 sll.LowerStageName = "TrigRead"
00156
00157 self.stage_cfg.SingleLoaderSequence.Members.append(sll)
00158
00159 def configureSim15(self):
00160 from Stage.StageConf import Sim15
00161 sim15=Sim15()
00162 sim15.TopStage=self.opts.top_stage
00163
00164 from Gaudi.Configuration import ApplicationMgr
00165 theApp = ApplicationMgr()
00166 theApp.TopAlg.append(sim15)
00167
00168 def configure(self):
00169
00170 from Stage import Configure as StageConfigure
00171 self.stage_cfg = StageConfigure()
00172
00173 stagedic={'Kinematic':1,'Detector':2,'Electronic':3,'TrigRead':4,'SingleLoader':5}
00174
00175 if not self.opts.top_stage in stagedic:
00176 print 'Error, wrong top stage parameter.', self.opts.top_stage
00177 print 'Valid stage is Kinematic, Detector, Electronic, TrigRead or SingleLoader'
00178
00179 for stg,idx in stagedic.iteritems():
00180 if idx <= stagedic[self.opts.top_stage]:
00181 self.stage_cfg.addStages([stg])
00182
00183 for stg in self.stage_cfg.stages:
00184
00185 pass
00186
00187 if stagedic[self.opts.top_stage]>=1:
00188 self.configureKinematic()
00189 if stagedic[self.opts.top_stage]>=2:
00190 self.configureDetector()
00191 if stagedic[self.opts.top_stage]>=3:
00192 self.configureElectronic()
00193 if stagedic[self.opts.top_stage]>=4:
00194 self.configureTrigRead()
00195 if stagedic[self.opts.top_stage]>=5:
00196 self.configureSingleLoader()
00197
00198 self.configureSim15()
00199
00200 return
00201
00202 def configure(argv=[]):
00203 cfc = ConfigureFullChain(argv)
00204 cfc.configure()
00205 return
00206
00207 if __name__ == "__main__":
00208 configure()
00209 pass