# How to create a Ntuple/Ttrees structure directly in JSROOT

**URL:** <https://root-forum.cern.ch/t/how-to-create-a-ntuple-ttrees-structure-directly-in-jsroot/48354>\
**Category:** Newbie\
**Tags:** jsroot\
**Created:** [January 12, 2022, 10:47am UTC](https://root-forum.cern.ch/t/how-to-create-a-ntuple-ttrees-structure-directly-in-jsroot/48354 "2022-01-12T10:47:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![je\_flc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/je_flc/32/28454_2.png) [@je\_flc](https://root-forum.cern.ch/u/je_flc)\
**Post date:** [January 12, 2022, 10:47am UTC](https://root-forum.cern.ch/t/how-to-create-a-ntuple-ttrees-structure-directly-in-jsroot/48354/1 "2022-01-12T10:47:35Z")

</div>

Is it possible to create a Ntuple/Ttrees structure directly in JSROOT and display it in the ROOT web browser?

I see how to create scater plots, and histograms in javascript, but not how to create ROOT objects hierarchy, is it possible to acheive this ?

Thanks in advance

JF

---

<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:** [January 12, 2022, 11:58am UTC](https://root-forum.cern.ch/t/how-to-create-a-ntuple-ttrees-structure-directly-in-jsroot/48354/2 "2022-01-12T11:58:21Z")

</div>

Hi,

JSROOT provides possibility to read data from existing `TTree` object from ROOT file.  
One can read selected branches and perform complex `TTree::Draw` operations.

It is not possible to create new TTree object and write it into the file.  
One should use ROOT C++ code for such purposes.  
ROOT provides `THttpServer` class which allows to use TTree object directly - via so called “player”.  
See snapshot of such functionality here:

> **[JSROOT API examples](https://root.cern/js/latest/api.htm#httpserver_c_tree_player)**
>
> Web page shows URL syntax and JSROOT API usage

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![je\_flc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/je_flc/32/28454_2.png) [@je\_flc](https://root-forum.cern.ch/u/je_flc)\
**Post date:** [January 12, 2022, 1:26pm UTC](https://root-forum.cern.ch/t/how-to-create-a-ntuple-ttrees-structure-directly-in-jsroot/48354/3 "2022-01-12T13:26:57Z")

</div>

Thanks for your clear answer,

I thought you will anser this…

I need JSROOT for some feature of ROOT in my web application, data is already in the DOM.

Can I use prototype of javascript JSROOT objects to manipulate/populate them myself ?

---

<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:** [January 12, 2022, 2:02pm UTC](https://root-forum.cern.ch/t/how-to-create-a-ntuple-ttrees-structure-directly-in-jsroot/48354/4 "2022-01-12T14:02:32Z")

</div>

> Can I use prototype of javascript JSROOT objects to manipulate/populate them myself

You can create histograms or graphs object directly in JavaScript. There are several such examples here:

> **[JSROOT API examples](https://root.cern/js/latest/api.htm)**
>
> Web page shows URL syntax and JSROOT API usage

Like: [th2](https://root.cern/js/latest/api.htm#custom_html_th2) or [multigraph](https://root.cern/js/latest/api.htm#custom_html_tmultigraph)

And some information can be found in reference:

[https://root.cern/js/latest/jsdoc/JSROOT.html#.createHistogram](https://root.cern/js/latest/jsdoc/JSROOT.html#.createHistogram)  
[https://root.cern/js/latest/jsdoc/JSROOT.html#.createTGraph](https://root.cern/js/latest/jsdoc/JSROOT.html#.createTGraph)

---

<div class="post-metadata">

**Author:** ![je\_flc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/je_flc/32/28454_2.png) [@je\_flc](https://root-forum.cern.ch/u/je_flc)\
**Post date:** [January 12, 2022, 2:02pm UTC](https://root-forum.cern.ch/t/how-to-create-a-ntuple-ttrees-structure-directly-in-jsroot/48354/5 "2022-01-12T14:02:56Z")

</div>

Hi again,  
I already tested  
root.cern/js/latest/jsdoc/JSROOT.html#.createHistogram  
and  
root.cern/js/latest/jsdoc/JSROOT.html#.createTGraph  
but how to create 3D scatter plots or other 3D objects?

Cheers  
JF

---

<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:** [January 12, 2022, 2:07pm UTC](https://root-forum.cern.ch/t/how-to-create-a-ntuple-ttrees-structure-directly-in-jsroot/48354/6 "2022-01-12T14:07:34Z")

</div>

> [@je\_flc](#):
>
> Or can I create 3D scatter plots

You want to use TH3 or TGraph2D objects?  
Example of supported draw options you can find here:

> **[JSROOT examples](https://root.cern/js/latest/examples.htm#th3)**
>
> Web page shows supported ROOT classes and correspondent draw options

---

<div class="post-metadata">

**Author:** ![je\_flc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/je_flc/32/28454_2.png) [@je\_flc](https://root-forum.cern.ch/u/je_flc)\
**Post date:** [January 12, 2022, 2:08pm UTC](https://root-forum.cern.ch/t/how-to-create-a-ntuple-ttrees-structure-directly-in-jsroot/48354/7 "2022-01-12T14:08:37Z")

</div>

Thanks, I am looking at this now!

---

<div class="post-metadata">

**Author:** ![je\_flc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/je_flc/32/28454_2.png) [@je\_flc](https://root-forum.cern.ch/u/je_flc)\
**Post date:** [January 12, 2022, 2:11pm UTC](https://root-forum.cern.ch/t/how-to-create-a-ntuple-ttrees-structure-directly-in-jsroot/48354/8 "2022-01-12T14:11:21Z")

</div>

But I cant find the code to populate those TH3 scatter from javascript,

it is exactly what I am after …

thanks to help me on this!

JF

---

<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:** [January 12, 2022, 2:17pm UTC](https://root-forum.cern.ch/t/how-to-create-a-ntuple-ttrees-structure-directly-in-jsroot/48354/9 "2022-01-12T14:17:47Z")

</div>

I will add example with TH3.

---

<div class="post-metadata">

**Author:** ![je\_flc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/je_flc/32/28454_2.png) [@je\_flc](https://root-forum.cern.ch/u/je_flc)\
**Post date:** [January 12, 2022, 2:37pm UTC](https://root-forum.cern.ch/t/how-to-create-a-ntuple-ttrees-structure-directly-in-jsroot/48354/10 "2022-01-12T14:37:02Z")

</div>

that will be great if you can give me the code to populate a 3D scatter plots with 3 series of floats.

thanks in advance

JF

---

<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:** [January 12, 2022, 3:20pm UTC](https://root-forum.cern.ch/t/how-to-create-a-ntuple-ttrees-structure-directly-in-jsroot/48354/11 "2022-01-12T15:20:43Z")

</div>

Here is demo:

> **[JSROOT API examples](https://jsroot.gsi.de/dev/api.htm#custom_html_th3)**
>
> Web page shows URL syntax and JSROOT API usage

And this is source code:

> <https://github.com/root-project/jsroot/blob/master/demo/th3.htm>

---

<div class="post-metadata">

**Author:** ![je\_flc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/je_flc/32/28454_2.png) [@je\_flc](https://root-forum.cern.ch/u/je_flc)\
**Post date:** [January 12, 2022, 4:21pm UTC](https://root-forum.cern.ch/t/how-to-create-a-ntuple-ttrees-structure-directly-in-jsroot/48354/12 "2022-01-12T16:21:13Z")

</div>

perfect.

thanks a LOT!

Cheers  
JF
