Create TFriend in TSelector

Dear rooters,

I wrote a TSelector to calculate physical observables from a “basic” leaves contained
in a TChain.

Now I would like to “quickly” analyze the correlation between these resulting observables and
the “basic” ones, using the Draw method (and the conditions therein).
Seems that the easiest way is to create a friend to my initial TChain.

What would be the cleanest way to do it ? My first attempts, following the basic example of the User’s Guide failed for, apparently, confusing the files : creating the file for the friend in the ::Begin() made ROOT loose the basic TChain file (?)

Additional question : it does not seem possible to have a friend smaller that the initial tree. A workaround would be filling “blank” branches. Again, is there a better trick ?

Thank you for your help.
Regards
Julien

Dear rooters,

I am back on this post after solving my problem.
Here is the solution I found (not very clean, but it works) :
[ol]
[li] have a private variable fFriend containing the pointer of the friend [/li]
[li] create a memory resident TFriend in the TSelector method Begin(). Something like :

 fFriend = new TTree("t3f","Friend tree");
 fFriend->SetDirectory(0);
 fFriend->Branch("FriendEvtNumber",&EvtNumber,"FriendEvtNumber/L");
 fFriend->Branch("correlation",&var,"variable/D");

note that EvtNumber is a variable of the processed TTree and var a new one calculated in Process()[/li]
[li] Initialize in Process() the variable var to a value I know is physically impossible (here var must be positive so -1 is a good initializer) and calculate eventually its value (if conditions are Ok)[/li]
[li] The main problem was that if the conditions are not Ok I am returning kFALSE in Process in other to abort the rest of the calculation (faster). But I must fill the tree every time I exit Process. I then defined a macro END_PROCESSto replace return …

#define END_PROCESS(tf) fFriend->Fill(); \ return tf; [/li]
[li]Save the TFriend in Terminate().[/li][/ol]
J.