Class MagneticField

java.lang.Object
cnuphys.magfield.MagneticField
All Implemented Interfaces:
IMagField
Direct Known Subclasses:
Solenoid, Torus

public abstract class MagneticField extends Object implements IMagField
For magnetic fields stored in a specific format. This is low-level, essentiall a container for the field values
Version:
1.0
Author:
David Heddle, Nicole Schumacher
  • Field Details

    • LOGGER

      public static Logger LOGGER
    • MAGICNUMBER

      public static final int MAGICNUMBER
      Magic number used to check if byteswapping is necessary.
      See Also:
    • MISALIGNTOL

      public static final double MISALIGNTOL
      misalignment tolerance
      See Also:
    • maxFieldIndex

      protected int maxFieldIndex
      Index where max field magnitude resides
    • maxField

      protected float maxField
      The maximum magnitude of the field.
    • maxVectorField

      protected final float[] maxVectorField
      The max vector field.
    • maxFieldLocation

      protected final float[] maxFieldLocation
      The location of the maximum field.
    • avgField

      protected float avgField
      The average magnitude of the field.
    • gridCoordinateSystem

      protected CoordinateSystem gridCoordinateSystem
      The grid coordinate system.
    • fieldCoordinateSystem

      protected CoordinateSystem fieldCoordinateSystem
      The field coordinate system.
    • lengthUnit

      protected LengthUnit lengthUnit
      The length unit.
    • angularUnit

      protected AngularUnit angularUnit
      The angular unit.
    • fieldUnit

      protected FieldUnit fieldUnit
      The field unit.
    • field

      protected FloatBuffer field
      holds the field in a float buffer.
    • highTime

      protected int highTime
      high word of unix creation time
    • lowTime

      protected int lowTime
      low word of unix creation time
    • reserved3

      protected int reserved3
      reserved word
    • reserved4

      protected int reserved4
      reserved word
    • reserved5

      protected int reserved5
      reserved word
    • _shiftX

      protected double _shiftX
      shift in x direction in cm (misalignment)
    • _shiftY

      protected double _shiftY
      shift in y direction in cm (misalignment)
    • _shiftZ

      protected double _shiftZ
      shift in z direction in cm (misalignment)
    • q1Coordinate

      protected GridCoordinate q1Coordinate
      Holds the grid info for the slowest changing coordinate (as stored in the file).
    • q2Coordinate

      protected GridCoordinate q2Coordinate
      Holds the grid info for the medium changing coordinate (as stored in the file).
    • q3Coordinate

      protected GridCoordinate q3Coordinate
      Holds the grid info for the fastest changing coordinate (as stored in the file).
    • numFieldPoints

      protected int numFieldPoints
      Total number of field points.
    • _scaleFactor

      protected double _scaleFactor
      Overall scale factor
    • _interpolate

      protected static boolean _interpolate
  • Constructor Details

    • MagneticField

      public MagneticField()
  • Method Details

    • setScaleFactor

      public final void setScaleFactor(double scale)
      Scale the field.
      Parameters:
      scale - the scale factor
    • getScaleFactor

      public double getScaleFactor()
      Description copied from interface: IMagField
      Get the scale factor
      Specified by:
      getScaleFactor in interface IMagField
      Returns:
      the scale factor
    • setShiftX

      public final void setShiftX(double shiftX)
      Change the shift in the x direction
      Parameters:
      shiftX - the shift in cm
    • setShiftY

      public final void setShiftY(double shiftY)
      Change the shift in the y direction
      Parameters:
      shiftY - the shift in cm
    • setShiftZ

      public final void setShiftZ(double shiftZ)
      Change the shift in the z direction
      Parameters:
      shiftZ - the shift in cm
    • getShiftX

      public final double getShiftX()
      Get the shift in x.
      Returns:
      the x shift in cm.
    • getShiftY

      public final double getShiftY()
      Get the shift in y.
      Returns:
      the y shift in cm.
    • getShiftZ

      public final double getShiftZ()
      Get the shift in z.
      Returns:
      the z shift in cm.
    • isZeroField

      public boolean isZeroField()
      Checks whether the field has been set to always return zero.
      Specified by:
      isZeroField in interface IMagField
      Returns:
      true if the field is set to return zero.
    • setZeroField

      public final void setZeroField(boolean zeroField)
      For debugging you can set the field to always return 0.
      Parameters:
      zeroField - if set to true the field will always return 0.
    • getCreationDate

      public String getCreationDate()
      Get the creation date
      Returns:
      the creation date as a string
    • getCompositeIndex

      public final int getCompositeIndex(int n1, int n2, int n3)
      Get the composite index to take me to the correct place in the buffer.
      Parameters:
      n1 - the index in the q1 direction
      n2 - the index in the q2 direction
      n3 - the index in the q3 direction
      Returns:
      the composite index (buffer offset)
    • getCoordinateIndices

      protected final void getCoordinateIndices(int index, int[] qindices)
      Convert a composite index back to the coordinate indices
      Parameters:
      index - the composite index.
      qindices - the coordinate indices
    • getMaxFieldMagnitude

      public float getMaxFieldMagnitude()
      Obtain the maximum field magnitude of any point in the map.
      Specified by:
      getMaxFieldMagnitude in interface IMagField
      Returns:
      the maximum field magnitude in the units of the map.
    • maxFieldMagnitude

      public final int maxFieldMagnitude()
      Get the maximum field magnitude.
      Returns:
      the index of the max field magnitude.
    • computeMaxField

      protected void computeMaxField()
    • squareMagnitude

      protected final double squareMagnitude(int index)
      Get the square of magnitude for a given index.
      Parameters:
      index - the index.
      Returns:
      the square of field magnitude at the given index.
    • vectorField

      protected final void vectorField(int index, float[] vv)
      Get the vector for a given index.
      Parameters:
      index - the index.
      vv - an array of three floats to hold the result.
    • toString

      public String toString()
      Get some data as a string.
      Overrides:
      toString in class Object
      Returns:
      a string representation.
    • vectorToString

      protected String vectorToString(float[] v)
      Convert a array used as a vector to a readable string.
      Parameters:
      v - the vector (float array) to represent.
      Returns:
      a string representation of the vector (array).
    • getBaseFileName

      public String getBaseFileName()
      Get the base file name of the field map
      Returns:
      the base file name
    • readBinaryMagneticField

      public final void readBinaryMagneticField(File binaryFile) throws FileNotFoundException
      Read a magnetic field from a binary file. The file has the documented format.
      Parameters:
      binaryFile - the binary file.
      Throws:
      FileNotFoundException - the file not found exception
    • fieldMagnitude

      public final double fieldMagnitude(int index)
      Get the magnitude for a given index.
      Parameters:
      index - the index.
      Returns:
      the field magnitude at the given index.
    • getLocation

      public final void getLocation(int index, float[] r)
      Get the location at a given index
      Parameters:
      index - the composite index
      r - a vector that holds the three components of the location
    • getB1

      public final float getB1(int index)
      Get the B1 component at a given composite index.
      Specified by:
      getB1 in interface IMagField
      Parameters:
      index - the composite index.
      Returns:
      the B1 at the given composite index.
    • getB2

      public final float getB2(int index)
      Get the B2 component at a given composite index.
      Specified by:
      getB2 in interface IMagField
      Parameters:
      index - the composite index.
      Returns:
      the B2 at the given composite index.
    • getB3

      public final float getB3(int index)
      Get the B3 component at a given composite index.
      Specified by:
      getB3 in interface IMagField
      Parameters:
      index - the composite index.
      Returns:
      the B3 at the given composite index.
    • getBComponent

      public double getBComponent(int componentIndex, int compositeIndex)
      Get a component of the magnetic field
      Parameters:
      componentIndex - [1..3]
      compositeIndex -
      Returns:
      the component
    • getQ1Coordinate

      public final GridCoordinate getQ1Coordinate()
      Get the q1 coordinate.
      Returns:
      the q1 coordinate
    • getQ2Coordinate

      public final GridCoordinate getQ2Coordinate()
      Get the q2 coordinate.
      Returns:
      the q2 coordinate
    • getQ3Coordinate

      public final GridCoordinate getQ3Coordinate()
      Get the q3 coordinate.
      Returns:
      the q3 coordinate
    • setCoordinateNames

      public void setCoordinateNames(String q1name, String q2name, String q3name)
      Set the names of the coordinate grid directions.
      Parameters:
      q1name - name in the q1 direction (e.g., "x")
      q2name - name in the q2 direction (e.g., "y")
      q3name - name in the q3 direction (e.g., "z")
    • isInterpolate

      public static final boolean isInterpolate()
      Check whether we interpolate or use nearest neighbor
      Returns:
      the interpolate flag
    • setInterpolate

      public static final void setInterpolate(boolean interpolate)
      Set whether we interpolate or use nearest neighbor
      Parameters:
      interpolate - the interpolate flag to set
    • getPhiCoordinate

      public GridCoordinate getPhiCoordinate()
      Get the phi coordinate which will be q1
      Returns:
      the phi Coordinate
    • getXCoordinate

      public GridCoordinate getXCoordinate()
      Get the x coordinate which will be q1
      Returns:
      the x Coordinate
    • getRCoordinate

      public GridCoordinate getRCoordinate()
      Get the R (rho) coordinate which will be q2
      Returns:
      the r (rho) coordinate
    • getYCoordinate

      public GridCoordinate getYCoordinate()
      Get the y coordinate which will be q2
      Returns:
      the y coordinate
    • getZCoordinate

      public GridCoordinate getZCoordinate()
      Get the z coordinate which will be q3
      Returns:
      the z coordinate
    • isMisalignedX

      public boolean isMisalignedX()
      Is the map misaligned in the X direction?
      Returns:
      true if map is misaligned
    • isMisalignedY

      public boolean isMisalignedY()
      Is the map misaligned in the Y direction?
      Returns:
      true if map is misaligned
    • isMisalignedZ

      public boolean isMisalignedZ()
      Is the map misaligned in the Z direction?
      Returns:
      true if map is misaligned
    • isMisaligned

      public boolean isMisaligned()
      Is the map misaligned in any direction?
      Returns:
      true if solenoid is misaligned
    • getFakeZMax

      public double getFakeZMax()
      Get the fake z lim used to remove overlap with torus
      Returns:
      the fake z lim used to remove overlap with torus (cm)
    • setFakeZMax

      public void setFakeZMax(double zlim)
      Set the fake z lim used to remove overlap with torus
      Parameters:
      zlim - the new value in cm
    • getZMax

      public double getZMax()
    • getZMin

      public double getZMin()
    • getRhoMax

      public double getRhoMax()
    • getRhoMin

      public double getRhoMin()
    • isActive

      public abstract boolean isActive()
      Checks this field active.
      Returns:
      true if this field is active;
    • contains

      public boolean contains(double x, double y, double z)
      Checks whether the field boundary contain the given point.
      Specified by:
      contains in interface IMagField
      Parameters:
      x - the x coordinate in cm
      y - the y coordinate in cm
      z - the z coordinate in cm
      Returns:
      true if the field contains the given point