Package org.jlab.detector.geant4.v2.SVT
Class Util
java.lang.Object
org.jlab.detector.geant4.v2.SVT.Util
Geometry Utility
Universal class for a variety of useful methods.- Vector manipulation: visualisation as volume, convert between Vector3D, Matrix and double[], convert difference to axis-angle rotation
- Volume manipulation: toString for GEMC, clone, append name, promote children, shift position, scale position
- Interfacing with Matrix to use appropriate rotation conversions for standard vectors and Geant
- File I/O
- Version:
- 1.1.2
- Author:
- pdavies
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidappendChildrenName(Geant4Basic aVol, String aTag) Recursively appends the given tag to the name of the descendents of the given volume.static voidappendName(Geant4Basic aVol, String aTag) Recursively appends the given tag to the name of the given volume and its descendents.static double[]calcDistance(Vector3d p0, Vector3d p1, double u0, double u1) Calculates the distance with uncertainty between two measured points.static voidcloseOutputDataFile(String aName, Writer aFile) Closes the given file.static double[]convertRotationVectorToGeant(double theta, double phi) Converts the given spherical angles to Tait-Bryan angles suitable for Geant4Basic rotations.static MatrixconvertRotationVectorToMatrix(double theta, double phi) Converts the given spherical angles to a rotation matrix.static double[]Calculates the difference between the two given direction vectors as an axis-angle rotation.static Geant4BasiccreateArrow(String aName, double aLen, double aCapRadius, double aPointerRadius, boolean aDisplayCapStart, boolean aDisplayPointer, boolean aDisplayCapEnd) Creates a cylinder, capped with two spheres, pointing in the direction of the given vector.static Geant4BasiccreateArrow(String aName, Vector3d aVec, double aCapRadius, double aPointerRadius, boolean aDisplayCapStart, boolean aDisplayPointer, boolean aDisplayCapEnd) static Geant4BasiccreateArrow(String aName, Line3d aLine, double aCapRadius, double aPointerRadius, boolean aDisplayCapStart, boolean aDisplayPointer, boolean aDisplayCapEnd) static StringgemcStringAll(Geant4Basic aVol) Returns a string, in a format suitable for GEMC, of the given volume, including all children.static double[][]inputTaggedData(String aFilename, int recLen) Reads data from a file of the format: String, double[].static voidReplaces mother of children with mother of given volume, while preserving positions and rotations, and removes given volume from mother.static WriteropenOutputDataFile(String aName) Opens a file ready for writing.static voidscalePosition(Geant4Basic aVol, double aFactor) Recursively multiplies each position coordinate of the given volume and its children by the given scale factor.static voidshiftPosition(Geant4Basic aVol, double aShiftX, double aShiftY, double aShiftZ) Deprecated.static intsubArraySum(int[] aArray, int aIndex) Sums elements of aArray from 0 to (aIndex-1)static double[]Converts the given vector to a double[] array.static MatrixConverts the given vector to a column-based Matrix.static Vector3dtoVector3d(double[] a) Converts the given double[] array to a vector.static Vector3dtoVector3d(Matrix m) Converts the given column-based Matrix to a vector.static Vector3dtoVector3D(double[] a) Converts the given double[] array to a vector.static voidAppends the given String to the given file.
- 
Field Details- 
VERBOSEpublic static boolean VERBOSE
 
- 
- 
Constructor Details- 
Utilpublic Util()
 
- 
- 
Method Details- 
calcDistanceCalculates the distance with uncertainty between two measured points.- Parameters:
- p0- first point
- p1- second point
- u0- uncertainty in the measurement of the coordinates of the first point
- u1- uncertainty in the measurement of the coordinates of the second point
- Returns:
- double[] an array containing a {value,uncertainty} pair
 
- 
moveChildrenToMotherReplaces mother of children with mother of given volume, while preserving positions and rotations, and removes given volume from mother. Effectively promotes a given volume's children to the same rank as that volume in the tree hierarchy.- Parameters:
- aVol- volume whose children are to be moved
 
- 
appendNameRecursively appends the given tag to the name of the given volume and its descendents.- Parameters:
- aVol- volume
- aTag- string to append
 
- 
appendChildrenNameRecursively appends the given tag to the name of the descendents of the given volume.- Parameters:
- aVol- volume
- aTag- string to append
 
- 
gemcStringAllReturns a string, in a format suitable for GEMC, of the given volume, including all children.- Parameters:
- aVol- volume
- Returns:
- String multiple lines of text
 
- 
toMatrixConverts the given vector to a column-based Matrix.- Parameters:
- v- vector
- Returns:
- Matrix column-based Matrix
 
- 
toVector3dConverts the given column-based Matrix to a vector.- Parameters:
- m- matrix
- Returns:
- Vector3D vector
- Throws:
- IllegalArgumentException- matrix wrong size
 
- 
toDoubleArrayConverts the given vector to a double[] array.- Parameters:
- v- vector
- Returns:
- double[] array
 
- 
toVector3DConverts the given double[] array to a vector.- Parameters:
- a- array
- Returns:
- Vector3D vector
- Throws:
- IllegalArgumentException- array wrong size
 
- 
toVector3dConverts the given double[] array to a vector.- Parameters:
- a- array
- Returns:
- Vector3d vector
- Throws:
- IllegalArgumentException- array wrong size
 
- 
createArrowpublic static Geant4Basic createArrow(String aName, Vector3d aVec, double aCapRadius, double aPointerRadius, boolean aDisplayCapStart, boolean aDisplayPointer, boolean aDisplayCapEnd) 
- 
createArrowpublic static Geant4Basic createArrow(String aName, Line3d aLine, double aCapRadius, double aPointerRadius, boolean aDisplayCapStart, boolean aDisplayPointer, boolean aDisplayCapEnd) 
- 
createArrowpublic static Geant4Basic createArrow(String aName, double aLen, double aCapRadius, double aPointerRadius, boolean aDisplayCapStart, boolean aDisplayPointer, boolean aDisplayCapEnd) Creates a cylinder, capped with two spheres, pointing in the direction of the given vector. Length of cylinder is equal to magnitude of vector.- Parameters:
- aName- subvolumes will have _arrow# appended to aName
- aLen- length of FIXME
- aCapRadius- radius of spherical caps
- aPointerRadius- radius of cylindrical shaft
- aDisplayCapStart- switch to show start cap
- aDisplayPointer- switch to show shaft
- aDisplayCapEnd- switch to show end cap
- Returns:
- Geant4Basic pseudo volume containing arrow components
 
- 
convertRotationVectorToMatrixConverts the given spherical angles to a rotation matrix. Tait-Bryan/Euler Intrinsic ZYX/Extrinsic XYZ.- Parameters:
- theta- elevation angle in radians
- phi- azimuth angle in radians
- Returns:
- Matrix a column-based rotation matrix
 
- 
convertRotationVectorToGeantpublic static double[] convertRotationVectorToGeant(double theta, double phi) Converts the given spherical angles to Tait-Bryan angles suitable for Geant4Basic rotations. Tait-Bryan/Euler Intrinsic XYZ/Extrinsic ZYX. N.B. Geant = passive/alias, Java = active/alibi, so please negate the angles before passing to Geant4Basic.- Parameters:
- theta- elevation angle in radians
- phi- azimuth angle in radians
- Returns:
- double[] xyz angles in radians
 
- 
convertVectorDiffToAxisAngleCalculates the difference between the two given direction vectors as an axis-angle rotation. http://math.stackexchange.com/questions/293116/rotating-one-3d-vector-to-another- Parameters:
- a- vector
- b- vector
- Returns:
- double[] axis-angle rotation, format: { rx, ry, rz, ra }, angle in radians
 
- 
scalePositionRecursively multiplies each position coordinate of the given volume and its children by the given scale factor.- Parameters:
- aVol- volume
- aFactor- scale factor
 
- 
shiftPositionDeprecated.Translates the given volume's position by the given shifts.- Parameters:
- aVol- volume
- aShiftX- shift
- aShiftY- shift
- aShiftZ- shift
 
- 
subArraySumpublic static int subArraySum(int[] aArray, int aIndex) Sums elements of aArray from 0 to (aIndex-1)- Parameters:
- aArray- an array of ints
- aIndex- a terminating index
- Returns:
- int cumulative sum of elements
 
- 
inputTaggedDatapublic static double[][] inputTaggedData(String aFilename, int recLen) throws IllegalArgumentException, IOException Reads data from a file of the format: String, double[].- Parameters:
- aFilename- name of file
- recLen- number of fields to read per record
- Returns:
- double[][] array indexed as [record][field]
- Throws:
- IllegalArgumentException- null or empty filename
- IOException- incorrect record length
 
- 
openOutputDataFileOpens a file ready for writing. Terminates program if IOException occurs.- Parameters:
- aName- a file name
- Returns:
- Writer a file handle
- Throws:
- IllegalArgumentException- null or empty filename
 
- 
writeLineAppends the given String to the given file. Terminates program if IOException occurs.- Parameters:
- aWriter- file handle
- aLine- string to write
 
- 
closeOutputDataFileCloses the given file. Terminates program if IOException occurs.- Parameters:
- aName- file name
- aFile- file handle
 
 
-