CloneTree crashed in 5.18 version

Hi,

I have a tree “TREE” which has many branches, one of them is “EVENT”. EVENT branch has many leaves, one of them is particle id “Id”. Now, I want to copy this tree with some selection on “Id”. For ex: I want to copy the EVENT which has 5 particular type of particle ids. The sample code is:

TFile *oldfile = new TFile("oldfile.root");
TFile *newfile = new TFile("newfile.root","recreate");

TTree *oldtree = (TTree*)oldfile->Get("TREE");
Int_t nEvent = (Int_t)oldtree->GetEntries();
oldtree->SetBranchStatus("*",1);

TTree *newtree = oldtree->CloneTree(0);

for(int i=0; i<nEvent; i++){
     oldtree->GetEntry(i);
     TLeaf *leaf = (TLeaf*)oldtree->GetLeaf("EVENT.Id");
     Int_t m = leaf->GetLen();
     
     Int_t Part1 = 0;
     Int_t Part2 = 0;
     .....................
     Int_t Part5 = 0;

     for(int j=0; j<m; j++){
         Int_t id = (Int_t) leaf->GetValue(j);
          if(id == Part1Id) Part1++;
          .....................................
          if(id == Part5Id) Part5++;
     }
     if(Part1 != 1 || Part2 != 1 || Part3 != 1 || part4 != 1 || part5 != 1) continue;
     newtree->Fill();
}
newtree->AutoSave();
newfile->Close();

Thie code runs fine in 5.22 version and everything is ok.
I also runs fine with 5.18 version but when I plot a variable using TBrowser from the new root file, it crashes.

Because of some reason I need to run it with 5.18 version. Is there any way to do this?

Thanks for your help.
Manoj

[quote]I also runs fine with 5.18 version but when I plot a variable using TBrowser from the new root file, it crashes. [/quote]Does the file produced by 5.18 also crashes the browser in 5.20? Does the same browsing succeed with both versions on the original tree? Can you give me access to all 3 files (original, copy with 5.18 and copy with 5.20)? [Also tell me exactly what fails and how)

Cheers,
Philippe.

Hi,

Sorry for late reply. I changed the code which runs on 5.18 to 5.22. So, problem is solved.

Thanks.