Is there a way to somehow clear a TGraph ?
Here’s my problem.
I have this piece of code that works great, but when I run it twice, the output is different and I don’t know why.
The vectors are cleared properly so it doesn’t come from there.
Thank you very much,
TGraph *gr_kaon = new TGraph(vec_xx_kaon.size(),&vec_xx_kaon,&vec_yy_kaon);
double a_fit_kaon = 0.;
double b_fit_kaon = 0.;
gr_kaon_fit = gr_kaon->GetFunction("pol1");
a_fit_kaon = gr_kaon_fit->GetParameter(1);
b_fit_kaon = gr_kaon_fit->GetParameter(0);
cout << "OUTPUT: " << a_fit_kaon << " " << b_fit_kaon << endl;
Your example is not complete and even incorrect (there is this
endl; alone …) …can you post some thing we can run ?
As a suggestion may be you can
delete the graph (if it exist) before creating it …
can I just do someting like gr_kaon->Delete() ??
I can’t give you an example you can run, because the code is REALLY long (this is just a very tiny part of it, but it was to illustrate the problem I have)
As for the “endl;”, it’s just a typo. Sorry
Like any C++ object, using
In addition, you should not forget that the pointer will then be invalid and should not be used. If a derefernce is performed after delete, you may cause a segmentation violation. Some advocate for setting it to
nullptr after calling delete unless it will be used for something else.
gr_kaon = nullptr;
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.