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
21#include <ROOT/RCanvas.hxx>
24
25#include <QMessageBox>
26
28 QWidget(parent)
29{
30 setupUi(this);
31
32 setAttribute(Qt::WA_DeleteOnClose);
33
34 setObjectName(name);
35
36 // create sample histogram
37
38 fHisto = new TH1F("gaus1","Example of TH1 drawing in TCanvas", 100, -5, 5);
39 fHisto->FillRandom("gaus", 10000);
40 fHisto->SetDirectory(nullptr);
41
42 gPad = fxTCanvasWidget->getCanvas();
43 fHisto->Draw();
44
45 static constexpr int nth2points = 40;
46 fHisto2 = std::make_shared<TH2I>("gaus2", "Example of TH2 drawing in RCanvas", nth2points, -5, 5, nth2points, -5, 5);
47 fHisto2->SetDirectory(nullptr);
48 for (int n=0;n<nth2points;++n) {
49 for (int k=0;k<nth2points;++k) {
50 double x = 10.*n/nth2points-5.;
51 double y = 10.*k/nth2points-5.;
52 fHisto2->SetBinContent(fHisto2->GetBin(n+1, k+1), (int) (1000*TMath::Gaus(x)*TMath::Gaus(y)));
53 }
54 }
55
56 fxRCanvasWidget->getCanvas()->Draw<ROOT::Experimental::TObjectDrawable>(fHisto2, "col");
57
59}
60
62{
63}
64
65
67{
68 auto viewer = fxGeomViewerWidget->getGeomViewer();
69
70 new TGeoManager("tubeseg", "poza3");
71 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
72 TGeoMedium *med = new TGeoMedium("MED",1,mat);
73 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
75 TGeoVolume *vol = gGeoManager->MakeTubs("TUBESEG",med, 20,30,40,-30,270);
76 vol->SetLineColor(kRed);
77 vol->SetLineWidth(2);
78 top->AddNode(vol,1);
80// gGeoManager->SetNsegments(40);
82
83 viewer->SetGeometry(gGeoManager);
84}
85
87{
89
90 if (!TGeoManager::Import("https://root.cern/files/cms.root")) {
92 return;
93 }
94
95 auto viewer = fxGeomViewerWidget->getGeomViewer();
96
113
114 viewer->SetGeometry(gGeoManager);
115
116 // select volume to draw
117 viewer->SelectVolume("CMSE");
118
119 // specify JSROOT draw options - here clipping on X,Y,Z axes
120 viewer->SetDrawOptions("clipxyz");
121
122 // set default limits for number of visible nodes and faces
123 // when viewer created, initial values exported from TGeoManager
124 viewer->SetLimits();
125}
126
128{
129 QMessageBox::information(this,"QtRoot standalone example","Demo how QRootCanvas can be inserted into the QWidget");
130}
131
132
134{
136 fxTabWidget->setCurrentIndex(3);
137}
138
140{
141 // when widget closed, application automatically exit
142 close();
143}
@ kRed
Definition Rtypes.h:66
char name[80]
Definition TGX11.cxx:110
R__EXTERN TGeoManager * gGeoManager
#define gPad
void InfoButton_clicked()
TH1F * fHisto
histogram for display in TCanvas
void ExitButton_clicked()
void CreateDummyGeometry()
ExampleWidget(QWidget *parent=nullptr, const char *name=nullptr)
std::shared_ptr< TH2I > fHisto2
histogram for display in RCanvas
virtual ~ExampleWidget()
void ImportCmsGeometry()
Provides v7 drawing facilities for TObject types (TGraph etc).
static Bool_t SetCacheFileDir(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Definition TFile.h:324
The manager class for any TGeo geometry.
Definition TGeoManager.h:45
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
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
void InvisibleAll(Bool_t flag=kTRUE)
Make volume and each of it daughters (in)visible.
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 an histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:8777
virtual void FillRandom(const char *fname, Int_t ntimes=5000, TRandom *rng=nullptr)
Fill histogram following distribution in function fname.
Definition TH1.cxx:3525
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3073
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