Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
overlay_test.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve_7
3/// Demonstrates usage of TEveBox class.
4///
5/// \image html eve_box.png
6/// \macro_code
7///
8/// \author Matevz Tadel
9
10#include <ROOT/REveBox.hxx>
11#include <ROOT/REveScene.hxx>
12#include <ROOT/REveManager.hxx>
14#include <ROOT/REveTrack.hxx>
15#include <ROOT/REveJetCone.hxx>
16#include <ROOT/REveText.hxx>
17
18#include "TROOT.h"
19
20using namespace ROOT::Experimental;
21const Double_t kR_min = 240;
22const Double_t kR_max = 250;
23const Double_t kZ_d = 300;
24
25void makeTracks(int N_Tracks, REveElement *trackHolder)
26{
27 TRandom &r = *gRandom;
28 auto prop = new REveTrackPropagator();
29 prop->SetMagFieldObj(new REveMagFieldDuo(350, 3.5, -2.0));
30 prop->SetMaxR(300);
31 prop->SetMaxZ(600);
32 prop->SetMaxOrbs(6);
33 // Default is kHelix propagator.
34 // prop->SetStepper(REX::REveTrackPropagator::kRungeKutta);
35
36 double v = 0.5;
37 double m = 5;
38
39 for (int i = 0; i < N_Tracks; i++) {
40 auto p = new TParticle();
41
42 int pdg = 11 * (r.Integer(2) > 0 ? 1 : -1);
43 p->SetPdgCode(pdg);
44
45 p->SetProductionVertex(r.Uniform(-v, v), r.Uniform(-v, v), r.Uniform(-v, v), 1);
46 p->SetMomentum(r.Uniform(-m, m), r.Uniform(-m, m), r.Uniform(-m, m) * r.Uniform(1, 3), 1);
47 auto track = new REveTrack(p, 1, prop);
48 track->MakeTrack();
49 track->SetMainColor(kBlue);
50 track->SetName(Form("RandomTrack_%d", i));
51 track->SetLineWidth(3);
52 trackHolder->AddElement(track);
53 }
54}
55
56REveElement *makeBox(Float_t a = 10, Float_t d = 5, Float_t x = 0, Float_t y = 0, Float_t z = 0)
57{
58
59 TRandom &r = *gRandom;
60 auto b = new REveBox;
61 b->SetMainColor(kCyan);
62 b->SetMainTransparency(0);
63
64#define RND_BOX(x) r.Uniform(-(x), (x))
65 b->SetVertex(0, x - a + RND_BOX(d), y - a + RND_BOX(d), z - a + RND_BOX(d));
66 b->SetVertex(1, x - a + RND_BOX(d), y + a + RND_BOX(d), z - a + RND_BOX(d));
67 b->SetVertex(2, x + a + RND_BOX(d), y + a + RND_BOX(d), z - a + RND_BOX(d));
68 b->SetVertex(3, x + a + RND_BOX(d), y - a + RND_BOX(d), z - a + RND_BOX(d));
69 b->SetVertex(4, x - a + RND_BOX(d), y - a + RND_BOX(d), z + a + RND_BOX(d));
70 b->SetVertex(5, x - a + RND_BOX(d), y + a + RND_BOX(d), z + a + RND_BOX(d));
71 b->SetVertex(6, x + a + RND_BOX(d), y + a + RND_BOX(d), z + a + RND_BOX(d));
72 b->SetVertex(7, x + a + RND_BOX(d), y - a + RND_BOX(d), z + a + RND_BOX(d));
73#undef RND_BOX
74
75 return b;
76}
77
78void makeJets(int N_Jets, REveElement *jetHolder)
79{
80 TRandom &r = *gRandom;
81
82 for (int i = 0; i < N_Jets; i++) {
83 auto jet = new REveJetCone(Form("Jet_%d", i));
84 jet->SetCylinder(2 * kR_max, 2 * kZ_d);
85 jet->AddEllipticCone(r.Uniform(-0.5, 0.5), r.Uniform(0, TMath::TwoPi()), 0.1, 0.2);
86 jet->SetFillColor(kRed);
87 jet->SetLineColor(kRed);
88
89 jetHolder->AddElement(jet);
90 }
91}
92
93void makeTexts(REveElement *textHolder)
94{
95 {
96 auto text = new REveText(Form("Text_0"));
97 text->SetMainColor(kViolet);
98 REveVector pos(0.5, 0.5, 0.2);
99 text->SetPosition(pos);
100 text->SetFontSize(0.1);
101 // LiberationSerif-Regular ships with ROOT. It is also REveText's default.
102 text->SetFont("LiberationSerif-Regular");
103 text->SetText(text->GetCName());
104 textHolder->AddElement(text);
105 }
106}
107
108void overlay_test()
109{
110 auto gEve = REveManager::Create();
111
112 // Call after REveManager::Create(), which the font directory needs. Generating
113 // the atlas needs a display, so the first run cannot be in batch mode.
114 {
115 std::string rf = std::string(TROOT::GetDataDir().Data()) + "/fonts/";
116 REveText::AssertSdfFont("LiberationSerif-Regular", rf + "LiberationSerif-Regular.ttf");
117 }
118
119 TRandom &r = *gRandom;
120
121 // create an overlay scene
122 REveScene *os = gEve->SpawnNewScene("Overly scene", "OverlayTitle");
123 ((REveViewer *)(gEve->GetViewers()->FirstChild()))->AddScene(os);
124 os->SetIsOverlay(true);
125
126 makeTexts(os);
127
128 auto jetHolder = new REveElement("jets");
129 makeJets(2, jetHolder);
130 gEve->GetEventScene()->AddElement(jetHolder);
131
132 auto trackHolder = new REveElement("Tracks");
133 gEve->GetEventScene()->AddElement(trackHolder);
134 makeTracks(10, trackHolder);
135
136 gEve->Show();
137}
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
@ kRed
Definition Rtypes.h:66
@ kCyan
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
@ kViolet
Definition Rtypes.h:67
R__EXTERN TEveManager * gEve
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
Option_t Option_t TPoint TPoint const char text
R__EXTERN TRandom * gRandom
Definition TRandom.h:73
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2571
3D box with arbitrary vertices (cuboid).
Base class for REveUtil visualization elements, providing hierarchy management, rendering control and...
Draws a jet cone with leading particle is specified in (eta,phi) and cone radius is given.
Implements constant magnetic filed that switches on given axial radius fR2 from vector fBIn to fBOut.
Eve representation of TGLScene.
Holding structure for a number of track rendering parameters.
Visual representation of a track.
Eve representation of a GL view.
virtual void AddElement(TEveElement *el)
Add el to the list of children.
TEveElement * FirstChild() const
Returns the first child element or 0 if the list is empty.
TEveViewerList * GetViewers() const
TEveScene * SpawnNewScene(const char *name, const char *title="")
Create a new scene.
TEveScene * GetEventScene() const
Description of the dynamic properties of a particle.
Definition TParticle.h:26
static const TString & GetDataDir()
Get the data directory in the installation. Static utility function.
Definition TROOT.cxx:3406
This is the base class for the ROOT Random number generators.
Definition TRandom.h:28
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Namespace for ROOT features in testing.
Definition TROOT.h:100
constexpr Double_t TwoPi()
Definition TMath.h:47
TMarker m
Definition textangle.C:8