00001
00002 '''
00003 Test that the kinematics are self consistent
00004
00005 nuwa.py -n 10 -m 'GenMuon.Helpers DYB ADE /dd/Structure/AD/db-ade1' -m GenMuon.TestMasses
00006
00007 '''
00008
00009 from DybPython.DybPythonAlg import DybPythonAlg, SUCCESS, FAILURE
00010 from DybPython.Util import irange
00011
00012 from GaudiKernel import SystemOfUnits as units
00013 from GaudiPython import loaddict
00014
00015 loaddict('libHepMCRflx')
00016
00017 from math import sqrt, fabs
00018
00019 class MassiveFailure(DybPythonAlg):
00020
00021 def __init__(self, name = 'MassiveFailure'):
00022 DybPythonAlg.__init__(self, name)
00023 self.ppsvc = None
00024 return
00025
00026 def initialize(self):
00027 sc = DybPythonAlg.initialize(self)
00028 if sc.isFailure(): return sc
00029
00030 self.ppsvc = self.svc('IParticlePropertySvc','ParticlePropertySvc')
00031 if not self.ppsvc:
00032 self.error('Failed to get the ParticlePropertySvc')
00033 return FAILURE
00034
00035 return SUCCESS
00036
00037 def execute(self):
00038 tes = self.evtSvc()
00039 gh = tes['/Event/Gen/GenHeader']
00040 if not gh:
00041 self.error('Failed to get a GenHeader')
00042 return FAILURE
00043
00044 ge = gh.event()
00045 if not ge:
00046 self.error('Failed to get a GenEvent')
00047 return FAILURE
00048
00049 for part in irange(ge.particles_begin(),ge.particles_end()):
00050 mom = part.momentum()
00051 pid = part.pdg_id()
00052
00053 prop = self.ppsvc.findByStdHepID(pid)
00054 if not prop:
00055 self.warning('No particle property for PID %d'%pid)
00056 continue
00057
00058 def check_mass(label,mtest,mcalc):
00059 dM = fabs(mtest-mcalc)
00060 dM_rat = dM / mtest
00061 dM_eps = 0.01*units.MeV
00062 if dM_rat > 0.001 or dM > dM_eps:
00063 self.warning('PID %d has %s mass %.2f MeV but calculated as %.2f MeV' % \
00064 (pid, label, mtest / units.MeV, mcalc / units.MeV))
00065 return False
00066 return True
00067
00068 mcalc = sqrt(fabs( mom.t()**2 - (mom.x()**2 + mom.y()**2 + mom.z()**2) ))
00069 ok1 = check_mass('generated',part.generated_mass(),mcalc)
00070 ok2 = check_mass('property',prop.mass(),mcalc)
00071 if not ok1 and not ok2:
00072 error("Failed to get reasonable mass")
00073 return FAILURE
00074 else:
00075 self.info('PID %d has mass %.2f MeV, energy %.2f GeV/c' % \
00076 (pid, mcalc / units.MeV, mom.e() / units.GeV ))
00077 continue
00078 return SUCCESS
00079
00080
00081 def run(app):
00082 app.ExtSvc += ['ParticlePropertySvc']
00083
00084 alg = MassiveFailure()
00085 app.addAlgorithm(alg)
00086
00087