Re: I/O of TClonesArray members in TTree

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Oct 13 1998 - 18:44:54 MEST


Mark Boulay wrote:
> 
> By 'testing' the object, I mean performing a logical operation on
> one of the object's data members.  As an example, if I have a
> TClonesArray *fTracks (as in the root example), I would like to do
> something like
> 
> Track *fTrack;
> Int_t i = 0;
> Float_t fMinPx = 10;
> 
> while ( i < fTracks->GetEntries() )
> {
>         fTrack = (Track *)fTracks->At(i);
>         if ( fTrack->GetPx() < fMinPx ) fTracks->Remove( fTrack );
> }
> 
> I don't want to modify the file which contains the TTree, but only
> have the fTracks array modified when read in, with the ability to
> vary fMinPx before doing so.
> I would like to have this implemented in the Streamer method of the
> Event class, and I'm wondering how I can do this if I've written
> the tree with splitlevel = 1.
> 
> Thanks again,
> Mark.
> 

Hi Mark,
OK, I understand now what you want to do.
You can remove the track from the list of tracks, but
BE VERY CAREFUL to loop on the list in the reverse order,
otherwise, your will skip tracks!!
If you do not want to delete the tracks from the list,
you can also mark the selected (or not-selected) tracks
with a statement like
  track->SetBit(kKEEP);
and later on:
  if (track->TestBit(kKEEP)) {...
where kKEEP is a bit mask that can be defined using the macro BIT.
SetBit will modify the TObject::fBits data member.
All classes deriving from  TObject can use this facility.
Up to 24 bits are free to use.
For example to kKEEP can be defined as
    const Int_t kKEEP = BIT(7); //want to set bit 7 in fBits
TestBit, SetBit are part of TObject and the macro BIT is defined
in TObject.h.
This method has the advantage that you can have several selection
mechanisms and quickly test (using the &, | bit operators)
a combination of tests.

Rene Brun



> 
> 
> =================================================================
> =                                                               =
> = Mark Boulay                                                   =
> = Department of Physics   phone/voice mail: (613) 545-6861      =
> = Queen's University      fax: (613) 545-6813                   =
> = Kingston, Ontario       email: mgb@sno.phy.queensu.ca         =
> = Canada, K7L 3N6                                               =
> =                                                               =
> =================================================================
> 
> On Tue, 13 Oct 1998, Rene Brun wrote:
> 
> > Mark Boulay wrote:
> > >
> > > Dear Root team:
> > >         I want to accomplish the following, and am not sure what
> > > the best (if any) method is for doing it.  I have a TTree which
> > > contains a TClonesArray branch.  When reading the tree, I would
> > > like to test each object in  the TClonesArray, and only use it
> > > if it passes some test based on a flag I have set.  I am currently
> > > writing the TTree with splitlevel = 1, which contains an event-level
> > > branch, which in turn contains the TClonesArray.
> > >
> >
> > Mark,
> > Please, be more specific with your question. What do you mean by
> > "testing each object"? What is the difference between testing
> > and using.
> > See examples of a TTree in $ROOTSYS/test/Event and associated
> > macros eventa and eventb.
> >
> > Rene Brun
> >



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:38 MET