# Delphes root files and RDataFrame

**URL:** <https://root-forum.cern.ch/t/delphes-root-files-and-rdataframe/64329>\
**Category:** ROOT\
**Tags:** rdataframe, python, tree, hist, root\
**Created:** [October 17, 2025, 6:59am UTC](https://root-forum.cern.ch/t/delphes-root-files-and-rdataframe/64329 "2025-10-17T06:59:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ammelsayed](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ammelsayed/32/39472_2.png) [@ammelsayed](https://root-forum.cern.ch/u/ammelsayed)\
**Post date:** [October 17, 2025, 6:59am UTC](https://root-forum.cern.ch/t/delphes-root-files-and-rdataframe/64329/1 "2025-10-17T06:59:51Z")

</div>

* * *

Hi,

I’m trying to preform some analysis cuts using RDataFrame from root files generated by Delphes. But I seem to encounter a problem with reading particles data from arrays. As i understand, in a delphes file, an event may contain more than one same particle, like electron or muon. If i do

```python
df = ROOT.RDataFrame("Delphes", filepath)
hist = df.Histo1D("Muon_size")
hist.Draw()

```

I get a histogram describing the distribution of muon numbers per event. For a particular event, that has say 2 muons, the Muon.PT branch contains an array that stores the pT of the two muons. When i try to the read the pT distrubution of the muons, with:

```python
hist = df.Histo1D("Muon.PT")
hist.Draw()

```

I get a distribution for all muons in the file. But if i chose to look for the leading muons in pT, or subleading as follows:

```python
hist = df.Histo1D("Muon.PT[0]")
hist.Draw()

```

I get the following error:

```bash
cppyy.gbl.std.runtime_error: Template method resolution failed:
  ROOT::RDF::RResultPtr<TH1D> ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void>::Histo1D(string_view vName) =>
    runtime_error: Unknown column: "Muon.PT[0]"

```

I’ve being trying many methods but none of them worked. Can please someone help me with this problem?

_ROOT Version:_ 6.32.12  
_Platform:_ Linux  
_Compiler:_ PyROOT

* * *

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [October 17, 2025, 8:03am UTC](https://root-forum.cern.ch/t/delphes-root-files-and-rdataframe/64329/2 "2025-10-17T08:03:44Z")

</div>

Welcome to the ROOT Forum!  
Maybe @vpadulan can help here

---

<div class="post-metadata">

**Author:** ![silverweed](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/silverweed/32/36670_2.png) [@silverweed](https://root-forum.cern.ch/u/silverweed)\
**Post date:** [October 17, 2025, 8:09am UTC](https://root-forum.cern.ch/t/delphes-root-files-and-rdataframe/64329/3 "2025-10-17T08:09:03Z")

</div>

Hi @ammelsayed,

Not a RDF expert, but could you try this?

```python
hist = df.Define("LeadingMuon", "Muon.PT[0]").Histo1D("LeadingMuon")
hist.Draw()

```

---

<div class="post-metadata">

**Author:** ![ammelsayed](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ammelsayed/32/39472_2.png) [@ammelsayed](https://root-forum.cern.ch/u/ammelsayed)\
**Post date:** [October 17, 2025, 8:20am UTC](https://root-forum.cern.ch/t/delphes-root-files-and-rdataframe/64329/4 "2025-10-17T08:20:01Z")

</div>

Hi @silverweed

It actually worked! But why, this is so strange 🙂 !!!

---

<div class="post-metadata">

**Author:** ![silverweed](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/silverweed/32/36670_2.png) [@silverweed](https://root-forum.cern.ch/u/silverweed)\
**Post date:** [October 17, 2025, 8:33am UTC](https://root-forum.cern.ch/t/delphes-root-files-and-rdataframe/64329/5 "2025-10-17T08:33:48Z")

</div>

The reason is that `Histo1D` accepts a _column name_ and not an expression, so you first need to `Define` a new column (which can use arbitrary expressions, including accessing other columns) and then you can do operations on the newly defined column.  
Think about Define as “assigning a variable” that is then available for all further operations 🙂

---

<div class="post-metadata">

**Author:** ![ammelsayed](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ammelsayed/32/39472_2.png) [@ammelsayed](https://root-forum.cern.ch/u/ammelsayed)\
**Post date:** [October 17, 2025, 8:42am UTC](https://root-forum.cern.ch/t/delphes-root-files-and-rdataframe/64329/6 "2025-10-17T08:42:05Z")

</div>

This really helpt me. Thank you very much !!!

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [October 17, 2025, 9:14am UTC](https://root-forum.cern.ch/t/delphes-root-files-and-rdataframe/64329/7 "2025-10-17T09:14:32Z")

</div>

Dear @ammelsayed ,

Thanks for reaching out! I absolutely agree with @silverweed , that is the right way to go. Just to give further context, allowing `Histo1D("Muon.PT[0]")` would be equivalent to allowing `Histo1D(“run_my_very_complicated_function_that_may_return_a_value_not_acceptable_for_a_histogram”)`, so RDataFrame really prefers making this distinction between a column (either on-disk or defined) and an expression, the latter being only usable in the parts of API that transform data (e.g. `Define` or `Filter`) but not in the parts of the API that declare a result (e.g. `Histo1D`, `Mean`, `Sum` etc.).

Cheers,

Vincenzo

---

<div class="post-metadata">

**Author:** ![ammelsayed](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ammelsayed/32/39472_2.png) [@ammelsayed](https://root-forum.cern.ch/u/ammelsayed)\
**Post date:** [October 20, 2025, 6:14am UTC](https://root-forum.cern.ch/t/delphes-root-files-and-rdataframe/64329/8 "2025-10-20T06:14:03Z")

</div>

Dear @vpadulan

Thanks a lot for the clear explanation, this really helps me. RDF is really great for making quick analysis, its very helpful!.

---

<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:** [November 3, 2025, 6:14am UTC](https://root-forum.cern.ch/t/delphes-root-files-and-rdataframe/64329/9 "2025-11-03T06:14:43Z")

</div>

Closed on November 3, 2025, 6:14am UTC

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