Module helixfit_tref_mod

module helixfit_tref_mod

        ! Uses
    use precision_mod
    use namelist_mod
    use physicalconstants_mod
    use helixfit_common_mod
    use helixfit_fitpar_mod
    use helixfit_hits_mod
    use helixfit_track_mod

        ! Variables
    logical, public, PARAMETER :: HelixFitTrefMedian = .true.
    logical, public, PARAMETER :: HelixFitTrefLsq = .false.
    logical, public, PARAMETER :: HelixFitTrefFilter = .false.

        ! Subroutines and functions
    public function getPCtime (iwindow, z, cost) result (time)
    public subroutine FitTref (hits, kinks, lastplane, fitparMC, fitpar, res)
    public function findtrefDCA (hits) result (tref)
    public function findtrefDCE (hits) result (tref)
    private subroutine fitTref_median (hits, fitparMC, fitpar, res)
    public subroutine fitTref_adjthit (hits, fitparMC, fitpar, res)
    private subroutine fitTref_lsq (hits, fitparMC, fitpar, res)
    private function fitTref_filter (hits, iresmap, fitpar, res) result (fittref)
    private function sqr (a) result (b)

end module helixfit_tref_mod

Description of Variables

HelixFitTrefMedian

logical, public, PARAMETER :: HelixFitTrefMedian = .true.
 fit tref using median method

HelixFitTrefLsq

logical, public, PARAMETER :: HelixFitTrefLsq = .false.
 fit tref using least-squares

HelixFitTrefFilter

logical, public, PARAMETER :: HelixFitTrefFilter = .false.
 fit tref using filter

Description of Subroutines and Functions

getPCtime

public function getPCtime (iwindow, z, cost) result (time)
    integer, intent(in) :: iwindow
    real (kind=r8), intent(in) :: z
    real (kind=r8), intent(in) :: cost
    real (kind=r8) :: time
            ! return value
end function getPCtime

FitTref

public subroutine FitTref (hits, kinks, lastplane, fitparMC, fitpar, res)
    type (hits_type), INTENT(in) :: hits
            
 Description: fit the track reference time

 hits data
    type (kinks_type), INTENT(in) :: kinks
             kink data
    integer, INTENT(in) :: lastplane
             last plane to use
    type (fitpar_type), INTENT(in) :: fitparMC
             "true" parameters
    type (fitpar_type), INTENT(inout) :: fitpar
             fit parameters
    type (residuals_type), INTENT(inout) :: res
             residuals
    ! Calls: fittref_adjthit, fittref_lsq, fittref_median
end subroutine FitTref

findtrefDCA

public function findtrefDCA (hits) result (tref)
    type (hits_type), INTENT(in) :: hits
            
 Arguments:

 hits array
    real (kind=R8) :: tref
            
 Description: make a first guess of tref: average DC time

 Returns: reference time, ns
end function findtrefDCA

findtrefDCE

public function findtrefDCE (hits) result (tref)
    type (hits_type), INTENT(in) :: hits
            
 Arguments:

 hits array
    real (kind=R8) :: tref
            
 Description: make a first guess of tref: earliest time

 Returns: reference time, ns
end function findtrefDCE

fitTref_median

private subroutine fitTref_median (hits, fitparMC, fitpar, res)
    type (hits_type), INTENT(in) :: hits
            
 Description: fit reference time, update fitpar and res%thit

 Arguments:

 hits
    type (fitpar_type), INTENT(in) :: fitparMC
             fit parameters
    type (fitpar_type), INTENT(inout) :: fitpar
             fit parameters
    type (residuals_type), INTENT(inout) :: res
             residuals
    ! Calls: makeTofCorrection, sortreal8
end subroutine fitTref_median

fitTref_adjthit

public subroutine fitTref_adjthit (hits, fitparMC, fitpar, res)
    type (hits_type), INTENT(in) :: hits
            
 Description: adjust tref to make all thits positive, update fitpar and res%thit

 Arguments:

 hits
    type (fitpar_type), INTENT(in) :: fitparMC
             fit parameters
    type (fitpar_type), INTENT(inout) :: fitpar
             fit parameters
    type (residuals_type), INTENT(inout) :: res
             residuals
end subroutine fitTref_adjthit

fitTref_lsq

private subroutine fitTref_lsq (hits, fitparMC, fitpar, res)
    type (hits_type), INTENT(in) :: hits
            
 Description: fit reference time, update fitpar and res%thit

 Arguments:

 hits
    type (fitpar_type), INTENT(in) :: fitparMC
             fit parameters
    type (fitpar_type), INTENT(inout) :: fitpar
             fit parameters
    type (residuals_type), INTENT(inout) :: res
             residuals
    ! Calls: hf1, makeTofCorrection
end subroutine fitTref_lsq

fitTref_filter

private function fitTref_filter (hits, iresmap, fitpar, res) result (fittref)
    type (hits_type), INTENT(in) :: hits
            
 Fit reference time using a Kalman filter

 hits
    integer, INTENT(in), dimension (:,:) :: iresmap
             residuals map
    type (fitpar_type), INTENT(in) :: fitpar
             fit parameters
    type (residuals_type), INTENT(in) :: res
             residuals
    real (kind=R8) :: fittref
             return value
    ! Calls: hf1, makeTofCorrection
end function fitTref_filter

sqr

private function sqr (a) result (b)
    real (kind=R8), INTENT(in) :: a
             Description: return square of a real(r8) number
    real (kind=R8) :: b
end function sqr