MVD ADCM cluster algorithm

               written by      Takahiro Fusayasu

---

1. Pedestal subtraction:

     PedSub(i) = ADC(i) - PED(i).   ( i=strip id )

     if ADC(i) < PED(i), PedSub(i) is set to zero.

     For dead channels, PED(i) should be set as 0x3FF(maximum),

     so that PedSud(i)=0.

2. Common mode subtraction:

     N(good strips) = N(strips per helix)(i.e.128) - N(dead channels)

     Common = sum(PED(i)| i=0 to 127)/N(good strips)      (for each HELIX).

     ComSub(i) = PedSub(i) - Common


3. Clustering using Threshold for each strip.

  a) strip i is "beginning of a cluster" if one of 3 cases below.

      1) ( ComSub(i-1) <= Thresh(i-1) ) &&
         ( ComSub(i)   <= Thresh(i)   ) &&
         ( ComSub(i+1) >  Thresh(i+1) )

      2) ( i==0 i.e. silicon edge ) &&
         ( ComSub(i)   <= Thresh(i)   ) &&
         ( ComSub(i+1) >  Thresh(i+1) )

      3) ( i==0 i.e. silicon edge ) &&
         ( ComSub(i) > Thresh(i) )

  b) Similarly, strip j is "end of a cluster" if one of 3 cases below.

      1) ( ComSub(j-1) >  Thresh(j-1) ) &&
         ( ComSub(j)   <= Thresh(j)   ) &&
         ( ComSub(j+1) <= Thresh(j+1) )

      2) ( ComSub(j-1) >  Thresh(j-1) ) &&
         ( ComSub(j)   <= Thresh(j)   ) &&
         ( j==511 i.e. silicon edge )

      3) ( ComSub(j) > Thresh(j) ) &&
         ( j==511 i.e. silicon edge )

  c) Then, strips i to j make one cluster.

  Here, a strip with a value below threshold is also included into
  the cluster if the neighbouring strip has a value above threshold.
  By this, we can avoid division of a cluster due to only
  one dead channel. That is, if (i-1) is above threshold,
  (i) is below (might be due to dead strip), and (i+1) is above, 
  then we think (i-1) to (i+1) are members of the same cluster.

4. Cut on Cluster.

    if( ( End#-Begin#+1 (cluster length)  > 16 ) ||
        ( sum( ComSub(i)| i=Begin# to End# ) > Cluster threshold ) )
    {
        the Cluster is acceped.
    }

99. At the same time, we also analyze trailer bits.

  At least on of the trailer bits is 0, because the maximum pipeline ID
  is smaller than 0xFF. So, we take the minimum value of ADC counts
  for 8 trailer bits as "Baseline":  Baseline = min(ADC(i)|i=128 to 135)

     if( ADC(i) > Baseline + 64 ){
         TRAIL_BIT(i) = 1
     } else {
         TRAIL_BIT(i) = 0
     }

  At the moment, the threshold "64" is fixed, but I am going to
  modify the circuit such that we can change it when setups.

---