module FirstGuess_mod
        ! Uses
    use Precision_mod
    use physicalconstants_mod
    use Namelist_mod
    use Chambers_mod
    use Det_Geom_mod
    use Tdc_mod
    use Unp_mod
    use Unpmc_mod
    use Track_mod
    use Hists_mod
    use Pattern_mod
    use Matrix_mod
    use timezero_mod
    use Calibrations_mod, only: BField
        ! Types
    public type coordP_type
    public type fgcluster_type
        ! Variables
    integer (kind=I4), private, PARAMETER :: MaxIterations = 50
    integer (kind=I4), private, PARAMETER :: DefaultIter = 5
    real (kind=R8), private, DIMENSION(10), PARAMETER :: CirSig2 = (/ 0.3903, 0.5932, 0.7471, 0.7711, 0.8559, 0.8257, 0.7149, 0.8087, 0.8726, 0.8363 /)
    real (kind=R8), private, DIMENSION(10), PARAMETER :: HelSig2 = (/ 0.06132, 0.05595, 0.07961, 0.07362, 0.1702, 0.09672, 0.3732, 0.1479, 0.1176, 0.3917 /)
    integer (kind=I4), public :: nCircle
    integer (kind=I4), public :: nFGTrack
    integer (kind=I4), public, DIMENSION(MaxWindows, 2) :: DenseStart
    integer (kind=I4), private :: iStream
    integer (kind=I4), private, DIMENSION(MaxWinTracks*MaxWindows) :: FirstDense
    integer (kind=I4), private, DIMENSION(MaxWinTracks*MaxWindows) :: LastDense
    integer (kind=I4), private, DIMENSION(MaxWinTracks*MaxWindows) :: FirstSparse
    integer (kind=I4), private, DIMENSION(MaxWinTracks*MaxWindows) :: LastSparse
    integer (kind=I4), private, DIMENSION(3*MaxIterations), TARGET :: iSum
    real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: Phi2Sum
    real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: zPhiSum
    real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: PhiSum
    real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: z2Sum
    real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: zSum
    real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: iRSum
    real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: Omega
    real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: PhiNot
    real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: ChiSq
    real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: uSum
    real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: vSum
    real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: uvSum
    real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: u2Sum
    real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: v2Sum
    real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: SqSum
    real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: uSqSum
    real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: vSqSum
    real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: Sq2Sum
    real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: InvSig2Sum
    real (kind=R8), private, TARGET, dimension (MaxWinTracks*MaxWindows, 8) :: aPar
    type (fgcluster_type), public, ALLOCATABLE, DIMENSION(:), TARGET :: FGCl
    type (fgcluster_type), public, ALLOCATABLE, DIMENSION(:), TARGET :: BestCl
    type (fgcluster_type), private, POINTER :: FGP
        ! Subroutines and functions
    public function FirstGuessJim (jStream, iWindow) result (iStat)
    private subroutine FillResidualPlots (iWindow, BestHelix, iFGTrack)
    private subroutine NewTrack (FGVersion, iWindow, iFGTrack, BestHelix, BestChiSq)
    private function FindCircle (iFGTrack, iWindow) result (iStat)
    private subroutine MinMaxUV (Crd, Extrema)
    private function InsertCluster (iFGTrack, Coord, iPair, PCorDC) result (iStat)
    private function ResolveCircle (iFGTrack) result (iStat)
    private function DenseOmegaPhiNot (iFGTrack, nIter) result (iStat)
    private subroutine ClusterSizeOmegaPhiNot (iFGTrack, nIter)
    private subroutine VaryPhi2 (nSets, iFGTrack, OmegaEst)
    private subroutine VaryOmega (nSets, iFGTrack, OmegaEst, nIter)
    private function CalcOmega (Estimator, iFGTrack) result (OmegaPred)
    private function ClusterSizeMatchOmega (iFGTrack) result (Match)
    private function SparseOmegaPhiNot (iFGTrack, nIter) result (iStat)
    private function FindHelix (iFGTrack, nHelices, BestHelix, BestChiSq) result (iStat)
    private subroutine FillHelixSums (iHelix, iCl, Phi, uz, vz, R)
    private function ResolveHelix (iHelix) result (iStat)
    private function CalcChiSq (iHelix) result (ChiSquare)
    private function CalcIter (In1, In2, Radius)
    private function Sig2MultScat (Initial, Current) result (Sig2MS)
    private subroutine RemoveCluster (iFGTrack, jCl, iPair, Spacing)
    private function CalcPhi (u, v, iFGTrack) result (Phi)
    private subroutine CopyTrack (iProto, iCopy)
    public subroutine ClearFGTracks (First)
    private subroutine ClearSingleTrack (iFGTrack)
    private subroutine ClearPhiSums (First, Last)
    private function UniqueTrack (iFGTrack, i0)
    private subroutine RecordFGResult (FGVersion, iWindow)
    private subroutine FillFGResult (FGVersion, iFGTrack, iFGResult, iWindow, jStream)
    public subroutine CalcAveClSize (iFGTrack, AveArea, AveSize)
    private subroutine TrackRange (iFGTrack, iPlane, MinWire, MaxWire)
    public function InsertFGResult (iFGResult, iHitWire, iWindow, iPlane, nFGHits) result (iStat)
    private subroutine FillFGvsMCPlots (iFGTrack, BestHelix, FGFitStat)
end module FirstGuess_mod
==============================================================================
 Author: Jim Musser
 Last Modified: July 18, 2001
------------------------------------------------------------------------------
 This version finds the circle parameters beginning at the target and
 progressing through the dense stack.  Winding frequency and PhiNot are found
 beginning in the dense stack and progressing to the target.
------------------------------------------------------------------------------
 FirstGuess error codes:
   iStat value:           Error:
                1                iFGTrack > MaxTmpTracks in InsertCluster
                2                iPair = PrevPair(iFGTrack) in InsertCluster
                3                FGCl(iFGTrack) % nCl >= MaxPairs in
                                    InsertCluster
                4                Cluster does not fit circle in InsertCluster
                5                Less than three clusters in ResolveCircle
                6                ChiSquare unacceptably large in ResolveCircle
                7                nRows in matrices A and B are unequal in
                                    MatSolv (Matrix_mod)
                8                Unique solution does not exist for matrix
                                    equation in MatSolv (Matrix_mod)
                9                0 row in matrix in Triangulate (Matrix_mod)
               10                Failed to find pivot in Triangulate
                                    (Matrix_mod)
               11                Solution fails check in MatSolv (Matrix_mod)
               12                ChiSquare unacceptably large in
                                    ResolvePhiLambda
               13                Cluster size inconsistent with tan(theta)
               14                Too many pairs skipped by final fit
 Helix parametrization:
 u = a1*cos[a2*z + a3] + a4
 v = a1*sin[a2*z + a3] + a5
 where a1 means aPar(iFGTrack, 1), a2 is aPar(iFGTrack, 2), etc.
 aPar(iFGTrack, 6) is t0
 aPar(iFGTrack, 7) is the Circle Chi-Square
 aPar(iFGTrack, 8) is the Omega/Phi Chi-Square
==============================================================================
public type coordP_type
    type (coord_type), POINTER :: P
    integer (kind=I4) :: iPair
    character :: PCorDC
end type coordP_type
public type fgcluster_type
    integer (kind=I4) :: nCl
    real (kind=R8) :: CirChi
    real (kind=R8) :: Chi
    type (coordP_type), DIMENSION(2*(max_planes_d/2 + max_planes_p/2)) :: Crd
end type fgcluster_type
integer (kind=I4), private, PARAMETER :: MaxIterations = 50
integer (kind=I4), private, PARAMETER :: DefaultIter = 5
real (kind=R8), private, DIMENSION(10), PARAMETER :: CirSig2 = (/ 0.3903, 0.5932, 0.7471, 0.7711, 0.8559, 0.8257, 0.7149, 0.8087, 0.8726, 0.8363 /)
real (kind=R8), private, DIMENSION(10), PARAMETER :: HelSig2 = (/ 0.06132, 0.05595, 0.07961, 0.07362, 0.1702, 0.09672, 0.3732, 0.1479, 0.1176, 0.3917 /)
integer (kind=I4), public :: nCircle
integer (kind=I4), public :: nFGTrack
integer (kind=I4), public, DIMENSION(MaxWindows, 2) :: DenseStart
integer (kind=I4), private :: iStream
integer (kind=I4), private, DIMENSION(MaxWinTracks*MaxWindows) :: FirstDense
integer (kind=I4), private, DIMENSION(MaxWinTracks*MaxWindows) :: LastDense
integer (kind=I4), private, DIMENSION(MaxWinTracks*MaxWindows) :: FirstSparse
integer (kind=I4), private, DIMENSION(MaxWinTracks*MaxWindows) :: LastSparse
integer (kind=I4), private, DIMENSION(3*MaxIterations), TARGET :: iSum
real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: Phi2Sum
real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: zPhiSum
real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: PhiSum
real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: z2Sum
real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: zSum
real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: iRSum
real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: Omega
real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: PhiNot
real (kind=R8), private, DIMENSION(3*MaxIterations), TARGET :: ChiSq
real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: uSum
real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: vSum
real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: uvSum
real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: u2Sum
real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: v2Sum
real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: SqSum
real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: uSqSum
real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: vSqSum
real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: Sq2Sum
real (kind=R8), private, DIMENSION(MaxWinTracks*MaxWindows) :: InvSig2Sum
real (kind=R8), private, TARGET, dimension (MaxWinTracks*MaxWindows, 8) :: aPar
type (fgcluster_type), public, ALLOCATABLE, DIMENSION(:), TARGET :: FGCl
type (fgcluster_type), public, ALLOCATABLE, DIMENSION(:), TARGET :: BestCl
type (fgcluster_type), private, POINTER :: FGP
public function FirstGuessJim (jStream, iWindow) result (iStat)
    integer (kind=I4), INTENT(in) :: jStream
    integer (kind=I4), INTENT(in) :: iWindow
    integer (kind=I4) :: iStat
    ! Calls: ClearSingleTrack, ClusterSizeOmegaPhiNot, HF1, NewTrack
end function FirstGuessJim
----------------------------------------------------------------------------
 FirstGuessJim finds first guess tracks within a window and detector half
----------------------------------------------------------------------------
private subroutine FillResidualPlots (iWindow, BestHelix, iFGTrack)
    integer (kind=I4), INTENT(in) :: iWindow
    integer (kind=I4), INTENT(in) :: BestHelix
    integer (kind=I4), INTENT(in) :: iFGTrack
    ! Calls: HF2
end subroutine FillResidualPlots
----------------------------------------------------------------------------
 Date created:  July 21, 2003
----------------------------------------------------------------------------
Author: Jim Musser
private subroutine NewTrack (FGVersion, iWindow, iFGTrack, BestHelix, BestChiSq)
    character, INTENT(in) :: FGVersion
    integer (kind=I4), INTENT(in) :: iWindow
    integer (kind=I4), INTENT(in) :: iFGTrack
    integer (kind=I4), INTENT(in) :: BestHelix
    real (kind=R8), INTENT(in) :: BestChiSq
    ! Calls: FillResidualPlots, HF1, HF2, RecordFGResult
end subroutine NewTrack
private function FindCircle (iFGTrack, iWindow) result (iStat)
    integer (kind=I4), INTENT(in) :: iFGTrack
    integer (kind=I4), INTENT(in) :: iWindow
    integer (kind=I4) :: iStat
    ! Calls: HF1, HF2, MinMaxUV
end function FindCircle
------------------------------------------------------------------------------
------------------------------------------------------------------------------
private subroutine MinMaxUV (Crd, Extrema)
    type (coord_type), INTENT(inout) :: Crd
    real (kind=R8), DIMENSION(4), INTENT(inout) :: Extrema
end subroutine MinMaxUV
------------------------------------------------------------------------------
------------------------------------------------------------------------------
private function InsertCluster (iFGTrack, Coord, iPair, PCorDC) result (iStat)
    integer (kind=I4), INTENT(in) :: iFGTrack
    type (coord_type), INTENT(in), TARGET :: Coord
    integer (kind=I4), INTENT(in) :: iPair
    character :: PCorDC
    integer (kind=I4) :: iStat
end function InsertCluster
------------------------------------------------------------------------------
 InsertCluster adds a cluster to a first guess track and adds to running sums
 necessary for calculating track parameters.
------------------------------------------------------------------------------
private function ResolveCircle (iFGTrack) result (iStat)
    integer (kind=I4), INTENT(in) :: iFGTrack
    integer (kind=I4) :: iStat
end function ResolveCircle
------------------------------------------------------------------------------
 ResolveCircle finds circle parameters based on Roman Tacik's algorithm.  The
 circle being the projection of the helix onto a uv plane.  aPar(4) is the x
 coordinate of the center of the circle.  aPar(5) is the y coordinate of the
 center of the circle.  aPar(1) is the radius of the circle.
 The equation of a circle is:
      (u - uCent)**2 + (v - vCent)**2 = R**2
 For FirstGuess it is parameterized as:
      Sq + 2Au + 2Bv + C = 0
 Where:
      A = -uCent                           B = -vCent
      C = A**2 + B**2 - R**2               Sq = (u**2 + v**2)
 Then
      X**2 = Sum{1/Sigma**2(Sq + 2Au + 2Bv + C)**2}
 And A, B, and C are found by solving the following matrix equation.
      /  2u2Sum     2uvSum      uSum    \  /  A  \     / -uSqSum  \.
     |   2uvSum     2v2Sum      vSum     ||   B   | = |  -vSqSum   |
      \   2uSum      2vSum   InvSig2Sum /  \  C  /     \  -SqSum  /
 (In the function this equation is written as Ax=B)
 Where each __Sum includes the division by Sigma**2
      Sig**2 = SigWire**2 + SigMultScat**2
      SigWire = 0.4cm     SigMultScat/pair = ?
------------------------------------------------------------------------------
private function DenseOmegaPhiNot (iFGTrack, nIter) result (iStat)
    integer (kind=I4), INTENT(in) :: iFGTrack
    integer (kind=I4), INTENT(out) :: nIter
    integer (kind=I4) :: iStat
    ! Calls: ClearPhiSums
end function DenseOmegaPhiNot
private subroutine ClusterSizeOmegaPhiNot (iFGTrack, nIter)
    integer (kind=I4), INTENT(in) :: iFGTrack
    integer (kind=I4), INTENT(out) :: nIter
    ! Calls: ClearPhiSums, HF1, HF2, VaryOmega, VaryPhi2
end subroutine ClusterSizeOmegaPhiNot
----------------------------------------------------------------------------
 Date created:  June 27, 2003
----------------------------------------------------------------------------
Author: Jim Musser
private subroutine VaryPhi2 (nSets, iFGTrack, OmegaEst)
    integer (kind=I4), INTENT(in) :: nSets
    integer (kind=I4), INTENT(in) :: iFGTrack
    real (kind=R8), INTENT(in) :: OmegaEst
end subroutine VaryPhi2
----------------------------------------------------------------------------
 Date created:  August 12, 2003
----------------------------------------------------------------------------
Author: Jim Musser
private subroutine VaryOmega (nSets, iFGTrack, OmegaEst, nIter)
    integer (kind=I4), INTENT(in) :: nSets
    integer (kind=I4), INTENT(in) :: iFGTrack
    real (kind=R8), INTENT(in) :: OmegaEst
    integer (kind=I4), INTENT(inout) :: nIter
end subroutine VaryOmega
----------------------------------------------------------------------------
 Date created:  August 12, 2003
----------------------------------------------------------------------------
Author: Jim Musser
private function CalcOmega (Estimator, iFGTrack) result (OmegaPred)
    integer (kind=I4), INTENT(in) :: Estimator
    integer (kind=I4), INTENT(in) :: iFGTrack
    real (kind=R8) :: OmegaPred
    ! Calls: CalcAveClSize
end function CalcOmega
----------------------------------------------------------------------------
 Date created:  August 8, 2003
----------------------------------------------------------------------------
Author: Jim Musser
private function ClusterSizeMatchOmega (iFGTrack) result (Match)
    integer (kind=I4), INTENT(in) :: iFGTrack
    logical :: Match
end function ClusterSizeMatchOmega
----------------------------------------------------------------------------
 ClusterSizeMatchOmega() tests to see if omega is consistent with the
 average cluster size for the track.
 Created: September 8, 2003
----------------------------------------------------------------------------
Author: Jim Musser
private function SparseOmegaPhiNot (iFGTrack, nIter) result (iStat)
    integer (kind=I4), INTENT(in) :: iFGTrack
    integer (kind=I4), INTENT(out) :: nIter
    integer (kind=I4) :: iStat
    ! Calls: ClearPhiSums
end function SparseOmegaPhiNot
private function FindHelix (iFGTrack, nHelices, BestHelix, BestChiSq) result (iStat)
    integer (kind=I4), INTENT(in) :: iFGTrack
    integer (kind=I4), INTENT(in) :: nHelices
    integer (kind=I4), INTENT(out) :: BestHelix
    real (kind=R8), INTENT(out) :: BestChiSq
    integer (kind=I4) :: iStat
    ! Calls: FillHelixSums
end function FindHelix
private subroutine FillHelixSums (iHelix, iCl, Phi, uz, vz, R)
    integer (kind=I4), INTENT(in) :: iHelix
    integer (kind=I4), INTENT(in) :: iCl
    real (kind=R8), INTENT(in) :: Phi
    real (kind=R8), INTENT(in) :: uz
    real (kind=R8), INTENT(in) :: vz
    real (kind=R8), INTENT(in) :: R
end subroutine FillHelixSums
private function ResolveHelix (iHelix) result (iStat)
    integer (kind=I4), INTENT(in) :: iHelix
    integer (kind=I4) :: iStat
end function ResolveHelix
------------------------------------------------------------------------------
 ResolveHelix solves the matrix equation to determine Phi and Lambda.
    Phi = Omega*z + PhiNot
 With Omega = aPar(2)  and  PhiNot = aPar(3)
 Where Phi is given by:
    Phi = aTan2(v - aPar(5), u - aPar(4))
 Then
    X**2 = Sum{(Phi - aPar(2)*z - aPar(3))**2}
 And aPar(2) and aPar(3) are found by solving the following matrix equation:
  /  a2Sum   zSum   \/  aPar(2)  \ _ /  zPhiSum  \
  \   zSum   iRSum  /\  aPar(3)  / - \  PhiSum   /
 Where each __Sum includes the division by Sigma**2
------------------------------------------------------------------------------
private function CalcChiSq (iHelix) result (ChiSquare)
    integer (kind=I4), INTENT(in) :: iHelix
    real (kind=R8) :: ChiSquare
end function CalcChiSq
----------------------------------------------------------------------------
 Created: September 10, 2003
 CalcChiSq calculates the Chi-Square for the (Omega, PhiNot) fit including
 a correction for missed hits.
----------------------------------------------------------------------------
Author: Jim Musser
private function CalcIter (In1, In2, Radius)
    integer (kind=I4), INTENT(in) :: In1
    integer (kind=I4), INTENT(in) :: In2
    real (kind=R8), INTENT(in) :: Radius
    integer (kind=I4) :: CalcIter
end function CalcIter
private function Sig2MultScat (Initial, Current) result (Sig2MS)
    integer (kind=I4), INTENT(in) :: Initial
    integer (kind=I4), INTENT(in) :: Current
    real (kind=R8) :: Sig2MS
end function Sig2MultScat
------------------------------------------------------------------------------
------------------------------------------------------------------------------
private subroutine RemoveCluster (iFGTrack, jCl, iPair, Spacing)
    integer (kind=I4), INTENT(in) :: iFGTrack
    integer (kind=I4), INTENT(in) :: jCl
    integer (kind=I4), INTENT(in) :: iPair
    real (kind=R8), INTENT(in) :: Spacing
    ! Calls: ClearSingleTrack
end subroutine RemoveCluster
------------------------------------------------------------------------------
------------------------------------------------------------------------------
private function CalcPhi (u, v, iFGTrack) result (Phi)
    real (kind=R8), INTENT(in) :: u
    real (kind=R8), INTENT(in) :: v
    integer (kind=I4) :: iFGTrack
    real (kind=R8) :: Phi
end function CalcPhi
------------------------------------------------------------------------------
 Date rewritten: August 7, 2003
 CalcPhi determines phi from (u, v) for a given track
------------------------------------------------------------------------------
Author: Jim Musser
private subroutine CopyTrack (iProto, iCopy)
    integer (kind=I4), INTENT(in) :: iProto
    integer (kind=I4), INTENT(in) :: iCopy
end subroutine CopyTrack
------------------------------------------------------------------------------
 CopyTrack
------------------------------------------------------------------------------
public subroutine ClearFGTracks (First)
    integer (kind=I4), INTENT(in) :: First
    ! Calls: ClearSingleTrack
end subroutine ClearFGTracks
------------------------------------------------------------------------------
------------------------------------------------------------------------------
private subroutine ClearSingleTrack (iFGTrack)
    integer (kind=I4), INTENT(in) :: iFGTrack
end subroutine ClearSingleTrack
private subroutine ClearPhiSums (First, Last)
    integer (kind=I4), INTENT(in) :: First
    integer (kind=I4), INTENT(in) :: Last
end subroutine ClearPhiSums
private function UniqueTrack (iFGTrack, i0)
    integer (kind=I4), INTENT(in) :: iFGTrack
    integer (kind=I4), INTENT(in) :: i0
    logical :: UniqueTrack
    ! Calls: CopyTrack
end function UniqueTrack
private subroutine RecordFGResult (FGVersion, iWindow)
    character, INTENT(in) :: FGVersion
    integer (kind=I4), INTENT(in) :: iWindow
    ! Calls: FillFGResult, HF1
end subroutine RecordFGResult
----------------------------------------------------------------------------
 Date created:  July 21, 2003
 Subroutine calls FillFGResult after determining whether particle is to be
 considered as having traversed half of the detector or all of the detector
----------------------------------------------------------------------------
Author: Jim Musser
private subroutine FillFGResult (FGVersion, iFGTrack, iFGResult, iWindow, jStream)
    character, INTENT(in) :: FGVersion
    integer (kind=I4), INTENT(in) :: iFGTrack
    integer (kind=I4), INTENT(in) :: iFGResult
    integer (kind=I4), INTENT(in) :: iWindow
    integer (kind=I4), INTENT(in) :: jStream
    ! Calls: CalcAveClSize, HF1, HF2, TrackRange
end subroutine FillFGResult
public subroutine CalcAveClSize (iFGTrack, AveArea, AveSize)
    integer (kind=I4), INTENT(in) :: iFGTrack
    real (kind=R8), INTENT(out) :: AveArea
    real (kind=R8), INTENT(out) :: AveSize
    ! Calls: HF1
end subroutine CalcAveClSize
----------------------------------------------------------------------------
 CalcAveClSize calculates the average size of DC clusters assigned to a
 particular track.
 Created: June 17, 2003
----------------------------------------------------------------------------
Author: Jim Musser
private subroutine TrackRange (iFGTrack, iPlane, MinWire, MaxWire)
    integer (kind=I4), INTENT(in) :: iFGTrack
    integer (kind=I4), INTENT(in) :: iPlane
    integer (kind=I4), INTENT(out) :: MinWire
    integer (kind=I4), INTENT(out) :: MaxWire
end subroutine TrackRange
------------------------------------------------------------------------------
 Revised TrackRange finds the range of wires that intersects the circular
 projection of the track.
 Revised March 27, 2003
public function InsertFGResult (iFGResult, iHitWire, iWindow, iPlane, nFGHits) result (iStat)
    integer (kind=I4), INTENT(in) :: iFGResult
    integer (kind=I4), INTENT(in) :: iHitWire
    integer (kind=I4), INTENT(in) :: iWindow
    integer (kind=I4), INTENT(in) :: iPlane
    integer (kind=I4), INTENT(inout) :: nFGHits
    integer (kind=I4) :: iStat
end function InsertFGResult
private subroutine FillFGvsMCPlots (iFGTrack, BestHelix, FGFitStat)
    integer (kind=I4), INTENT(in) :: iFGTrack
    integer (kind=I4), INTENT(in) :: BestHelix
    integer (kind=I4), INTENT(in) :: FGFitStat
    ! Calls: HF1, HF2
end subroutine FillFGvsMCPlots
----------------------------------------------------------------------------
 
----------------------------------------------------------------------------
Author: Jim Musser