1)I have branch "a" in a tree. I want to change that branch name to "b".
2)Then I want to create a new branch named "a", and fill it with new
values.
Step (1) is easy. I just do
TFile *g = new TFile("file.root","update");
TTree *tree = (TTree)g->Get("tree");
TBranch *br = tree->GetBranch("a");
br->SetObject("b","b/F");
g->cd();
tree->Write();
For step (2) I try
Float_t a;
TBranch *br2 = tree->Branch("a",&a,"a/F"); //create branch a
Int_t nentries = tree->GetEntries();
for (Int_t i=0; i<nentries;i++) {
tree->GetEvent(i);
a=(Float_t)(i);//assign some value to each entry
br2->Fill();
}
g->cd();
wgbr->Write();
h2->Write();
g->Close();
Problem: when I do h2->Scan("a:b") I find that "a" does not have the new
value I assigned, but instead has the original value (i.e. the same values
as "b"). When I create a new branch with a branch name that did not
previously exist in that tree, then the values fill properly. so the
problem seems to be that I'm using a branch name that already exists. I
tried creating a new tree via the "CloneTree" member function, but even
with the "a" branch deactivated (tree->SetBranchStatus("a",0)) the cloned
tree header still has that branch name, just with 0 entries, so the above
problem remains.
I guess my question is the following: is there any way to assign an
already existing variable a new value?
Scott Sampson