# Reading TClonesArray as a TChain in pyroot

**URL:** <https://root-forum.cern.ch/t/reading-tclonesarray-as-a-tchain-in-pyroot/54520>\
**Category:** Newbie\
**Created:** [April 17, 2023, 9:45am UTC](https://root-forum.cern.ch/t/reading-tclonesarray-as-a-tchain-in-pyroot/54520 "2023-04-17T09:45:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ROOTer1](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/977dab/32.png) [@ROOTer1](https://root-forum.cern.ch/u/ROOTer1)\
**Post date:** [April 17, 2023, 9:45am UTC](https://root-forum.cern.ch/t/reading-tclonesarray-as-a-tchain-in-pyroot/54520/1 "2023-04-17T09:45:44Z")

</div>

Dear, I have a rootfile with a set of TClonesArray’s, I was wondering how I can read it in a loop in the same way as for TChain:

```auto
chain = ROOT.TChain()
chain.Add("path_to_rootfile/tree")

TD_hist = ROOT.TH2F()

for iev in chain:
    TD_hist.Fill(iev.var2, iev.var1)

```

* * *

---

<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:** [April 17, 2023, 12:16pm UTC](https://root-forum.cern.ch/t/reading-tclonesarray-as-a-tchain-in-pyroot/54520/2 "2023-04-17T12:16:50Z")

</div>

The `tutorials/tree/tcl.C` tutorial might help

---

<div class="post-metadata">

**Author:** ![ROOTer1](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/977dab/32.png) [@ROOTer1](https://root-forum.cern.ch/u/ROOTer1)\
**Post date:** [April 17, 2023, 1:09pm UTC](https://root-forum.cern.ch/t/reading-tclonesarray-as-a-tchain-in-pyroot/54520/3 "2023-04-17T13:09:30Z")

</div>

Is there any pyroot version? many thanks !!

---

<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:** [April 17, 2023, 1:10pm UTC](https://root-forum.cern.ch/t/reading-tclonesarray-as-a-tchain-in-pyroot/54520/4 "2023-04-17T13:10:50Z")

</div>

I don’t think so…

---

<div class="post-metadata">

**Author:** ![ROOTer1](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/977dab/32.png) [@ROOTer1](https://root-forum.cern.ch/u/ROOTer1)\
**Post date:** [April 17, 2023, 2:06pm UTC](https://root-forum.cern.ch/t/reading-tclonesarray-as-a-tchain-in-pyroot/54520/5 "2023-04-17T14:06:36Z")

</div>

Is there any chance to just get one line of code that actually reads the TClonesArray in a loop similar to my example? I can’t get around TClonesArray for some reasons

---

<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:** [April 17, 2023, 2:09pm UTC](https://root-forum.cern.ch/t/reading-tclonesarray-as-a-tchain-in-pyroot/54520/6 "2023-04-17T14:09:58Z")

</div>

Not sure how to do this in PyROOT. Maybe @vpadulan can help
