Friend Tree and TRef

Hi,

I would like to make a friend tree containing a custom class of composite particles where that class has a TRefArray to the particles in the original ntuple Tree.

When i tried to do this, reading back the friend tree, the TRef pointers are NULL, however filling and using the class right away works fine.

Is this possible to do this or could i be missing something to allow TRef in a friend tree to point to the original tree ?

Any suggestions welcomed.

Cheers
-a

Hi,

Yes it is possible, however (even when you call TTree::BranchRef) there is no way for the TTree(s) to auto-read the branch containing the referenced objects. You will need to make sure to read explicitly the branch where the referenced objects have been stored.

Cheers,
Philippe.

Hi Philippe,

I’ve tried that, but i’m still not getting the TRef to point to it.
See below more details on what i’ve done.

Any ideas what i could be missing ?

Cheers
-a


I book the friend tree and call BranchRef.
 	_myFT = new TTree("Ana","Ana Friend Tree"); 
  	_myFT->BranchRef(); //For TRef
    	_myFT->Branch("lep",&(anaPart_A), 32000, 99 );
    	_myFT->Branch("Zcand",&(anaCompPart_A), 32000, 99 );
	with  
	vector<UCI::AnaParticle>*   anaPart_A;  
  	vector<UCI::AnaCompositeParticle>* anaCompPart_A;
  	& anaParticle & AnaCompositeParticle are custom classes w/ TRef & TRefArrays as members. 
	(Those classes work fine on the fly w/o using friend tree, ie filling those vector and using them right-away.)
I fill the vectors linked to myFT branches 
I fill the tree:
	 Int_t ObjectNumber = TProcessID::GetObjectCount(); //For TRef
	  _myFT->Fill();
	TProcessID::SetObjectCount(ObjectNumber);

To read back the info
  _myFT = (TTree*) _fileFT->Get("Ana");
  setBranch(); //See NtAnaExample
  _chain->AddFriend(_myFT);
  _myFT->BranchRef(); //For TRef
  _chain->BranchRef(); //For TRef

the output filling the friend tree:

Run: 106050 Event: 901326
tag PDG:        -11 Pt:  44.30 Eta: -0.84 Phi: -1.77 mass:    -0.0000 q:    1.00
 e1 PDG:        -11 Pt:  44.30 Eta: -0.84 Phi: -1.77 mass:    -0.0000 q:    1.00 Auth: 3 isEm() 0
   obj count 1   num 0x8ec50b0   e1 unique ID 1   eTag unique ID 1
probe PDG:         11 Pt:  40.19 Eta: -1.33 Phi:  1.63 mass:    -0.0000 q:   -1.00
 e2 PDG:         11 Pt:  40.19 Eta: -1.33 Phi:  1.63 mass:    -0.0000 q:   -1.00 Auth: 3 isEm() 0
   obj count 2   num 0x8ec50b0   unique ID 2   eProbe unique ID 2
Zcand PDG:         23 Pt:  11.77 Eta: -2.95 Phi: -2.86 mass:    86.2072 q:    1.00
tag PDG:         11 Pt:  40.19 Eta: -1.33 Phi:  1.63 mass:    -0.0000 q:   -1.00
 e1 PDG:         11 Pt:  40.19 Eta: -1.33 Phi:  1.63 mass:    -0.0000 q:   -1.00 Auth: 3 isEm() 0
   obj count 4   num 0x8ec50b0   e1 unique ID 2   eTag unique ID 2
probe PDG:        -11 Pt:  44.30 Eta: -0.84 Phi: -1.77 mass:    -0.0000 q:    1.00
 e2 PDG:        -11 Pt:  44.30 Eta: -0.84 Phi: -1.77 mass:    -0.0000 q:    1.00 Auth: 3 isEm() 0
   obj count 4   num 0x8ec50b0   unique ID 1   eProbe unique ID 1
Zcand PDG:         23 Pt:  11.77 Eta: -2.95 Phi: -2.86 mass:    86.2072 q:    1.00
Filled friend tree





To read my initial tree

 Long64_t lflag = _chain->LoadTree(iEvt);
 b_evt->GetEntry(lflag);   //grab initial tree branch

b_anaComp->GetEntry(lflag); //grab friend tree branch


Here a print out:

Run: 106050 Event: 901326
 Electron PDG:        -11 Pt:  44.30 Eta: -0.84 Phi: -1.77 mass:    -0.0000 q:    1.00 Auth: 3 isEm() 0   //initial tree output
   obj count 0   num 0x921e0b0   unique ID 0
 Electron PDG:         11 Pt:  40.19 Eta: -1.33 Phi:  1.63 mass:    -0.0000 q:   -1.00 Auth: 3 isEm() 0 //initial tree output
   obj count 0   num 0x921e0b0   unique ID 0
tag PDG:        -11 Pt:  44.30 Eta: -0.84 Phi: -1.77 mass:    -0.0000 q:    1.00   //Friend tree object
Warning in <TBufferFile::ReadBuffer>: The file was written during several processes with an older ROOT version; the TRefTable entries might be inconsistent.

It segfault trying to retrieve the TRef to the electron from the initial tree.

[quote]Warning in TBufferFile::ReadBuffer: The file was written during several processes with an older ROOT version; the TRefTable entries might be inconsistent.[/quote]The problem might be here (i.e. file might not be able to handle it).

Also note that if the referenced object have not been referenced as the time they were written, any subsequent TRef will be ineffective (For performance reasons an object is given an ‘id’ (necessary for TRef to find them) if and only if a TRef points to them … and we do not (can not) update an existing TTree). If you are in this situation, you will have to go through cloning the input/original TTree so that the referenced object can be saved with an ‘id’.

Cheers,
Philippe.