Back to home page

EIC code displayed by LXR

 
 

    


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

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 // G4TMagFieldEquation
0027 //
0028 // Class description:
0029 //
0030 // Templated version of  motion of quadrupole magnetic field.
0031 // Enables testing of inlined code for field, equation, stepper, driver,
0032 // avoiding all virtual calls.
0033 //
0034 // --------------------------------------------------------------------
0035 // Created: Josh Xie  (Google Summer of Code 2014 )
0036 // Adapted from G4QuadrupoleMagField  ( of June 2014 .... )
0037 //
0038 
0039 #ifndef G4T_QUADRUPOLE_MAGFIELD_HH
0040 #define G4T_QUADRUPOLE_MAGFIELD_HH
0041 
0042 #include "G4ThreeVector.hh"
0043 #include "G4RotationMatrix.hh"
0044 #include "G4MagneticField.hh"
0045 
0046 static G4RotationMatrix IdentityMatrix; 
0047 
0048 class G4TQuadrupoleMagField : public G4MagneticField 
0049 {
0050   public: // with description
0051 
0052   G4TQuadrupoleMagField(G4double pGradient)
0053   {
0054     fGradient = pGradient ;
0055     fOrigin   = G4ThreeVector( 0.0, 0.0, 0.0) ;
0056     fpMatrix  = &IdentityMatrix;
0057   }
0058 
0059         G4TQuadrupoleMagField(G4double pGradient, 
0060                 G4ThreeVector pOrigin, 
0061                 G4RotationMatrix* pMatrix)
0062         {
0063             fGradient    = pGradient ;
0064             fOrigin      = pOrigin ;
0065             fpMatrix     = pMatrix ;
0066         }
0067 
0068         virtual ~G4TQuadrupoleMagField() {;}
0069 
0070         inline void GetFieldValue(const G4double y[7],
0071                 G4double B[3]     ) const
0072         {
0073             G4ThreeVector r_global = G4ThreeVector(
0074                     y[0] - fOrigin.x(), 
0075                     y[1] - fOrigin.y(), 
0076                     y[2] - fOrigin.z());
0077 
0078             G4ThreeVector r_local = G4ThreeVector(
0079                     fpMatrix->colX() * r_global,
0080                     fpMatrix->colY() * r_global,
0081                     fpMatrix->colZ() * r_global);
0082 
0083             G4ThreeVector B_local = G4ThreeVector(
0084                     fGradient * r_local.y(),
0085                     fGradient * r_local.x(),
0086                     0);
0087 
0088             G4ThreeVector B_global = G4ThreeVector(
0089                     fpMatrix->inverse().rowX() * B_local,
0090                     fpMatrix->inverse().rowY() * B_local,
0091                     fpMatrix->inverse().rowZ() * B_local);
0092 
0093             B[0] = B_global.x() ;
0094             B[1] = B_global.y() ;
0095             B[2] = B_global.z() ;
0096         }
0097 
0098         G4TQuadrupoleMagField* Clone() const
0099         {
0100             //TODO: Can the fpMatrix be shared??
0101             return new G4TQuadrupoleMagField(this->fGradient,
0102                     this->fOrigin,
0103                     this->fpMatrix);
0104         }
0105 
0106     private:
0107 
0108         G4double          fGradient;
0109         G4ThreeVector     fOrigin;
0110         G4RotationMatrix* fpMatrix;
0111 };
0112 #endif
0113