Hi dear Rooters,
I have a question, a dumb one.
Just about the tree filling.
When I create a tree with different branches, how are they filled ?
I mean, I have a branch called “time” with values from 0 to 1 for example.
I can have access the data in “time”, doing
TFile *file_adress = TFile::Open("file_name");
TTree *tree = new TTree("name","title");
Double_t time;
tree->SetBranchAddress("time",&time);
for (Long64_t i=0;i<tree->GetEntries();i++) {
tree->GetEntry(i);
cout << time << endl;
}
Output is a mess, I mean I thought it should be ordered and increasing from 0 to 1 but it is not…
I know my question is really for beginners and not well expressed, but I really don’t understand…
TFile *file_adress = TFile::Open("file_name");
TTree *tree = new TTree("name","title");
Double_t time;
tree->Branch("time",&time);
for (Long64_t i=0;i< kNumberOfTimesToFillIntoTheTree; ++i) {
time = i; // or what ever the time is suppose to be for that entry.
tree->Fill();
}
file_adress->Write();
and to read it back
TFile *file_adress = TFile::Open("file_name","READ");
TTree *tree; file_adress->GetObject("name",tree);
if (!tree) {
std::cerr << "Can't find the tree\n";
return;
}
Double_t time;
tree->SetBranchAddress("time",&time);
for (Long64_t i=0;i<tree->GetEntries();i++) {
tree->GetEntry(i);
cout << time << endl;
}