Hi Rene, Thanks. It works indeed but if I run two times the code to readout the tree, Root failed and gives: *** Break *** segmentation violation Generating stack trace... 0x401dacbb in TUnixSystem::StackTrace(void) + 0x25b from /usr/local/ROOT/lib/libCore.so 0x401d9812 in TUnixSystem::DispatchSignals(ESignals) + 0xb2 from /usr/local/ROOT/lib/libCore.so 0x401d89bb in <unknown> from /usr/local/ROOT/lib/libCore.so 0x401dc585 in <unknown> from /usr/local/ROOT/lib/libCore.so 0x40e6e848 in <unknown> from /lib/i686/libc.so.6 0x40ec0bf4 in __libc_free at /usr/src/build/40457-i686/BUILD/glibc-2.2.4/malloc/malloc.c:3155 from /lib/i686/libc.so.6 .... I have solved the problem by opening myself a TCanvas and plotting in it. Then it works (I don't know why) as many times as I want. Thanks. Pascal. Rene Brun a écrit: >Hi Pascal, > >What is the problem with your example? >For me it works without any changes, although I suggest to modify your code >as shown in the attachements. >In particular, it does not make sense to use the split mode for an histogram. > >Rene Brun > >Pascal PERRODO wrote: > > >>Hi rooters, >> >>I try to create and read Trees containing not only Int_t and Float_t, >>but also objects (TH1F). >>I have tried to follow the recipies in the documentation (p202, Adding a >>TBranch to Hold an Object). >> >>I have written a simple example in the directory >>/afs/cern.ch/user/p/pperrodo/public/tree/ >>tree-read.C : creates the tree tree.root and seems to work >>tree-write.C : reads the tree and failed. Could you help me to read such >>a tree. >> >>I use the Version 3.05/05 8 May 2003 on redhat. >> >>Many thanks in advance. >>Regards. >>Pascal Perrodo. >> >> >> >> > >------------------------------------------------------------------------ > >// create a tree with TH1F as variable >// P. Perrodo >// 28/09/03 >{ > >TH1F h0("h0","h0",100,0,100); > >TFile fout("tree.root","RECREATE"); > >TTree tr1("tr1","tr1"); > >Int_t i1; >Float_t x1; >TH1F *h=0; //<======== > >tr1.Branch("i1",&i1,"i1/I"); >tr1.Branch("x1",&x1,"x1/F"); >tr1.Branch("hist", "TH1F", &h, 32000, 0); //<======== > >for ( Int_t n=0 ; n<100 ; n++ ){ > > i1 = n; > x1 = n*n; > > h0.Reset(); > h0.Fill(n); > h = (TH1F*) h0.Clone(); //<======== > > tr1.Fill(); > delete h; //<======== >} > >tr1.Print(); >fout.Write(); > >} > > >------------------------------------------------------------------------ > >{ > >TFile f("tree.root"); > >TTree *tr = (TTree*) f.Get("tr1"); > >Int_t i1; >Float_t x1; >TH1F *h=0; //<======== > >//h = new TH1F(); //<======== > >tr->SetBranchAddress("i1",&i1); >tr->SetBranchAddress("x1",&x1); >TBranch *bh0 = tr->GetBranch("hist"); >bh0->SetAddress(&h); > >TProfile hd1("hd1","hd1",100,0,100); > >Int_t nentries = tr->GetEntries(); >Int_t nbytes = 0; >for (Int_t i=0; i<nentries;i++) { > nbytes += tr->GetEntry(i); > > hd1.Fill(i1,x1); > >} > >hd1.Draw(); > >//getchar(); > >} > >
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:15 MET