Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TGeoSphere.h"
16#include "TParticle.h"
17#include "TApplication.h"
18#include "TMatrixDSym.h"
19#include "TVector.h"
20#include "TMatrixDEigen.h"
21
22#include <ROOT/REveGeoShape.hxx>
23#include <ROOT/REveScene.hxx>
24#include <ROOT/REveViewer.hxx>
25#include <ROOT/REveElement.hxx>
26#include <ROOT/REveManager.hxx>
27#include <ROOT/REveUtil.hxx>
28#include <ROOT/REveGeoShape.hxx>
31#include <ROOT/REvePointSet.hxx>
32#include <ROOT/REveJetCone.hxx>
33#include <ROOT/REveTrans.hxx>
34
35#include <ROOT/REveTrack.hxx>
37
38namespace REX = ROOT::Experimental;
39
40// globals
48
49const Double_t kR_min = 240;
50const Double_t kR_max = 250;
51const Double_t kZ_d = 300;
52
53
54REX::REvePointSet *getPointSet(int npoints = 2, float s=2, int color=28)
55{
56 TRandom &r = *gRandom;
57
58 auto ps = new REX::REvePointSet("fu", "", npoints);
59
60 for (Int_t i=0; i<npoints; ++i)
61 ps->SetNextPoint(r.Uniform(-s,s), r.Uniform(-s,s), r.Uniform(-s,s));
62
63 ps->SetMarkerColor(color);
64 ps->SetMarkerSize(3+r.Uniform(1, 7));
65 ps->SetMarkerStyle(4);
66 return ps;
67}
68
70{
72
73 auto pntHolder = new REX::REveElement("Hits");
74
75 auto ps1 = getPointSet(20, 100);
76 ps1->SetName("Points_1");
77 ps1->SetTitle("Points_1 title"); // used as tooltip
78
79 pntHolder->AddElement(ps1);
80
81 auto ps2 = getPointSet(10, 200, 4);
82 ps2->SetName("Points_2");
83 ps2->SetTitle("Points_2 title"); // used as tooltip
84 pntHolder->AddElement(ps2);
85
86 event->AddElement(pntHolder);
87}
88
90{
91 TRandom &r = *gRandom;
92
94 auto prop = new REX::REveTrackPropagator();
95 prop->SetMagFieldObj(new REX::REveMagFieldDuo(350, 3.5, -2.0));
96 prop->SetMaxR(300);
97 prop->SetMaxZ(600);
98 prop->SetMaxOrbs(6);
99
100 auto trackHolder = new REX::REveElement("Tracks");
101
102 double v = 0.2;
103 double m = 5;
104
105 int N_Tracks = 10 + r.Integer(20);
106 for (int i = 0; i < N_Tracks; i++)
107 {
108 TParticle* p = new TParticle();
109
110 int pdg = 11 * (r.Integer(2) > 0 ? 1 : -1);
111 p->SetPdgCode(pdg);
112
113 p->SetProductionVertex(r.Uniform(-v,v), r.Uniform(-v,v), r.Uniform(-v,v), 1);
114 p->SetMomentum(r.Uniform(-m,m), r.Uniform(-m,m), r.Uniform(-m,m)*r.Uniform(1, 3), 1);
115 auto track = new REX::REveTrack(p, 1, prop);
116 track->MakeTrack();
117 if (i % 4 == 3) track->SetLineStyle(2); // enabled dashed style for some tracks
118 track->SetMainColor(kBlue);
119 track->SetName(Form("RandomTrack_%d", i));
120 track->SetTitle(Form("RandomTrack_%d title", i)); // used as tooltip
121 trackHolder->AddElement(track);
122 }
123
124 event->AddElement(trackHolder);
125}
126
128{
129 TRandom &r = *gRandom;
130
132 auto jetHolder = new REX::REveElement("Jets");
133
134 int N_Jets = 5 + r.Integer(5);
135 for (int i = 0; i < N_Jets; i++)
136 {
137 auto jet = new REX::REveJetCone(Form("Jet_%d", i));
138 jet->SetTitle(Form("Jet_%d title", i)); // used as tooltip
139 jet->SetCylinder(2*kR_max, 2*kZ_d);
140 jet->AddEllipticCone(r.Uniform(-3.5, 3.5), r.Uniform(0, TMath::TwoPi()),
141 r.Uniform(0.02, 0.2), r.Uniform(0.02, 0.3));
142 jet->SetFillColor(kPink - 8);
143 jet->SetLineColor(kViolet - 7);
144
145 jetHolder->AddElement(jet);
146 }
147 event->AddElement(jetHolder);
148}
149
151{
152 addPoints();
153 addTracks();
154 addJets();
155}
156
158{
159 auto b1 = new REX::REveGeoShape("Barrel 1");
160 b1->SetShape(new TGeoTube(kR_min, kR_max, kZ_d));
161 b1->SetMainColor(kCyan);
163
164 // Debug of surface fill in RPhi (index buffer screwed).
165 // b1->SetNSegments(3);
166 b1->SetNSegments(40);
167}
168
169
171{
172 // project RhoPhi
173 rPhiGeomScene = eveMng->SpawnNewScene("RPhi Geometry","RPhi");
174 rPhiEventScene = eveMng->SpawnNewScene("RPhi Event Data","RPhi");
175
176 mngRhoPhi = new REX::REveProjectionManager(REX::REveProjection::kPT_RPhi);
177
178 rphiView = eveMng->SpawnNewViewer("RPhi View", "");
181
182 // ----------------------------------------------------------------
183
184 rhoZGeomScene = eveMng->SpawnNewScene("RhoZ Geometry", "RhoZ");
185 rhoZEventScene = eveMng->SpawnNewScene("RhoZ Event Data","RhoZ");
186
187 mngRhoZ = new REX::REveProjectionManager(REX::REveProjection::kPT_RhoZ);
188
189 rhoZView = eveMng->SpawnNewViewer("RhoZ View", "");
192}
193
194void projectScenes(bool geomp, bool eventp)
195{
196 if (geomp)
197 {
198 for (auto &ie : eveMng->GetGlobalScene()->RefChildren())
199 {
202 }
203 }
204 if (eventp)
205 {
206 for (auto &ie : eveMng->GetEventScene()->RefChildren())
207 {
210 }
211 }
212
213 // auto t0 = eveMng->GetEventScene()->FindChild("Tracks")->FirstChild();
214 // printf("t0=%p, %s %s\n", t0, t0->GetElementName(), t0->IsA()->GetName());
215 // dynamic_cast<REX::REveTrack*>(t0)->Print("all");
216
217 // auto t1 = rPhiEventScene->FindChild("Tracks [P]")->FirstChild();
218 // printf("t1=%p, %s %s\n", t1, t1->GetElementName(), t1->IsA()->GetName());
219 // dynamic_cast<REX::REveTrack*>(t1)->Print("all");
220}
221
222//==============================================================================
223
224class EventManager : public REX::REveElement
225{
226public:
227 EventManager() = default;
228
229 virtual ~EventManager() {}
230
231 virtual void NextEvent()
232 {
234 auto scene = eveMng->GetEventScene();
235 scene->DestroyElements();
237 for (auto &ie : scene->RefChildren())
238 {
239 if (mngRhoPhi)
241 if (mngRhoZ)
243 }
246 }
247
248 virtual void QuitRoot()
249 {
250 printf("Quit ROOT\n");
252 }
253
254};
255
257{
258 // disable browser cache - all scripts and html files will be loaded every time, useful for development
259 // gEnv->SetValue("WebGui.HttpMaxAge", 0);
260
261 gRandom->SetSeed(0); // make random seed
262
263 eveMng = REX::REveManager::Create();
264
265 auto eventMng = new EventManager();
266 eventMng->SetName("EventManager");
267 eveMng->GetWorld()->AddElement(eventMng);
268
269 eveMng->GetWorld()->AddCommand("QuitRoot", "sap-icon://log", eventMng, "QuitRoot()");
270
271 eveMng->GetWorld()->AddCommand("NextEvent", "sap-icon://step", eventMng, "NextEvent()");
272
275
276 if (1) {
278 projectScenes(true, true);
279 }
280
281 eveMng->Show();
282}
ROOT::R::TRInterface & r
Definition Object.C:4
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kPink
Definition Rtypes.h:67
@ kCyan
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
@ kViolet
Definition Rtypes.h:67
R__EXTERN TApplication * gApplication
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
char * Form(const char *fmt,...)
virtual void AddElement(REveElement *el)
Add el to the list of children.
virtual void DestroyElements()
Destroy all children of this element.
REveMagFieldDuo Interface to magnetic field with two different values depending on radius.
REveScene * GetEventScene() const
REveScene * GetGlobalScene() const
void DoRedraw3D()
Perform 3D redraw of scenes and viewers whose contents has changed.
REveScene * SpawnNewScene(const char *name, const char *title="")
Create a new scene.
REveViewer * SpawnNewViewer(const char *name, const char *title="")
Create a new GL viewer.
void Show(const RWebDisplayArgs &args="")
Show eve manager in specified browser.
REveProjectionManager Manager class for steering of projections and managing projected objects.
virtual REveElement * ImportElements(REveElement *el, REveElement *ext_list=nullptr)
Recursively import elements and apply projection to the newly imported objects.
void AddCommand(const std::string &name, const std::string &icon, const REveElement *element, const std::string &action)
Definition REveScene.cxx:82
REveTrackPropagator Calculates path of a particle taking into account special path-marks and imposed ...
REveTrack Track with given vertex, momentum and optional referece-points (path-marks) along its path.
Definition REveTrack.hxx:40
REveViewer Reve representation of TGLViewer.
virtual void AddScene(REveScene *scene)
Add 'scene' to the list of scenes.
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.
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:608
REX::REveScene * rPhiGeomScene
Definition event_demo.C:44
void addTracks()
Definition event_demo.C:89
void addJets()
Definition event_demo.C:127
REX::REveScene * rPhiEventScene
Definition event_demo.C:44
void makeEventScene()
Definition event_demo.C:150
const Double_t kR_max
Definition event_demo.C:50
REX::REveProjectionManager * mngRhoZ
Definition event_demo.C:43
REX::REveManager * eveMng
Definition event_demo.C:41
REX::REveViewer * rhoZView
Definition event_demo.C:47
const Double_t kZ_d
Definition event_demo.C:51
REX::REveScene * rhoZEventScene
Definition event_demo.C:45
void createProjectionStuff()
Definition event_demo.C:170
void addPoints()
Definition event_demo.C:69
REX::REveViewer * rphiView
Definition event_demo.C:46
void makeGeometryScene()
Definition event_demo.C:157
REX::REveProjectionManager * mngRhoPhi
Definition event_demo.C:42
void event_demo()
Definition event_demo.C:256
REX::REveScene * rhoZGeomScene
Definition event_demo.C:45
void projectScenes(bool geomp, bool eventp)
Definition event_demo.C:194
REX::REvePointSet * getPointSet(int npoints=2, float s=2, int color=28)
Definition event_demo.C:54
const Double_t kR_min
Definition event_demo.C:49
constexpr Double_t TwoPi()
Definition TMath.h:44
auto * m
Definition textangle.C:8