i sometimes have problems to use TTree:AddFriend correctly
for instance, i have:
TTree* ntup1 = (TTree*)f->Get(“CollectionTree”);
TTree* ntup5 = (TTree*)f->Get(“POOLContainer_egammaContainer_p1”);
ntup1 -> AddFriend(ntup5);
TCanvas *c1=new TCanvas(“c1”,“c1”,600,400);
TCanvas *c2=new TCanvas(“c2”,“c2”,600,400);
in principle something like this works, right?
indeed c2 gives me the correct plot
but c1 stays empty and i get:
root  .x dschape.c
Error in TTreeFormula::Compile: Bad numerical expression : “ntup5.m_momentum.m_eta”
Why? can someone help me on that?
thank you very much.
it works writting ntup5.m_eta and skipping the m.momentum part
i wont look further:)
oh no, it actually plots something else not in the tree i specify… so im back with the same problem.
The name ‘ntup5’ is only known to the interpreter and/or the compiler. The TTrees do not know about it. Instead when you use ntup5, you should use:“POOLContainer_egammaContainer_p1”.
You can also set an alias for the friend:
ntup1 -> AddFriend(ntup5,"alias_for_friend");and do
Thank you very much for your answer,
Unfortunately, it still doesn’t work…
i added ntup5 as a friend of ntup1.
if i draw:
i get the “correct” histogram i wish to plot.
i get the same one by giving a more complete path:
all give me the same “correct” ntuple.
ntup5d->Draw(“POOLContainer_egammaContainer_p1.m_momentum.m_eta”); doesn’t work, i really dunno why)
if i plot:
it gives me… another ntuple m_eta! not the one i want!
i dont really know where it takes it from. (the root file is pretty big)
all the other paths give me something like:
Error in TTreeFormula::Compile: Bad numerical expression : “POOLContainer_egammaContainer_p1.m_momentum.m_eta”
it’s a problem, because i want to plot an ntuple from POOLContainer_egammaContainer_p1 versus another one which i get from ntup1.
Do you know what should i try?
Thank you very much,
It looks like you should need to give really the fully qualified name for your leaf. In other word, you leaf is m_eta. It belongs to a branch named m_momentum which belong to ‘vector<egamma_p1>’ which belong to ???
And you need to reconstruct the chain up to the top level branch and write down the full name.
PS. To be more specific I would need access to your files
the more specific and longest path i can give is :
it does work.
but if i do
i get… another plot! not the one i want, not the one i get using ntup5.
i know it’s hard to help someone out when one can’t access the files, especially that i’m afraid i’m too new at root to explain my problem using the correct root vocabulary (like leaf:) )
Thanks for your help
Actually what you are now doing should work (and works in most case). Without your file, I can not know what is interfering with normal operation.
So if you can post your file on afs or an ftp server or a webserver, I will take a look.
do you have an access to
if so, the root file that concern me is 7trfaod.root
and my root routine is dschape.c
if you can’t access it, i’ll see where i can put it
thanks in advance !
The graph you get with:
is correct. You can verify this by running:
Note the 300,0 at the end that request only the first 300 entries.
ntupl1 and ntupl2 do NOT have the same number of entries (300 vs 600). When you go via the friend interface, it requires a strict semantic match between each of the entries (with the same entry number, unless you use an index).
Given the difference in number of entries, you should cross-check whether you can semantically attached those 2 trees (For example the ntuple1 might contain 1 entry per event, while the ntupl5 contains one entry per run).
Thank you very much Philippe, i’d never have realised that
basically, there’s no way of plotting something like:
to compare the eta measured in TrigEMCluster with the one in POOLContainer_egamma
since it compares different electrons anyway (with no match).
even by applying strict cuts on energy, phi, etc, we cant be sure to match the same electrons, we only lose a lot of events…
do you have a solution by any change?
Thanks a lot!
Is there information in the TTree “POOLContainer_egammaContainer_p1” and in the tree “CollectionTree” that tells you which ‘entry’ correspond to which?
If the answer is yes, then you can use these information to build a tree index (see TTree::BuildIndex) on the friend tree. After this, the load on the master will lead to the ‘correct’ load on the 2nd tree. [You are still limited to 300 events since that all there is on the master].