# Multiplying a Branch with a coefficient

Hello.

I have a tree, with (at least) two branches Q2 and Q5, both Float_t, written on a file.
I need to correct theses branches this way:

TFile f(“myfile.root”);
A=1.234; B=5.678;
mytree->Q2 = A*Q2+B
mytree->Write()

Is this possible, and how can I do this (without writing a new file)

Nicolas

I am not sure to understand what you want to do.
If you simply want to histogram Q2 multiplied by a coeeficient or
any other transformation, do
mytree.Draw(“Q2”); //to draw the original Q2
mytree.Draw(“1.234*Q2+5.678”);

Rene

René,

Precisely, here’s my pseudo-code:

• read ascii file and fill a tree with different branches
• fit branch Q2 to find peak
• compute a correction coefficient A = f(peak)
• compute branch Q2’ = f(Q2, A)
• write my tree to a root file

But, as I have read somewhere else in the forum, it is impossible (or “not recommended at all”) to do something like Q2 = Q2*A

So, I need to find another way to do this, with as few steps as possible.

Thanks

nicolas

[quote]But, as I have read somewhere else in the forum, it is impossible (or “not recommended at all”) to do something like Q2 = Q2*A [/quote]It is possible but not recommended since the step to do so are not trivial.

[quote]So, I need to find another way to do this, with as few steps as possible. [/quote]Simply create a new tree, with just the branch Q2 and make this new tree a friend of the first tree (oldtree->AddFriend(…) ).
Alternatively, Clone the old tree and add a new branch (See \$ROOTSYS/tutorials/copytree3.C)

Cheers,
Philippe.

Hi Philippe,

yes, it is exactly what I did, and it works. Well, almost, as I explain in :

http://root.cern.ch/phpBB2/viewtopic.php?t=2564

If you have any suggestion…
Thanks,

nico