;ς “0eBc@s€dkTdklZdefd„ƒYZdfd„ƒYZdefd„ƒYZdfd „ƒYZd efd „ƒYZd S( (s*(srandomsVectorcBshtZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z RS( sΧMathematical vector of any size Changes behaviour of lists so as to behave more like a vector w.r.t addition etc. Methods are described seperately. Builds on code by A. Pletzer in the ActiveState Python CookbookcCsBtgi}t||ƒD]\}}|||ƒq~ƒSdS(s-Returns an element by element sum in a VectorN(sVectorsappends_[1]szipsselfsothersisj(sselfsothersisjs_[1]((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys__add__scCs0tgi}|D]}|| ƒq~ƒSdS(s*Returns Vector with all elements negativedN(sVectorsappends_[1]sselfsi(sselfs_[1]si((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys__neg__scCsBtgi}t||ƒD]\}}|||ƒq~ƒSdS(s/Returns Vector of the difference of two vectorsN(sVectorsappends_[1]szipsselfsothersisj(sselfsothersisjs_[1]((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys__sub__ scCsyBtgi}t||ƒD]\}}|||ƒq~ƒSWn6tgi}|D]}|||ƒqY~ƒSnXdS(s5Returns element by element multiplication in a VectorN(sVectorsappends_[1]szipsselfsothersisj(sselfsothersisjs_[1]((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys__mul__#s BcCs ||SdS(s:Since multiplcation commutes, __rmul__() does as __mul__()N(sselfsother(sselfsother((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys__rmul__(scCsyBtgi}t||ƒD]\}}|||ƒq~ƒSWn6tgi}|D]}|||ƒqY~ƒSnXdS(sDivides, element by elementN(sVectorsappends_[1]szipsselfsothersisj(sselfsothersisjs_[1]((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys__div__+s BcCs9ttgi}|D]}||dƒq~ƒƒSdS(sReturns magnitude of the vectoriN(ssqrtssumsappends_[1]sselfsx(sselfs_[1]sx((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys magnitude0scCst||iƒSdS(s Returns unit vector in directionN(sVectorsselfs magnitude(sself((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pysunit3scCst||ƒSdS(s.Returns dot product of this and another vectorN(ssumsselfsother(sselfsother((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pysdot6scCs›t|ƒdjpt|ƒdjo td‚net|d|d|d|d|d|d|d|d|d|d|d|dƒSdS(sgReturns the cross product of this and another vector. Currently only works for Vectors with 3 valuesis6cross method currently only works for 3 valued VectorsiiiN(slensothersselfs ValueErrorsVector(sselfsother((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pyscross9s & "( s__name__s __module__s__doc__s__add__s__neg__s__sub__s__mul__s__rmul__s__div__s magnitudesunitsdotscross(((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pysVectors          sBoxcBsJtZdZdddgdddgd„Zd„Zd„Zd„ZRS(sνDefines a cuboid in 3D First argument when a Box is created is a 3 valued vector giving the dimensions of the cuboid, the second argument gives the position of the centre. If no arguments given a unit box centred on origin is creatediicCs|i||ƒdS(N(sselfs set_dims_possdimsspos(sselfsdimsspos((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys__init__JscCs―t|ƒ|_t|ƒ|_tgi}t||ƒD]\}}|||ƒq8~ƒ|_ tgi}t|i |ƒD]\}}|d||ƒq~~ƒ|_ dS(sUse to redefine corners of boxf0.5N( sVectorsnrsselfsfarsappends_[1]szipsnsfsdimssdspos(sselfsnrsfarsdsfsns_[1]((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys set_cornersOs CcCs±t|ƒ|_t|ƒ|_tgi}t||ƒD]\}}|d||ƒq8~ƒ|_ tgi}t||ƒD]\}}|d ||ƒq~ƒ|_ dS(s.Use to redefine position and dimensions of boxf0.5N( sVectorsdimssselfspossappends_[1]szipsdspsnrsfar(sselfsdimsspossdsps_[1]((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys set_dims_posUs GcCs°|d|idjp|d|idjotSn|d|idjp|d|idjotSn|d|idjp|d|idjotSntSdS(s6Returns True if a point is inside box, False otherwiseiiiN(spntsselfsnrsfarsFalsesTrue(sselfspnt((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pysinside[s000(s__name__s __module__s__doc__s__init__s set_cornerss set_dims_possinside(((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pysBoxDs !  sDetectorcBstZdZd„ZRS(s~Defines a cuboid shaped detector in 3D Inheriting from the Box class, the dimensions and position are defined as for a Box.cCs ti|||ƒh|_dS(N(sBoxs__init__sselfsdimssposshits(sselfsdimsspos((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys__init__gs(s__name__s __module__s__doc__s__init__(((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pysDetectorbs sParticlecBs/tZdZdddgdddgd„ZRS(s–Defines a particle Initialises a particle with a position and velocity vector. If no arguments given a stationary particle at the origin is createdicCs"t|ƒ|_t|ƒ|_dS(N(sVectorspossselfsvel(sselfspossvel((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys__init__rs(s__name__s __module__s__doc__s__init__(((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pysParticlems s CosmicRaycBs>tZdZedddgdddgƒd„Zd„ZRS(sωDefines a cosmic ray particle Creates a particle in a cuboid with random direction and displacement and traces back to point of entry. Parameter vol is instance of Box or Detector class. If no argument is passed, CosmicRay is created at originicCs!xHno@tƒtd|_tƒ}|t|iƒdjoPqq Wtƒdt|_tt|iƒt|iƒt|iƒt|iƒt|iƒ gƒ|_ ttƒ|i d|i dtƒ|i d|i dtƒ|i d|i dgƒ|_ |i|ƒdS(Niif2.0i(srandomspisselfsphisyscossthetasVectorssinsvelsvolsdimssfarsposs traceback(sselfsvolsy((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys__init__}s  NccCsrx<no4|id|i|_|i|iƒ oPqq Wx,|i|iƒ o|i|i|_qBWdS(Nii (sselfspossvelsvolsinside(sselfsvol((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys traceback“s (s__name__s __module__s__doc__sBoxs__init__s traceback(((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys CosmicRayvs 'N(smathsrandomslistsVectorsBoxsDetectorsParticles CosmicRay(sBoxsParticlesrandomsVectorsDetectors CosmicRay((s7/www/b/brendan/phy/project/code/ParticleModelClasses.pys?s  0