ROOT tree branch array

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 (908 Bytes)
.

_ROOT Version:6.24
Platform: Not Provided
Compiler: Not Provided


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

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

    // 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();
}
    }