Assume the following function
std::vector<double> LocatePulseEdges(int points, double* signal_x, double* signal_y, double threshold, vector<double> left_edge, vector<double> right_edge){
cout << "1" << endl;
for (int i=0; i<points; i++){
if(signal_y[i]<threshold){// left side of the pulse
left_edge.push_back(signal_x[i]);
break;
}
if(signal_y[i]>threshold){// right side of the pulse
right_edge.push_back(signal_x[i]);
break;
}
}
cout << "6" << endl;
return left_edge;
//return right_edge;
cout << "7" << endl;
}
I am calling this function in the following code
void Analyze(){
int points = 90000000;//hSignal->GetNbinsX();
double* x = new double[points]; // SIZE limited only by OS/Hardware
double* y = new double[points];
std::vector<double> left;
std::vector<double> right;
double threshold = 6234.34;
Function_to_Fill_X_and_Y();
LocatePulseEdges(points, x, y, threshold, left, right);
cout << "First left threshold crossing @ time : " << left[0] << endl;
}
Although I get no compilation error, when I run the program, it crashes right before the return statement.
Any idea on why this is happening?