[ROOT] Re: write selected events in tree...

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Feb 21 2003 - 10:22:43 MET


Hi Daniela,

In your Loop function, you should not call BranchOld. CloneTree will
recreate an identical Tree header.
Below, you will find an example of Loop code to copy a subset of
a Tree (TChain) to a new Tree.

Rene Brun


   TFile f("newTree.root","recreate");
   TTree *newTree = fChain->GetTree()->CloneTree(0);
   
   Int_t nentries = Int_t(fChain->GetEntriesFast());
   for (Int_t jentry=0; jentry<nentries;jentry++) {
      Int_t ientry = LoadTree(jentry);
      if (ientry < 0) break;
      fChain->GetEntry(jentry);
      // if event is rejected continue
      newTree->Fill();
   }
   newTree->AutoSave();

Daniela Kaefer wrote:
> 
> Hello,
> 
> I have the problem, that I would really like to write a tree (same
> structure and contents as the original one), but only with selected
> events in it in order to get smaller and smaller samples (data and
> MCs) to run over...
> 
> If someone could take a look at my code and tell me (or give me a
> hint, suggestion or anything) as to what I did wrong or why I cannot
> get it to work. Any help is highly appreciated.
> 
> Thanks in advance to anyone who can (or try to) help with this
> problem...
> 
> Cheers, Daniela
> 
>  +-----------------------------------------------------------+
>  | Daniela Kaefer     | email: kaefer@physik.rwth-aachen.de  |
>  | Fermilab, MS 357   |        kaefer@fnal.gov    \_L_/      |
>  | Batavia, IL 60510  |                           /* *\/     |
>  |                    |                           \_*_/\     |
>  | U.S.A.             | phone: +1-630-840-5439    / | \      |
>  +-----------------------------------------------------------+
> 
>   --------------------------------------------------------------------------------
>                       Name: wrtTopData.C
>    wrtTopData.C       Type: Plain Text (TEXT/PLAIN)
>                   Encoding: BASE64
>                Description: Macro
> 
>                       Name: wrtTopData.h
>    wrtTopData.h       Type: Plain Text (TEXT/PLAIN)
>                   Encoding: BASE64
>                Description: Header
> 
>                   Name: Makefile
>    Makefile       Type: Plain Text (TEXT/PLAIN)
>               Encoding: BASE64
>            Description: Makefile
> 
>                       Name: runTopData.C
>    runTopData.C       Type: Plain Text (TEXT/PLAIN)
>                   Encoding: BASE64
>                Description: Macro (executable)



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:09 MET