#include <MagneticField/Interpolation/src/MagneticFieldGrid.h>
Public Member Functions | |
int | gridType () |
returns value of GridType (and eventually prints the type + short description) | |
void | interpolateAtPoint (double X1, double X2, double X3, float &Bx, float &By, float &Bz) |
interpolates the magnetic field at input coordinate point and returns field values | |
int | lineNumber (int Index1, int Index2, int Index3) |
void | load (const std::string &name) |
load grid binary file | |
MagneticFieldGrid () | |
void | putCoordGetInd (double X1, double X2, double X3, int &Index1, int &Index2, int &Index3) |
void | putIndGetCoord (int Index1, int Index2, int Index3, double &X1, double &X2, double &X3) |
void | putIndicesGetB (int Index1, int Index2, int Index3, float &Bx, float &By, float &Bz) |
~MagneticFieldGrid () | |
Private Attributes | |
double | BasicDistance0 [3] |
double | BasicDistance1 [3][3] |
double | BasicDistance2 [3][3] |
bool | EasyCoordinate [3] |
std::vector< BVector > | FieldValues |
int | GridType |
int | NumberOfPoints [3] |
double | ReferencePoint [3] |
double | RParAsFunOfPhi [4] |
Classes | |
class | BVector |
class | HeaderType3 |
additional functions either translate indices <-> coordinates, transfer data, or activate the interpolation between grid points
Modifications:
Definition at line 32 of file MagneticFieldGrid.h.
MagneticFieldGrid::MagneticFieldGrid | ( | ) | [inline] |
Definition at line 35 of file MagneticFieldGrid.h.
References BasicDistance0, BasicDistance1, BasicDistance2, EasyCoordinate, GridType, i, j, NumberOfPoints, ReferencePoint, and RParAsFunOfPhi.
00035 { 00036 GridType = 0; 00037 for (int i=0;i<3; ++i) {NumberOfPoints[i] = 0;}; 00038 for (int i=0;i<3; ++i) {ReferencePoint[i] = 0.;}; 00039 for (int i=0;i<3; ++i) {BasicDistance0[i] = 0.;}; 00040 for (int i=0;i<3; ++i) {for (int j=0;j<3; ++j) {BasicDistance1[i][j] = 0.;};}; 00041 for (int i=0;i<3; ++i) {for (int j=0;j<3; ++j) {BasicDistance2[i][j] = 0.;};}; 00042 for (int i=0;i<4; ++i) {RParAsFunOfPhi[i] = 0.;}; 00043 for (int i=0;i<3; ++i) {EasyCoordinate[i] = false;}; 00044 }
MagneticFieldGrid::~MagneticFieldGrid | ( | ) | [inline] |
int MagneticFieldGrid::gridType | ( | ) |
returns value of GridType (and eventually prints the type + short description)
Definition at line 72 of file MagneticFieldGrid.cc.
References GenMuonPlsPt100GeV_cfg::cout, and lat::endl().
Referenced by GlobalGridWrapper::valueInTesla().
00072 { 00073 int type = GridType; 00074 bool text = false; 00075 if (text){ 00076 if (type == 0) cout << " grid type = " << type << " --> not determined" << endl; 00077 if (type == 1) cout << " grid type = " << type << " --> (x,y,z) cube" << endl; 00078 if (type == 2) cout << " grid type = " << type << " --> (x,y,z) trapezoid" << endl; 00079 if (type == 3) cout << " grid type = " << type << " --> (r,phi,z) cube" << endl; 00080 if (type == 4) cout << " grid type = " << type << " --> (r,phi,z) trapezoid" << endl; 00081 if (type == 5) cout << " grid type = " << type << " --> (r,phi,z) 1/sin(phi)" << endl; 00082 } 00083 return type; 00084 }
void MagneticFieldGrid::interpolateAtPoint | ( | double | X1, | |
double | X2, | |||
double | X3, | |||
float & | Bx, | |||
float & | By, | |||
float & | Bz | |||
) |
interpolates the magnetic field at input coordinate point and returns field values
Definition at line 86 of file MagneticFieldGrid.cc.
References VectorFieldInterpolation::defineCellPoint000(), VectorFieldInterpolation::defineCellPoint001(), VectorFieldInterpolation::defineCellPoint010(), VectorFieldInterpolation::defineCellPoint011(), VectorFieldInterpolation::defineCellPoint100(), VectorFieldInterpolation::defineCellPoint101(), VectorFieldInterpolation::defineCellPoint110(), VectorFieldInterpolation::defineCellPoint111(), i, index, max, putCoordGetInd(), putIndGetCoord(), putIndicesGetB(), and VectorFieldInterpolation::putSCoordGetVField().
Referenced by GlobalGridWrapper::valueInTesla().
00086 { 00087 double dB[3] = {0.,0.,0.}; 00088 // define interpolation object 00089 VectorFieldInterpolation MagInterpol; 00090 // calculate indices for "CellPoint000" 00091 int index[3]; 00092 putCoordGetInd(X1,X2,X3,index[0],index[1],index[2]); 00093 int index0[3] = {0,0,0}; 00094 int index1[3] = {0,0,0}; 00095 for (int i=0; i<3; ++i){ 00096 if (NumberOfPoints[i] > 1){ 00097 index0[i] = max(0,index[i]); 00098 if (index0[i] > NumberOfPoints[i]-2) index0[i] = NumberOfPoints[i]-2; 00099 index1[i] = max(1,index[i]+1); 00100 if (index1[i] > NumberOfPoints[i]-1) index1[i] = NumberOfPoints[i]-1; 00101 } 00102 } 00103 double tmpX[3]; 00104 float tmpB[3]; 00105 // define the corners of interpolation volume 00106 putIndicesGetB(index0[0],index0[1],index0[2],tmpB[0],tmpB[1],tmpB[2]); 00107 putIndGetCoord(index0[0],index0[1],index0[2],tmpX[0],tmpX[1],tmpX[2]); 00108 MagInterpol.defineCellPoint000(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2])); 00109 putIndicesGetB(index1[0],index0[1],index0[2],tmpB[0],tmpB[1],tmpB[2]); 00110 putIndGetCoord(index1[0],index0[1],index0[2],tmpX[0],tmpX[1],tmpX[2]); 00111 MagInterpol.defineCellPoint100(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2])); 00112 putIndicesGetB(index0[0],index1[1],index0[2],tmpB[0],tmpB[1],tmpB[2]); 00113 putIndGetCoord(index0[0],index1[1],index0[2],tmpX[0],tmpX[1],tmpX[2]); 00114 MagInterpol.defineCellPoint010(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2])); 00115 putIndicesGetB(index1[0],index1[1],index0[2],tmpB[0],tmpB[1],tmpB[2]); 00116 putIndGetCoord(index1[0],index1[1],index0[2],tmpX[0],tmpX[1],tmpX[2]); 00117 MagInterpol.defineCellPoint110(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2])); 00118 putIndicesGetB(index0[0],index0[1],index1[2],tmpB[0],tmpB[1],tmpB[2]); 00119 putIndGetCoord(index0[0],index0[1],index1[2],tmpX[0],tmpX[1],tmpX[2]); 00120 MagInterpol.defineCellPoint001(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2])); 00121 putIndicesGetB(index1[0],index0[1],index1[2],tmpB[0],tmpB[1],tmpB[2]); 00122 putIndGetCoord(index1[0],index0[1],index1[2],tmpX[0],tmpX[1],tmpX[2]); 00123 MagInterpol.defineCellPoint101(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2])); 00124 putIndicesGetB(index0[0],index1[1],index1[2],tmpB[0],tmpB[1],tmpB[2]); 00125 putIndGetCoord(index0[0],index1[1],index1[2],tmpX[0],tmpX[1],tmpX[2]); 00126 MagInterpol.defineCellPoint011(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2])); 00127 putIndicesGetB(index1[0],index1[1],index1[2],tmpB[0],tmpB[1],tmpB[2]); 00128 putIndGetCoord(index1[0],index1[1],index1[2],tmpX[0],tmpX[1],tmpX[2]); 00129 MagInterpol.defineCellPoint111(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2])); 00130 // interpolate 00131 MagInterpol.putSCoordGetVField(X1,X2,X3,dB[0],dB[1],dB[2]); 00132 Bx = float(dB[0]); 00133 By = float(dB[1]); 00134 Bz = float(dB[2]); 00135 return; 00136 }
Definition at line 275 of file MagneticFieldGrid.cc.
Referenced by putIndicesGetB().
00275 { 00276 return Index1*NumberOfPoints[1]*NumberOfPoints[2] + Index2*NumberOfPoints[2] + Index3; 00277 }
void MagneticFieldGrid::load | ( | const std::string & | name | ) |
load grid binary file
void MagneticFieldGrid::putCoordGetInd | ( | double | X1, | |
double | X2, | |||
double | X3, | |||
int & | Index1, | |||
int & | Index2, | |||
int & | Index3 | |||
) |
Definition at line 138 of file MagneticFieldGrid.cc.
References BasicDistance0, BasicDistance1, BasicDistance2, EasyCoordinate, i, index, int, j, offset, ReferencePoint, RParAsFunOfPhi, and funct::sin().
Referenced by interpolateAtPoint().
00138 { 00139 double pnt[3] = {X1,X2,X3}; 00140 int index[3]; 00141 switch (GridType){ 00142 case 1: 00143 for (int i=0; i<3; ++i){ 00144 index[i] = int((pnt[i]-ReferencePoint[i])/BasicDistance0[i]); 00145 } 00146 break; 00147 case 2: 00148 for (int i=0; i<3; ++i){ 00149 if (EasyCoordinate[i]){ 00150 index[i] = int((pnt[i]-ReferencePoint[i])/BasicDistance0[i]); 00151 } 00152 } 00153 for (int i=0; i<3; ++i){ 00154 if (!EasyCoordinate[i]){ 00155 double stepSize = BasicDistance0[i]; 00156 double offset = 0.0; 00157 for (int j=0; j<3; ++j){ 00158 stepSize += BasicDistance1[i][j]*index[j]; 00159 offset += BasicDistance2[i][j]*index[j]; 00160 } 00161 index[i] = int((pnt[i]-(ReferencePoint[i] + offset))/stepSize); 00162 } 00163 } 00164 break; 00165 case 3: 00166 for (int i=0; i<3; ++i){ 00167 index[i] = int((pnt[i]-ReferencePoint[i])/BasicDistance0[i]); 00168 } 00169 break; 00170 case 4: 00171 for (int i=0; i<3; ++i){ 00172 if (EasyCoordinate[i]){ 00173 index[i] = int((pnt[i]-ReferencePoint[i])/BasicDistance0[i]); 00174 } 00175 } 00176 for (int i=0; i<3; ++i){ 00177 if (!EasyCoordinate[i]){ 00178 double stepSize = BasicDistance0[i]; 00179 double offset = 0.0; 00180 for (int j=0; j<3; ++j){ 00181 stepSize += BasicDistance1[i][j]*index[j]; 00182 offset += BasicDistance2[i][j]*index[j]; 00183 } 00184 index[i] = int((pnt[i]-(ReferencePoint[i] + offset))/stepSize); 00185 } 00186 } 00187 break; 00188 case 5: 00189 double sinPhi = sin(pnt[1]); 00190 double stepSize = RParAsFunOfPhi[0] + RParAsFunOfPhi[1]/sinPhi - RParAsFunOfPhi[2] - RParAsFunOfPhi[3]/sinPhi; 00191 stepSize = stepSize/(NumberOfPoints[0]-1); 00192 double startingPoint = RParAsFunOfPhi[2] + RParAsFunOfPhi[3]/sinPhi; 00193 index[0] = int((pnt[0]-startingPoint)/stepSize); 00194 index[1] = int((pnt[1]-ReferencePoint[1])/BasicDistance0[1]); 00195 index[2] = int((pnt[2]-ReferencePoint[2])/BasicDistance0[2]); 00196 break; 00197 } 00198 Index1 = index[0]; 00199 Index2 = index[1]; 00200 Index3 = index[2]; 00201 return; 00202 }
void MagneticFieldGrid::putIndGetCoord | ( | int | Index1, | |
int | Index2, | |||
int | Index3, | |||
double & | X1, | |||
double & | X2, | |||
double & | X3 | |||
) |
Definition at line 213 of file MagneticFieldGrid.cc.
References BasicDistance0, BasicDistance1, BasicDistance2, EasyCoordinate, i, index, j, offset, ReferencePoint, RParAsFunOfPhi, and funct::sin().
Referenced by interpolateAtPoint().
00213 { 00214 int index[3] = {Index1, Index2, Index3}; 00215 double pnt[3]; 00216 switch (GridType){ 00217 case 1: 00218 for (int i=0; i<3; ++i){ 00219 pnt[i] = ReferencePoint[i] + BasicDistance0[i]*index[i]; 00220 } 00221 break; 00222 case 2: 00223 for (int i=0; i<3; ++i){ 00224 if (EasyCoordinate[i]){ 00225 pnt[i] = ReferencePoint[i] + BasicDistance0[i]*index[i]; 00226 } 00227 else { 00228 double stepSize = BasicDistance0[i]; 00229 double offset = 0.0; 00230 for (int j=0; j<3; ++j){ 00231 stepSize += BasicDistance1[i][j]*index[j]; 00232 offset += BasicDistance2[i][j]*index[j]; 00233 } 00234 pnt[i] = ReferencePoint[i] + offset + stepSize*index[i]; 00235 } 00236 } 00237 break; 00238 case 3: 00239 for (int i=0; i<3; ++i){ 00240 pnt[i] = ReferencePoint[i] + BasicDistance0[i]*index[i]; 00241 } 00242 break; 00243 case 4: 00244 for (int i=0; i<3; ++i){ 00245 if (EasyCoordinate[i]){ 00246 pnt[i] = ReferencePoint[i] + BasicDistance0[i]*index[i]; 00247 } 00248 else { 00249 double stepSize = BasicDistance0[i]; 00250 double offset = 0.0; 00251 for (int j=0; j<3; ++j){ 00252 stepSize += BasicDistance1[i][j]*index[j]; 00253 offset += BasicDistance2[i][j]*index[j]; 00254 } 00255 pnt[i] = ReferencePoint[i] + offset + stepSize*index[i]; 00256 } 00257 } 00258 break; 00259 case 5: 00260 pnt[2] = ReferencePoint[2] + BasicDistance0[2]*index[2]; 00261 pnt[1] = ReferencePoint[1] + BasicDistance0[1]*index[1]; 00262 double sinPhi = sin(pnt[1]); 00263 double stepSize = RParAsFunOfPhi[0] + RParAsFunOfPhi[1]/sinPhi - RParAsFunOfPhi[2] - RParAsFunOfPhi[3]/sinPhi; 00264 stepSize = stepSize/(NumberOfPoints[0]-1); 00265 double startingPoint = RParAsFunOfPhi[2] + RParAsFunOfPhi[3]/sinPhi; 00266 pnt[0] = startingPoint + stepSize*index[0]; 00267 break; 00268 } 00269 X1 = pnt[0]; 00270 X2 = pnt[1]; 00271 X3 = pnt[2]; 00272 return; 00273 }
void MagneticFieldGrid::putIndicesGetB | ( | int | Index1, | |
int | Index2, | |||
int | Index3, | |||
float & | Bx, | |||
float & | By, | |||
float & | Bz | |||
) |
Definition at line 204 of file MagneticFieldGrid.cc.
References MagneticFieldGrid::BVector::bx(), MagneticFieldGrid::BVector::by(), MagneticFieldGrid::BVector::bz(), FieldValues, and lineNumber().
Referenced by interpolateAtPoint().
00204 { 00205 BVector FieldEntry; 00206 FieldEntry = FieldValues.operator[](lineNumber(Index1, Index2, Index3)); 00207 Bx = FieldEntry.bx(); 00208 By = FieldEntry.by(); 00209 Bz = FieldEntry.bz(); 00210 return; 00211 }
double MagneticFieldGrid::BasicDistance0[3] [private] |
Definition at line 84 of file MagneticFieldGrid.h.
Referenced by MagneticFieldGrid(), putCoordGetInd(), and putIndGetCoord().
double MagneticFieldGrid::BasicDistance1[3][3] [private] |
Definition at line 85 of file MagneticFieldGrid.h.
Referenced by MagneticFieldGrid(), putCoordGetInd(), and putIndGetCoord().
double MagneticFieldGrid::BasicDistance2[3][3] [private] |
Definition at line 86 of file MagneticFieldGrid.h.
Referenced by MagneticFieldGrid(), putCoordGetInd(), and putIndGetCoord().
bool MagneticFieldGrid::EasyCoordinate[3] [private] |
Definition at line 88 of file MagneticFieldGrid.h.
Referenced by MagneticFieldGrid(), putCoordGetInd(), and putIndGetCoord().
std::vector<BVector> MagneticFieldGrid::FieldValues [private] |
int MagneticFieldGrid::GridType [private] |
int MagneticFieldGrid::NumberOfPoints[3] [private] |
double MagneticFieldGrid::ReferencePoint[3] [private] |
Definition at line 83 of file MagneticFieldGrid.h.
Referenced by MagneticFieldGrid(), putCoordGetInd(), and putIndGetCoord().
double MagneticFieldGrid::RParAsFunOfPhi[4] [private] |
Definition at line 87 of file MagneticFieldGrid.h.
Referenced by MagneticFieldGrid(), putCoordGetInd(), and putIndGetCoord().