Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
assembly.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve
3/// Geometry detector assembly example
4///
5/// Modified to save the assembly as shape-extract.
6/// 1. Run `root assembly.C`
7/// This will produce assembly.root containing the extract.
8/// 2. Display the assembly as:
9/// `root show_extract.C("assembly.root")`
10///
11/// \image html eve_assembly.png
12/// \macro_code
13///
14/// \author Andrei Gheata
15
16void assembly()
17{
18 //--- Definition of a simple geometry
19 gSystem->Load("libGeom");
20 auto geom = new TGeoManager("Assemblies", "Geometry using assemblies");
21 Int_t i;
22 //--- define some materials
23 auto matVacuum = new TGeoMaterial("Vacuum", 0, 0, 0);
24 auto matAl = new TGeoMaterial("Al", 26.98, 13, 2.7);
25 //--- define some media
26 auto Vacuum = new TGeoMedium("Vacuum", 1, matVacuum);
27 auto Al = new TGeoMedium("Aluminium", 2, matAl);
28
29 //--- make the top container volume
30 auto top = geom->MakeBox("TOP", Vacuum, 1000., 1000., 100.);
31 geom->SetTopVolume(top);
32
33 // Make the elementary assembly of the whole structure
34 auto tplate = new TGeoVolumeAssembly("TOOTHPLATE");
35
36 Int_t ntooth = 5;
37 Double_t xplate = 25;
38 Double_t yplate = 50;
39 Double_t xtooth = 10;
40 Double_t ytooth = 0.5 * yplate / ntooth;
42 Double_t xt, yt;
43
44 auto plate = geom->MakeBox("PLATE", Al, xplate, yplate, 1);
45 plate->SetLineColor(kBlue);
46 auto tooth = geom->MakeBox("TOOTH", Al, xtooth, ytooth, 1);
47 tooth->SetLineColor(kBlue);
48 tplate->AddNode(plate, 1);
49 for (i = 0; i < ntooth; i++) {
50 xt = xplate + xtooth;
51 yt = -yplate + (4 * i + 1) * ytooth;
52 tplate->AddNode(tooth, i + 1, new TGeoTranslation(xt, yt, 0));
53 xt = -xplate - xtooth;
54 yt = -yplate + (4 * i + 3) * ytooth;
55 tplate->AddNode(tooth, ntooth + i + 1, new TGeoTranslation(xt, yt, 0));
56 }
57
58 auto rot1 = new TGeoRotation();
59 rot1->RotateX(90);
61 // Make a hexagone cell out of 6 toothplates. These can zip togeather
62 // without generating overlaps (they are self-contained)
63 TGeoVolume *cell = new TGeoVolumeAssembly("CELL");
64 for (i = 0; i < 6; i++) {
65 Double_t phi = 60. * i;
69 rot = new TGeoRotation(*rot1);
70 rot->RotateZ(phi);
71 cell->AddNode(tplate, i + 1, new TGeoCombiTrans(xp, yp, 0, rot));
72 }
73
74 // Make a row as an assembly of cells, then combine rows in a honeycomb
75 // structure. This again works without any need to define rows as
76 // "overlapping"
77 auto row = new TGeoVolumeAssembly("ROW");
78 Int_t ncells = 5;
79 for (i = 0; i < ncells; i++) {
80 Double_t ycell = (2 * i + 1) * (dshift + 10);
81 row->AddNode(cell, ncells + i + 1, new TGeoTranslation(0, ycell, 0));
82 row->AddNode(cell, ncells - i, new TGeoTranslation(0, -ycell, 0));
83 }
84
85 Double_t dxrow = 3. * (dshift + 10.) * TMath::Tan(30. * TMath::DegToRad());
86 Double_t dyrow = dshift + 10.;
87 Int_t nrows = 5;
88 for (i = 0; i < nrows; i++) {
89 Double_t xrow = 0.5 * (2 * i + 1) * dxrow;
90 Double_t yrow = 0.5 * dyrow;
91 if ((i % 2) == 0)
92 yrow = -yrow;
93 top->AddNode(row, nrows + i + 1, new TGeoTranslation(xrow, yrow, 0));
94 top->AddNode(row, nrows - i, new TGeoTranslation(-xrow, -yrow, 0));
95 }
96
97 //--- close the geometry
98 geom->CloseGeometry();
99
101
102 auto node = gGeoManager->GetTopNode();
103 auto en = new TEveGeoTopNode(gGeoManager, node);
104 en->SetVisLevel(4);
105 en->GetNode()->GetVolume()->SetVisibility(kFALSE);
106
108
110
111 en->ExpandIntoListTreesRecursively();
112 en->Save("assembly.root", "Assembly");
113}
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
@ kBlue
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEveManager * gEve
R__EXTERN TGeoManager * gGeoManager
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
A wrapper over a TGeoNode, possibly displaced with a global trasformation stored in TEveElement.
Definition TEveGeoNode.h:90
void AddGlobalElement(TEveElement *element, TEveElement *parent=nullptr)
Add a global element, i.e.
static TEveManager * Create(Bool_t map_window=kTRUE, Option_t *opt="FIV")
If global TEveManager* gEve is not set initialize it.
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
Class describing rotation + translation.
Definition TGeoMatrix.h:317
The manager class for any TGeo geometry.
Definition TGeoManager.h:44
TGeoNode * GetTopNode() const
Base class describing materials.
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition TGeoMedium.h:23
Class describing rotations.
Definition TGeoMatrix.h:168
Class describing translations.
Definition TGeoMatrix.h:116
Volume assemblies.
Definition TGeoVolume.h:316
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition TSystem.cxx:1857
constexpr Double_t DegToRad()
Conversion from degree to radian: .
Definition TMath.h:79
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:598
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:592
Double_t Tan(Double_t)
Returns the tangent of an angle of x radians.
Definition TMath.h:604