00001
00002
00003 import os, sys, PyCintex
00004 Gaudi = PyCintex.makeNamespace('Gaudi')
00005
00006 import GaudiKernel.SystemOfUnits as units
00007 from DybPython.Util import irange
00008 from DybPython.DybPythonAlg import DybPythonAlg
00009 from GaudiPython import SUCCESS, FAILURE
00010 from GaudiPython import gbl
00011 from GaudiPython import loaddict
00012 loaddict('libHepMCRflx')
00013
00014
00015 TH1F = gbl.TH1F
00016 TH2F = gbl.TH2F
00017
00018 class GenMuonHists(DybPythonAlg):
00019 def __init__(self,name = "GenMuonHists", volume='/dd/Structure/AD/db-ade1'):
00020 DybPythonAlg.__init__(self,name)
00021 self.lastTime = 0
00022 self.volume = volume
00023 return
00024
00025 def initialize(self):
00026 status = DybPythonAlg.initialize(self)
00027 if status.isFailure(): return status
00028
00029 self.de = self.getDet(self.volume)
00030
00031 self.stats.defaultPath = "/file1/muons"
00032 self.stats["dT"] = self.dT = TH1F("dT","Time between events (microsec)",
00033 10000,0,10);
00034 self.stats["xy"] = self.xy = TH2F("xy","Vertex, Y vs. X (m)",
00035 200,-100,100,200,-100,100)
00036 self.stats["yz"] = self.yz = TH2F("yz","Vertex, Z vs. Y (m)",
00037 200,-100,100,200,-100,100)
00038 self.stats["zx"] = self.zx = TH2F("zx","Vertex, X vs. Z (m)",
00039 200,-100,100,200,-100,100)
00040 return SUCCESS
00041
00042 def execute(self):
00043 evt = self.evtSvc()
00044 genHdr = evt["/Event/Gen/GenHeader"]
00045 genEvt= genHdr.event()
00046
00047 for vertex in irange(genEvt.vertices_begin(), genEvt.vertices_end()):
00048 xGen = vertex.position().x()/units.m
00049 yGen = vertex.position().y()/units.m
00050 zGen = vertex.position().z()/units.m
00051 tGen = vertex.position().t()
00052
00053 point = Gaudi.XYZPoint(xGen,yGen,zGen)
00054 gpoint = self.de.geometry().toGlobal(point)
00055
00056 self.info("Vtx: %f %f %f %f"%(xGen,yGen,zGen,tGen))
00057
00058 self.dT.Fill(tGen-self.lastTime)
00059 self.lastTime = tGen
00060 self.xy.Fill(gpoint.x(),gpoint.y())
00061 self.yz.Fill(gpoint.y(),gpoint.z())
00062 self.zx.Fill(gpoing.z(),gpoint.x())
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 continue
00074 return SUCCESS
00075
00076 def configure(argv=[]):
00077 '''
00078 Configure GtMuoneratorTool based kinematics and an algorithm to
00079 histogram some quantities.
00080 '''
00081 from optparse import OptionParser
00082 op = OptionParser(usage=configure.__doc__)
00083 op.add_option("-r","--rotate-site",default=False,action="store_true",
00084 help="Rotate muons to match site")
00085 op.add_option("-s","--site",default='SAB',
00086 help="Detector site (DYB, LA, Mid, Far,SAB)")
00087 op.add_option("-M","--muon-file",default="",
00088 help="Path to text file of muon energy and directions to sample")
00089 op.add_option("-R","--ratio-file",default="",
00090 help="Path to ROOT file of mu+/mu- ratio histogram")
00091 op.add_option("-v","--volume",default="rock",
00092 help="Volume to use to place vertices (rock, RPC, ADE)")
00093 (opts,args) = op.parse_args(args=argv)
00094
00095 from StatisticsSvc.StatisticsSvcConf import StatisticsSvc
00096 statsSvc = StatisticsSvc()
00097 statsSvc.Output ={"file1":"MuonTestHist.root"}
00098
00099 volume = '/dd/Structure/AD/db-ade1'
00100 name = 'Mu'
00101
00102 from GaudiKernel import SystemOfUnits as units
00103
00104 from GenMuon.GenMuonConf import GtMuoneratorTool
00105 muon = GtMuoneratorTool(name+'onerator')
00106 muon.Rotation = opts.rotate_site
00107 muon.WhichSite = opts.site
00108 muon.MuonFile = opts.muon_file
00109 muon.RatioFile = opts.ratio_file
00110 muon.Volume = opts.volume
00111
00112 from GenTools.GenToolsConf import GtPositionerTool, GtTransformTool, GtTimeratorTool, GtGenerator
00113
00114
00115
00116
00117 pos = GtPositionerTool(name+'Pos',Volume=volume)
00118 pos.Mode = "Relative"
00119 pos.Position = [0,0,0]
00120
00121
00122 tim = GtTimeratorTool(name+'Tim')
00123 muonRate = 1000.
00124 lifet = 1./float(muonRate)
00125 tim.LifeTime = (lifet)*units.s
00126 print "Muon: Rate per second is ",muonRate
00127
00128
00129 tra = GtTransformTool(name+'Tra',Volume=volume)
00130 tra.Offset = [0., 0., (0.042)*units.meter]
00131
00132 gtgen = GtGenerator("muonerator")
00133 gtgen.GenName = 'muonerator'
00134 gtgen.GenTools = [muon,pos,tim,tra]
00135
00136 from Gaudi.Configuration import ApplicationMgr
00137 theApp = ApplicationMgr()
00138 theApp.TopAlg.append(gtgen)
00139
00140 return
00141
00142 def run(app):
00143 app.ExtSvc += ["StaticCableSvc", "StatisticsSvc"]
00144 alg = GenMuonHists()
00145 app.addAlgorithm(alg)
00146 pass
00147