I may be repeating things said many times, but I still cannot figure out the easiest-more straightforward way to do this:
I have a root file which has a tree, which has some leaves. I want to read the data from two of these leaves (which represent experimental data) and plot them as X, Y variables in a graph. These leaves contain data in vector or vector type.
What I do is:
vector<double> *charge;
for(UInt_t i=0; i<raw_tree->charge->size(); i++) {
time.push_back(raw_tree->charge->at(i));
}
unsigned int charge_size = charge.size();
TVectorT<double> tv_y(charge_size);
for ( unsigned int i=0; i<charge_size; i++) {
tv_y[i] = charge[i];
}
/* the same code for x axis data */
TGraph *g1 = new TGraph(tv_x, tv_y);
TCanvas *c1 = new TCanvas("c1", "RAW file plots", 800, 800);
g1->Draw("ap");
The output is a graph with many points and I think it just works. Is there a way to do it without creating the
vector variable??? A more straightforward-more correct way to do it?
thank you guys
p.s. I searched this forum for the key ‘graph vector’ but did not get really good results. I also think that the reference guide about TGraph does not have this info…