# Need an example that can covert data to tevetrack and tevepointset for jsroot

**URL:** <https://root-forum.cern.ch/t/need-an-example-that-can-covert-data-to-tevetrack-and-tevepointset-for-jsroot/50432>\
**Category:** Newbie\
**Tags:** jsroot\
**Created:** [June 16, 2022, 9:10am UTC](https://root-forum.cern.ch/t/need-an-example-that-can-covert-data-to-tevetrack-and-tevepointset-for-jsroot/50432 "2022-06-16T09:10:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iyuicu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/iyuicu/32/30021_2.png) [@iyuicu](https://root-forum.cern.ch/u/iyuicu)\
**Post date:** [June 16, 2022, 9:10am UTC](https://root-forum.cern.ch/t/need-an-example-that-can-covert-data-to-tevetrack-and-tevepointset-for-jsroot/50432/1 "2022-06-16T09:10:48Z")

</div>

* * *

_ROOT Version:_ 6.27/01  
_Platform:_ Ubuntu 20.04  
_Compiler:_ c++ (GCC) 11.2.0

* * *

Dear Experts!

I am a beginner with root. In our group, we are working for a simulation project. I’m asked to develop a simple event displayer. I planned to use jsroot, then I built an jsroot server and imported our detector geometry. They’re working properly! But as an event displayer, it needs to show some hits and tracks. I have many data that the simulation program worked out. As [the post](https://root-forum.cern.ch/t/jsroot-geometry-item/47438) have said, I need a root program that can convert this data to `TEvePointSet` and ` TEveTrack`. But I find it’s hard to find an example program that can generate data like [this](https://root.cern/js/files/geom/tracks_hits.root).

So could anyone give me an example program that can randomly generated some data then save as `TEvePointSet` or ` TEveTrack` object into a `.root` file (like [tracks\_hits.root](https://root.cern/js/files/geom/tracks_hits.root))?

Thanks a lot for any help

---

<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:** [June 16, 2022, 12:32pm UTC](https://root-forum.cern.ch/t/need-an-example-that-can-covert-data-to-tevetrack-and-tevepointset-for-jsroot/50432/2 "2022-06-16T12:32:11Z")

</div>

Hi and welcome on the forum.

Meanwhile one can use other classes in jsroot to display tracks and hits.  
For tracks - [TPolyLine3D](https://root.cern/doc/master/classTPolyLine3D.html) and for hits - [TPolyMarker3D](https://root.cern/doc/master/classTPolyMarker3D.html)  
Most simple way is to create `TList` object, add all tracks and hits there and then append that list to geometry drawing.

Regards,  
Sergey

---

<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:** [June 16, 2022, 2:04pm UTC](https://root-forum.cern.ch/t/need-an-example-that-can-covert-data-to-tevetrack-and-tevepointset-for-jsroot/50432/3 "2022-06-16T14:04:05Z")

</div>

There is also possibility to add several `TGeoTrack` to geometry.  
See [ROOT: tutorials/http/httpgeom.C File Reference](https://root.cern/doc/master/httpgeom_8C.html)  
Unfortunately, there is no such class for hits.

---

<div class="post-metadata">

**Author:** ![iyuicu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/iyuicu/32/30021_2.png) [@iyuicu](https://root-forum.cern.ch/u/iyuicu)\
**Post date:** [June 18, 2022, 10:33am UTC](https://root-forum.cern.ch/t/need-an-example-that-can-covert-data-to-tevetrack-and-tevepointset-for-jsroot/50432/4 "2022-06-18T10:33:30Z")

</div>

Sorry, it took me some time to learn [how to save `TList`](https://root-forum.cern.ch/t/saving-tlist-in-root-file/29366/2). Your advice help me a lot! I put the simplest example below that can generate some random data and save as root file. By the way, what are the differences between `TPolyLine3D` & `TGeoTrack` & `TEveTrack` and `TPolyMarker3D` & `TEvePointSet`? They look same in JSROOT. What do you recommend for event displayer?

Thank you,  
Aiyu

```c++
void random_hits_tracks()
{
    const Int_t n_hits = 150;
    TPolyMarker3D *hits = new TPolyMarker3D(n_hits, 1);

    Double_t x, y, z;
    auto r = new TRandom();

    hits->SetMarkerColor(kGreen);
    for (Int_t i=0;i<n_hits;i++) {
        r->Sphere(x, y, z, 30);
        hits->SetPoint(i,x+1,y+1,z+1);
    }

    const Int_t n_tracks_points = 150;
    const Int_t scale_tracks = 10;
    TPolyLine3D *tracks = new TPolyLine3D(n_tracks_points);
    for (Int_t i=0;i<n_tracks_points;i++) {
        tracks->SetPoint(i,scale_tracks*std::sin(.1*i),scale_tracks*std::cos(.1*i),0.1*i);
    }

    tracks->SetLineColor(kRed);
    // tracks->SetLineWidth(20); //doesn't work
    

    TFile* f = new TFile("random_hits_tracks.root", "recreate");
    TList* fList_hits = new TList();
    fList_hits->Add(hits,"testhit1");
    TList* fList_tracks = new TList();
    fList_tracks->Add(tracks,"testtrack1");
    
    f->cd();
    fList_hits->Write("testhit", 1);
    fList_tracks->Write("testtrack", 1);
    f->Close();
}

```

---

<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:** [June 18, 2022, 11:00am UTC](https://root-forum.cern.ch/t/need-an-example-that-can-covert-data-to-tevetrack-and-tevepointset-for-jsroot/50432/5 "2022-06-18T11:00:37Z")

</div>

Hi,

> What do you recommend for event displayer?

It is up to you. If you starts from scratch - then just use `TPolyLine3D` and `TPolyMarker3D`.

Regards,  
Sergey
