[ROOT] Filling branches independently

From: Gines MARTINEZ (martinez@subatech.in2p3.fr)
Date: Wed Sep 17 2003 - 10:27:20 MEST


Hi,
===
gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-110)
root-config --version
3.05/07
===
I would like to create branches in a tree, subsequently.
Enclosed, you will find a macro with 3 function test1() test2() and test3().

In test1, when a new branch is created, the TTree::Fill() method is used.
You realize that the first event contains AAAA in branch A and BBBB in branch B.
This is what we want, however, Tree T contains two entries and we would like to
have only one entry.

In test2, the problem with the number of entries is solved, since when B branch
is created we only fill the branch B.
In this case the only problem is "B" should be fill always after branch A is
created and "A" should be there.

In test3, I thought this would be the solution, when a branch is created it is
filled using TBranch::Fill().
However, I realize this is not working for the  branch "A". 
I realize that the number of entries is 0.
I would like to know why option test3() is not working, since this is the option
I would implement in my code.

Thanks in advance, Ginés

void test1()
{

  TTree T("test","test",99);

  TNamed * data1 = new TNamed("AAAA","AAAA");
  TNamed * data2 = new TNamed("BBBB","BBBB");

  T.Branch("A","TNamed",&data1,35000);

  T->Fill();
  
  T.Branch("B","TNamed",&data2,35000);

  T->Fill();

  Int_t nentries = T.GetEntries();
  printf(">>> nentries=%d \n",nentries);

  TNamed * lire = new TNamed("ZZZZ","ZZZZ");
  T.GetBranch("A")->SetAddress(&lire);
  T.GetEvent(0);
  lire->Print("");

  TNamed * lire2 = new TNamed("XXXX","XXXX");
  T.GetBranch("B")->SetAddress(&lire2);
  T.GetEvent(0);
  lire2->Print("");
}

void test2()
{

  TTree T("test","test",99);

  TNamed * data1 = new TNamed("AAAA","AAAA");
  TNamed * data2 = new TNamed("BBBB","BBBB");

  T.Branch("A","TNamed",&data1,35000);

  T->Fill();
  
  T.Branch("B","TNamed",&data2,35000);

  T->GetBranch("B")->Fill();

  Int_t nentries = T.GetEntries();
  printf(">>> nentries=%d \n",nentries);

  TNamed * lire = new TNamed("ZZZZ","ZZZZ");
  T.GetBranch("A")->SetAddress(&lire);
  T.GetEvent(0);
  lire->Print("");

  TNamed * lire2 = new TNamed("XXXX","XXXX");
  T.GetBranch("B")->SetAddress(&lire2);
  T.GetEvent(0);
  lire2->Print("");
}


void test3()
{

  TTree T("test","test",99);

  TNamed * data1 = new TNamed("AAAA","AAAA");
  TNamed * data2 = new TNamed("BBBB","BBBB");

  T.Branch("A","TNamed",&data1,35000);

  T->GetBranch("A")->Fill();
  
  T.Branch("B","TNamed",&data2,35000);

  T->GetBranch("B")->Fill();

  Int_t nentries = T.GetEntries();
  printf(">>> nentries=%d \n",nentries);

  TNamed * lire = new TNamed("ZZZZ","ZZZZ");
  T.GetBranch("A")->SetAddress(&lire);
  T.GetEvent(0);
  lire->Print("");

  TNamed * lire2 = new TNamed("XXXX","XXXX");
  T.GetBranch("B")->SetAddress(&lire2);
  T.GetEvent(0);
  lire2->Print("");
}



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:15 MET