Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
lego.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve7
3/// This example display only points in web browser
4///
5/// \macro_code
6///
7
8#include "TRandom.h"
10#include <ROOT/REveScene.hxx>
11#include <ROOT/REveManager.hxx>
12#include <ROOT/REvePointSet.hxx>
13
14namespace REX = ROOT::Experimental;
15
16REX::REvePointSet *createPointSet(int npoints = 2, float s = 2, int color = 28)
17{
18 TRandom &r = *gRandom;
19
20 REX::REvePointSet *ps = new REX::REvePointSet("MyTestPoints", "list of eve points", npoints);
21
22 for (Int_t i=0; i < npoints; ++i)
23 ps->SetNextPoint(r.Uniform(-s,s), r.Uniform(-s,s), r.Uniform(-s,s));
24
25 ps->SetMarkerColor(color);
26 ps->SetMarkerSize(3+r.Uniform(1, 2));
27 ps->SetMarkerStyle(4);
28 return ps;
29}
30
31void lego()
32{
33 auto eveMng = REX::REveManager::Create();
34
35 // disable default view
37
38 auto scene = eveMng->SpawnNewScene("Lego", "LegoView");
39 auto view = eveMng->SpawnNewViewer("Lego", "");
40 view->AddScene(scene);
41
42 auto ps = createPointSet(100);
43 scene->AddElement(ps);
44
45 {
46 // gROOT->SetBatch();
47
48 // TPad *p = new TPad("LegoPad", "Lego Pad Tit", 0, 0, 1, 1);
49 TPad *p = new TCanvas("LegoPad", "Lego Pad Tit", 800,400);
50 p->SetMargin(0, 0, 0, 0);
51
52 // *** Simple TH2
53 /*
54 TH2F* h = new TH2F("Booboo","exampul",128,-5,5,64,-2.5,2.5);
55 TRandom r;
56 for(int i=0;i<1000000;++i) {
57 h->Fill(r.Gaus() - 2, r.Gaus());
58 h->Fill(r.Gaus() + 2, r.Gaus());
59 }
60 for(int i=0;i<6000;++i) {
61 h->Fill(0.1*r.Gaus() - 2, 0.1*r.Gaus());
62 h->Fill(0.1*r.Gaus() + 2, 0.1*r.Gaus());
63 }
64 // h->Draw("LEGO2");
65 p->Add(h, "LEGO2");
66 p->Modified(kTRUE);
67 */
68
69 // *** Load std CMS calo demo
70 const char* histFile = "http://root.cern/files/cms_calo_hist.root";
72 auto hf = TFile::Open(histFile, "CACHEREAD");
73 auto ecalHist = (TH2F*)hf->Get("ecalLego");
74 auto hcalHist = (TH2F*)hf->Get("hcalLego");
75
76 THStack *s = new THStack("LegoStack", ""); // "ECal undt HCal");
77 ecalHist->SetFillColor(kRed);
78 ecalHist->GetXaxis()->SetLabelSize(1);
79 // ecalHist->GetXaxis()->SetTitle(reinterpret_cast<const char *>(u8"\u03B7"));
80 ecalHist->GetXaxis()->SetTitle("#eta");
81 ecalHist->GetYaxis()->SetLabelSize(1);
82 // ecalHist->GetYaxis()->SetTitle(reinterpret_cast<const char *>(u8"\u03C6"));
83 ecalHist->GetYaxis()->SetTitle("#varphi");
84 ecalHist->GetZaxis()->SetLabelSize(1);
85 s->Add(ecalHist);
86 hcalHist->SetFillColor(kBlue);
87 s->Add(hcalHist);
88 p->Add(s);
89
90 TGraph2D *line = new TGraph2D(200);
91 for (int i = 0; i < 200; ++i)
92 line->SetPoint(i, std::cos(i*0.1), std::sin(i*0.1), i*0.25);
95 p->Add(line, "LINE");
96
97 p->Modified(kTRUE);
98
100
101 ps->SetTitle(TBase64::Encode(json).Data());
102
103 s->Draw();
104 }
105
106 eveMng->Show();
107}
nlohmann::json json
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
@ kRed
Definition Rtypes.h:66
@ kCyan
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
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:62
REveElement * FirstChild() const
Returns the first child element or 0 if the list is empty.
virtual Bool_t SetRnrSelf(Bool_t rnr)
Set render state of this element, i.e.
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.
REveViewerList * GetViewers() const
void Show(const RWebDisplayArgs &args="")
Show eve manager in specified browser.
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 AddScene(REveScene *scene)
Add 'scene' to the list of scenes.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
static TString Encode(const char *data)
Transform data into a null terminated base64 string.
Definition TBase64.cxx:107
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
Definition TBufferJSON.h:75
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:4089
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:4626
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:307
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:366
void Draw(Option_t *chopt="") override
Draw this stack with its current attributes.
Definition THStack.cxx:453
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:27
Basic string class.
Definition TString.h:139
ROOT::Experimental::REveManager * eveMng
TLine * line
const char * histFile
void lego()
Definition lego.C:31
REX::REvePointSet * createPointSet(int npoints=2, float s=2, int color=28)
Definition lego.C:16