Difference between revisions of "CDC algo"

From GlueXWiki
Jump to: navigation, search
Line 1: Line 1:
CDC time & integral algorithm.   
+
<h1>CDC time & integral algorithm</h1>
 +
 
 +
We will need to arrange the trigger timing so that when the trigger signal arrives, the presample buffer contains a number of samples for pedestal followed by the earliest possible CDC sample and then another 155 samples (for maximum drift time).   
 +
 
  
 
<h2>Quantities to be returned, if a hit is found</h2>
 
<h2>Quantities to be returned, if a hit is found</h2>
Line 12: Line 15:
 
<h2>Configuration constants (all values are integers, σ=pedestal width ~16)</h2>
 
<h2>Configuration constants (all values are integers, σ=pedestal width ~16)</h2>
  
*window_start: start of hit search window as sample number relative to the trigger arrival
+
*window_start: start of hit search window as sample number relative to the trigger arrival, this is the earliest possible hit time
*window_end: end of hit search window as sample number relative to the trigger arrival, approx 100 samples after window_start
+
*window_end: end of hit search window as sample number relative to the trigger arrival, approx 155 samples after window_start
 
*hit_threshold: threshold to identify hit (default 5σ ~80, range 50 to 300)
 
*hit_threshold: threshold to identify hit (default 5σ ~80, range 50 to 300)
 
*high_threshold: High timing threshold (default 4σ ~ 64, range 40 to 270) must be lower than hit threshold
 
*high_threshold: High timing threshold (default 4σ ~ 64, range 40 to 270) must be lower than hit threshold
Line 22: Line 25:
 
*ped_sample: sample number to be used as local pedestal (default 4)
 
*ped_sample: sample number to be used as local pedestal (default 4)
 
*rough_dt: if timing fails because ADC values do not exceed high_threshold, return hit time of xthr_sample-rough_dt (default 20, units sample/10)
 
*rough_dt: if timing fails because ADC values do not exceed high_threshold, return hit time of xthr_sample-rough_dt (default 20, units sample/10)
 +
*integral_offset: number of samples before x to include in integration (default 3).
 +
  
 
<h2>Hit finding module</h2>
 
<h2>Hit finding module</h2>
Line 28: Line 33:
 
#Calculate start_pedestal as mean of 4 samples window_start-5 to window_start-1
 
#Calculate start_pedestal as mean of 4 samples window_start-5 to window_start-1
 
#Search hit signal window for ADC value rising above start_pedestal + hit_threshold at sample x
 
#Search hit signal window for ADC value rising above start_pedestal + hit_threshold at sample x
#Call up time-finding module and send in 14 ADC values with threshold crossing sample x as 9th value
+
#Call up time-finding module and send in 14 ADC values with threshold crossing sample x as 9th voalue
 
#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
  
  
 
<h2>Signal integral module</h2>
 
<h2>Signal integral module</h2>
Sum signal, from sample x-integral_lead to sample end_window
+
#Sum signal, from sample x-integral_offset to sample end_window, and count the number of samples with overflow bit set
 +
#Return integral scaled down by 2^m (return all bits set if value exceeds that of bits available)
 +
#Return overflow count (return 7 if count>6)
  
  
and sum signal from 2 samples before threshold crossing to end of hit signal window
+
<h2>Time finding module</h2>
 
+
  
  
Line 44: Line 51:
 
Data-scanning process starts up prompted by trigger signal, reads through ADC value to search for a hit. If a hit is found then it returns a time, sum of signal minus pedestal, and QF (Quality Factor) code.  The process is described for one ADC channel, it would be the same process running on all channels. This can be implemented to scan ADC samples initially, but eventually it should use upsampled data.  
 
Data-scanning process starts up prompted by trigger signal, reads through ADC value to search for a hit. If a hit is found then it returns a time, sum of signal minus pedestal, and QF (Quality Factor) code.  The process is described for one ADC channel, it would be the same process running on all channels. This can be implemented to scan ADC samples initially, but eventually it should use upsampled data.  
  
We will need to arrange the trigger timing so that when the trigger signal arrives, the presample buffer contains a number of samples for pedestal followed by the earliest possible CDC sample and then another 155 samples (for maximum drift time). 
 
  
  

Revision as of 16:05, 28 February 2014

CDC time & integral algorithm

We will need to arrange the trigger timing so that when the trigger signal arrives, the presample buffer contains a number of samples for pedestal followed by the earliest possible CDC sample and then another 155 samples (for maximum 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, set to 255 if >254)
  • Signal integral (n bits, scaled down by factor 2^m, n,m approx 14,4, TBC)
  • Overflow count (3 bits, set to 7 if >6)
  • Signal maximum (x bits, scaled down by factor 2^y; x,y approx 9,3, TBC) this is the first maximum in the signal after the threshold crossing


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

  • window_start: start of hit search window as sample number relative to the trigger arrival, this is the earliest possible hit time
  • window_end: end of hit search window as sample number relative to the trigger arrival, approx 155 samples after window_start
  • hit_threshold: threshold to identify hit (default 5σ ~80, range 50 to 300)
  • high_threshold: High timing threshold (default 4σ ~ 64, range 40 to 270) must be lower than hit threshold
  • low_threshold: Low timing threshold (default 1σ ~ 16, range 5 to 30)
  • nsamples: number of ADC samples to pass to time finding module (default 14)
  • xthr_sample: sample number containing first sample (x) above hit_threshold (default 8)
  • ped_sample: sample number to be used as local pedestal (default 4)
  • rough_dt: if timing fails because ADC values do not exceed high_threshold, return hit time of xthr_sample-rough_dt (default 20, units sample/10)
  • integral_offset: number of samples before x to include in integration (default 3).


Hit finding module

  1. Wake up on trigger
  2. Calculate start_pedestal as mean of 4 samples window_start-5 to window_start-1
  3. Search hit signal window for ADC value rising above start_pedestal + hit_threshold at sample x
  4. Call up time-finding module and send in 14 ADC values with threshold crossing sample x as 9th voalue
  5. Call up signal integral module
  6. Return local_pedestal as value of sample (x + ped_sample - xthr_sample), or 255 if local_pedestal>254


Signal integral module

  1. Sum signal, 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)


Time finding module


Data-scanning process starts up prompted by trigger signal, reads through ADC value to search for a hit. If a hit is found then it returns a time, sum of signal minus pedestal, and QF (Quality Factor) code. The process is described for one ADC channel, it would be the same process running on all channels. This can be implemented to scan ADC samples initially, but eventually it should use upsampled data.


The following constants should be be passed in through software:

name <defaults, type> description (sigma=pedestal width, approx 16 adc units)

  1. hit_threshold <5 or 6 sigma, integer, range 10 to 300> Threshold to identify that hit occurred
  2. high_threshold <4 or 5 sigma, integer, range 10 to 300> Slightly lower threshold, use for timing, typically hit_threshold-sigma
  3. low_threshold <1 sigma, integer, range 0 to 30> Low threshold, use for timing
  4. time_tolerance <3, real number, 1 dec place, range 0.5 to 8> Max number of samples between hit threshold crossing and leading edge time, if this is exceeded then output hit threshold crossing time minus a constant. (Could express this as integer number of ns.)
  5. time_constant <6 samples, real number, 1 dec place, range 0 to 20> Output hit threshold time minus this value instead of leading edge time if time_tolerance is exceeded. (Could express this as integer number of ns.)
  6. integration_period <100, integer, range 0 to 200> Number of samples to integrate signal over
  7. pedestal_start <0, integer, range 0-100> First sample to use in event pedestal calculation
  8. pedestal_end <9, integer, range 0-100> Last sample to use in event pedestal calculation
  9. pedestal_lead <4, integer, range 0-25> Take local pedestal as adc value this number of samples before hit threshold
  10. hit_start <12, integer, range 0-100> Earliest sample to be scanned for hit data


Data-scan process

  1. Find mean of sample values 'pedestal_start' to 'pedestal_end' in presample buffer and call this 'event pedestal'.
  2. Jump ahead to sample 'hit_start'
  3. Continue reading through next 'integration_time' number of samples in the presample buffer.
    1. Look for adc data values higher than 'event pedestal' + 'hit_threshold'
      1. If data is not over threshold then output nothing, return (to search next channel)
      2. If data is over threshold then process hit as follows

Hit processing

We are now at the threshold crossing, sample number x where adc value first rises over 'event pedestal' + 'hit_threshold'

  1. Find time:
    1. Store value of sample (x-'pedestal_lead') as 'local pedestal'
    2. Start at sample (x-'pedestal_lead') and search forward to find sample y where adc value rises above 'local pedestal' + 'high_threshold'
    3. Search back through progressively earlier samples to find sample z where adc value falls below 'local pedestal' + 'low_threshold'
    4. Calculate leading edge time 'le_time' as value t where straight line through y and z intercepts 'local_pedestal'
    5. Calculate x-t. if this is greater than 'time_tolerance,' set 'le_time' = x-'time_constant'
  2. Find integral:
    1. Return to first sample after 'le_time'
    2. Calculate the sum of (sample value - 'local pedestal') for the next 'integration_period' samples
    3. Calculate QF. This contains - as a starting point - a bit set if x-t > 'time_tolerance', and some measure of pedestal, maybe the lowest bits to cover the range 0-511.
  3. Return time, integral, QF.


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)