MyFieldMap Class Reference

#include <MyFieldMap.hh>

Inheritance diagram for MyFieldMap:
MyElementField

List of all members.

Public Member Functions

 MyFieldMap (G4String fieldMapFile, G4double current, G4double gradient, G4double timeOffset, G4LogicalVolume *fieldVolume)
 ~MyFieldMap ()
void addFieldValue (const G4double point[4], G4double field[6]) const
void setRot (G4RotationMatrix *aRotMat)
virtual G4double getMaxLength ()
 return the length used for the bounding box
virtual G4double getMaxWidth ()
 return the width used for the bounding box
virtual G4double getMaxHeight ()
 return the height used for the bounding box
void construct ()
 the actual implementation constructs the MyElementField
G4ThreeVector getCenter ()
void setCenter (G4ThreeVector)
G4double const * getBoundingBox ()
void setMaxStep (G4double s)
 setMaxStep(G4double) sets the max. step size
G4double getMaxStep ()
 getMaxStep() returns the max. step size
void setColor (G4String c)
 setColor(G4String) sets the color
G4String getColor ()
 getColor() returns the color
void setGlobalPoint (const G4double point[4])
bool isInBoundingBox (const G4double point[4]) const

Static Public Member Functions

static G4VisAttributes * getVisAttribute (G4String color)
 getVisAttribute() returns the appropriate G4VisAttributes.

Protected Attributes

G4LogicalVolume * lvolume
G4AffineTransform global2local

Private Attributes

G4RotationMatrix * fRotation
G4double fCurrent
G4double fGradient
G4double fTimeOffset
MyBLFieldMapfMap
G4double fMaxLength
G4double fMaxWidth
G4double fMaxHeight

Detailed Description

Definition at line 13 of file MyFieldMap.hh.


Constructor & Destructor Documentation

MyFieldMap::MyFieldMap ( G4String  fieldMapFile,
G4double  current,
G4double  gradient,
G4double  timeOffset,
G4LogicalVolume *  fieldVolume 
)

Definition at line 17 of file MyFieldMap.cc.

References fCurrent, fGradient, fMap, fMaxHeight, fMaxLength, fMaxWidth, fRotation, fTimeOffset, and MyBLFieldMap::readFile().

00019 : MyElementField(G4ThreeVector(0,0,0),fieldVolume) {
00020     // This constructor must be called after creating the logical
00021     // field volume and before defining any detectors in the field
00022     // volume.
00023 
00024     fMap = new MyBLFieldMap();
00025     fMap->readFile(mapFileName);
00026     fCurrent = current;
00027     fGradient = gradient;
00028     fRotation = NULL;
00029 
00030     // AK20110616: timeOffset doesn't appear to be used for anything
00031     fTimeOffset = timeOffset;
00032 
00033     // Set dimensions
00034     if (fieldVolume->GetSolid()->GetEntityType() == "G4Tubs") {
00035         fMaxLength = 2*((G4Tubs*)fieldVolume->GetSolid())->GetZHalfLength();
00036         fMaxWidth = 2*((G4Tubs*)fieldVolume->GetSolid())->GetOuterRadius();
00037         fMaxHeight = fMaxWidth;
00038     }
00039     else if (fieldVolume->GetSolid()->GetEntityType()== "G4Box") {
00040         fMaxLength = 2*((G4Box*)fieldVolume->GetSolid())->GetZHalfLength();
00041         fMaxWidth = 2*((G4Box*)fieldVolume->GetSolid())->GetXHalfLength();
00042         fMaxHeight = 2*((G4Box*)fieldVolume->GetSolid())->GetYHalfLength();
00043     }
00044 
00045 }

MyFieldMap::~MyFieldMap (  ) 

Definition at line 48 of file MyFieldMap.cc.

References fMap, and fRotation.

00048                         {
00049     delete fRotation;
00050     delete fMap;
00051 }


Member Function Documentation

void MyFieldMap::addFieldValue ( const G4double  point[4],
G4double  field[6] 
) const [virtual]

addFieldValue() will add the field value for this element to field[]. Implementations must be sure to verify that point[] is within the field region, and do nothing if not. point[] is in global coordinates and geant4 units; x,y,z,t. field[] is in geant4 units; Bx,By,Bz,Ex,Ey,Ez. For efficiency, the caller may (but need not) call isInBoundingBox(point), and only call this function if that returns true.

Implements MyElementField.

Definition at line 54 of file MyFieldMap.cc.

References fCurrent, fGradient, fMap, fRotation, MyBLFieldMap::getFieldValue(), MyElementField::global2local, MyBLFieldMap::hasB(), and MyBLFieldMap::hasE().

00054                                                                                {
00055     G4ThreeVector global(point[0],point[1],point[2]);
00056     G4ThreeVector local;
00057 
00058     local = global2local.TransformPoint(global);
00059 
00060     G4double relPoint[4]= {local[0],local[1],local[2],point[3]};
00061     G4double f[6];
00062     f[0] = f[1] = f[2] = f[3] = f[4] = f[5] = 0.0;
00063     fMap->getFieldValue(relPoint,f,fCurrent,fGradient);
00064 
00065     if(fRotation) {
00066         if (fMap->hasB()) {
00067             G4ThreeVector B(f[0],f[1],f[2]);
00068             B = *fRotation * B;
00069             field[0] += B[0];
00070             field[1] += B[1];
00071             field[2] += B[2];
00072         }
00073         if (fMap->hasE()) {
00074             G4ThreeVector E(f[3],f[4],f[5]);
00075             E = *fRotation * E;
00076             field[3] += E[0];
00077             field[4] += E[1];
00078             field[5] += E[2];
00079         }
00080     }
00081     else {
00082         if (fMap->hasB()) {
00083             field[0] += f[0];
00084             field[1] += f[1];
00085             field[2] += f[2];
00086         }
00087         if (fMap->hasE()) {
00088             field[3] += f[3];
00089             field[4] += f[4];
00090             field[5] += f[5];
00091         }
00092     }
00093 }

void MyElementField::construct (  )  [inherited]

the actual implementation constructs the MyElementField

Definition at line 74 of file MyElementField.cc.

References MyElementField::aNavigator, MyElementField::center, MyElementField::getMaxHeight(), MyElementField::getMaxLength(), MyElementField::getMaxWidth(), MyElementField::global2local, MyElementField::lvolume, and MyElementField::setGlobalPoint().

00074                                {
00075     G4Navigator* theNavigator =
00076         G4TransportationManager::GetTransportationManager()->
00077         GetNavigatorForTracking();
00078 
00079 //    G4cout << "-AK- In MyElementField::construct, lvolume is "
00080 //        << lvolume->GetName() << G4endl;
00081 
00082     if (!aNavigator) {
00083         aNavigator = new G4Navigator();
00084         if ( theNavigator->GetWorldVolume() )
00085             aNavigator->SetWorldVolume(theNavigator->GetWorldVolume());
00086     }
00087 
00088     G4GeometryManager* geomManager = G4GeometryManager::GetInstance();
00089 
00090     if (!geomManager->IsGeometryClosed()) {
00091         geomManager->OpenGeometry();
00092         geomManager->CloseGeometry(true);
00093     }
00094 
00095     aNavigator->LocateGlobalPointAndSetup(center,0,false);
00096 //    G4cout << "-AK- MyElementField::construct, center is " << center << G4endl;
00097 
00098     G4TouchableHistoryHandle fTouchable = aNavigator->
00099         CreateTouchableHistoryHandle();
00100 
00101     G4int depth = fTouchable->GetHistoryDepth();
00102 //    G4cout << "-AK- fTouchable->GetHistoryDepth is " << depth << G4endl;
00103 
00104     for (G4int i = 0; i<depth; ++i) {
00105 //        G4cout << "-AK- In MyElementField::construct, volume is "
00106  //           << fTouchable->GetVolume()->GetLogicalVolume()->GetName() << G4endl;
00107         if(fTouchable->GetVolume()->GetLogicalVolume() == lvolume) {
00108 //            G4cout << "-AK- In MyElementField::construct, found lvolume "
00109 //                << lvolume->GetName() << G4endl;
00110             break;
00111         }
00112 
00113         fTouchable->MoveUpHistory();
00114     }
00115 
00116     // set global2local transform
00117     global2local = fTouchable->GetHistory()->GetTopTransform();
00118 
00119     // set global bounding box
00120     G4double local[4], global[4];
00121 
00122     G4ThreeVector globalPosition;
00123     local[3] = 0.0;
00124     for (int i=0; i<2; ++i) {
00125         local[0] = (i==0 ? -1.0 : 1.0) * getMaxWidth()/2.;
00126         for (int j=0; j<2; ++j) {
00127             local[1] = (j==0 ? -1.0 : 1.0) * getMaxHeight()/2.;
00128             for (int k=0; k<2; ++k) {
00129                 local[2] = (k==0 ? -1.0 : 1.0) * getMaxLength()/2.;
00130                 G4ThreeVector localPosition(local[0],local[1],local[2]);
00131                 globalPosition =
00132                     global2local.Inverse().TransformPoint(localPosition);
00133                 global[0] = globalPosition.x();
00134                 global[1] = globalPosition.y();
00135                 global[2] = globalPosition.z();
00136                 setGlobalPoint(global);
00137                 //G4cout << "-AK- MyElementField::construct, bounding box global pos is"
00138                 //     << globalPosition << G4endl;
00139             }
00140         }
00141     }
00142 }

G4double const * MyElementField::getBoundingBox (  )  [inherited]

Definition at line 165 of file MyElementField.cc.

References MyElementField::boundingBox, MyElementField::maxX, MyElementField::maxY, MyElementField::maxZ, MyElementField::minX, MyElementField::minY, and MyElementField::minZ.

00165                                                 {
00166     if(boundingBox==NULL) {
00167         boundingBox= new G4double[6];
00168     }
00169     boundingBox[0] = minX;
00170     boundingBox[1] = maxX;
00171     boundingBox[2] = minY;
00172     boundingBox[3] = maxY;
00173     boundingBox[4] = minZ;
00174     boundingBox[5] = maxZ;
00175     return boundingBox;
00176 }

G4ThreeVector MyElementField::getCenter (  )  [inline, inherited]

Definition at line 75 of file MyElementField.hh.

References MyElementField::center.

00075 {return center;}

G4String MyElementField::getColor (  )  [inline, inherited]

getColor() returns the color

Definition at line 100 of file MyElementField.hh.

References MyElementField::color.

00100 { return color; }

virtual G4double MyFieldMap::getMaxHeight (  )  [inline, virtual]

return the height used for the bounding box

Implements MyElementField.

Definition at line 36 of file MyFieldMap.hh.

References fMaxHeight.

00036 { return fMaxHeight; }

virtual G4double MyFieldMap::getMaxLength (  )  [inline, virtual]

return the length used for the bounding box

Implements MyElementField.

Definition at line 30 of file MyFieldMap.hh.

References fMaxLength.

00030 { return fMaxLength; }

G4double MyElementField::getMaxStep (  )  [inline, inherited]

getMaxStep() returns the max. step size

Definition at line 91 of file MyElementField.hh.

References MyElementField::maxStep.

00091 { return maxStep; }

virtual G4double MyFieldMap::getMaxWidth (  )  [inline, virtual]

return the width used for the bounding box

Implements MyElementField.

Definition at line 33 of file MyFieldMap.hh.

References fMaxWidth.

00033 { return fMaxWidth; }

G4VisAttributes * MyElementField::getVisAttribute ( G4String  color  )  [static, inherited]

getVisAttribute() returns the appropriate G4VisAttributes.

Definition at line 145 of file MyElementField.cc.

Referenced by MyElementField::setColor().

00145                                                                {
00146     G4VisAttributes* p = NULL;
00147     if(color.size() > 0 &&
00148     (isdigit(color.c_str()[0]) || color.c_str()[0] == '.')) {
00149         G4double red=0.0, green=0.0, blue=0.0;
00150         if (sscanf(color.c_str(),"%lf,%lf,%lf",&red,&green,&blue) == 3) {
00151             p = new G4VisAttributes(true,G4Color(red,green,blue));
00152         }
00153         else {
00154             G4cout << " Invalid color " << color << G4endl;
00155         }
00156     }
00157 
00158     if (!p) p = new G4VisAttributes(G4VisAttributes::Invisible);
00159     p->SetDaughtersInvisible(false);
00160 
00161     return p;
00162 }

bool MyElementField::isInBoundingBox ( const G4double  point[4]  )  const [inline, inherited]

isInBoundingBox() returns true if the point is within the global bounding box - global coordinates.

Definition at line 122 of file MyElementField.hh.

References MyElementField::maxX, MyElementField::maxY, MyElementField::maxZ, MyElementField::minX, MyElementField::minY, and MyElementField::minZ.

Referenced by MyGlobalField::GetFieldValue().

00122                                                             {
00123             if(point[2] < minZ || point[2] > maxZ) return false;
00124             if(point[0] < minX || point[0] > maxX) return false;
00125             if(point[1] < minY || point[1] > maxY) return false;
00126             return true;
00127         }

void MyElementField::setCenter ( G4ThreeVector  c  )  [inherited]

Definition at line 179 of file MyElementField.cc.

References MyElementField::center.

00179                                               {
00180     center = c;
00181 }

void MyElementField::setColor ( G4String  c  )  [inline, inherited]

setColor(G4String) sets the color

Definition at line 94 of file MyElementField.hh.

References MyElementField::color, MyElementField::getVisAttribute(), and MyElementField::lvolume.

00094                                   {
00095             color = c;
00096             lvolume->SetVisAttributes(getVisAttribute(color));
00097         }

void MyElementField::setGlobalPoint ( const G4double  point[4]  )  [inline, inherited]

setGlobalPoint() ensures that the point is within the global bounding box of this ElementField's global coordinates. Normally called 8 times for the corners of the local bounding box, after a local->global coordinate transform. If never called, the global bounding box is infinite. BEWARE: if called only once, the bounding box is just a point.

Definition at line 111 of file MyElementField.hh.

References MyElementField::maxX, MyElementField::maxY, MyElementField::maxZ, MyElementField::minX, MyElementField::minY, and MyElementField::minZ.

Referenced by MyElementField::construct().

00111                                                      {
00112             if(minX == -DBL_MAX || minX > point[0]) minX = point[0];
00113             if(minY == -DBL_MAX || minY > point[1]) minY = point[1];
00114             if(minZ == -DBL_MAX || minZ > point[2]) minZ = point[2];
00115             if(maxX ==  DBL_MAX || maxX < point[0]) maxX = point[0];
00116             if(maxY ==  DBL_MAX || maxY < point[1]) maxY = point[1];
00117             if(maxZ ==  DBL_MAX || maxZ < point[2]) maxZ = point[2];
00118         }

void MyElementField::setMaxStep ( G4double  s  )  [inline, inherited]

setMaxStep(G4double) sets the max. step size

Definition at line 84 of file MyElementField.hh.

References MyElementField::lvolume, MyElementField::maxStep, and MyElementField::userLimits.

00084                                     {
00085             maxStep = s;
00086             userLimits->SetMaxAllowedStep(maxStep);
00087             lvolume->SetUserLimits(userLimits);
00088         }

void MyFieldMap::setRot ( G4RotationMatrix *  aRotMat  ) 

Definition at line 96 of file MyFieldMap.cc.

References fRotation.

00096                                                   {
00097     // aRotMat is the rotation matrix used when placing a physical object
00098     fRotation = new G4RotationMatrix(aRotMat->inverse());
00099 }


Member Data Documentation

G4double MyFieldMap::fCurrent [private]

Definition at line 40 of file MyFieldMap.hh.

Referenced by addFieldValue(), and MyFieldMap().

G4double MyFieldMap::fGradient [private]

Definition at line 41 of file MyFieldMap.hh.

Referenced by addFieldValue(), and MyFieldMap().

Definition at line 43 of file MyFieldMap.hh.

Referenced by addFieldValue(), MyFieldMap(), and ~MyFieldMap().

G4double MyFieldMap::fMaxHeight [private]

Definition at line 47 of file MyFieldMap.hh.

Referenced by getMaxHeight(), and MyFieldMap().

G4double MyFieldMap::fMaxLength [private]

Definition at line 45 of file MyFieldMap.hh.

Referenced by getMaxLength(), and MyFieldMap().

G4double MyFieldMap::fMaxWidth [private]

Definition at line 46 of file MyFieldMap.hh.

Referenced by getMaxWidth(), and MyFieldMap().

G4RotationMatrix* MyFieldMap::fRotation [private]

Definition at line 39 of file MyFieldMap.hh.

Referenced by addFieldValue(), MyFieldMap(), setRot(), and ~MyFieldMap().

G4double MyFieldMap::fTimeOffset [private]

Definition at line 42 of file MyFieldMap.hh.

Referenced by MyFieldMap().

G4AffineTransform MyElementField::global2local [protected, inherited]

Definition at line 149 of file MyElementField.hh.

Referenced by addFieldValue(), and MyElementField::construct().

G4LogicalVolume* MyElementField::lvolume [protected, inherited]

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

Generated on 15 Jun 2016 for g4sim by  doxygen 1.6.1