Difference between revisions of "CDC algo"

From GlueXWiki
Jump to: navigation, search
Line 7: Line 7:
 
*Leading edge time (11 bits, units of sample/10)
 
*Leading edge time (11 bits, units of sample/10)
 
*Time quality factor (1 bit) set to 0 if time is good, 1 if time is rough estimate
 
*Time quality factor (1 bit) set to 0 if time is good, 1 if time is rough estimate
*Pedestal immediately before the hit (8 bits, set to 255 if >254)
+
*Pedestal immediately before the hit (8 bits, all bits set if value > field max)
 
*Signal integral (n bits, scaled down by factor 2^m, all bits set if greater than range; n,m are 14,4)
 
*Signal integral (n bits, scaled down by factor 2^m, all bits set if greater than range; n,m are 14,4)
 
*Signal maximum (p bits, scaled down by factor 2^q; p,q approx 8,2)  this is the first maximum in the signal after the threshold crossing
 
*Signal maximum (p bits, scaled down by factor 2^q; p,q approx 8,2)  this is the first maximum in the signal after the threshold crossing
Line 16: Line 16:
 
<h2>Configuration constants (all values are integers, σ=pedestal width ~20)</h2>
 
<h2>Configuration constants (all values are integers, σ=pedestal width ~20)</h2>
  
*NPED: number of samples in pedestal window (default 16)
+
*NPED: number of samples in pedestal window (default 16, must be 2**integer)
*WINDOW_START: sample number of first sample in hit search window, this is immediately after the pedestal window
+
*WINDOW_START: position in buffer of first sample in hit search window, this is immediately after the pedestal window
*WINDOW_END: last sample in hit search window
+
*WINDOW_END: position in buffer of last sample in hit search window
 
*HIT_THRES: threshold to identify hit (default 5σ ~100, range 50 to 300)
 
*HIT_THRES: threshold to identify hit (default 5σ ~100, range 50 to 300)
 
*NSAMPLES: number of ADC samples in subset to pass to time finding module (default 15)
 
*NSAMPLES: number of ADC samples in subset to pass to time finding module (default 15)
 
*XTHR_SAMPLE: position in subset of first sample above hit_threshold (default 9, starts with 0)
 
*XTHR_SAMPLE: position in subset of first sample above hit_threshold (default 9, starts with 0)
 
*PED_SAMPLE: position in subset of sample to be used as local pedestal (default 5, starts with 0)
 
*PED_SAMPLE: position in subset of sample to be used as local pedestal (default 5, starts with 0)
 +
 +
  
 
<h2>Timing algorithm configuration constants</h2>
 
<h2>Timing algorithm configuration constants</h2>
 
*HIGH_THRESHOLD: High timing threshold (default 4σ ~ 80, range 40 to 270) must be lower than hit threshold
 
*HIGH_THRESHOLD: High timing threshold (default 4σ ~ 80, range 40 to 270) must be lower than hit threshold
 
*LOW_THRESHOLD: Low timing threshold (default 1σ ~ 20, range 5 to 30)
 
*LOW_THRESHOLD: Low timing threshold (default 1σ ~ 20, range 5 to 30)
*ROUGH_DT: rough time - if timing fails, return hit time of xthr_sample-RT (default 24, units sample/10)
+
*ROUGH_DT: rough time - if timing fails, return hit time of XTHR_SAMPLE - ROUGH_DT (default 24, units sample/10)
 
*INT_SAMPLE: if timing fails, start integration with this sample (default 6).
 
*INT_SAMPLE: if timing fails, start integration with this sample (default 6).
 
*NUPSAMPLED: number of upsampled values to calculate (default 8)
 
*NUPSAMPLED: number of upsampled values to calculate (default 8)
Line 34: Line 36:
 
*SET_ADC_MIN: reduce chances of calculating a negative upsampled value by adding a constant offset to the subset values such that the minimum is equal to SET_ADC_MIN (default 20)
 
*SET_ADC_MIN: reduce chances of calculating a negative upsampled value by adding a constant offset to the subset values such that the minimum is equal to SET_ADC_MIN (default 20)
 
*LIMIT_UPS_ERR: do not calculate accurate time if the sum of the error of the 2 upsampled values exceeds this (default 30)
 
*LIMIT_UPS_ERR: do not calculate accurate time if the sum of the error of the 2 upsampled values exceeds this (default 30)
 +
  
 
<h2>Hit finding module</h2>
 
<h2>Hit finding module</h2>
  
#Wake up on trigger
+
#Calculate start_pedestal as mean of NPED samples from WINDOW_START-NPED-1 to WINDOW_START-1
#Calculate start_pedestal as mean of 4 samples window_start-5 to window_start-1
+
#Search from WINDOW_START to WINDOW_END for ADC value >= start_pedestal + HIT_THRES.  If not found, go back to sleep. If found, continue, this is sample X.
#Search from window_start to window_end for ADC value rising above start_pedestal + hit_threshold.  If not found, go back to sleep. If found, continue.
+
#Call up time-finding module and send in NSAMPLES ADC values from the hit threshold crossing region, with the first sample >= HIT_THRES in position XTHR_SAMPLE (starting at 0)
#Call up time-finding module and send in nsamples ADC values from the hit threshold crossing region, with the threshold-crossing sample x as value number xthr_sample in the sequence (starting at 0)
+
 
#Call up signal maximum module
 
#Call up signal maximum module
 
#Call up signal integral module
 
#Call up signal integral module
#Return local_pedestal as value of sample (x + ped_sample - xthr_sample), or 255 if local_pedestal>254
+
#Return pedestal_at_hit as mean of NPED samples ending with sample (X + ped_sample - xthr_sample), or 255 if value > field max
 
#Return integral and overflow count from integral module
 
#Return integral and overflow count from integral module
 
#Return q_code from time module
 
#Return q_code from time module
Line 51: Line 53:
  
 
<h2>Time finding module</h2>
 
<h2>Time finding module</h2>
This returns an error code q_code and the hit time, relative to the threshold-crossing sample time
+
This returns an error code q_code and the hit time, relative to the first sample in the subset.
 +
If the timing fails before upsampling (eg LIMIT_PED_MAX or LIMIT_ADC_MAX are exceeded) then the algorithm returns XTHR_SAMPLE - ROUGH_DT.
 +
If the timing fails after upsampling (eg LIMIT_UPS_ERR is exceeded) then the algorithm returns the midpoint of the samples before and after the LOW_THRESHOLD crossing.
 +
 
 
#Calculate thresholds from constants and local_pedestal, which is sent in as in sample number ped_sample
 
#Calculate thresholds from constants and local_pedestal, which is sent in as in sample number ped_sample
 
#Search the samples from ped_sample+1 to nsamples-1 for value >= high_threshold + local_pedestal. If this threshold is not exceeded, return bit q_code=1 and time x*10-rough_dt
 
#Search the samples from ped_sample+1 to nsamples-1 for value >= high_threshold + local_pedestal. If this threshold is not exceeded, return bit q_code=1 and time x*10-rough_dt

Revision as of 17:39, 28 January 2015

CDC time & integral algorithm

When the trigger signal arrives, the presample buffer contains NP (default value 16) samples for pedestal followed by NW (default 100, possibly up to 155) samples to contain full range of drift time.


Quantities to be returned, if a hit is found

  • Leading edge time (11 bits, units of sample/10)
  • Time quality factor (1 bit) set to 0 if time is good, 1 if time is rough estimate
  • Pedestal immediately before the hit (8 bits, all bits set if value > field max)
  • Signal integral (n bits, scaled down by factor 2^m, all bits set if greater than range; n,m are 14,4)
  • Signal maximum (p bits, scaled down by factor 2^q; p,q approx 8,2) this is the first maximum in the signal after the threshold crossing
  • Overflow count (3 bits, set to 7 if >6)


Configuration constants (all values are integers, σ=pedestal width ~20)

  • NPED: number of samples in pedestal window (default 16, must be 2**integer)
  • WINDOW_START: position in buffer of first sample in hit search window, this is immediately after the pedestal window
  • WINDOW_END: position in buffer of last sample in hit search window
  • HIT_THRES: threshold to identify hit (default 5σ ~100, range 50 to 300)
  • NSAMPLES: number of ADC samples in subset to pass to time finding module (default 15)
  • XTHR_SAMPLE: position in subset of first sample above hit_threshold (default 9, starts with 0)
  • PED_SAMPLE: position in subset of sample to be used as local pedestal (default 5, starts with 0)


Timing algorithm configuration constants

  • HIGH_THRESHOLD: High timing threshold (default 4σ ~ 80, range 40 to 270) must be lower than hit threshold
  • LOW_THRESHOLD: Low timing threshold (default 1σ ~ 20, range 5 to 30)
  • ROUGH_DT: rough time - if timing fails, return hit time of XTHR_SAMPLE - ROUGH_DT (default 24, units sample/10)
  • INT_SAMPLE: if timing fails, start integration with this sample (default 6).
  • NUPSAMPLED: number of upsampled values to calculate (default 8)
  • LIMIT_PED_MAX: do not calculate accurate time if any of samples 0 to PED_SAMPLE in subset exceeds this (default 511)
  • LIMIT_ADC_MAX: do not calculate accurate time if any sample in the subset exceeds this (default 4095)
  • SET_ADC_MIN: reduce chances of calculating a negative upsampled value by adding a constant offset to the subset values such that the minimum is equal to SET_ADC_MIN (default 20)
  • LIMIT_UPS_ERR: do not calculate accurate time if the sum of the error of the 2 upsampled values exceeds this (default 30)


Hit finding module

  1. Calculate start_pedestal as mean of NPED samples from WINDOW_START-NPED-1 to WINDOW_START-1
  2. Search from WINDOW_START to WINDOW_END for ADC value >= start_pedestal + HIT_THRES. If not found, go back to sleep. If found, continue, this is sample X.
  3. Call up time-finding module and send in NSAMPLES ADC values from the hit threshold crossing region, with the first sample >= HIT_THRES in position XTHR_SAMPLE (starting at 0)
  4. Call up signal maximum module
  5. Call up signal integral module
  6. Return pedestal_at_hit as mean of NPED samples ending with sample (X + ped_sample - xthr_sample), or 255 if value > field max
  7. Return integral and overflow count from integral module
  8. Return q_code from time module
  9. Return (x - xthr_sample)*10 + time returned from time module, units are 0.1*sample-period (0.8ns)


Time finding module

This returns an error code q_code and the hit time, relative to the first sample in the subset. If the timing fails before upsampling (eg LIMIT_PED_MAX or LIMIT_ADC_MAX are exceeded) then the algorithm returns XTHR_SAMPLE - ROUGH_DT. If the timing fails after upsampling (eg LIMIT_UPS_ERR is exceeded) then the algorithm returns the midpoint of the samples before and after the LOW_THRESHOLD crossing.

  1. Calculate thresholds from constants and local_pedestal, which is sent in as in sample number ped_sample
  2. Search the samples from ped_sample+1 to nsamples-1 for value >= high_threshold + local_pedestal. If this threshold is not exceeded, return bit q_code=1 and time x*10-rough_dt
  3. Search back from high_threshold crossing down toward ped_sample to find sample y where value <= low_threshold + local_pedestal
  4. Calculate 7 upsampled values, from y-0.2 to y+1.2
  5. Search the upsampled values from y+1.2 down to y-0.2 to find where the value <= low_threshold + local_pedestal
  6. Interpolate between the upsampled value just found and the next to find the crossing time in units of sample/10
  7. Return crossing time found and q_code=0


Signal maximum module

This returns the signal maximum

  1. Inspect ADC values after sample x, find the first value which is less than its predecessor
  2. Return value of the predecessor scaled down by 2^p


Signal integral module

This returns the signal integral and overflow count

  1. Sum signal-local_pedestal, from sample x-integral_offset to sample end_window, and count the number of samples with overflow bit set
  2. Return integral scaled down by 2^m (return all bits set if value exceeds that of bits available)
  3. Return overflow count (return 7 if count>6)





Upsampled data

ADC samples in (big circles) and upsampled data out (small blue dots)
ADC samples in (big circles) and upsampled data out (small blue dots)
ADC samples in (big circles) and upsampled data out (small blue dots)