Line data Source code
1 : #ifndef CRPROPA_PARTICLE_STATE_H 2 : #define CRPROPA_PARTICLE_STATE_H 3 : 4 : #include "crpropa/Vector3.h" 5 : 6 : namespace crpropa { 7 : /** 8 : * \addtogroup Core 9 : * @{ 10 : */ 11 : 12 : /** 13 : @class ParticleState 14 : @brief State of the particle: ID, energy, position, direction 15 : 16 : The ParticleState defines the state of an ultra-high energy cosmic ray, which 17 : is assumed to be traveling at the exact speed of light. 18 : The cosmic ray state is defined by particle ID, energy and position and 19 : direction vector. 20 : For faster lookup mass and charge of the particle are stored as members. 21 : */ 22 7230041 : class ParticleState { 23 : private: 24 : int id; ///< particle ID (Particle Data Group numbering scheme) 25 : double energy; ///< total energy 26 : Vector3d position; ///< position vector in comoving coordinates 27 : Vector3d direction; ///< unit vector of velocity or momentum 28 : double pmass; ///< particle rest mass 29 : double charge; ///< particle charge 30 : 31 : public: 32 : /** Constructor for a particle state. 33 : @param id id of the particle following the PDG numbering scheme 34 : @param energy energy of the particle [in Joules] 35 : @param position vector containing the coordinates of the particle [in meters] 36 : @param direction vector containing the direction of motion of the particle 37 : */ 38 : ParticleState(int id = 0, double energy = 0, 39 : Vector3d position = Vector3d(0, 0, 0), 40 : Vector3d direction = Vector3d(-1, 0, 0)); 41 : 42 : /** Set particle position. 43 : In simulations including cosmological effects, the position is given in comoving coordinates. 44 : @param pos vector containing the coordinates of the particle [in meters] 45 : */ 46 : void setPosition(const Vector3d &pos); 47 : /** Get position of particle. 48 : @returns Position vector of particle. If cosmological effects are included, the coordinates are comoving. 49 : */ 50 : const Vector3d &getPosition() const; 51 : 52 : /** Set direction unit vector, non unit-vectors are normalized 53 : @param dir vector containing the direction of motion of the particle 54 : */ 55 : void setDirection(const Vector3d &dir); 56 : /** Get direction unit vector 57 : @returns Normalized vector containing direction of motion of particle. 58 : */ 59 : const Vector3d &getDirection() const; 60 : 61 : /** Set energy of particle. 62 : @param newEnergy energy to be assigned to particle [in Joules] 63 : */ 64 : void setEnergy(double newEnergy); 65 : /** Get energy of particle. 66 : @returns Energy of particle [in Joules] 67 : */ 68 : double getEnergy() const; 69 : /** Get rigidity of particle, defined as E/(Z*e). 70 : @returns Rigidity of the particle [in Volts] 71 : */ 72 : double getRigidity() const; 73 : 74 : /** Set particle ID. 75 : This follows the PDG numbering scheme: 76 : https://pdg.lbl.gov/2019/reviews/rpp2019-rev-monte-carlo-numbering.pdf 77 : @param newId id to be assigned to the particle 78 : */ 79 : void setId(int newId); 80 : /** Get particle ID 81 : @returns Particle ID (in PDG format). 82 : */ 83 : int getId() const; 84 : 85 : std::string getDescription() const; 86 : 87 : // ======== Helper methods ======== 88 : 89 : /** Get electrical charge of the particle. 90 : @returns Charge of the particle [in Coulombs] 91 : */ 92 : double getCharge() const; 93 : /** Get mass of the particle. 94 : @returns Mass of the particle [kg] 95 : */ 96 : double getMass() const; 97 : 98 : /** Set Lorentz factor and modify the particle's energy accordingly. 99 : @param gamma Lorentz factor 100 : */ 101 : void setLorentzFactor(double gamma); 102 : /** Get Lorentz factor 103 : @returns Lorentz factor of particle 104 : */ 105 : double getLorentzFactor() const; 106 : 107 : /** Get velocity: direction times the speed of light. 108 : @returns Velocity of particle [m/s] 109 : */ 110 : Vector3d getVelocity() const; 111 : /** Get momentum: direction times energy divided by the speed of light 112 : @returns The momentum [kg m/s] 113 : */ 114 : Vector3d getMomentum() const; 115 : }; 116 : /** @}*/ 117 : 118 : } // namespace crpropa 119 : 120 : #endif // CRPROPA_PARTICLE_STATE_H