The CopyTree function for chains was only implemented in version 3.01. Upgrade your setup to the current pro version 3.01/06. With this version, if your branches are only basic types, you can do: TChain datachain("h300"); datachain->Add("tops_m10_iso4_real_1a_01.root/TOPS/h300"); datachain->Add("tops_m10_iso4_real_1a_02.root/TOPS/h300"); .......... TFile *newFile = new TFile("myfile.root","recreate"); //solution 1 with an inline selection TTree *tree = datachain.CopyTree("(ezflag_d==0)&&(mzflag_d==0)"); //or solution 2 with your own loop Int_t ndataevents = Int_t(datachain->GetEntries()); for (Int_t ev=0; ev<ndataevents; ev++) { datachain->GetEntry(ev); if(nhptm_d>0) { if((ezflag_d==0)&&(mzflag_d==0)) { tree->Fill(); ... } newFile->cd(); tree->Write(); Rene Brun On Thu, 26 Jul 2001, Min-Jeong Kim wrote: > > Dear all, > > I might miss something, however I can't logically understand why > my lines cause a problem, maybe more. Please, correct me. > > I am working with ROOT 2.24/04 on SGI. I have a large size of > data samples divided into around 35 root files which have been > "h2root"ed from PAW row-wise ntuples, and I would like to generate > a filtered sample from the data sample. I already know the number > of selected events is very small, let's say 200 events, so I want > to keep them as one root file. That was my first intention of this > try. > > At first, I made a chain from data files; and, set branch address > for several branches which are used for the candidate selection. > However, I would like to keep all branches in my new root file > for the selected events. > > TChain datachain("h300"); > datachain->Add("tops_m10_iso4_real_1a_01.root/TOPS/h300"); > datachain->Add("tops_m10_iso4_real_1a_02.root/TOPS/h300"); > .......... > > datachain->SetBranchStatus("*",1); > > Float_t nhptm_d; > datachain->SetBranchAddress("nhptm",&nhptm_d); > Float_t ezflag_d; > datachain->SetBranchAddress("ezflag",&ezflag_d); > Float_t mzflag_d; > datachain->SetBranchAddress("mzflag",&mzflag_d); > ........... > > Second, I create new file; and, tried to clone only header from old tree. > Because the event selection would be done by some comparisons in the > later part of this file. > > TFile *filterdatafile = gROOT->FindObject("data_filter.root"); > if (filterdatafile) filterdatafile->Close(); > filterdatafile = new TFile("data_filter.root", "RECREATE", > "Filtered Data: the paris of Mu and Tau"); > > TTree *filterdatatree = datachain->CloneTree(0); > ================================================ > ==> I guess this line is not working. However, TTree is inherited as > public to TChain, so that the public member of TTree, CloneTree, > is able to be used, I think, in this way. > > message: *** Break *** segmentation violation > > Third, I began the filtering by several comparisons: > > Int_t ndataevents = Int_t(datachain->GetEntries()); > > for (Int_t ev=0; ev<ndataevents; ev++) { > > datachain->GetEntry(ev); > > if(nhptm_d>0) { > > if((ezflag_d==0)&&(mzflag_d==0)) { > > ...... > > filterdatatree->CopyEntries(datachain,1); > > } > } > } > > filterdatatree->Print(); > filterdatafile->Write(); > > } > > I might start from very wrong place far from my intention. Any > other suggestion or collection, both are welcome. Thanks. > > =============================================================== > Min-Jeong Kim, CDF/Carnegie Mellon University, mjkim@fnal.gov > =============================================================== >
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:53 MET