FACT++  1.0
void DrsCalibrateTime::CalcResult ( )
inline

Definition at line 1100 of file DrsCalib.h.

References end.

Referenced by GetResult().

1101  {
1102  for (int ch=0; ch<160; ch++)
1103  {
1104  const auto beg = fStat.begin() + ch*1024;
1105  const auto end = beg + 1024;
1106 
1107  // First calculate the average length s of a single
1108  // zero-crossing interval in the whole range [0;1023]
1109  // (which is identical to the/ wavelength of the
1110  // calibration signal)
1111  double s = 0;
1112  double w = 0;
1113  for (auto it=beg; it!=end; it++)
1114  {
1115  s += it->first;
1116  w += it->second;
1117  }
1118  s /= w;
1119 
1120  // Dividing the average length s of the zero-crossing
1121  // interval in the range [0;1023] by the average length
1122  // in the interval [0;n] yields the relative size of
1123  // the interval in the range [0;n].
1124  //
1125  // Example:
1126  // Average [0;1023]: 10.00 (global interval size in samples)
1127  // Average [0;512]: 8.00 (local interval size in samples)
1128  //
1129  // Globally, on average one interval is sampled by 10 samples.
1130  // In the sub-range [0;512] one interval is sampled on average
1131  // by 8 samples.
1132  // That means that the interval contains 64 periods, while
1133  // in the ideal case (each sample has the same length), it
1134  // should contain 51.2 periods.
1135  // So, the sampling position 512 corresponds to a time 640,
1136  // while in the ideal case with equally spaces samples,
1137  // it would correspond to a time 512.
1138  //
1139  // The offset (defined as 'ideal - real') is then calculated
1140  // as 512*(1-10/8) = -128, so that the time is calculated as
1141  // 'sampling position minus offset'
1142  //
1143  double sumw = 0;
1144  double sumv = 0;
1145  int n = 0;
1146 
1147  // Sums about many values are numerically less stable than
1148  // just sums over less. So we do the exercise from both sides.
1149  // First from the left
1150  for (auto it=beg; it!=end-512; it++, n++)
1151  {
1152  const double valv = it->first;
1153  const double valw = it->second;
1154 
1155  it->first = sumv>0 ? n*(1-s*sumw/sumv) : 0;
1156 
1157  sumv += valv;
1158  sumw += valw;
1159  }
1160 
1161  sumw = 0;
1162  sumv = 0;
1163  n = 1;
1164 
1165  // Second from the right
1166  for (auto it=end-1; it!=beg-1+512; it--, n++)
1167  {
1168  const double valv = it->first;
1169  const double valw = it->second;
1170 
1171  sumv += valv;
1172  sumw += valw;
1173 
1174  it->first = sumv>0 ? n*(s*sumw/sumv-1) : 0;
1175  }
1176 
1177  // A crosscheck has shown, that the values from the left
1178  // and right perfectly agree over the whole range. This means
1179  // the a calculation from just one side would be enough, but
1180  // doing it from both sides might still make the numerics
1181  // a bit more stable.
1182  }
1183  }
std::vector< std::pair< double, double > > fStat
Definition: DrsCalib.h:938
double end

+ Here is the caller graph for this function: