Logo ROOT   6.16/01
Reference Guide
table.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve7
3/// This example display table in web browser
4///
5/// \macro_code
6///
7
8#include "ROOT/REveManager.hxx"
9#include "ROOT/REveDataClasses.hxx"
10#include <ROOT/REveScene.hxx>
11#include <ROOT/REveViewer.hxx>
12#include <ROOT/REveGeoShape.hxx>
13
14#include "TParticle.h"
15#include "TRandom.h"
16#include "TSystem.h"
17
18namespace REX = ROOT::Experimental;
19
20REX::REveManager *eveMng = nullptr;
21std::vector<TParticle> ext_col;
22
23void fill_ext_col(int N)
24{
25 ext_col.clear();
26 ext_col.reserve(N);
27
28 TRandom &r = *gRandom;
29 r.SetSeed(0);
30
31 for (int i = 1; i <= N; ++i)
32 {
33 double pt = r.Uniform(0.5, 10);
34 double eta = r.Uniform(-2.55, 2.55);
35 double phi = r.Uniform(0, TMath::TwoPi());
36
37 double px = pt * std::cos(phi);
38 double py = pt * std::sin(phi);
39 double pz = pt * (1. / (std::tan(2*std::atan(std::exp(-eta)))));
40
41 // printf("%2d: pt=%.2f, eta=%.2f, phi=%.2f\n", i, pt, eta, phi);
42
43 ext_col.push_back
44 (TParticle(0, 0, 0, 0, 0, 0,
45 px, py, pz, std::sqrt(px*px + py*py + pz*pz + 80*80),
46 0, 0, 0, 0 ));
47
48 int pdg = 11 * (r.Integer(2) > 0 ? 1 : -1);
49 ext_col.back().SetPdgCode(pdg);
50 }
51}
52
53void makeTableScene( REX::REveDataCollection* col)
54{
55
56 auto tbl = new REX::REveDataTable();
57
58 tbl->SetCollection(col);
59
60 {
61 auto c = new REX::REveDataColumn("pt");
62 tbl->AddElement(c);
63 c->SetExpressionAndType("std::abs(i.Pt())", REX::REveDataColumn::FT_Double);
64 }
65 {
66 auto c = new REX::REveDataColumn("phi");
67 tbl->AddElement(c);
68 c->SetExpressionAndType("i.Phi()", REX::REveDataColumn::FT_Double);
69 c->SetPrecision(3);
70 }
71
72 {
73 auto c = new REX::REveDataColumn("eta");
74 tbl->AddElement(c);
75 c->SetExpressionAndType("i.Eta()", REX::REveDataColumn::FT_Double);
76 c->SetPrecision(3);
77 }
78
79 auto scene = eveMng->SpawnNewScene("Table","Table");
80 scene->AddElement(tbl);
81 auto view = eveMng->SpawnNewViewer("Table", "Table");
82 view->AddScene(scene);
83}
84
85void table()
86{
87 eveMng = REX::REveManager::Create();
88
89 REX::REveElement* defaultViewer = (*eveMng->GetViewers()->BeginChildren());
90 defaultViewer->SetRnrSelf(false);
91
92 fill_ext_col(100);
93
94 auto col = new REX::REveDataCollection();
95
96 col->SetItemClass(TParticle::Class());
97
98 {
99 int i = 1;
100 for (auto &p : ext_col)
101 {
102 TString pname; pname.Form("Particle %2d", i++);
103
104 col->AddItem(&p, pname.Data(), "");
105 }
106 }
107 col->SetFilterExpr("i.Pt() > 1 && std::abs(i.Eta()) < 1");
108 col->ApplyFilter();
109 eveMng->GetWorld()->AddElement(col);
110
111 makeTableScene(col);
112
113 eveMng->Show();
114}
void Class()
Definition: Class.C:29
ROOT::R::TRInterface & r
Definition: Object.C:4
#define c(i)
Definition: RSha256.hxx:101
#define N
double cos(double)
double atan(double)
double tan(double)
double sqrt(double)
double sin(double)
double exp(double)
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
Description of the dynamic properties of a particle.
Definition: TParticle.h:26
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2264
TPaveText * pt
constexpr Double_t TwoPi()
Definition: TMath.h:45
std::vector< TParticle > ext_col
Definition: table.C:21
REX::REveManager * eveMng
Definition: table.C:20
void makeTableScene(REX::REveDataCollection *col)
Definition: table.C:53
void fill_ext_col(int N)
Definition: table.C:23
void table()
Definition: table.C:85