# Create Histogram of composite variable in RDataframe

**URL:** <https://root-forum.cern.ch/t/create-histogram-of-composite-variable-in-rdataframe/47365>\
**Category:** Evolution Proposals, Apps & Ideas\
**Tags:** rdataframe\
**Created:** [October 22, 2021, 2:03pm UTC](https://root-forum.cern.ch/t/create-histogram-of-composite-variable-in-rdataframe/47365 "2021-10-22T14:03:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [October 22, 2021, 3:23pm UTC](https://root-forum.cern.ch/t/create-histogram-of-composite-variable-in-rdataframe/47365/2 "2021-10-22T15:23:51Z")

</div>

Hi @avilla ,  
there is no technical reason, it was a difficult, much discussed design choice (and it’s still being discussed 😃 ).

The upside is obvious: less typing.

The downsides are sneaky. Here’s some I could think of:

1. It encourages users to write less efficient code:

```cpp
df.Histo1D("log(D0_TAU)", "weight1")
df.Histo1D("log(D0_TAU)", "weight2")

```

now will evaluate the logarithm twice, while

```cpp
auto df2 = df.Define("logd0", "log(D0_TAU)")
df2.Histo1D("logd0", "weight1")
df2.Histo1D("logd0", "weight2")

```

only evaluates the logarithm once per event as the dependency is clear.  
There is some machinery to go from the string expression to executable code that would also have to run twice rather than once.

1. It removes the clear separation between where you can put an expression and where you can put a column name (or list thereof):

```cpp
df.Histo1D("sqrt(x)", "weight > 10 ? 10 : weight")

```

is nice, but

```cpp
df.Snapshot(..., {"sqrt(x)", "x*x"})

```

does not make sense (wouldn’t know what name to give to the output columns). So now you have _some_ places where you can use either column names or expressions and some others where it has to be a plain column name.

1. Not the most important reason, but it would complicate internals

So that’s why I’m not completely sold on the idea…doesn’t mean I’m right, but it’s not simple either.  
Cheers,  
Enrico

---

_[View the full topic](https://root-forum.cern.ch/t/create-histogram-of-composite-variable-in-rdataframe/47365)._
