since TGraph seems to me the only way to draw exact 2D histos (without the points beeing randomly distributed in the bins), I frequently use them.
And I am missing all the time the possibility to create TGraph from vectors <>, avoiding the use of staticly defined arrays.
Is there a way to use dynamic memory objects with Tgraphs?
You can already use a vector with a TGraph:
TGraph gr( v.size(), &(x), &(y) );
[quote]Is there a way to use dynamic memory objects with Tgraphs? [/quote]What do you mean?
I think he meant if you can define arrays dynamically like this:
Double_t *time = new Double_t [npoints];
Double_t *xpos = new Double_t [npoints];
And later use them with TGraph like this:
TGraph *x_vs_t = new TGraph( npoints , time , xpos );
I tried your suggestion for the STL vectors with this kind of dynamically defined array, but it didn’t work. I get no apparent errors (with either your syntax or mine) but my canvas is empty!..and I’ve checked my arrays contain the data I need.
I guess I can try using vectors instead, but they might be slower…
UPDATA/EDIT: pcanal’s method using STL vectors works indeed.
Using the new operator also works fine, only there is no need to use &(x) . Merely typing x works.