Hello again, I have some questions regarding the code below
a) What I get in the end is an empty tree. Meaning 0 entries, what am I doing wrong?
b) When I uncomment the line that deletes the pointers to the branches (see end of script) cint throws a segmentation error and crashes. Again can someone explain it to me? Is it necessary to delete the pointers to the branches?
c) With that line commented the script seems to run fine, although the tree has no entries. After I exit cint with .q i get an output which I post in the end of this thread. I have seen these happening many times and I know it is probably my memory handling, I want to start doing things right, so any help much appreciated.
[code]{
TFile siFile(“2802.root”);
TTree * siTree=(TTree*) siFile.Get(“siTree”);
vector * clPos1x=0;
vector * clPos3x=0;
vector * clPos6x=0;
TBranch * b_1x;
TBranch * b_3x;
TBranch * b_6x;
siTree->SetBranchAddress(“clustPos1x”,&clPos1x,&b_1x);
siTree->SetBranchAddress(“clustPos3x”,&clPos3x ,&b_3x);
siTree->SetBranchAddress(“clustPos6x”,&clPos6x ,&b_6x);
Float_t a;
Float_t b;
Int_t ev;
TFile extrFile(“extr2802.root”,“RECREATE”);
TTree extrTree(“extrTree”,“extrTree”);
TBranch * b_a = extrTree.Branch(“ax”, &a,“a/F” );
TBranch * b_b = extrTree.Branch(“bx”, &b,“b/F” );
TBranch * b_ev = extrTree.Branch(“ev”, &ev,“ev/I” );
Float_t c3=176;Float_t c1=15496;Float_t c2=30976;
Float_t z6=900;Float_t z1=860;Float_t z3=0;
Float_t p1,p2;
for(Int_t i=0;iGetEntries();i++){if (i%100==1) cout<<i<<"\n";
clPos1x.clear();clPos3x.clear();clPos6x.clear();
siTree->GetEntry(i);
ev=i;
if (i%10==1) cout<<clPos3x.size()<<"\n";
if( clPos3x.size()==1 && clPos1x.size()==1 && clPos6x.size()==1){
p1=z3*(*clPos3x)[0]+z6*(*clPos6x)[0]+z1*(*clPos1x)[0];
p2=(*clPos3x)[0]+(*clPos6x)[0]+(*clPos1x)[0];
a=(p2-c3*p1/c1)/(3.-c2/c1);
b=(3*p1-c3*p2)/(3*c1-c2);
//b_a->Fill();
//b_b->Fill();
}
else {a=NULL;b=NULL;}
//b_ev->Fill();
extrTree->Fill();
}
//extrTree->Write("", TObject::kOverwrite);
extrFile->Write();
delete clPos1x;delete clPos3x;delete clPos6x;
delete siTree;
//delete b_a;delete b_b;delete b_ev;delete b_1x;delete b_3x;delete b_6x;
extrFile->Close();
siFile->Close();
}[/code]
After I quit cint:
*** glibc detected *** /home/psifunk/root/bin/root.exe: corrupted double-linked list: 0x08ca4c28 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb6c72f09]
/lib/tls/i686/cmov/libc.so.6[0xb6c74a8d]
/lib/tls/i686/cmov/libc.so.6(__libc_malloc+0x95)[0xb6c768c5]
/usr/lib/libstdc++.so.6(_Znwj+0x27)[0xb6e6adc7]
/usr/lib/libstdc++.so.6(_Znaj+0x1d)[0xb6e6af0d]
/home/psifunk/root/lib/libCore.so(ErrorHandler+0xf6)[0xb78fece6]
/home/psifunk/root/lib/libCore.so(_Z5BreakPKcS0_z+0x33)[0xb78fefa3]
/home/psifunk/root/lib/libCore.so(_ZN11TUnixSystem15DispatchSignalsE8ESignals+0xc2)[0xb79d9042]
/home/psifunk/root/lib/libCore.so[0xb79d914d]
/home/psifunk/root/lib/libCore.so[0xb79cf9f2]
[0xb7f50400]
======= Memory map: ========
08048000-0804a000 r-xp 00000000 08:11 98327 /home/psifunk/root/bin/root.exe
0804a000-0804b000 rw-p 00001000 08:11 98327 /home/psifunk/root/bin/root.exe
08715000-08e95000 rw-p 08715000 00:00 0 [heap]
b6400000-b6421000 rw-p b6400000 00:00 0
b6421000-b6500000 —p b6421000 00:00 0
b652a000-b652b000 rw-p b652a000 00:00 0
…and goes on