Magnetic_Field.h

Go to the documentation of this file.
00001 //! \file
00002 //!
00003 //! Header file for Magnetic_Field class.
00004 //!
00005 //! This defines the Magnetic_Field class and the member routines which
00006 //! construct the OLYMPUS toroidal magnetic field.
00007 //!
00008 //! \author D.K. Hasell
00009 //! \version 1.0
00010 //! \date 2010-02-27
00011 //!
00012 //! \ingroup detector
00013 
00014 // Ensure this header file is included only once.
00015 
00016 #ifndef MAGNETIC_FIELD_H
00017 #define MAGNETIC_FIELD_H
00018 
00019 // Include the GEANT4 header files referenced here.
00020 
00021 #include "G4MagneticField.hh"
00022 
00023 // Include the STL header files referenced here.
00024 
00025 #include <vector>
00026 
00027 // Use the STD namespace.
00028 
00029 using namespace std;
00030 
00031 //! Declare the Magnetic_Field class.
00032 //!
00033 //! The Magnetic_Field class stores the grid of magnetic field values in an
00034 //! array of stl vectors.  The routine reads a file with the magnetic field
00035 //! grid values and loads these into the arrays. The member function
00036 //! GetMagneticField is then used to return the field at a given point.
00037 
00038 class Magnetic_Field : public G4MagneticField {
00039 
00040 private:
00041 
00042      vector< vector< vector< G4double > > > fBx; //!< X component of field.
00043      vector< vector< vector< G4double > > > fBy; //!< Y component of field.
00044      vector< vector< vector< G4double > > > fBz; //!< Z component of field.
00045 
00046      G4int fNdata;            //!< Number of grid points.
00047      G4int fNx;               //!< Number of grid steps in X direction.
00048      G4int fNy;               //!< Number of grid steps in Y direction.
00049      G4int fNz;               //!< Number of grid steps in Z direction.
00050 
00051      G4double fXmin;          //!< Starting X coordinate for grid.
00052      G4double fYmin;          //!< Starting Y coordinate for grid.
00053      G4double fZmin;          //!< Starting Z coordinate for grid.
00054 
00055      G4double fDx;            //!< Step size in X direction.
00056      G4double fDy;            //!< Step size in Y direction.
00057      G4double fDz;            //!< Step size in Z direction.
00058 
00059      G4double fScale;         //!< Scale factor for calculating the field.
00060 
00061 public:
00062 
00063      //! Constructor for Magnetic_Field class.
00064      //!
00065      //! Reads the file specified by \a filename for the magnetic field value
00066      //! grid and stores this into the arrays.  Also stores the scale factor
00067      //! \a scale used in scaling the magnetic field reurned by the member
00068      //! function.
00069      //!
00070      //! \param[in] filename - name of file containing the magnetic field grid
00071      //! \param[in] scale - multiplicative factor used to scale the calculated
00072      //! magnetic field returned by the member function GetFieldValue.
00073 
00074      Magnetic_Field( const char * filename, G4double scale = 1.0 );
00075 
00076      //! Member function to return the magnetic field value at a given point.
00077      //!
00078      //! Performs a simple linear interpolation over the grid of stored values
00079      //! which bracket the requested space point \a point and returns the 
00080      //! magnetic field \a Bfield at that point.
00081      //!
00082      //! \param[in] Point - array of x, y, z, t coordinates specifying the 
00083      //! coordinates where the field should be evaluated (time coordinate
00084      //! ignored in this code).
00085      //! \param[out] Bfield - pointer to a six dimensional array giving the
00086      //! magnetic and electric field components at \a Point 
00087 
00088      void GetFieldValue( const G4double Point[4], G4double * Bfield ) const;
00089 
00090      //! Member function to set the magnetic field scaling factor.
00091      //!
00092      //! The interpolated magnetic field is scaled, multiplicatively, by
00093      //! this factor to determine the actual field.  Typically this is set
00094      //! to 1.0 for normal operation but can be set to any value in the
00095      //! range [-1.0, 1.0] for reasonable operation.
00096      //!
00097      //! \param[in] scale - scale factor should be in range [-1, 1]
00098 
00099      G4double setScale( G4double scale = 1.0 );
00100 
00101      //! Member function to get the magnetic field scaling factor.
00102      //!
00103      //! Returns the current magnetic field scale factor.
00104 
00105      G4double getScale();
00106 
00107 };
00108 
00109 #endif