BLElement Class Reference

#include <BLElement.hh>

Inheritance diagram for BLElement:

BLCommand BLCMDcorner BLCMDfieldexpr BLCMDfieldmap BLCMDgenericquad BLCMDhelicaldipole BLCMDhelicalharmonic BLCMDidealsectorbend BLCMDlilens BLCMDmultipole BLCMDparticlefilter BLCMDpillbox BLCMDrfdevice BLCMDsolenoid BLCMDtrackerplane BLCMDusertrackfilter BLCMDvirtualdetector BLGroupElement

List of all members.


Detailed Description

class BLElement - interface class for all g4beamline Elements

BLElement defines elements to be placed into the geometry of g4beamline.

Normally an element implementation will derive a class from this one, and if it has an EM field, also derives from BLElementField. Usually all are in a single file named for the element command class. The default constructor of the derived class is used to implement the element command (see BLCommand), and the copy constructor is used by the element command to create instances of the element.

Note the constructor of the derived class must contain enough information so the size of the element is determined (getLength(), etc.). Or at least these must be known before the element command returns.

A non-default instance of this class represents a specific type of the element, complete with all argument values; it is created by the element command of the derived class. This instance can be placed multiple times by the place command and by place commands applied to groups in which the instance has been placed. After the command file has been read (i.e. all elements have been created and placed), then the World group is constructed, and that results in a traversal of the placement tree and the construction of all elements. Thus a single instance of this class can appear multiple times at multiple locations within the overall geometry.

When element argments are given on the place command, clone() is used to copy the element, and then defineNamedArgs() is called for each element argument. Then the cloned element is placed.

NOTE: Derived classes MUST use the copy constructor, not the default constructor! ONLY the default object should use the default constructor.

Public Member Functions

 BLElement ()
 Default constructor.
virtual ~BLElement ()
 Destructor.
 BLElement (const BLElement &r)
 Copy constructor.
virtual BLElementclone ()=0
 clone() will clone a copy of an element. Used when element arguments are given in a place command.
virtual G4String getName () const
 getName() returns the element's name; do not confuse this with commandName(). Not used by the default instance.
virtual void setName (G4String _name)
 setName() sets the element's name; Adds the BLElement to mapElement. Used by instances of the derived class representing real elements; not used by the default instance. virtual so derived base classes can keep a list of their elements.
virtual void construct (G4RotationMatrix *relativeRotation, G4ThreeVector relativePosition, G4LogicalVolume *parent, G4String parentName, G4RotationMatrix *parentRotation, G4ThreeVector parentPosition)=0
 construct() will construct a physical implementation of this element at a specific location within the overall geometry. The name of the implementation should be parentName plus the name of the element; the physical volume should be linked into the parent in the usual way. relativeRotation is an active rotation of this element wrt the parent's coordinate axes, and relativePosition is in the parent's coords as usual (if the parent is the world, the centerline coordinate transform is included) -- the rotation for G4VPlacement is relativeRotation->inverse(). parentRotation and parentPosition are the rotation and position of the parent, expressed in global coordinates -- most elements can ignore them, as they are normally used to construct a BLCoordinateTransform from global coordinates to the element's local coordinates (e.g. for GlobalField).
virtual G4double getLength ()=0
 getLength() returns this element's Length along the Z axis.
virtual G4double getWidth ()=0
 getWidth() returns this element's Width along the X axis. For asymmetric elements, the width is twice the element's futhest point from X=0.
virtual G4double getHeight ()=0
 getHeight() returns this element's height along the Y axis. For asymmetric elements, the width is twice the element's futhest point from Y=0.
virtual G4bool isOK ()=0
 isOK() returns true iff this element is ready to process beam. It is queried AFTER the reference particle is tracked, so it can reflect the status of tuning performed by the reference particle.
virtual G4bool isGroupElement ()
 isGroupElement() returns true if this is a BLGroupElement. That is, if this element can be the parent of other elements.
bool getPlacedFlag ()
 getPlacedFlag() returns true if this element has been placed.
void setPlacedFlag (bool flag=true)
 setPlacedFlag() sets the flag for placing this element.
virtual void generatePoints (int npoints, std::vector< G4ThreeVector > &v)=0
 generatePoints() will generate points for the testGeometry() function (of BLGroupElement) for this element. It generates however many points are necessary to test extremes of its surface, plus randomly distributed ones on the surface, up to npoints total. Each point is in the local coordinates of the element.
virtual G4bool isOutside (G4ThreeVector &local, G4double tolerance)=0
 isOutside() returns true if the point is outside this element, or is within tolerance of being outside. local[] is the point in local coordinates of this element.
void generateBox (unsigned int npoints, G4double width, G4double height, G4double length, std::vector< G4ThreeVector > &v)
 generateBox() generates geometry test points for a Box (a convenience method for derived classes to use)
void generateTubs (unsigned int npoints, G4double innerRadius, G4double outerRadius, G4double initialPhi, G4double finalPhi, G4double length, std::vector< G4ThreeVector > &v)
 generateTubs() generates geometry test points for a Tubs (a convenience method for derived classes to use)

Static Public Member Functions

static BLElementfind (G4String name)
 find() finds the BLElement with a given name.
static G4bool allOK ()
 allOK() returns true iff all elements are ready to process beam.

Private Attributes

G4String name
bool placed

Static Private Attributes

static std::map< G4String,
BLElement * > 
mapElement


Constructor & Destructor Documentation

BLElement::BLElement (  )  [inline]

Default constructor.

References placed.

00070 : BLCommand(), name() { placed = false; }

virtual BLElement::~BLElement (  )  [inline, virtual]

Destructor.

00073 { }

BLElement::BLElement ( const BLElement r  )  [inline]

Copy constructor.

References placed.

00076                                       : BLCommand(r), name(r.name) 
00077                 { placed = r.placed; }


Member Function Documentation

virtual BLElement* BLElement::clone (  )  [pure virtual]

virtual G4String BLElement::getName (  )  const [inline, virtual]

void BLElement::setName ( G4String  _name  )  [virtual]

BLElement * BLElement::find ( G4String  name  )  [static]

find() finds the BLElement with a given name.

Reimplemented in BLGroupElement.

References mapElement.

Referenced by BLCMDplace::command().

00032 {
00033         return mapElement[_name];
00034 }

G4bool BLElement::allOK (  )  [static]

allOK() returns true iff all elements are ready to process beam.

References mapElement.

Referenced by main().

00037 {
00038         std::map<G4String,BLElement*>::iterator i;
00039         for(i=mapElement.begin(); i!=mapElement.end(); ++i) {
00040                 if(!i->second->isOK()) return false;
00041         }
00042         return true;
00043 }

virtual void BLElement::construct ( G4RotationMatrix *  relativeRotation,
G4ThreeVector  relativePosition,
G4LogicalVolume *  parent,
G4String  parentName,
G4RotationMatrix *  parentRotation,
G4ThreeVector  parentPosition 
) [pure virtual]

construct() will construct a physical implementation of this element at a specific location within the overall geometry. The name of the implementation should be parentName plus the name of the element; the physical volume should be linked into the parent in the usual way. relativeRotation is an active rotation of this element wrt the parent's coordinate axes, and relativePosition is in the parent's coords as usual (if the parent is the world, the centerline coordinate transform is included) -- the rotation for G4VPlacement is relativeRotation->inverse(). parentRotation and parentPosition are the rotation and position of the parent, expressed in global coordinates -- most elements can ignore them, as they are normally used to construct a BLCoordinateTransform from global coordinates to the element's local coordinates (e.g. for GlobalField).

Implemented in BLGroup, BLCMDabsorber, BLCMDbox, BLCMDcorner, BLCMDextrusion, BLCMDfieldexpr, BLCMDfieldmap, BLCMDgenericbend, BLCMDgenericquad, BLCMDhelicaldipole, BLCMDhelicalharmonic, BLCMDidealsectorbend, BLCMDlilens, BLCMDmultipole, BLCMDparticlefilter, BLCMDpillbox, BLCMDpolycone, BLCMDrfdevice, BLCMDsolenoid, BLCMDsphere, BLCMDtorus, BLCMDtrackerplane, BLCMDtrap, BLCMDtubs, BLCMDusertrackfilter, and BLCMDvirtualdetector.

Referenced by BLGroupElement::constructChildren().

virtual G4double BLElement::getLength (  )  [pure virtual]

virtual G4double BLElement::getWidth (  )  [pure virtual]

virtual G4double BLElement::getHeight (  )  [pure virtual]

virtual G4bool BLElement::isOK (  )  [pure virtual]

isOK() returns true iff this element is ready to process beam. It is queried AFTER the reference particle is tracked, so it can reflect the status of tuning performed by the reference particle.

Implemented in BLGroup, BLCMDabsorber, BLCMDbox, BLCMDcorner, BLCMDextrusion, BLCMDfieldexpr, BLCMDfieldmap, BLCMDgenericbend, BLCMDgenericquad, BLCMDhelicaldipole, BLCMDhelicalharmonic, BLCMDidealsectorbend, BLCMDlilens, BLCMDmultipole, BLCMDparticlefilter, BLCMDpillbox, BLCMDpolycone, BLCMDrfdevice, BLCMDsolenoid, BLCMDsphere, BLCMDtorus, BLCMDtrackerplane, BLCMDtrap, BLCMDtubs, BLCMDusertrackfilter, and BLCMDvirtualdetector.

virtual G4bool BLElement::isGroupElement (  )  [inline, virtual]

isGroupElement() returns true if this is a BLGroupElement. That is, if this element can be the parent of other elements.

Reimplemented in BLGroupElement.

Referenced by BLGroupElement::testGeometry().

00145 { return false; }

bool BLElement::getPlacedFlag (  )  [inline]

getPlacedFlag() returns true if this element has been placed.

References placed.

Referenced by BLCMDplace::command().

00148 { return placed; }

void BLElement::setPlacedFlag ( bool  flag = true  )  [inline]

setPlacedFlag() sets the flag for placing this element.

References placed.

Referenced by BLCMDplace::command().

00151 { placed = flag; }

virtual void BLElement::generatePoints ( int  npoints,
std::vector< G4ThreeVector > &  v 
) [pure virtual]

generatePoints() will generate points for the testGeometry() function (of BLGroupElement) for this element. It generates however many points are necessary to test extremes of its surface, plus randomly distributed ones on the surface, up to npoints total. Each point is in the local coordinates of the element.

Implemented in BLGroup, BLCMDabsorber, BLCMDbox, BLCMDcorner, BLCMDextrusion, BLCMDfieldexpr, BLCMDfieldmap, BLCMDgenericbend, BLCMDgenericquad, BLCMDhelicaldipole, BLCMDhelicalharmonic, BLCMDidealsectorbend, BLCMDlilens, BLCMDmultipole, BLCMDparticlefilter, BLCMDpillbox, BLCMDpolycone, BLCMDrfdevice, BLCMDsolenoid, BLCMDsphere, BLCMDtorus, BLCMDtrackerplane, BLCMDtrap, BLCMDtubs, BLCMDusertrackfilter, and BLCMDvirtualdetector.

Referenced by BLGroupElement::testGeometry().

virtual G4bool BLElement::isOutside ( G4ThreeVector &  local,
G4double  tolerance 
) [pure virtual]

void BLElement::generateBox ( unsigned int  npoints,
G4double  width,
G4double  height,
G4double  length,
std::vector< G4ThreeVector > &  v 
)

generateBox() generates geometry test points for a Box (a convenience method for derived classes to use)

References rand.

Referenced by BLGroup::generatePoints(), BLCMDvirtualdetector::generatePoints(), BLCMDusertrackfilter::generatePoints(), BLCMDtrackerplane::generatePoints(), BLCMDparticlefilter::generatePoints(), BLCMDgenericbend::generatePoints(), and BLCMDbox::generatePoints().

00049 {
00050         v.clear();
00051         G4double w=width/2.0, h=height/2.0, l=length/2.0;
00052         // the 8 corners
00053         v.push_back(G4ThreeVector(w,h,l));
00054         v.push_back(G4ThreeVector(w,h,-l));
00055         v.push_back(G4ThreeVector(w,-h,l));
00056         v.push_back(G4ThreeVector(w,-h,-l));
00057         v.push_back(G4ThreeVector(-w,h,l));
00058         v.push_back(G4ThreeVector(-w,h,-l));
00059         v.push_back(G4ThreeVector(-w,-h,l));
00060         v.push_back(G4ThreeVector(-w,-h,-l));
00061         // the 12 edge midpoints
00062         v.push_back(G4ThreeVector(0,h,l));
00063         v.push_back(G4ThreeVector(0,h,-l));
00064         v.push_back(G4ThreeVector(0,-h,l));
00065         v.push_back(G4ThreeVector(0,-h,-l));
00066         v.push_back(G4ThreeVector(w,0,l));
00067         v.push_back(G4ThreeVector(w,0,-l));
00068         v.push_back(G4ThreeVector(-w,0,l));
00069         v.push_back(G4ThreeVector(-w,0,-l));
00070         v.push_back(G4ThreeVector(w,h,0));
00071         v.push_back(G4ThreeVector(w,-h,0));
00072         v.push_back(G4ThreeVector(-w,h,0));
00073         v.push_back(G4ThreeVector(-w,-h,0));
00074         // the 6 face centers
00075         v.push_back(G4ThreeVector(w,0,0));
00076         v.push_back(G4ThreeVector(-w,0,0));
00077         v.push_back(G4ThreeVector(0,h,0));
00078         v.push_back(G4ThreeVector(0,-h,0));
00079         // BLCMDgenericbend requires these two be last:
00080         v.push_back(G4ThreeVector(0,0,l));
00081         v.push_back(G4ThreeVector(0,0,-l));
00082         // random points on the surfaces
00083         while(v.size() < npoints) {
00084                 G4double x=0,y=0,z=0;
00085                 switch(v.size() % 6) {
00086                 case 0: x=w;  y=rand()*height-h; z=rand()*length-l; break;
00087                 case 1: x=-w; y=rand()*height-h; z=rand()*length-l; break;
00088                 case 2: x=rand()*width-w; y=h;  z=rand()*length-l; break;
00089                 case 3: x=rand()*width-w; y=-h; z=rand()*length-l; break;
00090                 case 4: x=rand()*width-w; y=rand()*height-h; z=l;  break;
00091                 case 5: x=rand()*width-w; y=rand()*height-h; z=-l; break;
00092                 }
00093                 v.push_back(G4ThreeVector(x,y,z));
00094         }
00095 }

void BLElement::generateTubs ( unsigned int  npoints,
G4double  innerRadius,
G4double  outerRadius,
G4double  initialPhi,
G4double  finalPhi,
G4double  length,
std::vector< G4ThreeVector > &  v 
)

generateTubs() generates geometry test points for a Tubs (a convenience method for derived classes to use)

References rand.

Referenced by BLGroup::generatePoints(), BLCMDvirtualdetector::generatePoints(), BLCMDusertrackfilter::generatePoints(), BLCMDtubs::generatePoints(), BLCMDtrackerplane::generatePoints(), BLCMDsolenoid::generatePoints(), BLCMDrfdevice::generatePoints(), BLCMDpillbox::generatePoints(), BLCMDparticlefilter::generatePoints(), BLCMDmultipole::generatePoints(), BLCMDlilens::generatePoints(), BLCMDgenericquad::generatePoints(), and BLCMDabsorber::generatePoints().

00100 {
00101         v.clear();
00102         G4double l=length/2.0;
00103 
00104         // 8 points evenly spaced around outer (+inner) surface
00105         G4double dPhi = (finalPhi-initialPhi)/8.0;
00106         for(int i=0; i<9; ++i) {
00107                 // if full cylinder, i=8 duplicates i=0
00108                 if(i == 8 && dPhi >= 3.1415/4.0) break;
00109                 G4double phi = (double)i*dPhi + initialPhi;
00110                 G4double x = outerRadius * cos(phi);
00111                 G4double y = outerRadius * sin(phi);
00112                 v.push_back(G4ThreeVector(x,y,l));
00113                 v.push_back(G4ThreeVector(x,y,-l));
00114                 v.push_back(G4ThreeVector(x,y,0.0));
00115                 if(innerRadius > 0.0) {
00116                         x = innerRadius * cos(phi);
00117                         y = innerRadius * sin(phi);
00118                         v.push_back(G4ThreeVector(x,y,l));
00119                         v.push_back(G4ThreeVector(x,y,-l));
00120                         v.push_back(G4ThreeVector(x,y,0.0));
00121                 }
00122         }
00123         // center of +z and =z ends, if innerRadius == 0
00124         if(innerRadius == 0.0) {
00125                 v.push_back(G4ThreeVector(0.0,0.0,l));
00126                 v.push_back(G4ThreeVector(0.0,0.0,-l));
00127         }
00128         // random points on the surface
00129         dPhi = finalPhi - initialPhi;
00130         G4double dR = outerRadius - innerRadius;
00131         while(v.size() < npoints) {
00132                 G4double z=0.0,phi=0.0,r=0.0;
00133                 switch(v.size() % 6) {
00134                 case 0: // inner surface
00135 inner:                  if(innerRadius > 0.0) {
00136                                 phi = rand()*dPhi + initialPhi;
00137                                 r = innerRadius;
00138                                 z = rand()*length - l;
00139                                 break;
00140                         }
00141                         // flow into case 1
00142                 case 1: // outer surface
00143 outer:                  phi = rand()*dPhi + initialPhi;
00144                         r = outerRadius;
00145                         z = rand()*length - l;
00146                         break;
00147                 case 2: // +z end
00148                         phi = rand()*dPhi + initialPhi;
00149                         r = rand()*dR + innerRadius;
00150                         z = l;
00151                         break;
00152                 case 3: // -z end
00153                         phi = rand()*dPhi + initialPhi;
00154                         r = rand()*dR + innerRadius;
00155                         z = -l;
00156                         break;
00157                 case 4: // initialPhi face
00158                         if(dPhi >= 3.1415*2.0) goto inner;
00159                         phi = initialPhi;
00160                         r = rand()*dR + innerRadius;
00161                         z = rand()*length - l;
00162                         break;
00163                 case 5: // finalPhi face
00164                         if(dPhi >= 3.1415*2.0) goto outer;
00165                         phi = finalPhi;
00166                         r = rand()*dR + innerRadius;
00167                         z = rand()*length - l;
00168                         break;
00169                 }
00170                 v.push_back(G4ThreeVector(r*cos(phi),r*sin(phi),z));
00171         }
00172 }


Member Data Documentation

std::map< G4String, BLElement * > BLElement::mapElement [static, private]

Referenced by allOK(), find(), and setName().

G4String BLElement::name [private]

Referenced by getName(), and setName().

bool BLElement::placed [private]


The documentation for this class was generated from the following files:
g4beamline