Class Util

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

public class Util extends Object

Geometry Utility Link icon

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 Details Link icon

    • VERBOSE Link icon

      public static boolean VERBOSE
  • Constructor Details Link icon

    • Util Link icon

      public Util()
  • Method Details Link icon

    • calcDistance Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

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

      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 Link icon

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

      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 Link icon

      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 Link icon

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

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

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

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