Package cnuphys.magfield
Class MagneticFields
java.lang.Object
cnuphys.magfield.MagneticFields
Static support for magnetic fields
- Author:
- heddle
- 
Nested Class SummaryNested Classes
- 
Field SummaryFields
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddMagneticFieldChangeListener(MagneticFieldChangeListener magChangeListener) Add a magnetic field change listenerprotected voidchangedScale(MagneticField field) protected voidchangedShift(MagneticField field) booleanchangeFieldsAndMenus(double torusScale, double solenoidScale) This programatically adjusts everything for new scale factors.static StringdateStringLong(long longtime) Returns the time as a string.Get a description of the torus and solenoid base file namesvoidfixMenus()Make sure the menus are consistent.Get the active fieldfinal StringGet a string description of the active fieldGet the field type of the active fieldGet the composite fieldGet a specific field map.static MagneticFieldspublic access to the singletonGet the magnetic field menugetMagneticFieldMenu(boolean incRotatedField, boolean includeTestFields) Get the magnetic field menuGet the rotated composite fielddoubleGet the scale factor got the field type.static intgetSector(double phi) Get the sector [1..6] from the phi valuestatic intgetSector(double labX, double labY) Get the sector [1..6] from the lab x and y coordinatesdoubleGet 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 packagebooleanCheck whether we have an active solenoid fieldbooleanCheck whether we have an active torus fieldvoidTries to load the magnetic fields from fieldmapsvoidinitializeMagneticFields(String dataDir, String torusName, String solenoidName) Initialize the magnetic field packagevoidinitializeMagneticFields(String dataDir, String torusName, String solenoidName, String transverseSolenoidName) Deprecated.voidAttempts to initialize the magnetic fields using the property or environment variables TORUSMAP and SOLENOIDMAP as full paths to the torus and solenoidvoidinitializeMagneticFieldsFromPath(String torusPath, String solenoidPath) Initialize the field from the two full paths.booleanIs the active field compositebooleanisProbeOrCompositeProbe(IField field) Is this a probe or a composite probe?booleanIs the active field solenoid onlybooleanIs the active field torus onlystatic voidlabToSector(int sector, float[] sect, float x, float y, float z) Converts the clas (lab) 3D coordinates to sector 3D coordinates tostatic voidFor testing and also as an exampledoubleGet the maximum value of the active field in kGprotected voidNotify all listeners that a change has occurred in the magnetic fieldsprotected voidOpen a new torus map from the file selectorprotected voidopenNewTorus(String path) Open a new torus map from a full pathprotected voidopenSolenoid(File file, boolean isTransverse) Open a new solenoid map from a filevoidPrint a one line version of the magnetic field configurationvoidremoveMagneticFieldChangeListener(MagneticFieldChangeListener magChangeListener) Remove a MagneticFieldChangeListener.voidRemoves the overlap between the solenoid and the torus.static voidsectorToLab(int sector, float[] lab, float x, float y, float z) Converts the sector 3D coordinates to clas (lab) 3D coordinatesvoidsetActiveField(IMagField field) Sets the active fieldvoidSets the active fieldvoidsetSolenoid(Solenoid solenoid) In case someone loads a solenoid externally.voidsetSolenoidShift(double shiftZ) Shift the solenoid along Z for misplacement.voidIn case someone loads a torus externally.voidshiftMagneticField(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 voidwriteHeader(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- 
getVersionGet the version of the magfield package- Returns:
- the version of the magfield package
 
- 
getInstancepublic access to the singleton- Returns:
- the MagneticFields singleton
 
- 
openNewTorusprotected void openNewTorus()Open a new torus map from the file selector
- 
openNewTorusOpen a new torus map from a full path- Parameters:
- path- the path to the torus map
- Throws:
- FileNotFoundException
 
- 
openSolenoidOpen a new solenoid map from a file- Parameters:
- file- the file holding the solenoid map
- Throws:
- FileNotFoundException
 
- 
setSolenoidShiftpublic 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
 
- 
shiftMagneticFieldShift the magnetic field (i.e., a misalignment)- Parameters:
- field- the field, either _solenoid or torus
- shiftX- the X shift in cm
- shiftY- the Y shift in cm
- shiftZ- the Z shift in cm A negative shift moved the field upstream.
 
- 
changeFieldsAndMenuspublic 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 factor
- solenoidScale- the solenoid scale factor
 
- 
getActiveFieldTypeGet the field type of the active field- Returns:
- the field type of the active field
 
- 
isSolenoidOnlypublic boolean isSolenoidOnly()Is the active field solenoid only- Returns:
- trueof the active field is solenoid only
 
- 
isTorusOnlypublic boolean isTorusOnly()Is the active field torus only- Returns:
- trueof the active field is torus only
 
- 
isCompositeFieldpublic boolean isCompositeField()Is the active field composite- Returns:
- trueof the active field is solenoid and torus composite
 
- 
setActiveFieldSets the active field- Parameters:
- field- the new active field
 
- 
setActiveFieldSets the active field- Parameters:
- ftype- one of the enum values
 
- 
getActiveFieldDescriptionGet a string description of the active field- Returns:
- a string description of the active field
 
- 
getActiveFieldGet the active field- Returns:
- the active field
 
- 
getIFieldGet a specific field map.- Parameters:
- ftype- the field map to get
- Returns:
- the field map, which might be null.
 
- 
getScaleFactorGet the scale factor got the field type.- Parameters:
- ftype- the field type
- Returns:
- the scale factor got the field type. Composite fields return NaN.
 
- 
getShiftZGet 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.
 
- 
setSolenoidIn case someone loads a solenoid externally.- Parameters:
- solenoid-
 
- 
setTorusIn case someone loads a torus externally.- Parameters:
- torus-
 
- 
tokensThis method breaks a string into an array of tokens.- Parameters:
- str- the string to decompose.
- delimiter- the delimiter
- Returns:
- an array of tokens
 
- 
initializeMagneticFieldsFromEnvpublic 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.
 
- 
initializeMagneticFieldspublic 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 solenoid
- torusName- the base name of the torus map
- solenoidName- the base name of the solenoid map
- Throws:
- FileNotFoundException- if either full path is not null but the corresponding file cannot be found
- MagneticFieldInitializationException- if both full paths are null. Will proceed as long as one path is not null.
 
- 
initializeMagneticFieldspublic 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 solenoid
- torusName- the base name of the torus map
- solenoidName- the base name of the solenoid map
- Throws:
- FileNotFoundException- if either full path is not null but the corresponding file cannot be found
- MagneticFieldInitializationException- if both full paths are null. Will proceed as long as one path is not null.
 
- 
initializeMagneticFieldsFromPathpublic 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
 
- 
initializeMagneticFieldspublic void initializeMagneticFields()Tries to load the magnetic fields from fieldmaps
- 
getMagneticFieldMenuGet the magnetic field menu- Returns:
- the magnetic field menu
 
- 
getMagneticFieldMenuGet the magnetic field menu- Returns:
- the magnetic field menu
 
- 
fixMenuspublic void fixMenus()Make sure the menus are consistent.
- 
changedScale
- 
changedShift
- 
notifyListenersprotected void notifyListeners()Notify all listeners that a change has occurred in the magnetic fields
- 
addMagneticFieldChangeListenerAdd a magnetic field change listener- Parameters:
- magChangeListener- the listener to add
 
- 
removeMagneticFieldChangeListenerRemove a MagneticFieldChangeListener.- Parameters:
- magChangeListener- the MagneticFieldChangeListener to remove.
 
- 
removeMapOverlappublic 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.
- 
hasActiveToruspublic boolean hasActiveTorus()Check whether we have an active torus field- Returns:
- trueif we have a torus
 
- 
hasActiveSolenoidpublic boolean hasActiveSolenoid()Check whether we have an active solenoid field- Returns:
- trueif we have a solenoid
 
- 
getTorusGet the torus field- Returns:
- the torus field
 
- 
getSolenoidGet the solenoid field- Returns:
- the solenoid field
 
- 
getCompositeFieldGet the composite field- Returns:
- the composite field
 
- 
getRotatedCompositeFieldGet the rotated composite field- Returns:
- the rotated composite field
 
- 
getTorusPathGet the full torus path- Returns:
- the full torus path
 
- 
getSolenoidPathGet the full solenoid path- Returns:
- the full solenoid path
 
- 
getTorusBaseNameGet the torus file base name- Returns:
- the torus file base name
 
- 
sectorToLabpublic 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 coordinate
- y- the sector y coordinate
- z- the sector z coordinate
 
- 
labToSectorpublic 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 coordinate
- y- the lab y coordinate
- z- the lab z coordinate
 
- 
getSectorpublic static int getSector(double labX, double labY) Get the sector [1..6] from the lab x and y coordinates- Parameters:
- labX- the lab x
- labY- the lab y
- Returns:
- the sector [1..6]
 
- 
getSectorpublic 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]
 
- 
getSolenoidBaseNameGet the solenoid file base name- Returns:
- the solenoid file base name
 
- 
fileBaseNamesGet a description of the torus and solenoid base file names- Returns:
- the torus and solenoid base file names
 
- 
dateStringLongReturns the time as a string.- Parameters:
- longtime- the time in millis.
- Returns:
- a string representation of the current time, down to seconds.
 
- 
isProbeOrCompositeProbeIs this a probe or a composite probe?- Parameters:
- field- the object to test
- Returns:
- t
 
- 
maxFieldMagnitudepublic double maxFieldMagnitude()Get the maximum value of the active field in kG- Returns:
- the maximum value of the active field in kG
 
- 
mainFor testing and also as an example- Parameters:
- arg- command line arguments
 
- 
getCurrentConfiguration
- 
getCurrentConfigurationMultiLine
- 
writeHeaderpublic 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 stream
- gridCS- 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 min
- q1Max- first coordinate max
- nq1- first coordinate num grid points including ends
- q2Min- second coordinate min
- q2Max- second coordinate max
- nq2- second coordinate num grid points including ends
- q3Min- third coordinate min
- q3Max- third coordinate max
- nq3- third coordinate num grid points including ends
 
- 
printCurrentConfigurationPrint a one line version of the magnetic field configuration- Parameters:
- ps- the print stream
 
 
-