*file member=anxx_count_com library=snoman language=inc date=08:Nov:2004
     
 <<<*     ANX: ANXX Banks Processor. General Counters for second-stage cuts.
     
    *     Contact:  M. Huang, Texas
     
    *     Program Notes:-
    *     =============
     
    *     Revision History:-
    *     ================
     
    *     5.01  M. Huang     First version.
    *           N. McCauley  Increase number of time periods
    *           C. Kyba      Add QHS/QLX gain ratio counter
    *           N. McCauley  Add variables for improved orphan check.
     
    ************************************************************************
    *    Following variable are for general COUNTs                         *
    *      npmt : total number of tubes (or channels)                      *
    *      ntag : total bits used for tagging                              *
    *      nperiod : number of periods used in low occ count               *
    *      time_interval : duration of every period used in low_occ        *
    *      tot_hits    : accumulate all pmt hits from all events           *
    *      tac_count   : count how many events TAC falling within cuts     *
    *      qhs_count   : count how many events QHS falling within cuts     *
    *      qhl_count   : count how many events QHL falling within cuts     *
    *      tac_lo_count: count how many events that tac < tac_lo           *
    *      tac_hi_count: count how many events that tac > tac_hi           *
    *      qhs_lo_count: count how many events that qhs < qhs_lo           *
    *      qhs_hi_count: count how many events that qhs > qhs_hi           *
    *      qhl_lo_count: count how many events that qhl < qhl_lo           *
    *      qhl_hi_count: count how many events that qhl > qhl_hi           *
    *      qlx_lo_count: count how many events that qlx < qlx_lo           *
    *      qlx_hi_count: count how many events that qlx > qlx_hi           *
    *      gr_count    : count how many hits with bad gain ratio           *
    *      gr_occ      : count how many hits with qhs>80                   *
    *      occ_count   : count hits for each pmt (for TAC, QHS, QHL, QLX)  *
    *      low_occ_rate_count: count occ_rate in each period               *
    *      low_occ_rate_cut  : criterion cuts in each period for low occ   *
    *      orphan_hit_count : count how many times a pmt been hit when     *
    *                         an event is reported as orphan               *
    *      sync_clear_err   : check sync clear error for each pmt          *
    *      cell_err    : if cell number out of order, incremented by 1     *
    *      cell_correct: if cell number in order, incremented by 1         *
    *      cell_flag   : to flag if cell number incremented properly       *
    *      low_occ_count : count hits for each pmt for low occ calculation *
    *      high_occ_count: count hits for each pmt for high occ calc.      *
    *      event_low_occ_count : accumulate hits for low occ calculation   *
    *      event_high_occ_count: accumulate hits for high occ calculation  *
    ************************************************************************
     
          integer npmt, ntag, nperiod, num_bin_low_occ, max_num_bin,
         +        nperiod_orphan
          parameter (npmt = 9727, ntag = 31, nperiod = 500,
         +           max_num_bin = 1000, nperiod_orphan = 5000)
          real    tot_hits(0:npmt)
          real    tac_count(0:npmt), qhs_count(0:npmt), qhl_count(0:npmt),
         +        qlx_count(0:npmt),
         +        tac_lo_count(0:npmt), tac_hi_count(0:npmt),
         +        qhs_lo_count(0:npmt), qhs_hi_count(0:npmt),
         +        qhl_lo_count(0:npmt), qhl_hi_count(0:npmt),
         +        qlx_lo_count(0:npmt), qlx_hi_count(0:npmt),
         +        gr_count(0:npmt),     gr_occ(0:npmt),
         +        occ_count(0:npmt),
         +        low_occ_count(0:npmt,nperiod+1), high_occ_count(0:npmt),
         +        orphan_hit_count(0:npmt), sync_clear_err(3,0:npmt),
         +        cell_err(0:npmt), cell_correct(0:npmt),
         +        event_low_occ_count, event_high_occ_count,
         +        elapse_time, time_interval, frac1, frac2,
         +        low_occ_rate_count(max_num_bin,nperiod+1),
         +        low_occ_rate_cut(nperiod+1)
          integer iperiod_orphan,iperiod_orphan_max,
         +        orphan_hit_count_period(0:npmt,nperiod_orphan),
         +        non_orphan_hit_count_period(0:npmt,nperiod_orphan)
     
          logical cell_flag(0:npmt), first_cell_call(0:npmt)
     
          common /anxx_count_com/
         +        num_bin_low_occ, tot_hits,
         +        tac_count, qhs_count, qhl_count, qlx_count,
         +        tac_lo_count, tac_hi_count,
         +        qhs_lo_count, qhs_hi_count,
         +        qhl_lo_count, qhl_hi_count,
         +        qlx_lo_count, qlx_hi_count,
         +        gr_count,     gr_occ,
         +        occ_count, low_occ_count, high_occ_count,
         +        orphan_hit_count, sync_clear_err,
         +        cell_err, cell_correct,
         +        event_low_occ_count, event_high_occ_count,
         +        elapse_time, time_interval, frac1, frac2,
         +        low_occ_rate_count, low_occ_rate_cut,
         +        iperiod_orphan,iperiod_orphan_max,
         +        orphan_hit_count_period,non_orphan_hit_count_period,
         +        cell_flag, first_cell_call
     
    *endfile member=anxx_count_com