Hello everyone,
i need to add a new TBranch to a TTree. This is an existing TBranch function.
I tried to run the following program which does not give errors, but when I call the TBrowser the TBranch is empty!
void treeAddBranch() {
TFile *f = new TFile("Sel3piM_0_793.root");
TTree *t = (TTree *)f->Get("h1");
Int_t nentries = (Int_t) t->GetEntries();
//Array already existing as TBranch
Float_t ppvt[20][3];
TBranch *b_ppvt;
t->SetBranchAddress("ppvt", ppvt, &b_ppvt);
TFile *f1 = TFile::Open("Sel3piM.root", "RECREATE");
TTree *t1 = t->CloneTree();
//New array TBranch
Double_t Minvariant[20];
TBranch *newBranch = t1-> Branch("Minvariant", Minvariant,"Minvariant[20]/F");
for (Int_t i = 0; i < nentries; i++) {
t->GetEntry(i);
for(Int_t j = 0; j< 20; j++) {
Minvariant[j] = sqrt(ppvt[j][0]*ppvt[j][0]+ppvt[j][1]*ppvt[j][1]+ppvt[j][2]*ppvt[j][2]+139.57018*139.57018);
}
t1->Fill();
}
t1->Write();
f1->Close();
}
What’s wrong?
Thanks for the help!
Root-v6.22