Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
lego.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve_7
3/// This example display only points in web browser
4///
5/// \macro_code
6///
7/// \author Alja Mrak-Tadel
8
9#include "TRandom.h"
10#include <ROOT/REveElement.hxx>
11#include <ROOT/REveScene.hxx>
12#include <ROOT/REveManager.hxx>
13#include <ROOT/REvePointSet.hxx>
14
15namespace REX = ROOT::Experimental;
16
17REX::REvePointSet *createPointSet(int npoints = 200, float s = 2, int color = 28)
18{
19 TRandom &r = *gRandom;
20
21 REX::REvePointSet *ps = new REX::REvePointSet("MyTestPoints", "list of eve points", npoints);
22
23 for (Int_t i = 0; i < npoints; ++i)
24 ps->SetNextPoint(r.Uniform(-s, s), r.Uniform(-s, s), r.Uniform(-s, s));
25
26 ps->SetMarkerColor(color);
27 ps->SetMarkerSize(3 + r.Uniform(1, 2));
28 ps->SetMarkerStyle(4);
29 return ps;
30}
31
32void lego()
33{
34 auto eveMng = REX::REveManager::Create();
35
36 // disable default view
37 eveMng->GetViewers()->FirstChild()->SetRnrSelf(false);
38
39 auto scene = eveMng->SpawnNewScene("Lego", "LegoView");
40 auto view = eveMng->SpawnNewViewer("Lego", "");
41 view->AddScene(scene);
42
43 auto ps = createPointSet(100);
44 scene->AddElement(ps);
45
46 {
47 TPad *p = new TCanvas("LegoPad", "Lego Pad", 800, 400);
48 p->SetMargin(0, 0, 0, 0);
49
50 // *** Load std CMS calo demo
51 const char *histFile = "http://root.cern/files/cms_calo_hist.root";
53 auto hf = TFile::Open(histFile, "CACHEREAD");
54 auto ecalHist = (TH2F *)hf->Get("ecalLego");
55 auto hcalHist = (TH2F *)hf->Get("hcalLego");
56
57 THStack *s = new THStack("LegoStack", ""); // "ECal and HCal";
58 ecalHist->SetFillColor(kRed);
59 ecalHist->GetXaxis()->SetLabelSize(1);
60 ecalHist->GetXaxis()->SetTitle("#eta");
61 ecalHist->GetYaxis()->SetLabelSize(1);
62 ecalHist->GetYaxis()->SetTitle("#varphi");
63 ecalHist->GetZaxis()->SetLabelSize(1);
64 s->Add(ecalHist);
65 hcalHist->SetFillColor(kBlue);
66 s->Add(hcalHist);
67 p->Add(s);
68
69 TGraph2D *line = new TGraph2D(200);
70 for (int i = 0; i < 200; ++i)
71 line->SetPoint(i, std::cos(i * 0.1), std::sin(i * 0.1), i * 0.25);
74 p->Add(line, "LINE");
75
76 p->Modified(kTRUE);
77
79
80 ps->SetTitle(TBase64::Encode(json).Data());
81
82 s->Draw();
83 }
84
85 eveMng->Show();
86}
nlohmann::json json
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
@ kRed
Definition Rtypes.h:67
@ kCyan
Definition Rtypes.h:67
@ kBlue
Definition Rtypes.h:67
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
R__EXTERN TRandom * gRandom
Definition TRandom.h:73
void SetTitle(const std::string &title)
Set title of an element.
void SetMarkerColor(Color_t col) override
Set the marker color.
void SetMarkerSize(Size_t msize=1) override
Set marker size, propagate to projecteds.
int SetNextPoint(float x, float y, float z)
void SetMarkerStyle(Style_t mstyle=1) override
Set marker style, propagate to projecteds.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
static TString Encode(const char *data)
Transform data into a null terminated base64 string.
Definition TBase64.cxx:106
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
Definition TBufferJSON.h:77
The Canvas class.
Definition TCanvas.h:23
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:3797
static Bool_t SetCacheFileDir(std::string_view cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Sets the directory where to locally stage/cache remote files.
Definition TFile.cxx:4338
Graphics object made of three arrays X, Y and Z with the same number of points each.
Definition TGraph2D.h:41
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:345
The Histogram stack class.
Definition THStack.h:40
virtual void Add(TH1 *h, Option_t *option="")
Add a new histogram to the list.
Definition THStack.cxx:364
void Draw(Option_t *chopt="") override
Draw this stack with its current attributes.
Definition THStack.cxx:451
The most important graphics class in the ROOT system.
Definition TPad.h:28
This is the base class for the ROOT Random number generators.
Definition TRandom.h:28
Basic string class.
Definition TString.h:138
TLine * line
Namespace for ROOT features in testing.
Definition TROOT.h:100