Hi Toni,
see example below:
Rene Brun
{
// Example of Root macro to copy a subset of a Tree to a new Tree
// The input file has been generated by the program in $ROOTSYS/test/Event
// with Event 1000 1 99 1
gROOT->Reset();
gSystem->Load("$ROOTSYS/test/libEvent.so");
//Get old file, old tree and set top branch address
TFile *oldfile = new TFile("$ROOTSYS/test/Event.root");
TTree *oldtree = (TTree*)oldfile->Get("T");
Int_t nentries = (Int_t)oldtree->GetEntries();
Event *event = 0;
oldtree->SetBranchAddress("event",&event);
//Create a new file + a clone of old tree in new file
TFile *newfile = new TFile("small.root","recreate");
TTree *newtree = oldtree->CloneTree(0);
for (Int_t i=0;i<nentries; i++) {
oldtree->GetEntry(i);
if (event->GetNtrack() > 605) newtree->Fill();
event->Clear();
}
newtree->Print();
newtree->AutoSave();
delete oldfile;
delete newfile;
}
On Wed, 27 Nov 2002, Antoni Munar wrote:
>
> Hi.
>
> I want to implement a simple macro (maybe through MakeClass) that opens a
> file, loops over the entries of a TTree, and under certain conditions
> copies selected entries into other TTree (and to other file)...
>
> I was looking at the available to me examples, but I did not found what I
> was expecting... any hint..?
>
> cheers,
> Toni
>
> ###################################################
> Antoni Munar Ara
> Department of Physics and Astronomy
> David Rittenhouse Laboratory
> University of Pennsylvania
> 209 South 33-rd Street
> Philadelphia, PA (USA)
> 19104-6396
>
>
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:21 MET