I have a question that haunts me since a while about TVectorT for a TGraph utilisation.
I would like to create TGraph without having to declare the size so I thought the TVectorT constructor was what I was looking for.
However it seems that you need to specify the size of your TVectorT. At least it seems since I get the error:
Error in <TVectorT::operator()>: Request index(0) outside vector range of 0 - 0
So my question is:
What is the goal of TVectorT if it doesn’t have the features of the classic vector object. I mean without having the possibility to use the handy push_back function and of not specifying sizes of the vectors.
(Another way of formulating the question is: Is there a handy “push_back” method and a way of not specifying sizes of the vectors ??)
I’m under the feeling that I missed some tricks about the use of this class.
Thank you for the answer and sorry if I wasn’t clear.
In your example, you could as well has used classic arrays (double x[2]
For me the interest of TVectorF was that it suppress the need to indicate the size of the vector( as does a vector array). If it doesn’t, then I don’t understand why to use them instead of classic arrays.
The problem is not TGraph but TVectorF. You specify the size of your vector before ( TVectorD x(2) If you need to know the exact size of your vector, I do not understand the value of the vector comparing to array.
Ok I understand. TVectorT is not the equivalent of “classic” vector in c++. Main problem with TGraph is it does not support vector, so we need to convert our vector in array with something like that
vector<float> vx;
vector<float> vy;
(one fills both vectors)
int N = vx.size();
float x[N];
float y[N];
for (int i=0 ; i<N ; i++)
{
x[i]=vx[i];
y[i]=vy[i];
}
TGraph *g = new TGraph(N,x,y);
Is there any method to write directly