Package cnuphys.magfield
Class MagneticFields
java.lang.Object
cnuphys.magfield.MagneticFields
Static support for magnetic fields
- Author:
- heddle
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMagneticFieldChangeListener
(MagneticFieldChangeListener magChangeListener) Add a magnetic field change listenerprotected void
changedScale
(MagneticField field) protected void
changedShift
(MagneticField field) boolean
changeFieldsAndMenus
(double torusScale, double solenoidScale) This programatically adjusts everything for new scale factors.static String
dateStringLong
(long longtime) Returns the time as a string.Get a description of the torus and solenoid base file namesvoid
fixMenus()
Make sure the menus are consistent.Get the active fieldfinal String
Get a string description of the active fieldGet the field type of the active fieldGet the composite fieldGet a specific field map.static MagneticFields
public access to the singletonGet the magnetic field menugetMagneticFieldMenu
(boolean incRotatedField, boolean includeTestFields) Get the magnetic field menuGet the rotated composite fielddouble
Get the scale factor got the field type.static int
getSector
(double phi) Get the sector [1..6] from the phi valuestatic int
getSector
(double labX, double labY) Get the sector [1..6] from the lab x and y coordinatesdouble
Get the shift Z given the field type.Get the solenoid fieldGet the solenoid file base nameGet the full solenoid pathgetTorus()
Get the torus fieldGet the torus file base nameGet the full torus pathGet the version of the magfield packageboolean
Check whether we have an active solenoid fieldboolean
Check whether we have an active torus fieldvoid
Tries to load the magnetic fields from fieldmapsvoid
initializeMagneticFields
(String dataDir, String torusName, String solenoidName) Initialize the magnetic field packagevoid
initializeMagneticFields
(String dataDir, String torusName, String solenoidName, String transverseSolenoidName) Deprecated.void
Attempts to initialize the magnetic fields using the property or environment variables TORUSMAP and SOLENOIDMAP as full paths to the torus and solenoidvoid
initializeMagneticFieldsFromPath
(String torusPath, String solenoidPath) Initialize the field from the two full paths.boolean
Is the active field compositeboolean
isProbeOrCompositeProbe
(IField field) Is this a probe or a composite probe?boolean
Is the active field solenoid onlyboolean
Is the active field torus onlystatic void
labToSector
(int sector, float[] sect, float x, float y, float z) Converts the clas (lab) 3D coordinates to sector 3D coordinates tostatic void
For testing and also as an exampledouble
Get the maximum value of the active field in kGprotected void
Notify all listeners that a change has occurred in the magnetic fieldsprotected void
Open a new torus map from the file selectorprotected void
openNewTorus
(String path) Open a new torus map from a full pathprotected void
openSolenoid
(File file, boolean isTransverse) Open a new solenoid map from a filevoid
Print a one line version of the magnetic field configurationvoid
removeMagneticFieldChangeListener
(MagneticFieldChangeListener magChangeListener) Remove a MagneticFieldChangeListener.void
Removes the overlap between the solenoid and the torus.static void
sectorToLab
(int sector, float[] lab, float x, float y, float z) Converts the sector 3D coordinates to clas (lab) 3D coordinatesvoid
setActiveField
(IMagField field) Sets the active fieldvoid
Sets the active fieldvoid
setSolenoid
(Solenoid solenoid) In case someone loads a solenoid externally.void
setSolenoidShift
(double shiftZ) Shift the solenoid along Z for misplacement.void
In case someone loads a torus externally.void
shiftMagneticField
(MagneticField field, double shiftX, double shiftY, double shiftZ) Shift the magnetic field (i.e., a misalignment)static String[]
This method breaks a string into an array of tokens.static void
writeHeader
(DataOutputStream dos, int gridCS, int fieldCS, int lenUnit, int angUnit, int fieldUnit, float q1Min, float q1Max, int nq1, float q2Min, float q2Max, int nq2, float q3Min, float q3Max, int nq3) Write the binary file header
-
Field Details
-
LOGGER
-
-
Method Details
-
getVersion
Get the version of the magfield package- Returns:
- the version of the magfield package
-
getInstance
public access to the singleton- Returns:
- the MagneticFields singleton
-
openNewTorus
protected void openNewTorus()Open a new torus map from the file selector -
openNewTorus
Open a new torus map from a full path- Parameters:
path
- the path to the torus map- Throws:
FileNotFoundException
-
openSolenoid
Open a new solenoid map from a file- Parameters:
file
- the file holding the solenoid map- Throws:
FileNotFoundException
-
setSolenoidShift
public void setSolenoidShift(double shiftZ) Shift the solenoid along Z for misplacement. A negative shift moved the solenoid upstream. Kept for backwards compatibility- Parameters:
shiftZ
- the shift in cm
-
shiftMagneticField
Shift the magnetic field (i.e., a misalignment)- Parameters:
field
- the field, either _solenoid or torusshiftX
- the X shift in cmshiftY
- the Y shift in cmshiftZ
- the Z shift in cm A negative shift moved the field upstream.
-
changeFieldsAndMenus
public boolean changeFieldsAndMenus(double torusScale, double solenoidScale) This programatically adjusts everything for new scale factors. This is used when data found in the file- Parameters:
torusScale
- the torus scale factorsolenoidScale
- the solenoid scale factor
-
getActiveFieldType
Get the field type of the active field- Returns:
- the field type of the active field
-
isSolenoidOnly
public boolean isSolenoidOnly()Is the active field solenoid only- Returns:
true
of the active field is solenoid only
-
isTorusOnly
public boolean isTorusOnly()Is the active field torus only- Returns:
true
of the active field is torus only
-
isCompositeField
public boolean isCompositeField()Is the active field composite- Returns:
true
of the active field is solenoid and torus composite
-
setActiveField
Sets the active field- Parameters:
field
- the new active field
-
setActiveField
Sets the active field- Parameters:
ftype
- one of the enum values
-
getActiveFieldDescription
Get a string description of the active field- Returns:
- a string description of the active field
-
getActiveField
Get the active field- Returns:
- the active field
-
getIField
Get a specific field map.- Parameters:
ftype
- the field map to get- Returns:
- the field map, which might be
null
.
-
getScaleFactor
Get the scale factor got the field type.- Parameters:
ftype
- the field type- Returns:
- the scale factor got the field type. Composite fields return NaN.
-
getShiftZ
Get the shift Z given the field type.- Parameters:
ftype
- the field type- Returns:
- the shift in z (cm) for the field type. Composite fields return NaN.
-
setSolenoid
In case someone loads a solenoid externally.- Parameters:
solenoid
-
-
setTorus
In case someone loads a torus externally.- Parameters:
torus
-
-
tokens
This method breaks a string into an array of tokens.- Parameters:
str
- the string to decompose.delimiter
- the delimiter- Returns:
- an array of tokens
-
initializeMagneticFieldsFromEnv
public void initializeMagneticFieldsFromEnv() throws MagneticFieldInitializationException, FileNotFoundExceptionAttempts to initialize the magnetic fields using the property or environment variables TORUSMAP and SOLENOIDMAP as full paths to the torus and solenoid- Throws:
MagneticFieldInitializationException
- if neither environment variable is not found. Will proceed if just one is found.FileNotFoundException
- if neither file is not found. Will proceed if just one is found.
-
initializeMagneticFields
public void initializeMagneticFields(String dataDir, String torusName, String solenoidName) throws FileNotFoundException, MagneticFieldInitializationException Initialize the magnetic field package- Parameters:
dataDir
- the common data directory containing the torus and solenoidtorusName
- the base name of the torus mapsolenoidName
- the base name of the solenoid map- Throws:
FileNotFoundException
- if either full path is not null but the corresponding file cannot be foundMagneticFieldInitializationException
- if both full paths are null. Will proceed as long as one path is not null.
-
initializeMagneticFields
public void initializeMagneticFields(String dataDir, String torusName, String solenoidName, String transverseSolenoidName) throws FileNotFoundException, MagneticFieldInitializationException Deprecated.Initialize the magnetic field package- Parameters:
dataDir
- the common data directory containing the torus and solenoidtorusName
- the base name of the torus mapsolenoidName
- the base name of the solenoid map- Throws:
FileNotFoundException
- if either full path is not null but the corresponding file cannot be foundMagneticFieldInitializationException
- if both full paths are null. Will proceed as long as one path is not null.
-
initializeMagneticFieldsFromPath
public void initializeMagneticFieldsFromPath(String torusPath, String solenoidPath) throws MagneticFieldInitializationException, FileNotFoundException Initialize the field from the two full paths. One of them can be null.- Parameters:
torusPath
- the full path to the torus map. Can be null.solenoidPath
- the full path to the solenoid map. Can be null.- Throws:
MagneticFieldInitializationException
- if both paths are null. Will proceed as long as one path is not null.FileNotFoundException
- if either path is not null but the corresponding file cannot be found
-
initializeMagneticFields
public void initializeMagneticFields()Tries to load the magnetic fields from fieldmaps -
getMagneticFieldMenu
Get the magnetic field menu- Returns:
- the magnetic field menu
-
getMagneticFieldMenu
Get the magnetic field menu- Returns:
- the magnetic field menu
-
fixMenus
public void fixMenus()Make sure the menus are consistent. -
changedScale
-
changedShift
-
notifyListeners
protected void notifyListeners()Notify all listeners that a change has occurred in the magnetic fields -
addMagneticFieldChangeListener
Add a magnetic field change listener- Parameters:
magChangeListener
- the listener to add
-
removeMagneticFieldChangeListener
Remove a MagneticFieldChangeListener.- Parameters:
magChangeListener
- the MagneticFieldChangeListener to remove.
-
removeMapOverlap
public void removeMapOverlap()Removes the overlap between the solenoid and the torus. It does this by Adding the solenoid field to the torus field cutting of the solenoid in the overlap region, then cut off the solenoid at the min Z of the torus. This is an experimental method and irreversible. In particular rescaling the torus after doing this will cause the solenoid part of the overlap area to be scaled too. Which is nonsense. -
hasActiveTorus
public boolean hasActiveTorus()Check whether we have an active torus field- Returns:
true
if we have a torus
-
hasActiveSolenoid
public boolean hasActiveSolenoid()Check whether we have an active solenoid field- Returns:
true
if we have a solenoid
-
getTorus
Get the torus field- Returns:
- the torus field
-
getSolenoid
Get the solenoid field- Returns:
- the solenoid field
-
getCompositeField
Get the composite field- Returns:
- the composite field
-
getRotatedCompositeField
Get the rotated composite field- Returns:
- the rotated composite field
-
getTorusPath
Get the full torus path- Returns:
- the full torus path
-
getSolenoidPath
Get the full solenoid path- Returns:
- the full solenoid path
-
getTorusBaseName
Get the torus file base name- Returns:
- the torus file base name
-
sectorToLab
public static void sectorToLab(int sector, float[] lab, float x, float y, float z) Converts the sector 3D coordinates to clas (lab) 3D coordinates- Parameters:
sector
- the 1-based sector [1..6]lab
- will hold the lab 3D Cartesian coordinates (modified)x
- the sector x coordinatey
- the sector y coordinatez
- the sector z coordinate
-
labToSector
public static void labToSector(int sector, float[] sect, float x, float y, float z) Converts the clas (lab) 3D coordinates to sector 3D coordinates to- Parameters:
sector
- the 1-based sector [1..6]lab
- will hold the lab 3D Cartesian coordinates (modified)x
- the lab x coordinatey
- the lab y coordinatez
- the lab z coordinate
-
getSector
public static int getSector(double labX, double labY) Get the sector [1..6] from the lab x and y coordinates- Parameters:
labX
- the lab xlabY
- the lab y- Returns:
- the sector [1..6]
-
getSector
public static int getSector(double phi) Get the sector [1..6] from the phi value- Parameters:
phi
- the value of phi in degrees- Returns:
- the sector [1..6]
-
getSolenoidBaseName
Get the solenoid file base name- Returns:
- the solenoid file base name
-
fileBaseNames
Get a description of the torus and solenoid base file names- Returns:
- the torus and solenoid base file names
-
dateStringLong
Returns the time as a string.- Parameters:
longtime
- the time in millis.- Returns:
- a string representation of the current time, down to seconds.
-
isProbeOrCompositeProbe
Is this a probe or a composite probe?- Parameters:
field
- the object to test- Returns:
t
-
maxFieldMagnitude
public double maxFieldMagnitude()Get the maximum value of the active field in kG- Returns:
- the maximum value of the active field in kG
-
main
For testing and also as an example- Parameters:
arg
- command line arguments
-
getCurrentConfiguration
-
getCurrentConfigurationMultiLine
-
writeHeader
public static void writeHeader(DataOutputStream dos, int gridCS, int fieldCS, int lenUnit, int angUnit, int fieldUnit, float q1Min, float q1Max, int nq1, float q2Min, float q2Max, int nq2, float q3Min, float q3Max, int nq3) Write the binary file header- Parameters:
dos
- the output streamgridCS
- grid coordinate system [0: cylindrical, 1:Cartesian]fieldCS
- field coordinate system [0: cylindrical, 1:Cartesian]lenUnit
- length units [0:cm, 1:m]angUnit
- angular units [0:deg, 1:radians]fieldUnit
- field units [0:kG, 1:T]q1Min
- first coordinate minq1Max
- first coordinate maxnq1
- first coordinate num grid points including endsq2Min
- second coordinate minq2Max
- second coordinate maxnq2
- second coordinate num grid points including endsq3Min
- third coordinate minq3Max
- third coordinate maxnq3
- third coordinate num grid points including ends
-
printCurrentConfiguration
Print a one line version of the magnetic field configuration- Parameters:
ps
- the print stream
-