Logo ROOT   6.08/07
Reference Guide
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 assebly as shape-extract.
6 /// 1. Run `root assembly.C`
7 /// This will produce assembly.root containing the extract.
8 /// 2. Display the assebly as:
9 /// `root show_extract.C("assembly.root")`
10 ///
11 /// \image html eve_assembly.png
12 /// \macro_code
13 ///
14 /// \author Andrei Gheata
15 
16 void assembly()
17 {
18 //--- Definition of a simple geometry
19  gSystem->Load("libGeom");
20  TGeoManager *geom = new TGeoManager("Assemblies",
21  "Geometry using assemblies");
22  Int_t i;
23  //--- define some materials
24  TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0);
25  TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7);
26 // //--- define some media
27  TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum);
28  TGeoMedium *Al = new TGeoMedium("Aluminium",2, matAl);
29 
30  //--- make the top container volume
31  TGeoVolume *top = geom->MakeBox("TOP", Vacuum, 1000., 1000., 100.);
32  geom->SetTopVolume(top);
33 
34  // Make the elementary assembly of the whole structure
35  TGeoVolume *tplate = new TGeoVolumeAssembly("TOOTHPLATE");
36 
37  Int_t ntooth = 5;
38  Double_t xplate = 25;
39  Double_t yplate = 50;
40  Double_t xtooth = 10;
41  Double_t ytooth = 0.5*yplate/ntooth;
42  Double_t dshift = 2.*xplate + xtooth;
43  Double_t xt,yt;
44 
45  TGeoVolume *plate = geom->MakeBox("PLATE", Al, xplate,yplate,1);
46  plate->SetLineColor(kBlue);
47  TGeoVolume *tooth = geom->MakeBox("TOOTH", Al, xtooth,ytooth,1);
48  tooth->SetLineColor(kBlue);
49  tplate->AddNode(plate,1);
50  for (i=0; i<ntooth; i++) {
51  xt = xplate+xtooth;
52  yt = -yplate + (4*i+1)*ytooth;
53  tplate->AddNode(tooth, i+1, new TGeoTranslation(xt,yt,0));
54  xt = -xplate-xtooth;
55  yt = -yplate + (4*i+3)*ytooth;
56  tplate->AddNode(tooth, ntooth+i+1, new TGeoTranslation(xt,yt,0));
57  }
58 
59  TGeoRotation *rot1 = new TGeoRotation();
60  rot1->RotateX(90);
61  TGeoRotation *rot;
62  // Make a hexagone cell out of 6 toothplates. These can zip togeather
63  // without generating overlaps (they are self-contained)
64  TGeoVolume *cell = new TGeoVolumeAssembly("CELL");
65  for (i=0; i<6; i++) {
66  Double_t phi = 60.*i;
67  Double_t phirad = phi*TMath::DegToRad();
68  Double_t xp = dshift*TMath::Sin(phirad);
69  Double_t yp = -dshift*TMath::Cos(phirad);
70  rot = new TGeoRotation(*rot1);
71  rot->RotateZ(phi);
72  cell->AddNode(tplate,i+1,new TGeoCombiTrans(xp,yp,0,rot));
73  }
74 
75  // Make a row as an assembly of cells, then combine rows in a honeycomb
76  // structure. This again works without any need to define rows as
77  // "overlapping"
78  TGeoVolume *row = new TGeoVolumeAssembly("ROW");
79  Int_t ncells = 5;
80  for (i=0; i<ncells; i++) {
81  Double_t ycell = (2*i+1)*(dshift+10);
82  row->AddNode(cell, ncells+i+1, new TGeoTranslation(0,ycell,0));
83  row->AddNode(cell,ncells-i,new TGeoTranslation(0,-ycell,0));
84  }
85 
86  Double_t dxrow = 3.*(dshift+10.)*TMath::Tan(30.*TMath::DegToRad());
87  Double_t dyrow = dshift+10.;
88  Int_t nrows = 5;
89  for (i=0; i<nrows; i++) {
90  Double_t xrow = 0.5*(2*i+1)*dxrow;
91  Double_t yrow = 0.5*dyrow;
92  if ((i%2)==0) 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  TGeoNode* node = gGeoManager->GetTopNode();
103  TEveGeoTopNode* en = new TEveGeoTopNode(gGeoManager, node);
104  en->SetVisLevel(4);
106 
107  gEve->AddGlobalElement(en);
108 
109  gEve->Redraw3D(kTRUE);
110 
112  en->Save("assembly.root", "Assembly");
113 }
The manager class for any TGeo geometry.
Definition: TGeoManager.h:38
Volume assemblies.
Definition: TGeoVolume.h:320
TGeoNode * GetNode() const
Definition: TEveGeoNode.h:57
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.
void AddGlobalElement(TEveElement *element, TEveElement *parent=0)
Add a global element, i.e.
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
const Bool_t kFALSE
Definition: Rtypes.h:92
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
Definition: TEveManager.h:168
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 Save(const char *file, const char *name="Extract", Bool_t leafs_only=kFALSE)
Save TEveGeoShapeExtract tree starting at this node.
static TEveManager * Create(Bool_t map_window=kTRUE, Option_t *opt="FIV")
If global TEveManager* gEve is not set initialize it.
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
A wrapper over a TGeoNode, possibly displaced with a global trasformation stored in TEveElement...
Definition: TEveGeoNode.h:92
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
Class describing rotation + translation.
Definition: TGeoMatrix.h:285
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
TGeoNode * GetTopNode() const
Definition: TGeoManager.h:498
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
void SetVisLevel(Int_t vl)
Definition: TEveGeoNode.h:115
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:554
double Double_t
Definition: RtypesCore.h:55
virtual void SetVisibility(Bool_t vis=kTRUE)
set visibility of this volume
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.
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition: TGeoNode.h:51
Double_t Sin(Double_t)
Definition: TMath.h:421
Definition: Rtypes.h:61
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void ExpandIntoListTreesRecursively()
Expand children into all list-trees recursively.
TGeoVolume * GetVolume() const
Definition: TGeoNode.h:106
Double_t Tan(Double_t)
Definition: TMath.h:427