Module pact_mod 
module pact_mod
        ! Uses
    use precision_mod
    use det_geom_mod
    use chambers_mod
    use tdc_mod
    use unp_mod
    use filters_mod
    use namelist_mod
    use hists_mod
    use calibrations_mod
    use pattern_mod
    use trackrange_mod
    use unpmc_mod
        ! Types
    public type pact_type
    private type pact_tests
        ! Variables
    integer (kind=i4), private :: DCsum
    integer (kind=i4), private :: PCsum
    real (kind=r4), private :: SCsum
    type (pact_tests), private, DIMENSION(FirstPCADC:LastPCADC,48) :: pact_hits
    type (pact_type), public, DIMENSION(FirstPCADC:LastPCADC) :: pact
    logical, private :: Z1SS
    logical, private :: Z1SM
    logical, private :: Z1MS
    logical, private :: Z1MM
    logical, private :: Z2SS
    logical, private :: Z2SM
    logical, private :: Z2MS
    logical, private :: Z2MM
    logical, private :: Z3SS
    logical, private :: Z3SM
    logical, private :: Z3MS
    logical, private :: Z3MM
        ! Subroutines and functions
    public subroutine PACTanalysis (Anal_Fail)
    private function TDChit (iPlane, iWire, iWindow)
    public subroutine PACTrawHists ()
    public subroutine PACThists ()
end module pact_mod
 =================================================================
  Marc Lalancette, July 2002
  Revamped March 2003, DRG to use more modern windowing etc.
  Revamped again Jan. 06 to analyse MC study data.
  Revised/created June 06 to analyse incomimg psPact data
  ----------------------------------------------------------------
  This module contains PACT calculations and histograms
  Note that finding a stop in PC6 finds very few events that fit
    all the cuts.  It is sensitive to a few namelist variables:
  * Time zero needs to be adjusted (roughly) with triggertime;
  * dc_mintdc_cut and pc_mintdc_cut should be adjusted so window 2
     is the trigger window (-400. works ok);
  * Everything except windowing can be turned off.
 =================================================================
 Analysis failure code histo 19099
  1 - e_lost < EnergyCut(kcm = 100.0).
  2 - no matching TDC hit on this wire.
  3 - tdc hit is after the end of pact time.
  4 - tdc hit is probably noise/xtalk.
  5 - all tdc hits before pact gate time.
  6 - PACT hits not adjacent.
  7 - Not adjacent hit had higher energy.
  8 - Not adjacent hit had e_lost < EnergyCut.
  9 - Not adjacent hit had less energy than accumulated so far.
 10 - More than PactClusterMax=10 PACT hits on this plane.
 ======================
 PC6 stop failure code - histo 19107(PC6)
  1 - Window(mu)%t0 > 100.0
  2 - No Pact 5 hit found
  3 - No Pact 6 hit found
  4 - PC hits in Window(3)
  5 - > 3 DC hits in Window(3)
  6 - TRmaxR(mu) > 3.5
  7 - TRmaxZ(mu) < -0.4 - Didn't make it to PC6
  8 - TRmaxZ(mu) > 0.0 - Went beyond PC6
  9 - TRminZ(e+) > 0.0 - e+ did not begin in PC6
 10 - TRminZ(e+) < -0.4 - e+ came from upstream of PC6
 11 - Had e+ hit on PC6 outside 3 nearest neighbors (either side).
 12 - no e+ hit in PC6
 
 =================================================================
 Description of Types 
pact_type
public type pact_type
    logical :: Found
    logical :: TooMany
    real (kind=r4) :: Energy
    real (kind=r4) :: EnergyPlus
    logical :: Multiple
    integer (kind=i4), dimension (48) :: Wire
    integer (kind=i4) :: Cluster_center
    integer (kind=i4) :: nfound
end type pact_type
pact_tests
private type pact_tests
    logical :: NotFound
    logical :: NoTDCMatch
end type pact_tests
 Description of Variables 
DCsum
integer (kind=i4), private :: DCsum
PCsum
integer (kind=i4), private :: PCsum
SCsum
real (kind=r4), private :: SCsum
pact_hits
type (pact_tests), private, DIMENSION(FirstPCADC:LastPCADC,48) :: pact_hits
pact
type (pact_type), public, DIMENSION(FirstPCADC:LastPCADC) :: pact
Z1SS
logical, private :: Z1SS
Z1SM
logical, private :: Z1SM
Z1MS
logical, private :: Z1MS
Z1MM
logical, private :: Z1MM
Z2SS
logical, private :: Z2SS
Z2SM
logical, private :: Z2SM
Z2MS
logical, private :: Z2MS
Z2MM
logical, private :: Z2MM
Z3SS
logical, private :: Z3SS
Z3SM
logical, private :: Z3SM
Z3MS
logical, private :: Z3MS
Z3MM
logical, private :: Z3MM
 Description of Subroutines and Functions 
PACTanalysis
public subroutine PACTanalysis (Anal_Fail)
    logical :: Anal_Fail
    ! Calls: hff1, hff2
end subroutine PACTanalysis
TDChit
private function TDChit (iPlane, iWire, iWindow)
    integer (kind=i4), INTENT(IN) :: iPlane
    integer (kind=i4), INTENT(IN) :: iWire
    integer (kind=i4), INTENT(IN) :: iWindow
    integer (kind=i4) :: TDChit
    ! Calls: hff1
end function TDChit
PACTrawHists
public subroutine PACTrawHists ()
    ! Calls: HF1, hff1, hff2
end subroutine PACTrawHists
PACThists
public subroutine PACThists ()
    ! Calls: hf2, hff1, hff2
end subroutine PACThists