Subroutine FillHelixTree

subroutine FillHelixTree

        ! Uses
    use calibrations_mod
    use track_mod
    use precision_mod
    use namelist_mod
    use pattern_mod
    use windowstat_mod
    use skim_mod
    use classify_mod
    use trackrange_mod
    use unp_mod
    use unpmc_mod
    use unpderiv_mod
    use chambers_mod
    use trackswim_mod
    use pact_mod
    use firstguess_mod
    use tracking_mod
    use helixfit_mod
    use classifybj_mod
    use det_geom_mod
    use windowbj_mod, ONLY: GetGlobalPlane
    use hists_mod, ONLY: FirstPCADC, LastPCADC
    use tec_mod

        ! Calls
    call AddToHeFitBranch
    call AddToWinBranch
    call AddToWinDCFirstLast
    call AddToWinStatBranch
    call AddtoFGFitBranch
    call FillEventBranch
    call FillMhitBranch
    call FillPACTBranch
    call FillPsPactBranch
    call FillPsPactTestBranch
    call FillWinHitWiresClusters
    call add_mc_vertex
    call filltree
    call makebranch
    call setbranchvar

        ! Variables
    logical, INTENT(in) :: eventSelected
    integer, save :: RTversion
    integer, save :: RTevType
    real, save :: RTm12width
    real, save, dimension (3) :: RTcptime
    real, save, dimension (3) :: RTrftime
    integer, save :: RTnwin
    integer, save :: RTntr
    integer, save :: RTpienuidx
    real, save, dimension (MaxWindows) :: RTwintime
    integer, save, dimension (MaxWindows) :: RTwintype
    integer, save, dimension (MaxWindows) :: RTwinflag
    real, save, dimension (MaxWindows) :: RTwinUfirst
    real, save, dimension (MaxWindows) :: RTwinVfirst
    integer, save, dimension (MaxWindows) :: RTwinPfirst
    real, save, dimension (MaxWindows) :: RTwinUlast
    real, save, dimension (MaxWindows) :: RTwinVlast
    integer, save, dimension (MaxWindows) :: RTwinPulast
    integer, save, dimension (MaxWindows) :: RTwinPvlast
    real, save, dimension (MaxWindows) :: RTtof
    real, save, dimension (MaxWindows) :: RTwinPCWidAvg
    integer, save, dimension (MaxTracks) :: RTwinidx
    real, save, dimension (MaxTracks) :: RTpu
    real, save, dimension (MaxTracks) :: RTpv
    real, save, dimension (MaxTracks) :: RTpz
    integer, save, dimension (MaxTracks) :: RTq
    real, save, dimension (MaxTracks) :: RTu
    real, save, dimension (MaxTracks) :: RTv
    real, save, dimension (MaxTracks) :: RTu0
    real, save, dimension (MaxTracks) :: RTv0
    real, save, dimension (MaxTracks) :: RTz
    integer, save, dimension (MaxTracks) :: RTpstart
    integer, save, dimension (MaxTracks) :: RTpstop
    real, save, dimension (MaxTracks) :: RTtime
    real, save, dimension (MaxTracks) :: RTchi2
    integer, save, dimension (MaxTracks) :: RTndof
    integer, save, dimension (MaxTracks) :: RTierror
    integer, save :: RTDkwinNcda
    real, save, dimension (MaxDkWinCDA) :: RTDkwincda
    real, save, dimension (MaxDkWinCDA) :: RTDkwincdaz
    real, save, dimension (MaxDkWinCDA) :: RTDkwincdadefl
    integer, save, dimension (MaxWindows) :: RTwinPUDCfirst
    integer, save, dimension (MaxWindows) :: RTwinPUDClast
    integer, save, dimension (MaxWindows) :: RTwinPVDCfirst
    integer, save, dimension (MaxWindows) :: RTwinPVDClast
    real, save, dimension (MaxWindows) :: RTwinUDCfirst
    real, save, dimension (MaxWindows) :: RTwinVDCfirst
    real, save, dimension (MaxWindows) :: RTwinUDClast
    real, save, dimension (MaxWindows) :: RTwinVDClast
    integer, save :: RTNfgtr
    integer, save, dimension (MaxTracks) :: RTfgwinidx
    real, save, dimension (MaxTracks) :: RTfgpu
    real, save, dimension (MaxTracks) :: RTfgpv
    real, save, dimension (MaxTracks) :: RTfgpz
    real, save, dimension (MaxTracks) :: RTfgu
    real, save, dimension (MaxTracks) :: RTfgv
    real, save, dimension (MaxTracks) :: RTfgz
    integer, save, dimension (MaxTracks) :: RTfgpstart
    integer, save, dimension (MaxTracks) :: RTfgpstop
    real, save, dimension (MaxTracks) :: RTfgtime
    real, save, dimension (MaxTracks) :: RTfgchi2
    integer, save, dimension (MaxTracks) :: RTfgndof
    integer, save, dimension (MaxTracks) :: RTfgndchits
    integer, save, dimension (MaxTracks) :: RTfgierror
    integer, save, dimension (MaxTracks) :: RTfgtype
    integer, save :: RTnMuScHits
    real, save, dimension (15) :: RTMuScTimes
    real, save, dimension (4) :: RTpcelost
    integer, save :: RTnpc5
    integer, save, dimension (max_wires_p) :: RTpc5wire
    real, save, dimension (max_wires_p) :: RTpc5time
    real, save, dimension (max_wires_p) :: RTpc5width
    integer, save :: RTnpc6
    integer, save, dimension (max_wires_p) :: RTpc6wire
    real, save, dimension (max_wires_p) :: RTpc6time
    real, save, dimension (max_wires_p) :: RTpc6width
    integer, save :: RTnpc7
    integer, save, dimension (max_wires_p) :: RTpc7wire
    real, save, dimension (max_wires_p) :: RTpc7time
    real, save, dimension (max_wires_p) :: RTpc7width
    integer, save :: RTnpc8
    integer, save, dimension (max_wires_p) :: RTpc8wire
    real, save, dimension (max_wires_p) :: RTpc8time
    real, save, dimension (max_wires_p) :: RTpc8width
    integer, save, dimension (MaxWindows) :: RTwinnumDC
    integer, save, dimension (MaxWindows) :: RTwinnumPC
    real, save, dimension (MaxWindows) :: RTwinmaxuv
    real, save, dimension (MaxWindows) :: RTwinUavg
    real, save, dimension (MaxWindows) :: RTwinVavg
    real, save, dimension (MaxWindows) :: RTwinUsig
    real, save, dimension (MaxWindows) :: RTwinVsig
    real, save, dimension (MaxWindows) :: RTwinHitspp
    real, save, dimension (MaxWindows) :: RTwinClArea
    real, save, dimension (MaxWindows) :: RTwinDCWidAvg
    real, save, dimension (MaxWindows) :: RTpctsig
    integer, save, dimension (MaxWindows) :: RTUpDenseStart
    integer, save, dimension (MaxWindows) :: RTDnDenseStart
    integer, save, dimension (MaxTracks) :: RTfitnumU
    integer, save, dimension (MaxTracks) :: RTfitnumV
    integer, save, dimension (MaxTracks) :: RTfitnunused
    integer, save, dimension (MaxTracks) :: RTfitmissing
    real, save, dimension (MaxTracks) :: RTlastpu
    real, save, dimension (MaxTracks) :: RTlastpv
    real, save, dimension (MaxTracks) :: RTlastpz
    real, save, dimension (MaxTracks) :: RTlastu
    real, save, dimension (MaxTracks) :: RTlastv
    real, save, dimension (MaxTracks) :: RTlastz
    integer, save, dimension (MaxTracks) :: RTfgfitnumU
    integer, save, dimension (MaxTracks) :: RTfgfitnumV
    integer, save, dimension (MaxTracks) :: RTfgfitnunused
    integer, save, dimension (MaxTracks) :: RTfgfitmissing
    real, save :: RTspin3
    integer, save :: RTnMcTr
    integer, save, dimension (kMaxMcTracks) :: RTmcitrack
    integer, save, dimension (kMaxMcTracks) :: RTmcpid
    integer, save, dimension (kMaxMcTracks) :: RTmcvoff
    integer, save, dimension (kMaxMcTracks) :: RTmcnv
    integer, save :: RTnMcVtx
    real, save, dimension (kMaxMcTracks) :: RTmcvptot
    real, save, dimension (kMaxMcTracks) :: RTmcvcosth
    real, save, dimension (kMaxMcTracks) :: RTmcvphi
    real, save, dimension (kMaxMcTracks) :: RTmcvtime
    real, save, dimension (kMaxMcTracks) :: RTmcvu
    real, save, dimension (kMaxMcTracks) :: RTmcvv
    real, save, dimension (kMaxMcTracks) :: RTmcvz
    integer, save, dimension (kMaxMcTracks) :: RTmcvstop
    real, save, dimension (10) :: RTEventUser
    real, save, dimension (MaxWindows) :: RTWinUser1
    real, save, dimension (MaxWindows) :: RTWinUser2
    real, save, dimension (MaxWindows) :: RTWinUser3
    real, save, dimension (MaxWindows) :: RTWinUser4
    real, save, dimension (MaxTracks) :: RTTrackUser1
    real, save, dimension (MaxTracks) :: RTTrackUser2
    real, save, dimension (MaxTracks) :: RTTrackUser3
    real, save, dimension (MaxTracks) :: RTTrackUser4
    real, save, dimension (kMaxMcTracks) :: RTMCTrackUser1
    real, save, dimension (kMaxMcTracks) :: RTMCTrackUser2
    real, save, dimension (kMaxMcTracks) :: RTMCTrackUser3
    real, save, dimension (kMaxMcTracks) :: RTMCTrackUser4
    integer, save, dimension (13) :: RTWinMuonHitWiresPC
    integer, save, dimension (45) :: RTWinMuonHitWiresDC
    integer, save, dimension (13) :: RTWinDecayHitWiresPC
    integer, save, dimension (45) :: RTWinDecayHitWiresDC
    integer, save, dimension (13) :: RTWinMuonClustersPC
    integer, save, dimension (45) :: RTWinMuonClustersDC
    integer, save, dimension (13) :: RTWinDecayClustersPC
    integer, save, dimension (45) :: RTWinDecayClustersDC
    integer, save, dimension (13) :: RTEventHitWiresPC
    integer, save, dimension (45) :: RTEventHitWiresDC
    integer, save, dimension (13) :: RTEventClustersPC
    integer, save, dimension (45) :: RTEventClustersDC
    integer (kind=i4), dimension (MaxWindows) :: RTwindow
    integer (kind=i4), dimension (MaxTracks) :: RTfitdcmin
    integer (kind=i4), dimension (MaxTracks) :: RTfitdcmax
    integer (kind=i4), dimension (MaxTracks) :: RTfgfitdcmin
    integer (kind=i4), dimension (MaxTracks) :: RTfgfitdcmax
    integer (kind=i4), dimension (MaxTracks) :: RTfgfitpcmin
    integer (kind=i4), dimension (MaxTracks) :: RTfgfitpcmax
    real (kind=r8) :: pmag
    real (kind=r8) :: mcpmag
    real (kind=r8) :: pz
    real (kind=r8) :: mcpz
    real (kind=r8), dimension (3) :: fgp
    real (kind=r8), dimension (3) :: fgv
    real (kind=r8) :: ztgt
    integer (kind=i4) :: fgq
    integer (kind=i4) :: fgfit
    real (kind=r4), dimension (MaxClPerPr) :: u
    real (kind=r4), dimension (MaxClPerPr) :: v
    real (kind=r4) :: r
    real (kind=r4) :: rmin
    integer :: irmin
    integer (kind=i4) :: ifit
    integer (kind=i4) :: ifitneg
    integer (kind=i4) :: ibadfit
    integer (kind=i4) :: i
    integer (kind=i4) :: icount
    integer (kind=i4) :: icda
    logical :: newtrack
    integer (kind=i4) :: goodfitierr
    integer (kind=i4) :: nMuSc
    integer (kind=i4) :: iSChit
    integer (kind=i4) :: iScint
    real (kind=r4) :: tdc_time
    integer (kind=i4) :: dcidx
    integer (kind=i4) :: pcidx
    integer (kind=i4) :: ipcplane
    integer (kind=i4) :: idcplane
    integer (kind=i4) :: firstP
    logical :: firsthit
    integer (kind=i4) :: SelectWin
    integer (kind=i4) :: InWin
    integer (kind=i4) :: ihit
    integer (kind=i4) :: iwire
    integer (kind=i4) :: iplane
    integer (kind=i4), dimension (4) :: npcADChits
    real (kind=r4) :: tdc_width
    logical :: foundhelixfit
    logical :: gotfit
    integer (kind=i4) :: imc
    integer (kind=i4) :: imcmc
    integer (kind=i4) :: imctrack
    integer (kind=i4) :: isp
    real (kind=r8), dimension (3) :: spV
    real (kind=r8), dimension (3) :: spP
    real (kind=r4) :: spVx
    real (kind=r4) :: spVy
    real (kind=r4) :: muscintz
    real (kind=r4) :: tgtz
    logical :: foundmusp
    logical :: foundesp
    integer (kind=i4) :: ipcwin
    integer (kind=i4) :: istr
    integer (kind=i4) :: RTnE
    integer (kind=i4) :: RTnDK
    integer (kind=i4) :: RTnMu
    logical :: foundmufit
    logical :: foundefit
    logical, SAVE :: firstTime = .true.
    integer :: imcwin
    integer :: iwindow
    integer :: idel
    integer (kind=i4) :: ipair
    integer (kind=i4) :: nCl
    integer (kind=i4) :: iCl
    real (kind=r8) :: areasum
    real (kind=r4) :: areaavg
    real (kind=R8) :: FGptot
    real (kind=R8) :: FGcosth
    integer (kind=i4) :: wtype
    integer (kind=i4) :: stopplane
    integer (kind=i4) :: ncptime
    integer (kind=i4) :: nrftime
    integer :: curr_itrack

        ! Subroutines and functions
    subroutine AddToFGFitBranch ()
    subroutine AddToHeFitBranch ()
    subroutine AddToWinDCFirstLast (inwin)
    subroutine AddToWinBranch ()
    subroutine AddToWinStatBranch ()
    subroutine FillMhitBranch ()
    subroutine FillEventBranch ()
    subroutine FillPsPactBranch ()
    subroutine FillPsPactTestBranch ()
    subroutine FillPACTBranch ()
    subroutine FillWinUVVertex (ivplane, firstp, uv, vv)
    subroutine add_mc_vertex (itreetrack, imc)
    subroutine FillWinHitWiresClusters ()

end subroutine FillHelixTree
 SUBROUTINE FillHelixTree( eventselected )
------------------------------------------------------------------------------
 FillHelixTree is the main steering subroutine for filling the
 helix ROOT tree.  As an argument, this fill routine takes a logical
 which is true if this event was selected for analysis. To enable this tree
 set the namelist variables:
  name RootTree enableRootTree = .true.
  name RootTree RootTreeType = 0

 This subroutine fills a Root Tree with information for production
 running.  Optional information can be added to the trees by enabling
 the appropriate namelist flag:
  name RootTree
   RootTreeEnableUser            =.false. ! Write "user" arrays
   RootTreeEnableMCBankOutput    =.false. ! Write MC bank arrays
   RootTreeEnableMicheldOutput   =.false. ! Write MC micheld information
   RootTreeMCSelectedEventsOnly  =.false. ! Write out MC bank arrays only for selected events (otherwise all events)
   RootTreeEnableFGOutput        =.false. ! Write First guess arrays
   RootTreeEnableMHitsOutput     =.false. ! Write M Scint TDC hit arrays
   RootTreeEnablePactOutput      =.false. ! Write Pact Energy arrays
   RootTreeEnableWinStatOutput   =.false. ! Write extra Window statistics arrays
   RootTreeEnableHeFitNHitsOutput=.false. ! Write helix fit hit count arrays
   RootTreeEnableFgFitNHitsOutput=.false. ! Write first guess fit hit count arrays
   RootTreeMuonDecayFitOnly      =.false. ! Write only muon and decay fits
   RootTreeMuonDecayWinOnly      =.false. ! Write only muon and decay windows
   RootTreeSelectedEventsOnly    =.false. ! Write only selected events (otherwise all events)
   RootTreeEnableAlStudy         =.false. ! Write out data for looking at downstream aluminum events

 This Root Tree can have multiple tracks per window.  Each track
 has an index to the window it sits in.  To save space, and avoid
 introducing time dependent bugs, no indicies are written out.  You
 will have to do some processing to figure out which track goes
 with which information, and which MC vertex goes with which fit track,
 etc...

  ! Variable in Code                        Root Tree Variable              Description
  ! ----------------                        ------------------              -----------
  INTEGER :: nrun                           EVID_nrun                       run number
  INTEGER :: nevt                           EVID_nevt                       event number
  INTEGER :: RTversion                      Event_treeversion               tree version
  INTEGER :: Event_timestamp                Event_timestamp                 time of event since 00:00:00 1970-01-01 UTC
  INTEGER :: RTevType                       Event_type                      event type
  REAL    :: RTm12width                     Event_m12width                  M Counter Analog Sum ADC Width (ns)
  REAL    :: RTcptime(3)                    Event_cptime[3]                 TCAP (ns)
  REAL    :: RTrftime(3)                    Event_rftime[3]                 RFTOF (ns)
  INTEGER :: RTnwin                         Event_nwin                      number of windows in tree
  INTEGER :: RTntr                          Event_ntr                       number of helix fits in tree
  INTEGER :: RTpienuidx                     Event_pienuitr                  index into hefit of possible pienutrack
  REAL    :: RTwintime(MaxWindows)          Win_time[Nwin]                  window time
  INTEGER :: RTwintype(MaxWindows)          Win_type[Nwin]                  window type    
  INTEGER :: RTwinflag(MaxWindows)          Win_flag[Nwin]                  window classification flag    
  REAL    :: RTwinUfirst(MaxWindows)        Win_ufirst[Nwin]                u coordinate of first plane in window (cm) 
  REAL    :: RTwinVfirst(MaxWindows)        Win_vfirst[Nwin]                v coordinate of first plane in window (cm)     
  INTEGER :: RTwinPfirst(MaxWindows)        Win_pfirst[Nwin]                global plane number of first plane in window   
  REAL    :: RTwinUlast(MaxWindows)         Win_ulast[Nwin]                 u coordinate of last u plane in window (cm) 
  REAL    :: RTwinVlast(MaxWindows)         Win_vlast[Nwin]                 v coordinate of last v plane in window (cm)        
  INTEGER :: RTwinPulast(MaxWindows)        Win_pulast[Nwin]                global plane number of last u plane in window   
  INTEGER :: RTwinPvlast(MaxWindows)        Win_pvlast[Nwin]                global plane number of last v plane in window   
  REAL    :: RTtof(MaxWindows)              Win_pctof[nwin]                 pc time of flight estimate in window (ns)
  REAL    :: RTwinPCWidAvg(MaxWindows)      Win_pcwidthavg[nwin]            pc TDC width average in window (ns)
  INTEGER :: RTwinidx(MaxTracks)            Hefit_winidx[Ntr]               index to window this helix fit is for
  REAL    :: RTpu(MaxTracks)                Hefit_pu[Ntr]                   fit u momentum at pstart (MeV/c)
  REAL    :: RTpv(MaxTracks)                Hefit_pv[Ntr]                   fit v momentum at pstart (MeV/c)
  REAL    :: RTpz(MaxTracks)                Hefit_pz[Ntr]                   fit z momentum at pstart (MeV/c)
  INTEGER :: RTq(MaxTracks)                 Hefit_q[Ntr]                    fit charge
  REAL    :: RTu(MaxTracks)                 Hefit_u[Ntr]                    fit u coordinate at Hefit_z (cm)
  REAL    :: RTv(MaxTracks)                 Hefit_v[Ntr]                    fit v coordinate at Hefit_z (cm)
  REAL    :: RTz(MaxTracks)                 Hefit_z[Ntr]                    fit z coordinate at Hefit_z (cm)
  INTEGER :: RTpstart(MaxTracks)            Hefit_pstart[Ntr]               first global plane used for helix fit
  INTEGER :: RTpstop(MaxTracks)             Hefit_pstop[Ntr]                last global plane used for helix fit
  REAL    :: RTtime(MaxTracks)              Hefit_time[Ntr]                 fit time (ns)
  REAL    :: RTchi2(MaxTracks)              Hefit_chi2[Ntr]                 fit chi-squared
  INTEGER :: RTndof(MaxTracks)              Hefit_ndof[Ntr]                 fit number of degrees of freedom
  INTEGER :: RTierror(MaxTracks)            Hefit_ierror[Ntr]               fit status code (ierror)

 !
 ! ---->>>> name roottree RootTreeEnableTECFit = t <<<<----
 REAL,   save:: TCa0(2)                    !TEC_xy0(2)                       element 1= x(0), element 2= y(0)
 REAL,   save:: TCa1(2)                    !TEC_tanthxy(2)                   element 1= tan(theta_x), element 2= tan(theta_y)
 REAL,   save:: TCsd(2)                    !TEC_sigma(2)                     don't know but it looks useful (cm?)
 
 !
 !---->>>> name roottree RootTreeEnableTECHits = t <<<<----
 INTEGER,save:: TCnhit                     !TEC_nhits                        number of TEC hits
 REAL,   save:: TCTIM(MaxTCHit)            !TEC_time(TEC_nhits)              times of TEC hits (ns?)
 REAL,   save:: TCWID(MaxTCHit)            !TEC_width(TEC_nhits)             widths of TEC hits (ns")
 REAL,   save:: TCZPOS(MaxTCHit)           !TEC_z(TEC_nhits)                 z position of TEC hits (cm?)

 !
 !---->>>> name roottree RootTreeEnableTECExtras = t <<<<----
 INTEGER,save:: nhits_in_scin              !nhits_in_scin                    number of hits in trigger scintillator
 INTEGER,save:: failed_cptof_m12           !failed_cptof_m12                 did you fail the M12/CPTOF selection? 0 = false, 1 = true
 REAL,   save:: TC_xy_TWIST(MaxTCHit)      !TC_xy_TWIST(TEC_nhits)           x or y position for the hit, in TWIST co-ordinates
 INTEGER,save:: global_wire(MaxTCHit)      !global_wire(TEC_nhits)           wire number, from 1 to 48 (i.e. tells you module as well!)

  ! 
  ! ---->>>> name roottree RootTreeEnableFirstLastDC = t <<<<----
  INTEGER :: RTwinPDCfirst(MaxWindows)      Win_pdcfirst[Nwin]             dc plane number of first plane in window
  INTEGER :: RTwinPDClast(MaxWindows)       Win_pdclast[Nwin]              dc plane number of last plane in window
  REAL    :: RTwinUDCfirst(MaxWindows)      Win_udcfirst[Nwin]             u coordinate of first DC u plane in window (cm)
  REAL    :: RTwinVDCfirst(MaxWindows)      Win_vdcfirst[Nwin]             v coordinate of first DC v plane in window (cm)
  REAL    :: RTwinUDClast(MaxWindows)       Win_udcfirst[Nwin]             u coordinate of last DC u plane in window (cm)
  REAL    :: RTwinVDClast(MaxWindows)       Win_vdclast[Nwin]              v coordinate of last DC v plane in window (cm)

  !   
  ! ---->>>> name roottree RootTreeEnableFGOutput = t <<<<----
  INTEGER :: RTNfgtr                        Nfgtr                           number of first guess fits in tree
  INTEGER :: RTfgwinidx(MaxTracks)          Fgfit_winidx[Nfgtr]             index to window this fgfit is for
  REAL    :: RTfgpu(MaxTracks)              Fgfit_pu[Nfgtr]                 fgfit u momentum at pstart (MeV/c)
  REAL    :: RTfgpv(MaxTracks)              Fgfit_pv[Nfgtr]                 fgfit v momentum at pstart (MeV/c)
  REAL    :: RTfgpz(MaxTracks)              Fgfit_pz[Nfgtr]                 fgfit z momentum at pstart (MeV/c)
  REAL    :: RTfgu(MaxTracks)               Fgfit_u[Nfgtr]                  fgfit u coordinate at z (cm)
  REAL    :: RTfgv(MaxTracks)               Fgfit_v[Nfgtr]                  fgfit v coordinate at z (cm)
  REAL    :: RTfgz(MaxTracks)               Fgfit_z[Nfgtr]                  fgfit z coordinate at z (cm)
  INTEGER :: RTfgpstart(MaxTracks)          Fgfit_pstart[Nfgtr]             first global plane used for fgfit
  INTEGER :: RTfgpstop(MaxTracks)           Fgfit_pstop[Nfgtr]              last global plane used for fgfit
  REAL    :: RTfgtime(MaxTracks)            Fgfit_time[Nfgtr]               fgfit time (ns)
  REAL    :: RTfgchi2(MaxTracks)            Fgfit_chi2[Nfgtr]               fgfit chi-squared
  INTEGER :: RTfgndof(MaxTracks)            Fgfit_ndof[Nfgtr]               fgfit number of degrees of freedom
  INTEGER :: RTfgndchits(MaxTracks)         Fgfit_ndchits[Nfgtr]            fgfit number dc hits in window
  INTEGER :: RTfgierror(MaxTracks)          Fgfit_ierror[Nfgtr]             fgfit status code (ierror)
  INTEGER :: RTfgtype(MaxTracks)            Fgfit_type[Nfgtr]               fgfit type of firstguess
  !
  ! ---->>>> name roottree RootTreeEnableMHitsOutput = t <<<<----
  INTEGER :: RTnMuScHits                    Nmhits                          number of M counter TDC hits in tree
  REAL    :: RTMuScTimes(15)                Mhit_time[Nmhits]               M counter hit times (ns)
  !
  ! ---->>>> name roottree RootTreeEnablePactOutput = t <<<<----
  REAL    :: RTpcelost(4)                   Pact_elost[4]                   PACT energy lost by muon estimate (units?)
  !
  ! ---->>>> name roottree RootTreeEnableWinStatOutput = t <<<<----
  INTEGER :: RTwinnumDC(MaxWindows)         Win_numdc[nwin]                 number of dc hits in window
  INTEGER :: RTwinnumPC(MaxWindows)         Win_numpc[nwin]                 number of pc hits in window
  REAL    :: RTwinmaxuv(MaxWindows)         Win_maxuv[nwin]                 largest u or v coordinate in window (cm)
  REAL    :: RTwinUavg(MaxWindows)          Win_uavg[nwin]                  average u coordinate in window (cm)
  REAL    :: RTwinVavg(MaxWindows)          Win_vavg[nwin]                  average v coordinate in window (cm)
  REAL    :: RTwinUsig(MaxWindows)          Win_usig[nwin]                  sigma of u hit coords in window (cm)
  REAL    :: RTwinVsig(MaxWindows)          Win_vsig[nwin]                  sigma of v hit coords in window (cm)
  REAL    :: RTwinHitspp(MaxWindows)        Win_hitspp[nwin]                average hits per plane in window (cm)
  REAL    :: RTwinClArea(MaxWindows)        Win_clareaavg[nwin]             average cluster area in window (cm)  
  REAL    :: RTwinDCWidAvg(MaxWindows)      Win_dcwidthavg[nwin]            dc TDC width average in window (ns)
  REAL    :: RTpctsig(MaxWindows)           Win_pctsig[nwin]                sigma of pc times in window (ns)
  INTEGER,save::RTUpDenseStart(MaxWindows)     !Win_up_dense_start[nwin]        flag denoting DenseStart call and success upstream
  INTEGER,save::RTDnDenseStart(MaxWindows)     !Win_dn_dense_start[nwin]        flag denoting DenseStart call and success downstream!!  !
  ! ---->>>> name roottree TreeEnableHeFitNHitsOutput = t <<<<----
  INTEGER :: RTfitnumU(MaxTracks)           Hefit_numu[ntr]                number of u hits used in helix fit 
  INTEGER :: RTfitnumV(MaxTracks)           Hefit_numv[ntr]                number of v hits used in helix fit 
  INTEGER :: RTfitnunused(MaxTracks)        Hefit_nunused[ntr]             number of unused hits for helix fit
  INTEGER :: RTfitmissing(MaxTracks)        Hefit_nmissingpl[ntr]          number of missing planes for helix fit
  !
  ! ---->>>> name roottree RootTreeEnableHeFitLastHitOutput = t <<<<----
  REAL    :: RTlastpu(MaxTracks)            Hefit_lastpu[Ntr]              fit u momentum at pstop (MeV/c)
  REAL    :: RTlastpv(MaxTracks)            Hefit_lastpv[Ntr]              fit v momentum at pstop (MeV/c)
  REAL    :: RTlastpz(MaxTracks)            Hefit_lastpz[Ntr]              fit z momentum at pstop (MeV/c)
  REAL    :: RTlastu(MaxTracks)             Hefit_lastu[Ntr]               fit u coordinate at Hefit_lastz (cm)
  REAL    :: RTlastv(MaxTracks)             Hefit_lastv[Ntr]               fit v coordinate at Hefit_lastz (cm)
  REAL    :: RTlastz(MaxTracks)             Hefit_lastz[Ntr]               fit z coordinate at Hefit_lastz (cm)
  !
  ! ---->>>> name roottree RootTreeEnableFgFitNHitsOutput = t <<<<----
  INTEGER :: RTfgfitnumU(MaxTracks)         Fgfit_numu[nfgtr]              number of u hits used in fgfit 
  INTEGER :: RTfgfitnumV(MaxTracks)         Fgfit_numv[nfgtr]              number of v hits used in fgfit 
  INTEGER :: RTfgfitnunused(MaxTracks)      Fgfit_nunused[nfgtr]           number of unused hits for fgfit
  INTEGER :: RTfgfitmissing(MaxTracks)      Fgfit_nmissingpl[ntr]          number of missing planes for fgfit
  !
  ! ---->>>> name roottree RootTreeEnableMCBankOutput = t <<<<----
  ! MCSet is controled by either RootTreeEnableMCBankOutput or RootTreeEnableMicheldOutput.
  INTEGER :: spectrum                      MCSet_spectrum                  MC michel spectrum number
  INTEGER :: sample                        MCSet_sample                    MC michel sample number
  INTEGER :: numMicheldDecays              MCSet_ndecays                   MC number of muons
  REAL     :: RTspin3                       MCSet_spin3                     MC z comp of spin for trigger muon
  !    
  INTEGER :: RTnMcTr                        Nmctr                           number of MC tracks in tree
  !
  INTEGER :: RTmcitrack(kMaxMcTracks)          Mctrack_itrack[Nmctr]           itrack of mc track
  INTEGER :: RTmcpid(kMaxMcTracks)             Mctrack_pid[Nmctr]              GEANT particle type of mc track
  INTEGER :: RTmcvoff(kMaxMcTracks)            Mctrack_voff[Nmctr]             offset into MC vertex array of this track
  INTEGER :: RTmcnv(kMaxMcTracks)              Mctrack_nv[Nmctr]               number of MC vertices for this track
  !
  INTEGER :: RTnMcVtx                       Nmcvtx                          number of MC vertices in tree
  !
  REAL    :: RTmcvptot(kMaxMcTracks)           MCVertex_ptot[Nmcvtx]           MC vertex total momentum (MeV/c)
  REAL    :: RTmcvcosth(kMaxMcTracks)          MCVertex_costh[Nmcvtx]          MC vertex cos theta
  REAL    :: RTmcvphi(kMaxMcTracks)            MCVertex_phimuv[Nmcvtx]         MC vertex phi from momentum in u,v coords (rad)
  REAL    :: RTmcvtime(kMaxMcTracks)           MCVertex_time[Nmcvtx]           MC time (ns)
  REAL    :: RTmcvu(kMaxMcTracks)              MCVertex_vu[Nmcvtx]             u coordinate of vertex (cm) 
  REAL    :: RTmcvv(kMaxMcTracks)              MCVertex_vv[Nmcvtx]             v coordinate of vertex (cm)
  REAL    :: RTmcvz(kMaxMcTracks)              MCVertex_vz[Nmcvtx]             z coordinate of vertex (cm)
  INTEGER :: RTmcvstop(kMaxMcTracks)           MCVertex_istop[Nmcvtx]          MC istop code
  !
  ! ---->>>> name roottree RootTreeEnableMicheldOutput = t <<<<----
  ! MCSet is controled by either RootTreeEnableMCBankOutput or RootTreeEnableMicheldOutput.
  INTEGER :: spectrum                      MCSet_spectrum                  MC michel spectrum number
  INTEGER :: sample                        MCSet_sample                    MC michel sample number
  INTEGER :: numMicheldDecays              MCSet_ndecays                   MC number of muons
  REAL    :: RTspin3                       MCSet_spin3                     MC z comp of spin for trigger muon
  !
  INTEGER :: micheldItrack                 MichelD_itrack[MCSet_decays]    itrack of mc track
  INTEGER :: micheldAccFlag                MichelD_accflag[MCSet_ndecays]  michel spectrum fitter histogramming code
  !
  !  ---->>>> name roottree RootTreeUserEnable = t <<<<----
  REAL    :: RTEventUser(10)                event_user[10]                  user variables
  REAL    :: RTWinUser1(MaxWindows)         win_user1[nwin]    
  REAL    :: RTWinUser2(MaxWindows)         win_user2[nwin]    
  REAL    :: RTWinUser3(MaxWindows)         win_user3[nwin]          
  REAL    :: RTWinUser4(MaxWindows)         win_user4[nwin]    
  REAL    :: RTTrackUser1(kMaxMcTracks)        track_user1[ntr]  
  REAL    :: RTTrackUser2(kMaxMcTracks)        track_user2[ntr]  
  REAL    :: RTTrackUser3(kMaxMcTracks)        track_user3[ntr]  
  REAL    :: RTTrackUser4(kMaxMcTracks)        track_user4[ntr]  
  REAL    :: RTMCTrackUser1(kMaxMcTracks)      mctrack_user1[nmctr]
  REAL    :: RTMCTrackUser2(kMaxMcTracks)      mctrack_user2[nmctr]
  REAL    :: RTMCTrackUser3(kMaxMcTracks)      mctrack_user3[nmctr]
  REAL    :: RTMCTrackUser4(kMaxMcTracks)      mctrack_user4[nmctr]

  !  ---->>>> name roottree RootTreeEnableAlStudy = t <<<<----
  INTEGER    :: RTWinMuonHitWiresPC(13)     Win_muon_hit_wires_PC[13]          number of hit wires in muon window PCs
  INTEGER    :: RTWinMuonHitWiresDC(45)     Win_muon_hit_wires_DC[45]          number of hit wires in muon window DCs
  INTEGER    :: RTWinDecayHitWiresPC(13)    Win_decay_hit_wires_PC[13]         number of hit wires in decay window PCs
  INTEGER    :: RTWinDecayHitWiresDC(45)    Win_decay_hit_wires_DC[45]         number of hit wires in decay window DCs
  INTEGER    :: RTWinMuonClustersPC(13)     Win_muon_clusters_PC[13]            number of clusters in muon window PCs
  INTEGER    :: RTWinMuonClustersDC(45)     Win_muon_clusters_DC[45]            number of clusters in muon window DCs
  INTEGER    :: RTWinDecayClustersPC(13)    Win_decay_clusters_PC[13]         number of clusters in decay window PCs
  INTEGER    :: RTWinDecayClustersDC(45)    Win_decay_clusters_DC[45]         number of clusters in decay window DCs
  INTEGER    :: RTEventHitWiresPC(13)       Event_hit_wires_PC[13]            number of hit wires in PCs for event
  INTEGER    :: RTEventHitWiresDC(45)       Event_hit_wires_DC[45]            number of hit wires in DCs for event
  INTEGER    :: RTEventClustersPC(13)       Event_clusters_PC[13]            number of clusters in PCs for event
  INTEGER    :: RTEventClustersDC(45)       Event_clusters_DC[45]            number of clusters in DCs for event

------------------------------------------------------------------------------------------------------
 Author: Blair Jamieson
 Date: March 2004                                             

Description of Variables

eventSelected

logical, INTENT(in) :: eventSelected

RTversion

integer, save :: RTversion
!! EVID Branch
!! Event Branch

RTevType

integer, save :: RTevType

RTm12width

real, save :: RTm12width

RTcptime

real, save, dimension (3) :: RTcptime

RTrftime

real, save, dimension (3) :: RTrftime

RTnwin

integer, save :: RTnwin

RTntr

integer, save :: RTntr

RTpienuidx

integer, save :: RTpienuidx

RTwintime

real, save, dimension (MaxWindows) :: RTwintime
!! Win Branch

RTwintype

integer, save, dimension (MaxWindows) :: RTwintype

RTwinflag

integer, save, dimension (MaxWindows) :: RTwinflag

RTwinUfirst

real, save, dimension (MaxWindows) :: RTwinUfirst

RTwinVfirst

real, save, dimension (MaxWindows) :: RTwinVfirst

RTwinPfirst

integer, save, dimension (MaxWindows) :: RTwinPfirst

RTwinUlast

real, save, dimension (MaxWindows) :: RTwinUlast

RTwinVlast

real, save, dimension (MaxWindows) :: RTwinVlast

RTwinPulast

integer, save, dimension (MaxWindows) :: RTwinPulast

RTwinPvlast

integer, save, dimension (MaxWindows) :: RTwinPvlast

RTtof

real, save, dimension (MaxWindows) :: RTtof

RTwinPCWidAvg

real, save, dimension (MaxWindows) :: RTwinPCWidAvg

RTwinidx

integer, save, dimension (MaxTracks) :: RTwinidx
!! Hefit Branch          

RTpu

real, save, dimension (MaxTracks) :: RTpu

RTpv

real, save, dimension (MaxTracks) :: RTpv

RTpz

real, save, dimension (MaxTracks) :: RTpz

RTq

integer, save, dimension (MaxTracks) :: RTq

RTu

real, save, dimension (MaxTracks) :: RTu

RTv

real, save, dimension (MaxTracks) :: RTv

RTu0

real, save, dimension (MaxTracks) :: RTu0

RTv0

real, save, dimension (MaxTracks) :: RTv0

RTz

real, save, dimension (MaxTracks) :: RTz

RTpstart

integer, save, dimension (MaxTracks) :: RTpstart

RTpstop

integer, save, dimension (MaxTracks) :: RTpstop

RTtime

real, save, dimension (MaxTracks) :: RTtime

RTchi2

real, save, dimension (MaxTracks) :: RTchi2

RTndof

integer, save, dimension (MaxTracks) :: RTndof

RTierror

integer, save, dimension (MaxTracks) :: RTierror

RTDkwinNcda

integer, save :: RTDkwinNcda

RTDkwincda

real, save, dimension (MaxDkWinCDA) :: RTDkwincda

RTDkwincdaz

real, save, dimension (MaxDkWinCDA) :: RTDkwincdaz

RTDkwincdadefl

real, save, dimension (MaxDkWinCDA) :: RTDkwincdadefl

RTwinPUDCfirst

integer, save, dimension (MaxWindows) :: RTwinPUDCfirst

RTwinPUDClast

integer, save, dimension (MaxWindows) :: RTwinPUDClast

RTwinPVDCfirst

integer, save, dimension (MaxWindows) :: RTwinPVDCfirst

RTwinPVDClast

integer, save, dimension (MaxWindows) :: RTwinPVDClast

RTwinUDCfirst

real, save, dimension (MaxWindows) :: RTwinUDCfirst

RTwinVDCfirst

real, save, dimension (MaxWindows) :: RTwinVDCfirst

RTwinUDClast

real, save, dimension (MaxWindows) :: RTwinUDClast

RTwinVDClast

real, save, dimension (MaxWindows) :: RTwinVDClast

RTNfgtr

integer, save :: RTNfgtr
!! Nfgtr Branch

RTfgwinidx

integer, save, dimension (MaxTracks) :: RTfgwinidx
!! Fgfit Branch

RTfgpu

real, save, dimension (MaxTracks) :: RTfgpu

RTfgpv

real, save, dimension (MaxTracks) :: RTfgpv

RTfgpz

real, save, dimension (MaxTracks) :: RTfgpz

RTfgu

real, save, dimension (MaxTracks) :: RTfgu

RTfgv

real, save, dimension (MaxTracks) :: RTfgv

RTfgz

real, save, dimension (MaxTracks) :: RTfgz

RTfgpstart

integer, save, dimension (MaxTracks) :: RTfgpstart

RTfgpstop

integer, save, dimension (MaxTracks) :: RTfgpstop

RTfgtime

real, save, dimension (MaxTracks) :: RTfgtime

RTfgchi2

real, save, dimension (MaxTracks) :: RTfgchi2

RTfgndof

integer, save, dimension (MaxTracks) :: RTfgndof

RTfgndchits

integer, save, dimension (MaxTracks) :: RTfgndchits

RTfgierror

integer, save, dimension (MaxTracks) :: RTfgierror

RTfgtype

integer, save, dimension (MaxTracks) :: RTfgtype

RTnMuScHits

integer, save :: RTnMuScHits
!! Nmhits Branch

RTMuScTimes

real, save, dimension (15) :: RTMuScTimes
!! Mhit Branch

RTpcelost

real, save, dimension (4) :: RTpcelost
!! Pact Branch

RTnpc5

integer, save :: RTnpc5
!! Pseudo Pact Branch

RTpc5wire

integer, save, dimension (max_wires_p) :: RTpc5wire

RTpc5time

real, save, dimension (max_wires_p) :: RTpc5time

RTpc5width

real, save, dimension (max_wires_p) :: RTpc5width

RTnpc6

integer, save :: RTnpc6

RTpc6wire

integer, save, dimension (max_wires_p) :: RTpc6wire

RTpc6time

real, save, dimension (max_wires_p) :: RTpc6time

RTpc6width

real, save, dimension (max_wires_p) :: RTpc6width

RTnpc7

integer, save :: RTnpc7
!! Pseudo Pact Test Branch

RTpc7wire

integer, save, dimension (max_wires_p) :: RTpc7wire

RTpc7time

real, save, dimension (max_wires_p) :: RTpc7time

RTpc7width

real, save, dimension (max_wires_p) :: RTpc7width

RTnpc8

integer, save :: RTnpc8

RTpc8wire

integer, save, dimension (max_wires_p) :: RTpc8wire

RTpc8time

real, save, dimension (max_wires_p) :: RTpc8time

RTpc8width

real, save, dimension (max_wires_p) :: RTpc8width

RTwinnumDC

integer, save, dimension (MaxWindows) :: RTwinnumDC
!! Winstat Branch

RTwinnumPC

integer, save, dimension (MaxWindows) :: RTwinnumPC

RTwinmaxuv

real, save, dimension (MaxWindows) :: RTwinmaxuv

RTwinUavg

real, save, dimension (MaxWindows) :: RTwinUavg

RTwinVavg

real, save, dimension (MaxWindows) :: RTwinVavg

RTwinUsig

real, save, dimension (MaxWindows) :: RTwinUsig

RTwinVsig

real, save, dimension (MaxWindows) :: RTwinVsig

RTwinHitspp

real, save, dimension (MaxWindows) :: RTwinHitspp

RTwinClArea

real, save, dimension (MaxWindows) :: RTwinClArea

RTwinDCWidAvg

real, save, dimension (MaxWindows) :: RTwinDCWidAvg

RTpctsig

real, save, dimension (MaxWindows) :: RTpctsig

RTUpDenseStart

integer, save, dimension (MaxWindows) :: RTUpDenseStart

RTDnDenseStart

integer, save, dimension (MaxWindows) :: RTDnDenseStart

RTfitnumU

integer, save, dimension (MaxTracks) :: RTfitnumU
!! Xhefit Branch

RTfitnumV

integer, save, dimension (MaxTracks) :: RTfitnumV

RTfitnunused

integer, save, dimension (MaxTracks) :: RTfitnunused

RTfitmissing

integer, save, dimension (MaxTracks) :: RTfitmissing

RTlastpu

real, save, dimension (MaxTracks) :: RTlastpu

RTlastpv

real, save, dimension (MaxTracks) :: RTlastpv

RTlastpz

real, save, dimension (MaxTracks) :: RTlastpz

RTlastu

real, save, dimension (MaxTracks) :: RTlastu

RTlastv

real, save, dimension (MaxTracks) :: RTlastv

RTlastz

real, save, dimension (MaxTracks) :: RTlastz

RTfgfitnumU

integer, save, dimension (MaxTracks) :: RTfgfitnumU
!! Xfgfit Branch

RTfgfitnumV

integer, save, dimension (MaxTracks) :: RTfgfitnumV

RTfgfitnunused

integer, save, dimension (MaxTracks) :: RTfgfitnunused

RTfgfitmissing

integer, save, dimension (MaxTracks) :: RTfgfitmissing

RTspin3

real, save :: RTspin3
!! MCSet Branch

RTnMcTr

integer, save :: RTnMcTr
!! Nmctr Branch 

RTmcitrack

integer, save, dimension (kMaxMcTracks) :: RTmcitrack
!! MCTrack Branch

RTmcpid

integer, save, dimension (kMaxMcTracks) :: RTmcpid

RTmcvoff

integer, save, dimension (kMaxMcTracks) :: RTmcvoff

RTmcnv

integer, save, dimension (kMaxMcTracks) :: RTmcnv

RTnMcVtx

integer, save :: RTnMcVtx
!! Nmcvtx Branch

RTmcvptot

real, save, dimension (kMaxMcTracks) :: RTmcvptot
!! MCVertex Branch

RTmcvcosth

real, save, dimension (kMaxMcTracks) :: RTmcvcosth

RTmcvphi

real, save, dimension (kMaxMcTracks) :: RTmcvphi

RTmcvtime

real, save, dimension (kMaxMcTracks) :: RTmcvtime

RTmcvu

real, save, dimension (kMaxMcTracks) :: RTmcvu

RTmcvv

real, save, dimension (kMaxMcTracks) :: RTmcvv

RTmcvz

real, save, dimension (kMaxMcTracks) :: RTmcvz

RTmcvstop

integer, save, dimension (kMaxMcTracks) :: RTmcvstop

RTEventUser

real, save, dimension (10) :: RTEventUser
!! MichelD Branch
 (These variables come directly from unpderiv_mod.f90 so they don't need to be declared here.)

RTWinUser1

real, save, dimension (MaxWindows) :: RTWinUser1

RTWinUser2

real, save, dimension (MaxWindows) :: RTWinUser2

RTWinUser3

real, save, dimension (MaxWindows) :: RTWinUser3

RTWinUser4

real, save, dimension (MaxWindows) :: RTWinUser4

RTTrackUser1

real, save, dimension (MaxTracks) :: RTTrackUser1

RTTrackUser2

real, save, dimension (MaxTracks) :: RTTrackUser2

RTTrackUser3

real, save, dimension (MaxTracks) :: RTTrackUser3

RTTrackUser4

real, save, dimension (MaxTracks) :: RTTrackUser4

RTMCTrackUser1

real, save, dimension (kMaxMcTracks) :: RTMCTrackUser1

RTMCTrackUser2

real, save, dimension (kMaxMcTracks) :: RTMCTrackUser2

RTMCTrackUser3

real, save, dimension (kMaxMcTracks) :: RTMCTrackUser3

RTMCTrackUser4

real, save, dimension (kMaxMcTracks) :: RTMCTrackUser4

RTWinMuonHitWiresPC

integer, save, dimension (13) :: RTWinMuonHitWiresPC

RTWinMuonHitWiresDC

integer, save, dimension (45) :: RTWinMuonHitWiresDC

RTWinDecayHitWiresPC

integer, save, dimension (13) :: RTWinDecayHitWiresPC

RTWinDecayHitWiresDC

integer, save, dimension (45) :: RTWinDecayHitWiresDC

RTWinMuonClustersPC

integer, save, dimension (13) :: RTWinMuonClustersPC

RTWinMuonClustersDC

integer, save, dimension (45) :: RTWinMuonClustersDC

RTWinDecayClustersPC

integer, save, dimension (13) :: RTWinDecayClustersPC

RTWinDecayClustersDC

integer, save, dimension (45) :: RTWinDecayClustersDC

RTEventHitWiresPC

integer, save, dimension (13) :: RTEventHitWiresPC

RTEventHitWiresDC

integer, save, dimension (45) :: RTEventHitWiresDC

RTEventClustersPC

integer, save, dimension (13) :: RTEventClustersPC

RTEventClustersDC

integer, save, dimension (45) :: RTEventClustersDC

RTwindow

integer (kind=i4), dimension (MaxWindows) :: RTwindow

RTfitdcmin

integer (kind=i4), dimension (MaxTracks) :: RTfitdcmin

RTfitdcmax

integer (kind=i4), dimension (MaxTracks) :: RTfitdcmax

RTfgfitdcmin

integer (kind=i4), dimension (MaxTracks) :: RTfgfitdcmin

RTfgfitdcmax

integer (kind=i4), dimension (MaxTracks) :: RTfgfitdcmax

RTfgfitpcmin

integer (kind=i4), dimension (MaxTracks) :: RTfgfitpcmin

RTfgfitpcmax

integer (kind=i4), dimension (MaxTracks) :: RTfgfitpcmax

pmag

real (kind=r8) :: pmag

mcpmag

real (kind=r8) :: mcpmag

pz

real (kind=r8) :: pz

mcpz

real (kind=r8) :: mcpz

fgp

real (kind=r8), dimension (3) :: fgp

fgv

real (kind=r8), dimension (3) :: fgv

ztgt

real (kind=r8) :: ztgt

fgq

integer (kind=i4) :: fgq

fgfit

integer (kind=i4) :: fgfit

u

real (kind=r4), dimension (MaxClPerPr) :: u

v

real (kind=r4), dimension (MaxClPerPr) :: v

r

real (kind=r4) :: r

rmin

real (kind=r4) :: rmin

irmin

integer :: irmin

ifit

integer (kind=i4) :: ifit

ifitneg

integer (kind=i4) :: ifitneg

ibadfit

integer (kind=i4) :: ibadfit

i

integer (kind=i4) :: i

icount

integer (kind=i4) :: icount

icda

integer (kind=i4) :: icda

newtrack

logical :: newtrack

goodfitierr

integer (kind=i4) :: goodfitierr

nMuSc

integer (kind=i4) :: nMuSc

iSChit

integer (kind=i4) :: iSChit

iScint

integer (kind=i4) :: iScint

tdc_time

real (kind=r4) :: tdc_time

dcidx

integer (kind=i4) :: dcidx

pcidx

integer (kind=i4) :: pcidx

ipcplane

integer (kind=i4) :: ipcplane

idcplane

integer (kind=i4) :: idcplane

firstP

integer (kind=i4) :: firstP

firsthit

logical :: firsthit

SelectWin

integer (kind=i4) :: SelectWin

InWin

integer (kind=i4) :: InWin

ihit

integer (kind=i4) :: ihit

iwire

integer (kind=i4) :: iwire

iplane

integer (kind=i4) :: iplane

npcADChits

integer (kind=i4), dimension (4) :: npcADChits

tdc_width

real (kind=r4) :: tdc_width

foundhelixfit

logical :: foundhelixfit

gotfit

logical :: gotfit

imc

integer (kind=i4) :: imc

imcmc

integer (kind=i4) :: imcmc

imctrack

integer (kind=i4) :: imctrack

isp

integer (kind=i4) :: isp

spV

real (kind=r8), dimension (3) :: spV

spP

real (kind=r8), dimension (3) :: spP

spVx

real (kind=r4) :: spVx

spVy

real (kind=r4) :: spVy

muscintz

real (kind=r4) :: muscintz

tgtz

real (kind=r4) :: tgtz

foundmusp

logical :: foundmusp

foundesp

logical :: foundesp

ipcwin

integer (kind=i4) :: ipcwin

istr

integer (kind=i4) :: istr

RTnE

integer (kind=i4) :: RTnE

RTnDK

integer (kind=i4) :: RTnDK

RTnMu

integer (kind=i4) :: RTnMu

foundmufit

logical :: foundmufit

foundefit

logical :: foundefit

firstTime

logical, SAVE :: firstTime = .true.

imcwin

integer :: imcwin

iwindow

integer :: iwindow

idel

integer :: idel

ipair

integer (kind=i4) :: ipair

nCl

integer (kind=i4) :: nCl

iCl

integer (kind=i4) :: iCl

areasum

real (kind=r8) :: areasum

areaavg

real (kind=r4) :: areaavg

FGptot

real (kind=R8) :: FGptot

FGcosth

real (kind=R8) :: FGcosth

wtype

integer (kind=i4) :: wtype

stopplane

integer (kind=i4) :: stopplane

ncptime

integer (kind=i4) :: ncptime

nrftime

integer (kind=i4) :: nrftime

curr_itrack

integer :: curr_itrack

Description of Subroutines and Functions

AddToFGFitBranch

subroutine AddToFGFitBranch ()
    ! Calls: ConvertFGZtoVPQ, GetGlobalPlane
end subroutine AddToFGFitBranch

AddToHeFitBranch

subroutine AddToHeFitBranch ()
    ! Calls: GetGlobalPlane
end subroutine AddToHeFitBranch

AddToWinDCFirstLast

subroutine AddToWinDCFirstLast (inwin)
    integer (kind=i4), INTENT(in) :: inwin
    ! Calls: FillWinDCUVPVertex
end subroutine AddToWinDCFirstLast

AddToWinBranch

subroutine AddToWinBranch ()
    ! Calls: FillWinUVPVertex
end subroutine AddToWinBranch

AddToWinStatBranch

subroutine AddToWinStatBranch ()
end subroutine AddToWinStatBranch

FillMhitBranch

subroutine FillMhitBranch ()
end subroutine FillMhitBranch

FillEventBranch

subroutine FillEventBranch ()
end subroutine FillEventBranch

FillPsPactBranch

subroutine FillPsPactBranch ()
end subroutine FillPsPactBranch

FillPsPactTestBranch

subroutine FillPsPactTestBranch ()
end subroutine FillPsPactTestBranch

FillPACTBranch

subroutine FillPACTBranch ()
end subroutine FillPACTBranch

FillWinUVVertex

subroutine FillWinUVVertex (ivplane, firstp, uv, vv)
    integer (kind=i4), INTENT(IN) :: ivplane
    logical, INTENT(IN) :: firstp
    real (kind=r4), INTENT(OUT) :: uv
    real (kind=r4), INTENT(OUT) :: vv
end subroutine FillWinUVVertex

add_mc_vertex

subroutine add_mc_vertex (itreetrack, imc)
    integer :: itreetrack
    integer :: imc
end subroutine add_mc_vertex

FillWinHitWiresClusters

subroutine FillWinHitWiresClusters ()
end subroutine FillWinHitWiresClusters
----------------------------------------------------------------------------

----------------------------------------------------------------------------