00001
00002
00003 class GenToolsConfig:
00004 def __init__(self,
00005 volume="/dd/Geometry/AD/lvAD",
00006 nevents=10,
00007 seed=1234567,
00008
00009 hepevt_source="Co60.exe -seed %(seed)s -n %(nevents)s|"):
00010 import GaudiPython as gm
00011 self.app = gm.AppMgr()
00012
00013
00014 self.nevents = nevents
00015 self.seed = seed
00016 self.volume = volume
00017 self.hepevt_source=hepevt_source
00018 self.init()
00019 return
00020
00021 def init(self):
00022 self.init_gen_tools()
00023 self.init_generator()
00024 return
00025
00026 def init_gen_tools(self):
00027 from GaudiKernel import SystemOfUnits as units
00028
00029
00030
00031
00032 tim = self.app.property("ToolSvc.GtTimeratorTool")
00033
00034 tim.LifeTime = int(1*units.second)
00035
00036
00037
00038
00039 poser = self.app.property("ToolSvc.GtPositionerTool")
00040 poser.OutputLevel = 2
00041 poser.Volume = self.volume
00042 poser.Strategy = "FullVolume"
00043 poser.Mode = "Uniform"
00044 poser.Spread = 10*units.cm
00045 poser.Position = [0,0,0]
00046
00047
00048 if self.hepevt_source[-1] == "|":
00049 exe = self.hepevt_source.split(' ')[0]
00050 if exe[0] != '/':
00051 import os, os.path
00052 path = os.getenv('PATH')
00053 for p in path:
00054 if (os.path.isfile(path+"/"+exe)):
00055 exe = path+"/"+exe
00056 break
00057 continue
00058 pass
00059 source = exe + ' ' + ' '.join(self.hepevt_source.split(' ')[1:])
00060 if "%" in source:
00061 source = source%{'nevents':str(self.nevents),
00062 'seed':str(self.seed)}
00063 pass
00064 pass
00065
00066
00067
00068
00069
00070
00071
00072
00073 gun = self.app.property("ToolSvc.GtGunGenTool")
00074 gun.OutputLevel = 2
00075 gun.ParticleName = "opticalphoton"
00076 gun.MomentumMode = "Fixed"
00077 gun.Momentum = 2.5*units.eV
00078 gun.DirectionMode = "Fixed"
00079 gun.Direction = [ 0.0,0.0,-1.0 ]
00080
00081
00082 return
00083
00084 def init_generator(self):
00085
00086
00087 self.app.TopAlg += [ "Gnrtr/Generator" ]
00088
00089 gen = self.app.algorithm("Generator")
00090
00091
00092 gen.GenTools = [ "GtGunGenTool/GunGen", "GtPositionerTool/GunPos", "GtTimeratorTool/GunTim" ]
00093 gen.GenName = "Bang Bang"
00094 gen.Location = "/Event/Gen/HepMCEvents"
00095
00096
00097 dump = self.app.algorithm("Dumper")
00098 dump.Location = "/Event/Gen/HepMCEvents"
00099 return
00100
00101 if '__main__' == __name__:
00102 import os
00103 loc = os.getenv('XMLDETDESCROOT')
00104 if not loc:
00105 raise RuntimeError,"Location of DetDesc XML file not specified"
00106 loc += "/DDDB/pmtbox.xml"
00107
00108 import xmldetdesc
00109 xddc = xmldetdesc.XmlDetDescConfig(loc=loc)
00110
00111 tg = GenToolsConfig(volume="/dd/Structure/steel-2/water-2")
00112 from GaudiPython import AppMgr
00113 app = AppMgr()
00114 app.EvtSel = "NONE"
00115 app.run(tg.nevents)
00116
00117 msv = app.service('MessageSvc')
00118 msv.OutputLevel = 2