12.07.2015 Views

Geant4 User's Guide for Application Developers - Geant4 - CERN

Geant4 User's Guide for Application Developers - Geant4 - CERN

Geant4 User's Guide for Application Developers - Geant4 - CERN

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Detector Definition and ResponseThe solids used can actually be of any type. However, in order to fully support the export of a <strong>Geant4</strong>solid model via STEP to CAD systems, we restrict the use of Boolean operations to this subset of solids.But this subset contains all the most interesting use cases.The constituent solids of a Boolean operation should possibly avoid be composed by sharing all or partof their surfaces. This precaution is necessary in order to avoid the generation of 'fake' surfaces due toprecision loss, or errors in the final visualization of the Boolean shape. Moreover, the final Boolean solidshould represent a single 'closed' solid, i.e. a Boolean operation between two solids which are disjoint orfar apart each other, is not a valid Boolean composition.The tracking cost <strong>for</strong> navigating in a Boolean solid in the current implementation, is proportional tothe number of constituent solids. So care must be taken to avoid extensive, unecessary use of Booleansolids in per<strong>for</strong>mance-critical areas of a geometry description, where each solid is created from Booleancombinations of many other solids.Examples of the creation of the simplest Boolean solids are given below:G4Box* box =new G4Box("Box",20*mm,30*mm,40*mm);G4Tubs* cyl =new G4Tubs("Cylinder",0,50*mm,50*mm,0,twopi); // r:G4UnionSolid* union =new G4UnionSolid("Box+Cylinder", box, cyl);G4IntersectionSolid* intersection =new G4IntersectionSolid("Box*Cylinder", box, cyl);G4SubtractionSolid* subtraction =new G4SubtractionSolid("Box-Cylinder", box, cyl);0 mm -> 50 mm// z: -50 mm -> 50 mm// phi: 0 -> 2 piwhere the union, intersection and subtraction of a box and cylinder are constructed.The more useful case where one of the solids is displaced from the origin of coordinates also exists. In this casethe second solid is positioned relative to the coordinate system (and thus relative to the first). This can be donein two ways:• Either by giving a rotation matrix and translation vector that are used to trans<strong>for</strong>m the coordinate system of thesecond solid to the coordinate system of the first solid. This is called the passive method.• Or by creating a trans<strong>for</strong>mation that moves the second solid from its desired position to its standard position,e.g., a box's standard position is with its centre at the origin and sides parallel to the three axes. This is calledthe active method.In the first case, the translation is applied first to move the origin of coordinates. Then the rotation is used to rotatethe coordinate system of the second solid to the coordinate system of the first.G4RotationMatrix* yRot = new G4RotationMatrix; // Rotates X and Z axes onlyyRot->rotateY(M_PI/4.*rad);// Rotates 45 degreesG4ThreeVector zTrans(0, 0, 50);G4UnionSolid* unionMoved =new G4UnionSolid("Box+CylinderMoved", box, cyl, yRot, zTrans);//// The new coordinate system of the cylinder is translated so that// its centre is at +50 on the original Z axis, and it is rotated// with its X axis halfway between the original X and Z axes.// Now we build the same solid using the alternative method//G4RotationMatrix invRot = *(yRot->invert());G4Trans<strong>for</strong>m3D trans<strong>for</strong>m(invRot, zTrans);G4UnionSolid* unionMoved =new G4UnionSolid("Box+CylinderMoved", box, cyl, trans<strong>for</strong>m);79

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!