# ROOT tree branch array

**URL:** <https://root-forum.cern.ch/t/root-tree-branch-array/56928>\
**Category:** Newbie\
**Tags:** tree, root\
**Created:** [October 31, 2023, 3:19am UTC](https://root-forum.cern.ch/t/root-tree-branch-array/56928 "2023-10-31T03:19:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sbecka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/7c8e57/32.png) [@Sbecka](https://root-forum.cern.ch/u/Sbecka)\
**Post date:** [October 31, 2023, 3:19am UTC](https://root-forum.cern.ch/t/root-tree-branch-array/56928/1 "2023-10-31T03:19:05Z")

</div>

Hello,  
I have a ROOT tree with a branch called “detector.energy”. I wanted to transform the branch with some calibration coefficients by using the macro attached and it worked fine.

However, I have another branch which is an array of 16 elements and is called “clover.energy[16]”. I would like to access the individual elements of this branch using a similar macro but I could not figure out how I can access to the individual elements from the array and make a new branch of 16 elements modified with the calibration coefficients.

Thank you so much for any suggestions.

[UpdateBranch.C](https://root-forum.cern.ch/uploads/short-url/j8XNqfYdSKoqyq5TySrczcaSWys.C) (908 Bytes)  
.

\_ROOT Version:6.24  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [October 31, 2023, 4:11am UTC](https://root-forum.cern.ch/t/root-tree-branch-array/56928/2 "2023-10-31T04:11:54Z")

</div>

```auto
    const Int_t N=16;
    Double_t energy_updated1[N]; // Updated energy values
    Double_t energy[N]; // energy values

    data->SetBranchAddress("detector.energy", &energy);
    TBranch *newBranch = data->Branch("energy_updated1", &energy_updated1, "energy_updated1[N]/D");

```

and whenever you do `data->GetEntry()` (or GetEvent), all N elements in that entry/event get their values, and you access each as for any array (so you need to copy/etc each one in an entra/nested loop).

---

<div class="post-metadata">

**Author:** ![Sbecka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/7c8e57/32.png) [@Sbecka](https://root-forum.cern.ch/u/Sbecka)\
**Post date:** [October 31, 2023, 1:13pm UTC](https://root-forum.cern.ch/t/root-tree-branch-array/56928/3 "2023-10-31T13:13:19Z")

</div>

Hello,  
Thank you so much for the quick help. This is what I have done extra following your suggestion and received the error,

Error in TTree::SetBranchAddress: unknown branch → clover.energy

```auto
    // Create new branch for the updated energy values
    Double_t energy_updated1[16]; // Updated energy values
    Double_t energy[16]; // energy values

    data->SetBranchAddress("detector.energy", &energy);
    TBranch *newBranch = data->Branch("energy_updated1", &energy_updated1, "energy_updated1/D");

    Int_t nEntries = data->GetEntries();

    for (Int_t entry = 0; entry < nEntries; entry++) {
for (int i = 0; i < 16; i++) {
        energy_updated1[i] = a + b * energy[i]; // Apply the calibration
        newBranch->Fill();
}
    }

```
