Class MagneticField
java.lang.Object
cnuphys.magfield.MagneticField
- All Implemented Interfaces:
IMagField
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static booleanprotected doubleOverall scale factorprotected doubleshift in x direction in cm (misalignment)protected doubleshift in y direction in cm (misalignment)protected doubleshift in z direction in cm (misalignment)protected AngularUnitThe angular unit.protected floatThe average magnitude of the field.protected FloatBufferholds the field in a float buffer.protected CoordinateSystemThe field coordinate system.protected FieldUnitThe field unit.protected CoordinateSystemThe grid coordinate system.protected inthigh word of unix creation timeprotected LengthUnitThe length unit.static Loggerprotected intlow word of unix creation timestatic final intMagic number used to check if byteswapping is necessary.protected floatThe maximum magnitude of the field.protected intIndex where max field magnitude residesprotected final float[]The location of the maximum field.protected final float[]The max vector field.static final doublemisalignment toleranceprotected intTotal number of field points.protected GridCoordinateHolds the grid info for the slowest changing coordinate (as stored in the file).protected GridCoordinateHolds the grid info for the medium changing coordinate (as stored in the file).protected GridCoordinateHolds the grid info for the fastest changing coordinate (as stored in the file).protected intreserved wordprotected intreserved wordprotected intreserved word -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbooleancontains(double x, double y, double z) Checks whether the field boundary contain the given point.final doublefieldMagnitude(int index) Get the magnitude for a given index.final floatgetB1(int index) Get the B1 component at a given composite index.final floatgetB2(int index) Get the B2 component at a given composite index.final floatgetB3(int index) Get the B3 component at a given composite index.Get the base file name of the field mapdoublegetBComponent(int componentIndex, int compositeIndex) Get a component of the magnetic fieldfinal intgetCompositeIndex(int n1, int n2, int n3) Get the composite index to take me to the correct place in the buffer.protected final voidgetCoordinateIndices(int index, int[] qindices) Convert a composite index back to the coordinate indicesGet the creation datedoubleGet the fake z lim used to remove overlap with torusfinal voidgetLocation(int index, float[] r) Get the location at a given indexfloatObtain the maximum field magnitude of any point in the map.Get the phi coordinate which will be q1final GridCoordinateGet the q1 coordinate.final GridCoordinateGet the q2 coordinate.final GridCoordinateGet the q3 coordinate.Get the R (rho) coordinate which will be q2doubledoubledoubleGet the scale factorfinal doubleGet the shift in x.final doubleGet the shift in y.final doubleGet 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 q3doublegetZMax()doublegetZMin()abstract booleanisActive()Checks this field active.static final booleanCheck whether we interpolate or use nearest neighborbooleanIs the map misaligned in any direction?booleanIs the map misaligned in the X direction?booleanIs the map misaligned in the Y direction?booleanIs the map misaligned in the Z direction?booleanChecks whether the field has been set to always return zero.final intGet the maximum field magnitude.final voidreadBinaryMagneticField(File binaryFile) Read a magnetic field from a binary file.voidsetCoordinateNames(String q1name, String q2name, String q3name) Set the names of the coordinate grid directions.voidsetFakeZMax(double zlim) Set the fake z lim used to remove overlap with torusstatic final voidsetInterpolate(boolean interpolate) Set whether we interpolate or use nearest neighborfinal voidsetScaleFactor(double scale) Scale the field.final voidsetShiftX(double shiftX) Change the shift in the x directionfinal voidsetShiftY(double shiftY) Change the shift in the y directionfinal voidsetShiftZ(double shiftZ) Change the shift in the z directionfinal voidsetZeroField(boolean zeroField) For debugging you can set the field to always return 0.protected final doublesquareMagnitude(int index) Get the square of magnitude for a given index.toString()Get some data as a string.protected final voidvectorField(int index, float[] vv) Get the vector for a given index.protected StringvectorToString(float[] v) Convert a array used as a vector to a readable string.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface 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:IMagFieldGet the scale factor- Specified by:
getScaleFactorin 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:
isZeroFieldin interfaceIMagField- Returns:
trueif 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 totruethe field will always return 0.
-
getCreationDate
-
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:
getMaxFieldMagnitudein 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
-
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
-
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
-
getB2
-
getB3
-
getBComponent
public double getBComponent(int componentIndex, int compositeIndex) Get a component of the magnetic field- Parameters:
componentIndex- [1..3]compositeIndex-- Returns:
- the component
-
getQ1Coordinate
-
getQ2Coordinate
-
getQ3Coordinate
-
setCoordinateNames
-
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:
trueif map is misaligned
-
isMisalignedY
public boolean isMisalignedY()Is the map misaligned in the Y direction?- Returns:
trueif map is misaligned
-
isMisalignedZ
public boolean isMisalignedZ()Is the map misaligned in the Z direction?- Returns:
trueif map is misaligned
-
isMisaligned
public boolean isMisaligned()Is the map misaligned in any direction?- Returns:
trueif 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:
trueif this field is active;
-
contains
public boolean contains(double x, double y, double z) Checks whether the field boundary contain the given point.
-