00001
00002 '''
00003 Helpers to configure GenMuon.
00004
00005 This is also a job module. See docs under configure()
00006 '''
00007
00008 import os
00009
00010 class CosmicHelper:
00011 '''
00012 A helper for use with GenTools.Configure()
00013 '''
00014
00015 def __init__(self, site, volume, coord_de, path):
00016 '''
00017 Create a helper to set up kinematics for cosmic muons.
00018 Options:
00019
00020 site : set which site (DYB, LA, Mid, Far,SAB)
00021 volume : keyword for muon generator to determine where to put muon vertices (rock, RPC, ADE)
00022 coord_de : detector element providing coordinate system to convert to global (eg, '/dd/Structure/AD/db-ade1')
00023 path : set directory holding muon data, overrides $MuonDataPath
00024
00025 The tools it produces are available via:
00026 .muon the GtMuoneratorTool
00027 .positioner the GtPositionerTool
00028 .transform the GtTransformTool
00029 .timerator the GtTimeratorTool
00030 '''
00031
00032
00033 if not path:
00034 print 'No muon data path given, checking $MuonDataPath'
00035 path = os.getenv('MuonDataPath')
00036 if not path:
00037 for where in [os.getenv('NEWMUONGENERATORROOT','data/NewMuonGenerator/data'),
00038 os.getenv('NEWMUONGENERATORROOT','data/trunk/NewMuonGenerator/data')]:
00039 print 'No $MuonDataPath, trying to locate %s/' % where
00040 sr = os.getenv('SITEROOT')
00041 if sr:
00042 maybe = os.path.join(sr,where)
00043 if os.path.exists(maybe):
00044 path = maybe
00045 break
00046 continue
00047 continue
00048 if not path:
00049 raise ValueError('Could not find input muon data anywhere, go fish.')
00050
00051 flux_file = os.path.join(path,'mountain_%s'%site)
00052 url = 'http://dayabay.ihep.ac.cn/svn/dybsvn/data/trunk/NewMuonGenerator/data/'
00053 if not os.path.exists(flux_file):
00054 raise RuntimeError('No flux file "%s" get it from %s' % (flux_file, url) )
00055
00056 ratio_file = os.path.join(path,'mu_plus_minus_ratio.root')
00057 if not os.path.exists(ratio_file):
00058 print 'No mu+/mu- ratio file found, will rely on paramatrization.'
00059
00060
00061 name = 'Cosmic-%s-%s' % (site,volume)
00062
00063 from GenMuon.GenMuonConf import GtMuoneratorTool
00064 muon = GtMuoneratorTool(name+'_muonerator')
00065
00066 muon.WhichSite = site
00067 muon.MuonFile = flux_file
00068 muon.RatioFile = ratio_file
00069 muon.Volume = volume
00070 self.muon = muon
00071
00072 from GenTools.GenToolsConf import GtPositionerTool, GtTransformTool, GtTimeratorTool
00073 from GaudiKernel import SystemOfUnits as units
00074
00075
00076 pos = GtPositionerTool(name+'_positioner',Volume=coord_de)
00077 pos.Mode = "Relative"
00078 pos.Position = [0,0,0]
00079 self.positioner = pos
00080
00081
00082 tim = GtTimeratorTool(name+'_timerator')
00083 muonRate = 1000.
00084 lifet = 1./float(muonRate)
00085 tim.LifeTime = (lifet)*units.s
00086 print "Muon: Rate per second is ",muonRate
00087 self.timerator = tim
00088
00089
00090 tra = GtTransformTool(name+'_transformer',Volume=coord_de)
00091 tra.Offset = [0., 0., (0.042)*units.meter]
00092 self.transformer = tra
00093
00094 return
00095
00096 def tools(self):
00097 return [self.muon,self.positioner,self.timerator,self.transformer]
00098
00099 pass
00100
00101 def configure(argv=None):
00102 '''
00103 Add a CosmicHelper to the job
00104
00105 usage: GenMuon.Helpers site volume coord_de [path]
00106 '''
00107 if not argv:
00108 raise ValueError("no args.")
00109
00110 import GenTools
00111
00112 site = argv[0]
00113 volume = argv[1]
00114 coord_de = argv[2]
00115 try:
00116 path = argv[3]
00117 except IndexError:
00118 path = None
00119
00120 cosmic_helper = CosmicHelper(site,volume,coord_de,path)
00121 res = GenTools.Configure('CosmicsIn%s%s'%(site,volume),
00122 'CosmicsIn%s%s'%(site,volume),
00123 cosmic_helper)
00124