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