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