BLCMDgenericbend Class Reference

Inheritance diagram for BLCMDgenericbend:

BLGroupElement BLElement BLCommand

List of all members.


Detailed Description

BLCMDgenericbend implements a generic bending magnet with a box field.

The magnetic field is uniform throught the box, along the local Y axis, modified by a fringe field computation.

Public Member Functions

 BLCMDgenericbend ()
 Default constructor. Defines the command, args, etc.
virtual ~BLCMDgenericbend ()
 Destructor.
 BLCMDgenericbend (const BLCMDgenericbend &r)
 Copy constructor.
BLElementclone ()
 clone()
G4String commandName ()
 commandName() returns "genericbend".
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
 command() implements the genericbend command.
void defineNamedArgs ()
 defineNamedArgs() defines the named arguments for the command.
void construct (G4RotationMatrix *relativeRotation, G4ThreeVector relativePosition, G4LogicalVolume *parent, G4String parentName, G4RotationMatrix *parentRotation, G4ThreeVector parentPosition)
 construct() - construct the generic bending magnet
G4double getLength ()
 getLength() returns the length of the iron region
G4double getWidth ()
 getWidth() returns the width of the iron region
G4double getHeight ()
 getHeight() returns the height of the iron region
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 fieldWidth
G4double fieldHeight
G4double fieldLength
G4double ironWidth
G4double ironHeight
G4double ironLength
G4double By
G4String fieldMaterial
G4String fieldColor
G4String ironMaterial
G4String ironColor
G4int kill
G4double maxStep
G4String fringe
G4double fringeFactor
G4int openAperture
G4Box * fieldBox
G4Box * ironBox
G4VSolid * ironSolid

Friends

class GenericBendField


Constructor & Destructor Documentation

BLCMDgenericbend::BLCMDgenericbend (  ) 

Default constructor. Defines the command, args, etc.

References BLCMDTYPE_ELEMENT, By, fieldBox, fieldColor, fieldHeight, fieldLength, fieldMaterial, fieldWidth, fringe, fringeFactor, ironBox, ironColor, ironHeight, ironLength, ironMaterial, ironSolid, ironWidth, kill, maxStep, openAperture, BLCommand::registerCommand(), BLCommand::setDescription(), and BLCommand::setSynopsis().

Referenced by clone(), and command().

00148                                    : BLGroupElement()
00149 {
00150         // register the commandName(), and its synopsis and description.
00151         registerCommand(BLCMDTYPE_ELEMENT);
00152         setSynopsis("construct a generic bending magnet.");
00153         setDescription("The field region is a box with By specified.\n"
00154                 "A fringe field computation based on the method of COSY\n"
00155                 "INFINITY is included by default, extending the field in a "
00156                 "rectangle extending the straight aperture along the local z.\n"
00157                 "This is first order only, and assumes the magnet is "
00158                 "infinitely wide; the fringe field extends outside of "
00159                 "the magnet aperture only in a region extending the "
00160                 "aperture in x and y. As the fringe field is first order "
00161                 "only, it is slightly non-Maxwellian.\n\n"
00162                 "By default, the aperture is filled with a box volume "
00163                 "of the fieldMaterial; this prevents placing any object "
00164                 "inside the aperture. With openAperture=1 no aperture volume "
00165                 "is used, and objects can be placed into the parent volume "
00166                 "that are inside the aperture.");
00167 
00168         // provide initial values for fields
00169         fieldWidth = 0.0;
00170         fieldHeight = 0.0;
00171         fieldLength = 0.0;
00172         ironWidth = 0.0;
00173         ironHeight = 0.0;
00174         ironLength = 0.0;
00175         By = 0.0;
00176         fieldMaterial = "Vacuum";
00177         fieldColor = "";
00178         ironMaterial = "Fe";
00179         ironColor = "1,1,1";
00180         kill = 0;
00181         maxStep = -1.0;
00182         fringe = "";
00183         fringeFactor = 1.0;
00184         openAperture = 0;
00185         fieldBox = 0;
00186         ironBox = 0;
00187         ironSolid = 0;
00188 }

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

Destructor.

00075 { }

BLCMDgenericbend::BLCMDgenericbend ( const BLCMDgenericbend r  ) 

Copy constructor.

References By, BLTune::copyTunableArg(), fieldBox, fieldColor, fieldHeight, fieldLength, fieldMaterial, fieldWidth, fringe, fringeFactor, ironBox, ironColor, ironHeight, ironLength, ironMaterial, ironSolid, ironWidth, kill, maxStep, and openAperture.

00191                                                             : BLGroupElement(r)
00192 {
00193         // copy fields one at a time (transfers default values from the
00194         // default object to this new object).
00195         fieldWidth = r.fieldWidth;
00196         fieldHeight = r.fieldHeight;
00197         fieldLength = r.fieldLength;
00198         ironWidth = r.ironWidth;
00199         ironHeight = r.ironHeight;
00200         ironLength = r.ironLength;
00201         BLTune::copyTunableArg(&By,&r.By);
00202         fieldMaterial = r.fieldMaterial;
00203         fieldColor = r.fieldColor;
00204         ironMaterial = r.ironMaterial;
00205         ironColor = r.ironColor;
00206         kill = r.kill;
00207         maxStep = r.maxStep;
00208         fringe = r.fringe;
00209         fringeFactor = r.fringeFactor;
00210         openAperture = r.openAperture;
00211         fieldBox = r.fieldBox;
00212         ironBox = r.ironBox;
00213         ironSolid = r.ironSolid;
00214 }


Member Function Documentation

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

clone()

Implements BLElement.

References BLCMDgenericbend().

00081 { return new BLCMDgenericbend(*this); }

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

commandName() returns "genericbend".

Implements BLCommand.

00084 { return "genericbend"; }

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

command() implements the genericbend command.

Implements BLCommand.

References BLCMDgenericbend(), fieldMaterial, BLParam::getDouble(), BLCommand::getMaterial(), BLCommand::handleNamedArgs(), ironMaterial, maxStep, Param, BLCommand::print(), BLCommand::printError(), and BLGroupElement::setName().

00217 {
00218         if(argv.size() != 1) {
00219                 printError("genericbend: Invalid command, must have name");
00220                 return -1;
00221         }
00222 
00223         if(argv[0] == "default") {
00224                 return defaultGenericBend.handleNamedArgs(namedArgs);
00225         }
00226 
00227         BLCMDgenericbend *t = new BLCMDgenericbend(defaultGenericBend);
00228         t->setName(argv[0]);
00229         int retval = t->handleNamedArgs(namedArgs);
00230 
00231         if(t->maxStep < 0.0) t->maxStep = Param.getDouble("maxStep");
00232 
00233         // check material exists
00234         getMaterial(t->fieldMaterial,false);
00235         getMaterial(t->ironMaterial,false);
00236 
00237         t->print(argv[0]);
00238 
00239         return retval;
00240 }

void BLCMDgenericbend::defineNamedArgs (  )  [virtual]

defineNamedArgs() defines the named arguments for the command.

Reimplemented from BLCommand.

References BLCommand::argDouble(), BLCommand::argInt(), BLCommand::argString(), BLCommand::argTunable(), By, fieldColor, fieldHeight, fieldLength, fieldMaterial, fieldWidth, fringe, fringeFactor, ironColor, ironHeight, ironLength, ironMaterial, ironWidth, kill, maxStep, and openAperture.

00243 {
00244         argDouble(fieldWidth,"fieldWidth","The width of the field region (mm)");
00245         argDouble(fieldHeight,"fieldHeight","The height of the field region (mm)");
00246         argDouble(fieldLength,"fieldLength","The length of the field region (mm)");
00247         argDouble(ironWidth,"ironWidth","The width of the iron region (mm)");
00248         argDouble(ironHeight,"ironHeight","The height of the iron region (mm)");
00249         argDouble(ironLength,"ironLength","The length of the iron region (mm)");
00250         argTunable(By,"By","The magnetic field (Tesla)",tesla);
00251         argDouble(maxStep,"maxStep","The maximum stepsize in the element (mm)");
00252         argString(fieldMaterial,"fieldMaterial","The material of the field region.");
00253         argString(fieldColor,"fieldColor","The color of the field region.");
00254         argString(ironMaterial,"ironMaterial","The material of the iron region.");
00255         argString(ironColor,"ironColor","The color of the iron region.");
00256         argInt(kill,"kill","Set nonzero to kill particles hitting the iron.");
00257         argString(fringe,"fringe","Fringe field computation, set to 0 to disable,"
00258                 " or a comma-separated list of 6 Enge function parameters.");
00259         argDouble(fringeFactor,"fringeFactor","Fringe depth factor (1.0).");
00260         argInt(openAperture,"openAperture","Set nonzero to omit the aperture volume.",false);
00261 }

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

construct() - construct the generic bending magnet

Implements BLElement.

References BLGlobalField::addElementField(), BLGroupElement::constructChildren(), fieldBox, fieldColor, fieldHeight, fieldMaterial, fieldWidth, GenericBendField, BLParam::getDouble(), getLength(), BLCommand::getMaterial(), BLElement::getName(), BLGroupElement::getNChildren(), BLGlobalField::getObject(), BLManager::getObject(), BLCommand::getVisAttrib(), ironBox, ironColor, ironHeight, ironLength, ironMaterial, ironSolid, ironWidth, kill, maxStep, openAperture, Param, and BLCommand::printError().

00270 {
00271         G4String thisname = parentName+getName();
00272 
00273         if(!fieldBox)
00274                 fieldBox = new G4Box(thisname+"GenericBendField",
00275                                         fieldWidth/2.0, fieldHeight/2.0,
00276                                         ironLength/2.0+0.1);
00277         G4LogicalVolume *lvfield=0;
00278         if(!openAperture) {
00279             G4Material *mat = getMaterial(fieldMaterial);
00280             lvfield = new G4LogicalVolume(fieldBox,mat,
00281                                         thisname+"LogVol");
00282             lvfield->SetVisAttributes(getVisAttrib(fieldColor));
00283             if(maxStep <= 0.0) maxStep = Param.getDouble("maxStep");
00284             lvfield->SetUserLimits(new G4UserLimits(maxStep));
00285         }
00286 
00287         if(!ironBox)
00288                 ironBox = new G4Box(thisname+"GenericBendIron",
00289                                         ironWidth/2.0, ironHeight/2.0,
00290                                         ironLength/2.0);
00291         if(!ironSolid)
00292                 ironSolid = new G4SubtractionSolid(thisname+"GenericBendSolid",
00293                                         ironBox, fieldBox);
00294         G4Material *mat = getMaterial(ironMaterial);
00295         G4LogicalVolume *lviron = new G4LogicalVolume(ironSolid,mat,
00296                                         thisname+"LogVol");
00297         lviron->SetVisAttributes(getVisAttrib(ironColor));
00298         lviron->SetUserLimits(new G4UserLimits(maxStep));
00299 
00300         // geant4 rotation convention is backwards from g4beamline
00301         G4RotationMatrix *g4rot = 0;
00302         if(relativeRotation)
00303                 g4rot = new G4RotationMatrix(relativeRotation->inverse());
00304 
00305         if(lvfield)
00306                 new G4PVPlacement(g4rot,relativePosition,lvfield,thisname,
00307                                         parent,false,0);
00308         G4PVPlacement *pv = new G4PVPlacement(g4rot,relativePosition,lviron,
00309                                         thisname, parent,false,0);
00310 
00311         if(kill)
00312                 BLManager::getObject()->
00313                         registerSteppingAction(pv,new BLKillTrack(thisname));
00314 
00315         // get globalRotation and globalPosition
00316         G4RotationMatrix *globalRotation = 0;
00317         if(relativeRotation && parentRotation) {
00318                 globalRotation = 
00319                     new G4RotationMatrix(*parentRotation * *relativeRotation);
00320         } else if(relativeRotation) {
00321                 globalRotation = relativeRotation;
00322         } else if(parentRotation) {
00323                 globalRotation = parentRotation;
00324         }
00325         G4ThreeVector globalPosition(relativePosition + parentPosition);
00326         if(parentRotation)
00327                 globalPosition = *parentRotation * relativePosition +
00328                                 parentPosition;
00329 
00330         BLCoordinateTransform global2local(globalRotation,globalPosition);
00331 
00332         G4double zmin = globalPosition[2]-getLength()/2.0;
00333         G4double zmax = globalPosition[2]+getLength()/2.0;
00334 
00335         GenericBendField *p = new GenericBendField(global2local,this);
00336         BLGlobalField::getObject()->addElementField(p);
00337 
00338         if(lvfield != 0) {
00339                 constructChildren(lvfield,getName(),globalRotation,globalPosition);
00340         } else if(getNChildren() != 0) {
00341                 printError("genericbend: cannot be a parent with openAperture=1");
00342         }
00343 
00344         printf("BLCMDgenericbend::Construct %s parent=%s relZ=%.1f globZ=%.1f\n"
00345                         "\tzmin=%.1f zmax=%.1f\n",
00346                 thisname.c_str(),parentName.c_str(),relativePosition[2],
00347                 globalPosition[2], zmin,zmax);
00348 }

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

getLength() returns the length of the iron region

Implements BLElement.

References ironLength.

Referenced by construct().

00101 { return ironLength; }

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

getWidth() returns the width of the iron region

Implements BLElement.

References ironWidth.

00104 { return ironWidth; }

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

getHeight() returns the height of the iron region

Implements BLElement.

References ironHeight.

00107 { return ironHeight; }

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

isOK() returns true.

Implements BLElement.

References BLGroupElement::getNChildren(), and openAperture.

00110 { return openAperture==0 || getNChildren()==0; }

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

isOutside() from BLElement.

Implements BLElement.

References fieldHeight, fieldWidth, ironHeight, ironLength, ironWidth, and openAperture.

00453 {
00454         if(openAperture)
00455                 return fabs(local[0]) > ironWidth/2.0-tolerance ||
00456                         fabs(local[1]) > ironHeight/2.0-tolerance ||
00457                         fabs(local[2]) > ironLength/2.0-tolerance ||
00458                         fabs(local[0]) < fieldWidth/2.0+tolerance ||
00459                         fabs(local[1]) < fieldHeight/2.0+tolerance;
00460         return fabs(local[0]) > ironWidth/2.0-tolerance ||
00461                 fabs(local[1]) > ironHeight/2.0-tolerance ||
00462                 fabs(local[2]) > ironLength/2.0-tolerance;
00463 }

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

generatePoints() from BLElement.

Implements BLElement.

References fieldHeight, fieldLength, fieldWidth, BLElement::generateBox(), ironHeight, ironLength, ironWidth, openAperture, and rand.

00466 {
00467         if(openAperture) {
00468                 // last two points are 0,0,l and 0,0,-l.
00469                 generateBox(0,ironWidth,ironHeight,ironLength,v);
00470                 v.erase(v.end());
00471                 v.erase(v.end());
00472                 G4double w=fieldWidth/2.0, h=fieldHeight/2.0, l=fieldLength/2.0;
00473                 // the 8 inside corners
00474                 v.push_back(G4ThreeVector(w,h,l));
00475                 v.push_back(G4ThreeVector(w,h,-l));
00476                 v.push_back(G4ThreeVector(w,-h,l));
00477                 v.push_back(G4ThreeVector(w,-h,-l));
00478                 v.push_back(G4ThreeVector(-w,h,l));
00479                 v.push_back(G4ThreeVector(-w,h,-l));
00480                 v.push_back(G4ThreeVector(-w,-h,l));
00481                 v.push_back(G4ThreeVector(-w,-h,-l));
00482                 // the 12 inside edge midpoints
00483                 v.push_back(G4ThreeVector(0,h,l));
00484                 v.push_back(G4ThreeVector(0,h,-l));
00485                 v.push_back(G4ThreeVector(0,-h,l));
00486                 v.push_back(G4ThreeVector(0,-h,-l));
00487                 v.push_back(G4ThreeVector(w,0,l));
00488                 v.push_back(G4ThreeVector(w,0,-l));
00489                 v.push_back(G4ThreeVector(-w,0,l));
00490                 v.push_back(G4ThreeVector(-w,0,-l));
00491                 v.push_back(G4ThreeVector(w,h,0));
00492                 v.push_back(G4ThreeVector(w,-h,0));
00493                 v.push_back(G4ThreeVector(-w,h,0));
00494                 v.push_back(G4ThreeVector(-w,-h,0));
00495                 // the 4 inside face centers
00496                 v.push_back(G4ThreeVector(w,0,0));
00497                 v.push_back(G4ThreeVector(-w,0,0));
00498                 v.push_back(G4ThreeVector(0,h,0));
00499                 v.push_back(G4ThreeVector(0,-h,0));
00500                 // random points on the surfaces
00501                 G4double wi=ironWidth/2.0, hi=ironHeight/2.0, li=ironLength/2.0;
00502                 while(v.size() < (unsigned)npoints) {
00503 again:                  G4double x=0,y=0,z=0;
00504                         switch(v.size() % 10) {
00505                         case 0: x=wi;
00506                                 y=rand()*ironHeight-hi;
00507                                 z=rand()*ironLength-li;
00508                                 break;
00509                         case 1: x=-wi;
00510                                 y=rand()*ironHeight-hi;
00511                                 z=rand()*ironLength-li;
00512                                 break;
00513                         case 2: x=rand()*ironWidth-wi;
00514                                 y=hi;
00515                                 z=rand()*ironLength-li;
00516                                 break;
00517                         case 3: x=rand()*ironWidth-wi;
00518                                 y=-hi;
00519                                 z=rand()*ironLength-li;
00520                                 break;
00521                         case 4: x=rand()*ironWidth-wi;
00522                                 y=rand()*ironHeight-hi;
00523                                 z=li;
00524                                 goto check;
00525                         case 5: x=rand()*ironWidth-w;
00526                                 y=rand()*ironHeight-hi;
00527                                 z=-li;
00528 check:                          if(w < wi-10.0*mm && h < hi-10.0*mm && 
00529                                    (fabs(x) < w && fabs(y) < h)) goto again;
00530                                 break;
00531                         case 6: x=w;
00532                                 y=rand()*fieldHeight-h;
00533                                 z=rand()*ironLength-li;
00534                                 break;
00535                         case 7: x=-w;
00536                                 y=rand()*fieldHeight-h;
00537                                 z=rand()*ironLength-li;
00538                                 break;
00539                         case 8: x=rand()*fieldWidth-w;
00540                                 y=h;
00541                                 z=rand()*ironLength-li;
00542                                 break;
00543                         case 9: x=rand()*fieldWidth-w;
00544                                 y=-h;
00545                                 z=rand()*ironLength-li;
00546                                 break;
00547                         }
00548                         v.push_back(G4ThreeVector(x,y,z));
00549                 }
00550         } else {
00551                 generateBox(npoints,ironWidth,ironHeight,ironLength,v);
00552         }
00553 }

G4bool BLCMDgenericbend::isWithin ( G4ThreeVector &  local,
G4double  tolerance 
) [virtual]

isWithin() from BLGroupElement.

Implements BLGroupElement.

References fieldHeight, fieldWidth, ironHeight, ironLength, ironWidth, and openAperture.

00556 {
00557         if(openAperture)
00558                 return fabs(local[0]) < ironWidth/2.0+tolerance &&
00559                         fabs(local[1]) < ironHeight/2.0+tolerance &&
00560                         fabs(local[2]) < ironLength/2.0+tolerance &&
00561                         fabs(local[0]) > fieldWidth/2.0-tolerance &&
00562                         fabs(local[1]) > fieldHeight/2.0-tolerance;
00563         return fabs(local[0]) < ironWidth/2.0+tolerance &&
00564                 fabs(local[1]) < ironHeight/2.0+tolerance &&
00565                 fabs(local[2]) < ironLength/2.0+tolerance;
00566 }


Friends And Related Function Documentation

friend class GenericBendField [friend]

Referenced by construct().


Member Data Documentation

G4double BLCMDgenericbend::fieldWidth [private]

G4double BLCMDgenericbend::fieldHeight [private]

G4double BLCMDgenericbend::fieldLength [private]

G4double BLCMDgenericbend::ironWidth [private]

G4double BLCMDgenericbend::ironHeight [private]

G4double BLCMDgenericbend::ironLength [private]

G4double BLCMDgenericbend::By [private]

G4String BLCMDgenericbend::fieldMaterial [private]

G4String BLCMDgenericbend::fieldColor [private]

G4String BLCMDgenericbend::ironMaterial [private]

G4String BLCMDgenericbend::ironColor [private]

G4int BLCMDgenericbend::kill [private]

G4double BLCMDgenericbend::maxStep [private]

G4String BLCMDgenericbend::fringe [private]

G4double BLCMDgenericbend::fringeFactor [private]

G4Box* BLCMDgenericbend::fieldBox [private]

Referenced by BLCMDgenericbend(), and construct().

G4Box* BLCMDgenericbend::ironBox [private]

Referenced by BLCMDgenericbend(), and construct().

G4VSolid* BLCMDgenericbend::ironSolid [private]

Referenced by BLCMDgenericbend(), and construct().


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