# Mixing events in ROOT RDataFrame

**URL:** <https://root-forum.cern.ch/t/mixing-events-in-root-rdataframe/51749>\
**Category:** ROOT\
**Tags:** rdataframe\
**Created:** [September 29, 2022, 3:48am UTC](https://root-forum.cern.ch/t/mixing-events-in-root-rdataframe/51749 "2022-09-29T03:48:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![denerslemos](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/denerslemos/32/31001_2.png) [@denerslemos](https://root-forum.cern.ch/u/denerslemos)\
**Post date:** [September 29, 2022, 3:48am UTC](https://root-forum.cern.ch/t/mixing-events-in-root-rdataframe/51749/1 "2022-09-29T03:48:00Z")

</div>

Hi all, @eguiraud,

I have a similar question as in

> [@Event mixing with RDataFrame](https://root-forum.cern.ch/t/event-mixing-with-rdataframe/48009):
>
> Hi all, I am currently discovering the RDataFrame tool, and I was wondering if mixing events are possible. I couldn’t see anything close to it in the different tutorials. Let´s say I have a Tree with a Jpsi and its muons for each entry, how can I get something like the difference of the pseudorapidity of the j/psi in entry 1 and the pseudorapidity of the j/psi in entry 2 (or any other uncorrelated entry). Maybe it is better to use plain ROOT for this kind of thing but if anybody knows somethi…

In my analysis I am interested to do correlations between different particles (let us call 1 and 2). Such correlations are corrected by mixing events, which means we fill the histograms using particle 1 and particle 2 (let say pT difference) from the same events and divide by the same distribution using particle 1 from event (or entry) 1 (let say nominal) and particle 2 from another entry (event) and/or vice-versa. Usually we do mixing by using 20 (or more) mixed events for each “nominal” event. Do you know if is still possible to use this type of mixing event in RDataFrame? Would be good to use multithreading, but if not possible, the single thread also must help.

Thank you so much in advice

Best regards,  
Dener

---

<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:** [September 30, 2022, 7:42am UTC](https://root-forum.cern.ch/t/mixing-events-in-root-rdataframe/51749/2 "2022-09-30T07:42:44Z")

</div>

Hi @denerslemos ,

I am afraid there is no built-in support in RDF for something like this 😕 What you can do is keep a sliding window with the values you are interested in for the last 20 events (like it’s done in the post you link to), but for random mixing it’s probably much simpler to do it with direct usage of TTreeReader or similar.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![denerslemos](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/denerslemos/32/31001_2.png) [@denerslemos](https://root-forum.cern.ch/u/denerslemos)\
**Post date:** [October 5, 2022, 3:24pm UTC](https://root-forum.cern.ch/t/mixing-events-in-root-rdataframe/51749/3 "2022-10-05T15:24:55Z")

</div>

Hi @eguiraud , sorry for the delay

Yeah, I think is hard to do mixing events using RDataFrame, since events must also match within similar vertex z and similar multiplicity.

Thank you so much for your answer.

Best regards,  
Dener

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [October 19, 2022, 3:25pm UTC](https://root-forum.cern.ch/t/mixing-events-in-root-rdataframe/51749/4 "2022-10-19T15:25:56Z")

</div>

Closed on October 19, 2022, 3:25pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
