Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
assembly.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_geometry
3/// Geometry detector assembly example
4///
5/// \macro_image
6/// \macro_code
7///
8/// \author Andrei Gheata
9
10void assembly()
11{
12 //--- Definition of a simple geometry
13 TGeoManager *geom = new TGeoManager("Assemblies", "Geometry using assemblies");
14 Int_t i;
15 //--- define some materials
16 TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0, 0, 0);
17 TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98, 13, 2.7);
18 // //--- define some media
19 TGeoMedium *Vacuum = new TGeoMedium("Vacuum", 1, matVacuum);
20 TGeoMedium *Al = new TGeoMedium("Aluminium", 2, matAl);
21
22 //--- make the top container volume
23 TGeoVolume *top = geom->MakeBox("TOP", Vacuum, 1000., 1000., 100.);
24 geom->SetTopVolume(top);
25
26 // Make the elementary assembly of the whole structure
27 TGeoVolume *tplate = new TGeoVolumeAssembly("TOOTHPLATE");
28
29 Int_t ntooth = 5;
30 Double_t xplate = 25;
31 Double_t yplate = 50;
32 Double_t xtooth = 10;
33 Double_t ytooth = 0.5 * yplate / ntooth;
35 Double_t xt, yt;
36
37 TGeoVolume *plate = geom->MakeBox("PLATE", Al, xplate, yplate, 1);
38 plate->SetLineColor(kBlue);
39 TGeoVolume *tooth = geom->MakeBox("TOOTH", Al, xtooth, ytooth, 1);
40 tooth->SetLineColor(kBlue);
41 tplate->AddNode(plate, 1);
42 for (i = 0; i < ntooth; i++) {
43 xt = xplate + xtooth;
44 yt = -yplate + (4 * i + 1) * ytooth;
45 tplate->AddNode(tooth, i + 1, new TGeoTranslation(xt, yt, 0));
46 xt = -xplate - xtooth;
47 yt = -yplate + (4 * i + 3) * ytooth;
48 tplate->AddNode(tooth, ntooth + i + 1, new TGeoTranslation(xt, yt, 0));
49 }
50
52 rot1->RotateX(90);
54 // Make a hexagone cell out of 6 tooth plates. These can zip together
55 // without generating overlaps (they are self-contained)
56 TGeoVolume *cell = new TGeoVolumeAssembly("CELL");
57 for (i = 0; i < 6; i++) {
58 Double_t phi = 60. * i;
62 rot = new TGeoRotation(*rot1);
63 rot->RotateZ(phi);
64 cell->AddNode(tplate, i + 1, new TGeoCombiTrans(xp, yp, 0, rot));
65 }
66
67 // Make a row as an assembly of cells, then combine rows in a honeycomb
68 // structure. This again works without any need to define rows as
69 // "overlapping"
70 TGeoVolume *row = new TGeoVolumeAssembly("ROW");
71 Int_t ncells = 5;
72 for (i = 0; i < ncells; i++) {
73 Double_t ycell = (2 * i + 1) * (dshift + 10);
74 row->AddNode(cell, ncells + i + 1, new TGeoTranslation(0, ycell, 0));
75 row->AddNode(cell, ncells - i, new TGeoTranslation(0, -ycell, 0));
76 }
77
78 Double_t dxrow = 3. * (dshift + 10.) * TMath::Tan(30. * TMath::DegToRad());
79 Double_t dyrow = dshift + 10.;
80 Int_t nrows = 5;
81 for (i = 0; i < nrows; i++) {
82 Double_t xrow = 0.5 * (2 * i + 1) * dxrow;
83 Double_t yrow = 0.5 * dyrow;
84 if ((i % 2) == 0)
85 yrow = -yrow;
86 top->AddNode(row, nrows + i + 1, new TGeoTranslation(xrow, yrow, 0));
87 top->AddNode(row, nrows - i, new TGeoTranslation(-xrow, -yrow, 0));
88 }
89
90 //--- close the geometry
91 geom->CloseGeometry();
92
93 geom->SetVisLevel(4);
94 geom->SetVisOption(0);
95 top->Draw();
96}
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kBlue
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Class describing rotation + translation.
Definition TGeoMatrix.h:317
The manager class for any TGeo geometry.
Definition TGeoManager.h:44
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 TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=nullptr, Option_t *option="")
Add a TGeoNode to the list of nodes.
void Draw(Option_t *option="") override
draw top volume according to option
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