# Histogram RVec branch in RDataFrame

**URL:** <https://root-forum.cern.ch/t/histogram-rvec-branch-in-rdataframe/49342>\
**Category:** Newbie\
**Tags:** rdataframe\
**Created:** [March 24, 2022, 2:23pm UTC](https://root-forum.cern.ch/t/histogram-rvec-branch-in-rdataframe/49342 "2022-03-24T14:23:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![certley](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/e47774/32.png) [@certley](https://root-forum.cern.ch/u/certley)\
**Post date:** [March 24, 2022, 2:23pm UTC](https://root-forum.cern.ch/t/histogram-rvec-branch-in-rdataframe/49342/1 "2022-03-24T14:23:59Z")

</div>

In my TTree, I have an RVec branch for the energy in each detector channel. When using RDataFrame, why do I have to define a new column to create a histogram of a single channel? For example, why do you have to use this:

```auto
df = ROOT.RDataFrame('<treename>', 'root://<path/to/file>.root')
h = df.Define('px_0', 'px[0]').Histo1D('px_0')

```

instead of just using this:

```auto
df = ROOT.RDataFrame('<treename>', 'root://<path/to/file>.root')
h = df.Histo1D('px[0]')

```

* * *

_ROOT Version:_ 6.24/06  
_Platform:_ Mac 12.3  
_Compiler:_ Not Provided

* * *

---

<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:** [March 24, 2022, 2:39pm UTC](https://root-forum.cern.ch/t/histogram-rvec-branch-in-rdataframe/49342/2 "2022-03-24T14:39:56Z")

</div>

Hi @certley ,  
and welcome to the ROOT forum!

Allowing expressions in place of column names could be done; on one hand it would save typing for users, on the other it would encourage some not-so-nice usage patterns and complicate internals. See also my reply here: [Create Histogram of composite variable in RDataframe - #2 by eguiraud](https://root-forum.cern.ch/t/create-histogram-of-composite-variable-in-rdataframe/47365/2) .

I have been thinking about it and a possible middle ground would be:

```python
df.Histo1D(ROOT.RDF.ColExpr('px[0]'))

```

but I don’t know if it’s worth it 😅  
Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![certley](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/e47774/32.png) [@certley](https://root-forum.cern.ch/u/certley)\
**Post date:** [March 24, 2022, 2:58pm UTC](https://root-forum.cern.ch/t/histogram-rvec-branch-in-rdataframe/49342/3 "2022-03-24T14:58:32Z")

</div>

Thank you, that clears it up for me. Your link was also very helpful.
