How to add an array TBranch to an existing Tree?

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++) {
      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);    

What’s wrong?
Thanks for the help!


At least: "Minvariant[20]/D"

1 Like


   TTree *t1 = t->CloneTree(0);
1 Like

The problem was these two program write errors. Thank you both!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.