filtering a tree

T Auger (thauger@phns27.saclay.cea.fr)
Tue, 29 Sep 1998 20:49:07 +0200


Hi ROOTers,
I am trying to copy from an existing tree only a fraction of the
events into a new tree. To do this filtering, I would like to be able to use
TCut as arguments like when I do a tree.Draw(); so I create an
TEventList which I then use to get the events which do satisfy my
criteria. I can create a tree but when I try to do a Draw() on this
new tree, ROOT bumps with this message:

root [3] tree_out.Draw("event.Mm_gp()")
Warning in <MakeDefCanvas>: creating a default canvas with name c1
Warning in <TBranchObject::GetBasket>: Estimated keylen too small=2468
Fatal in <operator new>: storage exhausted
aborting

I do not understand what's happening. It is quite similar to what's being
done in the CloneTree() TTree member function.
here is the macro :

{
gROOT->Reset();
TFile f("/home/crash30/thierry/run12415/run12415_v1.root");
TTree *tree = (TTree*)gDirectory->Get("T");
TTree *tree_out = (TTree*) tree->Clone();
TClasEvent *event;
Int_t nbytes = 0;
Float_t test;
tree->SetBranchAddress("event",&event);
cout<<" Nentries "<<tree->GetEntries()<<endl;
tree_out->Reset();
// tree_out->Branch("event", "TClasEvent", &event, 1000,0);
// copy branch addresses
Int_t i;
TObjArray *leaves = tree->GetListOfLeaves();
TObjArray *tleaves = tree_out->GetListOfLeaves();
Int_t nleaves = leaves->GetEntriesFast();
for (i=0;i<nleaves;i++) {
TLeaf *leaf = (TLeaf*)leaves->UncheckedAt(i);
TBranch *branch = leaf->GetBranch();
if (branch->GetAddress()) {
tree_out->SetBranchAddress(branch->GetName(),branch->GetAddress());
} else {
TLeaf *leaf2 = (TLeaf*)tleaves->UncheckedAt(i);
leaf2->SetAddress(leaf->GetValuePointer());
}
}

TEventList *elist1 = new TEventList("elist1","test",10000);

tree->Draw(">>elist1","event.Mm_gp()>0","",1000);
Int_t nentries = elist1->GetN();
for (Int_t i=0; i<nentries;i++) {
if(i%100 == 0) cout<<"alors"<<endl;
nbytes += tree->GetEvent(elist1->GetEntry(i));
tree_out->Fill();
event->Clear();
}
}

Does anyone see how this could work (or why it doesn't work)?
sincerely,
Thierry.