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