00001
00002
00003
00004
00005
00006 #include <fstream>
00007 #include <string.h>
00008 #include <ctype.h>
00009 #include <assert.h>
00010
00011 #include "G4Tubs.hh"
00012 #include "G4Box.hh"
00013
00014 #include "G4ElectroMagneticField.hh"
00015 #include "MyFieldMap.hh"
00016
00017 MyFieldMap::MyFieldMap(G4String mapFileName, G4double current,
00018 G4double gradient, G4double timeOffset, G4LogicalVolume* fieldVolume)
00019 : MyElementField(G4ThreeVector(0,0,0),fieldVolume) {
00020
00021
00022
00023
00024 fMap = new MyBLFieldMap();
00025 fMap->readFile(mapFileName);
00026 fCurrent = current;
00027 fGradient = gradient;
00028 fRotation = NULL;
00029
00030
00031 fTimeOffset = timeOffset;
00032
00033
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 }
00046
00047
00048 MyFieldMap::~MyFieldMap() {
00049 delete fRotation;
00050 delete fMap;
00051 }
00052
00053
00054 void MyFieldMap::addFieldValue(const G4double point[4], G4double field[6]) const {
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 }
00094
00095
00096 void MyFieldMap::setRot(G4RotationMatrix * aRotMat) {
00097
00098 fRotation = new G4RotationMatrix(aRotMat->inverse());
00099 }