# Multiplying a Branch with a coefficient

**URL:** <https://root-forum.cern.ch/t/multiplying-a-branch-with-a-coefficient/2474>\
**Category:** ROOT\
**Created:** [October 3, 2005, 12:06pm UTC](https://root-forum.cern.ch/t/multiplying-a-branch-with-a-coefficient/2474 "2005-10-03T12:06:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nico\_C](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/c37758/32.png) [@nico\_C](https://root-forum.cern.ch/u/nico_C)\
**Post date:** [October 3, 2005, 12:06pm UTC](https://root-forum.cern.ch/t/multiplying-a-branch-with-a-coefficient/2474/1 "2005-10-03T12:06:14Z")

</div>

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)

Thanks in advance

Nicolas

---

<div class="post-metadata">

**Author:** ![brun](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/b9e5f3/32.png) [@brun](https://root-forum.cern.ch/u/brun)\
**Post date:** [October 3, 2005, 2:13pm UTC](https://root-forum.cern.ch/t/multiplying-a-branch-with-a-coefficient/2474/2 "2005-10-03T14:13:49Z")

</div>

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”);

Please read the Users Guide and the tutorials relates to Trees.

Rene

---

<div class="post-metadata">

**Author:** ![nico\_C](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/c37758/32.png) [@nico\_C](https://root-forum.cern.ch/u/nico_C)\
**Post date:** [October 3, 2005, 3:09pm UTC](https://root-forum.cern.ch/t/multiplying-a-branch-with-a-coefficient/2474/3 "2005-10-03T15:09:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [October 6, 2005, 9:37pm UTC](https://root-forum.cern.ch/t/multiplying-a-branch-with-a-coefficient/2474/4 "2005-10-06T21:37:33Z")

</div>

[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.

---

<div class="post-metadata">

**Author:** ![nico\_C](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/c37758/32.png) [@nico\_C](https://root-forum.cern.ch/u/nico_C)\
**Post date:** [October 9, 2005, 8:29pm UTC](https://root-forum.cern.ch/t/multiplying-a-branch-with-a-coefficient/2474/5 "2005-10-09T20:29:24Z")

</div>

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](http://root.cern.ch/phpBB2/viewtopic.php?t=2564)

If you have any suggestion…  
Thanks,

nico
