Class Util

java.lang.Object
org.jlab.detector.geant4.v2.SVT.Util

public class Util extends Object

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 Summary

    Fields
    Modifier and Type
    Field
    Description
    static boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Recursively appends the given tag to the name of the descendents of the given volume.
    static void
    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 void
    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 Matrix
    convertRotationVectorToMatrix(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. http://math.stackexchange.com/questions/293116/rotating-one-3d-vector-to-another
    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.
    createArrow(String aName, Vector3d aVec, double aCapRadius, double aPointerRadius, boolean aDisplayCapStart, boolean aDisplayPointer, boolean aDisplayCapEnd)
     
    createArrow(String aName, Line3d aLine, double aCapRadius, double aPointerRadius, boolean aDisplayCapStart, boolean aDisplayPointer, boolean aDisplayCapEnd)
     
    static String
    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 void
    Replaces mother of children with mother of given volume, while preserving positions and rotations, and removes given volume from mother.
    static Writer
    Opens a file ready for writing.
    static void
    scalePosition(Geant4Basic aVol, double aFactor)
    Recursively multiplies each position coordinate of the given volume and its children by the given scale factor.
    static void
    shiftPosition(Geant4Basic aVol, double aShiftX, double aShiftY, double aShiftZ)
    Deprecated.
    static int
    subArraySum(int[] aArray, int aIndex)
    Sums elements of aArray from 0 to (aIndex-1)
    static double[]
    Converts the given vector to a double[] array.
    static Matrix
    Converts the given vector to a column-based Matrix.
    static Vector3d
    toVector3d(double[] a)
    Converts the given double[] array to a vector.
    static Vector3d
    Converts the given column-based Matrix to a vector.
    static Vector3d
    toVector3D(double[] a)
    Converts the given double[] array to a vector.
    static void
    writeLine(Writer aWriter, String aLine)
    Appends the given String to the given file.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • VERBOSE

      public static boolean VERBOSE
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • calcDistance

      public static double[] calcDistance(Vector3d p0, Vector3d p1, double u0, double u1)
      Calculates 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
    • moveChildrenToMother

      public static void moveChildrenToMother(Geant4Basic aVol)
      Replaces 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
    • appendName

      public static void appendName(Geant4Basic aVol, String aTag)
      Recursively appends the given tag to the name of the given volume and its descendents.
      Parameters:
      aVol - volume
      aTag - string to append
    • appendChildrenName

      public static void appendChildrenName(Geant4Basic aVol, String aTag)
      Recursively appends the given tag to the name of the descendents of the given volume.
      Parameters:
      aVol - volume
      aTag - string to append
    • gemcStringAll

      public static String gemcStringAll(Geant4Basic aVol)
      Returns a string, in a format suitable for GEMC, of the given volume, including all children.
      Parameters:
      aVol - volume
      Returns:
      String multiple lines of text
    • toMatrix

      public static Matrix toMatrix(Vector3d v)
      Converts the given vector to a column-based Matrix.
      Parameters:
      v - vector
      Returns:
      Matrix column-based Matrix
    • toVector3d

      public static Vector3d toVector3d(Matrix m) throws IllegalArgumentException
      Converts the given column-based Matrix to a vector.
      Parameters:
      m - matrix
      Returns:
      Vector3D vector
      Throws:
      IllegalArgumentException - matrix wrong size
    • toDoubleArray

      public static double[] toDoubleArray(Vector3d v)
      Converts the given vector to a double[] array.
      Parameters:
      v - vector
      Returns:
      double[] array
    • toVector3D

      public static Vector3d toVector3D(double[] a) throws IllegalArgumentException
      Converts the given double[] array to a vector.
      Parameters:
      a - array
      Returns:
      Vector3D vector
      Throws:
      IllegalArgumentException - array wrong size
    • toVector3d

      public static Vector3d toVector3d(double[] a) throws IllegalArgumentException
      Converts the given double[] array to a vector.
      Parameters:
      a - array
      Returns:
      Vector3d vector
      Throws:
      IllegalArgumentException - array wrong size
    • createArrow

      public static Geant4Basic createArrow(String aName, Vector3d aVec, double aCapRadius, double aPointerRadius, boolean aDisplayCapStart, boolean aDisplayPointer, boolean aDisplayCapEnd)
    • createArrow

      public static Geant4Basic createArrow(String aName, Line3d aLine, double aCapRadius, double aPointerRadius, boolean aDisplayCapStart, boolean aDisplayPointer, boolean aDisplayCapEnd)
    • createArrow

      public 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
    • convertRotationVectorToMatrix

      public static Matrix convertRotationVectorToMatrix(double theta, double phi)
      Converts 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
    • convertRotationVectorToGeant

      public 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
    • convertVectorDiffToAxisAngle

      public static double[] convertVectorDiffToAxisAngle(Vector3d a, Vector3d b)
      Calculates 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
    • scalePosition

      public static void scalePosition(Geant4Basic aVol, double aFactor)
      Recursively multiplies each position coordinate of the given volume and its children by the given scale factor.
      Parameters:
      aVol - volume
      aFactor - scale factor
    • shiftPosition

      public static void shiftPosition(Geant4Basic aVol, double aShiftX, double aShiftY, double aShiftZ)
      Deprecated.
      Translates the given volume's position by the given shifts.
      Parameters:
      aVol - volume
      aShiftX - shift
      aShiftY - shift
      aShiftZ - shift
    • subArraySum

      public 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
    • inputTaggedData

      public 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
    • openOutputDataFile

      public static Writer openOutputDataFile(String aName) throws IllegalArgumentException
      Opens 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
    • writeLine

      public static void writeLine(Writer aWriter, String aLine)
      Appends the given String to the given file. Terminates program if IOException occurs.
      Parameters:
      aWriter - file handle
      aLine - string to write
    • closeOutputDataFile

      public static void closeOutputDataFile(String aName, Writer aFile)
      Closes the given file. Terminates program if IOException occurs.
      Parameters:
      aName - file name
      aFile - file handle