Re: AddFriend

From: Henso Abreu <abreu_at_lal.in2p3.fr>
Date: Mon, 25 Jan 2010 13:54:12 +0100


Dear Rene,

I did you say , but I had the following message:

Processing Compare2trees.C...
Error in <TTreeFormula::Compile>: Bad numerical expression : "tree0.ph_pt"

Rene Brun wrote:
> See the doc of TTree::AddFriend functionS.
> To add a friend tree having the same name "tree" as in your case, do
>
> void Compare2trees(void){
>
> TFile *f0 = new TFile("ntuple0.root");
> TTree *tree0 = (TTree*)f0->Get("Tree");
>
> TFile *f1 = new TFile("ntuple1.root");
> TTree *tree1 = (TTree*)f1->Get("Tree");
>
> tree->AddFriend(tree1,"tree1");
>
>
> tree->Draw("tree.ph_pt-tree1.ph_pt");
>
> }
>
> Rene Brun
>
> Henso Abreu wrote:
>> Dear Rene,
>>
>> I did what you recommend to me, but I did not have success.
>>
>> I send you my code and also I remember you that my variable ph_pt is
>> a vector.
>>
>> Thank you into advance,
>>
>> Henso
>>
>> void Compare2trees(void){
>>
>> TFile *f0 = new TFile("ntuple0.root");
>> TTree *tree0 = (TTree*)f0->Get("Tree");
>>
>> TFile *f1 = new TFile("ntuple1.root");
>> TTree *tree1 = (TTree*)f1->Get("Tree");
>>
>> tree0->AddFriend("tree1");
>>
>>
>> tree0->Draw("tree0->ph_pt-tree1->ph_pt");
>>
>> }
>>
>>
>> Rene Brun wrote:
>>> see documentation of TTree::AddFriend. You can specify the treename
>>> in TTree::Draw, eg
>>> // tree.AddFriend("ft1","friendfile1.root");
>>> // tree.AddFriend("ft2","friendfile2.root");
>>> // tree.Draw("var:ft1.v1:ft2.v2");
>>> // tree.Draw("var:ft1.var:ft2.var")
>>>
>>> When your Trees have the same name, specify an alias using the
>>> special AddFriend function
>>> TFriendElement* TTree::AddFriend(TTree* tree, const char* alias,
>>> Bool_t warn)
>>>
>>>
>>> Rene Brun
>>>
>>> Marc Escalier wrote:
>>>> Dear roottalkers,
>>>>
>>>> I have a question from Henso, who is not yet subscribed to this forum
>>>>
>>>> Let's suppose we have two trees (tree0 and tree1) which have a same
>>>> given variable name inside : "myvariable"
>>>>
>>>> how to do something like
>>>>
>>>> tree0->Draw("myvariable_from_tree0 - myvariable_from_tree1")
>>>>
>>>> and how to do something like :
>>>>
>>>> mydifference = tree0->GetValueOf n-th event of
>>>> myvariable_from_tree0 - myvariable_from_tree0"
>>>>
>>>> AddFriend would be useful if the two tree would have different name
>>>> of variables, but here, the variables have the same names
>>>>
>>>> (where myvariable is the same name in the two trees)
>>>>
>>>> thanks in advance for Henso
>>>>
>>>> ================
>>>>>>>> TFile *f0 = new TFile("f0.root");
>>>>>>>> TTree *tree0 = (TTree*)f0->Get("tree");
>>>>>>>> TFile *f1 = new TFile("f1.root");
>>>>>>>> TTree *tree1 = (TTree*)f1->Get("tree");
>>>>>>>>
>>>>>>>> // get variable pt of tree0 and keep it in float pt0
>>>>>>>> // get variable pt of tree0 and keep it in float pt1
>>>>>>>> //we wish :
>>>>>>>> // pt0 - pt1 .
>>>>>>>>
>>>>>>>> }
>>>>
>>>
>>
>
Received on Mon Jan 25 2010 - 13:54:10 CET

This archive was generated by hypermail 2.2.0 : Mon Jan 25 2010 - 17:50:01 CET