# How to draw a TH1 from a TTree branch with a selection in JSROOT?

**URL:** <https://root-forum.cern.ch/t/how-to-draw-a-th1-from-a-ttree-branch-with-a-selection-in-jsroot/60402>\
**Category:** ROOT\
**Tags:** jsroot\
**Created:** [August 2, 2024, 12:44pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-th1-from-a-ttree-branch-with-a-selection-in-jsroot/60402 "2024-08-02T12:44:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ma128-bit](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ma128-bit/32/37217_2.png) [@Ma128-bit](https://root-forum.cern.ch/u/Ma128-bit)\
**Post date:** [August 2, 2024, 12:44pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-th1-from-a-ttree-branch-with-a-selection-in-jsroot/60402/1 "2024-08-02T12:44:23Z")

</div>

Dear experts,

I’m new to using JSROOT. I was wondering if there is a way to draw a TH1, from a TBranch of a TTree, by applying a selection directly from the web interface, without modifying the JavaScript code.

For instance, by opening this sample file:

```auto
https://root.cern.ch/js/latest/api.htm#url_syntax_open_file

```

I would like to display the following histogram:

```auto
ntuple->Draw(“px”, “py>0”)

```

Thank you in advance for your assistance.

Best regards,

Marco

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [August 2, 2024, 12:49pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-th1-from-a-ttree-branch-with-a-selection-in-jsroot/60402/2 "2024-08-02T12:49:57Z")

</div>

Hi Marco,

There is section [“TTree draw”](https://github.com/root-project/jsroot/blob/master/docs/JSROOT.md#ttree-draw) in JSROOT documentation.

It also explains how to use cut expression. In your case draw option for the tree should be “px::py\>0”. Full link is:

`https://root.cern/js/latest/?file=../files/hsimple.root&item=ntuple&opt=px::py>0`

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![Ma128-bit](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ma128-bit/32/37217_2.png) [@Ma128-bit](https://root-forum.cern.ch/u/Ma128-bit)\
**Post date:** [August 2, 2024, 1:10pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-th1-from-a-ttree-branch-with-a-selection-in-jsroot/60402/3 "2024-08-02T13:10:22Z")

</div>

Hi Sergey,

It worked. Thank you very much for your prompt response.

Best regards,  
Marco

---

<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:** [August 16, 2024, 1:10pm UTC](https://root-forum.cern.ch/t/how-to-draw-a-th1-from-a-ttree-branch-with-a-selection-in-jsroot/60402/4 "2024-08-16T13:10:30Z")

</div>

Closed on August 16, 2024, 1:10pm UTC

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