CMS 3D CMS Logo

Classes | Public Member Functions | Private Attributes

MagneticFieldGrid Class Reference

#include <MagneticFieldGrid.h>

List of all members.

Classes

class  BVector
class  HeaderType3

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< BVectorFieldValues
int GridType
int NumberOfPoints [3]
double ReferencePoint [3]
double RParAsFunOfPhi [4]

Detailed Description

load magnetic field grid from binary file remark: units are either (cm,cm,cm) or (cm,rad,cm) and Tesla for the magnetic field

additional functions either translate indices <-> coordinates, transfer data, or activate the interpolation between grid points

Author:
: <Volker.Drollinger@cern.ch> $date : 31/03/2004 13:07:28 CET $

Modifications:

Definition at line 33 of file MagneticFieldGrid.h.


Constructor & Destructor Documentation

MagneticFieldGrid::MagneticFieldGrid ( ) [inline]

Definition at line 36 of file MagneticFieldGrid.h.

References i, and j.

                     {
    GridType = 0;
    for (int i=0;i<3; ++i) {NumberOfPoints[i] = 0;};
    for (int i=0;i<3; ++i) {ReferencePoint[i] = 0.;};
    for (int i=0;i<3; ++i) {BasicDistance0[i] = 0.;};
    for (int i=0;i<3; ++i) {for (int j=0;j<3; ++j) {BasicDistance1[i][j] = 0.;};};
    for (int i=0;i<3; ++i) {for (int j=0;j<3; ++j) {BasicDistance2[i][j] = 0.;};};
    for (int i=0;i<4; ++i) {RParAsFunOfPhi[i] = 0.;};
    for (int i=0;i<3; ++i) {EasyCoordinate[i] = false;};
  }
MagneticFieldGrid::~MagneticFieldGrid ( ) [inline]

Definition at line 47 of file MagneticFieldGrid.h.

{}

Member Function Documentation

int MagneticFieldGrid::gridType ( )

returns value of GridType (and eventually prints the type + short description)

Definition at line 74 of file MagneticFieldGrid.cc.

References gather_cfg::cout, and runonSM::text.

Referenced by GlobalGridWrapper::valueInTesla().

                               {
  int type = GridType;
  bool text = false;
  if (text){
    if (type == 0) cout << "  grid type = " << type << "  -->  not determined" << endl;
    if (type == 1) cout << "  grid type = " << type << "  -->  (x,y,z) cube" << endl;
    if (type == 2) cout << "  grid type = " << type << "  -->  (x,y,z) trapezoid" << endl;
    if (type == 3) cout << "  grid type = " << type << "  -->  (r,phi,z) cube" << endl;
    if (type == 4) cout << "  grid type = " << type << "  -->  (r,phi,z) trapezoid" << endl;
    if (type == 5) cout << "  grid type = " << type << "  -->  (r,phi,z) 1/sin(phi)" << endl;
  }
  return type;
}
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 88 of file MagneticFieldGrid.cc.

References VectorFieldInterpolation::defineCellPoint000(), VectorFieldInterpolation::defineCellPoint001(), VectorFieldInterpolation::defineCellPoint010(), VectorFieldInterpolation::defineCellPoint011(), VectorFieldInterpolation::defineCellPoint100(), VectorFieldInterpolation::defineCellPoint101(), VectorFieldInterpolation::defineCellPoint110(), VectorFieldInterpolation::defineCellPoint111(), i, getHLTprescales::index, max(), and VectorFieldInterpolation::putSCoordGetVField().

Referenced by GlobalGridWrapper::valueInTesla().

                                                                                                          {
  double dB[3] = {0.,0.,0.};
  // define interpolation object
  VectorFieldInterpolation MagInterpol;
  // calculate indices for "CellPoint000"
  int index[3];
  putCoordGetInd(X1,X2,X3,index[0],index[1],index[2]);
  int index0[3] = {0,0,0};
  int index1[3] = {0,0,0};
  for (int i=0; i<3; ++i){
    if (NumberOfPoints[i] > 1){
                                           index0[i] = max(0,index[i]);
      if (index0[i] > NumberOfPoints[i]-2) index0[i] = NumberOfPoints[i]-2;
                                           index1[i] = max(1,index[i]+1);
      if (index1[i] > NumberOfPoints[i]-1) index1[i] = NumberOfPoints[i]-1;
    }
  }
  double tmpX[3];
  float  tmpB[3];
  // define the corners of interpolation volume
  // FIXME: should not unpack the arrays to then repack them as first thing.
  putIndicesGetB(index0[0],index0[1],index0[2],tmpB[0],tmpB[1],tmpB[2]);
  putIndGetCoord(index0[0],index0[1],index0[2],tmpX[0],tmpX[1],tmpX[2]);
  MagInterpol.defineCellPoint000(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2]));
  putIndicesGetB(index1[0],index0[1],index0[2],tmpB[0],tmpB[1],tmpB[2]);
  putIndGetCoord(index1[0],index0[1],index0[2],tmpX[0],tmpX[1],tmpX[2]);
  MagInterpol.defineCellPoint100(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2]));
  putIndicesGetB(index0[0],index1[1],index0[2],tmpB[0],tmpB[1],tmpB[2]);
  putIndGetCoord(index0[0],index1[1],index0[2],tmpX[0],tmpX[1],tmpX[2]);
  MagInterpol.defineCellPoint010(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2]));
  putIndicesGetB(index1[0],index1[1],index0[2],tmpB[0],tmpB[1],tmpB[2]);
  putIndGetCoord(index1[0],index1[1],index0[2],tmpX[0],tmpX[1],tmpX[2]);
  MagInterpol.defineCellPoint110(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2]));
  putIndicesGetB(index0[0],index0[1],index1[2],tmpB[0],tmpB[1],tmpB[2]);
  putIndGetCoord(index0[0],index0[1],index1[2],tmpX[0],tmpX[1],tmpX[2]);
  MagInterpol.defineCellPoint001(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2]));
  putIndicesGetB(index1[0],index0[1],index1[2],tmpB[0],tmpB[1],tmpB[2]);
  putIndGetCoord(index1[0],index0[1],index1[2],tmpX[0],tmpX[1],tmpX[2]);
  MagInterpol.defineCellPoint101(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2]));
  putIndicesGetB(index0[0],index1[1],index1[2],tmpB[0],tmpB[1],tmpB[2]);
  putIndGetCoord(index0[0],index1[1],index1[2],tmpX[0],tmpX[1],tmpX[2]);
  MagInterpol.defineCellPoint011(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2]));
  putIndicesGetB(index1[0],index1[1],index1[2],tmpB[0],tmpB[1],tmpB[2]);
  putIndGetCoord(index1[0],index1[1],index1[2],tmpX[0],tmpX[1],tmpX[2]);
  MagInterpol.defineCellPoint111(tmpX[0],tmpX[1],tmpX[2],double(tmpB[0]),double(tmpB[1]),double(tmpB[2]));
  // interpolate
  MagInterpol.putSCoordGetVField(X1,X2,X3,dB[0],dB[1],dB[2]);
  Bx = float(dB[0]);
  By = float(dB[1]);
  Bz = float(dB[2]);
  return;
}
int MagneticFieldGrid::lineNumber ( int  Index1,
int  Index2,
int  Index3 
)

Definition at line 285 of file MagneticFieldGrid.cc.

                                                                   {
  return Index1*NumberOfPoints[1]*NumberOfPoints[2] + Index2*NumberOfPoints[2] + Index3;
}
void MagneticFieldGrid::load ( const std::string &  name)

load grid binary file

Referenced by GlobalGridWrapper::GlobalGridWrapper().

void MagneticFieldGrid::putCoordGetInd ( double  X1,
double  X2,
double  X3,
int &  Index1,
int &  Index2,
int &  Index3 
)

Definition at line 145 of file MagneticFieldGrid.cc.

References i, getHLTprescales::index, j, evf::evtn::offset(), and funct::sin().

                                                                                                            {
  double pnt[3] = {X1,X2,X3};
  int index[3];
  switch (GridType){
  case 1:
    for (int i=0; i<3; ++i){
      index[i] = int((pnt[i]-ReferencePoint[i])/BasicDistance0[i]);
    }
    break;
  case 2:
    // FIXME: Should use else!
    for (int i=0; i<3; ++i){
      if (EasyCoordinate[i]){
        index[i] = int((pnt[i]-ReferencePoint[i])/BasicDistance0[i]);
      }
    }
    for (int i=0; i<3; ++i){
      if (!EasyCoordinate[i]){
        double stepSize = BasicDistance0[i];
        double offset   = 0.0;
        for (int j=0; j<3; ++j){
          stepSize += BasicDistance1[i][j]*index[j];
          offset   += BasicDistance2[i][j]*index[j];
        }
        index[i] = int((pnt[i]-(ReferencePoint[i] + offset))/stepSize);
      }
    }
    break;
  case 3:
    for (int i=0; i<3; ++i){
      index[i] = int((pnt[i]-ReferencePoint[i])/BasicDistance0[i]);
    }
    break;
  case 4:
    // FIXME: should use else!
    for (int i=0; i<3; ++i){
      if (EasyCoordinate[i]){
        index[i] = int((pnt[i]-ReferencePoint[i])/BasicDistance0[i]);
      }
    }
    for (int i=0; i<3; ++i){
      if (!EasyCoordinate[i]){
        double stepSize = BasicDistance0[i];
        double offset   = 0.0;
        for (int j=0; j<3; ++j){
          stepSize += BasicDistance1[i][j]*index[j];
          offset   += BasicDistance2[i][j]*index[j];
        }
        index[i] = int((pnt[i]-(ReferencePoint[i] + offset))/stepSize);
      }
    }
    break;
  case 5:
    double sinPhi = sin(pnt[1]);
    double stepSize = RParAsFunOfPhi[0] + RParAsFunOfPhi[1]/sinPhi - RParAsFunOfPhi[2] - RParAsFunOfPhi[3]/sinPhi;
    stepSize =  stepSize/(NumberOfPoints[0]-1);
    double startingPoint = RParAsFunOfPhi[2] + RParAsFunOfPhi[3]/sinPhi;
    index[0] = int((pnt[0]-startingPoint)/stepSize);
    index[1] = int((pnt[1]-ReferencePoint[1])/BasicDistance0[1]);
    index[2] = int((pnt[2]-ReferencePoint[2])/BasicDistance0[2]);
    break;
  }
  Index1 = index[0];
  Index2 = index[1];
  Index3 = index[2];
  return;
}
void MagneticFieldGrid::putIndGetCoord ( int  Index1,
int  Index2,
int  Index3,
double &  X1,
double &  X2,
double &  X3 
)

Definition at line 223 of file MagneticFieldGrid.cc.

References i, getHLTprescales::index, j, evf::evtn::offset(), and funct::sin().

                                                                                                            {
  int index[3] = {Index1, Index2, Index3};
  double pnt[3];
  switch (GridType){
  case 1:
    for (int i=0; i<3; ++i){
      pnt[i] = ReferencePoint[i] + BasicDistance0[i]*index[i];
    }
    break;
  case 2:
    for (int i=0; i<3; ++i){
      if (EasyCoordinate[i]){
        pnt[i] = ReferencePoint[i] + BasicDistance0[i]*index[i];
      }
      else {
        double stepSize = BasicDistance0[i];
        double offset   = 0.0;
        for (int j=0; j<3; ++j){
          stepSize += BasicDistance1[i][j]*index[j];
          offset   += BasicDistance2[i][j]*index[j];
        }
        pnt[i] = ReferencePoint[i] + offset + stepSize*index[i];
      }
    }
    break;
  case 3:
    for (int i=0; i<3; ++i){
      pnt[i] = ReferencePoint[i] + BasicDistance0[i]*index[i];
    }
    break;
  case 4:
    for (int i=0; i<3; ++i){
      if (EasyCoordinate[i]){
        pnt[i] = ReferencePoint[i] + BasicDistance0[i]*index[i];
      }
      else {
        double stepSize = BasicDistance0[i];
        double offset   = 0.0;
        for (int j=0; j<3; ++j){
          stepSize += BasicDistance1[i][j]*index[j];
          offset   += BasicDistance2[i][j]*index[j];
        }
        pnt[i] = ReferencePoint[i] + offset + stepSize*index[i];
      }
    }
    break;
  case 5:
    pnt[2] = ReferencePoint[2] + BasicDistance0[2]*index[2];
    pnt[1] = ReferencePoint[1] + BasicDistance0[1]*index[1];
    double sinPhi = sin(pnt[1]);
    double stepSize = RParAsFunOfPhi[0] + RParAsFunOfPhi[1]/sinPhi - RParAsFunOfPhi[2] - RParAsFunOfPhi[3]/sinPhi;
    stepSize =  stepSize/(NumberOfPoints[0]-1);
    double startingPoint = RParAsFunOfPhi[2] + RParAsFunOfPhi[3]/sinPhi;
    pnt[0] = startingPoint + stepSize*index[0];
    break;
  }
  X1 = pnt[0];
  X2 = pnt[1];
  X3 = pnt[2];
  return;
}
void MagneticFieldGrid::putIndicesGetB ( int  Index1,
int  Index2,
int  Index3,
float &  Bx,
float &  By,
float &  Bz 
)

Definition at line 213 of file MagneticFieldGrid.cc.

References MagneticFieldGrid::BVector::bx(), MagneticFieldGrid::BVector::by(), and MagneticFieldGrid::BVector::bz().

                                                                                                         {
  BVector FieldEntry;
  FieldEntry = FieldValues.operator[](lineNumber(Index1, Index2, Index3));
  Bx = FieldEntry.bx();
  By = FieldEntry.by();
  Bz = FieldEntry.bz();
  return;
}

Member Data Documentation

double MagneticFieldGrid::BasicDistance0[3] [private]

Definition at line 85 of file MagneticFieldGrid.h.

double MagneticFieldGrid::BasicDistance1[3][3] [private]

Definition at line 86 of file MagneticFieldGrid.h.

double MagneticFieldGrid::BasicDistance2[3][3] [private]

Definition at line 87 of file MagneticFieldGrid.h.

Definition at line 89 of file MagneticFieldGrid.h.

std::vector<BVector> MagneticFieldGrid::FieldValues [private]

Definition at line 91 of file MagneticFieldGrid.h.

Definition at line 81 of file MagneticFieldGrid.h.

Definition at line 83 of file MagneticFieldGrid.h.

double MagneticFieldGrid::ReferencePoint[3] [private]

Definition at line 84 of file MagneticFieldGrid.h.

double MagneticFieldGrid::RParAsFunOfPhi[4] [private]

Definition at line 88 of file MagneticFieldGrid.h.