BLCMDsphere Class Reference

Inheritance diagram for BLCMDsphere:

BLGroupElement BLElement BLCommand

List of all members.


Detailed Description

BLCMDsphere implements a sphere of material.

Public Member Functions

 BLCMDsphere ()
 Default constructor. Defines the command, args, etc.
virtual ~BLCMDsphere ()
 Destructor.
 BLCMDsphere (const BLCMDsphere &r)
 Copy constructor.
BLElementclone ()
 clone()
G4String commandName ()
 commandName() returns "sphere".
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
 command() implements the sphere command.
void defineNamedArgs ()
 defineNamedArgs() defines the named arguments for the command.
virtual void construct (G4RotationMatrix *relativeRotation, G4ThreeVector relativePosition, G4LogicalVolume *parent, G4String parentName, G4RotationMatrix *parentRotation, G4ThreeVector parentPosition)
 construct() - construct the sphere
G4double getLength ()
 getLength() returns the length of the sphere
G4double getWidth ()
 getWidth() returns the width of the sphere
G4double getHeight ()
 getHeight() returns the height of the sphere
G4bool isOK ()
 isOK() returns true.
bool isOutside (G4ThreeVector &local, G4double tolerance)
 isOutside() from BLElement.
void generatePoints (int npoints, std::vector< G4ThreeVector > &v)
 generatePoints() from BLElement.
bool isWithin (G4ThreeVector &local, G4double tolerance)
 isWithin() from BLGroupElement.

Private Attributes

G4double innerRadius
G4double outerRadius
G4double initialPhi
G4double finalPhi
G4double initialTheta
G4double finalTheta
G4String material
G4String color
G4int kill
G4double maxStep
G4Sphere * sphere

Constructor & Destructor Documentation

BLCMDsphere::BLCMDsphere (  ) 

Default constructor. Defines the command, args, etc.

References BLCMDTYPE_ELEMENT, color, finalPhi, finalTheta, initialPhi, initialTheta, innerRadius, kill, material, maxStep, outerRadius, BLCommand::registerCommand(), BLCommand::setDescription(), BLCommand::setSynopsis(), and sphere.

Referenced by clone(), and command().

00109                          : BLGroupElement()
00110 {
00111         // register the commandName(), and its synopsis and description.
00112         registerCommand(BLCMDTYPE_ELEMENT);
00113         setSynopsis("construct a sphere (or section of one)");
00114         setDescription("This is a direct interface to G4Sphere.");
00115 
00116         // provide initial values for fields
00117         innerRadius = 0.0;
00118         outerRadius = 0.0;
00119         initialPhi = 0.0;
00120         finalPhi = 360.0*deg;
00121         initialTheta = 0.0;
00122         finalTheta = 360.0*deg;
00123         material = "Vacuum";
00124         color = "1,1,1";
00125         kill = 0;
00126         maxStep = -1.0;
00127         sphere = 0;
00128 }

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

Destructor.

00053 { }

BLCMDsphere::BLCMDsphere ( const BLCMDsphere r  ) 

Copy constructor.

References color, finalPhi, finalTheta, initialPhi, initialTheta, innerRadius, kill, material, maxStep, outerRadius, and sphere.

00131                                              : BLGroupElement(r)
00132 {
00133         // copy fields one at a time (transfers default values from the
00134         // default object to this new object).
00135         innerRadius = r.innerRadius;
00136         outerRadius = r.outerRadius;
00137         initialPhi = r.initialPhi;
00138         finalPhi = r.finalPhi;
00139         initialTheta = r.initialTheta;
00140         finalTheta = r.finalTheta;
00141         material = r.material;
00142         color = r.color;
00143         kill = r.kill;
00144         maxStep = r.maxStep;
00145         sphere = r.sphere;
00146 }


Member Function Documentation

BLElement* BLCMDsphere::clone (  )  [inline, virtual]

clone()

Implements BLElement.

References BLCMDsphere().

00059 { return new BLCMDsphere(*this); }

G4String BLCMDsphere::commandName (  )  [inline, virtual]

commandName() returns "sphere".

Implements BLCommand.

00062 { return "sphere"; }

int BLCMDsphere::command ( BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

command() implements the sphere command.

Implements BLCommand.

References BLCMDsphere(), BLParam::getDouble(), BLCommand::getMaterial(), BLCommand::handleNamedArgs(), material, maxStep, Param, BLCommand::print(), BLCommand::printError(), and BLGroupElement::setName().

00149 {
00150         if(argv.size() != 1) {
00151                 printError("sphere: Invalid command, must have name");
00152                 return -1;
00153         }
00154 
00155         if(argv[0] == "default") {
00156                 return defaultSphere.handleNamedArgs(namedArgs);
00157         }
00158 
00159         BLCMDsphere *t = new BLCMDsphere(defaultSphere);
00160         t->setName(argv[0]);
00161         int retval = t->handleNamedArgs(namedArgs);
00162 
00163         if(t->maxStep < 0.0) t->maxStep = Param.getDouble("maxStep");
00164 
00165         // check material exists
00166         if(t->material.size() > 0) getMaterial(t->material,false);
00167 
00168         t->print(argv[0]);
00169 
00170         return retval;
00171 }

void BLCMDsphere::defineNamedArgs (  )  [virtual]

defineNamedArgs() defines the named arguments for the command.

Reimplemented from BLCommand.

References BLCommand::argDouble(), BLCommand::argInt(), BLCommand::argString(), color, finalPhi, finalTheta, initialPhi, initialTheta, innerRadius, kill, material, maxStep, and outerRadius.

00174 {
00175         argDouble(innerRadius,"innerRadius","The inside radius of the sphere (mm)");
00176         argDouble(outerRadius,"outerRadius","The outer radius of the sphere (mm)");
00177         argDouble(initialPhi,"initialPhi","The initial Phi value (deg; 0 for all)",deg);
00178         argDouble(finalPhi,"finalPhi","The final Phi value (deg; 360 for all)",deg);
00179         argDouble(initialTheta,"initialTheta","The initialTheta of the sphere (deg, 0 for all)",deg);
00180         argDouble(finalTheta,"finalTheta","The finalTheta of the sphere (deg, 180 for all)",deg);
00181         argDouble(maxStep,"maxStep","The maximum stepsize in the element (mm)");
00182         argString(material,"material","The material of the sphere");
00183         argString(color,"color","The color of the sphere (''=invisible)");
00184         argInt(kill,"kill","Set nonzero to kill every track that enters.");
00185 }

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

construct() - construct the sphere

Implements BLElement.

References color, BLGroupElement::constructChildren(), finalPhi, finalTheta, BLParam::getDouble(), getLength(), BLCommand::getMaterial(), BLElement::getName(), BLManager::getObject(), BLCommand::getVisAttrib(), initialPhi, initialTheta, innerRadius, kill, material, maxStep, outerRadius, Param, and sphere.

00193 {
00194         G4String thisname = parentName+getName();
00195 
00196         if(!sphere)
00197                 sphere = new G4Sphere(thisname+"Sphere", innerRadius, outerRadius,
00198                                 initialPhi,(finalPhi-initialPhi),
00199                                 initialTheta,(finalTheta-initialTheta));
00200         G4Material *mat = getMaterial(material);
00201         G4LogicalVolume *lv = new G4LogicalVolume(sphere,mat, thisname+"LogVol");
00202         lv->SetVisAttributes(getVisAttrib(color));
00203         if(maxStep < 0.0) maxStep = Param.getDouble("maxStep");
00204         lv->SetUserLimits(new G4UserLimits(maxStep));
00205 
00206         // geant4 rotation convention is backwards from g4beamline
00207         G4RotationMatrix *g4rot = 0;
00208         if(relativeRotation)
00209                 g4rot = new G4RotationMatrix(relativeRotation->inverse());
00210 
00211         G4VPhysicalVolume *pv = new G4PVPlacement(g4rot, relativePosition,lv,
00212                                         thisname, parent,false,0);
00213 
00214         if(kill)
00215                 BLManager::getObject()->
00216                         registerSteppingAction(pv,new BLKillTrack(thisname));
00217 
00218         // get globalRotation and globalPosition
00219         G4RotationMatrix *globalRotation = 0;
00220         if(relativeRotation && parentRotation) {
00221                 globalRotation = 
00222                     new G4RotationMatrix(*parentRotation * *relativeRotation);
00223         } else if(relativeRotation) {
00224                 globalRotation = relativeRotation;
00225         } else if(parentRotation) {
00226                 globalRotation = parentRotation;
00227         }
00228         G4ThreeVector globalPosition(relativePosition + parentPosition);
00229         if(parentRotation)
00230                 globalPosition = *parentRotation * relativePosition +
00231                                 parentPosition;
00232 
00233         constructChildren(lv,thisname,globalRotation,globalPosition);
00234 
00235         printf("BLCMDsphere::Construct %s parent=%s relZ=%.1f globZ=%.1f\n"
00236                         "\tzmin=%.1f zmax=%.1f kill=%d\n",
00237                 thisname.c_str(),parentName.c_str(),relativePosition[2],
00238                 globalPosition[2],
00239                 globalPosition[2]-getLength()/2.0,
00240                 globalPosition[2]+getLength()/2.0,
00241                 kill);
00242 }

G4double BLCMDsphere::getLength (  )  [inline, virtual]

getLength() returns the length of the sphere

Implements BLElement.

References outerRadius.

Referenced by construct().

00079 { return 2.0*outerRadius; }

G4double BLCMDsphere::getWidth (  )  [inline, virtual]

getWidth() returns the width of the sphere

Implements BLElement.

References outerRadius.

00082 { return 2.0*outerRadius; }

G4double BLCMDsphere::getHeight (  )  [inline, virtual]

getHeight() returns the height of the sphere

Implements BLElement.

References outerRadius.

00085 { return 2.0*outerRadius; }

G4bool BLCMDsphere::isOK (  )  [inline, virtual]

isOK() returns true.

Implements BLElement.

00088 { return true; }

bool BLCMDsphere::isOutside ( G4ThreeVector &  local,
G4double  tolerance 
) [inline, virtual]

isOutside() from BLElement.

Implements BLElement.

References sphere.

00092                 { assert(sphere!=0);  return sphere->Inside(local) != kInside; }

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

generatePoints() from BLElement.

Implements BLElement.

References sphere.

00096                 { v.clear();
00097                   for(int n=0; n<npoints*5; ++n)
00098                         v.push_back(sphere->GetPointOnSurface());
00099                 }

bool BLCMDsphere::isWithin ( G4ThreeVector &  local,
G4double  tolerance 
) [inline, virtual]

isWithin() from BLGroupElement.

Implements BLGroupElement.

References sphere.

00103             { assert(sphere!=0);  return sphere->Inside(local) != kOutside; }


Member Data Documentation

G4double BLCMDsphere::innerRadius [private]

G4double BLCMDsphere::outerRadius [private]

G4double BLCMDsphere::initialPhi [private]

G4double BLCMDsphere::finalPhi [private]

G4double BLCMDsphere::initialTheta [private]

G4double BLCMDsphere::finalTheta [private]

G4String BLCMDsphere::material [private]

G4String BLCMDsphere::color [private]

G4int BLCMDsphere::kill [private]

G4double BLCMDsphere::maxStep [private]

G4Sphere* BLCMDsphere::sphere [private]


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