# Update Entry in TTree branch

**URL:** <https://root-forum.cern.ch/t/update-entry-in-ttree-branch/37666>\
**Category:** ROOT\
**Created:** [January 22, 2020, 9:06am UTC](https://root-forum.cern.ch/t/update-entry-in-ttree-branch/37666 "2020-01-22T09:06:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cappelt](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/c4cdca/32.png) [@cappelt](https://root-forum.cern.ch/u/cappelt)\
**Post date:** [January 22, 2020, 9:06am UTC](https://root-forum.cern.ch/t/update-entry-in-ttree-branch/37666/1 "2020-01-22T09:06:49Z")

</div>

Hey everyone,

I’m a bit lost with “simple” root functions. I want to multiply all entries of a branch of a TTree with 1.24. Here is what I tried:

```
void HNL_modifyEfficiency(const char * fileName = "HNLNtuple.root", const char * treeName = "outTree") {

float eff;

TFile file(fileName,"READ");
TTree *tt = (TTree*)file.Get(treeName);

tt->SetBranchAddress("eff", &eff);

for(int i = 0; i < tt->GetEntries(); i++){
    tt->GetEntry(i);
    eff = eff * 1.24;
    tt->Fill();
}

TFile *ff = new TFile("HNLNtuple_plus1Sigma.root","recreate");
tt->Write();
ff->Close();
}

```

What am I doing wrong?

Cheers

Christian

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 22, 2020, 9:11am UTC](https://root-forum.cern.ch/t/update-entry-in-ttree-branch/37666/2 "2020-01-22T09:11:51Z")

</div>

This question was already asked on this forum, for instance here:

> [@Multiplying a Branch with a coefficient](https://root-forum.cern.ch/t/multiplying-a-branch-with-a-coefficient/2474/4):
>
> [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 $ROOT…

---

<div class="post-metadata">

**Author:** ![cappelt](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/c4cdca/32.png) [@cappelt](https://root-forum.cern.ch/u/cappelt)\
**Post date:** [January 22, 2020, 10:16am UTC](https://root-forum.cern.ch/t/update-entry-in-ttree-branch/37666/3 "2020-01-22T10:16:29Z")

</div>

Thanks for the hint.

just to document it here again how I’ve done it:

```
TFile file(fileName,"READ");
TTree *inTree = (TTree*)file.Get(treeName);

TFile::Open("HNLNtuple_plus1Sigma.root","RECREATE");
TTree *outTree = new TTree("outTree", "outTree");

inTree -> SetBranchAddress("eff", &eff);

outTree -> Branch("eff", &effNew);

for(int i = 0; i < inTree->GetEntries(); i++){
    inTree->GetEntry(i);
    effNew = eff * 1.24;
    outTree->Fill();
}

outTree->Write();
```

---

<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:** [February 5, 2020, 10:16am UTC](https://root-forum.cern.ch/t/update-entry-in-ttree-branch/37666/4 "2020-02-05T10:16:33Z")

</div>

Closed on February 5, 2020, 10:16am UTC

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