I’m using the data from TTree to produce a plot . I’m using the .GetV method to extract the data and assingne to variables. I draw in a first moment the first 3 variables and I get the values using GetV. (BOT, TN, TW) Then I draw again the tree using 3 different variables and I get also these 3 (BOT2, TN2, TN2).
The problem is that, also if I give different name to the variables, at the end they have the same value, equal to the second took: BOT=BOT2, TN=TN2, TW=TW2. Below a piece of code.
TTree::GetV1 and others simply return a pointer to an array of values. When you call the Draw command the second time it reassigns the values in the array at the same memory address. And thus calling GetV1 again will give you the same address as previously, but the values at that address have now changed. If you print the addresses as below you will see they are the same:
std::cout << resistivityBOT << " is the same as " << resistivityBOT2 << "\n";
You could create vectors from the arrays and then use those later. Here is an example:
{
//Create a tree
TTree * t = new TTree("t", "T");
double x, y;
t->Branch("x", &x);
t->Branch("y", &y);
// Fill it with some random data
for (int i=0;i<10000;i++) {
x = gRandom->Uniform();
y = gRandom->Gaus(0, x);
t->Fill();
}
t->ResetBranchAddresses();
// Make a vector for the x-values.
t->Draw("x","","GOFF");
std::vector<double> xVals(t->GetV1(), t->GetV1() + t->GetSelectedRows() % t->GetEstimate());
// Make a vector for the y-values.
t->Draw("y","","GOFF");
std::vector<double> yVals(t->GetV1(), t->GetV1() + t->GetSelectedRows() % t->GetEstimate());
// Do something with the values.
TH2D* h = new TH2D("h", "H", 100, 0, 1, 100, -3, 3);
for (int i=0;i<xVals.size() && i < yVals.size(); i++) {
h->Fill(xVals.at(i), yVals.at(i));
}
h->Draw("COLZ");
}