Adding a branch

From: Michelle Mesquita Medeiros <michelle_mmed_at_yahoo.com.br>
Date: Sun, 22 May 2011 19:58:57 -0700


Hello ROOTers,

I want to add a branch in a TTree but the variable of this branch is calculated with the entries of another branch. My code is:

void test()
{
   TFile f("newer2.root","update");

   Float_t energy,tgalpha,alphar,alpha;

   TTree *tree = (TTree*)f.Get("sim");
//   Float_t energy = tree->GetBranch("shower.Energy");    TBranch *newBranch = tree->Branch("alpha",&alpha,"alpha[nshower]/F");

   Long64_t nentries = tree->GetEntries();

    for (Long64_t i = 0; i < nentries; i++){
    tree->GetEntry(i);

//    energy = shower.Energy;

    energy = tree->GetBranch("shower.Energy");
    tgalpha = (1*55251.1*(pow(30.0,2)/2)*0.000001)/energy;
    alphar = atan(tgalpha);
    alpha = (alphar * 180)/3.1415927;

    newBranch->Fill();
    }

   tree->Write("", TObject::kOverwrite);  }

It compiles but when I try to draw the new branch, alpha, I get the error:

Error in <TLeafF::GetLen>: Leaf counter is greater than maximum!  leaf: 'alpha' len: 10000000 max: 0


ERROR leaf:alpha, len=10000000 and max=0

ERROR leaf:alpha, len=10000000 and max=0

ERROR leaf:alpha, len=10000000 and max=0

ERROR leaf:alpha, len=10000000 and max=0

ERROR leaf:alpha, len=10000000 and max=0

ERROR leaf:alpha, len=10000000 and max=0

How can I fix this?
Moreover it saves two copies of the tree: the old and the new one. How can I save just the new one? I'm using version 5.28.

Thanks in advance,


Michelle Mesquita de Medeiros
Instituto de Física - UFG - Brasil

e-mail: medeiros_at_fnal.gov
medeiros_at_posgrad.ufg.br Received on Mon May 23 2011 - 04:59:06 CEST

This archive was generated by hypermail 2.2.0 : Mon May 23 2011 - 17:50:01 CEST