Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-18 08:35:09

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 // Adapted from G4QuadrupoleMagField.
0034 
0035 // Author: Josh Xie (CERN, Google Summer of Code 2014), June 2014
0036 // Supervisors:  Sandro Wenzel, John Apostolakis (CERN)
0037 // --------------------------------------------------------------------
0038 #ifndef G4T_QUADRUPOLE_MAGFIELD_HH
0039 #define G4T_QUADRUPOLE_MAGFIELD_HH
0040 
0041 #include "G4ThreeVector.hh"
0042 #include "G4RotationMatrix.hh"
0043 #include "G4MagneticField.hh"
0044 
0045 /**
0046  * @brief G4TQuadrupoleMagField is a templated version of G4QuadrupoleMagField.
0047  */
0048 
0049 class G4TQuadrupoleMagField : public G4MagneticField 
0050 {
0051   public:
0052 
0053     G4TQuadrupoleMagField(G4double pGradient)
0054     {
0055       fGradient = pGradient ;
0056       fOrigin   = G4ThreeVector( 0.0, 0.0, 0.0) ;
0057       fpMatrix  = &IdentityMatrix;
0058     }
0059 
0060     G4TQuadrupoleMagField(G4double pGradient, 
0061                           G4ThreeVector pOrigin, 
0062                           G4RotationMatrix* pMatrix)
0063     {
0064       fGradient    = pGradient ;
0065       fOrigin      = pOrigin ;
0066       fpMatrix     = pMatrix ;
0067     }
0068 
0069     virtual ~G4TQuadrupoleMagField() = default;
0070 
0071     inline void GetFieldValue(const G4double y[7],
0072                                     G4double B[3] ) const
0073     {
0074       G4ThreeVector r_global = G4ThreeVector(
0075               y[0] - fOrigin.x(), 
0076               y[1] - fOrigin.y(), 
0077               y[2] - fOrigin.z());
0078 
0079       G4ThreeVector r_local = G4ThreeVector(
0080               fpMatrix->colX() * r_global,
0081               fpMatrix->colY() * r_global,
0082               fpMatrix->colZ() * r_global);
0083 
0084       G4ThreeVector B_local = G4ThreeVector(
0085               fGradient * r_local.y(),
0086               fGradient * r_local.x(),
0087               0);
0088 
0089       G4ThreeVector B_global = G4ThreeVector(
0090               fpMatrix->inverse().rowX() * B_local,
0091               fpMatrix->inverse().rowY() * B_local,
0092               fpMatrix->inverse().rowZ() * B_local);
0093 
0094       B[0] = B_global.x() ;
0095       B[1] = B_global.y() ;
0096       B[2] = B_global.z() ;
0097     }
0098 
0099     G4TQuadrupoleMagField* Clone() const
0100     {
0101       //TODO: Can the fpMatrix be shared??
0102       return new G4TQuadrupoleMagField(this->fGradient,
0103                                        this->fOrigin,
0104                                        this->fpMatrix);
0105     }
0106 
0107   private:
0108 
0109     static G4RotationMatrix IdentityMatrix; 
0110 
0111     G4double          fGradient;
0112     G4ThreeVector     fOrigin;
0113     G4RotationMatrix* fpMatrix;
0114 };
0115 
0116 #endif
0117