# Issues reading a single value in a Branch

**URL:** <https://root-forum.cern.ch/t/issues-reading-a-single-value-in-a-branch/45003>\
**Category:** Newbie\
**Tags:** tree, root\
**Created:** [May 20, 2021, 4:19pm UTC](https://root-forum.cern.ch/t/issues-reading-a-single-value-in-a-branch/45003 "2021-05-20T16:19:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PPierre](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ebca7d/32.png) [@PPierre](https://root-forum.cern.ch/u/PPierre)\
**Post date:** [May 20, 2021, 4:19pm UTC](https://root-forum.cern.ch/t/issues-reading-a-single-value-in-a-branch/45003/1 "2021-05-20T16:19:47Z")

</div>

Hi, I’m having an issue when trying to read a single values of a branch in my TTree.  
Here is a snippet of my root interpreter where a is my TTree :

```auto
a->GetEntry(1125103);
a->Show()
======> EVENT:1125103
 batch_index = 18
 iteration = 1195
 iteration_weight = 2.19721e-07

```

I want to get the iteration\_weight value for that event, proceeding as follow :

```auto
Double_t iteration_weight;
a->SetBranchAddress("iteration_weight",&iteration_weight);
a->GetEntry(1125103);
iteration_weight

```

the interpreter return the value “0.000” .  
I don’t really know where is the error, did I badly defined ‘iteration\_weight’ ? Though ‘iteration\_weight’ is declare as a Branch of Double\_t values when I look with a-\>Print().

I’ve tried some different options but I always get the outcome :

```auto
(double) 0.000000

```

How could I get the real value i.e. 2.19721e-07 ?

Thanks, sincerely,

Pierre.

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [May 20, 2021, 5:46pm UTC](https://root-forum.cern.ch/t/issues-reading-a-single-value-in-a-branch/45003/3 "2021-05-20T17:46:35Z")

</div>

That should work as you describe. Could you post your complete macro?

---

<div class="post-metadata">

**Author:** ![PPierre](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ebca7d/32.png) [@PPierre](https://root-forum.cern.ch/u/PPierre)\
**Post date:** [May 20, 2021, 5:52pm UTC](https://root-forum.cern.ch/t/issues-reading-a-single-value-in-a-branch/45003/4 "2021-05-20T17:52:57Z")

</div>

```auto
TFile *_file0 = TFile::Open("benchmark_nuclei_detailed.root")
Double_t iteration_weight;
TTreeReader reader("mas", _file0); //mas is the TTree
TTreeReaderValue<Double_t> my_branch_value(reader, "iteration_weight");
reader.SetEntry(1125103)
*my_branch_value

```

I’m not using a macro, I’m writing directly in the root interpreter (Cling by default?)

---

<div class="post-metadata">

**Author:** ![PPierre](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ebca7d/32.png) [@PPierre](https://root-forum.cern.ch/u/PPierre)\
**Post date:** [May 20, 2021, 5:57pm UTC](https://root-forum.cern.ch/t/issues-reading-a-single-value-in-a-branch/45003/5 "2021-05-20T17:57:38Z")

</div>

Sorry I tried two options, this was the first one :

```auto
TFile *_file0 = TFile::Open("benchmark_nuclei_detailed.root")
TTree* a=(TTree*)_file0->Get("mas")
double iteration_weight;
a->SetBranchAddress("iteration_weight",&iteration_weight);
a->GetEntry(1125103);
iteration_weight

```

With the same outcome …

---

<div class="post-metadata">

**Author:** ![PPierre](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ebca7d/32.png) [@PPierre](https://root-forum.cern.ch/u/PPierre)\
**Post date:** [May 20, 2021, 8:08pm UTC](https://root-forum.cern.ch/t/issues-reading-a-single-value-in-a-branch/45003/6 "2021-05-20T20:08:37Z")

</div>

I solved it, I missed to import a shared library.
