Logo ROOT   6.18/05
Reference Guide
event_demo.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve7
3/// This example display geometry, tracks and hits in web browser
4///
5/// \macro_code
6///
7
8#include <vector>
9#include <string>
10#include <iostream>
11
12#include "TClass.h"
13#include "TRandom.h"
14#include "TGeoTube.h"
15#include "TParticle.h"
16#include "TApplication.h"
17
18#include <ROOT/REveGeoShape.hxx>
19#include <ROOT/REveScene.hxx>
20#include <ROOT/REveViewer.hxx>
21#include <ROOT/REveElement.hxx>
22#include <ROOT/REveManager.hxx>
23#include <ROOT/REveProjectionManager.hxx>
24#include <ROOT/REveProjectionBases.hxx>
25#include <ROOT/REvePointSet.hxx>
26#include <ROOT/REveJetCone.hxx>
27
28#include <ROOT/REveTrack.hxx>
29#include <ROOT/REveTrackPropagator.hxx>
30
31namespace REX = ROOT::Experimental;
32
33// globals
34REX::REveManager *eveMng = nullptr;
35REX::REveProjectionManager *mngRhoPhi = nullptr;
36REX::REveProjectionManager *mngRhoZ = nullptr;
37REX::REveScene *rPhiGeomScene = nullptr, *rPhiEventScene = nullptr;
38REX::REveScene *rhoZGeomScene = nullptr, *rhoZEventScene = nullptr;
39REX::REveViewer *rphiView = nullptr;
40REX::REveViewer *rhoZView = nullptr;
41
42const Double_t kR_min = 240;
43const Double_t kR_max = 250;
44const Double_t kZ_d = 300;
45
46const Int_t N_Tracks = 40;
47const Int_t N_Jets = 20;
48
49
50REX::REvePointSet *getPointSet(int npoints = 2, float s=2, int color=28)
51{
52 TRandom &r = *gRandom;
53
54 auto ps = new REX::REvePointSet("fu", "", npoints);
55
56 for (Int_t i=0; i<npoints; ++i)
57 ps->SetNextPoint(r.Uniform(-s,s), r.Uniform(-s,s), r.Uniform(-s,s));
58
59 ps->SetMarkerColor(color);
60 ps->SetMarkerSize(3+r.Uniform(1, 7));
61 ps->SetMarkerStyle(4);
62 return ps;
63}
64
66{
67 REX::REveElement* event = eveMng->GetEventScene();
68
69 auto pntHolder = new REX::REveElement("Hits");
70
71 auto ps1 = getPointSet(20, 100);
72 ps1->SetName("Points_1");
73 pntHolder->AddElement(ps1);
74
75 auto ps2 = getPointSet(10, 200, 4);
76 ps2->SetName("Points_2");
77 pntHolder->AddElement(ps2);
78
79 event->AddElement(pntHolder);
80}
81
83{
84 TRandom &r = *gRandom;
85
86 REX::REveElement* event = eveMng->GetEventScene();
87 auto prop = new REX::REveTrackPropagator();
88 prop->SetMagFieldObj(new REX::REveMagFieldDuo(350, -3.5, 2.0));
89 prop->SetMaxR(300);
90 prop->SetMaxZ(600);
91 prop->SetMaxOrbs(6);
92
93 auto trackHolder = new REX::REveElement("Tracks");
94
95 double v = 0.5;
96 double m = 5;
97
98 for (int i = 0; i < N_Tracks; i++)
99 {
100 TParticle* p = new TParticle();
101
102 int pdg = 11* (r.Integer(2) -1);
103 p->SetPdgCode(pdg);
104
105 p->SetProductionVertex(r.Uniform(-v,v), r.Uniform(-v,v), r.Uniform(-v,v), 1);
106 p->SetMomentum(r.Uniform(-m,m), r.Uniform(-m,m), r.Uniform(-m,m)*r.Uniform(1, 3), 1);
107 auto track = new REX::REveTrack(p, 1, prop);
108 track->MakeTrack();
109 track->SetMainColor(kBlue);
110 track->SetName(Form("RandomTrack_%d", i));
111 trackHolder->AddElement(track);
112 }
113
114 event->AddElement(trackHolder);
115}
116
118{
119 TRandom &r = *gRandom;
120
121 REX::REveElement *event = eveMng->GetEventScene();
122 auto jetHolder = new REX::REveElement("Jets");
123
124 for (int i = 0; i < N_Jets; i++)
125 {
126 auto jet = new REX::REveJetCone(Form("Jet_%d", i));
127 jet->SetCylinder(2*kR_max, 2*kZ_d);
128 jet->AddEllipticCone(r.Uniform(-3.5, 3.5), r.Uniform(0, TMath::TwoPi()),
129 r.Uniform(0.02, 0.2), r.Uniform(0.02, 0.3));
130 jet->SetFillColor(kPink - 8);
131 jet->SetLineColor(kViolet - 7);
132
133 jetHolder->AddElement(jet);
134 }
135 event->AddElement(jetHolder);
136}
137
139{
140 addPoints();
141 addTracks();
142 addJets();
143}
144
146{
147 auto b1 = new REX::REveGeoShape("Barrel 1");
148 b1->SetShape(new TGeoTube(kR_min, kR_max, kZ_d));
149 b1->SetMainColor(kCyan);
150 eveMng->GetGlobalScene()->AddElement(b1);
151
152 // Debug of surface fill in RPhi (index buffer screwed).
153 // b1->SetNSegments(3);
154 b1->SetNSegments(40);
155}
156
157
159{
160 // project RhoPhi
161 rPhiGeomScene = eveMng->SpawnNewScene("RPhi Geometry","RPhi");
162 rPhiEventScene = eveMng->SpawnNewScene("RPhi Event Data","RPhi");
163
164 mngRhoPhi = new REX::REveProjectionManager(REX::REveProjection::kPT_RPhi);
165
166 rphiView = eveMng->SpawnNewViewer("RPhi View", "");
167 rphiView->AddScene(rPhiGeomScene);
168 rphiView->AddScene(rPhiEventScene);
169
170 // ----------------------------------------------------------------
171
172 rhoZGeomScene = eveMng->SpawnNewScene("RhoZ Geometry", "RhoZ");
173 rhoZEventScene = eveMng->SpawnNewScene("RhoZ Event Data","RhoZ");
174
175 mngRhoZ = new REX::REveProjectionManager(REX::REveProjection::kPT_RhoZ);
176
177 rhoZView = eveMng->SpawnNewViewer("RhoZ View", "");
178 rhoZView->AddScene(rhoZGeomScene);
179 rhoZView->AddScene(rhoZEventScene);
180}
181
182void projectScenes(bool geomp, bool eventp)
183{
184 if (geomp)
185 {
186 for (auto &ie : eveMng->GetGlobalScene()->RefChildren())
187 {
188 mngRhoPhi->ImportElements(ie, rPhiGeomScene);
189 mngRhoZ ->ImportElements(ie, rhoZGeomScene);
190 }
191 }
192 if (eventp)
193 {
194 for (auto &ie : eveMng->GetEventScene()->RefChildren())
195 {
196 mngRhoPhi->ImportElements(ie, rPhiEventScene);
197 mngRhoZ ->ImportElements(ie, rhoZEventScene);
198 }
199 }
200
201 // auto t0 = eveMng->GetEventScene()->FindChild("Tracks")->FirstChild();
202 // printf("t0=%p, %s %s\n", t0, t0->GetElementName(), t0->IsA()->GetName());
203 // dynamic_cast<REX::REveTrack*>(t0)->Print("all");
204
205 // auto t1 = rPhiEventScene->FindChild("Tracks [P]")->FirstChild();
206 // printf("t1=%p, %s %s\n", t1, t1->GetElementName(), t1->IsA()->GetName());
207 // dynamic_cast<REX::REveTrack*>(t1)->Print("all");
208}
209
210//==============================================================================
211
212class EventManager : public REX::REveElement
213{
214public:
215 EventManager() = default;
216
217 virtual ~EventManager() {}
218
219 virtual void NextEvent()
220 {
221 printf("NEXT EVENT \n");
222
223 REveElement::List_t ev_scenes;
224 ev_scenes.push_back(eveMng->GetEventScene());
225 if (rPhiEventScene)
226 ev_scenes.push_back(rPhiEventScene);
227
228 if (rhoZEventScene)
229 ev_scenes.push_back(rhoZEventScene);
230 eveMng->DestroyElementsOf(ev_scenes);
231
234 projectScenes(false, true);
235
236 eveMng->BroadcastElementsOf(ev_scenes);
237 }
238
239 virtual void QuitRoot()
240 {
241 printf("Quit ROOT\n");
243 }
244
245};
246
248{
249 // disable browser cache - all scripts and html files will be loaded every time, useful for development
250 // gEnv->SetValue("WebGui.HttpMaxAge", 0);
251
252 gRandom->SetSeed(0); // make random seed
253
254 eveMng = REX::REveManager::Create();
255
256 auto eventMng = new EventManager();
257 eventMng->SetName("EventManager");
258 eveMng->GetWorld()->AddElement(eventMng);
259
260 eveMng->GetWorld()->AddCommand("QuitRoot", "sap-icon://log", eventMng, "QuitRoot()");
261
262 eveMng->GetWorld()->AddCommand("NextEvent", "sap-icon://step", eventMng, "NextEvent()");
263
266
267 if (1) {
269 projectScenes(true, true);
270 }
271
272 eveMng->Show();
273}
SVector< double, 2 > v
Definition: Dict.h:5
ROOT::R::TRInterface & r
Definition: Object.C:4
int Int_t
Definition: RtypesCore.h:41
double Double_t
Definition: RtypesCore.h:55
@ kPink
Definition: Rtypes.h:65
@ kCyan
Definition: Rtypes.h:64
@ kBlue
Definition: Rtypes.h:64
@ kViolet
Definition: Rtypes.h:65
R__EXTERN TApplication * gApplication
Definition: TApplication.h:165
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
char * Form(const char *fmt,...)
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
Cylindrical tube class.
Definition: TGeoTube.h:18
Description of the dynamic properties of a particle.
Definition: TParticle.h:26
void SetMomentum(Double_t px, Double_t py, Double_t pz, Double_t e)
Definition: TParticle.h:166
void SetPdgCode(Int_t pdg)
Change the PDG code for this particle.
Definition: TParticle.cxx:353
void SetProductionVertex(Double_t vx, Double_t vy, Double_t vz, Double_t t)
Definition: TParticle.h:168
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:597
REX::REveScene * rPhiGeomScene
Definition: event_demo.C:37
void addTracks()
Definition: event_demo.C:82
void addJets()
Definition: event_demo.C:117
REX::REveScene * rPhiEventScene
Definition: event_demo.C:37
void makeEventScene()
Definition: event_demo.C:138
const Double_t kR_max
Definition: event_demo.C:43
REX::REveProjectionManager * mngRhoZ
Definition: event_demo.C:36
REX::REveManager * eveMng
Definition: event_demo.C:34
const Int_t N_Tracks
Definition: event_demo.C:46
const Int_t N_Jets
Definition: event_demo.C:47
REX::REveViewer * rhoZView
Definition: event_demo.C:40
const Double_t kZ_d
Definition: event_demo.C:44
REX::REveScene * rhoZEventScene
Definition: event_demo.C:38
void createProjectionStuff()
Definition: event_demo.C:158
void addPoints()
Definition: event_demo.C:65
REX::REveViewer * rphiView
Definition: event_demo.C:39
void makeGeometryScene()
Definition: event_demo.C:145
REX::REveProjectionManager * mngRhoPhi
Definition: event_demo.C:35
void event_demo()
Definition: event_demo.C:247
REX::REveScene * rhoZGeomScene
Definition: event_demo.C:38
void projectScenes(bool geomp, bool eventp)
Definition: event_demo.C:182
REX::REvePointSet * getPointSet(int npoints=2, float s=2, int color=28)
Definition: event_demo.C:50
const Double_t kR_min
Definition: event_demo.C:42
static constexpr double s
static constexpr double ps
constexpr Double_t TwoPi()
Definition: TMath.h:45
auto * m
Definition: textangle.C:8