# Passing variable arguments to Define in RDataFrame

**URL:** <https://root-forum.cern.ch/t/passing-variable-arguments-to-define-in-rdataframe/57662>\
**Category:** Newbie\
**Created:** [December 24, 2023, 5:50pm UTC](https://root-forum.cern.ch/t/passing-variable-arguments-to-define-in-rdataframe/57662 "2023-12-24T17:50:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicconflo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/nicconflo/32/33351_2.png) [@nicconflo](https://root-forum.cern.ch/u/nicconflo)\
**Post date:** [December 24, 2023, 5:50pm UTC](https://root-forum.cern.ch/t/passing-variable-arguments-to-define-in-rdataframe/57662/1 "2023-12-24T17:50:29Z")

</div>

Hi all,

I’m a bit new to using RDataFrame, so I was wondering if someone had some insight on how to implement this. I have a function (let’s say a simple linear polynomial) that I wish to operate on every element in a tree, and want to change the coefficients in that function to see how the result changes. But it’s not clear to me how to pass those coefficients as arguments to Define, since it only seems to accept columns.

To make it a bit more clear, say I have some function:

> double polyFunc(p0, p1, x) { return p0 + p1\*x; }

And I am trying to do something like this:

> double par0 = 0.3;  
> double par1 = 5.7;  
> auto rdfPoly = rdf.Define(“polyn1d”, polyFunc, {par0, par1, “xVals”});

Which doesn’t work since the third argument in Define only seems to accept columns.

My goal is to have some more complicated function whose parameters I can tweak, but I’m stuck on how to do this basic thing, if it’s possible. Any feedback would be greatly appreciated!

Thanks!

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [December 25, 2023, 9:15am UTC](https://root-forum.cern.ch/t/passing-variable-arguments-to-define-in-rdataframe/57662/2 "2023-12-25T09:15:54Z")

</div>

Hi,

Thanks for the this question.  
I see two rough options to accomplish what I understand you are after (please correct me if I am wrong!).

The first one is really to `Define` columns with the function parameters values and use them as arguments of the function.  
The second one, is to wrap the function in a C++ lambda and capture the parameters _by reference_, like

```cpp
double p0 = 0.1;
double p1 = 0.3;
auto myFunc = [&p0, &p1] (double x) {return polyFunc(p0, p1 * x);};

```

I insist on the capture by reference to be able to change the value of the parameters at a later stage and have these values percolated inside the lambda.

I hope this helps.  
Cheers,  
D

---

<div class="post-metadata">

**Author:** ![nicconflo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/nicconflo/32/33351_2.png) [@nicconflo](https://root-forum.cern.ch/u/nicconflo)\
**Post date:** [December 27, 2023, 11:11pm UTC](https://root-forum.cern.ch/t/passing-variable-arguments-to-define-in-rdataframe/57662/3 "2023-12-27T23:11:59Z")

</div>

The capture method works perfectly–thank you!
