Logo ROOT   6.16/01
Reference Guide
collection.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve7
3/// This example display collection of ??? in web browser
4///
5/// \macro_code
6///
7
8#include <ROOT/REvePointSet.hxx>
9#include <ROOT/REveScene.hxx>
10#include <ROOT/REveJetCone.hxx>
11#include <ROOT/REveGeoShape.hxx>
12#include "ROOT/REveDataClasses.hxx"
13#include <ROOT/REveTrack.hxx>
14#include <ROOT/REveTrackPropagator.hxx>
15#include <ROOT/REveViewer.hxx>
16#include <ROOT/REveProjectionManager.hxx>
17#include "ROOT/REveManager.hxx"
18
19#include "TParticle.h"
20#include "TRandom.h"
21#include "TGeoTube.h"
22
23namespace REX = ROOT::Experimental;
24
25const Double_t kR_min = 240;
26const Double_t kR_max = 250;
27const Double_t kZ_d = 300;
28REX::REveManager *eveMng = nullptr;
29std::vector<TParticle> ext_col;
30
31REX::REveProjectionManager *mngRhoPhi = nullptr;
32REX::REveProjectionManager *mngRhoZ = nullptr;
33REX::REveScene *rPhiGeomScene = nullptr, *rPhiEventScene = nullptr;
34REX::REveScene *rhoZGeomScene = nullptr, *rhoZEventScene = nullptr;
35REX::REveViewer *rphiView = nullptr;
36REX::REveViewer *rhoZView = nullptr;
37
38REX::REvePointSet *getPointSet(int npoints = 2, float s=2, int color=28)
39{
40 TRandom &r = *gRandom;
41
42 REX::REvePointSet* ps = new REX::REvePointSet("fu", npoints);
43
44 for (Int_t i=0; i<npoints; ++i)
45 ps->SetNextPoint(r.Uniform(-s,s), r.Uniform(-s,s), r.Uniform(-s,s));
46
47 ps->SetMarkerColor(color);
48 ps->SetMarkerSize(3+r.Uniform(1, 2));
49 ps->SetMarkerStyle(4);
50 return ps;
51}
52
53void addJets()
54{
55 TRandom &r = *gRandom;
56
57 REX::REveElement* event = eveMng->GetEventScene();
58 auto jetHolder = new REX::REveElementList("Jets");
59 int N_Jets = 5;
60 for (int i = 0; i < N_Jets; i++)
61 {
62 auto jet = new REX::REveJetCone("Jet_1");
63 jet->SetCylinder(2*kR_max, 2*kZ_d);
64 jet->AddEllipticCone(r.Uniform(-3.5, 3.5), r.Uniform(0, TMath::TwoPi()),
65 r.Uniform(0.02, 0.2), r.Uniform(0.02, 0.3));
66 jet->SetFillColor(kYellow);
67 jet->SetLineColor(kYellow - 7);
68
69 jetHolder->AddElement(jet);
70 }
71 event->AddElement(jetHolder);
72}
73
74void fill_ext_col(int N)
75{
76 ext_col.clear();
77 ext_col.reserve(N);
78
79 TRandom &r = * gRandom;
80 r.SetSeed(0);
81
82 for (int i = 1; i <= N; ++i)
83 {
84 double pt = r.Uniform(0.5, 10);
85 double eta = r.Uniform(-2.55, 2.55);
86 double phi = r.Uniform(0, TMath::TwoPi());
87
88 double px = pt * std::cos(phi);
89 double py = pt * std::sin(phi);
90 double pz = pt * (1. / (std::tan(2*std::atan(std::exp(-eta)))));
91
92 // printf("%2d: pt=%.2f, eta=%.2f, phi=%.2f\n", i, pt, eta, phi);
93
94 ext_col.push_back
95 (TParticle(0, 0, 0, 0, 0, 0,
96 px, py, pz, std::sqrt(px*px + py*py + pz*pz + 80*80),
97 0, 0, 0, 0 ));
98
99 int pdg = 11 * (r.Integer(2) > 0 ? 1 : -1);
100 ext_col.back().SetPdgCode(pdg);
101 }
102}
103
105{
106 auto b1 = new REX::REveGeoShape("Barrel 1");
107 float s = 0.2;
108 b1->SetShape(new TGeoTube(kR_min*s, kR_max*s, kZ_d*s));
109 b1->SetFillColor(kGray);
110 eveMng->GetGlobalScene()->AddElement(b1);
111
112 auto b2 = new REX::REveGeoShape("Barell 2");
113 b2->SetShape(new TGeoTube(kR_min, kR_max, kZ_d));
114 b2->SetFillColor(kGray);
115 b2->SetMainTransparency(80);
116 eveMng->GetGlobalScene()->AddElement(b2);
117}
118
119
120void makeEventScene(REX::REveDataCollection* col)
121{
122 REX::REveElement* event = eveMng->GetEventScene();
123
124 auto prop = new REX::REveTrackPropagator();
125 prop->SetMagFieldObj(new REX::REveMagFieldDuo(350, -3.5, 2.0));
126 prop->SetMaxR(300);
127 prop->SetMaxZ(600);
128 prop->SetMaxOrbs(0.5);
129 REX::REveElement* trackHolder = new REX::REveElementList("Tracks");
130
131 int i = 0;
132 for (auto &p : ext_col)
133 {
134 TString pname; pname.Form("Particle %2d", i+1);
135
136 auto track = new REX::REveTrack(&p, 1, prop);
137 track->SetMainColor(kBlue+2);
138 track->MakeTrack();
139
140
141 track->SetElementName(pname.Data());
142 track->SetRnrSelf(!col->GetDataItem(i)->GetFiltered());
143 printf("track %s [filtered %d/%d]: eta= %.2f, pt=%.2f \n", track->GetElementName(),col->GetDataItem(i)->GetFiltered(), track->GetRnrSelf(), p.Eta(), p.Phi());
144 trackHolder->AddElement(track);
145 i++;
146 }
147 event->AddElement(trackHolder);
148
149 // points
150 {
151 auto ps1 = getPointSet(20, 40);
152 ps1->SetElementName("Points_1");
153 ps1->SetMainColor(kRed);
154 event->AddElement(ps1);
155 }
156
157 {
158 auto ps1 = getPointSet(100, 10);
159 ps1->SetElementName("Points_2");
160 ps1->SetMainColor(kCyan);
161 event->AddElement(ps1);
162 }
163 addJets();
164}
165
166void makeTableScene( REX::REveDataCollection* col)
167{
168 // --------------------------------
169
170 auto tbl = new REX::REveDataTable();
171
172 tbl->SetCollection(col);
173
174 {
175 auto c = new REX::REveDataColumn("pt");
176 tbl->AddElement(c);
177 c->SetExpressionAndType("std::abs(i.Pt())", REX::REveDataColumn::FT_Double);
178 }
179
180 {
181 auto c = new REX::REveDataColumn("phi");
182 tbl->AddElement(c);
183 c->SetExpressionAndType("i.Phi()", REX::REveDataColumn::FT_Double);
184 c->SetPrecision(3);
185 }
186
187 {
188 auto c = new REX::REveDataColumn("eta");
189 tbl->AddElement(c);
190 c->SetExpressionAndType("i.Eta()", REX::REveDataColumn::FT_Double);
191 c->SetPrecision(3);
192 }/*
193 {
194 auto c2 = new REX::REveDataColumn("is_central");
195 tbl->AddElement(c2);
196 c2->SetExpressionAndType("std::abs(i.Eta()) < 1.0", REX::REveDataColumn::FT_Bool);
197 }*/
198 // tbl->PrintTable();
199
200 auto scene = eveMng->SpawnNewScene("Table","Table");
201 scene->AddElement(tbl);
202 auto view = eveMng->SpawnNewViewer("Table", "Table");
203 view->AddScene(scene);
204}
205
206
208{
209 /*
210 // project RhoPhi
211 rPhiGeomScene = eveMng->SpawnNewScene("RPhi Geometry","RPhi");
212 rPhiEventScene = eveMng->SpawnNewScene("RPhi Event Data","RPhi");
213
214 mngRhoPhi = new REX::REveProjectionManager(REX::REveProjection::kPT_RPhi);
215
216 rphiView = eveMng->SpawnNewViewer("RPhi View", "");
217 rphiView->AddScene(rPhiGeomScene);
218 rphiView->AddScene(rPhiEventScene);
219
220 // ----------------------------------------------------------------
221 */
222 rhoZGeomScene = eveMng->SpawnNewScene("RhoZ Geometry", "RhoZ");
223 rhoZEventScene = eveMng->SpawnNewScene("RhoZ Event Data","RhoZ");
224
225 mngRhoZ = new REX::REveProjectionManager(REX::REveProjection::kPT_RhoZ);
226
227 rhoZView = eveMng->SpawnNewViewer("RhoZ View", "");
228 rhoZView->AddScene(rhoZGeomScene);
229 rhoZView->AddScene(rhoZEventScene);
230}
231
232void projectScenes(bool geomp, bool eventp)
233{
234 if (geomp)
235 {
236 for (auto & ie : eveMng->GetGlobalScene()->RefChildren())
237 {
238 // mngRhoPhi->ImportElements(ie, rPhiGeomScene);
239 mngRhoZ ->ImportElements(ie, rhoZGeomScene);
240 }
241 }
242 if (eventp)
243 {
244 for (auto & ie : eveMng->GetEventScene()->RefChildren())
245 {
246 // mngRhoPhi->ImportElements(ie, rPhiEventScene);
247 mngRhoZ ->ImportElements(ie, rhoZEventScene);
248 }
249 }
250}
251
253{
254 eveMng = REX::REveManager::Create();
255
256 fill_ext_col(100);
257
258 auto col = new REX::REveDataCollection();
259
260 col->SetItemClass(TParticle::Class());
261
262 {
263 int i = 1;
264 for (auto &p : ext_col)
265 {
266 TString pname; pname.Form("Particle %2d", i++);
267
268 col->AddItem(&p, pname.Data(), "");
269 }
270 }
271 col->SetFilterExpr("i.Pt() > 1 && std::abs(i.Eta()) < 1");
272 col->ApplyFilter();
273 eveMng->GetWorld()->AddElement(col);
274
275 // --------------------------------
276
278 makeEventScene(col);
280 projectScenes(true, true);
281 makeTableScene(col);
282
283 eveMng->Show();
284}
void Class()
Definition: Class.C:29
ROOT::R::TRInterface & r
Definition: Object.C:4
#define c(i)
Definition: RSha256.hxx:101
int Int_t
Definition: RtypesCore.h:41
double Double_t
Definition: RtypesCore.h:55
@ kGray
Definition: Rtypes.h:62
@ kRed
Definition: Rtypes.h:63
@ kCyan
Definition: Rtypes.h:63
@ kBlue
Definition: Rtypes.h:63
@ kYellow
Definition: Rtypes.h:63
#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
Cylindrical tube class.
Definition: TGeoTube.h:18
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
REX::REveScene * rPhiGeomScene
Definition: collection.C:33
void addJets()
Definition: collection.C:53
REX::REveScene * rPhiEventScene
Definition: collection.C:33
std::vector< TParticle > ext_col
Definition: collection.C:29
const Double_t kR_max
Definition: collection.C:26
REX::REveProjectionManager * mngRhoZ
Definition: collection.C:32
REX::REveManager * eveMng
Definition: collection.C:28
void makeEventScene(REX::REveDataCollection *col)
Definition: collection.C:120
void makeTableScene(REX::REveDataCollection *col)
Definition: collection.C:166
void fill_ext_col(int N)
Definition: collection.C:74
REX::REveViewer * rhoZView
Definition: collection.C:36
const Double_t kZ_d
Definition: collection.C:27
REX::REveScene * rhoZEventScene
Definition: collection.C:34
void createProjectionStuff()
Definition: collection.C:207
REX::REveViewer * rphiView
Definition: collection.C:35
void makeGeometryScene()
Definition: collection.C:104
REX::REveProjectionManager * mngRhoPhi
Definition: collection.C:31
void collection()
Definition: collection.C:252
REX::REveScene * rhoZGeomScene
Definition: collection.C:34
void projectScenes(bool geomp, bool eventp)
Definition: collection.C:232
REX::REvePointSet * getPointSet(int npoints=2, float s=2, int color=28)
Definition: collection.C:38
const Double_t kR_min
Definition: collection.C:25
TPaveText * pt
const Int_t N_Jets
Definition: event_demo.C:46
static constexpr double s
static constexpr double ps
constexpr Double_t TwoPi()
Definition: TMath.h:45