ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
assembly.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_eve
3 /// Geometry detector assembly example
4 /// Author: Andrei Gheata
5 ///
6 /// Modified to save the assebly as shape-extract.
7 /// 1. Run `root assembly.C`
8 /// This will produce assembly.root containing the extract.
9 /// 2. Display the assebly as:
10 /// `root show_extract.C("assembly.root")`
11 ///
12 /// \image html eve_assembly.png
13 /// \macro_code
14 ///
15 /// \author Andrei Gheata
16 
17 void assembly()
18 {
19 //--- Definition of a simple geometry
20  gSystem->Load("libGeom");
21  TGeoManager *geom = new TGeoManager("Assemblies",
22  "Geometry using assemblies");
23  Int_t i;
24  //--- define some materials
25  TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0);
26  TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7);
27 // //--- define some media
28  TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum);
29  TGeoMedium *Al = new TGeoMedium("Aluminium",2, matAl);
30 
31  //--- make the top container volume
32  TGeoVolume *top = geom->MakeBox("TOP", Vacuum, 1000., 1000., 100.);
33  geom->SetTopVolume(top);
34 
35  // Make the elementary assembly of the whole structure
36  TGeoVolume *tplate = new TGeoVolumeAssembly("TOOTHPLATE");
37 
38  Int_t ntooth = 5;
39  Double_t xplate = 25;
40  Double_t yplate = 50;
41  Double_t xtooth = 10;
42  Double_t ytooth = 0.5*yplate/ntooth;
43  Double_t dshift = 2.*xplate + xtooth;
44  Double_t xt,yt;
45 
46  TGeoVolume *plate = geom->MakeBox("PLATE", Al, xplate,yplate,1);
47  plate->SetLineColor(kBlue);
48  TGeoVolume *tooth = geom->MakeBox("TOOTH", Al, xtooth,ytooth,1);
49  tooth->SetLineColor(kBlue);
50  tplate->AddNode(plate,1);
51  for (i=0; i<ntooth; i++) {
52  xt = xplate+xtooth;
53  yt = -yplate + (4*i+1)*ytooth;
54  tplate->AddNode(tooth, i+1, new TGeoTranslation(xt,yt,0));
55  xt = -xplate-xtooth;
56  yt = -yplate + (4*i+3)*ytooth;
57  tplate->AddNode(tooth, ntooth+i+1, new TGeoTranslation(xt,yt,0));
58  }
59 
60  TGeoRotation *rot1 = new TGeoRotation();
61  rot1->RotateX(90);
62  TGeoRotation *rot;
63  // Make a hexagone cell out of 6 toothplates. These can zip togeather
64  // without generating overlaps (they are self-contained)
65  TGeoVolume *cell = new TGeoVolumeAssembly("CELL");
66  for (i=0; i<6; i++) {
67  Double_t phi = 60.*i;
68  Double_t phirad = phi*TMath::DegToRad();
69  Double_t xp = dshift*TMath::Sin(phirad);
70  Double_t yp = -dshift*TMath::Cos(phirad);
71  rot = new TGeoRotation(*rot1);
72  rot->RotateZ(phi);
73  cell->AddNode(tplate,i+1,new TGeoCombiTrans(xp,yp,0,rot));
74  }
75 
76  // Make a row as an assembly of cells, then combine rows in a honeycomb
77  // structure. This again works without any need to define rows as
78  // "overlapping"
79  TGeoVolume *row = new TGeoVolumeAssembly("ROW");
80  Int_t ncells = 5;
81  for (i=0; i<ncells; i++) {
82  Double_t ycell = (2*i+1)*(dshift+10);
83  row->AddNode(cell, ncells+i+1, new TGeoTranslation(0,ycell,0));
84  row->AddNode(cell,ncells-i,new TGeoTranslation(0,-ycell,0));
85  }
86 
87  Double_t dxrow = 3.*(dshift+10.)*TMath::Tan(30.*TMath::DegToRad());
88  Double_t dyrow = dshift+10.;
89  Int_t nrows = 5;
90  for (i=0; i<nrows; i++) {
91  Double_t xrow = 0.5*(2*i+1)*dxrow;
92  Double_t yrow = 0.5*dyrow;
93  if ((i%2)==0) yrow = -yrow;
94  top->AddNode(row, nrows+i+1, new TGeoTranslation(xrow,yrow,0));
95  top->AddNode(row, nrows-i, new TGeoTranslation(-xrow,-yrow,0));
96  }
97 
98  //--- close the geometry
99  geom->CloseGeometry();
100 
102 
103  TGeoNode* node = gGeoManager->GetTopNode();
104  TEveGeoTopNode* en = new TEveGeoTopNode(gGeoManager, node);
105  en->SetVisLevel(4);
107 
108  gEve->AddGlobalElement(en);
109 
110  gEve->Redraw3D(kTRUE);
111 
113  en->Save("assembly.root", "Assembly");
114 }
TGeoVolume * GetVolume() const
Definition: TGeoNode.h:106
Double_t DegToRad()
Definition: TMath.h:50
virtual void RotateX(Double_t angle)
Rotate about X axis of the master frame with angle expressed in degrees.
Definition: TGeoMatrix.cxx:993
void AddGlobalElement(TEveElement *element, TEveElement *parent=0)
Add a global element, i.e.
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:1766
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
void assembly()
Definition: assembly.C:4
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.
TGeoNode * GetTopNode() const
Definition: TGeoManager.h:500
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:948
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:545
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
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
void SetVisLevel(Int_t vl)
Definition: TEveGeoNode.h:115
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:556
double Double_t
Definition: RtypesCore.h:55
virtual void SetVisibility(Bool_t vis=kTRUE)
set visibility of this volume
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Double_t Sin(Double_t)
Definition: TMath.h:421
TGeoNode * GetNode() const
Definition: TEveGeoNode.h:57
Definition: Rtypes.h:61
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void ExpandIntoListTreesRecursively()
Expand children into all list-trees recursively.
Double_t Tan(Double_t)
Definition: TMath.h:427