Logo ROOT   6.08/07
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 
10 void assembly()
11 {
12 //--- Definition of a simple geometry
13  gSystem->Load("libGeom");
14  TGeoManager *geom = new TGeoManager("Assemblies",
15  "Geometry using assemblies");
16  Int_t i;
17  //--- define some materials
18  TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0);
19  TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7);
20 // //--- define some media
21  TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum);
22  TGeoMedium *Al = new TGeoMedium("Aluminium",2, matAl);
23 
24  //--- make the top container volume
25  TGeoVolume *top = geom->MakeBox("TOP", Vacuum, 1000., 1000., 100.);
26  geom->SetTopVolume(top);
27 
28  // Make the elementary assembly of the whole structure
29  TGeoVolume *tplate = new TGeoVolumeAssembly("TOOTHPLATE");
30 
31  Int_t ntooth = 5;
32  Double_t xplate = 25;
33  Double_t yplate = 50;
34  Double_t xtooth = 10;
35  Double_t ytooth = 0.5*yplate/ntooth;
36  Double_t dshift = 2.*xplate + xtooth;
37  Double_t xt,yt;
38 
39  TGeoVolume *plate = geom->MakeBox("PLATE", Al, xplate,yplate,1);
40  plate->SetLineColor(kBlue);
41  TGeoVolume *tooth = geom->MakeBox("TOOTH", Al, xtooth,ytooth,1);
42  tooth->SetLineColor(kBlue);
43  tplate->AddNode(plate,1);
44  for (i=0; i<ntooth; i++) {
45  xt = xplate+xtooth;
46  yt = -yplate + (4*i+1)*ytooth;
47  tplate->AddNode(tooth, i+1, new TGeoTranslation(xt,yt,0));
48  xt = -xplate-xtooth;
49  yt = -yplate + (4*i+3)*ytooth;
50  tplate->AddNode(tooth, ntooth+i+1, new TGeoTranslation(xt,yt,0));
51  }
52 
53  TGeoRotation *rot1 = new TGeoRotation();
54  rot1->RotateX(90);
55  TGeoRotation *rot;
56  // Make a hexagone cell out of 6 tooth plates. These can zip together
57  // without generating overlaps (they are self-contained)
58  TGeoVolume *cell = new TGeoVolumeAssembly("CELL");
59  for (i=0; i<6; i++) {
60  Double_t phi = 60.*i;
61  Double_t phirad = phi*TMath::DegToRad();
62  Double_t xp = dshift*TMath::Sin(phirad);
63  Double_t yp = -dshift*TMath::Cos(phirad);
64  rot = new TGeoRotation(*rot1);
65  rot->RotateZ(phi);
66  cell->AddNode(tplate,i+1,new TGeoCombiTrans(xp,yp,0,rot));
67  }
68 
69  // Make a row as an assembly of cells, then combine rows in a honeycomb
70  // structure. This again works without any need to define rows as
71  // "overlapping"
72  TGeoVolume *row = new TGeoVolumeAssembly("ROW");
73  Int_t ncells = 5;
74  for (i=0; i<ncells; i++) {
75  Double_t ycell = (2*i+1)*(dshift+10);
76  row->AddNode(cell, ncells+i+1, new TGeoTranslation(0,ycell,0));
77  row->AddNode(cell,ncells-i,new TGeoTranslation(0,-ycell,0));
78  }
79 
80  Double_t dxrow = 3.*(dshift+10.)*TMath::Tan(30.*TMath::DegToRad());
81  Double_t dyrow = dshift+10.;
82  Int_t nrows = 5;
83  for (i=0; i<nrows; i++) {
84  Double_t xrow = 0.5*(2*i+1)*dxrow;
85  Double_t yrow = 0.5*dyrow;
86  if ((i%2)==0) yrow = -yrow;
87  top->AddNode(row, nrows+i+1, new TGeoTranslation(xrow,yrow,0));
88  top->AddNode(row, nrows-i, new TGeoTranslation(-xrow,-yrow,0));
89  }
90 
91  //--- close the geometry
92  geom->CloseGeometry();
93 
94  geom->SetVisLevel(4);
95  geom->SetVisOption(0);
96  top->Draw();
97 }
98 
The manager class for any TGeo geometry.
Definition: TGeoManager.h:38
Volume assemblies.
Definition: TGeoVolume.h:320
Double_t DegToRad()
Definition: TMath.h:50
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:61
virtual void RotateX(Double_t angle)
Rotate about X axis of the master frame with angle expressed in degrees.
virtual void Draw(Option_t *option="")
draw top volume according to option
Class describing translations.
Definition: TGeoMatrix.h:131
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1819
Base class describing materials.
Definition: TGeoMaterial.h:35
int Int_t
Definition: RtypesCore.h:41
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.
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:985
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
Class describing rotation + translation.
Definition: TGeoMatrix.h:285
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
virtual void RotateZ(Double_t angle)
Rotate about Z axis of the master frame with angle expressed in degrees.
Double_t Cos(Double_t)
Definition: TMath.h:424
Class describing rotations.
Definition: TGeoMatrix.h:180
double Double_t
Definition: RtypesCore.h:55
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition: TGeoMedium.h:25
virtual void SetLineColor(Color_t lcolor)
Set the line color.
void SetVisLevel(Int_t level=3)
set default level down to which visualization is performed
Double_t Sin(Double_t)
Definition: TMath.h:421
Definition: Rtypes.h:61
void SetVisOption(Int_t option=0)
set drawing mode :
Double_t Tan(Double_t)
Definition: TMath.h:427