Logo ROOT  
Reference Guide
assembly.C File Reference

Detailed Description

Geometry detector assembly example

void assembly()
{
//--- Definition of a simple geometry
TGeoManager *geom = new TGeoManager("Assemblies",
"Geometry using assemblies");
Int_t i;
//--- define some materials
TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0,0,0);
TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98,13,2.7);
// //--- define some media
TGeoMedium *Vacuum = new TGeoMedium("Vacuum",1, matVacuum);
TGeoMedium *Al = new TGeoMedium("Aluminium",2, matAl);
//--- make the top container volume
TGeoVolume *top = geom->MakeBox("TOP", Vacuum, 1000., 1000., 100.);
geom->SetTopVolume(top);
// Make the elementary assembly of the whole structure
TGeoVolume *tplate = new TGeoVolumeAssembly("TOOTHPLATE");
Int_t ntooth = 5;
Double_t xplate = 25;
Double_t yplate = 50;
Double_t xtooth = 10;
Double_t ytooth = 0.5*yplate/ntooth;
Double_t dshift = 2.*xplate + xtooth;
Double_t xt,yt;
TGeoVolume *plate = geom->MakeBox("PLATE", Al, xplate,yplate,1);
TGeoVolume *tooth = geom->MakeBox("TOOTH", Al, xtooth,ytooth,1);
tplate->AddNode(plate,1);
for (i=0; i<ntooth; i++) {
xt = xplate+xtooth;
yt = -yplate + (4*i+1)*ytooth;
tplate->AddNode(tooth, i+1, new TGeoTranslation(xt,yt,0));
xt = -xplate-xtooth;
yt = -yplate + (4*i+3)*ytooth;
tplate->AddNode(tooth, ntooth+i+1, new TGeoTranslation(xt,yt,0));
}
TGeoRotation *rot1 = new TGeoRotation();
rot1->RotateX(90);
// Make a hexagone cell out of 6 tooth plates. These can zip together
// without generating overlaps (they are self-contained)
TGeoVolume *cell = new TGeoVolumeAssembly("CELL");
for (i=0; i<6; i++) {
Double_t phi = 60.*i;
Double_t phirad = phi*TMath::DegToRad();
Double_t xp = dshift*TMath::Sin(phirad);
Double_t yp = -dshift*TMath::Cos(phirad);
rot = new TGeoRotation(*rot1);
rot->RotateZ(phi);
cell->AddNode(tplate,i+1,new TGeoCombiTrans(xp,yp,0,rot));
}
// Make a row as an assembly of cells, then combine rows in a honeycomb
// structure. This again works without any need to define rows as
// "overlapping"
TGeoVolume *row = new TGeoVolumeAssembly("ROW");
Int_t ncells = 5;
for (i=0; i<ncells; i++) {
Double_t ycell = (2*i+1)*(dshift+10);
row->AddNode(cell, ncells+i+1, new TGeoTranslation(0,ycell,0));
row->AddNode(cell,ncells-i,new TGeoTranslation(0,-ycell,0));
}
Double_t dxrow = 3.*(dshift+10.)*TMath::Tan(30.*TMath::DegToRad());
Double_t dyrow = dshift+10.;
Int_t nrows = 5;
for (i=0; i<nrows; i++) {
Double_t xrow = 0.5*(2*i+1)*dxrow;
Double_t yrow = 0.5*dyrow;
if ((i%2)==0) yrow = -yrow;
top->AddNode(row, nrows+i+1, new TGeoTranslation(xrow,yrow,0));
top->AddNode(row, nrows-i, new TGeoTranslation(-xrow,-yrow,0));
}
//--- close the geometry
geom->CloseGeometry();
geom->SetVisLevel(4);
geom->SetVisOption(0);
top->Draw();
}
Author
Andrei Gheata

Definition in file assembly.C.

TGeoManager::SetVisLevel
void SetVisLevel(Int_t level=3)
set default level down to which visualization is performed
Definition: TGeoManager.cxx:2248
TGeoCombiTrans
Definition: TGeoMatrix.h:291
TGeoManager::MakeBox
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.
Definition: TGeoManager.cxx:2918
TMath::Cos
Double_t Cos(Double_t)
Definition: TMath.h:643
TGeoManager::CloseGeometry
void CloseGeometry(Option_t *option="d")
Closing geometry implies checking the geometry validity, fixing shapes with negative parameters (run-...
Definition: TGeoManager.cxx:1359
TMath::DegToRad
constexpr Double_t DegToRad()
Conversion from degree to radian:
Definition: TMath.h:87
TMath::Tan
Double_t Tan(Double_t)
Definition: TMath.h:647
Int_t
int Int_t
Definition: RtypesCore.h:45
TGeoVolume::AddNode
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:932
TGeoTranslation
Definition: TGeoMatrix.h:121
TGeoMaterial
Definition: TGeoMaterial.h:34
TGeoRotation::RotateX
virtual void RotateX(Double_t angle)
Rotate about X axis of the master frame with angle expressed in degrees.
Definition: TGeoMatrix.cxx:1087
TGeoRotation::RotateZ
virtual void RotateZ(Double_t angle)
Rotate about Z axis of the master frame with angle expressed in degrees.
Definition: TGeoMatrix.cxx:1133
TGeoManager::SetTopVolume
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
Definition: TGeoManager.cxx:3397
TGeoManager::SetVisOption
void SetVisOption(Int_t option=0)
set drawing mode :
Definition: TGeoManager.cxx:2221
TGeoVolume::Draw
virtual void Draw(Option_t *option="")
draw top volume according to option
Definition: TGeoVolume.cxx:1146
TGeoRotation
Definition: TGeoMatrix.h:174
TMath::Sin
Double_t Sin(Double_t)
Definition: TMath.h:639
Double_t
double Double_t
Definition: RtypesCore.h:59
kBlue
@ kBlue
Definition: Rtypes.h:66
TGeoMedium
Definition: TGeoMedium.h:23
TGeoVolume::SetLineColor
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TGeoVolume.cxx:2035
TGeoManager
Definition: TGeoManager.h:44
TGeoVolume
Definition: TGeoVolume.h:44
TGeoVolumeAssembly
Definition: TGeoVolume.h:302