Hello,-
I have a problem which is probably caused by my lacking understanding of the
difference between a TTree and a TChain.
I have narrowed the problem down and can reproduce it using a slightly modified version of
the tree2.C example provided my the root installation.
I call the tree2w() method, which writes the tree t2 to the file tree2.root.
Then I make an identical copy of tree2.root to tree3.root.
Next I modify the tree2r() method so it works on a TChain in stead of a TTree.
This works without problems as long as I add only tree2.root.
But when I add two files to the chain (tree2.root and tree3.root) things don’t work.
Here is my modifed tree2r:
void tree2r()
{
TChain* t2 = new TChain(“t2”);
t2->Add(“tree2.root”);
t2->Add(“tree3.root”);
// TFile *f = new TFile(“tree2.root”);
// TTree t2 = (TTree)f->Get(“t2”);
static Float_t destep;
TBranch *b_destep = t2->GetBranch(“destep”);
b_destep->SetAddress(&destep);
TH1F *hdestep = new TH1F(“hdestep”,“destep in Mev”,150,0e-5,3e-5);
//read only the destep branch for all entries
Int_t nentries = (Int_t)t2->GetEntries();
printf(“nentries= %d\n”, nentries );
Int_t nbtot = 0;
for (Int_t i=0;i<nentries;i++) {
// Int_t nb = b_destep->GetEntry(i);
Int_t nb = t2->GetEntry(i);
if ( nb==0 ) {
printf(“nb=%d for i=%d\n”, nb, i );
break;
}
nbtot += nb;
hdestep->Fill(destep);
}
printf(“nBytes read in total: %d\n”, nbtot );
TCanvas *c1 = new TCanvas(“c1”,“c1”,600,800);
hdestep->Draw();
}
What happens when running the above, is that destep is alway 0.
I.e. destep is not correctly filled.
If I change to load only via b_destep->GetEntry(i) I get a segmentaiton violation.
What do I have to add to this example for it to work?
I am running v5.26 64 bit on a MacOsX 10.6.
Best wishes,
-Mogens Dam