Logo ROOT   6.18/05
Reference Guide
assembly.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_geom
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",
14 "Geometry using assemblies");
15 Int_t i;
16 //--- define some materials
17 TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0);
18 TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7);
19// //--- define some media
20 TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum);
21 TGeoMedium *Al = new TGeoMedium("Aluminium",2, matAl);
22
23 //--- make the top container volume
24 TGeoVolume *top = geom->MakeBox("TOP", Vacuum, 1000., 1000., 100.);
25 geom->SetTopVolume(top);
26
27 // Make the elementary assembly of the whole structure
28 TGeoVolume *tplate = new TGeoVolumeAssembly("TOOTHPLATE");
29
30 Int_t ntooth = 5;
31 Double_t xplate = 25;
32 Double_t yplate = 50;
33 Double_t xtooth = 10;
34 Double_t ytooth = 0.5*yplate/ntooth;
35 Double_t dshift = 2.*xplate + xtooth;
36 Double_t xt,yt;
37
38 TGeoVolume *plate = geom->MakeBox("PLATE", Al, xplate,yplate,1);
39 plate->SetLineColor(kBlue);
40 TGeoVolume *tooth = geom->MakeBox("TOOTH", Al, xtooth,ytooth,1);
41 tooth->SetLineColor(kBlue);
42 tplate->AddNode(plate,1);
43 for (i=0; i<ntooth; i++) {
44 xt = xplate+xtooth;
45 yt = -yplate + (4*i+1)*ytooth;
46 tplate->AddNode(tooth, i+1, new TGeoTranslation(xt,yt,0));
47 xt = -xplate-xtooth;
48 yt = -yplate + (4*i+3)*ytooth;
49 tplate->AddNode(tooth, ntooth+i+1, new TGeoTranslation(xt,yt,0));
50 }
51
52 TGeoRotation *rot1 = new TGeoRotation();
53 rot1->RotateX(90);
54 TGeoRotation *rot;
55 // Make a hexagone cell out of 6 tooth plates. These can zip together
56 // without generating overlaps (they are self-contained)
57 TGeoVolume *cell = new TGeoVolumeAssembly("CELL");
58 for (i=0; i<6; i++) {
59 Double_t phi = 60.*i;
60 Double_t phirad = phi*TMath::DegToRad();
61 Double_t xp = dshift*TMath::Sin(phirad);
62 Double_t yp = -dshift*TMath::Cos(phirad);
63 rot = new TGeoRotation(*rot1);
64 rot->RotateZ(phi);
65 cell->AddNode(tplate,i+1,new TGeoCombiTrans(xp,yp,0,rot));
66 }
67
68 // Make a row as an assembly of cells, then combine rows in a honeycomb
69 // structure. This again works without any need to define rows as
70 // "overlapping"
71 TGeoVolume *row = new TGeoVolumeAssembly("ROW");
72 Int_t ncells = 5;
73 for (i=0; i<ncells; i++) {
74 Double_t ycell = (2*i+1)*(dshift+10);
75 row->AddNode(cell, ncells+i+1, new TGeoTranslation(0,ycell,0));
76 row->AddNode(cell,ncells-i,new TGeoTranslation(0,-ycell,0));
77 }
78
79 Double_t dxrow = 3.*(dshift+10.)*TMath::Tan(30.*TMath::DegToRad());
80 Double_t dyrow = dshift+10.;
81 Int_t nrows = 5;
82 for (i=0; i<nrows; i++) {
83 Double_t xrow = 0.5*(2*i+1)*dxrow;
84 Double_t yrow = 0.5*dyrow;
85 if ((i%2)==0) 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}
97
int Int_t
Definition: RtypesCore.h:41
double Double_t
Definition: RtypesCore.h:55
@ kBlue
Definition: Rtypes.h:64
Class describing rotation + translation.
Definition: TGeoMatrix.h:292
The manager class for any TGeo geometry.
Definition: TGeoManager.h:43
void SetVisOption(Int_t option=0)
set drawing mode :
void SetVisLevel(Int_t level=3)
set default level down to which visualization is performed
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
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.
Base class describing materials.
Definition: TGeoMaterial.h:31
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
virtual void RotateX(Double_t angle)
Rotate about X axis of the master frame with angle expressed in degrees.
virtual void RotateZ(Double_t angle)
Rotate about Z axis of the master frame with angle expressed in degrees.
Class describing translations.
Definition: TGeoMatrix.h:122
Volume assemblies.
Definition: TGeoVolume.h:308
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:53
virtual void Draw(Option_t *option="")
draw top volume according to option
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a TGeoNode to the list of nodes.
Definition: TGeoVolume.cxx:984
constexpr Double_t DegToRad()
Conversion from degree to radian:
Definition: TMath.h:82
Double_t Cos(Double_t)
Definition: TMath.h:629
Double_t Sin(Double_t)
Definition: TMath.h:625
Double_t Tan(Double_t)
Definition: TMath.h:633