Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-09-27 07:03:37

0001 ///////////////////////////////////////////////////////////////////////////
0002 //
0003 //    Copyright 2010
0004 //
0005 //    This file is part of starlight.
0006 //
0007 //    starlight is free software: you can redistribute it and/or modify
0008 //    it under the terms of the GNU General Public License as published by
0009 //    the Free Software Foundation, either version 3 of the License, or
0010 //    (at your option) any later version.
0011 //
0012 //    starlight is distributed in the hope that it will be useful,
0013 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0015 //    GNU General Public License for more details.
0016 //
0017 //    You should have received a copy of the GNU General Public License
0018 //    along with starlight. If not, see <http://www.gnu.org/licenses/>.
0019 //
0020 ///////////////////////////////////////////////////////////////////////////
0021 //
0022 // File and Version Information:
0023 // $Rev:: 213                         $: revision of last commit
0024 // $Author:: butter                   $: author of last commit
0025 // $Date:: 2015-08-15 22:08:02 +0100 #$: date of last commit
0026 //
0027 // Description:
0028 //
0029 //
0030 //
0031 ///////////////////////////////////////////////////////////////////////////
0032 
0033 
0034 #ifndef LORENTZVECTOR_H
0035 #define LORENTZVECTOR_H
0036 
0037 
0038 #include "vector3.h"
0039 #include <vector>
0040 
0041 
0042 class lorentzVector
0043 {
0044    public:
0045       
0046       lorentzVector();
0047       virtual ~lorentzVector();
0048       
0049       lorentzVector(double x, double y, double z, double t);
0050       
0051       void SetXYZT(double x, double y, double z, double t);
0052       void SetPxPyPzE(double px, double py, double pz, double e) { SetXYZT(px, py, pz, e); };
0053       
0054       double GetPx() const { return fSpaceVec.GetVector()[0]; }
0055       double GetPy() const { return fSpaceVec.GetVector()[1]; }
0056       double GetPz() const { return fSpaceVec.GetVector()[2]; }
0057       double GetE() const { return fTime; }
0058       virtual void reflect(){fSpaceVec.SetVector(-1.0*fSpaceVec.X(),-1.0*fSpaceVec.Y(),-1.0*fSpaceVec.Z());};
0059       
0060         lorentzVector& operator +=(const lorentzVector& vec)
0061         {
0062             fSpaceVec += vec.fSpaceVec;
0063             fTime     += vec.fTime;
0064             return *this;
0065         }
0066         lorentzVector& operator -=(const lorentzVector& vec)
0067         {
0068             fSpaceVec -= vec.fSpaceVec;
0069             fTime     -= vec.fTime;
0070             return *this;
0071         }
0072 
0073         double M2() const { return fTime * fTime - fSpaceVec.Mag2(); }
0074       double M () const
0075         {
0076           const double mag2 = M2();
0077           return (mag2 < 0) ? -sqrt(-mag2) : sqrt(mag2);
0078       }
0079 
0080         vector3 BoostVector() const
0081         { return vector3(fSpaceVec.X() / fTime, fSpaceVec.Y() / fTime, fSpaceVec.Z() / fTime); }
0082         void Boost(const vector3& beta)
0083         {
0084             const double beta2        = beta.Mag2();
0085             const double gamma        = 1 / sqrt(1 - beta2);
0086             const double betaTimesMom = beta.X() * fSpaceVec.X() + beta.Y() * fSpaceVec.Y() + beta.Z() * fSpaceVec.Z();
0087             const double gamma2       = (beta2 > 0) ? (gamma - 1) / beta2 : 0;
0088             SetXYZT(fSpaceVec.X() + gamma2 * betaTimesMom * beta.X() + gamma * beta.X() * fTime,
0089                     fSpaceVec.Y() + gamma2 * betaTimesMom * beta.Y() + gamma * beta.Y() * fTime,
0090                     fSpaceVec.Z() + gamma2 * betaTimesMom * beta.Z() + gamma * beta.Z() * fTime,
0091                     gamma * (fTime + betaTimesMom));
0092         }
0093       
0094         friend std::ostream& operator << (std::ostream&        out,
0095                                           const lorentzVector& vec)
0096         {
0097             out << "(" << vec.GetPx() << ", " << vec.GetPy() << ", " << vec.GetPz()
0098                 << "; " << vec.GetE() << ")";
0099             return out;
0100         }
0101 
0102    private:
0103       
0104       vector3 fSpaceVec;
0105       double fTime;
0106       
0107 };
0108 
0109 
0110 #endif  // LORENTZVECTOR_H