I am passing a std::vector from a separate class back to my main and everything seems to work. However, after a few lines of code, the last element seems to be missing. I don’t understand what’s going on and would appreciate some help/insight.
Here is a snippet of my code.
void coincidences()
{
bool peaks = 1;
std::vector<double *> peakPosX;
TFile* fout;
...
if (peaks) {
...
peakPosX = pf.GetPeakPos(); //pf is a member of my own class to find peaks in a spectrum
cout << peakPosX[5][0] << endl;
}
...
fout = new TFile(foutName,"recreate");
for (int i = 0; i < nchannels; i++) {
if (peaks) {
//draw two histograms in same canvas, save that canvas and close it
printf("(%d) position of peaks in channel %d: %f\n",i,channels[i],peakPosX[i][0]);
}
}
}
Output:
14.65
...
(5) position of peaks in channel 349: 0.000000
There really is nothing more of interest inbetween and I don’t understand why this last element of my vector peakPosX is lost. Do you have any ideas?
Thanks for your reply Philippe,
I actually do mean std::vector<double *> peakPosX;
To explain: I use the TSpectrum::SearchHighRes() method to find peaks in my spectrum and get their x values with the TSpectrum::GetPositionX() method, which returns a double * with all x positions. This happens in my own class where I store these coordinates in a separate vector via peakPositions.push_back(s->GetPositionX());
where s is my TSpectrum.
This seems to work fine since I write the results into a separate file and there everything is saved correctly.
If that is true, then I wonder whether this could be the reason for why my method won’t work properly. But wouldn’t that mean that my whole method shouldn’t work at all?