# Changing the values in the branch

**URL:** <https://root-forum.cern.ch/t/changing-the-values-in-the-branch/52683>\
**Category:** ROOT\
**Tags:** tree, python, root\
**Created:** [December 7, 2022, 1:35pm UTC](https://root-forum.cern.ch/t/changing-the-values-in-the-branch/52683 "2022-12-07T13:35:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fredrih](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@Fredrih](https://root-forum.cern.ch/u/Fredrih)\
**Post date:** [December 7, 2022, 1:35pm UTC](https://root-forum.cern.ch/t/changing-the-values-in-the-branch/52683/1 "2022-12-07T13:35:16Z")

</div>

I need to change the data values in the branch: a given number needs to be subtracted from each numeric value. How can this be implemented?

\_ROOT Version: 6.26/10  
\_Platform: pycharm community  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [December 7, 2022, 5:41pm UTC](https://root-forum.cern.ch/t/changing-the-values-in-the-branch/52683/2 "2022-12-07T17:41:34Z")

</div>

This cannot be done.

- You could apply your “fixes” when you actually analyze the data (e.g., define some alias “corrected\_branch = original\_branch - corerection\_value” and then use the “corrected\_branch” in the analysis).
- You could “copy” your tree to another file, modifying its entries on the fly.
- You could create a “friend tree” with new branches.
- You could add new branches to the existing tree.

---

<div class="post-metadata">

**Author:** ![Fredrih](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@Fredrih](https://root-forum.cern.ch/u/Fredrih)\
**Post date:** [December 8, 2022, 10:34am UTC](https://root-forum.cern.ch/t/changing-the-values-in-the-branch/52683/3 "2022-12-08T10:34:32Z")

</div>

Alright.  
If i copy my file, how can i change the data of branch?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [December 8, 2022, 1:28pm UTC](https://root-forum.cern.ch/t/changing-the-values-in-the-branch/52683/4 "2022-12-08T13:28:25Z")

</div>

@eguiraud Maybe some [RDataFrame](https://root.cern/doc/master/classROOT_1_1RDataFrame.html) expert can help in creating a [Snapshot](https://root.cern/doc/master/classROOT_1_1RDF_1_1RInterface.html#ac5903d3acec8c52f13cbd405371f7fb7) with “recomputed” branches.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [December 13, 2022, 10:16pm UTC](https://root-forum.cern.ch/t/changing-the-values-in-the-branch/52683/5 "2022-12-13T22:16:53Z")

</div>

Hi, you can use `Redefine`+`Snapshot` for that. You can find the docs at [ROOT: ROOT::RDataFrame Class Reference](https://root.cern/doc/master/classROOT_1_1RDataFrame.html) .

For example

```cpp
ROOT::RDataFrame("tree", "file.root").Redefine("x", "x*0.9").Snapshot("newtree", "newfile.root");

```

will write out the contents of the original tree in a new tree and with `x` rescaled by a factor 0.9.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![Fredrih](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@Fredrih](https://root-forum.cern.ch/u/Fredrih)\
**Post date:** [December 14, 2022, 11:17am UTC](https://root-forum.cern.ch/t/changing-the-values-in-the-branch/52683/6 "2022-12-14T11:17:40Z")

</div>

TypeError: Template method resolution failed:  
none of the 3 overloaded methods succeeded. Full details:  
TypeError: takes at least 3 arguments (2 given)  
TypeError: takes at least 3 arguments (2 given)  
runtime\_error: Unknown column: size  
runtime\_error: Unknown column: size

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [December 14, 2022, 11:21am UTC](https://root-forum.cern.ch/t/changing-the-values-in-the-branch/52683/7 "2022-12-14T11:21:48Z")

</div>

> [@Fredrih](#):
>
> Unknown column: size

There is a “size” columns being used somewhere that RDF does not recognize. Feel free to share a minimal self-contained reproducer that I can take a look at.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![Fredrih](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@Fredrih](https://root-forum.cern.ch/u/Fredrih)\
**Post date:** [December 14, 2022, 12:58pm UTC](https://root-forum.cern.ch/t/changing-the-values-in-the-branch/52683/8 "2022-12-14T12:58:30Z")

</div>

It turns out that the desired column “Channel0” is located inside a branch with the same name.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [December 28, 2022, 12:58pm UTC](https://root-forum.cern.ch/t/changing-the-values-in-the-branch/52683/9 "2022-12-28T12:58:44Z")

</div>

Closed on December 28, 2022, 12:58pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
