Module efficiency_mod

module efficiency_mod

        ! Uses
    use precision_mod
    use det_geom_mod
    use calibrations_mod
    use chambers_mod
    use filters_mod
    use tdc_mod
    use unp_mod
    use kalman_mod
    use namelist_mod
    use cluster_mod
    use trackswim_mod
    use track_mod
    use pattern_mod
    use projections_mod
    use hists_mod
    use trackrange_mod
    use skim_mod

        ! Types
    private type EffCounters_type
    private type EffSideCounters_type

        ! Variables
    integer (kind=i4), private, PARAMETER :: nCellBins = 20
    type (EffCounters_type), private, dimension (max_planes_d) :: DCEffPlane
    type (EffCounters_type), private, dimension (max_planes_d,max_wires_d) :: DCEffWire
    type (EffCounters_type), private, dimension (nCellBins) :: DCEffCell
    type (EffCounters_type), private, dimension (max_planes_p) :: PCEffPlane
    type (EffCounters_type), private, dimension (max_planes_p,max_wires_p) :: PCEffWire
    type (EffCounters_type), private, dimension (nCellBins) :: PCEffCell
    real (kind=r4), private, dimension (MAX_PLANES_D) :: Zin
    real (kind=r4), private, dimension (MAX_PLANES_D) :: Zout
    real (kind=r8), private :: HelixChi2
    type (EffSideCounters_type), private, dimension (max_planes_d) :: DCEffSide
    type (EffSideCounters_type), private, dimension (max_planes_p) :: PCEffSide
    integer (kind=i4), private, dimension (2) :: pm_ti
    integer (kind=i4), private, dimension (2,2) :: pm_ilhz
    real (kind=r8), private, dimension (2,2) :: pm_z
    real (kind=r8), private, dimension (2) :: pm_deds
    real (kind=r8), private :: pm_r
    real (kind=r8), private, dimension (2) :: pm_zlimit
    real (kind=r8), private :: pm_theta
    logical, private, dimension (2) :: pm_usd

        ! Subroutines and functions
    private subroutine EffDC (iWindow, iTrack)
    private subroutine EffPC (iWindow, iTrack)
    public subroutine EffDCInit ()
    public subroutine EffPCInit ()
    public subroutine EffDCcalc (iWindow, iTrack)
    public subroutine EffPCcalc (iWindow, iTrack)
    public subroutine EffDCPrint ()
    public subroutine EffPCprint ()
    private function V3mag (a)
    public subroutine f09 (m, n, x, fvec, iflag)
    private subroutine diag_track (t1, z1, usd1, pmag1, ct1, ilhz, deds)
    private subroutine match_2_tracks (t1, t2, mind, minz, debug)
    public subroutine EFF_PAIR_MATCHING ()

end module efficiency_mod

Description of Types

EffCounters_type

private type EffCounters_type
    integer (kind=i4) :: present
    integer (kind=i4) :: expected
    logical :: found
end type EffCounters_type

EffSideCounters_type

private type EffSideCounters_type
    integer (kind=i4) :: Greater
    integer (kind=i4) :: Lower
    integer (kind=i4) :: Both
end type EffSideCounters_type

Description of Variables

nCellBins

integer (kind=i4), private, PARAMETER :: nCellBins = 20

DCEffPlane

type (EffCounters_type), private, dimension (max_planes_d) :: DCEffPlane

DCEffWire

type (EffCounters_type), private, dimension (max_planes_d,max_wires_d) :: DCEffWire

DCEffCell

type (EffCounters_type), private, dimension (nCellBins) :: DCEffCell

PCEffPlane

type (EffCounters_type), private, dimension (max_planes_p) :: PCEffPlane

PCEffWire

type (EffCounters_type), private, dimension (max_planes_p,max_wires_p) :: PCEffWire

PCEffCell

type (EffCounters_type), private, dimension (nCellBins) :: PCEffCell

Zin

real (kind=r4), private, dimension (MAX_PLANES_D) :: Zin

Zout

real (kind=r4), private, dimension (MAX_PLANES_D) :: Zout

HelixChi2

real (kind=r8), private :: HelixChi2

DCEffSide

type (EffSideCounters_type), private, dimension (max_planes_d) :: DCEffSide

PCEffSide

type (EffSideCounters_type), private, dimension (max_planes_p) :: PCEffSide

pm_ti

integer (kind=i4), private, dimension (2) :: pm_ti
 global variables for the pair matching

pm_ilhz

integer (kind=i4), private, dimension (2,2) :: pm_ilhz
 global variables for the pair matching

pm_z

real (kind=r8), private, dimension (2,2) :: pm_z

pm_deds

real (kind=r8), private, dimension (2) :: pm_deds

pm_r

real (kind=r8), private :: pm_r

pm_zlimit

real (kind=r8), private, dimension (2) :: pm_zlimit

pm_theta

real (kind=r8), private :: pm_theta

pm_usd

logical, private, dimension (2) :: pm_usd

Description of Subroutines and Functions

EffDC

private subroutine EffDC (iWindow, iTrack)
    integer (kind=i4) :: iWindow
    integer (kind=i4) :: iTrack
    ! Calls: EffDCCalc, EffDCInit
end subroutine EffDC
========================================================
 October 2000
--------------------------------------------------------
 DC Efficiency
========================================================

Author: Maher Quraan

EffPC

private subroutine EffPC (iWindow, iTrack)
    integer (kind=i4) :: iWindow
    integer (kind=i4) :: iTrack
    ! Calls: EffPCCalc, EffPCInit
end subroutine EffPC
========================================================
 October 2000
--------------------------------------------------------
 PC Efficiency
========================================================

Author: Maher Quraan

EffDCInit

public subroutine EffDCInit ()
end subroutine EffDCInit
========================================================
 October 2000
--------------------------------------------------------
 Initialize efficiency counters
========================================================

Author: Maher Quraan

EffPCInit

public subroutine EffPCInit ()
end subroutine EffPCInit
========================================================
 August 2001
--------------------------------------------------------
 Initialize efficiency counters
========================================================

Author: Sun-Chong Wang

EffDCcalc

public subroutine EffDCcalc (iWindow, iTrack)
    integer (kind=i4), INTENT(IN) :: iWindow
    integer (kind=i4), INTENT(IN) :: iTrack
    ! Calls: kerror
end subroutine EffDCcalc
========================================================
 October 2000
 August 2002, Marc Lalancette: Faster algorithm to find actual hits.
 September 2002, Alexandros Dimopoulos: modifications for helical tracks
--------------------------------------------------------
 Calculate DC Efficiency
========================================================

Author: Maher Quraan

EffPCcalc

public subroutine EffPCcalc (iWindow, iTrack)
    integer (kind=i4) :: iWindow
    integer (kind=i4) :: iTrack
    ! Calls: kerror
end subroutine EffPCcalc
========================================================
 August 2001
--------------------------------------------------------
 Calculate PC Efficiency. Copied from Maher's version
 August 2002, Marc Lalancette: Faster algorithm to find actual hits.
 September 2002, Alexandros Dimopoulos: modifications for helical tracks
========================================================

Author: Sun-Chong Wang

EffDCPrint

public subroutine EffDCPrint ()
    ! Calls: HPAK, HPAKE, HRESET, hf1
end subroutine EffDCPrint
========================================================
 October 2000
--------------------------------------------------------
 Print out DC efficiencies
========================================================

Author: Maher Quraan

EffPCprint

public subroutine EffPCprint ()
    ! Calls: HPAK, HPAKE, HRESET, hf1
end subroutine EffPCprint
========================================================
 August 2001
--------------------------------------------------------
 Print out PC efficiencies
========================================================

Author: Sun-Chong Wang

V3mag

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

f09

public subroutine f09 (m, n, x, fvec, iflag)
    integer :: m
    integer :: n
    real (kind=8), dimension (n) :: x
    real (kind=8), dimension (m) :: fvec
    integer :: iflag
end subroutine f09

diag_track

private subroutine diag_track (t1, z1, usd1, pmag1, ct1, ilhz, deds)
    integer :: t1
             -------------------------------------------------------
 some searching in track hits
    real (kind=r8), dimension (2) :: z1
    logical :: usd1
    real (kind=r8) :: pmag1
    real (kind=r8) :: ct1
    integer, dimension (2) :: ilhz
             -------------------------------------------------------
 some searching in track hits
    real (kind=r8) :: deds
end subroutine diag_track
 -------------------------------------------------------

match_2_tracks

private subroutine match_2_tracks (t1, t2, mind, minz, debug)
    integer :: t1
             trackwise
    integer :: t2
             trackwise
    real (kind=r8) :: mind
             for minimization
    real (kind=r8) :: minz
             for minimization
    logical :: debug
    ! Calls: diag_track, hf1, hf2, lmdif1
end subroutine match_2_tracks
 -------------------------------------------------------

EFF_PAIR_MATCHING

public subroutine EFF_PAIR_MATCHING ()
    ! Calls: match_2_tracks
end subroutine EFF_PAIR_MATCHING
 -------------------------------------------------------