Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ExampleWidget.cpp
Go to the documentation of this file.
1// Author: Sergey Linev, GSI 13/01/2021
2
3/*************************************************************************
4 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#include "ExampleWidget.h"
12
13#include "TCanvas.h"
14#include "TH1.h"
15#include "TH2.h"
16#include "TMath.h"
17#include "TFile.h"
18#include "TGeoManager.h"
19#include "TGeoVolume.h"
20#include "TGeoMatrix.h"
21#include "TGeoArb8.h"
22#include "TPolyLine3D.h"
23#include "TPolyMarker3D.h"
24
25#include <ROOT/RCanvas.hxx>
28
29#include <QMessageBox>
30
32 QWidget(parent)
33{
34 setupUi(this);
35
36 setAttribute(Qt::WA_DeleteOnClose);
37
38 setObjectName(name);
39
40 // create sample histogram
41
42 fHisto = new TH1F("gaus1","Example of TH1 drawing in TCanvas", 100, -5, 5);
43 fHisto->FillRandom("gaus", 10000);
44 fHisto->SetDirectory(nullptr);
45
46 gPad = fxTCanvasWidget->getCanvas();
47 fHisto->Draw();
48
49 static constexpr int nth2points = 40;
50 fHisto2 = std::make_shared<TH2I>("gaus2", "Example of TH2 drawing in RCanvas", nth2points, -5, 5, nth2points, -5, 5);
51 fHisto2->SetDirectory(nullptr);
52 for (int n=0;n<nth2points;++n) {
53 for (int k=0;k<nth2points;++k) {
54 double x = 10.*n/nth2points-5.;
55 double y = 10.*k/nth2points-5.;
56 fHisto2->SetBinContent(fHisto2->GetBin(n+1, k+1), (int) (1000*TMath::Gaus(x)*TMath::Gaus(y)));
57 }
58 }
59
60 fxRCanvasWidget->getCanvas()->Draw<ROOT::Experimental::TObjectDrawable>(fHisto2, "col");
61
63}
64
66{
67}
68
69
71{
72 auto viewer = fxGeomViewerWidget->getGeomViewer();
73
74 new TGeoManager("tubeseg", "poza3");
75 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
76 TGeoMedium *med = new TGeoMedium("MED",1,mat);
77 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
79 TGeoVolume *vol = gGeoManager->MakeTubs("TUBESEG",med, 20,30,40,-30,270);
80 vol->SetLineColor(kRed);
81 vol->SetLineWidth(2);
82 top->AddNode(vol,1);
84// gGeoManager->SetNsegments(40);
86
87 viewer->SetGeometry(gGeoManager);
88}
89
91{
93
94 if (!TGeoManager::Import("https://root.cern/files/cms.root")) {
96 return;
97 }
98
99 auto viewer = fxGeomViewerWidget->getGeomViewer();
100
117
118 viewer->SetGeometry(gGeoManager);
119
120 // select volume to draw
121 viewer->SelectVolume("CMSE");
122
123 // specify JSROOT draw options - here clipping on X,Y,Z axes
124 viewer->SetDrawOptions("clipxyz");
125
126 // set default limits for number of visible nodes and faces
127 // when viewer created, initial values exported from TGeoManager
128 viewer->SetLimits();
129}
130
132{
133 TGeoManager *geom = new TGeoManager("simple1", "Simple geometry");
134
135 //--- define some materials
136 TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0);
137 TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7);
138// //--- define some media
139 TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum);
140 TGeoMedium *Al = new TGeoMedium("Root Material",2, matAl);
141
142 //--- define the transformations
143 TGeoTranslation *tr1 = new TGeoTranslation(20., 0, 0.);
144 TGeoTranslation *tr2 = new TGeoTranslation(10., 0., 0.);
145 TGeoTranslation *tr3 = new TGeoTranslation(10., 20., 0.);
146 TGeoTranslation *tr4 = new TGeoTranslation(5., 10., 0.);
147 TGeoTranslation *tr5 = new TGeoTranslation(20., 0., 0.);
148 TGeoTranslation *tr6 = new TGeoTranslation(-5., 0., 0.);
149 TGeoTranslation *tr7 = new TGeoTranslation(7.5, 7.5, 0.);
150 TGeoRotation *rot1 = new TGeoRotation("rot1", 90., 0., 90., 270., 0., 0.);
151 TGeoCombiTrans *combi1 = new TGeoCombiTrans(7.5, -7.5, 0., rot1);
152 TGeoTranslation *tr8 = new TGeoTranslation(7.5, -5., 0.);
153 TGeoTranslation *tr9 = new TGeoTranslation(7.5, 20., 0.);
154 TGeoTranslation *tr10 = new TGeoTranslation(85., 0., 0.);
155 TGeoTranslation *tr11 = new TGeoTranslation(35., 0., 0.);
156 TGeoTranslation *tr12 = new TGeoTranslation(-15., 0., 0.);
157 TGeoTranslation *tr13 = new TGeoTranslation(-65., 0., 0.);
158
159 TGeoTranslation *tr14 = new TGeoTranslation(0,0,-100);
160 TGeoCombiTrans *combi2 = new TGeoCombiTrans(0,0,100,
161 new TGeoRotation("rot2",90,180,90,90,180,0));
162 TGeoCombiTrans *combi3 = new TGeoCombiTrans(100,0,0,
163 new TGeoRotation("rot3",90,270,0,0,90,180));
164 TGeoCombiTrans *combi4 = new TGeoCombiTrans(-100,0,0,
165 new TGeoRotation("rot4",90,90,0,0,90,0));
166 TGeoCombiTrans *combi5 = new TGeoCombiTrans(0,100,0,
167 new TGeoRotation("rot5",0,0,90,180,90,270));
168 TGeoCombiTrans *combi6 = new TGeoCombiTrans(0,-100,0,
169 new TGeoRotation("rot6",180,0,90,180,90,90));
170
171 //--- make the top container volume
172 Double_t worldx = 110.;
173 Double_t worldy = 50.;
174 Double_t worldz = 5.;
175 TGeoVolume *top = geom->MakeBox("TOP", Vacuum, 270., 270., 120.);
176 geom->SetTopVolume(top);
177
178 TGeoVolume *rootbox = geom->MakeBox("ROOT", Vacuum, 110., 50., 5.);
179 rootbox->SetVisibility(kFALSE);
180
181 //--- make letter 'R'
182 TGeoVolume *R = geom->MakeBox("R", Vacuum, 25., 25., 5.);
183 R->SetVisibility(kFALSE);
184 TGeoVolume *bar1 = geom->MakeBox("bar1", Al, 5., 25, 5.);
185 bar1->SetLineColor(kRed);
186 R->AddNode(bar1, 1, tr1);
187 TGeoVolume *bar2 = geom->MakeBox("bar2", Al, 5., 5., 5.);
188 bar2->SetLineColor(kRed);
189 R->AddNode(bar2, 1, tr2);
190 R->AddNode(bar2, 2, tr3);
191 TGeoVolume *tub1 = geom->MakeTubs("tub1", Al, 5., 15., 5., 90., 270.);
192 tub1->SetLineColor(kRed);
193 R->AddNode(tub1, 1, tr4);
194 TGeoVolume *bar3 = geom->MakeArb8("bar3", Al, 5.);
195 bar3->SetLineColor(kRed);
196 TGeoArb8 *arb = (TGeoArb8*)bar3->GetShape();
197 arb->SetVertex(0, 15., -5.);
198 arb->SetVertex(1, 0., -25.);
199 arb->SetVertex(2, -10., -25.);
200 arb->SetVertex(3, 5., -5.);
201 arb->SetVertex(4, 15., -5.);
202 arb->SetVertex(5, 0., -25.);
203 arb->SetVertex(6, -10., -25.);
204 arb->SetVertex(7, 5., -5.);
205 R->AddNode(bar3, 1, gGeoIdentity);
206
207 //--- make letter 'O'
208 TGeoVolume *O = geom->MakeBox("O", Vacuum, 25., 25., 5.);
210 TGeoVolume *bar4 = geom->MakeBox("bar4", Al, 5., 7.5, 5.);
211 bar4->SetLineColor(kYellow);
212 O->AddNode(bar4, 1, tr5);
213 O->AddNode(bar4, 2, tr6);
214 TGeoVolume *tub2 = geom->MakeTubs("tub1", Al, 7.5, 17.5, 5., 0., 180.);
215 tub2->SetLineColor(kYellow);
216 O->AddNode(tub2, 1, tr7);
217 O->AddNode(tub2, 2, combi1);
218
219 //--- make letter 'T'
220 TGeoVolume *T = geom->MakeBox("T", Vacuum, 25., 25., 5.);
221 T->SetVisibility(kFALSE);
222 TGeoVolume *bar5 = geom->MakeBox("bar5", Al, 5., 20., 5.);
223 bar5->SetLineColor(kBlue);
224 T->AddNode(bar5, 1, tr8);
225 TGeoVolume *bar6 = geom->MakeBox("bar6", Al, 17.5, 5., 5.);
226 bar6->SetLineColor(kBlue);
227 T->AddNode(bar6, 1, tr9);
228
229 rootbox->AddNode(R, 1, tr10);
230 rootbox->AddNode(O, 1, tr11);
231 rootbox->AddNode(O, 2, tr12);
232 rootbox->AddNode(T, 1, tr13);
233
234 top->AddNode(rootbox, 1, new TGeoRotation("rot7",180,90,0));
235
236 //--- close the geometry
237 geom->CloseGeometry();
238
239 geom->SetVisLevel(3);
240
241
242 auto canv = fxTCanvasWidget->getCanvas();
243 canv->Clear();
244
245 canv->GetListOfPrimitives()->Add(geom,"");
246
247
248 // create a first PolyMarker3D
249 TPolyMarker3D *pm = new TPolyMarker3D(21);
250
251 for (int n=0;n<21;n++)
252 pm->SetPoint(n, -120 + n*10, -20, 25);
253
254 // set marker size, color & style
255 pm->SetMarkerSize(2);
256 pm->SetMarkerColor(4);
257 pm->SetMarkerStyle(2);
258
259 canv->GetListOfPrimitives()->Add(pm,"");
260
261 TPolyLine3D *pl = new TPolyLine3D(5);
262
263 // set points
264 pl->SetPoint(0, -120, -20, -30);
265 pl->SetPoint(1, 80, -20, -30);
266 pl->SetPoint(2, 80, 20, -30);
267 pl->SetPoint(3, -120, 20, -30);
268 pl->SetPoint(4, -120, -20, -30);
269 // set attributes
270 pl->SetLineWidth(3);
271 pl->SetLineColor(2);
272
273 canv->GetListOfPrimitives()->Add(pl,"");
274
275 canv->Modified();
276 canv->Update();
277}
278
280{
281 QMessageBox::information(this,"QtRoot standalone example","Demo how QRootCanvas can be inserted into the QWidget");
282}
283
284
286{
287 if (fxTabWidget->count() > 3) {
289 fxTabWidget->setCurrentIndex(3);
290 }
291}
292
294{
295 // close and delete geo painter -
296 // not possible to have two TGeoManager at the same time
297 auto widget = fxTabWidget->widget(3);
298 fxTabWidget->removeTab(3);
299 delete widget;
300
301 fxTabWidget->setCurrentIndex(2);
303 fxTabWidget->setCurrentIndex(2);
304}
305
306
308{
309 // when widget closed, application automatically exit
310 close();
311}
const Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
@ kRed
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
@ kYellow
Definition Rtypes.h:66
char name[80]
Definition TGX11.cxx:110
R__EXTERN TGeoManager * gGeoManager
R__EXTERN TGeoIdentity * gGeoIdentity
Definition TGeoMatrix.h:478
#define gPad
void DrawGeometryInCanvas()
void InfoButton_clicked()
TH1F * fHisto
histogram for display in TCanvas
void ExitButton_clicked()
void CreateDummyGeometry()
ExampleWidget(QWidget *parent=nullptr, const char *name=nullptr)
void GeoCanvasButton_clicked()
std::shared_ptr< TH2I > fHisto2
histogram for display in RCanvas
virtual ~ExampleWidget()
void ImportCmsGeometry()
Provides v7 drawing facilities for TObject types (TGraph, TH1, TH2, etc).
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
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:41
static Bool_t SetCacheFileDir(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Definition TFile.h:326
An arbitrary trapezoid with less than 8 vertices standing on two parallel planes perpendicular to Z a...
Definition TGeoArb8.h:18
virtual void SetVertex(Int_t vnum, Double_t x, Double_t y)
Set values for a given vertex.
Class describing rotation + translation.
Definition TGeoMatrix.h:292
The manager class for any TGeo geometry.
Definition TGeoManager.h:45
TGeoVolume * MakeArb8(const char *name, TGeoMedium *medium, Double_t dz, Double_t *vertices=0)
Make an TGeoArb8 volume.
void SetVisLevel(Int_t level=3)
set default level down to which visualization is performed
static TGeoManager * Import(const char *filename, const char *name="", Option_t *option="")
static function Import a geometry from a gdml or ROOT file
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
TGeoVolume * GetVolume(const char *name) const
Search for a named volume. All trailing blanks stripped.
void DefaultColors()
Set default volume colors according to A of material.
TGeoVolume * MakeBox(const char *name, TGeoMedium *medium, Double_t dx, Double_t dy, Double_t dz)
Make in one step a volume pointing to a box shape with given medium.
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
void SetNsegments(Int_t nseg)
Set number of segments for approximating circles in drawing.
TGeoVolume * MakeTubs(const char *name, TGeoMedium *medium, Double_t rmin, Double_t rmax, Double_t dz, Double_t phi1, Double_t phi2)
Make in one step a volume pointing to a tube segment shape with given medium.
Base class describing materials.
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition TGeoMedium.h:24
Class describing rotations.
Definition TGeoMatrix.h:175
Class describing translations.
Definition TGeoMatrix.h:122
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:49
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a TGeoNode to the list of nodes.
void SetTransparency(Char_t transparency=0)
Definition TGeoVolume.h:218
virtual void SetVisibility(Bool_t vis=kTRUE)
set visibility of this volume
void InvisibleAll(Bool_t flag=kTRUE)
Make volume and each of it daughters (in)visible.
TGeoShape * GetShape() const
Definition TGeoVolume.h:189
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:575
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:8767
virtual void FillRandom(const char *fname, Int_t ntimes=5000, TRandom *rng=nullptr)
Fill histogram following distribution in function fname.
Definition TH1.cxx:3526
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3074
A 3-dimensional polyline.
Definition TPolyLine3D.h:33
virtual void SetPoint(Int_t point, Double_t x, Double_t y, Double_t z)
Set point n to x, y, z.
A 3D polymarker.
void SetPoint(Int_t n, Double_t x, Double_t y, Double_t z)
Set point n to x, y, z.
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Double_t Gaus(Double_t x, Double_t mean=0, Double_t sigma=1, Bool_t norm=kFALSE)
Calculate a gaussian function with mean and sigma.
Definition TMath.cxx:448