Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-21 09:11:19

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4TUniformMagneticField
0027 //
0028 // Class description:
0029 //
0030 // Templated version of G4UniformMagneticField.
0031 
0032 // Author: Josh Xie (CERN, Google Summer of Code 2014), June 2014
0033 // Supervisors:  Sandro Wenzel, John Apostolakis (CERN)
0034 // --------------------------------------------------------------------
0035 #ifndef G4TUniformMagneticField_HH
0036 #define G4TUniformMagneticField_HH
0037 
0038 #include "G4Types.hh"
0039 #include "G4ThreeVector.hh"
0040 #include "G4MagneticField.hh"
0041 
0042 /**
0043  * @brief G4TUniformMagneticField is a templated version of
0044  * G4UniformMagneticField.
0045  */
0046 
0047 class G4TUniformMagneticField : public G4MagneticField
0048 {
0049   public:
0050 
0051     G4TUniformMagneticField(const G4ThreeVector& FieldVector ) 
0052     // A field with value equal to FieldVector.
0053     {
0054       fFieldComponents[0] = FieldVector.x();
0055       fFieldComponents[1] = FieldVector.y();
0056       fFieldComponents[2] = FieldVector.z();
0057     }
0058    
0059 
0060     G4TUniformMagneticField(G4double vField,
0061                             G4double vTheta,
0062                             G4double vPhi     ) 
0063     {
0064       if ( (vField<0) || (vTheta<0) || (vTheta>pi) || (vPhi<0) || (vPhi>twopi) )
0065       {
0066          G4Exception("G4TUniformMagneticField::G4TUniformMagneticField()",
0067                      "GeomField0002", FatalException, "Invalid parameters.") ;
0068       }
0069       fFieldComponents[0] = vField*std::sin(vTheta)*std::cos(vPhi) ;
0070       fFieldComponents[1] = vField*std::sin(vTheta)*std::sin(vPhi) ;
0071       fFieldComponents[2] = vField*std::cos(vTheta) ;
0072     }
0073 
0074     virtual ~G4TUniformMagneticField() = default;
0075 
0076     G4TUniformMagneticField(const G4TUniformMagneticField &p)
0077        : G4MagneticField(p)
0078     {
0079        for (G4int i=0; i<3; ++i)
0080           fFieldComponents[i] = p.fFieldComponents[i];
0081     }
0082    
0083     G4TUniformMagneticField& operator = (const G4TUniformMagneticField &p)
0084             // Copy constructor and assignment operator.
0085     {
0086       if (&p == this) return *this;
0087       for (G4int i=0; i<3; ++i)
0088          fFieldComponents[i] = p.fFieldComponents[i];
0089       return *this;
0090     }
0091 
0092     inline void GetFieldValue(const G4double yTrack[4],
0093                               G4double *B) const 
0094     {
0095        B[0]= fFieldComponents[0] ;
0096        B[1]= fFieldComponents[1] ;
0097        B[2]= fFieldComponents[2] ;
0098     }
0099    
0100     void SetFieldValue(const G4ThreeVector& newFieldVector)
0101     {
0102        fFieldComponents[0] = newFieldVector.x();
0103        fFieldComponents[1] = newFieldVector.y();
0104        fFieldComponents[2] = newFieldVector.z();
0105     }
0106 
0107     G4ThreeVector GetConstantFieldValue() const
0108     {
0109        G4ThreeVector B(fFieldComponents[0],
0110                        fFieldComponents[1],
0111                        fFieldComponents[2]);
0112        return B;
0113     }
0114     // Return the field value
0115    
0116     virtual G4TUniformMagneticField* Clone() const
0117     { 
0118        return new G4TUniformMagneticField( G4ThreeVector(this->fFieldComponents[0],
0119                                                          this->fFieldComponents[1],
0120                                                          this->fFieldComponents[2]) );
0121     }
0122 
0123   private:
0124 
0125     G4double fFieldComponents[3] ;
0126 };
0127 
0128 #endif