Logo ROOT   6.19/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 "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 #include <ROOT/REveEllipsoid.hxx>
38 
39 namespace REX = ROOT::Experimental;
40 
41 // globals
49 
50 const Double_t kR_min = 240;
51 const Double_t kR_max = 250;
52 const Double_t kZ_d = 300;
53 
54 
55 REX::REvePointSet *getPointSet(int npoints = 2, float s=2, int color=28)
56 {
57  TRandom &r = *gRandom;
58 
59  auto ps = new REX::REvePointSet("fu", "", npoints);
60 
61  for (Int_t i=0; i<npoints; ++i)
62  ps->SetNextPoint(r.Uniform(-s,s), r.Uniform(-s,s), r.Uniform(-s,s));
63 
64  ps->SetMarkerColor(color);
65  ps->SetMarkerSize(3+r.Uniform(1, 7));
66  ps->SetMarkerStyle(4);
67  return ps;
68 }
69 
70 void addPoints()
71 {
73 
74  auto pntHolder = new REX::REveElement("Hits");
75 
76  auto ps1 = getPointSet(20, 100);
77  ps1->SetName("Points_1");
78  pntHolder->AddElement(ps1);
79 
80  auto ps2 = getPointSet(10, 200, 4);
81  ps2->SetName("Points_2");
82  pntHolder->AddElement(ps2);
83 
84  event->AddElement(pntHolder);
85 }
86 
87 void addTracks()
88 {
89  TRandom &r = *gRandom;
90 
92  auto prop = new REX::REveTrackPropagator();
93  prop->SetMagFieldObj(new REX::REveMagFieldDuo(350, -3.5, 2.0));
94  prop->SetMaxR(300);
95  prop->SetMaxZ(600);
96  prop->SetMaxOrbs(6);
97 
98  auto trackHolder = new REX::REveElement("Tracks");
99 
100  double v = 0.2;
101  double m = 5;
102 
103  int N_Tracks = 10 + r.Integer(20);
104  for (int i = 0; i < N_Tracks; i++)
105  {
106  TParticle* p = new TParticle();
107 
108  int pdg = 11* (r.Integer(2) -1);
109  p->SetPdgCode(pdg);
110 
111  p->SetProductionVertex(r.Uniform(-v,v), r.Uniform(-v,v), r.Uniform(-v,v), 1);
112  p->SetMomentum(r.Uniform(-m,m), r.Uniform(-m,m), r.Uniform(-m,m)*r.Uniform(1, 3), 1);
113  auto track = new REX::REveTrack(p, 1, prop);
114  track->MakeTrack();
115  track->SetMainColor(kBlue);
116  track->SetName(Form("RandomTrack_%d", i));
117  trackHolder->AddElement(track);
118  }
119 
120  event->AddElement(trackHolder);
121 }
122 
123 void addJets()
124 {
125  TRandom &r = *gRandom;
126 
128  auto jetHolder = new REX::REveElement("Jets");
129 
130  int N_Jets = 5 + r.Integer(5);
131  for (int i = 0; i < N_Jets; i++)
132  {
133  auto jet = new REX::REveJetCone(Form("Jet_%d", i));
134  jet->SetCylinder(2*kR_max, 2*kZ_d);
135  jet->AddEllipticCone(r.Uniform(-3.5, 3.5), r.Uniform(0, TMath::TwoPi()),
136  r.Uniform(0.02, 0.2), r.Uniform(0.02, 0.3));
137  jet->SetFillColor(kPink - 8);
138  jet->SetLineColor(kViolet - 7);
139 
140  jetHolder->AddElement(jet);
141  }
142  event->AddElement(jetHolder);
143 }
144 
145 void addVertex()
146 {
147  float pos[3] = {1.46589e-06,-1.30522e-05,-1.98267e-05};
148 
149  // symnetric matrix
150 
151  double a[16] = {1.46589e-01,-1.30522e-02,-1.98267e-02, 0,
152  -1.30522e-02, 4.22955e-02,-5.86628e-03, 0,
153  -1.98267e-02,-5.86628e-03, 2.12836e-01, 0,
154  0, 0, 0, 1};
155 
156  REX::REveTrans t;
157  t.SetFrom(a);
158  TMatrixDSym xxx(3);
159  for(int i = 0; i < 3; i++)
160  for(int j = 0; j < 3; j++)
161  {
162  xxx(i,j) = t(i+1,j+1);
163  }
164 
165  TMatrixDEigen eig(xxx);
166  TVectorD xxxEig ( eig.GetEigenValues() );
167  xxxEig = xxxEig.Sqrt();
168 
169  TMatrixD vecEig = eig.GetEigenVectors();
170  REX::REveVector v[3]; int ei = 0;
171  for (int i = 0; i < 3; ++i)
172  {
173  v[i].Set(vecEig(0,i), vecEig(1,i), vecEig(2,i));
174  v[i] *= xxxEig(i);
175  }
176  REX::REveEllipsoid* ell = new REX::REveEllipsoid("VertexError");
177  ell->InitMainTrans();
178  ell->SetMainColor(kGreen + 10);
179  ell->SetLineWidth(2);
180  ell->SetBaseVectors(v[0], v[1], v[2]);
181  ell->Outline();
183  event->AddElement(ell);
184  return;
185  //center
186  auto ps = new REX::REvePointSet();
187  ps->SetMainColor(kGreen + 10);
188  ps->SetNextPoint(pos[0], pos[1], pos[2]);
189  ps->SetMarkerStyle(4);
190  ps->SetMarkerSize(4);
191  event->AddElement(ps);
192 }
193 
194 
196 {
197  addPoints();
198  addTracks();
199  addJets();
200  addVertex();
201 }
202 
204 {
205  auto b1 = new REX::REveGeoShape("Barrel 1");
206  b1->SetShape(new TGeoTube(kR_min, kR_max, kZ_d));
207  b1->SetMainColor(kCyan);
209 
210  // Debug of surface fill in RPhi (index buffer screwed).
211  // b1->SetNSegments(3);
212  b1->SetNSegments(40);
213 }
214 
215 
217 {
218  // project RhoPhi
219  rPhiGeomScene = eveMng->SpawnNewScene("RPhi Geometry","RPhi");
220  rPhiEventScene = eveMng->SpawnNewScene("RPhi Event Data","RPhi");
221 
223 
224  rphiView = eveMng->SpawnNewViewer("RPhi View", "");
227 
228  // ----------------------------------------------------------------
229 
230  rhoZGeomScene = eveMng->SpawnNewScene("RhoZ Geometry", "RhoZ");
231  rhoZEventScene = eveMng->SpawnNewScene("RhoZ Event Data","RhoZ");
232 
234 
235  rhoZView = eveMng->SpawnNewViewer("RhoZ View", "");
238 }
239 
240 void projectScenes(bool geomp, bool eventp)
241 {
242  if (geomp)
243  {
244  for (auto &ie : eveMng->GetGlobalScene()->RefChildren())
245  {
248  }
249  }
250  if (eventp)
251  {
252  for (auto &ie : eveMng->GetEventScene()->RefChildren())
253  {
256  }
257  }
258 
259  // auto t0 = eveMng->GetEventScene()->FindChild("Tracks")->FirstChild();
260  // printf("t0=%p, %s %s\n", t0, t0->GetElementName(), t0->IsA()->GetName());
261  // dynamic_cast<REX::REveTrack*>(t0)->Print("all");
262 
263  // auto t1 = rPhiEventScene->FindChild("Tracks [P]")->FirstChild();
264  // printf("t1=%p, %s %s\n", t1, t1->GetElementName(), t1->IsA()->GetName());
265  // dynamic_cast<REX::REveTrack*>(t1)->Print("all");
266 }
267 
268 //==============================================================================
269 
270 class EventManager : public REX::REveElement
271 {
272 public:
273  EventManager() = default;
274 
275  virtual ~EventManager() {}
276 
277  virtual void NextEvent()
278  {
280  auto scene = eveMng->GetEventScene();
281  scene->DestroyElements();
282  makeEventScene();
283  for (auto &ie : scene->RefChildren())
284  {
285  if (mngRhoPhi)
287  if (mngRhoZ)
289  }
290  eveMng->EnableRedraw();
291  eveMng->DoRedraw3D();
292  }
293 
294  virtual void QuitRoot()
295  {
296  printf("Quit ROOT\n");
298  }
299 
300 };
301 
303 {
304  // disable browser cache - all scripts and html files will be loaded every time, useful for development
305  // gEnv->SetValue("WebGui.HttpMaxAge", 0);
306 
307  gRandom->SetSeed(0); // make random seed
308 
310 
311  auto eventMng = new EventManager();
312  eventMng->SetName("EventManager");
313  eveMng->GetWorld()->AddElement(eventMng);
314 
315  eveMng->GetWorld()->AddCommand("QuitRoot", "sap-icon://log", eventMng, "QuitRoot()");
316 
317  eveMng->GetWorld()->AddCommand("NextEvent", "sap-icon://step", eventMng, "NextEvent()");
318 
320  makeEventScene();
321 
322  if (1) {
324  projectScenes(true, true);
325  }
326 
327  eveMng->Show();
328 }
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
REX::REveScene * rPhiGeomScene
Definition: event_demo.C:45
Cylindrical tube class.
Definition: TGeoTube.h:17
REveTrackPropagator Calculates path of a particle taking into account special path-marks and imposed ...
auto * m
Definition: textangle.C:8
REveViewer Reve representation of TGLViewer.
Definition: REveViewer.hxx:27
void SetProductionVertex(Double_t vx, Double_t vy, Double_t vz, Double_t t)
Definition: TParticle.h:168
virtual void InitMainTrans(Bool_t can_edit=kTRUE)
Initialize the main transformation to identity matrix.
TMatrixDEigen.
Definition: TMatrixDEigen.h:26
constexpr Double_t TwoPi()
Definition: TMath.h:45
Description of the dynamic properties of a particle.
Definition: TParticle.h:26
REX::REvePointSet * getPointSet(int npoints=2, float s=2, int color=28)
Definition: event_demo.C:55
TVectorT.
Definition: TMatrixTBase.h:79
void projectScenes(bool geomp, bool eventp)
Definition: event_demo.C:240
void addJets()
Definition: event_demo.C:123
void createProjectionStuff()
Definition: event_demo.C:216
static constexpr double ps
int Int_t
Definition: RtypesCore.h:41
void event_demo()
Definition: event_demo.C:302
void SetFrom(Double_t *carr)
Definition: REveTrans.cxx:982
void AddCommand(const std::string &name, const std::string &icon, const REveElement *element, const std::string &action)
Definition: REveScene.hxx:121
Definition: Rtypes.h:64
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
virtual void Outline()
Draw archade around base vectors.
TMatrixT.
Definition: TMatrixDfwd.h:22
Definition: Rtypes.h:65
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
REveScene * GetEventScene() const
REX::REveScene * rPhiEventScene
Definition: event_demo.C:45
static constexpr double s
virtual void AddElement(REveElement *el)
Add el to the list of children.
TVectorT< Element > & Sqrt()
Take square root of all elements.
Definition: TVectorT.cxx:498
const Double_t kR_max
Definition: event_demo.C:51
REveScene * SpawnNewScene(const char *name, const char *title="")
Create a new scene.
const TMatrixD GetEigenValues() const
Computes the block diagonal eigenvalue matrix.
REX::REveScene * rhoZGeomScene
Definition: event_demo.C:46
REveMagFieldDuo Interface to magnetic field with two different values depending on radius...
void SetBaseVectors(REveVector &v0, REveVector &v1, REveVector &v3)
Three defining base vectors of ellipse.
const Double_t kR_min
Definition: event_demo.C:50
ROOT::R::TRInterface & r
Definition: Object.C:4
virtual void SetMainColor(Color_t color)
Set main color of the element.
void Show(const RWebDisplayArgs &args="")
Show eve manager in specified browser.
auto * a
Definition: textangle.C:12
static REveManager * Create()
If global REveManager* REX::gEve is not set initialize it.
REveProjectionManager Manager class for steering of projections and managing projected objects...
char * Form(const char *fmt,...)
virtual void AddScene(REveScene *scene)
Add &#39;scene&#39; to the list of scenes.
Definition: REveViewer.cxx:60
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
const TMatrixD & GetEigenVectors() const
Definition: TMatrixDEigen.h:55
void addTracks()
Definition: event_demo.C:87
double Double_t
Definition: RtypesCore.h:55
REveScene * GetGlobalScene() const
void addPoints()
Definition: event_demo.C:70
void SetMomentum(Double_t px, Double_t py, Double_t pz, Double_t e)
Definition: TParticle.h:166
Definition: Rtypes.h:64
virtual void Terminate(Int_t status=0)
REveViewer * SpawnNewViewer(const char *name, const char *title="")
Create a new GL viewer.
virtual REveElement * ImportElements(REveElement *el, REveElement *ext_list=nullptr)
Recursively import elements and apply projection to the newly imported objects.
void makeGeometryScene()
Definition: event_demo.C:203
REX::REveManager * eveMng
Definition: event_demo.C:42
REX::REveViewer * rhoZView
Definition: event_demo.C:48
void SetPdgCode(Int_t pdg)
Change the PDG code for this particle.
Definition: TParticle.cxx:353
REveTrack Track with given vertex, momentum and optional referece-points (path-marks) along its path...
Definition: REveTrack.hxx:39
Definition: Rtypes.h:65
REX::REveProjectionManager * mngRhoPhi
Definition: event_demo.C:43
virtual void DestroyElements()
Destroy all children of this element.
REX::REveViewer * rphiView
Definition: event_demo.C:47
void makeEventScene()
Definition: event_demo.C:195
const Double_t kZ_d
Definition: event_demo.C:52
void DoRedraw3D()
Perform 3D redraw of scenes and viewers whose contents has changed.
void addVertex()
Definition: event_demo.C:145
Definition: Rtypes.h:64
REX::REveScene * rhoZEventScene
Definition: event_demo.C:46
REX::REveProjectionManager * mngRhoZ
Definition: event_demo.C:44
REveScene * GetWorld() const