Module helixfit_mod

module helixfit_mod

        ! Uses
    use precision_mod
    use namelist_mod
    use physicalconstants_mod
    use track_mod
    use hists_mod, ONLY: HelixFitHist
    use helixfit_common_mod
    use helixfit_fitpar_mod
    use helixfit_hits_mod
    use helixfit_cell_mod
    use helixfit_track_mod
    use helixfit_kinks_mod
    use helixfit_tref_mod
    use helixfit_fitllsq_mod

        ! Types
    private type covariance_type

        ! Variables
    integer, private, PARAMETER :: kSmearNone = 0
    integer, private, PARAMETER :: kSmearFlat = 1
    integer, private, PARAMETER :: kSmearGauss = 2
    integer, private, PARAMETER :: kHitsDefault = 0
    integer, private, PARAMETER :: kHitsWin1 = 1
    integer, private, PARAMETER :: kHitsWin2 = 2
    integer, private, PARAMETER :: kHitsFG = 3
    integer, private, PARAMETER :: kStrtDefault = 0
    integer, private, PARAMETER :: kStrtMC = 1
    integer, private, PARAMETER :: kStrtFG = 2
    integer, private, PARAMETER :: kStrtLineFit = 3
    integer, private, PARAMETER :: kStrtMCSP = 4
    integer, public, PARAMETER :: kTrefDefault = 0
    integer, private, PARAMETER :: kTrefMC = 1
    integer, public, PARAMETER :: kTrefWin = 2
    integer, private, PARAMETER :: kTrefDCE = 3
    integer, private, PARAMETER :: kTrefDCA = 4
    logical, private :: tracktrace
    logical, private :: trace2
    real (kind=R8), private, EXTERNAL :: conlev
    integer, private, EXTERNAL :: inewunit
    type (covariance_type), private :: covWC
    type (covariance_type), private :: covDT

        ! Subroutines and functions
    public subroutine HelixFitInit ()
    public subroutine HelixFitResetCaches ()
    public subroutine HelixFitExit ()
    public subroutine HelixFitFindMC (imctrk, imcwindow)
    private subroutine FindMCSP (hits, z0, v, p)
    private function MCisValid (mctrk) result (isValid)
    public function HelixFitFldOff (iwindow, mass, fit) result (didfit)
    public subroutine HelixFitMC (mctrk, iwindow, mass, fit)
    public subroutine HelixFitFG (fg, mass, istream, xicost, xiend, fit)
    private subroutine VPTcmpMC (base, fgv3, fgp3, t, mc)
    private subroutine FGcmpMC (fg, mc)
    private subroutine HEcmpMC (fit, mc)
    private subroutine smearVPQT (v, p, q, t)
    private function checkFiducialsPCZT (p0mag, cost0, z0, tref0) result (pass)
    private function checkUVplanes (hits)
    private subroutine SetupMC (mctrk, mass0, z0, zmean, dpds, partype, fitparMC)
    private function finite (name, x)
    private subroutine HelixFitHZVPQMTMF (hits, z0, v0, p0, q0, mass0, t0, mctrk, fit)
    private subroutine HistInput (fitpar0, chi0)
    private function HelixFit1 (hits, fitparMC, fitpar0, kinksB, fitparB, resB, chiB, numiter) result (ierror)
    private function fitFunction (hits, kinks, lastplane, fitparMC, fitpar, restype, doFitTref, res, chi, value) result (ierror)
    private function fitLineMin (hits, kinks, lastplane, fitparMC, fitpar0, res0, chi0, val0, doFitTref, direction, maxiter, parx, resx, chix, valx, numiter, verbose) result (ierror)
    private function HelixFit2coordinateDescent (hits, kinks, lastplane, fitparMC, fitpar0, restype, maxiter, parstep, ambig0, doFitTref, res0, chi0, fitparB, resB, chiB, numiter) result (ierror)
    private function HelixFit2steepestDescent (hits, kinks, lastplane, fitparMC, fitpar0, restype, maxiter, parstep, ambig0, doFitTref, res0, chi0, fitparB, resB, chiB, numiter) result (ierror)
    private subroutine saveFit (fit, hits, kinks, fitpar, res, chi)
    private subroutine probeChiSqrD (hits, kinks, lastplane, fitpar0, ambig0, ipar, dpar, doprint, res, chi)
    private subroutine probeChebyshev (hits, kinks, lastplane, fitpar0, ambig0)
    private subroutine probeLikelihood (hits, kinks, lastplane, fitpar0, ambig0)
    private subroutine probeChiSqrE (hits, kinks, lastplane, fitpar0, ambig0)
    private subroutine probeChiSqrF (hits, kinks, lastplane, fitpar0, ambig0)
    private subroutine probeChiSqrA (hits, kinks, lastplane, fitpar0, ambig0)
    private subroutine FillAsciiAlign (res)
    private subroutine Write1EvtAsciiAlign (iunit, res)
    private subroutine FillTreeAlign (hits, fitpar, res, chi)
    private subroutine FillTreeResiduals (hits, fitpar, res, chi)
    private subroutine FillHistResiduals (hits, fitpar, res)
    private subroutine FillHistKinks (hits, kinks, fitpar, res)
    private subroutine FillHistMC (mctrk)
    private subroutine FillHistFit (fitpar, res, chi)
    private subroutine FillHistParDist (fitpar0, fitpar)
    private subroutine FillHistParF (fitparMC, fitparB)
    private subroutine FillHistPar0 (fitparMC, fitpar)
    private function rnd_uniform (a, b) result (ret)
    private function rnd_gauss (mean, sigma) result (ret)
    private function rad2deg (a)
    private function deg2rad (a)
    private function jsign (a) result (ival)
    private function sqr (a) result (b)
    private function V3mag (a)
    private function findz0 (hits, iend) result (z0)
    private function findzmean (hits) result (zmean)
    private subroutine SetupHists ()
    private subroutine SetupHistCmpMC (base, prefix)
    private subroutine SetupHistCmpPar (base, prefix, partype, numpar)
    private subroutine SetupHistResiduals ()
    private subroutine InitCov (cov)
    private subroutine addCov (cov, hits, lastplane, fitpar, res)
    private subroutine printCov (cov)

end module helixfit_mod

Description of Types

covariance_type

private type covariance_type
    integer :: numpar
    character, dimension (kMaxPar) :: partype
    real (kind=R8) :: sumpar0
    real (kind=R8), dimension (kMaxPar) :: sumpar1
    real (kind=R8), dimension (kMaxPar) :: sumpar2
    real (kind=R8), dimension (kMaxPar,kMaxPar) :: sumpar11
    real (kind=R8), dimension (kMaxResiduals) :: sumres0
    real (kind=R8), dimension (kMaxResiduals) :: sumres1
    real (kind=R8), dimension (kMaxResiduals) :: sumres2
    real (kind=R8), dimension (kMaxResiduals,kMaxResiduals) :: sumres11
end type covariance_type

Description of Variables

kSmearNone

integer, private, PARAMETER :: kSmearNone = 0
 HelixFitVerbose settings:
   0 - very quiet
   1 - print something about every event
   2 - print progress on every iteration
   3 - print initial and final residuals
   4 - print residuals on every iteration
   5 - print internals on every iteration
 101 - skip all events


 HelixFitSmearInput values:

 no smearing

kSmearFlat

integer, private, PARAMETER :: kSmearFlat = 1
 smear with a flat distribution

kSmearGauss

integer, private, PARAMETER :: kSmearGauss = 2
 smear with a gaussian distribution

kHitsDefault

integer, private, PARAMETER :: kHitsDefault = 0

kHitsWin1

integer, private, PARAMETER :: kHitsWin1 = 1
 take hits from time window, one side

kHitsWin2

integer, private, PARAMETER :: kHitsWin2 = 2
 take hits from time window, both sides

kHitsFG

integer, private, PARAMETER :: kHitsFG = 3
 take hits from first-guess

kStrtDefault

integer, private, PARAMETER :: kStrtDefault = 0

kStrtMC

integer, private, PARAMETER :: kStrtMC = 1
 take starting point from MC

kStrtFG

integer, private, PARAMETER :: kStrtFG = 2
 take starting point from first-guess

kStrtLineFit

integer, private, PARAMETER :: kStrtLineFit = 3
 take starting point from straight-line fit

kStrtMCSP

integer, private, PARAMETER :: kStrtMCSP = 4
 start from closest MCSP point

kTrefDefault

integer, public, PARAMETER :: kTrefDefault = 0

kTrefMC

integer, private, PARAMETER :: kTrefMC = 1
 tref from MC track

kTrefWin

integer, public, PARAMETER :: kTrefWin = 2
 tref from window%t0

kTrefDCE

integer, private, PARAMETER :: kTrefDCE = 3
 tref from earliest DC time

kTrefDCA

integer, private, PARAMETER :: kTrefDCA = 4
 tref from average DC time

tracktrace

logical, private :: tracktrace

trace2

logical, private :: trace2

conlev

real (kind=R8), private, EXTERNAL :: conlev
 external confidence level calculator

inewunit

integer, private, EXTERNAL :: inewunit
 external i/o unit allocator

covWC

type (covariance_type), private :: covWC

covDT

type (covariance_type), private :: covDT

Description of Subroutines and Functions

HelixFitInit

public subroutine HelixFitInit ()
    ! Calls: InitCov, SetupHistResiduals, SetupHists
end subroutine HelixFitInit

HelixFitResetCaches

public subroutine HelixFitResetCaches ()
end subroutine HelixFitResetCaches

HelixFitExit

public subroutine HelixFitExit ()
end subroutine HelixFitExit

HelixFitFindMC

public subroutine HelixFitFindMC (imctrk, imcwindow)
    integer, INTENT(out) :: imctrk
    integer, INTENT(out) :: imcwindow
end subroutine HelixFitFindMC
----------------------------------------------------------------------------
 Completely rewritten by Jim, April 5, 2004
 Modified by Jim, April 14, 2004 to find vertex at first DC foil.
----------------------------------------------------------------------------

FindMCSP

private subroutine FindMCSP (hits, z0, v, p)
    type (hits_type), INTENT(in) :: hits
             hits
    real (kind=R8), INTENT(in) :: z0
             track starting point
    real (kind=R8), INTENT(out), dimension (3) :: v
             output track position and momentum
    real (kind=R8), INTENT(out), dimension (3) :: p
             output track position and momentum
end subroutine FindMCSP

MCisValid

private function MCisValid (mctrk) result (isValid)
    type (mctrack_type), INTENT(in) :: mctrk
    logical :: isValid
end function MCisValid

HelixFitFldOff

public function HelixFitFldOff (iwindow, mass, fit) result (didfit)
    integer, INTENT(in) :: iwindow
    real (kind=R8), INTENT(in) :: mass
    type (helixfit_type), INTENT(out) :: fit
    logical :: didfit
             return value: false if did not do any fits, fit structure is invalid
    ! Calls: Die, FindWinHits, HelixFitHZVPQMTMF
end function HelixFitFldOff

HelixFitMC

public subroutine HelixFitMC (mctrk, iwindow, mass, fit)
    type (mctrack_type), INTENT(in) :: mctrk
             track to use as starting point
    integer, INTENT(in) :: iwindow
             use all hits from this window
    real (kind=R8), INTENT(in) :: mass
             particle mass
    type (helixfit_type), INTENT(out) :: fit
    ! Calls: FindWinHits, HelixFitHZVPQMTMF, die
end subroutine HelixFitMC

HelixFitFG

public subroutine HelixFitFG (fg, mass, istream, xicost, xiend, fit)
    type (FGresult_type), INTENT(in) :: fg
             first guess data
    real (kind=R8), INTENT(in) :: mass
             particle mass
    integer, INTENT(in) :: istream
             use hits: -1 upstream only, +1 downstream only, 0 all hits
    integer, INTENT(in) :: xicost
             direction of particle travel: -1: DS->US, +1: US->DS
    integer, INTENT(in) :: xiend
             fit US (-1) or DS (+1) end of the track
    type (helixfit_type), INTENT(out) :: fit
    ! Calls: ConvertFGZtoVPQ, FGcmpMC, FindFGHits, FindMCSP, FindWinHits, HelixFitFindMC, HelixFitHZVPQMTMF, die
end subroutine HelixFitFG

VPTcmpMC

private subroutine VPTcmpMC (base, fgv3, fgp3, t, mc)
    integer, INTENT(in) :: base
    real (kind=R8), INTENT(in), dimension (3) :: fgv3
    real (kind=R8), INTENT(in), dimension (3) :: fgp3
    real (kind=R8), INTENT(in) :: t
    type (mctrack_type), INTENT(in) :: mc
    ! Calls: hf1, hf2
end subroutine VPTcmpMC

FGcmpMC

private subroutine FGcmpMC (fg, mc)
    type (FGresult_type), INTENT(in) :: fg
    type (mctrack_type), INTENT(in) :: mc
    ! Calls: ConvertFGZtoVPQ, SetupHistCmpMC, VPTcmpMC
end subroutine FGcmpMC

HEcmpMC

private subroutine HEcmpMC (fit, mc)
    type (helixfit_type), INTENT(in) :: fit
    type (mctrack_type), INTENT(in) :: mc
    ! Calls: SetupHistCmpMC, VPTcmpMC
end subroutine HEcmpMC

smearVPQT

private subroutine smearVPQT (v, p, q, t)
    real (kind=R8), INTENT(inout), dimension (3) :: v
    real (kind=R8), INTENT(inout), dimension (3) :: p
    integer, INTENT(inout) :: q
    real (kind=R8), INTENT(inout) :: t
    ! Calls: die
end subroutine smearVPQT

checkFiducialsPCZT

private function checkFiducialsPCZT (p0mag, cost0, z0, tref0) result (pass)
    real (kind=R8), INTENT(in) :: p0mag
    real (kind=R8), INTENT(in) :: cost0
    real (kind=R8), INTENT(in) :: z0
    real (kind=R8), INTENT(in) :: tref0
    logical :: pass
             return value
end function checkFiducialsPCZT

checkUVplanes

private function checkUVplanes (hits)
    type (hits_type), INTENT(in) :: hits
    logical :: checkUVplanes
             return value
end function checkUVplanes

SetupMC

private subroutine SetupMC (mctrk, mass0, z0, zmean, dpds, partype, fitparMC)
    type (mctrack_type), INTENT(in) :: mctrk
             mc track
    real (kind=R8), INTENT(in) :: mass0
             particle mass
    real (kind=R8), INTENT(in) :: z0
             starting point z
    real (kind=R8), INTENT(in) :: zmean
             mean z of all hits
    real (kind=R8), INTENT(in) :: dpds
             energy loss
    integer, INTENT(in) :: partype
             parametrization
    type (fitpar_type), INTENT(out) :: fitparMC
    ! Calls: ClearFitpar
end subroutine SetupMC

finite

private function finite (name, x)
    character (len=*), INTENT(in) :: name
            
 Description: return .true. if (x) is not a NaN
    real (kind=R8), INTENT(in) :: x
    logical :: finite
    ! Calls: kerror
end function finite

HelixFitHZVPQMTMF

private subroutine HelixFitHZVPQMTMF (hits, z0, v0, p0, q0, mass0, t0, mctrk, fit)
    type (hits_type), INTENT(in) :: hits
             fit these hits
    real (kind=R8), INTENT(in) :: z0
             determine helix parameters at this z
    real (kind=R8), INTENT(in), dimension (3) :: v0
             initial position
    real (kind=R8), INTENT(in), dimension (3) :: p0
             initial momentum
    integer, INTENT(in) :: q0
             charge
    real (kind=R8), INTENT(in) :: mass0
             mass of the particle in MeV/c^2
    real (kind=R8), INTENT(in) :: t0
             track start time
    type (mctrack_type), INTENT(in) :: mctrk
             mc track
    type (helixfit_type), INTENT(out) :: fit
             fit results
    ! Calls: ClearFitpar, ClearRes, FillAsciiAlign, FillHistFit, FillHistKinks, FillHistMC, FillHistPar0, FillHistParDist, FillHistParF, FillHistResiduals, FillTreeAlign, FillTreeResiduals, SetupMC, hf1, makeChiSqr, printHelixFit, printHits, saveFit, smearVPQT
end subroutine HelixFitHZVPQMTMF

HistInput

private subroutine HistInput (fitpar0, chi0)
    type (fitpar_type), INTENT(in) :: fitpar0
            
 Histogram the input data
    type (chisqr_type), INTENT(in) :: chi0
    ! Calls: getFitparPPCP, hf1, hf2
end subroutine HistInput

HelixFit1

private function HelixFit1 (hits, fitparMC, fitpar0, kinksB, fitparB, resB, chiB, numiter) result (ierror)
    type (hits_type), INTENT(in) :: hits
            
 Helix fitter: do wire center fit followed by drift fit.
 Calls HelixFit2xxx() to do the fits.
    type (fitpar_type), INTENT(in) :: fitparMC
    type (fitpar_type), INTENT(in) :: fitpar0
    type (kinks_type), INTENT(out) :: kinksB
    type (fitpar_type), INTENT(out) :: fitparB
    type (residuals_type), INTENT(out) :: resB
    type (chisqr_type), INTENT(out) :: chiB
    integer, INTENT(out) :: numiter
    integer :: ierror
             return value
    ! Calls: HistInput, addCov, addFitparTref, addKinks, assignResiduals, clearKinks, copyFitpar, getFitparPPCP, printKinks, probeChebyshev, probeChiSqrA, probeChiSqrE, probeChiSqrF, probeLikelihood, scaleFitpar, setupKinks, unscaleFitpar, updateFitpar
end function HelixFit1

fitFunction

private function fitFunction (hits, kinks, lastplane, fitparMC, fitpar, restype, doFitTref, res, chi, value) result (ierror)
    type (hits_type), INTENT(in) :: hits
            
 Calculate goal function for data fitters.

 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 fit parameters
    type (fitpar_type), INTENT(in) :: fitpar
             fit parameters
    integer, INTENT(in) :: restype
             type of residuals
    logical, INTENT(in) :: doFitTref
             enable external fitting of tref
    type (residuals_type), INTENT(out) :: res
    type (chisqr_type), INTENT(out) :: chi
    real (kind=R8), INTENT(out) :: value
    integer :: ierror
             return value
    ! Calls: makeChiSqr, setResiduals
end function fitFunction

fitLineMin

private function fitLineMin (hits, kinks, lastplane, fitparMC, fitpar0, res0, chi0, val0, doFitTref, direction, maxiter, parx, resx, chix, valx, numiter, verbose) result (ierror)
    type (hits_type), INTENT(in) :: hits
            
 Do one-dimensional minimisation of fitFunction()

 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(in) :: fitpar0
             starting point parameters
    type (residuals_type), INTENT(in) :: res0
    type (chisqr_type), INTENT(in) :: chi0
    real (kind=R8), INTENT(in) :: val0
    logical, INTENT(in) :: doFitTref
             enable external fitting of tref
    real (kind=R8), INTENT(in), dimension (:) :: direction
             search direction
    integer, INTENT(in) :: maxiter
             maximum number of iterations
    type (fitpar_type), INTENT(out) :: parx
    type (residuals_type), INTENT(out) :: resx
    type (chisqr_type), INTENT(out) :: chix
    real (kind=R8), INTENT(out) :: valx
    integer, INTENT(out) :: numiter
    logical, INTENT(in) :: verbose
    integer :: ierror
             return value
    ! Calls: updateFitpar
end function fitLineMin

HelixFit2coordinateDescent

private function HelixFit2coordinateDescent (hits, kinks, lastplane, fitparMC, fitpar0, restype, maxiter, parstep, ambig0, doFitTref, res0, chi0, fitparB, resB, chiB, numiter) result (ierror)
    type (hits_type), INTENT(in) :: hits
            
 Minimise fitFunction() use per-coordinate descent method

 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(in) :: fitpar0
             starting point parameters
    integer, INTENT(in) :: restype
             type of residuals
    integer, INTENT(in) :: maxiter
             maximum number of iterations
    real (kind=R8), INTENT(in), dimension (:) :: parstep
    integer, INTENT(in), dimension (:) :: ambig0
             ambiguity settings
    logical, INTENT(in) :: doFitTref
             enable external fitting of tref
    type (residuals_type), INTENT(out) :: res0
    type (chisqr_type), INTENT(out) :: chi0
    type (fitpar_type), INTENT(out) :: fitparB
    type (residuals_type), INTENT(out) :: resB
    type (chisqr_type), INTENT(out) :: chiB
    integer, INTENT(out) :: numiter
    integer :: ierror
             return value
    ! Calls: getFitparPPCP, printres, probeChiSqrE
end function HelixFit2coordinateDescent

HelixFit2steepestDescent

private function HelixFit2steepestDescent (hits, kinks, lastplane, fitparMC, fitpar0, restype, maxiter, parstep, ambig0, doFitTref, res0, chi0, fitparB, resB, chiB, numiter) result (ierror)
    type (hits_type), INTENT(in) :: hits
            
 Minimise fitFunction() using steepest descent method

 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(in) :: fitpar0
             starting point parameters
    integer, INTENT(in) :: restype
             type of residuals
    integer, INTENT(in) :: maxiter
             maximum number of iterations
    real (kind=R8), INTENT(in), dimension (:) :: parstep
    integer, INTENT(in), dimension (:) :: ambig0
             ambiguity settings
    logical, INTENT(in) :: doFitTref
             enable external fitting of tref
    type (residuals_type), INTENT(out) :: res0
    type (chisqr_type), INTENT(out) :: chi0
    type (fitpar_type), INTENT(out) :: fitparB
    type (residuals_type), INTENT(out) :: resB
    type (chisqr_type), INTENT(out) :: chiB
    integer, INTENT(out) :: numiter
    integer :: ierror
             return value
    ! Calls: getFitparPPCP, printres, probeChiSqrE, updateFitpar
end function HelixFit2steepestDescent

saveFit

private subroutine saveFit (fit, hits, kinks, fitpar, res, chi)
    type (helixfit_type), INTENT(out) :: fit
            
 Description: store fit results
    type (hits_type), INTENT(in) :: hits
    type (kinks_type), INTENT(in) :: kinks
    type (fitpar_type), INTENT(in) :: fitpar
    type (residuals_type), INTENT(in) :: res
    type (chisqr_type), INTENT(in) :: chi
    ! Calls: getFitparVPQ
end subroutine saveFit

probeChiSqrD

private subroutine probeChiSqrD (hits, kinks, lastplane, fitpar0, ambig0, ipar, dpar, doprint, res, chi)
    type (hits_type), INTENT(in) :: hits
    type (kinks_type), INTENT(in) :: kinks
    integer, INTENT(in) :: lastplane
    type (fitpar_type), INTENT(in) :: fitpar0
    integer, INTENT(in), dimension (:) :: ambig0
    integer, INTENT(in) :: ipar
    real (kind=R8), INTENT(in) :: dpar
    logical, INTENT(in) :: doprint
    type (residuals_type), INTENT(out) :: res
    type (chisqr_type), INTENT(out) :: chi
    ! Calls: makeChiSqr, printres, setResiduals, updateFitpar
end subroutine probeChiSqrD

probeChebyshev

private subroutine probeChebyshev (hits, kinks, lastplane, fitpar0, ambig0)
    type (hits_type), INTENT(in) :: hits
            
 Probe the Chebyshev function
    type (kinks_type), INTENT(in) :: kinks
    integer, INTENT(in) :: lastplane
    type (fitpar_type), INTENT(in) :: fitpar0
    integer, INTENT(in), dimension (:) :: ambig0
    ! Calls: probeChiSqrD
end subroutine probeChebyshev

probeLikelihood

private subroutine probeLikelihood (hits, kinks, lastplane, fitpar0, ambig0)
    type (hits_type), INTENT(in) :: hits
            
 Probe the likelyhood function
    type (kinks_type), INTENT(in) :: kinks
    integer, INTENT(in) :: lastplane
    type (fitpar_type), INTENT(in) :: fitpar0
    integer, INTENT(in), dimension (:) :: ambig0
    ! Calls: probeChiSqrD
end subroutine probeLikelihood

probeChiSqrE

private subroutine probeChiSqrE (hits, kinks, lastplane, fitpar0, ambig0)
    type (hits_type), INTENT(in) :: hits
    type (kinks_type), INTENT(in) :: kinks
    integer, INTENT(in) :: lastplane
    type (fitpar_type), INTENT(in) :: fitpar0
    integer, INTENT(in), dimension (:) :: ambig0
    ! Calls: probeChiSqrD
end subroutine probeChiSqrE

probeChiSqrF

private subroutine probeChiSqrF (hits, kinks, lastplane, fitpar0, ambig0)
    type (hits_type), INTENT(in) :: hits
    type (kinks_type), INTENT(in) :: kinks
    integer, INTENT(in) :: lastplane
    type (fitpar_type), INTENT(in) :: fitpar0
    integer, INTENT(in), dimension (:) :: ambig0
    ! Calls: probeChiSqrD
end subroutine probeChiSqrF

probeChiSqrA

private subroutine probeChiSqrA (hits, kinks, lastplane, fitpar0, ambig0)
    type (hits_type), INTENT(in) :: hits
    type (kinks_type), INTENT(in) :: kinks
    integer, INTENT(in) :: lastplane
    type (fitpar_type), INTENT(in) :: fitpar0
    integer, INTENT(in), dimension (:) :: ambig0
    ! Calls: probeChiSqrD
end subroutine probeChiSqrA

FillAsciiAlign

private subroutine FillAsciiAlign (res)
    type (residuals_type), INTENT(in) :: res
    ! Calls: Getenv, Write1EvtAsciiAlign
end subroutine FillAsciiAlign

Write1EvtAsciiAlign

private subroutine Write1EvtAsciiAlign (iunit, res)
    integer, INTENT(in) :: iunit
    type (residuals_type), INTENT(in) :: res
end subroutine Write1EvtAsciiAlign

FillTreeAlign

private subroutine FillTreeAlign (hits, fitpar, res, chi)
    type (hits_type), INTENT(in) :: hits
            
 Special ROOT TTree output
    type (fitpar_type), INTENT(in) :: fitpar
    type (residuals_type), INTENT(in) :: res
    type (chisqr_type), INTENT(in) :: chi
    ! Calls: filltree, getFitparPPCP, makebranch, setbranchvar
end subroutine FillTreeAlign

FillTreeResiduals

private subroutine FillTreeResiduals (hits, fitpar, res, chi)
    type (hits_type), INTENT(in) :: hits
            
 Special ROOT TTree output
    type (fitpar_type), INTENT(in) :: fitpar
    type (residuals_type), INTENT(in) :: res
    type (chisqr_type), INTENT(in) :: chi
    ! Calls: filltree, hf1, makebranch, setbranchvar
end subroutine FillTreeResiduals

FillHistResiduals

private subroutine FillHistResiduals (hits, fitpar, res)
    type (hits_type), INTENT(in) :: hits
    type (fitpar_type), INTENT(in) :: fitpar
    type (residuals_type), INTENT(in) :: res
    ! Calls: getFitparPPCP, hf1, hf2
end subroutine FillHistResiduals

FillHistKinks

private subroutine FillHistKinks (hits, kinks, fitpar, res)
    type (hits_type), INTENT(in) :: hits
    type (kinks_type), INTENT(in) :: kinks
    type (fitpar_type), INTENT(in) :: fitpar
    type (residuals_type), INTENT(in) :: res
    ! Calls: hbook1, hbook2, hf1, hf2
end subroutine FillHistKinks

FillHistMC

private subroutine FillHistMC (mctrk)
    type (mctrack_type), INTENT(in) :: mctrk
    ! Calls: VPQtoPPCP, hf1
end subroutine FillHistMC

FillHistFit

private subroutine FillHistFit (fitpar, res, chi)
    type (fitpar_type), INTENT(in) :: fitpar
    type (residuals_type), INTENT(in) :: res
    type (chisqr_type), INTENT(in) :: chi
    ! Calls: getFitparPPCP, getFitparVPQ, hf1, hf2
end subroutine FillHistFit

FillHistParDist

private subroutine FillHistParDist (fitpar0, fitpar)
    type (fitpar_type), INTENT(in) :: fitpar0
    type (fitpar_type), INTENT(in) :: fitpar
    ! Calls: hbook1, hf1
end subroutine FillHistParDist

FillHistParF

private subroutine FillHistParF (fitparMC, fitparB)
    type (fitpar_type), INTENT(in) :: fitparMC
    type (fitpar_type), INTENT(in) :: fitparB
    ! Calls: SetupHistCmpPar, hf2
end subroutine FillHistParF

FillHistPar0

private subroutine FillHistPar0 (fitparMC, fitpar)
    type (fitpar_type), INTENT(in) :: fitparMC
    type (fitpar_type), INTENT(in) :: fitpar
    ! Calls: SetupHistCmpPar, hf2
end subroutine FillHistPar0

rnd_uniform

private function rnd_uniform (a, b) result (ret)
    real, INTENT(in) :: a
            
 Return a random number uniformly distributed between a and b
    real, INTENT(in) :: b
            
 Return a random number uniformly distributed between a and b
    real :: ret
    ! Calls: random_number
end function rnd_uniform

rnd_gauss

private function rnd_gauss (mean, sigma) result (ret)
    real, INTENT(in) :: mean
            
 Return a random number with a gaussian distribution
    real, INTENT(in) :: sigma
            
 Return a random number with a gaussian distribution
    real :: ret
    ! Calls: random_number
end function rnd_gauss

rad2deg

private function rad2deg (a)
    real (kind=R8), INTENT(in) :: a
            
 Description: convert radians to degrees
    real (kind=R8) :: rad2deg
end function rad2deg

deg2rad

private function deg2rad (a)
    real (kind=R8), INTENT(in) :: a
            
 Description: convert degrees to radians
    real (kind=R8) :: deg2rad
end function deg2rad

jsign

private function jsign (a) result (ival)
    real (kind=R8), INTENT(in) :: a
            
 Description: return sign of a real(r8) number
 Returns: +1 if positive
          -1 if negative
           0 if zero
    integer :: ival
end function jsign

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

V3mag

private function V3mag (a)
    real (kind=R8), INTENT(in), dimension (3) :: a
            
 Description: compute vector length
    real (kind=R8) :: v3mag
end function V3mag

findz0

private function findz0 (hits, iend) result (z0)
    type (hits_type), INTENT(in) :: hits
            
 Arguments:

 hits array
    integer, INTENT(in) :: iend
             -1: return first hit - eps, +1: return last hit + eps
    real (kind=R8) :: z0
            
 Description: return z coordinate of first or last hit, according to iend
    ! Calls: die
end function findz0

findzmean

private function findzmean (hits) result (zmean)
    type (hits_type), INTENT(in) :: hits
            
 Arguments:

 hits array
    real (kind=R8) :: zmean
            
 Description: return the mean z coordinate of all hits
end function findzmean

SetupHists

private subroutine SetupHists ()
    ! Calls: hbook1, hbook2
end subroutine SetupHists

SetupHistCmpMC

private subroutine SetupHistCmpMC (base, prefix)
    integer, INTENT(in) :: base
    character (len=*), INTENT(in) :: prefix
    ! Calls: hbook1, hbook2
end subroutine SetupHistCmpMC

SetupHistCmpPar

private subroutine SetupHistCmpPar (base, prefix, partype, numpar)
    integer, INTENT(in) :: base
    character (len=*), INTENT(in) :: prefix
    integer, INTENT(in) :: partype
    integer, INTENT(in) :: numpar
    ! Calls: die, hbook2
end subroutine SetupHistCmpPar

SetupHistResiduals

private subroutine SetupHistResiduals ()
    ! Calls: hbook1, hbook2
end subroutine SetupHistResiduals

InitCov

private subroutine InitCov (cov)
    type (covariance_type), INTENT(out) :: cov
end subroutine InitCov

addCov

private subroutine addCov (cov, hits, lastplane, fitpar, res)
    type (covariance_type), INTENT(inout) :: cov
    type (hits_type), INTENT(in) :: hits
    integer, INTENT(in) :: lastplane
    type (fitpar_type), INTENT(in) :: fitpar
    type (residuals_type), INTENT(in) :: res
    ! Calls: die
end subroutine addCov

printCov

private subroutine printCov (cov)
    type (covariance_type), INTENT(in) :: cov
end subroutine printCov