Package cnuphys.magfield
Class MagneticField
java.lang.Object
cnuphys.magfield.MagneticField
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprotected static boolean
protected double
Overall scale factorprotected double
shift in x direction in cm (misalignment)protected double
shift in y direction in cm (misalignment)protected double
shift in z direction in cm (misalignment)protected AngularUnit
The angular unit.protected float
The average magnitude of the field.protected FloatBuffer
holds the field in a float buffer.protected CoordinateSystem
The field coordinate system.protected FieldUnit
The field unit.protected CoordinateSystem
The grid coordinate system.protected int
high word of unix creation timeprotected LengthUnit
The length unit.static Logger
protected int
low word of unix creation timestatic final int
Magic number used to check if byteswapping is necessary.protected float
The maximum magnitude of the field.protected int
Index where max field magnitude residesprotected final float[]
The location of the maximum field.protected final float[]
The max vector field.static final double
misalignment toleranceprotected int
Total number of field points.protected GridCoordinate
Holds the grid info for the slowest changing coordinate (as stored in the file).protected GridCoordinate
Holds the grid info for the medium changing coordinate (as stored in the file).protected GridCoordinate
Holds the grid info for the fastest changing coordinate (as stored in the file).protected int
reserved wordprotected int
reserved wordprotected int
reserved word -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
boolean
contains
(double x, double y, double z) Checks whether the field boundary contain the given point.final double
fieldMagnitude
(int index) Get the magnitude for a given index.final float
getB1
(int index) Get the B1 component at a given composite index.final float
getB2
(int index) Get the B2 component at a given composite index.final float
getB3
(int index) Get the B3 component at a given composite index.Get the base file name of the field mapdouble
getBComponent
(int componentIndex, int compositeIndex) Get a component of the magnetic fieldfinal int
getCompositeIndex
(int n1, int n2, int n3) Get the composite index to take me to the correct place in the buffer.protected final void
getCoordinateIndices
(int index, int[] qindices) Convert a composite index back to the coordinate indicesGet the creation datedouble
Get the fake z lim used to remove overlap with torusfinal void
getLocation
(int index, float[] r) Get the location at a given indexfloat
Obtain the maximum field magnitude of any point in the map.Get the phi coordinate which will be q1final GridCoordinate
Get the q1 coordinate.final GridCoordinate
Get the q2 coordinate.final GridCoordinate
Get the q3 coordinate.Get the R (rho) coordinate which will be q2double
double
double
Get the scale factorfinal double
Get the shift in x.final double
Get the shift in y.final double
Get the shift in z.Get the x coordinate which will be q1Get the y coordinate which will be q2Get the z coordinate which will be q3double
getZMax()
double
getZMin()
abstract boolean
isActive()
Checks this field active.static final boolean
Check whether we interpolate or use nearest neighborboolean
Is the map misaligned in any direction?boolean
Is the map misaligned in the X direction?boolean
Is the map misaligned in the Y direction?boolean
Is the map misaligned in the Z direction?boolean
Checks whether the field has been set to always return zero.final int
Get the maximum field magnitude.final void
readBinaryMagneticField
(File binaryFile) Read a magnetic field from a binary file.void
setCoordinateNames
(String q1name, String q2name, String q3name) Set the names of the coordinate grid directions.void
setFakeZMax
(double zlim) Set the fake z lim used to remove overlap with torusstatic final void
setInterpolate
(boolean interpolate) Set whether we interpolate or use nearest neighborfinal void
setScaleFactor
(double scale) Scale the field.final void
setShiftX
(double shiftX) Change the shift in the x directionfinal void
setShiftY
(double shiftY) Change the shift in the y directionfinal void
setShiftZ
(double shiftZ) Change the shift in the z directionfinal void
setZeroField
(boolean zeroField) For debugging you can set the field to always return 0.protected final double
squareMagnitude
(int index) Get the square of magnitude for a given index.toString()
Get some data as a string.protected final void
vectorField
(int index, float[] vv) Get the vector for a given index.protected String
vectorToString
(float[] v) Convert a array used as a vector to a readable string.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface cnuphys.magfield.IMagField
getName, printConfiguration
-
Field Details
-
LOGGER
-
MAGICNUMBER
public static final int MAGICNUMBERMagic number used to check if byteswapping is necessary.- See Also:
-
MISALIGNTOL
public static final double MISALIGNTOLmisalignment tolerance- See Also:
-
maxFieldIndex
protected int maxFieldIndexIndex where max field magnitude resides -
maxField
protected float maxFieldThe maximum magnitude of the field. -
maxVectorField
protected final float[] maxVectorFieldThe max vector field. -
maxFieldLocation
protected final float[] maxFieldLocationThe location of the maximum field. -
avgField
protected float avgFieldThe average magnitude of the field. -
gridCoordinateSystem
The grid coordinate system. -
fieldCoordinateSystem
The field coordinate system. -
lengthUnit
The length unit. -
angularUnit
The angular unit. -
fieldUnit
The field unit. -
field
holds the field in a float buffer. -
highTime
protected int highTimehigh word of unix creation time -
lowTime
protected int lowTimelow word of unix creation time -
reserved3
protected int reserved3reserved word -
reserved4
protected int reserved4reserved word -
reserved5
protected int reserved5reserved word -
_shiftX
protected double _shiftXshift in x direction in cm (misalignment) -
_shiftY
protected double _shiftYshift in y direction in cm (misalignment) -
_shiftZ
protected double _shiftZshift in z direction in cm (misalignment) -
q1Coordinate
Holds the grid info for the slowest changing coordinate (as stored in the file). -
q2Coordinate
Holds the grid info for the medium changing coordinate (as stored in the file). -
q3Coordinate
Holds the grid info for the fastest changing coordinate (as stored in the file). -
numFieldPoints
protected int numFieldPointsTotal number of field points. -
_scaleFactor
protected double _scaleFactorOverall 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 interfaceIMagField
- 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 interfaceIMagField
- 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 totrue
the field will always return 0.
-
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 directionn2
- the index in the q2 directionn3
- 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 interfaceIMagField
- 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
Get some data as a string. -
vectorToString
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
Get the base file name of the field map- Returns:
- the base file name
-
readBinaryMagneticField
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 indexr
- 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. -
getB2
public final float getB2(int index) Get the B2 component at a given composite index. -
getB3
public final float getB3(int index) Get the B3 component at a 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
Get the q1 coordinate.- Returns:
- the q1 coordinate
-
getQ2Coordinate
Get the q2 coordinate.- Returns:
- the q2 coordinate
-
getQ3Coordinate
Get the q3 coordinate.- Returns:
- the q3 coordinate
-
setCoordinateNames
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
Get the phi coordinate which will be q1- Returns:
- the phi Coordinate
-
getXCoordinate
Get the x coordinate which will be q1- Returns:
- the x Coordinate
-
getRCoordinate
Get the R (rho) coordinate which will be q2- Returns:
- the r (rho) coordinate
-
getYCoordinate
Get the y coordinate which will be q2- Returns:
- the y coordinate
-
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.
-