Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:14

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 
0027 #ifndef G4UniformMagneticField_HH
0028 #define G4UniformMagneticField_HH
0029 
0030 #include "G4Types.hh"
0031 #include "G4ThreeVector.hh"
0032 #include "G4MagneticField.hh"
0033 
0034 class G4TUniformMagneticField : public G4MagneticField
0035 {
0036   public:  // with description
0037 
0038     G4TUniformMagneticField(const G4ThreeVector& FieldVector ) 
0039     // A field with value equal to FieldVector.
0040     {
0041       fFieldComponents[0] = FieldVector.x();
0042       fFieldComponents[1] = FieldVector.y();
0043       fFieldComponents[2] = FieldVector.z();
0044     }
0045    
0046 
0047     G4TUniformMagneticField(G4double vField,
0048                             G4double vTheta,
0049                             G4double vPhi     ) 
0050     {
0051       if ( (vField<0) || (vTheta<0) || (vTheta>pi) || (vPhi<0) || (vPhi>twopi) )
0052       {
0053          G4Exception("G4TUniformMagneticField::G4TUniformMagneticField()",
0054                      "GeomField0002", FatalException, "Invalid parameters.") ;
0055       }
0056       fFieldComponents[0] = vField*std::sin(vTheta)*std::cos(vPhi) ;
0057       fFieldComponents[1] = vField*std::sin(vTheta)*std::sin(vPhi) ;
0058       fFieldComponents[2] = vField*std::cos(vTheta) ;
0059     }
0060 
0061     virtual ~G4TUniformMagneticField() {;}
0062 
0063     G4TUniformMagneticField(const G4TUniformMagneticField &p)
0064        : G4MagneticField(p)
0065     {
0066        for (G4int i=0; i<3; ++i)
0067           fFieldComponents[i] = p.fFieldComponents[i];
0068     }
0069    
0070     G4TUniformMagneticField& operator = (const G4TUniformMagneticField &p)
0071             // Copy constructor and assignment operator.
0072     {
0073       if (&p == this) return *this;
0074       for (G4int i=0; i<3; ++i)
0075          fFieldComponents[i] = p.fFieldComponents[i];
0076       return *this;
0077     }
0078 
0079     inline void GetFieldValue(const G4double yTrack[4],
0080                               G4double *B) const 
0081     {
0082        B[0]= fFieldComponents[0] ;
0083        B[1]= fFieldComponents[1] ;
0084        B[2]= fFieldComponents[2] ;
0085     }
0086    
0087     void SetFieldValue(const G4ThreeVector& newFieldVector)
0088     {
0089        fFieldComponents[0] = newFieldVector.x();
0090        fFieldComponents[1] = newFieldVector.y();
0091        fFieldComponents[2] = newFieldVector.z();
0092     }
0093 
0094     G4ThreeVector GetConstantFieldValue() const
0095     {
0096        G4ThreeVector B(fFieldComponents[0],
0097                        fFieldComponents[1],
0098                        fFieldComponents[2]);
0099        return B;
0100     }
0101     // Return the field value
0102    
0103     virtual G4TUniformMagneticField* Clone() const
0104     { 
0105        return new G4TUniformMagneticField( G4ThreeVector(this->fFieldComponents[0],
0106                                                          this->fFieldComponents[1],
0107                                                          this->fFieldComponents[2]) );
0108     }
0109 
0110     private:
0111         G4double fFieldComponents[3] ;
0112 };
0113 
0114 #endif