假设我们有一个简单的信号,中心只有1个凸点,其余点没有信号。有点像高斯分布。例如,请参见This。好的,然后我们将此形状划分为一些数据点。
我想在c++
中将此形状转换为梯形。类似于this。
据我所知,这只是一种在数学上求平均值的方法。好吧,我该怎么办?
另外,我使用ROOT CERN
来显示结果...
这是我代码的主要部分,但是无法正常工作...
char Data[Data_Point][5]
for (int k = 0; k < Data_Point ; k++){ // Data_Point is equal to 512, and so my array has just 512 member.
h1 = 0.0;
h2 = 0.0;
H = 0.0;
H1 = 0.0;
H2 = 0.0;
for (int l = 0; l <= L; l++){ // L is a const int and equal to 80.
if (k + 1 < Data_Point){
h1 += ((stoi(Data[k + l])) - Baseline / 20.0); // Baseline is average of 20 data point of first of 512 data point, by this i'm trying to make more accuarcy by subtracting the baseline.
} else {
H1 = h1;
cout << H1;
}
if (L + G + k + l < Data_Point){ // G is a Const int and equal to 15.
h2 += ((stoi(Data[L + G + k + l])) - Baseline / 20.0);
} else {
H2 = h2;
cout << H2;
}
}
H = ((h2 - h1) / L);
}
RisingTime->Fill(H);
我在运行此代码时遇到错误,提示:Unhandled exception at 0x7731C54F in Pro1.exe: Microsoft C++ exception: std::invalid_argument at memory location 0x0019E854.
任何人都可以帮忙吗? 任何答案将不胜感激。
答案 0 :(得分:0)
我找到了:
// Trapezoidal filter
for (int k = 0; k < Data_Point; k++){
h1 = 0.0;
h2 = 0.0;
H = 0.0;
H1 = 0.0;
H2 = 0.0;
for (int m = 0; m <= (L - 1); m++){
if (k + m < Data_Point){
h1 += ((stoi(Data[k + m])));
} // if (k + m < Data_Point)
else{
H1 = h1;
cout << H1;
} // else
if (L + G + k + m < Data_Point){
h2 += ((stoi(Data[L + G + k + m])));
} // if (L + G + k + m < Data_Point)
else{
H2 = h2;
cout << H2;
} // else
} // for (int m = 0; m <= (L - 1); m++)
H = ((h2 - h1) / L);
}