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/REveCompound.hxx>
27#include <ROOT/REveManager.hxx>
28#include <ROOT/REveUtil.hxx>
29#include <ROOT/REveGeoShape.hxx>
32#include <ROOT/REvePointSet.hxx>
33#include <ROOT/REveJetCone.hxx>
34#include <ROOT/REveTrans.hxx>
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(8);
65 ps->SetMarkerStyle(4);
66 return ps;
67}
68
70{
72
73 auto pntHolder = new REX::REveCompound("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 ps2->SetAlwaysSecSelect(true);
85 pntHolder->AddElement(ps2);
86
87 event->AddElement(pntHolder);
88}
89
91{
92 TRandom &r = *gRandom;
93
95 auto prop = new REX::REveTrackPropagator();
96 prop->SetMagFieldObj(new REX::REveMagFieldDuo(350, 3.5, -2.0));
97 prop->SetMaxR(300);
98 prop->SetMaxZ(600);
99 prop->SetMaxOrbs(6);
100
101 auto trackHolder = new REX::REveCompound("Tracks");
102
103 double v = 0.2;
104 double m = 5;
105
106 int N_Tracks = 10 + r.Integer(20);
107 for (int i = 0; i < N_Tracks; i++)
108 {
109 TParticle p;
110
111 int pdg = 11 * (r.Integer(2) > 0 ? 1 : -1);
112 p.SetPdgCode(pdg);
113
114 p.SetProductionVertex(r.Uniform(-v,v), r.Uniform(-v,v), r.Uniform(-v,v), 1);
115 p.SetMomentum(r.Uniform(-m,m), r.Uniform(-m,m), r.Uniform(-m,m)*r.Uniform(1, 3), 1);
116 auto track = new REX::REveTrack(&p, 1, prop);
117 track->MakeTrack();
118 if (i % 4 == 3) track->SetLineStyle(kDashed); // enabled dashed style for some tracks
119 track->SetMainColor(kBlue);
120 track->SetName(Form("RandomTrack_%d", i));
121 track->SetTitle(Form("RandomTrack_%d title", i)); // used as tooltip
122 trackHolder->AddElement(track);
123 }
124
125 event->AddElement(trackHolder);
126}
127
129{
130 TRandom &r = *gRandom;
131
133 auto jetHolder = new REX::REveCompound("Jets");
134
135 int N_Jets = 5 + r.Integer(5);
136 for (int i = 0; i < N_Jets; i++)
137 {
138 auto jet = new REX::REveJetCone(Form("Jet_%d", i));
139 jet->SetTitle(Form("Jet_%d\n pT = %.2f", i, r.Uniform(1, 40))); // used as tooltip
140 jet->SetCylinder(2*kR_max, 2*kZ_d);
141 jet->AddEllipticCone(r.Uniform(-3.5, 3.5), r.Uniform(0, TMath::TwoPi()),
142 r.Uniform(0.02, 0.2), r.Uniform(0.02, 0.3));
143 jet->SetFillColor(kPink - 8);
144 jet->SetLineColor(kBlack);
145
146 jetHolder->AddElement(jet);
147 }
148 event->AddElement(jetHolder);
149}
150
151
153{
154 addPoints();
155 addTracks();
156 addJets();
157}
158
160{
161 auto b1 = new REX::REveGeoShape("Barrel 1");
162 b1->SetShape(new TGeoTube(kR_min, kR_max, kZ_d));
163 b1->SetMainColor(kCyan);
164 b1->SetNSegments(80);
165 b1->SetMainTransparency(70);
167
168 // Debug of surface fill in RPhi (index buffer screwed).
169 // b1->SetNSegments(3);
170 b1->SetNSegments(40);
171
172 // an example of axis guides
173 eveMng->GetDefaultViewer()->SetAxesType(REX::REveViewer::EAxesType::kAxesOrigin);
174}
175
176
178{
179 // project RhoPhi
180 rPhiGeomScene = eveMng->SpawnNewScene("RPhi Geometry","RPhi");
181 rPhiEventScene = eveMng->SpawnNewScene("RPhi Event Data","RPhi");
182
183 mngRhoPhi = new REX::REveProjectionManager(REX::REveProjection::kPT_RPhi);
184
185 rphiView = eveMng->SpawnNewViewer("RPhi View", "");
186 rphiView->SetCameraType(REX::REveViewer::kCameraOrthoXOY);
189
190 // ----------------------------------------------------------------
191
192 rhoZGeomScene = eveMng->SpawnNewScene("RhoZ Geometry", "RhoZ");
193 rhoZEventScene = eveMng->SpawnNewScene("RhoZ Event Data","RhoZ");
194
195 mngRhoZ = new REX::REveProjectionManager(REX::REveProjection::kPT_RhoZ);
196
197 rhoZView = eveMng->SpawnNewViewer("RhoZ View", "");
198 rhoZView->SetCameraType(REX::REveViewer::kCameraOrthoXOY);
201}
202
203void projectScenes(bool geomp, bool eventp)
204{
205 if (geomp)
206 {
207 for (auto &ie : eveMng->GetGlobalScene()->RefChildren())
208 {
213 }
214 }
215 if (eventp)
216 {
217 int depth = 50;
218 for (auto &ie : eveMng->GetEventScene()->RefChildren())
219 {
222 mngRhoZ ->SetCurrentDepth(depth);
224 depth -= 10;
225 }
226 }
227
228 // auto t0 = eveMng->GetEventScene()->FindChild("Tracks")->FirstChild();
229 // printf("t0=%p, %s %s\n", t0, t0->GetElementName(), t0->IsA()->GetName());
230 // dynamic_cast<REX::REveTrack*>(t0)->Print("all");
231
232 // auto t1 = rPhiEventScene->FindChild("Tracks [P]")->FirstChild();
233 // printf("t1=%p, %s %s\n", t1, t1->GetElementName(), t1->IsA()->GetName());
234 // dynamic_cast<REX::REveTrack*>(t1)->Print("all");
235}
236
237//==============================================================================
238
239class EventManager : public REX::REveElement
240{
241private:
242 bool fAutoplay{false};
243 int fPlayDelay{10};
244 int fCount{0};
245 std::chrono::duration<double> fDeltaTime{1};
246
247 std::thread* fTimerThread{nullptr};
248 std::mutex fMutex;
249 std::condition_variable fCV;
250
251
252public:
254 {
255 std::chrono::milliseconds ms(100);
256 fDeltaTime = ms;
257 }
258
259 ~EventManager() override {}
260
262 {
263 auto scene = eveMng->GetEventScene();
264 scene->DestroyElements();
266 projectScenes(false, true);
267 // if (++fCount % 10 == 0) printf("At event %d\n", fCount);
268 }
269
271 {
272 while (true) {
273 bool autoplay;
274 {
275 std::unique_lock<std::mutex> lock{fMutex};
276 if (!fAutoplay) {
277 // printf("exit thread pre wait\n");
278 return;
279 }
280 if (fCV.wait_for(lock, fDeltaTime) != std::cv_status::timeout) {
281 printf("autoplay not timed out \n");
282 if (!fAutoplay) {
283 printf("exit thread post wait\n");
284 return;
285 } else {
286 continue;
287 }
288 }
289 autoplay = fAutoplay;
290 }
291 if (autoplay) {
292 REX::REveManager::ChangeGuard ch;
293 NextEvent();
294 } else {
295 return;
296 }
297 }
298 }
299
300 void Autoplay()
301 {
302 static std::mutex autoplay_mutex;
303 std::unique_lock<std::mutex> aplock{autoplay_mutex};
304 {
305 std::unique_lock<std::mutex> lock{fMutex};
307 if (fAutoplay) {
308 if (fTimerThread) {
309 fTimerThread->join();
310 delete fTimerThread;
311 fTimerThread = nullptr;
312 }
313 NextEvent();
314 fTimerThread = new std::thread{[this] { autoplay_scheduler(); }};
315 } else {
316 fCV.notify_all();
317 }
318 }
319 }
320
321 virtual void QuitRoot()
322 {
323 printf("Quit ROOT\n");
324 REX::REveManager::QuitRoot();
325 }
326};
327
329{
330 // disable browser cache - all scripts and html files will be loaded every time, useful for development
331 // gEnv->SetValue("WebGui.HttpMaxAge", 0);
332
333 gRandom->SetSeed(0); // make random seed
334
335 eveMng = REX::REveManager::Create();
336
337 auto eventMng = new EventManager();
338 eventMng->SetName("EventManager");
339 eveMng->GetWorld()->AddElement(eventMng);
340
341 eveMng->GetWorld()->AddCommand("QuitRoot", "sap-icon://log", eventMng, "QuitRoot()");
342
343 eveMng->GetWorld()->AddCommand("NextEvent", "sap-icon://step", eventMng, "NextEvent()");
344
345 eveMng->GetWorld()->AddCommand("Autoplay", "sap-icon://refresh", eventMng, "Autoplay()");
346
349
350 if (true) {
352 projectScenes(true, true);
353 }
354
355 eveMng->Show();
356}
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kPink
Definition Rtypes.h:67
@ kBlack
Definition Rtypes.h:65
@ kCyan
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
@ kDashed
Definition TAttLine.h:48
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h prop
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
std::condition_variable fCV
Definition event_demo.C:249
std::chrono::duration< double > fDeltaTime
Definition event_demo.C:245
virtual void QuitRoot()
Definition event_demo.C:321
~EventManager() override
Definition event_demo.C:259
std::mutex fMutex
Definition event_demo.C:248
void Autoplay()
Definition event_demo.C:300
void NextEvent()
Definition event_demo.C:261
virtual void NextEvent()
std::thread * fTimerThread
Definition event_demo.C:247
void autoplay_scheduler()
Definition event_demo.C:270
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
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.
REveViewer * GetDefaultViewer() const
Get the default 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:90
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.
void SetCameraType(ECameraType t)
virtual void AddScene(REveScene *scene)
Add 'scene' to the list of scenes.
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
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition TRandom.cxx:615
REX::REveScene * rPhiGeomScene
Definition event_demo.C:44
void addTracks()
Definition event_demo.C:90
void addJets()
Definition event_demo.C:128
REX::REveScene * rPhiEventScene
Definition event_demo.C:44
void makeEventScene()
Definition event_demo.C:152
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:177
void addPoints()
Definition event_demo.C:69
REX::REveViewer * rphiView
Definition event_demo.C:46
void makeGeometryScene()
Definition event_demo.C:159
REX::REveProjectionManager * mngRhoPhi
Definition event_demo.C:42
void event_demo()
Definition event_demo.C:328
REX::REveScene * rhoZGeomScene
Definition event_demo.C:45
void projectScenes(bool geomp, bool eventp)
Definition event_demo.C:203
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
TMarker m
Definition textangle.C:8